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
c4bdb3588999023ccd1d8999ecdff3a4c3d8f2c6
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/topology/instances/ennreal.lean
1767ae115acedc8cc9c8f363705687a3691920c2
[ "Apache-2.0" ]
permissive
anrddh/mathlib
6a374da53c7e3a35cb0298b0cd67824efef362b4
a4266a01d2dcb10de19369307c986d038c7bb6a6
refs/heads/master
1,656,710,827,909
1,589,560,456,000
1,589,560,456,000
264,271,800
0
0
Apache-2.0
1,589,568,062,000
1,589,568,061,000
null
UTF-8
Lean
false
false
38,529
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl -/ import topology.instances.nnreal /-! # Extended non-negative reals -/ noncomputable theory open classical set filter metric open_locale classical open_locale topological_space variables {α : Type*} {β : Type*} {γ : Type*} open_locale ennreal namespace ennreal variables {a b c d : ennreal} {r p q : nnreal} variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal} section topological_space open topological_space /-- Topology on `ennreal`. Note: this is different from the `emetric_space` topology. The `emetric_space` topology has `is_open {⊤}`, while this topology doesn't have singleton elements. -/ instance : topological_space ennreal := preorder.topology ennreal instance : order_topology ennreal := ⟨rfl⟩ instance : t2_space ennreal := by apply_instance -- short-circuit type class inference instance : second_countable_topology ennreal := ⟨⟨⋃q ≥ (0:ℚ), {{a : ennreal | a < nnreal.of_real q}, {a : ennreal | ↑(nnreal.of_real q) < a}}, (countable_encodable _).bUnion $ assume a ha, (countable_singleton _).insert _, le_antisymm (le_generate_from $ by simp [or_imp_distrib, is_open_lt', is_open_gt'] {contextual := tt}) (le_generate_from $ λ s h, begin rcases h with ⟨a, hs | hs⟩; [ rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ a < nnreal.of_real q}, {b | ↑(nnreal.of_real q) < b}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn a b, and_assoc]), rw show s = ⋃q∈{q:ℚ | 0 ≤ q ∧ ↑(nnreal.of_real q) < a}, {b | b < ↑(nnreal.of_real q)}, from set.ext (assume b, by simp [hs, @ennreal.lt_iff_exists_rat_btwn b a, and_comm, and_assoc])]; { apply is_open_Union, intro q, apply is_open_Union, intro hq, exact generate_open.basic _ (mem_bUnion hq.1 $ by simp) } end)⟩⟩ lemma embedding_coe : embedding (coe : nnreal → ennreal) := ⟨⟨begin refine le_antisymm _ _, { rw [@order_topology.topology_eq_generate_intervals ennreal _, ← coinduced_le_iff_le_induced], refine le_generate_from (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, show is_open {b : nnreal | a < ↑b}, { cases a; simp [none_eq_top, some_eq_coe, is_open_lt'] }, show is_open {b : nnreal | ↑b < a}, { cases a; simp [none_eq_top, some_eq_coe, is_open_gt', is_open_const] } }, { rw [@order_topology.topology_eq_generate_intervals nnreal _], refine le_generate_from (assume s ha, _), rcases ha with ⟨a, rfl | rfl⟩, exact ⟨Ioi a, is_open_Ioi, by simp [Ioi]⟩, exact ⟨Iio a, is_open_Iio, by simp [Iio]⟩ } end⟩, assume a b, coe_eq_coe.1⟩ lemma is_open_ne_top : is_open {a : ennreal | a ≠ ⊤} := is_open_ne lemma is_open_Ico_zero : is_open (Ico 0 b) := by { rw ennreal.Ico_eq_Iio, exact is_open_Iio} lemma coe_range_mem_nhds : range (coe : nnreal → ennreal) ∈ 𝓝 (r : ennreal) := have {a : ennreal | a ≠ ⊤} = range (coe : nnreal → ennreal), from set.ext $ assume a, by cases a; simp [none_eq_top, some_eq_coe], this ▸ mem_nhds_sets is_open_ne_top coe_ne_top @[norm_cast] lemma tendsto_coe {f : filter α} {m : α → nnreal} {a : nnreal} : tendsto (λa, (m a : ennreal)) f (𝓝 ↑a) ↔ tendsto m f (𝓝 a) := embedding_coe.tendsto_nhds_iff.symm lemma continuous_coe {α} [topological_space α] {f : α → nnreal} : continuous (λa, (f a : ennreal)) ↔ continuous f := embedding_coe.continuous_iff.symm lemma nhds_coe {r : nnreal} : 𝓝 (r : ennreal) = (𝓝 r).map coe := by rw [embedding_coe.induced, map_nhds_induced_eq coe_range_mem_nhds] lemma nhds_coe_coe {r p : nnreal} : 𝓝 ((r : ennreal), (p : ennreal)) = (𝓝 (r, p)).map (λp:nnreal×nnreal, (p.1, p.2)) := begin rw [(embedding_coe.prod_mk embedding_coe).map_nhds_eq], rw [← prod_range_range_eq], exact prod_mem_nhds_sets coe_range_mem_nhds coe_range_mem_nhds end lemma continuous_of_real : continuous ennreal.of_real := (continuous_coe.2 continuous_id).comp nnreal.continuous_of_real lemma tendsto_of_real {f : filter α} {m : α → ℝ} {a : ℝ} (h : tendsto m f (𝓝 a)) : tendsto (λa, ennreal.of_real (m a)) f (𝓝 (ennreal.of_real a)) := tendsto.comp (continuous.tendsto continuous_of_real _) h lemma tendsto_to_nnreal {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_nnreal) (𝓝 a) (𝓝 a.to_nnreal) := begin cases a; simp [some_eq_coe, none_eq_top, nhds_coe, tendsto_map'_iff, (∘)], exact tendsto_id end lemma continuous_on_to_nnreal : continuous_on ennreal.to_nnreal {a | a ≠ ∞} := continuous_on_iff_continuous_restrict.2 $ continuous_iff_continuous_at.2 $ λ x, (tendsto_to_nnreal x.2).comp continuous_at_subtype_val lemma tendsto_to_real {a : ennreal} : a ≠ ⊤ → tendsto (ennreal.to_real) (𝓝 a) (𝓝 a.to_real) := λ ha, tendsto.comp ((@nnreal.tendsto_coe _ (𝓝 a.to_nnreal) id (a.to_nnreal)).2 tendsto_id) (tendsto_to_nnreal ha) lemma tendsto_nhds_top {m : α → ennreal} {f : filter α} (h : ∀ n : ℕ, ∀ᶠ a in f, ↑n < m a) : tendsto m f (𝓝 ⊤) := tendsto_nhds_generate_from $ assume s hs, match s, hs with | _, ⟨none, or.inl rfl⟩, hr := (lt_irrefl ⊤ hr).elim | _, ⟨some r, or.inl rfl⟩, hr := let ⟨n, hrn⟩ := exists_nat_gt r in mem_sets_of_superset (h n) $ assume a hnma, show ↑r < m a, from lt_trans (show (r : ennreal) < n, from (coe_nat n) ▸ coe_lt_coe.2 hrn) hnma | _, ⟨a, or.inr rfl⟩, hr := (not_top_lt $ show ⊤ < a, from hr).elim end lemma tendsto_nat_nhds_top : tendsto (λ n : ℕ, ↑n) at_top (𝓝 ∞) := tendsto_nhds_top $ λ n, mem_at_top_sets.2 ⟨n+1, λ m hm, ennreal.coe_nat_lt_coe_nat.2 $ nat.lt_of_succ_le hm⟩ lemma nhds_top : 𝓝 ∞ = ⨅a ≠ ∞, principal (Ioi a) := nhds_top_order.trans $ by simp [lt_top_iff_ne_top, Ioi] lemma nhds_zero : 𝓝 (0 : ennreal) = ⨅a ≠ 0, principal (Iio a) := nhds_bot_order.trans $ by simp [bot_lt_iff_ne_bot, Iio] /-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/ def ne_top_homeomorph_nnreal : {a | a ≠ ∞} ≃ₜ nnreal := { to_fun := λ x, ennreal.to_nnreal x, inv_fun := λ x, ⟨x, coe_ne_top⟩, left_inv := λ ⟨x, hx⟩, subtype.eq $ coe_to_nnreal hx, right_inv := λ x, to_nnreal_coe, continuous_to_fun := continuous_on_iff_continuous_restrict.1 continuous_on_to_nnreal, continuous_inv_fun := continuous_subtype_mk _ (continuous_coe.2 continuous_id) } /-- The set of finite `ennreal` numbers is homeomorphic to `nnreal`. -/ def lt_top_homeomorph_nnreal : {a | a < ∞} ≃ₜ nnreal := by refine (homeomorph.set_congr $ set.ext $ λ x, _).trans ne_top_homeomorph_nnreal; simp only [mem_set_of_eq, lt_top_iff_ne_top] -- using Icc because -- • don't have 'Ioo (x - ε) (x + ε) ∈ 𝓝 x' unless x > 0 -- • (x - y ≤ ε ↔ x ≤ ε + y) is true, while (x - y < ε ↔ x < ε + y) is not lemma Icc_mem_nhds : x ≠ ⊤ → ε > 0 → Icc (x - ε) (x + ε) ∈ 𝓝 x := begin assume xt ε0, rw mem_nhds_sets_iff, by_cases x0 : x = 0, { use Iio (x + ε), have : Iio (x + ε) ⊆ Icc (x - ε) (x + ε), assume a, rw x0, simpa using le_of_lt, use this, exact ⟨is_open_Iio, mem_Iio_self_add xt ε0⟩ }, { use Ioo (x - ε) (x + ε), use Ioo_subset_Icc_self, exact ⟨is_open_Ioo, mem_Ioo_self_sub_add xt x0 ε0 ε0 ⟩ } end lemma nhds_of_ne_top : x ≠ ⊤ → 𝓝 x = ⨅ε > 0, principal (Icc (x - ε) (x + ε)) := begin assume xt, refine le_antisymm _ _, -- first direction simp only [le_infi_iff, le_principal_iff], assume ε ε0, exact Icc_mem_nhds xt ε0, -- second direction rw nhds_generate_from, refine le_infi (assume s, le_infi $ assume hs, _), simp only [mem_set_of_eq] at hs, rcases hs with ⟨xs, ⟨a, ha⟩⟩, cases ha, { rw ha at *, rcases dense xs with ⟨b, ⟨ab, bx⟩⟩, have xb_pos : x - b > 0 := zero_lt_sub_iff_lt.2 bx, have xxb : x - (x - b) = b := sub_sub_cancel (by rwa lt_top_iff_ne_top) (le_of_lt bx), refine infi_le_of_le (x - b) (infi_le_of_le xb_pos _), simp only [mem_principal_sets, le_principal_iff], assume y, rintros ⟨h₁, h₂⟩, rw xxb at h₁, calc a < b : ab ... ≤ y : h₁ }, { rw ha at *, rcases dense xs with ⟨b, ⟨xb, ba⟩⟩, have bx_pos : b - x > 0 := zero_lt_sub_iff_lt.2 xb, have xbx : x + (b - x) = b := add_sub_cancel_of_le (le_of_lt xb), refine infi_le_of_le (b - x) (infi_le_of_le bx_pos _), simp only [mem_principal_sets, le_principal_iff], assume y, rintros ⟨h₁, h₂⟩, rw xbx at h₂, calc y ≤ b : h₂ ... < a : ba }, end /-- Characterization of neighborhoods for `ennreal` numbers. See also `tendsto_order` for a version with strict inequalities. -/ protected theorem tendsto_nhds {f : filter α} {u : α → ennreal} {a : ennreal} (ha : a ≠ ⊤) : tendsto u f (𝓝 a) ↔ ∀ ε > 0, ∀ᶠ x in f, (u x) ∈ Icc (a - ε) (a + ε) := by simp only [nhds_of_ne_top ha, tendsto_infi, tendsto_principal, mem_Icc] protected lemma tendsto_at_top [nonempty β] [semilattice_sup β] {f : β → ennreal} {a : ennreal} (ha : a ≠ ⊤) : tendsto f at_top (𝓝 a) ↔ ∀ε>0, ∃N, ∀n≥N, (f n) ∈ Icc (a - ε) (a + ε) := by simp only [ennreal.tendsto_nhds ha, mem_at_top_sets, mem_set_of_eq, filter.eventually] lemma tendsto_coe_nnreal_nhds_top {α} {l : filter α} {f : α → nnreal} (h : tendsto f l at_top) : tendsto (λa, (f a : ennreal)) l (𝓝 ∞) := tendsto_nhds_top $ assume n, have ∀ᶠ a in l, ↑(n+1) ≤ f a := h $ mem_at_top _, mem_sets_of_superset this $ assume a (ha : ↑(n+1) ≤ f a), begin rw [← coe_nat], dsimp, exact coe_lt_coe.2 (lt_of_lt_of_le (nat.cast_lt.2 (nat.lt_succ_self _)) ha) end instance : topological_add_monoid ennreal := ⟨ continuous_iff_continuous_at.2 $ have hl : ∀a:ennreal, tendsto (λ (p : ennreal × ennreal), p.fst + p.snd) (𝓝 (⊤, a)) (𝓝 ⊤), from assume a, tendsto_nhds_top $ assume n, have set.prod {a | ↑n < a } univ ∈ 𝓝 ((⊤:ennreal), a), from prod_mem_nhds_sets (lt_mem_nhds $ coe_nat n ▸ coe_lt_top) univ_mem_sets, show {a : ennreal × ennreal | ↑n < a.fst + a.snd} ∈ 𝓝 (⊤, a), begin filter_upwards [this] assume ⟨a₁, a₂⟩ ⟨h₁, h₂⟩, lt_of_lt_of_le h₁ (le_add_right $ le_refl _) end, begin rintro ⟨a₁, a₂⟩, cases a₁, { simp [continuous_at, none_eq_top, hl a₂], }, cases a₂, { simp [continuous_at, none_eq_top, some_eq_coe, nhds_swap (a₁ : ennreal) ⊤, tendsto_map'_iff, (∘)], convert hl a₁, simp [add_comm] }, simp [continuous_at, some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)], simp only [coe_add.symm, tendsto_coe, tendsto_add] end ⟩ protected lemma tendsto_mul (ha : a ≠ 0 ∨ b ≠ ⊤) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 (a, b)) (𝓝 (a * b)) := have ht : ∀b:ennreal, b ≠ 0 → tendsto (λp:ennreal×ennreal, p.1 * p.2) (𝓝 ((⊤:ennreal), b)) (𝓝 ⊤), begin refine assume b hb, tendsto_nhds_top $ assume n, _, rcases dense (zero_lt_iff_ne_zero.2 hb) with ⟨ε', hε', hεb'⟩, rcases ennreal.lt_iff_exists_coe.1 hεb' with ⟨ε, rfl, h⟩, rcases exists_nat_gt (↑n / ε) with ⟨m, hm⟩, have hε : ε > 0, from coe_lt_coe.1 hε', refine mem_sets_of_superset (prod_mem_nhds_sets (lt_mem_nhds $ @coe_lt_top m) (lt_mem_nhds $ h)) _, rintros ⟨a₁, a₂⟩ ⟨h₁, h₂⟩, dsimp at h₁ h₂ ⊢, calc (n:ennreal) = ↑(((n:nnreal) / ε) * ε) : begin simp [nnreal.div_def], rw [mul_assoc, ← coe_mul, nnreal.inv_mul_cancel, coe_one, ← coe_nat, mul_one], exact zero_lt_iff_ne_zero.1 hε end ... < (↑m * ε : nnreal) : coe_lt_coe.2 $ mul_lt_mul hm (le_refl _) hε (nat.cast_nonneg _) ... ≤ a₁ * a₂ : by rw [coe_mul]; exact canonically_ordered_semiring.mul_le_mul (le_of_lt h₁) (le_of_lt h₂) end, begin cases a, {simp [none_eq_top] at hb, simp [none_eq_top, ht b hb, top_mul, hb] }, cases b, { simp [none_eq_top] at ha, simp [*, nhds_swap (a : ennreal) ⊤, none_eq_top, some_eq_coe, top_mul, tendsto_map'_iff, (∘), mul_comm] }, simp [some_eq_coe, nhds_coe_coe, tendsto_map'_iff, (∘)], simp only [coe_mul.symm, tendsto_coe, tendsto_mul] end protected lemma tendsto.mul {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal} (hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λa, ma a * mb a) f (𝓝 (a * b)) := show tendsto ((λp:ennreal×ennreal, p.1 * p.2) ∘ (λa, (ma a, mb a))) f (𝓝 (a * b)), from tendsto.comp (ennreal.tendsto_mul ha hb) (hma.prod_mk_nhds hmb) protected lemma tendsto.const_mul {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 b)) (hb : b ≠ 0 ∨ a ≠ ⊤) : tendsto (λb, a * m b) f (𝓝 (a * b)) := by_cases (assume : a = 0, by simp [this, tendsto_const_nhds]) (assume ha : a ≠ 0, ennreal.tendsto.mul tendsto_const_nhds (or.inl ha) hm hb) protected lemma tendsto.mul_const {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ ⊤) : tendsto (λx, m x * b) f (𝓝 (a * b)) := by simpa only [mul_comm] using ennreal.tendsto.const_mul hm ha protected lemma continuous_const_mul {a : ennreal} (ha : a < ⊤) : continuous ((*) a) := continuous_iff_continuous_at.2 $ λ x, tendsto.const_mul tendsto_id $ or.inr $ ne_of_lt ha protected lemma continuous_mul_const {a : ennreal} (ha : a < ⊤) : continuous (λ x, x * a) := by simpa only [mul_comm] using ennreal.continuous_const_mul ha protected lemma continuous_inv : continuous (has_inv.inv : ennreal → ennreal) := continuous_iff_continuous_at.2 $ λ a, tendsto_order.2 ⟨begin assume b hb, simp only [@ennreal.lt_inv_iff_lt_inv b], exact gt_mem_nhds (ennreal.lt_inv_iff_lt_inv.1 hb), end, begin assume b hb, simp only [gt_iff_lt, @ennreal.inv_lt_iff_inv_lt _ b], exact lt_mem_nhds (ennreal.inv_lt_iff_inv_lt.1 hb) end⟩ @[simp] protected lemma tendsto_inv_iff {f : filter α} {m : α → ennreal} {a : ennreal} : tendsto (λ x, (m x)⁻¹) f (𝓝 a⁻¹) ↔ tendsto m f (𝓝 a) := ⟨λ h, by simpa only [function.comp, ennreal.inv_inv] using (ennreal.continuous_inv.tendsto a⁻¹).comp h, (ennreal.continuous_inv.tendsto a).comp⟩ protected lemma tendsto.div {f : filter α} {ma : α → ennreal} {mb : α → ennreal} {a b : ennreal} (hma : tendsto ma f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) (hmb : tendsto mb f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λa, ma a / mb a) f (𝓝 (a / b)) := by { apply tendsto.mul hma _ (ennreal.tendsto_inv_iff.2 hmb) _; simp [ha, hb] } protected lemma tendsto.const_div {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 b)) (hb : b ≠ ⊤ ∨ a ≠ ⊤) : tendsto (λb, a / m b) f (𝓝 (a / b)) := by { apply tendsto.const_mul (ennreal.tendsto_inv_iff.2 hm), simp [hb] } protected lemma tendsto.div_const {f : filter α} {m : α → ennreal} {a b : ennreal} (hm : tendsto m f (𝓝 a)) (ha : a ≠ 0 ∨ b ≠ 0) : tendsto (λx, m x / b) f (𝓝 (a / b)) := by { apply tendsto.mul_const hm, simp [ha] } protected lemma tendsto_inv_nat_nhds_zero : tendsto (λ n : ℕ, (n : ennreal)⁻¹) at_top (𝓝 0) := ennreal.inv_top ▸ ennreal.tendsto_inv_iff.2 tendsto_nat_nhds_top lemma Sup_add {s : set ennreal} (hs : s.nonempty) : Sup s + a = ⨆b∈s, b + a := have Sup ((λb, b + a) '' s) = Sup s + a, from is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto (assume x _ y _ h, add_le_add' h (le_refl _)) (is_lub_Sup s) hs (tendsto.add (tendsto_id' inf_le_left) tendsto_const_nhds)), by simp [Sup_image, -add_comm] at this; exact this.symm lemma supr_add {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : supr s + a = ⨆b, s b + a := let ⟨x⟩ := h in calc supr s + a = Sup (range s) + a : by simp [Sup_range] ... = (⨆b∈range s, b + a) : Sup_add ⟨s x, x, rfl⟩ ... = _ : supr_range lemma add_supr {ι : Sort*} {s : ι → ennreal} [h : nonempty ι] : a + supr s = ⨆b, a + s b := by rw [add_comm, supr_add]; simp [add_comm] lemma supr_add_supr {ι : Sort*} {f g : ι → ennreal} (h : ∀i j, ∃k, f i + g j ≤ f k + g k) : supr f + supr g = (⨆ a, f a + g a) := begin by_cases hι : nonempty ι, { letI := hι, refine le_antisymm _ (supr_le $ λ a, add_le_add' (le_supr _ _) (le_supr _ _)), simpa [add_supr, supr_add] using λ i j:ι, show f i + g j ≤ ⨆ a, f a + g a, from let ⟨k, hk⟩ := h i j in le_supr_of_le k hk }, { have : ∀f:ι → ennreal, (⨆i, f i) = 0 := assume f, bot_unique (supr_le $ assume i, (hι ⟨i⟩).elim), rw [this, this, this, zero_add] } end lemma supr_add_supr_of_monotone {ι : Sort*} [semilattice_sup ι] {f g : ι → ennreal} (hf : monotone f) (hg : monotone g) : supr f + supr g = (⨆ a, f a + g a) := supr_add_supr $ assume i j, ⟨i ⊔ j, add_le_add' (hf $ le_sup_left) (hg $ le_sup_right)⟩ lemma finset_sum_supr_nat {α} {ι} [semilattice_sup ι] {s : finset α} {f : α → ι → ennreal} (hf : ∀a, monotone (f a)) : s.sum (λa, supr (f a)) = (⨆ n, s.sum (λa, f a n)) := begin refine finset.induction_on s _ _, { simp, exact (bot_unique $ supr_le $ assume i, le_refl ⊥).symm }, { assume a s has ih, simp only [finset.sum_insert has], rw [ih, supr_add_supr_of_monotone (hf a)], assume i j h, exact (finset.sum_le_sum $ assume a ha, hf a h) } end section priority -- for some reason the next proof fails without changing the priority of this instance local attribute [instance, priority 1000] classical.prop_decidable lemma mul_Sup {s : set ennreal} {a : ennreal} : a * Sup s = ⨆i∈s, a * i := begin by_cases hs : ∀x∈s, x = (0:ennreal), { have h₁ : Sup s = 0 := (bot_unique $ Sup_le $ assume a ha, (hs a ha).symm ▸ le_refl 0), have h₂ : (⨆i ∈ s, a * i) = 0 := (bot_unique $ supr_le $ assume a, supr_le $ assume ha, by simp [hs a ha]), rw [h₁, h₂, mul_zero] }, { simp only [not_forall] at hs, rcases hs with ⟨x, hx, hx0⟩, have s₁ : Sup s ≠ 0 := zero_lt_iff_ne_zero.1 (lt_of_lt_of_le (zero_lt_iff_ne_zero.2 hx0) (le_Sup hx)), have : Sup ((λb, a * b) '' s) = a * Sup s := is_lub.Sup_eq (is_lub_of_is_lub_of_tendsto (assume x _ y _ h, canonically_ordered_semiring.mul_le_mul (le_refl _) h) (is_lub_Sup _) ⟨x, hx⟩ (ennreal.tendsto.const_mul (tendsto_id' inf_le_left) (or.inl s₁))), rw [this.symm, Sup_image] } end end priority lemma mul_supr {ι : Sort*} {f : ι → ennreal} {a : ennreal} : a * supr f = ⨆i, a * f i := by rw [← Sup_range, mul_Sup, supr_range] lemma supr_mul {ι : Sort*} {f : ι → ennreal} {a : ennreal} : supr f * a = ⨆i, f i * a := by rw [mul_comm, mul_supr]; congr; funext; rw [mul_comm] protected lemma tendsto_coe_sub : ∀{b:ennreal}, tendsto (λb:ennreal, ↑r - b) (𝓝 b) (𝓝 (↑r - b)) := begin refine (forall_ennreal.2 $ and.intro (assume a, _) _), { simp [@nhds_coe a, tendsto_map'_iff, (∘), tendsto_coe, coe_sub.symm], exact nnreal.tendsto.sub tendsto_const_nhds tendsto_id }, simp, exact (tendsto.congr' (mem_sets_of_superset (lt_mem_nhds $ @coe_lt_top r) $ by simp [le_of_lt] {contextual := tt})) tendsto_const_nhds end lemma sub_supr {ι : Sort*} [hι : nonempty ι] {b : ι → ennreal} (hr : a < ⊤) : a - (⨆i, b i) = (⨅i, a - b i) := let ⟨i⟩ := hι in let ⟨r, eq, _⟩ := lt_iff_exists_coe.mp hr in have Inf ((λb, ↑r - b) '' range b) = ↑r - (⨆i, b i), from is_glb.Inf_eq $ is_glb_of_is_lub_of_tendsto (assume x _ y _, sub_le_sub (le_refl _)) is_lub_supr ⟨_, i, rfl⟩ (tendsto.comp ennreal.tendsto_coe_sub (tendsto_id' inf_le_left)), by rw [eq, ←this]; simp [Inf_image, infi_range, -mem_range]; exact le_refl _ end topological_space section tsum variables {f g : α → ennreal} @[norm_cast] protected lemma has_sum_coe {f : α → nnreal} {r : nnreal} : has_sum (λa, (f a : ennreal)) ↑r ↔ has_sum f r := have (λs:finset α, s.sum (coe ∘ f)) = (coe : nnreal → ennreal) ∘ (λs:finset α, s.sum f), from funext $ assume s, ennreal.coe_finset_sum.symm, by unfold has_sum; rw [this, tendsto_coe] protected lemma tsum_coe_eq {f : α → nnreal} (h : has_sum f r) : (∑'a, (f a : ennreal)) = r := tsum_eq_has_sum $ ennreal.has_sum_coe.2 $ h protected lemma coe_tsum {f : α → nnreal} : summable f → ↑(tsum f) = (∑'a, (f a : ennreal)) | ⟨r, hr⟩ := by rw [tsum_eq_has_sum hr, ennreal.tsum_coe_eq hr] protected lemma has_sum : has_sum f (⨆s:finset α, s.sum f) := tendsto_order.2 ⟨assume a' ha', let ⟨s, hs⟩ := lt_supr_iff.mp ha' in mem_at_top_sets.mpr ⟨s, assume t ht, lt_of_lt_of_le hs $ finset.sum_le_sum_of_subset ht⟩, assume a' ha', univ_mem_sets' $ assume s, have s.sum f ≤ ⨆(s : finset α), s.sum f, from le_supr (λ(s : finset α), s.sum f) s, lt_of_le_of_lt this ha'⟩ @[simp] protected lemma summable : summable f := ⟨_, ennreal.has_sum⟩ lemma tsum_coe_ne_top_iff_summable {f : β → nnreal} : (∑' b, (f b:ennreal)) ≠ ∞ ↔ summable f := begin refine ⟨λ h, _, λ h, ennreal.coe_tsum h ▸ ennreal.coe_ne_top⟩, lift (∑' b, (f b:ennreal)) to nnreal using h with a ha, refine ⟨a, ennreal.has_sum_coe.1 _⟩, rw ha, exact ennreal.summable.has_sum end protected lemma tsum_eq_supr_sum : (∑'a, f a) = (⨆s:finset α, s.sum f) := tsum_eq_has_sum ennreal.has_sum protected lemma tsum_eq_supr_sum' {ι : Type*} (s : ι → finset α) (hs : ∀ t, ∃ i, t ⊆ s i) : (∑' a, f a) = ⨆ i, (s i).sum f := begin rw [ennreal.tsum_eq_supr_sum], symmetry, change (⨆i:ι, (λ t : finset α, t.sum f) (s i)) = ⨆s:finset α, s.sum f, exact (finset.sum_mono_set f).supr_comp_eq hs end protected lemma tsum_sigma {β : α → Type*} (f : Πa, β a → ennreal) : (∑'p:Σa, β a, f p.1 p.2) = (∑'a b, f a b) := tsum_sigma (assume b, ennreal.summable) ennreal.summable protected lemma tsum_sigma' {β : α → Type*} (f : (Σ a, β a) → ennreal) : (∑'p:(Σa, β a), f p) = (∑'a b, f ⟨a, b⟩) := tsum_sigma (assume b, ennreal.summable) ennreal.summable protected lemma tsum_prod {f : α → β → ennreal} : (∑'p:α×β, f p.1 p.2) = (∑'a, ∑'b, f a b) := let j : α × β → (Σa:α, β) := λp, sigma.mk p.1 p.2 in let i : (Σa:α, β) → α × β := λp, (p.1, p.2) in let f' : (Σa:α, β) → ennreal := λp, f p.1 p.2 in calc (∑'p:α×β, f' (j p)) = (∑'p:Σa:α, β, f p.1 p.2) : tsum_eq_tsum_of_iso j i (assume ⟨a, b⟩, rfl) (assume ⟨a, b⟩, rfl) ... = (∑'a, ∑'b, f a b) : ennreal.tsum_sigma f protected lemma tsum_comm {f : α → β → ennreal} : (∑'a, ∑'b, f a b) = (∑'b, ∑'a, f a b) := let f' : α×β → ennreal := λp, f p.1 p.2 in calc (∑'a, ∑'b, f a b) = (∑'p:α×β, f' p) : ennreal.tsum_prod.symm ... = (∑'p:β×α, f' (prod.swap p)) : (tsum_eq_tsum_of_iso prod.swap (@prod.swap α β) (assume ⟨a, b⟩, rfl) (assume ⟨a, b⟩, rfl)).symm ... = (∑'b, ∑'a, f' (prod.swap (b, a))) : @ennreal.tsum_prod β α (λb a, f' (prod.swap (b, a))) protected lemma tsum_add : (∑'a, f a + g a) = (∑'a, f a) + (∑'a, g a) := tsum_add ennreal.summable ennreal.summable protected lemma tsum_le_tsum (h : ∀a, f a ≤ g a) : (∑'a, f a) ≤ (∑'a, g a) := tsum_le_tsum h ennreal.summable ennreal.summable protected lemma tsum_eq_supr_nat {f : ℕ → ennreal} : (∑'i:ℕ, f i) = (⨆i:ℕ, (finset.range i).sum f) := ennreal.tsum_eq_supr_sum' _ finset.exists_nat_subset_range protected lemma le_tsum (a : α) : f a ≤ (∑'a, f a) := calc f a = ({a} : finset α).sum f : by simp ... ≤ (⨆s:finset α, s.sum f) : le_supr (λs:finset α, s.sum f) _ ... = (∑'a, f a) : by rw [ennreal.tsum_eq_supr_sum] protected lemma tsum_eq_top_of_eq_top : (∃ a, f a = ∞) → (∑' a, f a) = ∞ | ⟨a, ha⟩ := top_unique $ ha ▸ ennreal.le_tsum a protected lemma ne_top_of_tsum_ne_top (h : (∑' a, f a) ≠ ∞) (a : α) : f a ≠ ∞ := λ ha, h $ ennreal.tsum_eq_top_of_eq_top ⟨a, ha⟩ protected lemma tsum_mul_left : (∑'i, a * f i) = a * (∑'i, f i) := if h : ∀i, f i = 0 then by simp [h] else let ⟨i, (hi : f i ≠ 0)⟩ := classical.not_forall.mp h in have sum_ne_0 : (∑'i, f i) ≠ 0, from ne_of_gt $ calc 0 < f i : lt_of_le_of_ne (zero_le _) hi.symm ... ≤ (∑'i, f i) : ennreal.le_tsum _, have tendsto (λs:finset α, s.sum ((*) a ∘ f)) at_top (𝓝 (a * (∑'i, f i))), by rw [← show (*) a ∘ (λs:finset α, s.sum f) = λs, s.sum ((*) a ∘ f), from funext $ λ s, finset.mul_sum]; exact ennreal.tendsto.const_mul ennreal.summable.has_sum (or.inl sum_ne_0), tsum_eq_has_sum this protected lemma tsum_mul_right : (∑'i, f i * a) = (∑'i, f i) * a := by simp [mul_comm, ennreal.tsum_mul_left] @[simp] lemma tsum_supr_eq {α : Type*} (a : α) {f : α → ennreal} : (∑'b:α, ⨆ (h : a = b), f b) = f a := le_antisymm (by rw [ennreal.tsum_eq_supr_sum]; exact supr_le (assume s, calc s.sum (λb, ⨆ (h : a = b), f b) ≤ (finset.singleton a).sum (λb, ⨆ (h : a = b), f b) : finset.sum_le_sum_of_ne_zero $ assume b _ hb, suffices a = b, by simpa using this.symm, classical.by_contradiction $ assume h, by simpa [h] using hb ... = f a : by simp)) (calc f a ≤ (⨆ (h : a = a), f a) : le_supr (λh:a=a, f a) rfl ... ≤ (∑'b:α, ⨆ (h : a = b), f b) : ennreal.le_tsum _) lemma has_sum_iff_tendsto_nat {f : ℕ → ennreal} (r : ennreal) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (𝓝 r) := begin refine ⟨has_sum.tendsto_sum_nat, assume h, _⟩, rw [← supr_eq_of_tendsto _ h, ← ennreal.tsum_eq_supr_nat], { exact ennreal.summable.has_sum }, { exact assume s t hst, finset.sum_le_sum_of_subset (finset.range_subset.2 hst) } end end tsum end ennreal namespace nnreal lemma exists_le_has_sum_of_le {f g : β → nnreal} {r : nnreal} (hgf : ∀b, g b ≤ f b) (hfr : has_sum f r) : ∃p≤r, has_sum g p := have (∑'b, (g b : ennreal)) ≤ r, begin refine has_sum_le (assume b, _) ennreal.summable.has_sum (ennreal.has_sum_coe.2 hfr), exact ennreal.coe_le_coe.2 (hgf _) end, let ⟨p, eq, hpr⟩ := ennreal.le_coe_iff.1 this in ⟨p, hpr, ennreal.has_sum_coe.1 $ eq ▸ ennreal.summable.has_sum⟩ lemma summable_of_le {f g : β → nnreal} (hgf : ∀b, g b ≤ f b) : summable f → summable g | ⟨r, hfr⟩ := let ⟨p, _, hp⟩ := exists_le_has_sum_of_le hgf hfr in hp.summable lemma has_sum_iff_tendsto_nat {f : ℕ → nnreal} (r : nnreal) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (𝓝 r) := begin rw [← ennreal.has_sum_coe, ennreal.has_sum_iff_tendsto_nat], simp only [ennreal.coe_finset_sum.symm], exact ennreal.tendsto_coe end lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → nnreal} (hf : summable f) {i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f := tsum_le_tsum_of_inj i hi (λ c hc, zero_le _) (λ b, le_refl _) (summable_comp_injective hf hi) hf end nnreal lemma tsum_comp_le_tsum_of_inj {β : Type*} {f : α → ℝ} (hf : summable f) (hn : ∀ a, 0 ≤ f a) {i : β → α} (hi : function.injective i) : tsum (f ∘ i) ≤ tsum f := begin let g : α → nnreal := λ a, ⟨f a, hn a⟩, have hg : summable g, by rwa ← nnreal.summable_coe, convert nnreal.coe_le_coe.2 (nnreal.tsum_comp_le_tsum_of_inj hg hi); { rw nnreal.coe_tsum, congr } end lemma summable_of_nonneg_of_le {f g : β → ℝ} (hg : ∀b, 0 ≤ g b) (hgf : ∀b, g b ≤ f b) (hf : summable f) : summable g := let f' (b : β) : nnreal := ⟨f b, le_trans (hg b) (hgf b)⟩ in let g' (b : β) : nnreal := ⟨g b, hg b⟩ in have summable f', from nnreal.summable_coe.1 hf, have summable g', from nnreal.summable_of_le (assume b, (@nnreal.coe_le_coe (g' b) (f' b)).2 $ hgf b) this, show summable (λb, g' b : β → ℝ), from nnreal.summable_coe.2 this lemma has_sum_iff_tendsto_nat_of_nonneg {f : ℕ → ℝ} (hf : ∀i, 0 ≤ f i) (r : ℝ) : has_sum f r ↔ tendsto (λn:ℕ, (finset.range n).sum f) at_top (𝓝 r) := ⟨has_sum.tendsto_sum_nat, assume hfr, have 0 ≤ r := ge_of_tendsto at_top_ne_bot hfr $ univ_mem_sets' $ assume i, show 0 ≤ (finset.range i).sum f, from finset.sum_nonneg $ assume i _, hf i, let f' (n : ℕ) : nnreal := ⟨f n, hf n⟩, r' : nnreal := ⟨r, this⟩ in have f_eq : f = (λi:ℕ, (f' i : ℝ)) := rfl, have r_eq : r = r' := rfl, begin rw [f_eq, r_eq, nnreal.has_sum_coe, nnreal.has_sum_iff_tendsto_nat, ← nnreal.tendsto_coe], simp only [nnreal.coe_sum], exact hfr end⟩ lemma infi_real_pos_eq_infi_nnreal_pos {α : Type*} [complete_lattice α] {f : ℝ → α} : (⨅(n:ℝ) (h : n > 0), f n) = (⨅(n:nnreal) (h : n > 0), f n) := le_antisymm (le_infi $ assume n, le_infi $ assume hn, infi_le_of_le n $ infi_le _ (nnreal.coe_pos.2 hn)) (le_infi $ assume r, le_infi $ assume hr, infi_le_of_le ⟨r, le_of_lt hr⟩ $ infi_le _ hr) section variables [emetric_space β] open ennreal filter emetric /-- In an emetric ball, the distance between points is everywhere finite -/ lemma edist_ne_top_of_mem_ball {a : β} {r : ennreal} (x y : ball a r) : edist x.1 y.1 ≠ ⊤ := lt_top_iff_ne_top.1 $ calc edist x y ≤ edist a x + edist a y : edist_triangle_left x.1 y.1 a ... < r + r : by rw [edist_comm a x, edist_comm a y]; exact add_lt_add x.2 y.2 ... ≤ ⊤ : le_top /-- Each ball in an extended metric space gives us a metric space, as the edist is everywhere finite. -/ def metric_space_emetric_ball (a : β) (r : ennreal) : metric_space (ball a r) := emetric_space.to_metric_space edist_ne_top_of_mem_ball local attribute [instance] metric_space_emetric_ball lemma nhds_eq_nhds_emetric_ball (a x : β) (r : ennreal) (h : x ∈ ball a r) : 𝓝 x = map (coe : ball a r → β) (𝓝 ⟨x, h⟩) := (map_nhds_subtype_val_eq _ $ mem_nhds_sets emetric.is_open_ball h).symm end section variable [emetric_space α] open emetric lemma tendsto_iff_edist_tendsto_0 {l : filter β} {f : β → α} {y : α} : tendsto f l (𝓝 y) ↔ tendsto (λ x, edist (f x) y) l (𝓝 0) := by simp only [emetric.nhds_basis_eball.tendsto_right_iff, emetric.mem_ball, @tendsto_order ennreal β _ _, forall_prop_of_false ennreal.not_lt_zero, forall_const, true_and] /-- Yet another metric characterization of Cauchy sequences on integers. This one is often the most efficient. -/ lemma emetric.cauchy_seq_iff_le_tendsto_0 [nonempty β] [semilattice_sup β] {s : β → α} : cauchy_seq s ↔ (∃ (b: β → ennreal), (∀ n m N : β, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N) ∧ (tendsto b at_top (𝓝 0))) := ⟨begin assume hs, rw emetric.cauchy_seq_iff at hs, /- `s` is Cauchy sequence. The sequence `b` will be constructed by taking the supremum of the distances between `s n` and `s m` for `n m ≥ N`-/ let b := λN, Sup ((λ(p : β × β), edist (s p.1) (s p.2))''{p | p.1 ≥ N ∧ p.2 ≥ N}), --Prove that it bounds the distances of points in the Cauchy sequence have C : ∀ n m N, N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, { refine λm n N hm hn, le_Sup _, use (prod.mk m n), simp only [and_true, eq_self_iff_true, set.mem_set_of_eq], exact ⟨hm, hn⟩ }, --Prove that it tends to `0`, by using the Cauchy property of `s` have D : tendsto b at_top (𝓝 0), { refine tendsto_order.2 ⟨λa ha, absurd ha (ennreal.not_lt_zero), λε εpos, _⟩, rcases dense εpos with ⟨δ, δpos, δlt⟩, rcases hs δ δpos with ⟨N, hN⟩, refine filter.mem_at_top_sets.2 ⟨N, λn hn, _⟩, have : b n ≤ δ := Sup_le begin simp only [and_imp, set.mem_image, set.mem_set_of_eq, exists_imp_distrib, prod.exists], intros d p q hp hq hd, rw ← hd, exact le_of_lt (hN p q (le_trans hn hp) (le_trans hn hq)) end, simpa using lt_of_le_of_lt this δlt }, -- Conclude exact ⟨b, ⟨C, D⟩⟩ end, begin rintros ⟨b, ⟨b_bound, b_lim⟩⟩, /-b : ℕ → ℝ, b_bound : ∀ (n m N : ℕ), N ≤ n → N ≤ m → edist (s n) (s m) ≤ b N, b_lim : tendsto b at_top (𝓝 0)-/ refine emetric.cauchy_seq_iff.2 (λε εpos, _), have : ∀ᶠ n in at_top, b n < ε := (tendsto_order.1 b_lim ).2 _ εpos, rcases filter.mem_at_top_sets.1 this with ⟨N, hN⟩, exact ⟨N, λm n hm hn, calc edist (s m) (s n) ≤ b N : b_bound m n N hm hn ... < ε : (hN _ (le_refl N)) ⟩ end⟩ lemma continuous_of_le_add_edist {f : α → ennreal} (C : ennreal) (hC : C ≠ ⊤) (h : ∀x y, f x ≤ f y + C * edist x y) : continuous f := begin refine continuous_iff_continuous_at.2 (λx, tendsto_order.2 ⟨_, _⟩), show ∀e, e < f x → ∀ᶠ y in 𝓝 x, e < f y, { assume e he, let ε := min (f x - e) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, hC, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, { simp [C_zero, ‹0 < ε›] }, { calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 ‹0 < ε›) (lt_top_iff_ne_top.1 ‹ε < ⊤›) }}, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | e < f y}, { rintros y hy, by_cases htop : f y = ⊤, { simp [htop, lt_top_iff_ne_top, ne_top_of_lt he] }, { simp at hy, have : e + ε < f y + ε := calc e + ε ≤ e + (f x - e) : add_le_add_left' (min_le_left _ _) ... = f x : by simp [le_of_lt he] ... ≤ f y + C * edist x y : h x y ... = f y + C * edist y x : by simp [edist_comm] ... ≤ f y + C * (C⁻¹ * (ε/2)) : add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy) ... < f y + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I, show e < f y, from (ennreal.add_lt_add_iff_right ‹ε < ⊤›).1 this }}, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, show ∀e, f x < e → ∀ᶠ y in 𝓝 x, f y < e, { assume e he, let ε := min (e - f x) 1, have : ε < ⊤ := lt_of_le_of_lt (min_le_right _ _) (by simp [lt_top_iff_ne_top]), have : 0 < ε := by simp [ε, he, ennreal.zero_lt_one], have : 0 < C⁻¹ * (ε/2) := bot_lt_iff_ne_bot.2 (by simp [hC, (ne_of_lt this).symm, ennreal.mul_eq_zero]), have I : C * (C⁻¹ * (ε/2)) < ε, { by_cases C_zero : C = 0, simp [C_zero, ‹0 < ε›], calc C * (C⁻¹ * (ε/2)) = (C * C⁻¹) * (ε/2) : by simp [mul_assoc] ... = ε/2 : by simp [ennreal.mul_inv_cancel C_zero hC] ... < ε : ennreal.half_lt_self (bot_lt_iff_ne_bot.1 ‹0 < ε›) (lt_top_iff_ne_top.1 ‹ε < ⊤›) }, have : ball x (C⁻¹ * (ε/2)) ⊆ {y : α | f y < e}, { rintros y hy, have htop : f x ≠ ⊤ := ne_top_of_lt he, show f y < e, from calc f y ≤ f x + C * edist y x : h y x ... ≤ f x + C * (C⁻¹ * (ε/2)) : add_le_add_left' $ canonically_ordered_semiring.mul_le_mul (le_refl _) (le_of_lt hy) ... < f x + ε : (ennreal.add_lt_add_iff_left (lt_top_iff_ne_top.2 htop)).2 I ... ≤ f x + (e - f x) : add_le_add_left' (min_le_left _ _) ... = e : by simp [le_of_lt he] }, apply filter.mem_sets_of_superset (ball_mem_nhds _ (‹0 < C⁻¹ * (ε/2)›)) this }, end theorem continuous_edist : continuous (λp:α×α, edist p.1 p.2) := begin apply continuous_of_le_add_edist 2 (by simp), rintros ⟨x, y⟩ ⟨x', y'⟩, calc edist x y ≤ edist x x' + edist x' y' + edist y' y : edist_triangle4 _ _ _ _ ... = edist x' y' + (edist x x' + edist y y') : by simp [edist_comm]; cc ... ≤ edist x' y' + (edist (x, y) (x', y') + edist (x, y) (x', y')) : add_le_add_left' (add_le_add' (by simp [edist, le_refl]) (by simp [edist, le_refl])) ... = edist x' y' + 2 * edist (x, y) (x', y') : by rw [← mul_two, mul_comm] end theorem continuous.edist [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : continuous (λb, edist (f b) (g b)) := continuous_edist.comp (hf.prod_mk hg) theorem filter.tendsto.edist {f g : β → α} {x : filter β} {a b : α} (hf : tendsto f x (𝓝 a)) (hg : tendsto g x (𝓝 b)) : tendsto (λx, edist (f x) (g x)) x (𝓝 (edist a b)) := (continuous_edist.tendsto (a, b)).comp (hf.prod_mk_nhds hg) lemma cauchy_seq_of_edist_le_of_tsum_ne_top {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : tsum d ≠ ∞) : cauchy_seq f := begin lift d to (ℕ → nnreal) using (λ i, ennreal.ne_top_of_tsum_ne_top hd i), rw ennreal.tsum_coe_ne_top_iff_summable at hd, exact cauchy_seq_of_edist_le_of_summable d hf hd end /-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`, then the distance from `f n` to the limit is bounded by `∑'_{k=n}^∞ d k`. -/ lemma edist_le_tsum_of_edist_le_of_tendsto {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) : edist (f n) a ≤ ∑' m, d (n + m) := begin refine le_of_tendsto at_top_ne_bot (tendsto_const_nhds.edist ha) (mem_at_top_sets.2 ⟨n, λ m hnm, _⟩), refine le_trans (edist_le_Ico_sum_of_edist_le hnm (λ k _ _, hf k)) _, rw [finset.sum_Ico_eq_sum_range], exact sum_le_tsum _ (λ _ _, zero_le _) ennreal.summable end /-- If `edist (f n) (f (n+1))` is bounded above by a function `d : ℕ → ennreal`, then the distance from `f 0` to the limit is bounded by `∑'_{k=0}^∞ d k`. -/ lemma edist_le_tsum_of_edist_le_of_tendsto₀ {f : ℕ → α} (d : ℕ → ennreal) (hf : ∀ n, edist (f n) (f n.succ) ≤ d n) {a : α} (ha : tendsto f at_top (𝓝 a)) : edist (f 0) a ≤ ∑' m, d m := by simpa using edist_le_tsum_of_edist_le_of_tendsto d hf ha 0 end --section
ef0c51086f919a5e86e34c8434af55670052d83e
a45212b1526d532e6e83c44ddca6a05795113ddc
/src/topology/basic.lean
a98595f551aca22f4e26582e6f6b26ecdd84ddb7
[ "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
35,248
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro Theory of topological spaces. Parts of the formalization is based on the books: N. Bourbaki: General Topology I. M. James: Topologies and Uniformities A major difference is that this formalization is heavily based on the filter library. -/ import order.filter open set filter lattice classical local attribute [instance] prop_decidable universes u v w structure topological_space (α : Type u) := (is_open : set α → Prop) (is_open_univ : is_open univ) (is_open_inter : ∀s t, is_open s → is_open t → is_open (s ∩ t)) (is_open_sUnion : ∀s, (∀t∈s, is_open t) → is_open (⋃₀ s)) attribute [class] topological_space section topological_space variables {α : Type u} {β : Type v} {ι : Sort w} {a : α} {s s₁ s₂ : set α} {p p₁ p₂ : α → Prop} @[extensionality] lemma topological_space_eq : ∀ {f g : topological_space α}, f.is_open = g.is_open → f = g | ⟨a, _, _, _⟩ ⟨b, _, _, _⟩ rfl := rfl section variables [t : topological_space α] include t /-- `is_open s` means that `s` is open in the ambient topological space on `α` -/ def is_open (s : set α) : Prop := topological_space.is_open t s @[simp] lemma is_open_univ : is_open (univ : set α) := topological_space.is_open_univ t lemma is_open_inter (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∩ s₂) := topological_space.is_open_inter t s₁ s₂ h₁ h₂ lemma is_open_sUnion {s : set (set α)} (h : ∀t ∈ s, is_open t) : is_open (⋃₀ s) := topological_space.is_open_sUnion t s h end lemma is_open_fold {s : set α} {t : topological_space α} : t.is_open s = @is_open α t s := rfl variables [topological_space α] lemma is_open_Union {f : ι → set α} (h : ∀i, is_open (f i)) : is_open (⋃i, f i) := is_open_sUnion $ by rintro _ ⟨i, rfl⟩; exact h i lemma is_open_bUnion {s : set β} {f : β → set α} (h : ∀i∈s, is_open (f i)) : is_open (⋃i∈s, f i) := is_open_Union $ assume i, is_open_Union $ assume hi, h i hi lemma is_open_union (h₁ : is_open s₁) (h₂ : is_open s₂) : is_open (s₁ ∪ s₂) := by rw union_eq_Union; exact is_open_Union (bool.forall_bool.2 ⟨h₂, h₁⟩) @[simp] lemma is_open_empty : is_open (∅ : set α) := by rw ← sUnion_empty; exact is_open_sUnion (assume a, false.elim) lemma is_open_sInter {s : set (set α)} (hs : finite s) : (∀t ∈ s, is_open t) → is_open (⋂₀ s) := finite.induction_on hs (λ _, by rw sInter_empty; exact is_open_univ) $ λ a s has hs ih h, by rw sInter_insert; exact is_open_inter (h _ $ mem_insert _ _) (ih $ λ t, h t ∘ mem_insert_of_mem _) lemma is_open_bInter {s : set β} {f : β → set α} (hs : finite s) : (∀i∈s, is_open (f i)) → is_open (⋂i∈s, f i) := finite.induction_on hs (λ _, by rw bInter_empty; exact is_open_univ) (λ a s has hs ih h, by rw bInter_insert; exact is_open_inter (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi)))) lemma is_open_const {p : Prop} : is_open {a : α | p} := by_cases (assume : p, begin simp only [this]; exact is_open_univ end) (assume : ¬ p, begin simp only [this]; exact is_open_empty end) lemma is_open_and : is_open {a | p₁ a} → is_open {a | p₂ a} → is_open {a | p₁ a ∧ p₂ a} := is_open_inter /-- A set is closed if its complement is open -/ def is_closed (s : set α) : Prop := is_open (-s) @[simp] lemma is_closed_empty : is_closed (∅ : set α) := by unfold is_closed; rw compl_empty; exact is_open_univ @[simp] lemma is_closed_univ : is_closed (univ : set α) := by unfold is_closed; rw compl_univ; exact is_open_empty lemma is_closed_union : is_closed s₁ → is_closed s₂ → is_closed (s₁ ∪ s₂) := λ h₁ h₂, by unfold is_closed; rw compl_union; exact is_open_inter h₁ h₂ lemma is_closed_sInter {s : set (set α)} : (∀t ∈ s, is_closed t) → is_closed (⋂₀ s) := by simp only [is_closed, compl_sInter, sUnion_image]; exact assume h, is_open_Union $ assume t, is_open_Union $ assume ht, h t ht lemma is_closed_Inter {f : ι → set α} (h : ∀i, is_closed (f i)) : is_closed (⋂i, f i ) := is_closed_sInter $ assume t ⟨i, (heq : f i = t)⟩, heq ▸ h i @[simp] lemma is_open_compl_iff {s : set α} : is_open (-s) ↔ is_closed s := iff.rfl @[simp] lemma is_closed_compl_iff {s : set α} : is_closed (-s) ↔ is_open s := by rw [←is_open_compl_iff, compl_compl] lemma is_open_diff {s t : set α} (h₁ : is_open s) (h₂ : is_closed t) : is_open (s \ t) := is_open_inter h₁ $ is_open_compl_iff.mpr h₂ lemma is_closed_inter (h₁ : is_closed s₁) (h₂ : is_closed s₂) : is_closed (s₁ ∩ s₂) := by rw [is_closed, compl_inter]; exact is_open_union h₁ h₂ lemma is_closed_Union {s : set β} {f : β → set α} (hs : finite s) : (∀i∈s, is_closed (f i)) → is_closed (⋃i∈s, f i) := finite.induction_on hs (λ _, by rw bUnion_empty; exact is_closed_empty) (λ a s has hs ih h, by rw bUnion_insert; exact is_closed_union (h a (mem_insert _ _)) (ih (λ i hi, h i (mem_insert_of_mem _ hi)))) lemma is_closed_imp {p q : α → Prop} (hp : is_open {x | p x}) (hq : is_closed {x | q x}) : is_closed {x | p x → q x} := have {x | p x → q x} = (- {x | p x}) ∪ {x | q x}, from set.ext $ λ x, imp_iff_not_or, by rw [this]; exact is_closed_union (is_closed_compl_iff.mpr hp) hq lemma is_open_neg : is_closed {a | p a} → is_open {a | ¬ p a} := is_open_compl_iff.mpr /-- The interior of a set `s` is the largest open subset of `s`. -/ def interior (s : set α) : set α := ⋃₀ {t | is_open t ∧ t ⊆ s} lemma mem_interior {s : set α} {x : α} : x ∈ interior s ↔ ∃ t ⊆ s, is_open t ∧ x ∈ t := by simp only [interior, mem_set_of_eq, exists_prop, and_assoc, and.left_comm] @[simp] lemma is_open_interior {s : set α} : is_open (interior s) := is_open_sUnion $ assume t ⟨h₁, h₂⟩, h₁ lemma interior_subset {s : set α} : interior s ⊆ s := sUnion_subset $ assume t ⟨h₁, h₂⟩, h₂ lemma interior_maximal {s t : set α} (h₁ : t ⊆ s) (h₂ : is_open t) : t ⊆ interior s := subset_sUnion_of_mem ⟨h₂, h₁⟩ lemma interior_eq_of_open {s : set α} (h : is_open s) : interior s = s := subset.antisymm interior_subset (interior_maximal (subset.refl s) h) lemma interior_eq_iff_open {s : set α} : interior s = s ↔ is_open s := ⟨assume h, h ▸ is_open_interior, interior_eq_of_open⟩ lemma subset_interior_iff_open {s : set α} : s ⊆ interior s ↔ is_open s := by simp only [interior_eq_iff_open.symm, subset.antisymm_iff, interior_subset, true_and] lemma subset_interior_iff_subset_of_open {s t : set α} (h₁ : is_open s) : s ⊆ interior t ↔ s ⊆ t := ⟨assume h, subset.trans h interior_subset, assume h₂, interior_maximal h₂ h₁⟩ lemma interior_mono {s t : set α} (h : s ⊆ t) : interior s ⊆ interior t := interior_maximal (subset.trans interior_subset h) is_open_interior @[simp] lemma interior_empty : interior (∅ : set α) = ∅ := interior_eq_of_open is_open_empty @[simp] lemma interior_univ : interior (univ : set α) = univ := interior_eq_of_open is_open_univ @[simp] lemma interior_interior {s : set α} : interior (interior s) = interior s := interior_eq_of_open is_open_interior @[simp] lemma interior_inter {s t : set α} : interior (s ∩ t) = interior s ∩ interior t := subset.antisymm (subset_inter (interior_mono $ inter_subset_left s t) (interior_mono $ inter_subset_right s t)) (interior_maximal (inter_subset_inter interior_subset interior_subset) $ is_open_inter is_open_interior is_open_interior) lemma interior_union_is_closed_of_interior_empty {s t : set α} (h₁ : is_closed s) (h₂ : interior t = ∅) : interior (s ∪ t) = interior s := have interior (s ∪ t) ⊆ s, from assume x ⟨u, ⟨(hu₁ : is_open u), (hu₂ : u ⊆ s ∪ t)⟩, (hx₁ : x ∈ u)⟩, classical.by_contradiction $ assume hx₂ : x ∉ s, have u \ s ⊆ t, from assume x ⟨h₁, h₂⟩, or.resolve_left (hu₂ h₁) h₂, have u \ s ⊆ interior t, by rwa subset_interior_iff_subset_of_open (is_open_diff hu₁ h₁), have u \ s ⊆ ∅, by rwa h₂ at this, this ⟨hx₁, hx₂⟩, subset.antisymm (interior_maximal this is_open_interior) (interior_mono $ subset_union_left _ _) lemma is_open_iff_forall_mem_open : is_open s ↔ ∀ x ∈ s, ∃ t ⊆ s, is_open t ∧ x ∈ t := by rw ← subset_interior_iff_open; simp only [subset_def, mem_interior] /-- The closure of `s` is the smallest closed set containing `s`. -/ def closure (s : set α) : set α := ⋂₀ {t | is_closed t ∧ s ⊆ t} @[simp] lemma is_closed_closure {s : set α} : is_closed (closure s) := is_closed_sInter $ assume t ⟨h₁, h₂⟩, h₁ lemma subset_closure {s : set α} : s ⊆ closure s := subset_sInter $ assume t ⟨h₁, h₂⟩, h₂ lemma closure_minimal {s t : set α} (h₁ : s ⊆ t) (h₂ : is_closed t) : closure s ⊆ t := sInter_subset_of_mem ⟨h₂, h₁⟩ lemma closure_eq_of_is_closed {s : set α} (h : is_closed s) : closure s = s := subset.antisymm (closure_minimal (subset.refl s) h) subset_closure lemma closure_eq_iff_is_closed {s : set α} : closure s = s ↔ is_closed s := ⟨assume h, h ▸ is_closed_closure, closure_eq_of_is_closed⟩ lemma closure_subset_iff_subset_of_is_closed {s t : set α} (h₁ : is_closed t) : closure s ⊆ t ↔ s ⊆ t := ⟨subset.trans subset_closure, assume h, closure_minimal h h₁⟩ lemma closure_mono {s t : set α} (h : s ⊆ t) : closure s ⊆ closure t := closure_minimal (subset.trans h subset_closure) is_closed_closure lemma is_closed_of_closure_subset {s : set α} (h : closure s ⊆ s) : is_closed s := by rw subset.antisymm subset_closure h; exact is_closed_closure @[simp] lemma closure_empty : closure (∅ : set α) = ∅ := closure_eq_of_is_closed is_closed_empty lemma closure_empty_iff (s : set α) : closure s = ∅ ↔ s = ∅ := begin split; intro h, { rw set.eq_empty_iff_forall_not_mem, intros x H, simpa only [h] using subset_closure H }, { exact (eq.symm h) ▸ closure_empty }, end @[simp] lemma closure_univ : closure (univ : set α) = univ := closure_eq_of_is_closed is_closed_univ @[simp] lemma closure_closure {s : set α} : closure (closure s) = closure s := closure_eq_of_is_closed is_closed_closure @[simp] lemma closure_union {s t : set α} : closure (s ∪ t) = closure s ∪ closure t := subset.antisymm (closure_minimal (union_subset_union subset_closure subset_closure) $ is_closed_union is_closed_closure is_closed_closure) (union_subset (closure_mono $ subset_union_left _ _) (closure_mono $ subset_union_right _ _)) lemma interior_subset_closure {s : set α} : interior s ⊆ closure s := subset.trans interior_subset subset_closure lemma closure_eq_compl_interior_compl {s : set α} : closure s = - interior (- s) := begin unfold interior closure is_closed, rw [compl_sUnion, compl_image_set_of], simp only [compl_subset_compl] end @[simp] lemma interior_compl {s : set α} : interior (- s) = - closure s := by simp [closure_eq_compl_interior_compl] @[simp] lemma closure_compl {s : set α} : closure (- s) = - interior s := by simp [closure_eq_compl_interior_compl] theorem mem_closure_iff {s : set α} {a : α} : a ∈ closure s ↔ ∀ o, is_open o → a ∈ o → o ∩ s ≠ ∅ := ⟨λ h o oo ao os, have s ⊆ -o, from λ x xs xo, @ne_empty_of_mem α (o∩s) x ⟨xo, xs⟩ os, closure_minimal this (is_closed_compl_iff.2 oo) h ao, λ H c ⟨h₁, h₂⟩, classical.by_contradiction $ λ nc, let ⟨x, hc, hs⟩ := exists_mem_of_ne_empty (H _ h₁ nc) in hc (h₂ hs)⟩ lemma dense_iff_inter_open {s : set α} : closure s = univ ↔ ∀ U, is_open U → U ≠ ∅ → U ∩ s ≠ ∅ := begin split ; intro h, { intros U U_op U_ne, cases exists_mem_of_ne_empty U_ne with x x_in, exact mem_closure_iff.1 (by simp only [h]) U U_op x_in }, { apply eq_univ_of_forall, intro x, rw mem_closure_iff, intros U U_op x_in, exact h U U_op (ne_empty_of_mem x_in) }, end /-- The frontier of a set is the set of points between the closure and interior. -/ def frontier (s : set α) : set α := closure s \ interior s lemma frontier_eq_closure_inter_closure {s : set α} : frontier s = closure s ∩ closure (- s) := by rw [closure_compl, frontier, diff_eq] @[simp] lemma frontier_compl (s : set α) : frontier (-s) = frontier s := by simp only [frontier_eq_closure_inter_closure, lattice.neg_neg, inter_comm] lemma is_closed_frontier {s : set α} : is_closed (frontier s) := by rw frontier_eq_closure_inter_closure; exact is_closed_inter is_closed_closure is_closed_closure lemma interior_frontier {s : set α} (h : is_closed s) : interior (frontier s) = ∅ := begin have A : frontier s = s \ interior s, by rw [frontier, closure_eq_of_is_closed h], have B : interior (frontier s) ⊆ interior s, by rw A; exact interior_mono (diff_subset _ _), have C : interior (frontier s) ⊆ frontier s := interior_subset, have : interior (frontier s) ⊆ (interior s) ∩ (s \ interior s) := subset_inter B (by simpa [A] using C), rwa [inter_diff_self, subset_empty_iff] at this, end /-- neighbourhood filter -/ def nhds (a : α) : filter α := (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal s) lemma nhds_sets {a : α} : (nhds a).sets = {s | ∃t⊆s, is_open t ∧ a ∈ t} := calc (nhds a).sets = (⋃s∈{s : set α| a ∈ s ∧ is_open s}, (principal s).sets) : infi_sets_eq' (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, le_principal_iff.2 (inter_subset_left _ _), le_principal_iff.2 (inter_subset_right _ _)⟩) ⟨univ, mem_univ _, is_open_univ⟩ ... = {s | ∃t⊆s, is_open t ∧ a ∈ t} : le_antisymm (supr_le $ assume i, supr_le $ assume ⟨hi₁, hi₂⟩ t ht, ⟨i, ht, hi₂, hi₁⟩) (assume t ⟨i, hi₁, hi₂, hi₃⟩, mem_Union.2 ⟨i, mem_Union.2 ⟨⟨hi₃, hi₂⟩, hi₁⟩⟩) lemma map_nhds {a : α} {f : α → β} : map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, principal (image f s)) := calc map f (nhds a) = (⨅ s ∈ {s : set α | a ∈ s ∧ is_open s}, map f (principal s)) : map_binfi_eq (assume x ⟨hx₁, hx₂⟩ y ⟨hy₁, hy₂⟩, ⟨x ∩ y, ⟨⟨hx₁, hy₁⟩, is_open_inter hx₂ hy₂⟩, le_principal_iff.2 (inter_subset_left _ _), le_principal_iff.2 (inter_subset_right _ _)⟩) ⟨univ, mem_univ _, is_open_univ⟩ ... = _ : by simp only [map_principal] lemma mem_nhds_sets_iff {a : α} {s : set α} : s ∈ nhds a ↔ ∃t⊆s, is_open t ∧ a ∈ t := by simp only [nhds_sets, mem_set_of_eq, exists_prop] lemma mem_of_nhds {a : α} {s : set α} : s ∈ nhds a → a ∈ s := λ H, let ⟨t, ht, _, hs⟩ := mem_nhds_sets_iff.1 H in ht hs lemma mem_nhds_sets {a : α} {s : set α} (hs : is_open s) (ha : a ∈ s) : s ∈ nhds a := mem_nhds_sets_iff.2 ⟨s, subset.refl _, hs, ha⟩ theorem all_mem_nhds (x : α) (P : set α → Prop) (hP : ∀ s t, s ⊆ t → P s → P t) : (∀ s ∈ nhds x, P s) ↔ (∀ s, is_open s → x ∈ s → P s) := iff.intro (λ h s os xs, h s (mem_nhds_sets os xs)) (λ h t, begin change t ∈ (nhds x).sets → P t, rw nhds_sets, rintros ⟨s, hs, opens, xs⟩, exact hP _ _ hs (h s opens xs), end) theorem all_mem_nhds_filter (x : α) (f : set α → set β) (hf : ∀ s t, s ⊆ t → f s ⊆ f t) (l : filter β) : (∀ s ∈ nhds x, f s ∈ l) ↔ (∀ s, is_open s → x ∈ s → f s ∈ l) := all_mem_nhds _ _ (λ s t ssubt h, mem_sets_of_superset h (hf s t ssubt)) theorem rtendsto_nhds {r : rel β α} {l : filter β} {a : α} : rtendsto r l (nhds a) ↔ (∀ s, is_open s → a ∈ s → r.core s ∈ l) := all_mem_nhds_filter _ _ (λ s t h, λ x hx, λ y hy, h (hx y hy)) _ theorem rtendsto'_nhds {r : rel β α} {l : filter β} {a : α} : rtendsto' r l (nhds a) ↔ (∀ s, is_open s → a ∈ s → r.preimage s ∈ l) := by { rw [rtendsto'_def], apply all_mem_nhds_filter, apply rel.preimage_mono } theorem ptendsto_nhds {f : β →. α} {l : filter β} {a : α} : ptendsto f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f.core s ∈ l) := rtendsto_nhds theorem ptendsto'_nhds {f : β →. α} {l : filter β} {a : α} : ptendsto' f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f.preimage s ∈ l) := rtendsto'_nhds theorem tendsto_nhds {f : β → α} {l : filter β} {a : α} : tendsto f l (nhds a) ↔ (∀ s, is_open s → a ∈ s → f ⁻¹' s ∈ l) := all_mem_nhds_filter _ _ (λ s t h, preimage_mono h) _ lemma tendsto_const_nhds {a : α} {f : filter β} : tendsto (λb:β, a) f (nhds a) := tendsto_nhds.mpr $ assume s hs ha, univ_mem_sets' $ assume _, ha lemma pure_le_nhds : pure ≤ (nhds : α → filter α) := assume a, le_infi $ assume s, le_infi $ assume ⟨h₁, _⟩, principal_mono.mpr $ singleton_subset_iff.2 h₁ lemma tendsto_pure_nhds [topological_space β] (f : α → β) (a : α) : tendsto f (pure a) (nhds (f a)) := begin rw [tendsto, filter.map_pure], exact pure_le_nhds (f a) end @[simp] lemma nhds_neq_bot {a : α} : nhds a ≠ ⊥ := assume : nhds a = ⊥, have pure a = (⊥ : filter α), from lattice.bot_unique $ this ▸ pure_le_nhds a, pure_neq_bot this lemma interior_eq_nhds {s : set α} : interior s = {a | nhds a ≤ principal s} := set.ext $ λ x, by simp only [mem_interior, le_principal_iff, mem_nhds_sets_iff]; refl lemma mem_interior_iff_mem_nhds {s : set α} {a : α} : a ∈ interior s ↔ s ∈ nhds a := by simp only [interior_eq_nhds, le_principal_iff]; refl lemma is_open_iff_nhds {s : set α} : is_open s ↔ ∀a∈s, nhds a ≤ principal s := calc is_open s ↔ s ⊆ interior s : subset_interior_iff_open.symm ... ↔ (∀a∈s, nhds a ≤ principal s) : by rw [interior_eq_nhds]; refl lemma is_open_iff_mem_nhds {s : set α} : is_open s ↔ ∀a∈s, s ∈ nhds a := is_open_iff_nhds.trans $ forall_congr $ λ _, imp_congr_right $ λ _, le_principal_iff lemma closure_eq_nhds {s : set α} : closure s = {a | nhds a ⊓ principal s ≠ ⊥} := calc closure s = - interior (- s) : closure_eq_compl_interior_compl ... = {a | ¬ nhds a ≤ principal (-s)} : by rw [interior_eq_nhds]; refl ... = {a | nhds a ⊓ principal s ≠ ⊥} : set.ext $ assume a, not_congr (inf_eq_bot_iff_le_compl (show principal s ⊔ principal (-s) = ⊤, by simp only [sup_principal, union_compl_self, principal_univ]) (by simp only [inf_principal, inter_compl_self, principal_empty])).symm theorem mem_closure_iff_nhds {s : set α} {a : α} : a ∈ closure s ↔ ∀ t ∈ nhds a, t ∩ s ≠ ∅ := mem_closure_iff.trans ⟨λ H t ht, subset_ne_empty (inter_subset_inter_left _ interior_subset) (H _ is_open_interior (mem_interior_iff_mem_nhds.2 ht)), λ H o oo ao, H _ (mem_nhds_sets oo ao)⟩ /-- `x` belongs to the closure of `s` if and only if some ultrafilter supported on `s` converges to `x`. -/ lemma mem_closure_iff_ultrafilter {s : set α} {x : α} : x ∈ closure s ↔ ∃ (u : ultrafilter α), s ∈ u.val ∧ u.val ≤ nhds x := begin rw closure_eq_nhds, change nhds x ⊓ principal s ≠ ⊥ ↔ _, symmetry, convert exists_ultrafilter_iff _, ext u, rw [←le_principal_iff, inf_comm, le_inf_iff] end lemma is_closed_iff_nhds {s : set α} : is_closed s ↔ ∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s := calc is_closed s ↔ closure s = s : by rw [closure_eq_iff_is_closed] ... ↔ closure s ⊆ s : ⟨assume h, by rw h, assume h, subset.antisymm h subset_closure⟩ ... ↔ (∀a, nhds a ⊓ principal s ≠ ⊥ → a ∈ s) : by rw [closure_eq_nhds]; refl lemma closure_inter_open {s t : set α} (h : is_open s) : s ∩ closure t ⊆ closure (s ∩ t) := assume a ⟨hs, ht⟩, have s ∈ nhds a, from mem_nhds_sets h hs, have nhds a ⊓ principal s = nhds a, from inf_of_le_left $ by rwa le_principal_iff, have nhds a ⊓ principal (s ∩ t) ≠ ⊥, from calc nhds a ⊓ principal (s ∩ t) = nhds a ⊓ (principal s ⊓ principal t) : by rw inf_principal ... = nhds a ⊓ principal t : by rw [←inf_assoc, this] ... ≠ ⊥ : by rw [closure_eq_nhds] at ht; assumption, by rw [closure_eq_nhds]; assumption lemma closure_diff {s t : set α} : closure s - closure t ⊆ closure (s - t) := calc closure s \ closure t = (- closure t) ∩ closure s : by simp only [diff_eq, inter_comm] ... ⊆ closure (- closure t ∩ s) : closure_inter_open $ is_open_compl_iff.mpr $ is_closed_closure ... = closure (s \ closure t) : by simp only [diff_eq, inter_comm] ... ⊆ closure (s \ t) : closure_mono $ diff_subset_diff (subset.refl s) subset_closure lemma mem_of_closed_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α} (hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (hs : is_closed s) (h : f ⁻¹' s ∈ b) : a ∈ s := have b.map f ≤ nhds a ⊓ principal s, from le_trans (le_inf (le_refl _) (le_principal_iff.mpr h)) (inf_le_inf hf (le_refl _)), is_closed_iff_nhds.mp hs a $ neq_bot_of_le_neq_bot (map_ne_bot hb) this lemma mem_of_closed_of_tendsto' {f : β → α} {x : filter β} {a : α} {s : set α} (hf : tendsto f x (nhds a)) (hs : is_closed s) (h : x ⊓ principal (f ⁻¹' s) ≠ ⊥) : a ∈ s := is_closed_iff_nhds.mp hs _ $ neq_bot_of_le_neq_bot (@map_ne_bot _ _ _ f h) $ le_inf (le_trans (map_mono $ inf_le_left) hf) $ le_trans (map_mono $ inf_le_right_of_le $ by simp only [comap_principal, le_principal_iff]; exact subset.refl _) (@map_comap_le _ _ _ f) lemma mem_closure_of_tendsto {f : β → α} {b : filter β} {a : α} {s : set α} (hb : b ≠ ⊥) (hf : tendsto f b (nhds a)) (h : f ⁻¹' s ∈ b) : a ∈ closure s := mem_of_closed_of_tendsto hb hf (is_closed_closure) $ filter.mem_sets_of_superset h (preimage_mono subset_closure) section lim variables [inhabited α] /-- If `f` is a filter, then `lim f` is a limit of the filter, if it exists. -/ noncomputable def lim (f : filter α) : α := epsilon $ λa, f ≤ nhds a lemma lim_spec {f : filter α} (h : ∃a, f ≤ nhds a) : f ≤ nhds (lim f) := epsilon_spec h end lim /- The nhds_within filter. -/ def nhds_within (a : α) (s : set α) : filter α := nhds a ⊓ principal s theorem nhds_within_eq (a : α) (s : set α) : nhds_within a s = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (t ∩ s) := have set.univ ∈ {s : set α | a ∈ s ∧ is_open s}, from ⟨set.mem_univ _, is_open_univ⟩, begin rw [nhds_within, nhds, lattice.binfi_inf]; try { exact this }, simp only [inf_principal] end theorem nhds_within_univ (a : α) : nhds_within a set.univ = nhds a := by rw [nhds_within, principal_univ, lattice.inf_top_eq] theorem mem_nhds_within (t : set α) (a : α) (s : set α) : t ∈ nhds_within a s ↔ ∃ u, is_open u ∧ a ∈ u ∧ u ∩ s ⊆ t := begin rw [nhds_within, mem_inf_principal, mem_nhds_sets_iff], split, { rintros ⟨u, hu, openu, au⟩, exact ⟨u, openu, au, λ x ⟨xu, xs⟩, hu xu xs⟩ }, rintros ⟨u, openu, au, hu⟩, exact ⟨u, λ x xu xs, hu ⟨xu, xs⟩, openu, au⟩ end theorem nhds_within_mono (a : α) {s t : set α} (h : s ⊆ t) : nhds_within a s ≤ nhds_within a t := lattice.inf_le_inf (le_refl _) (principal_mono.mpr h) theorem nhds_within_restrict {a : α} (s : set α) {t : set α} (h₀ : a ∈ t) (h₁ : is_open t) : nhds_within a s = nhds_within a (s ∩ t) := have s ∩ t ∈ nhds_within a s, from inter_mem_sets (mem_inf_sets_of_right (mem_principal_self s)) (mem_inf_sets_of_left (mem_nhds_sets h₁ h₀)), le_antisymm (lattice.le_inf lattice.inf_le_left (le_principal_iff.mpr this)) (lattice.inf_le_inf (le_refl _) (principal_mono.mpr (set.inter_subset_left _ _))) theorem nhds_within_eq_nhds_within {a : α} {s t u : set α} (h₀ : a ∈ s) (h₁ : is_open s) (h₂ : t ∩ s = u ∩ s) : nhds_within a t = nhds_within a u := 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) : nhds_within a s = nhds a := by rw [←nhds_within_univ]; apply nhds_within_eq_nhds_within h₀ h₁; rw [set.univ_inter, set.inter_self] @[simp] theorem nhds_within_empty (a : α) : nhds_within a {} = ⊥ := by rw [nhds_within, principal_empty, lattice.inf_bot_eq] theorem nhds_within_union (a : α) (s t : set α) : nhds_within a (s ∪ t) = nhds_within a s ⊔ nhds_within a t := by unfold nhds_within; rw [←lattice.inf_sup_left, sup_principal] theorem nhds_within_inter (a : α) (s t : set α) : nhds_within a (s ∩ t) = nhds_within a s ⊓ nhds_within a t := by unfold nhds_within; rw [lattice.inf_left_comm, lattice.inf_assoc, inf_principal, ←lattice.inf_assoc, lattice.inf_idem] theorem nhds_within_inter' (a : α) (s t : set α) : nhds_within a (s ∩ t) = (nhds_within a s) ⊓ principal t := by { unfold nhds_within, rw [←inf_principal, lattice.inf_assoc] } theorem tendsto_if_nhds_within {f g : α → β} {p : α → Prop} [decidable_pred p] {a : α} {s : set α} {l : filter β} (h₀ : tendsto f (nhds_within a (s ∩ p)) l) (h₁ : tendsto g (nhds_within a (s ∩ {x | ¬ p x})) l) : tendsto (λ x, if p x then f x else g x) (nhds_within a s) l := by apply tendsto_if; rw [←nhds_within_inter']; assumption lemma map_nhds_within (f : α → β) (a : α) (s : set α) : map f (nhds_within a s) = ⨅ t ∈ {t : set α | a ∈ t ∧ is_open t}, principal (set.image f (t ∩ s)) := have h₀ : directed_on ((λ (i : set α), principal (i ∩ s)) ⁻¹'o ge) {x : set α | x ∈ {t : set α | a ∈ t ∧ is_open t}}, from assume x ⟨ax, openx⟩ y ⟨ay, openy⟩, ⟨x ∩ y, ⟨⟨ax, ay⟩, is_open_inter openx openy⟩, le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_left _ _)), le_principal_iff.mpr (set.inter_subset_inter_left _ (set.inter_subset_right _ _))⟩, have h₁ : ∃ (i : set α), i ∈ {t : set α | a ∈ t ∧ is_open t}, from ⟨set.univ, set.mem_univ _, is_open_univ⟩, by { rw [nhds_within_eq, map_binfi_eq h₀ h₁], simp only [map_principal] } theorem tendsto_nhds_within_mono_left {f : α → β} {a : α} {s t : set α} {l : filter β} (hst : s ⊆ t) (h : tendsto f (nhds_within a t) l) : tendsto f (nhds_within a s) l := tendsto_le_left (nhds_within_mono a hst) h theorem tendsto_nhds_within_mono_right {f : β → α} {l : filter β} {a : α} {s t : set α} (hst : s ⊆ t) (h : tendsto f l (nhds_within a s)) : tendsto f l (nhds_within a t) := tendsto_le_right (nhds_within_mono a hst) h theorem tendsto_nhds_within_of_tendsto_nhds {f : α → β} {a : α} {s : set α} {l : filter β} (h : tendsto f (nhds a) l) : tendsto f (nhds_within a s) l := by rw [←nhds_within_univ] at h; exact tendsto_nhds_within_mono_left (set.subset_univ _) h /- locally finite family [General Topology (Bourbaki, 1995)] -/ section locally_finite /-- A family of sets in `set α` is locally finite if at every point `x:α`, there is a neighborhood of `x` which meets only finitely many sets in the family -/ def locally_finite (f : β → set α) := ∀x:α, ∃t ∈ nhds x, finite {i | f i ∩ t ≠ ∅ } lemma locally_finite_of_finite {f : β → set α} (h : finite (univ : set β)) : locally_finite f := assume x, ⟨univ, univ_mem_sets, finite_subset h $ subset_univ _⟩ lemma locally_finite_subset {f₁ f₂ : β → set α} (hf₂ : locally_finite f₂) (hf : ∀b, f₁ b ⊆ f₂ b) : locally_finite f₁ := assume a, let ⟨t, ht₁, ht₂⟩ := hf₂ a in ⟨t, ht₁, finite_subset ht₂ $ assume i hi, neq_bot_of_le_neq_bot hi $ inter_subset_inter (hf i) $ subset.refl _⟩ lemma is_closed_Union_of_locally_finite {f : β → set α} (h₁ : locally_finite f) (h₂ : ∀i, is_closed (f i)) : is_closed (⋃i, f i) := is_open_iff_nhds.mpr $ assume a, assume h : a ∉ (⋃i, f i), have ∀i, a ∈ -f i, from assume i hi, h $ mem_Union.2 ⟨i, hi⟩, have ∀i, - f i ∈ (nhds a).sets, by rw [nhds_sets]; exact assume i, ⟨- f i, subset.refl _, h₂ i, this i⟩, let ⟨t, h_sets, (h_fin : finite {i | f i ∩ t ≠ ∅ })⟩ := h₁ a in calc nhds a ≤ principal (t ∩ (⋂ i∈{i | f i ∩ t ≠ ∅ }, - f i)) : begin rw [le_principal_iff], apply @filter.inter_mem_sets _ (nhds a) _ _ h_sets, apply @filter.Inter_mem_sets _ (nhds a) _ _ _ h_fin, exact assume i h, this i end ... ≤ principal (- ⋃i, f i) : begin simp only [principal_mono, subset_def, mem_compl_eq, mem_inter_eq, mem_Inter, mem_set_of_eq, mem_Union, and_imp, not_exists, not_eq_empty_iff_exists, exists_imp_distrib, (≠)], exact assume x xt ht i xfi, ht i x xfi xt xfi end end locally_finite end topological_space section continuous variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} variables [topological_space α] [topological_space β] [topological_space γ] /-- A function between topological spaces is continuous if the preimage of every open set is open. -/ def continuous (f : α → β) := ∀s, is_open s → is_open (f ⁻¹' s) def continuous_at (f : α → β) (x : α) := tendsto f (nhds x) (nhds (f x)) def continuous_at_within (f : α → β) (x : α) (s : set α) : Prop := tendsto f (nhds_within x s) (nhds (f x)) def continuous_on (f : α → β) (s : set α) : Prop := ∀ x ∈ s, continuous_at_within f x s lemma continuous_id : continuous (id : α → α) := assume s h, h lemma continuous.comp {f : α → β} {g : β → γ} (hf : continuous f) (hg : continuous g): continuous (g ∘ f) := assume s h, hf _ (hg s h) lemma continuous.tendsto {f : α → β} (hf : continuous f) (x) : tendsto f (nhds x) (nhds (f x)) | s := show s ∈ nhds (f x) → s ∈ map f (nhds x), by simp [nhds_sets]; exact assume t t_subset t_open fx_in_t, ⟨f ⁻¹' t, preimage_mono t_subset, hf t t_open, fx_in_t⟩ lemma continuous_iff_continuous_at {f : α → β} : continuous f ↔ ∀ x, continuous_at f x := ⟨continuous.tendsto, assume hf : ∀x, tendsto f (nhds x) (nhds (f x)), assume s, assume hs : is_open s, have ∀a, f a ∈ s → s ∈ nhds (f a), by simp [nhds_sets]; exact assume a ha, ⟨s, subset.refl s, hs, ha⟩, show is_open (f ⁻¹' s), by simp [is_open_iff_nhds]; exact assume a ha, hf a (this a ha)⟩ lemma continuous_const {b : β} : continuous (λa:α, b) := continuous_iff_continuous_at.mpr $ assume a, tendsto_const_nhds lemma continuous_iff_is_closed {f : α → β} : continuous f ↔ (∀s, is_closed s → is_closed (f ⁻¹' s)) := ⟨assume hf s hs, hf (-s) hs, assume hf s, by rw [←is_closed_compl_iff, ←is_closed_compl_iff]; exact hf _⟩ lemma continuous_at_iff_ultrafilter {f : α → β} (x) : continuous_at f x ↔ ∀ g, is_ultrafilter g → g ≤ nhds x → g.map f ≤ nhds (f x) := tendsto_iff_ultrafilter f (nhds x) (nhds (f x)) lemma continuous_iff_ultrafilter {f : α → β} : continuous f ↔ ∀ x g, is_ultrafilter g → g ≤ nhds x → g.map f ≤ nhds (f x) := by simp only [continuous_iff_continuous_at, continuous_at_iff_ultrafilter] lemma continuous_if {p : α → Prop} {f g : α → β} {h : ∀a, decidable (p a)} (hp : ∀a∈frontier {a | p a}, f a = g a) (hf : continuous f) (hg : continuous g) : continuous (λa, @ite (p a) (h a) β (f a) (g a)) := continuous_iff_is_closed.mpr $ assume s hs, have (λa, ite (p a) (f a) (g a)) ⁻¹' s = (closure {a | p a} ∩ f ⁻¹' s) ∪ (closure {a | ¬ p a} ∩ g ⁻¹' s), from set.ext $ assume a, classical.by_cases (assume : a ∈ frontier {a | p a}, have hac : a ∈ closure {a | p a}, from this.left, have hai : a ∈ closure {a | ¬ p a}, from have a ∈ - interior {a | p a}, from this.right, by rwa [←closure_compl] at this, by by_cases p a; simp [h, hp a this, hac, hai, iff_def] {contextual := tt}) (assume hf : a ∈ - frontier {a | p a}, classical.by_cases (assume : p a, have hc : a ∈ closure {a | p a}, from subset_closure this, have hnc : a ∉ closure {a | ¬ p a}, by show a ∉ closure (- {a | p a}); rw [closure_compl]; simpa [frontier, hc] using hf, by simp [this, hc, hnc]) (assume : ¬ p a, have hc : a ∈ closure {a | ¬ p a}, from subset_closure this, have hnc : a ∉ closure {a | p a}, begin have hc : a ∈ closure (- {a | p a}), from hc, simp [closure_compl] at hc, simpa [frontier, hc] using hf end, by simp [this, hc, hnc])), by rw [this]; exact is_closed_union (is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hf s hs) (is_closed_inter is_closed_closure $ continuous_iff_is_closed.mp hg s hs) /- Continuity and partial functions -/ def pcontinuous (f : α →. β) := ∀ s, is_open s → is_open (f.preimage s) lemma open_dom_of_pcontinuous {f : α →. β} (h : pcontinuous f) : is_open f.dom := by rw [←pfun.preimage_univ]; exact h _ is_open_univ lemma pcontinuous_iff' {f : α →. β} : pcontinuous f ↔ ∀ {x y} (h : y ∈ f x), ptendsto' f (nhds x) (nhds y) := begin split, { intros h x y h', rw [ptendsto'_def], change ∀ (s : set β), s ∈ (nhds y).sets → pfun.preimage f s ∈ (nhds x).sets, rw [nhds_sets, nhds_sets], rintros s ⟨t, tsubs, opent, yt⟩, exact ⟨f.preimage t, pfun.preimage_mono _ tsubs, h _ opent, ⟨y, yt, h'⟩⟩ }, intros hf s os, rw is_open_iff_nhds, rintros x ⟨y, ys, fxy⟩ t, rw [mem_principal_sets], assume h : f.preimage s ⊆ t, change t ∈ nhds x, apply mem_sets_of_superset _ h, have h' : ∀ s ∈ nhds y, f.preimage s ∈ nhds x, { intros s hs, have : ptendsto' f (nhds x) (nhds y) := hf fxy, rw ptendsto'_def at this, exact this s hs }, show f.preimage s ∈ nhds x, apply h', rw mem_nhds_sets_iff, exact ⟨s, set.subset.refl _, os, ys⟩ end lemma image_closure_subset_closure_image {f : α → β} {s : set α} (h : continuous f) : f '' closure s ⊆ closure (f '' s) := have ∀ (a : α), nhds a ⊓ principal s ≠ ⊥ → nhds (f a) ⊓ principal (f '' s) ≠ ⊥, from assume a ha, have h₁ : ¬ map f (nhds a ⊓ principal s) = ⊥, by rwa[map_eq_bot_iff], have h₂ : map f (nhds a ⊓ principal s) ≤ nhds (f a) ⊓ principal (f '' s), from le_inf (le_trans (map_mono inf_le_left) $ by rw [continuous_iff_continuous_at] at h; exact h a) (le_trans (map_mono inf_le_right) $ by simp; exact subset.refl _), neq_bot_of_le_neq_bot h₁ h₂, by simp [image_subset_iff, closure_eq_nhds]; assumption lemma mem_closure [topological_space α] [topological_space β] {s : set α} {t : set β} {f : α → β} {a : α} (hf : continuous f) (ha : a ∈ closure s) (ht : ∀a∈s, f a ∈ t) : f a ∈ closure t := subset.trans (image_closure_subset_closure_image hf) (closure_mono $ image_subset_iff.2 ht) $ (mem_image_of_mem f ha) end continuous
b65e16cd208a6833d8e4926047f9197580c551df
e0f9ba56b7fedc16ef8697f6caeef5898b435143
/src/data/list/defs.lean
db028ede3d9217a45952f1eb1c926346c3a37785
[ "Apache-2.0" ]
permissive
anrddh/mathlib
6a374da53c7e3a35cb0298b0cd67824efef362b4
a4266a01d2dcb10de19369307c986d038c7bb6a6
refs/heads/master
1,656,710,827,909
1,589,560,456,000
1,589,560,456,000
264,271,800
0
0
Apache-2.0
1,589,568,062,000
1,589,568,061,000
null
UTF-8
Lean
false
false
20,479
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 Extra definitions on lists. -/ import data.option.defs import logic.basic import tactic.cache namespace list open function nat universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} /-- Returns whether a list is []. Returns a boolean even if `l = []` is not decidable. -/ def is_nil {α} : list α → bool | [] := tt | _ := ff instance [decidable_eq α] : has_sdiff (list α) := ⟨ list.diff ⟩ /-- Split a list at an index. split_at 2 [a, b, c] = ([a, b], [c]) -/ def split_at : ℕ → list α → list α × list α | 0 a := ([], a) | (succ n) [] := ([], []) | (succ n) (x :: xs) := let (l, r) := split_at n xs in (x :: l, r) /-- An auxiliary function for `split_on_p`. -/ def split_on_p_aux {α : Type u} (P : α → Prop) [decidable_pred P] : list α → (list α → list α) → list (list α) | [] f := [f []] | (h :: t) f := if P h then f [] :: split_on_p_aux t id else split_on_p_aux t (λ l, f (h :: l)) /-- Split a list at every element satisfying a predicate. -/ def split_on_p {α : Type u} (P : α → Prop) [decidable_pred P] (l : list α) : list (list α) := split_on_p_aux P l id /-- Split a list at every occurrence of an element. [1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]] -/ def split_on {α : Type u} [decidable_eq α] (a : α) (as : list α) : list (list α) := as.split_on_p (=a) /-- Concatenate an element at the end of a list. concat [a, b] c = [a, b, c] -/ @[simp] def concat : list α → α → list α | [] a := [a] | (b::l) a := b :: concat l a /-- `head' xs` returns the first element of `xs` if `xs` is non-empty; it returns `none` otherwise -/ @[simp] def head' : list α → option α | [] := none | (a :: l) := some a /-- Convert a list into an array (whose length is the length of `l`). -/ def to_array (l : list α) : array l.length α := {data := λ v, l.nth_le v.1 v.2} /-- "inhabited" `nth` function: returns `default` instead of `none` in the case that the index is out of bounds. -/ @[simp] def inth [h : inhabited α] (l : list α) (n : nat) : α := (nth l n).iget /-- Apply a function to the nth tail of `l`. Returns the input without using `f` if the index is larger than the length of the list. modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c] -/ @[simp] def modify_nth_tail (f : list α → list α) : ℕ → list α → list α | 0 l := f l | (n+1) [] := [] | (n+1) (a::l) := a :: modify_nth_tail n l /-- Apply `f` to the head of the list, if it exists. -/ @[simp] def modify_head (f : α → α) : list α → list α | [] := [] | (a::l) := f a :: l /-- Apply `f` to the nth element of the list, if it exists. -/ def modify_nth (f : α → α) : ℕ → list α → list α := modify_nth_tail (modify_head f) def insert_nth (n : ℕ) (a : α) : list α → list α := modify_nth_tail (list.cons a) n section take' variable [inhabited α] /-- Take `n` elements from a list `l`. If `l` has less than `n` elements, append `n - length l` elements `default α`. -/ def take' : ∀ n, list α → list α | 0 l := [] | (n+1) l := l.head :: take' n l.tail end take' /-- Get the longest initial segment of the list whose members all satisfy `p`. take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2] -/ def take_while (p : α → Prop) [decidable_pred p] : list α → list α | [] := [] | (a::l) := if p a then a :: take_while l else [] /-- Fold a function `f` over the list from the left, returning the list of partial results. scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6] -/ def scanl (f : α → β → α) : α → list β → list α | a [] := [a] | a (b::l) := a :: scanl (f a b) l def scanr_aux (f : α → β → β) (b : β) : list α → β × list β | [] := (b, []) | (a::l) := let (b', l') := scanr_aux l in (f a b', b' :: l') /-- Fold a function `f` over the list from the right, returning the list of partial results. scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0] -/ def scanr (f : α → β → β) (b : β) (l : list α) : list β := let (b', l') := scanr_aux f b l in b' :: l' /-- Product of a list. prod [a, b, c] = ((1 * a) * b) * c -/ def prod [has_mul α] [has_one α] : list α → α := foldl (*) 1 /-- Sum of a list. sum [a, b, c] = ((0 + a) + b) + c -/ -- Later this will be tagged with `to_additive`, but this can't be done yet because of import -- dependencies. def sum [has_add α] [has_zero α] : list α → α := foldl (+) 0 def partition_map (f : α → β ⊕ γ) : list α → list β × list γ | [] := ([],[]) | (x::xs) := match f x with | (sum.inr r) := prod.map id (cons r) $ partition_map xs | (sum.inl l) := prod.map (cons l) id $ partition_map xs end /-- `find p l` is the first element of `l` satisfying `p`, or `none` if no such element exists. -/ def find (p : α → Prop) [decidable_pred p] : list α → option α | [] := none | (a::l) := if p a then some a else find l def find_indexes_aux (p : α → Prop) [decidable_pred p] : list α → nat → list nat | [] n := [] | (a::l) n := let t := find_indexes_aux l (succ n) in if p a then n :: t else t /-- `find_indexes p l` is the list of indexes of elements of `l` that satisfy `p`. -/ def find_indexes (p : α → Prop) [decidable_pred p] (l : list α) : list nat := find_indexes_aux p l 0 /-- `lookmap` is a combination of `lookup` and `filter_map`. `lookmap f l` will apply `f : α → option α` to each element of the list, replacing `a → b` at the first value `a` in the list such that `f a = some b`. -/ def lookmap (f : α → option α) : list α → list α | [] := [] | (a::l) := match f a with | some b := b :: l | none := a :: lookmap l end def map_with_index_core (f : ℕ → α → β) : ℕ → list α → list β | k [] := [] | k (a::as) := f k a::(map_with_index_core (k+1) as) /-- Given a function `f : ℕ → α → β` and `as : list α`, `as = [a₀, a₁, ...]`, returns the list `[f 0 a₀, f 1 a₁, ...]`. -/ def map_with_index (f : ℕ → α → β) (as : list α) : list β := map_with_index_core f 0 as /-- `indexes_of a l` is the list of all indexes of `a` in `l`. indexes_of a [a, b, a, a] = [0, 2, 3] -/ def indexes_of [decidable_eq α] (a : α) : list α → list nat := find_indexes (eq a) /-- Auxilliary definition for `indexes_values`. -/ def indexes_values_aux {α} (f : α → bool) : list α → ℕ → list (ℕ × α) | [] n := [] | (x::xs) n := let ns := indexes_values_aux xs (n+1) in if f x then (n, x)::ns else ns /-- Returns `(l.find_indexes f).zip l`, i.e. pairs of `(n, x)` such that `f x = tt` and `l.nth = some x`, in increasing order of first arguments. -/ def indexes_values {α} (l : list α) (f : α → bool) : list (ℕ × α) := indexes_values_aux f l 0 /-- `countp p l` is the number of elements of `l` that satisfy `p`. -/ def countp (p : α → Prop) [decidable_pred p] : list α → nat | [] := 0 | (x::xs) := if p x then succ (countp xs) else countp xs /-- `count a l` is the number of occurrences of `a` in `l`. -/ def count [decidable_eq α] (a : α) : list α → nat := countp (eq a) /-- `is_prefix l₁ l₂`, or `l₁ <+: l₂`, means that `l₁` is a prefix of `l₂`, that is, `l₂` has the form `l₁ ++ t` for some `t`. -/ def is_prefix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, l₁ ++ t = l₂ /-- `is_suffix l₁ l₂`, or `l₁ <:+ l₂`, means that `l₁` is a suffix of `l₂`, that is, `l₂` has the form `t ++ l₁` for some `t`. -/ def is_suffix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, t ++ l₁ = l₂ /-- `is_infix l₁ l₂`, or `l₁ <:+: l₂`, means that `l₁` is a contiguous substring of `l₂`, that is, `l₂` has the form `s ++ l₁ ++ t` for some `s, t`. -/ def is_infix (l₁ : list α) (l₂ : list α) : Prop := ∃ s t, s ++ l₁ ++ t = l₂ infix ` <+: `:50 := is_prefix infix ` <:+ `:50 := is_suffix infix ` <:+: `:50 := is_infix /-- `inits l` is the list of initial segments of `l`. inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]] -/ @[simp] def inits : list α → list (list α) | [] := [[]] | (a::l) := [] :: map (λt, a::t) (inits l) /-- `tails l` is the list of terminal segments of `l`. tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []] -/ @[simp] def tails : list α → list (list α) | [] := [[]] | (a::l) := (a::l) :: tails l def sublists'_aux : list α → (list α → list β) → list (list β) → list (list β) | [] f r := f [] :: r | (a::l) f r := sublists'_aux l f (sublists'_aux l (f ∘ cons a) r) /-- `sublists' l` is the list of all (non-contiguous) sublists of `l`. It differs from `sublists` only in the order of appearance of the sublists; `sublists'` uses the first element of the list as the MSB, `sublists` uses the first element of the list as the LSB. sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] -/ def sublists' (l : list α) : list (list α) := sublists'_aux l id [] def sublists_aux : list α → (list α → list β → list β) → list β | [] f := [] | (a::l) f := f [a] (sublists_aux l (λys r, f ys (f (a :: ys) r))) /-- `sublists l` is the list of all (non-contiguous) sublists of `l`; cf. `sublists'` for a different ordering. sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] -/ def sublists (l : list α) : list (list α) := [] :: sublists_aux l cons def sublists_aux₁ : list α → (list α → list β) → list β | [] f := [] | (a::l) f := f [a] ++ sublists_aux₁ l (λys, f ys ++ f (a :: ys)) section forall₂ variables {r : α → β → Prop} {p : γ → δ → Prop} inductive forall₂ (R : α → β → Prop) : list α → list β → Prop | nil : forall₂ [] [] | cons {a b l₁ l₂} : R a b → forall₂ l₁ l₂ → forall₂ (a::l₁) (b::l₂) attribute [simp] forall₂.nil end forall₂ def transpose_aux : list α → list (list α) → list (list α) | [] ls := ls | (a::i) [] := [a] :: transpose_aux i [] | (a::i) (l::ls) := (a::l) :: transpose_aux i ls /-- transpose of a list of lists, treated as a matrix. transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]] -/ def transpose : list (list α) → list (list α) | [] := [] | (l::ls) := transpose_aux l (transpose ls) /-- List of all sections through a list of lists. A section of `[L₁, L₂, ..., Lₙ]` is a list whose first element comes from `L₁`, whose second element comes from `L₂`, and so on. -/ def sections : list (list α) → list (list α) | [] := [[]] | (l::L) := bind (sections L) $ λ s, map (λ a, a::s) l section permutations def permutations_aux2 (t : α) (ts : list α) (r : list β) : list α → (list α → β) → list α × list β | [] f := (ts, r) | (y::ys) f := let (us, zs) := permutations_aux2 ys (λx : list α, f (y::x)) in (y :: us, f (t :: y :: us) :: zs) private def meas : (Σ'_:list α, list α) → ℕ × ℕ | ⟨l, i⟩ := (length l + length i, length l) local infix ` ≺ `:50 := inv_image (prod.lex (<) (<)) meas @[elab_as_eliminator] def permutations_aux.rec {C : list α → list α → Sort v} (H0 : ∀ is, C [] is) (H1 : ∀ t ts is, C ts (t::is) → C is [] → C (t::ts) is) : ∀ l₁ l₂, C l₁ l₂ | [] is := H0 is | (t::ts) is := have h1 : ⟨ts, t :: is⟩ ≺ ⟨t :: ts, is⟩, from show prod.lex _ _ (succ (length ts + length is), length ts) (succ (length ts) + length is, length (t :: ts)), by rw nat.succ_add; exact prod.lex.right _ (lt_succ_self _), have h2 : ⟨is, []⟩ ≺ ⟨t :: ts, is⟩, from prod.lex.left _ _ (lt_add_of_pos_left _ (succ_pos _)), H1 t ts is (permutations_aux.rec ts (t::is)) (permutations_aux.rec is []) using_well_founded { dec_tac := tactic.assumption, rel_tac := λ _ _, `[exact ⟨(≺), @inv_image.wf _ _ _ meas (prod.lex_wf lt_wf lt_wf)⟩] } def permutations_aux : list α → list α → list (list α) := @@permutations_aux.rec (λ _ _, list (list α)) (λ is, []) (λ t ts is IH1 IH2, foldr (λy r, (permutations_aux2 t ts r y id).2) IH1 (is :: IH2)) /-- List of all permutations of `l`. permutations [1, 2, 3] = [[1, 2, 3], [2, 1, 3], [3, 2, 1], [2, 3, 1], [3, 1, 2], [1, 3, 2]] -/ def permutations (l : list α) : list (list α) := l :: permutations_aux l [] end permutations def erasep (p : α → Prop) [decidable_pred p] : list α → list α | [] := [] | (a::l) := if p a then l else a :: erasep l def extractp (p : α → Prop) [decidable_pred p] : list α → option α × list α | [] := (none, []) | (a::l) := if p a then (some a, l) else let (a', l') := extractp l in (a', a :: l') def revzip (l : list α) : list (α × α) := zip l l.reverse /-- `product l₁ l₂` is the list of pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂`. product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)] -/ def product (l₁ : list α) (l₂ : list β) : list (α × β) := l₁.bind $ λ a, l₂.map $ prod.mk a /-- `sigma l₁ l₂` is the list of dependent pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂ a`. sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)] -/ protected def sigma {σ : α → Type*} (l₁ : list α) (l₂ : Π a, list (σ a)) : list (Σ a, σ a) := l₁.bind $ λ a, (l₂ a).map $ sigma.mk a def of_fn_aux {n} (f : fin n → α) : ∀ m, m ≤ n → list α → list α | 0 h l := l | (succ m) h l := of_fn_aux m (le_of_lt h) (f ⟨m, h⟩ :: l) def of_fn {n} (f : fin n → α) : list α := of_fn_aux f n (le_refl _) [] def of_fn_nth_val {n} (f : fin n → α) (i : ℕ) : option α := if h : _ then some (f ⟨i, h⟩) else none /-- `disjoint l₁ l₂` means that `l₁` and `l₂` have no elements in common. -/ def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, a ∈ l₁ → a ∈ l₂ → false section pairwise variables (R : α → α → Prop) /-- `pairwise R l` means that all the elements with earlier indexes are `R`-related to all the elements with later indexes. pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3 For example if `R = (≠)` then it asserts `l` has no duplicates, and if `R = (<)` then it asserts that `l` is (strictly) sorted. -/ inductive pairwise : list α → Prop | nil : pairwise [] | cons : ∀ {a : α} {l : list α}, (∀ a' ∈ l, R a a') → pairwise l → pairwise (a::l) variables {R} @[simp] theorem pairwise_cons {a : α} {l : list α} : pairwise R (a::l) ↔ (∀ a' ∈ l, R a a') ∧ pairwise R l := ⟨λ p, by cases p with a l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩ instance decidable_pairwise [decidable_rel R] (l : list α) : decidable (pairwise R l) := by induction l with hd tl ih; [exact is_true pairwise.nil, exactI decidable_of_iff' _ pairwise_cons] end pairwise /-- `pw_filter R l` is a maximal sublist of `l` which is `pairwise R`. `pw_filter (≠)` is the erase duplicates function (cf. `erase_dup`), and `pw_filter (<)` finds a maximal increasing subsequence in `l`. For example, pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4] -/ def pw_filter (R : α → α → Prop) [decidable_rel R] : list α → list α | [] := [] | (x :: xs) := let IH := pw_filter xs in if ∀ y ∈ IH, R x y then x :: IH else IH section chain variable (R : α → α → Prop) /-- `chain R a l` means that `R` holds between adjacent elements of `a::l`. chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d -/ inductive chain : α → list α → Prop | nil {a : α} : chain a [] | cons : ∀ {a b : α} {l : list α}, R a b → chain b l → chain a (b::l) /-- `chain' R l` means that `R` holds between adjacent elements of `l`. chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d -/ def chain' : list α → Prop | [] := true | (a :: l) := chain R a l variable {R} @[simp] theorem chain_cons {a b : α} {l : list α} : chain R a (b::l) ↔ R a b ∧ chain R b l := ⟨λ p, by cases p with _ a b l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩ attribute [simp] chain.nil instance decidable_chain [decidable_rel R] (a : α) (l : list α) : decidable (chain R a l) := by induction l generalizing a; simp only [chain.nil, chain_cons]; resetI; apply_instance instance decidable_chain' [decidable_rel R] (l : list α) : decidable (chain' R l) := by cases l; dunfold chain'; apply_instance end chain /-- `nodup l` means that `l` has no duplicates, that is, any element appears at most once in the list. It is defined as `pairwise (≠)`. -/ def nodup : list α → Prop := pairwise (≠) instance nodup_decidable [decidable_eq α] : ∀ l : list α, decidable (nodup l) := list.decidable_pairwise /-- `erase_dup l` removes duplicates from `l` (taking only the first occurrence). Defined as `pw_filter (≠)`. erase_dup [1, 0, 2, 2, 1] = [0, 2, 1] -/ def erase_dup [decidable_eq α] : list α → list α := pw_filter (≠) /-- `range' s n` is the list of numbers `[s, s+1, ..., s+n-1]`. It is intended mainly for proving properties of `range` and `iota`. -/ @[simp] def range' : ℕ → ℕ → list ℕ | s 0 := [] | s (n+1) := s :: range' (s+1) n /-- Drop `none`s from a list, and replace each remaining `some a` with `a`. -/ def reduce_option {α} : list (option α) → list α := list.filter_map id /-- Apply `f` to the first element of `l`. -/ def map_head {α} (f : α → α) : list α → list α | [] := [] | (x :: xs) := f x :: xs /-- Apply `f` to the last element of `l`. -/ def map_last {α} (f : α → α) : list α → list α | [] := [] | [x] := [f x] | (x :: xs) := x :: map_last xs /-- `ilast' x xs` returns the last element of `xs` if `xs` is non-empty; it returns `x` otherwise -/ @[simp] def ilast' {α} : α → list α → α | a [] := a | a (b::l) := ilast' b l /-- `last' xs` returns the last element of `xs` if `xs` is non-empty; it returns `none` otherwise -/ @[simp] def last' {α} : list α → option α | [] := none | [a] := some a | (b::l) := last' l /-- `rotate l n` rotates the elements of `l` to the left by `n` rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1] -/ def rotate (l : list α) (n : ℕ) : list α := let (l₁, l₂) := list.split_at (n % l.length) l in l₂ ++ l₁ /-- rotate' is the same as `rotate`, but slower. Used for proofs about `rotate`-/ def rotate' : list α → ℕ → list α | [] n := [] | l 0 := l | (a::l) (n+1) := rotate' (l ++ [a]) n section choose variables (p : α → Prop) [decidable_pred p] (l : list α) /-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`, choose the first element with this property. This version returns both `a` and proofs of `a ∈ l` and `p a`. -/ def choose_x : Π l : list α, Π hp : (∃ a, a ∈ l ∧ p a), { a // a ∈ l ∧ p a } | [] hp := false.elim (exists.elim hp (assume a h, not_mem_nil a h.left)) | (l :: ls) hp := if pl : p l then ⟨l, ⟨or.inl rfl, pl⟩⟩ else let ⟨a, ⟨a_mem_ls, pa⟩⟩ := choose_x ls (hp.imp (λ b ⟨o, h₂⟩, ⟨o.resolve_left (λ e, pl $ e ▸ h₂), h₂⟩)) in ⟨a, ⟨or.inr a_mem_ls, pa⟩⟩ /-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`, choose the first element with this property. This version returns `a : α`, and properties are given by `choose_mem` and `choose_property`. -/ def choose (hp : ∃ a, a ∈ l ∧ p a) : α := choose_x p l hp end choose /-- Filters and maps elements of a list -/ def mmap_filter {m : Type → Type v} [monad m] {α β} (f : α → m (option β)) : list α → m (list β) | [] := return [] | (h :: t) := do b ← f h, t' ← t.mmap_filter, return $ match b with none := t' | (some x) := x::t' end protected def traverse {F : Type u → Type v} [applicative F] {α β : Type*} (f : α → F β) : list α → F (list β) | [] := pure [] | (x :: xs) := list.cons <$> f x <*> traverse xs /-- `get_rest l l₁` returns `some l₂` if `l = l₁ ++ l₂`. If `l₁` is not a prefix of `l`, returns `none` -/ def get_rest [decidable_eq α] : list α → list α → option (list α) | l [] := some l | [] _ := none | (x::l) (y::l₁) := if x = y then get_rest l l₁ else none end list
38476b180482d0a4fd4498c55f9baf3b8973ec61
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/tactic/clear.lean
9012556d265eeec051994b856eb4dba3416d9d09
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
4,326
lean
/- Copyright (c) 2020 Jannis Limperg. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jannis Limperg -/ import tactic.core /-! # Better `clear` tactics We define two variants of the standard `clear` tactic: * `clear'` works like `clear` but the hypotheses that should be cleared can be given in any order. In contrast, `clear` can fail if hypotheses that depend on each other are given in the wrong order, even if all of them could be cleared. * `clear_dependent` works like `clear'` but also clears any hypotheses that depend on the given hypotheses. ## Implementation notes The implementation (ab)uses the native `revert_lst`, which can figure out dependencies between hypotheses. This implementation strategy was suggested by Simon Hudon. -/ open native tactic interactive lean.parser /-- Clears all the hypotheses in `hyps`. The tactic fails if any of the `hyps` is not a local or if the target depends on any of the `hyps`. If there are local hypotheses or definitions, say `H`, which are not in `hyps` but depend on one of the `hyps`, what we do depends on `clear_dependent`. If it is true, `H` is implicitly also cleared. If it is false, `clear'` fails. -/ meta def tactic.clear' (clear_dependent : bool) (hyps : expr_set) : tactic unit := do let hyps_list := hyps.to_list, tgt ← target, -- Check if the target depends on any of the hyps. Doing this (instead of -- letting one of the later tactics fail) lets us give a much more informative -- error message. hyps_list.mmap' (λ h, do dep ← kdepends_on tgt h, when dep $ fail $ format!"Cannot clear hypothesis {h} since the target depends on it."), n ← revert_lst hyps_list, -- If revert_lst reverted more hypotheses than we wanted to clear, there must -- have been other hypotheses dependent on some of the hyps. when (! clear_dependent && (n ≠ hyps.size)) $ fail $ format.join [ "Some of the following hypotheses cannot be cleared because other " , "hypotheses depend on (some of) them:\n" , format.intercalate ", " (hyps.to_list.map to_fmt) ], v ← mk_meta_var tgt, intron n, exact v, gs ← get_goals, set_goals $ v :: gs namespace tactic.interactive /-- `clear' a b c` removes the given hypotheses from the local context. In contrast to `clear`, the order of hypotheses does not matter, even if there are dependencies between them. Fails if the target or any local hypotheses (other than the given ones) depend on the given hypotheses. -/ meta def clear' (p : parse (many ident)) : tactic unit := do hyps ← p.mmap get_local, tactic.clear' false (rb_map.set_of_list hyps) /-- `clear_dependent a b c` removes from the local context the given hypotheses and any other hypotheses that depend on them. The hypotheses can be given in any order. Fails if the target depends on any of the given hypotheses. -/ meta def clear_dependent (p : parse (many ident)) : tactic unit := do hyps ← p.mmap get_local, tactic.clear' true (rb_map.set_of_list hyps) /-- An improved version of the standard `clear` tactic. `clear` is sensitive to the order of its arguments: `clear x y` may fail even though both `x` and `y` could be cleared (if the type of `y` depends on `x`). `clear'` lifts this limitation. ```lean example {α} {β : α → Type} (a : α) (b : β a) : unit := begin try { clear a b }, -- fails since `b` depends on `a` clear' a b, -- succeeds exact () end ``` -/ add_tactic_doc { name := "clear'", category := doc_category.tactic, decl_names := [`tactic.interactive.clear', `tactic.interactive.clear_dependent], tags := ["context management"], inherit_description_from := `tactic.interactive.clear' } /-- A variant of `clear'` which clears not only the given hypotheses, but also any other hypotheses depending on them. ```lean example {α} {β : α → Type} (a : α) (b : β a) : unit := begin try { clear' a }, -- fails since `b` depends on `a` clear_dependent a, -- succeeds, clearing `a` and `b` exact () end ``` -/ add_tactic_doc { name := "clear_dependent", category := doc_category.tactic, decl_names := [`tactic.interactive.clear', `tactic.interactive.clear_dependent], tags := ["context management"], inherit_description_from := `tactic.interactive.clear_dependent } end tactic.interactive
619a9e06f78ba4b0a8dd027bfb09cb0d523f25cf
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/measure_theory/measure/haar/of_basis.lean
dd1d618b23b18eab5914e6d3b6f433b4775c8986
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
11,175
lean
/- Copyright (c) 2022 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 measure_theory.measure.haar.basic import analysis.inner_product_space.pi_L2 /-! # Additive Haar measure constructed from a basis > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Given a basis of a finite-dimensional real vector space, we define the corresponding Lebesgue measure, which gives measure `1` to the parallelepiped spanned by the basis. ## Main definitions * `parallelepiped v` is the parallelepiped spanned by a finite family of vectors. * `basis.parallelepiped` is the parallelepiped associated to a basis, seen as a compact set with nonempty interior. * `basis.add_haar` is the Lebesgue measure associated to a basis, giving measure `1` to the corresponding parallelepiped. In particular, we declare a `measure_space` instance on any finite-dimensional inner product space, by using the Lebesgue measure associated to some orthonormal basis (which is in fact independent of the basis). -/ open set topological_space measure_theory measure_theory.measure finite_dimensional open_locale big_operators pointwise noncomputable theory variables {ι ι' E F : Type*} [fintype ι] [fintype ι'] section add_comm_group variables [add_comm_group E] [module ℝ E] [add_comm_group F] [module ℝ F] /-- The closed parallelepiped spanned by a finite family of vectors. -/ def parallelepiped (v : ι → E) : set E := (λ (t : ι → ℝ), ∑ i, t i • v i) '' (Icc 0 1) lemma mem_parallelepiped_iff (v : ι → E) (x : E) : x ∈ parallelepiped v ↔ ∃ (t : ι → ℝ) (ht : t ∈ Icc (0 : ι → ℝ) 1), x = ∑ i, t i • v i := by simp [parallelepiped, eq_comm] lemma image_parallelepiped (f : E →ₗ[ℝ] F) (v : ι → E) : f '' (parallelepiped v) = parallelepiped (f ∘ v) := begin simp only [parallelepiped, ← image_comp], congr' 1 with t, simp only [function.comp_app, linear_map.map_sum, linear_map.map_smulₛₗ, ring_hom.id_apply], end /-- Reindexing a family of vectors does not change their parallelepiped. -/ @[simp] lemma parallelepiped_comp_equiv (v : ι → E) (e : ι' ≃ ι) : parallelepiped (v ∘ e) = parallelepiped v := begin simp only [parallelepiped], let K : (ι' → ℝ) ≃ (ι → ℝ) := equiv.Pi_congr_left' (λ (a : ι'), ℝ) e, have : Icc (0 : (ι → ℝ)) 1 = K '' (Icc (0 : (ι' → ℝ)) 1), { rw ← equiv.preimage_eq_iff_eq_image, ext x, simp only [mem_preimage, mem_Icc, pi.le_def, pi.zero_apply, equiv.Pi_congr_left'_apply, pi.one_apply], refine ⟨λ h, ⟨λ i, _, λ i, _⟩, λ h, ⟨λ i, h.1 (e.symm i), λ i, h.2 (e.symm i)⟩⟩, { simpa only [equiv.symm_apply_apply] using h.1 (e i) }, { simpa only [equiv.symm_apply_apply] using h.2 (e i) } }, rw [this, ← image_comp], congr' 1 with x, simpa only [orthonormal_basis.coe_reindex, function.comp_app, equiv.symm_apply_apply, equiv.Pi_congr_left'_apply, equiv.apply_symm_apply] using (e.symm.sum_comp (λ (i : ι'), x i • v (e i))).symm, end /- The parallelepiped associated to an orthonormal basis of `ℝ` is either `[0, 1]` or `[-1, 0]`. -/ lemma parallelepiped_orthonormal_basis_one_dim (b : orthonormal_basis ι ℝ ℝ) : parallelepiped b = Icc 0 1 ∨ parallelepiped b = Icc (-1) 0 := begin have e : ι ≃ fin 1, { apply fintype.equiv_fin_of_card_eq, simp only [← finrank_eq_card_basis b.to_basis, finrank_self] }, have B : parallelepiped (b.reindex e) = parallelepiped b, { convert parallelepiped_comp_equiv b e.symm, ext i, simp only [orthonormal_basis.coe_reindex] }, rw ← B, let F : ℝ → (fin 1 → ℝ) := λ t, (λ i, t), have A : Icc (0 : fin 1 → ℝ) 1 = F '' (Icc (0 : ℝ) 1), { apply subset.antisymm, { assume x hx, refine ⟨x 0, ⟨hx.1 0, hx.2 0⟩, _⟩, ext j, simp only [subsingleton.elim j 0] }, { rintros x ⟨y, hy, rfl⟩, exact ⟨λ j, hy.1, λ j, hy.2⟩ } }, rcases orthonormal_basis_one_dim (b.reindex e) with H|H, { left, simp only [H, parallelepiped, algebra.id.smul_eq_mul, mul_one, A, finset.sum_singleton, ←image_comp, image_id', finset.univ_unique], }, { right, simp only [H, parallelepiped, algebra.id.smul_eq_mul, mul_one], rw A, simp only [←image_comp, mul_neg, mul_one, finset.sum_singleton, image_neg, preimage_neg_Icc, neg_zero, finset.univ_unique] }, end lemma parallelepiped_eq_sum_segment (v : ι → E) : parallelepiped v = ∑ i, segment ℝ 0 (v i) := begin ext, simp only [mem_parallelepiped_iff, set.mem_finset_sum, finset.mem_univ, forall_true_left, segment_eq_image, smul_zero, zero_add, ←set.pi_univ_Icc, set.mem_univ_pi], split, { rintro ⟨t, ht, rfl⟩, exact ⟨t • v, λ i, ⟨t i, ht _, by simp⟩, rfl⟩ }, rintro ⟨g, hg, rfl⟩, change ∀ i, _ at hg, choose t ht hg using hg, refine ⟨t, ht, _⟩, simp_rw hg, end lemma convex_parallelepiped (v : ι → E) : convex ℝ (parallelepiped v) := begin rw parallelepiped_eq_sum_segment, exact convex_sum _ (λ i hi, convex_segment _ _), end /-- A `parallelepiped` is the convex hull of its vertices -/ lemma parallelepiped_eq_convex_hull (v : ι → E) : parallelepiped v = convex_hull ℝ (∑ i, {(0 : E), v i}) := by simp_rw [convex_hull_sum, convex_hull_pair, parallelepiped_eq_sum_segment] /-- The axis aligned parallelepiped over `ι → ℝ` is a cuboid. -/ lemma parallelepiped_single [decidable_eq ι] (a : ι → ℝ) : parallelepiped (λ i, pi.single i (a i)) = set.uIcc 0 a := begin ext, simp_rw [set.uIcc, mem_parallelepiped_iff, set.mem_Icc, pi.le_def, ←forall_and_distrib, pi.inf_apply, pi.sup_apply, ←pi.single_smul', pi.one_apply, pi.zero_apply, ←pi.smul_apply', finset.univ_sum_single (_ : ι → ℝ)], split, { rintros ⟨t, ht, rfl⟩ i, specialize ht i, simp_rw [smul_eq_mul, pi.mul_apply], cases le_total (a i) 0 with hai hai, { rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai], exact ⟨le_mul_of_le_one_left hai ht.2, mul_nonpos_of_nonneg_of_nonpos ht.1 hai⟩ }, { rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai], exact ⟨mul_nonneg ht.1 hai, mul_le_of_le_one_left hai ht.2⟩ } }, { intro h, refine ⟨λ i, x i / a i, λ i, _, funext $ λ i, _⟩, { specialize h i, cases le_total (a i) 0 with hai hai, { rw [sup_eq_left.mpr hai, inf_eq_right.mpr hai] at h, exact ⟨div_nonneg_of_nonpos h.2 hai, div_le_one_of_ge h.1 hai⟩ }, { rw [sup_eq_right.mpr hai, inf_eq_left.mpr hai] at h, exact ⟨div_nonneg h.1 hai, div_le_one_of_le h.2 hai⟩ } }, { specialize h i, simp only [smul_eq_mul, pi.mul_apply], cases eq_or_ne (a i) 0 with hai hai, { rw [hai, inf_idem, sup_idem, ←le_antisymm_iff] at h, rw [hai, ← h, zero_div, zero_mul] }, { rw div_mul_cancel _ hai } } }, end end add_comm_group section normed_space variables [normed_add_comm_group E] [normed_add_comm_group F] [normed_space ℝ E] [normed_space ℝ F] /-- The parallelepiped spanned by a basis, as a compact set with nonempty interior. -/ def basis.parallelepiped (b : basis ι ℝ E) : positive_compacts E := { carrier := parallelepiped b, is_compact' := is_compact_Icc.image (continuous_finset_sum finset.univ (λ (i : ι) (H : i ∈ finset.univ), (continuous_apply i).smul continuous_const)), interior_nonempty' := begin suffices H : set.nonempty (interior (b.equiv_funL.symm.to_homeomorph '' (Icc 0 1))), { dsimp only [parallelepiped], convert H, ext t, exact (b.equiv_fun_symm_apply t).symm }, have A : set.nonempty (interior (Icc (0 : ι → ℝ) 1)), { rw [← pi_univ_Icc, interior_pi_set (@finite_univ ι _)], simp only [univ_pi_nonempty_iff, pi.zero_apply, pi.one_apply, interior_Icc, nonempty_Ioo, zero_lt_one, implies_true_iff] }, rwa [← homeomorph.image_interior, nonempty_image_iff], end } @[simp] lemma basis.coe_parallelepiped (b : basis ι ℝ E) : (b.parallelepiped : set E) = parallelepiped b := rfl @[simp] lemma basis.parallelepiped_reindex (b : basis ι ℝ E) (e : ι ≃ ι') : (b.reindex e).parallelepiped = b.parallelepiped := positive_compacts.ext $ (congr_arg parallelepiped (b.coe_reindex _)).trans (parallelepiped_comp_equiv b e.symm) lemma basis.parallelepiped_map (b : basis ι ℝ E) (e : E ≃ₗ[ℝ] F) : (b.map e).parallelepiped = b.parallelepiped.map e (by haveI := finite_dimensional.of_fintype_basis b; exact e.to_linear_map.continuous_of_finite_dimensional) (by haveI := finite_dimensional.of_fintype_basis (b.map e); exact e.to_linear_map.is_open_map_of_finite_dimensional e.surjective) := positive_compacts.ext (image_parallelepiped e.to_linear_map _).symm variables [measurable_space E] [borel_space E] /-- The Lebesgue measure associated to a basis, giving measure `1` to the parallelepiped spanned by the basis. -/ @[irreducible] def basis.add_haar (b : basis ι ℝ E) : measure E := measure.add_haar_measure b.parallelepiped instance is_add_haar_measure_basis_add_haar (b : basis ι ℝ E) : is_add_haar_measure b.add_haar := by { rw basis.add_haar, exact measure.is_add_haar_measure_add_haar_measure _ } lemma basis.add_haar_self (b : basis ι ℝ E) : b.add_haar (parallelepiped b) = 1 := by { rw [basis.add_haar], exact add_haar_measure_self } end normed_space /-- A finite dimensional inner product space has a canonical measure, the Lebesgue measure giving volume `1` to the parallelepiped spanned by any orthonormal basis. We define the measure using some arbitrary choice of orthonormal basis. The fact that it works with any orthonormal basis is proved in `orthonormal_basis.volume_parallelepiped`. -/ @[priority 100] instance measure_space_of_inner_product_space [normed_add_comm_group E] [inner_product_space ℝ E] [finite_dimensional ℝ E] [measurable_space E] [borel_space E] : measure_space E := { volume := (std_orthonormal_basis ℝ E).to_basis.add_haar } /- This instance should not be necessary, but Lean has difficulties to find it in product situations if we do not declare it explicitly. -/ instance real.measure_space : measure_space ℝ := by apply_instance /-! # Miscellaneous instances for `euclidean_space` In combination with `measure_space_of_inner_product_space`, these put a `measure_space` structure on `euclidean_space`. -/ namespace euclidean_space variables (ι) -- TODO: do we want these instances for `pi_Lp` too? instance : measurable_space (euclidean_space ℝ ι) := measurable_space.pi instance : borel_space (euclidean_space ℝ ι) := pi.borel_space /-- `pi_Lp.equiv` as a `measurable_equiv`. -/ @[simps to_equiv] protected def measurable_equiv : euclidean_space ℝ ι ≃ᵐ (ι → ℝ) := { to_equiv := pi_Lp.equiv _ _, measurable_to_fun := measurable_id, measurable_inv_fun := measurable_id } lemma coe_measurable_equiv : ⇑(euclidean_space.measurable_equiv ι) = pi_Lp.equiv 2 _ := rfl end euclidean_space
11a3e2a54afa09ca690a7183ff6cbd158c77479b
fe25de614feb5587799621c41487aaee0d083b08
/stage0/src/Std/Data/HashMap.lean
7cf5b079a14ec510732f627dfaef16804d0fc7c6
[ "Apache-2.0" ]
permissive
pollend/lean4
e8469c2f5fb8779b773618c3267883cf21fb9fac
c913886938c4b3b83238a3f99673c6c5a9cec270
refs/heads/master
1,687,973,251,481
1,628,039,739,000
1,628,039,739,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
8,308
lean
/- Copyright (c) 2018 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ import Std.Data.AssocList namespace Std universe u v w def HashMapBucket (α : Type u) (β : Type v) := { b : Array (AssocList α β) // b.size > 0 } def HashMapBucket.update {α : Type u} {β : Type v} (data : HashMapBucket α β) (i : USize) (d : AssocList α β) (h : i.toNat < data.val.size) : HashMapBucket α β := ⟨ data.val.uset i d h, by erw [Array.size_set]; exact data.property ⟩ structure HashMapImp (α : Type u) (β : Type v) where size : Nat buckets : HashMapBucket α β def mkHashMapImp {α : Type u} {β : Type v} (nbuckets := 8) : HashMapImp α β := let n := if nbuckets = 0 then 8 else nbuckets; { size := 0, buckets := ⟨ mkArray n AssocList.nil, by simp; cases nbuckets; decide; apply Nat.zeroLtSucc; done ⟩ } namespace HashMapImp variable {α : Type u} {β : Type v} def mkIdx {n : Nat} (h : n > 0) (u : USize) : { u : USize // u.toNat < n } := ⟨u % n, USize.modn_lt _ h⟩ @[inline] def reinsertAux (hashFn : α → UInt64) (data : HashMapBucket α β) (a : α) (b : β) : HashMapBucket α β := let ⟨i, h⟩ := mkIdx data.property (hashFn a |>.toUSize) data.update i (AssocList.cons a b (data.val.uget i h)) h @[inline] def foldBucketsM {δ : Type w} {m : Type w → Type w} [Monad m] (data : HashMapBucket α β) (d : δ) (f : δ → α → β → m δ) : m δ := data.val.foldlM (init := d) fun d b => b.foldlM f d @[inline] def foldBuckets {δ : Type w} (data : HashMapBucket α β) (d : δ) (f : δ → α → β → δ) : δ := Id.run $ foldBucketsM data d f @[inline] def foldM {δ : Type w} {m : Type w → Type w} [Monad m] (f : δ → α → β → m δ) (d : δ) (h : HashMapImp α β) : m δ := foldBucketsM h.buckets d f @[inline] def fold {δ : Type w} (f : δ → α → β → δ) (d : δ) (m : HashMapImp α β) : δ := foldBuckets m.buckets d f @[inline] def forBucketsM {m : Type w → Type w} [Monad m] (data : HashMapBucket α β) (f : α → β → m PUnit) : m PUnit := data.val.forM fun b => b.forM f @[inline] def forM {m : Type w → Type w} [Monad m] (f : α → β → m PUnit) (h : HashMapImp α β) : m PUnit := forBucketsM h.buckets f def findEntry? [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : Option (α × β) := match m with | ⟨_, buckets⟩ => let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize) (buckets.val.uget i h).findEntry? a def find? [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : Option β := match m with | ⟨_, buckets⟩ => let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize) (buckets.val.uget i h).find? a def contains [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : Bool := match m with | ⟨_, buckets⟩ => let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize) (buckets.val.uget i h).contains a -- TODO: remove `partial` by using well-founded recursion partial def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β)) (target : HashMapBucket α β) : HashMapBucket α β := if h : i < source.size then let idx : Fin source.size := ⟨i, h⟩ let es : AssocList α β := source.get idx -- We remove `es` from `source` to make sure we can reuse its memory cells when performing es.foldl let source := source.set idx AssocList.nil let target := es.foldl (reinsertAux hash) target moveEntries (i+1) source target else target def expand [Hashable α] (size : Nat) (buckets : HashMapBucket α β) : HashMapImp α β := let nbuckets := buckets.val.size * 2 have : nbuckets > 0 := Nat.mulPos buckets.property (by decide) let new_buckets : HashMapBucket α β := ⟨mkArray nbuckets AssocList.nil, by simp; assumption⟩ { size := size, buckets := moveEntries 0 buckets.val new_buckets } @[inline] def insert [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) (b : β) : HashMapImp α β × Bool := match m with | ⟨size, buckets⟩ => let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize) let bkt := buckets.val.uget i h if bkt.contains a then (⟨size, buckets.update i (bkt.replace a b) h⟩, true) else let size' := size + 1 let buckets' := buckets.update i (AssocList.cons a b bkt) h if size' ≤ buckets.val.size then ({ size := size', buckets := buckets' }, false) else (expand size' buckets', false) def erase [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : HashMapImp α β := match m with | ⟨ size, buckets ⟩ => let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize) let bkt := buckets.val.uget i h if bkt.contains a then ⟨size - 1, buckets.update i (bkt.erase a) h⟩ else m inductive WellFormed [BEq α] [Hashable α] : HashMapImp α β → Prop where | mkWff : ∀ n, WellFormed (mkHashMapImp n) | insertWff : ∀ m a b, WellFormed m → WellFormed (insert m a b |>.1) | eraseWff : ∀ m a, WellFormed m → WellFormed (erase m a) end HashMapImp def HashMap (α : Type u) (β : Type v) [BEq α] [Hashable α] := { m : HashMapImp α β // m.WellFormed } open Std.HashMapImp def mkHashMap {α : Type u} {β : Type v} [BEq α] [Hashable α] (nbuckets := 8) : HashMap α β := ⟨ mkHashMapImp nbuckets, WellFormed.mkWff nbuckets ⟩ namespace HashMap instance [BEq α] [Hashable α] : Inhabited (HashMap α β) where default := mkHashMap instance [BEq α] [Hashable α] : EmptyCollection (HashMap α β) := ⟨mkHashMap⟩ @[inline] def empty [BEq α] [Hashable α] : HashMap α β := mkHashMap variable {α : Type u} {β : Type v} {_ : BEq α} {_ : Hashable α} def insert (m : HashMap α β) (a : α) (b : β) : HashMap α β := match m with | ⟨ m, hw ⟩ => match h:m.insert a b with | (m', _) => ⟨ m', by have aux := WellFormed.insertWff m a b hw; rw [h] at aux; assumption ⟩ /-- Similar to `insert`, but also returns a Boolean flad indicating whether an existing entry has been replaced with `a -> b`. -/ def insert' (m : HashMap α β) (a : α) (b : β) : HashMap α β × Bool := match m with | ⟨ m, hw ⟩ => match h:m.insert a b with | (m', replaced) => (⟨ m', by have aux := WellFormed.insertWff m a b hw; rw [h] at aux; assumption ⟩, replaced) @[inline] def erase (m : HashMap α β) (a : α) : HashMap α β := match m with | ⟨ m, hw ⟩ => ⟨ m.erase a, WellFormed.eraseWff m a hw ⟩ @[inline] def findEntry? (m : HashMap α β) (a : α) : Option (α × β) := match m with | ⟨ m, _ ⟩ => m.findEntry? a @[inline] def find? (m : HashMap α β) (a : α) : Option β := match m with | ⟨ m, _ ⟩ => m.find? a @[inline] def findD (m : HashMap α β) (a : α) (b₀ : β) : β := (m.find? a).getD b₀ @[inline] def find! [Inhabited β] (m : HashMap α β) (a : α) : β := match m.find? a with | some b => b | none => panic! "key is not in the map" @[inline] def getOp (self : HashMap α β) (idx : α) : Option β := self.find? idx @[inline] def contains (m : HashMap α β) (a : α) : Bool := match m with | ⟨ m, _ ⟩ => m.contains a @[inline] def foldM {δ : Type w} {m : Type w → Type w} [Monad m] (f : δ → α → β → m δ) (init : δ) (h : HashMap α β) : m δ := match h with | ⟨ h, _ ⟩ => h.foldM f init @[inline] def fold {δ : Type w} (f : δ → α → β → δ) (init : δ) (m : HashMap α β) : δ := match m with | ⟨ m, _ ⟩ => m.fold f init @[inline] def forM {m : Type w → Type w} [Monad m] (f : α → β → m PUnit) (h : HashMap α β) : m PUnit := match h with | ⟨ h, _ ⟩ => h.forM f @[inline] def size (m : HashMap α β) : Nat := match m with | ⟨ {size := sz, ..}, _ ⟩ => sz @[inline] def isEmpty (m : HashMap α β) : Bool := m.size = 0 def toList (m : HashMap α β) : List (α × β) := m.fold (init := []) fun r k v => (k, v)::r def toArray (m : HashMap α β) : Array (α × β) := m.fold (init := #[]) fun r k v => r.push (k, v) def numBuckets (m : HashMap α β) : Nat := m.val.buckets.val.size end HashMap end Std
4e53d23fac260a66895136f834c1ebc7555aa766
38bf3fd2bb651ab70511408fcf70e2029e2ba310
/src/category_theory/limits/functor_category.lean
3cd956a5da03962e7b1a8889d26a48df4ad6984e
[ "Apache-2.0" ]
permissive
JaredCorduan/mathlib
130392594844f15dad65a9308c242551bae6cd2e
d5de80376088954d592a59326c14404f538050a1
refs/heads/master
1,595,862,206,333
1,570,816,457,000
1,570,816,457,000
209,134,499
0
0
Apache-2.0
1,568,746,811,000
1,568,746,811,000
null
UTF-8
Lean
false
false
4,863
lean
/- Copyright (c) 2018 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.products.basic import category_theory.limits.preserves open category_theory category_theory.category namespace category_theory.limits universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation variables {C : Type u} [𝒞 : category.{v} C] include 𝒞 variables {J K : Type v} [small_category J] [small_category K] @[simp] lemma cone.functor_w {F : J ⥤ (K ⥤ C)} (c : cone F) {j j' : J} (f : j ⟶ j') (k : K) : (c.π.app j).app k ≫ (F.map f).app k = (c.π.app j').app k := by convert ←nat_trans.congr_app (c.π.naturality f).symm k; apply id_comp @[simp] lemma cocone.functor_w {F : J ⥤ (K ⥤ C)} (c : cocone F) {j j' : J} (f : j ⟶ j') (k : K) : (F.map f).app k ≫ (c.ι.app j').app k = (c.ι.app j).app k := by convert ←nat_trans.congr_app (c.ι.naturality f) k; apply comp_id @[simp] def functor_category_limit_cone [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) : cone F := { X := F.flip ⋙ lim, π := { app := λ j, { app := λ k, limit.π (F.flip.obj k) j }, naturality' := λ j j' f, by ext k; convert (limit.w (F.flip.obj k) _).symm using 1; apply id_comp } } @[simp] def functor_category_colimit_cocone [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) : cocone F := { X := F.flip ⋙ colim, ι := { app := λ j, { app := λ k, colimit.ι (F.flip.obj k) j }, naturality' := λ j j' f, by ext k; convert (colimit.w (F.flip.obj k) _) using 1; apply comp_id } } @[simp] def evaluate_functor_category_limit_cone [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) : ((evaluation K C).obj k).map_cone (functor_category_limit_cone F) ≅ limit.cone (F.flip.obj k) := cones.ext (iso.refl _) (by tidy) @[simp] def evaluate_functor_category_colimit_cocone [has_colimits_of_shape J C] (F : J ⥤ K ⥤ C) (k : K) : ((evaluation K C).obj k).map_cocone (functor_category_colimit_cocone F) ≅ colimit.cocone (F.flip.obj k) := cocones.ext (iso.refl _) (by tidy) def functor_category_is_limit_cone [has_limits_of_shape J C] (F : J ⥤ K ⥤ C) : is_limit (functor_category_limit_cone F) := { lift := λ s, { app := λ k, limit.lift (F.flip.obj k) (((evaluation K C).obj k).map_cone s) }, uniq' := λ s m w, begin ext1 k, exact is_limit.uniq _ (((evaluation K C).obj k).map_cone s) (m.app k) (λ j, nat_trans.congr_app (w j) k) end } def functor_category_is_colimit_cocone [has_colimits_of_shape.{v} J C] (F : J ⥤ K ⥤ C) : is_colimit (functor_category_colimit_cocone F) := { desc := λ s, { app := λ k, colimit.desc (F.flip.obj k) (((evaluation K C).obj k).map_cocone s) }, uniq' := λ s m w, begin ext1 k, exact is_colimit.uniq _ (((evaluation K C).obj k).map_cocone s) (m.app k) (λ j, nat_trans.congr_app (w j) k) end } instance functor_category_has_limits_of_shape [has_limits_of_shape J C] : has_limits_of_shape J (K ⥤ C) := { has_limit := λ F, { cone := functor_category_limit_cone F, is_limit := functor_category_is_limit_cone F } } instance functor_category_has_colimits_of_shape [has_colimits_of_shape J C] : has_colimits_of_shape J (K ⥤ C) := { has_colimit := λ F, { cocone := functor_category_colimit_cocone F, is_colimit := functor_category_is_colimit_cocone F } } instance functor_category_has_limits [has_limits.{v} C] : has_limits.{v} (K ⥤ C) := { has_limits_of_shape := λ J 𝒥, by resetI; apply_instance } instance functor_category_has_colimits [has_colimits.{v} C] : has_colimits.{v} (K ⥤ C) := { has_colimits_of_shape := λ J 𝒥, by resetI; apply_instance } instance evaluation_preserves_limits_of_shape [has_limits_of_shape J C] (k : K) : preserves_limits_of_shape J ((evaluation K C).obj k) := { preserves_limit := λ F, preserves_limit_of_preserves_limit_cone (limit.is_limit _) $ is_limit.of_iso_limit (limit.is_limit _) (evaluate_functor_category_limit_cone F k).symm } instance evaluation_preserves_colimits_of_shape [has_colimits_of_shape J C] (k : K) : preserves_colimits_of_shape J ((evaluation K C).obj k) := { preserves_colimit := λ F, preserves_colimit_of_preserves_colimit_cocone (colimit.is_colimit _) $ is_colimit.of_iso_colimit (colimit.is_colimit _) (evaluate_functor_category_colimit_cocone F k).symm } instance evaluation_preserves_limits [has_limits.{v} C] (k : K) : preserves_limits ((evaluation K C).obj k) := { preserves_limits_of_shape := λ J 𝒥, by resetI; apply_instance } instance evaluation_preserves_colimits [has_colimits.{v} C] (k : K) : preserves_colimits ((evaluation K C).obj k) := { preserves_colimits_of_shape := λ J 𝒥, by resetI; apply_instance } end category_theory.limits
263c16b6cc2c871b7b95f6340ec28dabf057c9a9
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/instuniv.lean
7a63752a497c76e5fb44e9efed99d7054c2b3d85
[ "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
459
lean
import Lean open Lean unsafe def tst : IO Unit := withImportModules [{module := `Init.Data.Array}] {} 0 fun env => match env.find? `Array.foldl with | some info => do IO.println (info.instantiateTypeLevelParams [levelZero, levelZero]) IO.println (info.instantiateValueLevelParams! [levelZero, levelZero]) IO.println (info.instantiateValueLevelParams! [levelZero]) | none => IO.println "Array.foldl not found" #eval tst
e12e6431b9d8282b6bbb5e1b13d307d7aaa490d5
05f637fa14ac28031cb1ea92086a0f4eb23ff2b1
/tests/lean/simp18.lean
ba2b925da10529aa241dcb43e2eb1a2c1d7fde83
[ "Apache-2.0" ]
permissive
codyroux/lean0.1
1ce92751d664aacff0529e139083304a7bbc8a71
0dc6fb974aa85ed6f305a2f4b10a53a44ee5f0ef
refs/heads/master
1,610,830,535,062
1,402,150,480,000
1,402,150,480,000
19,588,851
2
0
null
null
null
null
UTF-8
Lean
false
false
901
lean
variable vec : Nat → Type variable concat {n m : Nat} (v : vec n) (w : vec m) : vec (n + m) infixl 65 ; : concat axiom concat_assoc {n1 n2 n3 : Nat} (v1 : vec n1) (v2 : vec n2) (v3 : vec n3) : (v1 ; v2) ; v3 = cast (to_heq (congr2 vec (symm (Nat::add_assoc n1 n2 n3)))) (v1 ; (v2 ; v3)) variable empty : vec 0 axiom concat_empty {n : Nat} (v : vec n) : v ; empty = cast (to_heq (congr2 vec (symm (Nat::add_zeror n)))) v rewrite_set simple add_rewrite concat_assoc concat_empty Nat::add_assoc Nat::add_zeror : simple variable n : Nat variable v : vec n variable w : vec n (* local opts = options({"simplifier", "heq"}, true) local t = parse_lean([[ (v ; w) ; empty ; (v ; empty) ]]) print(t) print("===>") local t2, pr = simplify(t, "simple", opts) print(t2) print(pr) get_environment():type_check(pr) *)
dd687b066a34b141ccd4d17fba9cdaec0b917061
d642a6b1261b2cbe691e53561ac777b924751b63
/src/topology/uniform_space/basic.lean
59e457abe80f12b778a72413379781427c640b19
[ "Apache-2.0" ]
permissive
cipher1024/mathlib
fee56b9954e969721715e45fea8bcb95f9dc03fe
d077887141000fefa5a264e30fa57520e9f03522
refs/heads/master
1,651,806,490,504
1,573,508,694,000
1,573,508,694,000
107,216,176
0
0
Apache-2.0
1,647,363,136,000
1,508,213,014,000
Lean
UTF-8
Lean
false
false
41,945
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot Theory of uniform spaces. Uniform spaces are a generalization of metric spaces and topological groups. Many concepts directly generalize to uniform spaces, e.g. * completeness * extension of uniform continuous functions to complete spaces * uniform contiunuity & embedding * totally bounded * totally bounded ∧ complete → compact The central concept of uniform spaces is its uniformity: a filter relating two elements of the space. This filter is reflexive, symmetric and transitive. So a set (i.e. a relation) in this filter represents a 'distance': it is reflexive, symmetric and the uniformity contains a set for which the `triangular` rule holds. The formalization is mostly based on the books: N. Bourbaki: General Topology I. M. James: Topologies and Uniformities A major difference is that this formalization is heavily based on the filter library. -/ import order.filter.basic order.filter.lift topology.separation open set lattice filter classical open_locale classical set_option eqn_compiler.zeta true universes u section variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*} /-- The identity relation, or the graph of the identity function -/ def id_rel {α : Type*} := {p : α × α | p.1 = p.2} @[simp] theorem mem_id_rel {a b : α} : (a, b) ∈ @id_rel α ↔ a = b := iff.rfl @[simp] theorem id_rel_subset {s : set (α × α)} : id_rel ⊆ s ↔ ∀ a, (a, a) ∈ s := by simp [subset_def]; exact forall_congr (λ a, by simp) /-- The composition of relations -/ def comp_rel {α : Type u} (r₁ r₂ : set (α×α)) := {p : α × α | ∃z:α, (p.1, z) ∈ r₁ ∧ (z, p.2) ∈ r₂} @[simp] theorem mem_comp_rel {r₁ r₂ : set (α×α)} {x y : α} : (x, y) ∈ comp_rel r₁ r₂ ↔ ∃ z, (x, z) ∈ r₁ ∧ (z, y) ∈ r₂ := iff.rfl @[simp] theorem swap_id_rel : prod.swap '' id_rel = @id_rel α := set.ext $ assume ⟨a, b⟩, by simp [image_swap_eq_preimage_swap]; exact eq_comm theorem monotone_comp_rel [preorder β] {f g : β → set (α×α)} (hf : monotone f) (hg : monotone g) : monotone (λx, comp_rel (f x) (g x)) := assume a b h p ⟨z, h₁, h₂⟩, ⟨z, hf h h₁, hg h h₂⟩ lemma prod_mk_mem_comp_rel {a b c : α} {s t : set (α×α)} (h₁ : (a, c) ∈ s) (h₂ : (c, b) ∈ t) : (a, b) ∈ comp_rel s t := ⟨c, h₁, h₂⟩ @[simp] lemma id_comp_rel {r : set (α×α)} : comp_rel id_rel r = r := set.ext $ assume ⟨a, b⟩, by simp lemma comp_rel_assoc {r s t : set (α×α)} : comp_rel (comp_rel r s) t = comp_rel r (comp_rel s t) := by ext p; cases p; simp only [mem_comp_rel]; tauto /-- This core description of a uniform space is outside of the type class hierarchy. It is useful for constructions of uniform spaces, when the topology is derived from the uniform space. -/ structure uniform_space.core (α : Type u) := (uniformity : filter (α × α)) (refl : principal id_rel ≤ uniformity) (symm : tendsto prod.swap uniformity uniformity) (comp : uniformity.lift' (λs, comp_rel s s) ≤ uniformity) def uniform_space.core.mk' {α : Type u} (U : filter (α × α)) (refl : ∀ (r ∈ U) x, (x, x) ∈ r) (symm : ∀ r ∈ U, {p | prod.swap p ∈ r} ∈ U) (comp : ∀ r ∈ U, ∃ t ∈ U, comp_rel t t ⊆ r) : uniform_space.core α := ⟨U, λ r ru, id_rel_subset.2 (refl _ ru), symm, begin intros r ru, rw [mem_lift'_sets], exact comp _ ru, apply monotone_comp_rel; exact monotone_id, end⟩ /-- A uniform space generates a topological space -/ def uniform_space.core.to_topological_space {α : Type u} (u : uniform_space.core α) : topological_space α := { is_open := λs, ∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ u.uniformity, is_open_univ := by simp; intro; exact univ_mem_sets, is_open_inter := assume s t hs ht x ⟨xs, xt⟩, by filter_upwards [hs x xs, ht x xt]; simp {contextual := tt}, is_open_sUnion := assume s hs x ⟨t, ts, xt⟩, by filter_upwards [hs t ts x xt] assume p ph h, ⟨t, ts, ph h⟩ } lemma uniform_space.core_eq : ∀{u₁ u₂ : uniform_space.core α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | ⟨u₁, _, _, _⟩ ⟨u₂, _, _, _⟩ h := have u₁ = u₂, from h, by simp [*] /-- A uniform space is a generalization of the "uniform" topological aspects of a metric space. It consists of a filter on `α × α` called the "uniformity", which satisfies properties analogous to the reflexivity, symmetry, and triangle properties of a metric. A metric space has a natural uniformity, and a uniform space has a natural topology. A topological group also has a natural uniformity, even when it is not metrizable. -/ class uniform_space (α : Type u) extends topological_space α, uniform_space.core α := (is_open_uniformity : ∀s, is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ uniformity)) @[pattern] def uniform_space.mk' {α} (t : topological_space α) (c : uniform_space.core α) (is_open_uniformity : ∀s:set α, t.is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ c.uniformity)) : uniform_space α := ⟨c, is_open_uniformity⟩ def uniform_space.of_core {α : Type u} (u : uniform_space.core α) : uniform_space α := { to_core := u, to_topological_space := u.to_topological_space, is_open_uniformity := assume a, iff.refl _ } def uniform_space.of_core_eq {α : Type u} (u : uniform_space.core α) (t : topological_space α) (h : t = u.to_topological_space) : uniform_space α := { to_core := u, to_topological_space := t, is_open_uniformity := assume a, h.symm ▸ iff.refl _ } lemma uniform_space.to_core_to_topological_space (u : uniform_space α) : u.to_core.to_topological_space = u.to_topological_space := topological_space_eq $ funext $ assume s, by rw [uniform_space.core.to_topological_space, uniform_space.is_open_uniformity] @[ext] lemma uniform_space_eq : ∀{u₁ u₂ : uniform_space α}, u₁.uniformity = u₂.uniformity → u₁ = u₂ | (uniform_space.mk' t₁ u₁ o₁) (uniform_space.mk' t₂ u₂ o₂) h := have u₁ = u₂, from uniform_space.core_eq h, have t₁ = t₂, from topological_space_eq $ funext $ assume s, by rw [o₁, o₂]; simp [this], by simp [*] lemma uniform_space.of_core_eq_to_core (u : uniform_space α) (t : topological_space α) (h : t = u.to_core.to_topological_space) : uniform_space.of_core_eq u.to_core t h = u := uniform_space_eq rfl section uniform_space variables [uniform_space α] /-- The uniformity is a filter on α × α (inferred from an ambient uniform space structure on α). -/ def uniformity (α : Type u) [uniform_space α] : filter (α × α) := (@uniform_space.to_core α _).uniformity localized "notation `𝓤` := uniformity" in uniformity lemma is_open_uniformity {s : set α} : is_open s ↔ (∀x∈s, { p : α × α | p.1 = x → p.2 ∈ s } ∈ 𝓤 α) := uniform_space.is_open_uniformity s lemma refl_le_uniformity : principal id_rel ≤ 𝓤 α := (@uniform_space.to_core α _).refl lemma refl_mem_uniformity {x : α} {s : set (α × α)} (h : s ∈ 𝓤 α) : (x, x) ∈ s := refl_le_uniformity h rfl lemma symm_le_uniformity : map (@prod.swap α α) (𝓤 _) ≤ (𝓤 _) := (@uniform_space.to_core α _).symm lemma comp_le_uniformity : (𝓤 α).lift' (λs:set (α×α), comp_rel s s) ≤ 𝓤 α := (@uniform_space.to_core α _).comp lemma tendsto_swap_uniformity : tendsto (@prod.swap α α) (𝓤 α) (𝓤 α) := symm_le_uniformity lemma tendsto_const_uniformity {a : α} {f : filter β} : tendsto (λ _, (a, a)) f (𝓤 α) := assume s hs, show {x | (a, a) ∈ s} ∈ f, from univ_mem_sets' $ assume b, refl_mem_uniformity hs lemma comp_mem_uniformity_sets {s : set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, comp_rel t t ⊆ s := have s ∈ (𝓤 α).lift' (λt:set (α×α), comp_rel t t), from comp_le_uniformity hs, (mem_lift'_sets $ monotone_comp_rel monotone_id monotone_id).mp this lemma symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀a b, (a, b) ∈ t → (b, a) ∈ t) ∧ t ⊆ s := have preimage prod.swap s ∈ 𝓤 α, from symm_le_uniformity hs, ⟨s ∩ preimage prod.swap s, inter_mem_sets hs this, assume a b ⟨h₁, h₂⟩, ⟨h₂, h₁⟩, inter_subset_left _ _⟩ lemma comp_symm_of_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) : ∃ t ∈ 𝓤 α, (∀{a b}, (a, b) ∈ t → (b, a) ∈ t) ∧ comp_rel t t ⊆ s := let ⟨t, ht₁, ht₂⟩ := comp_mem_uniformity_sets hs in let ⟨t', ht', ht'₁, ht'₂⟩ := symm_of_uniformity ht₁ in ⟨t', ht', ht'₁, subset.trans (monotone_comp_rel monotone_id monotone_id ht'₂) ht₂⟩ lemma uniformity_le_symm : 𝓤 α ≤ (@prod.swap α α) <$> 𝓤 α := by rw [map_swap_eq_comap_swap]; from map_le_iff_le_comap.1 tendsto_swap_uniformity lemma uniformity_eq_symm : 𝓤 α = (@prod.swap α α) <$> 𝓤 α := le_antisymm uniformity_le_symm symm_le_uniformity theorem uniformity_lift_le_swap {g : set (α×α) → filter β} {f : filter β} (hg : monotone g) (h : (𝓤 α).lift (λs, g (preimage prod.swap s)) ≤ f) : (𝓤 α).lift g ≤ f := calc (𝓤 α).lift g ≤ (filter.map (@prod.swap α α) $ 𝓤 α).lift g : lift_mono uniformity_le_symm (le_refl _) ... ≤ _ : by rw [map_lift_eq2 hg, image_swap_eq_preimage_swap]; exact h lemma uniformity_lift_le_comp {f : set (α×α) → filter β} (h : monotone f) : (𝓤 α).lift (λs, f (comp_rel s s)) ≤ (𝓤 α).lift f := calc (𝓤 α).lift (λs, f (comp_rel s s)) = ((𝓤 α).lift' (λs:set (α×α), comp_rel s s)).lift f : begin rw [lift_lift'_assoc], exact monotone_comp_rel monotone_id monotone_id, exact h end ... ≤ (𝓤 α).lift f : lift_mono comp_le_uniformity (le_refl _) lemma comp_le_uniformity3 : (𝓤 α).lift' (λs:set (α×α), comp_rel s (comp_rel s s)) ≤ (𝓤 α) := calc (𝓤 α).lift' (λd, comp_rel d (comp_rel d d)) = (𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), comp_rel s (comp_rel t t))) : begin rw [lift_lift'_same_eq_lift'], exact (assume x, monotone_comp_rel monotone_const $ monotone_comp_rel monotone_id monotone_id), exact (assume x, monotone_comp_rel monotone_id monotone_const), end ... ≤ (𝓤 α).lift (λs, (𝓤 α).lift' (λt:set(α×α), comp_rel s t)) : lift_mono' $ assume s hs, @uniformity_lift_le_comp α _ _ (principal ∘ comp_rel s) $ monotone_principal.comp (monotone_comp_rel monotone_const monotone_id) ... = (𝓤 α).lift' (λs:set(α×α), comp_rel s s) : lift_lift'_same_eq_lift' (assume s, monotone_comp_rel monotone_const monotone_id) (assume s, monotone_comp_rel monotone_id monotone_const) ... ≤ (𝓤 α) : comp_le_uniformity lemma mem_nhds_uniformity_iff {x : α} {s : set α} : s ∈ nhds x ↔ {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α := ⟨ begin simp only [mem_nhds_sets_iff, is_open_uniformity, and_imp, exists_imp_distrib], exact assume t ts ht xt, by filter_upwards [ht x xt] assume ⟨x', y⟩ h eq, ts $ h eq end, assume hs, mem_nhds_sets_iff.mpr ⟨{x | {p : α × α | p.1 = x → p.2 ∈ s} ∈ 𝓤 α}, assume x' hx', refl_mem_uniformity hx' rfl, is_open_uniformity.mpr $ assume x' hx', let ⟨t, ht, tr⟩ := comp_mem_uniformity_sets hx' in by filter_upwards [ht] assume ⟨a, b⟩ hp' (hax' : a = x'), by filter_upwards [ht] assume ⟨a, b'⟩ hp'' (hab : a = b), have hp : (x', b) ∈ t, from hax' ▸ hp', have (b, b') ∈ t, from hab ▸ hp'', have (x', b') ∈ comp_rel t t, from ⟨b, hp, this⟩, show b' ∈ s, from tr this rfl, hs⟩⟩ lemma nhds_eq_comap_uniformity {x : α} : nhds x = (𝓤 α).comap (prod.mk x) := by ext s; rw [mem_nhds_uniformity_iff, mem_comap_sets]; from iff.intro (assume hs, ⟨_, hs, assume x hx, hx rfl⟩) (assume ⟨t, h, ht⟩, (𝓤 α).sets_of_superset h $ assume ⟨p₁, p₂⟩ hp (h : p₁ = x), ht $ by simp [h.symm, hp]) lemma nhds_eq_uniformity {x : α} : nhds x = (𝓤 α).lift' (λs:set (α×α), {y | (x, y) ∈ s}) := begin ext s, rw [mem_lift'_sets], tactic.swap, apply monotone_preimage, simp [mem_nhds_uniformity_iff], exact ⟨assume h, ⟨_, h, assume y h, h rfl⟩, assume ⟨t, h₁, h₂⟩, (𝓤 α).sets_of_superset h₁ $ assume ⟨x', y⟩ hp (eq : x' = x), h₂ $ show (x, y) ∈ t, from eq ▸ hp⟩ end lemma mem_nhds_left (x : α) {s : set (α×α)} (h : s ∈ 𝓤 α) : {y : α | (x, y) ∈ s} ∈ nhds x := have nhds x ≤ principal {y : α | (x, y) ∈ s}, by rw [nhds_eq_uniformity]; exact infi_le_of_le s (infi_le _ h), by simp at this; assumption lemma mem_nhds_right (y : α) {s : set (α×α)} (h : s ∈ 𝓤 α) : {x : α | (x, y) ∈ s} ∈ nhds y := mem_nhds_left _ (symm_le_uniformity h) lemma tendsto_right_nhds_uniformity {a : α} : tendsto (λa', (a', a)) (nhds a) (𝓤 α) := assume s, mem_nhds_right a lemma tendsto_left_nhds_uniformity {a : α} : tendsto (λa', (a, a')) (nhds a) (𝓤 α) := assume s, mem_nhds_left a lemma lift_nhds_left {x : α} {g : set α → filter β} (hg : monotone g) : (nhds x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) := eq.trans begin rw [nhds_eq_uniformity], exact (filter.lift_assoc $ monotone_principal.comp $ monotone_preimage.comp monotone_preimage ) end (congr_arg _ $ funext $ assume s, filter.lift_principal hg) lemma lift_nhds_right {x : α} {g : set α → filter β} (hg : monotone g) : (nhds x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (y, x) ∈ s}) := calc (nhds x).lift g = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : lift_nhds_left hg ... = ((@prod.swap α α) <$> (𝓤 α)).lift (λs:set (α×α), g {y | (x, y) ∈ s}) : by rw [←uniformity_eq_symm] ... = (𝓤 α).lift (λs:set (α×α), g {y | (x, y) ∈ image prod.swap s}) : map_lift_eq2 $ hg.comp monotone_preimage ... = _ : by simp [image_swap_eq_preimage_swap] lemma nhds_nhds_eq_uniformity_uniformity_prod {a b : α} : filter.prod (nhds a) (nhds b) = (𝓤 α).lift (λs:set (α×α), (𝓤 α).lift' (λt:set (α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ t})) := begin rw [prod_def], show (nhds a).lift (λs:set α, (nhds b).lift (λt:set α, principal (set.prod s t))) = _, rw [lift_nhds_right], apply congr_arg, funext s, rw [lift_nhds_left], refl, exact monotone_principal.comp (monotone_prod monotone_const monotone_id), exact (monotone_lift' monotone_const $ monotone_lam $ assume x, monotone_prod monotone_id monotone_const) end lemma nhds_eq_uniformity_prod {a b : α} : nhds (a, b) = (𝓤 α).lift' (λs:set (α×α), set.prod {y : α | (y, a) ∈ s} {y : α | (b, y) ∈ s}) := begin rw [nhds_prod_eq, nhds_nhds_eq_uniformity_uniformity_prod, lift_lift'_same_eq_lift'], { intro s, exact monotone_prod monotone_const monotone_preimage }, { intro t, exact monotone_prod monotone_preimage monotone_const } end lemma nhdset_of_mem_uniformity {d : set (α×α)} (s : set (α×α)) (hd : d ∈ 𝓤 α) : ∃(t : set (α×α)), is_open t ∧ s ⊆ t ∧ t ⊆ {p | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} := let cl_d := {p:α×α | ∃x y, (p.1, x) ∈ d ∧ (x, y) ∈ s ∧ (y, p.2) ∈ d} in have ∀p ∈ s, ∃t ⊆ cl_d, is_open t ∧ p ∈ t, from assume ⟨x, y⟩ hp, mem_nhds_sets_iff.mp $ show cl_d ∈ nhds (x, y), begin rw [nhds_eq_uniformity_prod, mem_lift'_sets], exact ⟨d, hd, assume ⟨a, b⟩ ⟨ha, hb⟩, ⟨x, y, ha, hp, hb⟩⟩, exact monotone_prod monotone_preimage monotone_preimage end, have ∃t:(Π(p:α×α) (h:p ∈ s), set (α×α)), ∀p, ∀h:p ∈ s, t p h ⊆ cl_d ∧ is_open (t p h) ∧ p ∈ t p h, by simp [classical.skolem] at this; simp; assumption, match this with | ⟨t, ht⟩ := ⟨(⋃ p:α×α, ⋃ h : p ∈ s, t p h : set (α×α)), is_open_Union $ assume (p:α×α), is_open_Union $ assume hp, (ht p hp).right.left, assume ⟨a, b⟩ hp, begin simp; exact ⟨a, b, hp, (ht (a,b) hp).right.right⟩ end, Union_subset $ assume p, Union_subset $ assume hp, (ht p hp).left⟩ end lemma closure_eq_inter_uniformity {t : set (α×α)} : closure t = (⋂ d ∈ 𝓤 α, comp_rel d (comp_rel t d)) := set.ext $ assume ⟨a, b⟩, calc (a, b) ∈ closure t ↔ (nhds (a, b) ⊓ principal t ≠ ⊥) : by simp [closure_eq_nhds] ... ↔ (((@prod.swap α α) <$> 𝓤 α).lift' (λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ principal t ≠ ⊥) : by rw [←uniformity_eq_symm, nhds_eq_uniformity_prod] ... ↔ ((map (@prod.swap α α) (𝓤 α)).lift' (λ (s : set (α × α)), set.prod {x : α | (x, a) ∈ s} {y : α | (b, y) ∈ s}) ⊓ principal t ≠ ⊥) : by refl ... ↔ ((𝓤 α).lift' (λ (s : set (α × α)), set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s}) ⊓ principal t ≠ ⊥) : begin rw [map_lift'_eq2], simp [image_swap_eq_preimage_swap, function.comp], exact monotone_prod monotone_preimage monotone_preimage end ... ↔ (∀s ∈ 𝓤 α, ∃x, x ∈ set.prod {y : α | (a, y) ∈ s} {x : α | (x, b) ∈ s} ∩ t) : begin rw [lift'_inf_principal_eq, lift'_neq_bot_iff], apply forall_congr, intro s, rw [ne_empty_iff_exists_mem], exact monotone_inter (monotone_prod monotone_preimage monotone_preimage) monotone_const end ... ↔ (∀ s ∈ 𝓤 α, (a, b) ∈ comp_rel s (comp_rel t s)) : forall_congr $ assume s, forall_congr $ assume hs, ⟨assume ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩, ⟨x, hx, y, hxyt, hy⟩, assume ⟨x, hx, y, hxyt, hy⟩, ⟨⟨x, y⟩, ⟨⟨hx, hy⟩, hxyt⟩⟩⟩ ... ↔ _ : by simp lemma uniformity_eq_uniformity_closure : 𝓤 α = (𝓤 α).lift' closure := le_antisymm (le_infi $ assume s, le_infi $ assume hs, by simp; filter_upwards [hs] subset_closure) (calc (𝓤 α).lift' closure ≤ (𝓤 α).lift' (λd, comp_rel d (comp_rel d d)) : lift'_mono' (by intros s hs; rw [closure_eq_inter_uniformity]; exact bInter_subset_of_mem hs) ... ≤ (𝓤 α) : comp_le_uniformity3) lemma uniformity_eq_uniformity_interior : 𝓤 α = (𝓤 α).lift' interior := le_antisymm (le_infi $ assume d, le_infi $ assume hd, let ⟨s, hs, hs_comp⟩ := (mem_lift'_sets $ monotone_comp_rel monotone_id $ monotone_comp_rel monotone_id monotone_id).mp (comp_le_uniformity3 hd) in let ⟨t, ht, hst, ht_comp⟩ := nhdset_of_mem_uniformity s hs in have s ⊆ interior d, from calc s ⊆ t : hst ... ⊆ interior d : (subset_interior_iff_subset_of_open ht).mpr $ assume x, assume : x ∈ t, let ⟨x, y, h₁, h₂, h₃⟩ := ht_comp this in hs_comp ⟨x, h₁, y, h₂, h₃⟩, have interior d ∈ 𝓤 α, by filter_upwards [hs] this, by simp [this]) (assume s hs, ((𝓤 α).lift' interior).sets_of_superset (mem_lift' hs) interior_subset) lemma interior_mem_uniformity {s : set (α × α)} (hs : s ∈ 𝓤 α) : interior s ∈ 𝓤 α := by rw [uniformity_eq_uniformity_interior]; exact mem_lift' hs lemma mem_uniformity_is_closed {s : set (α×α)} (h : s ∈ 𝓤 α) : ∃t ∈ 𝓤 α, is_closed t ∧ t ⊆ s := have s ∈ (𝓤 α).lift' closure, by rwa [uniformity_eq_uniformity_closure] at h, have ∃ t ∈ 𝓤 α, closure t ⊆ s, by rwa [mem_lift'_sets] at this; apply closure_mono, let ⟨t, ht, hst⟩ := this in ⟨closure t, (𝓤 α).sets_of_superset ht subset_closure, is_closed_closure, hst⟩ /- uniform continuity -/ def uniform_continuous [uniform_space β] (f : α → β) := tendsto (λx:α×α, (f x.1, f x.2)) (𝓤 α) (𝓤 β) theorem uniform_continuous_def [uniform_space β] {f : α → β} : uniform_continuous f ↔ ∀ r ∈ 𝓤 β, {x : α × α | (f x.1, f x.2) ∈ r} ∈ 𝓤 α := iff.rfl lemma uniform_continuous_of_const [uniform_space β] {c : α → β} (h : ∀a b, c a = c b) : uniform_continuous c := have (λ (x : α × α), (c (x.fst), c (x.snd))) ⁻¹' id_rel = univ, from eq_univ_iff_forall.2 $ assume ⟨a, b⟩, h a b, le_trans (map_le_iff_le_comap.2 $ by simp [comap_principal, this, univ_mem_sets]) refl_le_uniformity lemma uniform_continuous_id : uniform_continuous (@id α) := by simp [uniform_continuous]; exact tendsto_id lemma uniform_continuous_const [uniform_space β] {b : β} : uniform_continuous (λa:α, b) := @tendsto_const_uniformity _ _ _ b (𝓤 α) lemma uniform_continuous.comp [uniform_space β] [uniform_space γ] {g : β → γ} {f : α → β} (hg : uniform_continuous g) (hf : uniform_continuous f) : uniform_continuous (g ∘ f) := hg.comp hf end uniform_space end open_locale uniformity section constructions variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*} {ι : Sort*} instance : partial_order (uniform_space α) := { le := λt s, t.uniformity ≤ s.uniformity, le_antisymm := assume t s h₁ h₂, uniform_space_eq $ le_antisymm h₁ h₂, le_refl := assume t, le_refl _, le_trans := assume a b c h₁ h₂, le_trans h₁ h₂ } instance : has_Inf (uniform_space α) := ⟨assume s, uniform_space.of_core { uniformity := (⨅u∈s, @uniformity α u), refl := le_infi $ assume u, le_infi $ assume hu, u.refl, symm := le_infi $ assume u, le_infi $ assume hu, le_trans (map_mono $ infi_le_of_le _ $ infi_le _ hu) u.symm, comp := le_infi $ assume u, le_infi $ assume hu, le_trans (lift'_mono (infi_le_of_le _ $ infi_le _ hu) $ le_refl _) u.comp }⟩ private lemma Inf_le {tt : set (uniform_space α)} {t : uniform_space α} (h : t ∈ tt) : Inf tt ≤ t := show (⨅u∈tt, @uniformity α u) ≤ t.uniformity, from infi_le_of_le t $ infi_le _ h private lemma le_Inf {tt : set (uniform_space α)} {t : uniform_space α} (h : ∀t'∈tt, t ≤ t') : t ≤ Inf tt := show t.uniformity ≤ (⨅u∈tt, @uniformity α u), from le_infi $ assume t', le_infi $ assume ht', h t' ht' instance : has_top (uniform_space α) := ⟨uniform_space.of_core { uniformity := ⊤, refl := le_top, symm := le_top, comp := le_top }⟩ instance : has_bot (uniform_space α) := ⟨{ to_topological_space := ⊥, uniformity := principal id_rel, refl := le_refl _, symm := by simp [tendsto]; apply subset.refl, comp := begin rw [lift'_principal], {simp}, exact monotone_comp_rel monotone_id monotone_id end, is_open_uniformity := assume s, by simp [is_open_fold, subset_def, id_rel] {contextual := tt } } ⟩ instance : complete_lattice (uniform_space α) := { sup := λa b, Inf {x | a ≤ x ∧ b ≤ x}, le_sup_left := λ a b, le_Inf (λ _ ⟨h, _⟩, h), le_sup_right := λ a b, le_Inf (λ _ ⟨_, h⟩, h), sup_le := λ a b c h₁ h₂, Inf_le ⟨h₁, h₂⟩, inf := λ a b, Inf {a, b}, le_inf := λ a b c h₁ h₂, le_Inf (λ u h, by { cases h, exact h.symm ▸ h₂, exact (mem_singleton_iff.1 h).symm ▸ h₁ }), inf_le_left := λ a b, Inf_le (by simp), inf_le_right := λ a b, Inf_le (by simp), top := ⊤, le_top := λ a, show a.uniformity ≤ ⊤, from le_top, bot := ⊥, bot_le := λ u, u.refl, Sup := λ tt, Inf {t | ∀ t' ∈ tt, t' ≤ t}, le_Sup := λ s u h, le_Inf (λ u' h', h' u h), Sup_le := λ s u h, Inf_le h, Inf := Inf, le_Inf := λ s a hs, le_Inf hs, Inf_le := λ s a ha, Inf_le ha, ..uniform_space.partial_order } lemma infi_uniformity {ι : Sort*} {u : ι → uniform_space α} : (infi u).uniformity = (⨅i, (u i).uniformity) := show (⨅a (h : ∃i:ι, u i = a), a.uniformity) = _, from le_antisymm (le_infi $ assume i, infi_le_of_le (u i) $ infi_le _ ⟨i, rfl⟩) (le_infi $ assume a, le_infi $ assume ⟨i, (ha : u i = a)⟩, ha ▸ infi_le _ _) lemma inf_uniformity {u v : uniform_space α} : (u ⊓ v).uniformity = u.uniformity ⊓ v.uniformity := have (u ⊓ v) = (⨅i (h : i = u ∨ i = v), i), by simp [infi_or, infi_inf_eq], calc (u ⊓ v).uniformity = ((⨅i (h : i = u ∨ i = v), i) : uniform_space α).uniformity : by rw [this] ... = _ : by simp [infi_uniformity, infi_or, infi_inf_eq] instance inhabited_uniform_space : inhabited (uniform_space α) := ⟨⊥⟩ /-- Given `f : α → β` and a uniformity `u` on `β`, the inverse image of `u` under `f` is the inverse image in the filter sense of the induced function `α × α → β × β`. -/ def uniform_space.comap (f : α → β) (u : uniform_space β) : uniform_space α := { uniformity := u.uniformity.comap (λp:α×α, (f p.1, f p.2)), to_topological_space := u.to_topological_space.induced f, refl := le_trans (by simp; exact assume ⟨a, b⟩ (h : a = b), h ▸ rfl) (comap_mono u.refl), symm := by simp [tendsto_comap_iff, prod.swap, (∘)]; exact tendsto_swap_uniformity.comp tendsto_comap, comp := le_trans begin rw [comap_lift'_eq, comap_lift'_eq2], exact (lift'_mono' $ assume s hs ⟨a₁, a₂⟩ ⟨x, h₁, h₂⟩, ⟨f x, h₁, h₂⟩), repeat { exact monotone_comp_rel monotone_id monotone_id } end (comap_mono u.comp), is_open_uniformity := λ s, begin change (@is_open α (u.to_topological_space.induced f) s ↔ _), simp [is_open_iff_nhds, nhds_induced, mem_nhds_uniformity_iff, filter.comap, and_comm], refine ball_congr (λ x hx, ⟨_, _⟩), { rintro ⟨t, hts, ht⟩, refine ⟨_, ht, _⟩, rintro ⟨x₁, x₂⟩ h rfl, exact hts (h rfl) }, { rintro ⟨t, ht, hts⟩, exact ⟨{y | (f x, y) ∈ t}, λ y hy, @hts (x, y) hy rfl, mem_nhds_uniformity_iff.1 $ mem_nhds_left _ ht⟩ } end } lemma uniform_space_comap_id {α : Type*} : uniform_space.comap (id : α → α) = id := by ext u ; dsimp [uniform_space.comap] ; rw [prod.id_prod, filter.comap_id] lemma uniform_space.comap_comap_comp {α β γ} [uγ : uniform_space γ] {f : α → β} {g : β → γ} : uniform_space.comap (g ∘ f) uγ = uniform_space.comap f (uniform_space.comap g uγ) := by ext ; dsimp [uniform_space.comap] ; rw filter.comap_comap_comp lemma uniform_continuous_iff {α β} [uα : uniform_space α] [uβ : uniform_space β] {f : α → β} : uniform_continuous f ↔ uα ≤ uβ.comap f := filter.map_le_iff_le_comap lemma uniform_continuous_comap {f : α → β} [u : uniform_space β] : @uniform_continuous α β (uniform_space.comap f u) u f := tendsto_comap theorem to_topological_space_comap {f : α → β} {u : uniform_space β} : @uniform_space.to_topological_space _ (uniform_space.comap f u) = topological_space.induced f (@uniform_space.to_topological_space β u) := rfl lemma uniform_continuous_comap' {f : γ → β} {g : α → γ} [v : uniform_space β] [u : uniform_space α] (h : uniform_continuous (f ∘ g)) : @uniform_continuous α γ u (uniform_space.comap f v) g := tendsto_comap_iff.2 h lemma to_topological_space_mono {u₁ u₂ : uniform_space α} (h : u₁ ≤ u₂) : @uniform_space.to_topological_space _ u₁ ≤ @uniform_space.to_topological_space _ u₂ := le_of_nhds_le_nhds $ assume a, by rw [@nhds_eq_uniformity α u₁ a, @nhds_eq_uniformity α u₂ a]; exact (lift'_mono h $ le_refl _) lemma uniform_continuous.continuous [uniform_space α] [uniform_space β] {f : α → β} (hf : uniform_continuous f) : continuous f := continuous_iff_le_induced.mpr $ to_topological_space_mono $ uniform_continuous_iff.1 hf lemma to_topological_space_bot : @uniform_space.to_topological_space α ⊥ = ⊥ := rfl lemma to_topological_space_top : @uniform_space.to_topological_space α ⊤ = ⊤ := top_unique $ assume s hs, classical.by_cases (assume : s = ∅, this.symm ▸ @is_open_empty _ ⊤) (assume : s ≠ ∅, let ⟨x, hx⟩ := exists_mem_of_ne_empty this in have s = univ, from top_unique $ assume y hy, hs x hx (x, y) rfl, this.symm ▸ @is_open_univ _ ⊤) lemma to_topological_space_infi {ι : Sort*} {u : ι → uniform_space α} : (infi u).to_topological_space = ⨅i, (u i).to_topological_space := classical.by_cases (assume h : nonempty ι, eq_of_nhds_eq_nhds $ assume a, begin rw [nhds_infi, nhds_eq_uniformity], change (infi u).uniformity.lift' (preimage $ prod.mk a) = _, begin rw [infi_uniformity, lift'_infi], exact (congr_arg _ $ funext $ assume i, (@nhds_eq_uniformity α (u i) a).symm), exact h, exact assume a b, rfl end end) (assume : ¬ nonempty ι, le_antisymm (le_infi $ assume i, to_topological_space_mono $ infi_le _ _) (have infi u = ⊤, from top_unique $ le_infi $ assume i, (this ⟨i⟩).elim, have @uniform_space.to_topological_space _ (infi u) = ⊤, from this.symm ▸ to_topological_space_top, this.symm ▸ le_top)) lemma to_topological_space_Inf {s : set (uniform_space α)} : (Inf s).to_topological_space = (⨅i∈s, @uniform_space.to_topological_space α i) := begin rw [Inf_eq_infi, to_topological_space_infi], apply congr rfl, funext x, exact to_topological_space_infi end lemma to_topological_space_inf {u v : uniform_space α} : (u ⊓ v).to_topological_space = u.to_topological_space ⊓ v.to_topological_space := by rw [to_topological_space_Inf, infi_pair] instance : uniform_space empty := ⊥ instance : uniform_space unit := ⊥ instance : uniform_space bool := ⊥ instance : uniform_space ℕ := ⊥ instance : uniform_space ℤ := ⊥ instance {p : α → Prop} [t : uniform_space α] : uniform_space (subtype p) := uniform_space.comap subtype.val t lemma uniformity_subtype {p : α → Prop} [t : uniform_space α] : 𝓤 (subtype p) = comap (λq:subtype p × subtype p, (q.1.1, q.2.1)) (𝓤 α) := rfl lemma uniform_continuous_subtype_val {p : α → Prop} [uniform_space α] : uniform_continuous (subtype.val : {a : α // p a} → α) := uniform_continuous_comap lemma uniform_continuous_subtype_mk {p : α → Prop} [uniform_space α] [uniform_space β] {f : β → α} (hf : uniform_continuous f) (h : ∀x, p (f x)) : uniform_continuous (λx, ⟨f x, h x⟩ : β → subtype p) := uniform_continuous_comap' hf lemma tendsto_of_uniform_continuous_subtype [uniform_space α] [uniform_space β] {f : α → β} {s : set α} {a : α} (hf : uniform_continuous (λx:s, f x.val)) (ha : s ∈ nhds a) : tendsto f (nhds a) (nhds (f a)) := by rw [(@map_nhds_subtype_val_eq α _ s a (mem_of_nhds ha) ha).symm]; exact tendsto_map' (continuous_iff_continuous_at.mp hf.continuous _) section prod /- a similar product space is possible on the function space (uniformity of pointwise convergence), but we want to have the uniformity of uniform convergence on function spaces -/ instance [u₁ : uniform_space α] [u₂ : uniform_space β] : uniform_space (α × β) := uniform_space.of_core_eq (u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_core prod.topological_space (calc prod.topological_space = (u₁.comap prod.fst ⊓ u₂.comap prod.snd).to_topological_space : by rw [to_topological_space_inf, to_topological_space_comap, to_topological_space_comap]; refl ... = _ : by rw [uniform_space.to_core_to_topological_space]) theorem uniformity_prod [uniform_space α] [uniform_space β] : 𝓤 (α × β) = (𝓤 α).comap (λp:(α × β) × α × β, (p.1.1, p.2.1)) ⊓ (𝓤 β).comap (λp:(α × β) × α × β, (p.1.2, p.2.2)) := inf_uniformity lemma uniformity_prod_eq_prod [uniform_space α] [uniform_space β] : 𝓤 (α×β) = map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) (filter.prod (𝓤 α) (𝓤 β)) := have map (λp:(α×α)×(β×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))) = comap (λp:(α×β)×(α×β), ((p.1.1, p.2.1), (p.1.2, p.2.2))), from funext $ assume f, map_eq_comap_of_inverse (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl) (funext $ assume ⟨⟨_, _⟩, ⟨_, _⟩⟩, rfl), by rw [this, uniformity_prod, filter.prod, comap_inf, comap_comap_comp, comap_comap_comp] lemma mem_map_sets_iff' {α : Type*} {β : Type*} {f : filter α} {m : α → β} {t : set β} : t ∈ (map m f).sets ↔ (∃s∈f, m '' s ⊆ t) := mem_map_sets_iff lemma mem_uniformity_of_uniform_continuous_invarant [uniform_space α] {s:set (α×α)} {f : α → α → α} (hf : uniform_continuous (λp:α×α, f p.1 p.2)) (hs : s ∈ 𝓤 α) : ∃u∈𝓤 α, ∀a b c, (a, b) ∈ u → (f a c, f b c) ∈ s := begin rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff, (∘)] at hf, rcases mem_map_sets_iff'.1 (hf hs) with ⟨t, ht, hts⟩, clear hf, rcases mem_prod_iff.1 ht with ⟨u, hu, v, hv, huvt⟩, clear ht, refine ⟨u, hu, assume a b c hab, hts $ (mem_image _ _ _).2 ⟨⟨⟨a, b⟩, ⟨c, c⟩⟩, huvt ⟨_, _⟩, _⟩⟩, exact hab, exact refl_mem_uniformity hv, refl end lemma mem_uniform_prod [t₁ : uniform_space α] [t₂ : uniform_space β] {a : set (α × α)} {b : set (β × β)} (ha : a ∈ 𝓤 α) (hb : b ∈ 𝓤 β) : {p:(α×β)×(α×β) | (p.1.1, p.2.1) ∈ a ∧ (p.1.2, p.2.2) ∈ b } ∈ (@uniformity (α × β) _) := by rw [uniformity_prod]; exact inter_mem_inf_sets (preimage_mem_comap ha) (preimage_mem_comap hb) lemma tendsto_prod_uniformity_fst [uniform_space α] [uniform_space β] : tendsto (λp:(α×β)×(α×β), (p.1.1, p.2.1)) (𝓤 (α × β)) (𝓤 α) := le_trans (map_mono (@inf_le_left (uniform_space (α×β)) _ _ _)) map_comap_le lemma tendsto_prod_uniformity_snd [uniform_space α] [uniform_space β] : tendsto (λp:(α×β)×(α×β), (p.1.2, p.2.2)) (𝓤 (α × β)) (𝓤 β) := le_trans (map_mono (@inf_le_right (uniform_space (α×β)) _ _ _)) map_comap_le lemma uniform_continuous_fst [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.1) := tendsto_prod_uniformity_fst lemma uniform_continuous_snd [uniform_space α] [uniform_space β] : uniform_continuous (λp:α×β, p.2) := tendsto_prod_uniformity_snd variables [uniform_space α] [uniform_space β] [uniform_space γ] lemma uniform_continuous.prod_mk {f₁ : α → β} {f₂ : α → γ} (h₁ : uniform_continuous f₁) (h₂ : uniform_continuous f₂) : uniform_continuous (λa, (f₁ a, f₂ a)) := by rw [uniform_continuous, uniformity_prod]; exact tendsto_inf.2 ⟨tendsto_comap_iff.2 h₁, tendsto_comap_iff.2 h₂⟩ lemma uniform_continuous.prod_mk_left {f : α × β → γ} (h : uniform_continuous f) (b) : uniform_continuous (λ a, f (a,b)) := h.comp (uniform_continuous_id.prod_mk uniform_continuous_const) lemma uniform_continuous.prod_mk_right {f : α × β → γ} (h : uniform_continuous f) (a) : uniform_continuous (λ b, f (a,b)) := h.comp (uniform_continuous_const.prod_mk uniform_continuous_id) lemma to_topological_space_prod {α} {β} [u : uniform_space α] [v : uniform_space β] : @uniform_space.to_topological_space (α × β) prod.uniform_space = @prod.topological_space α β u.to_topological_space v.to_topological_space := rfl end prod section open uniform_space function variables [uniform_space α] [uniform_space β] [uniform_space γ] [uniform_space δ] local notation f `∘₂` g := function.bicompr f g def uniform_continuous₂ (f : α → β → γ) := uniform_continuous (uncurry' f) lemma uniform_continuous₂_def (f : α → β → γ) : uniform_continuous₂ f ↔ uniform_continuous (uncurry' f) := iff.rfl lemma uniform_continuous₂_curry (f : α × β → γ) : uniform_continuous₂ (function.curry f) ↔ uniform_continuous f := by rw [←uncurry'_curry f] {occs := occurrences.pos [2]} ; refl lemma uniform_continuous₂.comp {f : α → β → γ} {g : γ → δ} (hg : uniform_continuous g) (hf : uniform_continuous₂ f) : uniform_continuous₂ (g ∘₂ f) := hg.comp hf end lemma to_topological_space_subtype [u : uniform_space α] {p : α → Prop} : @uniform_space.to_topological_space (subtype p) subtype.uniform_space = @subtype.topological_space α p u.to_topological_space := rfl section sum variables [uniform_space α] [uniform_space β] open sum /-- Uniformity on a disjoint union. Entourages of the diagonal in the union are obtained by taking independently an entourage of the diagonal in the first part, and an entourage of the diagonal in the second part. -/ def uniform_space.core.sum : uniform_space.core (α ⊕ β) := uniform_space.core.mk' (map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔ map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β)) (λ r ⟨H₁, H₂⟩ x, by cases x; [apply refl_mem_uniformity H₁, apply refl_mem_uniformity H₂]) (λ r ⟨H₁, H₂⟩, ⟨symm_le_uniformity H₁, symm_le_uniformity H₂⟩) (λ r ⟨Hrα, Hrβ⟩, begin rcases comp_mem_uniformity_sets Hrα with ⟨tα, htα, Htα⟩, rcases comp_mem_uniformity_sets Hrβ with ⟨tβ, htβ, Htβ⟩, refine ⟨_, ⟨mem_map_sets_iff.2 ⟨tα, htα, subset_union_left _ _⟩, mem_map_sets_iff.2 ⟨tβ, htβ, subset_union_right _ _⟩⟩, _⟩, rintros ⟨_, _⟩ ⟨z, ⟨⟨a, b⟩, hab, ⟨⟩⟩ | ⟨⟨a, b⟩, hab, ⟨⟩⟩, ⟨⟨_, c⟩, hbc, ⟨⟩⟩ | ⟨⟨_, c⟩, hbc, ⟨⟩⟩⟩, { have A : (a, c) ∈ comp_rel tα tα := ⟨b, hab, hbc⟩, exact Htα A }, { have A : (a, c) ∈ comp_rel tβ tβ := ⟨b, hab, hbc⟩, exact Htβ A } end) /-- The union of an entourage of the diagonal in each set of a disjoint union is again an entourage of the diagonal. -/ lemma union_mem_uniformity_sum {a : set (α × α)} (ha : a ∈ 𝓤 α) {b : set (β × β)} (hb : b ∈ 𝓤 β) : ((λ p : (α × α), (inl p.1, inl p.2)) '' a ∪ (λ p : (β × β), (inr p.1, inr p.2)) '' b) ∈ (@uniform_space.core.sum α β _ _).uniformity := ⟨mem_map_sets_iff.2 ⟨_, ha, subset_union_left _ _⟩, mem_map_sets_iff.2 ⟨_, hb, subset_union_right _ _⟩⟩ /- To prove that the topology defined by the uniform structure on the disjoint union coincides with the disjoint union topology, we need two lemmas saying that open sets can be characterized by the uniform structure -/ lemma uniformity_sum_of_open_aux {s : set (α ⊕ β)} (hs : is_open s) {x : α ⊕ β} (xs : x ∈ s) : { p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈ (@uniform_space.core.sum α β _ _).uniformity := begin cases x, { refine mem_sets_of_superset (union_mem_uniformity_sum (mem_nhds_uniformity_iff.1 (mem_nhds_sets hs.1 xs)) univ_mem_sets) (union_subset _ _); rintro _ ⟨⟨_, b⟩, h, ⟨⟩⟩ ⟨⟩, exact h rfl }, { refine mem_sets_of_superset (union_mem_uniformity_sum univ_mem_sets (mem_nhds_uniformity_iff.1 (mem_nhds_sets hs.2 xs))) (union_subset _ _); rintro _ ⟨⟨a, _⟩, h, ⟨⟩⟩ ⟨⟩, exact h rfl }, end lemma open_of_uniformity_sum_aux {s : set (α ⊕ β)} (hs : ∀x ∈ s, { p : ((α ⊕ β) × (α ⊕ β)) | p.1 = x → p.2 ∈ s } ∈ (@uniform_space.core.sum α β _ _).uniformity) : is_open s := begin split, { refine (@is_open_iff_mem_nhds α _ _).2 (λ a ha, mem_nhds_uniformity_iff.2 _), rcases mem_map_sets_iff.1 (hs _ ha).1 with ⟨t, ht, st⟩, refine mem_sets_of_superset ht _, rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl }, { refine (@is_open_iff_mem_nhds β _ _).2 (λ b hb, mem_nhds_uniformity_iff.2 _), rcases mem_map_sets_iff.1 (hs _ hb).2 with ⟨t, ht, st⟩, refine mem_sets_of_superset ht _, rintro p pt rfl, exact st ⟨_, pt, rfl⟩ rfl } end /- We can now define the uniform structure on the disjoint union -/ instance sum.uniform_space : uniform_space (α ⊕ β) := { to_core := uniform_space.core.sum, is_open_uniformity := λ s, ⟨uniformity_sum_of_open_aux, open_of_uniformity_sum_aux⟩ } lemma sum.uniformity : 𝓤 (α ⊕ β) = map (λ p : α × α, (inl p.1, inl p.2)) (𝓤 α) ⊔ map (λ p : β × β, (inr p.1, inr p.2)) (𝓤 β) := rfl end sum end constructions lemma lebesgue_number_lemma {α : Type u} [uniform_space α] {s : set α} {ι} {c : ι → set α} (hs : compact s) (hc₁ : ∀ i, is_open (c i)) (hc₂ : s ⊆ ⋃ i, c i) : ∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ i, {y | (x, y) ∈ n} ⊆ c i := begin let u := λ n, {x | ∃ i (m ∈ 𝓤 α), {y | (x, y) ∈ comp_rel m n} ⊆ c i}, have hu₁ : ∀ n ∈ 𝓤 α, is_open (u n), { refine λ n hn, is_open_uniformity.2 _, rintro x ⟨i, m, hm, h⟩, rcases comp_mem_uniformity_sets hm with ⟨m', hm', mm'⟩, apply (𝓤 α).sets_of_superset hm', rintros ⟨x, y⟩ hp rfl, refine ⟨i, m', hm', λ z hz, h (monotone_comp_rel monotone_id monotone_const mm' _)⟩, dsimp at hz ⊢, rw comp_rel_assoc, exact ⟨y, hp, hz⟩ }, have hu₂ : s ⊆ ⋃ n ∈ 𝓤 α, u n, { intros x hx, rcases mem_Union.1 (hc₂ hx) with ⟨i, h⟩, rcases comp_mem_uniformity_sets (is_open_uniformity.1 (hc₁ i) x h) with ⟨m', hm', mm'⟩, exact mem_bUnion hm' ⟨i, _, hm', λ y hy, mm' hy rfl⟩ }, rcases compact_elim_finite_subcover_image hs hu₁ hu₂ with ⟨b, bu, b_fin, b_cover⟩, refine ⟨_, Inter_mem_sets b_fin bu, λ x hx, _⟩, rcases mem_bUnion_iff.1 (b_cover hx) with ⟨n, bn, i, m, hm, h⟩, refine ⟨i, λ y hy, h _⟩, exact prod_mk_mem_comp_rel (refl_mem_uniformity hm) (bInter_subset_of_mem bn hy) end lemma lebesgue_number_lemma_sUnion {α : Type u} [uniform_space α] {s : set α} {c : set (set α)} (hs : compact s) (hc₁ : ∀ t ∈ c, is_open t) (hc₂ : s ⊆ ⋃₀ c) : ∃ n ∈ 𝓤 α, ∀ x ∈ s, ∃ t ∈ c, ∀ y, (x, y) ∈ n → y ∈ t := by rw sUnion_eq_Union at hc₂; simpa using lebesgue_number_lemma hs (by simpa) hc₂
b5cea0e45b7c51a01e7205505f3945e4c7be0242
618003631150032a5676f229d13a079ac875ff77
/src/tactic/omega/eq_elim.lean
c9fd7bde7287358bbb4ceb790241bd6d6639e661
[ "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
14,660
lean
/- Copyright (c) 2019 Seul Baek. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Seul Baek Correctness lemmas for equality elimination. See 5.5 of <http://www.decision-procedures.org/> for details. -/ import tactic.omega.clause open list.func namespace omega def symdiv (i j : int) : int := if (2 * (i % j)) < j then i / j else (i / j) + 1 def symmod (i j : int) : int := if (2 * (i % j)) < j then i % j else (i % j) - j lemma symmod_add_one_self {i : int} : 0 < i → symmod i (i+1) = -1 := begin intro h1, unfold symmod, rw [int.mod_eq_of_lt (le_of_lt h1) (lt_add_one _), if_neg], simp only [add_comm, add_neg_cancel_left, neg_add_rev, sub_eq_add_neg], have h2 : 2 * i = (1 + 1) * i := rfl, simpa only [h2, add_mul, one_mul, add_lt_add_iff_left, not_lt] using h1 end lemma mul_symdiv_eq {i j : int} : j * (symdiv i j) = i - (symmod i j) := begin unfold symdiv, unfold symmod, by_cases h1 : (2 * (i % j)) < j, { repeat {rw if_pos h1}, rw [int.mod_def, sub_sub_cancel] }, { repeat {rw if_neg h1}, rw [int.mod_def, sub_sub, sub_sub_cancel, mul_add, mul_one] } end lemma symmod_eq {i j : int} : symmod i j = i - j * (symdiv i j) := by rw [mul_symdiv_eq, sub_sub_cancel] /-- (sgm v b as n) is the new value assigned to the nth variable after a single step of equality elimination using valuation v, term ⟨b, as⟩, and variable index n. If v satisfies the initial constraint set, then (v ⟨n ↦ sgm v b as n⟩) satisfies the new constraint set after equality elimination. -/ def sgm (v : nat → int) (b : int) (as : list int) (n : nat) := let a_n : int := get n as in let m : int := a_n + 1 in ((symmod b m) + (coeffs.val v (as.map (λ x, symmod x m)))) / m open_locale list.func def rhs : nat → int → list int → term | n b as := let m := get n as + 1 in ⟨(symmod b m), (as.map (λ x, symmod x m)) {n ↦ -m}⟩ lemma rhs_correct_aux {v : nat → int} {m : int} {as : list int} : ∀ {k}, ∃ d, (m * d + coeffs.val_between v (as.map (λ (x : ℤ), symmod x m)) 0 k = coeffs.val_between v as 0 k) | 0 := begin existsi (0 : int), simp only [add_zero, mul_zero, coeffs.val_between] end | (k+1) := begin simp only [zero_add, coeffs.val_between, list.map], cases @rhs_correct_aux k with d h1, rw ← h1, by_cases hk : k < as.length, { rw [get_map hk, symmod_eq, sub_mul], existsi (d + (symdiv (get k as) m * v k)), ring }, { rw not_lt at hk, repeat {rw get_eq_default_of_le}, existsi d, rw add_assoc, exact hk, simp only [hk, list.length_map] } end open_locale omega lemma rhs_correct {v : nat → int} {b : int} {as : list int} (n : nat) : 0 < get n as → 0 = term.val v (b,as) → v n = term.val (v ⟨n ↦ sgm v b as n⟩) (rhs n b as) := begin intros h0 h1, let a_n := get n as, let m := a_n + 1, have h3 : m ≠ 0, { apply ne_of_gt, apply lt_trans h0, simp [a_n, m] }, have h2 : m * (sgm v b as n) = (symmod b m) + coeffs.val v (as.map (λ x, symmod x m)), { simp only [sgm, mul_comm m], rw [int.div_mul_cancel], have h4 : ∃ c, m * c + (symmod b (get n as + 1) + coeffs.val v (as.map (λ (x : ℤ), symmod x m))) = term.val v (b,as), { have h5: ∃ d, m * d + (coeffs.val v (as.map (λ x, symmod x m))) = coeffs.val v as, { simp only [coeffs.val, list.length_map], apply rhs_correct_aux }, cases h5 with d h5, rw symmod_eq, existsi (symdiv b m + d), unfold term.val, rw ← h5, simp only [term.val, mul_add, add_mul, m, a_n], ring }, cases h4 with c h4, rw [dvd_add_iff_right (dvd_mul_right m c), h4, ← h1], apply dvd_zero }, apply calc v n = -(m * sgm v b as n) + (symmod b m) + (coeffs.val_except n v (as.map (λ x, symmod x m))) : begin rw [h2, ← coeffs.val_except_add_eq n], have hn : n < as.length, { by_contra hc, rw not_lt at hc, rw (get_eq_default_of_le n hc) at h0, cases h0 }, rw get_map hn, simp only [a_n, m], rw [add_comm, symmod_add_one_self h0], ring end ... = term.val (v⟨n↦sgm v b as n⟩) (rhs n b as) : begin unfold rhs, unfold term.val, rw [← coeffs.val_except_add_eq n, get_set, update_eq], have h2 : ∀ a b c : int, a + b + c = b + (c + a) := by {intros, ring}, rw (h2 (- _)), apply fun_mono_2 rfl, apply fun_mono_2, { rw coeffs.val_except_update_set }, { simp only [m, a_n], ring } end end def sym_sym (m b : int) : int := symdiv b m + symmod b m def coeffs_reduce : nat → int → list int → term | n b as := let a := get n as in let m := a + 1 in (sym_sym m b, (as.map (sym_sym m)) {n ↦ -a}) lemma coeffs_reduce_correct {v : nat → int} {b : int} {as : list int} {n : nat} : 0 < get n as → 0 = term.val v (b,as) → 0 = term.val (v ⟨n ↦ sgm v b as n⟩) (coeffs_reduce n b as) := begin intros h1 h2, let a_n := get n as, let m := a_n + 1, have h3 : m ≠ 0, { apply ne_of_gt, apply lt_trans h1, simp only [m, lt_add_iff_pos_right] }, have h4 : 0 = (term.val (v⟨n↦sgm v b as n⟩) (coeffs_reduce n b as)) * m := calc 0 = term.val v (b,as) : h2 ... = b + coeffs.val_except n v as + a_n * ((rhs n b as).val (v⟨n ↦ sgm v b as n⟩)) : begin unfold term.val, rw [← coeffs.val_except_add_eq n, rhs_correct n h1 h2], simp only [a_n, add_assoc], end ... = -(m * a_n * sgm v b as n) + (b + a_n * (symmod b m)) + (coeffs.val_except n v as + a_n * coeffs.val_except n v (as.map (λ x, symmod x m))) : begin simp only [term.val, rhs, mul_add, m, a_n, add_assoc, add_right_inj, add_comm, add_left_comm], rw [← coeffs.val_except_add_eq n, get_set, update_eq, mul_add], apply fun_mono_2, { rw coeffs.val_except_eq_val_except update_eq_of_ne (get_set_eq_of_ne _) }, simp only [m], ring, end ... = -(m * a_n * sgm v b as n) + (b + a_n * (symmod b m)) + coeffs.val_except n v (as.map (λ a_i, a_i + a_n * (symmod a_i m))) : begin apply fun_mono_2 rfl, simp only [coeffs.val_except, mul_add], repeat {rw ← coeffs.val_between_map_mul}, have h4 : ∀ {a b c d : int}, a + b + (c + d) = (a + c) + (b + d), { intros, ring }, rw h4, have h5 : add as (list.map (has_mul.mul a_n) (list.map (λ (x : ℤ), symmod x (get n as + 1)) as)) = list.map (λ (a_i : ℤ), a_i + a_n * symmod a_i m) as, { rw [list.map_map, ←map_add_map], apply fun_mono_2, { have h5 : (λ x : int, x) = id, { rw function.funext_iff, intro x, refl }, rw [h5, list.map_id] }, { apply fun_mono_2 _ rfl, rw function.funext_iff, intro x, simp only [m] } }, simp only [list.length_map], repeat { rw [← coeffs.val_between_add, h5] }, end ... = -(m * a_n * sgm v b as n) + (m * sym_sym m b) + coeffs.val_except n v (as.map (λ a_i, m * sym_sym m a_i)) : begin repeat {rw add_assoc}, apply fun_mono_2, refl, rw ← add_assoc, have h4 : ∀ (x : ℤ), x + a_n * symmod x m = m * sym_sym m x, { intro x, have h5 : a_n = m - 1, { simp only [m], rw add_sub_cancel }, rw [h5, sub_mul, one_mul, add_sub, add_comm, add_sub_assoc, ← mul_symdiv_eq], simp only [sym_sym, mul_add, add_comm] }, apply fun_mono_2 (h4 _), apply coeffs.val_except_eq_val_except; intros x h5, refl, apply congr_arg, apply fun_mono_2 _ rfl, rw function.funext_iff, apply h4 end ... = (-(a_n * sgm v b as n) + (sym_sym m b) + coeffs.val_except n v (as.map (sym_sym m))) * m : begin simp only [add_mul _ _ m], apply fun_mono_2, ring, simp only [coeffs.val_except, add_mul _ _ m], apply fun_mono_2, { rw [mul_comm _ m, ← coeffs.val_between_map_mul, list.map_map] }, simp only [list.length_map, mul_comm _ m], rw [← coeffs.val_between_map_mul, list.map_map] end ... = (sym_sym m b + (coeffs.val_except n v (as.map (sym_sym m)) + (-a_n * sgm v b as n))) * m : by ring ... = (term.val (v ⟨n ↦ sgm v b as n⟩) (coeffs_reduce n b as)) * m : begin simp only [coeffs_reduce, term.val, m, a_n], rw [← coeffs.val_except_add_eq n, coeffs.val_except_update_set, get_set, update_eq] end, rw [← int.mul_div_cancel (term.val _ _) h3, ← h4, int.zero_div] end -- Requires : t1.coeffs[m] = 1 def cancel (m : nat) (t1 t2 : term) : term := term.add (t1.mul (-(get m (t2.snd)))) t2 def subst (n : nat) (t1 t2 : term) : term := term.add (t1.mul (get n t2.snd)) (t2.fst, t2.snd {n ↦ 0}) lemma subst_correct {v : nat → int} {b : int} {as : list int} {t : term} {n : nat} : 0 < get n as → 0 = term.val v (b,as) → term.val v t = term.val (v ⟨n ↦ sgm v b as n⟩) (subst n (rhs n b as) t) := begin intros h1 h2, simp only [subst, term.val, term.val_add, term.val_mul], rw ← rhs_correct _ h1 h2, cases t with b' as', simp only [term.val], have h3 : coeffs.val (v ⟨n ↦ sgm v b as n⟩) (as' {n ↦ 0}) = coeffs.val_except n v as', { rw [← coeffs.val_except_add_eq n, get_set, zero_mul, add_zero, coeffs.val_except_update_set] }, rw [h3, ← coeffs.val_except_add_eq n], ring end /-- The type of equality elimination rules. -/ @[derive has_reflect, derive inhabited] inductive ee : Type | drop : ee | nondiv : int → ee | factor : int → ee | neg : ee | reduce : nat → ee | cancel : nat → ee namespace ee def repr : ee → string | drop := "↓" | (nondiv i) := i.repr ++ "∤" | (factor i) := "/" ++ i.repr | neg := "-" | (reduce n) := "≻" ++ n.repr | (cancel n) := "+" ++ n.repr instance has_repr : has_repr ee := ⟨repr⟩ meta instance has_to_format : has_to_format ee := ⟨λ x, x.repr⟩ end ee /-- Apply a given sequence of equality elimination steps to a clause. -/ def eq_elim : list ee → clause → clause | [] ([], les) := ([],les) | [] ((_::_), les) := ([],[]) | (_::_) ([], les) := ([],[]) | (ee.drop::es) ((eq::eqs), les) := eq_elim es (eqs, les) | (ee.neg::es) ((eq::eqs), les) := eq_elim es ((eq.neg::eqs), les) | (ee.nondiv i::es) ((b,as)::eqs, les) := if ¬(i ∣ b) ∧ (∀ x ∈ as, i ∣ x) then ([],[⟨-1,[]⟩]) else ([],[]) | (ee.factor i::es) ((b,as)::eqs, les) := if (i ∣ b) ∧ (∀ x ∈ as, i ∣ x) then eq_elim es ((term.div i (b,as)::eqs), les) else ([],[]) | (ee.reduce n::es) ((b,as)::eqs, les) := if 0 < get n as then let eq' := coeffs_reduce n b as in let r := rhs n b as in let eqs' := eqs.map (subst n r) in let les' := les.map (subst n r) in eq_elim es ((eq'::eqs'), les') else ([],[]) | (ee.cancel m::es) ((eq::eqs), les) := eq_elim es ((eqs.map (cancel m eq)), (les.map (cancel m eq))) open tactic lemma sat_empty : clause.sat ([],[]) := ⟨λ _,0, ⟨dec_trivial, dec_trivial⟩⟩ lemma sat_eq_elim : ∀ {es : list ee} {c : clause}, c.sat → (eq_elim es c).sat | [] ([], les) h := h | (e::_) ([], les) h := by {cases e; simp only [eq_elim]; apply sat_empty} | [] ((_::_), les) h := sat_empty | (ee.drop::es) ((eq::eqs), les) h1 := begin apply (@sat_eq_elim es _ _), rcases h1 with ⟨v,h1,h2⟩, refine ⟨v, list.forall_mem_of_forall_mem_cons h1, h2⟩ end | (ee.neg::es) ((eq::eqs), les) h1 := begin simp only [eq_elim], apply sat_eq_elim, cases h1 with v h1, existsi v, cases h1 with hl hr, apply and.intro _ hr, rw list.forall_mem_cons at *, apply and.intro _ hl.right, rw term.val_neg, rw ← hl.left, refl end | (ee.nondiv i::es) ((b,as)::eqs, les) h1 := begin unfold eq_elim, by_cases h2 : (¬i ∣ b ∧ ∀ (x : ℤ), x ∈ as → i ∣ x), { exfalso, cases h1 with v h1, have h3 : 0 = b + coeffs.val v as := h1.left _ (or.inl rfl), have h4 : i ∣ coeffs.val v as := coeffs.dvd_val h2.right, have h5 : i ∣ b + coeffs.val v as := by { rw ← h3, apply dvd_zero }, rw ← dvd_add_iff_left h4 at h5, apply h2.left h5 }, rw if_neg h2, apply sat_empty end | (ee.factor i::es) ((b,as)::eqs, les) h1 := begin simp only [eq_elim], by_cases h2 : (i ∣ b) ∧ (∀ x ∈ as, i ∣ x), { rw if_pos h2, apply sat_eq_elim, cases h1 with v h1, existsi v, cases h1 with h3 h4, apply and.intro _ h4, rw list.forall_mem_cons at *, cases h3 with h5 h6, apply and.intro _ h6, rw [term.val_div h2.left h2.right, ← h5, int.zero_div] }, { rw if_neg h2, apply sat_empty } end | (ee.reduce n::es) ((b,as)::eqs, les) h1 := begin simp only [eq_elim], by_cases h2 : 0 < get n as, tactic.rotate 1, { rw if_neg h2, apply sat_empty }, rw if_pos h2, apply sat_eq_elim, cases h1 with v h1, existsi v ⟨n ↦ sgm v b as n⟩, cases h1 with h1 h3, rw list.forall_mem_cons at h1, cases h1 with h4 h5, constructor, { rw list.forall_mem_cons, constructor, { apply coeffs_reduce_correct h2 h4 }, { intros x h6, rw list.mem_map at h6, cases h6 with t h6, cases h6 with h6 h7, rw [← h7, ← subst_correct h2 h4], apply h5 _ h6 } }, { intros x h6, rw list.mem_map at h6, cases h6 with t h6, cases h6 with h6 h7, rw [← h7, ← subst_correct h2 h4], apply h3 _ h6 } end | (ee.cancel m::es) ((eq::eqs), les) h1 := begin unfold eq_elim, apply sat_eq_elim, cases h1 with v h1, existsi v, cases h1 with h1 h2, rw list.forall_mem_cons at h1, cases h1 with h1 h3, constructor; intros t h4; rw list.mem_map at h4; rcases h4 with ⟨s,h4,h5⟩; rw ← h5; simp only [term.val_add, term.val_mul, cancel]; rw [← h1, mul_zero, zero_add], { apply h3 _ h4 }, { apply h2 _ h4 } end /-- If the result of equality elimination is unsatisfiable, the original clause is unsatisfiable. -/ lemma unsat_of_unsat_eq_elim (ee : list ee) (c : clause) : (eq_elim ee c).unsat → c.unsat := by {intros h1 h2, apply h1, apply sat_eq_elim h2} end omega
5961e542d80abb3a2f039091585f48aa0a483e9b
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/category_theory/category/Cat.lean
b8ff7a982d526f42b0baa45b0ffd7949ba8b1752
[ "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,913
lean
/- Copyright (c) 2019 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import category_theory.concrete_category.bundled import category_theory.discrete_category import category_theory.types import category_theory.bicategory.strict /-! # Category of categories > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file contains the definition of the category `Cat` of all categories. In this category objects are categories and morphisms are functors between these categories. ## Implementation notes Though `Cat` is not a concrete category, we use `bundled` to define its carrier type. -/ universes v u namespace category_theory /-- Category of categories. -/ @[nolint check_univs] -- intended to be used with explicit universe parameters def Cat := bundled category.{v u} namespace Cat instance : inhabited Cat := ⟨⟨Type u, category_theory.types⟩⟩ instance : has_coe_to_sort Cat (Type u) := ⟨bundled.α⟩ instance str (C : Cat.{v u}) : category.{v u} C := C.str /-- Construct a bundled `Cat` from the underlying type and the typeclass. -/ def of (C : Type u) [category.{v} C] : Cat.{v u} := bundled.of C /-- Bicategory structure on `Cat` -/ instance bicategory : bicategory.{(max v u) (max v u)} Cat.{v u} := { hom := λ C D, C ⥤ D, id := λ C, 𝟭 C, comp := λ C D E F G, F ⋙ G, hom_category := λ C D, functor.category C D, whisker_left := λ C D E F G H η, whisker_left F η, whisker_right := λ C D E F G η H, whisker_right η H, associator := λ A B C D, functor.associator, left_unitor := λ A B, functor.left_unitor, right_unitor := λ A B, functor.right_unitor, pentagon' := λ A B C D E, functor.pentagon, triangle' := λ A B C, functor.triangle } /-- `Cat` is a strict bicategory. -/ instance bicategory.strict : bicategory.strict Cat.{v u} := { id_comp' := λ C D F, by cases F; refl, comp_id' := λ C D F, by cases F; refl, assoc' := by intros; refl } /-- Category structure on `Cat` -/ instance category : large_category.{max v u} Cat.{v u} := strict_bicategory.category Cat.{v u} @[simp] lemma id_map {C : Cat} {X Y : C} (f : X ⟶ Y) : (𝟙 C : C ⥤ C).map f = f := functor.id_map f @[simp] lemma comp_obj {C D E : Cat} (F : C ⟶ D) (G : D ⟶ E) (X : C) : (F ≫ G).obj X = G.obj (F.obj X) := functor.comp_obj F G X @[simp] lemma comp_map {C D E : Cat} (F : C ⟶ D) (G : D ⟶ E) {X Y : C} (f : X ⟶ Y) : (F ≫ G).map f = G.map (F.map f) := functor.comp_map F G f /-- Functor that gets the set of objects of a category. It is not called `forget`, because it is not a faithful functor. -/ def objects : Cat.{v u} ⥤ Type u := { obj := λ C, C, map := λ C D F, F.obj } section local attribute [simp] eq_to_hom_map /-- Any isomorphism in `Cat` induces an equivalence of the underlying categories. -/ def equiv_of_iso {C D : Cat} (γ : C ≅ D) : C ≌ D := { functor := γ.hom, inverse := γ.inv, unit_iso := eq_to_iso $ eq.symm γ.hom_inv_id, counit_iso := eq_to_iso γ.inv_hom_id } end end Cat /-- Embedding `Type` into `Cat` as discrete categories. This ought to be modelled as a 2-functor! -/ @[simps] def Type_to_Cat : Type u ⥤ Cat := { obj := λ X, Cat.of (discrete X), map := λ X Y f, discrete.functor (discrete.mk ∘ f), map_id' := λ X, begin apply functor.ext, tidy, end, map_comp' := λ X Y Z f g, begin apply functor.ext, tidy, end } instance : faithful Type_to_Cat.{u} := { map_injective' := λ X Y f g h, funext (λ x, congr_arg discrete.as (functor.congr_obj h ⟨x⟩)), } instance : full Type_to_Cat.{u} := { preimage := λ X Y F, discrete.as ∘ F.obj ∘ discrete.mk, witness' := begin intros X Y F, apply functor.ext, { intros x y f, dsimp, ext, }, { rintros ⟨x⟩, ext, refl, } end } end category_theory
80ee63c70b5d3e319c9457858ff8bda08a4ee5af
bb31430994044506fa42fd667e2d556327e18dfe
/src/algebra/monoid_algebra/basic.lean
5eac4ef411e8baac1215cea54569d374815c221c
[ "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
64,654
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Yury G. Kudryashov, Scott Morrison -/ import algebra.algebra.equiv import algebra.big_operators.finsupp import algebra.hom.non_unital_alg import algebra.module.big_operators import linear_algebra.finsupp /-! # Monoid algebras When the domain of a `finsupp` has a multiplicative or additive structure, we can define a convolution product. To mathematicians this structure is known as the "monoid algebra", i.e. the finite formal linear combinations over a given semiring of elements of the monoid. The "group ring" ℤ[G] or the "group algebra" k[G] are typical uses. In fact the construction of the "monoid algebra" makes sense when `G` is not even a monoid, but merely a magma, i.e., when `G` carries a multiplication which is not required to satisfy any conditions at all. In this case the construction yields a not-necessarily-unital, not-necessarily-associative algebra but it is still adjoint to the forgetful functor from such algebras to magmas, and we prove this as `monoid_algebra.lift_magma`. In this file we define `monoid_algebra k G := G →₀ k`, and `add_monoid_algebra k G` in the same way, and then define the convolution product on these. When the domain is additive, this is used to define polynomials: ``` polynomial α := add_monoid_algebra ℕ α mv_polynomial σ α := add_monoid_algebra (σ →₀ ℕ) α ``` When the domain is multiplicative, e.g. a group, this will be used to define the group ring. ## Implementation note Unfortunately because additive and multiplicative structures both appear in both cases, it doesn't appear to be possible to make much use of `to_additive`, and we just settle for saying everything twice. Similarly, I attempted to just define `add_monoid_algebra k G := monoid_algebra k (multiplicative G)`, but the definitional equality `multiplicative G = G` leaks through everywhere, and seems impossible to use. -/ noncomputable theory open_locale big_operators open finset finsupp universes u₁ u₂ u₃ variables (k : Type u₁) (G : Type u₂) {R : Type*} /-! ### Multiplicative monoids -/ section variables [semiring k] /-- The monoid algebra over a semiring `k` generated by the monoid `G`. It is the type of finite formal `k`-linear combinations of terms of `G`, endowed with the convolution product. -/ @[derive [inhabited, add_comm_monoid]] def monoid_algebra : Type (max u₁ u₂) := G →₀ k instance : has_coe_to_fun (monoid_algebra k G) (λ _, G → k) := finsupp.has_coe_to_fun end namespace monoid_algebra variables {k G} section variables [semiring k] [non_unital_non_assoc_semiring R] /-- A non-commutative version of `monoid_algebra.lift`: given a additive homomorphism `f : k →+ R` and a homomorphism `g : G → R`, returns the additive homomorphism from `monoid_algebra k G` such that `lift_nc f g (single a b) = f b * g a`. If `f` is a ring homomorphism and the range of either `f` or `g` is in center of `R`, then the result is a ring homomorphism. If `R` is a `k`-algebra and `f = algebra_map k R`, then the result is an algebra homomorphism called `monoid_algebra.lift`. -/ def lift_nc (f : k →+ R) (g : G → R) : monoid_algebra k G →+ R := lift_add_hom (λ x : G, (add_monoid_hom.mul_right (g x)).comp f) @[simp] lemma lift_nc_single (f : k →+ R) (g : G → R) (a : G) (b : k) : lift_nc f g (single a b) = f b * g a := lift_add_hom_apply_single _ _ _ end section has_mul variables [semiring k] [has_mul G] /-- The product of `f g : monoid_algebra k G` is the finitely supported function whose value at `a` is the sum of `f x * g y` over all pairs `x, y` such that `x * y = a`. (Think of the group ring of a group.) -/ instance : has_mul (monoid_algebra k G) := ⟨λf g, f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ * a₂) (b₁ * b₂)⟩ lemma mul_def {f g : monoid_algebra k G} : f * g = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ * a₂) (b₁ * b₂)) := rfl instance : non_unital_non_assoc_semiring (monoid_algebra k G) := { zero := 0, mul := (*), add := (+), left_distrib := assume f g h, by simp only [mul_def, sum_add_index, mul_add, mul_zero, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_add], right_distrib := assume f g h, by simp only [mul_def, sum_add_index, add_mul, zero_mul, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_zero, sum_add], zero_mul := assume f, by simp only [mul_def, sum_zero_index], mul_zero := assume f, by simp only [mul_def, sum_zero_index, sum_zero], .. finsupp.add_comm_monoid } variables [semiring R] lemma lift_nc_mul {g_hom : Type*} [mul_hom_class g_hom G R] (f : k →+* R) (g : g_hom) (a b : monoid_algebra k G) (h_comm : ∀ {x y}, y ∈ a.support → commute (f (b x)) (g y)) : lift_nc (f : k →+ R) g (a * b) = lift_nc (f : k →+ R) g a * lift_nc (f : k →+ R) g b := begin conv_rhs { rw [← sum_single a, ← sum_single b] }, simp_rw [mul_def, (lift_nc _ g).map_finsupp_sum, lift_nc_single, finsupp.sum_mul, finsupp.mul_sum], refine finset.sum_congr rfl (λ y hy, finset.sum_congr rfl (λ x hx, _)), simp [mul_assoc, (h_comm hy).left_comm] end end has_mul section semigroup variables [semiring k] [semigroup G] [semiring R] instance : non_unital_semiring (monoid_algebra k G) := { zero := 0, mul := (*), add := (+), mul_assoc := assume f g h, by simp only [mul_def, sum_sum_index, sum_zero_index, sum_add_index, sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, add_mul, mul_add, add_assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add], .. monoid_algebra.non_unital_non_assoc_semiring} end semigroup section has_one variables [non_assoc_semiring R] [semiring k] [has_one G] /-- The unit of the multiplication is `single 1 1`, i.e. the function that is `1` at `1` and zero elsewhere. -/ instance : has_one (monoid_algebra k G) := ⟨single 1 1⟩ lemma one_def : (1 : monoid_algebra k G) = single 1 1 := rfl @[simp] lemma lift_nc_one {g_hom : Type*} [one_hom_class g_hom G R] (f : k →+* R) (g : g_hom) : lift_nc (f : k →+ R) g 1 = 1 := by simp [one_def] end has_one section mul_one_class variables [semiring k] [mul_one_class G] instance : non_assoc_semiring (monoid_algebra k G) := { one := 1, mul := (*), zero := 0, add := (+), nat_cast := λ n, single 1 n, nat_cast_zero := by simp [nat.cast], nat_cast_succ := λ _, by simp [nat.cast]; refl, one_mul := assume f, by simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add, one_mul, sum_single], mul_one := assume f, by simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero, mul_one, sum_single], ..monoid_algebra.non_unital_non_assoc_semiring } lemma nat_cast_def (n : ℕ) : (n : monoid_algebra k G) = single 1 n := rfl end mul_one_class /-! #### Semiring structure -/ section semiring variables [semiring k] [monoid G] instance : semiring (monoid_algebra k G) := { one := 1, mul := (*), zero := 0, add := (+), .. monoid_algebra.non_unital_semiring, .. monoid_algebra.non_assoc_semiring } variables [semiring R] /-- `lift_nc` as a `ring_hom`, for when `f x` and `g y` commute -/ def lift_nc_ring_hom (f : k →+* R) (g : G →* R) (h_comm : ∀ x y, commute (f x) (g y)) : monoid_algebra k G →+* R := { to_fun := lift_nc (f : k →+ R) g, map_one' := lift_nc_one _ _, map_mul' := λ a b, lift_nc_mul _ _ _ _ $ λ _ _ _, h_comm _ _, ..(lift_nc (f : k →+ R) g)} end semiring instance [comm_semiring k] [comm_semigroup G] : non_unital_comm_semiring (monoid_algebra k G) := { mul_comm := assume f g, begin simp only [mul_def, finsupp.sum, mul_comm], rw [finset.sum_comm], simp only [mul_comm] end, .. monoid_algebra.non_unital_semiring } instance [semiring k] [nontrivial k] [nonempty G]: nontrivial (monoid_algebra k G) := finsupp.nontrivial /-! #### Derived instances -/ section derived_instances instance [comm_semiring k] [comm_monoid G] : comm_semiring (monoid_algebra k G) := { .. monoid_algebra.non_unital_comm_semiring, .. monoid_algebra.semiring } instance [semiring k] [subsingleton k] : unique (monoid_algebra k G) := finsupp.unique_of_right instance [ring k] : add_comm_group (monoid_algebra k G) := finsupp.add_comm_group instance [ring k] [has_mul G] : non_unital_non_assoc_ring (monoid_algebra k G) := { .. monoid_algebra.add_comm_group, .. monoid_algebra.non_unital_non_assoc_semiring } instance [ring k] [semigroup G] : non_unital_ring (monoid_algebra k G) := { .. monoid_algebra.add_comm_group, .. monoid_algebra.non_unital_semiring } instance [ring k] [mul_one_class G] : non_assoc_ring (monoid_algebra k G) := { int_cast := λ z, single 1 (z : k), int_cast_of_nat := λ n, by simpa, int_cast_neg_succ_of_nat := λ n, by simpa, .. monoid_algebra.add_comm_group, .. monoid_algebra.non_assoc_semiring } lemma int_cast_def [ring k] [mul_one_class G] (z : ℤ) : (z : monoid_algebra k G) = single 1 z := rfl instance [ring k] [monoid G] : ring (monoid_algebra k G) := { .. monoid_algebra.non_assoc_ring, .. monoid_algebra.semiring } instance [comm_ring k] [comm_semigroup G] : non_unital_comm_ring (monoid_algebra k G) := { .. monoid_algebra.non_unital_comm_semiring, .. monoid_algebra.non_unital_ring } instance [comm_ring k] [comm_monoid G] : comm_ring (monoid_algebra k G) := { .. monoid_algebra.non_unital_comm_ring, .. monoid_algebra.ring } variables {S : Type*} instance [semiring k] [smul_zero_class R k] : smul_zero_class R (monoid_algebra k G) := finsupp.smul_zero_class instance [semiring k] [distrib_smul R k] : distrib_smul R (monoid_algebra k G) := finsupp.distrib_smul _ _ instance [monoid R] [semiring k] [distrib_mul_action R k] : distrib_mul_action R (monoid_algebra k G) := finsupp.distrib_mul_action G k instance [semiring R] [semiring k] [module R k] : module R (monoid_algebra k G) := finsupp.module G k instance [monoid R] [semiring k] [distrib_mul_action R k] [has_faithful_smul R k] [nonempty G] : has_faithful_smul R (monoid_algebra k G) := finsupp.has_faithful_smul instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k] [has_smul R S] [is_scalar_tower R S k] : is_scalar_tower R S (monoid_algebra k G) := finsupp.is_scalar_tower G k instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k] [smul_comm_class R S k] : smul_comm_class R S (monoid_algebra k G) := finsupp.smul_comm_class G k instance [monoid R] [semiring k] [distrib_mul_action R k] [distrib_mul_action Rᵐᵒᵖ k] [is_central_scalar R k] : is_central_scalar R (monoid_algebra k G) := finsupp.is_central_scalar G k /-- This is not an instance as it conflicts with `monoid_algebra.distrib_mul_action` when `G = kˣ`. -/ def comap_distrib_mul_action_self [group G] [semiring k] : distrib_mul_action G (monoid_algebra k G) := finsupp.comap_distrib_mul_action end derived_instances section misc_theorems variables [semiring k] local attribute [reducible] monoid_algebra lemma mul_apply [decidable_eq G] [has_mul G] (f g : monoid_algebra k G) (x : G) : (f * g) x = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, if a₁ * a₂ = x then b₁ * b₂ else 0) := begin rw [mul_def], simp only [finsupp.sum_apply, single_apply], end lemma mul_apply_antidiagonal [has_mul G] (f g : monoid_algebra k G) (x : G) (s : finset (G × G)) (hs : ∀ {p : G × G}, p ∈ s ↔ p.1 * p.2 = x) : (f * g) x = ∑ p in s, (f p.1 * g p.2) := let F : G × G → k := λ p, by classical; exact if p.1 * p.2 = x then f p.1 * g p.2 else 0 in calc (f * g) x = (∑ a₁ in f.support, ∑ a₂ in g.support, F (a₁, a₂)) : mul_apply f g x ... = ∑ p in f.support ×ˢ g.support, F p : finset.sum_product.symm ... = ∑ p in (f.support ×ˢ g.support).filter (λ p : G × G, p.1 * p.2 = x), f p.1 * g p.2 : (finset.sum_filter _ _).symm ... = ∑ p in s.filter (λ p : G × G, p.1 ∈ f.support ∧ p.2 ∈ g.support), f p.1 * g p.2 : sum_congr (by { ext, simp only [mem_filter, mem_product, hs, and_comm] }) (λ _ _, rfl) ... = ∑ p in s, f p.1 * g p.2 : sum_subset (filter_subset _ _) $ λ p hps hp, begin simp only [mem_filter, mem_support_iff, not_and, not_not] at hp ⊢, by_cases h1 : f p.1 = 0, { rw [h1, zero_mul] }, { rw [hp hps h1, mul_zero] } end @[simp] lemma single_mul_single [has_mul G] {a₁ a₂ : G} {b₁ b₂ : k} : (single a₁ b₁ : monoid_algebra k G) * single a₂ b₂ = single (a₁ * a₂) (b₁ * b₂) := (sum_single_index (by simp only [zero_mul, single_zero, sum_zero])).trans (sum_single_index (by rw [mul_zero, single_zero])) @[simp] lemma single_pow [monoid G] {a : G} {b : k} : ∀ n : ℕ, (single a b : monoid_algebra k G)^n = single (a^n) (b ^ n) | 0 := by { simp only [pow_zero], refl } | (n+1) := by simp only [pow_succ, single_pow n, single_mul_single] section /-- Like `finsupp.map_domain_zero`, but for the `1` we define in this file -/ @[simp] lemma map_domain_one {α : Type*} {β : Type*} {α₂ : Type*} [semiring β] [has_one α] [has_one α₂] {F : Type*} [one_hom_class F α α₂] (f : F) : (map_domain f (1 : monoid_algebra β α) : monoid_algebra β α₂) = (1 : monoid_algebra β α₂) := by simp_rw [one_def, map_domain_single, map_one] /-- Like `finsupp.map_domain_add`, but for the convolutive multiplication we define in this file -/ lemma map_domain_mul {α : Type*} {β : Type*} {α₂ : Type*} [semiring β] [has_mul α] [has_mul α₂] {F : Type*} [mul_hom_class F α α₂] (f : F) (x y : monoid_algebra β α) : (map_domain f (x * y : monoid_algebra β α) : monoid_algebra β α₂) = (map_domain f x * map_domain f y : monoid_algebra β α₂) := begin simp_rw [mul_def, map_domain_sum, map_domain_single, map_mul], rw finsupp.sum_map_domain_index, { congr, ext a b, rw finsupp.sum_map_domain_index, { simp }, { simp [mul_add] } }, { simp }, { simp [add_mul] } end variables (k G) /-- The embedding of a magma into its magma algebra. -/ @[simps] def of_magma [has_mul G] : G →ₙ* (monoid_algebra k G) := { to_fun := λ a, single a 1, map_mul' := λ a b, by simp only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero], } /-- The embedding of a unital magma into its magma algebra. -/ @[simps] def of [mul_one_class G] : G →* monoid_algebra k G := { to_fun := λ a, single a 1, map_one' := rfl, .. of_magma k G } end lemma smul_of [mul_one_class G] (g : G) (r : k) : r • (of k G g) = single g r := by simp lemma of_injective [mul_one_class G] [nontrivial k] : function.injective (of k G) := λ a b h, by simpa using (single_eq_single_iff _ _ _ _).mp h /-- `finsupp.single` as a `monoid_hom` from the product type into the monoid algebra. Note the order of the elements of the product are reversed compared to the arguments of `finsupp.single`. -/ @[simps] def single_hom [mul_one_class G] : k × G →* monoid_algebra k G := { to_fun := λ a, single a.2 a.1, map_one' := rfl, map_mul' := λ a b, single_mul_single.symm } lemma mul_single_apply_aux [has_mul G] (f : monoid_algebra k G) {r : k} {x y z : G} (H : ∀ a, a * x = z ↔ a = y) : (f * single x r) z = f y * r := by classical; exact have A : ∀ a₁ b₁, (single x r).sum (λ a₂ b₂, ite (a₁ * a₂ = z) (b₁ * b₂) 0) = ite (a₁ * x = z) (b₁ * r) 0, from λ a₁ b₁, sum_single_index $ by simp, calc (f * single x r) z = sum f (λ a b, if (a = y) then (b * r) else 0) : by simp only [mul_apply, A, H] ... = if y ∈ f.support then f y * r else 0 : f.support.sum_ite_eq' _ _ ... = f y * r : by split_ifs with h; simp at h; simp [h] lemma mul_single_one_apply [mul_one_class G] (f : monoid_algebra k G) (r : k) (x : G) : (f * single 1 r) x = f x * r := f.mul_single_apply_aux $ λ a, by rw [mul_one] lemma single_mul_apply_aux [has_mul G] (f : monoid_algebra k G) {r : k} {x y z : G} (H : ∀ a, x * a = y ↔ a = z) : (single x r * f) y = r * f z := by classical; exact ( have f.sum (λ a b, ite (x * a = y) (0 * b) 0) = 0, by simp, calc (single x r * f) y = sum f (λ a b, ite (x * a = y) (r * b) 0) : (mul_apply _ _ _).trans $ sum_single_index (by exact this) ... = f.sum (λ a b, ite (a = z) (r * b) 0) : by simp only [H] ... = if z ∈ f.support then (r * f z) else 0 : f.support.sum_ite_eq' _ _ ... = _ : by split_ifs with h; simp at h; simp [h]) lemma single_one_mul_apply [mul_one_class G] (f : monoid_algebra k G) (r : k) (x : G) : (single 1 r * f) x = r * f x := f.single_mul_apply_aux $ λ a, by rw [one_mul] lemma lift_nc_smul [mul_one_class G] {R : Type*} [semiring R] (f : k →+* R) (g : G →* R) (c : k) (φ : monoid_algebra k G) : lift_nc (f : k →+ R) g (c • φ) = f c * lift_nc (f : k →+ R) g φ := begin suffices : (lift_nc ↑f g).comp (smul_add_hom k (monoid_algebra k G) c) = (add_monoid_hom.mul_left (f c)).comp (lift_nc ↑f g), from add_monoid_hom.congr_fun this φ, ext a b, simp [mul_assoc] end end misc_theorems /-! #### Non-unital, non-associative algebra structure -/ section non_unital_non_assoc_algebra variables (k) [semiring k] [distrib_smul R k] [has_mul G] instance is_scalar_tower_self [is_scalar_tower R k k] : is_scalar_tower R (monoid_algebra k G) (monoid_algebra k G) := ⟨λ t a b, begin ext m, classical, simp only [mul_apply, finsupp.smul_sum, smul_ite, smul_mul_assoc, sum_smul_index', zero_mul, if_t_t, implies_true_iff, eq_self_iff_true, sum_zero, coe_smul, smul_eq_mul, pi.smul_apply, smul_zero], end⟩ /-- Note that if `k` is a `comm_semiring` then we have `smul_comm_class k k k` and so we can take `R = k` in the below. In other words, if the coefficients are commutative amongst themselves, they also commute with the algebra multiplication. -/ instance smul_comm_class_self [smul_comm_class R k k] : smul_comm_class R (monoid_algebra k G) (monoid_algebra k G) := ⟨λ t a b, begin ext m, simp only [mul_apply, finsupp.sum, finset.smul_sum, smul_ite, mul_smul_comm, sum_smul_index', implies_true_iff, eq_self_iff_true, coe_smul, ite_eq_right_iff, smul_eq_mul, pi.smul_apply, mul_zero, smul_zero], end⟩ instance smul_comm_class_symm_self [smul_comm_class k R k] : smul_comm_class (monoid_algebra k G) R (monoid_algebra k G) := ⟨λ t a b, by { haveI := smul_comm_class.symm k R k, rw ← smul_comm, } ⟩ variables {A : Type u₃} [non_unital_non_assoc_semiring A] /-- A non_unital `k`-algebra homomorphism from `monoid_algebra k G` is uniquely defined by its values on the functions `single a 1`. -/ lemma non_unital_alg_hom_ext [distrib_mul_action k A] {φ₁ φ₂ : monoid_algebra k G →ₙₐ[k] A} (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := non_unital_alg_hom.to_distrib_mul_action_hom_injective $ finsupp.distrib_mul_action_hom_ext' $ λ a, distrib_mul_action_hom.ext_ring (h a) /-- See note [partially-applied ext lemmas]. -/ @[ext] lemma non_unital_alg_hom_ext' [distrib_mul_action k A] {φ₁ φ₂ : monoid_algebra k G →ₙₐ[k] A} (h : φ₁.to_mul_hom.comp (of_magma k G) = φ₂.to_mul_hom.comp (of_magma k G)) : φ₁ = φ₂ := non_unital_alg_hom_ext k $ mul_hom.congr_fun h /-- The functor `G ↦ monoid_algebra k G`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps] def lift_magma [module k A] [is_scalar_tower k A A] [smul_comm_class k A A] : (G →ₙ* A) ≃ (monoid_algebra k G →ₙₐ[k] A) := { to_fun := λ f, { to_fun := λ a, a.sum (λ m t, t • f m), map_smul' := λ t' a, begin rw [finsupp.smul_sum, sum_smul_index'], { simp_rw smul_assoc, }, { intros m, exact zero_smul k (f m), }, end, map_mul' := λ a₁ a₂, begin let g : G → k → A := λ m t, t • f m, have h₁ : ∀ m, g m 0 = 0, { intros, exact zero_smul k (f m), }, have h₂ : ∀ m (t₁ t₂ : k), g m (t₁ + t₂) = g m t₁ + g m t₂, { intros, rw ← add_smul, }, simp_rw [finsupp.mul_sum, finsupp.sum_mul, smul_mul_smul, ← f.map_mul, mul_def, sum_comm a₂ a₁, sum_sum_index h₁ h₂, sum_single_index (h₁ _)], end, .. lift_add_hom (λ x, (smul_add_hom k A).flip (f x)) }, inv_fun := λ F, F.to_mul_hom.comp (of_magma k G), left_inv := λ f, by { ext m, simp only [non_unital_alg_hom.coe_mk, of_magma_apply, non_unital_alg_hom.to_mul_hom_eq_coe, sum_single_index, function.comp_app, one_smul, zero_smul, mul_hom.coe_comp, non_unital_alg_hom.coe_to_mul_hom], }, right_inv := λ F, by { ext m, simp only [non_unital_alg_hom.coe_mk, of_magma_apply, non_unital_alg_hom.to_mul_hom_eq_coe, sum_single_index, function.comp_app, one_smul, zero_smul, mul_hom.coe_comp, non_unital_alg_hom.coe_to_mul_hom], }, } end non_unital_non_assoc_algebra /-! #### Algebra structure -/ section algebra local attribute [reducible] monoid_algebra lemma single_one_comm [comm_semiring k] [mul_one_class G] (r : k) (f : monoid_algebra k G) : single 1 r * f = f * single 1 r := by { ext, rw [single_one_mul_apply, mul_single_one_apply, mul_comm] } /-- `finsupp.single 1` as a `ring_hom` -/ @[simps] def single_one_ring_hom [semiring k] [mul_one_class G] : k →+* monoid_algebra k G := { map_one' := rfl, map_mul' := λ x y, by rw [single_add_hom, single_mul_single, one_mul], ..finsupp.single_add_hom 1} /-- If `f : G → H` is a multiplicative homomorphism between two monoids, then `finsupp.map_domain f` is a ring homomorphism between their monoid algebras. -/ @[simps] def map_domain_ring_hom (k : Type*) {H F : Type*} [semiring k] [monoid G] [monoid H] [monoid_hom_class F G H] (f : F) : monoid_algebra k G →+* monoid_algebra k H := { map_one' := map_domain_one f, map_mul' := λ x y, map_domain_mul f x y, ..(finsupp.map_domain.add_monoid_hom f : monoid_algebra k G →+ monoid_algebra k H) } /-- If two ring homomorphisms from `monoid_algebra k G` are equal on all `single a 1` and `single 1 b`, then they are equal. -/ lemma ring_hom_ext {R} [semiring k] [mul_one_class G] [semiring R] {f g : monoid_algebra k G →+* R} (h₁ : ∀ b, f (single 1 b) = g (single 1 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) : f = g := ring_hom.coe_add_monoid_hom_injective $ add_hom_ext $ λ a b, by rw [← one_mul a, ← mul_one b, ← single_mul_single, f.coe_add_monoid_hom, g.coe_add_monoid_hom, f.map_mul, g.map_mul, h₁, h_of] /-- If two ring homomorphisms from `monoid_algebra k G` are equal on all `single a 1` and `single 1 b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] lemma ring_hom_ext' {R} [semiring k] [mul_one_class G] [semiring R] {f g : monoid_algebra k G →+* R} (h₁ : f.comp single_one_ring_hom = g.comp single_one_ring_hom) (h_of : (f : monoid_algebra k G →* R).comp (of k G) = (g : monoid_algebra k G →* R).comp (of k G)) : f = g := ring_hom_ext (ring_hom.congr_fun h₁) (monoid_hom.congr_fun h_of) /-- The instance `algebra k (monoid_algebra A G)` whenever we have `algebra k A`. In particular this provides the instance `algebra k (monoid_algebra k G)`. -/ instance {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid G] : algebra k (monoid_algebra A G) := { smul_def' := λ r a, by { ext, simp [single_one_mul_apply, algebra.smul_def, pi.smul_apply], }, commutes' := λ r f, by { ext, simp [single_one_mul_apply, mul_single_one_apply, algebra.commutes], }, ..single_one_ring_hom.comp (algebra_map k A) } /-- `finsupp.single 1` as a `alg_hom` -/ @[simps] def single_one_alg_hom {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid G] : A →ₐ[k] monoid_algebra A G := { commutes' := λ r, by { ext, simp, refl, }, ..single_one_ring_hom} @[simp] lemma coe_algebra_map {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid G] : ⇑(algebra_map k (monoid_algebra A G)) = single 1 ∘ (algebra_map k A) := rfl lemma single_eq_algebra_map_mul_of [comm_semiring k] [monoid G] (a : G) (b : k) : single a b = algebra_map k (monoid_algebra k G) b * of k G a := by simp lemma single_algebra_map_eq_algebra_map_mul_of {A : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid G] (a : G) (b : k) : single a (algebra_map k A b) = algebra_map k (monoid_algebra A G) b * of A G a := by simp lemma induction_on [semiring k] [monoid G] {p : monoid_algebra k G → Prop} (f : monoid_algebra k G) (hM : ∀ g, p (of k G g)) (hadd : ∀ f g : monoid_algebra k G, p f → p g → p (f + g)) (hsmul : ∀ (r : k) f, p f → p (r • f)) : p f := begin refine finsupp.induction_linear f _ (λ f g hf hg, hadd f g hf hg) (λ g r, _), { simpa using hsmul 0 (of k G 1) (hM 1) }, { convert hsmul r (of k G g) (hM g), simp only [mul_one, smul_single', of_apply] }, end end algebra section lift variables {k G} [comm_semiring k] [monoid G] variables {A : Type u₃} [semiring A] [algebra k A] {B : Type*} [semiring B] [algebra k B] /-- `lift_nc_ring_hom` as a `alg_hom`, for when `f` is an `alg_hom` -/ def lift_nc_alg_hom (f : A →ₐ[k] B) (g : G →* B) (h_comm : ∀ x y, commute (f x) (g y)) : monoid_algebra A G →ₐ[k] B := { to_fun := lift_nc_ring_hom (f : A →+* B) g h_comm, commutes' := by simp [lift_nc_ring_hom], ..(lift_nc_ring_hom (f : A →+* B) g h_comm)} /-- A `k`-algebra homomorphism from `monoid_algebra k G` is uniquely defined by its values on the functions `single a 1`. -/ lemma alg_hom_ext ⦃φ₁ φ₂ : monoid_algebra k G →ₐ[k] A⦄ (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := alg_hom.to_linear_map_injective $ finsupp.lhom_ext' $ λ a, linear_map.ext_ring (h a) /-- See note [partially-applied ext lemmas]. -/ @[ext] lemma alg_hom_ext' ⦃φ₁ φ₂ : monoid_algebra k G →ₐ[k] A⦄ (h : (φ₁ : monoid_algebra k G →* A).comp (of k G) = (φ₂ : monoid_algebra k G →* A).comp (of k G)) : φ₁ = φ₂ := alg_hom_ext $ monoid_hom.congr_fun h variables (k G A) /-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism `monoid_algebra k G →ₐ[k] A`. -/ def lift : (G →* A) ≃ (monoid_algebra k G →ₐ[k] A) := { inv_fun := λ f, (f : monoid_algebra k G →* A).comp (of k G), to_fun := λ F, lift_nc_alg_hom (algebra.of_id k A) F $ λ _ _, algebra.commutes _ _, left_inv := λ f, by { ext, simp [lift_nc_alg_hom, lift_nc_ring_hom] }, right_inv := λ F, by { ext, simp [lift_nc_alg_hom, lift_nc_ring_hom] } } variables {k G A} lemma lift_apply' (F : G →* A) (f : monoid_algebra k G) : lift k G A F f = f.sum (λ a b, (algebra_map k A b) * F a) := rfl lemma lift_apply (F : G →* A) (f : monoid_algebra k G) : lift k G A F f = f.sum (λ a b, b • F a) := by simp only [lift_apply', algebra.smul_def] lemma lift_def (F : G →* A) : ⇑(lift k G A F) = lift_nc ((algebra_map k A : k →+* A) : k →+ A) F := rfl @[simp] lemma lift_symm_apply (F : monoid_algebra k G →ₐ[k] A) (x : G) : (lift k G A).symm F x = F (single x 1) := rfl lemma lift_of (F : G →* A) (x) : lift k G A F (of k G x) = F x := by rw [of_apply, ← lift_symm_apply, equiv.symm_apply_apply] @[simp] lemma lift_single (F : G →* A) (a b) : lift k G A F (single a b) = b • F a := by rw [lift_def, lift_nc_single, algebra.smul_def, ring_hom.coe_add_monoid_hom] lemma lift_unique' (F : monoid_algebra k G →ₐ[k] A) : F = lift k G A ((F : monoid_algebra k G →* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `monoid_algebra k G` by its values on `F (single a 1)`. -/ lemma lift_unique (F : monoid_algebra k G →ₐ[k] A) (f : monoid_algebra k G) : F f = f.sum (λ a b, b • F (single a 1)) := by conv_lhs { rw lift_unique' F, simp [lift_apply] } /-- If `f : G → H` is a homomorphism between two magmas, then `finsupp.map_domain f` is a non-unital algebra homomorphism between their magma algebras. -/ @[simps] def map_domain_non_unital_alg_hom (k A : Type*) [comm_semiring k] [semiring A] [algebra k A] {G H F : Type*} [has_mul G] [has_mul H] [mul_hom_class F G H] (f : F) : monoid_algebra A G →ₙₐ[k] monoid_algebra A H := { map_mul' := λ x y, map_domain_mul f x y, map_smul' := λ r x, map_domain_smul r x, ..(finsupp.map_domain.add_monoid_hom f : monoid_algebra A G →+ monoid_algebra A H) } lemma map_domain_algebra_map (k A : Type*) {H F : Type*} [comm_semiring k] [semiring A] [algebra k A] [monoid H] [monoid_hom_class F G H] (f : F) (r : k) : map_domain f (algebra_map k (monoid_algebra A G) r) = algebra_map k (monoid_algebra A H) r := by simp only [coe_algebra_map, map_domain_single, map_one] /-- If `f : G → H` is a multiplicative homomorphism between two monoids, then `finsupp.map_domain f` is an algebra homomorphism between their monoid algebras. -/ @[simps] def map_domain_alg_hom (k A : Type*) [comm_semiring k] [semiring A] [algebra k A] {H F : Type*} [monoid H] [monoid_hom_class F G H] (f : F) : monoid_algebra A G →ₐ[k] monoid_algebra A H := { commutes' := map_domain_algebra_map k A f, ..map_domain_ring_hom A f} end lift section local attribute [reducible] monoid_algebra variables (k) /-- When `V` is a `k[G]`-module, multiplication by a group element `g` is a `k`-linear map. -/ def group_smul.linear_map [monoid G] [comm_semiring k] (V : Type u₃) [add_comm_monoid V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] (g : G) : V →ₗ[k] V := { to_fun := λ v, (single g (1 : k) • v : V), map_add' := λ x y, smul_add (single g (1 : k)) x y, map_smul' := λ c x, smul_algebra_smul_comm _ _ _ } @[simp] lemma group_smul.linear_map_apply [monoid G] [comm_semiring k] (V : Type u₃) [add_comm_monoid V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] (g : G) (v : V) : (group_smul.linear_map k V g) v = (single g (1 : k) • v : V) := rfl section variables {k} variables [monoid G] [comm_semiring k] {V W : Type u₃} [add_comm_monoid V] [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] [add_comm_monoid W] [module k W] [module (monoid_algebra k G) W] [is_scalar_tower k (monoid_algebra k G) W] (f : V →ₗ[k] W) (h : ∀ (g : G) (v : V), f (single g (1 : k) • v : V) = (single g (1 : k) • (f v) : W)) include h /-- Build a `k[G]`-linear map from a `k`-linear map and evidence that it is `G`-equivariant. -/ def equivariant_of_linear_of_comm : V →ₗ[monoid_algebra k G] W := { to_fun := f, map_add' := λ v v', by simp, map_smul' := λ c v, begin apply finsupp.induction c, { simp, }, { intros g r c' nm nz w, dsimp at *, simp only [add_smul, f.map_add, w, add_left_inj, single_eq_algebra_map_mul_of, ← smul_smul], erw [algebra_map_smul (monoid_algebra k G) r, algebra_map_smul (monoid_algebra k G) r, f.map_smul, h g v, of_apply], all_goals { apply_instance } } end, } @[simp] lemma equivariant_of_linear_of_comm_apply (v : V) : (equivariant_of_linear_of_comm f h) v = f v := rfl end end section universe ui variable {ι : Type ui} local attribute [reducible] monoid_algebra lemma prod_single [comm_semiring k] [comm_monoid G] {s : finset ι} {a : ι → G} {b : ι → k} : (∏ i in s, single (a i) (b i)) = single (∏ i in s, a i) (∏ i in s, b i) := finset.cons_induction_on s rfl $ λ a s has ih, by rw [prod_cons has, ih, single_mul_single, prod_cons has, prod_cons has] end section -- We now prove some additional statements that hold for group algebras. variables [semiring k] [group G] local attribute [reducible] monoid_algebra @[simp] lemma mul_single_apply (f : monoid_algebra k G) (r : k) (x y : G) : (f * single x r) y = f (y * x⁻¹) * r := f.mul_single_apply_aux $ λ a, eq_mul_inv_iff_mul_eq.symm @[simp] lemma single_mul_apply (r : k) (x : G) (f : monoid_algebra k G) (y : G) : (single x r * f) y = r * f (x⁻¹ * y) := f.single_mul_apply_aux $ λ z, eq_inv_mul_iff_mul_eq.symm lemma mul_apply_left (f g : monoid_algebra k G) (x : G) : (f * g) x = (f.sum $ λ a b, b * (g (a⁻¹ * x))) := calc (f * g) x = sum f (λ a b, (single a b * g) x) : by rw [← finsupp.sum_apply, ← finsupp.sum_mul, f.sum_single] ... = _ : by simp only [single_mul_apply, finsupp.sum] -- If we'd assumed `comm_semiring`, we could deduce this from `mul_apply_left`. lemma mul_apply_right (f g : monoid_algebra k G) (x : G) : (f * g) x = (g.sum $ λa b, (f (x * a⁻¹)) * b) := calc (f * g) x = sum g (λ a b, (f * single a b) x) : by rw [← finsupp.sum_apply, ← finsupp.mul_sum, g.sum_single] ... = _ : by simp only [mul_single_apply, finsupp.sum] end section opposite open finsupp mul_opposite variables [semiring k] /-- The opposite of an `monoid_algebra R I` equivalent as a ring to the `monoid_algebra Rᵐᵒᵖ Iᵐᵒᵖ` over the opposite ring, taking elements to their opposite. -/ @[simps {simp_rhs := tt}] protected noncomputable def op_ring_equiv [monoid G] : (monoid_algebra k G)ᵐᵒᵖ ≃+* monoid_algebra kᵐᵒᵖ Gᵐᵒᵖ := { map_mul' := begin dsimp only [add_equiv.to_fun_eq_coe, ←add_equiv.coe_to_add_monoid_hom], rw add_monoid_hom.map_mul_iff, ext i₁ r₁ i₂ r₂ : 6, simp end, ..op_add_equiv.symm.trans $ (finsupp.map_range.add_equiv (op_add_equiv : k ≃+ kᵐᵒᵖ)).trans $ finsupp.dom_congr op_equiv } @[simp] lemma op_ring_equiv_single [monoid G] (r : k) (x : G) : monoid_algebra.op_ring_equiv (op (single x r)) = single (op x) (op r) := by simp @[simp] lemma op_ring_equiv_symm_single [monoid G] (r : kᵐᵒᵖ) (x : Gᵐᵒᵖ) : monoid_algebra.op_ring_equiv.symm (single x r) = op (single x.unop r.unop) := by simp end opposite section submodule variables {k G} [comm_semiring k] [monoid G] variables {V : Type*} [add_comm_monoid V] variables [module k V] [module (monoid_algebra k G) V] [is_scalar_tower k (monoid_algebra k G) V] /-- A submodule over `k` which is stable under scalar multiplication by elements of `G` is a submodule over `monoid_algebra k G` -/ def submodule_of_smul_mem (W : submodule k V) (h : ∀ (g : G) (v : V), v ∈ W → (of k G g) • v ∈ W) : submodule (monoid_algebra k G) V := { carrier := W, zero_mem' := W.zero_mem', add_mem' := λ _ _, W.add_mem', smul_mem' := begin intros f v hv, rw [←finsupp.sum_single f, finsupp.sum, finset.sum_smul], simp_rw [←smul_of, smul_assoc], exact submodule.sum_smul_mem W _ (λ g _, h g v hv) end } end submodule end monoid_algebra /-! ### Additive monoids -/ section variables [semiring k] /-- The monoid algebra over a semiring `k` generated by the additive monoid `G`. It is the type of finite formal `k`-linear combinations of terms of `G`, endowed with the convolution product. -/ @[derive [inhabited, add_comm_monoid]] def add_monoid_algebra := G →₀ k instance : has_coe_to_fun (add_monoid_algebra k G) (λ _, G → k) := finsupp.has_coe_to_fun end namespace add_monoid_algebra variables {k G} section variables [semiring k] [non_unital_non_assoc_semiring R] /-- A non-commutative version of `add_monoid_algebra.lift`: given a additive homomorphism `f : k →+ R` and a map `g : multiplicative G → R`, returns the additive homomorphism from `add_monoid_algebra k G` such that `lift_nc f g (single a b) = f b * g a`. If `f` is a ring homomorphism and the range of either `f` or `g` is in center of `R`, then the result is a ring homomorphism. If `R` is a `k`-algebra and `f = algebra_map k R`, then the result is an algebra homomorphism called `add_monoid_algebra.lift`. -/ def lift_nc (f : k →+ R) (g : multiplicative G → R) : add_monoid_algebra k G →+ R := lift_add_hom (λ x : G, (add_monoid_hom.mul_right (g $ multiplicative.of_add x)).comp f) @[simp] lemma lift_nc_single (f : k →+ R) (g : multiplicative G → R) (a : G) (b : k) : lift_nc f g (single a b) = f b * g (multiplicative.of_add a) := lift_add_hom_apply_single _ _ _ end section has_mul variables [semiring k] [has_add G] /-- The product of `f g : add_monoid_algebra k G` is the finitely supported function whose value at `a` is the sum of `f x * g y` over all pairs `x, y` such that `x + y = a`. (Think of the product of multivariate polynomials where `α` is the additive monoid of monomial exponents.) -/ instance : has_mul (add_monoid_algebra k G) := ⟨λf g, f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)⟩ lemma mul_def {f g : add_monoid_algebra k G} : f * g = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, single (a₁ + a₂) (b₁ * b₂)) := rfl instance : non_unital_non_assoc_semiring (add_monoid_algebra k G) := { zero := 0, mul := (*), add := (+), left_distrib := assume f g h, by simp only [mul_def, sum_add_index, mul_add, mul_zero, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_add], right_distrib := assume f g h, by simp only [mul_def, sum_add_index, add_mul, mul_zero, zero_mul, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, sum_zero, sum_add], zero_mul := assume f, by simp only [mul_def, sum_zero_index], mul_zero := assume f, by simp only [mul_def, sum_zero_index, sum_zero], nsmul := λ n f, n • f, nsmul_zero' := by { intros, ext, simp [-nsmul_eq_mul, add_smul] }, nsmul_succ' := by { intros, ext, simp [-nsmul_eq_mul, nat.succ_eq_one_add, add_smul] }, .. finsupp.add_comm_monoid } variables [semiring R] lemma lift_nc_mul {g_hom : Type*} [mul_hom_class g_hom (multiplicative G) R] (f : k →+* R) (g : g_hom) (a b : add_monoid_algebra k G) (h_comm : ∀ {x y}, y ∈ a.support → commute (f (b x)) (g $ multiplicative.of_add y)) : lift_nc (f : k →+ R) g (a * b) = lift_nc (f : k →+ R) g a * lift_nc (f : k →+ R) g b := (monoid_algebra.lift_nc_mul f g _ _ @h_comm : _) end has_mul section has_one variables [semiring k] [has_zero G] [non_assoc_semiring R] /-- The unit of the multiplication is `single 1 1`, i.e. the function that is `1` at `0` and zero elsewhere. -/ instance : has_one (add_monoid_algebra k G) := ⟨single 0 1⟩ lemma one_def : (1 : add_monoid_algebra k G) = single 0 1 := rfl @[simp] lemma lift_nc_one {g_hom : Type*} [one_hom_class g_hom (multiplicative G) R] (f : k →+* R) (g : g_hom) : lift_nc (f : k →+ R) g 1 = 1 := (monoid_algebra.lift_nc_one f g : _) end has_one section semigroup variables [semiring k] [add_semigroup G] instance : non_unital_semiring (add_monoid_algebra k G) := { zero := 0, mul := (*), add := (+), mul_assoc := assume f g h, by simp only [mul_def, sum_sum_index, sum_zero_index, sum_add_index, sum_single_index, single_zero, single_add, eq_self_iff_true, forall_true_iff, forall_3_true_iff, add_mul, mul_add, add_assoc, mul_assoc, zero_mul, mul_zero, sum_zero, sum_add], .. add_monoid_algebra.non_unital_non_assoc_semiring } end semigroup section mul_one_class variables [semiring k] [add_zero_class G] instance : non_assoc_semiring (add_monoid_algebra k G) := { one := 1, mul := (*), zero := 0, add := (+), nat_cast := λ n, single 0 n, nat_cast_zero := by simp [nat.cast], nat_cast_succ := λ _, by simp [nat.cast]; refl, one_mul := assume f, by simp only [mul_def, one_def, sum_single_index, zero_mul, single_zero, sum_zero, zero_add, one_mul, sum_single], mul_one := assume f, by simp only [mul_def, one_def, sum_single_index, mul_zero, single_zero, sum_zero, add_zero, mul_one, sum_single], .. add_monoid_algebra.non_unital_non_assoc_semiring } lemma nat_cast_def (n : ℕ) : (n : add_monoid_algebra k G) = single 0 n := rfl end mul_one_class /-! #### Semiring structure -/ section semiring instance {R : Type*} [semiring k] [smul_zero_class R k] : smul_zero_class R (add_monoid_algebra k G) := finsupp.smul_zero_class variables [semiring k] [add_monoid G] instance : semiring (add_monoid_algebra k G) := { one := 1, mul := (*), zero := 0, add := (+), .. add_monoid_algebra.non_unital_semiring, .. add_monoid_algebra.non_assoc_semiring, } variables [semiring R] /-- `lift_nc` as a `ring_hom`, for when `f` and `g` commute -/ def lift_nc_ring_hom (f : k →+* R) (g : multiplicative G →* R) (h_comm : ∀ x y, commute (f x) (g y)) : add_monoid_algebra k G →+* R := { to_fun := lift_nc (f : k →+ R) g, map_one' := lift_nc_one _ _, map_mul' := λ a b, lift_nc_mul _ _ _ _ $ λ _ _ _, h_comm _ _, ..(lift_nc (f : k →+ R) g)} end semiring instance [comm_semiring k] [add_comm_semigroup G] : non_unital_comm_semiring (add_monoid_algebra k G) := { mul_comm := @mul_comm (monoid_algebra k $ multiplicative G) _, .. add_monoid_algebra.non_unital_semiring } instance [semiring k] [nontrivial k] [nonempty G] : nontrivial (add_monoid_algebra k G) := finsupp.nontrivial /-! #### Derived instances -/ section derived_instances instance [comm_semiring k] [add_comm_monoid G] : comm_semiring (add_monoid_algebra k G) := { .. add_monoid_algebra.non_unital_comm_semiring, .. add_monoid_algebra.semiring } instance [semiring k] [subsingleton k] : unique (add_monoid_algebra k G) := finsupp.unique_of_right instance [ring k] : add_comm_group (add_monoid_algebra k G) := finsupp.add_comm_group instance [ring k] [has_add G] : non_unital_non_assoc_ring (add_monoid_algebra k G) := { .. add_monoid_algebra.add_comm_group, .. add_monoid_algebra.non_unital_non_assoc_semiring } instance [ring k] [add_semigroup G] : non_unital_ring (add_monoid_algebra k G) := { .. add_monoid_algebra.add_comm_group, .. add_monoid_algebra.non_unital_semiring } instance [ring k] [add_zero_class G] : non_assoc_ring (add_monoid_algebra k G) := { int_cast := λ z, single 0 (z : k), int_cast_of_nat := λ n, by simpa, int_cast_neg_succ_of_nat := λ n, by simpa, .. add_monoid_algebra.add_comm_group, .. add_monoid_algebra.non_assoc_semiring } lemma int_cast_def [ring k] [add_zero_class G] (z : ℤ) : (z : add_monoid_algebra k G) = single 0 z := rfl instance [ring k] [add_monoid G] : ring (add_monoid_algebra k G) := { .. add_monoid_algebra.non_assoc_ring, .. add_monoid_algebra.semiring } instance [comm_ring k] [add_comm_semigroup G] : non_unital_comm_ring (add_monoid_algebra k G) := { .. add_monoid_algebra.non_unital_comm_semiring, .. add_monoid_algebra.non_unital_ring } instance [comm_ring k] [add_comm_monoid G] : comm_ring (add_monoid_algebra k G) := { .. add_monoid_algebra.non_unital_comm_ring, .. add_monoid_algebra.ring } variables {S : Type*} instance [monoid R] [semiring k] [distrib_mul_action R k] : distrib_mul_action R (add_monoid_algebra k G) := finsupp.distrib_mul_action G k instance [monoid R] [semiring k] [distrib_mul_action R k] [has_faithful_smul R k] [nonempty G] : has_faithful_smul R (add_monoid_algebra k G) := finsupp.has_faithful_smul instance [semiring R] [semiring k] [module R k] : module R (add_monoid_algebra k G) := finsupp.module G k instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k] [has_smul R S] [is_scalar_tower R S k] : is_scalar_tower R S (add_monoid_algebra k G) := finsupp.is_scalar_tower G k instance [monoid R] [monoid S] [semiring k] [distrib_mul_action R k] [distrib_mul_action S k] [smul_comm_class R S k] : smul_comm_class R S (add_monoid_algebra k G) := finsupp.smul_comm_class G k instance [monoid R] [semiring k] [distrib_mul_action R k] [distrib_mul_action Rᵐᵒᵖ k] [is_central_scalar R k] : is_central_scalar R (add_monoid_algebra k G) := finsupp.is_central_scalar G k /-! It is hard to state the equivalent of `distrib_mul_action G (add_monoid_algebra k G)` because we've never discussed actions of additive groups. -/ end derived_instances . section misc_theorems variables [semiring k] lemma mul_apply [decidable_eq G] [has_add G] (f g : add_monoid_algebra k G) (x : G) : (f * g) x = (f.sum $ λa₁ b₁, g.sum $ λa₂ b₂, if a₁ + a₂ = x then b₁ * b₂ else 0) := @monoid_algebra.mul_apply k (multiplicative G) _ _ _ _ _ _ lemma mul_apply_antidiagonal [has_add G] (f g : add_monoid_algebra k G) (x : G) (s : finset (G × G)) (hs : ∀ {p : G × G}, p ∈ s ↔ p.1 + p.2 = x) : (f * g) x = ∑ p in s, (f p.1 * g p.2) := @monoid_algebra.mul_apply_antidiagonal k (multiplicative G) _ _ _ _ _ s @hs lemma single_mul_single [has_add G] {a₁ a₂ : G} {b₁ b₂ : k} : (single a₁ b₁ * single a₂ b₂ : add_monoid_algebra k G) = single (a₁ + a₂) (b₁ * b₂) := @monoid_algebra.single_mul_single k (multiplicative G) _ _ _ _ _ _ -- This should be a `@[simp]` lemma, but the simp_nf linter times out if we add this. -- Probably the correct fix is to make a `[add_]monoid_algebra.single` with the correct type, -- instead of relying on `finsupp.single`. lemma single_pow [add_monoid G] {a : G} {b : k} : ∀ n : ℕ, ((single a b)^n : add_monoid_algebra k G) = single (n • a) (b ^ n) | 0 := by { simp only [pow_zero, zero_nsmul], refl } | (n+1) := by rw [pow_succ, pow_succ, single_pow n, single_mul_single, add_comm, add_nsmul, one_nsmul] /-- Like `finsupp.map_domain_zero`, but for the `1` we define in this file -/ @[simp] lemma map_domain_one {α : Type*} {β : Type*} {α₂ : Type*} [semiring β] [has_zero α] [has_zero α₂] {F : Type*} [zero_hom_class F α α₂] (f : F) : (map_domain f (1 : add_monoid_algebra β α) : add_monoid_algebra β α₂) = (1 : add_monoid_algebra β α₂) := by simp_rw [one_def, map_domain_single, map_zero] /-- Like `finsupp.map_domain_add`, but for the convolutive multiplication we define in this file -/ lemma map_domain_mul {α : Type*} {β : Type*} {α₂ : Type*} [semiring β] [has_add α] [has_add α₂] {F : Type*} [add_hom_class F α α₂] (f : F) (x y : add_monoid_algebra β α) : (map_domain f (x * y : add_monoid_algebra β α) : add_monoid_algebra β α₂) = (map_domain f x * map_domain f y : add_monoid_algebra β α₂) := begin simp_rw [mul_def, map_domain_sum, map_domain_single, map_add], rw finsupp.sum_map_domain_index, { congr, ext a b, rw finsupp.sum_map_domain_index, { simp }, { simp [mul_add] } }, { simp }, { simp [add_mul] } end section variables (k G) /-- The embedding of an additive magma into its additive magma algebra. -/ @[simps] def of_magma [has_add G] : multiplicative G →ₙ* add_monoid_algebra k G := { to_fun := λ a, single a 1, map_mul' := λ a b, by simpa only [mul_def, mul_one, sum_single_index, single_eq_zero, mul_zero], } /-- Embedding of a magma with zero into its magma algebra. -/ def of [add_zero_class G] : multiplicative G →* add_monoid_algebra k G := { to_fun := λ a, single a 1, map_one' := rfl, .. of_magma k G } /-- Embedding of a magma with zero `G`, into its magma algebra, having `G` as source. -/ def of' : G → add_monoid_algebra k G := λ a, single a 1 end @[simp] lemma of_apply [add_zero_class G] (a : multiplicative G) : of k G a = single a.to_add 1 := rfl @[simp] lemma of'_apply (a : G) : of' k G a = single a 1 := rfl lemma of'_eq_of [add_zero_class G] (a : G) : of' k G a = of k G a := rfl lemma of_injective [nontrivial k] [add_zero_class G] : function.injective (of k G) := λ a b h, by simpa using (single_eq_single_iff _ _ _ _).mp h /-- `finsupp.single` as a `monoid_hom` from the product type into the additive monoid algebra. Note the order of the elements of the product are reversed compared to the arguments of `finsupp.single`. -/ @[simps] def single_hom [add_zero_class G] : k × multiplicative G →* add_monoid_algebra k G := { to_fun := λ a, single a.2.to_add a.1, map_one' := rfl, map_mul' := λ a b, single_mul_single.symm } lemma mul_single_apply_aux [has_add G] (f : add_monoid_algebra k G) (r : k) (x y z : G) (H : ∀ a, a + x = z ↔ a = y) : (f * single x r) z = f y * r := @monoid_algebra.mul_single_apply_aux k (multiplicative G) _ _ _ _ _ _ _ H lemma mul_single_zero_apply [add_zero_class G] (f : add_monoid_algebra k G) (r : k) (x : G) : (f * single 0 r) x = f x * r := f.mul_single_apply_aux r _ _ _ $ λ a, by rw [add_zero] lemma single_mul_apply_aux [has_add G] (f : add_monoid_algebra k G) (r : k) (x y z : G) (H : ∀ a, x + a = y ↔ a = z) : (single x r * f : add_monoid_algebra k G) y = r * f z := @monoid_algebra.single_mul_apply_aux k (multiplicative G) _ _ _ _ _ _ _ H lemma single_zero_mul_apply [add_zero_class G] (f : add_monoid_algebra k G) (r : k) (x : G) : (single 0 r * f : add_monoid_algebra k G) x = r * f x := f.single_mul_apply_aux r _ _ _ $ λ a, by rw [zero_add] lemma mul_single_apply [add_group G] (f : add_monoid_algebra k G) (r : k) (x y : G) : (f * single x r) y = f (y - x) * r := (sub_eq_add_neg y x).symm ▸ @monoid_algebra.mul_single_apply k (multiplicative G) _ _ _ _ _ _ lemma single_mul_apply [add_group G] (r : k) (x : G) (f : add_monoid_algebra k G) (y : G) : (single x r * f : add_monoid_algebra k G) y = r * f (- x + y) := @monoid_algebra.single_mul_apply k (multiplicative G) _ _ _ _ _ _ lemma lift_nc_smul {R : Type*} [add_zero_class G] [semiring R] (f : k →+* R) (g : multiplicative G →* R) (c : k) (φ : monoid_algebra k G) : lift_nc (f : k →+ R) g (c • φ) = f c * lift_nc (f : k →+ R) g φ := @monoid_algebra.lift_nc_smul k (multiplicative G) _ _ _ _ f g c φ lemma induction_on [add_monoid G] {p : add_monoid_algebra k G → Prop} (f : add_monoid_algebra k G) (hM : ∀ g, p (of k G (multiplicative.of_add g))) (hadd : ∀ f g : add_monoid_algebra k G, p f → p g → p (f + g)) (hsmul : ∀ (r : k) f, p f → p (r • f)) : p f := begin refine finsupp.induction_linear f _ (λ f g hf hg, hadd f g hf hg) (λ g r, _), { simpa using hsmul 0 (of k G (multiplicative.of_add 0)) (hM 0) }, { convert hsmul r (of k G (multiplicative.of_add g)) (hM g), simp only [mul_one, to_add_of_add, smul_single', of_apply] }, end /-- If `f : G → H` is an additive homomorphism between two additive monoids, then `finsupp.map_domain f` is a ring homomorphism between their add monoid algebras. -/ @[simps] def map_domain_ring_hom (k : Type*) [semiring k] {H F : Type*} [add_monoid G] [add_monoid H] [add_monoid_hom_class F G H] (f : F) : add_monoid_algebra k G →+* add_monoid_algebra k H := { map_one' := map_domain_one f, map_mul' := λ x y, map_domain_mul f x y, ..(finsupp.map_domain.add_monoid_hom f : monoid_algebra k G →+ monoid_algebra k H) } end misc_theorems end add_monoid_algebra /-! #### Conversions between `add_monoid_algebra` and `monoid_algebra` We have not defined `add_monoid_algebra k G = monoid_algebra k (multiplicative G)` because historically this caused problems; since the changes that have made `nsmul` definitional, this would be possible, but for now we just contruct the ring isomorphisms using `ring_equiv.refl _`. -/ /-- The equivalence between `add_monoid_algebra` and `monoid_algebra` in terms of `multiplicative` -/ protected def add_monoid_algebra.to_multiplicative [semiring k] [has_add G] : add_monoid_algebra k G ≃+* monoid_algebra k (multiplicative G) := { to_fun := equiv_map_domain multiplicative.of_add, map_mul' := λ x y, begin repeat {rw equiv_map_domain_eq_map_domain}, dsimp [multiplicative.of_add], convert monoid_algebra.map_domain_mul (mul_hom.id (multiplicative G)) _ _, end, ..finsupp.dom_congr multiplicative.of_add } /-- The equivalence between `monoid_algebra` and `add_monoid_algebra` in terms of `additive` -/ protected def monoid_algebra.to_additive [semiring k] [has_mul G] : monoid_algebra k G ≃+* add_monoid_algebra k (additive G) := { to_fun := equiv_map_domain additive.of_mul, map_mul' := λ x y, begin repeat {rw equiv_map_domain_eq_map_domain}, dsimp [additive.of_mul], convert monoid_algebra.map_domain_mul (mul_hom.id G) _ _, end, ..finsupp.dom_congr additive.of_mul } namespace add_monoid_algebra variables {k G} /-! #### Non-unital, non-associative algebra structure -/ section non_unital_non_assoc_algebra variables (k) [semiring k] [distrib_smul R k] [has_add G] instance is_scalar_tower_self [is_scalar_tower R k k] : is_scalar_tower R (add_monoid_algebra k G) (add_monoid_algebra k G) := @monoid_algebra.is_scalar_tower_self k (multiplicative G) R _ _ _ _ /-- Note that if `k` is a `comm_semiring` then we have `smul_comm_class k k k` and so we can take `R = k` in the below. In other words, if the coefficients are commutative amongst themselves, they also commute with the algebra multiplication. -/ instance smul_comm_class_self [smul_comm_class R k k] : smul_comm_class R (add_monoid_algebra k G) (add_monoid_algebra k G) := @monoid_algebra.smul_comm_class_self k (multiplicative G) R _ _ _ _ instance smul_comm_class_symm_self [smul_comm_class k R k] : smul_comm_class (add_monoid_algebra k G) R (add_monoid_algebra k G) := @monoid_algebra.smul_comm_class_symm_self k (multiplicative G) R _ _ _ _ variables {A : Type u₃} [non_unital_non_assoc_semiring A] /-- A non_unital `k`-algebra homomorphism from `add_monoid_algebra k G` is uniquely defined by its values on the functions `single a 1`. -/ lemma non_unital_alg_hom_ext [distrib_mul_action k A] {φ₁ φ₂ : add_monoid_algebra k G →ₙₐ[k] A} (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := @monoid_algebra.non_unital_alg_hom_ext k (multiplicative G) _ _ _ _ _ φ₁ φ₂ h /-- See note [partially-applied ext lemmas]. -/ @[ext] lemma non_unital_alg_hom_ext' [distrib_mul_action k A] {φ₁ φ₂ : add_monoid_algebra k G →ₙₐ[k] A} (h : φ₁.to_mul_hom.comp (of_magma k G) = φ₂.to_mul_hom.comp (of_magma k G)) : φ₁ = φ₂ := @monoid_algebra.non_unital_alg_hom_ext' k (multiplicative G) _ _ _ _ _ φ₁ φ₂ h /-- The functor `G ↦ add_monoid_algebra k G`, from the category of magmas to the category of non-unital, non-associative algebras over `k` is adjoint to the forgetful functor in the other direction. -/ @[simps] def lift_magma [module k A] [is_scalar_tower k A A] [smul_comm_class k A A] : (multiplicative G →ₙ* A) ≃ (add_monoid_algebra k G →ₙₐ[k] A) := { to_fun := λ f, { to_fun := λ a, sum a (λ m t, t • f (multiplicative.of_add m)), .. (monoid_algebra.lift_magma k f : _)}, inv_fun := λ F, F.to_mul_hom.comp (of_magma k G), .. (monoid_algebra.lift_magma k : (multiplicative G →ₙ* A) ≃ (_ →ₙₐ[k] A)) } end non_unital_non_assoc_algebra /-! #### Algebra structure -/ section algebra local attribute [reducible] add_monoid_algebra /-- `finsupp.single 0` as a `ring_hom` -/ @[simps] def single_zero_ring_hom [semiring k] [add_monoid G] : k →+* add_monoid_algebra k G := { map_one' := rfl, map_mul' := λ x y, by rw [single_add_hom, single_mul_single, zero_add], ..finsupp.single_add_hom 0} /-- If two ring homomorphisms from `add_monoid_algebra k G` are equal on all `single a 1` and `single 0 b`, then they are equal. -/ lemma ring_hom_ext {R} [semiring k] [add_monoid G] [semiring R] {f g : add_monoid_algebra k G →+* R} (h₀ : ∀ b, f (single 0 b) = g (single 0 b)) (h_of : ∀ a, f (single a 1) = g (single a 1)) : f = g := @monoid_algebra.ring_hom_ext k (multiplicative G) R _ _ _ _ _ h₀ h_of /-- If two ring homomorphisms from `add_monoid_algebra k G` are equal on all `single a 1` and `single 0 b`, then they are equal. See note [partially-applied ext lemmas]. -/ @[ext] lemma ring_hom_ext' {R} [semiring k] [add_monoid G] [semiring R] {f g : add_monoid_algebra k G →+* R} (h₁ : f.comp single_zero_ring_hom = g.comp single_zero_ring_hom) (h_of : (f : add_monoid_algebra k G →* R).comp (of k G) = (g : add_monoid_algebra k G →* R).comp (of k G)) : f = g := ring_hom_ext (ring_hom.congr_fun h₁) (monoid_hom.congr_fun h_of) section opposite open finsupp mul_opposite variables [semiring k] /-- The opposite of an `add_monoid_algebra R I` is ring equivalent to the `add_monoid_algebra Rᵐᵒᵖ I` over the opposite ring, taking elements to their opposite. -/ @[simps {simp_rhs := tt}] protected noncomputable def op_ring_equiv [add_comm_monoid G] : (add_monoid_algebra k G)ᵐᵒᵖ ≃+* add_monoid_algebra kᵐᵒᵖ G := { map_mul' := begin dsimp only [add_equiv.to_fun_eq_coe, ←add_equiv.coe_to_add_monoid_hom], rw add_monoid_hom.map_mul_iff, ext i r i' r' : 6, dsimp, simp only [map_range_single, single_mul_single, ←op_mul, add_comm] end, ..mul_opposite.op_add_equiv.symm.trans (finsupp.map_range.add_equiv (mul_opposite.op_add_equiv : k ≃+ kᵐᵒᵖ))} @[simp] lemma op_ring_equiv_single [add_comm_monoid G] (r : k) (x : G) : add_monoid_algebra.op_ring_equiv (op (single x r)) = single x (op r) := by simp @[simp] lemma op_ring_equiv_symm_single [add_comm_monoid G] (r : kᵐᵒᵖ) (x : Gᵐᵒᵖ) : add_monoid_algebra.op_ring_equiv.symm (single x r) = op (single x r.unop) := by simp end opposite /-- The instance `algebra R (add_monoid_algebra k G)` whenever we have `algebra R k`. In particular this provides the instance `algebra k (add_monoid_algebra k G)`. -/ instance [comm_semiring R] [semiring k] [algebra R k] [add_monoid G] : algebra R (add_monoid_algebra k G) := { smul_def' := λ r a, by { ext, simp [single_zero_mul_apply, algebra.smul_def, pi.smul_apply], }, commutes' := λ r f, by { ext, simp [single_zero_mul_apply, mul_single_zero_apply, algebra.commutes], }, ..single_zero_ring_hom.comp (algebra_map R k) } /-- `finsupp.single 0` as a `alg_hom` -/ @[simps] def single_zero_alg_hom [comm_semiring R] [semiring k] [algebra R k] [add_monoid G] : k →ₐ[R] add_monoid_algebra k G := { commutes' := λ r, by { ext, simp, refl, }, ..single_zero_ring_hom} @[simp] lemma coe_algebra_map [comm_semiring R] [semiring k] [algebra R k] [add_monoid G] : (algebra_map R (add_monoid_algebra k G) : R → add_monoid_algebra k G) = single 0 ∘ (algebra_map R k) := rfl end algebra section lift variables {k G} [comm_semiring k] [add_monoid G] variables {A : Type u₃} [semiring A] [algebra k A] {B : Type*} [semiring B] [algebra k B] /-- `lift_nc_ring_hom` as a `alg_hom`, for when `f` is an `alg_hom` -/ def lift_nc_alg_hom (f : A →ₐ[k] B) (g : multiplicative G →* B) (h_comm : ∀ x y, commute (f x) (g y)) : add_monoid_algebra A G →ₐ[k] B := { to_fun := lift_nc_ring_hom (f : A →+* B) g h_comm, commutes' := by simp [lift_nc_ring_hom], ..(lift_nc_ring_hom (f : A →+* B) g h_comm)} /-- A `k`-algebra homomorphism from `monoid_algebra k G` is uniquely defined by its values on the functions `single a 1`. -/ lemma alg_hom_ext ⦃φ₁ φ₂ : add_monoid_algebra k G →ₐ[k] A⦄ (h : ∀ x, φ₁ (single x 1) = φ₂ (single x 1)) : φ₁ = φ₂ := @monoid_algebra.alg_hom_ext k (multiplicative G) _ _ _ _ _ _ _ h /-- See note [partially-applied ext lemmas]. -/ @[ext] lemma alg_hom_ext' ⦃φ₁ φ₂ : add_monoid_algebra k G →ₐ[k] A⦄ (h : (φ₁ : add_monoid_algebra k G →* A).comp (of k G) = (φ₂ : add_monoid_algebra k G →* A).comp (of k G)) : φ₁ = φ₂ := alg_hom_ext $ monoid_hom.congr_fun h variables (k G A) /-- Any monoid homomorphism `G →* A` can be lifted to an algebra homomorphism `monoid_algebra k G →ₐ[k] A`. -/ def lift : (multiplicative G →* A) ≃ (add_monoid_algebra k G →ₐ[k] A) := { inv_fun := λ f, (f : add_monoid_algebra k G →* A).comp (of k G), to_fun := λ F, { to_fun := lift_nc_alg_hom (algebra.of_id k A) F $ λ _ _, algebra.commutes _ _, .. @monoid_algebra.lift k (multiplicative G) _ _ A _ _ F}, .. @monoid_algebra.lift k (multiplicative G) _ _ A _ _ } variables {k G A} lemma lift_apply' (F : multiplicative G →* A) (f : monoid_algebra k G) : lift k G A F f = f.sum (λ a b, (algebra_map k A b) * F (multiplicative.of_add a)) := rfl lemma lift_apply (F : multiplicative G →* A) (f : monoid_algebra k G) : lift k G A F f = f.sum (λ a b, b • F (multiplicative.of_add a)) := by simp only [lift_apply', algebra.smul_def] lemma lift_def (F : multiplicative G →* A) : ⇑(lift k G A F) = lift_nc ((algebra_map k A : k →+* A) : k →+ A) F := rfl @[simp] lemma lift_symm_apply (F : add_monoid_algebra k G →ₐ[k] A) (x : multiplicative G) : (lift k G A).symm F x = F (single x.to_add 1) := rfl lemma lift_of (F : multiplicative G →* A) (x : multiplicative G) : lift k G A F (of k G x) = F x := by rw [of_apply, ← lift_symm_apply, equiv.symm_apply_apply] @[simp] lemma lift_single (F : multiplicative G →* A) (a b) : lift k G A F (single a b) = b • F (multiplicative.of_add a) := by rw [lift_def, lift_nc_single, algebra.smul_def, ring_hom.coe_add_monoid_hom] lemma lift_unique' (F : add_monoid_algebra k G →ₐ[k] A) : F = lift k G A ((F : add_monoid_algebra k G →* A).comp (of k G)) := ((lift k G A).apply_symm_apply F).symm /-- Decomposition of a `k`-algebra homomorphism from `monoid_algebra k G` by its values on `F (single a 1)`. -/ lemma lift_unique (F : add_monoid_algebra k G →ₐ[k] A) (f : monoid_algebra k G) : F f = f.sum (λ a b, b • F (single a 1)) := by conv_lhs { rw lift_unique' F, simp [lift_apply] } lemma alg_hom_ext_iff {φ₁ φ₂ : add_monoid_algebra k G →ₐ[k] A} : (∀ x, φ₁ (finsupp.single x 1) = φ₂ (finsupp.single x 1)) ↔ φ₁ = φ₂ := ⟨λ h, alg_hom_ext h, by rintro rfl _; refl⟩ end lift section local attribute [reducible] add_monoid_algebra universe ui variable {ι : Type ui} lemma prod_single [comm_semiring k] [add_comm_monoid G] {s : finset ι} {a : ι → G} {b : ι → k} : (∏ i in s, single (a i) (b i)) = single (∑ i in s, a i) (∏ i in s, b i) := finset.cons_induction_on s rfl $ λ a s has ih, by rw [prod_cons has, ih, single_mul_single, sum_cons has, prod_cons has] end lemma map_domain_algebra_map {A H F : Type*} [comm_semiring k] [semiring A] [algebra k A] [add_monoid G] [add_monoid H] [add_monoid_hom_class F G H] (f : F) (r : k) : map_domain f (algebra_map k (add_monoid_algebra A G) r) = algebra_map k (add_monoid_algebra A H) r := by simp only [function.comp_app, map_domain_single, add_monoid_algebra.coe_algebra_map, map_zero] /-- If `f : G → H` is a homomorphism between two additive magmas, then `finsupp.map_domain f` is a non-unital algebra homomorphism between their additive magma algebras. -/ @[simps] def map_domain_non_unital_alg_hom (k A : Type*) [comm_semiring k] [semiring A] [algebra k A] {G H F : Type*} [has_add G] [has_add H] [add_hom_class F G H] (f : F) : add_monoid_algebra A G →ₙₐ[k] add_monoid_algebra A H := { map_mul' := λ x y, map_domain_mul f x y, map_smul' := λ r x, map_domain_smul r x, ..(finsupp.map_domain.add_monoid_hom f : monoid_algebra A G →+ monoid_algebra A H) } /-- If `f : G → H` is an additive homomorphism between two additive monoids, then `finsupp.map_domain f` is an algebra homomorphism between their add monoid algebras. -/ @[simps] def map_domain_alg_hom (k A : Type*) [comm_semiring k] [semiring A] [algebra k A] [add_monoid G] {H F : Type*} [add_monoid H] [add_monoid_hom_class F G H] (f : F) : add_monoid_algebra A G →ₐ[k] add_monoid_algebra A H := { commutes' := map_domain_algebra_map f, ..map_domain_ring_hom A f} end add_monoid_algebra variables [comm_semiring R] (k G) /-- The algebra equivalence between `add_monoid_algebra` and `monoid_algebra` in terms of `multiplicative`. -/ def add_monoid_algebra.to_multiplicative_alg_equiv [semiring k] [algebra R k] [add_monoid G] : add_monoid_algebra k G ≃ₐ[R] monoid_algebra k (multiplicative G) := { commutes' := λ r, by simp [add_monoid_algebra.to_multiplicative], ..add_monoid_algebra.to_multiplicative k G } /-- The algebra equivalence between `monoid_algebra` and `add_monoid_algebra` in terms of `additive`. -/ def monoid_algebra.to_additive_alg_equiv [semiring k] [algebra R k] [monoid G] : monoid_algebra k G ≃ₐ[R] add_monoid_algebra k (additive G) := { commutes' := λ r, by simp [monoid_algebra.to_additive], ..monoid_algebra.to_additive k G }
4aa03005333cbc206ae34d15608ce716cb430060
4727251e0cd73359b15b664c3170e5d754078599
/src/category_theory/monoidal/category.lean
7dcc5f6d38b04ea56d72ab4358a44961ff8abd1f
[ "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
22,113
lean
/- Copyright (c) 2018 Michael Jendrusch. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Michael Jendrusch, Scott Morrison, Bhavik Mehta, Jakob von Raumer -/ import category_theory.products.basic /-! # Monoidal categories A monoidal category is a category equipped with a tensor product, unitors, and an associator. In the definition, we provide the tensor product as a pair of functions * `tensor_obj : C → C → C` * `tensor_hom : (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))` and allow use of the overloaded notation `⊗` for both. The unitors and associator are provided componentwise. The tensor product can be expressed as a functor via `tensor : C × C ⥤ C`. The unitors and associator are gathered together as natural isomorphisms in `left_unitor_nat_iso`, `right_unitor_nat_iso` and `associator_nat_iso`. Some consequences of the definition are proved in other files, e.g. `(λ_ (𝟙_ C)).hom = (ρ_ (𝟙_ C)).hom` in `category_theory.monoidal.unitors_equal`. ## Implementation Dealing with unitors and associators is painful, and at this stage we do not have a useful implementation of coherence for monoidal categories. In an effort to lessen the pain, we put some effort into choosing the right `simp` lemmas. Generally, the rule is that the component index of a natural transformation "weighs more" in considering the complexity of an expression than does a structural isomorphism (associator, etc). As an example when we prove Proposition 2.2.4 of <http://www-math.mit.edu/~etingof/egnobookfinal.pdf> we state it as a `@[simp]` lemma as ``` (λ_ (X ⊗ Y)).hom = (α_ (𝟙_ C) X Y).inv ≫ (λ_ X).hom ⊗ (𝟙 Y) ``` This is far from completely effective, but seems to prove a useful principle. ## References * Tensor categories, Etingof, Gelaki, Nikshych, Ostrik, http://www-math.mit.edu/~etingof/egnobookfinal.pdf * <https://stacks.math.columbia.edu/tag/0FFK>. -/ open category_theory universes v u open category_theory open category_theory.category open category_theory.iso namespace category_theory /-- In a monoidal category, we can take the tensor product of objects, `X ⊗ Y` and of morphisms `f ⊗ g`. Tensor product does not need to be strictly associative on objects, but there is a specified associator, `α_ X Y Z : (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)`. There is a tensor unit `𝟙_ C`, with specified left and right unitor isomorphisms `λ_ X : 𝟙_ C ⊗ X ≅ X` and `ρ_ X : X ⊗ 𝟙_ C ≅ X`. These associators and unitors satisfy the pentagon and triangle equations. See <https://stacks.math.columbia.edu/tag/0FFK>. -/ class monoidal_category (C : Type u) [𝒞 : category.{v} C] := -- curried tensor product of objects: (tensor_obj : C → C → C) (infixr ` ⊗ `:70 := tensor_obj) -- This notation is only temporary -- curried tensor product of morphisms: (tensor_hom : Π {X₁ Y₁ X₂ Y₂ : C}, (X₁ ⟶ Y₁) → (X₂ ⟶ Y₂) → ((X₁ ⊗ X₂) ⟶ (Y₁ ⊗ Y₂))) (infixr ` ⊗' `:69 := tensor_hom) -- This notation is only temporary -- tensor product laws: (tensor_id' : ∀ (X₁ X₂ : C), (𝟙 X₁) ⊗' (𝟙 X₂) = 𝟙 (X₁ ⊗ X₂) . obviously) (tensor_comp' : ∀ {X₁ Y₁ Z₁ X₂ Y₂ Z₂ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (g₁ : Y₁ ⟶ Z₁) (g₂ : Y₂ ⟶ Z₂), (f₁ ≫ g₁) ⊗' (f₂ ≫ g₂) = (f₁ ⊗' f₂) ≫ (g₁ ⊗' g₂) . obviously) -- tensor unit: (tensor_unit [] : C) (notation `𝟙_` := tensor_unit) -- associator: (associator : Π X Y Z : C, (X ⊗ Y) ⊗ Z ≅ X ⊗ (Y ⊗ Z)) (notation `α_` := associator) (associator_naturality' : ∀ {X₁ X₂ X₃ Y₁ Y₂ Y₃ : C} (f₁ : X₁ ⟶ Y₁) (f₂ : X₂ ⟶ Y₂) (f₃ : X₃ ⟶ Y₃), ((f₁ ⊗' f₂) ⊗' f₃) ≫ (α_ Y₁ Y₂ Y₃).hom = (α_ X₁ X₂ X₃).hom ≫ (f₁ ⊗' (f₂ ⊗' f₃)) . obviously) -- left unitor: (left_unitor : Π X : C, 𝟙_ ⊗ X ≅ X) (notation `λ_` := left_unitor) (left_unitor_naturality' : ∀ {X Y : C} (f : X ⟶ Y), ((𝟙 𝟙_) ⊗' f) ≫ (λ_ Y).hom = (λ_ X).hom ≫ f . obviously) -- right unitor: (right_unitor : Π X : C, X ⊗ 𝟙_ ≅ X) (notation `ρ_` := right_unitor) (right_unitor_naturality' : ∀ {X Y : C} (f : X ⟶ Y), (f ⊗' (𝟙 𝟙_)) ≫ (ρ_ Y).hom = (ρ_ X).hom ≫ f . obviously) -- pentagon identity: (pentagon' : ∀ W X Y Z : C, ((α_ W X Y).hom ⊗' (𝟙 Z)) ≫ (α_ W (X ⊗ Y) Z).hom ≫ ((𝟙 W) ⊗' (α_ X Y Z).hom) = (α_ (W ⊗ X) Y Z).hom ≫ (α_ W X (Y ⊗ Z)).hom . obviously) -- triangle identity: (triangle' : ∀ X Y : C, (α_ X 𝟙_ Y).hom ≫ ((𝟙 X) ⊗' (λ_ Y).hom) = (ρ_ X).hom ⊗' (𝟙 Y) . obviously) restate_axiom monoidal_category.tensor_id' attribute [simp] monoidal_category.tensor_id restate_axiom monoidal_category.tensor_comp' attribute [reassoc] monoidal_category.tensor_comp -- This would be redundant in the simp set. attribute [simp] monoidal_category.tensor_comp restate_axiom monoidal_category.associator_naturality' attribute [reassoc] monoidal_category.associator_naturality restate_axiom monoidal_category.left_unitor_naturality' attribute [reassoc] monoidal_category.left_unitor_naturality restate_axiom monoidal_category.right_unitor_naturality' attribute [reassoc] monoidal_category.right_unitor_naturality restate_axiom monoidal_category.pentagon' restate_axiom monoidal_category.triangle' attribute [reassoc] monoidal_category.pentagon attribute [simp, reassoc] monoidal_category.triangle open monoidal_category infixr ` ⊗ `:70 := tensor_obj infixr ` ⊗ `:70 := tensor_hom notation `𝟙_` := tensor_unit notation `α_` := associator notation `λ_` := left_unitor notation `ρ_` := right_unitor /-- The tensor product of two isomorphisms is an isomorphism. -/ @[simps] def tensor_iso {C : Type u} {X Y X' Y' : C} [category.{v} C] [monoidal_category.{v} C] (f : X ≅ Y) (g : X' ≅ Y') : X ⊗ X' ≅ Y ⊗ Y' := { hom := f.hom ⊗ g.hom, inv := f.inv ⊗ g.inv, hom_inv_id' := by rw [←tensor_comp, iso.hom_inv_id, iso.hom_inv_id, ←tensor_id], inv_hom_id' := by rw [←tensor_comp, iso.inv_hom_id, iso.inv_hom_id, ←tensor_id] } infixr ` ⊗ `:70 := tensor_iso namespace monoidal_category section variables {C : Type u} [category.{v} C] [monoidal_category.{v} C] instance tensor_is_iso {W X Y Z : C} (f : W ⟶ X) [is_iso f] (g : Y ⟶ Z) [is_iso g] : is_iso (f ⊗ g) := is_iso.of_iso (as_iso f ⊗ as_iso g) @[simp] lemma inv_tensor {W X Y Z : C} (f : W ⟶ X) [is_iso f] (g : Y ⟶ Z) [is_iso g] : inv (f ⊗ g) = inv f ⊗ inv g := by { ext, simp [←tensor_comp], } variables {U V W X Y Z : C} lemma tensor_dite {P : Prop} [decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : f ⊗ (if h : P then g h else g' h) = if h : P then f ⊗ g h else f ⊗ g' h := by { split_ifs; refl } lemma dite_tensor {P : Prop} [decidable P] {W X Y Z : C} (f : W ⟶ X) (g : P → (Y ⟶ Z)) (g' : ¬P → (Y ⟶ Z)) : (if h : P then g h else g' h) ⊗ f = if h : P then g h ⊗ f else g' h ⊗ f := by { split_ifs; refl } @[reassoc, simp] lemma comp_tensor_id (f : W ⟶ X) (g : X ⟶ Y) : (f ≫ g) ⊗ (𝟙 Z) = (f ⊗ (𝟙 Z)) ≫ (g ⊗ (𝟙 Z)) := by { rw ←tensor_comp, simp } @[reassoc, simp] lemma id_tensor_comp (f : W ⟶ X) (g : X ⟶ Y) : (𝟙 Z) ⊗ (f ≫ g) = (𝟙 Z ⊗ f) ≫ (𝟙 Z ⊗ g) := by { rw ←tensor_comp, simp } @[simp, reassoc] lemma id_tensor_comp_tensor_id (f : W ⟶ X) (g : Y ⟶ Z) : ((𝟙 Y) ⊗ f) ≫ (g ⊗ (𝟙 X)) = g ⊗ f := by { rw [←tensor_comp], simp } @[simp, reassoc] lemma tensor_id_comp_id_tensor (f : W ⟶ X) (g : Y ⟶ Z) : (g ⊗ (𝟙 W)) ≫ ((𝟙 Z) ⊗ f) = g ⊗ f := by { rw [←tensor_comp], simp } @[simp] lemma right_unitor_conjugation {X Y : C} (f : X ⟶ Y) : (f ⊗ (𝟙 (𝟙_ C))) = (ρ_ X).hom ≫ f ≫ (ρ_ Y).inv := by rw [←right_unitor_naturality_assoc, iso.hom_inv_id, category.comp_id] @[simp] lemma left_unitor_conjugation {X Y : C} (f : X ⟶ Y) : ((𝟙 (𝟙_ C)) ⊗ f) = (λ_ X).hom ≫ f ≫ (λ_ Y).inv := by rw [←left_unitor_naturality_assoc, iso.hom_inv_id, category.comp_id] @[reassoc] lemma left_unitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (λ_ X').inv = (λ_ X).inv ≫ (𝟙 _ ⊗ f) := by simp @[reassoc] lemma right_unitor_inv_naturality {X X' : C} (f : X ⟶ X') : f ≫ (ρ_ X').inv = (ρ_ X).inv ≫ (f ⊗ 𝟙 _) := by simp lemma tensor_left_iff {X Y : C} (f g : X ⟶ Y) : ((𝟙 (𝟙_ C)) ⊗ f = (𝟙 (𝟙_ C)) ⊗ g) ↔ (f = g) := by simp lemma tensor_right_iff {X Y : C} (f g : X ⟶ Y) : (f ⊗ (𝟙 (𝟙_ C)) = g ⊗ (𝟙 (𝟙_ C))) ↔ (f = g) := by simp /-! The lemmas in the next section are true by coherence, but we prove them directly as they are used in proving the coherence theorem. -/ section @[reassoc] lemma pentagon_inv (W X Y Z : C) : ((𝟙 W) ⊗ (α_ X Y Z).inv) ≫ (α_ W (X ⊗ Y) Z).inv ≫ ((α_ W X Y).inv ⊗ (𝟙 Z)) = (α_ W X (Y ⊗ Z)).inv ≫ (α_ (W ⊗ X) Y Z).inv := category_theory.eq_of_inv_eq_inv (by simp [pentagon]) @[reassoc, simp] lemma right_unitor_tensor (X Y : C) : (ρ_ (X ⊗ Y)).hom = (α_ X Y (𝟙_ C)).hom ≫ ((𝟙 X) ⊗ (ρ_ Y).hom) := by rw [←tensor_right_iff, comp_tensor_id, ←cancel_mono (α_ X Y (𝟙_ C)).hom, assoc, associator_naturality, ←triangle_assoc, ←triangle, id_tensor_comp, pentagon_assoc, ←associator_naturality, tensor_id] @[reassoc, simp] lemma right_unitor_tensor_inv (X Y : C) : ((ρ_ (X ⊗ Y)).inv) = ((𝟙 X) ⊗ (ρ_ Y).inv) ≫ (α_ X Y (𝟙_ C)).inv := eq_of_inv_eq_inv (by simp) @[simp, reassoc] lemma triangle_assoc_comp_right (X Y : C) : (α_ X (𝟙_ C) Y).inv ≫ ((ρ_ X).hom ⊗ 𝟙 Y) = ((𝟙 X) ⊗ (λ_ Y).hom) := by rw [←triangle, iso.inv_hom_id_assoc] @[simp, reassoc] lemma triangle_assoc_comp_left_inv (X Y : C) : ((𝟙 X) ⊗ (λ_ Y).inv) ≫ (α_ X (𝟙_ C) Y).inv = ((ρ_ X).inv ⊗ 𝟙 Y) := begin apply (cancel_mono ((ρ_ X).hom ⊗ 𝟙 Y)).1, simp only [triangle_assoc_comp_right, assoc], rw [←id_tensor_comp, iso.inv_hom_id, ←comp_tensor_id, iso.inv_hom_id] end end @[reassoc] lemma associator_inv_naturality {X Y Z X' Y' Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ (g ⊗ h)) ≫ (α_ X' Y' Z').inv = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) := by { rw [comp_inv_eq, assoc, associator_naturality], simp } @[reassoc, simp] lemma associator_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : (f ⊗ g) ⊗ h = (α_ X Y Z).hom ≫ (f ⊗ (g ⊗ h)) ≫ (α_ X' Y' Z').inv := by rw [associator_inv_naturality, hom_inv_id_assoc] @[reassoc] lemma associator_inv_conjugation {X X' Y Y' Z Z' : C} (f : X ⟶ X') (g : Y ⟶ Y') (h : Z ⟶ Z') : f ⊗ g ⊗ h = (α_ X Y Z).inv ≫ ((f ⊗ g) ⊗ h) ≫ (α_ X' Y' Z').hom := by rw [associator_naturality, inv_hom_id_assoc] -- TODO these next two lemmas aren't so fundamental, and perhaps could be removed -- (replacing their usages by their proofs). @[reassoc] lemma id_tensor_associator_naturality {X Y Z Z' : C} (h : Z ⟶ Z') : (𝟙 (X ⊗ Y) ⊗ h) ≫ (α_ X Y Z').hom = (α_ X Y Z).hom ≫ (𝟙 X ⊗ (𝟙 Y ⊗ h)) := by { rw [←tensor_id, associator_naturality], } @[reassoc] lemma id_tensor_associator_inv_naturality {X Y Z X' : C} (f : X ⟶ X') : (f ⊗ 𝟙 (Y ⊗ Z)) ≫ (α_ X' Y Z).inv = (α_ X Y Z).inv ≫ ((f ⊗ 𝟙 Y) ⊗ 𝟙 Z) := by { rw [←tensor_id, associator_inv_naturality] } @[simp, reassoc] lemma hom_inv_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.hom ⊗ g) ≫ (f.inv ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [←tensor_comp, f.hom_inv_id, id_tensor_comp] @[simp, reassoc] lemma inv_hom_id_tensor {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (f.inv ⊗ g) ≫ (f.hom ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [←tensor_comp, f.inv_hom_id, id_tensor_comp] @[simp, reassoc] lemma tensor_hom_inv_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.hom) ≫ (h ⊗ f.inv) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [←tensor_comp, f.hom_inv_id, comp_tensor_id] @[simp, reassoc] lemma tensor_inv_hom_id {V W X Y Z : C} (f : V ≅ W) (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f.inv) ≫ (h ⊗ f.hom) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [←tensor_comp, f.inv_hom_id, comp_tensor_id] @[simp, reassoc] lemma hom_inv_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [is_iso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (f ⊗ g) ≫ (inv f ⊗ h) = (𝟙 V ⊗ g) ≫ (𝟙 V ⊗ h) := by rw [←tensor_comp, is_iso.hom_inv_id, id_tensor_comp] @[simp, reassoc] lemma inv_hom_id_tensor' {V W X Y Z : C} (f : V ⟶ W) [is_iso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (inv f ⊗ g) ≫ (f ⊗ h) = (𝟙 W ⊗ g) ≫ (𝟙 W ⊗ h) := by rw [←tensor_comp, is_iso.inv_hom_id, id_tensor_comp] @[simp, reassoc] lemma tensor_hom_inv_id' {V W X Y Z : C} (f : V ⟶ W) [is_iso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ f) ≫ (h ⊗ inv f) = (g ⊗ 𝟙 V) ≫ (h ⊗ 𝟙 V) := by rw [←tensor_comp, is_iso.hom_inv_id, comp_tensor_id] @[simp, reassoc] lemma tensor_inv_hom_id' {V W X Y Z : C} (f : V ⟶ W) [is_iso f] (g : X ⟶ Y) (h : Y ⟶ Z) : (g ⊗ inv f) ≫ (h ⊗ f) = (g ⊗ 𝟙 W) ≫ (h ⊗ 𝟙 W) := by rw [←tensor_comp, is_iso.inv_hom_id, comp_tensor_id] end section variables (C : Type u) [category.{v} C] [monoidal_category.{v} C] /-- The tensor product expressed as a functor. -/ @[simps] def tensor : (C × C) ⥤ C := { obj := λ X, X.1 ⊗ X.2, map := λ {X Y : C × C} (f : X ⟶ Y), f.1 ⊗ f.2 } /-- The left-associated triple tensor product as a functor. -/ def left_assoc_tensor : (C × C × C) ⥤ C := { obj := λ X, (X.1 ⊗ X.2.1) ⊗ X.2.2, map := λ {X Y : C × C × C} (f : X ⟶ Y), (f.1 ⊗ f.2.1) ⊗ f.2.2 } @[simp] lemma left_assoc_tensor_obj (X) : (left_assoc_tensor C).obj X = (X.1 ⊗ X.2.1) ⊗ X.2.2 := rfl @[simp] lemma left_assoc_tensor_map {X Y} (f : X ⟶ Y) : (left_assoc_tensor C).map f = (f.1 ⊗ f.2.1) ⊗ f.2.2 := rfl /-- The right-associated triple tensor product as a functor. -/ def right_assoc_tensor : (C × C × C) ⥤ C := { obj := λ X, X.1 ⊗ (X.2.1 ⊗ X.2.2), map := λ {X Y : C × C × C} (f : X ⟶ Y), f.1 ⊗ (f.2.1 ⊗ f.2.2) } @[simp] lemma right_assoc_tensor_obj (X) : (right_assoc_tensor C).obj X = X.1 ⊗ (X.2.1 ⊗ X.2.2) := rfl @[simp] lemma right_assoc_tensor_map {X Y} (f : X ⟶ Y) : (right_assoc_tensor C).map f = f.1 ⊗ (f.2.1 ⊗ f.2.2) := rfl /-- The functor `λ X, 𝟙_ C ⊗ X`. -/ def tensor_unit_left : C ⥤ C := { obj := λ X, 𝟙_ C ⊗ X, map := λ {X Y : C} (f : X ⟶ Y), (𝟙 (𝟙_ C)) ⊗ f } /-- The functor `λ X, X ⊗ 𝟙_ C`. -/ def tensor_unit_right : C ⥤ C := { obj := λ X, X ⊗ 𝟙_ C, map := λ {X Y : C} (f : X ⟶ Y), f ⊗ (𝟙 (𝟙_ C)) } -- We can express the associator and the unitors, given componentwise above, -- as natural isomorphisms. /-- The associator as a natural isomorphism. -/ @[simps] def associator_nat_iso : left_assoc_tensor C ≅ right_assoc_tensor C := nat_iso.of_components (by { intros, apply monoidal_category.associator }) (by { intros, apply monoidal_category.associator_naturality }) /-- The left unitor as a natural isomorphism. -/ @[simps] def left_unitor_nat_iso : tensor_unit_left C ≅ 𝟭 C := nat_iso.of_components (by { intros, apply monoidal_category.left_unitor }) (by { intros, apply monoidal_category.left_unitor_naturality }) /-- The right unitor as a natural isomorphism. -/ @[simps] def right_unitor_nat_iso : tensor_unit_right C ≅ 𝟭 C := nat_iso.of_components (by { intros, apply monoidal_category.right_unitor }) (by { intros, apply monoidal_category.right_unitor_naturality }) section variables {C} /-- Tensoring on the left with a fixed object, as a functor. -/ @[simps] def tensor_left (X : C) : C ⥤ C := { obj := λ Y, X ⊗ Y, map := λ Y Y' f, (𝟙 X) ⊗ f, } /-- Tensoring on the left with `X ⊗ Y` is naturally isomorphic to tensoring on the left with `Y`, and then again with `X`. -/ def tensor_left_tensor (X Y : C) : tensor_left (X ⊗ Y) ≅ tensor_left Y ⋙ tensor_left X := nat_iso.of_components (associator _ _) (λ Z Z' f, by { dsimp, rw[←tensor_id], apply associator_naturality }) @[simp] lemma tensor_left_tensor_hom_app (X Y Z : C) : (tensor_left_tensor X Y).hom.app Z = (associator X Y Z).hom := rfl @[simp] lemma tensor_left_tensor_inv_app (X Y Z : C) : (tensor_left_tensor X Y).inv.app Z = (associator X Y Z).inv := by { simp [tensor_left_tensor], } /-- Tensoring on the right with a fixed object, as a functor. -/ @[simps] def tensor_right (X : C) : C ⥤ C := { obj := λ Y, Y ⊗ X, map := λ Y Y' f, f ⊗ (𝟙 X), } variables (C) /-- Tensoring on the left, as a functor from `C` into endofunctors of `C`. TODO: show this is a op-monoidal functor. -/ @[simps] def tensoring_left : C ⥤ C ⥤ C := { obj := tensor_left, map := λ X Y f, { app := λ Z, f ⊗ (𝟙 Z) } } instance : faithful (tensoring_left C) := { map_injective' := λ X Y f g h, begin injections with h, replace h := congr_fun h (𝟙_ C), simpa using h, end } /-- Tensoring on the right, as a functor from `C` into endofunctors of `C`. We later show this is a monoidal functor. -/ @[simps] def tensoring_right : C ⥤ C ⥤ C := { obj := tensor_right, map := λ X Y f, { app := λ Z, (𝟙 Z) ⊗ f } } instance : faithful (tensoring_right C) := { map_injective' := λ X Y f g h, begin injections with h, replace h := congr_fun h (𝟙_ C), simpa using h, end } variables {C} /-- Tensoring on the right with `X ⊗ Y` is naturally isomorphic to tensoring on the right with `X`, and then again with `Y`. -/ def tensor_right_tensor (X Y : C) : tensor_right (X ⊗ Y) ≅ tensor_right X ⋙ tensor_right Y := nat_iso.of_components (λ Z, (associator Z X Y).symm) (λ Z Z' f, by { dsimp, rw[←tensor_id], apply associator_inv_naturality }) @[simp] lemma tensor_right_tensor_hom_app (X Y Z : C) : (tensor_right_tensor X Y).hom.app Z = (associator Z X Y).inv := rfl @[simp] lemma tensor_right_tensor_inv_app (X Y Z : C) : (tensor_right_tensor X Y).inv.app Z = (associator Z X Y).hom := by simp [tensor_right_tensor] variables {C} /-- Any property closed under `𝟙_` and `⊗` induces a full monoidal subcategory of `C`, where the category on the subtype is given by `full_subcategory`. -/ def full_monoidal_subcategory (P : C → Prop) (h_id : P (𝟙_ C)) (h_tensor : ∀ {X Y}, P X → P Y → P (X ⊗ Y)) : monoidal_category {X : C // P X} := { tensor_obj := λ X Y, ⟨X ⊗ Y, h_tensor X.2 Y.2⟩, tensor_hom := λ X₁ Y₁ X₂ Y₂ f g, by { change X₁.1 ⊗ X₂.1 ⟶ Y₁.1 ⊗ Y₂.1, change X₁.1 ⟶ Y₁.1 at f, change X₂.1 ⟶ Y₂.1 at g, exact f ⊗ g }, tensor_unit := ⟨𝟙_ C, h_id⟩, associator := λ X Y Z, ⟨(α_ X.1 Y.1 Z.1).hom, (α_ X.1 Y.1 Z.1).inv, hom_inv_id (α_ X.1 Y.1 Z.1), inv_hom_id (α_ X.1 Y.1 Z.1)⟩, left_unitor := λ X, ⟨(λ_ X.1).hom, (λ_ X.1).inv, hom_inv_id (λ_ X.1), inv_hom_id (λ_ X.1)⟩, right_unitor := λ X, ⟨(ρ_ X.1).hom, (ρ_ X.1).inv, hom_inv_id (ρ_ X.1), inv_hom_id (ρ_ X.1)⟩, tensor_id' := λ X Y, tensor_id X.1 Y.1, tensor_comp' := λ X₁ Y₁ Z₁ X₂ Y₂ Z₂ f₁ f₂ g₁ g₂, tensor_comp f₁ f₂ g₁ g₂, associator_naturality' := λ X₁ X₂ X₃ Y₁ Y₂ Y₃ f₁ f₂ f₃, associator_naturality f₁ f₂ f₃, left_unitor_naturality' := λ X Y f, left_unitor_naturality f, right_unitor_naturality' := λ X Y f, right_unitor_naturality f, pentagon' := λ W X Y Z, pentagon W.1 X.1 Y.1 Z.1, triangle' := λ X Y, triangle X.1 Y.1 } end end section universes v₁ v₂ u₁ u₂ variables (C₁ : Type u₁) [category.{v₁} C₁] [monoidal_category.{v₁} C₁] variables (C₂ : Type u₂) [category.{v₂} C₂] [monoidal_category.{v₂} C₂] local attribute [simp] associator_naturality left_unitor_naturality right_unitor_naturality pentagon @[simps tensor_obj tensor_hom tensor_unit associator] instance prod_monoidal : monoidal_category (C₁ × C₂) := { tensor_obj := λ X Y, (X.1 ⊗ Y.1, X.2 ⊗ Y.2), tensor_hom := λ _ _ _ _ f g, (f.1 ⊗ g.1, f.2 ⊗ g.2), tensor_unit := (𝟙_ C₁, 𝟙_ C₂), associator := λ X Y Z, (α_ X.1 Y.1 Z.1).prod (α_ X.2 Y.2 Z.2), left_unitor := λ ⟨X₁, X₂⟩, (λ_ X₁).prod (λ_ X₂), right_unitor := λ ⟨X₁, X₂⟩, (ρ_ X₁).prod (ρ_ X₂) } @[simp] lemma prod_monoidal_left_unitor_hom_fst (X : C₁ × C₂) : ((λ_ X).hom : (𝟙_ _) ⊗ X ⟶ X).1 = (λ_ X.1).hom := by { cases X, refl } @[simp] lemma prod_monoidal_left_unitor_hom_snd (X : C₁ × C₂) : ((λ_ X).hom : (𝟙_ _) ⊗ X ⟶ X).2 = (λ_ X.2).hom := by { cases X, refl } @[simp] lemma prod_monoidal_left_unitor_inv_fst (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ (𝟙_ _) ⊗ X).1 = (λ_ X.1).inv := by { cases X, refl } @[simp] lemma prod_monoidal_left_unitor_inv_snd (X : C₁ × C₂) : ((λ_ X).inv : X ⟶ (𝟙_ _) ⊗ X).2 = (λ_ X.2).inv := by { cases X, refl } @[simp] lemma prod_monoidal_right_unitor_hom_fst (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ (𝟙_ _) ⟶ X).1 = (ρ_ X.1).hom := by { cases X, refl } @[simp] lemma prod_monoidal_right_unitor_hom_snd (X : C₁ × C₂) : ((ρ_ X).hom : X ⊗ (𝟙_ _) ⟶ X).2 = (ρ_ X.2).hom := by { cases X, refl } @[simp] lemma prod_monoidal_right_unitor_inv_fst (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ (𝟙_ _)).1 = (ρ_ X.1).inv := by { cases X, refl } @[simp] lemma prod_monoidal_right_unitor_inv_snd (X : C₁ × C₂) : ((ρ_ X).inv : X ⟶ X ⊗ (𝟙_ _)).2 = (ρ_ X.2).inv := by { cases X, refl } end end monoidal_category end category_theory
6c84102c591981655d86a9fb790ddd46a798a835
35960c5b117752aca7e3e7767c0b393e4dbd72a7
/src/data/fresh.lean
b9920e86cc0682341e76a98f514a7ede7b915c5d
[ "Apache-2.0" ]
permissive
spl/tts
461dc76b83df8db47e4660d0941dc97e6d4fd7d1
b65298fea68ce47c8ed3ba3dbce71c1a20dd3481
refs/heads/master
1,541,049,198,347
1,537,967,023,000
1,537,967,029,000
119,653,145
1
0
null
null
null
null
UTF-8
Lean
false
false
10,685
lean
/- Copyright (c) 2018 Sean Leather. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Sean Leather Generating fresh atoms. An atom (or inhabitant) of type `α` that is not a member of a given finite set `s : finset α` is called “fresh.” The set `s` is called the “avoidance set” since it contains the atoms to be avoided when generating the fresh atom. The `fresh` structure specifies a fresh atom generator given an avoidance set. The type `α` is countably infinite since a fresh atom must not be a member of any given finite set. -/ import data.finset variables {α : Type*} /-- Fresh atom generator -/ structure fresh (α : Type*) := /- Generate an atom from an avoidance set -/ (gen : finset α → α) /- The atom is fresh. -/ (gen_not_mem : ∀ (s : finset α), gen s ∉ s) namespace fresh variables [decidable_eq α] /- gen -/ theorem gen_ne_of_mem (F : fresh α) {a} {s : finset α} (h : a ∈ s) : a ≠ F.gen s := λ h', F.gen_not_mem s (h' ▸ h : F.gen s ∈ s) @[simp] theorem gen_not_mem_of_subset (F : fresh α) {s s' : finset α} (h : s ⊆ s') : F.gen s' ∉ s := λ h', F.gen_not_mem s' (h h') theorem gen_not_mem_singleton (F : fresh α) (a : α) : F.gen (finset.singleton a) ≠ a := finset.not_mem_singleton.mp $ F.gen_not_mem _ theorem gen_not_mem_insert (F : fresh α) (a : α) (s : finset α) : F.gen (insert a s) ≠ a ∧ F.gen (insert a s) ∉ s := not_or_distrib.mp $ mt finset.mem_insert.mpr $ F.gen_not_mem _ theorem gen_not_mem_union (F : fresh α) (s₁ s₂ : finset α) : F.gen (s₁ ∪ s₂) ∉ s₁ ∧ F.gen (s₁ ∪ s₂) ∉ s₂ := finset.not_mem_union.mp $ F.gen_not_mem _ theorem gen_ssubset_insert (F : fresh α) (s : finset α) : s ⊂ insert (F.gen s) s := finset.ssubset_insert (F.gen_not_mem s) @[simp] theorem gen_insert_ne (F : fresh α) (s : finset α) : F.gen (insert (F.gen s) s) ≠ F.gen s := have h₁ : F.gen (insert (F.gen s) s) ∉ insert (F.gen s) s := F.gen_not_mem (insert (F.gen s) s), have F.gen s ∈ insert (F.gen s) s := finset.mem_insert_self _ _, λ h₂, by rw h₂ at h₁; contradiction /- pgen -/ /-- Generate a pair of a fresh atom and a new avoidance set. -/ def pgen (F : fresh α) (s : finset α) : α × finset α := let a := F.gen s in ⟨a, insert a s⟩ theorem pgen_not_mem (F : fresh α) : ∀ (s : finset α), (F.pgen s).1 ∉ s := F.gen_not_mem theorem pgen_subset (F : fresh α) (s : finset α) : s ⊆ (F.pgen s).2 := finset.subset_insert _ _ theorem pgen_ne_of_mem {a} (F : fresh α) (s : finset α) (h : a ∈ s) : a ≠ (F.pgen s).1 := F.gen_ne_of_mem h /- pgenl -/ /-- Generate a pair of a fresh atom list of the given length and a new avoidance set. -/ def pgenl (F : fresh α) (s : finset α) : ℕ → list α × finset α | 0 := ⟨[], s⟩ | (n+1) := have ih : list α × finset α := pgenl n, have a : α := F.gen ih.2, ⟨a :: ih.1, insert a ih.2⟩ @[simp] theorem pgenl_zero (F : fresh α) (s : finset α) : F.pgenl s 0 = prod.mk [] s := rfl @[simp] theorem pgenl_succ (F : fresh α) (s : finset α) (n : ℕ) : F.pgenl s (n+1) = prod.mk (F.gen (F.pgenl s n).2 :: (F.pgenl s n).1) (insert (F.gen (F.pgenl s n).2) (F.pgenl s n).2) := by simp [pgenl] theorem pgenl_length_eq (F : fresh α) (s : finset α) : ∀ n, (F.pgenl s n).1.length = n | 0 := rfl | (n+1) := by simp * theorem pgenl_subset (F : fresh α) (s : finset α) : ∀ n, s ⊆ (F.pgenl s n).2 | 0 := by simp | (n+1) := begin rcases finset.ssubset_iff.mp (F.gen_ssubset_insert (F.pgenl s n).2) with ⟨a, _, h₃⟩, have h₁ : s ⊆ (F.pgenl s n).2 := pgenl_subset _, have h₂ : (F.pgenl s n).2 ⊆ insert a (F.pgenl s n).2 := finset.subset_insert _ _, exact finset.subset.trans h₁ (finset.subset.trans h₂ h₃) end theorem pgenl_list_subset (F : fresh α) (s : finset α) : ∀ n, ∀ a ∈ (F.pgenl s n).1, a ∈ (F.pgenl s n).2 | 0 := by simp | (n+1) := λ a h, by simp at h; cases h; [simp [h], simp [pgenl_list_subset _ _ h]] @[simp] theorem gen_pgenl_not_mem (F : fresh α) (s : finset α) (n : ℕ) : F.gen (F.pgenl s n).2 ∉ s := mt (λ p, F.pgenl_subset s n p) (F.gen_not_mem _) @[simp] theorem gen_pgenl_not_mem_list (F : fresh α) (s : finset α) (n : ℕ) : F.gen (F.pgenl s n).2 ∉ (F.pgenl s n).1 := mt (F.pgenl_list_subset s n _) (F.gen_not_mem (F.pgenl s n).2) theorem pgenl_not_mem (F : fresh α) {s : finset α} {a} : ∀ {n}, a ∈ (F.pgenl s n).1 → a ∉ s | 0 h := by cases h | (n+1) h := by simp at h; cases h; [simp [h], simp [pgenl_not_mem h]] theorem pgenl_nodup (F : fresh α) (s : finset α) : ∀ n, (F.pgenl s n).1.nodup | 0 := list.nodup_nil | (n+1) := list.nodup_cons_of_nodup (by simp) (pgenl_nodup n) @[simp] theorem gen_pgenl_ne_of_mem (F : fresh α) {s : finset α} {a n} (h : a ∈ s) : a ≠ F.gen (F.pgenl s n).2 := F.gen_ne_of_mem $ F.pgenl_subset s n h theorem pgenl_not_mem_singleton_self (F : fresh α) (a) (n) : a ∉ (F.pgenl (finset.singleton a) n).1 := by induction n; simp * theorem pgenl_mem_singleton (F : fresh α) {a b n} (h : a ∈ (F.pgenl (finset.singleton b) n).1) : a ≠ b := λ h', F.pgenl_not_mem_singleton_self b n (by simpa [h'] using h) theorem pgenl_mem_union (F : fresh α) {s₁ s₂ : finset α} {n a} (h : a ∈ (F.pgenl (s₁ ∪ s₂) n).1) : a ∉ s₁ ∧ a ∉ s₂ := finset.not_mem_union.mp $ F.pgenl_not_mem h /- pgenf -/ /-- Generate a pair of a fresh atom set of the given cardinality and a new avoidance set. -/ def pgenf (F : fresh α) (s : finset α) (n : ℕ) : finset α × finset α := ⟨⟨(F.pgenl s n).1, F.pgenl_nodup s n⟩, (F.pgenl s n).2⟩ @[simp] theorem pgenf_zero (F : fresh α) (s : finset α) : F.pgenf s 0 = prod.mk ∅ s := rfl @[simp] theorem pgenf_succ (F : fresh α) (s : finset α) (n : ℕ) : F.pgenf s (n+1) = prod.mk (insert (F.gen (F.pgenf s n).2) (F.pgenf s n).1) (insert (F.gen (F.pgenf s n).2) (F.pgenf s n).2) := by simp [pgenf]; congr; exact (list.insert_of_not_mem (F.gen_pgenl_not_mem_list s n)).symm theorem pgenf_subset (F : fresh α) (s : finset α) (n : ℕ) : ∀ a ∈ (F.pgenf s n).1, a ∈ (F.pgenf s n).2 := F.pgenl_list_subset s n theorem pgenf_not_mem (F : fresh α) (s : finset α) (n : ℕ) : F.gen (F.pgenf s n).2 ∉ (F.pgenf s n).1 := F.gen_pgenl_not_mem_list s n end fresh /-- Fresh atom list generator -/ structure freshL (α : Type*) := /- Generate an atom list from an avoidance set -/ (gen : finset α → list α) /- The list has no duplicates. -/ (gen_nodup : ∀ (s : finset α), (gen s).nodup) /- The list is fresh. -/ (gen_not_mem : ∀ {s : finset α} {a : α}, a ∈ gen s → a ∉ s) namespace freshL variables [decidable_eq α] /- gen -/ @[simp] theorem gen_not_mem_of_subset (F : freshL α) {s s' : finset α} (ss : s ⊆ s') {a : α} (h : a ∈ s) : a ∉ F.gen s' := λ h', F.gen_not_mem h' (ss h) /- pgen -/ /-- Generate a pair of a fresh atom list and a new avoidance set. -/ def pgen (F : freshL α) (s : finset α) : list α × finset α := let l := F.gen s in ⟨l, l.foldr insert s⟩ theorem pgen_nodup (F : freshL α) (s : finset α) : (F.pgen s).1.nodup := F.gen_nodup s theorem pgen_not_mem (F : freshL α) : ∀ {s : finset α} {a : α}, a ∈ (F.pgen s).1 → a ∉ s := F.gen_not_mem theorem pgen_mem_union (F : freshL α) {s₁ s₂ : finset α} {a} (h : a ∈ (F.pgen (s₁ ∪ s₂)).1) : a ∉ s₁ ∧ a ∉ s₂ := finset.not_mem_union.mp $ F.pgen_not_mem h end freshL /- infinite nat -/ namespace finset /-- Successor of the maximum: the minimum nat not a member of a finite set -/ def max_succ (s : finset ℕ) : ℕ := match s.max with | none := 0 | some m := m + 1 end @[simp] theorem max_succ_empty : max_succ ∅ = 0 := rfl @[simp] theorem max_succ_of_ne_empty {s : finset ℕ} (h : s ≠ ∅) : s.max_succ = s.max.iget + 1 := let ⟨m, hm⟩ := finset.max_of_ne_empty h in by simp [option.mem_def.mp hm, max_succ, option.iget] theorem max_succ_not_mem (s : finset ℕ) : s.max_succ ∉ s := λ h, if p : s = ∅ then by simpa [p] using h else let ⟨m, hm⟩ := finset.max_of_ne_empty p in have hms : m+1 ∈ s := by simpa [max_succ, option.mem_def.mp hm] using h, m.not_succ_le_self $ le_max_of_mem hms hm end finset /-- A simple fresh nat generator -/ protected def fresh.nat : fresh ℕ := ⟨finset.max_succ, finset.max_succ_not_mem⟩ /-- Tagged pair: a value and a natural number. This is useful for associating strings with numbers and printing uniquely tagged strings. -/ @[derive decidable_eq] structure tagged (α : Type*) := (val : α) (tag : ℕ) namespace tagged instance [has_repr α] : has_repr (tagged α) := ⟨λ ⟨a, t⟩, repr a ++ "_" ++ repr t⟩ def zero (a : α) : tagged α := ⟨a, 0⟩ def succ : tagged α → tagged α | ⟨a, t⟩ := ⟨a, t.succ⟩ variables [_root_.decidable_eq α] /-- All tags for a given value. -/ def tags (s : finset (tagged α)) (a : α) : finset ℕ := (s.filter (λ (b : tagged α), a = b.val)).image tag def fresh (s : finset (tagged α)) (a : α) : tagged α := mk a (tags s a).max_succ theorem fresh_not_mem (s : finset (tagged α)) (a : α) : fresh s a ∉ s := have p : (tags s a).max_succ ∉ tags s a := finset.max_succ_not_mem _, by simp [tags] at p; exact λ h, p _ h rfl rfl theorem fresh_inj (s : finset (tagged α)) : function.injective (fresh s) := λ a₁ a₂ h, by simp [fresh] at h; exact h.1 def freshL (s : finset (tagged α)) : list α → list (tagged α) := list.map (fresh s) theorem freshL_nodup (s : finset (tagged α)) {l : list α} (nd : l.nodup) : (freshL s l).nodup := list.nodup_map (fresh_inj s) nd theorem freshL_not_mem {s : finset (tagged α)} : ∀ {l : list α} {a : tagged α}, a ∈ freshL s l → a ∉ s | [] a h := by cases h | (a'::_) a h := by simp [freshL] at h; cases h; [{subst h}, {rcases h with ⟨a', _, h⟩, induction h}]; exact fresh_not_mem s a' end tagged section fresh_tagged variables [decidable_eq α] {l : list α} /-- A fresh tagged pair generator for a particular atom. -/ protected def fresh.tagged (a : α) : fresh (tagged α) := ⟨λ s, tagged.fresh s a, λ s, tagged.fresh_not_mem s a⟩ /-- A fresh tagged list pair generator for a particular list of atoms. -/ protected def freshL.tagged (nd : l.nodup) : freshL (tagged α) := ⟨λ s, tagged.freshL s l, λ s, tagged.freshL_nodup s nd, λ _ _, tagged.freshL_not_mem⟩ theorem freshL.tagged_length_eq (s : finset (tagged α)) (nd : l.nodup) : ((freshL.tagged nd).pgen s).1.length = l.length := by simp [freshL.pgen, freshL.tagged, tagged.freshL] end fresh_tagged
334b1f589a1d2a14dc5b4d76e6e5fb0abdc109aa
87a08a8e9b222ec02f3327dca4ae24590c1b3de9
/src/data/set/lattice.lean
6dfb2be4ef2d872b6109066b9eb9b1e5f8be61d1
[ "Apache-2.0" ]
permissive
naussicaa/mathlib
86d05223517a39e80920549a8052f9cf0e0b77b8
1ef2c2df20cf45c21675d855436228c7ae02d47a
refs/heads/master
1,592,104,950,080
1,562,073,069,000
1,562,073,069,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
34,328
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, Johannes Hölzl, Mario Carneiro -- QUESTION: can make the first argument in ∀ x ∈ a, ... implicit? -/ import logic.basic data.set.basic data.equiv.basic import order.complete_boolean_algebra category.basic import tactic.finish data.sigma.basic order.galois_connection open function tactic set lattice auto universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace set instance lattice_set : complete_lattice (set α) := { lattice.complete_lattice . le := (⊆), le_refl := subset.refl, le_trans := assume a b c, subset.trans, le_antisymm := assume a b, subset.antisymm, lt := λ x y, x ⊆ y ∧ ¬ y ⊆ x, lt_iff_le_not_le := λ x y, iff.refl _, sup := (∪), le_sup_left := subset_union_left, le_sup_right := subset_union_right, sup_le := assume a b c, union_subset, inf := (∩), inf_le_left := inter_subset_left, inf_le_right := inter_subset_right, le_inf := assume a b c, subset_inter, top := {a | true }, le_top := assume s a h, trivial, bot := ∅, bot_le := assume s a, false.elim, Sup := λs, {a | ∃ t ∈ s, a ∈ t }, le_Sup := assume s t t_in a a_in, ⟨t, ⟨t_in, a_in⟩⟩, Sup_le := assume s t h a ⟨t', ⟨t'_in, a_in⟩⟩, h t' t'_in a_in, Inf := λs, {a | ∀ t ∈ s, a ∈ t }, le_Inf := assume s t h a a_in t' t'_in, h t' t'_in a_in, Inf_le := assume s t t_in a h, h _ t_in } instance : distrib_lattice (set α) := { le_sup_inf := λ s t u x, or_and_distrib_left.2, ..set.lattice_set } lemma monotone_image {f : α → β} : monotone (image f) := assume s t, assume h : s ⊆ t, image_subset _ h theorem monotone_inter [preorder β] {f g : β → set α} (hf : monotone f) (hg : monotone g) : monotone (λx, f x ∩ g x) := assume b₁ b₂ h, inter_subset_inter (hf h) (hg h) theorem monotone_union [preorder β] {f g : β → set α} (hf : monotone f) (hg : monotone g) : monotone (λx, f x ∪ g x) := assume b₁ b₂ h, union_subset_union (hf h) (hg h) theorem monotone_set_of [preorder α] {p : α → β → Prop} (hp : ∀b, monotone (λa, p a b)) : monotone (λa, {b | p a b}) := assume a a' h b, hp b h section galois_connection variables {f : α → β} protected lemma image_preimage : galois_connection (image f) (preimage f) := assume a b, image_subset_iff def kern_image (f : α → β) (s : set α) : set β := {y | ∀x, f x = y → x ∈ s} protected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) := assume a b, ⟨ assume h x hx y hy, have f y ∈ a, from hy.symm ▸ hx, h this, assume h x (hx : f x ∈ a), h hx x rfl⟩ end galois_connection /- union and intersection over a family of sets indexed by a type -/ /-- Indexed union of a family of sets -/ @[reducible] def Union (s : ι → set β) : set β := supr s /-- Indexed intersection of a family of sets -/ @[reducible] def Inter (s : ι → set β) : set β := infi s notation `⋃` binders `, ` r:(scoped f, Union f) := r notation `⋂` binders `, ` r:(scoped f, Inter f) := r @[simp] theorem mem_Union {x : β} {s : ι → set β} : x ∈ Union s ↔ ∃ i, x ∈ s i := ⟨assume ⟨t, ⟨⟨a, (t_eq : s a = t)⟩, (h : x ∈ t)⟩⟩, ⟨a, t_eq.symm ▸ h⟩, assume ⟨a, h⟩, ⟨s a, ⟨⟨a, rfl⟩, h⟩⟩⟩ /- alternative proof: dsimp [Union, supr, Sup]; simp -/ -- TODO: more rewrite rules wrt forall / existentials and logical connectives -- TODO: also eliminate ∃i, ... ∧ i = t ∧ ... @[simp] theorem mem_Inter {x : β} {s : ι → set β} : x ∈ Inter s ↔ ∀ i, x ∈ s i := ⟨assume (h : ∀a ∈ {a : set β | ∃i, s i = a}, x ∈ a) a, h (s a) ⟨a, rfl⟩, assume h t ⟨a, (eq : s a = t)⟩, eq ▸ h a⟩ theorem Union_subset {s : ι → set β} {t : set β} (h : ∀ i, s i ⊆ t) : (⋃ i, s i) ⊆ t := -- TODO: should be simpler when sets' order is based on lattices @supr_le (set β) _ set.lattice_set _ _ h theorem Union_subset_iff {α : Sort u} {s : α → set β} {t : set β} : (⋃ i, s i) ⊆ t ↔ (∀ i, s i ⊆ t):= ⟨assume h i, subset.trans (le_supr s _) h, Union_subset⟩ theorem mem_Inter_of_mem {α : Sort u} {x : β} {s : α → set β} : (∀ i, x ∈ s i) → (x ∈ ⋂ i, s i) := assume h t ⟨a, (eq : s a = t)⟩, eq ▸ h a theorem subset_Inter {t : set β} {s : α → set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := -- TODO: should be simpler when sets' order is based on lattices @le_infi (set β) _ set.lattice_set _ _ h theorem subset_Union : ∀ (s : ι → set β) (i : ι), s i ⊆ (⋃ i, s i) := le_supr theorem Inter_subset : ∀ (s : ι → set β) (i : ι), (⋂ i, s i) ⊆ s i := infi_le theorem Union_const [inhabited ι] (s : set β) : (⋃ i:ι, s) = s := ext $ by simp theorem Inter_const [inhabited ι] (s : set β) : (⋂ i:ι, s) = s := ext $ by simp @[simp] -- complete_boolean_algebra theorem compl_Union (s : ι → set β) : - (⋃ i, s i) = (⋂ i, - s i) := ext (by simp) -- classical -- complete_boolean_algebra theorem compl_Inter (s : ι → set β) : -(⋂ i, s i) = (⋃ i, - s i) := ext (λ x, by simp [classical.not_forall]) -- classical -- complete_boolean_algebra theorem Union_eq_comp_Inter_comp (s : ι → set β) : (⋃ i, s i) = - (⋂ i, - s i) := by simp [compl_Inter, compl_compl] -- classical -- complete_boolean_algebra theorem Inter_eq_comp_Union_comp (s : ι → set β) : (⋂ i, s i) = - (⋃ i, -s i) := by simp [compl_compl] theorem inter_Union (s : set β) (t : ι → set β) : s ∩ (⋃ i, t i) = ⋃ i, s ∩ t i := ext $ by simp theorem Union_inter (s : set β) (t : ι → set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := ext $ by simp theorem Union_union_distrib (s : ι → set β) (t : ι → set β) : (⋃ i, s i ∪ t i) = (⋃ i, s i) ∪ (⋃ i, t i) := ext $ by simp [exists_or_distrib] theorem Inter_inter_distrib (s : ι → set β) (t : ι → set β) : (⋂ i, s i ∩ t i) = (⋂ i, s i) ∩ (⋂ i, t i) := ext $ by simp [forall_and_distrib] theorem union_Union [inhabited ι] (s : set β) (t : ι → set β) : s ∪ (⋃ i, t i) = ⋃ i, s ∪ t i := by rw [Union_union_distrib, Union_const] theorem Union_union [inhabited ι] (s : set β) (t : ι → set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := by rw [Union_union_distrib, Union_const] theorem inter_Inter [inhabited ι] (s : set β) (t : ι → set β) : s ∩ (⋂ i, t i) = ⋂ i, s ∩ t i := by rw [Inter_inter_distrib, Inter_const] theorem Inter_inter [inhabited ι] (s : set β) (t : ι → set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := by rw [Inter_inter_distrib, Inter_const] -- classical theorem union_Inter (s : set β) (t : ι → set β) : s ∪ (⋂ i, t i) = ⋂ i, s ∪ t i := ext $ assume x, by simp [classical.forall_or_distrib_left] theorem Union_diff (s : set β) (t : ι → set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := Union_inter _ _ theorem diff_Union [inhabited ι] (s : set β) (t : ι → set β) : s \ (⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_Union, inter_Inter]; refl theorem diff_Inter (s : set β) (t : ι → set β) : s \ (⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_Inter, inter_Union]; refl /- bounded unions and intersections -/ theorem mem_bUnion_iff {s : set α} {t : α → set β} {y : β} : y ∈ (⋃ x ∈ s, t x) ↔ ∃ x, x ∈ s ∧ y ∈ t x := by simp theorem mem_bInter_iff {s : set α} {t : α → set β} {y : β} : y ∈ (⋂ x ∈ s, t x) ↔ ∀ x ∈ s, y ∈ t x := by simp theorem mem_bUnion {s : set α} {t : α → set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := by simp; exact ⟨x, ⟨xs, ytx⟩⟩ theorem mem_bInter {s : set α} {t : α → set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := by simp; assumption theorem bUnion_subset {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, u x ⊆ t) : (⋃ x ∈ s, u x) ⊆ t := show (⨆ x ∈ s, u x) ≤ t, -- TODO: should not be necessary when sets' order is based on lattices from supr_le $ assume x, supr_le (h x) theorem subset_bInter {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, t ⊆ u x) : t ⊆ (⋂ x ∈ s, u x) := show t ≤ (⨅ x ∈ s, u x), -- TODO: should not be necessary when sets' order is based on lattices from le_infi $ assume x, le_infi (h x) theorem subset_bUnion_of_mem {s : set α} {u : α → set β} {x : α} (xs : x ∈ s) : u x ⊆ (⋃ x ∈ s, u x) := show u x ≤ (⨆ x ∈ s, u x), from le_supr_of_le x $ le_supr _ xs theorem bInter_subset_of_mem {s : set α} {t : α → set β} {x : α} (xs : x ∈ s) : (⋂ x ∈ s, t x) ⊆ t x := show (⨅x ∈ s, t x) ≤ t x, from infi_le_of_le x $ infi_le _ xs theorem bUnion_subset_bUnion_left {s s' : set α} {t : α → set β} (h : s ⊆ s') : (⋃ x ∈ s, t x) ⊆ (⋃ x ∈ s', t x) := bUnion_subset (λ x xs, subset_bUnion_of_mem (h xs)) theorem bInter_subset_bInter_left {s s' : set α} {t : α → set β} (h : s' ⊆ s) : (⋂ x ∈ s, t x) ⊆ (⋂ x ∈ s', t x) := subset_bInter (λ x xs, bInter_subset_of_mem (h xs)) theorem bUnion_subset_bUnion_right {s : set α} {t1 t2 : α → set β} (h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋃ x ∈ s, t1 x) ⊆ (⋃ x ∈ s, t2 x) := bUnion_subset (λ x xs, subset.trans (h x xs) (subset_bUnion_of_mem xs)) theorem bInter_subset_bInter_right {s : set α} {t1 t2 : α → set β} (h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋂ x ∈ s, t1 x) ⊆ (⋂ x ∈ s, t2 x) := subset_bInter (λ x xs, subset.trans (bInter_subset_of_mem xs) (h x xs)) theorem bUnion_eq_Union (s : set α) (t : α → set β) : (⋃ x ∈ s, t x) = (⋃ x : s, t x.1) := set.ext $ by simp theorem bInter_eq_Inter (s : set α) (t : α → set β) : (⋂ x ∈ s, t x) = (⋂ x : s, t x.1) := set.ext $ by simp @[simp] theorem bInter_empty (u : α → set β) : (⋂ x ∈ (∅ : set α), u x) = univ := show (⨅x ∈ (∅ : set α), u x) = ⊤, -- simplifier should be able to rewrite x ∈ ∅ to false. from infi_emptyset @[simp] theorem bInter_univ (u : α → set β) : (⋂ x ∈ @univ α, u x) = ⋂ x, u x := infi_univ -- TODO(Jeremy): here is an artifact of the the encoding of bounded intersection: -- without dsimp, the next theorem fails to type check, because there is a lambda -- in a type that needs to be contracted. Using simp [eq_of_mem_singleton xa] also works. @[simp] theorem bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : set α), s x) = s a := show (⨅ x ∈ ({a} : set α), s x) = s a, by simp theorem bInter_union (s t : set α) (u : α → set β) : (⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) := show (⨅ x ∈ s ∪ t, u x) = (⨅ x ∈ s, u x) ⊓ (⨅ x ∈ t, u x), from infi_union -- TODO(Jeremy): simp [insert_eq, bInter_union] doesn't work @[simp] theorem bInter_insert (a : α) (s : set α) (t : α → set β) : (⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) := begin rw insert_eq, simp [bInter_union] end -- TODO(Jeremy): another example of where an annotation is needed theorem bInter_pair (a b : α) (s : α → set β) : (⋂ x ∈ ({a, b} : set α), s x) = s a ∩ s b := by rw insert_of_has_insert; simp [inter_comm] @[simp] theorem bUnion_empty (s : α → set β) : (⋃ x ∈ (∅ : set α), s x) = ∅ := supr_emptyset @[simp] theorem bUnion_univ (s : α → set β) : (⋃ x ∈ @univ α, s x) = ⋃ x, s x := supr_univ @[simp] theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : set α), s x) = s a := supr_singleton @[simp] theorem bUnion_of_singleton (s : set α) : (⋃ x ∈ s, {x}) = s := ext $ by simp theorem bUnion_union (s t : set α) (u : α → set β) : (⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) := supr_union -- TODO(Jeremy): once again, simp doesn't do it alone. @[simp] theorem bUnion_insert (a : α) (s : set α) (t : α → set β) : (⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) := begin rw [insert_eq], simp [bUnion_union] end theorem bUnion_pair (a b : α) (s : α → set β) : (⋃ x ∈ ({a, b} : set α), s x) = s a ∪ s b := by rw insert_of_has_insert; simp [union_comm] @[simp] -- complete_boolean_algebra theorem compl_bUnion (s : set α) (t : α → set β) : - (⋃ i ∈ s, t i) = (⋂ i ∈ s, - t i) := ext (λ x, by simp) -- classical -- complete_boolean_algebra theorem compl_bInter (s : set α) (t : α → set β) : -(⋂ i ∈ s, t i) = (⋃ i ∈ s, - t i) := ext (λ x, by simp [classical.not_forall]) theorem inter_bUnion (s : set α) (t : α → set β) (u : set β) : u ∩ (⋃ i ∈ s, t i) = ⋃ i ∈ s, u ∩ t i := begin ext x, simp only [exists_prop, mem_Union, mem_inter_eq], exact ⟨λ ⟨hx, ⟨i, is, xi⟩⟩, ⟨i, is, hx, xi⟩, λ ⟨i, is, hx, xi⟩, ⟨hx, ⟨i, is, xi⟩⟩⟩ end theorem bUnion_inter (s : set α) (t : α → set β) (u : set β) : (⋃ i ∈ s, t i) ∩ u = (⋃ i ∈ s, t i ∩ u) := by simp [@inter_comm _ _ u, inter_bUnion] /-- Intersection of a set of sets. -/ @[reducible] def sInter (S : set (set α)) : set α := Inf S prefix `⋂₀`:110 := sInter theorem mem_sUnion_of_mem {x : α} {t : set α} {S : set (set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀ S := ⟨t, ⟨ht, hx⟩⟩ @[simp] theorem mem_sUnion {x : α} {S : set (set α)} : x ∈ ⋃₀ S ↔ ∃t ∈ S, x ∈ t := iff.rfl -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : set α} {S : set (set α)} (hx : x ∉ ⋃₀ S) (ht : t ∈ S) : x ∉ t := λ h, hx ⟨t, ht, h⟩ @[simp] theorem mem_sInter {x : α} {S : set (set α)} : x ∈ ⋂₀ S ↔ ∀ t ∈ S, x ∈ t := iff.rfl theorem sInter_subset_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := Inf_le tS theorem subset_sUnion_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : t ⊆ ⋃₀ S := le_Sup tS lemma subset_sUnion_of_subset {s : set α} (t : set (set α)) (u : set α) (h₁ : s ⊆ u) (h₂ : u ∈ t) : s ⊆ ⋃₀ t := subset.trans h₁ (subset_sUnion_of_mem h₂) theorem sUnion_subset {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t' ⊆ t) : (⋃₀ S) ⊆ t := Sup_le h theorem sUnion_subset_iff {s : set (set α)} {t : set α} : ⋃₀ s ⊆ t ↔ ∀t' ∈ s, t' ⊆ t := ⟨assume h t' ht', subset.trans (subset_sUnion_of_mem ht') h, sUnion_subset⟩ theorem subset_sInter {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t ⊆ t') : t ⊆ (⋂₀ S) := le_Inf h theorem sUnion_subset_sUnion {S T : set (set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T := sUnion_subset $ λ s hs, subset_sUnion_of_mem (h hs) theorem sInter_subset_sInter {S T : set (set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter $ λ s hs, sInter_subset_of_mem (h hs) @[simp] theorem sUnion_empty : ⋃₀ ∅ = (∅ : set α) := Sup_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : set α) := Inf_empty @[simp] theorem sUnion_singleton (s : set α) : ⋃₀ {s} = s := Sup_singleton @[simp] theorem sInter_singleton (s : set α) : ⋂₀ {s} = s := Inf_singleton theorem sUnion_union (S T : set (set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := Sup_union theorem sInter_union (S T : set (set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := Inf_union @[simp] theorem sUnion_insert (s : set α) (T : set (set α)) : ⋃₀ (insert s T) = s ∪ ⋃₀ T := Sup_insert @[simp] theorem sInter_insert (s : set α) (T : set (set α)) : ⋂₀ (insert s T) = s ∩ ⋂₀ T := Inf_insert theorem sUnion_pair (s t : set α) : ⋃₀ {s, t} = s ∪ t := (sUnion_insert _ _).trans $ by rw [union_comm, sUnion_singleton] theorem sInter_pair (s t : set α) : ⋂₀ {s, t} = s ∩ t := (sInter_insert _ _).trans $ by rw [inter_comm, sInter_singleton] @[simp] theorem sUnion_image (f : α → set β) (s : set α) : ⋃₀ (f '' s) = ⋃ x ∈ s, f x := Sup_image @[simp] theorem sInter_image (f : α → set β) (s : set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := Inf_image @[simp] theorem sUnion_range (f : ι → set β) : ⋃₀ (range f) = ⋃ x, f x := Sup_range @[simp] theorem sInter_range (f : ι → set β) : ⋂₀ (range f) = ⋂ x, f x := Inf_range theorem compl_sUnion (S : set (set α)) : - ⋃₀ S = ⋂₀ (compl '' S) := set.ext $ assume x, ⟨assume : ¬ (∃s∈S, x ∈ s), assume s h, match s, h with ._, ⟨t, hs, rfl⟩ := assume h, this ⟨t, hs, h⟩ end, assume : ∀s, s ∈ compl '' S → x ∈ s, assume ⟨t, tS, xt⟩, this (compl t) (mem_image_of_mem _ tS) xt⟩ -- classical theorem sUnion_eq_compl_sInter_compl (S : set (set α)) : ⋃₀ S = - ⋂₀ (compl '' S) := by rw [←compl_compl (⋃₀ S), compl_sUnion] -- classical theorem compl_sInter (S : set (set α)) : - ⋂₀ S = ⋃₀ (compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] -- classical theorem sInter_eq_comp_sUnion_compl (S : set (set α)) : ⋂₀ S = -(⋃₀ (compl '' S)) := by rw [←compl_compl (⋂₀ S), compl_sInter] theorem inter_empty_of_inter_sUnion_empty {s t : set α} {S : set (set α)} (hs : t ∈ S) (h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ := eq_empty_of_subset_empty $ by rw ← h; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) theorem Union_eq_sUnion_range (s : α → set β) : (⋃ i, s i) = ⋃₀ (range s) := by rw [← image_univ, sUnion_image]; simp theorem Inter_eq_sInter_range {α I : Type} (s : I → set α) : (⋂ i, s i) = ⋂₀ (range s) := by rw [← image_univ, sInter_image]; simp theorem range_sigma_eq_Union_range {γ : α → Type*} (f : sigma γ → β) : range f = ⋃ a, range (λ b, f ⟨a, b⟩) := set.ext $ by simp theorem Union_eq_range_sigma (s : α → set β) : (⋃ i, s i) = range (λ a : Σ i, s i, a.2) := by simp [set.ext_iff] lemma sUnion_mono {s t : set (set α)} (h : s ⊆ t) : (⋃₀ s) ⊆ (⋃₀ t) := sUnion_subset $ assume t' ht', subset_sUnion_of_mem $ h ht' lemma Union_subset_Union {s t : ι → set α} (h : ∀i, s i ⊆ t i) : (⋃i, s i) ⊆ (⋃i, t i) := @supr_le_supr (set α) ι _ s t h lemma Union_subset_Union2 {ι₂ : Sort*} {s : ι → set α} {t : ι₂ → set α} (h : ∀i, ∃j, s i ⊆ t j) : (⋃i, s i) ⊆ (⋃i, t i) := @supr_le_supr2 (set α) ι ι₂ _ s t h lemma Union_subset_Union_const {ι₂ : Sort x} {s : set α} (h : ι → ι₂) : (⋃ i:ι, s) ⊆ (⋃ j:ι₂, s) := @supr_le_supr_const (set α) ι ι₂ _ s h @[simp] lemma Union_of_singleton (α : Type u) : (⋃(x : α), {x}) = @set.univ α := ext $ λ x, ⟨λ h, ⟨⟩, λ h, ⟨{x}, ⟨⟨x, rfl⟩, mem_singleton x⟩⟩⟩ theorem bUnion_subset_Union (s : set α) (t : α → set β) : (⋃ x ∈ s, t x) ⊆ (⋃ x, t x) := Union_subset_Union $ λ i, Union_subset $ λ h, by refl lemma sUnion_eq_bUnion {s : set (set α)} : (⋃₀ s) = (⋃ (i : set α) (h : i ∈ s), i) := set.ext $ by simp lemma sInter_eq_bInter {s : set (set α)} : (⋂₀ s) = (⋂ (i : set α) (h : i ∈ s), i) := set.ext $ by simp lemma sUnion_eq_Union {s : set (set α)} : (⋃₀ s) = (⋃ (i : s), i.1) := set.ext $ λ x, by simp lemma sInter_eq_Inter {s : set (set α)} : (⋂₀ s) = (⋂ (i : s), i.1) := set.ext $ λ x, by simp lemma union_eq_Union {s₁ s₂ : set α} : s₁ ∪ s₂ = ⋃ b : bool, cond b s₁ s₂ := set.ext $ λ x, by simp [bool.exists_bool, or_comm] lemma inter_eq_Inter {s₁ s₂ : set α} : s₁ ∩ s₂ = ⋂ b : bool, cond b s₁ s₂ := set.ext $ λ x, by simp [bool.forall_bool, and_comm] instance : complete_boolean_algebra (set α) := { neg := compl, sub := (\), inf_neg_eq_bot := assume s, ext $ assume x, ⟨assume ⟨h, nh⟩, nh h, false.elim⟩, sup_neg_eq_top := assume s, ext $ assume x, ⟨assume h, trivial, assume _, classical.em $ x ∈ s⟩, le_sup_inf := distrib_lattice.le_sup_inf, sub_eq := assume x y, rfl, infi_sup_le_sup_Inf := assume s t x, show x ∈ (⋂ b ∈ t, s ∪ b) → x ∈ s ∪ (⋂₀ t), by simp; exact assume h, or.imp_right (assume hn : x ∉ s, assume i hi, or.resolve_left (h i hi) hn) (classical.em $ x ∈ s), inf_Sup_le_supr_inf := assume s t x, show x ∈ s ∩ (⋃₀ t) → x ∈ (⋃ b ∈ t, s ∩ b), by simp [-and_imp, and.left_comm], ..set.lattice_set } lemma sInter_union_sInter {S T : set (set α)} : (⋂₀S) ∪ (⋂₀T) = (⋂p ∈ set.prod S T, (p : (set α) × (set α)).1 ∪ p.2) := Inf_sup_Inf lemma sUnion_inter_sUnion {s t : set (set α)} : (⋃₀s) ∩ (⋃₀t) = (⋃p ∈ set.prod s t, (p : (set α) × (set α )).1 ∩ p.2) := Sup_inf_Sup lemma sInter_bUnion {S : set (set α)} {T : set α → set (set α)} (hT : ∀s∈S, s = ⋂₀ T s) : ⋂₀ (⋃s∈S, T s) = ⋂₀ S := begin ext, simp only [and_imp, exists_prop, set.mem_sInter, set.mem_Union, exists_imp_distrib], split, { assume H s sS, rw [hT s sS, mem_sInter], assume t tTs, apply H t s sS tTs }, { assume H t s sS tTs, have xs : x ∈ s := H s sS, have : s ⊆ t, { have Z := hT s sS, rw sInter_eq_bInter at Z, rw Z, apply bInter_subset_of_mem, exact tTs }, exact this xs } end lemma sUnion_bUnion {S : set (set α)} {T : set α → set (set α)} (hT : ∀s∈S, s = ⋃₀ T s) : ⋃₀ (⋃s∈S, T s) = ⋃₀ S := begin ext, simp only [exists_prop, set.mem_Union, set.mem_set_of_eq], split, { rintros ⟨t, ⟨⟨s, ⟨sS, tTs⟩⟩, xt⟩⟩, refine ⟨s, ⟨sS, _⟩⟩, rw hT s sS, exact subset_sUnion_of_mem tTs xt }, { rintros ⟨s, ⟨sS, xs⟩⟩, rw hT s sS at xs, rcases mem_sUnion.1 xs with ⟨t, tTs, xt⟩, exact ⟨t, ⟨⟨s, ⟨sS, tTs⟩⟩, xt⟩⟩ } end lemma Union_range_eq_sUnion {α β : Type*} (C : set (set α)) {f : ∀(s : C), β → s} (hf : ∀(s : C), surjective (f s)) : (⋃(y : β), range (λ(s : C), (f s y).val)) = ⋃₀ C := begin ext x, split, { rintro ⟨s, ⟨y, rfl⟩, ⟨⟨s, hs⟩, rfl⟩⟩, refine ⟨_, hs, _⟩, exact (f ⟨s, hs⟩ y).2 }, { rintro ⟨s, hs, hx⟩, cases hf ⟨s, hs⟩ ⟨x, hx⟩ with y hy, refine ⟨_, ⟨y, rfl⟩, ⟨⟨s, hs⟩, _⟩⟩, exact congr_arg subtype.val hy } end lemma Union_range_eq_Union {ι α β : Type*} (C : ι → set α) {f : ∀(x : ι), β → C x} (hf : ∀(x : ι), surjective (f x)) : (⋃(y : β), range (λ(x : ι), (f x y).val)) = ⋃x, C x := begin ext x, rw [mem_Union, mem_Union], split, { rintro ⟨y, ⟨i, rfl⟩⟩, exact ⟨i, (f i y).2⟩ }, { rintro ⟨i, hx⟩, cases hf i ⟨x, hx⟩ with y hy, refine ⟨y, ⟨i, congr_arg subtype.val hy⟩⟩ } end @[simp] theorem sub_eq_diff (s t : set α) : s - t = s \ t := rfl section variables {p : Prop} {μ : p → set α} @[simp] lemma Inter_pos (hp : p) : (⋂h:p, μ h) = μ hp := infi_pos hp @[simp] lemma Inter_neg (hp : ¬ p) : (⋂h:p, μ h) = univ := infi_neg hp @[simp] lemma Union_pos (hp : p) : (⋃h:p, μ h) = μ hp := supr_pos hp @[simp] lemma Union_neg (hp : ¬ p) : (⋃h:p, μ h) = ∅ := supr_neg hp @[simp] lemma Union_empty {ι : Sort*} : (⋃i:ι, ∅:set α) = ∅ := supr_bot @[simp] lemma Inter_univ {ι : Sort*} : (⋂i:ι, univ:set α) = univ := infi_top end section image lemma image_Union {f : α → β} {s : ι → set α} : f '' (⋃ i, s i) = (⋃i, f '' s i) := begin apply set.ext, intro x, simp [image, exists_and_distrib_right.symm, -exists_and_distrib_right], exact exists_swap end lemma univ_subtype {p : α → Prop} : (univ : set (subtype p)) = (⋃x (h : p x), {⟨x, h⟩}) := set.ext $ assume ⟨x, h⟩, by simp [h] lemma range_eq_Union {ι} (f : ι → α) : range f = (⋃i, {f i}) := set.ext $ assume a, by simp [@eq_comm α a] lemma image_eq_Union (f : α → β) (s : set α) : f '' s = (⋃i∈s, {f i}) := set.ext $ assume b, by simp [@eq_comm β b] lemma bUnion_range {f : ι → α} {g : α → set β} : (⋃x ∈ range f, g x) = (⋃y, g (f y)) := by rw [← sUnion_image, ← range_comp, sUnion_range] lemma bInter_range {f : ι → α} {g : α → set β} : (⋂x ∈ range f, g x) = (⋂y, g (f y)) := by rw [← sInter_image, ← range_comp, sInter_range] variables {s : set γ} {f : γ → α} {g : α → set β} lemma bUnion_image : (⋃x∈ (f '' s), g x) = (⋃y ∈ s, g (f y)) := by rw [← sUnion_image, ← image_comp, sUnion_image] lemma bInter_image : (⋂x∈ (f '' s), g x) = (⋂y ∈ s, g (f y)) := by rw [← sInter_image, ← image_comp, sInter_image] end image section preimage theorem monotone_preimage {f : α → β} : monotone (preimage f) := assume a b h, preimage_mono h @[simp] theorem preimage_Union {ι : Sort w} {f : α → β} {s : ι → set β} : preimage f (⋃i, s i) = (⋃i, preimage f (s i)) := set.ext $ by simp [preimage] theorem preimage_bUnion {ι} {f : α → β} {s : set ι} {t : ι → set β} : preimage f (⋃i ∈ s, t i) = (⋃i ∈ s, preimage f (t i)) := by simp @[simp] theorem preimage_sUnion {f : α → β} {s : set (set β)} : preimage f (⋃₀ s) = (⋃t ∈ s, preimage f t) := set.ext $ by simp [preimage] lemma preimage_Inter {ι : Sort*} {s : ι → set β} {f : α → β} : f ⁻¹' (⋂ i, s i) = (⋂ i, f ⁻¹' s i) := by ext; simp lemma preimage_bInter {s : γ → set β} {t : set γ} {f : α → β} : f ⁻¹' (⋂ i∈t, s i) = (⋂ i∈t, f ⁻¹' s i) := by ext; simp end preimage section seq def seq (s : set (α → β)) (t : set α) : set β := {b | ∃f∈s, ∃a∈t, (f : α → β) a = b} lemma seq_def {s : set (α → β)} {t : set α} : seq s t = ⋃f∈s, f '' t := set.ext $ by simp [seq] @[simp] lemma mem_seq_iff {s : set (α → β)} {t : set α} {b : β} : b ∈ seq s t ↔ ∃ (f ∈ s) (a ∈ t), (f : α → β) a = b := iff.refl _ lemma seq_subset {s : set (α → β)} {t : set α} {u : set β} : seq s t ⊆ u ↔ (∀f∈s, ∀a∈t, (f : α → β) a ∈ u) := iff.intro (assume h f hf a ha, h ⟨f, hf, a, ha, rfl⟩) (assume h b ⟨f, hf, a, ha, eq⟩, eq ▸ h f hf a ha) lemma seq_mono {s₀ s₁ : set (α → β)} {t₀ t₁ : set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) : seq s₀ t₀ ⊆ seq s₁ t₁ := assume b ⟨f, hf, a, ha, eq⟩, ⟨f, hs hf, a, ht ha, eq⟩ lemma singleton_seq {f : α → β} {t : set α} : set.seq {f} t = f '' t := set.ext $ by simp lemma seq_singleton {s : set (α → β)} {a : α} : set.seq s {a} = (λf:α→β, f a) '' s := set.ext $ by simp lemma seq_seq {s : set (β → γ)} {t : set (α → β)} {u : set α} : seq s (seq t u) = seq (seq ((∘) '' s) t) u := begin refine set.ext (assume c, iff.intro _ _), { rintros ⟨f, hfs, b, ⟨g, hg, a, hau, rfl⟩, rfl⟩, exact ⟨f ∘ g, ⟨(∘) f, mem_image_of_mem _ hfs, g, hg, rfl⟩, a, hau, rfl⟩ }, { rintros ⟨fg, ⟨fc, ⟨f, hfs, rfl⟩, g, hgt, rfl⟩, a, ha, rfl⟩, exact ⟨f, hfs, g a, ⟨g, hgt, a, ha, rfl⟩, rfl⟩ } end lemma image_seq {f : β → γ} {s : set (α → β)} {t : set α} : f '' seq s t = seq ((∘) f '' s) t := by rw [← singleton_seq, ← singleton_seq, seq_seq, image_singleton] lemma prod_eq_seq {s : set α} {t : set β} : set.prod s t = (prod.mk '' s).seq t := begin ext ⟨a, b⟩, split, { rintros ⟨ha, hb⟩, exact ⟨prod.mk a, ⟨a, ha, rfl⟩, b, hb, rfl⟩ }, { rintros ⟨f, ⟨x, hx, rfl⟩, y, hy, eq⟩, rw ← eq, exact ⟨hx, hy⟩ } end lemma prod_image_seq_comm (s : set α) (t : set β) : (prod.mk '' s).seq t = seq ((λb a, (a, b)) '' t) s := by rw [← prod_eq_seq, ← image_swap_prod, prod_eq_seq, image_seq, ← image_comp] end seq theorem monotone_prod [preorder α] {f : α → set β} {g : α → set γ} (hf : monotone f) (hg : monotone g) : monotone (λx, set.prod (f x) (g x)) := assume a b h, prod_mono (hf h) (hg h) instance : monad set := { pure := λ(α : Type u) a, {a}, bind := λ(α β : Type u) s f, ⋃i∈s, f i, seq := λ(α β : Type u), set.seq, map := λ(α β : Type u), set.image } instance : is_lawful_monad set := { pure_bind := assume α β x f, by simp, bind_assoc := assume α β γ s f g, set.ext $ assume a, by simp [exists_and_distrib_right.symm, -exists_and_distrib_right, exists_and_distrib_left.symm, -exists_and_distrib_left, and_assoc]; exact exists_swap, id_map := assume α, id_map, bind_pure_comp_eq_map := assume α β f s, set.ext $ by simp [set.image, eq_comm], bind_map_eq_seq := assume α β s t, by simp [seq_def] } instance : is_comm_applicative (set : Type u → Type u) := ⟨ assume α β s t, prod_image_seq_comm s t ⟩ section monad variables {α' β' : Type u} {s : set α'} {f : α' → set β'} {g : set (α' → β')} @[simp] lemma bind_def : s >>= f = ⋃i∈s, f i := rfl @[simp] lemma fmap_eq_image (f : α' → β') : f <$> s = f '' s := rfl @[simp] lemma seq_eq_set_seq {α β : Type*} (s : set (α → β)) (t : set α) : s <*> t = s.seq t := rfl @[simp] lemma pure_def (a : α) : (pure a : set α) = {a} := rfl end monad section pi lemma pi_def {α : Type*} {π : α → Type*} (i : set α) (s : Πa, set (π a)) : pi i s = (⋂ a∈i, ((λf:(Πa, π a), f a) ⁻¹' (s a))) := by ext; simp [pi] end pi end set /- disjoint sets -/ section disjoint variable [semilattice_inf_bot α] /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) -/ def disjoint (a b : α) : Prop := a ⊓ b ≤ ⊥ theorem disjoint.eq_bot {a b : α} (h : disjoint a b) : a ⊓ b = ⊥ := eq_bot_iff.2 h theorem disjoint_iff {a b : α} : disjoint a b ↔ a ⊓ b = ⊥ := eq_bot_iff.symm theorem disjoint.comm {a b : α} : disjoint a b ↔ disjoint b a := by rw [disjoint, disjoint, inf_comm] theorem disjoint.symm {a b : α} : disjoint a b → disjoint b a := disjoint.comm.1 @[simp] theorem disjoint_bot_left {a : α} : disjoint ⊥ a := disjoint_iff.2 bot_inf_eq @[simp] theorem disjoint_bot_right {a : α} : disjoint a ⊥ := disjoint_iff.2 inf_bot_eq theorem disjoint_mono {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : disjoint b d → disjoint a c := le_trans (inf_le_inf h₁ h₂) theorem disjoint_mono_left {a b c : α} (h : a ≤ b) : disjoint b c → disjoint a c := disjoint_mono h (le_refl _) theorem disjoint_mono_right {a b c : α} (h : b ≤ c) : disjoint a c → disjoint a b := disjoint_mono (le_refl _) h @[simp] lemma disjoint_self {a : α} : disjoint a a ↔ a = ⊥ := by simp [disjoint] lemma ne_of_disjoint {a b : α} (ha : a ≠ ⊥) (hab : disjoint a b) : a ≠ b := by { intro h, rw [←h, disjoint_self] at hab, exact ha hab } end disjoint namespace set protected theorem disjoint_iff {s t : set α} : disjoint s t ↔ s ∩ t ⊆ ∅ := iff.refl _ theorem disjoint_diff {a b : set α} : disjoint a (b \ a) := disjoint_iff.2 (inter_diff_self _ _) theorem disjoint_compl (s : set α) : disjoint s (-s) := assume a ⟨h₁, h₂⟩, h₂ h₁ theorem disjoint_singleton_left {a : α} {s : set α} : disjoint {a} s ↔ a ∉ s := by simp [set.disjoint_iff, subset_def]; exact iff.rfl theorem disjoint_singleton_right {a : α} {s : set α} : disjoint s {a} ↔ a ∉ s := by rw [disjoint.comm]; exact disjoint_singleton_left theorem disjoint_image_image {f : β → α} {g : γ → α} {s : set β} {t : set γ} (h : ∀b∈s, ∀c∈t, f b ≠ g c) : disjoint (f '' s) (g '' t) := by rintros a ⟨⟨b, hb, eq⟩, ⟨c, hc, rfl⟩⟩; exact h b hb c hc eq def pairwise_disjoint (s : set (set α)) : Prop := pairwise_on s disjoint lemma pairwise_disjoint_subset {s t : set (set α)} (h : s ⊆ t) (ht : pairwise_disjoint t) : pairwise_disjoint s := pairwise_on.mono h ht lemma pairwise_disjoint_range {s : set (set α)} (f : s → set α) (hf : ∀(x : s), f x ⊆ x.1) (ht : pairwise_disjoint s) : pairwise_disjoint (range f) := begin rintro _ ⟨x, rfl⟩ _ ⟨y, rfl⟩ hxy, refine disjoint_mono (hf x) (hf y) (ht _ x.2 _ y.2 _), intro h, apply hxy, apply congr_arg f, exact subtype.eq h end /- warning: classical -/ lemma pairwise_disjoint_elim {s : set (set α)} (h : pairwise_disjoint s) {x y : set α} (hx : x ∈ s) (hy : y ∈ s) (z : α) (hzx : z ∈ x) (hzy : z ∈ y) : x = y := begin haveI := classical.prop_decidable, by_contra, have : x ∩ y ≠ ∅, { rw [ne_empty_iff_exists_mem], exact ⟨z, ⟨hzx, hzy⟩⟩ }, apply this, exact disjoint_iff.mp (h x hx y hy a), end end set namespace set variables (t : α → set β) def sigma_to_Union (x : Σi, t i) : (⋃i, t i) := ⟨x.2, mem_Union.2 ⟨x.1, x.2.2⟩⟩ lemma surjective_sigma_to_Union : surjective (sigma_to_Union t) | ⟨b, hb⟩ := have ∃a, b ∈ t a, by simpa using hb, let ⟨a, hb⟩ := this in ⟨⟨a, ⟨b, hb⟩⟩, rfl⟩ lemma injective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) : injective (sigma_to_Union t) | ⟨a₁, ⟨b₁, h₁⟩⟩ ⟨a₂, ⟨b₂, h₂⟩⟩ eq := have b_eq : b₁ = b₂, from congr_arg subtype.val eq, have a_eq : a₁ = a₂, from classical.by_contradiction $ assume ne, have b₁ ∈ t a₁ ∩ t a₂, from ⟨h₁, b_eq.symm ▸ h₂⟩, h _ _ ne this, sigma.eq a_eq $ subtype.eq $ by subst b_eq; subst a_eq lemma bijective_sigma_to_Union (h : ∀i j, i ≠ j → disjoint (t i) (t j)) : bijective (sigma_to_Union t) := ⟨injective_sigma_to_Union t h, surjective_sigma_to_Union t⟩ noncomputable def Union_eq_sigma_of_disjoint {t : α → set β} (h : ∀i j, i ≠ j → disjoint (t i) (t j)) : (⋃i, t i) ≃ (Σi, t i) := (equiv.of_bijective $ bijective_sigma_to_Union t h).symm noncomputable def bUnion_eq_sigma_of_disjoint {s : set α} {t : α → set β} (h : pairwise_on s (disjoint on t)) : (⋃i∈s, t i) ≃ (Σi:s, t i.val) := equiv.trans (equiv.set_congr (bUnion_eq_Union _ _)) $ Union_eq_sigma_of_disjoint $ assume ⟨i, hi⟩ ⟨j, hj⟩ ne, h _ hi _ hj $ assume eq, ne $ subtype.eq eq end set
7efb26bc2220c4a46fc5dcb5b874fd2eedfe7a6e
c8b4b578b2fe61d500fbca7480e506f6603ea698
/src/caseI/aux_lemmas.lean
8ffefdfa4ab80e80d979e2e006a9503e6c6c494d
[]
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
9,292
lean
import may_assume.lemmas import number_theory.cyclotomic.factoring import number_theory.cyclotomic.Unit_lemmas import number_theory.cyclotomic.case_I open finset nat is_cyclotomic_extension ideal polynomial int basis open_locale big_operators number_field namespace flt_regular variables {p : ℕ} (hpri : p.prime) local notation `P` := (⟨p, hpri.pos⟩ : ℕ+) local notation `K` := cyclotomic_field P ℚ local notation `R` := 𝓞 K namespace caseI lemma two_lt (hp5 : 5 ≤ p) : 2 < p := by linarith section zerok₁ lemma aux_cong0k₁ {k : fin p} (hcong : k ≡ -1 [ZMOD p]) : k = ⟨p.pred, pred_lt hpri.ne_zero⟩ := begin refine fin.ext _, rw [fin.coe_mk, ← zmod.val_cast_of_lt (fin.is_lt k)], suffices : ((k : ℤ) : zmod p).val = p.pred, simpa, rw [← zmod.int_coe_eq_int_coe_iff] at hcong, rw [hcong, cast_neg, int.cast_one, pred_eq_sub_one], haveI : ne_zero p := ⟨hpri.ne_zero⟩, haveI : fact (p.prime) := ⟨hpri⟩, haveI : fact (1 < p) := ⟨hpri.one_lt⟩, simp [zmod.neg_val, zmod.val_one] end /-- Auxiliary function. -/ def f0k₁ (b : ℤ) (p : ℕ) : ℕ → ℤ := λ x, if x = 1 then b else if x = p.pred then -b else 0 lemma auxf0k₁ (hp5 : 5 ≤ p) (b : ℤ) : ∃ i : fin P, f0k₁ b p (i : ℕ) = 0 := begin refine ⟨⟨2, two_lt hp5⟩, _⟩, have h1 : ((⟨2, two_lt hp5⟩ : fin p) : ℕ) ≠ 1, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, exact one_lt_two.ne h.symm }, have hpred : ((⟨2, two_lt hp5⟩ : fin p) : ℕ) ≠ p.pred, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, replace h := h.symm, rw [nat.pred_eq_succ_iff] at h, linarith }, simp only [f0k₁, h1, if_false, hpred] end lemma aux0k₁ {a b c : ℤ} {ζ : R} (hp5 : 5 ≤ p) (hζ : is_primitive_root ζ p) (caseI : ¬ ↑p ∣ a * b * c) {k₁ k₂ : fin p} (hcong : k₂ ≡ k₁ - 1 [ZMOD p]) (hdiv : ↑p ∣ ↑a + ↑b * ζ - ↑a * ζ ^ (k₁ : ℕ) - ↑b * ζ ^ (k₂ : ℕ)) : 0 ≠ ↑k₁ := begin haveI := (⟨hpri⟩ : fact ((P : ℕ).prime)), symmetry, intro habs, rw [show (k₁ : ℤ) = 0, by simpa using habs, zero_sub] at hcong, rw [habs, pow_zero, mul_one, add_sub_cancel', aux_cong0k₁ hpri hcong] at hdiv, nth_rewrite 0 [show ζ = ζ ^ ((⟨1, hpri.one_lt⟩ : fin p) : ℕ), by simp] at hdiv, have key : ↑(p : ℤ) ∣ ∑ j in range p, (f0k₁ b p j) • ζ ^ j, { convert hdiv using 1, have h : 1 ≠ p.pred := λ h, by linarith [pred_eq_succ_iff.1 h.symm], simp_rw [f0k₁, ite_smul, sum_ite, filter_filter, ← ne.def, ne_and_eq_iff_right h, finset.range_filter_eq], simp [hpri.one_lt, pred_lt (hpri.ne_zero), sub_eq_add_neg] }, rw [sum_range] at key, refine caseI (has_dvd.dvd.mul_right (has_dvd.dvd.mul_left _ _) _), simpa [f0k₁] using dvd_coeff_cycl_integer (by exact hζ) (auxf0k₁ hpri hp5 b) key ⟨1, hpri.one_lt⟩, end end zerok₁ section zerok₂ /-- Auxiliary function -/ def f0k₂ (a b : ℤ) : ℕ → ℤ := λ x, if x = 0 then a - b else if x = 1 then b - a else 0 lemma aux_cong0k₂ {k : fin p} (hcong : k ≡ 1 [ZMOD p]) : k = ⟨1, hpri.one_lt⟩ := begin refine fin.ext _, rw [fin.coe_mk, ← zmod.val_cast_of_lt (fin.is_lt k)], suffices : ((k : ℤ) : zmod p).val = 1, simpa, rw [← zmod.int_coe_eq_int_coe_iff] at hcong, rw [hcong, int.cast_one], haveI : fact (p.prime) := ⟨hpri⟩, simp [zmod.val_one] end lemma auxf0k₂ (hp5 : 5 ≤ p) (a b : ℤ) : ∃ i : fin P, f0k₂ a b (i : ℕ) = 0 := begin refine ⟨⟨2, two_lt hp5⟩, _⟩, have h1 : ((⟨2, two_lt hp5⟩ : fin p) : ℕ) ≠ 1, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, exact one_lt_two.ne h.symm }, have hzero : ((⟨2, two_lt hp5⟩ : fin p) : ℕ) ≠ 0, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, linarith }, simp only [f0k₂, h1, if_false, hzero] end lemma aux0k₂ {a b : ℤ} {ζ : R} (hp5 : 5 ≤ p) (hζ : is_primitive_root ζ p) (hab : ¬a ≡ b [ZMOD p]) {k₁ k₂ : fin p} (hcong : k₂ ≡ k₁ - 1 [ZMOD p]) (hdiv : ↑p ∣ ↑a + ↑b * ζ - ↑a * ζ ^ (k₁ : ℕ) - ↑b * ζ ^ (k₂ : ℕ)) : 0 ≠ ↑k₂ := begin haveI := (⟨hpri⟩ : fact ((P : ℕ).prime)), symmetry, intro habs, replace hcong := hcong.symm, rw [show (k₂ : ℤ) = 0, by simpa using habs, ← zmod.int_coe_eq_int_coe_iff, int.cast_sub, int.cast_zero, sub_eq_zero, zmod.int_coe_eq_int_coe_iff] at hcong, rw [habs, pow_zero, mul_one, aux_cong0k₂ hpri hcong, fin.coe_mk, pow_one, add_sub_assoc, ← sub_mul, add_sub_right_comm, show ζ = ζ ^ ((⟨1, hpri.one_lt⟩ : fin p) : ℕ), by simp, ← neg_sub ↑a, neg_mul, ← sub_eq_add_neg] at hdiv, have key : ↑(p : ℤ) ∣ ∑ j in range p, (f0k₂ a b j) • ζ ^ j, { convert hdiv using 1, simp_rw [f0k₂, ite_smul, sum_ite, filter_filter, ← ne.def, ne_and_eq_iff_right zero_ne_one, finset.range_filter_eq], simp only [hpri.pos, hpri.one_lt, if_true, zsmul_eq_mul, int.cast_sub, sum_singleton, pow_zero, mul_one, pow_one, ne.def, filter_congr_decidable, zero_smul, sum_const_zero, add_zero, fin.coe_mk], ring }, rw [sum_range] at key, refine hab _, symmetry, rw [← zmod.int_coe_eq_int_coe_iff, zmod.int_coe_eq_int_coe_iff_dvd_sub], simpa [f0k₂] using dvd_coeff_cycl_integer (by exact hζ) (auxf0k₂ hpri hp5 a b) key ⟨0, hpri.pos⟩ end end zerok₂ section onek_one lemma aux_cong1k₁ {k : fin p} (hcong : k ≡ 0 [ZMOD p]) : k = ⟨0, hpri.pos⟩ := begin refine fin.ext _, rw [fin.coe_mk, ← zmod.val_cast_of_lt (fin.is_lt k)], suffices : ((k : ℤ) : zmod p).val = 0, simpa, rw [← zmod.int_coe_eq_int_coe_iff] at hcong, rw [hcong, int.cast_zero], haveI : fact (p.prime) := ⟨hpri⟩, simp end lemma aux1k₁ {a b : ℤ} {ζ : R} (hp5 : 5 ≤ p) (hζ : is_primitive_root ζ p) (hab : ¬a ≡ b [ZMOD p]) {k₁ k₂ : fin p} (hcong : k₂ ≡ k₁ - 1 [ZMOD p]) (hdiv : ↑p ∣ ↑a + ↑b * ζ - ↑a * ζ ^ (k₁ : ℕ) - ↑b * ζ ^ (k₂ : ℕ)) : 1 ≠ ↑k₁ := begin intro habs, have h := aux0k₂ hpri hp5 hζ hab hcong hdiv, rw [show (k₁ : ℤ) = 1, by simpa using habs.symm, sub_self] at hcong, have := (aux_cong1k₁ hpri hcong), simp only [←fin.coe_eq_coe, fin.coe_mk] at this, exact h.symm this end end onek_one section onek_two /-- Auxiliary function -/ def f1k₂ (a : ℤ) : ℕ → ℤ := λ x, if x = 0 then a else if x = 2 then -a else 0 lemma aux_cong1k₂ {k : fin p} (hpri : p.prime) (hp5 : 5 ≤ p) (hcong : k ≡ 1 + 1 [ZMOD p]) : k = ⟨2, two_lt hp5⟩ := begin refine fin.ext _, rw [fin.coe_mk, ← zmod.val_cast_of_lt (fin.is_lt k)], suffices : ((k : ℤ) : zmod p).val = 2, simpa, rw [← zmod.int_coe_eq_int_coe_iff] at hcong, rw [hcong], simp only [int.cast_add, algebra_map.coe_one], haveI : fact (p.prime) := ⟨hpri⟩, have := congr_arg nat.succ (nat.succ_pred_eq_of_pos hpri.pred_pos), rw [succ_pred_prime hpri] at this, rw [zmod.val_add, zmod.val_one, ← nat.mod_add_mod, ← this, one_mod, this, nat.mod_eq_of_lt], linarith end lemma auxf1k₂ (a : ℤ) : ∃ i : fin P, f1k₂ a (i : ℕ) = 0 := begin refine ⟨⟨1, hpri.one_lt⟩, _⟩, have h2 : ((⟨1, hpri.one_lt⟩ : fin p) : ℕ) ≠ 2, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, linarith }, have hzero : ((⟨1, hpri.one_lt⟩ : fin p) : ℕ) ≠ 0, { intro h, simp only [fin.ext_iff, fin.coe_mk] at h, linarith }, simp only [f1k₂, h2, if_false, hzero] end lemma aux1k₂ {a b c : ℤ} {ζ : R} (hp5 : 5 ≤ p) (hζ : is_primitive_root ζ p) (caseI : ¬ ↑p ∣ a * b * c) {k₁ k₂ : fin p} (hcong : k₂ ≡ k₁ - 1 [ZMOD p]) (hdiv : ↑p ∣ ↑a + ↑b * ζ - ↑a * ζ ^ (k₁ : ℕ) - ↑b * ζ ^ (k₂ : ℕ)) : 1 ≠ ↑k₂ := begin haveI := (⟨hpri⟩ : fact ((P : ℕ).prime)), symmetry, intro habs, replace hcong := hcong.symm, rw [show (k₂ : ℤ) = 1, by simpa using habs, ← zmod.int_coe_eq_int_coe_iff, int.cast_sub, sub_eq_iff_eq_add, ← int.cast_add, zmod.int_coe_eq_int_coe_iff] at hcong, rw [habs, pow_one, (aux_cong1k₂ hpri hp5 hcong)] at hdiv, ring_nf at hdiv, rw [add_mul, one_mul, add_comm, mul_comm, mul_neg] at hdiv, have key : ↑(p : ℤ) ∣ ∑ j in range p, (f1k₂ a j) • ζ ^ j, { convert hdiv using 1, simp_rw [f1k₂, ite_smul, sum_ite, filter_filter, ← ne.def, ne_and_eq_iff_right (show 0 ≠ 2, by norm_num), finset.range_filter_eq], simp [hpri.pos, two_lt hp5, fin.coe_mk (two_lt hp5),eq_self_iff_true, -fin.mk_bit0] }, rw [sum_range] at key, refine caseI (has_dvd.dvd.mul_right (has_dvd.dvd.mul_right _ _) _), simpa [f1k₂] using dvd_coeff_cycl_integer (by exact hζ) (auxf1k₂ hpri a) key ⟨0, hpri.pos⟩ end end onek_two section kone_ktwo lemma auxk₁k₂ {k₁ k₂ : fin p} (hpri : p.prime) (hcong : k₂ ≡ k₁ - 1 [ZMOD p]) : (k₁ : ℕ) ≠ (k₂ : ℕ) := begin haveI := (⟨hpri⟩ : fact (p.prime)), intro habs, rw [show (k₁ : ℤ) = (k₂ : ℕ), by simpa using habs, ← zmod.int_coe_eq_int_coe_iff, ← sub_eq_zero, int.cast_sub, sub_sub_eq_add_sub, coe_coe, add_sub_cancel', algebra_map.coe_one] at hcong, exact one_ne_zero hcong end end kone_ktwo end caseI end flt_regular
8a077f4f854dd1c6c6b7afd2f5af2612dc7e9d3a
4e0d7c3132ce31edc5829849735dd25db406b144
/lean/love13_rational_and_real_numbers_demo.lean
fd37736d4c4a213852603c658e83af4a8a922716
[]
no_license
gonzalgu/logical_verification_2020
a0013a6c22ea254e9f4d245f2948f0f4d44df4bb
724d0457dff2c3ff10f9ab2170388f4c5e958b75
refs/heads/master
1,660,886,374,533
1,589,859,641,000
1,589,859,641,000
256,069,971
0
0
null
1,586,997,430,000
1,586,997,429,000
null
UTF-8
Lean
false
false
13,515
lean
import .lovelib /-! # LoVe Demo 13: Rational and Real Numbers We review the construction of `ℚ` and `ℝ` as quotient types. A procedure to construct types with specific properties: 1. Create a new type that can represent all elements, but not necessarily in a unique manner. 2. Quotient this representation, equating elements that should be equal. 3. Define operators on the quotient type by lifting functions from the base type and prove that they are compatible with the quotient relation. We used this approach in lecture 11 to construct `ℤ`. It can be used for `ℚ` and `ℝ` as well. -/ set_option pp.beta true namespace LoVe /-! ## Rational Numbers **Step 1:** A rational number is a number that can be expressed as a fraction `n/d` of integers `n` and `d ≠ 0`: -/ structure fraction : Type := (num : ℤ) (denom : ℤ) (denom_ne_zero : denom ≠ 0) /-! The number `n` is called the numerator, and the number `d` is called the denominator. The representation of a rational number as a fraction is not unique—e.g., `1/2 = 2/4 = -1/-2`. **Step 2:** Two fractions `n₁/d₁` and `n₂/d₂` represent the same rational number if the ratio between numerator and denominator are the same—i.e., `n₁ * d₂ = n₂ * d₁`. This will be our equivalence relation `≈` on fractions. -/ namespace fraction @[instance] def setoid : setoid fraction := { r := λa b, num a * denom b = num b * denom a, iseqv := begin repeat { apply and.intro }, { intros a; refl }, { intros a b h; cc }, { intros a b c eq_ab eq_bc, apply eq_of_mul_eq_mul_right (denom_ne_zero b), cc } end } lemma setoid_iff (a b : fraction) : a ≈ b ↔ num a * denom b = num b * denom a := by refl /-! **Step 3:** Define `0 := 0/1`, `1 := 1/1`, addition, multiplication, etc. `n₁/d₁ + n₂/d₂` := `(n₁ * d₂ + n₂ * d₁)/(d₁ * d₂)` `(n₁/d₁) * (n₂/d₂)` := `(n₁ * n₂)/(d₁ * d₂)` Then show that they are compatible with `≈`. -/ def of_int (i : ℤ) : fraction := { num := i, denom := 1, denom_ne_zero := by simp } @[instance] def has_zero : has_zero fraction := { zero := of_int 0 } @[instance] def has_one : has_one fraction := { one := of_int 1 } @[instance] def has_add : has_add fraction := { add := λa b : fraction, { num := num a * denom b + num b * denom a, denom := denom a * denom b, denom_ne_zero := by apply mul_ne_zero; exact denom_ne_zero _ } } @[simp] lemma add_num (a b : fraction) : num (a + b) = num a * denom b + num b * denom a := by refl @[simp] lemma add_denom (a b : fraction) : denom (a + b) = denom a * denom b := by refl lemma add_equiv_add {a a' b b' : fraction} (ha : a ≈ a') (hb : b ≈ b') : a + b ≈ a' + b' := begin simp [setoid_iff] at *, calc (num a * denom b + num b * denom a) * (denom a' * denom b') = num a * denom a' * denom b * denom b' + num b * denom b' * denom a * denom a' : by simp [add_mul]; ac_refl ... = num a' * denom a * denom b * denom b' + num b' * denom b * denom a * denom a' : by simp [*] ... = (num a' * denom b' + num b' * denom a') * (denom a * denom b) : by simp [add_mul]; ac_refl end @[instance] def has_neg : has_neg fraction := { neg := λa : fraction, { num := - num a, ..a } } @[simp] lemma neg_num (a : fraction) : num (- a) = - num a := by refl @[simp] lemma neg_denom (a : fraction) : denom (- a) = denom a := by refl lemma setoid_neg {a a' : fraction} (hab : a ≈ a') : - a ≈ - a' := by simp [setoid_iff] at hab ⊢; exact hab @[instance] def has_mul : has_mul fraction := { mul := λa b : fraction, { num := num a * num b, denom := denom a * denom b, denom_ne_zero := mul_ne_zero (denom_ne_zero a) (denom_ne_zero b) } } @[simp] lemma mul_num (a b : fraction) : num (a * b) = num a * num b := by refl @[simp] lemma mul_denom (a b : fraction) : denom (a * b) = denom a * denom b := by refl lemma setoid_mul {a a' b b' : fraction} (ha : a ≈ a') (hb : b ≈ b') : a * b ≈ a' * b' := by simp [setoid_iff] at ha hb ⊢; cc @[instance] def has_inv : has_inv fraction := { inv := λa, if ha : num a = 0 then 0 else { num := denom a, denom := num a, denom_ne_zero := ha } } lemma inv_def (a : fraction) (ha : num a ≠ 0) : a⁻¹ = { num := denom a, denom := num a, denom_ne_zero := ha } := dif_neg ha lemma inv_zero (a : fraction) (ha : num a = 0) : a⁻¹ = 0 := dif_pos ha @[simp] lemma inv_num (a : fraction) (ha : num a ≠ 0) : num (a⁻¹) = denom a := by rewrite inv_def a ha @[simp] lemma inv_denom (a : fraction) (ha : num a ≠ 0) : denom (a⁻¹) = num a := by rewrite inv_def a ha lemma setoid_inv {a a' : fraction} (ha : a ≈ a') : a⁻¹ ≈ a'⁻¹ := begin cases classical.em (num a = 0), case or.inl : ha0 { cases classical.em (num a' = 0), case or.inl : ha'0 { simp [ha0, ha'0, inv_zero] }, case or.inr : ha'0 { simp [ha0, ha'0, setoid_iff, denom_ne_zero] at ha, cc } }, case or.inr : ha0 { cases classical.em (num a' = 0), case or.inl : ha'0 { simp [setoid_iff, ha'0, denom_ne_zero] at ha, cc }, case or.inr : ha'0 { simp [setoid_iff, ha0, ha'0] at ha ⊢, cc } } end end fraction def rat : Type := quotient fraction.setoid namespace rat @[instance] def has_zero : has_zero rat := { zero := ⟦0⟧ } @[instance] def has_one : has_one rat := { one := ⟦1⟧ } @[instance] def has_add : has_add rat := { add := quotient.lift₂ (λa b, ⟦a + b⟧) begin intros a b a' b' ha hb, apply quotient.sound, exact fraction.add_equiv_add ha hb end } @[instance] def has_neg : has_neg rat := { neg := quotient.lift (λa, ⟦- a⟧) begin intros a a' ha, apply quotient.sound, exact fraction.setoid_neg ha end } @[instance] def has_mul : has_mul rat := { mul := quotient.lift₂ (λa b, ⟦a * b⟧) begin intros a b a' b' ha hb, apply quotient.sound, exact fraction.setoid_mul ha hb end } @[instance] def has_inv : has_inv rat := { inv := quotient.lift (λa, ⟦a⁻¹⟧) begin intros a a' ha, apply quotient.sound, exact fraction.setoid_inv ha end } end rat /-! ### Alternative Definitions of `ℚ` **Alternative 1:** Define `ℚ` as a subtype of `fraction`, with the requirement that the numerator and the denominator have no common divisors except `1` and `-1`: -/ namespace alternative_1 def rat := {a : fraction // nat.coprime (int.nat_abs (fraction.num a)) (int.nat_abs (fraction.denom a))} end alternative_1 /-! This is the definition used in `mathlib`. Advantages: * no quotient required; * more efficient computation; * more properties are equalities up to computation. Disadvantage: * more complicated function definitions. **Alternative 2**: Define all elements syntactically, including the desired operations: -/ namespace alternative_2 inductive pre_rat : Type | zero : pre_rat | one : pre_rat | add : pre_rat → pre_rat → pre_rat | sub : pre_rat → pre_rat → pre_rat | mul : pre_rat → pre_rat → pre_rat | div : pre_rat → pre_rat → pre_rat /-! Then quotient `pre_rat` to enforce congruence rules and the field axioms: -/ inductive rat.rel : pre_rat → pre_rat → Prop | add_congr {a b c d : pre_rat} : rat.rel a b → rat.rel c d → rat.rel (pre_rat.add a c) (pre_rat.add b d) | add_assoc {a b c : pre_rat} : rat.rel (pre_rat.add a (pre_rat.add b c)) (pre_rat.add (pre_rat.add a b) c) | zero_add {a : pre_rat} : rat.rel (pre_rat.add pre_rat.zero a) a -- etc. def rat : Type := quot rat.rel end alternative_2 /-! Advantages: * no dependency on `ℤ`; * easy proofs of the field axioms; * general recipe reusable for other algebraic constructions (e.g., free monoids, free groups). Disadvantage: * the definition of orders and lemmas about them are more complicated. ### Real Numbers Some sequences of rational numbers seem to converge because the numbers in the sequence get closer and closer to each other, and yet do not converge to a rational number. Example: `a₀ = 1` `a₁ = 1.4` `a₂ = 1.41` `a₃ = 1.414` `a₄ = 1.4142` `a₅ = 1.41421` `a₆ = 1.414213` `a₇ = 1.4142135` ⋮ This sequence seems to converge because each `a_n` is at most `10^-n` away from any of the following numbers. But the limit is `√2`, which is not a rational number. The rational numbers are incomplete, and the reals are their __completion__. To construct the reals, we need to fill in the gaps that are revealed by these sequences that seem to converge, but do not. Mathematically, a sequence `a₀, a₁, …` of rational numbers is __Cauchy__ if for any `ε > 0`, there exists an `N ∈ ℕ` such that for all `m ≥ N`, we have `|a_N - a_m| < ε`. In other words, no matter how small we choose `ε`, we can always find a point in the sequence from which all following numbers deviate less than by `ε`. -/ def is_cau_seq (f : ℕ → ℚ) : Prop := ∀ε > 0, ∃N, ∀m ≥ N, abs (f N - f m) < ε /-! Not every sequence is a Cauchy sequence: -/ lemma id_not_cau_seq : ¬ is_cau_seq (λn : ℕ, (n : ℚ)) := begin rewrite is_cau_seq, intro h, cases h 1 zero_lt_one with i hi, have hi_succi := hi (i + 1) (by simp), simp at hi_succi, linarith end /-! We define a type of Cauchy sequences as a subtype: -/ def cau_seq : Type := {f : ℕ → ℚ // is_cau_seq f} def seq_of (f : cau_seq) : ℕ → ℚ := subtype.val f /-! Cauchy sequences represent real numbers: * `a_n = 1/n` represents the real number `0`; * `1, 1.4, 1.41, …` represents the real number `√2`; * `a_n = 0` also represents the real number `0`. Since different Cauchy sequences can represent the same real number, we need to take the quotient. Formally, two sequences represent the same real number when their difference converges to zero: -/ namespace cau_seq @[instance] def setoid : setoid cau_seq := { r := λf g : cau_seq, ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε, iseqv := begin apply and.intro, { intros f ε hε, apply exists.intro 0, finish }, apply and.intro, { intros f g hfg ε hε, cases hfg ε hε with N hN, apply exists.intro N, intros m hm, rewrite abs_sub, apply hN m hm }, { intros f g h hfg hgh ε hε, cases hfg (ε / 2) (half_pos hε) with N₁ hN₁, cases hgh (ε / 2) (half_pos hε) with N₂ hN₂, apply exists.intro (max N₁ N₂), intros m hm, calc abs (seq_of f m - seq_of h m) ≤ abs (seq_of f m - seq_of g m) + abs (seq_of g m - seq_of h m) : by apply abs_sub_le ... < ε / 2 + ε / 2 : add_lt_add (hN₁ m (le_of_max_le_left hm)) (hN₂ m (le_of_max_le_right hm)) ... = ε : by simp } end } lemma setoid_iff (f g : cau_seq) : f ≈ g ↔ ∀ε > 0, ∃N, ∀m ≥ N, abs (seq_of f m - seq_of g m) < ε := by refl /-! We can define constants such as `0` and `1` as a constant sequence. Any constant sequence is a Cauchy sequence: -/ def const (q : ℚ) : cau_seq := subtype.mk (λ_, q) (by rewrite is_cau_seq; intros ε hε; finish) /-! Defining addition of real numbers requires a little more effort. We define addition on Cauchy sequences as pairwise addition: -/ @[instance] def has_add : has_add cau_seq := { add := λf g, subtype.mk (λn, seq_of f n + seq_of g n) sorry } /-! Above, we omit the proof that the addition of two Cauchy sequences is again a Cauchy sequence. Next, we need to show that this addition is compatible with `≈`: -/ lemma add_equiv_add {f f' g g' : cau_seq} (hf : f ≈ f') (hg : g ≈ g') : f + g ≈ f' + g' := begin intros ε₀ hε₀, simp [setoid_iff], cases hf (ε₀ / 2) (half_pos hε₀) with Nf hNf, cases hg (ε₀ / 2) (half_pos hε₀) with Ng hNg, apply exists.intro (max Nf Ng), intros m hm, calc abs (seq_of (f + g) m - seq_of (f' + g') m) = abs ((seq_of f m + seq_of g m) - (seq_of f' m + seq_of g' m)) : by refl ... = abs ((seq_of f m - seq_of f' m) + (seq_of g m - seq_of g' m)) : by simp ... ≤ abs (seq_of f m - seq_of f' m) + abs (seq_of g m - seq_of g' m) : by apply abs_add ... < ε₀ / 2 + ε₀ / 2 : add_lt_add (hNf m (le_of_max_le_left hm)) (hNg m (le_of_max_le_right hm)) ... = ε₀ : by simp end end cau_seq /-! The real numbers are the quotient: -/ def real : Type := quotient cau_seq.setoid namespace real @[instance] def has_zero : has_zero real := { zero := ⟦cau_seq.const 0⟧ } @[instance] def has_one : has_one real := { one := ⟦cau_seq.const 1⟧ } @[instance] def has_add : has_add real := { add := quotient.lift₂ (λa b, ⟦a + b⟧) begin intros a b a' b' ha hb, apply quotient.sound, exact cau_seq.add_equiv_add ha hb, end } end real /-! ### Alternative Definitions of `ℝ` * Dedekind cuts: `r : ℝ` is represented essentially as `{x : ℚ | x < r}`. * Binary sequences `ℕ → bool` can represent the interval `[0, 1]`. This can be used to build `ℝ`. -/ end LoVe
4e3e1223bb6b8738abbff1acfc5ead83b3b13aa0
80162757f50b09d3cad5564907e4c9b00742e045
/rb_dep.lean
cc3902a9cd3df8627eed332054952540f77836de
[]
no_license
EdAyers/edlib
cc30d0a54fed347a85b6df6045f68e6b48bc71a3
78b8c5d91f023f939c102837d748868e2f3ed27d
refs/heads/master
1,586,459,758,216
1,571,322,179,000
1,571,322,179,000
160,538,917
2
0
null
null
null
null
UTF-8
Lean
false
false
2,147
lean
/- Mirrors `rb.lean` but with dependent types from the start -/ namespace rb_dep universes u v section rb open nat inductive col | Red | Black open col inductive node (K : Type u) (A : Type v) : col → ℕ → Type max u v |Leaf {} : node Black 0 |Rd {n} (l : node Black n) (v : K × A) (r : node Black n) : node Red n |Bk {cl cr n} (l : node cl n) (v : K × A) (r : node cr n) : node Black (succ n) open node inductive growth (K : Type u) (A : Type v) : ℕ → Type max u v |sproutl {cll clr cr n} (ll : node K A cll n) (lv : K×A) (lr : node K A clr n) (v : K×A) (r : node K A cr n) : growth n |sproutr {cl crl crr n} (l : node K A cl n) (v : K×A) (rl : node K A crl n) (rv : K×A) (rr : node K A crr n) : growth n |sprout {c n} (t : node K A c n) : growth n open growth variables {K : Type u} {A : Type v} [has_lt K] [decidable_rel ((<) : K → K → Prop)] variables {n : ℕ} {cl cr c : col} def get_col : Π {c}, node K A c n → Σ c, node K A c n |Black t := ⟨Black, t⟩ |Red t := ⟨Red, t⟩ instance : has_coe (node K A c n) (Σ c, node K A c n) := ⟨λ t, get_col t⟩ def ins_aux.type (K : Type u) (A : Type v) : col → Type (max u v) | Black := def ins_aux (k : K) (a : A) : Π {c n}, node K A c n → Σ c, node K A c n |Black 0 Leaf := Rd Leaf ⟨k,a⟩ Leaf |Red n (Rd l v r) := -- l and r are both Black. So `ins_aux l` is either black, balanced, or sprouting if k < v.1 then match ins_aux l with |⟨Red, Rd ll lv lr⟩ := sproutl ll lv lr v r |⟨Black, l⟩ := stay (Rd l v r) end else if k > v.1 then Rd l v (ins_aux r) -- R else Rd l ⟨k,a⟩ r -- R |Black n (Bk l v r) := if k < v.1 then match ins_aux l with | (sproutl a x b y c) := Rd (Bk a x b) y (Bk c v r) | (sproutr a x b y c) := Rd (Bk a x b) y (Bk c v r) | (stay l) := Bk l v r end else if k > v.1 then match ins_aux r with | (sproutl b w c z d) := Rd (Bk l v b) w (Bk c z d) | (sproutr b w c z d) := Rd (Bk l v b) w (Bk c z d) | (stay r) := Bk l v r end else stay $ Bk l ⟨k,a⟩ r -- B end rb end rb_dep
b7f17ae8f53ba6f0116147627d53d6c82f3a420c
2c096fdfecf64e46ea7bc6ce5521f142b5926864
/src/Lean/Elab/Extra.lean
854b418a29c0ea55811d685d7141ad7e9157392d
[ "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
Kha/lean4
1005785d2c8797ae266a303968848e5f6ce2fe87
b99e11346948023cd6c29d248cd8f3e3fb3474cf
refs/heads/master
1,693,355,498,027
1,669,080,461,000
1,669,113,138,000
184,748,176
0
0
Apache-2.0
1,665,995,520,000
1,556,884,930,000
Lean
UTF-8
Lean
false
false
23,260
lean
/- Copyright (c) 2021 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ import Lean.Elab.App import Lean.Elab.BuiltinNotation /-! # Auxiliary elaboration functions: AKA custom elaborators -/ namespace Lean.Elab.Term open Meta private def getMonadForIn (expectedType? : Option Expr) : TermElabM Expr := do match expectedType? with | none => throwError "invalid 'for_in%' notation, expected type is not available" | some expectedType => match (← isTypeApp? expectedType) with | some (m, _) => return m | none => throwError "invalid 'for_in%' notation, expected type is not of of the form `M α`{indentExpr expectedType}" private def throwForInFailure (forInInstance : Expr) : TermElabM Expr := throwError "failed to synthesize instance for 'for_in%' notation{indentExpr forInInstance}" @[builtin_term_elab forInMacro] def elabForIn : TermElab := fun stx expectedType? => do match stx with | `(for_in% $col $init $body) => match (← isLocalIdent? col) with | none => elabTerm (← `(let col := $col; for_in% col $init $body)) expectedType? | some colFVar => tryPostponeIfNoneOrMVar expectedType? let m ← getMonadForIn expectedType? let colType ← inferType colFVar let elemType ← mkFreshExprMVar (mkSort (mkLevelSucc (← mkFreshLevelMVar))) let forInInstance ← try mkAppM ``ForIn #[m, colType, elemType] catch _ => tryPostpone; throwError "failed to construct 'ForIn' instance for collection{indentExpr colType}\nand monad{indentExpr m}" match (← trySynthInstance forInInstance) with | .some inst => let forInFn ← mkConst ``forIn elabAppArgs forInFn (namedArgs := #[{ name := `m, val := Arg.expr m}, { name := `α, val := Arg.expr elemType }, { name := `self, val := Arg.expr inst }]) (args := #[Arg.stx col, Arg.stx init, Arg.stx body]) (expectedType? := expectedType?) (explicit := false) (ellipsis := false) (resultIsOutParamSupport := false) | .undef => tryPostpone; throwForInFailure forInInstance | .none => throwForInFailure forInInstance | _ => throwUnsupportedSyntax @[builtin_term_elab forInMacro'] def elabForIn' : TermElab := fun stx expectedType? => do match stx with | `(for_in'% $col $init $body) => match (← isLocalIdent? col) with | none => elabTerm (← `(let col := $col; for_in'% col $init $body)) expectedType? | some colFVar => tryPostponeIfNoneOrMVar expectedType? let m ← getMonadForIn expectedType? let colType ← inferType colFVar let elemType ← mkFreshExprMVar (mkSort (mkLevelSucc (← mkFreshLevelMVar))) let forInInstance ← try let memType ← mkFreshExprMVar (← mkAppM ``Membership #[elemType, colType]) mkAppM ``ForIn' #[m, colType, elemType, memType] catch _ => tryPostpone; throwError "failed to construct `ForIn'` instance for collection{indentExpr colType}\nand monad{indentExpr m}" match (← trySynthInstance forInInstance) with | .some inst => let forInFn ← mkConst ``forIn' elabAppArgs forInFn (namedArgs := #[{ name := `m, val := Arg.expr m}, { name := `α, val := Arg.expr elemType}, { name := `self, val := Arg.expr inst }]) (args := #[Arg.expr colFVar, Arg.stx init, Arg.stx body]) (expectedType? := expectedType?) (explicit := false) (ellipsis := false) (resultIsOutParamSupport := false) | .undef => tryPostpone; throwForInFailure forInInstance | .none => throwForInFailure forInInstance | _ => throwUnsupportedSyntax namespace Op /-! The elaborator for `binop%`, `binop_lazy%`, and `unop%` terms. It works as follows: 1- Expand macros. 2- Convert `Syntax` object corresponding to the `binop%` (`binop_lazy%` and `unop%`) term into a `Tree`. The `toTree` method visits nested `binop%` (`binop_lazy%` and `unop%`) terms and parentheses. 3- Synthesize pending metavariables without applying default instances and using the `(mayPostpone := true)`. 4- Tries to compute a maximal type for the tree computed at step 2. We say a type α is smaller than type β if there is a (nondependent) coercion from α to β. We are currently ignoring the case we may have cycles in the coercion graph. If there are "uncomparable" types α and β in the tree, we skip the next step. We say two types are "uncomparable" if there isn't a coercion between them. Note that two types may be "uncomparable" because some typing information may still be missing. 5- We traverse the tree and inject coercions to the "maximal" type when needed. Recall that the coercions are expanded eagerly by the elaborator. Properties: a) Given `n : Nat` and `i : Nat`, it can successfully elaborate `n + i` and `i + n`. Recall that Lean 3 fails on the former. b) The coercions are inserted in the "leaves" like in Lean 3. c) There are no coercions "hidden" inside instances, and we can elaborate ``` axiom Int.add_comm (i j : Int) : i + j = j + i example (n : Nat) (i : Int) : n + i = i + n := by rw [Int.add_comm] ``` Recall that the `rw` tactic used to fail because our old `binop%` elaborator would hide coercions inside of a `HAdd` instance. Remarks: In the new `binop%` and related elaborators the decision whether a coercion will be inserted or not is made at `binop%` elaboration time. This was not the case in the old elaborator. For example, an instance, such as `HAdd Int ?m ?n`, could be created when executing the `binop%` elaborator, and only resolved much later. We try to minimize this problem by synthesizing pending metavariables at step 3. For types containing heterogeneous operators (e.g., matrix multiplication), step 4 will fail and we will skip coercion insertion. For example, `x : Matrix Real 5 4` and `y : Matrix Real 4 8`, there is no coercion `Matrix Real 5 4` from `Matrix Real 4 8` and vice-versa, but `x * y` is elaborated successfully and has type `Matrix Real 5 8`. -/ private inductive Tree where /-- Leaf of the tree. We store the `infoTrees` generated when elaborating `val`. These trees become subtrees of the infotree nodes generated for `op` nodes. -/ | term (ref : Syntax) (infoTrees : PersistentArray InfoTree) (val : Expr) /-- `ref` is the original syntax that expanded into `binop%`. `macroName` is the `macro_rule` that produce the expansion. We store this information here to make sure "go to definition" behaves similarly to notation defined without using `binop%` helper elaborator. -/ | binop (ref : Syntax) (macroName : Name) (lazy : Bool) (f : Expr) (lhs rhs : Tree) /-- `ref` is the original syntax that expanded into `unop%`. `macroName` is the `macro_rule` that produce the expansion. We store this information here to make sure "go to definition" behaves similarly to notation defined without using `unop%` helper elaborator. -/ | unop (ref : Syntax) (macroName : Name) (f : Expr) (arg : Tree) private partial def toTree (s : Syntax) : TermElabM Tree := do /- Remark: ew used to use `expandMacros` here, but this is a bad idiom because we do not record the macro expansion information in the info tree. We now manually expand the notation in the `go` function, and save the macro declaration names in the `op` nodes. -/ let result ← go s synthesizeSyntheticMVars (mayPostpone := true) return result where go (s : Syntax) := do match s with | `(binop% $f $lhs $rhs) => processBinOp (lazy := false) s .anonymous f lhs rhs | `(binop_lazy% $f $lhs $rhs) => processBinOp (lazy := true) s .anonymous f lhs rhs | `(unop% $f $arg) => processUnOp s .anonymous f arg | `(($e)) => if hasCDot e then processLeaf s else go e | _ => match (← liftMacroM <| expandMacroImpl? (← getEnv) s) with | some (macroName, s?) => let s' ← liftMacroM <| liftExcept s? match s' with | `(binop% $f $lhs $rhs) => processBinOp (lazy := false) s macroName f lhs rhs | `(binop_lazy% $f $lhs $rhs) => processBinOp (lazy := true) s macroName f lhs rhs | `(unop% $f $arg) => processUnOp s .anonymous f arg | _ => processLeaf s | none => processLeaf s processBinOp (ref : Syntax) (declName : Name) (f lhs rhs : Syntax) (lazy : Bool) := do let some f ← resolveId? f | throwUnknownConstant f.getId return .binop (lazy := lazy) ref declName f (← go lhs) (← go rhs) processUnOp (ref : Syntax) (declName : Name) (f arg : Syntax) := do let some f ← resolveId? f | throwUnknownConstant f.getId return .unop ref declName f (← go arg) processLeaf (s : Syntax) := do let e ← elabTerm s none let info ← getResetInfoTrees return .term s info e -- Auxiliary function used at `analyze` private def hasCoe (fromType toType : Expr) : TermElabM Bool := do if (← getEnv).contains ``CoeHTCT then let u ← getLevel fromType let v ← getLevel toType let coeInstType := mkAppN (Lean.mkConst ``CoeHTCT [u, v]) #[fromType, toType] match ← trySynthInstance coeInstType (some (maxCoeSize.get (← getOptions))) with | .some _ => return true | .none => return false | .undef => return false -- TODO: should we do something smarter here? else return false private structure AnalyzeResult where max? : Option Expr := none hasUncomparable : Bool := false -- `true` if there are two types `α` and `β` where we don't have coercions in any direction. private def isUnknow : Expr → Bool | .mvar .. => true | .app f _ => isUnknow f | .letE _ _ _ b _ => isUnknow b | .mdata _ b => isUnknow b | _ => false private def analyze (t : Tree) (expectedType? : Option Expr) : TermElabM AnalyzeResult := do let max? ← match expectedType? with | none => pure none | some expectedType => let expectedType ← instantiateMVars expectedType if isUnknow expectedType then pure none else pure (some expectedType) (go t *> get).run' { max? } where go (t : Tree) : StateRefT AnalyzeResult TermElabM Unit := do unless (← get).hasUncomparable do match t with | .binop _ _ _ _ lhs rhs => go lhs; go rhs | .unop _ _ _ arg => go arg | .term _ _ val => let type ← instantiateMVars (← inferType val) unless isUnknow type do match (← get).max? with | none => modify fun s => { s with max? := type } | some max => unless (← withNewMCtxDepth <| isDefEqGuarded max type) do if (← hasCoe type max) then return () else if (← hasCoe max type) then modify fun s => { s with max? := type } else trace[Elab.binop] "uncomparable types: {max}, {type}" modify fun s => { s with hasUncomparable := true } private def mkBinOp (f : Expr) (lhs rhs : Expr) : TermElabM Expr := do elabAppArgs f #[] #[Arg.expr lhs, Arg.expr rhs] (expectedType? := none) (explicit := false) (ellipsis := false) (resultIsOutParamSupport := false) private def mkUnOp (f : Expr) (arg : Expr) : TermElabM Expr := do elabAppArgs f #[] #[Arg.expr arg] (expectedType? := none) (explicit := false) (ellipsis := false) (resultIsOutParamSupport := false) private def toExprCore (t : Tree) : TermElabM Expr := do match t with | .term _ trees e => modifyInfoState (fun s => { s with trees := s.trees ++ trees }); return e | .binop ref macroName true f lhs rhs => withRef ref <| withInfoContext' ref (mkInfo := mkTermInfo macroName ref) do mkBinOp f (← toExprCore lhs) (← mkFunUnit (← toExprCore rhs)) | .binop ref macroName false f lhs rhs => withRef ref <| withInfoContext' ref (mkInfo := mkTermInfo macroName ref) do mkBinOp f (← toExprCore lhs) (← toExprCore rhs) | .unop ref macroName f arg => withRef ref <| withInfoContext' ref (mkInfo := mkTermInfo macroName ref) do mkUnOp f (← toExprCore arg) /-- Auxiliary function to decide whether we should coerce `f`'s argument to `maxType` or not. - `f` is a binary operator. - `lhs == true` (`lhs == false`) if are trying to coerce the left-argument (right-argument). This function assumes `f` is a heterogeneous operator (e.g., `HAdd.hAdd`, `HMul.hMul`, etc). It returns true IF - `f` is a constant of the form `Cls.op` where `Cls` is a class name, and - `maxType` is of the form `C ...` where `C` is a constant, and - There are more than one default instance. That is, it assumes the class `Cls` for the heterogeneous operator `f`, and always has the monomorphic instance. (e.g., for `HAdd`, we have `instance [Add α] : HAdd α α α`), and - If `lhs == true`, then there is a default instance of the form `Cls _ (C ..) _`, and - If `lhs == false`, then there is a default instance of the form `Cls (C ..) _ _`. The motivation is to support default instances such as ``` @[default_instance high] instance [Mul α] : HMul α (Array α) (Array α) where hMul a as := as.map (a * ·) #eval 2 * #[3, 4, 5] ``` If the type of an argument is unknown we should not coerce it to `maxType` because it would prevent the default instance above from being even tried. -/ private def hasHeterogeneousDefaultInstances (f : Expr) (maxType : Expr) (lhs : Bool) : MetaM Bool := do let .const fName .. := f | return false let .const typeName .. := maxType.getAppFn | return false let className := fName.getPrefix let defInstances ← getDefaultInstances className if defInstances.length ≤ 1 then return false for (instName, _) in defInstances do if let .app (.app (.app _heteroClass lhsType) rhsType) _resultType := (← getConstInfo instName).type.getForallBody then if lhs && rhsType.isAppOf typeName then return true if !lhs && lhsType.isAppOf typeName then return true return false /-- Return `true` if polymorphic function `f` has a homogenous instance of `maxType`. The coercions to `maxType` only makes sense if such instance exists. For example, suppose `maxType` is `Int`, and `f` is `HPow.hPow`. Then, adding coercions to `maxType` only make sense if we have an instance `HPow Int Int Int`. -/ private def hasHomogeneousInstance (f : Expr) (maxType : Expr) : MetaM Bool := do let .const fName .. := f | return false let className := fName.getPrefix try let inst ← mkAppM className #[maxType, maxType, maxType] return (← trySynthInstance inst) matches .some _ catch _ => return false mutual /-- Try to coerce elements in the `t` to `maxType` when needed. If the type of an element in `t` is unknown we only coerce it to `maxType` if `maxType` does not have heterogeneous default instances. This extra check is approximated by `hasHeterogeneousDefaultInstances`. Remark: If `maxType` does not implement heterogeneous default instances, we do want to assign unknown types `?m` to `maxType` because it produces better type information propagation. Our test suite has many tests that would break if we don't do this. For example, consider the term ``` eq_of_isEqvAux a b hsz (i+1) (Nat.succ_le_of_lt h) heqv.2 ``` `Nat.succ_le_of_lt h` type depends on `i+1`, but `i+1` only reduces to `Nat.succ i` if we know that `1` is a `Nat`. There are several other examples like that in our test suite, and one can find them by just replacing the `← hasHeterogeneousDefaultInstances f maxType lhs` test with `true` Remark: if `hasHeterogeneousDefaultInstances` implementation is not good enough we should refine it in the future. -/ private partial def applyCoe (t : Tree) (maxType : Expr) (isPred : Bool) : TermElabM Tree := do go t none false isPred where go (t : Tree) (f? : Option Expr) (lhs : Bool) (isPred : Bool) : TermElabM Tree := do match t with | .binop ref macroName lazy f lhs rhs => /- We only keep applying coercions to `maxType` if `f` is predicate or `f` has a homogenous instance with `maxType`. See `hasHomogeneousInstance` for additional details. Remark: We assume `binrel%` elaborator is only used with homogenous predicates. -/ if (← pure isPred <||> hasHomogeneousInstance f maxType) then return .binop ref macroName lazy f (← go lhs f true false) (← go rhs f false false) else let r ← withRef ref <| withInfoContext' ref (mkInfo := mkTermInfo macroName ref) do mkBinOp f (← toExpr lhs none) (← toExpr rhs none) let infoTrees ← getResetInfoTrees return .term ref infoTrees r | .unop ref macroName f arg => return .unop ref macroName f (← go arg none false false) | .term ref trees e => let type ← instantiateMVars (← inferType e) trace[Elab.binop] "visiting {e} : {type} =?= {maxType}" if isUnknow type then if let some f := f? then if (← hasHeterogeneousDefaultInstances f maxType lhs) then -- See comment at `hasHeterogeneousDefaultInstances` return t if (← isDefEqGuarded maxType type) then return t else trace[Elab.binop] "added coercion: {e} : {type} => {maxType}" withRef ref <| return .term ref trees (← mkCoe maxType e) private partial def toExpr (tree : Tree) (expectedType? : Option Expr) : TermElabM Expr := do let r ← analyze tree expectedType? trace[Elab.binop] "hasUncomparable: {r.hasUncomparable}, maxType: {r.max?}" if r.hasUncomparable || r.max?.isNone then let result ← toExprCore tree ensureHasType expectedType? result else let result ← toExprCore (← applyCoe tree r.max?.get! (isPred := false)) trace[Elab.binop] "result: {result}" ensureHasType expectedType? result end def elabOp : TermElab := fun stx expectedType? => do toExpr (← toTree stx) expectedType? @[builtin_term_elab binop] def elabBinOp : TermElab := elabOp @[builtin_term_elab binop_lazy] def elabBinOpLazy : TermElab := elabOp @[builtin_term_elab unop] def elabUnOp : TermElab := elabOp /-- Elaboration functionf for `binrel%` and `binrel_no_prop%` notations. We use the infrastructure for `binop%` to make sure we propagate information between the left and right hand sides of a binary relation. Recall that the `binrel_no_prop%` notation is used for relations such as `==` which do not support `Prop`, but we still want to be able to write `(5 > 2) == (2 > 1)`. -/ def elabBinRelCore (noProp : Bool) (stx : Syntax) (expectedType? : Option Expr) : TermElabM Expr := do match (← resolveId? stx[1]) with | some f => withSynthesizeLight do /- We used to use `withSynthesize (mayPostpone := true)` here instead of `withSynthesizeLight` here. Recall that `withSynthesizeLight` is equivalent to `withSynthesize (mayPostpone := true) (synthesizeDefault := false)`. It seems too much to apply default instances at binary relations. For example, we cannot elaborate ``` def as : List Int := [-1, 2, 0, -3, 4] #eval as.map fun a => ite (a ≥ 0) [a] [] ``` The problem is that when elaborating `a ≥ 0` we don't know yet that `a` is an `Int`. Then, by applying default instances, we apply the default instance to `0` that forces it to become an `Int`, and Lean infers that `a` has type `Nat`. Then, later we get a type error because `as` is `List Int` instead of `List Nat`. This behavior is quite counterintuitive since if we avoid this elaborator by writing ``` def as : List Int := [-1, 2, 0, -3, 4] #eval as.map fun a => ite (GE.ge a 0) [a] [] ``` everything works. However, there is a drawback of using `withSynthesizeLight` instead of `withSynthesize (mayPostpone := true)`. The following cannot be elaborated ``` have : (0 == 1) = false := rfl ``` We get a type error at `rfl`. `0 == 1` only reduces to `false` after we have applied the default instances that force the numeral to be `Nat`. We claim this is defensible behavior because the same happens if we do not use this elaborator. ``` have : (BEq.beq 0 1) = false := rfl ``` We can improve this failure in the future by applying default instances before reporting a type mismatch. -/ let lhs ← withRef stx[2] <| toTree stx[2] let rhs ← withRef stx[3] <| toTree stx[3] let tree := .binop (lazy := false) stx .anonymous f lhs rhs let r ← analyze tree none trace[Elab.binrel] "hasUncomparable: {r.hasUncomparable}, maxType: {r.max?}" if r.hasUncomparable || r.max?.isNone then -- Use default elaboration strategy + `toBoolIfNecessary` let lhs ← toExprCore lhs let rhs ← toExprCore rhs let lhs ← toBoolIfNecessary lhs let rhs ← toBoolIfNecessary rhs let lhsType ← inferType lhs let rhs ← ensureHasType lhsType rhs elabAppArgs f #[] #[Arg.expr lhs, Arg.expr rhs] expectedType? (explicit := false) (ellipsis := false) (resultIsOutParamSupport := false) else let mut maxType := r.max?.get! /- If `noProp == true` and `maxType` is `Prop`, then set `maxType := Bool`. `See toBoolIfNecessary` -/ if noProp then if (← withNewMCtxDepth <| isDefEq maxType (mkSort levelZero)) then maxType := Lean.mkConst ``Bool let result ← toExprCore (← applyCoe tree maxType (isPred := true)) trace[Elab.binrel] "result: {result}" return result | none => throwUnknownConstant stx[1].getId where /-- If `noProp == true` and `e` has type `Prop`, then coerce it to `Bool`. -/ toBoolIfNecessary (e : Expr) : TermElabM Expr := do if noProp then -- We use `withNewMCtxDepth` to make sure metavariables are not assigned if (← withNewMCtxDepth <| isDefEq (← inferType e) (mkSort levelZero)) then return (← ensureHasType (Lean.mkConst ``Bool) e) return e @[builtin_term_elab binrel] def elabBinRel : TermElab := elabBinRelCore false @[builtin_term_elab binrel_no_prop] def elabBinRelNoProp : TermElab := elabBinRelCore true @[builtin_term_elab defaultOrOfNonempty] def elabDefaultOrNonempty : TermElab := fun stx expectedType? => do tryPostponeIfNoneOrMVar expectedType? match expectedType? with | none => throwError "invalid 'default_or_ofNonempty%', expected type is not known" | some expectedType => try mkDefault expectedType catch ex => try mkOfNonempty expectedType catch _ => if stx[1].isNone then throw ex else -- It is in the context of an `unsafe` constant. We can use sorry instead. -- Another option is to make a recursive application since it is unsafe. mkSorry expectedType false builtin_initialize registerTraceClass `Elab.binop registerTraceClass `Elab.binrel end Op end Lean.Elab.Term
10fb166a7511f3318cbd7b121c8ce3cec895779b
2c41ae31b2b771ad5646ad880201393f5269a7f0
/Lean/Examples/Car/Car_SystemModel.lean
3a06232a98fd937b75861d6cef596574d209a21a
[]
no_license
kevinsullivan/Boehm
926f25bc6f1a8b6bd47d333d936fdfc278228312
55208395bff20d48a598b7fa33a4d55a2447a9cf
refs/heads/master
1,586,127,134,302
1,488,252,326,000
1,488,252,326,000
32,836,930
0
0
null
null
null
null
UTF-8
Lean
false
false
3,008
lean
import Qualities.Changeable inductive CarStakeholders : Type | manufacturer | dealer | owner | driver | passenger | mechanic | ai record CarValue := mk :: (timeMinutes: nat) (moneyDollars: nat) (gasolineGallons: nat) (wearRate: nat) inductive CarPhases : Type | manufacturing | sale | ownership inductive CarContexts : Type | factory | dealership | home | road | shop /- Model: Product state space -/ inductive OilCleanliness : Type | oil_clean | oil_dirty inductive OilFullness : Type | oil_full | oil_low | oil_empty record OilCondition := mk :: (oilCleanliness : OilCleanliness) (oilFullness: OilFullness) inductive Location : Type | l_home | l_away inductive TireInflation : Type | tire_full | tire_low | tire_empty | tire_punctured record Car := mk :: (oilState : OilCondition) (tireState : TireInflation) (location : Location) def CarSystemType : SystemType := {Contexts := CarContexts, Stakeholders := CarStakeholders, Phases := CarPhases, ArtifactType := Car, ValueType := CarValue} /- Abbreviations for writing propositions, assertions, actions. -/ definition CarSystemState := @SystemInstance CarSystemType definition CarAssertion := @Assertion CarSystemType definition CarAction := @Action CarSystemType /- Useful propositions -/ definition oilLow (cs: CarSystemState): Prop := cs^.artifact^.oilState^.oilFullness = OilFullness.oil_low definition oilFull (cs: CarSystemState): Prop := cs^.artifact^.oilState^.oilFullness = OilFullness.oil_full definition oilClean (cs: CarSystemState): Prop := cs^.artifact^.oilState^.oilCleanliness = OilCleanliness.oil_clean definition oilDirty (cs: CarSystemState): Prop := cs^.artifact^.oilState^.oilCleanliness = OilCleanliness.oil_dirty definition atHome (cs: CarSystemState): Prop := cs^.artifact^.location = Location.l_home definition inOwnershipPhase (cs: CarSystemState): Prop := cs^.phase = CarPhases.ownership definition oilLowState: CarAssertion := fun cs: CarSystemState, (oilLow cs) definition oilFullState: CarAssertion := fun cs: CarSystemState, oilFull cs definition oilCleanState: CarAssertion := fun cs: CarSystemState, oilClean cs definition oilDirtyState: CarAssertion := fun cs: CarSystemState, oilDirty cs definition oilFreshState: CarAssertion := fun cs: CarSystemState, oilClean cs /\ oilFull cs definition anyState: CarAssertion := fun cs: CarSystemState, true definition atHomeState: CarAssertion := fun cs: CarSystemState, atHome cs /- The changeOil action yields a full tank of clean oil and makes no other changes. -/ definition ownerChangeOil: CarAction := fun cs: CarSystemState, { context := cs^.context, phase := cs^.phase, artifact := { oilState := { oilCleanliness := OilCleanliness.oil_clean, oilFullness := OilFullness.oil_full }, tireState := cs^.artifact^.tireState, location := cs^.artifact^.location }, value := cs^.value }
420e9a74429eb584f857d96d391b8e808b1e19b1
77c5b91fae1b966ddd1db969ba37b6f0e4901e88
/src/data/nat/multiplicity.lean
622d30908691c5d79eac9da82e13ab710bbb866d
[ "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
11,881
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 algebra.big_operators.intervals import data.nat.bitwise import data.nat.log import data.nat.parity import ring_theory.int.basic /-! # Natural number multiplicity This file contains lemmas about the multiplicity function (the maximum prime power dividing a number) when applied to naturals, in particular calculating it for factorials and binomial coefficients. ## Multiplicity calculations * `nat.multiplicity_factorial`: Legendre's Theorem. The multiplicity of `p` in `n!` is `n/p + ... + n/p^b` for any `b` such that `n/p^(b + 1) = 0`. * `nat.multiplicity_factorial_mul`: The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. * `nat.multiplicity_choose`: The multiplicity of `p` in `n.choose k` is the number of carries when `k` and`n - k` are added in base `p`. ## Other declarations * `nat.multiplicity_eq_card_pow_dvd`: The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i` divides `n`. * `nat.multiplicity_two_factorial_lt`: The multiplicity of `2` in `n!` is strictly less than `n`. * `nat.prime.multiplicity_something`: Specialization of `multiplicity.something` to a prime in the naturals. Avoids having to provide `p ≠ 1` and other trivialities, along with translating between `prime` and `nat.prime`. ## Tags Legendre, p-adic -/ open finset nat multiplicity open_locale big_operators nat namespace nat /-- The multiplicity of `m` in `n` is the number of positive natural numbers `i` such that `m ^ i` divides `n`. This set is expressed by filtering `Ico 1 b` where `b` is any bound greater than `log m n`. -/ lemma multiplicity_eq_card_pow_dvd {m n b : ℕ} (hm : m ≠ 1) (hn : 0 < n) (hb : log m n < b): multiplicity m n = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card := calc multiplicity m n = ↑(Ico 1 $ ((multiplicity m n).get (finite_nat_iff.2 ⟨hm, hn⟩) + 1)).card : by simp ... = ↑((finset.Ico 1 b).filter (λ i, m ^ i ∣ n)).card : congr_arg coe $ congr_arg card $ finset.ext $ λ i, begin rw [mem_filter, Ico.mem, Ico.mem, lt_succ_iff, ←@enat.coe_le_coe i, enat.coe_get, ←pow_dvd_iff_le_multiplicity, and.right_comm], refine (and_iff_left_of_imp (λ h, _)).symm, cases m, { rw [zero_pow, zero_dvd_iff] at h, exact (hn.ne' h.2).elim, { exact h.1 } }, exact ((pow_le_iff_le_log (succ_lt_succ $ nat.pos_of_ne_zero $ succ_ne_succ.1 hm) hn).1 $ le_of_dvd hn h.2).trans_lt hb, end namespace prime lemma multiplicity_one {p : ℕ} (hp : p.prime) : multiplicity p 1 = 0 := multiplicity.one_right (prime_iff.mp hp).not_unit lemma multiplicity_mul {p m n : ℕ} (hp : p.prime) : multiplicity p (m * n) = multiplicity p m + multiplicity p n := multiplicity.mul $ prime_iff.mp hp lemma multiplicity_pow {p m n : ℕ} (hp : p.prime) : multiplicity p (m ^ n) = n • (multiplicity p m) := multiplicity.pow $ prime_iff.mp hp lemma multiplicity_self {p : ℕ} (hp : p.prime) : multiplicity p p = 1 := multiplicity_self (prime_iff.mp hp).not_unit hp.ne_zero lemma multiplicity_pow_self {p n : ℕ} (hp : p.prime) : multiplicity p (p ^ n) = n := multiplicity_pow_self hp.ne_zero (prime_iff.mp hp).not_unit n /-- **Legendre's Theorem** The multiplicity of a prime in `n!` is the sum of the quotients `n / p ^ i`. This sum is expressed over the finset `Ico 1 b` where `b` is any bound greater than `log p n`. -/ lemma multiplicity_factorial {p : ℕ} (hp : p.prime) : ∀ {n b : ℕ}, log p n < b → multiplicity p n! = (∑ i in Ico 1 b, n / p ^ i : ℕ) | 0 b hb := by simp [Ico, hp.multiplicity_one] | (n+1) b hb := calc multiplicity p (n+1)! = multiplicity p n! + multiplicity p (n+1) : by rw [factorial_succ, hp.multiplicity_mul, add_comm] ... = (∑ i in Ico 1 b, n / p ^ i : ℕ) + ((finset.Ico 1 b).filter (λ i, p ^ i ∣ n+1)).card : by rw [multiplicity_factorial ((log_le_log_of_le $ le_succ _).trans_lt hb), ← multiplicity_eq_card_pow_dvd hp.ne_one (succ_pos _) hb] ... = (∑ i in Ico 1 b, (n / p ^ i + if p^i ∣ n+1 then 1 else 0) : ℕ) : by { rw [sum_add_distrib, sum_boole], simp } ... = (∑ i in Ico 1 b, (n + 1) / p ^ i : ℕ) : congr_arg coe $ finset.sum_congr rfl $ λ _ _, (succ_div _ _).symm /-- The multiplicity of `p` in `(p * (n + 1))!` is one more than the sum of the multiplicities of `p` in `(p * n)!` and `n + 1`. -/ lemma multiplicity_factorial_mul_succ {n p : ℕ} (hp : p.prime) : multiplicity p (p * (n + 1))! = multiplicity p (p * n)! + multiplicity p (n + 1) + 1 := begin have hp' := prime_iff.mp hp, have h0 : 2 ≤ p := hp.two_le, have h1 : 1 ≤ p * n + 1 := nat.le_add_left _ _, have h2 : p * n + 1 ≤ p * (n + 1), linarith, have h3 : p * n + 1 ≤ p * (n + 1) + 1, linarith, have hm : multiplicity p (p * n)! ≠ ⊤, { rw [ne.def, eq_top_iff_not_finite, not_not, finite_nat_iff], exact ⟨hp.ne_one, factorial_pos _⟩ }, revert hm, have h4 : ∀ m ∈ Ico (p * n + 1) (p * (n + 1)), multiplicity p m = 0, { intros m hm, apply multiplicity_eq_zero_of_not_dvd, rw [← exists_lt_and_lt_iff_not_dvd _ (pos_iff_ne_zero.mpr hp.ne_zero)], rw [Ico.mem] at hm, exact ⟨n, lt_of_succ_le hm.1, hm.2⟩ }, simp_rw [← prod_Ico_id_eq_factorial, multiplicity.finset.prod hp', ← sum_Ico_consecutive _ h1 h3, add_assoc], intro h, rw [enat.add_left_cancel_iff h, sum_Ico_succ_top h2, multiplicity.mul hp', hp.multiplicity_self, sum_congr rfl h4, sum_const_zero, zero_add, add_comm (1 : enat)] end /-- The multiplicity of `p` in `(p * n)!` is `n` more than that of `n!`. -/ lemma multiplicity_factorial_mul {n p : ℕ} (hp : p.prime) : multiplicity p (p * n)! = multiplicity p n! + n := begin induction n with n ih, { simp }, { simp only [succ_eq_add_one, multiplicity.mul, hp, prime_iff.mp hp, ih, multiplicity_factorial_mul_succ, ←add_assoc, nat.cast_one, nat.cast_add, factorial_succ], congr' 1, rw [add_comm, add_assoc] } end /-- A prime power divides `n!` iff it is at most the sum of the quotients `n / p ^ i`. This sum is expressed over the set `Ico 1 b` where `b` is any bound greater than `log p n` -/ lemma pow_dvd_factorial_iff {p : ℕ} {n r b : ℕ} (hp : p.prime) (hbn : log p n < b) : p ^ r ∣ n! ↔ r ≤ ∑ i in Ico 1 b, n / p ^ i := by rw [← enat.coe_le_coe, ← hp.multiplicity_factorial hbn, ← pow_dvd_iff_le_multiplicity] lemma multiplicity_factorial_le_div_pred {p : ℕ} (hp : p.prime) (n : ℕ) : multiplicity p n! ≤ (n/(p - 1) : ℕ) := begin rw [hp.multiplicity_factorial (lt_succ_self _), enat.coe_le_coe], exact nat.geom_sum_Ico_le hp.two_le _ _, end lemma multiplicity_choose_aux {p n b k : ℕ} (hp : p.prime) (hkn : k ≤ n) : ∑ i in finset.Ico 1 b, n / p ^ i = ∑ i in finset.Ico 1 b, k / p ^ i + ∑ i in finset.Ico 1 b, (n - k) / p ^ i + ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card := calc ∑ i in finset.Ico 1 b, n / p ^ i = ∑ i in finset.Ico 1 b, (k + (n - k)) / p ^ i : by simp only [nat.add_sub_cancel' hkn] ... = ∑ i in finset.Ico 1 b, (k / p ^ i + (n - k) / p ^ i + if p ^ i ≤ k % p ^ i + (n - k) % p ^ i then 1 else 0) : by simp only [nat.add_div (pow_pos hp.pos _)] ... = _ : by simp [sum_add_distrib, sum_boole] /-- The multiplicity of `p` in `choose n k` is the number of carries when `k` and `n - k` are added in base `p`. The set is expressed by filtering `Ico 1 b` where `b` is any bound greater than `log p n`. -/ lemma multiplicity_choose {p n k b : ℕ} (hp : p.prime) (hkn : k ≤ n) (hnb : log p n < b) : multiplicity p (choose n k) = ((Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card := have h₁ : multiplicity p (choose n k) + multiplicity p (k! * (n - k)!) = ((finset.Ico 1 b).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card + multiplicity p (k! * (n - k)!), begin rw [← hp.multiplicity_mul, ← mul_assoc, choose_mul_factorial_mul_factorial hkn, hp.multiplicity_factorial hnb, hp.multiplicity_mul, hp.multiplicity_factorial ((log_le_log_of_le hkn).trans_lt hnb), hp.multiplicity_factorial (lt_of_le_of_lt (log_le_log_of_le (nat.sub_le_self _ _)) hnb), multiplicity_choose_aux hp hkn], simp [add_comm], end, (enat.add_right_cancel_iff (enat.ne_top_iff_dom.2 $ by exact finite_nat_iff.2 ⟨ne_of_gt hp.one_lt, mul_pos (factorial_pos k) (factorial_pos (n - k))⟩)).1 h₁ /-- A lower bound on the multiplicity of `p` in `choose n k`. -/ lemma multiplicity_le_multiplicity_choose_add {p : ℕ} (hp : p.prime) (n k : ℕ) : multiplicity p n ≤ multiplicity p (choose n k) + multiplicity p k := if hkn : n < k then by simp [choose_eq_zero_of_lt hkn] else if hk0 : k = 0 then by simp [hk0] else if hn0 : n = 0 then by cases k; simp [hn0, *] at * else begin rw [multiplicity_choose hp (le_of_not_gt hkn) (lt_succ_self _), multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hk0) (lt_succ_of_le (log_le_log_of_le (le_of_not_gt hkn))), multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) (nat.pos_of_ne_zero hn0) (lt_succ_self _), ← nat.cast_add, enat.coe_le_coe], calc ((Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ n)).card ≤ ((Ico 1 (log p n).succ).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i) ∪ (Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ k) ).card : card_le_of_subset $ λ i, begin have := @le_mod_add_mod_of_dvd_add_of_not_dvd k (n - k) (p ^ i), simp [nat.add_sub_cancel' (le_of_not_gt hkn)] at * {contextual := tt}, tauto end ... ≤ ((Ico 1 (log p n).succ).filter (λ i, p ^ i ≤ k % p ^ i + (n - k) % p ^ i)).card + ((Ico 1 (log p n).succ).filter (λ i, p ^ i ∣ k)).card : card_union_le _ _ end lemma multiplicity_choose_prime_pow {p n k : ℕ} (hp : p.prime) (hkn : k ≤ p ^ n) (hk0 : 0 < k) : multiplicity p (choose (p ^ n) k) + multiplicity p k = n := le_antisymm (have hdisj : disjoint ((Ico 1 n.succ).filter (λ i, p ^ i ≤ k % p ^ i + (p ^ n - k) % p ^ i)) ((Ico 1 n.succ).filter (λ i, p ^ i ∣ k)), by simp [disjoint_right, *, dvd_iff_mod_eq_zero, nat.mod_lt _ (pow_pos hp.pos _)] {contextual := tt}, begin rw [multiplicity_choose hp hkn (lt_succ_self _), multiplicity_eq_card_pow_dvd (ne_of_gt hp.one_lt) hk0 (lt_succ_of_le (log_le_log_of_le hkn)), ← nat.cast_add, enat.coe_le_coe, log_pow hp.one_lt, ← card_disjoint_union hdisj, filter_union_right], have filter_le_Ico := (Ico 1 n.succ).card_filter_le _, rwa Ico.card 1 n.succ at filter_le_Ico, end) (by rw [← hp.multiplicity_pow_self]; exact multiplicity_le_multiplicity_choose_add hp _ _) end prime lemma multiplicity_two_factorial_lt : ∀ {n : ℕ} (h : n ≠ 0), multiplicity 2 n! < n := begin have h2 := prime_iff.mp prime_two, refine binary_rec _ _, { contradiction }, { intros b n ih h, by_cases hn : n = 0, { subst hn, simp at h, simp [h, one_right h2.not_unit, enat.zero_lt_one] }, have : multiplicity 2 (2 * n)! < (2 * n : ℕ), { rw [prime_two.multiplicity_factorial_mul], refine (enat.add_lt_add_right (ih hn) (enat.coe_ne_top _)).trans_le _, rw [two_mul], norm_cast }, cases b, { simpa [bit0_eq_two_mul n] }, { suffices : multiplicity 2 (2 * n + 1) + multiplicity 2 (2 * n)! < ↑(2 * n) + 1, { simpa [succ_eq_add_one, multiplicity.mul, h2, prime_two, nat.bit1_eq_succ_bit0, bit0_eq_two_mul n] }, rw [multiplicity_eq_zero_of_not_dvd (two_not_dvd_two_mul_add_one n), zero_add], refine this.trans _, exact_mod_cast lt_succ_self _ }} end end nat
e722d9d0afe8550cff7f86dec90923fea26662c0
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/src/Init/Data/Format/Syntax.lean
4a551e718588500bcb72a9f848256cd9410b2147
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
1,939
lean
/- Copyright (c) 2021 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.Format.Macro import Init.Data.Format.Instances import Init.Meta namespace Lean.Syntax open Std open Std.Format private def formatInfo (showInfo : Bool) (info : SourceInfo) (f : Format) : Format := match showInfo, info with | true, SourceInfo.original lead pos trail endPos => f!"{lead}:{pos}:{f}:{endPos}:{trail}" | true, SourceInfo.synthetic pos endPos => f!"{pos}:{f}:{endPos}" | _, _ => f partial def formatStxAux (maxDepth : Option Nat) (showInfo : Bool) : Nat → Syntax → Format | _, atom info val => formatInfo showInfo info $ format (repr val) | _, ident info _ val _ => formatInfo showInfo info $ format "`" ++ format val | _, missing => "<missing>" | depth, node _ kind args => let depth := depth + 1; if kind == nullKind then sbracket $ if args.size > 0 && depth > maxDepth.getD depth then ".." else joinSep (args.toList.map (formatStxAux maxDepth showInfo depth)) line else let shorterName := kind.replacePrefix `Lean.Parser Name.anonymous; let header := format shorterName; let body : List Format := if args.size > 0 && depth > maxDepth.getD depth then [".."] else args.toList.map (formatStxAux maxDepth showInfo depth); paren $ joinSep (header :: body) line def formatStx (stx : Syntax) (maxDepth : Option Nat := none) (showInfo := false) : Format := formatStxAux maxDepth showInfo 0 stx instance : ToFormat (Syntax) := ⟨formatStx⟩ instance : ToString (Syntax) := ⟨@toString Format _ ∘ format⟩ instance : ToFormat (TSyntax k) := ⟨(format ·.raw)⟩ instance : ToString (TSyntax k) := ⟨(toString ·.raw)⟩ end Lean.Syntax
42fd9007532328fac412416e7de6c691bb34f0be
ec62863c729b7eedee77b86d974f2c529fa79d25
/1/b.lean
f57cbb80143dd92c1cdd90d1d076f3ffdf7b1eeb
[]
no_license
rwbarton/advent-of-lean-4
2ac9b17ba708f66051e3d8cd694b0249bc433b65
417c7e2718253ba7148c0279fcb251b6fc291477
refs/heads/main
1,675,917,092,057
1,609,864,581,000
1,609,864,581,000
317,700,289
24
0
null
null
null
null
UTF-8
Lean
false
false
586
lean
def solve₂ (x₀ x₁ : Int) : List Int → Option Int | [] => Option.none | (x :: xs) => if x₀ + x₁ + x = 2020 then Option.some (x₀ * x₁ * x) else solve₂ x₀ x₁ xs def solve₁ (x₀ : Int) : List Int → Option Int | [] => Option.none | (x :: xs) => solve₂ x₀ x xs <|> solve₁ x₀ xs def solve : List Int → Option Int | [] => Option.none | (x :: xs) => solve₁ x xs <|> solve xs def main (args : List String) : IO UInt32 := do let input ← IO.FS.lines "a.in" IO.print $ (solve (input.toList.map String.toInt!)).getD 0 IO.print "\n" return 0
f3babd085460dec91e9e58626182c298f221a6ee
9a0b1b3a653ea926b03d1495fef64da1d14b3174
/tidy/lib/list.lean
d59ba88d598c821667f0b383a4e115bd8c37d22e
[ "Apache-2.0" ]
permissive
khoek/mathlib-tidy
8623b27b4e04e7d598164e7eaf248610d58f768b
866afa6ab597c47f1b72e8fe2b82b97fff5b980f
refs/heads/master
1,585,598,975,772
1,538,659,544,000
1,538,659,544,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
2,358
lean
import data.option import data.buffer universes u v w namespace list private def min_rel_aux {α : Type u} (r : α → α → Prop) [decidable_rel r] (curr : α) : list α → α | [] := curr | (a :: rest) := if r a curr then a else curr def min_rel {α : Type u} (l : list α) (r : α → α → Prop) [decidable_rel r] : option α := match l with | [] := none | (a :: rest) := some $ min_rel_aux r a rest end def min {α : Type u} (l : list α) [has_lt α] [@decidable_rel α has_lt.lt] : option α := min_rel l has_lt.lt def contains {α : Type u} [decidable_eq α] (a : α) : list α → bool | [] := ff | (h :: rest) := if a = h then tt else rest.contains meta def erase_duplicates {α : Type u} [decidable_eq α] : list α → list α | [] := [] | (x :: t) := (x :: erase_duplicates (t.filter $ λ a, a ≠ x)) def multiplex {α : Type u} : list α → list α → list α | [] l := l | l [] := l | (a₁ :: l₁) (a₂ :: l₂) := [a₁, a₂].append $ l₁.multiplex l₂ private def set_at_aux {α : Type u} (val : α) : list α → list α → ℕ → list α | _ [] _ := [] | l (a :: rest) 0 := l.append (val :: rest) | l (a :: rest) k := set_at_aux (l.append [a]) rest (k - 1) def set_at {α : Type u} (l : list α) (idx : ℕ) (val : α) : list α := set_at_aux val [] l idx def split_on_aux {α : Type u} [decidable_eq α] (a : α) : list α → list α → list (list α) | [] l := [l.reverse] | (h :: t) l := if h = a then l.reverse :: (split_on_aux t []) else split_on_aux t (h :: l) def split_on {α : Type u} [decidable_eq α] (a : α) : list α → list (list α) | l := split_on_aux a l [] def erase_first_such_that {α : Type u} (f : α → Prop) [decidable_pred f] : list α → list α | [] := [] | (h :: t) := if f h then t else (h :: t.erase_first_such_that) def erase_such_that {α : Type u} (f : α → Prop) [decidable_pred f] : list α → list α := filter (λ x, ¬ f x) def strip {α : Type u} [decidable_eq α] (l : list α) (v : α) : list α := l.erase_such_that (λ c, c = v) def stripl {α : Type u} [decidable_eq α] (l : list α) (vs : list α) : list α := l.erase_such_that (λ c, c ∈ vs) end list def list.at {α : Type u} [inhabited α] (l : list α) (n : ℕ) : α := list.head $ option.to_list $ list.nth l n
aa7f3f2563986382a628e2db1d0a17dba321d519
abd85493667895c57a7507870867b28124b3998f
/src/linear_algebra/matrix.lean
6e7e1ccfbb3b0d7d23b64fb9a4a403edc7245277
[ "Apache-2.0" ]
permissive
pechersky/mathlib
d56eef16bddb0bfc8bc552b05b7270aff5944393
f1df14c2214ee114c9738e733efd5de174deb95d
refs/heads/master
1,666,714,392,571
1,591,747,567,000
1,591,747,567,000
270,557,274
0
0
Apache-2.0
1,591,597,975,000
1,591,597,974,000
null
UTF-8
Lean
false
false
13,250
lean
/- Copyright (c) 2019 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl, Casper Putz -/ import linear_algebra.dimension /-! # Linear maps and matrices This file defines the maps to send matrices to a linear map, and to send linear maps between modules with a finite bases to matrices. This defines a linear equivalence between linear maps between finite-dimensional vector spaces and matrices indexed by the respective bases. Some results are proved about the linear map corresponding to a diagonal matrix (range, ker and rank). ## Main definitions to_lin, to_matrix, linear_equiv_matrix ## Tags linear_map, matrix, linear_equiv, diagonal -/ noncomputable theory open set submodule universes u v w variables {l m n : Type u} [fintype l] [fintype m] [fintype n] namespace matrix variables {R : Type v} [comm_ring R] instance [decidable_eq m] [decidable_eq n] (R) [fintype R] : fintype (matrix m n R) := by unfold matrix; apply_instance /-- Evaluation of matrices gives a linear map from matrix m n R to linear maps (n → R) →ₗ[R] (m → R). -/ def eval : (matrix m n R) →ₗ[R] ((n → R) →ₗ[R] (m → R)) := begin refine linear_map.mk₂ R mul_vec _ _ _ _, { assume M N v, funext x, change finset.univ.sum (λy:n, (M x y + N x y) * v y) = _, simp only [_root_.add_mul, finset.sum_add_distrib], refl }, { assume c M v, funext x, change finset.univ.sum (λy:n, (c * M x y) * v y) = _, simp only [_root_.mul_assoc, finset.mul_sum.symm], refl }, { assume M v w, funext x, change finset.univ.sum (λy:n, M x y * (v y + w y)) = _, simp [_root_.mul_add, finset.sum_add_distrib], refl }, { assume c M v, funext x, change finset.univ.sum (λy:n, M x y * (c * v y)) = _, rw [show (λy:n, M x y * (c * v y)) = (λy:n, c * (M x y * v y)), { funext n, ac_refl }, ← finset.mul_sum], refl } end /-- Evaluation of matrices gives a map from matrix m n R to linear maps (n → R) →ₗ[R] (m → R). -/ def to_lin : matrix m n R → (n → R) →ₗ[R] (m → R) := eval.to_fun lemma to_lin_add (M N : matrix m n R) : (M + N).to_lin = M.to_lin + N.to_lin := matrix.eval.map_add M N @[simp] lemma to_lin_zero : (0 : matrix m n R).to_lin = 0 := matrix.eval.map_zero @[simp] lemma to_lin_neg (M : matrix m n R) : (-M).to_lin = -M.to_lin := @linear_map.map_neg _ _ ((n → R) →ₗ[R] m → R) _ _ _ _ _ matrix.eval M instance to_lin.is_linear_map : @is_linear_map R (matrix m n R) ((n → R) →ₗ[R] (m → R)) _ _ _ _ _ to_lin := matrix.eval.is_linear instance to_lin.is_add_monoid_hom : @is_add_monoid_hom (matrix m n R) ((n → R) →ₗ[R] (m → R)) _ _ to_lin := { map_zero := to_lin_zero, map_add := to_lin_add } @[simp] lemma to_lin_apply (M : matrix m n R) (v : n → R) : (M.to_lin : (n → R) → (m → R)) v = mul_vec M v := rfl lemma mul_to_lin (M : matrix m n R) (N : matrix n l R) : (M.mul N).to_lin = M.to_lin.comp N.to_lin := by { ext, simp } @[simp] lemma to_lin_one [decidable_eq n] : (1 : matrix n n R).to_lin = linear_map.id := by { ext, simp } end matrix namespace linear_map variables {R : Type v} [comm_ring R] /-- The linear map from linear maps (n → R) →ₗ[R] (m → R) to matrix m n R. -/ def to_matrixₗ [decidable_eq n] : ((n → R) →ₗ[R] (m → R)) →ₗ[R] matrix m n R := begin refine linear_map.mk (λ f i j, f (λ n, ite (j = n) 1 0) i) _ _, { assume f g, simp only [add_apply], refl }, { assume f g, simp only [smul_apply], refl } end /-- The map from linear maps (n → R) →ₗ[R] (m → R) to matrix m n R. -/ def to_matrix [decidable_eq n] : ((n → R) →ₗ[R] (m → R)) → matrix m n R := to_matrixₗ.to_fun @[simp] lemma to_matrix_id [decidable_eq n] : (@linear_map.id _ (n → R) _ _ _).to_matrix = 1 := by { ext, simp [to_matrix, to_matrixₗ, matrix.one_val, eq_comm] } end linear_map section linear_equiv_matrix variables {R : Type v} [comm_ring R] [decidable_eq n] open finsupp matrix linear_map /-- to_lin is the left inverse of to_matrix. -/ lemma to_matrix_to_lin {f : (n → R) →ₗ[R] (m → R)} : to_lin (to_matrix f) = f := begin ext : 1, -- Show that the two sides are equal by showing that they are equal on a basis convert linear_eq_on (set.range _) _ (is_basis.mem_span (@pi.is_basis_fun R n _ _) _), assume e he, rw [@std_basis_eq_single R _ _ _ 1] at he, cases (set.mem_range.mp he) with i h, ext j, change finset.univ.sum (λ k, (f.to_fun (λ l, ite (k = l) 1 0)) j * (e k)) = _, rw [←h], conv_lhs { congr, skip, funext, rw [mul_comm, ←smul_eq_mul, ←pi.smul_apply, ←linear_map.smul], rw [show _ = ite (i = k) (1:R) 0, by convert single_apply], rw [show f.to_fun (ite (i = k) (1:R) 0 • (λ l, ite (k = l) 1 0)) = ite (i = k) (f.to_fun _) 0, { split_ifs, { rw [one_smul] }, { rw [zero_smul], exact linear_map.map_zero f } }] }, convert finset.sum_eq_single i _ _, { rw [if_pos rfl], convert rfl, ext, congr }, { assume _ _ hbi, rw [if_neg $ ne.symm hbi], refl }, { assume hi, exact false.elim (hi $ finset.mem_univ i) } end /-- to_lin is the right inverse of to_matrix. -/ lemma to_lin_to_matrix {M : matrix m n R} : to_matrix (to_lin M) = M := begin ext, change finset.univ.sum (λ y, M i y * ite (j = y) 1 0) = M i j, have h1 : (λ y, M i y * ite (j = y) 1 0) = (λ y, ite (j = y) (M i y) 0), { ext, split_ifs, exact mul_one _, exact ring.mul_zero _ }, have h2 : finset.univ.sum (λ y, ite (j = y) (M i y) 0) = ({j} : finset n).sum (λ y, ite (j = y) (M i y) 0), { refine (finset.sum_subset _ _).symm, { intros _ H, rwa finset.mem_singleton.1 H, exact finset.mem_univ _ }, { exact λ _ _ H, if_neg (mt (finset.mem_singleton.2 ∘ eq.symm) H) } }, rw [h1, h2, finset.sum_singleton], exact if_pos rfl end /-- Linear maps (n → R) →ₗ[R] (m → R) are linearly equivalent to matrix m n R. -/ def linear_equiv_matrix' : ((n → R) →ₗ[R] (m → R)) ≃ₗ[R] matrix m n R := { to_fun := to_matrix, inv_fun := to_lin, right_inv := λ _, to_lin_to_matrix, left_inv := λ _, to_matrix_to_lin, add := to_matrixₗ.add, smul := to_matrixₗ.smul } /-- Given a basis of two modules M₁ and M₂ over a commutative ring R, we get a linear equivalence between linear maps M₁ →ₗ M₂ and matrices over R indexed by the bases. -/ def linear_equiv_matrix {ι κ M₁ M₂ : Type*} [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂] [fintype ι] [decidable_eq ι] [fintype κ] {v₁ : ι → M₁} {v₂ : κ → M₂} (hv₁ : is_basis R v₁) (hv₂ : is_basis R v₂) : (M₁ →ₗ[R] M₂) ≃ₗ[R] matrix κ ι R := linear_equiv.trans (linear_equiv.arrow_congr (equiv_fun_basis hv₁) (equiv_fun_basis hv₂)) linear_equiv_matrix' end linear_equiv_matrix namespace matrix open_locale matrix lemma comp_to_matrix_mul {R : Type v} [comm_ring R] [decidable_eq l] [decidable_eq m] (f : (m → R) →ₗ[R] (n → R)) (g : (l → R) →ₗ[R] (m → R)) : (f.comp g).to_matrix = f.to_matrix ⬝ g.to_matrix := suffices (f.comp g) = (f.to_matrix ⬝ g.to_matrix).to_lin, by rw [this, to_lin_to_matrix], by rw [mul_to_lin, to_matrix_to_lin, to_matrix_to_lin] section trace variables {R : Type v} {M : Type w} [ring R] [add_comm_group M] [module R M] /-- The diagonal of a square matrix. -/ def diag (n : Type u) (R : Type v) (M : Type w) [ring R] [add_comm_group M] [module R M] [fintype n] : (matrix n n M) →ₗ[R] n → M := { to_fun := λ A i, A i i, add := by { intros, ext, refl, }, smul := by { intros, ext, refl, } } @[simp] lemma diag_apply (A : matrix n n M) (i : n) : diag n R M A i = A i i := rfl @[simp] lemma diag_one [decidable_eq n] : diag n R R 1 = λ i, 1 := by { dunfold diag, ext, simp [one_val_eq] } @[simp] lemma diag_transpose (A : matrix n n M) : diag n R M Aᵀ = diag n R M A := rfl /-- The trace of a square matrix. -/ def trace (n : Type u) (R : Type v) (M : Type w) [ring R] [add_comm_group M] [module R M] [fintype n] : (matrix n n M) →ₗ[R] M := { to_fun := finset.univ.sum ∘ (diag n R M), add := by { intros, apply finset.sum_add_distrib, }, smul := by { intros, simp [finset.smul_sum], } } @[simp] lemma trace_diag (A : matrix n n M) : trace n R M A = finset.univ.sum (diag n R M A) := rfl @[simp] lemma trace_one [decidable_eq n] : trace n R R 1 = fintype.card n := have h : trace n R R 1 = finset.univ.sum (diag n R R 1) := rfl, by rw [h, diag_one, finset.sum_const, nsmul_one]; refl @[simp] lemma trace_transpose (A : matrix n n M) : trace n R M Aᵀ = trace n R M A := rfl @[simp] lemma trace_transpose_mul (A : matrix m n R) (B : matrix n m R) : trace n R R (Aᵀ ⬝ Bᵀ) = trace m R R (A ⬝ B) := finset.sum_comm lemma trace_mul_comm {S : Type v} [comm_ring S] (A : matrix m n S) (B : matrix n m S) : trace n S S (B ⬝ A) = trace m S S (A ⬝ B) := by rw [←trace_transpose, ←trace_transpose_mul, transpose_mul] end trace section ring variables {R : Type v} [comm_ring R] open linear_map matrix lemma proj_diagonal [decidable_eq m] (i : m) (w : m → R) : (proj i).comp (to_lin (diagonal w)) = (w i) • proj i := by ext j; simp [mul_vec_diagonal] lemma diagonal_comp_std_basis [decidable_eq n] (w : n → R) (i : n) : (diagonal w).to_lin.comp (std_basis R (λ_:n, R) i) = (w i) • std_basis R (λ_:n, R) i := begin ext a j, simp only [linear_map.comp_apply, smul_apply, to_lin_apply, mul_vec_diagonal, smul_apply, pi.smul_apply, smul_eq_mul], by_cases i = j, { subst h }, { rw [std_basis_ne R (λ_:n, R) _ _ (ne.symm h), _root_.mul_zero, _root_.mul_zero] } end lemma diagonal_to_lin [decidable_eq m] (w : m → R) : (diagonal w).to_lin = linear_map.pi (λi, w i • linear_map.proj i) := by ext v j; simp [mul_vec_diagonal] end ring section vector_space variables {K : Type u} [field K] -- maybe try to relax the universe constraint open linear_map matrix lemma rank_vec_mul_vec (w : m → K) (v : n → K) : rank (vec_mul_vec w v).to_lin ≤ 1 := begin rw [vec_mul_vec_eq, mul_to_lin], refine le_trans (rank_comp_le1 _ _) _, refine le_trans (rank_le_domain _) _, rw [dim_fun', ← cardinal.fintype_card], exact le_refl _ end lemma ker_diagonal_to_lin [decidable_eq m] (w : m → K) : ker (diagonal w).to_lin = (⨆i∈{i | w i = 0 }, range (std_basis K (λi, K) i)) := begin rw [← comap_bot, ← infi_ker_proj], simp only [comap_infi, (ker_comp _ _).symm, proj_diagonal, ker_smul'], have : univ ⊆ {i : m | w i = 0} ∪ -{i : m | w i = 0}, { rw set.union_compl_self }, exact (supr_range_std_basis_eq_infi_ker_proj K (λi:m, K) (disjoint_compl {i | w i = 0}) this (finite.of_fintype _)).symm end lemma range_diagonal [decidable_eq m] (w : m → K) : (diagonal w).to_lin.range = (⨆ i ∈ {i | w i ≠ 0}, (std_basis K (λi, K) i).range) := begin dsimp only [mem_set_of_eq], rw [← map_top, ← supr_range_std_basis, map_supr], congr, funext i, rw [← linear_map.range_comp, diagonal_comp_std_basis, ← range_smul'] end lemma rank_diagonal [decidable_eq m] [decidable_eq K] (w : m → K) : rank (diagonal w).to_lin = fintype.card { i // w i ≠ 0 } := begin have hu : univ ⊆ - {i : m | w i = 0} ∪ {i : m | w i = 0}, { rw set.compl_union_self }, have hd : disjoint {i : m | w i ≠ 0} {i : m | w i = 0} := (disjoint_compl {i | w i = 0}).symm, have h₁ := supr_range_std_basis_eq_infi_ker_proj K (λi:m, K) hd hu (finite.of_fintype _), have h₂ := @infi_ker_proj_equiv K _ _ (λi:m, K) _ _ _ _ (by simp; apply_instance) hd hu, rw [rank, range_diagonal, h₁, ←@dim_fun' K], apply linear_equiv.dim_eq, apply h₂, end end vector_space end matrix /-- The natural equivalence between linear endomorphisms of finite free modules and square matrices is compatible with the algebra structures. -/ def alg_equiv_matrix' {R : Type v} [comm_ring R] [decidable_eq n] : module.End R (n → R) ≃ₐ[R] matrix n n R := { map_mul' := matrix.comp_to_matrix_mul, map_add' := linear_equiv_matrix'.map_add, commutes' := λ r, by { change (r • (linear_map.id : module.End R _)).to_matrix = r • 1, rw ←linear_map.to_matrix_id, refl, }, ..linear_equiv_matrix' } /-- A linear equivalence of two modules induces an equivalence of algebras of their endomorphisms. -/ def linear_equiv.alg_conj {R : Type v} [comm_ring R] {M₁ M₂ : Type*} [add_comm_group M₁] [module R M₁] [add_comm_group M₂] [module R M₂] (e : M₁ ≃ₗ[R] M₂) : module.End R M₁ ≃ₐ[R] module.End R M₂ := { map_mul' := λ f g, by apply e.arrow_congr_comp, map_add' := e.conj.add, commutes' := λ r, by { change e.conj (r • linear_map.id) = r • linear_map.id, rw [linear_equiv.map_smul, linear_equiv.conj_id], }, ..e.conj } /-- A basis of a module induces an equivalence of algebras from the endomorphisms of the module to square matrices. -/ def alg_equiv_matrix {R : Type v} {M : Type w} [comm_ring R] [add_comm_group M] [module R M] [decidable_eq n] {b : n → M} (h : is_basis R b) : module.End R M ≃ₐ[R] matrix n n R := (equiv_fun_basis h).alg_conj.trans alg_equiv_matrix'
d509c119a8ac60aae77eb18067e2c3341114d0b0
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/limits/shapes/default.lean
2563b304688718cd20c915192af52b360b3dba8f
[]
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
775
lean
import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.category_theory.limits.shapes.terminal import Mathlib.category_theory.limits.shapes.binary_products import Mathlib.category_theory.limits.shapes.products import Mathlib.category_theory.limits.shapes.finite_products import Mathlib.category_theory.limits.shapes.finite_limits import Mathlib.category_theory.limits.shapes.biproducts import Mathlib.category_theory.limits.shapes.images import Mathlib.category_theory.limits.shapes.zero import Mathlib.category_theory.limits.shapes.kernels import Mathlib.category_theory.limits.shapes.equalizers import Mathlib.category_theory.limits.shapes.wide_pullbacks import Mathlib.category_theory.limits.shapes.pullbacks import Mathlib.PostPort namespace Mathlib
50c3c88469ff1084226284630a39fad4837b97e8
c777c32c8e484e195053731103c5e52af26a25d1
/src/analysis/ODE/gronwall.lean
04426303cd2c01d82a882c05bc4d2d82e9dc432b
[ "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
13,190
lean
/- Copyright (c) 2020 Yury Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury Kudryashov -/ import analysis.special_functions.exp_deriv /-! # Grönwall's inequality The main technical result of this file is the Grönwall-like inequality `norm_le_gronwall_bound_of_norm_deriv_right_le`. It states that if `f : ℝ → E` satisfies `‖f a‖ ≤ δ` and `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then for all `x ∈ [a, b]` we have `‖f x‖ ≤ δ * exp (K * x) + (ε / K) * (exp (K * x) - 1)`. Then we use this inequality to prove some estimates on the possible rate of growth of the distance between two approximate or exact solutions of an ordinary differential equation. The proofs are based on [Hubbard and West, *Differential Equations: A Dynamical Systems Approach*, Sec. 4.5][HubbardWest-ode], where `norm_le_gronwall_bound_of_norm_deriv_right_le` is called “Fundamental Inequality”. ## TODO - Once we have FTC, prove an inequality for a function satisfying `‖f' x‖ ≤ K x * ‖f x‖ + ε`, or more generally `liminf_{y→x+0} (f y - f x)/(y - x) ≤ K x * f x + ε` with any sign of `K x` and `f x`. -/ variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] {F : Type*} [normed_add_comm_group F] [normed_space ℝ F] open metric set asymptotics filter real open_locale classical topology nnreal /-! ### Technical lemmas about `gronwall_bound` -/ /-- Upper bound used in several Grönwall-like inequalities. -/ noncomputable def gronwall_bound (δ K ε x : ℝ) : ℝ := if K = 0 then δ + ε * x else δ * exp (K * x) + (ε / K) * (exp (K * x) - 1) lemma gronwall_bound_K0 (δ ε : ℝ) : gronwall_bound δ 0 ε = λ x, δ + ε * x := funext $ λ x, if_pos rfl lemma gronwall_bound_of_K_ne_0 {δ K ε : ℝ} (hK : K ≠ 0) : gronwall_bound δ K ε = λ x, δ * exp (K * x) + (ε / K) * (exp (K * x) - 1) := funext $ λ x, if_neg hK lemma has_deriv_at_gronwall_bound (δ K ε x : ℝ) : has_deriv_at (gronwall_bound δ K ε) (K * (gronwall_bound δ K ε x) + ε) x := begin by_cases hK : K = 0, { subst K, simp only [gronwall_bound_K0, zero_mul, zero_add], convert ((has_deriv_at_id x).const_mul ε).const_add δ, rw [mul_one] }, { simp only [gronwall_bound_of_K_ne_0 hK], convert (((has_deriv_at_id x).const_mul K).exp.const_mul δ).add ((((has_deriv_at_id x).const_mul K).exp.sub_const 1).const_mul (ε / K)) using 1, simp only [id, mul_add, (mul_assoc _ _ _).symm, mul_comm _ K, mul_div_cancel' _ hK], ring } end lemma has_deriv_at_gronwall_bound_shift (δ K ε x a : ℝ) : has_deriv_at (λ y, gronwall_bound δ K ε (y - a)) (K * (gronwall_bound δ K ε (x - a)) + ε) x := begin convert (has_deriv_at_gronwall_bound δ K ε _).comp x ((has_deriv_at_id x).sub_const a), rw [id, mul_one] end lemma gronwall_bound_x0 (δ K ε : ℝ) : gronwall_bound δ K ε 0 = δ := begin by_cases hK : K = 0, { simp only [gronwall_bound, if_pos hK, mul_zero, add_zero] }, { simp only [gronwall_bound, if_neg hK, mul_zero, exp_zero, sub_self, mul_one, add_zero] } end lemma gronwall_bound_ε0 (δ K x : ℝ) : gronwall_bound δ K 0 x = δ * exp (K * x) := begin by_cases hK : K = 0, { simp only [gronwall_bound_K0, hK, zero_mul, exp_zero, add_zero, mul_one] }, { simp only [gronwall_bound_of_K_ne_0 hK, zero_div, zero_mul, add_zero] } end lemma gronwall_bound_ε0_δ0 (K x : ℝ) : gronwall_bound 0 K 0 x = 0 := by simp only [gronwall_bound_ε0, zero_mul] lemma gronwall_bound_continuous_ε (δ K x : ℝ) : continuous (λ ε, gronwall_bound δ K ε x) := begin by_cases hK : K = 0, { simp only [gronwall_bound_K0, hK], exact continuous_const.add (continuous_id.mul continuous_const) }, { simp only [gronwall_bound_of_K_ne_0 hK], exact continuous_const.add ((continuous_id.mul continuous_const).mul continuous_const) } end /-! ### Inequality and corollaries -/ /-- A Grönwall-like inequality: if `f : ℝ → ℝ` is continuous on `[a, b]` and satisfies the inequalities `f a ≤ δ` and `∀ x ∈ [a, b), liminf_{z→x+0} (f z - f x)/(z - x) ≤ K * (f x) + ε`, then `f x` is bounded by `gronwall_bound δ K ε (x - a)` on `[a, b]`. See also `norm_le_gronwall_bound_of_norm_deriv_right_le` for a version bounding `‖f x‖`, `f : ℝ → E`. -/ theorem le_gronwall_bound_of_liminf_deriv_right_le {f f' : ℝ → ℝ} {δ K ε : ℝ} {a b : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ x ∈ Ico a b, ∀ r, f' x < r → ∃ᶠ z in 𝓝[>] x, (z - x)⁻¹ * (f z - f x) < r) (ha : f a ≤ δ) (bound : ∀ x ∈ Ico a b, f' x ≤ K * f x + ε) : ∀ x ∈ Icc a b, f x ≤ gronwall_bound δ K ε (x - a) := begin have H : ∀ x ∈ Icc a b, ∀ ε' ∈ Ioi ε, f x ≤ gronwall_bound δ K ε' (x - a), { assume x hx ε' hε', apply image_le_of_liminf_slope_right_lt_deriv_boundary hf hf', { rwa [sub_self, gronwall_bound_x0] }, { exact λ x, has_deriv_at_gronwall_bound_shift δ K ε' x a }, { assume x hx hfB, rw [← hfB], apply lt_of_le_of_lt (bound x hx), exact add_lt_add_left hε' _ }, { exact hx } }, assume x hx, change f x ≤ (λ ε', gronwall_bound δ K ε' (x - a)) ε, convert continuous_within_at_const.closure_le _ _ (H x hx), { simp only [closure_Ioi, left_mem_Ici] }, exact (gronwall_bound_continuous_ε δ K (x - a)).continuous_within_at end /-- A Grönwall-like inequality: if `f : ℝ → E` is continuous on `[a, b]`, has right derivative `f' x` at every point `x ∈ [a, b)`, and satisfies the inequalities `‖f a‖ ≤ δ`, `∀ x ∈ [a, b), ‖f' x‖ ≤ K * ‖f x‖ + ε`, then `‖f x‖` is bounded by `gronwall_bound δ K ε (x - a)` on `[a, b]`. -/ theorem norm_le_gronwall_bound_of_norm_deriv_right_le {f f' : ℝ → E} {δ K ε : ℝ} {a b : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ x ∈ Ico a b, has_deriv_within_at f (f' x) (Ici x) x) (ha : ‖f a‖ ≤ δ) (bound : ∀ x ∈ Ico a b, ‖f' x‖ ≤ K * ‖f x‖ + ε) : ∀ x ∈ Icc a b, ‖f x‖ ≤ gronwall_bound δ K ε (x - a) := le_gronwall_bound_of_liminf_deriv_right_le (continuous_norm.comp_continuous_on hf) (λ x hx r hr, (hf' x hx).liminf_right_slope_norm_le hr) ha bound /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_approx_trajectories_ODE_of_mem_set {v : ℝ → E → E} {s : ℝ → set E} {K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y) {f g f' g' : ℝ → E} {a b : ℝ} {εf εg δ : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwall_bound δ K (εf + εg) (t - a) := begin simp only [dist_eq_norm] at ha ⊢, have h_deriv : ∀ t ∈ Ico a b, has_deriv_within_at (λ t, f t - g t) (f' t - g' t) (Ici t) t, from λ t ht, (hf' t ht).sub (hg' t ht), apply norm_le_gronwall_bound_of_norm_deriv_right_le (hf.sub hg) h_deriv ha, assume t ht, have := dist_triangle4_right (f' t) (g' t) (v t (f t)) (v t (g t)), rw [dist_eq_norm] at this, refine this.trans ((add_le_add (add_le_add (f_bound t ht) (g_bound t ht)) (hv t (f t) (hfs t ht) (g t) (hgs t ht))).trans _), rw [dist_eq_norm, add_comm] end /-- If `f` and `g` are two approximate solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_approx_trajectories_ODE {v : ℝ → E → E} {K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t)) {f g f' g' : ℝ → E} {a b : ℝ} {εf εg δ : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (f' t) (Ici t) t) (f_bound : ∀ t ∈ Ico a b, dist (f' t) (v t (f t)) ≤ εf) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (g' t) (Ici t) t) (g_bound : ∀ t ∈ Ico a b, dist (g' t) (v t (g t)) ≤ εg) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ gronwall_bound δ K (εf + εg) (t - a) := have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial, dist_le_of_approx_trajectories_ODE_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y) hf hf' f_bound hfs hg hg' g_bound (λ t ht, trivial) ha /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in some time-dependent set `s t`, and assumes that the solutions never leave this set. -/ theorem dist_le_of_trajectories_ODE_of_mem_set {v : ℝ → E → E} {s : ℝ → set E} {K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y) {f g : ℝ → E} {a b : ℝ} {δ : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) := begin have f_bound : ∀ t ∈ Ico a b, dist (v t (f t)) (v t (f t)) ≤ 0, by { intros, rw [dist_self] }, have g_bound : ∀ t ∈ Ico a b, dist (v t (g t)) (v t (g t)) ≤ 0, by { intros, rw [dist_self] }, assume t ht, have := dist_le_of_approx_trajectories_ODE_of_mem_set hv hf hf' f_bound hfs hg hg' g_bound hgs ha t ht, rwa [zero_add, gronwall_bound_ε0] at this, end /-- If `f` and `g` are two exact solutions of the same ODE, then the distance between them can't grow faster than exponentially. This is a simple corollary of Grönwall's inequality, and some people call this Grönwall's inequality too. This version assumes all inequalities to be true in the whole space. -/ theorem dist_le_of_trajectories_ODE {v : ℝ → E → E} {K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t)) {f g : ℝ → E} {a b : ℝ} {δ : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t) (ha : dist (f a) (g a) ≤ δ) : ∀ t ∈ Icc a b, dist (f t) (g t) ≤ δ * exp (K * (t - a)) := have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial, dist_le_of_trajectories_ODE_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y) hf hf' hfs hg hg' (λ t ht, trivial) ha /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) in a set `s ⊆ ℝ × E` with a given initial value provided that RHS is Lipschitz continuous in `x` within `s`, and we consider only solutions included in `s`. -/ theorem ODE_solution_unique_of_mem_set {v : ℝ → E → E} {s : ℝ → set E} {K : ℝ} (hv : ∀ t, ∀ x y ∈ s t, dist (v t x) (v t y) ≤ K * dist x y) {f g : ℝ → E} {a b : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t) (hfs : ∀ t ∈ Ico a b, f t ∈ s t) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t) (hgs : ∀ t ∈ Ico a b, g t ∈ s t) (ha : f a = g a) : ∀ t ∈ Icc a b, f t = g t := begin assume t ht, have := dist_le_of_trajectories_ODE_of_mem_set hv hf hf' hfs hg hg' hgs (dist_le_zero.2 ha) t ht, rwa [zero_mul, dist_le_zero] at this end /-- There exists only one solution of an ODE \(\dot x=v(t, x)\) with a given initial value provided that RHS is Lipschitz continuous in `x`. -/ theorem ODE_solution_unique {v : ℝ → E → E} {K : ℝ≥0} (hv : ∀ t, lipschitz_with K (v t)) {f g : ℝ → E} {a b : ℝ} (hf : continuous_on f (Icc a b)) (hf' : ∀ t ∈ Ico a b, has_deriv_within_at f (v t (f t)) (Ici t) t) (hg : continuous_on g (Icc a b)) (hg' : ∀ t ∈ Ico a b, has_deriv_within_at g (v t (g t)) (Ici t) t) (ha : f a = g a) : ∀ t ∈ Icc a b, f t = g t := have hfs : ∀ t ∈ Ico a b, f t ∈ (@univ E), from λ t ht, trivial, ODE_solution_unique_of_mem_set (λ t x hx y hy, (hv t).dist_le_mul x y) hf hf' hfs hg hg' (λ t ht, trivial) ha
785953f5c328c33f01d6310951b85ec542045383
9be442d9ec2fcf442516ed6e9e1660aa9071b7bd
/src/Lean/ParserCompiler/Attribute.lean
150fe0af8a41bc60f1f605eba11886809421b736
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
EdAyers/lean4
57ac632d6b0789cb91fab2170e8c9e40441221bd
37ba0df5841bde51dbc2329da81ac23d4f6a4de4
refs/heads/master
1,676,463,245,298
1,660,619,433,000
1,660,619,433,000
183,433,437
1
0
Apache-2.0
1,657,612,672,000
1,556,196,574,000
Lean
UTF-8
Lean
false
false
1,972
lean
/- Copyright (c) 2020 Sebastian Ullrich. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura, Sebastian Ullrich -/ import Lean.Attributes import Lean.Compiler.InitAttr import Lean.ToExpr namespace Lean namespace ParserCompiler structure CombinatorAttribute where impl : AttributeImpl ext : SimplePersistentEnvExtension (Name × Name) (NameMap Name) deriving Inhabited -- TODO(Sebastian): We'll probably want priority support here at some point def registerCombinatorAttribute (name : Name) (descr : String) : IO CombinatorAttribute := do let ext : SimplePersistentEnvExtension (Name × Name) (NameMap Name) ← registerSimplePersistentEnvExtension { name := name, addImportedFn := mkStateFromImportedEntries (fun s p => s.insert p.1 p.2) {}, addEntryFn := fun (s : NameMap Name) (p : Name × Name) => s.insert p.1 p.2, } let attrImpl : AttributeImpl := { name := name, descr := descr, add := fun decl stx _ => do let env ← getEnv let parserDeclName ← Attribute.Builtin.getId stx discard <| getConstInfo parserDeclName setEnv <| ext.addEntry env (parserDeclName, decl) } registerBuiltinAttribute attrImpl pure { impl := attrImpl, ext := ext } namespace CombinatorAttribute def getDeclFor? (attr : CombinatorAttribute) (env : Environment) (parserDecl : Name) : Option Name := (attr.ext.getState env).find? parserDecl def setDeclFor (attr : CombinatorAttribute) (env : Environment) (parserDecl : Name) (decl : Name) : Environment := attr.ext.addEntry env (parserDecl, decl) unsafe def runDeclFor {α} (attr : CombinatorAttribute) (parserDecl : Name) : CoreM α := do match attr.getDeclFor? (← getEnv) parserDecl with | some d => evalConst α d | _ => throwError "no declaration of attribute [{attr.impl.name}] found for '{parserDecl}'" end CombinatorAttribute end ParserCompiler end Lean
1fb02a618803387a5a2d231fe5d666ea2cf57c6a
2c096fdfecf64e46ea7bc6ce5521f142b5926864
/src/Init/Data/Nat/Basic.lean
2b676b596883fadb4bdb9637789091fe62c1088e
[ "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
Kha/lean4
1005785d2c8797ae266a303968848e5f6ce2fe87
b99e11346948023cd6c29d248cd8f3e3fb3474cf
refs/heads/master
1,693,355,498,027
1,669,080,461,000
1,669,113,138,000
184,748,176
0
0
Apache-2.0
1,665,995,520,000
1,556,884,930,000
Lean
UTF-8
Lean
false
false
28,191
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn, Leonardo de Moura -/ prelude import Init.SimpLemmas set_option linter.missingDocs true -- keep it documented universe u namespace Nat /-- `Nat.fold` evaluates `f` on the numbers up to `n` exclusive, in increasing order: * `Nat.fold f 3 init = init |> f 0 |> f 1 |> f 2` -/ @[specialize] def fold {α : Type u} (f : Nat → α → α) : (n : Nat) → (init : α) → α | 0, a => a | succ n, a => f n (fold f n a) /-- Tail-recursive version of `Nat.fold`. -/ @[inline] def foldTR {α : Type u} (f : Nat → α → α) (n : Nat) (init : α) : α := let rec @[specialize] loop | 0, a => a | succ m, a => loop m (f (n - succ m) a) loop n init /-- `Nat.foldRev` evaluates `f` on the numbers up to `n` exclusive, in decreasing order: * `Nat.foldRev f 3 init = f 0 <| f 1 <| f 2 <| init` -/ @[specialize] def foldRev {α : Type u} (f : Nat → α → α) : (n : Nat) → (init : α) → α | 0, a => a | succ n, a => foldRev f n (f n a) /-- `any f n = true` iff there is `i in [0, n-1]` s.t. `f i = true` -/ @[specialize] def any (f : Nat → Bool) : Nat → Bool | 0 => false | succ n => any f n || f n /-- Tail-recursive version of `Nat.any`. -/ @[inline] def anyTR (f : Nat → Bool) (n : Nat) : Bool := let rec @[specialize] loop : Nat → Bool | 0 => false | succ m => f (n - succ m) || loop m loop n /-- `all f n = true` iff every `i in [0, n-1]` satisfies `f i = true` -/ @[specialize] def all (f : Nat → Bool) : Nat → Bool | 0 => true | succ n => all f n && f n /-- Tail-recursive version of `Nat.all`. -/ @[inline] def allTR (f : Nat → Bool) (n : Nat) : Bool := let rec @[specialize] loop : Nat → Bool | 0 => true | succ m => f (n - succ m) && loop m loop n /-- `Nat.repeat f n a` is `f^(n) a`; that is, it iterates `f` `n` times on `a`. * `Nat.repeat f 3 a = f <| f <| f <| a` -/ @[specialize] def repeat {α : Type u} (f : α → α) : (n : Nat) → (a : α) → α | 0, a => a | succ n, a => f (repeat f n a) /-- Tail-recursive version of `Nat.repeat`. -/ @[inline] def repeatTR {α : Type u} (f : α → α) (n : Nat) (a : α) : α := let rec @[specialize] loop | 0, a => a | succ n, a => loop n (f a) loop n a /-- Boolean less-than of natural numbers. -/ def blt (a b : Nat) : Bool := ble a.succ b attribute [simp] Nat.zero_le /-! # Helper "packing" theorems -/ @[simp] theorem zero_eq : Nat.zero = 0 := rfl @[simp] theorem add_eq : Nat.add x y = x + y := rfl @[simp] theorem mul_eq : Nat.mul x y = x * y := rfl @[simp] theorem sub_eq : Nat.sub x y = x - y := rfl @[simp] theorem lt_eq : Nat.lt x y = (x < y) := rfl @[simp] theorem le_eq : Nat.le x y = (x ≤ y) := rfl /-! # Helper Bool relation theorems -/ @[simp] theorem beq_refl (a : Nat) : Nat.beq a a = true := by induction a with simp [Nat.beq] | succ a ih => simp [ih] @[simp] theorem beq_eq : (Nat.beq x y = true) = (x = y) := propext <| Iff.intro Nat.eq_of_beq_eq_true (fun h => h ▸ (Nat.beq_refl x)) @[simp] theorem ble_eq : (Nat.ble x y = true) = (x ≤ y) := propext <| Iff.intro Nat.le_of_ble_eq_true Nat.ble_eq_true_of_le @[simp] theorem blt_eq : (Nat.blt x y = true) = (x < y) := propext <| Iff.intro Nat.le_of_ble_eq_true Nat.ble_eq_true_of_le instance : LawfulBEq Nat where eq_of_beq h := Nat.eq_of_beq_eq_true h rfl := by simp [BEq.beq] @[simp] theorem beq_eq_true_eq (a b : Nat) : ((a == b) = true) = (a = b) := propext <| Iff.intro eq_of_beq (fun h => by subst h; apply LawfulBEq.rfl) @[simp] theorem not_beq_eq_true_eq (a b : Nat) : ((!(a == b)) = true) = ¬(a = b) := propext <| Iff.intro (fun h₁ h₂ => by subst h₂; rw [LawfulBEq.rfl] at h₁; contradiction) (fun h => have : ¬ ((a == b) = true) := fun h' => absurd (eq_of_beq h') h by simp [this]) /-! # Nat.add theorems -/ @[simp] protected theorem zero_add : ∀ (n : Nat), 0 + n = n | 0 => rfl | n+1 => congrArg succ (Nat.zero_add n) theorem succ_add : ∀ (n m : Nat), (succ n) + m = succ (n + m) | _, 0 => rfl | n, m+1 => congrArg succ (succ_add n m) theorem add_succ (n m : Nat) : n + succ m = succ (n + m) := rfl theorem add_one (n : Nat) : n + 1 = succ n := rfl theorem succ_eq_add_one (n : Nat) : succ n = n + 1 := rfl protected theorem add_comm : ∀ (n m : Nat), n + m = m + n | n, 0 => Eq.symm (Nat.zero_add n) | n, m+1 => by have : succ (n + m) = succ (m + n) := by apply congrArg; apply Nat.add_comm rw [succ_add m n] apply this protected theorem add_assoc : ∀ (n m k : Nat), (n + m) + k = n + (m + k) | _, _, 0 => rfl | n, m, succ k => congrArg succ (Nat.add_assoc n m k) protected theorem add_left_comm (n m k : Nat) : n + (m + k) = m + (n + k) := by rw [← Nat.add_assoc, Nat.add_comm n m, Nat.add_assoc] protected theorem add_right_comm (n m k : Nat) : (n + m) + k = (n + k) + m := by rw [Nat.add_assoc, Nat.add_comm m k, ← Nat.add_assoc] protected theorem add_left_cancel {n m k : Nat} : n + m = n + k → m = k := by induction n with | zero => simp; intros; assumption | succ n ih => simp [succ_add]; intro h; apply ih h protected theorem add_right_cancel {n m k : Nat} (h : n + m = k + m) : n = k := by rw [Nat.add_comm n m, Nat.add_comm k m] at h apply Nat.add_left_cancel h /-! # Nat.mul theorems -/ @[simp] protected theorem mul_zero (n : Nat) : n * 0 = 0 := rfl theorem mul_succ (n m : Nat) : n * succ m = n * m + n := rfl @[simp] protected theorem zero_mul : ∀ (n : Nat), 0 * n = 0 | 0 => rfl | succ n => mul_succ 0 n ▸ (Nat.zero_mul n).symm ▸ rfl theorem succ_mul (n m : Nat) : (succ n) * m = (n * m) + m := by induction m with | zero => rfl | succ m ih => rw [mul_succ, add_succ, ih, mul_succ, add_succ, Nat.add_right_comm] protected theorem mul_comm : ∀ (n m : Nat), n * m = m * n | n, 0 => (Nat.zero_mul n).symm ▸ (Nat.mul_zero n).symm ▸ rfl | n, succ m => (mul_succ n m).symm ▸ (succ_mul m n).symm ▸ (Nat.mul_comm n m).symm ▸ rfl @[simp] protected theorem mul_one : ∀ (n : Nat), n * 1 = n := Nat.zero_add @[simp] protected theorem one_mul (n : Nat) : 1 * n = n := Nat.mul_comm n 1 ▸ Nat.mul_one n protected theorem left_distrib (n m k : Nat) : n * (m + k) = n * m + n * k := by induction n generalizing m k with | zero => repeat rw [Nat.zero_mul] | succ n ih => simp [succ_mul, ih]; rw [Nat.add_assoc, Nat.add_assoc (n*m)]; apply congrArg; apply Nat.add_left_comm protected theorem right_distrib (n m k : Nat) : (n + m) * k = n * k + m * k := by rw [Nat.mul_comm, Nat.left_distrib]; simp [Nat.mul_comm] protected theorem mul_add (n m k : Nat) : n * (m + k) = n * m + n * k := Nat.left_distrib n m k protected theorem add_mul (n m k : Nat) : (n + m) * k = n * k + m * k := Nat.right_distrib n m k protected theorem mul_assoc : ∀ (n m k : Nat), (n * m) * k = n * (m * k) | n, m, 0 => rfl | n, m, succ k => by simp [mul_succ, Nat.mul_assoc n m k, Nat.left_distrib] protected theorem mul_left_comm (n m k : Nat) : n * (m * k) = m * (n * k) := by rw [← Nat.mul_assoc, Nat.mul_comm n m, Nat.mul_assoc] /-! # Inequalities -/ attribute [simp] Nat.le_refl theorem succ_lt_succ {n m : Nat} : n < m → succ n < succ m := succ_le_succ theorem lt_succ_of_le {n m : Nat} : n ≤ m → n < succ m := succ_le_succ @[simp] protected theorem sub_zero (n : Nat) : n - 0 = n := rfl theorem succ_sub_succ_eq_sub (n m : Nat) : succ n - succ m = n - m := by induction m with | zero => exact rfl | succ m ih => apply congrArg pred ih theorem pred_le : ∀ (n : Nat), pred n ≤ n | zero => Nat.le.refl | succ _ => le_succ _ theorem pred_lt : ∀ {n : Nat}, n ≠ 0 → pred n < n | zero, h => absurd rfl h | succ _, _ => lt_succ_of_le (Nat.le_refl _) theorem sub_le (n m : Nat) : n - m ≤ n := by induction m with | zero => exact Nat.le_refl (n - 0) | succ m ih => apply Nat.le_trans (pred_le (n - m)) ih theorem sub_lt : ∀ {n m : Nat}, 0 < n → 0 < m → n - m < n | 0, _, h1, _ => absurd h1 (Nat.lt_irrefl 0) | _+1, 0, _, h2 => absurd h2 (Nat.lt_irrefl 0) | n+1, m+1, _, _ => Eq.symm (succ_sub_succ_eq_sub n m) ▸ show n - m < succ n from lt_succ_of_le (sub_le n m) theorem sub_succ (n m : Nat) : n - succ m = pred (n - m) := rfl theorem succ_sub_succ (n m : Nat) : succ n - succ m = n - m := succ_sub_succ_eq_sub n m @[simp] protected theorem sub_self : ∀ (n : Nat), n - n = 0 | 0 => by rw [Nat.sub_zero] | (succ n) => by rw [succ_sub_succ, Nat.sub_self n] theorem sub_add_eq (a b c : Nat) : a - (b + c) = a - b - c := by induction c with | zero => simp | succ c ih => simp [Nat.add_succ, Nat.sub_succ, ih] protected theorem lt_of_lt_of_le {n m k : Nat} : n < m → m ≤ k → n < k := Nat.le_trans protected theorem lt_of_lt_of_eq {n m k : Nat} : n < m → m = k → n < k := fun h₁ h₂ => h₂ ▸ h₁ instance : Trans (. < . : Nat → Nat → Prop) (. < . : Nat → Nat → Prop) (. < . : Nat → Nat → Prop) where trans := Nat.lt_trans instance : Trans (. ≤ . : Nat → Nat → Prop) (. ≤ . : Nat → Nat → Prop) (. ≤ . : Nat → Nat → Prop) where trans := Nat.le_trans instance : Trans (. < . : Nat → Nat → Prop) (. ≤ . : Nat → Nat → Prop) (. < . : Nat → Nat → Prop) where trans := Nat.lt_of_lt_of_le instance : Trans (. ≤ . : Nat → Nat → Prop) (. < . : Nat → Nat → Prop) (. < . : Nat → Nat → Prop) where trans := Nat.lt_of_le_of_lt protected theorem le_of_eq {n m : Nat} (p : n = m) : n ≤ m := p ▸ Nat.le_refl n theorem le_of_succ_le {n m : Nat} (h : succ n ≤ m) : n ≤ m := Nat.le_trans (le_succ n) h protected theorem le_of_lt {n m : Nat} (h : n < m) : n ≤ m := le_of_succ_le h theorem lt.step {n m : Nat} : n < m → n < succ m := le_step theorem eq_zero_or_pos : ∀ (n : Nat), n = 0 ∨ n > 0 | 0 => Or.inl rfl | _+1 => Or.inr (succ_pos _) theorem lt.base (n : Nat) : n < succ n := Nat.le_refl (succ n) theorem lt_succ_self (n : Nat) : n < succ n := lt.base n protected theorem le_total (m n : Nat) : m ≤ n ∨ n ≤ m := match Nat.lt_or_ge m n with | Or.inl h => Or.inl (Nat.le_of_lt h) | Or.inr h => Or.inr h theorem eq_zero_of_le_zero {n : Nat} (h : n ≤ 0) : n = 0 := Nat.le_antisymm h (zero_le _) theorem lt_of_succ_lt {n m : Nat} : succ n < m → n < m := le_of_succ_le theorem lt_of_succ_lt_succ {n m : Nat} : succ n < succ m → n < m := le_of_succ_le_succ theorem lt_of_succ_le {n m : Nat} (h : succ n ≤ m) : n < m := h theorem succ_le_of_lt {n m : Nat} (h : n < m) : succ n ≤ m := h theorem zero_lt_of_lt : {a b : Nat} → a < b → 0 < b | 0, _, h => h | a+1, b, h => have : a < b := Nat.lt_trans (Nat.lt_succ_self _) h zero_lt_of_lt this theorem zero_lt_of_ne_zero {a : Nat} (h : a ≠ 0) : 0 < a := by match a with | 0 => contradiction | a+1 => apply Nat.zero_lt_succ attribute [simp] Nat.lt_irrefl theorem ne_of_lt {a b : Nat} (h : a < b) : a ≠ b := fun he => absurd (he ▸ h) (Nat.lt_irrefl a) theorem le_or_eq_or_le_succ {m n : Nat} (h : m ≤ succ n) : m ≤ n ∨ m = succ n := Decidable.byCases (fun (h' : m = succ n) => Or.inr h') (fun (h' : m ≠ succ n) => have : m < succ n := Nat.lt_of_le_of_ne h h' have : succ m ≤ succ n := succ_le_of_lt this Or.inl (le_of_succ_le_succ this)) theorem le_add_right : ∀ (n k : Nat), n ≤ n + k | n, 0 => Nat.le_refl n | n, k+1 => le_succ_of_le (le_add_right n k) theorem le_add_left (n m : Nat): n ≤ m + n := Nat.add_comm n m ▸ le_add_right n m theorem le.dest : ∀ {n m : Nat}, n ≤ m → Exists (fun k => n + k = m) | zero, zero, _ => ⟨0, rfl⟩ | zero, succ n, _ => ⟨succ n, Nat.add_comm 0 (succ n) ▸ rfl⟩ | succ _, zero, h => absurd h (not_succ_le_zero _) | succ n, succ m, h => have : n ≤ m := Nat.le_of_succ_le_succ h have : Exists (fun k => n + k = m) := dest this match this with | ⟨k, h⟩ => ⟨k, show succ n + k = succ m from ((succ_add n k).symm ▸ h ▸ rfl)⟩ theorem le.intro {n m k : Nat} (h : n + k = m) : n ≤ m := h ▸ le_add_right n k protected theorem not_le_of_gt {n m : Nat} (h : n > m) : ¬ n ≤ m := fun h₁ => match Nat.lt_or_ge n m with | Or.inl h₂ => absurd (Nat.lt_trans h h₂) (Nat.lt_irrefl _) | Or.inr h₂ => have Heq : n = m := Nat.le_antisymm h₁ h₂ absurd (@Eq.subst _ _ _ _ Heq h) (Nat.lt_irrefl m) theorem gt_of_not_le {n m : Nat} (h : ¬ n ≤ m) : n > m := match Nat.lt_or_ge m n with | Or.inl h₁ => h₁ | Or.inr h₁ => absurd h₁ h theorem ge_of_not_lt {n m : Nat} (h : ¬ n < m) : n ≥ m := match Nat.lt_or_ge n m with | Or.inl h₁ => absurd h₁ h | Or.inr h₁ => h₁ instance : Antisymm ( . ≤ . : Nat → Nat → Prop) where antisymm h₁ h₂ := Nat.le_antisymm h₁ h₂ instance : Antisymm (¬ . < . : Nat → Nat → Prop) where antisymm h₁ h₂ := Nat.le_antisymm (Nat.ge_of_not_lt h₂) (Nat.ge_of_not_lt h₁) protected theorem add_le_add_left {n m : Nat} (h : n ≤ m) (k : Nat) : k + n ≤ k + m := match le.dest h with | ⟨w, hw⟩ => have h₁ : k + n + w = k + (n + w) := Nat.add_assoc .. have h₂ : k + (n + w) = k + m := congrArg _ hw le.intro <| h₁.trans h₂ protected theorem add_le_add_right {n m : Nat} (h : n ≤ m) (k : Nat) : n + k ≤ m + k := by rw [Nat.add_comm n k, Nat.add_comm m k] apply Nat.add_le_add_left assumption protected theorem add_lt_add_left {n m : Nat} (h : n < m) (k : Nat) : k + n < k + m := lt_of_succ_le (add_succ k n ▸ Nat.add_le_add_left (succ_le_of_lt h) k) protected theorem add_lt_add_right {n m : Nat} (h : n < m) (k : Nat) : n + k < m + k := Nat.add_comm k m ▸ Nat.add_comm k n ▸ Nat.add_lt_add_left h k protected theorem zero_lt_one : 0 < (1:Nat) := zero_lt_succ 0 theorem add_le_add {a b c d : Nat} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d := Nat.le_trans (Nat.add_le_add_right h₁ c) (Nat.add_le_add_left h₂ b) theorem add_lt_add {a b c d : Nat} (h₁ : a < b) (h₂ : c < d) : a + c < b + d := Nat.lt_trans (Nat.add_lt_add_right h₁ c) (Nat.add_lt_add_left h₂ b) protected theorem le_of_add_le_add_left {a b c : Nat} (h : a + b ≤ a + c) : b ≤ c := by match le.dest h with | ⟨d, hd⟩ => apply @le.intro _ _ d rw [Nat.add_assoc] at hd apply Nat.add_left_cancel hd protected theorem le_of_add_le_add_right {a b c : Nat} : a + b ≤ c + b → a ≤ c := by rw [Nat.add_comm _ b, Nat.add_comm _ b] apply Nat.le_of_add_le_add_left /-! # Basic theorems for comparing numerals -/ theorem ctor_eq_zero : Nat.zero = 0 := rfl protected theorem one_ne_zero : 1 ≠ (0 : Nat) := fun h => Nat.noConfusion h protected theorem zero_ne_one : 0 ≠ (1 : Nat) := fun h => Nat.noConfusion h theorem succ_ne_zero (n : Nat) : succ n ≠ 0 := fun h => Nat.noConfusion h /-! # mul + order -/ theorem mul_le_mul_left {n m : Nat} (k : Nat) (h : n ≤ m) : k * n ≤ k * m := match le.dest h with | ⟨l, hl⟩ => have : k * n + k * l = k * m := Nat.left_distrib k n l ▸ hl.symm ▸ rfl le.intro this theorem mul_le_mul_right {n m : Nat} (k : Nat) (h : n ≤ m) : n * k ≤ m * k := Nat.mul_comm k m ▸ Nat.mul_comm k n ▸ mul_le_mul_left k h protected theorem mul_le_mul {n₁ m₁ n₂ m₂ : Nat} (h₁ : n₁ ≤ n₂) (h₂ : m₁ ≤ m₂) : n₁ * m₁ ≤ n₂ * m₂ := Nat.le_trans (mul_le_mul_right _ h₁) (mul_le_mul_left _ h₂) protected theorem mul_lt_mul_of_pos_left {n m k : Nat} (h : n < m) (hk : k > 0) : k * n < k * m := Nat.lt_of_lt_of_le (Nat.add_lt_add_left hk _) (Nat.mul_succ k n ▸ Nat.mul_le_mul_left k (succ_le_of_lt h)) protected theorem mul_lt_mul_of_pos_right {n m k : Nat} (h : n < m) (hk : k > 0) : n * k < m * k := Nat.mul_comm k m ▸ Nat.mul_comm k n ▸ Nat.mul_lt_mul_of_pos_left h hk protected theorem mul_pos {n m : Nat} (ha : n > 0) (hb : m > 0) : n * m > 0 := have h : 0 * m < n * m := Nat.mul_lt_mul_of_pos_right ha hb Nat.zero_mul m ▸ h protected theorem le_of_mul_le_mul_left {a b c : Nat} (h : c * a ≤ c * b) (hc : 0 < c) : a ≤ b := Nat.ge_of_not_lt fun hlt : b < a => have h' : c * b < c * a := Nat.mul_lt_mul_of_pos_left hlt hc absurd h (Nat.not_le_of_gt h') protected theorem eq_of_mul_eq_mul_left {m k n : Nat} (hn : 0 < n) (h : n * m = n * k) : m = k := Nat.le_antisymm (Nat.le_of_mul_le_mul_left (Nat.le_of_eq h) hn) (Nat.le_of_mul_le_mul_left (Nat.le_of_eq h.symm) hn) theorem eq_of_mul_eq_mul_right {n m k : Nat} (hm : 0 < m) (h : n * m = k * m) : n = k := by rw [Nat.mul_comm n m, Nat.mul_comm k m] at h; exact Nat.eq_of_mul_eq_mul_left hm h /-! # power -/ theorem pow_succ (n m : Nat) : n^(succ m) = n^m * n := rfl theorem pow_zero (n : Nat) : n^0 = 1 := rfl theorem pow_le_pow_of_le_left {n m : Nat} (h : n ≤ m) : ∀ (i : Nat), n^i ≤ m^i | 0 => Nat.le_refl _ | succ i => Nat.mul_le_mul (pow_le_pow_of_le_left h i) h theorem pow_le_pow_of_le_right {n : Nat} (hx : n > 0) {i : Nat} : ∀ {j}, i ≤ j → n^i ≤ n^j | 0, h => have : i = 0 := eq_zero_of_le_zero h this.symm ▸ Nat.le_refl _ | succ j, h => match le_or_eq_or_le_succ h with | Or.inl h => show n^i ≤ n^j * n from have : n^i * 1 ≤ n^j * n := Nat.mul_le_mul (pow_le_pow_of_le_right hx h) hx Nat.mul_one (n^i) ▸ this | Or.inr h => h.symm ▸ Nat.le_refl _ theorem pos_pow_of_pos {n : Nat} (m : Nat) (h : 0 < n) : 0 < n^m := pow_le_pow_of_le_right h (Nat.zero_le _) /-! # min/max -/ instance : Min Nat := minOfLe /-- `Nat.min a b` is the minimum of `a` and `b`: * if `a ≤ b` then `Nat.min a b = a` * if `b ≤ a` then `Nat.min a b = b` -/ protected abbrev min (n m : Nat) := min n m protected theorem min_def {n m : Nat} : min n m = if n ≤ m then n else m := rfl instance : Max Nat := maxOfLe /-- `Nat.max a b` is the maximum of `a` and `b`: * if `a ≤ b` then `Nat.max a b = b` * if `b ≤ a` then `Nat.max a b = a` -/ protected abbrev max (n m : Nat) := max n m protected theorem max_def {n m : Nat} : max n m = if n ≤ m then m else n := rfl /-! # Auxiliary theorems for well-founded recursion -/ theorem not_eq_zero_of_lt (h : b < a) : a ≠ 0 := by cases a exact absurd h (Nat.not_lt_zero _) apply Nat.noConfusion theorem pred_lt' {n m : Nat} (h : m < n) : pred n < n := pred_lt (not_eq_zero_of_lt h) /-! # sub/pred theorems -/ theorem add_sub_self_left (a b : Nat) : (a + b) - a = b := by induction a with | zero => simp | succ a ih => rw [Nat.succ_add, Nat.succ_sub_succ] apply ih theorem add_sub_self_right (a b : Nat) : (a + b) - b = a := by rw [Nat.add_comm]; apply add_sub_self_left theorem sub_le_succ_sub (a i : Nat) : a - i ≤ a.succ - i := by cases i with | zero => apply Nat.le_of_lt; apply Nat.lt_succ_self | succ i => rw [Nat.sub_succ, Nat.succ_sub_succ]; apply Nat.pred_le theorem zero_lt_sub_of_lt (h : i < a) : 0 < a - i := by induction a with | zero => contradiction | succ a ih => match Nat.eq_or_lt_of_le h with | Or.inl h => injection h with h; subst h; rw [←Nat.add_one, Nat.add_sub_self_left]; decide | Or.inr h => have : 0 < a - i := ih (Nat.lt_of_succ_lt_succ h) exact Nat.lt_of_lt_of_le this (Nat.sub_le_succ_sub _ _) theorem sub_succ_lt_self (a i : Nat) (h : i < a) : a - (i + 1) < a - i := by rw [Nat.add_succ, Nat.sub_succ] apply Nat.pred_lt apply Nat.not_eq_zero_of_lt apply Nat.zero_lt_sub_of_lt assumption theorem succ_pred {a : Nat} (h : a ≠ 0) : a.pred.succ = a := by induction a with | zero => contradiction | succ => rfl theorem sub_ne_zero_of_lt : {a b : Nat} → a < b → b - a ≠ 0 | 0, 0, h => absurd h (Nat.lt_irrefl 0) | 0, succ b, _ => by simp | succ a, 0, h => absurd h (Nat.not_lt_zero a.succ) | succ a, succ b, h => by rw [Nat.succ_sub_succ]; exact sub_ne_zero_of_lt (Nat.lt_of_succ_lt_succ h) theorem add_sub_of_le {a b : Nat} (h : a ≤ b) : a + (b - a) = b := by induction a with | zero => simp | succ a ih => have hne : b - a ≠ 0 := Nat.sub_ne_zero_of_lt h have : a ≤ b := Nat.le_of_succ_le h rw [sub_succ, Nat.succ_add, ← Nat.add_succ, Nat.succ_pred hne, ih this] protected theorem sub_add_cancel {n m : Nat} (h : m ≤ n) : n - m + m = n := by rw [Nat.add_comm, Nat.add_sub_of_le h] protected theorem add_sub_add_right (n k m : Nat) : (n + k) - (m + k) = n - m := by induction k with | zero => simp | succ k ih => simp [add_succ, add_succ, succ_sub_succ, ih] protected theorem add_sub_add_left (k n m : Nat) : (k + n) - (k + m) = n - m := by rw [Nat.add_comm k n, Nat.add_comm k m, Nat.add_sub_add_right] protected theorem add_sub_cancel (n m : Nat) : n + m - m = n := suffices n + m - (0 + m) = n by rw [Nat.zero_add] at this; assumption by rw [Nat.add_sub_add_right, Nat.sub_zero] protected theorem add_sub_cancel_left (n m : Nat) : n + m - n = m := show n + m - (n + 0) = m from by rw [Nat.add_sub_add_left, Nat.sub_zero] protected theorem add_sub_assoc {m k : Nat} (h : k ≤ m) (n : Nat) : n + m - k = n + (m - k) := by cases Nat.le.dest h rename_i l hl rw [← hl, Nat.add_sub_cancel_left, Nat.add_comm k, ← Nat.add_assoc, Nat.add_sub_cancel] protected theorem eq_add_of_sub_eq {a b c : Nat} (hle : b ≤ a) (h : a - b = c) : a = c + b := by rw [h.symm, Nat.sub_add_cancel hle] protected theorem sub_eq_of_eq_add {a b c : Nat} (h : a = c + b) : a - b = c := by rw [h, Nat.add_sub_cancel] theorem le_add_of_sub_le {a b c : Nat} (h : a - b ≤ c) : a ≤ c + b := by match le.dest h, Nat.le_total a b with | _, Or.inl hle => exact Nat.le_trans hle (Nat.le_add_left ..) | ⟨d, hd⟩, Or.inr hge => apply @le.intro _ _ d rw [Nat.add_comm, ← Nat.add_sub_assoc hge] at hd have hd := Nat.eq_add_of_sub_eq (Nat.le_trans hge (Nat.le_add_left ..)) hd rw [Nat.add_comm, hd] @[simp] protected theorem zero_sub (n : Nat) : 0 - n = 0 := by induction n with | zero => rfl | succ n ih => simp [ih, Nat.sub_succ] protected theorem sub_self_add (n m : Nat) : n - (n + m) = 0 := by show (n + 0) - (n + m) = 0 rw [Nat.add_sub_add_left, Nat.zero_sub] protected theorem sub_eq_zero_of_le {n m : Nat} (h : n ≤ m) : n - m = 0 := by match le.dest h with | ⟨k, hk⟩ => rw [← hk, Nat.sub_self_add] theorem sub_le_of_le_add {a b c : Nat} (h : a ≤ c + b) : a - b ≤ c := by match le.dest h, Nat.le_total a b with | _, Or.inl hle => rw [Nat.sub_eq_zero_of_le hle] apply Nat.zero_le | ⟨d, hd⟩, Or.inr hge => apply @le.intro _ _ d have hd := Nat.sub_eq_of_eq_add hd rw [Nat.add_comm, ← Nat.add_sub_assoc hge, Nat.add_comm] exact hd theorem add_le_of_le_sub {a b c : Nat} (hle : b ≤ c) (h : a ≤ c - b) : a + b ≤ c := by match le.dest h with | ⟨d, hd⟩ => apply @le.intro _ _ d rw [Nat.eq_add_of_sub_eq hle hd.symm] simp [Nat.add_comm, Nat.add_assoc, Nat.add_left_comm] theorem le_sub_of_add_le {a b c : Nat} (h : a + b ≤ c) : a ≤ c - b := by match le.dest h with | ⟨d, hd⟩ => apply @le.intro _ _ d have hd : a + d + b = c := by simp [← hd, Nat.add_comm, Nat.add_assoc, Nat.add_left_comm] have hd := Nat.sub_eq_of_eq_add hd.symm exact hd.symm theorem add_lt_of_lt_sub {a b c : Nat} (h : a < c - b) : a + b < c := by have hle : b ≤ c := by apply Nat.ge_of_not_lt intro hgt apply Nat.not_lt_zero a rw [Nat.sub_eq_zero_of_le (Nat.le_of_lt hgt)] at h exact h have : a.succ + b ≤ c := add_le_of_le_sub hle h simp [Nat.succ_add] at this exact this theorem lt_sub_of_add_lt {a b c : Nat} (h : a + b < c) : a < c - b := have : a.succ + b ≤ c := by simp [Nat.succ_add]; exact h le_sub_of_add_le this @[simp] protected theorem pred_zero : pred 0 = 0 := rfl @[simp] protected theorem pred_succ (n : Nat) : pred n.succ = n := rfl theorem sub.elim {motive : Nat → Prop} (x y : Nat) (h₁ : y ≤ x → (k : Nat) → x = y + k → motive k) (h₂ : x < y → motive 0) : motive (x - y) := by cases Nat.lt_or_ge x y with | inl hlt => rw [Nat.sub_eq_zero_of_le (Nat.le_of_lt hlt)]; exact h₂ hlt | inr hle => exact h₁ hle (x - y) (Nat.add_sub_of_le hle).symm theorem mul_pred_left (n m : Nat) : pred n * m = n * m - m := by cases n with | zero => simp | succ n => rw [Nat.pred_succ, succ_mul, Nat.add_sub_cancel] theorem mul_pred_right (n m : Nat) : n * pred m = n * m - n := by rw [Nat.mul_comm, mul_pred_left, Nat.mul_comm] protected theorem sub_sub (n m k : Nat) : n - m - k = n - (m + k) := by induction k with | zero => simp | succ k ih => rw [Nat.add_succ, Nat.sub_succ, Nat.sub_succ, ih] protected theorem mul_sub_right_distrib (n m k : Nat) : (n - m) * k = n * k - m * k := by induction m with | zero => simp | succ m ih => rw [Nat.sub_succ, Nat.mul_pred_left, ih, succ_mul, Nat.sub_sub]; done protected theorem mul_sub_left_distrib (n m k : Nat) : n * (m - k) = n * m - n * k := by rw [Nat.mul_comm, Nat.mul_sub_right_distrib, Nat.mul_comm m n, Nat.mul_comm n k] /-! # Helper normalization theorems -/ theorem not_le_eq (a b : Nat) : (¬ (a ≤ b)) = (b + 1 ≤ a) := propext <| Iff.intro (fun h => Nat.gt_of_not_le h) (fun h => Nat.not_le_of_gt h) theorem not_ge_eq (a b : Nat) : (¬ (a ≥ b)) = (a + 1 ≤ b) := not_le_eq b a theorem not_lt_eq (a b : Nat) : (¬ (a < b)) = (b ≤ a) := propext <| Iff.intro (fun h => have h := Nat.succ_le_of_lt (Nat.gt_of_not_le h); Nat.le_of_succ_le_succ h) (fun h => Nat.not_le_of_gt (Nat.succ_le_succ h)) theorem not_gt_eq (a b : Nat) : (¬ (a > b)) = (a ≤ b) := not_lt_eq b a /-! # csimp theorems -/ @[csimp] theorem fold_eq_foldTR : @fold = @foldTR := funext fun α => funext fun f => funext fun n => funext fun init => let rec go : ∀ m n, foldTR.loop f (m + n) m (fold f n init) = fold f (m + n) init | 0, n => by simp [foldTR.loop] | succ m, n => by rw [foldTR.loop, add_sub_self_left, succ_add]; exact go m (succ n) (go n 0).symm @[csimp] theorem any_eq_anyTR : @any = @anyTR := funext fun f => funext fun n => let rec go : ∀ m n, (any f n || anyTR.loop f (m + n) m) = any f (m + n) | 0, n => by simp [anyTR.loop] | succ m, n => by rw [anyTR.loop, add_sub_self_left, ← Bool.or_assoc, succ_add] exact go m (succ n) (go n 0).symm @[csimp] theorem all_eq_allTR : @all = @allTR := funext fun f => funext fun n => let rec go : ∀ m n, (all f n && allTR.loop f (m + n) m) = all f (m + n) | 0, n => by simp [allTR.loop] | succ m, n => by rw [allTR.loop, add_sub_self_left, ← Bool.and_assoc, succ_add] exact go m (succ n) (go n 0).symm @[csimp] theorem repeat_eq_repeatTR : @repeat = @repeatTR := funext fun α => funext fun f => funext fun n => funext fun init => let rec go : ∀ m n, repeatTR.loop f m (repeat f n init) = repeat f (m + n) init | 0, n => by simp [repeatTR.loop] | succ m, n => by rw [repeatTR.loop, succ_add]; exact go m (succ n) (go n 0).symm end Nat namespace Prod /-- `(start, stop).foldI f a` evaluates `f` on all the numbers from `start` (inclusive) to `stop` (exclusive) in increasing order: * `(5, 8).foldI f init = init |> f 5 |> f 6 |> f 7` -/ @[inline] def foldI {α : Type u} (f : Nat → α → α) (i : Nat × Nat) (a : α) : α := Nat.foldTR.loop f i.2 (i.2 - i.1) a /-- `(start, stop).anyI f a` returns true if `f` is true for some natural number from `start` (inclusive) to `stop` (exclusive): * `(5, 8).anyI f = f 5 || f 6 || f 7` -/ @[inline] def anyI (f : Nat → Bool) (i : Nat × Nat) : Bool := Nat.anyTR.loop f i.2 (i.2 - i.1) /-- `(start, stop).allI f a` returns true if `f` is true for all natural numbers from `start` (inclusive) to `stop` (exclusive): * `(5, 8).anyI f = f 5 && f 6 && f 7` -/ @[inline] def allI (f : Nat → Bool) (i : Nat × Nat) : Bool := Nat.allTR.loop f i.2 (i.2 - i.1) end Prod
62c9389a7866a29d8bbc00b0099e69f0671b4f71
9b9a16fa2cb737daee6b2785474678b6fa91d6d4
/src/data/multivariate_polynomial.lean
17ddb63618baf7fa2aa317db2b1931b4eda2d44a
[ "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
28,007
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, Johan Commelin, Mario Carneiro Multivariate Polynomial -/ import algebra.ring import data.finsupp data.polynomial data.equiv.algebra open set function finsupp lattice universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} /-- Multivariate polynomial, where `σ` is the index set of the variables and `α` is the coefficient ring -/ def mv_polynomial (σ : Type*) (α : Type*) [comm_semiring α] := (σ →₀ ℕ) →₀ α namespace mv_polynomial variables {σ : Type*} {a a' a₁ a₂ : α} {e : ℕ} {n m : σ} {s : σ →₀ ℕ} variables [decidable_eq σ] [decidable_eq α] section comm_semiring variables [comm_semiring α] {p q : mv_polynomial σ α} instance : decidable_eq (mv_polynomial σ α) := finsupp.decidable_eq instance : has_zero (mv_polynomial σ α) := finsupp.has_zero instance : has_one (mv_polynomial σ α) := finsupp.has_one instance : has_add (mv_polynomial σ α) := finsupp.has_add instance : has_mul (mv_polynomial σ α) := finsupp.has_mul instance : comm_semiring (mv_polynomial σ α) := finsupp.to_comm_semiring /-- `monomial s a` is the monomial `a * X^s` -/ def monomial (s : σ →₀ ℕ) (a : α) : mv_polynomial σ α := single s a /-- `C a` is the constant polynomial with value `a` -/ def C (a : α) : mv_polynomial σ α := monomial 0 a /-- `X n` is the polynomial with value X_n -/ def X (n : σ) : mv_polynomial σ α := monomial (single n 1) 1 @[simp] lemma C_0 : C 0 = (0 : mv_polynomial σ α) := by simp [C, monomial]; refl @[simp] lemma C_1 : C 1 = (1 : mv_polynomial σ α) := rfl lemma C_mul_monomial : C a * monomial s a' = monomial s (a * a') := by simp [C, monomial, single_mul_single] @[simp] lemma C_add : (C (a + a') : mv_polynomial σ α) = C a + C a' := single_add @[simp] lemma C_mul : (C (a * a') : mv_polynomial σ α) = C a * C a' := C_mul_monomial.symm instance : is_semiring_hom (C : α → mv_polynomial σ α) := { map_zero := C_0, map_one := C_1, map_add := λ a a', C_add, map_mul := λ a a', C_mul } lemma X_pow_eq_single : X n ^ e = monomial (single n e) (1 : α) := begin induction e, { simp [X], refl }, { simp [pow_succ, e_ih], simp [X, monomial, single_mul_single, nat.succ_eq_add_one] } end lemma monomial_add_single : monomial (s + single n e) a = (monomial s a * X n ^ e):= by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_single_add : monomial (single n e + s) a = (X n ^ e * monomial s a):= by rw [X_pow_eq_single, monomial, monomial, monomial, single_mul_single]; simp lemma monomial_eq : monomial s a = C a * (s.prod $ λn e, X n ^ e : mv_polynomial σ α) := begin apply @finsupp.induction σ ℕ _ _ _ _ s, { simp [C, prod_zero_index]; exact (mul_one _).symm }, { assume n e s hns he ih, simp [prod_add_index, prod_single_index, pow_zero, pow_add, (mul_assoc _ _ _).symm, ih.symm, monomial_add_single] } end @[recursor 7] lemma induction_on {M : mv_polynomial σ α → Prop} (p : mv_polynomial σ α) (h_C : ∀a, M (C a)) (h_add : ∀p q, M p → M q → M (p + q)) (h_X : ∀p n, M p → M (p * X n)) : M p := have ∀s a, M (monomial s a), begin assume s a, apply @finsupp.induction σ ℕ _ _ _ _ s, { show M (monomial 0 a), from h_C a, }, { assume n e p hpn he ih, have : ∀e:ℕ, M (monomial p a * X n ^ e), { intro e, induction e, { simp [ih] }, { simp [ih, pow_succ', (mul_assoc _ _ _).symm, h_X, e_ih] } }, simp [monomial_add_single, this] } end, finsupp.induction p (by have : M (C 0) := h_C 0; rwa [C_0] at this) (assume s a p hsp ha hp, h_add _ _ (this s a) hp) lemma hom_eq_hom [semiring γ] (f g : mv_polynomial σ α → γ) (hf : is_semiring_hom f) (hg : is_semiring_hom g) (hC : ∀a:α, f (C a) = g (C a)) (hX : ∀n:σ, f (X n) = g (X n)) (p : mv_polynomial σ α) : f p = g p := mv_polynomial.induction_on p hC begin assume p q hp hq, rw [is_semiring_hom.map_add f, is_semiring_hom.map_add g, hp, hq] end begin assume p n hp, rw [is_semiring_hom.map_mul f, is_semiring_hom.map_mul g, hp, hX] end lemma is_id (f : mv_polynomial σ α → mv_polynomial σ α) (hf : is_semiring_hom f) (hC : ∀a:α, f (C a) = (C a)) (hX : ∀n:σ, f (X n) = (X n)) (p : mv_polynomial σ α) : f p = p := hom_eq_hom f id hf is_semiring_hom.id hC hX p section eval₂ variables [comm_semiring β] variables (f : α → β) (g : σ → β) /-- Evaluate a polynomial `p` given a valuation `g` of all the variables and a ring hom `f` from the scalar ring to the target -/ def eval₂ (p : mv_polynomial σ α) : β := p.sum (λs a, f a * s.prod (λn e, g n ^ e)) @[simp] lemma eval₂_zero : (0 : mv_polynomial σ α).eval₂ f g = 0 := finsupp.sum_zero_index variables [is_semiring_hom f] @[simp] lemma eval₂_add : (p + q).eval₂ f g = p.eval₂ f g + q.eval₂ f g := finsupp.sum_add_index (by simp [is_semiring_hom.map_zero f]) (by simp [add_mul, is_semiring_hom.map_add f]) @[simp] lemma eval₂_monomial : (monomial s a).eval₂ f g = f a * s.prod (λn e, g n ^ e) := finsupp.sum_single_index (by simp [is_semiring_hom.map_zero f]) @[simp] lemma eval₂_C (a) : (C a).eval₂ f g = f a := by simp [eval₂_monomial, C, prod_zero_index] @[simp] lemma eval₂_one : (1 : mv_polynomial σ α).eval₂ f g = 1 := (eval₂_C _ _ _).trans (is_semiring_hom.map_one f) @[simp] lemma eval₂_X (n) : (X n).eval₂ f g = g n := by simp [eval₂_monomial, is_semiring_hom.map_one f, X, prod_single_index, pow_one] lemma eval₂_mul_monomial : ∀{s a}, (p * monomial s a).eval₂ f g = p.eval₂ f g * f a * s.prod (λn e, g n ^ e) := begin apply mv_polynomial.induction_on p, { assume a' s a, simp [C_mul_monomial, eval₂_monomial, is_semiring_hom.map_mul f] }, { assume p q ih_p ih_q, simp [add_mul, eval₂_add, ih_p, ih_q] }, { assume p n ih s a, from calc (p * X n * monomial s a).eval₂ f g = (p * monomial (single n 1 + s) a).eval₂ f g : by simp [monomial_single_add, -add_comm, pow_one, mul_assoc] ... = (p * monomial (single n 1) 1).eval₂ f g * f a * s.prod (λn e, g n ^ e) : by simp [ih, prod_single_index, prod_add_index, pow_one, pow_add, mul_assoc, mul_left_comm, is_semiring_hom.map_one f, -add_comm] } end lemma eval₂_mul : ∀{p}, (p * q).eval₂ f g = p.eval₂ f g * q.eval₂ f g := begin apply mv_polynomial.induction_on q, { simp [C, eval₂_monomial, eval₂_mul_monomial, prod_zero_index] }, { simp [mul_add, eval₂_add] {contextual := tt} }, { simp [X, eval₂_monomial, eval₂_mul_monomial, (mul_assoc _ _ _).symm] { contextual := tt} } end lemma eval₂_pow {p:mv_polynomial σ α} : ∀{n:ℕ}, (p ^ n).eval₂ f g = (p.eval₂ f g)^n | 0 := eval₂_one _ _ | (n + 1) := by rw [pow_add, pow_one, pow_add, pow_one, eval₂_mul, eval₂_pow] instance eval₂.is_semiring_hom : is_semiring_hom (eval₂ f g) := { map_zero := eval₂_zero _ _, map_one := eval₂_one _ _, map_add := λ p q, eval₂_add _ _, map_mul := λ p q, eval₂_mul _ _ } lemma eval₂_comp_left {γ} [comm_semiring γ] (k : β → γ) [is_semiring_hom k] (f : α → β) [is_semiring_hom f] (g : σ → β) (p) : k (eval₂ f g p) = eval₂ (k ∘ f) (k ∘ g) p := by apply mv_polynomial.induction_on p; simp [ eval₂_add, is_semiring_hom.map_add k, eval₂_mul, is_semiring_hom.map_mul k] {contextual := tt} lemma eval₂_eta (p : mv_polynomial σ α) : eval₂ C X p = p := by apply mv_polynomial.induction_on p; simp [eval₂_add, eval₂_mul] {contextual := tt} end eval₂ section eval variables {f : σ → α} /-- Evaluate a polynomial `p` given a valuation `f` of all the variables -/ def eval (f : σ → α) : mv_polynomial σ α → α := eval₂ id f @[simp] lemma eval_zero : (0 : mv_polynomial σ α).eval f = 0 := eval₂_zero _ _ @[simp] lemma eval_add : (p + q).eval f = p.eval f + q.eval f := eval₂_add _ _ lemma eval_monomial : (monomial s a).eval f = a * s.prod (λn e, f n ^ e) := eval₂_monomial _ _ @[simp] lemma eval_C : ∀ a, (C a).eval f = a := eval₂_C _ _ @[simp] lemma eval_X : ∀ n, (X n).eval f = f n := eval₂_X _ _ @[simp] lemma eval_mul : (p * q).eval f = p.eval f * q.eval f := eval₂_mul _ _ instance eval.is_semiring_hom : is_semiring_hom (eval f) := eval₂.is_semiring_hom _ _ theorem eval_assoc {τ} [decidable_eq τ] (f : σ → mv_polynomial τ α) (g : τ → α) (p : mv_polynomial σ α) : p.eval (eval g ∘ f) = (eval₂ C f p).eval g := begin rw eval₂_comp_left (eval g), unfold eval, congr; funext a; simp end end eval section map variables [comm_semiring β] [decidable_eq β] variables (f : α → β) [is_semiring_hom f] /-- `map f p` maps a polynomial `p` across a ring hom `f` -/ def map : mv_polynomial σ α → mv_polynomial σ β := eval₂ (C ∘ f) X @[simp] theorem map_monomial (s : σ →₀ ℕ) (a : α) : map f (monomial s a) = monomial s (f a) := (eval₂_monomial _ _).trans monomial_eq.symm @[simp] theorem map_C : ∀ (a : α), map f (C a : mv_polynomial σ α) = C (f a) := map_monomial _ _ @[simp] theorem map_X : ∀ (n : σ), map f (X n : mv_polynomial σ α) = X n := eval₂_X _ _ @[simp] theorem map_one : map f (1 : mv_polynomial σ α) = 1 := eval₂_one _ _ @[simp] theorem map_add (p q : mv_polynomial σ α) : map f (p + q) = map f p + map f q := eval₂_add _ _ @[simp] theorem map_mul (p q : mv_polynomial σ α) : map f (p * q) = map f p * map f q := eval₂_mul _ _ instance map.is_semiring_hom : is_semiring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_semiring_hom _ _ theorem map_id : ∀ (p : mv_polynomial σ α), map id p = p := eval₂_eta theorem map_map [comm_semiring γ] [decidable_eq γ] (g : β → γ) [is_semiring_hom g] (p : mv_polynomial σ α) : map g (map f p) = map (g ∘ f) p := (eval₂_comp_left (map g) (C ∘ f) X p).trans $ by congr; funext a; simp theorem eval₂_eq_eval_map (g : σ → β) (p : mv_polynomial σ α) : p.eval₂ f g = (map f p).eval g := begin unfold map eval, rw eval₂_comp_left (eval₂ id g), congr; funext a; simp end end map section degrees section comm_semiring def degrees (p : mv_polynomial σ α) : multiset σ := p.support.sup (λs:σ →₀ ℕ, s.to_multiset) lemma degrees_monomial (s : σ →₀ ℕ) (a : α) : degrees (monomial s a) ≤ s.to_multiset := finset.sup_le $ assume t h, begin have := finsupp.support_single_subset h, rw [finset.singleton_eq_singleton, finset.mem_singleton] at this, rw this end lemma degrees_monomial_eq (s : σ →₀ ℕ) (a : α) (ha : a ≠ 0) : degrees (monomial s a) = s.to_multiset := le_antisymm (degrees_monomial s a) $ finset.le_sup $ by rw [monomial, finsupp.support_single_ne_zero ha, finset.singleton_eq_singleton, finset.mem_singleton] lemma degrees_C (a : α) : degrees (C a : mv_polynomial σ α) = 0 := multiset.le_zero.1 $ degrees_monomial _ _ lemma degrees_X (n : σ) : degrees (X n : mv_polynomial σ α) ≤ {n} := le_trans (degrees_monomial _ _) $ le_of_eq $ to_multiset_single _ _ lemma degrees_zero : degrees (0 : mv_polynomial σ α) = 0 := degrees_C 0 lemma degrees_one : degrees (1 : mv_polynomial σ α) = 0 := degrees_C 1 lemma degrees_add (p q : mv_polynomial σ α) : (p + q).degrees ≤ p.degrees ⊔ q.degrees := begin refine finset.sup_le (assume b hb, _), cases finset.mem_union.1 (finsupp.support_add hb), { exact le_sup_left_of_le (finset.le_sup h) }, { exact le_sup_right_of_le (finset.le_sup h) }, end lemma degrees_sum {ι : Type*} [decidable_eq ι] (s : finset ι) (f : ι → mv_polynomial σ α) : (s.sum f).degrees ≤ s.sup (λi, (f i).degrees) := begin refine s.induction _ _, { simp only [finset.sum_empty, finset.sup_empty, degrees_zero], exact le_refl _ }, { assume i s his ih, rw [finset.sup_insert, finset.sum_insert his], exact le_trans (degrees_add _ _) (sup_le_sup_left ih _) } end lemma degrees_mul (p q : mv_polynomial σ α) : (p * q).degrees ≤ p.degrees + q.degrees := begin refine finset.sup_le (assume b hb, _), have := support_mul p q hb, simp only [finset.mem_bind, finset.singleton_eq_singleton, finset.mem_singleton] at this, rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩, rw [finsupp.to_multiset_add], exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂) end lemma degrees_prod {ι : Type*} [decidable_eq ι] (s : finset ι) (f : ι → mv_polynomial σ α) : (s.prod f).degrees ≤ s.sum (λi, (f i).degrees) := begin refine s.induction _ _, { simp only [finset.prod_empty, finset.sum_empty, degrees_one] }, { assume i s his ih, rw [finset.prod_insert his, finset.sum_insert his], exact le_trans (degrees_mul _ _) (add_le_add_left ih _) } end lemma degrees_pow (p : mv_polynomial σ α) : ∀(n : ℕ), (p^n).degrees ≤ add_monoid.smul n p.degrees | 0 := begin rw [pow_zero, degrees_one], exact multiset.zero_le _ end | (n + 1) := le_trans (degrees_mul _ _) (add_le_add_left (degrees_pow n) _) end comm_semiring end degrees section vars /-- `vars p` is the set of variables appearing in the polynomial `p` -/ def vars (p : mv_polynomial σ α) : finset σ := p.degrees.to_finset @[simp] lemma vars_0 : (0 : mv_polynomial σ α).vars = ∅ := by rw [vars, degrees_zero, multiset.to_finset_zero] @[simp] lemma vars_monomial (h : a ≠ 0) : (monomial s a).vars = s.support := by rw [vars, degrees_monomial_eq _ _ h, finsupp.to_finset_to_multiset] @[simp] lemma vars_C : (C a : mv_polynomial σ α).vars = ∅ := by rw [vars, degrees_C, multiset.to_finset_zero] @[simp] lemma vars_X (h : 0 ≠ (1 : α)) : (X n : mv_polynomial σ α).vars = {n} := by rw [X, vars_monomial h.symm, finsupp.support_single_ne_zero zero_ne_one.symm] end vars section degree_of /-- `degree_of n p` gives the highest power of X_n that appears in `p` -/ def degree_of (n : σ) (p : mv_polynomial σ α) : ℕ := p.degrees.count n end degree_of section total_degree /-- `total_degree p` gives the maximum |s| over the monomials X^s in `p` -/ def total_degree (p : mv_polynomial σ α) : ℕ := p.support.sup (λs, s.sum $ λn e, e) lemma total_degree_eq (p : mv_polynomial σ α) : p.total_degree = p.support.sup (λm, m.to_multiset.card) := begin rw [total_degree], congr, funext m, exact (finsupp.card_to_multiset _).symm end lemma total_degree_le_degrees_card (p : mv_polynomial σ α) : p.total_degree ≤ p.degrees.card := begin rw [total_degree_eq], exact finset.sup_le (assume s hs, multiset.card_le_of_le $ finset.le_sup hs) end lemma total_degree_C (a : α) : (C a : mv_polynomial σ α).total_degree = 0 := nat.eq_zero_of_le_zero $ finset.sup_le $ assume n hn, have _ := finsupp.support_single_subset hn, begin rw [finset.singleton_eq_singleton, finset.mem_singleton] at this, subst this, exact le_refl _ end lemma total_degree_zero : (0 : mv_polynomial σ α).total_degree = 0 := by rw [← C_0]; exact total_degree_C (0 : α) lemma total_degree_one : (1 : mv_polynomial σ α).total_degree = 0 := total_degree_C (1 : α) lemma total_degree_add (a b : mv_polynomial σ α) : (a + b).total_degree ≤ max a.total_degree b.total_degree := finset.sup_le $ assume n hn, have _ := finsupp.support_add hn, begin rcases finset.mem_union.1 this, { exact le_max_left_of_le (finset.le_sup h) }, { exact le_max_right_of_le (finset.le_sup h) } end lemma total_degree_mul (a b : mv_polynomial σ α) : (a * b).total_degree ≤ a.total_degree + b.total_degree := finset.sup_le $ assume n hn, have _ := finsupp.support_mul a b hn, begin simp only [finset.mem_bind, finset.mem_singleton, finset.singleton_eq_singleton] at this, rcases this with ⟨a₁, h₁, a₂, h₂, rfl⟩, rw [finsupp.sum_add_index], { exact add_le_add (finset.le_sup h₁) (finset.le_sup h₂) }, { assume a, refl }, { assume a b₁ b₂, refl } end lemma total_degree_list_prod : ∀(s : list (mv_polynomial σ α)), s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum | [] := by rw [@list.prod_nil (mv_polynomial σ α) _, total_degree_one]; refl | (p :: ps) := begin rw [@list.prod_cons (mv_polynomial σ α) _, list.map, list.sum_cons], exact le_trans (total_degree_mul _ _) (add_le_add_left (total_degree_list_prod ps) _) end lemma total_degree_multiset_prod (s : multiset (mv_polynomial σ α)) : s.prod.total_degree ≤ (s.map mv_polynomial.total_degree).sum := begin refine quotient.induction_on s (assume l, _), rw [multiset.quot_mk_to_coe, multiset.coe_prod, multiset.coe_map, multiset.coe_sum], exact total_degree_list_prod l end lemma total_degree_finset_prod {ι : Type*} (s : finset ι) (f : ι → mv_polynomial σ α) : (s.prod f).total_degree ≤ s.sum (λi, (f i).total_degree) := begin refine le_trans (total_degree_multiset_prod _) _, rw [multiset.map_map], refl end end total_degree end comm_semiring section comm_ring variable [comm_ring α] variables {p q : mv_polynomial σ α} instance : ring (mv_polynomial σ α) := finsupp.to_ring instance : comm_ring (mv_polynomial σ α) := finsupp.to_comm_ring instance : has_scalar α (mv_polynomial σ α) := finsupp.to_has_scalar instance : module α (mv_polynomial σ α) := finsupp.to_module _ α instance C.is_ring_hom : is_ring_hom (C : α → mv_polynomial σ α) := by apply is_ring_hom.of_semiring variables (σ a a') lemma C_sub : (C (a - a') : mv_polynomial σ α) = C a - C a' := is_ring_hom.map_sub _ @[simp] lemma C_neg : (C (-a) : mv_polynomial σ α) = -C a := is_ring_hom.map_neg _ variables {σ} (p) theorem C_mul' : mv_polynomial.C a * p = a • p := begin apply finsupp.induction p, { exact (mul_zero $ mv_polynomial.C a).trans (@smul_zero α (mv_polynomial σ α) _ _ _ a).symm }, intros p b f haf hb0 ih, rw [mul_add, ih, @smul_add α (mv_polynomial σ α) _ _ _ a], congr' 1, rw [finsupp.mul_def, finsupp.smul_single, mv_polynomial.C, mv_polynomial.monomial], rw [finsupp.sum_single_index, finsupp.sum_single_index, zero_add, smul_eq_mul], { rw [mul_zero, finsupp.single_zero] }, { rw finsupp.sum_single_index, all_goals { rw [zero_mul, finsupp.single_zero] } } end lemma smul_eq_C_mul (p : mv_polynomial σ α) (a : α) : a • p = C a * p := begin rw [← finsupp.sum_single p, @finsupp.smul_sum (σ →₀ ℕ) α α, finsupp.mul_sum], refine finset.sum_congr rfl (assume n _, _), simp only [finsupp.smul_single], exact C_mul_monomial.symm end @[simp] lemma smul_eval (x) (p : mv_polynomial σ α) (s) : (s • p).eval x = s * p.eval x := by rw [smul_eq_C_mul, eval_mul, eval_C] section degrees lemma degrees_neg [comm_ring α] (p : mv_polynomial σ α) : (- p).degrees = p.degrees := by rw [degrees, finsupp.support_neg]; refl lemma degrees_sub [comm_ring α] (p q : mv_polynomial σ α) : (p - q).degrees ≤ p.degrees ⊔ q.degrees := le_trans (degrees_add p (-q)) $ by rw [degrees_neg] end degrees section eval₂ variables [comm_ring β] variables (f : α → β) [is_ring_hom f] (g : σ → β) instance eval₂.is_ring_hom : is_ring_hom (eval₂ f g) := by apply is_ring_hom.of_semiring lemma eval₂_sub : (p - q).eval₂ f g = p.eval₂ f g - q.eval₂ f g := is_ring_hom.map_sub _ @[simp] lemma eval₂_neg : (-p).eval₂ f g = -(p.eval₂ f g) := is_ring_hom.map_neg _ end eval₂ section eval variables (f : σ → α) instance eval.is_ring_hom : is_ring_hom (eval f) := eval₂.is_ring_hom _ _ lemma eval_sub : (p - q).eval f = p.eval f - q.eval f := is_ring_hom.map_sub _ @[simp] lemma eval_neg : (-p).eval f = -(p.eval f) := is_ring_hom.map_neg _ end eval section map variables [decidable_eq β] [comm_ring β] variables (f : α → β) [is_ring_hom f] instance map.is_ring_hom : is_ring_hom (map f : mv_polynomial σ α → mv_polynomial σ β) := eval₂.is_ring_hom _ _ lemma map_sub : (p - q).map f = p.map f - q.map f := is_ring_hom.map_sub _ @[simp] lemma map_neg : (-p).map f = -(p.map f) := is_ring_hom.map_neg _ end map end comm_ring section rename variables {α} [comm_semiring α] [decidable_eq α] [decidable_eq β] [decidable_eq γ] [decidable_eq δ] def rename (f : β → γ) : mv_polynomial β α → mv_polynomial γ α := eval₂ C (X ∘ f) instance rename.is_semiring_hom (f : β → γ) : is_semiring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := by unfold rename; apply_instance @[simp] lemma rename_C (f : β → γ) (a : α) : rename f (C a) = C a := eval₂_C _ _ _ @[simp] lemma rename_X (f : β → γ) (b : β) : rename f (X b : mv_polynomial β α) = X (f b) := eval₂_X _ _ _ lemma rename_rename (f : β → γ) (g : γ → δ) (p : mv_polynomial β α) : rename g (rename f p) = rename (g ∘ f) p := show rename g (eval₂ C (X ∘ f) p) = _, by simp only [eval₂_comp_left (rename g) C (X ∘ f) p, (∘), rename_C, rename_X]; refl lemma rename_id (p : mv_polynomial β α) : rename id p = p := eval₂_eta p end rename instance rename.is_ring_hom {α} [comm_ring α] [decidable_eq α] [decidable_eq β] [decidable_eq γ] (f : β → γ) : is_ring_hom (rename f : mv_polynomial β α → mv_polynomial γ α) := @is_ring_hom.of_semiring (mv_polynomial β α) (mv_polynomial γ α) _ _ (rename f) (rename.is_semiring_hom f) section equiv variables (α) [comm_ring α] variables [decidable_eq β] [decidable_eq γ] [decidable_eq δ] def pempty_ring_equiv : mv_polynomial pempty α ≃r α := { to_fun := mv_polynomial.eval₂ id $ pempty.elim, inv_fun := C, left_inv := is_id _ (by apply_instance) (assume a, by rw [eval₂_C]; refl) (assume a, a.elim), right_inv := λ r, eval₂_C _ _ _, hom := eval₂.is_ring_hom _ _ } def punit_ring_equiv : mv_polynomial punit α ≃r polynomial α := { to_fun := eval₂ polynomial.C (λu:punit, polynomial.X), inv_fun := polynomial.eval₂ mv_polynomial.C (X punit.star), left_inv := begin refine is_id _ _ _ _, apply is_semiring_hom.comp (eval₂ polynomial.C (λu:punit, polynomial.X)) _; apply_instance, { assume a, rw [eval₂_C, polynomial.eval₂_C] }, { rintros ⟨⟩, rw [eval₂_X, polynomial.eval₂_X] } end, right_inv := assume p, polynomial.induction_on p (assume a, by rw [polynomial.eval₂_C, mv_polynomial.eval₂_C]) (assume p q hp hq, by rw [polynomial.eval₂_add, mv_polynomial.eval₂_add, hp, hq]) (assume p n hp, by rw [polynomial.eval₂_mul, polynomial.eval₂_pow, polynomial.eval₂_X, polynomial.eval₂_C, eval₂_mul, eval₂_C, eval₂_pow, eval₂_X]), hom := eval₂.is_ring_hom _ _ } def ring_equiv_of_equiv (e : β ≃ γ) : mv_polynomial β α ≃r mv_polynomial γ α := { to_fun := rename e, inv_fun := rename e.symm, left_inv := λ p, by simp only [rename_rename, (∘), e.inverse_apply_apply]; exact rename_id p, right_inv := λ p, by simp only [rename_rename, (∘), e.apply_inverse_apply]; exact rename_id p, hom := rename.is_ring_hom e } def ring_equiv_congr [comm_ring γ] (e : α ≃r γ) : mv_polynomial β α ≃r mv_polynomial β γ := { to_fun := map e.to_fun, inv_fun := map e.symm.to_fun, left_inv := assume p, have (e.symm.to_equiv.to_fun ∘ e.to_equiv.to_fun) = id, { ext a, exact e.to_equiv.inverse_apply_apply a }, by simp only [map_map, this, map_id], right_inv := assume p, have (e.to_equiv.to_fun ∘ e.symm.to_equiv.to_fun) = id, { ext a, exact e.to_equiv.apply_inverse_apply a }, by simp only [map_map, this, map_id], hom := map.is_ring_hom e.to_fun } section variables (β γ δ) instance ring_on_sum : ring (mv_polynomial (β ⊕ γ) α) := by apply_instance instance ring_on_iter : ring (mv_polynomial β (mv_polynomial γ α)) := by apply_instance def sum_to_iter : mv_polynomial (β ⊕ γ) α → mv_polynomial β (mv_polynomial γ α) := eval₂ (C ∘ C) (λbc, sum.rec_on bc X (C ∘ X)) instance is_semiring_hom_C_C : is_semiring_hom (C ∘ C : α → mv_polynomial β (mv_polynomial γ α)) := @is_semiring_hom.comp _ _ _ _ C mv_polynomial.is_semiring_hom _ _ C mv_polynomial.is_semiring_hom instance is_semiring_hom_sum_to_iter : is_semiring_hom (sum_to_iter α β γ) := eval₂.is_semiring_hom _ _ lemma sum_to_iter_C (a : α) : sum_to_iter α β γ (C a) = C (C a) := eval₂_C _ _ a lemma sum_to_iter_Xl (b : β) : sum_to_iter α β γ (X (sum.inl b)) = X b := eval₂_X _ _ (sum.inl b) lemma sum_to_iter_Xr (c : γ) : sum_to_iter α β γ (X (sum.inr c)) = C (X c) := eval₂_X _ _ (sum.inr c) def iter_to_sum : mv_polynomial β (mv_polynomial γ α) → mv_polynomial (β ⊕ γ) α := eval₂ (eval₂ C (X ∘ sum.inr)) (X ∘ sum.inl) section instance is_semiring_hom_iter_to_sum : is_semiring_hom (iter_to_sum α β γ) := eval₂.is_semiring_hom _ _ end lemma iter_to_sum_C_C (a : α) : iter_to_sum α β γ (C (C a)) = C a := eq.trans (eval₂_C _ _ (C a)) (eval₂_C _ _ _) lemma iter_to_sum_X (b : β) : iter_to_sum α β γ (X b) = X (sum.inl b) := eval₂_X _ _ _ lemma iter_to_sum_C_X (c : γ) : iter_to_sum α β γ (C (X c)) = X (sum.inr c) := eq.trans (eval₂_C _ _ (X c)) (eval₂_X _ _ _) def mv_polynomial_equiv_mv_polynomial [comm_ring δ] (f : mv_polynomial β α → mv_polynomial γ δ) (hf : is_semiring_hom f) (g : mv_polynomial γ δ → mv_polynomial β α) (hg : is_semiring_hom g) (hfgC : ∀a, f (g (C a)) = C a) (hfgX : ∀n, f (g (X n)) = X n) (hgfC : ∀a, g (f (C a)) = C a) (hgfX : ∀n, g (f (X n)) = X n) : mv_polynomial β α ≃r mv_polynomial γ δ := { to_fun := f, inv_fun := g, left_inv := is_id _ (is_semiring_hom.comp _ _) hgfC hgfX, right_inv := is_id _ (is_semiring_hom.comp _ _) hfgC hfgX, hom := is_ring_hom.of_semiring f } def sum_ring_equiv : mv_polynomial (β ⊕ γ) α ≃r mv_polynomial β (mv_polynomial γ α) := begin apply @mv_polynomial_equiv_mv_polynomial α (β ⊕ γ) _ _ _ _ _ _ _ _ (sum_to_iter α β γ) _ (iter_to_sum α β γ) _, { assume p, apply @hom_eq_hom _ _ _ _ _ _ _ _ _ _ _ _ _ p, apply_instance, { apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _, apply_instance, apply @is_semiring_hom.comp _ _ _ _ _ _ _ _ _ _, apply_instance, { apply @mv_polynomial.is_semiring_hom }, { apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ }, { apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ } }, { apply mv_polynomial.is_semiring_hom }, { assume a, rw [iter_to_sum_C_C α β γ, sum_to_iter_C α β γ] }, { assume c, rw [iter_to_sum_C_X α β γ, sum_to_iter_Xr α β γ] } }, { assume b, rw [iter_to_sum_X α β γ, sum_to_iter_Xl α β γ] }, { assume a, rw [sum_to_iter_C α β γ, iter_to_sum_C_C α β γ] }, { assume n, cases n with b c, { rw [sum_to_iter_Xl, iter_to_sum_X] }, { rw [sum_to_iter_Xr, iter_to_sum_C_X] } }, { apply mv_polynomial.is_semiring_hom_sum_to_iter α β γ }, { apply mv_polynomial.is_semiring_hom_iter_to_sum α β γ } end instance option_ring : ring (mv_polynomial (option β) α) := mv_polynomial.ring instance polynomial_ring : ring (polynomial (mv_polynomial β α)) := @comm_ring.to_ring _ polynomial.comm_ring instance polynomial_ring2 : ring (mv_polynomial β (polynomial α)) := by apply_instance def option_equiv_left : mv_polynomial (option β) α ≃r polynomial (mv_polynomial β α) := (ring_equiv_of_equiv α $ (equiv.option_equiv_sum_punit β).trans (equiv.sum_comm _ _)).trans $ (sum_ring_equiv α _ _).trans $ punit_ring_equiv _ def option_equiv_right : mv_polynomial (option β) α ≃r mv_polynomial β (polynomial α) := (ring_equiv_of_equiv α $ equiv.option_equiv_sum_punit.{0} β).trans $ (sum_ring_equiv α β unit).trans $ ring_equiv_congr (mv_polynomial unit α) (punit_ring_equiv α) end end equiv end mv_polynomial
2603fea42593d881e36aef829b8a8e8746ede5f7
56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3
/src/utils/util.lean
cd4d2b629837d2e3321aa41b95cc15212c8da4e3
[ "Apache-2.0" ]
permissive
DyeKuu/lean-tpe-public
3a9968f286ca182723ef7e7d97e155d8cb6b1e70
750ade767ab28037e80b7a80360d213a875038f8
refs/heads/master
1,682,842,633,115
1,621,330,793,000
1,621,330,793,000
368,475,816
0
0
Apache-2.0
1,621,330,745,000
1,621,330,744,000
null
UTF-8
Lean
false
false
18,438
lean
import tactic import .sexp import control.traversable.derive import data.string.basic import meta.rb_map infix `<e>`:100 := λ x y, tactic.to_expr y >>= x section iterate_until meta def iterate_until_aux {m} [monad m] [alternative m] {α} (tac : m α) (stop : α → m bool) (fuel_exhausted_callback : m α) : Π (fuel : ℕ), m α | 0 := do {result ← tac, mcond (stop result) (pure result) fuel_exhausted_callback} | (n+1) := do { result ← tac, mcond (stop result) (pure result) (iterate_until_aux n)} meta def iterate_until {m} [monad m] [alternative m] {α} (tac : m α) (stop : α → m bool) (fuel := 100000) (fuel_exhausted_callback : m α := alternative.failure) : m α := iterate_until_aux tac stop fuel_exhausted_callback fuel end iterate_until section interaction_monad meta def interaction_monad.result.is_success {σ α} : interaction_monad.result σ α → bool := λ x, match x with | (interaction_monad.result.success _ _) := tt | _ := ff end end interaction_monad section setup_tactic_parser meta def parse_decl_nm_and_open_ns : string → tactic (name × list name) := λ inp, flip lean.parser.run_with_input inp $ prod.mk <$> iterate_until ident (λ nm, pure ∘ bnot $ nm = name.anonymous) 100 <*> many ident -- -- brilliant -- #eval (["foo bar baz\n", "baz baz baz\n", "a b c d e\n"].mmap $ io.run_tactic' ∘ parse_decl_nm_and_open_ns) >>= λ x, io.put_str_ln' format!"{x}" end section io open interaction_monad interaction_monad.result namespace io meta def run_tactic' {α} (tac :tactic α) : io α := do { io.run_tactic $ do { result ← tactic.capture tac, match result with | (success val _) := pure val | (exception m_fmt pos _) := do { let fmt_msg := (m_fmt.get_or_else (λ _, format!"none")) (), let msg := format!"[io.run_tactic'] {pos}: tactic failed\n-------\n{fmt_msg}\n-------\n", tactic.trace msg, tactic.fail msg } end } } end io end io section list parameter {α : Type} variables [has_lt α] [decidable_rel (has_lt.lt : α → α → Prop)] meta structure dedup_state : Type := (seen : native.rb_set α := native.mk_rb_set) (result : list α := []) meta def dedup_list_aux {m} [monad m] : list α → state_t dedup_state m unit | [] := pure () | (x::xs) := do { σ ← get, when (not $ σ.seen.contains x) $ modify $ λ σ, dedup_state.mk (σ.seen.insert x) (σ.result ++ [x]), dedup_list_aux xs } meta def list.dedup {m} [monad m] : list α → m (list α) := λ xs, dedup_state.result <$> prod.snd <$> state_t.run (dedup_list_aux xs) {} /-- version of list.mfoldl with sane argument ordering -/ def list.iterM {m} [monad m] {α β} (xs : list α) (init : β) (body : β → α → m β) : m β := list.mfoldl body init xs def list.iter {α β} (xs : list α) (init : β) (body : β → α → β) : β := list.foldl body init xs end list section list -- WARNING: hack local notation `α` := string meta structure dedup_state' : Type := (seen : native.rb_map α native.float := native.mk_rb_map) (result : list (α) := []) local notation `m` := tactic meta def dedup_list_aux' : list (α × native.float) → state_t dedup_state' m unit | [] := pure () | (x::xs) := do { σ ← get, if (σ.seen.contains x.1) then (do (some old_score) ← (pure $ σ.seen.find x.1) | state_t.lift tactic.failed, let new_seen := if x.2 > old_score then (σ.seen.erase x.1).insert x.1 x.2 else σ.seen, modify $ λ σ, dedup_state'.mk new_seen (σ.result), dedup_list_aux' xs) else do modify $ λ σ, dedup_state'.mk (σ.seen.insert x.1 x.2) (σ.result ++ [x.1]), dedup_list_aux' xs } meta def list.dedup' : list (α × native.float) → m (list $ α × native.float) := λ xs, do σ ← prod.snd <$> state_t.run (dedup_list_aux' xs) {}, σ.result.mmap (λ x, do { prod.mk x <$> σ.seen.find x }) -- OK, seems to work -- run_cmd list.dedup' [("foo", (1.0 : native.float)), ("foo", (2.0 : native.float))] >>= tactic.trace end list section name namespace name meta def is_aux : name → bool | name.anonymous := ff | (name.mk_string str nm) := (||) ((list.head str.to_list) = '_') (is_aux nm) | (name.mk_numeral _ nm) := is_aux nm end name end name section string namespace string def replace_char : string → char → char → string | ⟨cs⟩ c₁ c₂ := ⟨cs.map (λ c, if c = c₁ then c₂ else c)⟩ end string end string section util -- TODO(jesse): refactor when we expose mk_initial_parser_state def hacky_name_from_string (nm_str : string) : name := let components : list string := nm_str.split (= '.') in components.foldl (flip name.mk_string) name.anonymous def drop_newlines (s : string) : string := ⟨s.data.filter (λ c, !(c = '\n'))⟩ namespace io meta def fail' {α} (fmt : format) : io α := io.fail $ format.to_string fmt meta def put_str_ln' : Π (fmt : format), io unit := io.put_str_ln ∘ format.to_string namespace fs def put_str_ln_flush (h : handle) (s : string) : io unit := put_str h s *> put_str h "\n" *> flush h end fs -- discards empty lines meta def readlines (f : io.handle) : io (list string) := do { ls ← io.iterate [] (λ acc, do { do { r ← buffer.to_string <$> io.fs.get_line f, mcond (io.fs.is_eof f) (pure none) $ do pure ∘ pure $ if r.length = 0 then acc else acc ++ [r] } }), pure ls } end io section list_nth_except -- convenience function for command-line argument parsing meta def list.nth_except {α} : list α → ℕ → string → io α := λ xs pos msg, match (xs.nth pos) with | (some result) := pure result | none := do { io.fail' format!"must supply {msg} as argument {pos}" } end end list_nth_except def unless {m} [monad m] (cond : bool) (body : m unit) := when (not cond) body def unlessM {m} [monad m] (cond : m bool) (body : m unit) := mcond cond (pure ()) body def whenM {m} [monad m] (cond : m bool) (body : m unit) := mcond cond body $ pure () def for_ {m α β} [monad m] (xs : list α) (body : α → m β) := list.mmap' body xs def any : list bool -> bool := λ xs, xs.foldl (||) ff def all : list bool → bool := λ xs, xs.foldl (&&) tt inductive my_nat : Type | zero : my_nat | succ : my_nat → my_nat -- probably in the stdlib somewhere meta def lift_option {α} {m} [alternative m]: option α → m α := λo, match o with | (some x) := pure x | none := alternative.failure end namespace tactic meta def guard_sorry : expr → tactic unit := λ e, do { contains_sorry_flag ← e.mfold ff (λ e' _ acc, if acc then pure acc else pure $ bor acc $ e'.is_sorry.is_some), guard $ bnot contains_sorry_flag } meta def set_goal_to (goal : expr) : tactic unit := mk_meta_var goal >>= set_goals ∘ pure meta def get_proof : Π (decl : declaration), tactic expr | (declaration.thm _ _ _ value_thunk) := pure $ value_thunk.get | _ := tactic.fail "" meta def test_get_proof (nm : name) : tactic unit := do { e <- tactic.get_env, d <- e.get nm, get_proof d >>= tactic.trace } meta def get_proof_from_env (nm : name) : tactic expr := do { e ← get_env, d ← e.get nm, get_proof d } /-- Prints a 'Try this:' message. -/ meta def trythis : string → tactic unit | s := tactic.trace (sformat!"Try this: {s}") end tactic -- meta instance has_to_json_list {α} [H : has_to_json α] : has_to_json (list α) := -- ⟨json.array ∘ list.map H.to_json⟩ -- meta instance has_to_tactic_json_list {α} [H : has_to_tactic_json α] : has_to_tactic_json (list α) := -- ⟨λ xs, json.array <$> (list.mmap H.to_tactic_json xs)⟩ -- -- TODO(jesse): questionable. -- meta instance has_to_json_prod {α β} [H₁ : has_to_json α] [H₂ : has_to_json β] : has_to_json (α × β) := -- ⟨λ ⟨a,b⟩, by {tactic.unfreeze_local_instances, cases H₁ with f₁, cases H₂ with f₂, exact (json.array $ [f₁ a, f₂ b])}⟩ -- -- TODO(jesse): even more questionable. -- meta instance has_to_tactic_json_prod {α β} [H₁ : has_to_tactic_json α] [H₂ : has_to_tactic_json β] : has_to_tactic_json (α × β) := -- ⟨λ ⟨a,b⟩, by {tactic.unfreeze_local_instances, -- cases H₁ with f₁, -- cases H₂ with f₂, -- exact (json.array <$> ((list.cons) <$> (f₁ a) <*> ((::) <$> (f₂ b) <*> (pure []))))}⟩ -- open expr -- meta def structured_tactic_json_of_expr : expr → tactic json := λ ex, do { -- repr ← (format.to_string ∘ format.flatten) <$> tactic.pp ex, -- match ex with -- | e@(var k) := do { -- pure $ json.object $ -- [("constructor", "var"), ("value", k), ("repr", repr)]} -- | e@(sort l) := do { -- pure $ json.object $ -- [("constructor", "sort"), ("level", to_string l), ("repr", repr)]} -- TODO(jesse): to_json instance for universe levels -- | e@(const nm ls) := do { -- pure $ json.object $ -- [("constructor", "const"), ("name", to_string nm), -- ("levels", to_string ls), ("repr", repr)]} -- | e@(mvar un pt tp) := do { -- r ← structured_tactic_json_of_expr tp, -- pure $ json.object $ -- [("constructor", "mvar"), ("unique", to_string un), ("pretty", to_string pt), -- ("type", r), ("repr", repr)]} -- | e@(local_const un pt binder_info tp) := do { -- r ← structured_tactic_json_of_expr tp, -- pure $ json.object $ -- [("constructor", "local_const"), ("unique", to_string un), -- ("pretty", to_string pt), ("binder_info", has_repr.repr binder_info), ("type", r), ("repr", repr)]} -- | e@(app e₁ e₂) := do { -- r₁ ← structured_tactic_json_of_expr e₁, -- r₂ ← structured_tactic_json_of_expr e₂, -- pure $ json.object $ -- [("constructor", "app"), ("head", r₁), -- ("body", r₁), ("repr", repr)]} -- | e@(lam var_name b_info var_type body) := do { -- ⟨[b], e'⟩ ← tactic.open_n_lambdas e 1, -- r₁ ← structured_tactic_json_of_expr var_type, -- r₂ ← structured_tactic_json_of_expr e', -- b_json ← structured_tactic_json_of_expr b, -- pure $ json.object $ -- [("constructor", "lam"), ("var_name", to_string var_name), -- ("binder", b_json), -- ("binder_info", has_repr.repr b_info), -- ("var_type", r₁), ("body", r₂), ("repr", repr)]} -- | e@(pi var_name b_info var_type body) := do { -- ⟨[b], e'⟩ ← tactic.open_n_pis e 1, -- r₁ ← structured_tactic_json_of_expr var_type, -- r₂ ← structured_tactic_json_of_expr e', -- b_json ← structured_tactic_json_of_expr b, -- pure $ json.object $ -- [("constructor", "pi"), ("var_name", to_string var_name), -- ("binder", b_json), -- ("binder_info", has_repr.repr b_info), -- ("var_type", r₁), ("body", r₂), ("repr", repr)]} -- | e@(elet var_name var_type var_assignment body) := do { -- r₁ ← structured_tactic_json_of_expr var_type, -- r₂ ← structured_tactic_json_of_expr var_assignment, -- r₃ ← structured_tactic_json_of_expr body, -- pure $ json.object $ -- [("constructor", "elet"), ("var_name", to_string var_name), -- ("var_type", r₁), ("var_assignment", r₂), ("body", r₃), ("repr", repr)]} -- | e@(macro md deps) := do { -- deps_jsons ← deps.mmap structured_tactic_json_of_expr, -- pure $ json.object $ [("constructor", "macro"), ("macro_def", (json.of_string ∘ name.to_string) $ expr.macro_def_name md), -- ("deps", json.array $ deps_jsons), ("repr", repr)]} -- end -- } -- meta instance : has_to_tactic_json expr := ⟨structured_tactic_json_of_expr⟩ -- namespace expr -- meta def to_flattened_json : expr → tactic json := λ e, -- json.of_string <$> ((format.to_string ∘ format.flatten) <$> has_to_tactic_format.to_tactic_format e) -- meta def to_flattened_sexp_json : expr → tactic json := λ e, -- json.of_string <$> (format.to_string ∘ has_to_format.to_format) <$> (sexp_of_expr none e) -- end expr end util section unfold_macros meta def expr.unfold_string_macros {elab} : expr elab → expr elab | e := match e.is_string_macro with | (some a) := expr.unfold_string_macros a | none := e end meta def expr.unfold_macros (e : expr) : tactic expr := do { -- env ← tactic.get_env, -- pure $ env.unfold_all_macros e pure $ e.unfold_string_macros.erase_annotations } end unfold_macros section derive_has_to_format meta def expr.join (tp : expr) : list expr → tactic expr := λ xs, xs.foldr (λ e₁ acc, do {acc ← acc, tactic.to_expr ``(@list.cons %%tp %%e₁ %%acc)}) (tactic.to_expr ``(list.nil)) meta def format.join_using : format → list format → format := λ x xs, format.join $ list.intercalate [x] (pure <$> xs) meta def format.apply_constructor : format → list format → format := λ f fs, match fs with | [] := f | fs := format.join_using " " [f, format.join ["(", format.join_using " " fs, ")"]] end open tactic namespace tactic namespace interactive meta def mk_to_format (type : name) : tactic unit := do { ls ← local_context, (x::_) ← tactic.intro_lst [`arg], et ← infer_type x, xs ← tactic.induction x, xs.mmap' $ λ ⟨c, args, _⟩, do (args', rec_call) ← args.mpartition $ λ e, do { e' ← tactic.to_expr ``(format), bnot <$> e'.occurs <$> tactic.infer_type e }, args'' ← args'.mmap (λ a, flip prod.mk a <$> (et.occurs <$> tactic.infer_type a)), let fn : list (bool × expr) → state_t (list expr) tactic (list expr) := λ args'', do { let pop : state_t (list expr) tactic (option expr) := do { xs ← get, match xs with | (a::as) := modify (λ _, as) *> pure (some a) | [] := pure none end }, args''.mmap (λ ⟨b, a⟩, if b then do (some x) ← pop, pure x else state_t.lift $ do a_tp ← infer_type a, _inst ← mk_app ``has_to_format [a_tp] >>= mk_instance, tactic.to_expr ``(@has_to_format.to_format _ (%%_inst) %%a)) }, args''' ← prod.fst <$> (fn args'').run rec_call, c ← tactic.resolve_constant c, nm_tp ← to_expr ``(name), nm_fmt ← mk_app ``has_to_format [nm_tp] >>= mk_instance, fs ← expr.join `(format) args''', result ← to_expr ``(format.apply_constructor (@has_to_format.to_format %%nm_tp %%nm_fmt %%c) %%fs), tactic.exact result } meta def derive_has_to_format (pre : option name) : tactic unit := do { vs ← local_context, `(has_to_format %%f) ← target, env ← get_env, let n := f.get_app_fn.const_name, d ← get_decl n, refine ``( { to_format := _ } ), tgt ← target, extract_def (with_prefix pre n <.> "to_format") ff $ mk_to_format n } meta def has_to_format_derive_handler' (nspace : option name := none) : derive_handler := higher_order_derive_handler ``has_to_format (derive_has_to_format nspace) [] nspace @[derive_handler] meta def has_to_format_derive_handler : derive_handler := guard_class ``has_to_format has_to_format_derive_handler' attribute [derive [has_to_format]] my_nat end interactive end tactic end derive_has_to_format section json section has_to_json universe u meta class has_to_json (α : Type u) : Type (u+1) := (to_json : α → json) meta class has_to_tactic_json (α : Type u) : Type (u+1) := (to_tactic_json : α → tactic json) meta class has_from_json (α : Type u) : Type (u+1) := (from_json : json → tactic α) end has_to_json meta def list.lookup_prod {α β} : (list (α × β)) → (α → bool) → option β | [] _ := none | (⟨a,b⟩::xs) p := if p a then pure b else xs.lookup_prod p meta def json.get_string : json → option string | (json.of_string str) := pure str | _ := none meta def json.get_float : json → option native.float | (json.of_float str) := pure str | _ := none meta def json.lookup : json → string → option json | (json.object kvs) str := kvs.lookup_prod $ λ k, k = str | _ _ := none end json section full_names namespace tactic meta def enable_full_names : tactic unit := do { set_bool_option `pp.full_names true } meta def with_full_names {α} (tac : tactic α) : tactic α := tactic.save_options $ enable_full_names *> tac end tactic meta def tactic_state.fully_qualified (ts : tactic_state) : tactic tactic_state := do { ts₀ ← tactic.read, tactic.write ts, result_ts ← tactic.with_full_names $ tactic.read, tactic.write ts₀, pure result_ts } meta def tactic_state.fully_qualified_string (ts : tactic_state) : tactic string := do { ts₀ ← tactic.read, tactic.write ts, result ← tactic.with_full_names $ (tactic.read >>= λ ts, pure ts.to_format.to_string), tactic.write ts₀, pure result } end full_names -- TODO(jesse): typeclasses also for updating decl_name section search_state_instances class has_mark_global_timeout (α : Type) : Type := (mark_global_timeout : α → α) class has_register_task_id (α : Type) : Type := (register_task_id : α → string → α) class has_set_tac_timeout (α : Type) : Type := (set_tac_timeout : α → ℕ → α) class has_get_tac_timeout (α : Type) : Type := (get_tac_timeout : α → ℕ) class has_mark_fuel_exhausted (α : Type) : Type := (mark_fuel_exhausted : α → α) class has_register_decl_goal (α : Type) : Type := (register_decl_goal : α → string → α) end search_state_instances section eval_trace meta def EVAL_TRACE := tt meta def set_show_eval_trace : bool → tactic unit := tactic.set_bool_option `evaltrace -- meta def eval_trace {α} [has_to_tactic_format α] : α → tactic unit | a := do -- st ← tactic.get_bool_option `evaltrace ff, -- if st || EVAL_TRACE then tactic.trace a else pure () meta def eval_trace {α} [has_to_tactic_format α] : α → tactic unit | a := do { evaltrace_flag ← tactic.get_bool_option `evaltrace ff, -- let trace_flag := tactic.is_trace_enabled_for `EVAL_TRACE, let trace_flag := EVAL_TRACE, let cond := (trace_flag || evaltrace_flag), when cond (tactic.trace a) } end eval_trace section set_env_at_decl meta def get_env_at_decl (decl_nm : name) : tactic environment := do { env ← tactic.get_env, lean_file ← env.decl_olean decl_nm, pure $ environment.for_decl_of_imported_module lean_file decl_nm } meta def set_env_at_decl (decl_nm : name) : tactic unit := do { env ← get_env_at_decl decl_nm, eval_trace format!"[set_env_at_decl] GOT ENV AT DECL {decl_nm}", tactic.set_env_core env, eval_trace format!"[set_env_at_decl] SET ENV AT DECL {decl_nm}" } end set_env_at_decl
16e5a5fbab62dd0c0bd81a6b04630db0ca186d3e
b7f22e51856f4989b970961f794f1c435f9b8f78
/library/theories/analysis/real_limit.lean
ff9e05b0c8dea6d69c22b4cf12dd0bf1b6966e82
[ "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
29,225
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 Instantiates the reals as a Banach space. -/ import .metric_space data.real.complete data.set .normed_space open real classical analysis nat topology noncomputable theory /- sup and inf -/ -- Expresses completeness, sup, and inf in a manner that is less constructive, but more convenient, -- than the way it is done in data.real.complete. -- Issue: real.sup and real.inf conflict with sup and inf in lattice. -- Perhaps put algebra sup and inf into a namespace? namespace real open set private definition exists_is_sup {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) : ∃ y, is_sup X y := let x := some (and.left H), b := some (and.right H) in exists_is_sup_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H)) private definition sup_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) := some (exists_is_sup H) private definition sup_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b)) : is_sup X (sup_aux H) := some_spec (exists_is_sup H) definition sup (X : set ℝ) : ℝ := if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b) then sup_aux H else 0 proposition le_sup {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : x ≤ sup X := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b), from and.intro (exists.intro x Hx) (exists.intro b Hb), by rewrite [↑sup, dif_pos H]; exact and.left (sup_aux_spec H) x Hx proposition sup_le {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : sup X ≤ b := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → x ≤ b), from and.intro HX (exists.intro b Hb), by rewrite [↑sup, dif_pos H]; exact and.right (sup_aux_spec H) b Hb proposition exists_mem_and_lt_of_lt_sup {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : b < sup X) : ∃ x, x ∈ X ∧ b < x := have ¬ ∀ x, x ∈ X → x ≤ b, from assume H, not_le_of_gt Hb (sup_le HX H), obtain x (Hx : ¬ (x ∈ X → x ≤ b)), from exists_not_of_not_forall this, exists.intro x (have x ∈ X ∧ ¬ x ≤ b, by rewrite [-not_implies_iff_and_not]; apply Hx, and.intro (and.left this) (lt_of_not_ge (and.right this))) private definition exists_is_inf {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) : ∃ y, is_inf X y := let x := some (and.left H), b := some (and.right H) in exists_is_inf_of_inh_of_bdd X x (some_spec (and.left H)) b (some_spec (and.right H)) private definition inf_aux {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) := some (exists_is_inf H) private definition inf_aux_spec {X : set ℝ} (H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x)) : is_inf X (inf_aux H) := some_spec (exists_is_inf H) definition inf (X : set ℝ) : ℝ := if H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x) then inf_aux H else 0 proposition inf_le {x : ℝ} {X : set ℝ} (Hx : x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : inf X ≤ x := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x), from and.intro (exists.intro x Hx) (exists.intro b Hb), by rewrite [↑inf, dif_pos H]; exact and.left (inf_aux_spec H) x Hx proposition le_inf {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : b ≤ inf X := have H : (∃ x, x ∈ X) ∧ (∃ b, ∀ x, x ∈ X → b ≤ x), from and.intro HX (exists.intro b Hb), by rewrite [↑inf, dif_pos H]; exact and.right (inf_aux_spec H) b Hb proposition exists_mem_and_lt_of_inf_lt {X : set ℝ} (HX : ∃ x, x ∈ X) {b : ℝ} (Hb : inf X < b) : ∃ x, x ∈ X ∧ x < b := have ¬ ∀ x, x ∈ X → b ≤ x, from assume H, not_le_of_gt Hb (le_inf HX H), obtain x (Hx : ¬ (x ∈ X → b ≤ x)), from exists_not_of_not_forall this, exists.intro x (have x ∈ X ∧ ¬ b ≤ x, by rewrite [-not_implies_iff_and_not]; apply Hx, and.intro (and.left this) (lt_of_not_ge (and.right this))) section local attribute mem [reducible] -- TODO: is there a better place to put this? proposition image_neg_eq (X : set ℝ) : (λ x, -x) ' X = {x | -x ∈ X} := set.ext (take x, iff.intro (assume H, obtain y [(Hy₁ : y ∈ X) (Hy₂ : -y = x)], from H, show -x ∈ X, by rewrite [-Hy₂, neg_neg]; exact Hy₁) (assume H : -x ∈ X, exists.intro (-x) (and.intro H !neg_neg))) proposition sup_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → b ≤ x) : sup {x | -x ∈ X} = - inf X := let negX := {x | -x ∈ X} in have nonempty_negX : ∃ x, x ∈ negX, from obtain x Hx, from nonempty_X, have -(-x) ∈ X, by rewrite neg_neg; apply Hx, exists.intro (-x) this, have H₁ : ∀ x, x ∈ negX → x ≤ - inf X, from take x, assume H, have inf X ≤ -x, from inf_le H Hb, show x ≤ - inf X, from le_neg_of_le_neg this, have H₂ : ∀ x, x ∈ X → -sup negX ≤ x, from take x, assume H, have -(-x) ∈ X, by rewrite neg_neg; apply H, have -x ≤ sup negX, from le_sup this H₁, show -sup negX ≤ x, from !neg_le_of_neg_le this, eq_of_le_of_ge (show sup negX ≤ - inf X, from sup_le nonempty_negX H₁) (show -inf X ≤ sup negX, from !neg_le_of_neg_le (le_inf nonempty_X H₂)) proposition inf_neg {X : set ℝ} (nonempty_X : ∃ x, x ∈ X) {b : ℝ} (Hb : ∀ x, x ∈ X → x ≤ b) : inf {x | -x ∈ X} = - sup X := let negX := {x | -x ∈ X} in have nonempty_negX : ∃ x, x ∈ negX, from obtain x Hx, from nonempty_X, have -(-x) ∈ X, by rewrite neg_neg; apply Hx, exists.intro (-x) this, have Hb' : ∀ x, x ∈ negX → -b ≤ x, from take x, assume H, !neg_le_of_neg_le (Hb _ H), have HX : X = {x | -x ∈ negX}, from set.ext (take x, by rewrite [↑set_of, ↑mem, +neg_neg]), show inf {x | -x ∈ X} = - sup X, by rewrite [HX at {2}, sup_neg nonempty_negX Hb', neg_neg] end end real /- the reals form a complete metric space -/ namespace real proposition approaches_at_infty_intro {X : ℕ → ℝ} {y : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε) : (X ⟶ y [at ∞]) := metric_space.approaches_at_infty_intro H proposition approaches_at_infty_dest {X : ℕ → ℝ} {y : ℝ} (H : X ⟶ y [at ∞]) : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε := metric_space.approaches_at_infty_dest H proposition approaches_at_infty_intro' {X : ℕ → ℝ} {y : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) ≤ ε) : (X ⟶ y [at ∞]) := approaches_at_infty_intro' H end real namespace analysis theorem dist_eq_abs (x y : real) : dist x y = abs (x - y) := rfl open pnat subtype local postfix ⁻¹ := pnat.inv private definition pnat.succ (n : ℕ) : ℕ+ := tag (succ n) !succ_pos private definition r_seq_of (X : ℕ → ℝ) : r_seq := λ n, X (elt_of n) private lemma rate_of_cauchy_aux {X : ℕ → ℝ} (H : cauchy X) : ∀ k : ℕ+, ∃ N : ℕ+, ∀ m n : ℕ+, m ≥ N → n ≥ N → abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹ := take k : ℕ+, have H1 : (k⁻¹ >[rat] (rat.of_num 0)), from !pnat.inv_pos, have H2 : (of_rat k⁻¹ > of_rat (rat.of_num 0)), from !of_rat_lt_of_rat_of_lt H1, obtain (N : ℕ) (H : ∀ m n, m ≥ N → n ≥ N → abs (X m - X n) < of_rat k⁻¹), from H _ H2, exists.intro (pnat.succ N) (take m n : ℕ+, assume Hm : m ≥ (pnat.succ N), assume Hn : n ≥ (pnat.succ N), have Hm' : elt_of m ≥ N, begin apply le.trans, apply le_succ, apply Hm end, have Hn' : elt_of n ≥ N, begin apply le.trans, apply le_succ, apply Hn end, show abs (X (elt_of m) - X (elt_of n)) ≤ of_rat k⁻¹, from le_of_lt (H _ _ Hm' Hn')) private definition rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) (k : ℕ+) : ℕ+ := some (rate_of_cauchy_aux H k) private lemma cauchy_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : cauchy_with_rate (r_seq_of X) (rate_of_cauchy H) := take k : ℕ+, some_spec (rate_of_cauchy_aux H k) private lemma converges_to_with_rate_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : ∃ l Nb, converges_to_with_rate (r_seq_of X) l Nb := begin apply exists.intro, apply exists.intro, apply converges_to_with_rate_of_cauchy_with_rate, exact cauchy_with_rate_of_cauchy H end theorem converges_seq_of_cauchy {X : ℕ → ℝ} (H : cauchy X) : converges_seq X := obtain l Nb (conv : converges_to_with_rate (r_seq_of X) l Nb), from converges_to_with_rate_of_cauchy H, exists.intro l (real.approaches_at_infty_intro take ε : ℝ, suppose ε > 0, obtain (k' : ℕ) (Hn : 1 / succ k' < ε), from archimedean_small `ε > 0`, let k : ℕ+ := tag (succ k') !succ_pos, N : ℕ+ := Nb k in have Hk : real.of_rat k⁻¹ < ε, by rewrite [↑pnat.inv, of_rat_divide]; exact Hn, exists.intro (elt_of N) (take n : ℕ, assume Hn : n ≥ elt_of N, let n' : ℕ+ := tag n (nat.lt_of_lt_of_le (has_property N) Hn) in have abs (X n - l) ≤ real.of_rat k⁻¹, by apply conv k n' Hn, show abs (X n - l) < ε, from lt_of_le_of_lt this Hk)) end analysis definition complete_metric_space_real [trans_instance] : complete_metric_space ℝ := ⦃complete_metric_space, metric_space_real, complete := @analysis.converges_seq_of_cauchy ⦄ /- the real numbers can be viewed as a banach space -/ definition real_vector_space_real : real_vector_space ℝ := ⦃ real_vector_space, real.discrete_linear_ordered_field, smul := mul, smul_left_distrib := left_distrib, smul_right_distrib := right_distrib, mul_smul := mul.assoc, one_smul := one_mul ⦄ definition banach_space_real [trans_instance] : banach_space ℝ := ⦃ banach_space, real_vector_space_real, norm := abs, norm_zero := abs_zero, eq_zero_of_norm_eq_zero := λ a H, eq_zero_of_abs_eq_zero H, norm_triangle := abs_add_le_abs_add_abs, norm_smul := abs_mul, complete := λ X H, analysis.complete ℝ H ⦄ namespace real open topology set open normed_vector_space section variable {f : ℝ → ℝ} theorem continuous_dest (H : continuous f) : ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε := normed_vector_space.continuous_dest H theorem continuous_intro (H : ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) : continuous f := normed_vector_space.continuous_intro H theorem continuous_at_dest {x : ℝ} (H : continuous_at f x) : ∀ ε : ℝ, ε > 0 → (∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) := normed_vector_space.continuous_at_dest H theorem continuous_at_intro {x : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) : continuous_at f x := normed_vector_space.continuous_at_intro H theorem continuous_at_within_intro {x : ℝ} {s : set ℝ} (H : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε) : continuous_at_on f x s := normed_vector_space.continuous_at_within_intro H theorem continuous_at_on_dest {x : ℝ} {s : set ℝ} (Hfx : continuous_at_on f x s) : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε := normed_vector_space.continuous_at_on_dest Hfx theorem continuous_on_intro {s : set ℝ} (H : ∀ x ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε) : continuous_on f s := normed_vector_space.continuous_on_intro H theorem continuous_on_dest {s : set ℝ} (H : continuous_on f s) {x : ℝ} (Hxs : x ∈ s) : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε := normed_vector_space.continuous_on_dest H Hxs end section approaches open set.filter set topology variables {X : Type} {F : filter X} {f : X → ℝ} {y : ℝ} proposition approaches_intro (H : ∀ ε, ε > 0 → eventually (λ x, abs ((f x) - y) < ε) F) : (f ⟶ y) F := normed_vector_space.approaches_intro H proposition approaches_dest (H : (f ⟶ y) F) {ε : ℝ} (εpos : ε > 0) : eventually (λ x, abs ((f x) - y) < ε) F := normed_vector_space.approaches_dest H εpos variables (F f y) proposition approaches_iff : ((f ⟶ y) F) ↔ (∀ ε, ε > 0 → eventually (λ x, abs ((f x) - y) < ε) F) := iff.intro approaches_dest approaches_intro end approaches section variable {f : ℝ → ℝ} proposition approaches_at_dest {y x : ℝ} (H : f ⟶ y [at x]) ⦃ε : ℝ⦄ (εpos : ε > 0) : ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε := metric_space.approaches_at_dest H εpos proposition approaches_at_intro {y x : ℝ} (H : ∀ ε, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε) : f ⟶ y [at x] := metric_space.approaches_at_intro H proposition approaches_at_iff (y x : ℝ) : f ⟶ y [at x] ↔ (∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε) := iff.intro approaches_at_dest approaches_at_intro end end real /- limits under pointwise operations -/ section limit_operations open set variable {A : Type} variables {X Y : A → ℝ} variables {x y : ℝ} variable {F : filter A} proposition mul_left_approaches (c : ℝ) (HX : (X ⟶ x) F) : ((λ n, c * X n) ⟶ c * x) F := smul_approaches HX c proposition mul_right_approaches (c : ℝ) (HX : (X ⟶ x) F) : ((λ n, X n * c) ⟶ x * c) F := have (λ n, X n * c) = (λ n, c * X n), from funext (λ n, !mul.comm), by rewrite [this, mul.comm]; apply mul_left_approaches _ HX theorem approaches_squeeze (HX : (X ⟶ x) F) (HY : (Y ⟶ x) F) {Z : A → ℝ} (HZX : filter.eventually (λ n, X n ≤ Z n) F) (HZY : filter.eventually (λ n, Z n ≤ Y n) F) : (Z ⟶ x) F := begin apply real.approaches_intro, intro ε Hε, apply filter.eventually_mp, rotate 1, apply filter.eventually_and, apply real.approaches_dest HX Hε, apply real.approaches_dest HY Hε, apply filter.eventually_mono, apply filter.eventually_and HZX HZY, intros x' Hlo Hdst, change abs (Z x' - x) < ε, cases em (x ≤ Z x') with HxleZ HxnleZ, -- annoying linear arith {have Y x' - x = (Z x' - x) + (Y x' - Z x'), by rewrite -sub_eq_sub_add_sub, have H : abs (Y x' - x) < ε, from and.right Hdst, rewrite this at H, have H'' : Y x' - Z x' ≥ 0, from sub_nonneg_of_le (and.right Hlo), have H' : Z x' - x ≥ 0, from sub_nonneg_of_le HxleZ, krewrite [abs_of_nonneg H', abs_of_nonneg (add_nonneg H' H'') at H], apply lt_of_add_lt_of_nonneg_left H H''}, {have X x' - x = (Z x' - x) + (X x' - Z x'), by rewrite -sub_eq_sub_add_sub, have H : abs (X x' - x) < ε, from and.left Hdst, rewrite this at H, have H' : x - Z x' > 0, from sub_pos_of_lt (lt_of_not_ge HxnleZ), have H'2 : Z x' - x < 0, by rewrite [-neg_neg (Z x' - x)]; apply neg_neg_of_pos; rewrite [neg_sub]; apply H', have H'' : X x' - Z x' ≤ 0, from sub_nonpos_of_le (and.left Hlo), krewrite [abs_of_neg H'2, abs_of_neg (add_neg_of_neg_of_nonpos H'2 H'') at H, neg_add at H], apply lt_of_add_lt_of_nonneg_left H, apply neg_nonneg_of_nonpos H''} end proposition approaches_of_abs_sub_approaches {F} (Habs : ((λ n, abs (X n - x)) ⟶ 0) F) : (X ⟶ x) F := begin apply real.approaches_intro, intro ε Hε, apply set.filter.eventually_mono, apply real.approaches_dest Habs Hε, intro n Hn, have Hn' : abs (abs (X n - x) - 0) < ε, from Hn, rewrite [sub_zero at Hn', abs_abs at Hn'], exact Hn' end proposition abs_sub_approaches_of_approaches {F} (HX : (X ⟶ x) F) : ((λ n, abs (X n - x)) ⟶ 0) F := begin apply real.approaches_intro, intros ε Hε, apply set.filter.eventually_mono, apply real.approaches_dest HX Hε, intro n Hn, have Hn' : abs (abs (X n - x) - 0) < ε, by rewrite [sub_zero, abs_abs]; apply Hn, exact Hn' end proposition bounded_of_approaches_real {F} (HX : (X ⟶ x) F) : ∃ K : ℝ, filter.eventually (λ n, abs (X n) ≤ K) F := begin cases bounded_of_converges HX with K HK, existsi K + abs x, apply filter.eventually_mono HK, intro x' Hx', note Hle := abs_sub_abs_le_abs_sub (X x') x, apply le.trans, apply le_add_of_sub_right_le, apply Hle, apply add_le_add_right, apply Hx' end proposition mul_approaches {F} (HX : (X ⟶ x) F) (HY : (Y ⟶ y) F) : ((λ n, X n * Y n) ⟶ x * y) F := obtain K HK, from bounded_of_approaches_real HX, have Habsle : filter.eventually (λ n, abs (X n * Y n - x * y) ≤ K * abs (Y n - y) + abs y * abs (X n - x)) F, begin have Heq : ∀ n, X n * Y n - x * y = (X n * Y n - X n * y) + (X n * y - x * y), by intro n; rewrite [-sub_add_cancel (X n * Y n) (X n * y) at {1}, sub_eq_add_neg, *add.assoc], apply filter.eventually_mono HK, intro x' Hx', apply le.trans, rewrite Heq, apply abs_add_le_abs_add_abs, apply add_le_add, rewrite [-mul_sub_left_distrib, abs_mul], apply mul_le_mul_of_nonneg_right, apply Hx', apply abs_nonneg, rewrite [-mul_sub_right_distrib, abs_mul, mul.comm], apply le.refl end, have Hdifflim : ((λ n, abs (X n * Y n - x * y)) ⟶ 0) F, begin apply approaches_squeeze, rotate 2, intro, apply filter.eventually_mono HK, intro x' Hx', apply abs_nonneg, apply Habsle, apply approaches_constant, rewrite -{0}zero_add, apply add_approaches, krewrite -(mul_zero K), apply mul_left_approaches, apply abs_sub_approaches_of_approaches, exact HY, krewrite -(mul_zero (abs y)), apply mul_left_approaches, apply abs_sub_approaches_of_approaches, exact HX end, approaches_of_abs_sub_approaches Hdifflim proposition mul_approaches_zero_of_approaches_zero_of_approaches (HX : (X ⟶ 0) F) (HY : (Y ⟶ y) F) : ((λ z, X z * Y z) ⟶ 0) F := begin krewrite [-zero_mul y], apply mul_approaches, exact HX, exact HY end proposition mul_approaches_zero_of_approaches_of_approaches_zero (HX : (X ⟶ y) F) (HY : (Y ⟶ 0) F) : ((λ z, X z * Y z) ⟶ 0) F := begin have H : (λ z, X z * Y z) = (λ z, Y z * X z), from funext (λ a, !mul.comm), rewrite H, exact mul_approaches_zero_of_approaches_zero_of_approaches HY HX end proposition abs_approaches_zero_of_approaches_zero (HX : (X ⟶ 0) F) : ((λ n, abs (X n)) ⟶ 0) F := norm_approaches_zero_of_approaches_zero HX proposition approaches_zero_of_abs_approaches_zero (HX : ((λ n, abs (X n)) ⟶ 0) F) : (X ⟶ 0) F := approaches_zero_of_norm_approaches_zero HX proposition abs_approaches_zero_iff : ((λ n, abs (X n)) ⟶ 0) F ↔ (X ⟶ 0) F := iff.intro approaches_zero_of_abs_approaches_zero abs_approaches_zero_of_approaches_zero end limit_operations /- monotone sequences -/ section monotone_sequences open real set variable {X : ℕ → ℝ} proposition converges_to_seq_sup_of_nondecreasing (nondecX : nondecreasing X) {b : ℝ} (Hb : ∀ i, X i ≤ b) : X ⟶ sup (X ' univ) [at ∞] := real.approaches_at_infty_intro (let sX := sup (X ' univ) in have Xle : ∀ i, X i ≤ sX, from take i, have ∀ x, x ∈ X ' univ → x ≤ b, from (take x, assume H, obtain i [H' (Hi : X i = x)], from H, by rewrite -Hi; exact Hb i), show X i ≤ sX, from le_sup (mem_image_of_mem X !mem_univ) this, have exX : ∃ x, x ∈ X ' univ, from exists.intro (X 0) (mem_image_of_mem X !mem_univ), take ε, assume epos : ε > 0, have sX - ε < sX, from !sub_lt_of_pos epos, obtain x' [(H₁x' : x' ∈ X ' univ) (H₂x' : sX - ε < x')], from exists_mem_and_lt_of_lt_sup exX this, obtain i [H' (Hi : X i = x')], from H₁x', have Hi' : ∀ j, j ≥ i → sX - ε < X j, from take j, assume Hj, lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj), exists.intro i (take j, assume Hj : j ≥ i, have X j - sX ≤ 0, from sub_nonpos_of_le (Xle j), have eq₁ : abs (X j - sX) = sX - X j, by rewrite [abs_of_nonpos this, neg_sub], have sX - ε < X j, from lt_of_lt_of_le (by rewrite Hi; apply H₂x') (nondecX Hj), have sX < X j + ε, from lt_add_of_sub_lt_right this, have sX - X j < ε, from sub_lt_left_of_lt_add this, show (abs (X j - sX)) < ε, by rewrite eq₁; exact this)) proposition converges_to_seq_inf_of_nonincreasing (nonincX : nonincreasing X) {b : ℝ} (Hb : ∀ i, b ≤ X i) : X ⟶ inf (X ' univ) [at ∞] := have H₁ : ∃ x, x ∈ X ' univ, from exists.intro (X 0) (mem_image_of_mem X !mem_univ), have H₂ : ∀ x, x ∈ X ' univ → b ≤ x, from (take x, assume H, obtain i [Hi₁ (Hi₂ : X i = x)], from H, show b ≤ x, by rewrite -Hi₂; apply Hb i), have H₃ : {x : ℝ | -x ∈ X ' univ} = {x : ℝ | x ∈ (λ n, -X n) ' univ}, from calc {x : ℝ | -x ∈ X ' univ} = (λ y, -y) ' (X ' univ) : by rewrite image_neg_eq ... = {x : ℝ | x ∈ (λ n, -X n) ' univ} : image_comp, have H₄ : ∀ i, - X i ≤ - b, from take i, neg_le_neg (Hb i), begin apply approaches_neg, -- need krewrite here krewrite [-sup_neg H₁ H₂, H₃, -nondecreasing_neg_iff at nonincX], apply converges_to_seq_sup_of_nondecreasing nonincX H₄ end end monotone_sequences /- x^n converges to 0 if abs x < 1 -/ section xn open nat set theorem pow_approaches_zero_at_infty {x : ℝ} (H : abs x < 1) : (λ n, x^n) ⟶ 0 [at ∞] := suffices H' : (λ n, (abs x)^n) ⟶ 0 [at ∞], from have (λ n, (abs x)^n) = (λ n, abs (x^n)), from funext (take n, eq.symm !abs_pow), by rewrite this at H'; exact approaches_zero_of_abs_approaches_zero H', let aX := (λ n, (abs x)^n), iaX := real.inf (aX ' univ), asX := (λ n, (abs x)^(succ n)) in have noninc_aX : nonincreasing aX, from nonincreasing_of_forall_ge_succ (take i, have (abs x) * (abs x)^i ≤ 1 * (abs x)^i, from mul_le_mul_of_nonneg_right (le_of_lt H) (!pow_nonneg_of_nonneg !abs_nonneg), have (abs x) * (abs x)^i ≤ (abs x)^i, by krewrite one_mul at this; exact this, show (abs x) ^ (succ i) ≤ (abs x)^i, by rewrite pow_succ; apply this), have bdd_aX : ∀ i, 0 ≤ aX i, from take i, !pow_nonneg_of_nonneg !abs_nonneg, have aXconv : aX ⟶ iaX [at ∞], proof converges_to_seq_inf_of_nonincreasing noninc_aX bdd_aX qed, have asXconv : asX ⟶ iaX [at ∞], from tendsto_succ_at_infty aXconv, have asXconv' : asX ⟶ (abs x) * iaX [at ∞], from mul_left_approaches (abs x) aXconv, have iaX = (abs x) * iaX, from sorry, -- converges_to_seq_unique asXconv asXconv', have iaX = 0, from eq_zero_of_mul_eq_self_left (ne_of_lt H) (eq.symm this), show aX ⟶ 0 [at ∞], begin rewrite -this, exact aXconv end --from this ▸ aXconv end xn /- continuity on the reals -/ /-namespace real open topology set open normed_vector_space section variable {f : ℝ → ℝ} theorem continuous_dest (H : continuous f) : ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε := normed_vector_space.continuous_dest H theorem continuous_intro (H : ∀ x : ℝ, ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) : continuous f := normed_vector_space.continuous_intro H theorem continuous_at_dest {x : ℝ} (H : continuous_at f x) : ∀ ε : ℝ, ε > 0 → (∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) := normed_vector_space.continuous_at_dest H theorem continuous_at_intro {x : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ δ : ℝ, δ > 0 ∧ ∀ x' : ℝ, abs (x' - x) < δ → abs (f x' - f x) < ε) : continuous_at f x := normed_vector_space.continuous_at_intro H theorem continuous_at_within_intro {x : ℝ} {s : set ℝ} (H : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε) : continuous_at_on f x s := normed_vector_space.continuous_at_within_intro H theorem continuous_at_on_dest {x : ℝ} {s : set ℝ} (Hfx : continuous_at_on f x s) : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε := normed_vector_space.continuous_at_on_dest Hfx theorem continuous_on_intro {s : set ℝ} (H : ∀ x ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε) : continuous_on f s := normed_vector_space.continuous_on_intro H theorem continuous_on_dest {s : set ℝ} (H : continuous_on f s) {x : ℝ} (Hxs : x ∈ s) : ∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, x' ∈ s → abs (x' - x) < δ → abs ((f x') - (f x)) < ε := normed_vector_space.continuous_on_dest H Hxs end section variable {f : ℕ → ℝ} proposition approaches_at_infty_intro {y : ℝ} (H : ∀ ε, ε > 0 → ∃ N, ∀ n, n ≥ N → abs ((f n) - y) < ε) : f ⟶ y [at ∞] := normed_vector_space.approaches_at_infty_intro H proposition approaches_at_infty_dest {y : ℝ} (H : f ⟶ y [at ∞]) ⦃ε : ℝ⦄ (εpos : ε > 0) : ∃ N, ∀ ⦃n⦄, n ≥ N → abs ((f n) - y) < ε := approaches_at_infty_dest H εpos proposition approaches_at_infty_iff (y : ℝ) : f ⟶ y [at ∞] ↔ (∀ ε, ε > 0 → ∃ N, ∀ ⦃n⦄, n ≥ N → abs((f n) - y) < ε) := iff.intro approaches_at_infty_dest approaches_at_infty_intro end section variable {f : ℝ → ℝ} proposition approaches_at_dest {y x : ℝ} (H : f ⟶ y [at x]) ⦃ε : ℝ⦄ (εpos : ε > 0) : ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε := approaches_at_dest H εpos proposition approaches_at_intro {y x : ℝ} (H : ∀ ε, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε) : f ⟶ y [at x] := approaches_at_intro H proposition approaches_at_iff (y x : ℝ) : f ⟶ y [at x] ↔ (∀ ⦃ε⦄, ε > 0 → ∃ δ, δ > 0 ∧ ∀ ⦃x'⦄, abs (x' - x) < δ → x' ≠ x → abs ((f x') - y) < ε) := iff.intro approaches_at_dest approaches_at_intro /-proposition approaches_seq_real_intro {X : ℕ → ℝ} {y : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε) : (X ⟶ y [at ∞]) := metric_space.approaches_at_infty_intro H proposition approaches_seq_real_elim {X : ℕ → ℝ} {y : ℝ} (H : X ⟶ y [at ∞]) : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) < ε := metric_space.approaches_at_infty_dest H proposition approaches_seq_real_intro' {X : ℕ → ℝ} {y : ℝ} (H : ∀ ⦃ε : ℝ⦄, ε > 0 → ∃ N : ℕ, ∀ {n}, n ≥ N → abs (X n - y) ≤ ε) : (X ⟶ y [at ∞]) := approaches_at_infty_intro' H-/ end end real-/ section continuous open topology variable {f : ℝ → ℝ} variable (Hf : continuous f) include Hf theorem pos_on_nbhd_of_cts_of_pos {b : ℝ} (Hb : f b > 0) : ∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (y - b) < δ → f y > 0 := begin let Hcont := real.continuous_dest Hf b Hb, cases Hcont with δ Hδ, existsi δ, split, exact and.left Hδ, intro y Hy, let Hy' := and.right Hδ y Hy, note Hlt := sub_lt_of_abs_sub_lt_left Hy', rewrite sub_self at Hlt, assumption end theorem neg_on_nbhd_of_cts_of_neg {b : ℝ} (Hb : f b < 0) : ∃ δ : ℝ, δ > 0 ∧ ∀ y, abs (y - b) < δ → f y < 0 := begin let Hcont := real.continuous_dest Hf b (neg_pos_of_neg Hb), cases Hcont with δ Hδ, existsi δ, split, exact and.left Hδ, intro y Hy, let Hy' := and.right Hδ y Hy, let Hlt := sub_lt_of_abs_sub_lt_right Hy', note Hlt' := lt_add_of_sub_lt_left Hlt, rewrite [add.comm at Hlt', -sub_eq_add_neg at Hlt', sub_self at Hlt'], assumption end theorem continuous_mul_of_continuous {g : ℝ → ℝ} (Hcong : continuous g) : continuous (λ x, f x * g x) := begin apply continuous_of_forall_continuous_at, intro x, apply continuous_at_of_tendsto_at, apply mul_approaches, all_goals apply tendsto_at_of_continuous_at, all_goals apply forall_continuous_at_of_continuous, apply Hf, apply Hcong end end continuous
fe8d60c2b7684bc282443ef904f64dd609b6365a
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/topology/order/basic.lean
a17106de53df54568ded17e0b3d18ab90dc49c48
[ "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
121,972
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov -/ import data.set.intervals.pi import data.set.pointwise.interval import order.filter.interval import topology.support import topology.algebra.order.left_right /-! # Theory of topology on ordered spaces > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. ## Main definitions The order topology on an ordered space is the topology generated by all open intervals (or equivalently by those of the form `(-∞, a)` and `(b, +∞)`). We define it as `preorder.topology α`. However, we do *not* register it as an instance (as many existing ordered types already have topologies, which would be equal but not definitionally equal to `preorder.topology α`). Instead, we introduce a class `order_topology α` (which is a `Prop`, also known as a mixin) saying that on the type `α` having already a topological space structure and a preorder structure, the topological structure is equal to the order topology. We also introduce another (mixin) class `order_closed_topology α` saying that the set of points `(x, y)` with `x ≤ y` is closed in the product space. This is automatically satisfied on a linear order with the order topology. We prove many basic properties of such topologies. ## Main statements This file contains the proofs of the following facts. For exact requirements (`order_closed_topology` vs `order_topology`, `preorder` vs `partial_order` vs `linear_order` etc) see their statements. ### Open / closed sets * `is_open_lt` : if `f` and `g` are continuous functions, then `{x | f x < g x}` is open; * `is_open_Iio`, `is_open_Ioi`, `is_open_Ioo` : open intervals are open; * `is_closed_le` : if `f` and `g` are continuous functions, then `{x | f x ≤ g x}` is closed; * `is_closed_Iic`, `is_closed_Ici`, `is_closed_Icc` : closed intervals are closed; * `frontier_le_subset_eq`, `frontier_lt_subset_eq` : frontiers of both `{x | f x ≤ g x}` and `{x | f x < g x}` are included by `{x | f x = g x}`; * `exists_Ioc_subset_of_mem_nhds`, `exists_Ico_subset_of_mem_nhds` : if `x < y`, then any neighborhood of `x` includes an interval `[x, z)` for some `z ∈ (x, y]`, and any neighborhood of `y` includes an interval `(z, y]` for some `z ∈ [x, y)`. ### Convergence and inequalities * `le_of_tendsto_of_tendsto` : if `f` converges to `a`, `g` converges to `b`, and eventually `f x ≤ g x`, then `a ≤ b` * `le_of_tendsto`, `ge_of_tendsto` : if `f` converges to `a` and eventually `f x ≤ b` (resp., `b ≤ f x`), then `a ≤ b` (resp., `b ≤ a); we also provide primed versions that assume the inequalities to hold for all `x`. ### Min, max, `Sup` and `Inf` * `continuous.min`, `continuous.max`: pointwise `min`/`max` of two continuous functions is continuous. * `tendsto.min`, `tendsto.max` : if `f` tends to `a` and `g` tends to `b`, then their pointwise `min`/`max` tend to `min a b` and `max a b`, respectively. * `tendsto_of_tendsto_of_tendsto_of_le_of_le` : theorem known as squeeze theorem, sandwich theorem, theorem of Carabinieri, and two policemen (and a drunk) theorem; if `g` and `h` both converge to `a`, and eventually `g x ≤ f x ≤ h x`, then `f` converges to `a`. ## Implementation notes We do _not_ register the order topology as an instance on a preorder (or even on a linear order). Indeed, on many such spaces, a topology has already been constructed in a different way (think of the discrete spaces `ℕ` or `ℤ`, or `ℝ` that could inherit a topology as the completion of `ℚ`), and is in general not defeq to the one generated by the intervals. We make it available as a definition `preorder.topology α` though, that can be registered as an instance when necessary, or for specific types. -/ open set filter topological_space open function open order_dual (to_dual of_dual) open_locale topology classical filter universes u v w variables {α : Type u} {β : Type v} {γ : Type w} /-- A topology on a set which is both a topological space and a preorder is _order-closed_ if the set of points `(x, y)` with `x ≤ y` is closed in the product space. We introduce this as a mixin. This property is satisfied for the order topology on a linear order, but it can be satisfied more generally, and suffices to derive many interesting properties relating order and topology. -/ class order_closed_topology (α : Type*) [topological_space α] [preorder α] : Prop := (is_closed_le' : is_closed {p : α × α | p.1 ≤ p.2}) instance [topological_space α] [h : first_countable_topology α] : first_countable_topology αᵒᵈ := h instance [topological_space α] [h : second_countable_topology α] : second_countable_topology αᵒᵈ := h lemma dense.order_dual [topological_space α] {s : set α} (hs : dense s) : dense (order_dual.of_dual ⁻¹' s) := hs section order_closed_topology section preorder variables [topological_space α] [preorder α] [t : order_closed_topology α] include t namespace subtype instance {p : α → Prop} : order_closed_topology (subtype p) := have this : continuous (λ (p : (subtype p) × (subtype p)), ((p.fst : α), (p.snd : α))) := (continuous_subtype_coe.comp continuous_fst).prod_mk (continuous_subtype_coe.comp continuous_snd), order_closed_topology.mk (t.is_closed_le'.preimage this) end subtype lemma is_closed_le_prod : is_closed {p : α × α | p.1 ≤ p.2} := t.is_closed_le' lemma is_closed_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_closed {b | f b ≤ g b} := continuous_iff_is_closed.mp (hf.prod_mk hg) _ is_closed_le_prod lemma is_closed_le' (a : α) : is_closed {b | b ≤ a} := is_closed_le continuous_id continuous_const lemma is_closed_Iic {a : α} : is_closed (Iic a) := is_closed_le' a lemma is_closed_ge' (a : α) : is_closed {b | a ≤ b} := is_closed_le continuous_const continuous_id lemma is_closed_Ici {a : α} : is_closed (Ici a) := is_closed_ge' a instance : order_closed_topology αᵒᵈ := ⟨(@order_closed_topology.is_closed_le' α _ _ _).preimage continuous_swap⟩ lemma is_closed_Icc {a b : α} : is_closed (Icc a b) := is_closed.inter is_closed_Ici is_closed_Iic @[simp] lemma closure_Icc (a b : α) : closure (Icc a b) = Icc a b := is_closed_Icc.closure_eq @[simp] lemma closure_Iic (a : α) : closure (Iic a) = Iic a := is_closed_Iic.closure_eq @[simp] lemma closure_Ici (a : α) : closure (Ici a) = Ici a := is_closed_Ici.closure_eq lemma le_of_tendsto_of_tendsto {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : f ≤ᶠ[b] g) : a₁ ≤ a₂ := have tendsto (λb, (f b, g b)) b (𝓝 (a₁, a₂)), by rw [nhds_prod_eq]; exact hf.prod_mk hg, show (a₁, a₂) ∈ {p:α×α | p.1 ≤ p.2}, from t.is_closed_le'.mem_of_tendsto this h alias le_of_tendsto_of_tendsto ← tendsto_le_of_eventually_le lemma le_of_tendsto_of_tendsto' {f g : β → α} {b : filter β} {a₁ a₂ : α} [ne_bot b] (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) (h : ∀ x, f x ≤ g x) : a₁ ≤ a₂ := le_of_tendsto_of_tendsto hf hg (eventually_of_forall h) lemma le_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, f c ≤ b) : a ≤ b := le_of_tendsto_of_tendsto lim tendsto_const_nhds h lemma le_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, f c ≤ b) : a ≤ b := le_of_tendsto lim (eventually_of_forall h) lemma ge_of_tendsto {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ᶠ c in x, b ≤ f c) : b ≤ a := le_of_tendsto_of_tendsto tendsto_const_nhds lim h lemma ge_of_tendsto' {f : β → α} {a b : α} {x : filter β} [ne_bot x] (lim : tendsto f x (𝓝 a)) (h : ∀ c, b ≤ f c) : b ≤ a := ge_of_tendsto lim (eventually_of_forall h) @[simp] lemma closure_le_eq [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b ≤ g b} = {b | f b ≤ g b} := (is_closed_le hf hg).closure_eq lemma closure_lt_subset_le [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : closure {b | f b < g b} ⊆ {b | f b ≤ g b} := closure_minimal (λ x, le_of_lt) $ is_closed_le hf hg lemma continuous_within_at.closure_le [topological_space β] {f g : β → α} {s : set β} {x : β} (hx : x ∈ closure s) (hf : continuous_within_at f s x) (hg : continuous_within_at g s x) (h : ∀ y ∈ s, f y ≤ g y) : f x ≤ g x := show (f x, g x) ∈ {p : α × α | p.1 ≤ p.2}, from order_closed_topology.is_closed_le'.closure_subset ((hf.prod hg).mem_closure hx h) /-- If `s` is a closed set and two functions `f` and `g` are continuous on `s`, then the set `{x ∈ s | f x ≤ g x}` is a closed set. -/ lemma is_closed.is_closed_le [topological_space β] {f g : β → α} {s : set β} (hs : is_closed s) (hf : continuous_on f s) (hg : continuous_on g s) : is_closed {x ∈ s | f x ≤ g x} := (hf.prod hg).preimage_closed_of_closed hs order_closed_topology.is_closed_le' lemma le_on_closure [topological_space β] {f g : β → α} {s : set β} (h : ∀ x ∈ s, f x ≤ g x) (hf : continuous_on f (closure s)) (hg : continuous_on g (closure s)) ⦃x⦄ (hx : x ∈ closure s) : f x ≤ g x := have s ⊆ {y ∈ closure s | f y ≤ g y}, from λ y hy, ⟨subset_closure hy, h y hy⟩, (closure_minimal this (is_closed_closure.is_closed_le hf hg) hx).2 lemma is_closed.epigraph [topological_space β] {f : β → α} {s : set β} (hs : is_closed s) (hf : continuous_on f s) : is_closed {p : β × α | p.1 ∈ s ∧ f p.1 ≤ p.2} := (hs.preimage continuous_fst).is_closed_le (hf.comp continuous_on_fst subset.rfl) continuous_on_snd lemma is_closed.hypograph [topological_space β] {f : β → α} {s : set β} (hs : is_closed s) (hf : continuous_on f s) : is_closed {p : β × α | p.1 ∈ s ∧ p.2 ≤ f p.1} := (hs.preimage continuous_fst).is_closed_le continuous_on_snd (hf.comp continuous_on_fst subset.rfl) omit t lemma nhds_within_Ici_ne_bot {a b : α} (H₂ : a ≤ b) : ne_bot (𝓝[Ici a] b) := nhds_within_ne_bot_of_mem H₂ @[instance] lemma nhds_within_Ici_self_ne_bot (a : α) : ne_bot (𝓝[≥] a) := nhds_within_Ici_ne_bot (le_refl a) lemma nhds_within_Iic_ne_bot {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iic b] a) := nhds_within_ne_bot_of_mem H @[instance] lemma nhds_within_Iic_self_ne_bot (a : α) : ne_bot (𝓝[≤] a) := nhds_within_Iic_ne_bot (le_refl a) end preorder section partial_order variables [topological_space α] [partial_order α] [t : order_closed_topology α] include t @[priority 90] -- see Note [lower instance priority] instance order_closed_topology.to_t2_space : t2_space α := t2_iff_is_closed_diagonal.2 $ by simpa only [diagonal, le_antisymm_iff] using t.is_closed_le'.inter (is_closed_le continuous_snd continuous_fst) end partial_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] lemma is_open_lt_prod : is_open {p : α × α | p.1 < p.2} := by { simp_rw [← is_closed_compl_iff, compl_set_of, not_lt], exact is_closed_le continuous_snd continuous_fst } lemma is_open_lt [topological_space β] {f g : β → α} (hf : continuous f) (hg : continuous g) : is_open {b | f b < g b} := by simp [lt_iff_not_ge, -not_le]; exact (is_closed_le hg hf).is_open_compl variables {a b : α} lemma is_open_Iio : is_open (Iio a) := is_open_lt continuous_id continuous_const lemma is_open_Ioi : is_open (Ioi a) := is_open_lt continuous_const continuous_id lemma is_open_Ioo : is_open (Ioo a b) := is_open.inter is_open_Ioi is_open_Iio @[simp] lemma interior_Ioi : interior (Ioi a) = Ioi a := is_open_Ioi.interior_eq @[simp] lemma interior_Iio : interior (Iio a) = Iio a := is_open_Iio.interior_eq @[simp] lemma interior_Ioo : interior (Ioo a b) = Ioo a b := is_open_Ioo.interior_eq lemma Ioo_subset_closure_interior : Ioo a b ⊆ closure (interior (Ioo a b)) := by simp only [interior_Ioo, subset_closure] lemma Iio_mem_nhds {a b : α} (h : a < b) : Iio b ∈ 𝓝 a := is_open.mem_nhds is_open_Iio h lemma Ioi_mem_nhds {a b : α} (h : a < b) : Ioi a ∈ 𝓝 b := is_open.mem_nhds is_open_Ioi h lemma Iic_mem_nhds {a b : α} (h : a < b) : Iic b ∈ 𝓝 a := mem_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self lemma Ici_mem_nhds {a b : α} (h : a < b) : Ici a ∈ 𝓝 b := mem_of_superset (Ioi_mem_nhds h) Ioi_subset_Ici_self lemma Ioo_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioo a b ∈ 𝓝 x := is_open.mem_nhds is_open_Ioo ⟨ha, hb⟩ lemma Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ioc_self lemma Ico_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ico a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Ico_self lemma Icc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Icc a b ∈ 𝓝 x := mem_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self lemma eventually_lt_of_tendsto_lt {l : filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : filter.tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a < u := tendsto_nhds.1 h (< u) is_open_Iio hv lemma eventually_gt_of_tendsto_gt {l : filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : filter.tendsto f l (𝓝 v)) : ∀ᶠ a in l, u < f a := tendsto_nhds.1 h (> u) is_open_Ioi hv lemma eventually_le_of_tendsto_lt {l : filter γ} {f : γ → α} {u v : α} (hv : v < u) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, f a ≤ u := (eventually_lt_of_tendsto_lt hv h).mono (λ v, le_of_lt) lemma eventually_ge_of_tendsto_gt {l : filter γ} {f : γ → α} {u v : α} (hv : u < v) (h : tendsto f l (𝓝 v)) : ∀ᶠ a in l, u ≤ f a := (eventually_gt_of_tendsto_gt hv h).mono (λ v, le_of_lt) variables [topological_space γ] /-! ### Neighborhoods to the left and to the right on an `order_closed_topology` Limits to the left and to the right of real functions are defined in terms of neighborhoods to the left and to the right, either open or closed, i.e., members of `𝓝[>] a` and `𝓝[≥] a` on the right, and similarly on the left. Here we simply prove that all right-neighborhoods of a point are equal, and we'll prove later other useful characterizations which require the stronger hypothesis `order_topology α` -/ /-! #### Right neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioo a c ∈ 𝓝[>] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by rw [inter_comm, Ioi_inter_Iio]; exact Ioo_subset_Ioo_left H.1⟩ lemma Ioc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ioc a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Ico_self lemma Icc_mem_nhds_within_Ioi {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[>] b := mem_of_superset (Ioo_mem_nhds_within_Ioi H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ioc_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioc a b] a = 𝓝[>] a := le_antisymm (nhds_within_mono _ Ioc_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioc_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ioo_eq_nhds_within_Ioi {a b : α} (h : a < b) : 𝓝[Ioo a b] a = 𝓝[>] a := le_antisymm (nhds_within_mono _ Ioo_subset_Ioi_self) $ nhds_within_le_of_mem $ Ioo_mem_nhds_within_Ioi $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Ioc_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Ioi h] @[simp] lemma continuous_within_at_Ioo_iff_Ioi [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioo a b) a ↔ continuous_within_at f (Ioi a) a := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Ioi h] /-! #### Left neighborhoods, point excluded -/ lemma Ioo_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioo a c ∈ 𝓝[<] b := by simpa only [dual_Ioo] using Ioo_mem_nhds_within_Ioi (show to_dual b ∈ Ico (to_dual c) (to_dual a), from H.symm) lemma Ico_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ico a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Ioc_self lemma Icc_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[<] b := mem_of_superset (Ioo_mem_nhds_within_Iio H) Ioo_subset_Icc_self @[simp] lemma nhds_within_Ico_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ico a b] b = 𝓝[<] b := by simpa only [dual_Ioc] using nhds_within_Ioc_eq_nhds_within_Ioi h.dual @[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : α} (h : a < b) : 𝓝[Ioo a b] b = 𝓝[<] b := by simpa only [dual_Ioo] using nhds_within_Ioo_eq_nhds_within_Ioi h.dual @[simp] lemma continuous_within_at_Ico_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ico a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Iio h] @[simp] lemma continuous_within_at_Ioo_iff_Iio {a b : α} {f : α → γ} (h : a < b) : continuous_within_at f (Ioo a b) b ↔ continuous_within_at f (Iio b) b := by simp only [continuous_within_at, nhds_within_Ioo_eq_nhds_within_Iio h] /-! #### Right neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≥] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ioc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) : Ioc a c ∈ 𝓝[≥] b := mem_of_superset (Ioo_mem_nhds_within_Ici H) Ioo_subset_Ioc_self lemma Ico_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Ico a c ∈ 𝓝[≥] b := mem_nhds_within.2 ⟨Iio c, is_open_Iio, H.2, by simp only [inter_comm, Ici_inter_Iio, Ico_subset_Ico_left H.1]⟩ lemma Icc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ico a c) : Icc a c ∈ 𝓝[≥] b := mem_of_superset (Ico_mem_nhds_within_Ici H) Ico_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Icc a b] a = 𝓝[≥] a := le_antisymm (nhds_within_mono _ Icc_subset_Ici_self) $ nhds_within_le_of_mem $ Icc_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma nhds_within_Ico_eq_nhds_within_Ici {a b : α} (h : a < b) : 𝓝[Ico a b] a = 𝓝[≥] a := le_antisymm (nhds_within_mono _ (λ x, and.left)) $ nhds_within_le_of_mem $ Ico_mem_nhds_within_Ici $ left_mem_Ico.2 h @[simp] lemma continuous_within_at_Icc_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Ici h] @[simp] lemma continuous_within_at_Ico_iff_Ici [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ico a b) a ↔ continuous_within_at f (Ici a) a := by simp only [continuous_within_at, nhds_within_Ico_eq_nhds_within_Ici h] /-! #### Left neighborhoods, point included -/ lemma Ioo_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ioo a c ∈ 𝓝[≤] b := mem_nhds_within_of_mem_nhds $ is_open.mem_nhds is_open_Ioo H lemma Ico_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) : Ico a c ∈ 𝓝[≤] b := mem_of_superset (Ioo_mem_nhds_within_Iic H) Ioo_subset_Ico_self lemma Ioc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Ioc a c ∈ 𝓝[≤] b := by simpa only [dual_Ico] using Ico_mem_nhds_within_Ici (show to_dual b ∈ Ico (to_dual c) (to_dual a), from H.symm) lemma Icc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) : Icc a c ∈ 𝓝[≤] b := mem_of_superset (Ioc_mem_nhds_within_Iic H) Ioc_subset_Icc_self @[simp] lemma nhds_within_Icc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Icc a b] b = 𝓝[≤] b := by simpa only [dual_Icc] using nhds_within_Icc_eq_nhds_within_Ici h.dual @[simp] lemma nhds_within_Ioc_eq_nhds_within_Iic {a b : α} (h : a < b) : 𝓝[Ioc a b] b = 𝓝[≤] b := by simpa only [dual_Ico] using nhds_within_Ico_eq_nhds_within_Ici h.dual @[simp] lemma continuous_within_at_Icc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Icc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Icc_eq_nhds_within_Iic h] @[simp] lemma continuous_within_at_Ioc_iff_Iic [topological_space β] {a b : α} {f : α → β} (h : a < b) : continuous_within_at f (Ioc a b) b ↔ continuous_within_at f (Iic b) b := by simp only [continuous_within_at, nhds_within_Ioc_eq_nhds_within_Iic h] end linear_order section linear_order variables [topological_space α] [linear_order α] [order_closed_topology α] {f g : β → α} section variables [topological_space β] lemma lt_subset_interior_le (hf : continuous f) (hg : continuous g) : {b | f b < g b} ⊆ interior {b | f b ≤ g b} := interior_maximal (λ p, le_of_lt) $ is_open_lt hf hg lemma frontier_le_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b ≤ g b} ⊆ {b | f b = g b} := begin rw [frontier_eq_closure_inter_closure, closure_le_eq hf hg], rintros b ⟨hb₁, hb₂⟩, refine le_antisymm hb₁ (closure_lt_subset_le hg hf _), convert hb₂ using 2, simp only [not_le.symm], refl end lemma frontier_Iic_subset (a : α) : frontier (Iic a) ⊆ {a} := frontier_le_subset_eq (@continuous_id α _) continuous_const lemma frontier_Ici_subset (a : α) : frontier (Ici a) ⊆ {a} := @frontier_Iic_subset αᵒᵈ _ _ _ _ lemma frontier_lt_subset_eq (hf : continuous f) (hg : continuous g) : frontier {b | f b < g b} ⊆ {b | f b = g b} := by rw ← frontier_compl; convert frontier_le_subset_eq hg hf; simp [ext_iff, eq_comm] lemma continuous_if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf : continuous f) (hg : continuous g) (hf' : continuous_on f' {x | f x ≤ g x}) (hg' : continuous_on g' {x | g x ≤ f x}) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := begin refine continuous_if (λ a ha, hfg _ (frontier_le_subset_eq hf hg ha)) _ (hg'.mono _), { rwa [(is_closed_le hf hg).closure_eq] }, { simp only [not_le], exact closure_lt_subset_le hg hf } end lemma continuous.if_le [topological_space γ] [Π x, decidable (f x ≤ g x)] {f' g' : β → γ} (hf' : continuous f') (hg' : continuous g') (hf : continuous f) (hg : continuous g) (hfg : ∀ x, f x = g x → f' x = g' x) : continuous (λ x, if f x ≤ g x then f' x else g' x) := continuous_if_le hf hg hf'.continuous_on hg'.continuous_on hfg lemma tendsto.eventually_lt {l : filter γ} {f g : γ → α} {y z : α} (hf : tendsto f l (𝓝 y)) (hg : tendsto g l (𝓝 z)) (hyz : y < z) : ∀ᶠ x in l, f x < g x := begin by_cases h : y ⋖ z, { filter_upwards [hf (Iio_mem_nhds hyz), hg (Ioi_mem_nhds hyz)], rw [h.Iio_eq], exact λ x hfx hgx, lt_of_le_of_lt hfx hgx }, { obtain ⟨w, hyw, hwz⟩ := (not_covby_iff hyz).mp h, filter_upwards [hf (Iio_mem_nhds hyw), hg (Ioi_mem_nhds hwz)], exact λ x, lt_trans }, end lemma continuous_at.eventually_lt {x₀ : β} (hf : continuous_at f x₀) (hg : continuous_at g x₀) (hfg : f x₀ < g x₀) : ∀ᶠ x in 𝓝 x₀, f x < g x := tendsto.eventually_lt hf hg hfg @[continuity] lemma continuous.min (hf : continuous f) (hg : continuous g) : continuous (λb, min (f b) (g b)) := by { simp only [min_def], exact hf.if_le hg hf hg (λ x, id) } @[continuity] lemma continuous.max (hf : continuous f) (hg : continuous g) : continuous (λb, max (f b) (g b)) := @continuous.min αᵒᵈ _ _ _ _ _ _ _ hf hg end lemma continuous_min : continuous (λ p : α × α, min p.1 p.2) := continuous_fst.min continuous_snd lemma continuous_max : continuous (λ p : α × α, max p.1 p.2) := continuous_fst.max continuous_snd lemma filter.tendsto.max {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, max (f b) (g b)) b (𝓝 (max a₁ a₂)) := (continuous_max.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) lemma filter.tendsto.min {b : filter β} {a₁ a₂ : α} (hf : tendsto f b (𝓝 a₁)) (hg : tendsto g b (𝓝 a₂)) : tendsto (λb, min (f b) (g b)) b (𝓝 (min a₁ a₂)) := (continuous_min.tendsto (a₁, a₂)).comp (hf.prod_mk_nhds hg) lemma filter.tendsto.max_right {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ i, max a (f i)) l (𝓝 a) := by { convert ((continuous_max.comp (@continuous.prod.mk α α _ _ a)).tendsto a).comp h, simp, } lemma filter.tendsto.max_left {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ i, max (f i) a) l (𝓝 a) := by { simp_rw max_comm _ a, exact h.max_right, } lemma filter.tendsto_nhds_max_right {l : filter β} {a : α} (h : tendsto f l (𝓝[>] a)) : tendsto (λ i, max a (f i)) l (𝓝[>] a) := begin obtain ⟨h₁ : tendsto f l (𝓝 a), h₂ : ∀ᶠ i in l, f i ∈ Ioi a⟩ := tendsto_nhds_within_iff.mp h, exact tendsto_nhds_within_iff.mpr ⟨h₁.max_right, h₂.mono $ λ i hi, lt_max_of_lt_right hi⟩, end lemma filter.tendsto_nhds_max_left {l : filter β} {a : α} (h : tendsto f l (𝓝[>] a)) : tendsto (λ i, max (f i) a) l (𝓝[>] a) := by { simp_rw max_comm _ a, exact filter.tendsto_nhds_max_right h, } lemma filter.tendsto.min_right {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ i, min a (f i)) l (𝓝 a) := @filter.tendsto.max_right αᵒᵈ β _ _ _ f l a h lemma filter.tendsto.min_left {l : filter β} {a : α} (h : tendsto f l (𝓝 a)) : tendsto (λ i, min (f i) a) l (𝓝 a) := @filter.tendsto.max_left αᵒᵈ β _ _ _ f l a h lemma filter.tendsto_nhds_min_right {l : filter β} {a : α} (h : tendsto f l (𝓝[<] a)) : tendsto (λ i, min a (f i)) l (𝓝[<] a) := @filter.tendsto_nhds_max_right αᵒᵈ β _ _ _ f l a h lemma filter.tendsto_nhds_min_left {l : filter β} {a : α} (h : tendsto f l (𝓝[<] a)) : tendsto (λ i, min (f i) a) l (𝓝[<] a) := @filter.tendsto_nhds_max_left αᵒᵈ β _ _ _ f l a h lemma dense.exists_lt [no_min_order α] {s : set α} (hs : dense s) (x : α) : ∃ y ∈ s, y < x := hs.exists_mem_open is_open_Iio (exists_lt x) lemma dense.exists_gt [no_max_order α] {s : set α} (hs : dense s) (x : α) : ∃ y ∈ s, x < y := hs.order_dual.exists_lt x lemma dense.exists_le [no_min_order α] {s : set α} (hs : dense s) (x : α) : ∃ y ∈ s, y ≤ x := (hs.exists_lt x).imp $ λ y hy, ⟨hy.fst, hy.snd.le⟩ lemma dense.exists_ge [no_max_order α] {s : set α} (hs : dense s) (x : α) : ∃ y ∈ s, x ≤ y := hs.order_dual.exists_le x lemma dense.exists_le' {s : set α} (hs : dense s) (hbot : ∀ x, is_bot x → x ∈ s) (x : α) : ∃ y ∈ s, y ≤ x := begin by_cases hx : is_bot x, { exact ⟨x, hbot x hx, le_rfl⟩ }, { simp only [is_bot, not_forall, not_le] at hx, rcases hs.exists_mem_open is_open_Iio hx with ⟨y, hys, hy : y < x⟩, exact ⟨y, hys, hy.le⟩ } end lemma dense.exists_ge' {s : set α} (hs : dense s) (htop : ∀ x, is_top x → x ∈ s) (x : α) : ∃ y ∈ s, x ≤ y := hs.order_dual.exists_le' htop x lemma dense.exists_between [densely_ordered α] {s : set α} (hs : dense s) {x y : α} (h : x < y) : ∃ z ∈ s, z ∈ Ioo x y := hs.exists_mem_open is_open_Ioo (nonempty_Ioo.2 h) end linear_order end order_closed_topology instance [preorder α] [topological_space α] [order_closed_topology α] [preorder β] [topological_space β] [order_closed_topology β] : order_closed_topology (α × β) := ⟨(is_closed_le (continuous_fst.comp continuous_fst) (continuous_fst.comp continuous_snd)).inter (is_closed_le (continuous_snd.comp continuous_fst) (continuous_snd.comp continuous_snd))⟩ instance {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)] [Π i, order_closed_topology (α i)] : order_closed_topology (Π i, α i) := begin constructor, simp only [pi.le_def, set_of_forall], exact is_closed_Inter (λ i, is_closed_le ((continuous_apply i).comp continuous_fst) ((continuous_apply i).comp continuous_snd)) end instance pi.order_closed_topology' [preorder β] [topological_space β] [order_closed_topology β] : order_closed_topology (α → β) := pi.order_closed_topology /-- The order topology on an ordered type is the topology generated by open intervals. We register it on a preorder, but it is mostly interesting in linear orders, where it is also order-closed. We define it as a mixin. If you want to introduce the order topology on a preorder, use `preorder.topology`. -/ class order_topology (α : Type*) [t : topological_space α] [preorder α] : Prop := (topology_eq_generate_intervals : t = generate_from {s | ∃ a, s = Ioi a ∨ s = Iio a}) /-- (Order) topology on a partial order `α` generated by the subbase of open intervals `(a, ∞) = { x ∣ a < x }, (-∞ , b) = {x ∣ x < b}` for all `a, b` in `α`. We do not register it as an instance as many ordered sets are already endowed with the same topology, most often in a non-defeq way though. Register as a local instance when necessary. -/ def preorder.topology (α : Type*) [preorder α] : topological_space α := generate_from {s : set α | ∃ (a : α), s = {b : α | a < b} ∨ s = {b : α | b < a}} section order_topology section preorder variables [topological_space α] [preorder α] [t : order_topology α] include t instance : order_topology αᵒᵈ := ⟨by convert @order_topology.topology_eq_generate_intervals α _ _ _; conv in (_ ∨ _) { rw or.comm }; refl⟩ lemma is_open_iff_generate_intervals {s : set α} : is_open s ↔ generate_open {s | ∃ a, s = Ioi a ∨ s = Iio a} s := by rw [t.topology_eq_generate_intervals]; refl lemma is_open_lt' (a : α) : is_open {b : α | a < b} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inl rfl⟩ lemma is_open_gt' (a : α) : is_open {b : α | b < a} := by rw [@is_open_iff_generate_intervals α _ _ t]; exact generate_open.basic _ ⟨a, or.inr rfl⟩ lemma lt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a < x := is_open.mem_nhds (is_open_lt' _) h lemma le_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 b, a ≤ x := (𝓝 b).sets_of_superset (lt_mem_nhds h) $ assume b hb, le_of_lt hb lemma gt_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x < b := is_open.mem_nhds (is_open_gt' _) h lemma ge_mem_nhds {a b : α} (h : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := (𝓝 a).sets_of_superset (gt_mem_nhds h) $ assume b hb, le_of_lt hb lemma nhds_eq_order (a : α) : 𝓝 a = (⨅ b ∈ Iio a, 𝓟 (Ioi b)) ⊓ (⨅ b ∈ Ioi a, 𝓟 (Iio b)) := by rw [t.topology_eq_generate_intervals, nhds_generate_from]; from le_antisymm (le_inf (le_infi₂ $ assume b hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩) (le_infi₂ $ assume b hb, infi_le_of_le {c : α | c < b} $ infi_le _ ⟨hb, b, or.inr rfl⟩)) (le_infi $ assume s, le_infi $ assume ⟨ha, b, hs⟩, match s, ha, hs with | _, h, (or.inl rfl) := inf_le_of_left_le $ infi_le_of_le b $ infi_le _ h | _, h, (or.inr rfl) := inf_le_of_right_le $ infi_le_of_le b $ infi_le _ h end) lemma tendsto_order {f : β → α} {a : α} {x : filter β} : tendsto f x (𝓝 a) ↔ (∀ a' < a, ∀ᶠ b in x, a' < f b) ∧ (∀ a' > a, ∀ᶠ b in x, f b < a') := by simp [nhds_eq_order a, tendsto_inf, tendsto_infi, tendsto_principal] instance tendsto_Icc_class_nhds (a : α) : tendsto_Ixx_class Icc (𝓝 a) (𝓝 a) := begin simp only [nhds_eq_order, infi_subtype'], refine ((has_basis_infi_principal_finite _).inf (has_basis_infi_principal_finite _)).tendsto_Ixx_class (λ s hs, _), refine ((ord_connected_bInter _).inter (ord_connected_bInter _)).out; intros _ _, exacts [ord_connected_Ioi, ord_connected_Iio] end instance tendsto_Ico_class_nhds (a : α) : tendsto_Ixx_class Ico (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ico_subset_Icc_self) instance tendsto_Ioc_class_nhds (a : α) : tendsto_Ixx_class Ioc (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioc_subset_Icc_self) instance tendsto_Ioo_class_nhds (a : α) : tendsto_Ixx_class Ioo (𝓝 a) (𝓝 a) := tendsto_Ixx_class_of_subset (λ _ _, Ioo_subset_Icc_self) /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold eventually for the filter. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le' {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : ∀ᶠ b in b, g b ≤ f b) (hfh : ∀ᶠ b in b, f b ≤ h b) : tendsto f b (𝓝 a) := (hg.Icc hh).of_small_sets $ hgf.and hfh /-- **Squeeze theorem** (also known as **sandwich theorem**). This version assumes that inequalities hold everywhere. -/ lemma tendsto_of_tendsto_of_tendsto_of_le_of_le {f g h : β → α} {b : filter β} {a : α} (hg : tendsto g b (𝓝 a)) (hh : tendsto h b (𝓝 a)) (hgf : g ≤ f) (hfh : f ≤ h) : tendsto f b (𝓝 a) := tendsto_of_tendsto_of_tendsto_of_le_of_le' hg hh (eventually_of_forall hgf) (eventually_of_forall hfh) lemma nhds_order_unbounded {a : α} (hu : ∃u, a < u) (hl : ∃l, l < a) : 𝓝 a = (⨅l (h₂ : l < a) u (h₂ : a < u), 𝓟 (Ioo l u)) := have ∃ u, u ∈ Ioi a, from hu, have ∃ l, l ∈ Iio a, from hl, by { simp only [nhds_eq_order, inf_binfi, binfi_inf, *, inf_principal, Ioi_inter_Iio], refl } lemma tendsto_order_unbounded {f : β → α} {a : α} {x : filter β} (hu : ∃u, a < u) (hl : ∃l, l < a) (h : ∀l u, l < a → a < u → ∀ᶠ b in x, l < f b ∧ f b < u) : tendsto f x (𝓝 a) := by rw [nhds_order_unbounded hu hl]; from (tendsto_infi.2 $ assume l, tendsto_infi.2 $ assume hl, tendsto_infi.2 $ assume u, tendsto_infi.2 $ assume hu, tendsto_principal.2 $ h l u hl hu) end preorder instance tendsto_Ixx_nhds_within {α : Type*} [preorder α] [topological_space α] (a : α) {s t : set α} {Ixx} [tendsto_Ixx_class Ixx (𝓝 a) (𝓝 a)] [tendsto_Ixx_class Ixx (𝓟 s) (𝓟 t)]: tendsto_Ixx_class Ixx (𝓝[s] a) (𝓝[t] a) := filter.tendsto_Ixx_class_inf instance tendsto_Icc_class_nhds_pi {ι : Type*} {α : ι → Type*} [Π i, preorder (α i)] [Π i, topological_space (α i)] [∀ i, order_topology (α i)] (f : Π i, α i) : tendsto_Ixx_class Icc (𝓝 f) (𝓝 f) := begin constructor, conv in ((𝓝 f).small_sets) { rw [nhds_pi, filter.pi] }, simp only [small_sets_infi, small_sets_comap, tendsto_infi, tendsto_lift', (∘), mem_powerset_iff], intros i s hs, have : tendsto (λ g : Π i, α i, g i) (𝓝 f) (𝓝 (f i)) := ((continuous_apply i).tendsto f), refine (tendsto_lift'.1 ((this.comp tendsto_fst).Icc (this.comp tendsto_snd)) s hs).mono _, exact λ p hp g hg, hp ⟨hg.1 _, hg.2 _⟩ end theorem induced_order_topology' {α : Type u} {β : Type v} [preorder α] [ta : topological_space β] [preorder β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H₁ : ∀ {a x}, x < f a → ∃ b < a, x ≤ f b) (H₂ : ∀ {a x}, f a < x → ∃ b > a, f b ≤ x) : @order_topology _ (induced f ta) _ := begin letI := induced f ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (f a)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { exact mem_comap.2 ⟨{x | f b < x}, mem_inf_of_left $ mem_infi_of_mem _ $ mem_infi_of_mem (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ }, { exact mem_comap.2 ⟨{x | x < f b}, mem_inf_of_right $ mem_infi_of_mem _ $ mem_infi_of_mem (hf.2 ab) $ mem_principal_self _, λ x, hf.1⟩ } }, { rw [← map_le_iff_le_comap], refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp, { rcases H₁ h with ⟨b, ab, xb⟩, refine mem_infi_of_mem _ (mem_infi_of_mem ⟨ab, b, or.inl rfl⟩ (mem_principal.2 _)), exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) }, { rcases H₂ h with ⟨b, ab, xb⟩, refine mem_infi_of_mem _ (mem_infi_of_mem ⟨ab, b, or.inr rfl⟩ (mem_principal.2 _)), exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } }, end theorem induced_order_topology {α : Type u} {β : Type v} [preorder α] [ta : topological_space β] [preorder β] [order_topology β] (f : α → β) (hf : ∀ {x y}, f x < f y ↔ x < y) (H : ∀ {x y}, x < y → ∃ a, x < f a ∧ f a < y) : @order_topology _ (induced f ta) _ := induced_order_topology' f @hf (λ a x xa, let ⟨b, xb, ba⟩ := H xa in ⟨b, hf.1 ba, le_of_lt xb⟩) (λ a x ax, let ⟨b, ab, bx⟩ := H ax in ⟨b, hf.1 ab, le_of_lt bx⟩) /-- On an `ord_connected` subset of a linear order, the order topology for the restriction of the order is the same as the restriction to the subset of the order topology. -/ instance order_topology_of_ord_connected {α : Type u} [ta : topological_space α] [linear_order α] [order_topology α] {t : set α} [ht : ord_connected t] : order_topology t := begin letI := induced (coe : t → α) ta, refine ⟨eq_of_nhds_eq_nhds (λ a, _)⟩, rw [nhds_induced, nhds_generate_from, nhds_eq_order (a : α)], apply le_antisymm, { refine le_infi (λ s, le_infi $ λ hs, le_principal_iff.2 _), rcases hs with ⟨ab, b, rfl|rfl⟩, { refine ⟨Ioi b, _, λ _, id⟩, refine mem_inf_of_left (mem_infi_of_mem b _), exact mem_infi_of_mem ab (mem_principal_self (Ioi ↑b)) }, { refine ⟨Iio b, _, λ _, id⟩, refine mem_inf_of_right (mem_infi_of_mem b _), exact mem_infi_of_mem ab (mem_principal_self (Iio b)) } }, { rw [← map_le_iff_le_comap], refine le_inf _ _, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_of_mem (Ioi ⟨x, hx⟩) (mem_infi_of_mem ⟨h, ⟨⟨x, hx⟩, or.inl rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map'], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Ioi x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out y.2 a.2 ⟨le_of_not_gt hx, le_of_lt h⟩ }, { refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _), by_cases hx : x ∈ t, { refine mem_infi_of_mem (Iio ⟨x, hx⟩) (mem_infi_of_mem ⟨h, ⟨⟨x, hx⟩, or.inr rfl⟩⟩ _), exact λ _, id }, simp only [set_coe.exists, mem_set_of_eq, mem_map'], convert univ_sets _, suffices hx' : ∀ (y : t), ↑y ∈ Iio x, { simp [hx'] }, intros y, revert hx, contrapose!, -- here we use the `ord_connected` hypothesis exact λ hx, ht.out a.2 y.2 ⟨le_of_lt h, le_of_not_gt hx⟩ } } end lemma nhds_within_Ici_eq'' [topological_space α] [preorder α] [order_topology α] (a : α) : 𝓝[≥] a = (⨅ u (hu : a < u), 𝓟 (Iio u)) ⊓ 𝓟 (Ici a) := begin rw [nhds_within, nhds_eq_order], refine le_antisymm (inf_le_inf_right _ inf_le_right) (le_inf (le_inf _ inf_le_left) inf_le_right), exact inf_le_right.trans (le_infi₂ $ λ l hl, principal_mono.2 $ Ici_subset_Ioi.2 hl) end lemma nhds_within_Iic_eq'' [topological_space α] [preorder α] [order_topology α] (a : α) : 𝓝[≤] a = (⨅ l < a, 𝓟 (Ioi l)) ⊓ 𝓟 (Iic a) := nhds_within_Ici_eq'' (to_dual a) lemma nhds_within_Ici_eq' [topological_space α] [preorder α] [order_topology α] {a : α} (ha : ∃ u, a < u) : 𝓝[≥] a = ⨅ u (hu : a < u), 𝓟 (Ico a u) := by simp only [nhds_within_Ici_eq'', binfi_inf ha, inf_principal, Iio_inter_Ici] lemma nhds_within_Iic_eq' [topological_space α] [preorder α] [order_topology α] {a : α} (ha : ∃ l, l < a) : 𝓝[≤] a = ⨅ l < a, 𝓟 (Ioc l a) := by simp only [nhds_within_Iic_eq'', binfi_inf ha, inf_principal, Ioi_inter_Iic] lemma nhds_within_Ici_basis' [topological_space α] [linear_order α] [order_topology α] {a : α} (ha : ∃ u, a < u) : (𝓝[≥] a).has_basis (λ u, a < u) (λ u, Ico a u) := (nhds_within_Ici_eq' ha).symm ▸ has_basis_binfi_principal (λ b hb c hc, ⟨min b c, lt_min hb hc, Ico_subset_Ico_right (min_le_left _ _), Ico_subset_Ico_right (min_le_right _ _)⟩) ha lemma nhds_within_Iic_basis' [topological_space α] [linear_order α] [order_topology α] {a : α} (ha : ∃ l, l < a) : (𝓝[≤] a).has_basis (λ l, l < a) (λ l, Ioc l a) := by { convert @nhds_within_Ici_basis' αᵒᵈ _ _ _ (to_dual a) ha, exact funext (λ x, (@dual_Ico _ _ _ _).symm) } lemma nhds_within_Ici_basis [topological_space α] [linear_order α] [order_topology α] [no_max_order α] (a : α) : (𝓝[≥] a).has_basis (λ u, a < u) (λ u, Ico a u) := nhds_within_Ici_basis' (exists_gt a) lemma nhds_within_Iic_basis [topological_space α] [linear_order α] [order_topology α] [no_min_order α] (a : α) : (𝓝[≤] a).has_basis (λ l, l < a) (λ l, Ioc l a) := nhds_within_Iic_basis' (exists_lt a) lemma nhds_top_order [topological_space α] [preorder α] [order_top α] [order_topology α] : 𝓝 (⊤:α) = (⨅l (h₂ : l < ⊤), 𝓟 (Ioi l)) := by simp [nhds_eq_order (⊤:α)] lemma nhds_bot_order [topological_space α] [preorder α] [order_bot α] [order_topology α] : 𝓝 (⊥:α) = (⨅l (h₂ : ⊥ < l), 𝓟 (Iio l)) := by simp [nhds_eq_order (⊥:α)] lemma nhds_top_basis [topological_space α] [linear_order α] [order_top α] [order_topology α] [nontrivial α] : (𝓝 ⊤).has_basis (λ a : α, a < ⊤) (λ a : α, Ioi a) := have ∃ x : α, x < ⊤, from (exists_ne ⊤).imp $ λ x hx, hx.lt_top, by simpa only [Iic_top, nhds_within_univ, Ioc_top] using nhds_within_Iic_basis' this lemma nhds_bot_basis [topological_space α] [linear_order α] [order_bot α] [order_topology α] [nontrivial α] : (𝓝 ⊥).has_basis (λ a : α, ⊥ < a) (λ a : α, Iio a) := @nhds_top_basis αᵒᵈ _ _ _ _ _ lemma nhds_top_basis_Ici [topological_space α] [linear_order α] [order_top α] [order_topology α] [nontrivial α] [densely_ordered α] : (𝓝 ⊤).has_basis (λ a : α, a < ⊤) Ici := nhds_top_basis.to_has_basis (λ a ha, let ⟨b, hab, hb⟩ := exists_between ha in ⟨b, hb, Ici_subset_Ioi.mpr hab⟩) (λ a ha, ⟨a, ha, Ioi_subset_Ici_self⟩) lemma nhds_bot_basis_Iic [topological_space α] [linear_order α] [order_bot α] [order_topology α] [nontrivial α] [densely_ordered α] : (𝓝 ⊥).has_basis (λ a : α, ⊥ < a) Iic := @nhds_top_basis_Ici αᵒᵈ _ _ _ _ _ _ lemma tendsto_nhds_top_mono [topological_space β] [preorder β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ᶠ[l] g) : tendsto g l (𝓝 ⊤) := begin simp only [nhds_top_order, tendsto_infi, tendsto_principal] at hf ⊢, intros x hx, filter_upwards [hf x hx, hg] with _ using lt_of_lt_of_le, end lemma tendsto_nhds_bot_mono [topological_space β] [preorder β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) : tendsto g l (𝓝 ⊥) := @tendsto_nhds_top_mono α βᵒᵈ _ _ _ _ _ _ _ hf hg lemma tendsto_nhds_top_mono' [topological_space β] [preorder β] [order_top β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊤)) (hg : f ≤ g) : tendsto g l (𝓝 ⊤) := tendsto_nhds_top_mono hf (eventually_of_forall hg) lemma tendsto_nhds_bot_mono' [topological_space β] [preorder β] [order_bot β] [order_topology β] {l : filter α} {f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ f) : tendsto g l (𝓝 ⊥) := tendsto_nhds_bot_mono hf (eventually_of_forall hg) section linear_order variables [topological_space α] [linear_order α] section order_closed_topology variables [order_closed_topology α] {a b : α} lemma eventually_le_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x ≤ b := eventually_iff.mpr (mem_nhds_iff.mpr ⟨Iio b, Iio_subset_Iic_self, is_open_Iio, hab⟩) lemma eventually_lt_nhds (hab : a < b) : ∀ᶠ x in 𝓝 a, x < b := eventually_iff.mpr (mem_nhds_iff.mpr ⟨Iio b, rfl.subset, is_open_Iio, hab⟩) lemma eventually_ge_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b ≤ x := eventually_iff.mpr (mem_nhds_iff.mpr ⟨Ioi b, Ioi_subset_Ici_self, is_open_Ioi, hab⟩) lemma eventually_gt_nhds (hab : b < a) : ∀ᶠ x in 𝓝 a, b < x := eventually_iff.mpr (mem_nhds_iff.mpr ⟨Ioi b, rfl.subset, is_open_Ioi, hab⟩) end order_closed_topology section order_topology variables [order_topology α] lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) : ∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) := match dense_or_discrete a₁ a₂ with | or.inl ⟨a, ha₁, ha₂⟩ := ⟨{a' | a' < a}, {a' | a < a'}, is_open_gt' a, is_open_lt' a, ha₁, ha₂, assume b₁ h₁ b₂ h₂, lt_trans h₁ h₂⟩ | or.inr ⟨h₁, h₂⟩ := ⟨{a | a < a₂}, {a | a₁ < a}, is_open_gt' a₂, is_open_lt' a₁, h, h, assume b₁ hb₁ b₂ hb₂, calc b₁ ≤ a₁ : h₂ _ hb₁ ... < a₂ : h ... ≤ b₂ : h₁ _ hb₂⟩ end @[priority 100] -- see Note [lower instance priority] instance order_topology.to_order_closed_topology : order_closed_topology α := { is_closed_le' := is_open_compl_iff.1 $ is_open_prod_iff.mpr $ assume a₁ a₂ (h : ¬ a₁ ≤ a₂), have h : a₂ < a₁, from lt_of_not_ge h, let ⟨u, v, hu, hv, ha₁, ha₂, h⟩ := order_separated h in ⟨v, u, hv, hu, ha₂, ha₁, assume ⟨b₁, b₂⟩ ⟨h₁, h₂⟩, not_le_of_gt $ h b₂ h₂ b₁ h₁⟩ } lemma exists_Ioc_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) : ∃ l < a, Ioc l a ⊆ s := (nhds_within_Iic_basis' h).mem_iff.mp (nhds_within_le_nhds hs) lemma exists_Ioc_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {l : α} (hl : l < a) : ∃ l' ∈ Ico l a, Ioc l' a ⊆ s := let ⟨l', hl'a, hl's⟩ := exists_Ioc_subset_of_mem_nhds hs ⟨l, hl⟩ in ⟨max l l', ⟨le_max_left _ _, max_lt hl hl'a⟩, (Ioc_subset_Ioc_left $ le_max_right _ _).trans hl's⟩ lemma exists_Ico_subset_of_mem_nhds' {a : α} {s : set α} (hs : s ∈ 𝓝 a) {u : α} (hu : a < u) : ∃ u' ∈ Ioc a u, Ico a u' ⊆ s := by simpa only [order_dual.exists, exists_prop, dual_Ico, dual_Ioc] using exists_Ioc_subset_of_mem_nhds' (show of_dual ⁻¹' s ∈ 𝓝 (to_dual a), from hs) hu.dual lemma exists_Ico_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ u, a < u) : ∃ u (_ : a < u), Ico a u ⊆ s := let ⟨l', hl'⟩ := h, ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.1, hl.snd⟩ lemma exists_Icc_mem_subset_of_mem_nhds_within_Ici {a : α} {s : set α} (hs : s ∈ 𝓝[≥] a) : ∃ b (_ : a ≤ b), Icc a b ∈ 𝓝[≥] a ∧ Icc a b ⊆ s := begin rcases (em (is_max a)).imp_right not_is_max_iff.mp with ha|ha, { use a, simpa [ha.Ici_eq] using hs }, { rcases (nhds_within_Ici_basis' ha).mem_iff.mp hs with ⟨b, hab, hbs⟩, rcases eq_empty_or_nonempty (Ioo a b) with H|⟨c, hac, hcb⟩, { have : Ico a b = Icc a a, { rw [← Icc_union_Ioo_eq_Ico le_rfl hab, H, union_empty] }, exact ⟨a, le_rfl, this ▸ ⟨Ico_mem_nhds_within_Ici $ left_mem_Ico.2 hab, hbs⟩⟩ }, { refine ⟨c, hac.le, Icc_mem_nhds_within_Ici $ left_mem_Ico.mpr hac, _⟩, exact (Icc_subset_Ico_right hcb).trans hbs } } end lemma exists_Icc_mem_subset_of_mem_nhds_within_Iic {a : α} {s : set α} (hs : s ∈ 𝓝[≤] a) : ∃ b ≤ a, Icc b a ∈ 𝓝[≤] a ∧ Icc b a ⊆ s := by simpa only [dual_Icc, to_dual.surjective.exists] using @exists_Icc_mem_subset_of_mem_nhds_within_Ici αᵒᵈ _ _ _ (to_dual a) _ hs lemma exists_Icc_mem_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) : ∃ b c, a ∈ Icc b c ∧ Icc b c ∈ 𝓝 a ∧ Icc b c ⊆ s := begin rcases exists_Icc_mem_subset_of_mem_nhds_within_Iic (nhds_within_le_nhds hs) with ⟨b, hba, hb_nhds, hbs⟩, rcases exists_Icc_mem_subset_of_mem_nhds_within_Ici (nhds_within_le_nhds hs) with ⟨c, hac, hc_nhds, hcs⟩, refine ⟨b, c, ⟨hba, hac⟩, _⟩, rw [← Icc_union_Icc_eq_Icc hba hac, ← nhds_left_sup_nhds_right], exact ⟨union_mem_sup hb_nhds hc_nhds, union_subset hbs hcs⟩ end lemma is_open.exists_Ioo_subset [nontrivial α] {s : set α} (hs : is_open s) (h : s.nonempty) : ∃ a b, a < b ∧ Ioo a b ⊆ s := begin obtain ⟨x, hx⟩ : ∃ x, x ∈ s := h, obtain ⟨y, hy⟩ : ∃ y, y ≠ x := exists_ne x, rcases lt_trichotomy x y with H|rfl|H, { obtain ⟨u, xu, hu⟩ : ∃ (u : α) (hu : x < u), Ico x u ⊆ s := exists_Ico_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩, exact ⟨x, u, xu, Ioo_subset_Ico_self.trans hu⟩ }, { exact (hy rfl).elim }, { obtain ⟨l, lx, hl⟩ : ∃ (l : α) (hl : l < x), Ioc l x ⊆ s := exists_Ioc_subset_of_mem_nhds (hs.mem_nhds hx) ⟨y, H⟩, exact ⟨l, x, lx, Ioo_subset_Ioc_self.trans hl⟩ } end lemma dense_of_exists_between [nontrivial α] {s : set α} (h : ∀ ⦃a b⦄, a < b → ∃ c ∈ s, a < c ∧ c < b) : dense s := begin apply dense_iff_inter_open.2 (λ U U_open U_nonempty, _), obtain ⟨a, b, hab, H⟩ : ∃ (a b : α), a < b ∧ Ioo a b ⊆ U := U_open.exists_Ioo_subset U_nonempty, obtain ⟨x, xs, hx⟩ : ∃ (x : α) (H : x ∈ s), a < x ∧ x < b := h hab, exact ⟨x, ⟨H hx, xs⟩⟩ end /-- A set in a nontrivial densely linear ordered type is dense in the sense of topology if and only if for any `a < b` there exists `c ∈ s`, `a < c < b`. Each implication requires less typeclass assumptions. -/ lemma dense_iff_exists_between [densely_ordered α] [nontrivial α] {s : set α} : dense s ↔ ∀ a b, a < b → ∃ c ∈ s, a < c ∧ c < b := ⟨λ h a b hab, h.exists_between hab, dense_of_exists_between⟩ /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`, provided `a` is neither a bottom element nor a top element. -/ lemma mem_nhds_iff_exists_Ioo_subset' {a : α} {s : set α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := begin split, { assume h, rcases exists_Ico_subset_of_mem_nhds h hu with ⟨u, au, hu⟩, rcases exists_Ioc_subset_of_mem_nhds h hl with ⟨l, la, hl⟩, exact ⟨l, u, ⟨la, au⟩, Ioc_union_Ico_eq_Ioo la au ▸ union_subset hl hu⟩ }, { rintros ⟨l, u, ha, h⟩, apply mem_of_superset (Ioo_mem_nhds ha.1 ha.2) h } end /-- A set is a neighborhood of `a` if and only if it contains an interval `(l, u)` containing `a`. -/ lemma mem_nhds_iff_exists_Ioo_subset [no_max_order α] [no_min_order α] {a : α} {s : set α} : s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s := mem_nhds_iff_exists_Ioo_subset' (exists_lt a) (exists_gt a) lemma nhds_basis_Ioo' {a : α} (hl : ∃ l, l < a) (hu : ∃ u, a < u) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := ⟨λ s, (mem_nhds_iff_exists_Ioo_subset' hl hu).trans $ by simp⟩ lemma nhds_basis_Ioo [no_max_order α] [no_min_order α] (a : α) : (𝓝 a).has_basis (λ b : α × α, b.1 < a ∧ a < b.2) (λ b, Ioo b.1 b.2) := nhds_basis_Ioo' (exists_lt a) (exists_gt a) lemma filter.eventually.exists_Ioo_subset [no_max_order α] [no_min_order α] {a : α} {p : α → Prop} (hp : ∀ᶠ x in 𝓝 a, p x) : ∃ l u, a ∈ Ioo l u ∧ Ioo l u ⊆ {x | p x} := mem_nhds_iff_exists_Ioo_subset.1 hp /-- The set of points which are isolated on the right is countable when the space is second-countable. -/ lemma countable_of_isolated_right [second_countable_topology α] : set.countable {x : α | ∃ y, x < y ∧ Ioo x y = ∅} := begin nontriviality α, let s := {x : α | ∃ y, x < y ∧ Ioo x y = ∅}, have : ∀ x ∈ s, ∃ y, x < y ∧ Ioo x y = ∅ := λ x, id, choose! y hy h'y using this, have Hy : ∀ x z, x ∈ s → z < y x → z ≤ x, { assume x z xs hz, have A : Ioo x (y x) = ∅ := h'y _ xs, contrapose! A, exact nonempty.ne_empty ⟨z, A, hz⟩ }, suffices H : ∀ (a : set α), is_open a → set.countable {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a}, { have : s ⊆ ⋃ (a ∈ countable_basis α), {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a}, { assume x hx, rcases (is_basis_countable_basis α).exists_mem_of_ne (hy x hx).ne with ⟨a, ab, xa, ya⟩, simp only [mem_set_of_eq, mem_Union], exact ⟨a, ab, hx, xa, ya⟩ }, apply countable.mono this, refine countable.bUnion (countable_countable_basis α) (λ a ha, H _ _), exact is_open_of_mem_countable_basis ha }, assume a ha, suffices H : set.countable {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a ∧ ¬(is_bot x)}, { have : {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a} ⊆ {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a ∧ ¬(is_bot x)} ∪ {x | is_bot x}, { assume x hx, by_cases h'x : is_bot x, { simp only [h'x, mem_set_of_eq, mem_union, not_true, and_false, false_or] }, { simpa only [h'x, hx.2.1, hx.2.2, mem_set_of_eq, mem_union, not_false_iff, and_true, or_false] using hx.left } }, exact countable.mono this (H.union (subsingleton_is_bot α).countable) }, let t := {x | x ∈ s ∧ x ∈ a ∧ y x ∉ a ∧ ¬(is_bot x)}, have : ∀ x ∈ t, ∃ z < x, Ioc z x ⊆ a, { assume x hx, apply exists_Ioc_subset_of_mem_nhds (ha.mem_nhds hx.2.1), simpa only [is_bot, not_forall, not_le] using hx.right.right.right }, choose! z hz h'z using this, have : pairwise_disjoint t (λ x, Ioc (z x) x), { assume x xt x' x't hxx', rcases lt_or_gt_of_ne hxx' with h'|h', { refine disjoint_left.2 (λ u ux ux', xt.2.2.1 _), refine h'z x' x't ⟨ux'.1.trans_le (ux.2.trans (hy x xt.1).le), _⟩, by_contra' H, exact false.elim (lt_irrefl _ ((Hy _ _ xt.1 H).trans_lt h')) }, { refine disjoint_left.2 (λ u ux ux', x't.2.2.1 _), refine h'z x xt ⟨ux.1.trans_le (ux'.2.trans (hy x' x't.1).le), _⟩, by_contra' H, exact false.elim (lt_irrefl _ ((Hy _ _ x't.1 H).trans_lt h')) } }, refine this.countable_of_is_open (λ x hx, _) (λ x hx, ⟨x, hz x hx, le_rfl⟩), suffices H : Ioc (z x) x = Ioo (z x) (y x), { rw H, exact is_open_Ioo }, exact subset.antisymm (Ioc_subset_Ioo_right (hy x hx.1)) (λ u hu, ⟨hu.1, Hy _ _ hx.1 hu.2⟩), end /-- The set of points which are isolated on the left is countable when the space is second-countable. -/ lemma countable_of_isolated_left [second_countable_topology α] : set.countable {x : α | ∃ y, y < x ∧ Ioo y x = ∅} := begin convert @countable_of_isolated_right αᵒᵈ _ _ _ _, have : ∀ (x y : α), Ioo x y = {z | z < y ∧ x < z}, { simp_rw [and_comm, Ioo], simp only [eq_self_iff_true, forall_2_true_iff] }, simp_rw [this], refl end /-- Consider a disjoint family of intervals `(x, y)` with `x < y` in a second-countable space. Then the family is countable. This is not a straightforward consequence of second-countability as some of these intervals might be empty (but in fact this can happen only for countably many of them). -/ lemma set.pairwise_disjoint.countable_of_Ioo [second_countable_topology α] {y : α → α} {s : set α} (h : pairwise_disjoint s (λ x, Ioo x (y x))) (h' : ∀ x ∈ s, x < y x) : s.countable := begin let t := {x | x ∈ s ∧ (Ioo x (y x)).nonempty}, have t_count : t.countable, { have : t ⊆ s := λ x hx, hx.1, exact (h.subset this).countable_of_is_open (λ x hx, is_open_Ioo) (λ x hx, hx.2) }, have : s ⊆ t ∪ {x : α | ∃ x', x < x' ∧ Ioo x x' = ∅}, { assume x hx, by_cases h'x : (Ioo x (y x)).nonempty, { exact or.inl ⟨hx, h'x⟩ }, { exact or.inr ⟨y x, h' x hx, not_nonempty_iff_eq_empty.1 h'x⟩ } }, exact countable.mono this (t_count.union countable_of_isolated_right), end section pi /-! ### Intervals in `Π i, π i` belong to `𝓝 x` For each lemma `pi_Ixx_mem_nhds` we add a non-dependent version `pi_Ixx_mem_nhds'` because sometimes Lean fails to unify different instances while trying to apply the dependent version to, e.g., `ι → ℝ`. -/ variables {ι : Type*} {π : ι → Type*} [finite ι] [Π i, linear_order (π i)] [Π i, topological_space (π i)] [∀ i, order_topology (π i)] {a b x : Π i, π i} {a' b' x' : ι → α} lemma pi_Iic_mem_nhds (ha : ∀ i, x i < a i) : Iic a ∈ 𝓝 x := pi_univ_Iic a ▸ set_pi_mem_nhds (set.to_finite _) (λ i _, Iic_mem_nhds (ha _)) lemma pi_Iic_mem_nhds' (ha : ∀ i, x' i < a' i) : Iic a' ∈ 𝓝 x' := pi_Iic_mem_nhds ha lemma pi_Ici_mem_nhds (ha : ∀ i, a i < x i) : Ici a ∈ 𝓝 x := pi_univ_Ici a ▸ set_pi_mem_nhds (set.to_finite _) (λ i _, Ici_mem_nhds (ha _)) lemma pi_Ici_mem_nhds' (ha : ∀ i, a' i < x' i) : Ici a' ∈ 𝓝 x' := pi_Ici_mem_nhds ha lemma pi_Icc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Icc a b ∈ 𝓝 x := pi_univ_Icc a b ▸ set_pi_mem_nhds finite_univ (λ i _, Icc_mem_nhds (ha _) (hb _)) lemma pi_Icc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Icc a' b' ∈ 𝓝 x' := pi_Icc_mem_nhds ha hb variables [nonempty ι] lemma pi_Iio_mem_nhds (ha : ∀ i, x i < a i) : Iio a ∈ 𝓝 x := begin refine mem_of_superset (set_pi_mem_nhds (set.to_finite _) (λ i _, _)) (pi_univ_Iio_subset a), exact Iio_mem_nhds (ha i) end lemma pi_Iio_mem_nhds' (ha : ∀ i, x' i < a' i) : Iio a' ∈ 𝓝 x' := pi_Iio_mem_nhds ha lemma pi_Ioi_mem_nhds (ha : ∀ i, a i < x i) : Ioi a ∈ 𝓝 x := @pi_Iio_mem_nhds ι (λ i, (π i)ᵒᵈ) _ _ _ _ _ _ _ ha lemma pi_Ioi_mem_nhds' (ha : ∀ i, a' i < x' i) : Ioi a' ∈ 𝓝 x' := pi_Ioi_mem_nhds ha lemma pi_Ioc_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioc a b ∈ 𝓝 x := begin refine mem_of_superset (set_pi_mem_nhds (set.to_finite _) (λ i _, _)) (pi_univ_Ioc_subset a b), exact Ioc_mem_nhds (ha i) (hb i) end lemma pi_Ioc_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioc a' b' ∈ 𝓝 x' := pi_Ioc_mem_nhds ha hb lemma pi_Ico_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ico a b ∈ 𝓝 x := begin refine mem_of_superset (set_pi_mem_nhds (set.to_finite _) (λ i _, _)) (pi_univ_Ico_subset a b), exact Ico_mem_nhds (ha i) (hb i) end lemma pi_Ico_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ico a' b' ∈ 𝓝 x' := pi_Ico_mem_nhds ha hb lemma pi_Ioo_mem_nhds (ha : ∀ i, a i < x i) (hb : ∀ i, x i < b i) : Ioo a b ∈ 𝓝 x := begin refine mem_of_superset (set_pi_mem_nhds (set.to_finite _) (λ i _, _)) (pi_univ_Ioo_subset a b), exact Ioo_mem_nhds (ha i) (hb i) end lemma pi_Ioo_mem_nhds' (ha : ∀ i, a' i < x' i) (hb : ∀ i, x' i < b' i) : Ioo a' b' ∈ 𝓝 x' := pi_Ioo_mem_nhds ha hb end pi lemma disjoint_nhds_at_top [no_max_order α] (x : α) : disjoint (𝓝 x) at_top := begin rcases exists_gt x with ⟨y, hy : x < y⟩, refine disjoint_of_disjoint_of_mem _ (Iio_mem_nhds hy) (mem_at_top y), exact disjoint_left.mpr (λ z, not_le.2) end @[simp] lemma inf_nhds_at_top [no_max_order α] (x : α) : 𝓝 x ⊓ at_top = ⊥ := disjoint_iff.1 (disjoint_nhds_at_top x) lemma disjoint_nhds_at_bot [no_min_order α] (x : α) : disjoint (𝓝 x) at_bot := @disjoint_nhds_at_top αᵒᵈ _ _ _ _ x @[simp] lemma inf_nhds_at_bot [no_min_order α] (x : α) : 𝓝 x ⊓ at_bot = ⊥ := @inf_nhds_at_top αᵒᵈ _ _ _ _ x lemma not_tendsto_nhds_of_tendsto_at_top [no_max_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_top) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_top x).symm lemma not_tendsto_at_top_of_tendsto_nhds [no_max_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_top := hf.not_tendsto (disjoint_nhds_at_top x) lemma not_tendsto_nhds_of_tendsto_at_bot [no_min_order α] {F : filter β} [ne_bot F] {f : β → α} (hf : tendsto f F at_bot) (x : α) : ¬ tendsto f F (𝓝 x) := hf.not_tendsto (disjoint_nhds_at_bot x).symm lemma not_tendsto_at_bot_of_tendsto_nhds [no_min_order α] {F : filter β} [ne_bot F] {f : β → α} {x : α} (hf : tendsto f F (𝓝 x)) : ¬ tendsto f F at_bot := hf.not_tendsto (disjoint_nhds_at_bot x) /-! ### Neighborhoods to the left and to the right on an `order_topology` We've seen some properties of left and right neighborhood of a point in an `order_closed_topology`. In an `order_topology`, such neighborhoods can be characterized as the sets containing suitable intervals to the right or to the left of `a`. We give now these characterizations. -/ -- NB: If you extend the list, append to the end please to avoid breaking the API /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `(a, +∞)` 1. `s` is a neighborhood of `a` within `(a, b]` 2. `s` is a neighborhood of `a` within `(a, b)` 3. `s` includes `(a, u)` for some `u ∈ (a, b]` 4. `s` includes `(a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ioi {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[>] a, -- 0 : `s` is a neighborhood of `a` within `(a, +∞)` s ∈ 𝓝[Ioc a b] a, -- 1 : `s` is a neighborhood of `a` within `(a, b]` s ∈ 𝓝[Ioo a b] a, -- 2 : `s` is a neighborhood of `a` within `(a, b)` ∃ u ∈ Ioc a b, Ioo a u ⊆ s, -- 3 : `s` includes `(a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ioo a u ⊆ s] := -- 4 : `s` includes `(a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Ioc_eq_nhds_within_Ioi hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ioo_eq_nhds_within_Ioi hab], tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 1, { rintros ⟨u, hau, hu⟩, exact mem_of_superset (Ioo_mem_nhds_within_Ioi ⟨le_refl a, hau⟩) hu }, tfae_have : 1 → 4, { assume h, rcases mem_nhds_within_iff_exists_mem_nhds_inter.1 h with ⟨v, va, hv⟩, rcases exists_Ico_subset_of_mem_nhds' va hab with ⟨u, au, hu⟩, refine ⟨u, au, λx hx, _⟩, refine hv ⟨hu ⟨le_of_lt hx.1, hx.2⟩, _⟩, exact hx.1 }, tfae_finish end lemma mem_nhds_within_Ioi_iff_exists_mem_Ioc_Ioo_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃u ∈ Ioc a u', Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 3 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[>] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := (tfae_mem_nhds_within_Ioi hu' s).out 0 4 /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u)` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioo_subset [no_max_order α] {a : α} {s : set α} : s ∈ 𝓝[>] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s := let ⟨u', hu'⟩ := exists_gt a in mem_nhds_within_Ioi_iff_exists_Ioo_subset' hu' /-- A set is a neighborhood of `a` within `(a, +∞)` if and only if it contains an interval `(a, u]` with `a < u`. -/ lemma mem_nhds_within_Ioi_iff_exists_Ioc_subset [no_max_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[>] a ↔ ∃u ∈ Ioi a, Ioc a u ⊆ s := begin rw mem_nhds_within_Ioi_iff_exists_Ioo_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ioo_subset_Ioc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b)` 1. `s` is a neighborhood of `b` within `[a, b)` 2. `s` is a neighborhood of `b` within `(a, b)` 3. `s` includes `(l, b)` for some `l ∈ [a, b)` 4. `s` includes `(l, b)` for some `l < b` -/ lemma tfae_mem_nhds_within_Iio {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[<] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b)` s ∈ 𝓝[Ico a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b)` s ∈ 𝓝[Ioo a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b)` ∃ l ∈ Ico a b, Ioo l b ⊆ s, -- 3 : `s` includes `(l, b)` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioo l b ⊆ s] := -- 4 : `s` includes `(l, b)` for some `l < b` by simpa only [exists_prop, order_dual.exists, dual_Ioi, dual_Ioc, dual_Ioo] using tfae_mem_nhds_within_Ioi h.dual (of_dual ⁻¹' s) lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃l ∈ Ico l' a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 3 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[<] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := (tfae_mem_nhds_within_Iio hl' s).out 0 4 /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `(l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ioo_subset [no_min_order α] {a : α} {s : set α} : s ∈ 𝓝[<] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s := let ⟨l', hl'⟩ := exists_lt a in mem_nhds_within_Iio_iff_exists_Ioo_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a)` if and only if it contains an interval `[l, a)` with `l < a`. -/ lemma mem_nhds_within_Iio_iff_exists_Ico_subset [no_min_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[<] a ↔ ∃l ∈ Iio a, Ico l a ⊆ s := begin have : of_dual ⁻¹' s ∈ 𝓝[>] (to_dual a) ↔ _ := mem_nhds_within_Ioi_iff_exists_Ioc_subset, simpa only [order_dual.exists, exists_prop, dual_Ioc] using this, end /-- The following statements are equivalent: 0. `s` is a neighborhood of `a` within `[a, +∞)` 1. `s` is a neighborhood of `a` within `[a, b]` 2. `s` is a neighborhood of `a` within `[a, b)` 3. `s` includes `[a, u)` for some `u ∈ (a, b]` 4. `s` includes `[a, u)` for some `u > a` -/ lemma tfae_mem_nhds_within_Ici {a b : α} (hab : a < b) (s : set α) : tfae [s ∈ 𝓝[≥] a, -- 0 : `s` is a neighborhood of `a` within `[a, +∞)` s ∈ 𝓝[Icc a b] a, -- 1 : `s` is a neighborhood of `a` within `[a, b]` s ∈ 𝓝[Ico a b] a, -- 2 : `s` is a neighborhood of `a` within `[a, b)` ∃ u ∈ Ioc a b, Ico a u ⊆ s, -- 3 : `s` includes `[a, u)` for some `u ∈ (a, b]` ∃ u ∈ Ioi a, Ico a u ⊆ s] := -- 4 : `s` includes `[a, u)` for some `u > a` begin tfae_have : 1 ↔ 2, by rw [nhds_within_Icc_eq_nhds_within_Ici hab], tfae_have : 1 ↔ 3, by rw [nhds_within_Ico_eq_nhds_within_Ici hab], tfae_have : 1 ↔ 5, from (nhds_within_Ici_basis' ⟨b, hab⟩).mem_iff, tfae_have : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩, tfae_have : 5 → 4, { rintro ⟨u, hua, hus⟩, exact ⟨min u b, ⟨lt_min hua hab, min_le_right _ _⟩, (Ico_subset_Ico_right $ min_le_left _ _).trans hus⟩, }, tfae_finish end lemma mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃u ∈ Ioc a u', Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u < u'`, provided `a` is not a top element. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset' {a u' : α} {s : set α} (hu' : a < u') : s ∈ 𝓝[≥] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := (tfae_mem_nhds_within_Ici hu' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u)` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Ico_subset [no_max_order α] {a : α} {s : set α} : s ∈ 𝓝[≥] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s := let ⟨u', hu'⟩ := exists_gt a in mem_nhds_within_Ici_iff_exists_Ico_subset' hu' lemma nhds_within_Ici_basis_Ico [no_max_order α] (a : α) : (𝓝[≥] a).has_basis (λ u, a < u) (Ico a) := ⟨λ s, mem_nhds_within_Ici_iff_exists_Ico_subset⟩ /-- A set is a neighborhood of `a` within `[a, +∞)` if and only if it contains an interval `[a, u]` with `a < u`. -/ lemma mem_nhds_within_Ici_iff_exists_Icc_subset [no_max_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[≥] a ↔ ∃ u, a < u ∧ Icc a u ⊆ s := begin rw mem_nhds_within_Ici_iff_exists_Ico_subset, split, { rintros ⟨u, au, as⟩, rcases exists_between au with ⟨v, hv⟩, exact ⟨v, hv.1, λx hx, as ⟨hx.1, lt_of_le_of_lt hx.2 hv.2⟩⟩ }, { rintros ⟨u, au, as⟩, exact ⟨u, au, subset.trans Ico_subset_Icc_self as⟩ } end /-- The following statements are equivalent: 0. `s` is a neighborhood of `b` within `(-∞, b]` 1. `s` is a neighborhood of `b` within `[a, b]` 2. `s` is a neighborhood of `b` within `(a, b]` 3. `s` includes `(l, b]` for some `l ∈ [a, b)` 4. `s` includes `(l, b]` for some `l < b` -/ lemma tfae_mem_nhds_within_Iic {a b : α} (h : a < b) (s : set α) : tfae [s ∈ 𝓝[≤] b, -- 0 : `s` is a neighborhood of `b` within `(-∞, b]` s ∈ 𝓝[Icc a b] b, -- 1 : `s` is a neighborhood of `b` within `[a, b]` s ∈ 𝓝[Ioc a b] b, -- 2 : `s` is a neighborhood of `b` within `(a, b]` ∃ l ∈ Ico a b, Ioc l b ⊆ s, -- 3 : `s` includes `(l, b]` for some `l ∈ [a, b)` ∃ l ∈ Iio b, Ioc l b ⊆ s] := -- 4 : `s` includes `(l, b]` for some `l < b` by simpa only [exists_prop, order_dual.exists, dual_Ici, dual_Ioc, dual_Icc, dual_Ico] using tfae_mem_nhds_within_Ici h.dual (of_dual ⁻¹' s) lemma mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃l ∈ Ico l' a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 3 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`, provided `a` is not a bottom element. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset' {a l' : α} {s : set α} (hl' : l' < a) : s ∈ 𝓝[≤] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := (tfae_mem_nhds_within_Iic hl' s).out 0 4 (by norm_num) (by norm_num) /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `(l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Ioc_subset [no_min_order α] {a : α} {s : set α} : s ∈ 𝓝[≤] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s := let ⟨l', hl'⟩ := exists_lt a in mem_nhds_within_Iic_iff_exists_Ioc_subset' hl' /-- A set is a neighborhood of `a` within `(-∞, a]` if and only if it contains an interval `[l, a]` with `l < a`. -/ lemma mem_nhds_within_Iic_iff_exists_Icc_subset [no_min_order α] [densely_ordered α] {a : α} {s : set α} : s ∈ 𝓝[≤] a ↔ ∃ l, l < a ∧ Icc l a ⊆ s := begin convert @mem_nhds_within_Ici_iff_exists_Icc_subset αᵒᵈ _ _ _ _ _ _ _, simp_rw (show ∀ u : αᵒᵈ, @Icc αᵒᵈ _ a u = @Icc α _ u a, from λ u, dual_Icc), refl, end end order_topology end linear_order section linear_ordered_add_comm_group variables [topological_space α] [linear_ordered_add_comm_group α] [order_topology α] variables {l : filter β} {f g : β → α} lemma nhds_eq_infi_abs_sub (a : α) : 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r}) := begin simp only [le_antisymm_iff, nhds_eq_order, le_inf_iff, le_infi_iff, le_principal_iff, mem_Ioi, mem_Iio, abs_sub_lt_iff, @sub_lt_iff_lt_add _ _ _ _ _ _ a, @sub_lt_comm _ _ _ _ a, set_of_and], refine ⟨_, _, _⟩, { intros ε ε0, exact inter_mem_inf (mem_infi_of_mem (a - ε) $ mem_infi_of_mem (sub_lt_self a ε0) (mem_principal_self _)) (mem_infi_of_mem (ε + a) $ mem_infi_of_mem (by simpa) (mem_principal_self _)) }, { intros b hb, exact mem_infi_of_mem (a - b) (mem_infi_of_mem (sub_pos.2 hb) (by simp [Ioi])) }, { intros b hb, exact mem_infi_of_mem (b - a) (mem_infi_of_mem (sub_pos.2 hb) (by simp [Iio])) } end lemma order_topology_of_nhds_abs {α : Type*} [topological_space α] [linear_ordered_add_comm_group α] (h_nhds : ∀a:α, 𝓝 a = (⨅r>0, 𝓟 {b | |a - b| < r})) : order_topology α := begin refine ⟨eq_of_nhds_eq_nhds $ λ a, _⟩, rw [h_nhds], letI := preorder.topology α, letI : order_topology α := ⟨rfl⟩, exact (nhds_eq_infi_abs_sub a).symm end lemma linear_ordered_add_comm_group.tendsto_nhds {x : filter β} {a : α} : tendsto f x (𝓝 a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε := by simp [nhds_eq_infi_abs_sub, abs_sub_comm a] lemma eventually_abs_sub_lt (a : α) {ε : α} (hε : 0 < ε) : ∀ᶠ x in 𝓝 a, |x - a| < ε := (nhds_eq_infi_abs_sub a).symm ▸ mem_infi_of_mem ε (mem_infi_of_mem hε $ by simp only [abs_sub_comm, mem_principal_self]) /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_top` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.add_at_top {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) : tendsto (λ x, f x + g x) l at_top := begin nontriviality α, obtain ⟨C', hC'⟩ : ∃ C', C' < C := exists_lt C, refine tendsto_at_top_add_left_of_le' _ C' _ hg, exact (hf.eventually (lt_mem_nhds hC')).mono (λ x, le_of_lt) end /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `C` and `g` tends to `at_bot` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.add_at_bot {C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) : tendsto (λ x, f x + g x) l at_bot := @filter.tendsto.add_at_top αᵒᵈ _ _ _ _ _ _ _ _ hf hg /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_top` and `g` tends to `C` then `f + g` tends to `at_top`. -/ lemma filter.tendsto.at_top_add {C : α} (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_top := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_top hf } /-- In a linearly ordered additive commutative group with the order topology, if `f` tends to `at_bot` and `g` tends to `C` then `f + g` tends to `at_bot`. -/ lemma filter.tendsto.at_bot_add {C : α} (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) : tendsto (λ x, f x + g x) l at_bot := by { conv in (_ + _) { rw add_comm }, exact hg.add_at_bot hf } lemma nhds_basis_Ioo_pos [no_min_order α] [no_max_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, Ioo (a-ε) (a+ε)) := ⟨begin refine λ t, (nhds_basis_Ioo a).mem_iff.trans ⟨_, _⟩, { rintros ⟨⟨l, u⟩, ⟨hl : l < a, hu : a < u⟩, h' : Ioo l u ⊆ t⟩, refine ⟨min (a-l) (u-a), by apply lt_min; rwa sub_pos, _⟩, rintros x ⟨hx, hx'⟩, apply h', rw [sub_lt_comm, lt_min_iff, sub_lt_sub_iff_left] at hx, rw [← sub_lt_iff_lt_add', lt_min_iff, sub_lt_sub_iff_right] at hx', exact ⟨hx.1, hx'.2⟩ }, { rintros ⟨ε, ε_pos, h⟩, exact ⟨(a-ε, a+ε), by simp [ε_pos], h⟩ }, end⟩ lemma nhds_basis_abs_sub_lt [no_min_order α] [no_max_order α] (a : α) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | |b - a| < ε}) := begin convert nhds_basis_Ioo_pos a, { ext ε, change |x - a| < ε ↔ a - ε < x ∧ x < a + ε, simp [abs_lt, sub_lt_iff_lt_add, add_comm ε a, add_comm x ε] } end variable (α) lemma nhds_basis_zero_abs_sub_lt [no_min_order α] [no_max_order α] : (𝓝 (0 : α)).has_basis (λ ε : α, (0 : α) < ε) (λ ε, {b | |b| < ε}) := by simpa using nhds_basis_abs_sub_lt (0 : α) variable {α} /-- If `a` is positive we can form a basis from only nonnegative `Ioo` intervals -/ lemma nhds_basis_Ioo_pos_of_pos [no_min_order α] [no_max_order α] {a : α} (ha : 0 < a) : (𝓝 a).has_basis (λ ε : α, (0 : α) < ε ∧ ε ≤ a) (λ ε, Ioo (a-ε) (a+ε)) := ⟨ λ t, (nhds_basis_Ioo_pos a).mem_iff.trans ⟨λ h, let ⟨i, hi, hit⟩ := h in ⟨min i a, ⟨lt_min hi ha, min_le_right i a⟩, trans (Ioo_subset_Ioo (sub_le_sub_left (min_le_left i a) a) (add_le_add_left (min_le_left i a) a)) hit⟩, λ h, let ⟨i, hi, hit⟩ := h in ⟨i, hi.1, hit⟩ ⟩ ⟩ end linear_ordered_add_comm_group lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) := (image_eq_preimage_of_inverse neg_neg neg_neg).symm lemma filter.map_neg_eq_comap_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) := funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg) section order_topology variables [topological_space α] [topological_space β] [linear_order α] [linear_order β] [order_topology α] [order_topology β] lemma is_lub.frequently_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[≤] a, x ∈ s := begin rcases hs with ⟨a', ha'⟩, intro h, rcases (ha.1 ha').eq_or_lt with (rfl|ha'a), { exact h.self_of_nhds_within le_rfl ha' }, { rcases (mem_nhds_within_Iic_iff_exists_Ioc_subset' ha'a).1 h with ⟨b, hba, hb⟩, rcases ha.exists_between hba with ⟨b', hb's, hb'⟩, exact hb hb' hb's }, end lemma is_lub.frequently_nhds_mem {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_glb.frequently_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝[≥] a, x ∈ s := @is_lub.frequently_mem αᵒᵈ _ _ _ _ _ ha hs lemma is_glb.frequently_nhds_mem {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : ∃ᶠ x in 𝓝 a, x ∈ s := (ha.frequently_mem hs).filter_mono inf_le_left lemma is_lub.mem_closure {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_glb.mem_closure {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) : a ∈ closure s := (ha.frequently_nhds_mem hs).mem_closure lemma is_lub.nhds_within_ne_bot {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) : ne_bot (𝓝[s] a) := mem_closure_iff_nhds_within_ne_bot.1 (ha.mem_closure hs) lemma is_glb.nhds_within_ne_bot : ∀ {a : α} {s : set α}, is_glb s a → s.nonempty → ne_bot (𝓝[s] a) := @is_lub.nhds_within_ne_bot αᵒᵈ _ _ _ lemma is_lub_of_mem_nhds {s : set α} {a : α} {f : filter α} (hsa : a ∈ upper_bounds s) (hsf : s ∈ f) [ne_bot (f ⊓ 𝓝 a)] : is_lub s a := ⟨hsa, assume b hb, not_lt.1 $ assume hba, have s ∩ {a | b < a} ∈ f ⊓ 𝓝 a, from inter_mem_inf hsf (is_open.mem_nhds (is_open_lt' _) hba), let ⟨x, ⟨hxs, hxb⟩⟩ := filter.nonempty_of_mem this in have b < b, from lt_of_lt_of_le hxb $ hb hxs, lt_irrefl b this⟩ lemma is_lub_of_mem_closure {s : set α} {a : α} (hsa : a ∈ upper_bounds s) (hsf : a ∈ closure s) : is_lub s a := begin rw [mem_closure_iff_cluster_pt, cluster_pt, inf_comm] at hsf, haveI : (𝓟 s ⊓ 𝓝 a).ne_bot := hsf, exact is_lub_of_mem_nhds hsa (mem_principal_self s), end lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α}, a ∈ lower_bounds s → s ∈ f → ne_bot (f ⊓ 𝓝 a) → is_glb s a := @is_lub_of_mem_nhds αᵒᵈ _ _ _ lemma is_glb_of_mem_closure {s : set α} {a : α} (hsa : a ∈ lower_bounds s) (hsf : a ∈ closure s) : is_glb s a := @is_lub_of_mem_closure αᵒᵈ _ _ _ s a hsa hsf lemma is_lub.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : monotone_on f s) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := begin rintro _ ⟨x, hx, rfl⟩, replace ha := ha.inter_Ici_of_mem hx, haveI := ha.nhds_within_ne_bot ⟨x, hx, le_rfl⟩, refine ge_of_tendsto (hb.mono_left (nhds_within_mono _ (inter_subset_left s (Ici x)))) _, exact mem_of_superset self_mem_nhds_within (λ y hy, hf hx hy.1 hy.2) end -- For a version of this theorem in which the convergence considered on the domain `α` is as `x : α` -- tends to infinity, rather than tending to a point `x` in `α`, see `is_lub_of_tendsto_at_top` lemma is_lub.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : monotone_on f s) (ha : is_lub s a) (hs : s.nonempty) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : is_lub (f '' s) b := begin haveI := ha.nhds_within_ne_bot hs, exact ⟨ha.mem_upper_bounds_of_tendsto hf hb, λ b' hb', le_of_tendsto hb (mem_of_superset self_mem_nhds_within $ λ x hx, hb' $ mem_image_of_mem _ hx)⟩ end lemma is_glb.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : monotone_on f s) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto αᵒᵈ γᵒᵈ _ _ _ _ _ _ _ _ _ _ hf.dual ha hb -- For a version of this theorem in which the convergence considered on the domain `α` is as -- `x : α` tends to negative infinity, rather than tending to a point `x` in `α`, see -- `is_glb_of_tendsto_at_bot` lemma is_glb.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : monotone_on f s) : is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto αᵒᵈ γᵒᵈ _ _ _ _ _ _ f s a b hf.dual lemma is_lub.mem_lower_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : antitone_on f s) (ha : is_lub s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ lower_bounds (f '' s) := @is_lub.mem_upper_bounds_of_tendsto α γᵒᵈ _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_lub.is_glb_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (antitone_on f s) → is_lub s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b := @is_lub.is_lub_of_tendsto α γᵒᵈ _ _ _ _ _ _ lemma is_glb.mem_upper_bounds_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] {f : α → γ} {s : set α} {a : α} {b : γ} (hf : antitone_on f s) (ha : is_glb s a) (hb : tendsto f (𝓝[s] a) (𝓝 b)) : b ∈ upper_bounds (f '' s) := @is_glb.mem_lower_bounds_of_tendsto α γᵒᵈ _ _ _ _ _ _ _ _ _ _ hf ha hb lemma is_glb.is_lub_of_tendsto [preorder γ] [topological_space γ] [order_closed_topology γ] : ∀ {f : α → γ} {s : set α} {a : α} {b : γ}, (antitone_on f s) → is_glb s a → s.nonempty → tendsto f (𝓝[s] a) (𝓝 b) → is_lub (f '' s) b := @is_glb.is_glb_of_tendsto α γᵒᵈ _ _ _ _ _ _ lemma is_lub.mem_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_lub.mem_of_is_closed ← is_closed.is_lub_mem lemma is_glb.mem_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) (sc : is_closed s) : a ∈ s := sc.closure_subset $ ha.mem_closure hs alias is_glb.mem_of_is_closed ← is_closed.is_glb_mem /-! ### Existence of sequences tending to Inf or Sup of a given set -/ lemma is_lub.exists_seq_strict_mono_tendsto_of_not_mem {t : set α} {x : α} [is_countably_generated (𝓝 x)] (htx : is_lub t x) (not_mem : x ∉ t) (ht : t.nonempty) : ∃ u : ℕ → α, strict_mono u ∧ (∀ n, u n < x) ∧ tendsto u at_top (𝓝 x) ∧ (∀ n, u n ∈ t) := begin rcases ht with ⟨l, hl⟩, have hl : l < x, from (htx.1 hl).eq_or_lt.resolve_left (λ h, (not_mem $ h ▸ hl).elim), obtain ⟨s, hs⟩ : ∃ s : ℕ → set α, (𝓝 x).has_basis (λ (_x : ℕ), true) s := let ⟨s, hs⟩ := (𝓝 x).exists_antitone_basis in ⟨s, hs.to_has_basis⟩, have : ∀ n k, k < x → ∃ y, Icc y x ⊆ s n ∧ k < y ∧ y < x ∧ y ∈ t, { assume n k hk, obtain ⟨L, hL, h⟩ : ∃ (L : α) (hL : L ∈ Ico k x), Ioc L x ⊆ s n := exists_Ioc_subset_of_mem_nhds' (hs.mem_of_mem trivial) hk, obtain ⟨y, hy⟩ : ∃ (y : α), L < y ∧ y < x ∧ y ∈ t, { rcases htx.exists_between' not_mem hL.2 with ⟨y, yt, hy⟩, refine ⟨y, hy.1, hy.2, yt⟩ }, exact ⟨y, λ z hz, h ⟨hy.1.trans_le hz.1, hz.2⟩, hL.1.trans_lt hy.1, hy.2⟩ }, choose! f hf using this, let u : ℕ → α := λ n, nat.rec_on n (f 0 l) (λ n h, f n.succ h), have I : ∀ n, u n < x, { assume n, induction n with n IH, { exact (hf 0 l hl).2.2.1 }, { exact (hf n.succ _ IH).2.2.1 } }, have S : strict_mono u := strict_mono_nat_of_lt_succ (λ n, (hf n.succ _ (I n)).2.1), refine ⟨u, S, I, hs.tendsto_right_iff.2 (λ n _, _), (λ n, _)⟩, { simp only [ge_iff_le, eventually_at_top], refine ⟨n, λ p hp, _⟩, have up : u p ∈ Icc (u n) x := ⟨S.monotone hp, (I p).le⟩, have : Icc (u n) x ⊆ s n, by { cases n, { exact (hf 0 l hl).1 }, { exact (hf n.succ (u n) (I n)).1 } }, exact this up }, { cases n, { exact (hf 0 l hl).2.2.2 }, { exact (hf n.succ _ (I n)).2.2.2 } } end lemma is_lub.exists_seq_monotone_tendsto {t : set α} {x : α} [is_countably_generated (𝓝 x)] (htx : is_lub t x) (ht : t.nonempty) : ∃ u : ℕ → α, monotone u ∧ (∀ n, u n ≤ x) ∧ tendsto u at_top (𝓝 x) ∧ (∀ n, u n ∈ t) := begin by_cases h : x ∈ t, { exact ⟨λ n, x, monotone_const, λ n, le_rfl, tendsto_const_nhds, λ n, h⟩ }, { rcases htx.exists_seq_strict_mono_tendsto_of_not_mem h ht with ⟨u, hu⟩, exact ⟨u, hu.1.monotone, λ n, (hu.2.1 n).le, hu.2.2⟩ } end lemma exists_seq_strict_mono_tendsto' {α : Type*} [linear_order α] [topological_space α] [densely_ordered α] [order_topology α] [first_countable_topology α] {x y : α} (hy : y < x) : ∃ u : ℕ → α, strict_mono u ∧ (∀ n, u n ∈ Ioo y x) ∧ tendsto u at_top (𝓝 x) := begin have hx : x ∉ Ioo y x := λ h, (lt_irrefl x h.2).elim, have ht : set.nonempty (Ioo y x) := nonempty_Ioo.2 hy, rcases (is_lub_Ioo hy).exists_seq_strict_mono_tendsto_of_not_mem hx ht with ⟨u, hu⟩, exact ⟨u, hu.1, hu.2.2.symm⟩ end lemma exists_seq_strict_mono_tendsto [densely_ordered α] [no_min_order α] [first_countable_topology α] (x : α) : ∃ u : ℕ → α, strict_mono u ∧ (∀ n, u n < x) ∧ tendsto u at_top (𝓝 x) := begin obtain ⟨y, hy⟩ : ∃ y, y < x := exists_lt x, rcases exists_seq_strict_mono_tendsto' hy with ⟨u, hu_mono, hu_mem, hux⟩, exact ⟨u, hu_mono, λ n, (hu_mem n).2, hux⟩ end lemma exists_seq_strict_mono_tendsto_nhds_within [densely_ordered α] [no_min_order α] [first_countable_topology α] (x : α) : ∃ u : ℕ → α, strict_mono u ∧ (∀ n, u n < x) ∧ tendsto u at_top (𝓝[<] x) := let ⟨u, hu, hx, h⟩ := exists_seq_strict_mono_tendsto x in ⟨u, hu, hx, tendsto_nhds_within_mono_right (range_subset_iff.2 hx) $ tendsto_nhds_within_range.2 h⟩ lemma exists_seq_tendsto_Sup {α : Type*} [conditionally_complete_linear_order α] [topological_space α] [order_topology α] [first_countable_topology α] {S : set α} (hS : S.nonempty) (hS' : bdd_above S) : ∃ (u : ℕ → α), monotone u ∧ tendsto u at_top (𝓝 (Sup S)) ∧ (∀ n, u n ∈ S) := begin rcases (is_lub_cSup hS hS').exists_seq_monotone_tendsto hS with ⟨u, hu⟩, exact ⟨u, hu.1, hu.2.2⟩, end lemma is_glb.exists_seq_strict_anti_tendsto_of_not_mem {t : set α} {x : α} [is_countably_generated (𝓝 x)] (htx : is_glb t x) (not_mem : x ∉ t) (ht : t.nonempty) : ∃ u : ℕ → α, strict_anti u ∧ (∀ n, x < u n) ∧ tendsto u at_top (𝓝 x) ∧ (∀ n, u n ∈ t) := @is_lub.exists_seq_strict_mono_tendsto_of_not_mem αᵒᵈ _ _ _ t x _ htx not_mem ht lemma is_glb.exists_seq_antitone_tendsto {t : set α} {x : α} [is_countably_generated (𝓝 x)] (htx : is_glb t x) (ht : t.nonempty) : ∃ u : ℕ → α, antitone u ∧ (∀ n, x ≤ u n) ∧ tendsto u at_top (𝓝 x) ∧ (∀ n, u n ∈ t) := @is_lub.exists_seq_monotone_tendsto αᵒᵈ _ _ _ t x _ htx ht lemma exists_seq_strict_anti_tendsto' [densely_ordered α] [first_countable_topology α] {x y : α} (hy : x < y) : ∃ u : ℕ → α, strict_anti u ∧ (∀ n, u n ∈ Ioo x y) ∧ tendsto u at_top (𝓝 x) := by simpa only [dual_Ioo] using exists_seq_strict_mono_tendsto' (order_dual.to_dual_lt_to_dual.2 hy) lemma exists_seq_strict_anti_tendsto [densely_ordered α] [no_max_order α] [first_countable_topology α] (x : α) : ∃ u : ℕ → α, strict_anti u ∧ (∀ n, x < u n) ∧ tendsto u at_top (𝓝 x) := @exists_seq_strict_mono_tendsto αᵒᵈ _ _ _ _ _ _ x lemma exists_seq_strict_anti_tendsto_nhds_within [densely_ordered α] [no_max_order α] [first_countable_topology α] (x : α) : ∃ u : ℕ → α, strict_anti u ∧ (∀ n, x < u n) ∧ tendsto u at_top (𝓝[>] x) := @exists_seq_strict_mono_tendsto_nhds_within αᵒᵈ _ _ _ _ _ _ _ lemma exists_seq_strict_anti_strict_mono_tendsto [densely_ordered α] [first_countable_topology α] {x y : α} (h : x < y) : ∃ (u v : ℕ → α), strict_anti u ∧ strict_mono v ∧ (∀ k, u k ∈ Ioo x y) ∧ (∀ l, v l ∈ Ioo x y) ∧ (∀ k l, u k < v l) ∧ tendsto u at_top (𝓝 x) ∧ tendsto v at_top (𝓝 y) := begin rcases exists_seq_strict_anti_tendsto' h with ⟨u, hu_anti, hu_mem, hux⟩, rcases exists_seq_strict_mono_tendsto' (hu_mem 0).2 with ⟨v, hv_mono, hv_mem, hvy⟩, exact ⟨u, v, hu_anti, hv_mono, hu_mem, λ l, ⟨(hu_mem 0).1.trans (hv_mem l).1, (hv_mem l).2⟩, λ k l, (hu_anti.antitone (zero_le k)).trans_lt (hv_mem l).1, hux, hvy⟩ end lemma exists_seq_tendsto_Inf {α : Type*} [conditionally_complete_linear_order α] [topological_space α] [order_topology α] [first_countable_topology α] {S : set α} (hS : S.nonempty) (hS' : bdd_below S) : ∃ (u : ℕ → α), antitone u ∧ tendsto u at_top (𝓝 (Inf S)) ∧ (∀ n, u n ∈ S) := @exists_seq_tendsto_Sup αᵒᵈ _ _ _ _ S hS hS' end order_topology section densely_ordered variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α] {a b : α} {s : set α} /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top element. -/ lemma closure_Ioi' {a : α} (h : (Ioi a).nonempty) : closure (Ioi a) = Ici a := begin apply subset.antisymm, { exact closure_minimal Ioi_subset_Ici_self is_closed_Ici }, { rw [← diff_subset_closure_iff, Ici_diff_Ioi_same, singleton_subset_iff], exact is_glb_Ioi.mem_closure h } end /-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/ @[simp] lemma closure_Ioi (a : α) [no_max_order α] : closure (Ioi a) = Ici a := closure_Ioi' nonempty_Ioi /-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom element. -/ lemma closure_Iio' (h : (Iio a).nonempty) : closure (Iio a) = Iic a := @closure_Ioi' αᵒᵈ _ _ _ _ _ h /-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/ @[simp] lemma closure_Iio (a : α) [no_min_order α] : closure (Iio a) = Iic a := closure_Iio' nonempty_Iio /-- The closure of the open interval `(a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioo {a b : α} (hab : a ≠ b) : closure (Ioo a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioo_subset_Icc_self is_closed_Icc }, { cases hab.lt_or_lt with hab hab, { rw [← diff_subset_closure_iff, Icc_diff_Ioo_same hab.le], have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab, simp only [insert_subset, singleton_subset_iff], exact ⟨(is_glb_Ioo hab).mem_closure hab', (is_lub_Ioo hab).mem_closure hab'⟩ }, { rw Icc_eq_empty_of_lt hab, exact empty_subset _ } } end /-- The closure of the interval `(a, b]` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ioc {a b : α} (hab : a ≠ b) : closure (Ioc a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ioc_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ioc_self), rw closure_Ioo hab } end /-- The closure of the interval `[a, b)` is the closed interval `[a, b]`. -/ @[simp] lemma closure_Ico {a b : α} (hab : a ≠ b) : closure (Ico a b) = Icc a b := begin apply subset.antisymm, { exact closure_minimal Ico_subset_Icc_self is_closed_Icc }, { apply subset.trans _ (closure_mono Ioo_subset_Ico_self), rw closure_Ioo hab } end @[simp] lemma interior_Ici' {a : α} (ha : (Iio a).nonempty) : interior (Ici a) = Ioi a := by rw [← compl_Iio, interior_compl, closure_Iio' ha, compl_Iic] lemma interior_Ici [no_min_order α] {a : α} : interior (Ici a) = Ioi a := interior_Ici' nonempty_Iio @[simp] lemma interior_Iic' {a : α} (ha : (Ioi a).nonempty) : interior (Iic a) = Iio a := @interior_Ici' αᵒᵈ _ _ _ _ _ ha lemma interior_Iic [no_max_order α] {a : α} : interior (Iic a) = Iio a := interior_Iic' nonempty_Ioi @[simp] lemma interior_Icc [no_min_order α] [no_max_order α] {a b : α}: interior (Icc a b) = Ioo a b := by rw [← Ici_inter_Iic, interior_inter, interior_Ici, interior_Iic, Ioi_inter_Iio] @[simp] lemma interior_Ico [no_min_order α] {a b : α} : interior (Ico a b) = Ioo a b := by rw [← Ici_inter_Iio, interior_inter, interior_Ici, interior_Iio, Ioi_inter_Iio] @[simp] lemma interior_Ioc [no_max_order α] {a b : α} : interior (Ioc a b) = Ioo a b := by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio] lemma closure_interior_Icc {a b : α} (h : a ≠ b) : closure (interior (Icc a b)) = Icc a b := (closure_minimal interior_subset is_closed_Icc).antisymm $ calc Icc a b = closure (Ioo a b) : (closure_Ioo h).symm ... ⊆ closure (interior (Icc a b)) : closure_mono (interior_maximal Ioo_subset_Icc_self is_open_Ioo) lemma Ioc_subset_closure_interior (a b : α) : Ioc a b ⊆ closure (interior (Ioc a b)) := begin rcases eq_or_ne a b with rfl|h, { simp }, { calc Ioc a b ⊆ Icc a b : Ioc_subset_Icc_self ... = closure (Ioo a b) : (closure_Ioo h).symm ... ⊆ closure (interior (Ioc a b)) : closure_mono (interior_maximal Ioo_subset_Ioc_self is_open_Ioo) } end lemma Ico_subset_closure_interior (a b : α) : Ico a b ⊆ closure (interior (Ico a b)) := by simpa only [dual_Ioc] using Ioc_subset_closure_interior (order_dual.to_dual b) (order_dual.to_dual a) @[simp] lemma frontier_Ici' {a : α} (ha : (Iio a).nonempty) : frontier (Ici a) = {a} := by simp [frontier, ha] lemma frontier_Ici [no_min_order α] {a : α} : frontier (Ici a) = {a} := frontier_Ici' nonempty_Iio @[simp] lemma frontier_Iic' {a : α} (ha : (Ioi a).nonempty) : frontier (Iic a) = {a} := by simp [frontier, ha] lemma frontier_Iic [no_max_order α] {a : α} : frontier (Iic a) = {a} := frontier_Iic' nonempty_Ioi @[simp] lemma frontier_Ioi' {a : α} (ha : (Ioi a).nonempty) : frontier (Ioi a) = {a} := by simp [frontier, closure_Ioi' ha, Iic_diff_Iio, Icc_self] lemma frontier_Ioi [no_max_order α] {a : α} : frontier (Ioi a) = {a} := frontier_Ioi' nonempty_Ioi @[simp] lemma frontier_Iio' {a : α} (ha : (Iio a).nonempty) : frontier (Iio a) = {a} := by simp [frontier, closure_Iio' ha, Iic_diff_Iio, Icc_self] lemma frontier_Iio [no_min_order α] {a : α} : frontier (Iio a) = {a} := frontier_Iio' nonempty_Iio @[simp] lemma frontier_Icc [no_min_order α] [no_max_order α] {a b : α} (h : a ≤ b) : frontier (Icc a b) = {a, b} := by simp [frontier, h, Icc_diff_Ioo_same] @[simp] lemma frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} := by rw [frontier, closure_Ioo h.ne, interior_Ioo, Icc_diff_Ioo_same h.le] @[simp] lemma frontier_Ico [no_min_order α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} := by rw [frontier, closure_Ico h.ne, interior_Ico, Icc_diff_Ioo_same h.le] @[simp] lemma frontier_Ioc [no_max_order α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} := by rw [frontier, closure_Ioc h.ne, interior_Ioc, Icc_diff_Ioo_same h.le] lemma nhds_within_Ioi_ne_bot' {a b : α} (H₁ : (Ioi a).nonempty) (H₂ : a ≤ b) : ne_bot (𝓝[Ioi a] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by rwa [closure_Ioi' H₁] lemma nhds_within_Ioi_ne_bot [no_max_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Ioi a] b) := nhds_within_Ioi_ne_bot' nonempty_Ioi H lemma nhds_within_Ioi_self_ne_bot' {a : α} (H : (Ioi a).nonempty) : ne_bot (𝓝[>] a) := nhds_within_Ioi_ne_bot' H (le_refl a) @[instance] lemma nhds_within_Ioi_self_ne_bot [no_max_order α] (a : α) : ne_bot (𝓝[>] a) := nhds_within_Ioi_ne_bot (le_refl a) lemma filter.eventually.exists_gt [no_max_order α] {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∃ b > a, p b := by simpa only [exists_prop, gt_iff_lt, and_comm] using ((h.filter_mono (@nhds_within_le_nhds _ _ a (Ioi a))).and self_mem_nhds_within).exists lemma nhds_within_Iio_ne_bot' {b c : α} (H₁ : (Iio c).nonempty) (H₂ : b ≤ c) : ne_bot (𝓝[Iio c] b) := mem_closure_iff_nhds_within_ne_bot.1 $ by rwa closure_Iio' H₁ lemma nhds_within_Iio_ne_bot [no_min_order α] {a b : α} (H : a ≤ b) : ne_bot (𝓝[Iio b] a) := nhds_within_Iio_ne_bot' nonempty_Iio H lemma nhds_within_Iio_self_ne_bot' {b : α} (H : (Iio b).nonempty) : ne_bot (𝓝[<] b) := nhds_within_Iio_ne_bot' H (le_refl b) @[instance] lemma nhds_within_Iio_self_ne_bot [no_min_order α] (a : α) : ne_bot (𝓝[<] a) := nhds_within_Iio_ne_bot (le_refl a) lemma filter.eventually.exists_lt [no_min_order α] {a : α} {p : α → Prop} (h : ∀ᶠ x in 𝓝 a, p x) : ∃ b < a, p b := @filter.eventually.exists_gt αᵒᵈ _ _ _ _ _ _ _ h lemma right_nhds_within_Ico_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ico a b] b) := (is_lub_Ico H).nhds_within_ne_bot (nonempty_Ico.2 H) lemma left_nhds_within_Ioc_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioc a b] a) := (is_glb_Ioc H).nhds_within_ne_bot (nonempty_Ioc.2 H) lemma left_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] a) := (is_glb_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) lemma right_nhds_within_Ioo_ne_bot {a b : α} (H : a < b) : ne_bot (𝓝[Ioo a b] b) := (is_lub_Ioo H).nhds_within_ne_bot (nonempty_Ioo.2 H) lemma comap_coe_nhds_within_Iio_of_Ioo_subset (hb : s ⊆ Iio b) (hs : s.nonempty → ∃ a < b, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[<] b) = at_top := begin nontriviality, haveI : nonempty s := nontrivial_iff_nonempty.1 ‹_›, rcases hs (nonempty_subtype.1 ‹_›) with ⟨a, h, hs⟩, ext u, split, { rintros ⟨t, ht, hts⟩, obtain ⟨x, ⟨hxa : a ≤ x, hxb : x < b⟩, hxt : Ioo x b ⊆ t⟩ := (mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset h).mp ht, obtain ⟨y, hxy, hyb⟩ := exists_between hxb, refine mem_of_superset (mem_at_top ⟨y, hs ⟨hxa.trans_lt hxy, hyb⟩⟩) _, rintros ⟨z, hzs⟩ (hyz : y ≤ z), refine hts (hxt ⟨hxy.trans_le _, hb _⟩); assumption }, { intros hu, obtain ⟨x : s, hx : ∀ z, x ≤ z → z ∈ u⟩ := mem_at_top_sets.1 hu, exact ⟨Ioo x b, Ioo_mem_nhds_within_Iio (right_mem_Ioc.2 $ hb x.2), λ z hz, hx _ hz.1.le⟩ } end lemma comap_coe_nhds_within_Ioi_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : s.nonempty → ∃ b > a, Ioo a b ⊆ s) : comap (coe : s → α) (𝓝[>] a) = at_bot := comap_coe_nhds_within_Iio_of_Ioo_subset (show of_dual ⁻¹' s ⊆ Iio (to_dual a), from ha) (λ h, by simpa only [order_dual.exists, dual_Ioo] using hs h) lemma map_coe_at_top_of_Ioo_subset (hb : s ⊆ Iio b) (hs : ∀ a' < b, ∃ a < b, Ioo a b ⊆ s) : map (coe : s → α) at_top = 𝓝[<] b := begin rcases eq_empty_or_nonempty (Iio b) with (hb'|⟨a, ha⟩), { rw [filter_eq_bot_of_is_empty at_top, filter.map_bot, hb', nhds_within_empty], exact ⟨λ x, hb'.subset (hb x.2)⟩ }, { rw [← comap_coe_nhds_within_Iio_of_Ioo_subset hb (λ _, hs a ha), map_comap_of_mem], rw subtype.range_coe, exact (mem_nhds_within_Iio_iff_exists_Ioo_subset' ha).2 (hs a ha) }, end lemma map_coe_at_bot_of_Ioo_subset (ha : s ⊆ Ioi a) (hs : ∀ b' > a, ∃ b > a, Ioo a b ⊆ s) : map (coe : s → α) at_bot = (𝓝[>] a) := begin -- the elaborator gets stuck without `(... : _)` refine (map_coe_at_top_of_Ioo_subset (show of_dual ⁻¹' s ⊆ Iio (to_dual a), from ha) (λ b' hb', _) : _), simpa only [order_dual.exists, dual_Ioo] using hs b' hb', end /-- The `at_top` filter for an open interval `Ioo a b` comes from the left-neighbourhoods filter at the right endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Iio (a b : α) : comap (coe : Ioo a b → α) (𝓝[<] b) = at_top := comap_coe_nhds_within_Iio_of_Ioo_subset Ioo_subset_Iio_self $ λ h, ⟨a, nonempty_Ioo.1 h, subset.refl _⟩ /-- The `at_bot` filter for an open interval `Ioo a b` comes from the right-neighbourhoods filter at the left endpoint in the ambient order. -/ lemma comap_coe_Ioo_nhds_within_Ioi (a b : α) : comap (coe : Ioo a b → α) (𝓝[>] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset Ioo_subset_Ioi_self $ λ h, ⟨b, nonempty_Ioo.1 h, subset.refl _⟩ lemma comap_coe_Ioi_nhds_within_Ioi (a : α) : comap (coe : Ioi a → α) (𝓝[>] a) = at_bot := comap_coe_nhds_within_Ioi_of_Ioo_subset (subset.refl _) $ λ ⟨x, hx⟩, ⟨x, hx, Ioo_subset_Ioi_self⟩ lemma comap_coe_Iio_nhds_within_Iio (a : α) : comap (coe : Iio a → α) (𝓝[<] a) = at_top := @comap_coe_Ioi_nhds_within_Ioi αᵒᵈ _ _ _ _ a @[simp] lemma map_coe_Ioo_at_top {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_top = 𝓝[<] b := map_coe_at_top_of_Ioo_subset Ioo_subset_Iio_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioo_at_bot {a b : α} (h : a < b) : map (coe : Ioo a b → α) at_bot = 𝓝[>] a := map_coe_at_bot_of_Ioo_subset Ioo_subset_Ioi_self $ λ _ _, ⟨_, h, subset.refl _⟩ @[simp] lemma map_coe_Ioi_at_bot (a : α) : map (coe : Ioi a → α) at_bot = 𝓝[>] a := map_coe_at_bot_of_Ioo_subset (subset.refl _) $ λ b hb, ⟨b, hb, Ioo_subset_Ioi_self⟩ @[simp] lemma map_coe_Iio_at_top (a : α) : map (coe : Iio a → α) at_top = 𝓝[<] a := @map_coe_Ioi_at_bot αᵒᵈ _ _ _ _ _ variables {l : filter β} {f : α → β} @[simp] lemma tendsto_comp_coe_Ioo_at_top (h : a < b) : tendsto (λ x : Ioo a b, f x) at_top l ↔ tendsto f (𝓝[<] b) l := by rw [← map_coe_Ioo_at_top h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioo_at_bot (h : a < b) : tendsto (λ x : Ioo a b, f x) at_bot l ↔ tendsto f (𝓝[>] a) l := by rw [← map_coe_Ioo_at_bot h, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Ioi_at_bot : tendsto (λ x : Ioi a, f x) at_bot l ↔ tendsto f (𝓝[>] a) l := by rw [← map_coe_Ioi_at_bot, tendsto_map'_iff] @[simp] lemma tendsto_comp_coe_Iio_at_top : tendsto (λ x : Iio a, f x) at_top l ↔ tendsto f (𝓝[<] a) l := by rw [← map_coe_Iio_at_top, tendsto_map'_iff] @[simp] lemma tendsto_Ioo_at_top {f : β → Ioo a b} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[<] b) := by rw [← comap_coe_Ioo_nhds_within_Iio, tendsto_comap_iff] @[simp] lemma tendsto_Ioo_at_bot {f : β → Ioo a b} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[>] a) := by rw [← comap_coe_Ioo_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Ioi_at_bot {f : β → Ioi a} : tendsto f l at_bot ↔ tendsto (λ x, (f x : α)) l (𝓝[>] a) := by rw [← comap_coe_Ioi_nhds_within_Ioi, tendsto_comap_iff] @[simp] lemma tendsto_Iio_at_top {f : β → Iio a} : tendsto f l at_top ↔ tendsto (λ x, (f x : α)) l (𝓝[<] a) := by rw [← comap_coe_Iio_nhds_within_Iio, tendsto_comap_iff] instance (x : α) [nontrivial α] : ne_bot (𝓝[≠] x) := begin apply forall_mem_nonempty_iff_ne_bot.1 (λ s hs, _), obtain ⟨u, u_open, xu, us⟩ : ∃ (u : set α), is_open u ∧ x ∈ u ∧ u ∩ {x}ᶜ ⊆ s := mem_nhds_within.1 hs, obtain ⟨a, b, a_lt_b, hab⟩ : ∃ (a b : α), a < b ∧ Ioo a b ⊆ u := u_open.exists_Ioo_subset ⟨x, xu⟩, obtain ⟨y, hy⟩ : ∃ y, a < y ∧ y < b := exists_between a_lt_b, rcases ne_or_eq x y with xy|rfl, { exact ⟨y, us ⟨hab hy, xy.symm⟩⟩ }, obtain ⟨z, hz⟩ : ∃ z, a < z ∧ z < x := exists_between hy.1, exact ⟨z, us ⟨hab ⟨hz.1, hz.2.trans hy.2⟩, hz.2.ne⟩⟩, end /-- Let `s` be a dense set in a nontrivial dense linear order `α`. If `s` is a separable space (e.g., if `α` has a second countable topology), then there exists a countable dense subset `t ⊆ s` such that `t` does not contain bottom/top elements of `α`. -/ lemma dense.exists_countable_dense_subset_no_bot_top [nontrivial α] {s : set α} [separable_space s] (hs : dense s) : ∃ t ⊆ s, t.countable ∧ dense t ∧ (∀ x, is_bot x → x ∉ t) ∧ (∀ x, is_top x → x ∉ t) := begin rcases hs.exists_countable_dense_subset with ⟨t, hts, htc, htd⟩, refine ⟨t \ ({x | is_bot x} ∪ {x | is_top x}), _, _, _, _, _⟩, { exact (diff_subset _ _).trans hts }, { exact htc.mono (diff_subset _ _) }, { exact htd.diff_finite ((subsingleton_is_bot α).finite.union (subsingleton_is_top α).finite) }, { assume x hx, simp [hx] }, { assume x hx, simp [hx] } end variable (α) /-- If `α` is a nontrivial separable dense linear order, then there exists a countable dense set `s : set α` that contains neither top nor bottom elements of `α`. For a dense set containing both bot and top elements, see `exists_countable_dense_bot_top`. -/ lemma exists_countable_dense_no_bot_top [separable_space α] [nontrivial α] : ∃ s : set α, s.countable ∧ dense s ∧ (∀ x, is_bot x → x ∉ s) ∧ (∀ x, is_top x → x ∉ s) := by simpa using dense_univ.exists_countable_dense_subset_no_bot_top end densely_ordered section complete_linear_order variables [complete_linear_order α] [topological_space α] [order_topology α] [complete_linear_order β] [topological_space β] [order_closed_topology β] [nonempty γ] lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Sup s ∈ closure s := (is_lub_Sup s).mem_closure hs lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) : Inf s ∈ closure s := (is_glb_Inf s).mem_closure hs lemma is_closed.Sup_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Sup s ∈ s := (is_lub_Sup s).mem_of_is_closed hs hc lemma is_closed.Inf_mem {α : Type u} [topological_space α] [complete_linear_order α] [order_topology α] {s : set α} (hs : s.nonempty) (hc : is_closed s) : Inf s ∈ s := (is_glb_Inf s).mem_of_is_closed hs hc /-- A monotone function continuous at the supremum of a nonempty set sends this supremum to the supremum of the image of this set. -/ lemma monotone.map_Sup_of_continuous_at' {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (hs : s.nonempty) : f (Sup s) = Sup (f '' s) := --This is a particular case of the more general is_lub.is_lub_of_tendsto ((is_lub_Sup _).is_lub_of_tendsto (λ x hx y hy xy, Mf xy) hs $ Cf.mono_left inf_le_left).Sup_eq.symm /-- A monotone function `f` sending `bot` to `bot` and continuous at the supremum of a set sends this supremum to the supremum of the image of this set. -/ lemma monotone.map_Sup_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (Sup s) = Sup (f '' s) := begin cases s.eq_empty_or_nonempty with h h, { simp [h, fbot] }, { exact Mf.map_Sup_of_continuous_at' Cf h } end /-- A monotone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed supremum of the composition. -/ lemma monotone.map_supr_of_continuous_at' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, Mf.map_Sup_of_continuous_at' Cf (range_nonempty g), ← range_comp, supr] /-- If a monotone function sending `bot` to `bot` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ lemma monotone.map_supr_of_continuous_at {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Mf : monotone f) (fbot : f ⊥ = ⊥) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, Mf.map_Sup_of_continuous_at Cf fbot, ← range_comp, supr] /-- A monotone function continuous at the infimum of a nonempty set sends this infimum to the infimum of the image of this set. -/ lemma monotone.map_Inf_of_continuous_at' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (hs : s.nonempty) : f (Inf s) = Inf (f '' s) := @monotone.map_Sup_of_continuous_at' αᵒᵈ βᵒᵈ _ _ _ _ _ _ f s Cf Mf.dual hs /-- A monotone function `f` sending `top` to `top` and continuous at the infimum of a set sends this infimum to the infimum of the image of this set. -/ lemma monotone.map_Inf_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (Inf s) = Inf (f '' s) := @monotone.map_Sup_of_continuous_at αᵒᵈ βᵒᵈ _ _ _ _ _ _ f s Cf Mf.dual ftop /-- A monotone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed infimum of the composition. -/ lemma monotone.map_infi_of_continuous_at' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) : f (⨅ i, g i) = ⨅ i, f (g i) := @monotone.map_supr_of_continuous_at' αᵒᵈ βᵒᵈ _ _ _ _ _ _ ι _ f g Cf Mf.dual /-- If a monotone function sending `top` to `top` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed infimum of the composition. -/ lemma monotone.map_infi_of_continuous_at {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Mf : monotone f) (ftop : f ⊤ = ⊤) : f (infi g) = infi (f ∘ g) := @monotone.map_supr_of_continuous_at αᵒᵈ βᵒᵈ _ _ _ _ _ _ ι f g Cf Mf.dual ftop /-- An antitone function continuous at the supremum of a nonempty set sends this supremum to the infimum of the image of this set. -/ lemma antitone.map_Sup_of_continuous_at' {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Af : antitone f) (hs : s.nonempty) : f (Sup s) = Inf (f '' s) := monotone.map_Sup_of_continuous_at' (show continuous_at (order_dual.to_dual ∘ f) (Sup s), from Cf) Af hs /-- An antitone function `f` sending `bot` to `top` and continuous at the supremum of a set sends this supremum to the infimum of the image of this set. -/ lemma antitone.map_Sup_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Af : antitone f) (fbot : f ⊥ = ⊤) : f (Sup s) = Inf (f '' s) := monotone.map_Sup_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (Sup s), from Cf) Af fbot /-- An antitone function continuous at the indexed supremum over a nonempty `Sort` sends this indexed supremum to the indexed infimum of the composition. -/ lemma antitone.map_supr_of_continuous_at' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Af : antitone f) : f (⨆ i, g i) = ⨅ i, f (g i) := monotone.map_supr_of_continuous_at' (show continuous_at (order_dual.to_dual ∘ f) (supr g), from Cf) Af /-- An antitone function sending `bot` to `top` is continuous at the indexed supremum over a `Sort`, then it sends this indexed supremum to the indexed supremum of the composition. -/ lemma antitone.map_supr_of_continuous_at {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (supr g)) (Af : antitone f) (fbot : f ⊥ = ⊤) : f (⨆ i, g i) = ⨅ i, f (g i) := monotone.map_supr_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (supr g), from Cf) Af fbot /-- An antitone function continuous at the infimum of a nonempty set sends this infimum to the supremum of the image of this set. -/ lemma antitone.map_Inf_of_continuous_at' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Af : antitone f) (hs : s.nonempty) : f (Inf s) = Sup (f '' s) := monotone.map_Inf_of_continuous_at' (show continuous_at (order_dual.to_dual ∘ f) (Inf s), from Cf) Af hs /-- An antitone function `f` sending `top` to `bot` and continuous at the infimum of a set sends this infimum to the supremum of the image of this set. -/ lemma antitone.map_Inf_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Af : antitone f) (ftop : f ⊤ = ⊥) : f (Inf s) = Sup (f '' s) := monotone.map_Inf_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (Inf s), from Cf) Af ftop /-- An antitone function continuous at the indexed infimum over a nonempty `Sort` sends this indexed infimum to the indexed supremum of the composition. -/ lemma antitone.map_infi_of_continuous_at' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Af : antitone f) : f (⨅ i, g i) = ⨆ i, f (g i) := monotone.map_infi_of_continuous_at' (show continuous_at (order_dual.to_dual ∘ f) (infi g), from Cf) Af /-- If an antitone function sending `top` to `bot` is continuous at the indexed infimum over a `Sort`, then it sends this indexed infimum to the indexed supremum of the composition. -/ lemma antitone.map_infi_of_continuous_at {ι : Sort*} {f : α → β} {g : ι → α} (Cf : continuous_at f (infi g)) (Af : antitone f) (ftop : f ⊤ = ⊥) : f (infi g) = supr (f ∘ g) := monotone.map_infi_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (infi g), from Cf) Af ftop end complete_linear_order section conditionally_complete_linear_order variables [conditionally_complete_linear_order α] [topological_space α] [order_topology α] [conditionally_complete_linear_order β] [topological_space β] [order_closed_topology β] [nonempty γ] lemma cSup_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ closure s := (is_lub_cSup hs B).mem_closure hs lemma cInf_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ closure s := (is_glb_cInf hs B).mem_closure hs lemma is_closed.cSup_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ s := (is_lub_cSup hs B).mem_of_is_closed hs hc lemma is_closed.cInf_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ s := (is_glb_cInf hs B).mem_of_is_closed hs hc /-- If a monotone function is continuous at the supremum of a nonempty bounded above set `s`, then it sends this supremum to the supremum of the image of `s`. -/ lemma monotone.map_cSup_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_above s) : f (Sup s) = Sup (f '' s) := begin refine ((is_lub_cSup (ne.image f) (Mf.map_bdd_above H)).unique _).symm, refine (is_lub_cSup ne H).is_lub_of_tendsto (λx hx y hy xy, Mf xy) ne _, exact Cf.mono_left inf_le_left end /-- If a monotone function is continuous at the indexed supremum of a bounded function on a nonempty `Sort`, then it sends this supremum to the supremum of the composition. -/ lemma monotone.map_csupr_of_continuous_at {f : α → β} {g : γ → α} (Cf : continuous_at f (⨆ i, g i)) (Mf : monotone f) (H : bdd_above (range g)) : f (⨆ i, g i) = ⨆ i, f (g i) := by rw [supr, Mf.map_cSup_of_continuous_at Cf (range_nonempty _) H, ← range_comp, supr] /-- If a monotone function is continuous at the infimum of a nonempty bounded below set `s`, then it sends this infimum to the infimum of the image of `s`. -/ lemma monotone.map_cInf_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Mf : monotone f) (ne : s.nonempty) (H : bdd_below s) : f (Inf s) = Inf (f '' s) := @monotone.map_cSup_of_continuous_at αᵒᵈ βᵒᵈ _ _ _ _ _ _ f s Cf Mf.dual ne H /-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally complete linear order, under a boundedness assumption. -/ lemma monotone.map_cinfi_of_continuous_at {f : α → β} {g : γ → α} (Cf : continuous_at f (⨅ i, g i)) (Mf : monotone f) (H : bdd_below (range g)) : f (⨅ i, g i) = ⨅ i, f (g i) := @monotone.map_csupr_of_continuous_at αᵒᵈ βᵒᵈ _ _ _ _ _ _ _ _ _ _ Cf Mf.dual H /-- If an antitone function is continuous at the supremum of a nonempty bounded above set `s`, then it sends this supremum to the infimum of the image of `s`. -/ lemma antitone.map_cSup_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Sup s)) (Af : antitone f) (ne : s.nonempty) (H : bdd_above s) : f (Sup s) = Inf (f '' s) := monotone.map_cSup_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (Sup s), from Cf) Af ne H /-- If an antitone function is continuous at the indexed supremum of a bounded function on a nonempty `Sort`, then it sends this supremum to the infimum of the composition. -/ lemma antitone.map_csupr_of_continuous_at {f : α → β} {g : γ → α} (Cf : continuous_at f (⨆ i, g i)) (Af : antitone f) (H : bdd_above (range g)) : f (⨆ i, g i) = ⨅ i, f (g i) := monotone.map_csupr_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (⨆ i, g i), from Cf) Af H /-- If an antitone function is continuous at the infimum of a nonempty bounded below set `s`, then it sends this infimum to the supremum of the image of `s`. -/ lemma antitone.map_cInf_of_continuous_at {f : α → β} {s : set α} (Cf : continuous_at f (Inf s)) (Af : antitone f) (ne : s.nonempty) (H : bdd_below s) : f (Inf s) = Sup (f '' s) := monotone.map_cInf_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (Inf s), from Cf) Af ne H /-- A continuous antitone function sends indexed infimum to indexed supremum in conditionally complete linear order, under a boundedness assumption. -/ lemma antitone.map_cinfi_of_continuous_at {f : α → β} {g : γ → α} (Cf : continuous_at f (⨅ i, g i)) (Af : antitone f) (H : bdd_below (range g)) : f (⨅ i, g i) = ⨆ i, f (g i) := monotone.map_cinfi_of_continuous_at (show continuous_at (order_dual.to_dual ∘ f) (⨅ i, g i), from Cf) Af H /-- A monotone map has a limit to the left of any point `x`, equal to `Sup (f '' (Iio x))`. -/ lemma monotone.tendsto_nhds_within_Iio {α β : Type*} [linear_order α] [topological_space α] [order_topology α] [conditionally_complete_linear_order β] [topological_space β] [order_topology β] {f : α → β} (Mf : monotone f) (x : α) : tendsto f (𝓝[<] x) (𝓝 (Sup (f '' (Iio x)))) := begin rcases eq_empty_or_nonempty (Iio x) with h|h, { simp [h] }, refine tendsto_order.2 ⟨λ l hl, _, λ m hm, _⟩, { obtain ⟨z, zx, lz⟩ : ∃ (a : α), a < x ∧ l < f a, by simpa only [mem_image, exists_prop, exists_exists_and_eq_and] using exists_lt_of_lt_cSup (nonempty_image_iff.2 h) hl, exact (mem_nhds_within_Iio_iff_exists_Ioo_subset' zx).2 ⟨z, zx, λ y hy, lz.trans_le (Mf (hy.1.le))⟩ }, { filter_upwards [self_mem_nhds_within] with _ hy, apply lt_of_le_of_lt _ hm, exact le_cSup (Mf.map_bdd_above bdd_above_Iio) (mem_image_of_mem _ hy), }, end /-- A monotone map has a limit to the right of any point `x`, equal to `Inf (f '' (Ioi x))`. -/ lemma monotone.tendsto_nhds_within_Ioi {α β : Type*} [linear_order α] [topological_space α] [order_topology α] [conditionally_complete_linear_order β] [topological_space β] [order_topology β] {f : α → β} (Mf : monotone f) (x : α) : tendsto f (𝓝[>] x) (𝓝 (Inf (f '' (Ioi x)))) := @monotone.tendsto_nhds_within_Iio αᵒᵈ βᵒᵈ _ _ _ _ _ _ f Mf.dual x end conditionally_complete_linear_order section nhds_with_pos section linear_ordered_add_comm_group variables [linear_order α] [has_zero α] [topological_space α] [order_topology α] lemma eventually_nhds_within_pos_mem_Ioo {ε : α} (h : 0 < ε) : ∀ᶠ x in 𝓝[>] 0, x ∈ Ioo 0 ε := Ioo_mem_nhds_within_Ioi (left_mem_Ico.2 h) lemma eventually_nhds_within_pos_mem_Ioc {ε : α} (h : 0 < ε) : ∀ᶠ x in 𝓝[>] 0, x ∈ Ioc 0 ε := Ioc_mem_nhds_within_Ioi (left_mem_Ico.2 h) end linear_ordered_add_comm_group end nhds_with_pos end order_topology
6db0d0f2add6c8e6cbb6d3d54b870b4d2d0eda38
367134ba5a65885e863bdc4507601606690974c1
/archive/imo/imo1998_q2.lean
f4e5364b443a2c6a64d259fa84b4110905fc889a
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
9,579
lean
/- Copyright (c) 2020 Oliver Nash. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Oliver Nash -/ import data.fintype.basic import data.int.parity import algebra.big_operators.order import tactic.ring import tactic.noncomm_ring /-! # IMO 1998 Q2 In a competition, there are `a` contestants and `b` judges, where `b ≥ 3` is an odd integer. Each judge rates each contestant as either "pass" or "fail". Suppose `k` is a number such that, for any two judges, their ratings coincide for at most `k` contestants. Prove that `k / a ≥ (b - 1) / (2b)`. ## Solution The problem asks us to think about triples consisting of a contestant and two judges whose ratings agree for that contestant. We thus consider the subset `A ⊆ C × JJ` of all such incidences of agreement, where `C` and `J` are the sets of contestants and judges, and `JJ = J × J − {(j, j)}`. We have natural maps: `left : A → C` and `right: A → JJ`. We count the elements of `A` in two ways: as the sum of the cardinalities of the fibres of `left` and as the sum of the cardinalities of the fibres of `right`. We obtain an upper bound on the cardinality of `A` from the count for `right`, and a lower bound from the count for `left`. These two bounds combine to the required result. First consider the map `right : A → JJ`. Since the size of any fibre over a point in JJ is bounded by `k` and since `|JJ| = b^2 - b`, we obtain the upper bound: `|A| ≤ k(b^2−b)`. Now consider the map `left : A → C`. The fibre over a given contestant `c ∈ C` is the set of ordered pairs of (distinct) judges who agree about `c`. We seek to bound the cardinality of this fibre from below. Minimum agreement for a contestant occurs when the judges' ratings are split as evenly as possible. Since `b` is odd, this occurs when they are divided into groups of size `(b−1)/2` and `(b+1)/2`. This corresponds to a fibre of cardinality `(b-1)^2/2` and so we obtain the lower bound: `a(b-1)^2/2 ≤ |A|`. Rearranging gives the result. -/ open_locale classical noncomputable theory /-- An ordered pair of judges. -/ abbreviation judge_pair (J : Type*) := J × J /-- A triple consisting of contestant together with an ordered pair of judges. -/ abbreviation agreed_triple (C J : Type*) := C × (judge_pair J) variables {C J : Type*} (r : C → J → Prop) /-- The first judge from an ordered pair of judges. -/ abbreviation judge_pair.judge₁ : judge_pair J → J := prod.fst /-- The second judge from an ordered pair of judges. -/ abbreviation judge_pair.judge₂ : judge_pair J → J := prod.snd /-- The proposition that the judges in an ordered pair are distinct. -/ abbreviation judge_pair.distinct (p : judge_pair J) := p.judge₁ ≠ p.judge₂ /-- The proposition that the judges in an ordered pair agree about a contestant's rating. -/ abbreviation judge_pair.agree (p : judge_pair J) (c : C) := r c p.judge₁ ↔ r c p.judge₂ /-- The contestant from the triple consisting of a contestant and an ordered pair of judges. -/ abbreviation agreed_triple.contestant : agreed_triple C J → C := prod.fst /-- The ordered pair of judges from the triple consisting of a contestant and an ordered pair of judges. -/ abbreviation agreed_triple.judge_pair : agreed_triple C J → judge_pair J := prod.snd @[simp] lemma judge_pair.agree_iff_same_rating (p : judge_pair J) (c : C) : p.agree r c ↔ (r c p.judge₁ ↔ r c p.judge₂) := iff.rfl /-- The set of contestants on which two judges agree. -/ def agreed_contestants [fintype C] (p : judge_pair J) : finset C := finset.univ.filter (λ c, p.agree r c) section variables [fintype J] [fintype C] /-- All incidences of agreement. -/ def A : finset (agreed_triple C J) := finset.univ.filter (λ (a : agreed_triple C J), a.judge_pair.agree r a.contestant ∧ a.judge_pair.distinct) lemma A_maps_to_off_diag_judge_pair (a : agreed_triple C J) : a ∈ A r → a.judge_pair ∈ finset.off_diag (@finset.univ J _) := by simp [A, finset.mem_off_diag] lemma A_fibre_over_contestant (c : C) : finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct) = ((A r).filter (λ (a : agreed_triple C J), a.contestant = c)).image prod.snd := begin ext p, simp only [A, finset.mem_univ, finset.mem_filter, finset.mem_image, true_and, exists_prop], split, { rintros ⟨h₁, h₂⟩, refine ⟨(c, p), _⟩, finish, }, { intros h, finish, }, end lemma A_fibre_over_contestant_card (c : C) : (finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct)).card = ((A r).filter (λ (a : agreed_triple C J), a.contestant = c)).card := by { rw A_fibre_over_contestant r, apply finset.card_image_of_inj_on, tidy, } lemma A_fibre_over_judge_pair {p : judge_pair J} (h : p.distinct) : agreed_contestants r p = ((A r).filter(λ (a : agreed_triple C J), a.judge_pair = p)).image agreed_triple.contestant := begin dunfold A agreed_contestants, ext c, split; intros h, { rw finset.mem_image, refine ⟨⟨c, p⟩, _⟩, finish, }, { finish, }, end lemma A_fibre_over_judge_pair_card {p : judge_pair J} (h : p.distinct) : (agreed_contestants r p).card = ((A r).filter(λ (a : agreed_triple C J), a.judge_pair = p)).card := by { rw A_fibre_over_judge_pair r h, apply finset.card_image_of_inj_on, tidy, } lemma A_card_upper_bound {k : ℕ} (hk : ∀ (p : judge_pair J), p.distinct → (agreed_contestants r p).card ≤ k) : (A r).card ≤ k * ((fintype.card J) * (fintype.card J) - (fintype.card J)) := begin change _ ≤ k * ((finset.card _ ) * (finset.card _ ) - (finset.card _ )), rw ← finset.off_diag_card, apply finset.card_le_mul_card_image_of_maps_to (A_maps_to_off_diag_judge_pair r), intros p hp, have hp' : p.distinct, { simp [finset.mem_off_diag] at hp, exact hp, }, rw ← A_fibre_over_judge_pair_card r hp', apply hk, exact hp', end end lemma add_sq_add_sq_sub {α : Type*} [ring α] (x y : α) : (x + y) * (x + y) + (x - y) * (x - y) = 2*x*x + 2*y*y := by noncomm_ring lemma norm_bound_of_odd_sum {x y z : ℤ} (h : x + y = 2*z + 1) : 2*z*z + 2*z + 1 ≤ x*x + y*y := begin suffices : 4*z*z + 4*z + 1 + 1 ≤ 2*x*x + 2*y*y, { rw ← mul_le_mul_left (@zero_lt_two _ _ int.nontrivial), convert this; ring, }, have h' : (x + y) * (x + y) = 4*z*z + 4*z + 1, { rw h, ring, }, rw [← add_sq_add_sq_sub, h', add_le_add_iff_left], suffices : 0 < (x - y) * (x - y), { apply int.add_one_le_of_lt this, }, apply mul_self_pos, rw sub_ne_zero, apply int.ne_of_odd_sum ⟨z, h⟩, end section variables [fintype J] lemma judge_pairs_card_lower_bound {z : ℕ} (hJ : fintype.card J = 2*z + 1) (c : C) : 2*z*z + 2*z + 1 ≤ (finset.univ.filter (λ (p : judge_pair J), p.agree r c)).card := begin let x := (finset.univ.filter (λ j, r c j)).card, let y := (finset.univ.filter (λ j, ¬ r c j)).card, have h : (finset.univ.filter (λ (p : judge_pair J), p.agree r c)).card = x*x + y*y, { simp [← finset.filter_product_card], }, rw h, apply int.le_of_coe_nat_le_coe_nat, simp only [int.coe_nat_add, int.coe_nat_mul], apply norm_bound_of_odd_sum, suffices : x + y = 2*z + 1, { simp [← int.coe_nat_add, this], }, rw [finset.filter_card_add_filter_neg_card_eq_card, ← hJ], refl, end lemma distinct_judge_pairs_card_lower_bound {z : ℕ} (hJ : fintype.card J = 2*z + 1) (c : C) : 2*z*z ≤ (finset.univ.filter (λ (p : judge_pair J), p.agree r c ∧ p.distinct)).card := begin let s := finset.univ.filter (λ (p : judge_pair J), p.agree r c), let t := finset.univ.filter (λ (p : judge_pair J), p.distinct), have hs : 2*z*z + 2*z + 1 ≤ s.card, { exact judge_pairs_card_lower_bound r hJ c, }, have hst : s \ t = finset.univ.diag, { ext p, split; intros, { finish, }, { suffices : p.judge₁ = p.judge₂, { simp [this], }, finish, }, }, have hst' : (s \ t).card = 2*z + 1, { rw [hst, finset.diag_card, ← hJ], refl, }, rw [finset.filter_and, ← finset.sdiff_sdiff_self_left s t, finset.card_sdiff], { rw hst', rw add_assoc at hs, apply nat.le_sub_right_of_add_le hs, }, { apply finset.sdiff_subset_self, }, end lemma A_card_lower_bound [fintype C] {z : ℕ} (hJ : fintype.card J = 2*z + 1) : 2*z*z * (fintype.card C) ≤ (A r).card := begin have h : ∀ a, a ∈ A r → prod.fst a ∈ @finset.univ C _, { intros, apply finset.mem_univ, }, apply finset.mul_card_image_le_card_of_maps_to h, intros c hc, rw ← A_fibre_over_contestant_card, apply distinct_judge_pairs_card_lower_bound r hJ, end end local notation x `/` y := (x : ℚ) / y lemma clear_denominators {a b k : ℕ} (ha : 0 < a) (hb : 0 < b) : (b - 1) / (2 * b) ≤ k / a ↔ (b - 1) * a ≤ k * (2 * b) := by rw div_le_div_iff; norm_cast; simp [ha, hb] theorem imo1998_q2 [fintype J] [fintype C] (a b k : ℕ) (hC : fintype.card C = a) (hJ : fintype.card J = b) (ha : 0 < a) (hb : odd b) (hk : ∀ (p : judge_pair J), p.distinct → (agreed_contestants r p).card ≤ k) : (b - 1) / (2 * b) ≤ k / a := begin rw clear_denominators ha (nat.odd_gt_zero hb), obtain ⟨z, hz⟩ := hb, rw hz at hJ, rw hz, have h := le_trans (A_card_lower_bound r hJ) (A_card_upper_bound r hk), rw [hC, hJ] at h, -- We are now essentially done; we just need to bash `h` into exactly the right shape. have hl : k * ((2 * z + 1) * (2 * z + 1) - (2 * z + 1)) = (k * (2 * (2 * z + 1))) * z, { simp only [add_mul, two_mul, mul_comm, mul_assoc], finish, }, have hr : 2 * z * z * a = 2 * z * a * z, { ring, }, rw [hl, hr] at h, cases z, { simp, }, { exact le_of_mul_le_mul_right h z.succ_pos, }, end
05ddc3c12ded1520ebbde0bceaf141a647f42383
63abd62053d479eae5abf4951554e1064a4c45b4
/src/category_theory/limits/shapes/images.lean
c596c5dab4e0341c595b1266e5a949661916de51
[ "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
26,088
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison, Markus Himmel -/ import category_theory.limits.shapes.equalizers import category_theory.limits.shapes.strong_epi /-! # Categorical images We define the categorical image of `f` as a factorisation `f = e ≫ m` through a monomorphism `m`, so that `m` factors through the `m'` in any other such factorisation. ## Main definitions * A `mono_factorisation` is a factorisation `f = e ≫ m`, where `m` is a monomorphism * `is_image F` means that a given mono factorisation `F` has the universal property of the image. * `has_image f` means that we have chosen an image for the morphism `f : X ⟶ Y`. * In this case, `image f` is the image object, `image.ι f : image f ⟶ Y` is the monomorphism `m` of the factorisation and `factor_thru_image f : X ⟶ image f` is the morphism `e`. * `has_images C` means that every morphism in `C` has an image. * Let `f : X ⟶ Y` and `g : P ⟶ Q` be morphisms in `C`, which we will represent as objects of the arrow category `arrow C`. Then `sq : f ⟶ g` is a commutative square in `C`. If `f` and `g` have images, then `has_image_map sq` represents the fact that there is a morphism `i : image f ⟶ image g` making the diagram X ----→ image f ----→ Y | | | | | | ↓ ↓ ↓ P ----→ image g ----→ Q commute, where the top row is the image factorisation of `f`, the bottom row is the image factorisation of `g`, and the outer rectangle is the commutative square `sq`. * If a category `has_images`, then `has_image_maps` means that every commutative square admits an image map. * If a category `has_images`, then `has_strong_epi_images` means that the morphism to the image is always a strong epimorphism. ## Main statements * When `C` has equalizers, the morphism `e` appearing in an image factorisation is an epimorphism. * When `C` has strong epi images, then these images admit image maps. ## Future work * TODO: coimages, and abelian categories. * TODO: connect this with existing working in the group theory and ring theory libraries. -/ noncomputable theory universes v u open category_theory open category_theory.limits.walking_parallel_pair namespace category_theory.limits variables {C : Type u} [category.{v} C] variables {X Y : C} (f : X ⟶ Y) /-- A factorisation of a morphism `f = e ≫ m`, with `m` monic. -/ structure mono_factorisation (f : X ⟶ Y) := (I : C) (m : I ⟶ Y) [m_mono : mono m] (e : X ⟶ I) (fac' : e ≫ m = f . obviously) restate_axiom mono_factorisation.fac' attribute [simp, reassoc] mono_factorisation.fac attribute [instance] mono_factorisation.m_mono attribute [instance] mono_factorisation.m_mono namespace mono_factorisation /-- The obvious factorisation of a monomorphism through itself. -/ def self [mono f] : mono_factorisation f := { I := X, m := f, e := 𝟙 X } -- I'm not sure we really need this, but the linter says that an inhabited instance ought to exist... instance [mono f] : inhabited (mono_factorisation f) := ⟨self f⟩ /-- The morphism `m` in a factorisation `f = e ≫ m` through a monomorphism is uniquely determined. -/ @[ext] lemma ext {F F' : mono_factorisation f} (hI : F.I = F'.I) (hm : F.m = (eq_to_hom hI) ≫ F'.m) : F = F' := begin cases F, cases F', cases hI, simp at hm, dsimp at F_fac' F'_fac', congr, { assumption }, { resetI, apply (cancel_mono F_m).1, rw [F_fac', hm, F'_fac'], } end end mono_factorisation variable {f} /-- Data exhibiting that a given factorisation through a mono is initial. -/ structure is_image (F : mono_factorisation f) := (lift : Π (F' : mono_factorisation f), F.I ⟶ F'.I) (lift_fac' : Π (F' : mono_factorisation f), lift F' ≫ F'.m = F.m . obviously) restate_axiom is_image.lift_fac' attribute [simp, reassoc] is_image.lift_fac @[simp, reassoc] lemma is_image.fac_lift {F : mono_factorisation f} (hF : is_image F) (F' : mono_factorisation f) : F.e ≫ hF.lift F' = F'.e := (cancel_mono F'.m).1 $ by simp variable (f) namespace is_image /-- The trivial factorisation of a monomorphism satisfies the universal property. -/ @[simps] def self [mono f] : is_image (mono_factorisation.self f) := { lift := λ F', F'.e } instance [mono f] : inhabited (is_image (mono_factorisation.self f)) := ⟨self f⟩ variable {f} /-- Two factorisations through monomorphisms satisfying the universal property must factor through isomorphic objects. -/ -- TODO this is another good candidate for a future `unique_up_to_canonical_iso`. @[simps] def iso_ext {F F' : mono_factorisation f} (hF : is_image F) (hF' : is_image F') : F.I ≅ F'.I := { hom := hF.lift F', inv := hF'.lift F, hom_inv_id' := (cancel_mono F.m).1 (by simp), inv_hom_id' := (cancel_mono F'.m).1 (by simp) } variables {F F' : mono_factorisation f} (hF : is_image F) (hF' : is_image F') lemma iso_ext_hom_m : (iso_ext hF hF').hom ≫ F'.m = F.m := by simp lemma iso_ext_inv_m : (iso_ext hF hF').inv ≫ F.m = F'.m := by simp lemma e_iso_ext_hom : F.e ≫ (iso_ext hF hF').hom = F'.e := by simp lemma e_iso_ext_inv : F'.e ≫ (iso_ext hF hF').inv = F.e := by simp end is_image /-- Data exhibiting that a morphism `f` has an image. -/ structure image_factorisation (f : X ⟶ Y) := (F : mono_factorisation f) (is_image : is_image F) instance inhabited_image_factorisation (f : X ⟶ Y) [mono f] : inhabited (image_factorisation f) := ⟨⟨_, is_image.self f⟩⟩ /-- `has_image f` means that there exists an image factorisation of `f`. -/ class has_image (f : X ⟶ Y) : Prop := mk' :: (exists_image : nonempty (image_factorisation f)) lemma has_image.mk {f : X ⟶ Y} (F : image_factorisation f) : has_image f := ⟨nonempty.intro F⟩ section variable [has_image f] /-- The chosen factorisation of `f` through a monomorphism. -/ def image.mono_factorisation : mono_factorisation f := (classical.choice (has_image.exists_image)).F /-- The witness of the universal property for the chosen factorisation of `f` through a monomorphism. -/ def image.is_image : is_image (image.mono_factorisation f) := (classical.choice (has_image.exists_image)).is_image /-- The categorical image of a morphism. -/ def image : C := (image.mono_factorisation f).I /-- The inclusion of the image of a morphism into the target. -/ def image.ι : image f ⟶ Y := (image.mono_factorisation f).m @[simp] lemma image.as_ι : (image.mono_factorisation f).m = image.ι f := rfl instance : mono (image.ι f) := (image.mono_factorisation f).m_mono /-- The map from the source to the image of a morphism. -/ def factor_thru_image : X ⟶ image f := (image.mono_factorisation f).e /-- Rewrite in terms of the `factor_thru_image` interface. -/ @[simp] lemma as_factor_thru_image : (image.mono_factorisation f).e = factor_thru_image f := rfl @[simp, reassoc] lemma image.fac : factor_thru_image f ≫ image.ι f = f := (image.mono_factorisation f).fac' variable {f} /-- Any other factorisation of the morphism `f` through a monomorphism receives a map from the image. -/ def image.lift (F' : mono_factorisation f) : image f ⟶ F'.I := (image.is_image f).lift F' @[simp, reassoc] lemma image.lift_fac (F' : mono_factorisation f) : image.lift F' ≫ F'.m = image.ι f := (image.is_image f).lift_fac' F' @[simp, reassoc] lemma image.fac_lift (F' : mono_factorisation f) : factor_thru_image f ≫ image.lift F' = F'.e := (image.is_image f).fac_lift F' @[simp, reassoc] lemma is_image.lift_ι {F : mono_factorisation f} (hF : is_image F) : hF.lift (image.mono_factorisation f) ≫ image.ι f = F.m := hF.lift_fac _ -- TODO we could put a category structure on `mono_factorisation f`, -- with the morphisms being `g : I ⟶ I'` commuting with the `m`s -- (they then automatically commute with the `e`s) -- and show that an `image_of f` gives an initial object there -- (uniqueness of the lift comes for free). instance lift_mono (F' : mono_factorisation f) : mono (image.lift F') := begin split, intros Z a b w, have w' : a ≫ image.ι f = b ≫ image.ι f := calc a ≫ image.ι f = a ≫ (image.lift F' ≫ F'.m) : by simp ... = (a ≫ image.lift F') ≫ F'.m : by rw [category.assoc] ... = (b ≫ image.lift F') ≫ F'.m : by rw w ... = b ≫ (image.lift F' ≫ F'.m) : by rw [←category.assoc] ... = b ≫ image.ι f : by simp, exact (cancel_mono (image.ι f)).1 w', end lemma has_image.uniq (F' : mono_factorisation f) (l : image f ⟶ F'.I) (w : l ≫ F'.m = image.ι f) : l = image.lift F' := (cancel_mono F'.m).1 (by simp [w]) end section variables (C) /-- `has_images` represents a choice of image for every morphism -/ class has_images := (has_image : Π {X Y : C} (f : X ⟶ Y), has_image f) attribute [instance, priority 100] has_images.has_image end section variables (f) [has_image f] /-- The image of a monomorphism is isomorphic to the source. -/ def image_mono_iso_source [mono f] : image f ≅ X := is_image.iso_ext (image.is_image f) (is_image.self f) @[simp, reassoc] lemma image_mono_iso_source_inv_ι [mono f] : (image_mono_iso_source f).inv ≫ image.ι f = f := by simp [image_mono_iso_source] @[simp, reassoc] lemma image_mono_iso_source_hom_self [mono f] : (image_mono_iso_source f).hom ≫ f = image.ι f := begin conv { to_lhs, congr, skip, rw ←image_mono_iso_source_inv_ι f, }, rw [←category.assoc, iso.hom_inv_id, category.id_comp], end -- This is the proof that `factor_thru_image f` is an epimorphism -- from https://en.wikipedia.org/wiki/Image_(category_theory), which is in turn taken from: -- Mitchell, Barry (1965), Theory of categories, MR 0202787, p.12, Proposition 10.1 @[ext] lemma image.ext {W : C} {g h : image f ⟶ W} [has_limit (parallel_pair g h)] (w : factor_thru_image f ≫ g = factor_thru_image f ≫ h) : g = h := begin let q := equalizer.ι g h, let e' := equalizer.lift _ w, let F' : mono_factorisation f := { I := equalizer g h, m := q ≫ image.ι f, m_mono := by apply mono_comp, e := e' }, let v := image.lift F', have t₀ : v ≫ q ≫ image.ι f = image.ι f := image.lift_fac F', have t : v ≫ q = 𝟙 (image f) := (cancel_mono_id (image.ι f)).1 (by { convert t₀ using 1, rw category.assoc }), -- The proof from wikipedia next proves `q ≫ v = 𝟙 _`, -- and concludes that `equalizer g h ≅ image f`, -- but this isn't necessary. calc g = 𝟙 (image f) ≫ g : by rw [category.id_comp] ... = v ≫ q ≫ g : by rw [←t, category.assoc] ... = v ≫ q ≫ h : by rw [equalizer.condition g h] ... = 𝟙 (image f) ≫ h : by rw [←category.assoc, t] ... = h : by rw [category.id_comp] end instance [Π {Z : C} (g h : image f ⟶ Z), has_limit (parallel_pair g h)] : epi (factor_thru_image f) := ⟨λ Z g h w, image.ext f w⟩ lemma epi_image_of_epi {X Y : C} (f : X ⟶ Y) [has_image f] [E : epi f] : epi (image.ι f) := begin rw ←image.fac f at E, resetI, exact epi_of_epi (factor_thru_image f) (image.ι f), end lemma epi_of_epi_image {X Y : C} (f : X ⟶ Y) [has_image f] [epi (image.ι f)] [epi (factor_thru_image f)] : epi f := by { rw [←image.fac f], apply epi_comp, } end section variables {f} {f' : X ⟶ Y} [has_image f] [has_image f'] /-- An equation between morphisms gives a comparison map between the images (which momentarily we prove is an iso). -/ def image.eq_to_hom (h : f = f') : image f ⟶ image f' := image.lift { I := image f', m := image.ι f', e := factor_thru_image f', }. instance (h : f = f') : is_iso (image.eq_to_hom h) := { inv := image.eq_to_hom h.symm, hom_inv_id' := (cancel_mono (image.ι f)).1 (by simp [image.eq_to_hom]), inv_hom_id' := (cancel_mono (image.ι f')).1 (by simp [image.eq_to_hom]), } /-- An equation between morphisms gives an isomorphism between the images. -/ def image.eq_to_iso (h : f = f') : image f ≅ image f' := as_iso (image.eq_to_hom h) /-- As long as the category has equalizers, the image inclusion maps commute with `image.eq_to_iso`. -/ lemma image.eq_fac [has_equalizers C] (h : f = f') : image.ι f = (image.eq_to_iso h).hom ≫ image.ι f' := by { ext, simp [image.eq_to_iso, image.eq_to_hom], } end section variables {Z : C} (g : Y ⟶ Z) /-- The comparison map `image (f ≫ g) ⟶ image g`. -/ def image.pre_comp [has_image g] [has_image (f ≫ g)] : image (f ≫ g) ⟶ image g := image.lift { I := image g, m := image.ι g, e := f ≫ factor_thru_image g } @[simp, reassoc] lemma image.factor_thru_image_pre_comp [has_image g] [has_image (f ≫ g)] : factor_thru_image (f ≫ g) ≫ image.pre_comp f g = f ≫ factor_thru_image g := by simp [image.pre_comp] /-- The two step comparison map `image (f ≫ (g ≫ h)) ⟶ image (g ≫ h) ⟶ image h` agrees with the one step comparison map `image (f ≫ (g ≫ h)) ≅ image ((f ≫ g) ≫ h) ⟶ image h`. -/ lemma image.pre_comp_comp {W : C} (h : Z ⟶ W) [has_image (g ≫ h)] [has_image (f ≫ g ≫ h)] [has_image h] [has_image ((f ≫ g) ≫ h)] : image.pre_comp f (g ≫ h) ≫ image.pre_comp g h = image.eq_to_hom (category.assoc f g h).symm ≫ (image.pre_comp (f ≫ g) h) := begin apply (cancel_mono (image.ι h)).1, simp [image.pre_comp, image.eq_to_hom], end variables [has_equalizers C] /-- `image.pre_comp f g` is an isomorphism when `f` is an isomorphism (we need `C` to have equalizers to prove this). -/ instance image.is_iso_precomp_iso (f : X ≅ Y) [has_image g] [has_image (f.hom ≫ g)] : is_iso (image.pre_comp f.hom g) := { inv := image.lift { I := image (f.hom ≫ g), m := image.ι (f.hom ≫ g), e := f.inv ≫ factor_thru_image (f.hom ≫ g) }, hom_inv_id' := by { ext, simp [image.pre_comp], }, inv_hom_id' := by { ext, simp [image.pre_comp], }, } -- Note that in general we don't have the other comparison map you might expect -- `image f ⟶ image (f ≫ g)`. /-- Postcomposing by an isomorphism induces an isomorphism on the image. -/ def image.post_comp_is_iso [is_iso g] [has_image f] [has_image (f ≫ g)] : image f ≅ image (f ≫ g) := { hom := image.lift { I := _, m := image.ι (f ≫ g) ≫ inv g, m_mono := mono_comp _ _, e := factor_thru_image (f ≫ g) }, inv := image.lift { I := _, m := image.ι f ≫ g, m_mono := mono_comp _ _, e := factor_thru_image f } } @[simp, reassoc] lemma image.post_comp_is_iso_hom_comp_image_ι [is_iso g] [has_image f] [has_image (f ≫ g)] : (image.post_comp_is_iso f g).hom ≫ image.ι (f ≫ g) = image.ι f ≫ g := by { ext, simp [image.post_comp_is_iso] } @[simp, reassoc] lemma image.post_comp_is_iso_inv_comp_image_ι [is_iso g] [has_image f] [has_image (f ≫ g)] : (image.post_comp_is_iso f g).inv ≫ image.ι f = image.ι (f ≫ g) ≫ inv g := by { ext, simp [image.post_comp_is_iso] } end end category_theory.limits namespace category_theory.limits variables {C : Type u} [category.{v} C] section instance {X Y : C} (f : X ⟶ Y) [has_image f] : has_image (arrow.mk f).hom := show has_image f, by apply_instance end section has_image_map /-- An image map is a morphism `image f → image g` fitting into a commutative square and satisfying the obvious commutativity conditions. -/ structure image_map {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) := (map : image f.hom ⟶ image g.hom) (map_ι' : map ≫ image.ι g.hom = image.ι f.hom ≫ sq.right . obviously) instance inhabited_image_map {f : arrow C} [has_image f.hom] : inhabited (image_map (𝟙 f)) := ⟨⟨𝟙 _, by tidy⟩⟩ restate_axiom image_map.map_ι' attribute [simp, reassoc] image_map.map_ι @[simp, reassoc] lemma image_map.factor_map {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) (m : image_map sq) : factor_thru_image f.hom ≫ m.map = sq.left ≫ factor_thru_image g.hom := (cancel_mono (image.ι g.hom)).1 $ by simp [arrow.w] /-- To give an image map for a commutative square with `f` at the top and `g` at the bottom, it suffices to give a map between any mono factorisation of `f` and any image factorisation of `g`. -/ def image_map.transport {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) (F : mono_factorisation f.hom) {F' : mono_factorisation g.hom} (hF' : is_image F') {map : F.I ⟶ F'.I} (map_ι : map ≫ F'.m = F.m ≫ sq.right) : image_map sq := { map := image.lift F ≫ map ≫ hF'.lift (image.mono_factorisation g.hom), map_ι' := by simp [map_ι] } /-- `has_image_map sq` means that there is an `image_map` for the square `sq`. -/ class has_image_map {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) : Prop := mk' :: (has_image_map : nonempty (image_map sq)) lemma has_image_map.mk {f g : arrow C} [has_image f.hom] [has_image g.hom] {sq : f ⟶ g} (m : image_map sq) : has_image_map sq := ⟨nonempty.intro m⟩ lemma has_image_map.transport {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) (F : mono_factorisation f.hom) {F' : mono_factorisation g.hom} (hF' : is_image F') (map : F.I ⟶ F'.I) (map_ι : map ≫ F'.m = F.m ≫ sq.right) : has_image_map sq := has_image_map.mk $ image_map.transport sq F hF' map_ι /-- Obtain an `image_map` from a `has_image_map` instance. -/ def has_image_map.image_map {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) [has_image_map sq] : image_map sq := classical.choice $ @has_image_map.has_image_map _ _ _ _ _ _ sq _ variables {f g : arrow C} [has_image f.hom] [has_image g.hom] (sq : f ⟶ g) section local attribute [ext] image_map instance : subsingleton (image_map sq) := subsingleton.intro $ λ a b, image_map.ext a b $ (cancel_mono (image.ι g.hom)).1 $ by simp only [image_map.map_ι] end variable [has_image_map sq] /-- The map on images induced by a commutative square. -/ abbreviation image.map : image f.hom ⟶ image g.hom := (has_image_map.image_map sq).map lemma image.factor_map : factor_thru_image f.hom ≫ image.map sq = sq.left ≫ factor_thru_image g.hom := by simp lemma image.map_ι : image.map sq ≫ image.ι g.hom = image.ι f.hom ≫ sq.right := by simp lemma image.map_hom_mk'_ι {X Y P Q : C} {k : X ⟶ Y} [has_image k] {l : P ⟶ Q} [has_image l] {m : X ⟶ P} {n : Y ⟶ Q} (w : m ≫ l = k ≫ n) [has_image_map (arrow.hom_mk' w)] : image.map (arrow.hom_mk' w) ≫ image.ι l = image.ι k ≫ n := image.map_ι _ section variables {h : arrow C} [has_image h.hom] (sq' : g ⟶ h) variables [has_image_map sq'] /-- Image maps for composable commutative squares induce an image map in the composite square. -/ def image_map_comp : image_map (sq ≫ sq') := { map := image.map sq ≫ image.map sq' } @[simp] lemma image.map_comp [has_image_map (sq ≫ sq')] : image.map (sq ≫ sq') = image.map sq ≫ image.map sq' := show (has_image_map.image_map (sq ≫ sq')).map = (image_map_comp sq sq').map, by congr end section variables (f) /-- The identity `image f ⟶ image f` fits into the commutative square represented by the identity morphism `𝟙 f` in the arrow category. -/ def image_map_id : image_map (𝟙 f) := { map := 𝟙 (image f.hom) } @[simp] lemma image.map_id [has_image_map (𝟙 f)] : image.map (𝟙 f) = 𝟙 (image f.hom) := show (has_image_map.image_map (𝟙 f)).map = (image_map_id f).map, by congr end end has_image_map section variables (C) [has_images C] /-- If a category `has_image_maps`, then all commutative squares induce morphisms on images. -/ class has_image_maps := (has_image_map : Π {f g : arrow C} (st : f ⟶ g), has_image_map st) attribute [instance, priority 100] has_image_maps.has_image_map end section has_image_maps variables [has_images C] [has_image_maps C] /-- The functor from the arrow category of `C` to `C` itself that maps a morphism to its image and a commutative square to the induced morphism on images. -/ @[simps] def im : arrow C ⥤ C := { obj := λ f, image f.hom, map := λ _ _ st, image.map st } end has_image_maps section strong_epi_mono_factorisation /-- A strong epi-mono factorisation is a decomposition `f = e ≫ m` with `e` a strong epimorphism and `m` a monomorphism. -/ structure strong_epi_mono_factorisation {X Y : C} (f : X ⟶ Y) extends mono_factorisation f := [e_strong_epi : strong_epi e] attribute [instance] strong_epi_mono_factorisation.e_strong_epi /-- Satisfying the inhabited linter -/ instance strong_epi_mono_factorisation_inhabited {X Y : C} (f : X ⟶ Y) [strong_epi f] : inhabited (strong_epi_mono_factorisation f) := ⟨⟨⟨Y, 𝟙 Y, f, by simp⟩⟩⟩ /-- A mono factorisation coming from a strong epi-mono factorisation always has the universal property of the image. -/ def strong_epi_mono_factorisation.to_mono_is_image {X Y : C} {f : X ⟶ Y} (F : strong_epi_mono_factorisation f) : is_image F.to_mono_factorisation := { lift := λ G, arrow.lift $ arrow.hom_mk' $ show G.e ≫ G.m = F.e ≫ F.m, by rw [F.to_mono_factorisation.fac, G.fac] } variable (C) /-- A category has strong epi-mono factorisations if every morphism admits a strong epi-mono factorisation. -/ class has_strong_epi_mono_factorisations : Prop := mk' :: (has_fac : Π {X Y : C} (f : X ⟶ Y), nonempty (strong_epi_mono_factorisation f)) variable {C} lemma has_strong_epi_mono_factorisations.mk (d : Π {X Y : C} (f : X ⟶ Y), strong_epi_mono_factorisation f) : has_strong_epi_mono_factorisations C := ⟨λ X Y f, nonempty.intro $ d f⟩ @[priority 100] instance has_images_of_has_strong_epi_mono_factorisations [has_strong_epi_mono_factorisations C] : has_images C := { has_image := λ X Y f, let F' := classical.choice (has_strong_epi_mono_factorisations.has_fac f) in has_image.mk { F := F'.to_mono_factorisation, is_image := F'.to_mono_is_image } } end strong_epi_mono_factorisation section has_strong_epi_images variables (C) [has_images C] /-- A category has strong epi images if it has all images and `factor_thru_image f` is a strong epimorphism for all `f`. -/ class has_strong_epi_images : Prop := (strong_factor_thru_image : Π {X Y : C} (f : X ⟶ Y), strong_epi (factor_thru_image f)) attribute [instance] has_strong_epi_images.strong_factor_thru_image end has_strong_epi_images section has_strong_epi_images /-- If there is a single strong epi-mono factorisation of `f`, then every image factorisation is a strong epi-mono factorisation. -/ lemma strong_epi_of_strong_epi_mono_factorisation {X Y : C} {f : X ⟶ Y} (F : strong_epi_mono_factorisation f) {F' : mono_factorisation f} (hF' : is_image F') : strong_epi F'.e := by { rw ←is_image.e_iso_ext_hom F.to_mono_is_image hF', apply strong_epi_comp } lemma strong_epi_factor_thru_image_of_strong_epi_mono_factorisation {X Y : C} {f : X ⟶ Y} [has_image f] (F : strong_epi_mono_factorisation f) : strong_epi (factor_thru_image f) := strong_epi_of_strong_epi_mono_factorisation F $ image.is_image f /-- If we constructed our images from strong epi-mono factorisations, then these images are strong epi images. -/ @[priority 100] instance has_strong_epi_images_of_has_strong_epi_mono_factorisations [has_strong_epi_mono_factorisations C] : has_strong_epi_images C := { strong_factor_thru_image := λ X Y f, strong_epi_factor_thru_image_of_strong_epi_mono_factorisation $ classical.choice $ has_strong_epi_mono_factorisations.has_fac f } end has_strong_epi_images section has_strong_epi_images variables [has_images C] /-- A category with strong epi images has image maps. The construction is taken from Borceux, Handbook of Categorical Algebra 1, Proposition 4.4.5. -/ @[priority 100] instance has_image_maps_of_has_strong_epi_images [has_strong_epi_images C] : has_image_maps C := { has_image_map := λ f g st, let I := image (image.ι f.hom ≫ st.right) in let I' := image (st.left ≫ factor_thru_image g.hom) in let upper : strong_epi_mono_factorisation (f.hom ≫ st.right) := { I := I, e := factor_thru_image f.hom ≫ factor_thru_image (image.ι f.hom ≫ st.right), m := image.ι (image.ι f.hom ≫ st.right), e_strong_epi := strong_epi_comp _ _, m_mono := by apply_instance } in let lower : strong_epi_mono_factorisation (f.hom ≫ st.right) := { I := I', e := factor_thru_image (st.left ≫ factor_thru_image g.hom), m := image.ι (st.left ≫ factor_thru_image g.hom) ≫ image.ι g.hom, fac' := by simp [arrow.w], e_strong_epi := by apply_instance, m_mono := mono_comp _ _ } in let s : I ⟶ I' := is_image.lift upper.to_mono_is_image lower.to_mono_factorisation in has_image_map.mk { map := factor_thru_image (image.ι f.hom ≫ st.right) ≫ s ≫ image.ι (st.left ≫ factor_thru_image g.hom), map_ι' := by rw [category.assoc, category.assoc, is_image.lift_fac upper.to_mono_is_image lower.to_mono_factorisation, image.fac] } } end has_strong_epi_images variables [has_strong_epi_mono_factorisations.{v} C] variables {X Y : C} {f : X ⟶ Y} /-- If `C` has strong epi mono factorisations, then the image is unique up to isomorphism, in that if `f` factors as a strong epi followed by a mono, this factorisation is essentially the image factorisation. -/ def image.iso_strong_epi_mono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [strong_epi e] [mono m] : I' ≅ image f := is_image.iso_ext {strong_epi_mono_factorisation . I := I', m := m, e := e}.to_mono_is_image (image.is_image f) @[simp] lemma image.iso_strong_epi_mono_hom_comp_ι {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [strong_epi e] [mono m] : (image.iso_strong_epi_mono e m comm).hom ≫ image.ι f = m := is_image.lift_fac _ _ @[simp] lemma image.iso_strong_epi_mono_inv_comp_mono {I' : C} (e : X ⟶ I') (m : I' ⟶ Y) (comm : e ≫ m = f) [strong_epi e] [mono m] : (image.iso_strong_epi_mono e m comm).inv ≫ m = image.ι f := image.lift_fac _ end category_theory.limits
27da2c0c3a7a1a7922e2f952ba8a5f75a9ed0476
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/tactic/localized_auto.lean
b49bd53a4dd4690e1c85ab63b4e5a3b3ac2ea14f
[]
no_license
AurelienSaue/Mathlib4_auto
f538cfd0980f65a6361eadea39e6fc639e9dae14
590df64109b08190abe22358fabc3eae000943f2
refs/heads/master
1,683,906,849,776
1,622,564,669,000
1,622,564,669,000
371,723,747
0
0
null
null
null
null
UTF-8
Lean
false
false
1,077
lean
/- Copyright (c) 2019 Floris van Doorn. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Floris van Doorn -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.tactic.core import Mathlib.PostPort namespace Mathlib /-! # Localized notation This consists of two user-commands which allow you to declare notation and commands localized to a locale. See the tactic doc entry below for more information. The code is inspired by code from Gabriel Ebner from the [hott3 repository](https://github.com/gebner/hott3). -/ /-- Get all commands in the given locale and return them as a list of strings -/ /-- Execute all commands in the given locale -/ /-- Add a new command to a locale and execute it right now. The new command is added as a declaration to the environment with name `_localized_decl.<number>`. This declaration has attribute `_localized` and as value a name-string pair. -/ /-- This consists of two user-commands which allow you to declare notation and commands localized to a end Mathlib
1bdb829ca3fa1fbd8fbb7b75b37cc6db5fe40dd3
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
/library/data/int/default.lean
c71c4f767e83e18c839db3652f7f1aebb5873927
[ "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
197
lean
/- Copyright (c) 2014 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Jeremy Avigad -/ import .basic .order .div .power .gcd
2c1d09bb40e6815fca71e8bf58ff35da6f0ed327
b7f22e51856f4989b970961f794f1c435f9b8f78
/tests/lean/run/tactic17.lean
aa4d76bb6a1287f9da941c7a4a6e2ba5741180ca
[ "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
232
lean
import logic open tactic constant A : Type.{1} constant f : A → A → A theorem tst {a b c : A} (H1 : a = b) (H2 : b = c) : f a b = f b c := begin apply (@congr A A (f a) (f b)), apply (congr_arg f), repeat assumption end
666671ff9656ecacf74ced5046485d28dea4f236
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/ring_theory/adjoin/field.lean
7a4b4920535d2f4df24be895fa881fea3eeb3c70
[ "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,855
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.polynomial.splits import ring_theory.adjoin.basic import ring_theory.adjoin_root /-! # Adjoining elements to a field > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. Some lemmas on the ring generating by adjoining an element to a field. ## Main statements * `lift_of_splits`: If `K` and `L` are field extensions of `F` and we have `s : finset K` such that the minimal polynomial of each `x ∈ s` splits in `L` then `algebra.adjoin F s` embeds in `L`. -/ noncomputable theory open_locale big_operators polynomial section embeddings variables (F : Type*) [field F] /-- If `p` is the minimal polynomial of `a` over `F` then `F[a] ≃ₐ[F] F[x]/(p)` -/ def alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly {R : Type*} [comm_ring R] [algebra F R] (x : R) : algebra.adjoin F ({x} : set R) ≃ₐ[F] adjoin_root (minpoly F x) := alg_equiv.symm $ alg_equiv.of_bijective (alg_hom.cod_restrict (adjoin_root.lift_hom _ x $ minpoly.aeval F x) _ (λ p, adjoin_root.induction_on _ p $ λ p, (algebra.adjoin_singleton_eq_range_aeval F x).symm ▸ (polynomial.aeval _).mem_range.mpr ⟨p, rfl⟩)) ⟨(alg_hom.injective_cod_restrict _ _ _).2 $ (injective_iff_map_eq_zero _).2 $ λ p, adjoin_root.induction_on _ p $ λ p hp, ideal.quotient.eq_zero_iff_mem.2 $ ideal.mem_span_singleton.2 $ minpoly.dvd F x hp, λ y, let ⟨p, hp⟩ := (set_like.ext_iff.1 (algebra.adjoin_singleton_eq_range_aeval F x) (y : R)).1 y.2 in ⟨adjoin_root.mk _ p, subtype.eq hp⟩⟩ open finset /-- If `K` and `L` are field extensions of `F` and we have `s : finset K` such that the minimal polynomial of each `x ∈ s` splits in `L` then `algebra.adjoin F s` embeds in `L`. -/ theorem lift_of_splits {F K L : Type*} [field F] [field K] [field L] [algebra F K] [algebra F L] (s : finset K) : (∀ x ∈ s, is_integral F x ∧ polynomial.splits (algebra_map F L) (minpoly F x)) → nonempty (algebra.adjoin F (↑s : set K) →ₐ[F] L) := begin classical, refine finset.induction_on s (λ H, _) (λ a s has ih H, _), { rw [coe_empty, algebra.adjoin_empty], exact ⟨(algebra.of_id F L).comp (algebra.bot_equiv F K)⟩ }, rw forall_mem_insert at H, rcases H with ⟨⟨H1, H2⟩, H3⟩, cases ih H3 with f, choose H3 H4 using H3, rw [coe_insert, set.insert_eq, set.union_comm, algebra.adjoin_union_eq_adjoin_adjoin], letI := (f : algebra.adjoin F (↑s : set K) →+* L).to_algebra, haveI : finite_dimensional F (algebra.adjoin F (↑s : set K)) := ( (submodule.fg_iff_finite_dimensional _).1 (fg_adjoin_of_finite s.finite_to_set H3)).of_subalgebra_to_submodule, letI := field_of_finite_dimensional F (algebra.adjoin F (↑s : set K)), have H5 : is_integral (algebra.adjoin F (↑s : set K)) a := is_integral_of_is_scalar_tower H1, have H6 : (minpoly (algebra.adjoin F (↑s : set K)) a).splits (algebra_map (algebra.adjoin F (↑s : set K)) L), { refine polynomial.splits_of_splits_of_dvd _ (polynomial.map_ne_zero $ minpoly.ne_zero H1 : polynomial.map (algebra_map _ _) _ ≠ 0) ((polynomial.splits_map_iff _ _).2 _) (minpoly.dvd _ _ _), { rw ← is_scalar_tower.algebra_map_eq, exact H2 }, { rw [polynomial.aeval_map_algebra_map, minpoly.aeval] } }, obtain ⟨y, hy⟩ := polynomial.exists_root_of_splits _ H6 (ne_of_lt (minpoly.degree_pos H5)).symm, refine ⟨subalgebra.of_restrict_scalars _ _ _⟩, refine (adjoin_root.lift_hom (minpoly (algebra.adjoin F (↑s : set K)) a) y hy).comp _, exact alg_equiv.adjoin_singleton_equiv_adjoin_root_minpoly (algebra.adjoin F (↑s : set K)) a end end embeddings
8641a53777d5602505f710d69cfba5caa8590b6f
6b7c9c6393bac7cb1c64582a1c62597e24f5bb80
/src/tactic/gptf/utils/default.lean
eef350cc2e3d8d3fecd9715626a1b553eed19a37
[ "Apache-2.0" ]
permissive
alreadydone/lean-gptf
56a7d9cbd9400af72fb143d60c8774b8cfbc09cb
b4ab1eb2da0178f3dcdc49771d9fed6b50e35d98
refs/heads/master
1,679,371,993,063
1,614,479,778,000
1,614,479,778,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
30
lean
import tactic.gptf.utils.util
a7f6eaa14b60f03562bddb1d47a879ec1e893dfe
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/topology/algebra/open_subgroup.lean
dfa12d394678c4c1d1ce0876b5580511a54da5f6
[ "Apache-2.0" ]
permissive
AntoineChambert-Loir/mathlib
64aabb896129885f12296a799818061bc90da1ff
07be904260ab6e36a5769680b6012f03a4727134
refs/heads/master
1,693,187,631,771
1,636,719,886,000
1,636,719,886,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
9,447
lean
/- Copyright (c) 2019 Johan Commelin All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johan Commelin -/ import order.filter.lift import topology.opens import topology.algebra.ring /-! # Open subgroups of a topological groups This files builds the lattice `open_subgroup G` of open subgroups in a topological group `G`, and its additive version `open_add_subgroup`. This lattice has a top element, the subgroup of all elements, but no bottom element in general. The trivial subgroup which is the natural candidate bottom has no reason to be open (this happens only in discrete groups). Note that this notion is especially relevant in a non-archimedean context, for instance for `p`-adic groups. ## Main declarations * `open_subgroup.is_closed`: An open subgroup is automatically closed. * `subgroup.is_open_mono`: A subgroup containing an open subgroup is open. There are also versions for additive groups, submodules and ideals. * `open_subgroup.comap`: Open subgroups can be pulled back by a continuous group morphism. ## TODO * Prove that the identity component of a locally path connected group is an open subgroup. Up to now this file is really geared towards non-archimedean algebra, not Lie groups. -/ open topological_space open_locale topological_space /-- The type of open subgroups of a topological additive group. -/ @[ancestor add_subgroup] structure open_add_subgroup (G : Type*) [add_group G] [topological_space G] extends add_subgroup G := (is_open' : is_open carrier) /-- The type of open subgroups of a topological group. -/ @[ancestor subgroup, to_additive] structure open_subgroup (G : Type*) [group G] [topological_space G] extends subgroup G := (is_open' : is_open carrier) /-- Reinterpret an `open_subgroup` as a `subgroup`. -/ add_decl_doc open_subgroup.to_subgroup /-- Reinterpret an `open_add_subgroup` as an `add_subgroup`. -/ add_decl_doc open_add_subgroup.to_add_subgroup -- Tell Lean that `open_add_subgroup` is a namespace namespace open_add_subgroup end open_add_subgroup namespace open_subgroup open function topological_space variables {G : Type*} [group G] [topological_space G] variables {U V : open_subgroup G} {g : G} @[to_additive] instance has_coe_set : has_coe_t (open_subgroup G) (set G) := ⟨λ U, U.1⟩ @[to_additive] instance : has_mem G (open_subgroup G) := ⟨λ g U, g ∈ (U : set G)⟩ @[to_additive] instance has_coe_subgroup : has_coe_t (open_subgroup G) (subgroup G) := ⟨to_subgroup⟩ @[to_additive] instance has_coe_opens : has_coe_t (open_subgroup G) (opens G) := ⟨λ U, ⟨U, U.is_open'⟩⟩ @[simp, norm_cast, to_additive] lemma mem_coe : g ∈ (U : set G) ↔ g ∈ U := iff.rfl @[simp, norm_cast, to_additive] lemma mem_coe_opens : g ∈ (U : opens G) ↔ g ∈ U := iff.rfl @[simp, norm_cast, to_additive] lemma mem_coe_subgroup : g ∈ (U : subgroup G) ↔ g ∈ U := iff.rfl @[to_additive] lemma coe_injective : injective (coe : open_subgroup G → set G) := by { rintros ⟨⟨⟩⟩ ⟨⟨⟩⟩ ⟨h⟩, congr, } @[ext, to_additive] lemma ext (h : ∀ x, x ∈ U ↔ x ∈ V) : (U = V) := coe_injective $ set.ext h @[to_additive] lemma ext_iff : (U = V) ↔ (∀ x, x ∈ U ↔ x ∈ V) := ⟨λ h x, h ▸ iff.rfl, ext⟩ variable (U) @[to_additive] protected lemma is_open : is_open (U : set G) := U.is_open' @[to_additive] protected lemma one_mem : (1 : G) ∈ U := U.one_mem' @[to_additive] protected lemma inv_mem {g : G} (h : g ∈ U) : g⁻¹ ∈ U := U.inv_mem' h @[to_additive] protected lemma mul_mem {g₁ g₂ : G} (h₁ : g₁ ∈ U) (h₂ : g₂ ∈ U) : g₁ * g₂ ∈ U := U.mul_mem' h₁ h₂ @[to_additive] lemma mem_nhds_one : (U : set G) ∈ 𝓝 (1 : G) := is_open.mem_nhds U.is_open U.one_mem variable {U} @[to_additive] instance : has_top (open_subgroup G) := ⟨{ is_open' := is_open_univ, .. (⊤ : subgroup G) }⟩ @[to_additive] instance : inhabited (open_subgroup G) := ⟨⊤⟩ @[to_additive] lemma is_closed [has_continuous_mul G] (U : open_subgroup G) : is_closed (U : set G) := begin apply is_open_compl_iff.1, refine is_open_iff_forall_mem_open.2 (λ x hx, ⟨(λ y, y * x⁻¹) ⁻¹' U, _, _, _⟩), { intros u hux, simp only [set.mem_preimage, set.mem_compl_iff, mem_coe] at hux hx ⊢, refine mt (λ hu, _) hx, convert U.mul_mem (U.inv_mem hux) hu, simp }, { exact U.is_open.preimage (continuous_mul_right _) }, { simp [U.one_mem] } end section variables {H : Type*} [group H] [topological_space H] /-- The product of two open subgroups as an open subgroup of the product group. -/ @[to_additive "The product of two open subgroups as an open subgroup of the product group."] def prod (U : open_subgroup G) (V : open_subgroup H) : open_subgroup (G × H) := { carrier := (U : set G).prod (V : set H), is_open' := U.is_open.prod V.is_open, .. (U : subgroup G).prod (V : subgroup H) } end @[to_additive] instance : partial_order (open_subgroup G) := { le := λ U V, ∀ ⦃x⦄, x ∈ U → x ∈ V, .. partial_order.lift (coe : open_subgroup G → set G) coe_injective } @[to_additive] instance : order_top (open_subgroup G) := { top := ⊤, le_top := λ U, set.subset_univ _ } @[to_additive] instance : semilattice_inf_top (open_subgroup G) := { inf := λ U V, { is_open' := is_open.inter U.is_open V.is_open, .. (U : subgroup G) ⊓ V }, inf_le_left := λ U V, set.inter_subset_left _ _, inf_le_right := λ U V, set.inter_subset_right _ _, le_inf := λ U V W hV hW, set.subset_inter hV hW, ..open_subgroup.order_top, ..open_subgroup.partial_order } @[simp, norm_cast, to_additive] lemma coe_inf : (↑(U ⊓ V) : set G) = (U : set G) ∩ V := rfl @[simp, norm_cast, to_additive] lemma coe_subset : (U : set G) ⊆ V ↔ U ≤ V := iff.rfl @[simp, norm_cast, to_additive] lemma coe_subgroup_le : (U : subgroup G) ≤ (V : subgroup G) ↔ U ≤ V := iff.rfl variables {N : Type*} [group N] [topological_space N] /-- The preimage of an `open_subgroup` along a continuous `monoid` homomorphism is an `open_subgroup`. -/ @[to_additive "The preimage of an `open_add_subgroup` along a continuous `add_monoid` homomorphism is an `open_add_subgroup`."] def comap (f : G →* N) (hf : continuous f) (H : open_subgroup N) : open_subgroup G := { is_open' := H.is_open.preimage hf, .. (H : subgroup N).comap f } @[simp, to_additive] lemma coe_comap (H : open_subgroup N) (f : G →* N) (hf : continuous f) : (H.comap f hf : set G) = f ⁻¹' H := rfl @[simp, to_additive] lemma mem_comap {H : open_subgroup N} {f : G →* N} {hf : continuous f} {x : G} : x ∈ H.comap f hf ↔ f x ∈ H := iff.rfl @[to_additive] lemma comap_comap {P : Type*} [group P] [topological_space P] (K : open_subgroup P) (f₂ : N →* P) (hf₂ : continuous f₂) (f₁ : G →* N) (hf₁ : continuous f₁) : (K.comap f₂ hf₂).comap f₁ hf₁ = K.comap (f₂.comp f₁) (hf₂.comp hf₁) := rfl end open_subgroup namespace subgroup variables {G : Type*} [group G] [topological_space G] [has_continuous_mul G] (H : subgroup G) @[to_additive] lemma is_open_of_mem_nhds {g : G} (hg : (H : set G) ∈ 𝓝 g) : is_open (H : set G) := begin simp only [is_open_iff_mem_nhds, set_like.mem_coe] at hg ⊢, intros x hx, have : filter.tendsto (λ y, y * (x⁻¹ * g)) (𝓝 x) (𝓝 $ x * (x⁻¹ * g)) := (continuous_id.mul continuous_const).tendsto _, rw [mul_inv_cancel_left] at this, have := filter.mem_map'.1 (this hg), replace hg : g ∈ H := set_like.mem_coe.1 (mem_of_mem_nhds hg), simp only [set_like.mem_coe, H.mul_mem_cancel_right (H.mul_mem (H.inv_mem hx) hg)] at this, exact this end @[to_additive] lemma is_open_of_open_subgroup {U : open_subgroup G} (h : U.1 ≤ H) : is_open (H : set G) := H.is_open_of_mem_nhds (filter.mem_of_superset U.mem_nhds_one h) @[to_additive] lemma is_open_mono {H₁ H₂ : subgroup G} (h : H₁ ≤ H₂) (h₁ : is_open (H₁ :set G)) : is_open (H₂ : set G) := @is_open_of_open_subgroup _ _ _ _ H₂ { is_open' := h₁, .. H₁ } h end subgroup namespace open_subgroup variables {G : Type*} [group G] [topological_space G] [has_continuous_mul G] @[to_additive] instance : semilattice_sup_top (open_subgroup G) := { sup := λ U V, { is_open' := show is_open (((U : subgroup G) ⊔ V : subgroup G) : set G), from subgroup.is_open_mono le_sup_left U.is_open, .. ((U : subgroup G) ⊔ V) }, le_sup_left := λ U V, coe_subgroup_le.1 le_sup_left, le_sup_right := λ U V, coe_subgroup_le.1 le_sup_right, sup_le := λ U V W hU hV, coe_subgroup_le.1 (sup_le hU hV), ..open_subgroup.semilattice_inf_top } @[to_additive] instance : lattice (open_subgroup G) := { ..open_subgroup.semilattice_sup_top, ..open_subgroup.semilattice_inf_top } end open_subgroup namespace submodule open open_add_subgroup variables {R : Type*} {M : Type*} [comm_ring R] variables [add_comm_group M] [topological_space M] [topological_add_group M] [module R M] lemma is_open_mono {U P : submodule R M} (h : U ≤ P) (hU : is_open (U : set M)) : is_open (P : set M) := @add_subgroup.is_open_mono M _ _ _ U.to_add_subgroup P.to_add_subgroup h hU end submodule namespace ideal variables {R : Type*} [comm_ring R] variables [topological_space R] [topological_ring R] lemma is_open_of_open_subideal {U I : ideal R} (h : U ≤ I) (hU : is_open (U : set R)) : is_open (I : set R) := submodule.is_open_mono h hU end ideal
9e91667def6b3aa6a5f4219a0e5c818f4a3293f5
fa02ed5a3c9c0adee3c26887a16855e7841c668b
/src/geometry/manifold/instances/sphere.lean
f081b216a54e92bae7223615be0dd16b224e2419
[ "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
20,126
lean
/- Copyright (c) 2021 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import geometry.manifold.instances.real import analysis.complex.circle /-! # Manifold structure on the sphere This file defines stereographic projection from the sphere in an inner product space `E`, and uses it to put a smooth manifold structure on the sphere. ## Main results For a unit vector `v` in `E`, the definition `stereographic` gives the stereographic projection centred at `v`, a local homeomorphism from the sphere to `(ℝ ∙ v)ᗮ` (the orthogonal complement of `v`). For finite-dimensional `E`, we then construct a smooth manifold instance on the sphere; the charts here are obtained by composing the local homeomorphisms `stereographic` with arbitrary isometries from `(ℝ ∙ v)ᗮ` to Euclidean space. We prove two lemmas about smooth maps: * `times_cont_mdiff_coe_sphere` states that the coercion map from the sphere into `E` is smooth; this is a useful tool for constructing smooth maps *from* the sphere. * `times_cont_mdiff.cod_restrict_sphere` states that a map from a manifold into the sphere is smooth if its lift to a map to `E` is smooth; this is a useful tool for constructing smooth maps *to* the sphere. As an application we prove `times_cont_mdiff_neg_sphere`, that the antipodal map is smooth. Finally, we equip the `circle` (defined in `analysis.complex.circle` to be the sphere in `ℂ` centred at `0` of radius `1`) with the following structure: * a charted space with model space `euclidean_space ℝ (fin 1)` (inherited from `metric.sphere`) * a Lie group with model with corners `𝓡 1` We furthermore show that `exp_map_circle` (defined in `analysis.complex.circle` to be the natural map `λ t, exp (t * I)` from `ℝ` to `circle`) is smooth. ## Implementation notes The model space for the charted space instance is `euclidean_space ℝ (fin n)`, where `n` is a natural number satisfying the typeclass assumption `[fact (finrank ℝ E = n + 1)]`. This may seem a little awkward, but it is designed to circumvent the problem that the literal expression for the dimension of the model space (up to definitional equality) determines the type. If one used the naive expression `euclidean_space ℝ (fin (finrank ℝ E - 1))` for the model space, then the sphere in `ℂ` would be a manifold with model space `euclidean_space ℝ (fin (2 - 1))` but not with model space `euclidean_space ℝ (fin 1)`. -/ variables {E : Type*} [inner_product_space ℝ E] noncomputable theory open metric finite_dimensional open_locale manifold local attribute [instance] finite_dimensional_of_finrank_eq_succ section stereographic_projection variables (v : E) /-! ### Construction of the stereographic projection -/ /-- Stereographic projection, forward direction. This is a map from an inner product space `E` to the orthogonal complement of an element `v` of `E`. It is smooth away from the affine hyperplane through `v` parallel to the orthogonal complement. It restricts on the sphere to the stereographic projection. -/ def stereo_to_fun [complete_space E] (x : E) : (ℝ ∙ v)ᗮ := (2 / ((1:ℝ) - inner_right v x)) • orthogonal_projection (ℝ ∙ v)ᗮ x variables {v} @[simp] lemma stereo_to_fun_apply [complete_space E] (x : E) : stereo_to_fun v x = (2 / ((1:ℝ) - inner_right v x)) • orthogonal_projection (ℝ ∙ v)ᗮ x := rfl lemma times_cont_diff_on_stereo_to_fun [complete_space E] : times_cont_diff_on ℝ ⊤ (stereo_to_fun v) {x : E | inner_right v x ≠ (1:ℝ)} := begin refine times_cont_diff_on.smul _ (orthogonal_projection ((ℝ ∙ v)ᗮ)).times_cont_diff.times_cont_diff_on, refine times_cont_diff_const.times_cont_diff_on.div _ _, { exact (times_cont_diff_const.sub (inner_right v).times_cont_diff).times_cont_diff_on }, { intros x h h', exact h (sub_eq_zero.mp h').symm } end lemma continuous_on_stereo_to_fun [complete_space E] : continuous_on (stereo_to_fun v) {x : E | inner_right v x ≠ (1:ℝ)} := times_cont_diff_on_stereo_to_fun.continuous_on variables (v) /-- Auxiliary function for the construction of the reverse direction of the stereographic projection. This is a map from the orthogonal complement of a unit vector `v` in an inner product space `E` to `E`; we will later prove that it takes values in the unit sphere. For most purposes, use `stereo_inv_fun`, not `stereo_inv_fun_aux`. -/ def stereo_inv_fun_aux (w : E) : E := (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v) variables {v} @[simp] lemma stereo_inv_fun_aux_apply (w : E) : stereo_inv_fun_aux v w = (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v) := rfl lemma stereo_inv_fun_aux_mem (hv : ∥v∥ = 1) {w : E} (hw : w ∈ (ℝ ∙ v)ᗮ) : stereo_inv_fun_aux v w ∈ (sphere (0:E) 1) := begin have h₁ : 0 ≤ ∥w∥ ^ 2 + 4 := by nlinarith, suffices : ∥(4:ℝ) • w + (∥w∥ ^ 2 - 4) • v∥ = ∥w∥ ^ 2 + 4, { have h₂ : ∥w∥ ^ 2 + 4 ≠ 0 := by nlinarith, simp only [mem_sphere_zero_iff_norm, norm_smul, real.norm_eq_abs, abs_inv, this, abs_of_nonneg h₁, stereo_inv_fun_aux_apply], field_simp }, suffices : ∥(4:ℝ) • w + (∥w∥ ^ 2 - 4) • v∥ ^ 2 = (∥w∥ ^ 2 + 4) ^ 2, { have h₃ : 0 ≤ ∥stereo_inv_fun_aux v w∥ := norm_nonneg _, simpa [h₁, h₃, -one_pow] using this }, simp [norm_add_sq_real, norm_smul, inner_smul_left, inner_smul_right, inner_left_of_mem_orthogonal_singleton _ hw, mul_pow, real.norm_eq_abs, hv], ring end lemma times_cont_diff_stereo_inv_fun_aux : times_cont_diff ℝ ⊤ (stereo_inv_fun_aux v) := begin have h₀ : times_cont_diff ℝ ⊤ (λ w : E, ∥w∥ ^ 2) := times_cont_diff_norm_sq, have h₁ : times_cont_diff ℝ ⊤ (λ w : E, (∥w∥ ^ 2 + 4)⁻¹), { refine (h₀.add times_cont_diff_const).inv _, intros x, nlinarith }, have h₂ : times_cont_diff ℝ ⊤ (λ w, (4:ℝ) • w + (∥w∥ ^ 2 - 4) • v), { refine (times_cont_diff_const.smul times_cont_diff_id).add _, refine (h₀.sub times_cont_diff_const).smul times_cont_diff_const }, exact h₁.smul h₂ end /-- Stereographic projection, reverse direction. This is a map from the orthogonal complement of a unit vector `v` in an inner product space `E` to the unit sphere in `E`. -/ def stereo_inv_fun (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) : sphere (0:E) 1 := ⟨stereo_inv_fun_aux v (w:E), stereo_inv_fun_aux_mem hv w.2⟩ @[simp] lemma stereo_inv_fun_apply (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) : (stereo_inv_fun hv w : E) = (∥w∥ ^ 2 + 4)⁻¹ • ((4:ℝ) • w + (∥w∥ ^ 2 - 4) • v) := rfl lemma stereo_inv_fun_ne_north_pole (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) : stereo_inv_fun hv w ≠ (⟨v, by simp [hv]⟩ : sphere (0:E) 1) := begin refine subtype.ne_of_val_ne _, rw ← inner_lt_one_iff_real_of_norm_one _ hv, { have hw : ⟪v, w⟫_ℝ = 0 := inner_right_of_mem_orthogonal_singleton v w.2, have hw' : (∥(w:E)∥ ^ 2 + 4)⁻¹ * (∥(w:E)∥ ^ 2 - 4) < 1, { refine (inv_mul_lt_iff' _).mpr _, { nlinarith }, linarith }, simpa [real_inner_comm, inner_add_right, inner_smul_right, real_inner_self_eq_norm_sq, hw, hv] using hw' }, { simpa using stereo_inv_fun_aux_mem hv w.2 } end lemma continuous_stereo_inv_fun (hv : ∥v∥ = 1) : continuous (stereo_inv_fun hv) := continuous_induced_rng (times_cont_diff_stereo_inv_fun_aux.continuous.comp continuous_subtype_coe) variables [complete_space E] lemma stereo_left_inv (hv : ∥v∥ = 1) {x : sphere (0:E) 1} (hx : (x:E) ≠ v) : stereo_inv_fun hv (stereo_to_fun v x) = x := begin ext, simp only [stereo_to_fun_apply, stereo_inv_fun_apply, smul_add], -- name two frequently-occuring quantities and write down their basic properties set a : ℝ := inner_right v x, set y := orthogonal_projection (ℝ ∙ v)ᗮ x, have split : ↑x = a • v + ↑y, { convert eq_sum_orthogonal_projection_self_orthogonal_complement (ℝ ∙ v) x, exact (orthogonal_projection_unit_singleton ℝ hv x).symm }, have hvy : ⟪v, y⟫_ℝ = 0 := inner_right_of_mem_orthogonal_singleton v y.2, have pythag : 1 = a ^ 2 + ∥y∥ ^ 2, { have hvy' : ⟪a • v, y⟫_ℝ = 0 := by simp [inner_smul_left, hvy], convert norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ hvy' using 2, { simp [← split] }, { simp [norm_smul, hv, real.norm_eq_abs, ← sq, sq_abs] }, { exact sq _ } }, -- two facts which will be helpful for clearing denominators in the main calculation have ha : 1 - a ≠ 0, { have : a < 1 := (inner_lt_one_iff_real_of_norm_one hv (by simp)).mpr hx.symm, linarith }, have : 2 ^ 2 * ∥y∥ ^ 2 + 4 * (1 - a) ^ 2 ≠ 0, { refine ne_of_gt _, have := norm_nonneg (y:E), have : 0 < (1 - a) ^ 2 := sq_pos_of_ne_zero (1 - a) ha, nlinarith }, -- the core of the problem is these two algebraic identities: have h₁ : (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 + 4)⁻¹ * 4 * (2 / (1 - a)) = 1, { field_simp, nlinarith }, have h₂ : (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 + 4)⁻¹ * (2 ^ 2 / (1 - a) ^ 2 * ∥y∥ ^ 2 - 4) = a, { field_simp, transitivity (1 - a) ^ 2 * (a * (2 ^ 2 * ∥y∥ ^ 2 + 4 * (1 - a) ^ 2)), { congr, nlinarith }, ring_nf, ring }, -- deduce the result convert congr_arg2 has_add.add (congr_arg (λ t, t • (y:E)) h₁) (congr_arg (λ t, t • v) h₂) using 1, { simp [inner_add_right, inner_smul_right, hvy, real_inner_self_eq_norm_sq, hv, mul_smul, mul_pow, real.norm_eq_abs, sq_abs, norm_smul] }, { simp [split, add_comm] } end lemma stereo_right_inv (hv : ∥v∥ = 1) (w : (ℝ ∙ v)ᗮ) : stereo_to_fun v (stereo_inv_fun hv w) = w := begin have : 2 / (1 - (∥(w:E)∥ ^ 2 + 4)⁻¹ * (∥(w:E)∥ ^ 2 - 4)) * (∥(w:E)∥ ^ 2 + 4)⁻¹ * 4 = 1, { have : ∥(w:E)∥ ^ 2 + 4 ≠ 0 := by nlinarith, have : (4:ℝ) + 4 ≠ 0 := by nlinarith, field_simp, ring }, convert congr_arg (λ c, c • w) this, { have h₁ : orthogonal_projection (ℝ ∙ v)ᗮ v = 0 := orthogonal_projection_orthogonal_complement_singleton_eq_zero v, have h₂ : orthogonal_projection (ℝ ∙ v)ᗮ w = w := orthogonal_projection_mem_subspace_eq_self w, have h₃ : inner_right v w = (0:ℝ) := inner_right_of_mem_orthogonal_singleton v w.2, have h₄ : inner_right v v = (1:ℝ) := by simp [real_inner_self_eq_norm_sq, hv], simp [h₁, h₂, h₃, h₄, continuous_linear_map.map_add, continuous_linear_map.map_smul, mul_smul] }, { simp } end /-- Stereographic projection from the unit sphere in `E`, centred at a unit vector `v` in `E`; this is the version as a local homeomorphism. -/ def stereographic (hv : ∥v∥ = 1) : local_homeomorph (sphere (0:E) 1) (ℝ ∙ v)ᗮ := { to_fun := (stereo_to_fun v) ∘ coe, inv_fun := stereo_inv_fun hv, source := {⟨v, by simp [hv]⟩}ᶜ, target := set.univ, map_source' := by simp, map_target' := λ w _, stereo_inv_fun_ne_north_pole hv w, left_inv' := λ _ hx, stereo_left_inv hv (λ h, hx (subtype.ext h)), right_inv' := λ w _, stereo_right_inv hv w, open_source := is_open_compl_singleton, open_target := is_open_univ, continuous_to_fun := continuous_on_stereo_to_fun.comp continuous_subtype_coe.continuous_on (λ w h, h ∘ subtype.ext ∘ eq.symm ∘ (inner_eq_norm_mul_iff_of_norm_one hv (by simp)).mp), continuous_inv_fun := (continuous_stereo_inv_fun hv).continuous_on } @[simp] lemma stereographic_source (hv : ∥v∥ = 1) : (stereographic hv).source = {⟨v, by simp [hv]⟩}ᶜ := rfl @[simp] lemma stereographic_target (hv : ∥v∥ = 1) : (stereographic hv).target = set.univ := rfl end stereographic_projection section charted_space /-! ### Charted space structure on the sphere In this section we construct a charted space structure on the unit sphere in a finite-dimensional real inner product space `E`; that is, we show that it is locally homeomorphic to the Euclidean space of dimension one less than `E`. The restriction to finite dimension is for convenience. The most natural `charted_space` structure for the sphere uses the stereographic projection from the antipodes of a point as the canonical chart at this point. However, the codomain of the stereographic projection constructed in the previous section is `(ℝ ∙ v)ᗮ`, the orthogonal complement of the vector `v` in `E` which is the "north pole" of the projection, so a priori these charts all have different codomains. So it is necessary to prove that these codomains are all continuously linearly equivalent to a fixed normed space. This could be proved in general by a simple case of Gram-Schmidt orthogonalization, but in the finite-dimensional case it follows more easily by dimension-counting. -/ /-- Variant of the stereographic projection, for the sphere in an `n + 1`-dimensional inner product space `E`. This version has codomain the Euclidean space of dimension `n`, and is obtained by composing the original sterographic projection (`stereographic`) with an arbitrary linear isometry from `(ℝ ∙ v)ᗮ` to the Euclidean space. -/ def stereographic' (n : ℕ) [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) : local_homeomorph (sphere (0:E) 1) (euclidean_space ℝ (fin n)) := (stereographic (norm_eq_of_mem_sphere v)) ≫ₕ (linear_isometry_equiv.from_orthogonal_span_singleton n (nonzero_of_mem_unit_sphere v)).to_homeomorph.to_local_homeomorph @[simp] lemma stereographic'_source {n : ℕ} [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) : (stereographic' n v).source = {v}ᶜ := by simp [stereographic'] @[simp] lemma stereographic'_target {n : ℕ} [fact (finrank ℝ E = n + 1)] (v : sphere (0:E) 1) : (stereographic' n v).target = set.univ := by simp [stereographic'] /-- The unit sphere in an `n + 1`-dimensional inner product space `E` is a charted space modelled on the Euclidean space of dimension `n`. -/ instance {n : ℕ} [fact (finrank ℝ E = n + 1)] : charted_space (euclidean_space ℝ (fin n)) (sphere (0:E) 1) := { atlas := {f | ∃ v : (sphere (0:E) 1), f = stereographic' n v}, chart_at := λ v, stereographic' n (-v), mem_chart_source := λ v, by simpa using ne_neg_of_mem_unit_sphere ℝ v, chart_mem_atlas := λ v, ⟨-v, rfl⟩ } end charted_space section smooth_manifold /-! ### Smooth manifold structure on the sphere -/ /-- The unit sphere in an `n + 1`-dimensional inner product space `E` is a smooth manifold, modelled on the Euclidean space of dimension `n`. -/ instance {n : ℕ} [fact (finrank ℝ E = n + 1)] : smooth_manifold_with_corners (𝓡 n) (sphere (0:E) 1) := smooth_manifold_with_corners_of_times_cont_diff_on (𝓡 n) (sphere (0:E) 1) begin rintros _ _ ⟨v, rfl⟩ ⟨v', rfl⟩, let U : (ℝ ∙ (v:E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) := linear_isometry_equiv.from_orthogonal_span_singleton n (nonzero_of_mem_unit_sphere v), let U' : (ℝ ∙ (v':E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) := linear_isometry_equiv.from_orthogonal_span_singleton n (nonzero_of_mem_unit_sphere v'), have hUv : stereographic' n v = (stereographic (norm_eq_of_mem_sphere v)) ≫ₕ U.to_homeomorph.to_local_homeomorph := rfl, have hU'v' : stereographic' n v' = (stereographic (norm_eq_of_mem_sphere v')).trans U'.to_homeomorph.to_local_homeomorph := rfl, have H₁ := U'.times_cont_diff.comp_times_cont_diff_on times_cont_diff_on_stereo_to_fun, have H₂ := (times_cont_diff_stereo_inv_fun_aux.comp (ℝ ∙ (v:E))ᗮ.subtypeL.times_cont_diff).comp U.symm.times_cont_diff, convert H₁.comp' (H₂.times_cont_diff_on : times_cont_diff_on ℝ ⊤ _ set.univ) using 1, have h_set : ∀ p : sphere (0:E) 1, p = v' ↔ ⟪(p:E), v'⟫_ℝ = 1, { simp [subtype.ext_iff, inner_eq_norm_mul_iff_of_norm_one] }, ext, simp [h_set, hUv, hU'v', stereographic, real_inner_comm] end /-- The inclusion map (i.e., `coe`) from the sphere in `E` to `E` is smooth. -/ lemma times_cont_mdiff_coe_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)] : times_cont_mdiff (𝓡 n) 𝓘(ℝ, E) ∞ (coe : (sphere (0:E) 1) → E) := begin rw times_cont_mdiff_iff, split, { exact continuous_subtype_coe }, { intros v _, let U : (ℝ ∙ ((-v):E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) := linear_isometry_equiv.from_orthogonal_span_singleton n (nonzero_of_mem_unit_sphere (-v)), exact ((times_cont_diff_stereo_inv_fun_aux.comp (ℝ ∙ ((-v):E))ᗮ.subtypeL.times_cont_diff).comp U.symm.times_cont_diff).times_cont_diff_on } end variables {F : Type*} [normed_group F] [normed_space ℝ F] variables {H : Type*} [topological_space H] {I : model_with_corners ℝ F H} variables {M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M] /-- If a `times_cont_mdiff` function `f : M → E`, where `M` is some manifold, takes values in the sphere, then it restricts to a `times_cont_mdiff` function from `M` to the sphere. -/ lemma times_cont_mdiff.cod_restrict_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)] {m : with_top ℕ} {f : M → E} (hf : times_cont_mdiff I 𝓘(ℝ, E) m f) (hf' : ∀ x, f x ∈ sphere (0:E) 1) : times_cont_mdiff I (𝓡 n) m (set.cod_restrict _ _ hf' : M → (sphere (0:E) 1)) := begin rw times_cont_mdiff_iff_target, refine ⟨continuous_induced_rng hf.continuous, _⟩, intros v, let U : (ℝ ∙ ((-v):E))ᗮ ≃ₗᵢ[ℝ] euclidean_space ℝ (fin n) := (linear_isometry_equiv.from_orthogonal_span_singleton n (nonzero_of_mem_unit_sphere (-v))), have h : times_cont_diff_on ℝ ⊤ U set.univ := U.times_cont_diff.times_cont_diff_on, have H₁ := (h.comp' times_cont_diff_on_stereo_to_fun).times_cont_mdiff_on, have H₂ : times_cont_mdiff_on _ _ _ _ set.univ := hf.times_cont_mdiff_on, convert (H₁.of_le le_top).comp' H₂ using 1, ext x, have hfxv : f x = -↑v ↔ ⟪f x, -↑v⟫_ℝ = 1, { have hfx : ∥f x∥ = 1 := by simpa using hf' x, rw inner_eq_norm_mul_iff_of_norm_one hfx, exact norm_eq_of_mem_sphere (-v) }, dsimp [chart_at], simp [not_iff_not, subtype.ext_iff, hfxv, real_inner_comm] end /-- The antipodal map is smooth. -/ lemma times_cont_mdiff_neg_sphere {n : ℕ} [fact (finrank ℝ E = n + 1)] : times_cont_mdiff (𝓡 n) (𝓡 n) ∞ (λ x : sphere (0:E) 1, -x) := (times_cont_diff_neg.times_cont_mdiff.comp times_cont_mdiff_coe_sphere).cod_restrict_sphere _ end smooth_manifold section circle open complex local attribute [instance] finrank_real_complex_fact /-- The unit circle in `ℂ` is a charted space modelled on `euclidean_space ℝ (fin 1)`. This follows by definition from the corresponding result for `metric.sphere`. -/ instance : charted_space (euclidean_space ℝ (fin 1)) circle := metric.sphere.charted_space instance : smooth_manifold_with_corners (𝓡 1) circle := metric.sphere.smooth_manifold_with_corners /-- The unit circle in `ℂ` is a Lie group. -/ instance : lie_group (𝓡 1) circle := { smooth_mul := begin let c : circle → ℂ := coe, have h₁ : times_cont_mdiff _ _ _ (prod.map c c) := times_cont_mdiff_coe_sphere.prod_map times_cont_mdiff_coe_sphere, have h₂ : times_cont_mdiff (𝓘(ℝ, ℂ).prod 𝓘(ℝ, ℂ)) 𝓘(ℝ, ℂ) ∞ (λ (z : ℂ × ℂ), z.fst * z.snd), { rw times_cont_mdiff_iff, exact ⟨continuous_mul, λ x y, (times_cont_diff_mul.restrict_scalars ℝ).times_cont_diff_on⟩ }, exact (h₂.comp h₁).cod_restrict_sphere _, end, smooth_inv := (complex.conj_cle.times_cont_diff.times_cont_mdiff.comp times_cont_mdiff_coe_sphere).cod_restrict_sphere _, .. metric.sphere.smooth_manifold_with_corners } /-- The map `λ t, exp (t * I)` from `ℝ` to the unit circle in `ℂ` is smooth. -/ lemma times_cont_mdiff_exp_map_circle : times_cont_mdiff 𝓘(ℝ, ℝ) (𝓡 1) ∞ exp_map_circle := (((times_cont_diff_exp.restrict_scalars ℝ).comp (times_cont_diff_id.smul times_cont_diff_const)).times_cont_mdiff).cod_restrict_sphere _ end circle
58ebcdff91e2afae2bc47d4fad03bd7e490be301
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Elab/Deriving/Nonempty.lean
735193b7ae2f761e517f4417fcaad59254faa124
[ "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,497
lean
/- Copyright (c) 2022 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Gabriel Ebner -/ import Lean.Elab.Deriving.Basic namespace Lean.Elab open Command Meta Parser Term private def mkNonemptyInstance (declName : Name) : TermElabM Syntax.Command := do let indVal ← getConstInfoInduct declName forallTelescopeReducing indVal.type fun paramsIndices _ => do let mut indArgs := #[] let mut binders := #[] for x in paramsIndices do let arg := mkIdent (← mkFreshUserName (← x.fvarId!.getUserName).eraseMacroScopes) indArgs := indArgs.push arg binders := binders.push (← `(bracketedBinderF| {$arg})) if let .sort u ← whnf (← inferType x) then if let .some _ ← decLevel? u then binders := binders.push (← `(bracketedBinderF| [Nonempty $arg])) let ctorTacs ← indVal.ctors.toArray.mapM fun ctor => `(tactic| apply @$(mkCIdent ctor) <;> exact Classical.ofNonempty) `(command| variable $binders* in instance : Nonempty (@$(mkCIdent declName) $indArgs*) := ⟨by first $[| $ctorTacs:tactic]*⟩) def mkNonemptyInstanceHandler (declNames : Array Name) : CommandElabM Bool := do if (← declNames.allM isInductive) then for declName in declNames do elabCommand (← liftTermElabM do mkNonemptyInstance declName) return true else return false builtin_initialize registerDerivingHandler `Nonempty mkNonemptyInstanceHandler end Lean.Elab
00aeb77f1c49edd2354966e18ce8a2dc4207cb2f
02005f45e00c7ecf2c8ca5db60251bd1e9c860b5
/src/category_theory/adjunction/lifting.lean
be406c39c8c727d78607d9524886afd94581343f
[ "Apache-2.0" ]
permissive
anthony2698/mathlib
03cd69fe5c280b0916f6df2d07c614c8e1efe890
407615e05814e98b24b2ff322b14e8e3eb5e5d67
refs/heads/master
1,678,792,774,873
1,614,371,563,000
1,614,371,563,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
11,843
lean
/- Copyright (c) 2020 Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Bhavik Mehta -/ import category_theory.limits.shapes.equalizers import category_theory.limits.shapes.reflexive import category_theory.adjunction import category_theory.monad.adjunction import category_theory.monad.coequalizer /-! # Adjoint lifting This file gives two constructions for building left adjoints: the adjoint triangle theorem and the adjoint lifting theorem. The adjoint triangle theorem says that given a functor `U : B ⥤ C` with a left adjoint `F` such that `ε_X : FUX ⟶ X` is a regular epi. Then for any category `A` with coequalizers of reflexive pairs, a functor `R : A ⥤ B` has a left adjoint if (and only if) the composite `R ⋙ U` does. Note that the condition on `U` regarding `ε_X` is automatically satisfied in the case when `U` is a monadic functor, giving the corollary: `monadic_adjoint_triangle_lift`, i.e. if `U` is monadic, `A` has reflexive coequalizers then `R : A ⥤ B` has a left adjoint provided `R ⋙ U` does. The adjoint lifting theorem says that given a commutative square of functors (up to isomorphism): Q A → B U ↓ ↓ V C → D R where `U` and `V` are monadic and `A` has reflexive coequalizers, then if `R` has a left adjoint then `Q` has a left adjoint. ## Implementation It is more convenient to prove this theorem by assuming we are given the explicit adjunction rather than just a functor known to be a right adjoint. In docstrings, we write `(η, ε)` for the unit and counit of the adjunction `adj₁ : F ⊣ U` and `(ι, δ)` for the unit and counit of the adjunction `adj₂ : F' ⊣ R ⋙ U`. ## TODO Dualise to lift right adjoints through comonads (by reversing 1-cells) and dualise to lift right adjoints through monads (by reversing 2-cells), and the combination. ## References * https://ncatlab.org/nlab/show/adjoint+triangle+theorem * https://ncatlab.org/nlab/show/adjoint+lifting+theorem * Adjoint Lifting Theorems for Categories of Algebras (PT Johnstone, 1975) * A unified approach to the lifting of adjoints (AJ Power, 1988) -/ namespace category_theory open category limits universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄ variables {A : Type u₁} {B : Type u₂} {C : Type u₃} variables [category.{v₁} A] [category.{v₂} B] [category.{v₃} C] -- Hide implementation details in this namespace namespace lift_adjoint variables {U : B ⥤ C} {F : C ⥤ B} (R : A ⥤ B) (F' : C ⥤ A) variables (adj₁ : F ⊣ U) (adj₂ : F' ⊣ R ⋙ U) /-- To show that `ε_X` is a coequalizer for `(FUε_X, ε_FUX)`, it suffices to assume it's always a coequalizer of something (i.e. a regular epi). -/ def counit_coequalises [∀ (X : B), regular_epi (adj₁.counit.app X)] (X : B) : is_colimit (cofork.of_π (adj₁.counit.app X) (adj₁.counit_naturality _)) := cofork.is_colimit.mk' _ $ λ s, begin refine ⟨(regular_epi.desc' (adj₁.counit.app X) s.π _).1, _, _⟩, { rw ← cancel_epi (adj₁.counit.app (regular_epi.W (adj₁.counit.app X))), rw ← adj₁.counit_naturality_assoc, dsimp only [functor.comp_obj], rw [← s.condition, ← F.map_comp_assoc, ← U.map_comp, regular_epi.w, U.map_comp, F.map_comp_assoc, s.condition, ← adj₁.counit_naturality_assoc] }, { apply (regular_epi.desc' (adj₁.counit.app X) s.π _).2 }, { intros m hm, rw ← cancel_epi (adj₁.counit.app X), apply hm.trans (regular_epi.desc' (adj₁.counit.app X) s.π _).2.symm } end include adj₁ adj₂ /-- (Implementation) To construct the left adjoint, we use the coequalizer of `F' U ε_Y` with the composite `F' U F U X ⟶ F' U F U R F U' X ⟶ F' U R F' U X ⟶ F' U X` where the first morphism is `F' U F ι_UX`, the second is `F' U ε_RF'UX`, and the third is `δ_F'UX`. We will show that this coequalizer exists and that it forms the object map for a left adjoint to `R`. -/ def other_map (X) : F'.obj (U.obj (F.obj (U.obj X))) ⟶ F'.obj (U.obj X) := F'.map (U.map (F.map (adj₂.unit.app _) ≫ adj₁.counit.app _)) ≫ adj₂.counit.app _ /-- `(F'Uε_X, other_map X)` is a reflexive pair: in particular if `A` has reflexive coequalizers then it has a coequalizer. -/ instance (X : B) : is_reflexive_pair (F'.map (U.map (adj₁.counit.app X))) (other_map _ _ adj₁ adj₂ X) := is_reflexive_pair.mk' (F'.map (adj₁.unit.app (U.obj X))) (by {rw [← F'.map_comp, adj₁.right_triangle_components], apply F'.map_id }) begin dsimp [other_map], rw [← F'.map_comp_assoc, U.map_comp, adj₁.unit_naturality_assoc, adj₁.right_triangle_components, comp_id, adj₂.left_triangle_components] end variables [has_reflexive_coequalizers A] /-- Construct the object part of the desired left adjoint as the coequalizer of `F'Uε_Y` with `other_map`. -/ noncomputable def construct_left_adjoint_obj (Y : B) : A := coequalizer (F'.map (U.map (adj₁.counit.app Y))) (other_map _ _ adj₁ adj₂ Y) /-- The homset equivalence which helps show that `R` is a right adjoint. -/ @[simps {rhs_md := semireducible}] noncomputable def construct_left_adjoint_equiv [∀ (X : B), regular_epi (adj₁.counit.app X)] (Y : A) (X : B) : (construct_left_adjoint_obj _ _ adj₁ adj₂ X ⟶ Y) ≃ (X ⟶ R.obj Y) := calc (construct_left_adjoint_obj _ _ adj₁ adj₂ X ⟶ Y) ≃ {f : F'.obj (U.obj X) ⟶ Y // F'.map (U.map (adj₁.counit.app X)) ≫ f = other_map _ _ adj₁ adj₂ _ ≫ f} : cofork.is_colimit.hom_iso (colimit.is_colimit _) _ ... ≃ {g : U.obj X ⟶ U.obj (R.obj Y) // U.map (F.map g ≫ adj₁.counit.app _) = U.map (adj₁.counit.app _) ≫ g} : begin apply (adj₂.hom_equiv _ _).subtype_equiv _, intro f, rw [← (adj₂.hom_equiv _ _).injective.eq_iff, eq_comm, adj₂.hom_equiv_naturality_left, other_map, assoc, adj₂.hom_equiv_naturality_left, ← adj₂.counit_naturality, adj₂.hom_equiv_naturality_left, adj₂.hom_equiv_unit, adj₂.right_triangle_components, comp_id, functor.comp_map, ← U.map_comp, assoc, ← adj₁.counit_naturality, adj₂.hom_equiv_unit, adj₂.hom_equiv_unit, F.map_comp, assoc], refl, end ... ≃ {z : F.obj (U.obj X) ⟶ R.obj Y // _} : begin apply (adj₁.hom_equiv _ _).symm.subtype_equiv, intro g, rw [← (adj₁.hom_equiv _ _).symm.injective.eq_iff, adj₁.hom_equiv_counit, adj₁.hom_equiv_counit, adj₁.hom_equiv_counit, F.map_comp, assoc, U.map_comp, F.map_comp, assoc, adj₁.counit_naturality, adj₁.counit_naturality_assoc], apply eq_comm, end ... ≃ (X ⟶ R.obj Y) : (cofork.is_colimit.hom_iso (counit_coequalises adj₁ X) _).symm /-- Construct the left adjoint to `R`, with object map `construct_left_adjoint_obj`. -/ noncomputable def construct_left_adjoint [∀ (X : B), regular_epi (adj₁.counit.app X)] : B ⥤ A := begin refine adjunction.left_adjoint_of_equiv (λ X Y, construct_left_adjoint_equiv R _ adj₁ adj₂ Y X) _, intros X Y Y' g h, rw [construct_left_adjoint_equiv_apply, construct_left_adjoint_equiv_apply, function.comp_app, function.comp_app, equiv.trans_apply, equiv.trans_apply, equiv.trans_apply, equiv.trans_apply, equiv.symm_apply_eq, subtype.ext_iff, cofork.is_colimit.hom_iso_natural, equiv.apply_symm_apply, equiv.subtype_equiv_apply, equiv.subtype_equiv_apply, equiv.subtype_equiv_apply, equiv.subtype_equiv_apply, subtype.coe_mk, subtype.coe_mk, subtype.coe_mk, subtype.coe_mk, ← adj₁.hom_equiv_naturality_right_symm, cofork.is_colimit.hom_iso_natural, adj₂.hom_equiv_naturality_right, functor.comp_map], end end lift_adjoint /-- The adjoint triangle theorem: Suppose `U : B ⥤ C` has a left adjoint `F` such that each counit `ε_X : FUX ⟶ X` is a regular epimorphism. Then if a category `A` has coequalizers of reflexive pairs, then a functor `R : A ⥤ B` has a left adjoint if the composite `R ⋙ U` does. Note the converse is true (with weaker assumptions), by `adjunction.comp`. See https://ncatlab.org/nlab/show/adjoint+triangle+theorem -/ noncomputable def adjoint_triangle_lift {U : B ⥤ C} {F : C ⥤ B} (R : A ⥤ B) (adj₁ : F ⊣ U) [Π (X : B), regular_epi (adj₁.counit.app X)] [has_reflexive_coequalizers A] [is_right_adjoint (R ⋙ U)] : is_right_adjoint R := { left := lift_adjoint.construct_left_adjoint R _ adj₁ (adjunction.of_right_adjoint _), adj := adjunction.adjunction_of_equiv_left _ _ } /-- If `R ⋙ U` has a left adjoint, the domain of `R` has reflexive coequalizers and `U` is a monadic functor, then `R` has a left adjoint. This is a special case of `adjoint_triangle_lift` which is often more useful in practice. -/ noncomputable def monadic_adjoint_triangle_lift (U : B ⥤ C) [monadic_right_adjoint U] {R : A ⥤ B} [has_reflexive_coequalizers A] [is_right_adjoint (R ⋙ U)] : is_right_adjoint R := begin let R' : A ⥤ _ := R ⋙ monad.comparison (adjunction.of_right_adjoint U), suffices : is_right_adjoint R', { let : is_right_adjoint (R' ⋙ (monad.comparison (adjunction.of_right_adjoint U)).inv), { resetI, apply_instance }, { let : R' ⋙ (monad.comparison (adjunction.of_right_adjoint U)).inv ≅ R := (iso_whisker_left R (monad.comparison _).fun_inv_id : _) ≪≫ R.right_unitor, exactI adjunction.right_adjoint_of_nat_iso this } }, let : is_right_adjoint (R' ⋙ monad.forget (adjunction.of_right_adjoint U).to_monad) := adjunction.right_adjoint_of_nat_iso (iso_whisker_left R (monad.comparison_forget (adjunction.of_right_adjoint U)).symm : _), letI : Π X, regular_epi ((monad.adj (adjunction.of_right_adjoint U).to_monad).counit.app X), { intro X, dsimp only [monad.adj_counit, functor.comp_map, monad.forget_obj, functor.id_obj, functor.comp_obj, monad.free_obj_A], simp only [functor.map_id, id_comp], exact ⟨_, _, _, _, monad.beck_algebra_coequalizer X⟩ }, exact adjoint_triangle_lift R' (monad.adj _), end variables {D : Type u₄} variables [category.{v₄} D] /-- Suppose we have a commutative square of functors Q A → B U ↓ ↓ V C → D R where `U` has a left adjoint, `A` has reflexive coequalizers and `V` has a left adjoint such that each component of the counit is a regular epi. Then `Q` has a left adjoint if `R` has a left adjoint. See https://ncatlab.org/nlab/show/adjoint+lifting+theorem -/ noncomputable def adjoint_square_lift (Q : A ⥤ B) (V : B ⥤ D) (U : A ⥤ C) (R : C ⥤ D) (comm : U ⋙ R ≅ Q ⋙ V) [is_right_adjoint U] [is_right_adjoint V] [is_right_adjoint R] [∀ X, regular_epi ((adjunction.of_right_adjoint V).counit.app X)] [has_reflexive_coequalizers A] : is_right_adjoint Q := begin let := adjunction.right_adjoint_of_nat_iso comm, exactI adjoint_triangle_lift Q (adjunction.of_right_adjoint V), end /-- Suppose we have a commutative square of functors Q A → B U ↓ ↓ V C → D R where `U` has a left adjoint, `A` has reflexive coequalizers and `V` is monadic. Then `Q` has a left adjoint if `R` has a left adjoint. See https://ncatlab.org/nlab/show/adjoint+lifting+theorem -/ noncomputable def monadic_adjoint_square_lift (Q : A ⥤ B) (V : B ⥤ D) (U : A ⥤ C) (R : C ⥤ D) (comm : U ⋙ R ≅ Q ⋙ V) [is_right_adjoint U] [monadic_right_adjoint V] [is_right_adjoint R] [has_reflexive_coequalizers A] : is_right_adjoint Q := begin let := adjunction.right_adjoint_of_nat_iso comm, exactI monadic_adjoint_triangle_lift V, end end category_theory
0d32f3ed40b9f6cadd36f51604cebbbaf06afa14
ed27983dd289b3bcad416f0b1927105d6ef19db8
/src/inClassNotes/higherOrderFunctions/list_map.lean
6aa88d6a68e3eae298f01c50fa7f2b4e7134e36b
[]
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
168
lean
def list_map {α β : Type} : (α → β) → (list α) → list β | f list.nil := list.nil | f (h::t) := (f h)::(list_map f t) #eval list_map nat.succ [1,2,3,4,5,6]
c22acd6a60dd8b8e853ef79da7629db57421b72c
35677d2df3f081738fa6b08138e03ee36bc33cad
/src/ring_theory/localization.lean
17fca5c07622bfd5c31444b466a1c5f038f11fce
[ "Apache-2.0" ]
permissive
gebner/mathlib
eab0150cc4f79ec45d2016a8c21750244a2e7ff0
cc6a6edc397c55118df62831e23bfbd6e6c6b4ab
refs/heads/master
1,625,574,853,976
1,586,712,827,000
1,586,712,827,000
99,101,412
1
0
Apache-2.0
1,586,716,389,000
1,501,667,958,000
Lean
UTF-8
Lean
false
false
27,210
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 -/ import tactic.ring data.quot data.equiv.ring ring_theory.ideal_operations group_theory.submonoid universes u v local attribute [instance, priority 10] is_ring_hom.comp namespace localization variables (α : Type u) [comm_ring α] (S : set α) def r (x y : α × S) : Prop := ∃ t ∈ S, ((x.2 : α) * y.1 - y.2 * x.1) * t = 0 local infix ≈ := r α S theorem symm (x y : α × S) : x ≈ y → y ≈ x := λ ⟨t, hts, ht⟩, ⟨t, hts, by rw [← neg_sub, ← neg_mul_eq_neg_mul, ht, neg_zero]⟩ variable [is_submonoid S] section variables {α S} theorem r_of_eq {a₀ a₁ : α × S} (h : (a₀.2 : α) * a₁.1 = a₁.2 * a₀.1) : a₀ ≈ a₁ := ⟨1, is_submonoid.one_mem, by rw [h, sub_self, mul_one]⟩ end theorem refl (x : α × S) : x ≈ x := r_of_eq rfl theorem trans : ∀ (x y z : α × S), x ≈ y → y ≈ z → x ≈ z := λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨t, hts, ht⟩ ⟨t', hts', ht'⟩, ⟨s₂ * t' * t, is_submonoid.mul_mem (is_submonoid.mul_mem hs₂ hts') hts, calc (s₁ * r₃ - s₃ * r₁) * (s₂ * t' * t) = t' * s₃ * ((s₁ * r₂ - s₂ * r₁) * t) + t * s₁ * ((s₂ * r₃ - s₃ * r₂) * t') : by ring ... = 0 : by simp only [subtype.coe_mk] at ht ht'; rw [ht, ht']; simp⟩ instance : setoid (α × S) := ⟨r α S, refl α S, symm α S, trans α S⟩ end localization /-- The localization of a ring at a submonoid: the elements of the submonoid become invertible in the localization.-/ def localization (α : Type u) [comm_ring α] (S : set α) [is_submonoid S] := quotient $ localization.setoid α S namespace localization variables (α : Type u) [comm_ring α] (S : set α) [is_submonoid S] instance : has_add (localization α S) := ⟨quotient.lift₂ (λ x y : α × S, (⟦⟨x.2 * y.1 + y.2 * x.1, x.2 * y.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩, quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅, calc (s₁ * s₂ * (s₃ * r₄ + s₄ * r₃) - s₃ * s₄ * (s₁ * r₂ + s₂ * r₁)) * (t₆ * t₅) = s₁ * s₃ * ((s₂ * r₄ - s₄ * r₂) * t₆) * t₅ + s₂ * s₄ * ((s₁ * r₃ - s₃ * r₁) * t₅) * t₆ : by ring ... = 0 : by simp only [subtype.coe_mk] at ht₅ ht₆; rw [ht₆, ht₅]; simp⟩⟩ instance : has_neg (localization α S) := ⟨quotient.lift (λ x : α × S, (⟦⟨-x.1, x.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩, quotient.sound ⟨t, hts, calc (s₁ * -r₂ - s₂ * -r₁) * t = -((s₁ * r₂ - s₂ * r₁) * t) : by ring ... = 0 : by simp only [subtype.coe_mk] at ht; rw ht; simp⟩⟩ instance : has_mul (localization α S) := ⟨quotient.lift₂ (λ x y : α × S, (⟦⟨x.1 * y.1, x.2 * y.2⟩⟧ : localization α S)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩, quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅, calc ((s₁ * s₂) * (r₃ * r₄) - (s₃ * s₄) * (r₁ * r₂)) * (t₆ * t₅) = t₆ * ((s₁ * r₃ - s₃ * r₁) * t₅) * r₂ * s₄ + t₅ * ((s₂ * r₄ - s₄ * r₂) * t₆) * r₃ * s₁ : by ring ... = 0 : by simp only [subtype.coe_mk] at ht₅ ht₆; rw [ht₅, ht₆]; simp⟩⟩ variables {α S} def mk (r : α) (s : S) : localization α S := ⟦(r, s)⟧ /-- The natural map from the ring to the localization.-/ def of (r : α) : localization α S := mk r 1 instance : comm_ring (localization α S) := by refine { add := has_add.add, add_assoc := λ m n k, quotient.induction_on₃ m n k _, zero := of 0, zero_add := quotient.ind _, add_zero := quotient.ind _, neg := has_neg.neg, add_left_neg := quotient.ind _, add_comm := quotient.ind₂ _, mul := has_mul.mul, mul_assoc := λ m n k, quotient.induction_on₃ m n k _, one := of 1, one_mul := quotient.ind _, mul_one := quotient.ind _, left_distrib := λ m n k, quotient.induction_on₃ m n k _, right_distrib := λ m n k, quotient.induction_on₃ m n k _, mul_comm := quotient.ind₂ _ }; { intros, try {rcases a with ⟨r₁, s₁, hs₁⟩}, try {rcases b with ⟨r₂, s₂, hs₂⟩}, try {rcases c with ⟨r₃, s₃, hs₃⟩}, refine (quotient.sound $ r_of_eq _), simp only [is_submonoid.coe_mul, is_submonoid.coe_one, subtype.coe_mk], ring } instance : inhabited (localization α S) := ⟨0⟩ instance of.is_ring_hom : is_ring_hom (of : α → localization α S) := { map_add := λ x y, quotient.sound $ by simp [add_comm], map_mul := λ x y, quotient.sound $ by simp [add_comm], map_one := rfl } variables {S} instance : has_coe_t α (localization α S) := ⟨of⟩ -- note [use has_coe_t] instance coe.is_ring_hom : is_ring_hom (coe : α → localization α S) := localization.of.is_ring_hom /-- The natural map from the submonoid to the unit group of the localization.-/ def to_units (s : S) : units (localization α S) := { val := s, inv := mk 1 s, val_inv := quotient.sound $ r_of_eq $ mul_assoc _ _ _, inv_val := quotient.sound $ r_of_eq $ show s.val * 1 * 1 = 1 * (1 * s.val), by simp } @[simp] lemma to_units_coe (s : S) : ((to_units s) : localization α S) = ((s : α) : localization α S) := rfl section variables (α S) (x y : α) (n : ℕ) @[simp] lemma of_zero : (of 0 : localization α S) = 0 := rfl @[simp] lemma of_one : (of 1 : localization α S) = 1 := rfl @[simp] lemma of_add : (of (x + y) : localization α S) = of x + of y := by apply is_ring_hom.map_add @[simp] lemma of_sub : (of (x - y) : localization α S) = of x - of y := by apply is_ring_hom.map_sub @[simp] lemma of_mul : (of (x * y) : localization α S) = of x * of y := by apply is_ring_hom.map_mul @[simp] lemma of_neg : (of (-x) : localization α S) = -of x := by apply is_ring_hom.map_neg @[simp] lemma of_pow : (of (x ^ n) : localization α S) = (of x) ^ n := by apply is_semiring_hom.map_pow @[simp] lemma of_is_unit' (s ∈ S) : is_unit (of s : localization α S) := is_unit_unit $ to_units ⟨s, ‹s ∈ S›⟩ @[simp] lemma of_is_unit (s : S) : is_unit (of s : localization α S) := is_unit_unit $ to_units s @[simp] lemma coe_zero : ((0 : α) : localization α S) = 0 := rfl @[simp] lemma coe_one : ((1 : α) : localization α S) = 1 := rfl @[simp] lemma coe_add : (↑(x + y) : localization α S) = x + y := of_add _ _ _ _ @[simp] lemma coe_sub : (↑(x - y) : localization α S) = x - y := of_sub _ _ _ _ @[simp] lemma coe_mul : (↑(x * y) : localization α S) = x * y := of_mul _ _ _ _ @[simp] lemma coe_neg : (↑(-x) : localization α S) = -x := of_neg _ _ _ @[simp] lemma coe_pow : (↑(x ^ n) : localization α S) = x ^ n := of_pow _ _ _ _ @[simp] lemma coe_is_unit' (s ∈ S) : is_unit ((s : α) : localization α S) := of_is_unit' _ _ _ ‹s ∈ S› @[simp] lemma coe_is_unit (s : S) : is_unit ((s : α) : localization α S) := of_is_unit _ _ _ end lemma mk_self {x : α} {hx : x ∈ S} : (mk x ⟨x, hx⟩ : localization α S) = 1 := quotient.sound ⟨1, is_submonoid.one_mem, by simp only [subtype.coe_mk, is_submonoid.coe_one, mul_one, one_mul, sub_self]⟩ lemma mk_self' {s : S} : (mk s s : localization α S) = 1 := by cases s; exact mk_self lemma mk_self'' {s : S} : (mk s.1 s : localization α S) = 1 := mk_self' -- This lemma does not apply with simp, since (mk r s) simplifies to (r * s⁻¹). -- However, it could apply with dsimp. @[simp, nolint simp_nf] lemma coe_mul_mk (x y : α) (s : S) : ↑x * mk y s = mk (x * y) s := quotient.sound $ r_of_eq $ by rw one_mul lemma mk_eq_mul_mk_one (r : α) (s : S) : mk r s = r * mk 1 s := by rw [coe_mul_mk, mul_one] -- This lemma does not apply with simp, since (mk r s) simplifies to (r * s⁻¹). -- However, it could apply with dsimp. @[simp, nolint simp_nf] lemma mk_mul_mk (x y : α) (s t : S) : mk x s * mk y t = mk (x * y) (s * t) := rfl lemma mk_mul_cancel_left (r : α) (s : S) : mk (↑s * r) s = r := by rw [mk_eq_mul_mk_one, mul_comm ↑s, coe_mul, mul_assoc, ← mk_eq_mul_mk_one, mk_self', mul_one] lemma mk_mul_cancel_right (r : α) (s : S) : mk (r * s) s = r := by rw [mul_comm, mk_mul_cancel_left] @[simp] lemma mk_eq (r : α) (s : S) : mk r s = r * ((to_units s)⁻¹ : units _) := quotient.sound $ by simp @[elab_as_eliminator] protected theorem induction_on {C : localization α S → Prop} (x : localization α S) (ih : ∀ r s, C (mk r s : localization α S)) : C x := by rcases x with ⟨r, s⟩; exact ih r s section variables {β : Type v} [comm_ring β] {T : set β} [is_submonoid T] (f : α → β) [is_ring_hom f] @[elab_with_expected_type] def lift' (g : S → units β) (hg : ∀ s, (g s : β) = f s) (x : localization α S) : β := quotient.lift_on x (λ p, f p.1 * ((g p.2)⁻¹ : units β)) $ λ ⟨r₁, s₁⟩ ⟨r₂, s₂⟩ ⟨t, hts, ht⟩, show f r₁ * ↑(g s₁)⁻¹ = f r₂ * ↑(g s₂)⁻¹, from calc f r₁ * ↑(g s₁)⁻¹ = (f r₁ * g s₂ + ((g s₁ * f r₂ - g s₂ * f r₁) * g ⟨t, hts⟩) * ↑(g ⟨t, hts⟩)⁻¹) * ↑(g s₁)⁻¹ * ↑(g s₂)⁻¹ : by simp only [hg, subtype.coe_mk, (is_ring_hom.map_mul f).symm, (is_ring_hom.map_sub f).symm, ht, is_ring_hom.map_zero f, zero_mul, add_zero]; rw [is_ring_hom.map_mul f, ← hg, mul_right_comm, mul_assoc (f r₁), ← units.coe_mul, mul_inv_self]; rw [units.coe_one, mul_one] ... = f r₂ * ↑(g s₂)⁻¹ : by rw [mul_assoc, mul_assoc, ← units.coe_mul, mul_inv_self, units.coe_one, mul_one, mul_comm ↑(g s₂), add_sub_cancel'_right]; rw [mul_comm ↑(g s₁), ← mul_assoc, mul_assoc (f r₂), ← units.coe_mul, mul_inv_self, units.coe_one, mul_one] instance lift'.is_ring_hom (g : S → units β) (hg : ∀ s, (g s : β) = f s) : is_ring_hom (localization.lift' f g hg) := { map_one := have g 1 = 1, from units.ext (by rw hg; exact is_ring_hom.map_one f), show f 1 * ↑(g 1)⁻¹ = 1, by rw [this, one_inv, units.coe_one, mul_one, is_ring_hom.map_one f], map_mul := λ x y, localization.induction_on x $ λ r₁ s₁, localization.induction_on y $ λ r₂ s₂, have g (s₁ * s₂) = g s₁ * g s₂, from units.ext (by simp only [hg, units.coe_mul]; exact is_ring_hom.map_mul f), show _ * ↑(g (_ * _))⁻¹ = (_ * _) * (_ * _), by simp only [subtype.coe_mk, mul_one, one_mul, subtype.coe_eta, this, mul_inv_rev]; rw [is_ring_hom.map_mul f, units.coe_mul, ← mul_assoc, ← mul_assoc]; simp only [mul_right_comm], map_add := λ x y, localization.induction_on x $ λ r₁ s₁, localization.induction_on y $ λ r₂ s₂, have g (s₁ * s₂) = g s₁ * g s₂, from units.ext (by simp only [hg, units.coe_mul]; exact is_ring_hom.map_mul f), show _ * ↑(g (_ * _))⁻¹ = _ * _ + _ * _, by simp only [subtype.coe_mk, mul_one, one_mul, subtype.coe_eta, this, mul_inv_rev]; simp only [is_ring_hom.map_mul f, is_ring_hom.map_add f, add_mul, (hg _).symm]; simp only [mul_assoc, mul_comm, mul_left_comm, (units.coe_mul _ _).symm]; rw [mul_inv_cancel_left, mul_left_comm, ← mul_assoc, mul_inv_cancel_right, add_comm] } noncomputable def lift (h : ∀ s ∈ S, is_unit (f s)) : localization α S → β := localization.lift' f (λ s, classical.some $ h s.1 s.2) (λ s, by rw [← classical.some_spec (h s.1 s.2)]; refl) instance lift.is_ring_hom (h : ∀ s ∈ S, is_unit (f s)) : is_ring_hom (lift f h) := lift'.is_ring_hom _ _ _ -- This lemma does not apply with simp, since (mk r s) simplifies to (r * s⁻¹). -- However, it could apply with dsimp. @[simp, nolint simp_nf] lemma lift'_mk (g : S → units β) (hg : ∀ s, (g s : β) = f s) (r : α) (s : S) : lift' f g hg (mk r s) = f r * ↑(g s)⁻¹ := rfl @[simp] lemma lift'_of (g : S → units β) (hg : ∀ s, (g s : β) = f s) (a : α) : lift' f g hg (of a) = f a := have g 1 = 1, from units.ext_iff.2 $ by simp [hg, is_ring_hom.map_one f], by simp [lift', quotient.lift_on_beta, of, mk, this] @[simp] lemma lift'_coe (g : S → units β) (hg : ∀ s, (g s : β) = f s) (a : α) : lift' f g hg a = f a := lift'_of _ _ _ _ @[simp] lemma lift_of (h : ∀ s ∈ S, is_unit (f s)) (a : α) : lift f h (of a) = f a := lift'_of _ _ _ _ @[simp] lemma lift_coe (h : ∀ s ∈ S, is_unit (f s)) (a : α) : lift f h a = f a := lift'_of _ _ _ _ @[simp] lemma lift'_comp_of (g : S → units β) (hg : ∀ s, (g s : β) = f s) : lift' f g hg ∘ of = f := funext $ λ a, lift'_of _ _ _ a @[simp] lemma lift_comp_of (h : ∀ s ∈ S, is_unit (f s)) : lift f h ∘ of = f := lift'_comp_of _ _ _ @[simp] lemma lift'_apply_coe (f : localization α S → β) [is_ring_hom f] (g : S → units β) (hg : ∀ s, (g s : β) = f s) : lift' (λ a : α, f a) g hg = f := have g = (λ s, (units.map' f : units (localization α S) → units β) (to_units s)), from funext $ λ x, units.ext $ (hg x).symm ▸ rfl, funext $ λ x, localization.induction_on x (λ r s, by subst this; rw [lift'_mk, ← (units.map' f).map_inv, units.coe_map']; simp [is_ring_hom.map_mul f]) @[simp] lemma lift_apply_coe (f : localization α S → β) [is_ring_hom f] : lift (λ a : α, f a) (λ s hs, is_unit.map' f (is_unit_unit (to_units ⟨s, hs⟩))) = f := by rw [lift, lift'_apply_coe] /-- Function extensionality for localisations: two functions are equal if they agree on elements that are coercions.-/ protected lemma funext (f g : localization α S → β) [is_ring_hom f] [is_ring_hom g] (h : ∀ a : α, f a = g a) : f = g := begin rw [← lift_apply_coe f, ← lift_apply_coe g], congr' 1, exact funext h end variables {α S T} def map (hf : ∀ s ∈ S, f s ∈ T) : localization α S → localization β T := lift' (of ∘ f) (to_units ∘ subtype.map f hf) (λ s, rfl) instance map.is_ring_hom (hf : ∀ s ∈ S, f s ∈ T) : is_ring_hom (map f hf) := lift'.is_ring_hom _ _ _ @[simp] lemma map_of (hf : ∀ s ∈ S, f s ∈ T) (a : α) : map f hf (of a) = of (f a) := lift'_of _ _ _ _ @[simp] lemma map_coe (hf : ∀ s ∈ S, f s ∈ T) (a : α) : map f hf a = (f a) := lift'_of _ _ _ _ @[simp] lemma map_comp_of (hf : ∀ s ∈ S, f s ∈ T) : map f hf ∘ of = of ∘ f := funext $ λ a, map_of _ _ _ @[simp] lemma map_id : map id (λ s (hs : s ∈ S), hs) = id := localization.funext _ _ $ map_coe _ _ lemma map_comp_map {γ : Type*} [comm_ring γ] (hf : ∀ s ∈ S, f s ∈ T) (U : set γ) [is_submonoid U] (g : β → γ) [is_ring_hom g] (hg : ∀ t ∈ T, g t ∈ U) : map g hg ∘ map f hf = map (λ x, g (f x)) (λ s hs, hg _ (hf _ hs)) := localization.funext _ _ $ by simp lemma map_map {γ : Type*} [comm_ring γ] (hf : ∀ s ∈ S, f s ∈ T) (U : set γ) [is_submonoid U] (g : β → γ) [is_ring_hom g] (hg : ∀ t ∈ T, g t ∈ U) (x) : map g hg (map f hf x) = map (λ x, g (f x)) (λ s hs, hg _ (hf _ hs)) x := congr_fun (map_comp_map _ _ _ _ _) x def equiv_of_equiv (h₁ : α ≃+* β) (h₂ : h₁ '' S = T) : localization α S ≃+* localization β T := { to_fun := map h₁ $ λ s hs, h₂ ▸ set.mem_image_of_mem _ hs, inv_fun := map h₁.symm $ λ t ht, by simp [h₁.image_eq_preimage, set.preimage, set.ext_iff, *] at *, left_inv := λ _, by simp only [map_map, h₁.symm_apply_apply]; erw map_id; refl, right_inv := λ _, by simp only [map_map, h₁.apply_symm_apply]; erw map_id; refl, map_mul' := λ _ _, is_ring_hom.map_mul _, map_add' := λ _ _, is_ring_hom.map_add _ } end section away variables {β : Type v} [comm_ring β] (f : α → β) [is_ring_hom f] @[reducible] def away (x : α) := localization α (powers x) @[simp] def away.inv_self (x : α) : away x := mk 1 ⟨x, 1, pow_one x⟩ @[elab_with_expected_type] noncomputable def away.lift {x : α} (hfx : is_unit (f x)) : away x → β := localization.lift' f (λ s, classical.some hfx ^ classical.some s.2) $ λ s, by rw [units.coe_pow, ← classical.some_spec hfx, ← is_semiring_hom.map_pow f, classical.some_spec s.2]; refl instance away.lift.is_ring_hom {x : α} (hfx : is_unit (f x)) : is_ring_hom (localization.away.lift f hfx) := lift'.is_ring_hom _ _ _ @[simp] lemma away.lift_of {x : α} (hfx : is_unit (f x)) (a : α) : away.lift f hfx (of a) = f a := lift'_of _ _ _ _ @[simp] lemma away.lift_coe {x : α} (hfx : is_unit (f x)) (a : α) : away.lift f hfx a = f a := lift'_of _ _ _ _ @[simp] lemma away.lift_comp_of {x : α} (hfx : is_unit (f x)) : away.lift f hfx ∘ of = f := lift'_comp_of _ _ _ noncomputable def away_to_away_right (x y : α) : away x → away (x * y) := localization.away.lift coe $ is_unit_of_mul_eq_one x (y * away.inv_self (x * y)) $ by rw [away.inv_self, coe_mul_mk, coe_mul_mk, mul_one, mk_self] instance away_to_away_right.is_ring_hom (x y : α) : is_ring_hom (away_to_away_right x y) := away.lift.is_ring_hom _ _ end away section at_prime variables (P : ideal α) [hp : ideal.is_prime P] include hp instance prime.is_submonoid : is_submonoid (-P : set α) := { one_mem := P.ne_top_iff_one.1 hp.1, mul_mem := λ x y hnx hny hxy, or.cases_on (hp.2 hxy) hnx hny } @[reducible] def at_prime := localization α (-P) instance at_prime.local_ring : local_ring (at_prime P) := local_of_nonunits_ideal (λ hze, let ⟨t, hts, ht⟩ := quotient.exact hze in hts $ have htz : t = 0, by simpa using ht, suffices (0:α) ∈ P, by rwa htz, P.zero_mem) (begin rintro ⟨⟨r₁, s₁, hs₁⟩⟩ ⟨⟨r₂, s₂, hs₂⟩⟩ hx hy hu, rcases is_unit_iff_exists_inv.1 hu with ⟨⟨⟨r₃, s₃, hs₃⟩⟩, hz⟩, rcases quotient.exact hz with ⟨t, hts, ht⟩, simp at ht, have : ∀ {r s hs}, (⟦⟨r, s, hs⟩⟧ : at_prime P) ∈ nonunits (at_prime P) → r ∈ P, { haveI := classical.dec, exact λ r s hs, not_imp_comm.1 (λ nr, is_unit_iff_exists_inv.2 ⟨⟦⟨s, r, nr⟩⟧, quotient.sound $ r_of_eq $ by simp [mul_comm]⟩) }, have hr₃ := (hp.mem_or_mem_of_mul_eq_zero ht).resolve_right hts, have := (ideal.add_mem_iff_left _ _).1 hr₃, { exact not_or (mt hp.mem_or_mem (not_or hs₁ hs₂)) hs₃ (hp.mem_or_mem this) }, { exact P.neg_mem (P.mul_mem_right (P.add_mem (P.mul_mem_left (this hy)) (P.mul_mem_left (this hx)))) } end) end at_prime variable (α) def non_zero_divisors : set α := {x | ∀ z, z * x = 0 → z = 0} instance non_zero_divisors.is_submonoid : is_submonoid (non_zero_divisors α) := { 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 } @[simp] lemma non_zero_divisors_one_val : (1 : non_zero_divisors α).val = 1 := rfl /-- The field of fractions of an integral domain.-/ @[reducible] def fraction_ring := localization α (non_zero_divisors α) namespace fraction_ring open function variables {β : Type u} [integral_domain β] lemma eq_zero_of_ne_zero_of_mul_eq_zero {x y : β} : x ≠ 0 → y * x = 0 → y = 0 := λ hnx hxy, or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx lemma mem_non_zero_divisors_iff_ne_zero {x : β} : x ∈ non_zero_divisors β ↔ 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⟩ variables (β) [de : decidable_eq β] include de def inv_aux (x : β × (non_zero_divisors β)) : fraction_ring β := if h : x.1 = 0 then 0 else ⟦⟨x.2, x.1, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ instance : has_inv (fraction_ring β) := ⟨quotient.lift (inv_aux β) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩, begin have hrs : s₁ * r₂ = 0 + s₂ * r₁, from sub_eq_iff_eq_add.1 (hts _ ht), by_cases hr₁ : r₁ = 0; by_cases hr₂ : r₂ = 0; simp [hr₁, hr₂] at hrs; simp only [inv_aux, hr₁, hr₂, dif_pos, dif_neg, not_false_iff, subtype.coe_mk, quotient.eq], { exfalso, exact mem_non_zero_divisors_iff_ne_zero.mp hs₁ hrs }, { exfalso, exact mem_non_zero_divisors_iff_ne_zero.mp hs₂ hrs }, { apply r_of_eq, simpa [mul_comm] using hrs.symm } end⟩ lemma mk_inv {r s} : (mk r s : fraction_ring β)⁻¹ = if h : r = 0 then 0 else ⟦⟨s, r, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ := rfl lemma mk_inv' : ∀ (x : β × (non_zero_divisors β)), (⟦x⟧⁻¹ : fraction_ring β) = if h : x.1 = 0 then 0 else ⟦⟨x.2.val, x.1, mem_non_zero_divisors_iff_ne_zero.mpr h⟩⟧ | ⟨r,s,hs⟩ := rfl instance : decidable_eq (fraction_ring β) := @quotient.decidable_eq (β × non_zero_divisors β) (localization.setoid β (non_zero_divisors β)) $ λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩, show decidable (∃ t ∈ non_zero_divisors β, (s₁ * r₂ - s₂ * r₁) * t = 0), from decidable_of_iff (s₁ * r₂ - s₂ * r₁ = 0) ⟨λ H, ⟨1, λ y, (mul_one y).symm ▸ id, H.symm ▸ zero_mul _⟩, λ ⟨t, ht1, ht2⟩, or.resolve_right (mul_eq_zero.1 ht2) $ λ ht, one_ne_zero (ht1 1 ((one_mul t).symm ▸ ht))⟩ instance : field (fraction_ring β) := by refine { inv := has_inv.inv, zero_ne_one := λ hzo, let ⟨t, hts, ht⟩ := quotient.exact hzo in zero_ne_one (by simpa using hts _ ht : 0 = 1), mul_inv_cancel := quotient.ind _, inv_zero := dif_pos rfl, .. localization.comm_ring }; { intros x hnx, rcases x with ⟨x, z, hz⟩, have : x ≠ 0, from assume hx, hnx (quotient.sound $ r_of_eq $ by simp [hx]), simp only [has_inv.inv, inv_aux, quotient.lift_beta, dif_neg this], exact (quotient.sound $ r_of_eq $ by simp [mul_comm]) } @[simp, nolint simp_nf] -- takes a crazy amount of time simplify lhs lemma mk_eq_div {r s} : (mk r s : fraction_ring β) = (r / s : fraction_ring β) := show _ = _ * dite (s.1 = 0) _ _, by rw [dif_neg (mem_non_zero_divisors_iff_ne_zero.mp s.2)]; exact localization.mk_eq_mul_mk_one _ _ variables {β} @[simp] lemma mk_eq_div' (x : β × (non_zero_divisors β)) : (⟦x⟧ : fraction_ring β) = ((x.1) / ((x.2).val) : fraction_ring β) := by erw ← mk_eq_div; cases x; refl lemma eq_zero_of (x : β) (h : (of x : fraction_ring β) = 0) : x = 0 := begin rcases quotient.exact h with ⟨t, ht, ht'⟩, simpa [mem_non_zero_divisors_iff_ne_zero.mp ht] using ht' end omit de lemma of.injective : function.injective (of : β → fraction_ring β) := (is_add_group_hom.injective_iff _).mpr $ by { classical, exact eq_zero_of } section map open function is_ring_hom variables {A : Type u} [integral_domain A] variables {B : Type v} [integral_domain B] variables (f : A → B) [is_ring_hom f] def map (hf : injective f) : fraction_ring A → fraction_ring B := localization.map f $ λ s h, by rw [mem_non_zero_divisors_iff_ne_zero, ← map_zero f, ne.def, hf.eq_iff]; exact mem_non_zero_divisors_iff_ne_zero.1 h @[simp] lemma map_of (hf : injective f) (a : A) : map f hf (of a) = of (f a) := localization.map_of _ _ _ @[simp] lemma map_coe (hf : injective f) (a : A) : map f hf a = f a := localization.map_coe _ _ _ @[simp] lemma map_comp_of (hf : injective f) : map f hf ∘ (of : A → fraction_ring A) = (of : B → fraction_ring B) ∘ f := localization.map_comp_of _ _ instance map.is_ring_hom (hf : injective f) : is_ring_hom (map f hf) := localization.map.is_ring_hom _ _ def equiv_of_equiv (h : A ≃+* B) : fraction_ring A ≃+* fraction_ring B := localization.equiv_of_equiv h begin ext b, rw [h.image_eq_preimage, set.preimage, set.mem_set_of_eq, mem_non_zero_divisors_iff_ne_zero, mem_non_zero_divisors_iff_ne_zero, ne.def], exact h.symm.map_ne_zero_iff end end map end fraction_ring section ideals theorem map_comap (J : ideal (localization α S)) : ideal.map (ring_hom.of coe) (ideal.comap (ring_hom.of (coe : α → localization α S)) J) = J := le_antisymm (ideal.map_le_iff_le_comap.2 (le_refl _)) $ λ x, localization.induction_on x $ λ r s hJ, (submodule.mem_coe _).2 $ mul_one r ▸ coe_mul_mk r 1 s ▸ (ideal.mul_mem_right _ $ ideal.mem_map_of_mem $ have _ := @ideal.mul_mem_left (localization α S) _ _ s _ hJ, by rwa [coe_coe, coe_mul_mk, mk_mul_cancel_left] at this) def le_order_embedding : ((≤) : ideal (localization α S) → ideal (localization α S) → Prop) ≼o ((≤) : ideal α → ideal α → Prop) := { to_fun := λ J, ideal.comap (ring_hom.of coe) J, inj := function.injective_of_left_inverse (map_comap α), ord := λ J₁ J₂, ⟨ideal.comap_mono, λ hJ, map_comap α J₁ ▸ map_comap α J₂ ▸ ideal.map_mono hJ⟩ } end ideals section module /-! ### `module` section Localizations form an algebra over `α` induced by the embedding `coe : α → localization α S`. -/ set_option class.instance_max_depth 50 variables (α S) instance : algebra α (localization α S) := (ring_hom.of coe).to_algebra $ λ _, mul_comm _ lemma of_smul (c x : α) : (of (c • x) : localization α S) = c • of x := by { simp, refl } lemma coe_smul (c x : α) : (coe (c • x) : localization α S) = c • coe x := of_smul α S c x lemma coe_mul_eq_smul (c : α) (x : localization α S) : coe c * x = c • x := rfl lemma mul_coe_eq_smul (c : α) (x : localization α S) : x * coe c = c • x := mul_comm x (coe c) /-- The embedding `coe : α → localization α S` induces a linear map. -/ def lin_coe : α →ₗ[α] localization α S := ⟨coe, coe_add α S, coe_smul α S⟩ @[simp] lemma lin_coe_apply (a : α) : lin_coe α S a = coe a := rfl instance coe_submodules : has_coe (ideal α) (submodule α (localization α S)) := ⟨submodule.map (lin_coe _ _)⟩ @[simp] lemma of_id (a : α) : (algebra.of_id α (localization α S) : α → localization α S) a = ↑a := rfl end module section is_integer /-- `a : localization α S` is an integer if it is an element of the original ring `α` -/ def is_integer (S : set α) [is_submonoid S] (a : localization α S) : Prop := a ∈ set.range (coe : α → localization α S) lemma is_integer_coe (a : α) : is_integer α S a := ⟨a, rfl⟩ lemma is_integer_add {a b} (ha : is_integer α S a) (hb : is_integer α S b) : is_integer α S (a + b) := begin rcases ha with ⟨a', ha⟩, rcases hb with ⟨b', hb⟩, use a' + b', rw [coe_add, ha, hb] end lemma is_integer_mul {a b} (ha : is_integer α S a) (hb : is_integer α S b) : is_integer α S (a * b) := begin rcases ha with ⟨a', ha⟩, rcases hb with ⟨b', hb⟩, use a' * b', rw [coe_mul, ha, hb] end set_option class.instance_max_depth 50 lemma is_integer_smul {a : α} {b} (hb : is_integer α S b) : is_integer α S (a • b) := begin rcases hb with ⟨b', hb⟩, use a * b', rw [←hb, ←coe_smul, smul_eq_mul] end end is_integer end localization
24844e84f628cbf076a31761aa1b3250edf7513e
36938939954e91f23dec66a02728db08a7acfcf9
/lean4/app/WordSize.lean
897593f254f569ada8d62af55517747d49127c08
[]
no_license
pnwamk/reopt-vcg
f8b56dd0279392a5e1c6aee721be8138e6b558d3
c9f9f185fbefc25c36c4b506bbc85fd1a03c3b6d
refs/heads/master
1,631,145,017,772
1,593,549,019,000
1,593,549,143,000
254,191,418
0
0
null
1,586,377,077,000
1,586,377,077,000
null
UTF-8
Lean
false
false
523
lean
import SMTLIB.Syntax inductive WordSize | word8 : WordSize | word16 : WordSize | word32 : WordSize | word64 : WordSize namespace WordSize def bytes : WordSize → Nat | word8 => 1 | word16 => 2 | word32 => 4 | word64 => 8 /-- Bit width (i.e., the nominal width) --/ def bits (w:WordSize) : Nat := 8 * w.bytes def sort (w:WordSize) : SMT.sort := SMT.sort.bitvec w.bits def fromNat : Nat → Option WordSize | 8 => some word8 | 16 => some word16 | 32 => some word32 | 64 => some word64 | _ => none end WordSize
0be2f2c4b3955b00208712d9a9478b61a767b5b7
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/type_annot_app.lean
d11a674a84f54cb7a4d35512d15b6c36a405aa07
[ "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
466
lean
def f : ℕ → ℕ := λ _, 0 theorem A (x : ℕ) : f x = 0 := rfl theorem B (x : ℕ) : (f : _) x = 0 := rfl theorem C (x : ℕ) : (f : ℕ → ℕ) x = 0 := rfl example (x) : f x = 0 := by simp [A] --ok example (x) : f x = 0 := by have := A x; rw this --ok example (x) : f x = 0 := by simp [B] --fails example (x) : f x = 0 := by have := B x; rw this --fails example (x) : f x = 0 := by simp [C] --fails example (x) : f x = 0 := by have := C x; rw this --fails
513235c5745994fec7e5659e7d92ef5b98cbec62
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/Lean3Lib/init/meta/ref_auto.lean
d1cd405b02685a06f32d110d1e76188fa6796148
[]
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
444
lean
/- Copyright (c) 2017 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.tactic namespace Mathlib namespace tactic /-- A `ref` performs the role of a mutable variable within a tactic. -/ /-- Create a new reference `r` with initial value `a`, execute `t r`, and then delete `r`. -/ end Mathlib
9818434ffa65f36587f59a201e54c982acb7b191
367134ba5a65885e863bdc4507601606690974c1
/src/ring_theory/polynomial/symmetric.lean
27ab1c3b0e6f1ac18985afcfe0767426677469e5
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
5,541
lean
/- Copyright (c) 2020 Hanting Zhang. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Hanting Zhang, Johan Commelin -/ import tactic import data.mv_polynomial.rename import data.mv_polynomial.comm_ring /-! # Symmetric Polynomials and Elementary Symmetric Polynomials This file defines symmetric `mv_polynomial`s and elementary symmetric `mv_polynomial`s. We also prove some basic facts about them. ## Main declarations * `mv_polynomial.is_symmetric` * `mv_polynomial.esymm` ## Notation + `esymm σ R n`, is the `n`th elementary symmetric polynomial in `mv_polynomial σ R`. As in other polynomial files, we typically use the notation: + `σ τ : Type*` (indexing the variables) + `R S : Type*` `[comm_semiring R]` `[comm_semiring S]` (the coefficients) + `r : R` elements of the coefficient ring + `i : σ`, with corresponding monomial `X i`, often denoted `X_i` by mathematicians + `φ ψ : mv_polynomial σ R` -/ open equiv (perm) open_locale big_operators noncomputable theory namespace mv_polynomial variables {σ : Type*} {R : Type*} variables {τ : Type*} {S : Type*} /-- A `mv_polynomial φ` is symmetric if it is invariant under permutations of its variables by the `rename` operation -/ def is_symmetric [comm_semiring R] (φ : mv_polynomial σ R) : Prop := ∀ e : perm σ, rename e φ = φ namespace is_symmetric section comm_semiring variables [comm_semiring R] [comm_semiring S] {φ ψ : mv_polynomial σ R} @[simp] lemma C (r : R) : is_symmetric (C r : mv_polynomial σ R) := λ e, rename_C e r @[simp] lemma zero : is_symmetric (0 : mv_polynomial σ R) := by { rw [← C_0], exact is_symmetric.C 0 } @[simp] lemma one : is_symmetric (1 : mv_polynomial σ R) := by { rw [← C_1], exact is_symmetric.C 1 } lemma add (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ + ψ) := λ e, by rw [alg_hom.map_add, hφ, hψ] lemma mul (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ * ψ) := λ e, by rw [alg_hom.map_mul, hφ, hψ] lemma smul (r : R) (hφ : is_symmetric φ) : is_symmetric (r • φ) := λ e, by rw [alg_hom.map_smul, hφ] @[simp] lemma map (hφ : is_symmetric φ) (f : R →+* S) : is_symmetric (map f φ) := λ e, by rw [← map_rename, hφ] end comm_semiring section comm_ring variables [comm_ring R] {φ ψ : mv_polynomial σ R} lemma neg (hφ : is_symmetric φ) : is_symmetric (-φ) := λ e, by rw [alg_hom.map_neg, hφ] lemma sub (hφ : is_symmetric φ) (hψ : is_symmetric ψ) : is_symmetric (φ - ψ) := by { rw sub_eq_add_neg, exact hφ.add hψ.neg } end comm_ring end is_symmetric section elementary_symmetric open finset variables (σ R) [comm_semiring R] [comm_semiring S] [fintype σ] [fintype τ] /-- The `n`th elementary symmetric `mv_polynomial σ R`. -/ def esymm (n : ℕ) : mv_polynomial σ R := ∑ t in powerset_len n univ, ∏ i in t, X i /-- We can define `esymm σ R n` by summing over a subtype instead of over `powerset_len`. -/ lemma esymm_eq_sum_subtype (n : ℕ) : esymm σ R n = ∑ t : {s : finset σ // s.card = n}, ∏ i in (t : finset σ), X i := begin rw esymm, let i : Π (a : finset σ), a ∈ powerset_len n univ → {s : finset σ // s.card = n} := λ a ha, ⟨_, (mem_powerset_len.mp ha).2⟩, refine sum_bij i (λ a ha, mem_univ (i a ha)) _ (λ _ _ _ _ hi, subtype.ext_iff_val.mp hi) _, { intros, apply prod_congr, simp only [subtype.coe_mk], intros, refl,}, { refine (λ b H, ⟨b.val, mem_powerset_len.mpr ⟨subset_univ b.val, b.property⟩, _⟩), simp [i] }, end /-- We can define `esymm σ R n` as a sum over explicit monomials -/ lemma esymm_eq_sum_monomial (n : ℕ) : esymm σ R n = ∑ t in powerset_len n univ, monomial (∑ i in t, finsupp.single i 1) 1 := begin refine sum_congr rfl (λ x hx, _), rw monic_monomial_eq, rw finsupp.prod_pow, rw ← prod_subset (λ y _, finset.mem_univ y : x ⊆ univ) (λ y _ hy, _), { refine prod_congr rfl (λ x' hx', _), convert (pow_one _).symm, convert (finsupp.apply_add_hom x' : (σ →₀ ℕ) →+ ℕ).map_sum _ x, classical, simp [finsupp.single_apply, finset.filter_eq', apply_ite, apply_ite finset.card], rw if_pos hx', }, { convert pow_zero _, convert (finsupp.apply_add_hom y : (σ →₀ ℕ) →+ ℕ).map_sum _ x, classical, simp [finsupp.single_apply, finset.filter_eq', apply_ite, apply_ite finset.card], rw if_neg hy, } end @[simp] lemma esymm_zero : esymm σ R 0 = 1 := by simp only [esymm, powerset_len_zero, sum_singleton, prod_empty] lemma map_esymm (n : ℕ) (f : R →+* S) : map f (esymm σ R n) = esymm σ S n := begin rw [esymm, (map f).map_sum], refine sum_congr rfl (λ x hx, _), rw (map f).map_prod, simp, end lemma rename_esymm (n : ℕ) (e : σ ≃ τ) : rename e (esymm σ R n) = esymm τ R n := begin rw [esymm_eq_sum_subtype, esymm_eq_sum_subtype, (rename ⇑e).map_sum], let e' : {s : finset σ // s.card = n} ≃ {s : finset τ // s.card = n} := equiv.subtype_equiv (equiv.finset_congr e) (by simp), rw ← equiv.sum_comp e'.symm, apply fintype.sum_congr, intro, calc _ = (∏ i in (e'.symm a : finset σ), (rename e) (X i)) : (rename e).map_prod _ _ ... = (∏ i in (a : finset τ), (rename e) (X (e.symm i))) : prod_map (a : finset τ) _ _ ... = _ : _, apply finset.prod_congr rfl, intros, simp, end lemma esymm_is_symmetric (n : ℕ) : is_symmetric (esymm σ R n) := by { intro, rw rename_esymm } end elementary_symmetric end mv_polynomial
37843d8055cc5b38fbefc7cc7cd796546745418b
367134ba5a65885e863bdc4507601606690974c1
/src/data/qpf/multivariate/constructions/sigma.lean
1b4c8963c09db0fc84b6da7d5b9054d8505152c1
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
3,045
lean
/- Copyright (c) 2018 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Simon Hudon -/ import data.pfunctor.multivariate.basic import data.qpf.multivariate.basic /-! # Dependent product and sum of QPFs are QPFs -/ universes u namespace mvqpf open_locale mvfunctor variables {n : ℕ} {A : Type u} variables (F : A → typevec.{u} n → Type u) /-- Dependent sum of of an `n`-ary functor. The sum can range over data types like `ℕ` or over `Type.{u-1}` -/ def sigma (v : typevec.{u} n) : Type.{u} := Σ α : A, F α v /-- Dependent product of of an `n`-ary functor. The sum can range over data types like `ℕ` or over `Type.{u-1}` -/ def pi (v : typevec.{u} n) : Type.{u} := Π α : A, F α v instance sigma.inhabited {α} [inhabited A] [inhabited (F (default A) α)] : inhabited (sigma F α) := ⟨ ⟨default A, default _⟩ ⟩ instance pi.inhabited {α} [Π a, inhabited (F a α)] : inhabited (pi F α) := ⟨ λ a, default _ ⟩ variables [Π α, mvfunctor $ F α] namespace sigma instance : mvfunctor (sigma F) := { map := λ α β f ⟨a,x⟩, ⟨a,f <$$> x⟩ } variables [Π α, mvqpf $ F α] /-- polynomial functor representation of a dependent sum -/ protected def P : mvpfunctor n := ⟨ Σ a, (P (F a)).A, λ x, (P (F x.1)).B x.2 ⟩ /-- abstraction function for dependent sums -/ protected def abs ⦃α⦄ : (sigma.P F).obj α → sigma F α | ⟨a,f⟩ := ⟨ a.1, mvqpf.abs ⟨a.2, f⟩ ⟩ /-- representation function for dependent sums -/ protected def repr ⦃α⦄ : sigma F α → (sigma.P F).obj α | ⟨a,f⟩ := let x := mvqpf.repr f in ⟨ ⟨a,x.1⟩, x.2 ⟩ instance : mvqpf (sigma F) := { P := sigma.P F, abs := sigma.abs F, repr := sigma.repr F, abs_repr := by rintros α ⟨x,f⟩; simp [sigma.repr,sigma.abs,abs_repr], abs_map := by rintros α β f ⟨x,g⟩; simp [sigma.abs,mvpfunctor.map_eq]; simp [(<$$>),mvfunctor._match_1,← abs_map,← mvpfunctor.map_eq] } end sigma namespace pi instance : mvfunctor (pi F) := { map := λ α β f x a, f <$$> x a } variables [Π α, mvqpf $ F α] /-- polynomial functor representation of a dependent product -/ protected def P : mvpfunctor n := ⟨ Π a, (P (F a)).A, λ x i, Σ a : A, (P (F a)).B (x a) i ⟩ /-- abstraction function for dependent products -/ protected def abs ⦃α⦄ : (pi.P F).obj α → pi F α | ⟨a,f⟩ := λ x, mvqpf.abs ⟨a x, λ i y, f i ⟨_,y⟩⟩ /-- representation function for dependent products -/ protected def repr ⦃α⦄ : pi F α → (pi.P F).obj α | f := ⟨ λ a, (mvqpf.repr (f a)).1, λ i a, (@mvqpf.repr _ _ _ (_inst_2 _) _ (f _)).2 _ a.2 ⟩ instance : mvqpf (pi F) := { P := pi.P F, abs := pi.abs F, repr := pi.repr F, abs_repr := by rintros α f; ext; simp [pi.repr,pi.abs,abs_repr], abs_map := by rintros α β f ⟨x,g⟩; simp only [pi.abs, mvpfunctor.map_eq]; ext; simp only [(<$$>)]; simp only [←abs_map, mvpfunctor.map_eq]; refl } end pi end mvqpf
e3589b985f9601fdc89dd1b7cda2775e950e8470
bce603343785d07c32cb8b35950aba0b4d9415ae
/lean3/src/relations.lean
e609ee2e07f9f3d120e41be42bd5a2ecde8808f8
[]
no_license
fpvandoorn/cryptomorphism
db00cf0b12c8fd561a6200eee6a6ff2a023f1228
d486419ecced54de3db759dae81110be44b7c28b
refs/heads/master
1,693,198,883,854
1,636,562,038,000
1,636,562,038,000
363,219,330
0
0
null
null
null
null
UTF-8
Lean
false
false
5,065
lean
import tactic import tactic.slim_check mk_simp_attribute props "" variables {α : Type*} @[props] def is_reflexive (r : α → α → Prop) : Prop := ∀ a, r a a @[props] def is_irreflexive (r : α → α → Prop) : Prop := ∀ a, ¬ r a a @[props] def is_symmetric (r : α → α → Prop) : Prop := ∀ a b, r a b → r b a @[props] def is_transitive (r : α → α → Prop) : Prop := ∀ a b c, r a b → r b c → r a c @[props] def is_asymmetric (r : α → α → Prop) : Prop := ∀ a b, r a b → ¬ r b a @[props] def is_total' (r : α → α → Prop) : Prop := ∀ a b, r a b ∨ r b a @[props] def is_antisymmetric (r : α → α → Prop) : Prop := ∀ a b, r a b → r b a → a = b @[props] def is_partial_equivalence (r : α → α → Prop) : Prop := is_symmetric r ∧ is_transitive r @[props] def is_trichotomous' (r : α → α → Prop) : Prop := ∀ a b, r a b ∨ a = b ∨ r b a @[props] def is_preorder' (r : α → α → Prop) : Prop := is_reflexive r ∧ is_transitive r @[props] def is_total_preorder' (r : α → α → Prop) : Prop := is_transitive r ∧ is_total' r @[props] def is_partial_order' (r : α → α → Prop) : Prop := is_preorder' r ∧ is_antisymmetric r @[props] def is_linear_order' (r : α → α → Prop) : Prop := is_partial_order' r ∧ is_total' r @[props] def is_equivalence (r : α → α → Prop) : Prop := is_preorder' r ∧ is_symmetric r @[props] def is_strict_order' (r : α → α → Prop) : Prop := is_irreflexive r ∧ is_transitive r -- def is_strict_weak_order' (r : α → α → Prop) : Prop := is_strict_order' r ∧ is_incomp_trans' r -- def is_strict_total_order' (r : α → α → Prop) : Prop := is_trichotomous' r ∧ is_strict_weak_order' r open tactic expr sum meta def props : list (name × string) := [(`is_reflexive, "reflexive"), (`is_irreflexive, "irreflexive"), (`is_symmetric, "symmetric"), (`is_transitive, "transitive"), (`is_asymmetric, "asymmetric"), (`is_total', "total"), (`is_antisymmetric, "antisymmetric"), (`is_trichotomous', "trichotomous")] meta def omega_that_fails_on_false : tactic unit := done <|> all_goals' (target >>= λ tgt, guard (tgt.const_name ≠ `false) >> interactive.omega []) meta def try_slim_check (cfg : slim_check.slim_check_cfg) : tactic (option string) := do result ← try_or_report_error (interactive.slim_check {quiet := tt, ..cfg}), inr n ← return result | return none, when (n.starts_with "Failed to create a") failed, return (some n) meta def finds_slim_check_example (cfg : slim_check.slim_check_cfg := {}) : tactic unit := do n ← try_slim_check cfg, guard n.is_some meta def test_init : tactic unit := do t ← target, let ⟨f, args⟩ := t.get_app_fn_args, let prop_name := f.const_name, let rel_name := args.ilast.const_name, dsimp_target none [prop_name, rel_name] {fail_if_unchanged := ff} meta def test_init_main (t : expr) (R : name) : tactic expr := do t.dsimp {} ff [`props] [simp_arg_type.expr $ expr.const R []] meta def test_main (t : expr) (cfg : slim_check.slim_check_cfg := {}) : tactic (ℕ ⊕ string) := do -- trace t, let not_t := const `not [] t, retrieve (tactic.assert `this t >> focus1 (tidy >> omega_that_fails_on_false >> done) >> return (inl 0)) <|> retrieve (tactic.assert `this not_t >> focus1 (tidy >> omega_that_fails_on_false >> done) >> return (inl 1)) <|> retrieve (do tactic.assert `this t, some error ← focus1 (try_slim_check cfg), return (inr error)) <|> return (inl 2) meta def test_core (cfg : slim_check.slim_check_cfg := {}) : tactic (ℕ ⊕ string) := do test_init, t ← target, r ← test_main t cfg, when (r = inl 0) (get_local `this >>= exact), return r meta def test (cfg : slim_check.slim_check_cfg := {}) : tactic unit := do result ← test_core cfg, when (result = inl 0) (trace "succeeded!"), when (result = inl 1) (trace "proved the negation!"), when (result.is_right) (trace "found a counterexample!" >> trace result.get_right.iget), when (result = inl 2) (trace "couldn't make progress."), skip meta def test_all (R : name) (cfg : slim_check.slim_check_cfg := {}) : tactic unit := props.mmap' $ λ ⟨prop_nm, prop_str⟩, retrieve $ do { -- let t : expr := (const rel [level.zero]) (const `nat []) (const R []), rel ← mk_const R, prop ← mk_const prop_nm, t ← to_expr ``(%%prop %%rel), t ← test_init_main t R, result ← test_main t cfg, -- trace result, when (result = inl 0) (trace!"{R} is {prop_str}!"), when (result = inl 1) (trace!"{R} is not {prop_str}!"), when (result.is_right) (trace!"{R} is not {prop_str}!"), when (result = inl 2) (trace!"Cannot resolve whether {R} is {prop_str}.") } @[user_attribute] meta def test_attr : user_attribute := { name := `test, descr := "Automatically tests whether a relation `ℕ → ℕ → Prop` satisfies some properties.", after_set := some $ λ R _ _, do test_all R } -- def dummy : false ↔ 0 = 1 := by simp @[test] def R (n m : ℕ) : Prop := n < m ∨ n > 10 example : is_transitive R := by { test, sorry }
a8f88930d54ca2988e689593811cd6d68936ee34
f1b175e38ffc5cc1c7c5551a72d0dbaf70786f83
/data/set/lattice.lean
b05c20cb0bb609273b8465a6737febda12dbae12
[ "Apache-2.0" ]
permissive
mjendrusch/mathlib
df3ae884dd5ce38c7edf452bcbfd3baf4e3a6214
5c209edb7eb616a26f64efe3500f2b1ba95b8d55
refs/heads/master
1,585,663,284,800
1,539,062,055,000
1,539,062,055,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
26,530
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, Johannes Hölzl, Mario Carneiro -- QUESTION: can make the first argument in ∀ x ∈ a, ... implicit? -/ import logic.basic data.set.basic data.equiv.basic tactic import order.complete_boolean_algebra category.basic import tactic.finish data.sigma.basic order.galois_connection open function tactic set lattice auto universes u v w x variables {α : Type u} {β : Type v} {γ : Type w} {ι : Sort x} namespace set instance lattice_set : complete_lattice (set α) := { lattice.complete_lattice . le := (⊆), le_refl := subset.refl, le_trans := assume a b c, subset.trans, le_antisymm := assume a b, subset.antisymm, lt := λ x y, x ⊆ y ∧ ¬ y ⊆ x, lt_iff_le_not_le := λ x y, iff.refl _, sup := (∪), le_sup_left := subset_union_left, le_sup_right := subset_union_right, sup_le := assume a b c, union_subset, inf := (∩), inf_le_left := inter_subset_left, inf_le_right := inter_subset_right, le_inf := assume a b c, subset_inter, top := {a | true }, le_top := assume s a h, trivial, bot := ∅, bot_le := assume s a, false.elim, Sup := λs, {a | ∃ t ∈ s, a ∈ t }, le_Sup := assume s t t_in a a_in, ⟨t, ⟨t_in, a_in⟩⟩, Sup_le := assume s t h a ⟨t', ⟨t'_in, a_in⟩⟩, h t' t'_in a_in, Inf := λs, {a | ∀ t ∈ s, a ∈ t }, le_Inf := assume s t h a a_in t' t'_in, h t' t'_in a_in, Inf_le := assume s t t_in a h, h _ t_in } instance : distrib_lattice (set α) := { le_sup_inf := λ s t u x, or_and_distrib_left.2, ..set.lattice_set } lemma monotone_image {f : α → β} : monotone (image f) := assume s t, assume h : s ⊆ t, image_subset _ h section galois_connection variables {f : α → β} protected lemma image_preimage : galois_connection (image f) (preimage f) := assume a b, image_subset_iff def kern_image (f : α → β) (s : set α) : set β := {y | ∀x, f x = y → x ∈ s} protected lemma preimage_kern_image : galois_connection (preimage f) (kern_image f) := assume a b, ⟨ assume h x hx y hy, have f y ∈ a, from hy.symm ▸ hx, h this, assume h x (hx : f x ∈ a), h hx x rfl⟩ end galois_connection /- union and intersection over a family of sets indexed by a type -/ /-- Indexed union of a family of sets -/ @[reducible] def Union (s : ι → set β) : set β := supr s /-- Indexed intersection of a family of sets -/ @[reducible] def Inter (s : ι → set β) : set β := infi s notation `⋃` binders `, ` r:(scoped f, Union f) := r notation `⋂` binders `, ` r:(scoped f, Inter f) := r @[simp] theorem mem_Union {x : β} {s : ι → set β} : x ∈ Union s ↔ ∃ i, x ∈ s i := ⟨assume ⟨t, ⟨⟨a, (t_eq : t = s a)⟩, (h : x ∈ t)⟩⟩, ⟨a, t_eq ▸ h⟩, assume ⟨a, h⟩, ⟨s a, ⟨⟨a, rfl⟩, h⟩⟩⟩ /- alternative proof: dsimp [Union, supr, Sup]; simp -/ -- TODO: more rewrite rules wrt forall / existentials and logical connectives -- TODO: also eliminate ∃i, ... ∧ i = t ∧ ... @[simp] theorem mem_Inter {x : β} {s : ι → set β} : x ∈ Inter s ↔ ∀ i, x ∈ s i := ⟨assume (h : ∀a ∈ {a : set β | ∃i, a = s i}, x ∈ a) a, h (s a) ⟨a, rfl⟩, assume h t ⟨a, (eq : t = s a)⟩, eq.symm ▸ h a⟩ theorem Union_subset {s : ι → set β} {t : set β} (h : ∀ i, s i ⊆ t) : (⋃ i, s i) ⊆ t := -- TODO: should be simpler when sets' order is based on lattices @supr_le (set β) _ set.lattice_set _ _ h theorem Union_subset_iff {α : Sort u} {s : α → set β} {t : set β} : (⋃ i, s i) ⊆ t ↔ (∀ i, s i ⊆ t):= ⟨assume h i, subset.trans (le_supr s _) h, Union_subset⟩ theorem mem_Inter_of_mem {α : Sort u} {x : β} {s : α → set β} : (∀ i, x ∈ s i) → (x ∈ ⋂ i, s i) := assume h t ⟨a, (eq : t = s a)⟩, eq.symm ▸ h a theorem subset_Inter {t : set β} {s : α → set β} (h : ∀ i, t ⊆ s i) : t ⊆ ⋂ i, s i := -- TODO: should be simpler when sets' order is based on lattices @le_infi (set β) _ set.lattice_set _ _ h theorem subset_Union : ∀ (s : ι → set β) (i : ι), s i ⊆ (⋃ i, s i) := le_supr theorem Inter_subset : ∀ (s : ι → set β) (i : ι), (⋂ i, s i) ⊆ s i := infi_le theorem Union_const [inhabited ι] (s : set β) : (⋃ i:ι, s) = s := ext $ by simp theorem Inter_const [inhabited ι] (s : set β) : (⋂ i:ι, s) = s := ext $ by simp @[simp] -- complete_boolean_algebra theorem compl_Union (s : ι → set β) : - (⋃ i, s i) = (⋂ i, - s i) := ext (by simp) -- classical -- complete_boolean_algebra theorem compl_Inter (s : ι → set β) : -(⋂ i, s i) = (⋃ i, - s i) := ext (λ x, by simp [classical.not_forall]) -- classical -- complete_boolean_algebra theorem Union_eq_comp_Inter_comp (s : ι → set β) : (⋃ i, s i) = - (⋂ i, - s i) := by simp [compl_Inter, compl_compl] -- classical -- complete_boolean_algebra theorem Inter_eq_comp_Union_comp (s : ι → set β) : (⋂ i, s i) = - (⋃ i, -s i) := by simp [compl_compl] theorem inter_Union_left (s : set β) (t : ι → set β) : s ∩ (⋃ i, t i) = ⋃ i, s ∩ t i := ext $ by simp theorem inter_Union_right (s : set β) (t : ι → set β) : (⋃ i, t i) ∩ s = ⋃ i, t i ∩ s := ext $ by simp theorem Union_union_distrib (s : ι → set β) (t : ι → set β) : (⋃ i, s i ∪ t i) = (⋃ i, s i) ∪ (⋃ i, t i) := ext $ by simp [exists_or_distrib] theorem Inter_inter_distrib (s : ι → set β) (t : ι → set β) : (⋂ i, s i ∩ t i) = (⋂ i, s i) ∩ (⋂ i, t i) := ext $ by simp [forall_and_distrib] theorem union_Union_left [inhabited ι] (s : set β) (t : ι → set β) : s ∪ (⋃ i, t i) = ⋃ i, s ∪ t i := by rw [Union_union_distrib, Union_const] theorem union_Union_right [inhabited ι] (s : set β) (t : ι → set β) : (⋃ i, t i) ∪ s = ⋃ i, t i ∪ s := by rw [Union_union_distrib, Union_const] theorem inter_Inter_left [inhabited ι] (s : set β) (t : ι → set β) : s ∩ (⋂ i, t i) = ⋂ i, s ∩ t i := by rw [Inter_inter_distrib, Inter_const] theorem inter_Inter_right [inhabited ι] (s : set β) (t : ι → set β) : (⋂ i, t i) ∩ s = ⋂ i, t i ∩ s := by rw [Inter_inter_distrib, Inter_const] -- classical theorem union_Inter_left (s : set β) (t : ι → set β) : s ∪ (⋂ i, t i) = ⋂ i, s ∪ t i := ext $ assume x, by simp [classical.forall_or_distrib_left] theorem diff_Union_right (s : set β) (t : ι → set β) : (⋃ i, t i) \ s = ⋃ i, t i \ s := inter_Union_right _ _ theorem diff_Union_left [inhabited ι] (s : set β) (t : ι → set β) : s \ (⋃ i, t i) = ⋂ i, s \ t i := by rw [diff_eq, compl_Union, inter_Inter_left]; refl theorem diff_Inter_left (s : set β) (t : ι → set β) : s \ (⋂ i, t i) = ⋃ i, s \ t i := by rw [diff_eq, compl_Inter, inter_Union_left]; refl /- bounded unions and intersections -/ theorem mem_bUnion_iff {s : set α} {t : α → set β} {y : β} : y ∈ (⋃ x ∈ s, t x) ↔ ∃ x, x ∈ s ∧ y ∈ t x := by simp theorem mem_bInter_iff {s : set α} {t : α → set β} {y : β} : y ∈ (⋂ x ∈ s, t x) ↔ ∀ x ∈ s, y ∈ t x := by simp theorem mem_bUnion {s : set α} {t : α → set β} {x : α} {y : β} (xs : x ∈ s) (ytx : y ∈ t x) : y ∈ ⋃ x ∈ s, t x := by simp; exact ⟨x, ⟨xs, ytx⟩⟩ theorem mem_bInter {s : set α} {t : α → set β} {y : β} (h : ∀ x ∈ s, y ∈ t x) : y ∈ ⋂ x ∈ s, t x := by simp; assumption theorem bUnion_subset {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, u x ⊆ t) : (⋃ x ∈ s, u x) ⊆ t := show (⨆ x ∈ s, u x) ≤ t, -- TODO: should not be necessary when sets' order is based on lattices from supr_le $ assume x, supr_le (h x) theorem subset_bInter {s : set α} {t : set β} {u : α → set β} (h : ∀ x ∈ s, t ⊆ u x) : t ⊆ (⋂ x ∈ s, u x) := show t ≤ (⨅ x ∈ s, u x), -- TODO: should not be necessary when sets' order is based on lattices from le_infi $ assume x, le_infi (h x) theorem subset_bUnion_of_mem {s : set α} {u : α → set β} {x : α} (xs : x ∈ s) : u x ⊆ (⋃ x ∈ s, u x) := show u x ≤ (⨆ x ∈ s, u x), from le_supr_of_le x $ le_supr _ xs theorem bInter_subset_of_mem {s : set α} {t : α → set β} {x : α} (xs : x ∈ s) : (⋂ x ∈ s, t x) ⊆ t x := show (⨅x ∈ s, t x) ≤ t x, from infi_le_of_le x $ infi_le _ xs theorem bUnion_subset_bUnion_left {s s' : set α} {t : α → set β} (h : s ⊆ s') : (⋃ x ∈ s, t x) ⊆ (⋃ x ∈ s', t x) := bUnion_subset (λ x xs, subset_bUnion_of_mem (h xs)) theorem bInter_subset_bInter_left {s s' : set α} {t : α → set β} (h : s' ⊆ s) : (⋂ x ∈ s, t x) ⊆ (⋂ x ∈ s', t x) := subset_bInter (λ x xs, bInter_subset_of_mem (h xs)) theorem bUnion_subset_bUnion_right {s : set α} {t1 t2 : α → set β} (h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋃ x ∈ s, t1 x) ⊆ (⋃ x ∈ s, t2 x) := bUnion_subset (λ x xs, subset.trans (h x xs) (subset_bUnion_of_mem xs)) theorem bInter_subset_bInter_right {s : set α} {t1 t2 : α → set β} (h : ∀ x ∈ s, t1 x ⊆ t2 x) : (⋂ x ∈ s, t1 x) ⊆ (⋂ x ∈ s, t2 x) := subset_bInter (λ x xs, subset.trans (bInter_subset_of_mem xs) (h x xs)) theorem bUnion_eq_Union (s : set α) (t : α → set β) : (⋃ x ∈ s, t x) = (⋃ x : s, t x.1) := set.ext $ by simp theorem bInter_eq_Inter (s : set α) (t : α → set β) : (⋂ x ∈ s, t x) = (⋂ x : s, t x.1) := set.ext $ by simp @[simp] theorem bInter_empty (u : α → set β) : (⋂ x ∈ (∅ : set α), u x) = univ := show (⨅x ∈ (∅ : set α), u x) = ⊤, -- simplifier should be able to rewrite x ∈ ∅ to false. from infi_emptyset @[simp] theorem bInter_univ (u : α → set β) : (⋂ x ∈ @univ α, u x) = ⋂ x, u x := infi_univ -- TODO(Jeremy): here is an artifact of the the encoding of bounded intersection: -- without dsimp, the next theorem fails to type check, because there is a lambda -- in a type that needs to be contracted. Using simp [eq_of_mem_singleton xa] also works. @[simp] theorem bInter_singleton (a : α) (s : α → set β) : (⋂ x ∈ ({a} : set α), s x) = s a := show (⨅ x ∈ ({a} : set α), s x) = s a, by simp theorem bInter_union (s t : set α) (u : α → set β) : (⋂ x ∈ s ∪ t, u x) = (⋂ x ∈ s, u x) ∩ (⋂ x ∈ t, u x) := show (⨅ x ∈ s ∪ t, u x) = (⨅ x ∈ s, u x) ⊓ (⨅ x ∈ t, u x), from infi_union -- TODO(Jeremy): simp [insert_eq, bInter_union] doesn't work @[simp] theorem bInter_insert (a : α) (s : set α) (t : α → set β) : (⋂ x ∈ insert a s, t x) = t a ∩ (⋂ x ∈ s, t x) := begin rw insert_eq, simp [bInter_union] end -- TODO(Jeremy): another example of where an annotation is needed theorem bInter_pair (a b : α) (s : α → set β) : (⋂ x ∈ ({a, b} : set α), s x) = s a ∩ s b := by rw insert_of_has_insert; simp [inter_comm] @[simp] theorem bUnion_empty (s : α → set β) : (⋃ x ∈ (∅ : set α), s x) = ∅ := supr_emptyset @[simp] theorem bUnion_univ (s : α → set β) : (⋃ x ∈ @univ α, s x) = ⋃ x, s x := supr_univ @[simp] theorem bUnion_singleton (a : α) (s : α → set β) : (⋃ x ∈ ({a} : set α), s x) = s a := supr_singleton theorem bUnion_union (s t : set α) (u : α → set β) : (⋃ x ∈ s ∪ t, u x) = (⋃ x ∈ s, u x) ∪ (⋃ x ∈ t, u x) := supr_union -- TODO(Jeremy): once again, simp doesn't do it alone. @[simp] theorem bUnion_insert (a : α) (s : set α) (t : α → set β) : (⋃ x ∈ insert a s, t x) = t a ∪ (⋃ x ∈ s, t x) := begin rw [insert_eq], simp [bUnion_union] end theorem bUnion_pair (a b : α) (s : α → set β) : (⋃ x ∈ ({a, b} : set α), s x) = s a ∪ s b := by rw insert_of_has_insert; simp [union_comm] @[simp] -- complete_boolean_algebra theorem compl_bUnion (s : set α) (t : α → set β) : - (⋃ i ∈ s, t i) = (⋂ i ∈ s, - t i) := ext (λ x, by simp) -- classical -- complete_boolean_algebra theorem compl_bInter (s : set α) (t : α → set β) : -(⋂ i ∈ s, t i) = (⋃ i ∈ s, - t i) := ext (λ x, by simp [classical.not_forall]) /-- Intersection of a set of sets. -/ @[reducible] def sInter (S : set (set α)) : set α := Inf S prefix `⋂₀`:110 := sInter theorem mem_sUnion_of_mem {x : α} {t : set α} {S : set (set α)} (hx : x ∈ t) (ht : t ∈ S) : x ∈ ⋃₀ S := ⟨t, ⟨ht, hx⟩⟩ @[simp] theorem mem_sUnion {x : α} {S : set (set α)} : x ∈ ⋃₀ S ↔ ∃t ∈ S, x ∈ t := iff.rfl -- is this theorem really necessary? theorem not_mem_of_not_mem_sUnion {x : α} {t : set α} {S : set (set α)} (hx : x ∉ ⋃₀ S) (ht : t ∈ S) : x ∉ t := λ h, hx ⟨t, ht, h⟩ @[simp] theorem mem_sInter {x : α} {S : set (set α)} : x ∈ ⋂₀ S ↔ ∀ t ∈ S, x ∈ t := iff.rfl theorem sInter_subset_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : ⋂₀ S ⊆ t := Inf_le tS theorem subset_sUnion_of_mem {S : set (set α)} {t : set α} (tS : t ∈ S) : t ⊆ ⋃₀ S := le_Sup tS theorem sUnion_subset {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t' ⊆ t) : (⋃₀ S) ⊆ t := Sup_le h theorem sUnion_subset_iff {s : set (set α)} {t : set α} : ⋃₀ s ⊆ t ↔ ∀t' ∈ s, t' ⊆ t := ⟨assume h t' ht', subset.trans (subset_sUnion_of_mem ht') h, sUnion_subset⟩ theorem subset_sInter {S : set (set α)} {t : set α} (h : ∀t' ∈ S, t ⊆ t') : t ⊆ (⋂₀ S) := le_Inf h theorem sUnion_subset_sUnion {S T : set (set α)} (h : S ⊆ T) : ⋃₀ S ⊆ ⋃₀ T := sUnion_subset $ λ s hs, subset_sUnion_of_mem (h hs) theorem sInter_subset_sInter {S T : set (set α)} (h : S ⊆ T) : ⋂₀ T ⊆ ⋂₀ S := subset_sInter $ λ s hs, sInter_subset_of_mem (h hs) @[simp] theorem sUnion_empty : ⋃₀ ∅ = (∅ : set α) := Sup_empty @[simp] theorem sInter_empty : ⋂₀ ∅ = (univ : set α) := Inf_empty @[simp] theorem sUnion_singleton (s : set α) : ⋃₀ {s} = s := Sup_singleton @[simp] theorem sInter_singleton (s : set α) : ⋂₀ {s} = s := Inf_singleton theorem sUnion_union (S T : set (set α)) : ⋃₀ (S ∪ T) = ⋃₀ S ∪ ⋃₀ T := Sup_union theorem sInter_union (S T : set (set α)) : ⋂₀ (S ∪ T) = ⋂₀ S ∩ ⋂₀ T := Inf_union @[simp] theorem sUnion_insert (s : set α) (T : set (set α)) : ⋃₀ (insert s T) = s ∪ ⋃₀ T := Sup_insert @[simp] theorem sInter_insert (s : set α) (T : set (set α)) : ⋂₀ (insert s T) = s ∩ ⋂₀ T := Inf_insert theorem sUnion_pair (s t : set α) : ⋃₀ {s, t} = s ∪ t := (sUnion_insert _ _).trans $ by rw [union_comm, sUnion_singleton] theorem sInter_pair (s t : set α) : ⋂₀ {s, t} = s ∩ t := (sInter_insert _ _).trans $ by rw [inter_comm, sInter_singleton] @[simp] theorem sUnion_image (f : α → set β) (s : set α) : ⋃₀ (f '' s) = ⋃ x ∈ s, f x := Sup_image @[simp] theorem sInter_image (f : α → set β) (s : set α) : ⋂₀ (f '' s) = ⋂ x ∈ s, f x := Inf_image theorem compl_sUnion (S : set (set α)) : - ⋃₀ S = ⋂₀ (compl '' S) := set.ext $ assume x, ⟨assume : ¬ (∃s∈S, x ∈ s), assume s h, match s, h with ._, ⟨t, hs, rfl⟩ := assume h, this ⟨t, hs, h⟩ end, assume : ∀s, s ∈ compl '' S → x ∈ s, assume ⟨t, tS, xt⟩, this (compl t) (mem_image_of_mem _ tS) xt⟩ -- classical theorem sUnion_eq_compl_sInter_compl (S : set (set α)) : ⋃₀ S = - ⋂₀ (compl '' S) := by rw [←compl_compl (⋃₀ S), compl_sUnion] -- classical theorem compl_sInter (S : set (set α)) : - ⋂₀ S = ⋃₀ (compl '' S) := by rw [sUnion_eq_compl_sInter_compl, compl_compl_image] -- classical theorem sInter_eq_comp_sUnion_compl (S : set (set α)) : ⋂₀ S = -(⋃₀ (compl '' S)) := by rw [←compl_compl (⋂₀ S), compl_sInter] theorem inter_empty_of_inter_sUnion_empty {s t : set α} {S : set (set α)} (hs : t ∈ S) (h : s ∩ ⋃₀ S = ∅) : s ∩ t = ∅ := eq_empty_of_subset_empty $ by rw ← h; exact inter_subset_inter_right _ (subset_sUnion_of_mem hs) theorem Union_eq_sUnion_range (s : α → set β) : (⋃ i, s i) = ⋃₀ (range s) := by rw [← image_univ, sUnion_image]; simp theorem Inter_eq_sInter_range {α I : Type} (s : I → set α) : (⋂ i, s i) = ⋂₀ (range s) := by rw [← image_univ, sInter_image]; simp theorem range_sigma_eq_Union_range {γ : α → Type*} (f : sigma γ → β) : range f = ⋃ a, range (λ b, f ⟨a, b⟩) := set.ext $ by simp theorem Union_eq_range_sigma (s : α → set β) : (⋃ i, s i) = range (λ a : Σ i, s i, a.2) := by simp [set.ext_iff] lemma sUnion_mono {s t : set (set α)} (h : s ⊆ t) : (⋃₀ s) ⊆ (⋃₀ t) := sUnion_subset $ assume t' ht', subset_sUnion_of_mem $ h ht' lemma Union_subset_Union {s t : ι → set α} (h : ∀i, s i ⊆ t i) : (⋃i, s i) ⊆ (⋃i, t i) := @supr_le_supr (set α) ι _ s t h lemma Union_subset_Union2 {ι₂ : Sort*} {s : ι → set α} {t : ι₂ → set α} (h : ∀i, ∃j, s i ⊆ t j) : (⋃i, s i) ⊆ (⋃i, t i) := @supr_le_supr2 (set α) ι ι₂ _ s t h lemma Union_subset_Union_const {ι₂ : Sort x} {s : set α} (h : ι → ι₂) : (⋃ i:ι, s) ⊆ (⋃ j:ι₂, s) := @supr_le_supr_const (set α) ι ι₂ _ s h lemma sUnion_eq_bUnion {s : set (set α)} : (⋃₀ s) = (⋃ (i : set α) (h : i ∈ s), i) := set.ext $ by simp lemma sInter_eq_bInter {s : set (set α)} : (⋂₀ s) = (⋂ (i : set α) (h : i ∈ s), i) := set.ext $ by simp lemma sUnion_eq_Union {s : set (set α)} : (⋃₀ s) = (⋃ (i : s), i.1) := set.ext $ λ x, by simp lemma sInter_eq_Inter {s : set (set α)} : (⋂₀ s) = (⋂ (i : s), i.1) := set.ext $ λ x, by simp lemma union_eq_Union {s₁ s₂ : set α} : s₁ ∪ s₂ = ⋃ b : bool, cond b s₁ s₂ := set.ext $ λ x, by simp [bool.exists_bool, or_comm] lemma inter_eq_Inter {s₁ s₂ : set α} : s₁ ∩ s₂ = ⋂ b : bool, cond b s₁ s₂ := set.ext $ λ x, by simp [bool.forall_bool, and_comm] instance : complete_boolean_algebra (set α) := { neg := compl, sub := (\), inf_neg_eq_bot := assume s, ext $ assume x, ⟨assume ⟨h, nh⟩, nh h, false.elim⟩, sup_neg_eq_top := assume s, ext $ assume x, ⟨assume h, trivial, assume _, classical.em $ x ∈ s⟩, le_sup_inf := distrib_lattice.le_sup_inf, sub_eq := assume x y, rfl, infi_sup_le_sup_Inf := assume s t x, show x ∈ (⋂ b ∈ t, s ∪ b) → x ∈ s ∪ (⋂₀ t), by simp; exact assume h, or.imp_right (assume hn : x ∉ s, assume i hi, or.resolve_left (h i hi) hn) (classical.em $ x ∈ s), inf_Sup_le_supr_inf := assume s t x, show x ∈ s ∩ (⋃₀ t) → x ∈ (⋃ b ∈ t, s ∩ b), by simp [-and_imp, and.left_comm], ..set.lattice_set } @[simp] theorem sub_eq_diff (s t : set α) : s - t = s \ t := rfl section variables {p : Prop} {μ : p → set α} @[simp] lemma Inter_pos (hp : p) : (⋂h:p, μ h) = μ hp := infi_pos hp @[simp] lemma Inter_neg (hp : ¬ p) : (⋂h:p, μ h) = univ := infi_neg hp @[simp] lemma Union_pos (hp : p) : (⋃h:p, μ h) = μ hp := supr_pos hp @[simp] lemma Union_neg (hp : ¬ p) : (⋃h:p, μ h) = ∅ := supr_neg hp @[simp] lemma Union_empty {ι : Sort*} : (⋃i:ι, ∅:set α) = ∅ := supr_bot @[simp] lemma Inter_univ {ι : Sort*} : (⋂i:ι, univ:set α) = univ := infi_top end section image lemma image_Union {f : α → β} {s : ι → set α} : f '' (⋃ i, s i) = (⋃i, f '' s i) := begin apply set.ext, intro x, simp [image, exists_and_distrib_right.symm, -exists_and_distrib_right], exact exists_swap end lemma univ_subtype {p : α → Prop} : (univ : set (subtype p)) = (⋃x (h : p x), {⟨x, h⟩}) := set.ext $ assume ⟨x, h⟩, by simp [h] end image section preimage theorem monotone_preimage {f : α → β} : monotone (preimage f) := assume a b h, preimage_mono h @[simp] theorem preimage_Union {ι : Sort w} {f : α → β} {s : ι → set β} : preimage f (⋃i, s i) = (⋃i, preimage f (s i)) := set.ext $ by simp [preimage] @[simp] theorem preimage_sUnion {f : α → β} {s : set (set β)} : preimage f (⋃₀ s) = (⋃t ∈ s, preimage f t) := set.ext $ by simp [preimage] end preimage section seq def seq (s : set (α → β)) (t : set α) : set β := {b | ∃f∈s, ∃a∈t, (f : α → β) a = b} lemma seq_def {s : set (α → β)} {t : set α} : seq s t = ⋃f∈s, f '' t := set.ext $ by simp [seq] lemma mem_seq_iff {s : set (α → β)} {t : set α} {b : β} : b ∈ seq s t ↔ (∃f ∈ s, ∃a∈t, (f : α → β) a = b) := iff.refl _ lemma seq_subset {s : set (α → β)} {t : set α} {u : set β} : seq s t ⊆ u ↔ (∀f∈s, ∀a∈t, (f : α → β) a ∈ u) := iff.intro (assume h f hf a ha, h ⟨f, hf, a, ha, rfl⟩) (assume h b ⟨f, hf, a, ha, eq⟩, eq ▸ h f hf a ha) lemma seq_mono {s₀ s₁ : set (α → β)} {t₀ t₁ : set α} (hs : s₀ ⊆ s₁) (ht : t₀ ⊆ t₁) : seq s₀ t₀ ⊆ seq s₁ t₁ := assume b ⟨f, hf, a, ha, eq⟩, ⟨f, hs hf, a, ht ha, eq⟩ lemma singleton_seq {f : α → β} {t : set α} : set.seq {f} t = f '' t := set.ext $ by simp [seq] lemma seq_singleton {s : set (α → β)} {a : α} : set.seq s {a} = (λf:α→β, f a) '' s := set.ext $ by simp [seq] lemma seq_seq {s : set (β → γ)} {t : set (α → β)} {u : set α} : seq s (seq t u) = seq (seq ((∘) '' s) t) u := begin refine (set.ext $ assume c, iff.intro _ _), { rintros ⟨f, hfs, b, ⟨g, hg, a, hau, rfl⟩, rfl⟩, exact ⟨f ∘ g, ⟨(∘) f, mem_image_of_mem _ hfs, g, hg, rfl⟩, a, hau, rfl⟩ }, { rintros ⟨fg, ⟨fc, ⟨f, hfs, rfl⟩, g, hgt, rfl⟩, a, ha, rfl⟩, exact ⟨f, hfs, g a, ⟨g, hgt, a, ha, rfl⟩ , rfl⟩ } end lemma image_seq {f : β → γ} {s : set (α → β)} {t : set α} : f '' seq s t = seq ((∘) f '' s) t := by rw [← singleton_seq, ← singleton_seq, seq_seq, image_singleton] lemma prod_eq_seq {s : set α} {t : set β} : set.prod s t = (prod.mk '' s).seq t := begin ext ⟨a, b⟩, split, { rintros ⟨ha, hb⟩, exact ⟨prod.mk a, ⟨a, ha, rfl⟩, b, hb, rfl⟩ }, { rintros ⟨f, ⟨x, hx, rfl⟩, y, hy, eq⟩, rw ← eq, exact ⟨hx, hy⟩ } end lemma prod_image_seq_comm (s : set α) (t : set β) : (prod.mk '' s).seq t = seq ((λb a, (a, b)) '' t) s := by rw [← prod_eq_seq, ← image_swap_prod, prod_eq_seq, image_seq, ← image_comp] end seq theorem monotone_prod [preorder α] {f : α → set β} {g : α → set γ} (hf : monotone f) (hg : monotone g) : monotone (λx, set.prod (f x) (g x)) := assume a b h, prod_mono (hf h) (hg h) instance : monad set := { pure := λ(α : Type u) a, {a}, bind := λ(α β : Type u) s f, ⋃i∈s, f i, seq := λ(α β : Type u), set.seq, map := λ(α β : Type u), set.image } instance : is_lawful_monad set := { pure_bind := assume α β x f, by simp, bind_assoc := assume α β γ s f g, set.ext $ assume a, by simp [exists_and_distrib_right.symm, -exists_and_distrib_right, exists_and_distrib_left.symm, -exists_and_distrib_left, and_assoc]; exact exists_swap, id_map := assume α, id_map, bind_pure_comp_eq_map := assume α β f s, set.ext $ by simp [set.image, eq_comm], bind_map_eq_seq := assume α β s t, by simp [seq_def] } instance : is_comm_applicative (set : Type u → Type u) := ⟨ assume α β s t, prod_image_seq_comm s t ⟩ section monad variables {α' β' : Type u} {s : set α'} {f : α' → set β'} {g : set (α' → β')} @[simp] lemma bind_def : s >>= f = ⋃i∈s, f i := rfl lemma fmap_eq_image : f <$> s = f '' s := rfl lemma seq_eq_set_seq {α β : Type*} (s : set (α → β)) (t : set α) : s <*> t = s.seq t := rfl @[simp] lemma pure_def (a : α): (pure a : set α) = {a} := rfl end monad section pi lemma pi_def {α : Type*} {π : α → Type*} (i : set α) (s : Πa, set (π a)) : pi i s = (⋂ a∈i, ((λf:(Πa, π a), f a) ⁻¹' (s a))) := by ext; simp [pi] end pi end set /- disjoint sets -/ section disjoint variable [semilattice_inf_bot α] /-- Two elements of a lattice are disjoint if their inf is the bottom element. (This generalizes disjoint sets, viewed as members of the subset lattice.) -/ def disjoint (a b : α) : Prop := a ⊓ b ≤ ⊥ theorem disjoint.eq_bot {a b : α} (h : disjoint a b) : a ⊓ b = ⊥ := eq_bot_iff.2 h theorem disjoint_iff {a b : α} : disjoint a b ↔ a ⊓ b = ⊥ := eq_bot_iff.symm theorem disjoint.comm {a b : α} : disjoint a b ↔ disjoint b a := by rw [disjoint, disjoint, inf_comm] theorem disjoint.symm {a b : α} : disjoint a b → disjoint b a := disjoint.comm.1 theorem disjoint_bot_left {a : α} : disjoint ⊥ a := disjoint_iff.2 bot_inf_eq theorem disjoint_bot_right {a : α} : disjoint a ⊥ := disjoint_iff.2 inf_bot_eq theorem disjoint_mono {a b c d : α} (h₁ : a ≤ b) (h₂ : c ≤ d) : disjoint b d → disjoint a c := le_trans (inf_le_inf h₁ h₂) theorem disjoint_mono_left {a b c : α} (h : a ≤ b) : disjoint b c → disjoint a c := disjoint_mono h (le_refl _) theorem disjoint_mono_right {a b c : α} (h : b ≤ c) : disjoint a c → disjoint a b := disjoint_mono (le_refl _) h end disjoint theorem set.disjoint_diff {a b : set α} : disjoint a (b \ a) := disjoint_iff.2 (inter_diff_self _ _) section open set set_option eqn_compiler.zeta true noncomputable def set.bUnion_eq_sigma_of_disjoint {α β} {s : set α} {t : α → set β} (h : pairwise_on s (disjoint on t)) : (⋃i∈s, t i) ≃ (Σi:s, t i.val) := let f : (Σi:s, t i.val) → (⋃i∈s, t i) := λ⟨⟨a, ha⟩, ⟨b, hb⟩⟩, ⟨b, mem_bUnion ha hb⟩ in have injective f, from assume ⟨⟨a₁, ha₁⟩, ⟨b₁, hb₁⟩⟩ ⟨⟨a₂, ha₂⟩, ⟨b₂, hb₂⟩⟩ eq, have b_eq : b₁ = b₂, from congr_arg subtype.val eq, have a_eq : a₁ = a₂, from classical.by_contradiction $ assume ne, have b₁ ∈ t a₁ ∩ t a₂, from ⟨hb₁, b_eq.symm ▸ hb₂⟩, h _ ha₁ _ ha₂ ne this, sigma.eq (subtype.eq a_eq) (subtype.eq $ by subst b_eq; subst a_eq), have surjective f, from assume ⟨b, hb⟩, have ∃a∈s, b ∈ t a, by simpa using hb, let ⟨a, ha, hb⟩ := this in ⟨⟨⟨a, ha⟩, ⟨b, hb⟩⟩, rfl⟩, (equiv.of_bijective ⟨‹injective f›, ‹surjective f›⟩).symm end
6f47d11327e9a379d3d93ab333d9a72be3a198b9
1446f520c1db37e157b631385707cc28a17a595e
/src/Init/Lean/Meta/Tactic/Target.lean
a493655c3ba2d23b2e3958ac932f0ec4a2bb7017
[ "Apache-2.0" ]
permissive
bdbabiak/lean4
cab06b8a2606d99a168dd279efdd404edb4e825a
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
refs/heads/master
1,615,045,275,530
1,583,793,696,000
1,583,793,696,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
1,750
lean
/- Copyright (c) 2020 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Leonardo de Moura -/ prelude import Init.Lean.Meta.AppBuilder import Init.Lean.Meta.Tactic.Util namespace Lean namespace Meta /-- Convert the given goal `Ctx |- target` into `Ctx |- newTarget` using an equality proof `eqProof : target = newTarget`. It assumes `eqProof` has type `target = newTarget` -/ def replaceTargetEq (mvarId : MVarId) (newTarget : Expr) (eqProof : Expr) : MetaM MVarId := do withMVarContext mvarId $ do checkNotAssigned mvarId `replaceTarget; tag ← getMVarTag mvarId; newMVar ← mkFreshExprSyntheticOpaqueMVar newTarget tag; target ← getMVarType mvarId; u ← getLevel target; eq ← mkEq target newTarget; let newProof := mkApp2 (mkConst `id [levelZero]) eq eqProof; -- checkpoint for eqProof let newVal := mkAppN (Lean.mkConst `Eq.mpr [u]) #[target, newTarget, eqProof, newMVar]; assignExprMVar mvarId newMVar; pure newMVar.mvarId! /-- Convert the given goal `Ctx | target` into `Ctx |- newTarget`. It assumes the goals are definitionally equal. We use the proof term ``` @id target newMVar ``` to create a checkpoint. -/ def replaceTargetDefEq (mvarId : MVarId) (newTarget : Expr) : MetaM MVarId := withMVarContext mvarId $ do checkNotAssigned mvarId `change; target ← getMVarType mvarId; if target == newTarget then pure mvarId else do tag ← getMVarTag mvarId; newMVar ← mkFreshExprSyntheticOpaqueMVar newTarget tag; u ← getLevel target; let newVal := mkApp2 (Lean.mkConst `id [u]) target newMVar; assignExprMVar mvarId newMVar; pure newMVar.mvarId! end Meta end Lean
075c9c554a5939dd893f2dc0e22927a87f146118
8e381650eb2c1c5361be64ff97e47d956bf2ab9f
/src/spectrum_of_a_ring/structure_sheaf_gluing.lean
ae596eefbbede80e352ef134fa989bfeee29f522
[]
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
7,943
lean
/- Second argument of the ring lemma. We show that the map R[1/fᵢ] → R[1/fᵢfⱼ] inverts fᵢ/1 * fⱼ/1. -/ import ring_theory.localization import to_mathlib.localization.localization_alt import spectrum_of_a_ring.structure_presheaf import spectrum_of_a_ring.structure_presheaf_localization import spectrum_of_a_ring.structure_presheaf_res import spectrum_of_a_ring.structure_sheaf_locality universe u local attribute [instance] classical.prop_decidable noncomputable theory section structure_presheaf open topological_space open classical open localization open localization_alt -- Needed. variables {R : Type u} [comm_ring R] variables {U V W : opens (Spec R)} variables (BU : U ∈ D_fs R) (BV : V ∈ D_fs R) (BW : W ∈ D_fs R) variables (HVU : V ⊆ U) (HWU : W ⊆ U) ------- def BVW : V ∩ W ∈ D_fs R := (D_fs_standard_basis R).2 BV BW def HVWU : V ∩ W ⊆ U := set.subset.trans (set.inter_subset_left V W) HVU def structure_presheaf_on_basis.res_to_inter : localization R (S U) → localization R (S (V ∩ W)) := structure_presheaf_on_basis.res BU (BVW BV BW) (HVWU HVU) def structure_presheaf_on_basis.res_to_inter_left : localization R (S V) → localization R (S (V ∩ W)) := structure_presheaf_on_basis.res BV (BVW BV BW) (set.inter_subset_left V W) def structure_presheaf_on_basis.res_to_inter_right : localization R (S W) → localization R (S (V ∩ W)) := structure_presheaf_on_basis.res BW (BVW BV BW) (set.inter_subset_right V W) instance structure_presheaf_on_basis.res_to_inter.is_ring_hom : is_ring_hom (structure_presheaf_on_basis.res_to_inter BU BV BW HVU) := by simp [structure_presheaf_on_basis.res_to_inter, structure_presheaf_on_basis.res]; by apply_instance instance structure_presheaf_on_basis.res_to_inter_to_inter_left.is_ring_hom : is_ring_hom (structure_presheaf_on_basis.res_to_inter_left BV BW) := by simp [structure_presheaf_on_basis.res_to_inter_left, structure_presheaf_on_basis.res]; by apply_instance instance structure_presheaf_on_basis.res_to_inter_to_inter_right.is_ring_hom : is_ring_hom (structure_presheaf_on_basis.res_to_inter_right BV BW) := by simp [structure_presheaf_on_basis.res_to_inter_right, structure_presheaf_on_basis.res]; by apply_instance ------- -- (f' g')^e = a * (fg)' include BU HVU lemma pow_eq.fmulg : ∃ a : R, ∃ e : ℕ, ((some BV) * (some BW))^e = a * (some (BVW BV BW)) := begin let f := some BV, let g := some BW, let fg := some (BVW BV BW), -- D(f*g) ⊆ D(fg). have HDfg : Spec.D'(f*g) ⊆ Spec.D'(fg), rw Spec.D'.product_eq_inter, show Spec.DO R f ∩ Spec.DO R g ⊆ Spec.DO R fg, rw [←some_spec BV, ←some_spec BW, ←some_spec (BVW BV BW)], exact set.subset.refl _, -- Hence (f*g)^e = a * fg. exact pow_eq.of_Dfs_subset HDfg, end lemma pow_eq.fg : ∃ a : R, ∃ e : ℕ, (some (BVW BV BW))^e = a * ((some BV) * (some BW)) := begin let f := some BV, let g := some BW, let fg := some (BVW BV BW), -- D(fg) ⊆ D(f*g). have HDfg : Spec.D'(fg) ⊆ Spec.D'(f*g), rw Spec.D'.product_eq_inter, show Spec.DO R fg ⊆ Spec.DO R f ∩ Spec.DO R g, rw [←some_spec BV, ←some_spec BW, ←some_spec (BVW BV BW)], exact set.subset.refl _, -- Hence (f*g)^e = a * fg. exact pow_eq.of_Dfs_subset HDfg, end ------- lemma structure_presheaf.res_to_inter.inverts_data : inverts_data (powers ((of (some BV)) * (of (some BW)))) (structure_presheaf_on_basis.res_to_inter BU BV BW HVU) := begin rcases (indefinite_description _ (pow_eq.fg BU BV BW HVU)) with ⟨a, Ha⟩, rcases (indefinite_description _ Ha) with ⟨e, Hea⟩, clear Ha, let f := some BV, let g := some BW, let fg := some (BVW BV BW), -- Using structure_presheaf.res.inverts_data rintros ⟨s, Hs⟩, rcases (indefinite_description _ Hs) with ⟨n, Hn⟩, have Hans : s * (of (a^n)) ∈ powers ((of : R → localization R (S U)) fg), rw is_semiring_hom.map_pow (of : R → localization R (S U)), rw [←Hn, ←mul_pow], iterate 2 { rw ←is_ring_hom.map_mul (of : R → localization R (S U)), }, rw [mul_comm, ←Hea, is_semiring_hom.map_pow (of : R → localization R (S U)), ←pow_mul], exact ⟨e * n, rfl⟩, rcases (structure_presheaf.res.inverts_data BU (BVW BV BW) (HVWU HVU) ⟨s * (of (a^n)), Hans⟩) with ⟨w, Hw⟩, rw ←is_ring_hom.map_mul (of : R → localization R (S U)) at Hn, rw ←is_semiring_hom.map_pow (of : R → localization R (S U)) at Hn, dsimp [structure_presheaf_on_basis.res_to_inter], dsimp only [subtype.coe_mk] at Hw, rw ←Hn, rw ←Hn at Hw, rw is_ring_hom.map_mul (structure_presheaf_on_basis.res BU (BVW BV BW) (HVWU HVU)) at Hw, use [(structure_presheaf_on_basis.res BU (BVW BV BW) (HVWU HVU) (of (a^n))) * w], rw ←mul_assoc, exact Hw, end lemma structure_presheaf.res_to_inter.has_denom_data : has_denom_data (powers ((of (some BV)) * (of (some BW)))) (structure_presheaf_on_basis.res_to_inter BU BV BW HVU) := begin rcases (indefinite_description _ (pow_eq.fmulg BU BV BW HVU)) with ⟨a, Ha⟩, rcases (indefinite_description _ Ha) with ⟨e, Hea⟩, clear Ha, let f := some BV, let g := some BW, let fg := some (BVW BV BW), -- Using structure_presheaf.res.has_denom -- This gives us ( fg^n, y ∈ R[1/S(U)] ) -- We have (f*g)^(n*e) = (fg)^n * a^n -- So let x = y * (of a)^n. intros x, rcases (structure_presheaf.res.has_denom_data BU (BVW BV BW) (HVWU HVU) x) with ⟨⟨⟨q, Hq⟩, p⟩, Hpq⟩, dsimp only [subtype.coe_mk] at Hpq, rcases (indefinite_description _ Hq) with ⟨n, Hn⟩, use [⟨⟨(of f * of g)^(e * n), ⟨e * n, rfl⟩⟩, p * (of a)^n⟩], dsimp [structure_presheaf_on_basis.res_to_inter], rw ←is_ring_hom.map_mul (of : R → localization R (S U)), rw ←is_semiring_hom.map_pow (of : R → localization R (S U)), rw [pow_mul, Hea], rw is_semiring_hom.map_pow (of : R → localization R (S U)), rw is_ring_hom.map_mul (of : R → localization R (S U)), rw [mul_pow, Hn, mul_comm p], iterate 2 { rw is_ring_hom.map_mul (structure_presheaf_on_basis.res BU (BVW BV BW) (HVWU HVU)), }, rw [←Hpq, ←mul_assoc], end lemma structure_presheaf.res_to_inter.ker_le : ker (structure_presheaf_on_basis.res_to_inter BU BV BW HVU) ≤ submonoid_ann (powers ((of (some BV)) * (of (some BW)))) := begin rcases (indefinite_description _ (pow_eq.fmulg BU BV BW HVU)) with ⟨a, Ha⟩, rcases (indefinite_description _ Ha) with ⟨e, Hea⟩, clear Ha, let f := some BV, let g := some BW, let fg := some (BVW BV BW), -- Using structure_presheaf.res.ker_le intros x Hx, dsimp [structure_presheaf_on_basis.res_to_inter] at Hx, replace Hx := (structure_presheaf.res.ker_le BU (BVW BV BW) (HVWU HVU)) Hx, rcases Hx with ⟨⟨⟨u, ⟨v, ⟨n, Hv⟩⟩⟩, Hxfgn⟩, Hx⟩, dsimp at Hx, dsimp at Hxfgn, rw [Hx, ←Hv] at Hxfgn; clear Hx; clear Hv, let fgne : localization R (S U) := (of f * of g)^(e * n), have Hfgne : fgne ∈ (powers (of f * of g) : set (localization R (S U))) := ⟨e * n, rfl⟩, have Hxfgne : x * fgne = 0, dsimp [fgne], rw ←is_ring_hom.map_mul (of : R → localization R (S U)), rw ←is_semiring_hom.map_pow (of : R → localization R (S U)), rw [pow_mul, Hea], rw is_semiring_hom.map_pow (of : R → localization R (S U)), rw is_ring_hom.map_mul (of : R → localization R (S U)), rw [mul_pow, mul_comm ((of a)^n), ←mul_assoc, Hxfgn, zero_mul], use ⟨⟨x, ⟨fgne, Hfgne⟩⟩, Hxfgne⟩, end lemma structure_presheaf.res_to_inter.localization : is_localization_data (powers ((of (some BV)) * (of (some BW)))) (structure_presheaf_on_basis.res_to_inter BU BV BW HVU) := { inverts := structure_presheaf.res_to_inter.inverts_data BU BV BW HVU, has_denom := structure_presheaf.res_to_inter.has_denom_data BU BV BW HVU, ker_le := structure_presheaf.res_to_inter.ker_le BU BV BW HVU } end structure_presheaf
264848c5a3f6c50b725174c5162f38b7f73d5f71
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/category_theory/monoidal/internal/types_auto.lean
d0d64b2caacd73e870c4b7ac9ad9e9327bc36af3
[]
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
5,618
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.algebra.category.Mon.basic import Mathlib.category_theory.monoidal.CommMon_ import Mathlib.category_theory.monoidal.types import Mathlib.PostPort universes u namespace Mathlib /-! # `Mon_ (Type u) ≌ Mon.{u}` The category of internal monoid objects in `Type` is equivalent to the category of "native" bundled monoids. Moreover, this equivalence is compatible with the forgetful functors to `Type`. -/ namespace Mon_Type_equivalence_Mon protected instance Mon_monoid (A : Mon_ (Type u)) : monoid (Mon_.X A) := monoid.mk (fun (x y : Mon_.X A) => Mon_.mul A (x, y)) sorry (Mon_.one A PUnit.unit) sorry sorry /-- Converting a monoid object in `Type` to a bundled monoid. -/ def functor : Mon_ (Type u) ⥤ Mon := category_theory.functor.mk (fun (A : Mon_ (Type u)) => category_theory.bundled.mk (Mon_.X A)) fun (A B : Mon_ (Type u)) (f : A ⟶ B) => monoid_hom.mk (Mon_.hom.hom f) sorry sorry /-- Converting a bundled monoid to a monoid object in `Type`. -/ def inverse : Mon ⥤ Mon_ (Type u) := category_theory.functor.mk (fun (A : Mon) => Mon_.mk (↥A) (fun (_x : 𝟙_) => 1) fun (p : ↥A ⊗ ↥A) => prod.fst p * prod.snd p) fun (A B : Mon) (f : A ⟶ B) => Mon_.hom.mk ⇑f end Mon_Type_equivalence_Mon /-- The category of internal monoid objects in `Type` is equivalent to the category of "native" bundled monoids. -/ def Mon_Type_equivalence_Mon : Mon_ (Type u) ≌ Mon := category_theory.equivalence.mk' sorry sorry (category_theory.nat_iso.of_components (fun (A : Mon_ (Type u)) => category_theory.iso.mk (Mon_.hom.mk 𝟙) (Mon_.hom.mk 𝟙)) sorry) (category_theory.nat_iso.of_components (fun (A : Mon) => category_theory.iso.mk (monoid_hom.mk id sorry sorry) (monoid_hom.mk id sorry sorry)) sorry) /-- The equivalence `Mon_ (Type u) ≌ Mon.{u}` is naturally compatible with the forgetful functors to `Type u`. -/ def Mon_Type_equivalence_Mon_forget : Mon_Type_equivalence_Mon.functor ⋙ category_theory.forget Mon ≅ Mon_.forget (Type u) := category_theory.nat_iso.of_components (fun (A : Mon_ (Type u)) => category_theory.iso.refl (category_theory.functor.obj (Mon_Type_equivalence_Mon.functor ⋙ category_theory.forget Mon) A)) sorry protected instance Mon_Type_inhabited : Inhabited (Mon_ (Type u)) := { default := category_theory.functor.obj Mon_Type_equivalence_Mon.inverse (Mon.of PUnit) } namespace CommMon_Type_equivalence_CommMon protected instance CommMon_comm_monoid (A : CommMon_ (Type u)) : comm_monoid (Mon_.X (CommMon_.to_Mon_ A)) := comm_monoid.mk monoid.mul sorry monoid.one sorry sorry sorry /-- Converting a commutative monoid object in `Type` to a bundled commutative monoid. -/ def functor : CommMon_ (Type u) ⥤ CommMon := category_theory.functor.mk (fun (A : CommMon_ (Type u)) => category_theory.bundled.mk (Mon_.X (CommMon_.to_Mon_ A))) fun (A B : CommMon_ (Type u)) (f : A ⟶ B) => category_theory.functor.map Mon_Type_equivalence_Mon.functor f /-- Converting a bundled commutative monoid to a commutative monoid object in `Type`. -/ def inverse : CommMon ⥤ CommMon_ (Type u) := category_theory.functor.mk (fun (A : CommMon) => CommMon_.mk (Mon_.mk (Mon_.X (category_theory.functor.obj Mon_Type_equivalence_Mon.inverse (category_theory.functor.obj (category_theory.forget₂ CommMon Mon) A))) (Mon_.one (category_theory.functor.obj Mon_Type_equivalence_Mon.inverse (category_theory.functor.obj (category_theory.forget₂ CommMon Mon) A))) (Mon_.mul (category_theory.functor.obj Mon_Type_equivalence_Mon.inverse (category_theory.functor.obj (category_theory.forget₂ CommMon Mon) A))))) fun (A B : CommMon) (f : A ⟶ B) => category_theory.functor.map Mon_Type_equivalence_Mon.inverse f end CommMon_Type_equivalence_CommMon /-- The category of internal commutative monoid objects in `Type` is equivalent to the category of "native" bundled commutative monoids. -/ def CommMon_Type_equivalence_CommMon : CommMon_ (Type u) ≌ CommMon := category_theory.equivalence.mk' sorry sorry (category_theory.nat_iso.of_components (fun (A : CommMon_ (Type u)) => category_theory.iso.mk (Mon_.hom.mk 𝟙) (Mon_.hom.mk 𝟙)) sorry) (category_theory.nat_iso.of_components (fun (A : CommMon) => category_theory.iso.mk (monoid_hom.mk id sorry sorry) (monoid_hom.mk id sorry sorry)) sorry) /-- The equivalences `Mon_ (Type u) ≌ Mon.{u}` and `CommMon_ (Type u) ≌ CommMon.{u}` are naturally compatible with the forgetful functors to `Mon` and `Mon_ (Type u)`. -/ def CommMon_Type_equivalence_CommMon_forget : CommMon_Type_equivalence_CommMon.functor ⋙ category_theory.forget₂ CommMon Mon ≅ CommMon_.forget₂_Mon_ (Type u) ⋙ Mon_Type_equivalence_Mon.functor := category_theory.nat_iso.of_components (fun (A : CommMon_ (Type u)) => category_theory.iso.refl (category_theory.functor.obj (CommMon_Type_equivalence_CommMon.functor ⋙ category_theory.forget₂ CommMon Mon) A)) sorry protected instance CommMon_Type_inhabited : Inhabited (CommMon_ (Type u)) := { default := category_theory.functor.obj CommMon_Type_equivalence_CommMon.inverse (CommMon.of PUnit) } end Mathlib
b93b4046c473305d7304f53e7218d5490ea268a2
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/eqn_value_issue.lean
9c4c49b50644b0328466828e6dca6d4dbb072b13
[ "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
269
lean
def f : nat -> nat | 1 := 1 | 2000 := 2 | _ := 3 #check f.equations._eqn_1 #check f.equations._eqn_2 #check f.equations._eqn_3 def g : nat -> nat | 0 := 1 | 2000 := 2 | _ := 3 #check g.equations._eqn_1 #check g.equations._eqn_2 #check g.equations._eqn_3
ebe19a4d17831e448497365c76de5355658af846
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/tests/lean/run/spec_issue.lean
a083563ea2cc8b492942befb1691de76222dd56a
[ "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
158
lean
set_option trace.compiler.ir.result true def g (ys : List Nat) : IO Nat := do let x := 0 let (_, x) ← StateT.run (ys.forM fun y => IO.println y) x pure x
7ad2d8c9f815eb9af57fe0d95c65ff2e028d66ca
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/dec_trivial_problem.lean
c8a40ffff33da90405a8aa1db0147abf565f0b27
[ "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
401
lean
definition n : nat := 3 open tactic meta definition dec_triv : tactic unit := do tgt ← target, inst ← to_expr ``(decidable %%tgt) >>= mk_instance, to_expr ``(@of_as_true %%tgt %%inst trivial) >>= exact example : 0 < n := by dec_triv notation `dec_trivial2` := by dec_triv example : 0 < n := dec_trivial2 notation `dec_trivial3` := of_as_true (by triv) example : 0 < n := dec_trivial3
0fc192df9ea2fe4fdbe1f70ff7c05ce223e7aff7
7cdf3413c097e5d36492d12cdd07030eb991d394
/world_experiments/world7/level13.lean
c5b8be3adda9769d107c341d8a6120514c320a32
[]
no_license
alreadydone/natural_number_game
3135b9385a9f43e74cfbf79513fc37e69b99e0b3
1a39e693df4f4e871eb449890d3c7715a25c2ec9
refs/heads/master
1,599,387,390,105
1,573,200,587,000
1,573,200,691,000
220,397,084
0
0
null
1,573,192,734,000
1,573,192,733,000
null
UTF-8
Lean
false
false
723
lean
import mynat.definition -- hide import mynat.add -- hide import game.world2.level12 -- hide namespace mynat -- hide /- # World 2 -- Addition World ## Level 13 -- `add_left_eq_zero` You have the usual stuff. * `zero_ne_succ (a : mynat) : zero ≠ succ(a)` might be useful for this one. The following lemma will be useful when we want to prove that $\leq$ is antisymmetric somewhere in world 4. -/ /- Lemma If $a$ and $b$ are natural numbers such that $$ a + b = 0, $$ then $b = 0$. -/ lemma add_left_eq_zero {a b : mynat} (H : a + b = 0) : b = 0 := begin [less_leaky] cases b with c, { refl}, { rw add_succ at H, exfalso, apply zero_ne_succ (a + c), rw H, refl, }, end end mynat -- hide
60832c336900a0ada4e40bd3efff64b63327f4c2
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/order/partition/finpartition.lean
6a26c426fca3e71507140f4a63b1658b9c04ceee
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
19,678
lean
/- Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies, Bhavik Mehta -/ import algebra.big_operators.basic import order.atoms import order.sup_indep /-! # Finite partitions In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise disjoint parts `parts : finset α` which does not contain `⊥` and whose supremum is `a`. Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied purely order theoretically in Sperner theory. ## Constructions We provide many ways to build finpartitions: * `finpartition.of_erase`: Builds a finpartition by erasing `⊥` for you. * `finpartition.of_subset`: Builds a finpartition from a subset of the parts of a previous finpartition. * `finpartition.empty`: The empty finpartition of `⊥`. * `finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single part. * `finpartition.discrete`: The discrete finpartition of `s : finset α` made of singletons. * `finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new finpartition. * `finpartition.atomise`: Makes a finpartition of `s : finset α` by breaking `s` along all finsets in `F : finset (finset α)`. Two elements of `s` belong to the same part iff they belong to the same elements of `F`. `finpartition.indiscrete` and `finpartition.bind` together form the monadic structure of `finpartition`. ## Implementation notes Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning operations on `finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing `⊥` to be a part makes `finpartition.bind` uglier and doesn't rid us of the need of `finpartition.of_erase`. ## TODO Link `finpartition` and `setoid.is_partition`. The order is the wrong way around to make `finpartition a` a graded order. Is it bad to depart from the literature and turn the order around? -/ open finset function open_locale big_operators variables {α : Type*} /-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is `a`. We forbid `⊥` as a part. -/ @[ext, derive decidable_eq] structure finpartition [lattice α] [order_bot α] (a : α) := (parts : finset α) (sup_indep : parts.sup_indep id) (sup_parts : parts.sup id = a) (not_bot_mem : ⊥ ∉ parts) attribute [protected] finpartition.sup_indep namespace finpartition section lattice variables [lattice α] [order_bot α] /-- A `finpartition` constructor which does not insist on `⊥` not being a part. -/ @[simps] def of_erase [decidable_eq α] {a : α} (parts : finset α) (sup_indep : parts.sup_indep id) (sup_parts : parts.sup id = a) : finpartition a := { parts := parts.erase ⊥, sup_indep := sup_indep.subset (erase_subset _ _), sup_parts := (sup_erase_bot _).trans sup_parts, not_bot_mem := not_mem_erase _ _ } /-- A `finpartition` constructor from a bigger existing finpartition. -/ @[simps] def of_subset {a b : α} (P : finpartition a) {parts : finset α} (subset : parts ⊆ P.parts) (sup_parts : parts.sup id = b) : finpartition b := { parts := parts, sup_indep := P.sup_indep.subset subset, sup_parts := sup_parts, not_bot_mem := λ h, P.not_bot_mem (subset h) } /-- Changes the type of a finpartition to an equal one. -/ @[simps] def copy {a b : α} (P : finpartition a) (h : a = b) : finpartition b := { parts := P.parts, sup_indep := P.sup_indep, sup_parts := h ▸ P.sup_parts, not_bot_mem := P.not_bot_mem } variables (α) /-- The empty finpartition. -/ @[simps] protected def empty : finpartition (⊥ : α) := { parts := ∅, sup_indep := sup_indep_empty _, sup_parts := finset.sup_empty, not_bot_mem := not_mem_empty ⊥ } instance : inhabited (finpartition (⊥ : α)) := ⟨finpartition.empty α⟩ @[simp] lemma default_eq_empty : (default : finpartition (⊥ : α)) = finpartition.empty α := rfl variables {α} {a : α} /-- The finpartition in one part, aka indiscrete finpartition. -/ @[simps] def indiscrete (ha : a ≠ ⊥) : finpartition a := { parts := {a}, sup_indep := sup_indep_singleton _ _, sup_parts := finset.sup_singleton, not_bot_mem := λ h, ha (mem_singleton.1 h).symm } variables (P : finpartition a) protected lemma le {b : α} (hb : b ∈ P.parts) : b ≤ a := (le_sup hb).trans P.sup_parts.le lemma ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := λ h, P.not_bot_mem $ h.subst hb protected lemma disjoint : (P.parts : set α).pairwise_disjoint id := P.sup_indep.pairwise_disjoint variables {P} lemma parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ := begin simp_rw ←P.sup_parts, refine ⟨λ h, _, λ h, eq_empty_iff_forall_not_mem.2 (λ b hb, P.not_bot_mem _)⟩, { rw h, exact finset.sup_empty }, { rwa ←le_bot_iff.1 ((le_sup hb).trans h.le) } end lemma parts_nonempty_iff : P.parts.nonempty ↔ a ≠ ⊥ := by rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff] lemma parts_nonempty (P : finpartition a) (ha : a ≠ ⊥) : P.parts.nonempty := parts_nonempty_iff.2 ha instance : unique (finpartition (⊥ : α)) := { uniq := λ P, by { ext a, exact iff_of_false (λ h, P.ne_bot h $ le_bot_iff.1 $ P.le h) (not_mem_empty a) }, ..finpartition.inhabited α } /-- There's a unique partition of an atom. -/ @[reducible] -- See note [reducible non instances] def _root_.is_atom.unique_finpartition (ha : is_atom a) : unique (finpartition a) := { default := indiscrete ha.1, uniq := λ P, begin have h : ∀ b ∈ P.parts, b = a, { exact λ b hb, (ha.le_iff.mp $ P.le hb).resolve_left (P.ne_bot hb) }, ext b, refine iff.trans ⟨h b, _⟩ mem_singleton.symm, rintro rfl, obtain ⟨c, hc⟩ := P.parts_nonempty ha.1, simp_rw ←h c hc, exact hc, end } instance [fintype α] [decidable_eq α] (a : α) : fintype (finpartition a) := @fintype.of_surjective {p : finset α // p.sup_indep id ∧ p.sup id = a ∧ ⊥ ∉ p} (finpartition a) _ (subtype.fintype _) (λ i, ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) (λ ⟨_, y, z, w⟩, ⟨⟨_, y, z, w⟩, rfl⟩) /-! ### Refinement order -/ section order /-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/ instance : has_le (finpartition a) := ⟨λ P Q, ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩ instance : partial_order (finpartition a) := { le_refl := λ P b hb, ⟨b, hb, le_rfl⟩, le_trans := λ P Q R hPQ hQR b hb, begin obtain ⟨c, hc, hbc⟩ := hPQ hb, obtain ⟨d, hd, hcd⟩ := hQR hc, exact ⟨d, hd, hbc.trans hcd⟩, end, le_antisymm := λ P Q hPQ hQP, begin ext b, refine ⟨λ hb, _, λ hb, _⟩, { obtain ⟨c, hc, hbc⟩ := hPQ hb, obtain ⟨d, hd, hcd⟩ := hQP hc, rwa hbc.antisymm, rwa P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd) }, { obtain ⟨c, hc, hbc⟩ := hQP hb, obtain ⟨d, hd, hcd⟩ := hPQ hc, rwa hbc.antisymm, rwa Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd) } end, ..finpartition.has_le } instance [decidable (a = ⊥)] : order_top (finpartition a) := { top := if ha : a = ⊥ then (finpartition.empty α).copy ha.symm else indiscrete ha, le_top := λ P, begin split_ifs, { intros x hx, simpa [h, P.ne_bot hx] using P.le hx }, { exact λ b hb, ⟨a, mem_singleton_self _, P.le hb⟩ } end } lemma parts_top_subset (a : α) [decidable (a = ⊥)] : (⊤ : finpartition a).parts ⊆ {a} := begin intros b hb, change b ∈ finpartition.parts (dite _ _ _) at hb, split_ifs at hb, { simp only [copy_parts, empty_parts, not_mem_empty] at hb, exact hb.elim }, { exact hb } end lemma parts_top_subsingleton (a : α) [decidable (a = ⊥)] : ((⊤ : finpartition a).parts : set α).subsingleton := set.subsingleton_of_subset_singleton $ λ b hb, mem_singleton.1 $ parts_top_subset _ hb end order end lattice section distrib_lattice variables [distrib_lattice α] [order_bot α] section inf variables [decidable_eq α] {a b c : α} instance : has_inf (finpartition a) := ⟨λ P Q, of_erase ((P.parts ×ˢ Q.parts).image $ λ bc, bc.1 ⊓ bc.2) begin rw sup_indep_iff_disjoint_erase, simp only [mem_image, and_imp, exists_prop, forall_exists_index, id.def, prod.exists, mem_product, finset.disjoint_sup_right, mem_erase, ne.def], rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl, rcases eq_or_ne x₁ x₂ with rfl | xdiff, { refine disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ _), intro t, simpa [t] using h }, exact disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff), end begin rw [sup_image, comp.left_id, sup_product_left], transitivity P.parts.sup id ⊓ Q.parts.sup id, { simp_rw [finset.sup_inf_distrib_right, finset.sup_inf_distrib_left], refl }, { rw [P.sup_parts, Q.sup_parts, inf_idem] } end⟩ @[simp] lemma parts_inf (P Q : finpartition a) : (P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image $ λ bc : α × α, bc.1 ⊓ bc.2).erase ⊥ := rfl instance : semilattice_inf (finpartition a) := { inf_le_left := λ P Q b hb, begin obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb), rw mem_product at hc, exact ⟨c.1, hc.1, inf_le_left⟩, end, inf_le_right := λ P Q b hb, begin obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb), rw mem_product at hc, exact ⟨c.2, hc.2, inf_le_right⟩, end, le_inf := λ P Q R hPQ hPR b hb, begin obtain ⟨c, hc, hbc⟩ := hPQ hb, obtain ⟨d, hd, hbd⟩ := hPR hb, have h := _root_.le_inf hbc hbd, refine ⟨c ⊓ d, mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h) (mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩), h⟩, end, ..finpartition.partial_order, ..finpartition.has_inf } end inf lemma exists_le_of_le {a b : α} {P Q : finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) : ∃ c ∈ P.parts, c ≤ b := begin by_contra' H, refine Q.ne_bot hb (disjoint_self.1 $ disjoint.mono_right (Q.le hb) _), rw [←P.sup_parts, finset.disjoint_sup_right], rintro c hc, obtain ⟨d, hd, hcd⟩ := h hc, refine (Q.disjoint hb hd _).mono_right hcd, rintro rfl, exact H _ hc hcd, end lemma card_mono {a : α} {P Q : finpartition a} (h : P ≤ Q) : Q.parts.card ≤ P.parts.card := begin classical, have : ∀ b ∈ Q.parts, ∃ c ∈ P.parts, c ≤ b := λ b, exists_le_of_le h, choose f hP hf using this, rw ←card_attach, refine card_le_card_of_inj_on (λ b, f _ b.2) (λ b _, hP _ b.2) (λ b hb c hc h, _), exact subtype.coe_injective (Q.disjoint.elim b.2 c.2 $ λ H, P.ne_bot (hP _ b.2) $ disjoint_self.1 $ H.mono (hf _ b.2) $ h.le.trans $ hf _ c.2), end variables [decidable_eq α] {a b c : α} section bind variables {P : finpartition a} {Q : Π i ∈ P.parts, finpartition i} /-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the finpartition of `a` obtained by juxtaposing all the subpartitions. -/ @[simps] def bind (P : finpartition a) (Q : Π i ∈ P.parts, finpartition i) : finpartition a := { parts := P.parts.attach.bUnion (λ i, (Q i.1 i.2).parts), sup_indep := begin rw sup_indep_iff_pairwise_disjoint, rintro a ha b hb h, rw [finset.mem_coe, finset.mem_bUnion] at ha hb, obtain ⟨⟨A, hA⟩, -, ha⟩ := ha, obtain ⟨⟨B, hB⟩, -, hb⟩ := hb, obtain rfl | hAB := eq_or_ne A B, { exact (Q A hA).disjoint ha hb h }, { exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb) } end, sup_parts := begin simp_rw [sup_bUnion, ←P.sup_parts], rw [eq_comm, ←finset.sup_attach], exact sup_congr rfl (λ b hb, (Q b.1 b.2).sup_parts.symm), end, not_bot_mem := λ h, begin rw finset.mem_bUnion at h, obtain ⟨⟨A, hA⟩, -, h⟩ := h, exact (Q A hA).not_bot_mem h, end } lemma mem_bind : b ∈ (P.bind Q).parts ↔ ∃ A hA, b ∈ (Q A hA).parts := begin rw [bind, mem_bUnion], split, { rintro ⟨⟨A, hA⟩, -, h⟩, exact ⟨A, hA, h⟩ }, { rintro ⟨A, hA, h⟩, exact ⟨⟨A, hA⟩, mem_attach _ ⟨A, hA⟩, h⟩ } end lemma card_bind (Q : Π i ∈ P.parts, finpartition i) : (P.bind Q).parts.card = ∑ A in P.parts.attach, (Q _ A.2).parts.card := begin apply card_bUnion, rintro ⟨b, hb⟩ - ⟨c, hc⟩ - hbc, rw finset.disjoint_left, rintro d hdb hdc, rw [ne.def, subtype.mk_eq_mk] at hbc, exact (Q b hb).ne_bot hdb (eq_bot_iff.2 $ (le_inf ((Q b hb).le hdb) $ (Q c hc).le hdc).trans $ (P.disjoint hb hc hbc).le_bot), end end bind /-- Adds `b` to a finpartition of `a` to make a finpartition of `a ⊔ b`. -/ @[simps] def extend (P : finpartition a) (hb : b ≠ ⊥) (hab : disjoint a b) (hc : a ⊔ b = c) : finpartition c := { parts := insert b P.parts, sup_indep := begin rw [sup_indep_iff_pairwise_disjoint, coe_insert], exact P.disjoint.insert (λ d hd hbd, hab.symm.mono_right $ P.le hd), end, sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm], not_bot_mem := λ h, (mem_insert.1 h).elim hb.symm P.not_bot_mem } lemma card_extend (P : finpartition a) (b c : α) {hb : b ≠ ⊥} {hab : disjoint a b} {hc : a ⊔ b = c} : (P.extend hb hab hc).parts.card = P.parts.card + 1 := card_insert_of_not_mem $ λ h, hb $ hab.symm.eq_bot_of_le $ P.le h end distrib_lattice section generalized_boolean_algebra variables [generalized_boolean_algebra α] [decidable_eq α] {a b c : α} (P : finpartition a) /-- Restricts a finpartition to avoid a given element. -/ @[simps] def avoid (b : α) : finpartition (a \ b) := of_erase (P.parts.image (\ b)) (P.disjoint.image_finset_of_le $ λ a, sdiff_le).sup_indep (by rw [sup_image, comp.left_id, finset.sup_sdiff_right, ←id_def, P.sup_parts]) @[simp] lemma mem_avoid : c ∈ (P.avoid b).parts ↔ ∃ d ∈ P.parts, ¬ d ≤ b ∧ d \ b = c := begin simp only [avoid, of_erase_parts, mem_erase, ne.def, mem_image, exists_prop, ←exists_and_distrib_left, @and.left_comm (c ≠ ⊥)], refine exists_congr (λ d, and_congr_right' $ and_congr_left _), rintro rfl, rw sdiff_eq_bot_iff, end end generalized_boolean_algebra end finpartition /-! ### Finite partitions of finsets -/ namespace finpartition variables [decidable_eq α] {s t : finset α} (P : finpartition s) lemma nonempty_of_mem_parts {a : finset α} (ha : a ∈ P.parts) : a.nonempty := nonempty_iff_ne_empty.2 $ P.ne_bot ha lemma exists_mem {a : α} (ha : a ∈ s) : ∃ t ∈ P.parts, a ∈ t := by { simp_rw ←P.sup_parts at ha, exact mem_sup.1 ha } lemma bUnion_parts : P.parts.bUnion id = s := (sup_eq_bUnion _ _).symm.trans P.sup_parts lemma sum_card_parts : ∑ i in P.parts, i.card = s.card := begin convert congr_arg finset.card P.bUnion_parts, rw card_bUnion P.sup_indep.pairwise_disjoint, refl, end /-- `⊥` is the partition in singletons, aka discrete partition. -/ instance (s : finset α) : has_bot (finpartition s) := ⟨{ parts := s.map ⟨singleton, singleton_injective⟩, sup_indep := set.pairwise_disjoint.sup_indep begin rw finset.coe_map, exact finset.pairwise_disjoint_range_singleton.subset (set.image_subset_range _ _), end, sup_parts := by rw [sup_map, comp.left_id, embedding.coe_fn_mk, finset.sup_singleton'], not_bot_mem := by simp }⟩ @[simp] lemma parts_bot (s : finset α) : (⊥ : finpartition s).parts = s.map ⟨singleton, singleton_injective⟩ := rfl lemma card_bot (s : finset α) : (⊥ : finpartition s).parts.card = s.card := finset.card_map _ lemma mem_bot_iff : t ∈ (⊥ : finpartition s).parts ↔ ∃ a ∈ s, {a} = t := mem_map instance (s : finset α) : order_bot (finpartition s) := { bot_le := λ P t ht, begin rw mem_bot_iff at ht, obtain ⟨a, ha, rfl⟩ := ht, obtain ⟨t, ht, hat⟩ := P.exists_mem ha, exact ⟨t, ht, singleton_subset_iff.2 hat⟩, end, ..finpartition.has_bot s } lemma card_parts_le_card (P : finpartition s) : P.parts.card ≤ s.card := by { rw ←card_bot s, exact card_mono bot_le } section atomise /-- Cuts `s` along the finsets in `F`: Two elements of `s` will be in the same part if they are in the same finsets of `F`. -/ def atomise (s : finset α) (F : finset (finset α)) : finpartition s := of_erase (F.powerset.image $ λ Q, s.filter (λ i, ∀ t ∈ F, t ∈ Q ↔ i ∈ t)) (set.pairwise_disjoint.sup_indep $ λ x hx y hy h, disjoint_left.mpr $ λ z hz1 hz2, h begin rw [mem_coe, mem_image] at hx hy, obtain ⟨Q, hQ, rfl⟩ := hx, obtain ⟨R, hR, rfl⟩ := hy, suffices h : Q = R, { subst h }, rw [id, mem_filter] at hz1 hz2, rw mem_powerset at hQ hR, ext i, refine ⟨λ hi, _, λ hi, _⟩, { rwa [hz2.2 _ (hQ hi), ←hz1.2 _ (hQ hi)] }, { rwa [hz1.2 _ (hR hi), ←hz2.2 _ (hR hi)] } end) (begin refine (finset.sup_le $ λ t ht, _).antisymm (λ a ha, _), { rw mem_image at ht, obtain ⟨A, hA, rfl⟩ := ht, exact s.filter_subset _ }, { rw [mem_sup], refine ⟨s.filter (λ i, ∀ t, t ∈ F → (t ∈ F.filter (λ u, a ∈ u) ↔ i ∈ t)), mem_image_of_mem _ (mem_powerset.2 $ filter_subset _ _), mem_filter.2 ⟨ha, λ t ht, _⟩⟩, rw mem_filter, exact and_iff_right ht } end) variables {F : finset (finset α)} lemma mem_atomise : t ∈ (atomise s F).parts ↔ t.nonempty ∧ ∃ (Q ⊆ F), s.filter (λ i, ∀ u ∈ F, u ∈ Q ↔ i ∈ u) = t := by simp only [atomise, of_erase, bot_eq_empty, mem_erase, mem_image, nonempty_iff_ne_empty, mem_singleton, and_comm, mem_powerset, exists_prop] lemma atomise_empty (hs : s.nonempty) : (atomise s ∅).parts = {s} := begin simp only [atomise, powerset_empty, image_singleton, not_mem_empty, is_empty.forall_iff, implies_true_iff, filter_true], exact erase_eq_of_not_mem (not_mem_singleton.2 hs.ne_empty.symm), end lemma card_atomise_le : (atomise s F).parts.card ≤ 2^F.card := (card_le_of_subset $ erase_subset _ _).trans $ finset.card_image_le.trans (card_powerset _).le lemma bUnion_filter_atomise (ht : t ∈ F) (hts : t ⊆ s) : ((atomise s F).parts.filter $ λ u, u ⊆ t ∧ u.nonempty).bUnion id = t := begin ext a, refine mem_bUnion.trans ⟨λ ⟨u, hu, ha⟩, (mem_filter.1 hu).2.1 ha, λ ha, _⟩, obtain ⟨u, hu, hau⟩ := (atomise s F).exists_mem (hts ha), refine ⟨u, mem_filter.2 ⟨hu, λ b hb, _, _, hau⟩, hau⟩, obtain ⟨Q, hQ, rfl⟩ := (mem_atomise.1 hu).2, rw mem_filter at hau hb, rwa [←hb.2 _ ht, hau.2 _ ht], end lemma card_filter_atomise_le_two_pow (ht : t ∈ F) : ((atomise s F).parts.filter $ λ u, u ⊆ t ∧ u.nonempty).card ≤ 2 ^ (F.card - 1) := begin suffices h : (atomise s F).parts.filter (λ u, u ⊆ t ∧ u.nonempty) ⊆ (F.erase t).powerset.image (λ P, s.filter $ λ i, ∀ x ∈ F, x ∈ insert t P ↔ i ∈ x), { refine (card_le_of_subset h).trans (card_image_le.trans _), rw [card_powerset, card_erase_of_mem ht] }, rw subset_iff, simp only [mem_erase, mem_sdiff, mem_powerset, mem_image, exists_prop, mem_filter, and_assoc, finset.nonempty, exists_imp_distrib, and_imp, mem_atomise, forall_apply_eq_imp_iff₂], rintro P' i hi P PQ rfl hy₂ j hj, refine ⟨P.erase t, erase_subset_erase _ PQ, _⟩, simp only [insert_erase (((mem_filter.1 hi).2 _ ht).2 $ hy₂ hi), filter_congr_decidable], end end atomise end finpartition
dac78d9c37ae3ee269326aabc8d5b8f4a948619d
aa3f8992ef7806974bc1ffd468baa0c79f4d6643
/tests/lean/t9.lean
4c0afbe75fd9451f89eb59af310d2b3cde33c91c
[ "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
388
lean
precedence `+` : 65 precedence `*` : 75 precedence `=` : 50 precedence `≃` : 50 constant N : Type.{1} constant a : N constant b : N constant add : N → N → N constant mul : N → N → N namespace foo infixl + := add infixl * := mul check a+b*a end foo -- Notation is not avaiable outside the namespace check a+b*a namespace foo -- Notation is restored check a+b*a end foo
6f02fa8328be2432618fbd657678b4fe2a91b53a
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
/src/order/filter/germ.lean
605ee3d27129cbeee1cf9f6e5a6f67f74b681628
[ "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
21,463
lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yury G. Kudryashov, Abhimanyu Pallavi Sudhir -/ import order.filter.basic import algebra.module.pi /-! # Germ of a function at a filter The germ of a function `f : α → β` at a filter `l : filter α` is the equivalence class of `f` with respect to the equivalence relation `eventually_eq l`: `f ≈ g` means `∀ᶠ x in l, f x = g x`. ## Main definitions We define * `germ l β` to be the space of germs of functions `α → β` at a filter `l : filter α`; * coercion from `α → β` to `germ l β`: `(f : germ l β)` is the germ of `f : α → β` at `l : filter α`; this coercion is declared as `has_coe_t`, so it does not require an explicit up arrow `↑`; * coercion from `β` to `germ l β`: `(↑c : germ l β)` is the germ of the constant function `λ x:α, c` at a filter `l`; this coercion is declared as `has_lift_t`, so it requires an explicit up arrow `↑`, see [TPiL][TPiL_coe] for details. * `map (F : β → γ) (f : germ l β)` to be the composition of a function `F` and a germ `f`; * `map₂ (F : β → γ → δ) (f : germ l β) (g : germ l γ)` to be the germ of `λ x, F (f x) (g x)` at `l`; * `f.tendsto lb`: we say that a germ `f : germ l β` tends to a filter `lb` if its representatives tend to `lb` along `l`; * `f.comp_tendsto g hg` and `f.comp_tendsto' g hg`: given `f : germ l β` and a function `g : γ → α` (resp., a germ `g : germ lc α`), if `g` tends to `l` along `lc`, then the composition `f ∘ g` is a well-defined germ at `lc`; * `germ.lift_pred`, `germ.lift_rel`: lift a predicate or a relation to the space of germs: `(f : germ l β).lift_pred p` means `∀ᶠ x in l, p (f x)`, and similarly for a relation. [TPiL_coe]: https://leanprover.github.io/theorem_proving_in_lean/type_classes.html#coercions-using-type-classes We also define `map (F : β → γ) : germ l β → germ l γ` sending each germ `f` to `F ∘ f`. For each of the following structures we prove that if `β` has this structure, then so does `germ l β`: * one-operation algebraic structures up to `comm_group`; * `mul_zero_class`, `distrib`, `semiring`, `comm_semiring`, `ring`, `comm_ring`; * `mul_action`, `distrib_mul_action`, `module`; * `preorder`, `partial_order`, and `lattice` structures up to `bounded_lattice`; * `ordered_cancel_comm_monoid` and `ordered_cancel_add_comm_monoid`. ## Tags filter, germ -/ namespace filter variables {α β γ δ : Type*} {l : filter α} {f g h : α → β} lemma const_eventually_eq' [ne_bot l] {a b : β} : (∀ᶠ x in l, a = b) ↔ a = b := eventually_const lemma const_eventually_eq [ne_bot l] {a b : β} : ((λ _, a) =ᶠ[l] (λ _, b)) ↔ a = b := @const_eventually_eq' _ _ _ _ a b lemma eventually_eq.comp_tendsto {f' : α → β} (H : f =ᶠ[l] f') {g : γ → α} {lc : filter γ} (hg : tendsto g lc l) : f ∘ g =ᶠ[lc] f' ∘ g := hg.eventually H /-- Setoid used to define the space of germs. -/ def germ_setoid (l : filter α) (β : Type*) : setoid (α → β) := { r := eventually_eq l, iseqv := ⟨eventually_eq.refl _, λ _ _, eventually_eq.symm, λ _ _ _, eventually_eq.trans⟩ } /-- The space of germs of functions `α → β` at a filter `l`. -/ def germ (l : filter α) (β : Type*) : Type* := quotient (germ_setoid l β) namespace germ instance : has_coe_t (α → β) (germ l β) := ⟨quotient.mk'⟩ instance : has_lift_t β (germ l β) := ⟨λ c, ↑(λ (x : α), c)⟩ @[simp] lemma quot_mk_eq_coe (l : filter α) (f : α → β) : quot.mk _ f = (f : germ l β) := rfl @[simp] lemma mk'_eq_coe (l : filter α) (f : α → β) : quotient.mk' f = (f : germ l β) := rfl @[elab_as_eliminator] lemma induction_on (f : germ l β) {p : germ l β → Prop} (h : ∀ f : α → β, p f) : p f := quotient.induction_on' f h @[elab_as_eliminator] lemma induction_on₂ (f : germ l β) (g : germ l γ) {p : germ l β → germ l γ → Prop} (h : ∀ (f : α → β) (g : α → γ), p f g) : p f g := quotient.induction_on₂' f g h @[elab_as_eliminator] lemma induction_on₃ (f : germ l β) (g : germ l γ) (h : germ l δ) {p : germ l β → germ l γ → germ l δ → Prop} (H : ∀ (f : α → β) (g : α → γ) (h : α → δ), p f g h) : p f g h := quotient.induction_on₃' f g h H /-- Given a map `F : (α → β) → (γ → δ)` that sends functions eventually equal at `l` to functions eventually equal at `lc`, returns a map from `germ l β` to `germ lc δ`. -/ def map' {lc : filter γ} (F : (α → β) → (γ → δ)) (hF : (l.eventually_eq ⇒ lc.eventually_eq) F F) : germ l β → germ lc δ := quotient.map' F hF /-- Given a germ `f : germ l β` and a function `F : (α → β) → γ` sending eventually equal functions to the same value, returns the value `F` takes on functions having germ `f` at `l`. -/ def lift_on {γ : Sort*} (f : germ l β) (F : (α → β) → γ) (hF : (l.eventually_eq ⇒ (=)) F F) : γ := quotient.lift_on' f F hF @[simp] lemma map'_coe {lc : filter γ} (F : (α → β) → (γ → δ)) (hF : (l.eventually_eq ⇒ lc.eventually_eq) F F) (f : α → β) : map' F hF f = F f := rfl @[simp, norm_cast] lemma coe_eq : (f : germ l β) = g ↔ (f =ᶠ[l] g) := quotient.eq' alias coe_eq ↔ _ filter.eventually_eq.germ_eq /-- Lift a function `β → γ` to a function `germ l β → germ l γ`. -/ def map (op : β → γ) : germ l β → germ l γ := map' ((∘) op) $ λ f g H, H.mono $ λ x H, congr_arg op H @[simp] lemma map_coe (op : β → γ) (f : α → β) : map op (f : germ l β) = op ∘ f := rfl @[simp] lemma map_id : map id = (id : germ l β → germ l β) := by { ext ⟨f⟩, refl } lemma map_map (op₁ : γ → δ) (op₂ : β → γ) (f : germ l β) : map op₁ (map op₂ f) = map (op₁ ∘ op₂) f := induction_on f $ λ f, rfl /-- Lift a binary function `β → γ → δ` to a function `germ l β → germ l γ → germ l δ`. -/ def map₂ (op : β → γ → δ) : germ l β → germ l γ → germ l δ := quotient.map₂' (λ f g x, op (f x) (g x)) $ λ f f' Hf g g' Hg, Hg.mp $ Hf.mono $ λ x Hf Hg, by simp only [Hf, Hg] @[simp] lemma map₂_coe (op : β → γ → δ) (f : α → β) (g : α → γ) : map₂ op (f : germ l β) g = λ x, op (f x) (g x) := rfl /-- A germ at `l` of maps from `α` to `β` tends to `lb : filter β` if it is represented by a map which tends to `lb` along `l`. -/ protected def tendsto (f : germ l β) (lb : filter β) : Prop := lift_on f (λ f, tendsto f l lb) $ λ f g H, propext (tendsto_congr' H) @[simp, norm_cast] lemma coe_tendsto {f : α → β} {lb : filter β} : (f : germ l β).tendsto lb ↔ tendsto f l lb := iff.rfl alias coe_tendsto ↔ _ filter.tendsto.germ_tendsto /-- Given two germs `f : germ l β`, and `g : germ lc α`, where `l : filter α`, if `g` tends to `l`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def comp_tendsto' (f : germ l β) {lc : filter γ} (g : germ lc α) (hg : g.tendsto l) : germ lc β := lift_on f (λ f, g.map f) $ λ f₁ f₂ hF, (induction_on g $ λ g hg, coe_eq.2 $ hg.eventually hF) hg @[simp] lemma coe_comp_tendsto' (f : α → β) {lc : filter γ} {g : germ lc α} (hg : g.tendsto l) : (f : germ l β).comp_tendsto' g hg = g.map f := rfl /-- Given a germ `f : germ l β` and a function `g : γ → α`, where `l : filter α`, if `g` tends to `l` along `lc : filter γ`, then the composition `f ∘ g` is well-defined as a germ at `lc`. -/ def comp_tendsto (f : germ l β) {lc : filter γ} (g : γ → α) (hg : tendsto g lc l) : germ lc β := f.comp_tendsto' _ hg.germ_tendsto @[simp] lemma coe_comp_tendsto (f : α → β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : (f : germ l β).comp_tendsto g hg = f ∘ g := rfl @[simp] lemma comp_tendsto'_coe (f : germ l β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : f.comp_tendsto' _ hg.germ_tendsto = f.comp_tendsto g hg := rfl @[simp, norm_cast] lemma const_inj [ne_bot l] {a b : β} : (↑a : germ l β) = ↑b ↔ a = b := coe_eq.trans $ const_eventually_eq @[simp] lemma map_const (l : filter α) (a : β) (f : β → γ) : (↑a : germ l β).map f = ↑(f a) := rfl @[simp] lemma map₂_const (l : filter α) (b : β) (c : γ) (f : β → γ → δ) : map₂ f (↑b : germ l β) ↑c = ↑(f b c) := rfl @[simp] lemma const_comp_tendsto {l : filter α} (b : β) {lc : filter γ} {g : γ → α} (hg : tendsto g lc l) : (↑b : germ l β).comp_tendsto g hg = ↑b := rfl @[simp] lemma const_comp_tendsto' {l : filter α} (b : β) {lc : filter γ} {g : germ lc α} (hg : g.tendsto l) : (↑b : germ l β).comp_tendsto' g hg = ↑b := induction_on g (λ _ _, rfl) hg /-- Lift a predicate on `β` to `germ l β`. -/ def lift_pred (p : β → Prop) (f : germ l β) : Prop := lift_on f (λ f, ∀ᶠ x in l, p (f x)) $ λ f g H, propext $ eventually_congr $ H.mono $ λ x hx, hx ▸ iff.rfl @[simp] lemma lift_pred_coe {p : β → Prop} {f : α → β} : lift_pred p (f : germ l β) ↔ ∀ᶠ x in l, p (f x) := iff.rfl lemma lift_pred_const {p : β → Prop} {x : β} (hx : p x) : lift_pred p (↑x : germ l β) := eventually_of_forall $ λ y, hx @[simp] lemma lift_pred_const_iff [ne_bot l] {p : β → Prop} {x : β} : lift_pred p (↑x : germ l β) ↔ p x := @eventually_const _ _ _ (p x) /-- Lift a relation `r : β → γ → Prop` to `germ l β → germ l γ → Prop`. -/ def lift_rel (r : β → γ → Prop) (f : germ l β) (g : germ l γ) : Prop := quotient.lift_on₂' f g (λ f g, ∀ᶠ x in l, r (f x) (g x)) $ λ f g f' g' Hf Hg, propext $ eventually_congr $ Hg.mp $ Hf.mono $ λ x hf hg, hf ▸ hg ▸ iff.rfl @[simp] lemma lift_rel_coe {r : β → γ → Prop} {f : α → β} {g : α → γ} : lift_rel r (f : germ l β) g ↔ ∀ᶠ x in l, r (f x) (g x) := iff.rfl lemma lift_rel_const {r : β → γ → Prop} {x : β} {y : γ} (h : r x y) : lift_rel r (↑x : germ l β) ↑y := eventually_of_forall $ λ _, h @[simp] lemma lift_rel_const_iff [ne_bot l] {r : β → γ → Prop} {x : β} {y : γ} : lift_rel r (↑x : germ l β) ↑y ↔ r x y := @eventually_const _ _ _ (r x y) instance [inhabited β] : inhabited (germ l β) := ⟨↑(default β)⟩ section monoid variables {M : Type*} {G : Type*} @[to_additive] instance [has_mul M] : has_mul (germ l M) := ⟨map₂ (*)⟩ @[simp, norm_cast, to_additive] lemma coe_mul [has_mul M] (f g : α → M) : ↑(f * g) = (f * g : germ l M) := rfl @[to_additive] instance [has_one M] : has_one (germ l M) := ⟨↑(1:M)⟩ @[simp, norm_cast, to_additive] lemma coe_one [has_one M] : ↑(1 : α → M) = (1 : germ l M) := rfl @[to_additive] instance [semigroup M] : semigroup (germ l M) := { mul := (*), mul_assoc := by { rintros ⟨f⟩ ⟨g⟩ ⟨h⟩, simp only [mul_assoc, quot_mk_eq_coe, ← coe_mul] } } @[to_additive] instance [comm_semigroup M] : comm_semigroup (germ l M) := { mul := (*), mul_comm := by { rintros ⟨f⟩ ⟨g⟩, simp only [mul_comm, quot_mk_eq_coe, ← coe_mul] }, .. germ.semigroup } @[to_additive add_left_cancel_semigroup] instance [left_cancel_semigroup M] : left_cancel_semigroup (germ l M) := { mul := (*), mul_left_cancel := λ f₁ f₂ f₃, induction_on₃ f₁ f₂ f₃ $ λ f₁ f₂ f₃ H, coe_eq.2 ((coe_eq.1 H).mono $ λ x, mul_left_cancel), .. germ.semigroup } @[to_additive add_right_cancel_semigroup] instance [right_cancel_semigroup M] : right_cancel_semigroup (germ l M) := { mul := (*), mul_right_cancel := λ f₁ f₂ f₃, induction_on₃ f₁ f₂ f₃ $ λ f₁ f₂ f₃ H, coe_eq.2 $ (coe_eq.1 H).mono $ λ x, mul_right_cancel, .. germ.semigroup } @[to_additive] instance [monoid M] : monoid (germ l M) := { mul := (*), one := 1, one_mul := λ f, induction_on f $ λ f, by { norm_cast, rw [one_mul] }, mul_one := λ f, induction_on f $ λ f, by { norm_cast, rw [mul_one] }, .. germ.semigroup } /-- coercion from functions to germs as a monoid homomorphism. -/ @[to_additive] def coe_mul_hom [monoid M] (l : filter α) : (α → M) →* germ l M := ⟨coe, rfl, λ f g, rfl⟩ /-- coercion from functions to germs as an additive monoid homomorphism. -/ add_decl_doc coe_add_hom @[simp, to_additive] lemma coe_coe_mul_hom [monoid M] : (coe_mul_hom l : (α → M) → germ l M) = coe := rfl @[to_additive] instance [comm_monoid M] : comm_monoid (germ l M) := { mul := (*), one := 1, .. germ.comm_semigroup, .. germ.monoid } @[to_additive] instance [has_inv G] : has_inv (germ l G) := ⟨map has_inv.inv⟩ @[simp, norm_cast, to_additive] lemma coe_inv [has_inv G] (f : α → G) : ↑f⁻¹ = (f⁻¹ : germ l G) := rfl @[to_additive] instance [has_div M] : has_div (germ l M) := ⟨map₂ (/)⟩ @[simp, norm_cast, to_additive] lemma coe_div [has_div M] (f g : α → M) : ↑(f / g) = (f / g : germ l M) := rfl @[to_additive] instance [div_inv_monoid G] : div_inv_monoid (germ l G) := { inv := has_inv.inv, div := has_div.div, div_eq_mul_inv := by { rintros ⟨f⟩ ⟨g⟩, exact congr_arg (quot.mk _) (div_eq_mul_inv f g) }, .. germ.monoid } @[to_additive] instance [group G] : group (germ l G) := { mul := (*), one := 1, mul_left_inv := by { rintros ⟨f⟩, exact congr_arg (quot.mk _) (mul_left_inv f) }, .. germ.div_inv_monoid } @[to_additive] instance [comm_group G] : comm_group (germ l G) := { mul := (*), one := 1, inv := has_inv.inv, .. germ.group, .. germ.comm_monoid } end monoid section ring variables {R : Type*} instance nontrivial [nontrivial R] [ne_bot l] : nontrivial (germ l R) := let ⟨x, y, h⟩ := exists_pair_ne R in ⟨⟨↑x, ↑y, mt const_inj.1 h⟩⟩ instance [mul_zero_class R] : mul_zero_class (germ l R) := { zero := 0, mul := (*), mul_zero := λ f, induction_on f $ λ f, by { norm_cast, rw [mul_zero] }, zero_mul := λ f, induction_on f $ λ f, by { norm_cast, rw [zero_mul] } } instance [distrib R] : distrib (germ l R) := { mul := (*), add := (+), left_distrib := λ f g h, induction_on₃ f g h $ λ f g h, by { norm_cast, rw [left_distrib] }, right_distrib := λ f g h, induction_on₃ f g h $ λ f g h, by { norm_cast, rw [right_distrib] } } instance [semiring R] : semiring (germ l R) := { .. germ.add_comm_monoid, .. germ.monoid, .. germ.distrib, .. germ.mul_zero_class } /-- Coercion `(α → R) → germ l R` as a `ring_hom`. -/ def coe_ring_hom [semiring R] (l : filter α) : (α → R) →+* germ l R := { to_fun := coe, .. (coe_mul_hom l : _ →* germ l R), .. (coe_add_hom l : _ →+ germ l R) } @[simp] lemma coe_coe_ring_hom [semiring R] : (coe_ring_hom l : (α → R) → germ l R) = coe := rfl instance [ring R] : ring (germ l R) := { .. germ.add_comm_group, .. germ.monoid, .. germ.distrib, .. germ.mul_zero_class } instance [comm_semiring R] : comm_semiring (germ l R) := { .. germ.semiring, .. germ.comm_monoid } instance [comm_ring R] : comm_ring (germ l R) := { .. germ.ring, .. germ.comm_monoid } end ring section module variables {M N R : Type*} instance [has_scalar M β] : has_scalar M (germ l β) := ⟨λ c, map ((•) c)⟩ instance has_scalar' [has_scalar M β] : has_scalar (germ l M) (germ l β) := ⟨map₂ (•)⟩ @[simp, norm_cast] lemma coe_smul [has_scalar M β] (c : M) (f : α → β) : ↑(c • f) = (c • f : germ l β) := rfl @[simp, norm_cast] lemma coe_smul' [has_scalar M β] (c : α → M) (f : α → β) : ↑(c • f) = (c : germ l M) • (f : germ l β) := rfl instance [monoid M] [mul_action M β] : mul_action M (germ l β) := { one_smul := λ f, induction_on f $ λ f, by { norm_cast, simp only [one_smul] }, mul_smul := λ c₁ c₂ f, induction_on f $ λ f, by { norm_cast, simp only [mul_smul] } } instance mul_action' [monoid M] [mul_action M β] : mul_action (germ l M) (germ l β) := { one_smul := λ f, induction_on f $ λ f, by simp only [← coe_one, ← coe_smul', one_smul], mul_smul := λ c₁ c₂ f, induction_on₃ c₁ c₂ f $ λ c₁ c₂ f, by { norm_cast, simp only [mul_smul] } } instance [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action M (germ l N) := { smul_add := λ c f g, induction_on₂ f g $ λ f g, by { norm_cast, simp only [smul_add] }, smul_zero := λ c, by simp only [← coe_zero, ← coe_smul, smul_zero] } instance distrib_mul_action' [monoid M] [add_monoid N] [distrib_mul_action M N] : distrib_mul_action (germ l M) (germ l N) := { smul_add := λ c f g, induction_on₃ c f g $ λ c f g, by { norm_cast, simp only [smul_add] }, smul_zero := λ c, induction_on c $ λ c, by simp only [← coe_zero, ← coe_smul', smul_zero] } instance [semiring R] [add_comm_monoid M] [module R M] : module R (germ l M) := { add_smul := λ c₁ c₂ f, induction_on f $ λ f, by { norm_cast, simp only [add_smul] }, zero_smul := λ f, induction_on f $ λ f, by { norm_cast, simp only [zero_smul, coe_zero] } } instance module' [semiring R] [add_comm_monoid M] [module R M] : module (germ l R) (germ l M) := { add_smul := λ c₁ c₂ f, induction_on₃ c₁ c₂ f $ λ c₁ c₂ f, by { norm_cast, simp only [add_smul] }, zero_smul := λ f, induction_on f $ λ f, by simp only [← coe_zero, ← coe_smul', zero_smul] } end module instance [has_le β] : has_le (germ l β) := ⟨lift_rel (≤)⟩ @[simp] lemma coe_le [has_le β] : (f : germ l β) ≤ g ↔ (f ≤ᶠ[l] g) := iff.rfl lemma le_def [has_le β] : ((≤) : germ l β → germ l β → Prop) = lift_rel (≤) := rfl lemma const_le [has_le β] {x y : β} (h : x ≤ y) : (↑x : germ l β) ≤ ↑y := lift_rel_const h @[simp, norm_cast] lemma const_le_iff [has_le β] [ne_bot l] {x y : β} : (↑x : germ l β) ≤ ↑y ↔ x ≤ y := lift_rel_const_iff instance [preorder β] : preorder (germ l β) := { le := (≤), le_refl := λ f, induction_on f $ eventually_le.refl l, le_trans := λ f₁ f₂ f₃, induction_on₃ f₁ f₂ f₃ $ λ f₁ f₂ f₃, eventually_le.trans } instance [partial_order β] : partial_order (germ l β) := { le := (≤), le_antisymm := λ f g, induction_on₂ f g $ λ f g h₁ h₂, (eventually_le.antisymm h₁ h₂).germ_eq, .. germ.preorder } instance [has_bot β] : has_bot (germ l β) := ⟨↑(⊥:β)⟩ @[simp, norm_cast] lemma const_bot [has_bot β] : (↑(⊥:β) : germ l β) = ⊥ := rfl instance [has_le β] [order_bot β] : order_bot (germ l β) := { bot := ⊥, bot_le := λ f, induction_on f $ λ f, eventually_of_forall $ λ x, bot_le } instance [has_top β] : has_top (germ l β) := ⟨↑(⊤:β)⟩ @[simp, norm_cast] lemma const_top [has_top β] : (↑(⊤:β) : germ l β) = ⊤ := rfl instance [has_le β] [order_top β] : order_top (germ l β) := { top := ⊤, le_top := λ f, induction_on f $ λ f, eventually_of_forall $ λ x, le_top } instance [has_sup β] : has_sup (germ l β) := ⟨map₂ (⊔)⟩ @[simp, norm_cast] lemma const_sup [has_sup β] (a b : β) : ↑(a ⊔ b) = (↑a ⊔ ↑b : germ l β) := rfl instance [has_inf β] : has_inf (germ l β) := ⟨map₂ (⊓)⟩ @[simp, norm_cast] lemma const_inf [has_inf β] (a b : β) : ↑(a ⊓ b) = (↑a ⊓ ↑b : germ l β) := rfl instance [semilattice_sup β] : semilattice_sup (germ l β) := { sup := (⊔), le_sup_left := λ f g, induction_on₂ f g $ λ f g, eventually_of_forall $ λ x, le_sup_left, le_sup_right := λ f g, induction_on₂ f g $ λ f g, eventually_of_forall $ λ x, le_sup_right, sup_le := λ f₁ f₂ g, induction_on₃ f₁ f₂ g $ λ f₁ f₂ g h₁ h₂, h₂.mp $ h₁.mono $ λ x, sup_le, .. germ.partial_order } instance [semilattice_inf β] : semilattice_inf (germ l β) := { inf := (⊓), inf_le_left := λ f g, induction_on₂ f g $ λ f g, eventually_of_forall $ λ x, inf_le_left, inf_le_right := λ f g, induction_on₂ f g $ λ f g, eventually_of_forall $ λ x, inf_le_right, le_inf := λ f₁ f₂ g, induction_on₃ f₁ f₂ g $ λ f₁ f₂ g h₁ h₂, h₂.mp $ h₁.mono $ λ x, le_inf, .. germ.partial_order } instance [semilattice_inf_bot β] : semilattice_inf_bot (germ l β) := { .. germ.semilattice_inf, .. germ.order_bot } instance [semilattice_sup_bot β] : semilattice_sup_bot (germ l β) := { .. germ.semilattice_sup, .. germ.order_bot } instance [semilattice_inf_top β] : semilattice_inf_top (germ l β) := { .. germ.semilattice_inf, .. germ.order_top } instance [semilattice_sup_top β] : semilattice_sup_top (germ l β) := { .. germ.semilattice_sup, .. germ.order_top } instance [lattice β] : lattice (germ l β) := { .. germ.semilattice_sup, .. germ.semilattice_inf } instance [bounded_lattice β] : bounded_lattice (germ l β) := { .. germ.lattice, .. germ.order_bot, .. germ.order_top } @[to_additive] instance [ordered_cancel_comm_monoid β] : ordered_cancel_comm_monoid (germ l β) := { mul_le_mul_left := λ f g, induction_on₂ f g $ λ f g H h, induction_on h $ λ h, H.mono $ λ x H, mul_le_mul_left' H _, le_of_mul_le_mul_left := λ f g h, induction_on₃ f g h $ λ f g h H, H.mono $ λ x, le_of_mul_le_mul_left', .. germ.partial_order, .. germ.comm_monoid, .. germ.left_cancel_semigroup } @[to_additive] instance ordered_comm_group [ordered_comm_group β] : ordered_comm_group (germ l β) := { mul_le_mul_left := λ f g, induction_on₂ f g $ λ f g H h, induction_on h $ λ h, H.mono $ λ x H, mul_le_mul_left' H _, .. germ.partial_order, .. germ.comm_group } end germ end filter
a2251b665826e91681cd60b38cac8e46f39dfa07
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/order/iterate_auto.lean
1ed403d7ee5986d1539c50f6601b953b93db8d3f
[]
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
5,241
lean
/- Copyright (c) 2020 Yury G. Kudryashov. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Yury G. Kudryashov -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.order.basic import Mathlib.logic.function.iterate import Mathlib.data.nat.basic import Mathlib.PostPort universes u_1 namespace Mathlib /-! # Inequalities on iterates In this file we prove some inequalities comparing `f^[n] x` and `g^[n] x` where `f` and `g` are two self-maps that commute with each other. Current selection of inequalities is motivated by formalization of the rotation number of a circle homeomorphism. -/ namespace monotone theorem seq_le_seq {α : Type u_1} [preorder α] {f : α → α} {x : ℕ → α} {y : ℕ → α} (hf : monotone f) (n : ℕ) (h₀ : x 0 ≤ y 0) (hx : ∀ (k : ℕ), k < n → x (k + 1) ≤ f (x k)) (hy : ∀ (k : ℕ), k < n → f (y k) ≤ y (k + 1)) : x n ≤ y n := sorry theorem seq_pos_lt_seq_of_lt_of_le {α : Type u_1} [preorder α] {f : α → α} {x : ℕ → α} {y : ℕ → α} (hf : monotone f) {n : ℕ} (hn : 0 < n) (h₀ : x 0 ≤ y 0) (hx : ∀ (k : ℕ), k < n → x (k + 1) < f (x k)) (hy : ∀ (k : ℕ), k < n → f (y k) ≤ y (k + 1)) : x n < y n := sorry theorem seq_pos_lt_seq_of_le_of_lt {α : Type u_1} [preorder α] {f : α → α} {x : ℕ → α} {y : ℕ → α} (hf : monotone f) {n : ℕ} (hn : 0 < n) (h₀ : x 0 ≤ y 0) (hx : ∀ (k : ℕ), k < n → x (k + 1) ≤ f (x k)) (hy : ∀ (k : ℕ), k < n → f (y k) < y (k + 1)) : x n < y n := seq_pos_lt_seq_of_lt_of_le (monotone.order_dual hf) hn h₀ hy hx theorem seq_lt_seq_of_lt_of_le {α : Type u_1} [preorder α] {f : α → α} {x : ℕ → α} {y : ℕ → α} (hf : monotone f) (n : ℕ) (h₀ : x 0 < y 0) (hx : ∀ (k : ℕ), k < n → x (k + 1) < f (x k)) (hy : ∀ (k : ℕ), k < n → f (y k) ≤ y (k + 1)) : x n < y n := sorry theorem seq_lt_seq_of_le_of_lt {α : Type u_1} [preorder α] {f : α → α} {x : ℕ → α} {y : ℕ → α} (hf : monotone f) (n : ℕ) (h₀ : x 0 < y 0) (hx : ∀ (k : ℕ), k < n → x (k + 1) ≤ f (x k)) (hy : ∀ (k : ℕ), k < n → f (y k) < y (k + 1)) : x n < y n := seq_lt_seq_of_lt_of_le (monotone.order_dual hf) n h₀ hy hx end monotone namespace function namespace commute theorem iterate_le_of_map_le {α : Type u_1} [preorder α] {f : α → α} {g : α → α} (h : commute f g) (hf : monotone f) (hg : monotone g) {x : α} (hx : f x ≤ g x) (n : ℕ) : nat.iterate f n x ≤ nat.iterate g n x := sorry theorem iterate_pos_lt_of_map_lt {α : Type u_1} [preorder α] {f : α → α} {g : α → α} (h : commute f g) (hf : monotone f) (hg : strict_mono g) {x : α} (hx : f x < g x) {n : ℕ} (hn : 0 < n) : nat.iterate f n x < nat.iterate g n x := sorry theorem iterate_pos_lt_of_map_lt' {α : Type u_1} [preorder α] {f : α → α} {g : α → α} (h : commute f g) (hf : strict_mono f) (hg : monotone g) {x : α} (hx : f x < g x) {n : ℕ} (hn : 0 < n) : nat.iterate f n x < nat.iterate g n x := iterate_pos_lt_of_map_lt (symm h) (monotone.order_dual hg) (strict_mono.order_dual hf) hx hn theorem iterate_pos_lt_iff_map_lt {α : Type u_1} [linear_order α] {f : α → α} {g : α → α} (h : commute f g) (hf : monotone f) (hg : strict_mono g) {x : α} {n : ℕ} (hn : 0 < n) : nat.iterate f n x < nat.iterate g n x ↔ f x < g x := sorry theorem iterate_pos_lt_iff_map_lt' {α : Type u_1} [linear_order α] {f : α → α} {g : α → α} (h : commute f g) (hf : strict_mono f) (hg : monotone g) {x : α} {n : ℕ} (hn : 0 < n) : nat.iterate f n x < nat.iterate g n x ↔ f x < g x := iterate_pos_lt_iff_map_lt (symm h) (monotone.order_dual hg) (strict_mono.order_dual hf) hn theorem iterate_pos_le_iff_map_le {α : Type u_1} [linear_order α] {f : α → α} {g : α → α} (h : commute f g) (hf : monotone f) (hg : strict_mono g) {x : α} {n : ℕ} (hn : 0 < n) : nat.iterate f n x ≤ nat.iterate g n x ↔ f x ≤ g x := sorry theorem iterate_pos_le_iff_map_le' {α : Type u_1} [linear_order α] {f : α → α} {g : α → α} (h : commute f g) (hf : strict_mono f) (hg : monotone g) {x : α} {n : ℕ} (hn : 0 < n) : nat.iterate f n x ≤ nat.iterate g n x ↔ f x ≤ g x := sorry theorem iterate_pos_eq_iff_map_eq {α : Type u_1} [linear_order α] {f : α → α} {g : α → α} (h : commute f g) (hf : monotone f) (hg : strict_mono g) {x : α} {n : ℕ} (hn : 0 < n) : nat.iterate f n x = nat.iterate g n x ↔ f x = g x := sorry end commute end function namespace monotone /-- If `f ≤ g` and `f` is monotone, then `f^[n] ≤ g^[n]`. -/ theorem iterate_le_of_le {α : Type u_1} [preorder α] {f : α → α} {g : α → α} (hf : monotone f) (h : f ≤ g) (n : ℕ) : nat.iterate f n ≤ nat.iterate g n := sorry /-- If `f ≤ g` and `f` is monotone, then `f^[n] ≤ g^[n]`. -/ theorem iterate_ge_of_ge {α : Type u_1} [preorder α] {f : α → α} {g : α → α} (hg : monotone g) (h : f ≤ g) (n : ℕ) : nat.iterate f n ≤ nat.iterate g n := iterate_le_of_le (monotone.order_dual hg) h n end Mathlib
81c5eb34a376d5fbaa50476c72d53badfa017077
053e034f0e0e1fe8e0505b2354923e53b2bc5311
/src/exercises_sources/friday/analysis.lean
e4b7c7237a7955f0588f282b4dae0137e72faf86
[]
permissive
eric-wieser/lftcm2020
58d2e207f9862005f2ac25ac58f0cfa50c24116e
042ef8cbe34f3ca91207b8ba379e837c3872945d
refs/heads/master
1,669,034,846,341
1,594,981,386,000
1,594,981,386,000
280,398,568
0
0
MIT
1,594,982,530,000
1,594,982,530,000
null
UTF-8
Lean
false
false
1,097
lean
import analysis.analytic.composition import analysis.normed_space.real_inner_product import topology.metric_space.pi_Lp import analysis.calculus.iterated_deriv namespace lftcm open real /-! # Derivatives Lean can automatically compute some simple derivatives using `simp` tactic. -/ example : deriv (λ x : ℝ, x^5) 6 = 5 * 6^4 := sorry example (x₀ : ℝ) (h₀ : x₀ ≠ 0) : deriv (λ x:ℝ, 1 / x) x₀ = -1 / x₀^2 := sorry example : deriv sin pi = -1 := sorry -- Sometimes you need `ring` and/or `field_simp` after `simp` example (x₀ : ℝ) (h : x₀ ≠ 0) : deriv (λ x : ℝ, exp(x^2) / x^5) x₀ = (2 * x₀^2 - 5) * exp (x₀^2) / x₀^6 := begin have : x₀^5 ≠ 0, { sorry }, simp [this], sorry end example (a b x₀ : ℝ) (h : x₀ ≠ 1) : deriv (λ x, (a * x + b) / (x - 1)) x₀ = -(a + b) / (x₀ - 1)^2 := begin sorry end -- Currently `simp` is unable to solve the next example -- A PR that will make this example provable `by simp` would be very welcome! example : iterated_deriv 7 (λ x, sin (tan x) - tan (sin x)) 0 = -168 := sorry end lftcm
f89b254f01e373993094b970346b02c22060a4b7
8b9f17008684d796c8022dab552e42f0cb6fb347
/tests/lean/run/match_tac4.lean
62944d07e835f8544a27d32ad35a47b887d7dd89
[ "Apache-2.0" ]
permissive
chubbymaggie/lean
0d06ae25f9dd396306fb02190e89422ea94afd7b
d2c7b5c31928c98f545b16420d37842c43b4ae9a
refs/heads/master
1,611,313,622,901
1,430,266,839,000
1,430,267,083,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
736
lean
notation `⟪`:max t:(foldr `,` (e r, and.intro e r)) `⟫`:0 := t check ⟪ trivial, trivial, trivial ⟫ theorem tst (a b c d : Prop) : a ∧ b ∧ c ∧ d ↔ d ∧ c ∧ b ∧ a := begin apply iff.intro, begin intro H, match H with | ⟪ H₁, H₂, H₃, H₄ ⟫ := ⟪ H₄, H₃, H₂, H₁ ⟫ end end, begin intro H, match H with | ⟪ H₁, H₂, H₃, H₄ ⟫ := begin repeat (apply and.intro | assumption) end end end end print definition tst theorem tst2 (a b c d : Prop) : a ∧ b ∧ c ∧ d ↔ d ∧ c ∧ b ∧ a := begin apply iff.intro, repeat (intro H; repeat (cases H with [H', H] | apply and.intro | assumption)) end print definition tst2
e56daca30abd35da69294b46650364c2f5066270
4fa161becb8ce7378a709f5992a594764699e268
/src/data/support.lean
72375836ec0476bec5e3d2ad31ad1a7a5b398578
[ "Apache-2.0" ]
permissive
laughinggas/mathlib
e4aa4565ae34e46e834434284cb26bd9d67bc373
86dcd5cda7a5017c8b3c8876c89a510a19d49aad
refs/heads/master
1,669,496,232,688
1,592,831,995,000
1,592,831,995,000
274,155,979
0
0
Apache-2.0
1,592,835,190,000
1,592,835,189,000
null
UTF-8
Lean
false
false
4,754
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 order.conditionally_complete_lattice import algebra.big_operators /-! # Support of a function In this file we define `function.support f = {x | f x ≠ 0}` and prove its basic properties. -/ universes u v w x y open set open_locale big_operators namespace function variables {α : Type u} {β : Type v} {ι : Sort w} {A : Type x} {B : Type y} /-- `support` of a function is the set of points `x` such that `f x ≠ 0`. -/ def support [has_zero A] (f : α → A) : set α := {x | f x ≠ 0} lemma nmem_support [has_zero A] {f : α → A} {x : α} : x ∉ support f ↔ f x = 0 := classical.not_not lemma support_binop_subset [has_zero A] (op : A → A → A) (op0 : op 0 0 = 0) (f g : α → A) : support (λ x, op (f x) (g x)) ⊆ support f ∪ support g := λ x hx, classical.by_cases (λ hf : f x = 0, or.inr $ λ hg, hx $ by simp only [hf, hg, op0]) or.inl lemma support_add [add_monoid A] (f g : α → A) : support (λ x, f x + g x) ⊆ support f ∪ support g := support_binop_subset (+) (zero_add _) f g @[simp] lemma support_neg [add_group A] (f : α → A) : support (λ x, -f x) = support f := set.ext $ λ x, not_congr neg_eq_zero lemma support_sub [add_group A] (f g : α → A) : support (λ x, f x - g x) ⊆ support f ∪ support g := support_binop_subset (has_sub.sub) (sub_self _) f g @[simp] lemma support_mul [domain A] (f g : α → A) : support (λ x, f x * g x) = support f ∩ support g := set.ext $ λ x, by simp only [support, ne.def, mul_eq_zero, mem_set_of_eq, mem_inter_iff, not_or_distrib] @[simp] lemma support_mul' {A} [group_with_zero A] (f g : α → A) : support (λ x, f x * g x) = support f ∩ support g := set.ext $ λ x, by simp only [support, ne.def, mul_eq_zero_iff', mem_set_of_eq, mem_inter_iff, not_or_distrib] @[simp] lemma support_inv [division_ring A] (f : α → A) : support (λ x, (f x)⁻¹) = support f := set.ext $ λ x, not_congr inv_eq_zero @[simp] lemma support_div [division_ring A] (f g : α → A) : support (λ x, f x / g x) = support f ∩ support g := by simp [div_eq_mul_inv] lemma support_sup [has_zero A] [semilattice_sup A] (f g : α → A) : support (λ x, (f x) ⊔ (g x)) ⊆ support f ∪ support g := support_binop_subset (⊔) sup_idem f g lemma support_inf [has_zero A] [semilattice_inf A] (f g : α → A) : support (λ x, (f x) ⊓ (g x)) ⊆ support f ∪ support g := support_binop_subset (⊓) inf_idem f g lemma support_max [has_zero A] [decidable_linear_order A] (f g : α → A) : support (λ x, max (f x) (g x)) ⊆ support f ∪ support g := support_sup f g lemma support_min [has_zero A] [decidable_linear_order A] (f g : α → A) : support (λ x, min (f x) (g x)) ⊆ support f ∪ support g := support_inf f g lemma support_supr [has_zero A] [conditionally_complete_lattice A] [nonempty ι] (f : ι → α → A) : support (λ x, ⨆ i, f i x) ⊆ ⋃ i, support (f i) := begin intros x hx, classical, contrapose hx, simp only [mem_Union, not_exists, nmem_support] at hx ⊢, simp only [hx, csupr_const] end lemma support_infi [has_zero A] [conditionally_complete_lattice A] [nonempty ι] (f : ι → α → A) : support (λ x, ⨅ i, f i x) ⊆ ⋃ i, support (f i) := @support_supr _ _ (order_dual A) ⟨(0:A)⟩ _ _ f lemma support_sum [add_comm_monoid A] (s : finset α) (f : α → β → A) : support (λ x, ∑ i in s, f i x) ⊆ ⋃ i ∈ s, support (f i) := begin intros x hx, classical, contrapose hx, simp only [mem_Union, not_exists, nmem_support] at hx ⊢, exact finset.sum_eq_zero hx end -- TODO: Drop `classical` once #2332 is merged lemma support_prod [integral_domain A] (s : finset α) (f : α → β → A) : support (λ x, ∏ i in s, f i x) = ⋂ i ∈ s, support (f i) := set.ext $ λ x, by classical; simp only [support, ne.def, finset.prod_eq_zero_iff, mem_set_of_eq, set.mem_Inter, not_exists] lemma support_comp [has_zero A] [has_zero B] (g : A → B) (hg : g 0 = 0) (f : α → A) : support (g ∘ f) ⊆ support f := λ x, mt $ λ h, by simp [(∘), *] lemma support_comp' [has_zero A] [has_zero B] (g : A → B) (hg : g 0 = 0) (f : α → A) : support (λ x, g (f x)) ⊆ support f := support_comp g hg f lemma support_comp_eq [has_zero A] [has_zero B] (g : A → B) (hg : ∀ {x}, g x = 0 ↔ x = 0) (f : α → A) : support (g ∘ f) = support f := set.ext $ λ x, not_congr hg lemma support_comp_eq' [has_zero A] [has_zero B] (g : A → B) (hg : ∀ {x}, g x = 0 ↔ x = 0) (f : α → A) : support (λ x, g (f x)) = support f := support_comp_eq g @hg f end function
deb395a337d085fb6f665361f80595b07068171e
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/ring_theory/witt_vector/isocrystal.lean
74f49caeefa05e9ea8550884c216b7f075e01316
[ "Apache-2.0" ]
permissive
alreadydone/mathlib
dc0be621c6c8208c581f5170a8216c5ba6721927
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
refs/heads/master
1,685,523,275,196
1,670,184,141,000
1,670,184,141,000
287,574,545
0
0
Apache-2.0
1,670,290,714,000
1,597,421,623,000
Lean
UTF-8
Lean
false
false
8,642
lean
/- Copyright (c) 2022 Heather Macbeth. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Heather Macbeth -/ import ring_theory.witt_vector.frobenius_fraction_field /-! ## F-isocrystals over a perfect field When `k` is an integral domain, so is `𝕎 k`, and we can consider its field of fractions `K(p, k)`. The endomorphism `witt_vector.frobenius` lifts to `φ : K(p, k) → K(p, k)`; if `k` is perfect, `φ` is an automorphism. Let `k` be a perfect integral domain. Let `V` be a vector space over `K(p,k)`. An *isocrystal* is a bijective map `V → V` that is `φ`-semilinear. A theorem of Dieudonné and Manin classifies the finite-dimensional isocrystals over algebraically closed fields. In the one-dimensional case, this classification states that the isocrystal structures are parametrized by their "slope" `m : ℤ`. Any one-dimensional isocrystal is isomorphic to `φ(p^m • x) : K(p,k) → K(p,k)` for some `m`. This file proves this one-dimensional case of the classification theorem. The construction is described in Dupuis, Lewis, and Macbeth, [Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022]. ## Main declarations * `witt_vector.isocrystal`: a vector space over the field `K(p, k)` additionally equipped with a Frobenius-linear automorphism. * `witt_vector.isocrystal_classification`: a one-dimensional isocrystal admits an isomorphism to one of the standard one-dimensional isocrystals. ## Notation This file introduces notation in the locale `isocrystal`. * `K(p, k)`: `fraction_ring (witt_vector p k)` * `φ(p, k)`: `witt_vector.fraction_ring.frobenius_ring_hom p k` * `M →ᶠˡ[p, k] M₂`: `linear_map (witt_vector.fraction_ring.frobenius_ring_hom p k) M M₂` * `M ≃ᶠˡ[p, k] M₂`: `linear_equiv (witt_vector.fraction_ring.frobenius_ring_hom p k) M M₂` * `Φ(p, k)`: `witt_vector.isocrystal.frobenius p k` * `M →ᶠⁱ[p, k] M₂`: `witt_vector.isocrystal_hom p k M M₂` * `M ≃ᶠⁱ[p, k] M₂`: `witt_vector.isocrystal_equiv p k M M₂` ## References * [Formalized functional analysis via semilinear maps][dupuis-lewis-macbeth2022] * [Theory of commutative formal groups over fields of finite characteristic][manin1963] * <https://www.math.ias.edu/~lurie/205notes/Lecture26-Isocrystals.pdf> -/ noncomputable theory open finite_dimensional namespace witt_vector variables (p : ℕ) [fact p.prime] variables (k : Type*) [comm_ring k] localized "notation (name := witt_vector.fraction_ring) `K(`p`, `k`)` := fraction_ring (witt_vector p k)" in isocrystal section perfect_ring variables [is_domain k] [char_p k p] [perfect_ring k p] /-! ### Frobenius-linear maps -/ /-- The Frobenius automorphism of `k` induces an automorphism of `K`. -/ def fraction_ring.frobenius : K(p, k) ≃+* K(p, k) := is_fraction_ring.field_equiv_of_ring_equiv (frobenius_equiv p k) /-- The Frobenius automorphism of `k` induces an endomorphism of `K`. For notation purposes. -/ def fraction_ring.frobenius_ring_hom : K(p, k) →+* K(p, k) := fraction_ring.frobenius p k localized "notation (name := witt_vector.frobenius_ring_hom) `φ(`p`, `k`)` := witt_vector.fraction_ring.frobenius_ring_hom p k" in isocrystal instance inv_pair₁ : ring_hom_inv_pair (φ(p, k)) _ := ring_hom_inv_pair.of_ring_equiv (fraction_ring.frobenius p k) instance inv_pair₂ : ring_hom_inv_pair ((fraction_ring.frobenius p k).symm : K(p, k) →+* K(p, k)) _ := ring_hom_inv_pair.of_ring_equiv (fraction_ring.frobenius p k).symm localized "notation (name := frobenius_ring_hom.linear_map) M ` →ᶠˡ[`:50 p `, ` k `] ` M₂ := linear_map (witt_vector.fraction_ring.frobenius_ring_hom p k) M M₂" in isocrystal localized "notation (name := frobenius_ring_hom.linear_equiv) M ` ≃ᶠˡ[`:50 p `, ` k `] ` M₂ := linear_equiv (witt_vector.fraction_ring.frobenius_ring_hom p k) M M₂" in isocrystal /-! ### Isocrystals -/ /-- An isocrystal is a vector space over the field `K(p, k)` additionally equipped with a Frobenius-linear automorphism. -/ class isocrystal (V : Type*) [add_comm_group V] extends module K(p, k) V := ( frob : V ≃ᶠˡ[p, k] V ) variables (V : Type*) [add_comm_group V] [isocrystal p k V] variables (V₂ : Type*) [add_comm_group V₂] [isocrystal p k V₂] variables {V} /-- Project the Frobenius automorphism from an isocrystal. Denoted by `Φ(p, k)` when V can be inferred. -/ def isocrystal.frobenius : V ≃ᶠˡ[p, k] V := @isocrystal.frob p _ k _ _ _ _ _ _ _ variables (V) localized "notation `Φ(`p`, `k`)` := witt_vector.isocrystal.frobenius p k" in isocrystal /-- A homomorphism between isocrystals respects the Frobenius map. -/ @[nolint has_nonempty_instance] structure isocrystal_hom extends V →ₗ[K(p, k)] V₂ := ( frob_equivariant : ∀ x : V, Φ(p, k) (to_linear_map x) = to_linear_map (Φ(p, k) x) ) /-- An isomorphism between isocrystals respects the Frobenius map. -/ @[nolint has_nonempty_instance] structure isocrystal_equiv extends V ≃ₗ[K(p, k)] V₂ := ( frob_equivariant : ∀ x : V, Φ(p, k) (to_linear_equiv x) = to_linear_equiv (Φ(p, k) x) ) localized "notation (name := isocrystal_hom) M ` →ᶠⁱ[`:50 p `, ` k `] ` M₂ := witt_vector.isocrystal_hom p k M M₂" in isocrystal localized "notation (name := isocrystal_equiv) M ` ≃ᶠⁱ[`:50 p `, ` k `] ` M₂ := witt_vector.isocrystal_equiv p k M M₂" in isocrystal end perfect_ring open_locale isocrystal /-! ### Classification of isocrystals in dimension 1 -/ /-- A helper instance for type class inference. -/ local attribute [instance] def fraction_ring.module : module K(p, k) K(p, k) := semiring.to_module /-- Type synonym for `K(p, k)` to carry the standard 1-dimensional isocrystal structure of slope `m : ℤ`. -/ @[nolint unused_arguments has_nonempty_instance, derive [add_comm_group, module K(p, k)]] def standard_one_dim_isocrystal (m : ℤ) : Type* := K(p, k) section perfect_ring variables [is_domain k] [char_p k p] [perfect_ring k p] /-- The standard one-dimensional isocrystal of slope `m : ℤ` is an isocrystal. -/ instance (m : ℤ) : isocrystal p k (standard_one_dim_isocrystal p k m) := { frob := (fraction_ring.frobenius p k).to_semilinear_equiv.trans (linear_equiv.smul_of_ne_zero _ _ _ (zpow_ne_zero m (witt_vector.fraction_ring.p_nonzero p k))) } @[simp] lemma standard_one_dim_isocrystal.frobenius_apply (m : ℤ) (x : standard_one_dim_isocrystal p k m) : Φ(p, k) x = (p:K(p, k)) ^ m • φ(p, k) x := rfl end perfect_ring /-- A one-dimensional isocrystal over an algebraically closed field admits an isomorphism to one of the standard (indexed by `m : ℤ`) one-dimensional isocrystals. -/ theorem isocrystal_classification (k : Type*) [field k] [is_alg_closed k] [char_p k p] (V : Type*) [add_comm_group V] [isocrystal p k V] (h_dim : finrank K(p, k) V = 1) : ∃ (m : ℤ), nonempty (standard_one_dim_isocrystal p k m ≃ᶠⁱ[p, k] V) := begin haveI : nontrivial V := finite_dimensional.nontrivial_of_finrank_eq_succ h_dim, obtain ⟨x, hx⟩ : ∃ x : V, x ≠ 0 := exists_ne 0, have : Φ(p, k) x ≠ 0 := by simpa only [map_zero] using Φ(p,k).injective.ne hx, obtain ⟨a, ha, hax⟩ : ∃ a : K(p, k), a ≠ 0 ∧ Φ(p, k) x = a • x, { rw finrank_eq_one_iff_of_nonzero' x hx at h_dim, obtain ⟨a, ha⟩ := h_dim (Φ(p, k) x), refine ⟨a, _, ha.symm⟩, intros ha', apply this, simp only [←ha, ha', zero_smul] }, obtain ⟨b, hb, m, hmb⟩ := witt_vector.exists_frobenius_solution_fraction_ring p ha, replace hmb : φ(p, k) b * a = p ^ m * b := by convert hmb, use m, let F₀ : standard_one_dim_isocrystal p k m →ₗ[K(p,k)] V := linear_map.to_span_singleton K(p, k) V x, let F : standard_one_dim_isocrystal p k m ≃ₗ[K(p,k)] V, { refine linear_equiv.of_bijective F₀ _ _, { rw ← linear_map.ker_eq_bot, exact linear_map.ker_to_span_singleton K(p, k) V hx }, { rw ← linear_map.range_eq_top, rw ← (finrank_eq_one_iff_of_nonzero x hx).mp h_dim, rw linear_map.span_singleton_eq_range } }, refine ⟨⟨(linear_equiv.smul_of_ne_zero K(p, k) _ _ hb).trans F, _⟩⟩, intros c, rw [linear_equiv.trans_apply, linear_equiv.trans_apply, linear_equiv.smul_of_ne_zero_apply, linear_equiv.smul_of_ne_zero_apply, linear_equiv.map_smul, linear_equiv.map_smul], simp only [hax, linear_equiv.of_bijective_apply, linear_map.to_span_singleton_apply, linear_equiv.map_smulₛₗ, standard_one_dim_isocrystal.frobenius_apply, algebra.id.smul_eq_mul], simp only [←mul_smul], congr' 1, linear_combination φ(p,k) c * hmb, end end witt_vector
1d1c583a1fc367f4c7f5cd250c98e8f2a5519154
3f48345ac9bbaa421714efc9872a0409379bb4ae
/src/set_category/colimits/Sum.lean
e6f911f4a44e439f9ffbff3d3fcdd2ca66f078d7
[]
no_license
QaisHamarneh/Coalgebra-in-Lean
b4318ee6d83780e5c734eb78fed98b1fe8016f7e
bd0452df98bc64b608e5dfd7babc42c301bb6a46
refs/heads/master
1,663,371,200,241
1,661,004,695,000
1,661,004,695,000
209,798,828
0
0
null
null
null
null
UTF-8
Lean
false
false
3,494
lean
import category_theory.category import category_theory.functor import category_theory.types import help_functions import tactic.tidy universes v u namespace Sum open category_theory set classical function help_functions sum local notation f ` ⊚ `:80 g:80 := category_struct.comp g f /- Sum -/ /-- predicate to determine if S along with e₁ and e₂ is a Sum in category theory definition -/ def is_sum {X : Type v} [category X] {A B : X} (S: X) (e₁ : A ⟶ S) (e₂ : B ⟶ S) :Prop := Π (Q : X) (q₁ : A ⟶ Q) (q₂ : B ⟶ Q), ∃! s : S ⟶ Q, q₁ = s ⊚ e₁ ∧ q₂ = s ⊚ e₂ lemma jointly_epi_cat {X : Type v} [category X] {A B S Q : X} (e₁ : A ⟶ S) (e₂ : B ⟶ S) (is_sm : is_sum S e₁ e₂) (f g: S ⟶ Q) (h1 : f ⊚ e₁ = g ⊚ e₁) (h2 : f ⊚ e₂ = g ⊚ e₂) : f = g := begin have ex : _ := is_sm Q (f ⊚ e₁) (f ⊚ e₂), cases ex with s spec_s, have g_s : g = s := spec_s.2 g ⟨h1, h2⟩, rw g_s, exact spec_s.2 f ⟨rfl, rfl⟩ end lemma jointly_epi {A B Q : Type u} (s s₁: (A ⊕ B) → Q) (h1 : s₁ ∘ inl = s ∘ inl) (h2 : s₁ ∘ inr = s ∘ inr) : s₁ = s := begin have all_ab : ∀ ab : (A ⊕ B) , s₁ ab = s ab := begin intro ab, induction ab, case inl : { have s0 : (s₁ ∘ inl) ab = (s ∘ inl) ab := by rw h1, exact s0 }, case inr : begin have s0 : (s₁ ∘ inr) ab = (s ∘ inr) ab := by rw h2, exact s0 end, end, exact funext all_ab end variables {A B C: Type u} /-- A proof that the disjoint union, which is defined inductively (inl : A → sum, inr : B → sum) in lean is a sum in the category theory definition. -/ lemma disjoint_union_is_sum : is_sum (A ⊕ B) inl inr := begin intros Q q₁ q₂, -- competitor with 2 morphisms show ∃! s : (A ⊕ B) ⟶ Q, (q₁ = s ∘ inl ∧ q₂ = s ∘ inr) , from let s : (A ⊕ B) ⟶ Q := --defining the unique morphism s : sum → Q inductively begin intro ab, induction ab, case inl : begin exact q₁ ab end, case inr : begin exact q₂ ab end, end in have commut_A : q₁ = s ∘ inl := rfl, have commut_B : q₂ = s ∘ inr := rfl, have unique : ∀ s₁ , (q₁ = s₁ ∘ inl ∧ q₂ = s₁ ∘ inr) → s₁ = s := assume s₁ h₁, jointly_epi s s₁ (by rw [← h₁.1 ,commut_A ]) (by rw [← h₁.2 ,commut_B ]), exists_unique.intro s ⟨commut_A , commut_B⟩ unique end end Sum
23307954f9908e6c6222c25e7d8b778c4e768007
d0c6b2ba2af981e9ab0a98f6e169262caad4b9b9
/src/Lean/Meta/AppBuilder.lean
d3983d45a184b2514a6ab6f62d37f0ba10a70055
[ "Apache-2.0" ]
permissive
fizruk/lean4
953b7dcd76e78c17a0743a2c1a918394ab64bbc0
545ed50f83c570f772ade4edbe7d38a078cbd761
refs/heads/master
1,677,655,987,815
1,612,393,885,000
1,612,393,885,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
18,881
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 -/ import Lean.Structure import Lean.Util.Recognizers import Lean.Meta.SynthInstance import Lean.Meta.Check namespace Lean.Meta /-- Return `id e` -/ def mkId (e : Expr) : MetaM Expr := do let type ← inferType e let u ← getLevel type return mkApp2 (mkConst ``id [u]) type e /-- Return `idRhs e` -/ def mkIdRhs (e : Expr) : MetaM Expr := do let type ← inferType e let u ← getLevel type return mkApp2 (mkConst ``idRhs [u]) type e /-- Given `e` s.t. `inferType e` is definitionally equal to `expectedType`, return term `@id expectedType e`. -/ def mkExpectedTypeHint (e : Expr) (expectedType : Expr) : MetaM Expr := do let u ← getLevel expectedType return mkApp2 (mkConst ``id [u]) expectedType e def mkEq (a b : Expr) : MetaM Expr := do let aType ← inferType a let u ← getLevel aType return mkApp3 (mkConst ``Eq [u]) aType a b def mkHEq (a b : Expr) : MetaM Expr := do let aType ← inferType a let bType ← inferType b let u ← getLevel aType return mkApp4 (mkConst ``HEq [u]) aType a bType b def mkEqRefl (a : Expr) : MetaM Expr := do let aType ← inferType a let u ← getLevel aType return mkApp2 (mkConst ``Eq.refl [u]) aType a def mkHEqRefl (a : Expr) : MetaM Expr := do let aType ← inferType a let u ← getLevel aType return mkApp2 (mkConst ``HEq.refl [u]) aType a private def infer (h : Expr) : MetaM Expr := do let hType ← inferType h whnfD hType private def hasTypeMsg (e type : Expr) : MessageData := m!"{indentExpr e}\nhas type{indentExpr type}" private def throwAppBuilderException {α} (op : Name) (msg : MessageData) : MetaM α := throwError! "AppBuilder for '{op}', {msg}" def mkEqSymm (h : Expr) : MetaM Expr := do if h.isAppOf ``Eq.refl then return h else let hType ← infer h match hType.eq? with | some (α, a, b) => let u ← getLevel α return mkApp4 (mkConst ``Eq.symm [u]) α a b h | none => throwAppBuilderException ``Eq.symm ("equality proof expected" ++ hasTypeMsg h hType) def mkEqTrans (h₁ h₂ : Expr) : MetaM Expr := do if h₁.isAppOf ``Eq.refl then return h₂ else if h₂.isAppOf ``Eq.refl then return h₁ else let hType₁ ← infer h₁ let hType₂ ← infer h₂ match hType₁.eq?, hType₂.eq? with | some (α, a, b), some (_, _, c) => let u ← getLevel α return mkApp6 (mkConst ``Eq.trans [u]) α a b c h₁ h₂ | none, _ => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₁ hType₁) | _, none => throwAppBuilderException ``Eq.trans ("equality proof expected" ++ hasTypeMsg h₂ hType₂) def mkHEqSymm (h : Expr) : MetaM Expr := do if h.isAppOf ``HEq.refl then return h else let hType ← infer h match hType.heq? with | some (α, a, β, b) => let u ← getLevel α return mkApp5 (mkConst ``HEq.symm [u]) α β a b h | none => throwAppBuilderException ``HEq.symm ("heterogeneous equality proof expected" ++ hasTypeMsg h hType) def mkHEqTrans (h₁ h₂ : Expr) : MetaM Expr := do if h₁.isAppOf ``HEq.refl then return h₂ else if h₂.isAppOf ``HEq.refl then return h₁ else let hType₁ ← infer h₁ let hType₂ ← infer h₂ match hType₁.heq?, hType₂.heq? with | some (α, a, β, b), some (_, _, γ, c) => let u ← getLevel α return mkApp8 (mkConst ``HEq.trans [u]) α β γ a b c h₁ h₂ | none, _ => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₁ hType₁) | _, none => throwAppBuilderException ``HEq.trans ("heterogeneous equality proof expected" ++ hasTypeMsg h₂ hType₂) def mkEqOfHEq (h : Expr) : MetaM Expr := do let hType ← infer h match hType.heq? with | some (α, a, β, b) => unless (← isDefEq α β) do throwAppBuilderException ``eqOfHEq m!"heterogeneous equality types are not definitionally equal{indentExpr α}\nis not definitionally equal to{indentExpr β}" let u ← getLevel α return mkApp4 (mkConst ``eqOfHEq [u]) α a b h | _ => throwAppBuilderException ``HEq.trans m!"heterogeneous equality proof expected{indentExpr h}" def mkCongrArg (f h : Expr) : MetaM Expr := do if h.isAppOf ``Eq.refl then mkEqRefl (mkApp f h.appArg!) else let hType ← infer h let fType ← infer f match fType.arrow?, hType.eq? with | some (α, β), some (_, a, b) => let u ← getLevel α let v ← getLevel β return mkApp6 (mkConst ``congrArg [u, v]) α β a b f h | none, _ => throwAppBuilderException ``congrArg ("non-dependent function expected" ++ hasTypeMsg f fType) | _, none => throwAppBuilderException ``congrArg ("equality proof expected" ++ hasTypeMsg h hType) def mkCongrFun (h a : Expr) : MetaM Expr := do if h.isAppOf ``Eq.refl then mkEqRefl (mkApp h.appArg! a) else let hType ← infer h match hType.eq? with | some (ρ, f, g) => do let ρ ← whnfD ρ match ρ with | Expr.forallE n α β _ => let β' := Lean.mkLambda n BinderInfo.default α β let u ← getLevel α let v ← getLevel (mkApp β' a) return mkApp6 (mkConst ``congrFun [u, v]) α β' f g h a | _ => throwAppBuilderException ``congrFun ("equality proof between functions expected" ++ hasTypeMsg h hType) | _ => throwAppBuilderException ``congrFun ("equality proof expected" ++ hasTypeMsg h hType) def mkCongr (h₁ h₂ : Expr) : MetaM Expr := do if h₁.isAppOf ``Eq.refl then mkCongrArg h₁.appArg! h₂ else if h₂.isAppOf ``Eq.refl then mkCongrFun h₁ h₂.appArg! else let hType₁ ← infer h₁ let hType₂ ← infer h₂ match hType₁.eq?, hType₂.eq? with | some (ρ, f, g), some (α, a, b) => let ρ ← whnfD ρ match ρ.arrow? with | some (_, β) => do let u ← getLevel α let v ← getLevel β return mkApp8 (mkConst ``congr [u, v]) α β f g a b h₁ h₂ | _ => throwAppBuilderException ``congr ("non-dependent function expected" ++ hasTypeMsg h₁ hType₁) | none, _ => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₁ hType₁) | _, none => throwAppBuilderException ``congr ("equality proof expected" ++ hasTypeMsg h₂ hType₂) private def mkAppMFinal (methodName : Name) (f : Expr) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do instMVars.forM fun mvarId => do let mvarDecl ← getMVarDecl mvarId let mvarVal ← synthInstance mvarDecl.type assignExprMVar mvarId mvarVal let result ← instantiateMVars (mkAppN f args) if (← hasAssignableMVar result) then throwAppBuilderException methodName ("result contains metavariables" ++ indentExpr result) return result private partial def mkAppMArgs (f : Expr) (fType : Expr) (xs : Array Expr) : MetaM Expr := let rec loop (type : Expr) (i : Nat) (j : Nat) (args : Array Expr) (instMVars : Array MVarId) : MetaM Expr := do if i >= xs.size then mkAppMFinal `mkAppM f args instMVars else match type with | Expr.forallE n d b c => let d := d.instantiateRevRange j args.size args match c.binderInfo with | BinderInfo.implicit => let mvar ← mkFreshExprMVar d MetavarKind.natural n loop b i j (args.push mvar) instMVars | BinderInfo.instImplicit => let mvar ← mkFreshExprMVar d MetavarKind.synthetic n loop b i j (args.push mvar) (instMVars.push mvar.mvarId!) | _ => let x := xs[i] let xType ← inferType x if (← isDefEq d xType) then loop b (i+1) j (args.push x) instMVars else throwAppTypeMismatch (mkAppN f args) x | type => let type := type.instantiateRevRange j args.size args let type ← whnfD type if type.isForall then loop type i args.size args instMVars else throwAppBuilderException `mkAppM m!"too many explicit arguments provided to{indentExpr f}\narguments{indentD xs}" loop fType 0 0 #[] #[] private def mkFun (constName : Name) : MetaM (Expr × Expr) := do let cinfo ← getConstInfo constName let us ← cinfo.lparams.mapM fun _ => mkFreshLevelMVar let f := mkConst constName us let fType := cinfo.instantiateTypeLevelParams us return (f, fType) /-- Return the application `constName xs`. It tries to fill the implicit arguments before the last element in `xs`. Remark: ``mkAppM `arbitrary #[α]`` returns `@arbitrary.{u} α` without synthesizing the implicit argument occurring after `α`. Given a `x : (([Decidable p] → Bool) × Nat`, ``mkAppM `Prod.fst #[x]`` returns `@Prod.fst ([Decidable p] → Bool) Nat x` -/ def mkAppM (constName : Name) (xs : Array Expr) : MetaM Expr := do traceCtx `Meta.appBuilder <| withNewMCtxDepth do let (f, fType) ← mkFun constName let r ← mkAppMArgs f fType xs trace[Meta.appBuilder]! "constName: {constName}, xs: {xs}, result: {r}" return r private partial def mkAppOptMAux (f : Expr) (xs : Array (Option Expr)) : Nat → Array Expr → Nat → Array MVarId → Expr → MetaM Expr | i, args, j, instMVars, Expr.forallE n d b c => do let d := d.instantiateRevRange j args.size args if h : i < xs.size then match xs.get ⟨i, h⟩ with | none => match c.binderInfo with | BinderInfo.instImplicit => do let mvar ← mkFreshExprMVar d MetavarKind.synthetic n mkAppOptMAux f xs (i+1) (args.push mvar) j (instMVars.push mvar.mvarId!) b | _ => do let mvar ← mkFreshExprMVar d MetavarKind.natural n mkAppOptMAux f xs (i+1) (args.push mvar) j instMVars b | some x => let xType ← inferType x if (← isDefEq d xType) then mkAppOptMAux f xs (i+1) (args.push x) j instMVars b else throwAppTypeMismatch (mkAppN f args) x else mkAppMFinal `mkAppOptM f args instMVars | i, args, j, instMVars, type => do let type := type.instantiateRevRange j args.size args let type ← whnfD type if type.isForall then mkAppOptMAux f xs i args args.size instMVars type else if i == xs.size then mkAppMFinal `mkAppOptM f args instMVars else do let xs : Array Expr := xs.foldl (fun r x? => match x? with | none => r | some x => r.push x) #[] throwAppBuilderException `mkAppOptM ("too many arguments provided to" ++ indentExpr f ++ Format.line ++ "arguments" ++ xs) /-- Similar to `mkAppM`, but it allows us to specify which arguments are provided explicitly using `Option` type. Example: Given `Pure.pure {m : Type u → Type v} [Pure m] {α : Type u} (a : α) : m α`, ``` mkAppOptM `Pure.pure #[m, none, none, a] ``` returns a `Pure.pure` application if the instance `Pure m` can be synthesized, and the universes match. Note that, ``` mkAppM `Pure.pure #[a] ``` fails because the only explicit argument `(a : α)` is not sufficient for inferring the remaining arguments, we would need the expected type. -/ def mkAppOptM (constName : Name) (xs : Array (Option Expr)) : MetaM Expr := do traceCtx `Meta.appBuilder <| withNewMCtxDepth do let (f, fType) ← mkFun constName mkAppOptMAux f xs 0 #[] 0 #[] fType def mkEqNDRec (motive h1 h2 : Expr) : MetaM Expr := do if h2.isAppOf ``Eq.refl then return h1 else let h2Type ← infer h2 match h2Type.eq? with | none => throwAppBuilderException ``Eq.ndrec ("equality proof expected" ++ hasTypeMsg h2 h2Type) | some (α, a, b) => let u2 ← getLevel α let motiveType ← infer motive match motiveType with | Expr.forallE _ _ (Expr.sort u1 _) _ => return mkAppN (mkConst ``Eq.ndrec [u1, u2]) #[α, a, motive, h1, b, h2] | _ => throwAppBuilderException ``Eq.ndrec ("invalid motive" ++ indentExpr motive) def mkEqRec (motive h1 h2 : Expr) : MetaM Expr := do if h2.isAppOf ``Eq.refl then return h1 else let h2Type ← infer h2 match h2Type.eq? with | none => throwAppBuilderException ``Eq.rec ("equality proof expected" ++ indentExpr h2) | some (α, a, b) => let u2 ← getLevel α let motiveType ← infer motive match motiveType with | Expr.forallE _ _ (Expr.forallE _ _ (Expr.sort u1 _) _) _ => return mkAppN (mkConst ``Eq.rec [u1, u2]) #[α, a, motive, h1, b, h2] | _ => throwAppBuilderException ``Eq.rec ("invalid motive" ++ indentExpr motive) def mkEqMP (eqProof pr : Expr) : MetaM Expr := mkAppM ``Eq.mp #[eqProof, pr] def mkEqMPR (eqProof pr : Expr) : MetaM Expr := mkAppM ``Eq.mpr #[eqProof, pr] def mkNoConfusion (target : Expr) (h : Expr) : MetaM Expr := do let type ← inferType h let type ← whnf type match type.eq? with | none => throwAppBuilderException `noConfusion ("equality expected" ++ hasTypeMsg h type) | some (α, a, b) => let α ← whnf α matchConstInduct α.getAppFn (fun _ => throwAppBuilderException `noConfusion ("inductive type expected" ++ indentExpr α)) fun v us => do let u ← getLevel target return mkAppN (mkConst (Name.mkStr v.name "noConfusion") (u :: us)) (α.getAppArgs ++ #[target, a, b, h]) def mkPure (monad : Expr) (e : Expr) : MetaM Expr := mkAppOptM ``Pure.pure #[monad, none, none, e] /-- `mkProjection s fieldName` return an expression for accessing field `fieldName` of the structure `s`. Remark: `fieldName` may be a subfield of `s`. -/ partial def mkProjection : Expr → Name → MetaM Expr | s, fieldName => do let type ← inferType s let type ← whnf type match type.getAppFn with | Expr.const structName us _ => let env ← getEnv unless isStructureLike env structName do throwAppBuilderException `mkProjection ("structure expected" ++ hasTypeMsg s type) match getProjFnForField? env structName fieldName with | some projFn => let params := type.getAppArgs return mkApp (mkAppN (mkConst projFn us) params) s | none => let fields := getStructureFields env structName let r? ← fields.findSomeM? fun fieldName' => do match isSubobjectField? env structName fieldName' with | none => pure none | some _ => let parent ← mkProjection s fieldName' (do let r ← mkProjection parent fieldName; return some r) <|> pure none match r? with | some r => pure r | none => throwAppBuilderException `mkProjectionn ("invalid field name '" ++ toString fieldName ++ "' for" ++ hasTypeMsg s type) | _ => throwAppBuilderException `mkProjectionn ("structure expected" ++ hasTypeMsg s type) private def mkListLitAux (nil : Expr) (cons : Expr) : List Expr → Expr | [] => nil | x::xs => mkApp (mkApp cons x) (mkListLitAux nil cons xs) def mkListLit (type : Expr) (xs : List Expr) : MetaM Expr := do let u ← getDecLevel type let nil := mkApp (mkConst ``List.nil [u]) type match xs with | [] => return nil | _ => let cons := mkApp (mkConst ``List.cons [u]) type return mkListLitAux nil cons xs def mkArrayLit (type : Expr) (xs : List Expr) : MetaM Expr := do let u ← getDecLevel type let listLit ← mkListLit type xs return mkApp (mkApp (mkConst ``List.toArray [u]) type) listLit def mkSorry (type : Expr) (synthetic : Bool) : MetaM Expr := do let u ← getLevel type return mkApp2 (mkConst ``sorryAx [u]) type (toExpr synthetic) /-- Return `Decidable.decide p` -/ def mkDecide (p : Expr) : MetaM Expr := mkAppOptM ``Decidable.decide #[p, none] /-- Return a proof for `p : Prop` using `decide p` -/ def mkDecideProof (p : Expr) : MetaM Expr := do let decP ← mkDecide p let decEqTrue ← mkEq decP (mkConst ``Bool.true) let h ← mkEqRefl (mkConst ``Bool.true) let h ← mkExpectedTypeHint h decEqTrue mkAppM ``ofDecideEqTrue #[h] /-- Return `a < b` -/ def mkLt (a b : Expr) : MetaM Expr := mkAppM ``HasLess.Less #[a, b] /-- Return `a <= b` -/ def mkLe (a b : Expr) : MetaM Expr := mkAppM ``HasLessEq.LessEq #[a, b] /-- Return `arbitrary α` -/ def mkArbitrary (α : Expr) : MetaM Expr := mkAppOptM ``arbitrary #[α, none] /-- Return `sorryAx type` -/ def mkSyntheticSorry (type : Expr) : MetaM Expr := return mkApp2 (mkConst ``sorryAx [← getLevel type]) type (mkConst ``Bool.true) /-- Return `funext h` -/ def mkFunExt (h : Expr) : MetaM Expr := mkAppM ``funext #[h] /-- Return `propext h` -/ def mkPropExt (h : Expr) : MetaM Expr := mkAppM ``propext #[h] /-- Return `eqTrue h` -/ def mkEqTrue (h : Expr) : MetaM Expr := mkAppM ``eqTrue #[h] /-- Return `eqFalse h` -/ def mkEqFalse (h : Expr) : MetaM Expr := mkAppM ``eqFalse #[h] def mkImpCongr (h₁ h₂ : Expr) : MetaM Expr := mkAppM ``impCongr #[h₁, h₂] def mkImpCongrCtx (h₁ h₂ : Expr) : MetaM Expr := mkAppM ``impCongrCtx #[h₁, h₂] def mkForallCongr (h : Expr) : MetaM Expr := mkAppM ``forallCongr #[h] /-- Return `(n : type)`, a numeric literal of type `type`. The method fails if we don't have an instance `OfNat type n` -/ def mkNumeral (type : Expr) (n : Nat) : MetaM Expr := do let u ← getDecLevel type let inst ← synthInstance (mkApp2 (mkConst ``OfNat [u]) type (mkNatLit n)) return mkApp3 (mkConst ``OfNat.ofNat [u]) type (mkNatLit n) inst /-- Return `a op b`, where `op` has name `opName` and is implemented using the typeclass `className`. This method assumes `a` and `b` have the same type, and typeclass `className` is heterogeneous. Examples of supported clases: `HAdd`, `HSub`, `HMul`. We use heterogeneous operators to ensure we have a uniform representation. -/ private def mkBinaryOp (className : Name) (opName : Name) (a b : Expr) : MetaM Expr := do let aType ← inferType a let u ← getDecLevel aType let inst ← synthInstance (mkApp3 (mkConst className [u, u, u]) aType aType aType) return mkApp6 (mkConst opName [u, u, u]) aType aType aType inst a b /-- Return `a + b` using a heterogeneous `+`. This method assumes `a` and `b` have the same type. -/ def mkAdd (a b : Expr) : MetaM Expr := mkBinaryOp ``HAdd ``HAdd.hAdd a b /-- Return `a - b` using a heterogeneous `-`. This method assumes `a` and `b` have the same type. -/ def mkSub (a b : Expr) : MetaM Expr := mkBinaryOp ``HSub ``HSub.hSub a b /-- Return `a * b` using a heterogeneous `*`. This method assumes `a` and `b` have the same type. -/ def mkMul (a b : Expr) : MetaM Expr := mkBinaryOp ``HMul ``HMul.hMul a b builtin_initialize registerTraceClass `Meta.appBuilder end Lean.Meta
fe62cca1d772fcc2c1af753667f99158da5dbdf8
7cef822f3b952965621309e88eadf618da0c8ae9
/src/category_theory/limits/shapes/terminal.lean
f8f37a5a4354a53a19e5fd35d9c1e778f120a1a0
[ "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
2,048
lean
/- Copyright (c) 2019 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Scott Morrison -/ import category_theory.limits.shapes.finite_products import category_theory.pempty universes v u open category_theory namespace category_theory.limits variables (C : Type u) [𝒞 : category.{v} C] include 𝒞 class has_terminal := (has_limits_of_shape : has_limits_of_shape.{v} pempty C) class has_initial := (has_colimits_of_shape : has_colimits_of_shape.{v} pempty C) attribute [instance] has_terminal.has_limits_of_shape has_initial.has_colimits_of_shape @[priority 100] -- see Note [lower instance priority] instance [has_finite_products.{v} C] : has_terminal.{v} C := { has_limits_of_shape := { has_limit := λ F, has_limit_of_equivalence_comp ((functor.empty.{v} (discrete pempty.{v+1})).as_equivalence.symm) } } @[priority 100] -- see Note [lower instance priority] instance [has_finite_coproducts.{v} C] : has_initial.{v} C := { has_colimits_of_shape := { has_colimit := λ F, has_colimit_of_equivalence_comp ((functor.empty.{v} (discrete pempty.{v+1})).as_equivalence.symm) } } abbreviation terminal [has_terminal.{v} C] : C := limit (functor.empty C) abbreviation initial [has_initial.{v} C] : C := colimit (functor.empty C) notation `⊤_` C:20 := terminal C notation `⊥_` C:20 := initial C section variables {C} abbreviation terminal.from [has_terminal.{v} C] (P : C) : P ⟶ ⊤_ C := limit.lift (functor.empty C) { X := P, π := by tidy }. abbreviation initial.to [has_initial.{v} C] (P : C) : ⊥_ C ⟶ P := colimit.desc (functor.empty C) { X := P, ι := by tidy }. instance unique_to_terminal [has_terminal.{v} C] (P : C) : unique (P ⟶ ⊤_ C) := { default := terminal.from P, uniq := λ m, by { apply limit.hom_ext, rintro ⟨⟩ } } instance unique_from_initial [has_initial.{v} C] (P : C) : unique (⊥_ C ⟶ P) := { default := initial.to P, uniq := λ m, by { apply colimit.hom_ext, rintro ⟨⟩ } } end end category_theory.limits
44de55c3329e014c6d4aa0ddb0db17ec227b146f
fe84e287c662151bb313504482b218a503b972f3
/src/data/cfrac/numbers.lean
967bfc6d207951f9f440385847832703ba22ba79
[]
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
25,294
lean
import data.pnat.basic data.setoid.basic inductive spread (α : Type*) | zero : spread | ps : α → spread | ng : α → spread namespace spread instance {α : Type*} : has_zero (spread α) := ⟨zero⟩ lemma zero_def {α : Type*} : (0 : spread α) = zero := rfl instance {α : Type*} [has_one α] : has_one (spread α) := ⟨ps 1⟩ lemma one_def {α : Type*} [has_one α] : (1 : spread α) = ps 1 := rfl def is_sub {α : Type*} [add_comm_semigroup α] (x y : α) : spread α → Prop | zero := x = y | (ps z) := x = y + z | (ng z) := x + z = y lemma is_sub_unique {α : Type*} [add_comm_semigroup α] (hp : ∀ {x y : α}, x + y ≠ x) (hc : ∀ {x y z : α}, x + y = x + z → y = z) {x y : α} {z₀ z₁ : spread α} (h₀ : is_sub x y z₀) (h₁ : is_sub x y z₁) : z₀ = z₁ := begin cases z₀; cases z₁; dsimp[is_sub] at h₀ h₁, { refl, }, { rw[h₀] at h₁, exact (hp h₁.symm).elim }, { rw[h₀] at h₁, exact (hp h₁).elim }, { rw[h₁] at h₀, exact (hp h₀.symm).elim }, { rw[h₀] at h₁, rw[hc h₁] }, { rw[h₀, add_assoc] at h₁, exact (hp h₁).elim }, { rw[h₁] at h₀, exact (hp h₀).elim }, { rw[h₁, add_assoc] at h₀, exact (hp h₀).elim }, { rw[← h₁] at h₀, rw[hc h₀]} end def neg {α : Type*} : (spread α) → (spread α) | zero := zero | (ps x) := ng x | (ng x) := ps x instance {α : Type*} : has_neg (spread α) := ⟨neg⟩ lemma is_sub_swap {α : Type*} [add_comm_semigroup α] {x y : α} {z : spread α}: is_sub y x z ↔ is_sub x y (neg z) := begin cases z; dsimp[neg, is_sub]; exact comm end @[simp] def mul {α : Type*} [has_mul α] : (spread α) → (spread α) → (spread α) | (zero) _ := zero | (ps x) (zero) := zero | (ps x) (ps y) := ps (x * y) | (ps x) (ng y) := ng (x * y) | (ng x) (zero) := zero | (ng x) (ps y) := ng (x * y) | (ng x) (ng y) := ps (x * y) instance {α : Type*} [has_mul α] : has_mul (spread α) := ⟨mul⟩ instance {α : Type*} [comm_monoid α] : comm_monoid (spread α) := { one_mul := λ a, begin change mul 1 a = a, rw[one_def], cases a; simp[one_mul] end, mul_one := λ a, begin change mul a 1 = a, rw[one_def], cases a; simp[mul_one] end, mul_comm := λ a b, begin change mul a b = mul b a, cases a; cases b; simp[mul_comm], end, mul_assoc := λ a b c, begin change mul (mul a b) c = mul a (mul b c), cases a; cases b; cases c; simp[mul_assoc], end, .. (by { apply_instance } : has_one (spread α)), .. (by { apply_instance } : has_mul (spread α)) } section add variables {α : Type*} [add_comm_semigroup α] variables (hp : ∀ {x y : α}, x + y ≠ x) variables (hc : ∀ {x y z : α}, x + y = x + z → y = z) def is_add : (spread α) → (spread α) → (spread α) → Prop | (zero) (zero) (zero) := true | (zero) (zero) (ps z) := false | (zero) (zero) (ng z) := false | (zero) (ps y) (zero) := false | (zero) (ps y) (ps z) := (y = z) | (zero) (ps y) (ng z) := false | (zero) (ng y) (zero) := false | (zero) (ng y) (ps z) := false | (zero) (ng y) (ng z) := (y = z) | (ps x) (zero) (zero) := false | (ps x) (zero) (ps z) := (x = z) | (ps x) (zero) (ng z) := false | (ps x) (ps y) (zero) := false | (ps x) (ps y) (ps z) := (x + y = z) | (ps x) (ps y) (ng z) := false | (ps x) (ng y) (zero) := (x = y) | (ps x) (ng y) (ps z) := (y + z = x) | (ps x) (ng y) (ng z) := (x + z = y) | (ng x) (zero) (zero) := false | (ng x) (zero) (ps z) := false | (ng x) (zero) (ng z) := (x = z) | (ng x) (ps y) (zero) := (x = y) | (ng x) (ps y) (ps z) := (x + z = y) | (ng x) (ps y) (ng z) := (y + z = x) | (ng x) (ng y) (zero) := false | (ng x) (ng y) (ps z) := false | (ng x) (ng y) (ng z) := (x + y = z) include hp hc lemma is_add_unique {a b c₀ c₁ : spread α} (h₀ : is_add a b c₀) (h₁ : is_add a b c₁) : c₀ = c₁ := begin cases a; cases b; cases c₀; dsimp[is_add] at h₀; try { exfalso, assumption }; cases c₁; dsimp[is_add] at h₁; try { exfalso, assumption }; try { match_hyp h₀ : _ = _, fail_if_success { match_hyp h₀ : _ = _ + _}, fail_if_success { match_hyp h₀ : _ + _ = _}, cases h₀ }; try { match_hyp h₁ : _ = _, fail_if_success { match_hyp h₁ : _ = _ + _}, fail_if_success { match_hyp h₁ : _ + _ = _}, cases h₁ }; try { refl }; try { exact (hp h₀).elim }; try { exact (hp h₁).elim }; try { rw[← h₀] at h₁, rw[hc h₁] }; try { rw[← h₀, add_assoc] at h₁, exact (hp h₁).elim, }; try { rw[← h₀, ← h₁] } end omit hp hc lemma is_add_zero (a a' : spread α) : is_add a zero a' ↔ a = a' := begin split, { cases a; cases a'; dsimp[is_add]; intro h; try { exfalso, assumption }; try { cases h ; refl } },{ intro h, cases h, cases a; dsimp[is_add]; trivial } end lemma is_zero_add (a a' : spread α) : is_add zero a a' ↔ a = a' := begin split, { cases a; cases a'; dsimp[is_add]; intro h; try { exfalso, assumption }; try { cases h ; refl } },{ intro h, cases h, cases a; dsimp[is_add]; trivial } end include hp lemma is_add_neg (a z : spread α) : is_add a (- a) z ↔ z = zero := begin change is_add a (neg a) z ↔ z = zero, split, { cases a; cases z; intro h; dsimp[neg, is_add] at h; try { replace h := hp h }; try { exfalso, assumption }; try { refl } }, { intro h, rw[h], change is_add a (neg a) zero, cases a; dsimp[neg, is_add]; trivial } end omit hp lemma is_add_comm (a b ab : spread α) : is_add a b ab ↔ is_add b a ab := begin cases a; cases b; cases ab; dsimp[is_add]; try { trivial }; try { rw[add_comm b a] }; try { exact comm } end include hp hc lemma is_add_assoc {a b c ab bc abc : spread α} (hab : is_add a b ab) (hbc : is_add b c bc) (habc : is_add ab c abc) : is_add a bc abc := begin have hp₁ : ∀ {x y : α}, y + x ≠ x := λ x y h, by { rw[add_comm] at h, exact hp h}, have hp₂ : ∀ {x y z : α}, x + (y + z) ≠ y := λ x y z h, by { rw[add_comm x, add_assoc] at h, exact hp h }, have hc₁ : ∀ { x y z : α}, x + y = z + x → y = z := λ x y z h, by { rw[add_comm z x] at h, exact hc h }, have hc₂ : ∀ { w x y z : α}, w + x = y + (w + z) → x = y + z := λ w x y z h, by { rw[add_comm y, add_assoc, add_comm z] at h, exact hc h }, cases a; cases b; cases c; try { rw[is_add_zero] at * }; try { rw[is_zero_add] at * }; try { match_hyp habc : _ = _, cases habc }; try { match_hyp hbc : _ = _, cases hbc }; try { match_hyp hab : _ = _, cases hab }; try { rw[is_add_zero] at * }; try { rw[is_zero_add] at * }; try { rw[is_add_unique @hp @hc hab habc] }; try { rw[is_add_unique @hp @hc hbc habc] }; try { exact is_add_unique @hp @hc hbc habc }; try { refl }; try { assumption }; cases ab; dsimp[is_add] at hab; try { exfalso, assumption }; try { rw[is_add_zero] at * }; try { rw[is_zero_add] at * }; rw[← hab] at *; cases bc; dsimp[is_add] at hbc; try { exfalso, assumption }; try { rw[is_add_zero] at * }; try { rw[is_zero_add] at * }; rw[← hbc] at *; cases abc; try { dsimp[is_add] at habc }; try { exfalso, assumption }; try { injection habc with habc'; replace habc := habc' }; try { dsimp[is_add] }; rw[← habc] at *; repeat { rw[add_assoc] at * }; try { rw[add_comm], done }; try { exact (hp₁ habc).elim }; try { exact (hp₁ habc.symm).elim }; try { exact (hp₂ habc).elim }; try { exact (hp₂ habc.symm).elim }; try { rw[hc₁ habc] }; try { rw[hc₁ habc.symm] }; try { rw[hc₁ hbc] }; try { rw[hc₁ hbc.symm] }; try { rw[(hc₁ hbc).symm, add_comm], done }; try { rw[hc₂ habc] }; try { rw[hc₂ habc.symm] }; try { rw[hc₂ hbc] }; try { rw[add_comm b, add_assoc, add_comm b] }; try { rw[add_comm c, add_assoc, add_comm _ c] } end omit hp hc @[simp] def add₀ (s : α → α → spread α) : spread α → spread α → spread α | (zero) (zero) := zero | (zero) (ps a) := ps a | (zero) (ng b) := ng b | (ps a) (zero) := ps a | (ps a) (ps b) := ps (a + b) | (ps a) (ng b) := s a b | (ng a) (zero) := ng a | (ng a) (ps b) := s b a | (ng a) (ng b) := ng (a + b) include hp hc lemma add₀_is_add (s : α → α → spread α) (hs : ∀ a b : α, is_sub a b (s a b)) : ∀ (a b : spread α), is_add a b (add₀ s a b) := begin have hs' : ∀ {x y : α} {z : spread α} (h : is_sub x y z), is_add (ps x) (ng y) z := λ x y z, begin cases z; dsimp[is_sub, is_add]; intro h; rw[h] end, intros a b, cases a; cases b; dsimp[add₀, is_add]; try { refl }; try { trivial }, { exact hs' (hs a b) }, { rw[is_add_comm], exact hs' (hs b a) } end lemma add₀_is_add' (hp : ∀ {x y : α}, x + y ≠ x) (hc : ∀ {x y z : α}, x + y = x + z → y = z) (s : α → α → spread α) (hs : ∀ a b : α, is_sub a b (s a b)) {a b c : spread α} : is_add a b c ↔ c = add₀ s a b := begin have h : is_add a b (add₀ s a b) := add₀_is_add @hp @hc s hs a b, split, { intro h', exact is_add_unique @hp @hc h' h }, { intro h', rw[h'], exact h } end end add section mul variables {α : Type*} [add_comm_semigroup α] [comm_monoid α] variable (hp : ∀ {x y : α}, x + y ≠ x) variable (hc : ∀ {x y z : α}, x + y = x + z → y = z) variables (s : α → α → spread α) (hs : ∀ a b : α, is_sub a b (s a b)) variable (hd : ∀ a b c : α, a * (b + c) = a * b + a * c) include hd lemma mul_ps_is_sub (x : α) {y z : α} {u : spread α} (h : is_sub y z u) : is_sub (x * y) (x * z) (mul (ps x) u) := begin cases u; dsimp[is_sub] at h; dsimp[mul, is_sub], { rw[h] }, { rw[h,hd] }, { rw[← h, hd] } end lemma mul_ng_is_sub (x : α) {y z : α} {u : spread α} (h : is_sub y z u) : is_sub (x * z) (x * y) (mul (ng x) u) := begin cases u; dsimp[is_sub] at h; dsimp[mul, is_sub], { rw[h] }, { rw[h,hd] }, { rw[← h, hd] } end omit hd include s hs hp hc hd lemma mul_add₀ (a b c : spread α) : a * (add₀ s b c) = add₀ s (a * b) (a * c) := begin change mul a (add₀ s b c) = add₀ s (mul a b) (mul a c), cases a; cases b; cases c; dsimp[add₀, mul]; try { rw[hd] }; try { refl }, { have := (mul_ps_is_sub hd a (hs b c)), exact is_sub_unique @hp @hc this (hs (a * b) (a * c)) }, { have := (mul_ps_is_sub hd a (hs c b)), exact is_sub_unique @hp @hc this (hs (a * c) (a * b)) }, { have := (mul_ng_is_sub hd a (hs b c)), exact is_sub_unique @hp @hc this (hs (a * c) (a * b)) }, { have := (mul_ng_is_sub hd a (hs c b)), exact is_sub_unique @hp @hc this (hs (a * b) (a * c)) }, end lemma add₀_mul (a b c : spread α) : (add₀ s a b) * c = add₀ s (a * c) (b * c) := by { repeat { rw[mul_comm _ c] }, apply mul_add₀ @hp @hc s hs hd } variable (α) def comm_ring₀ : comm_ring (spread α) := { add := add₀ s, zero_add := λ a, by { cases a; refl }, add_zero := λ a, by { cases a; refl }, add_left_neg := λ a, begin have hu := @is_sub_unique α (by apply_instance) @hp @hc, cases a, { refl }, { have hz : is_sub a a zero := rfl, exact hu (hs a a) hz }, { have hz : is_sub a a zero := rfl, exact hu (hs a a) hz } end, add_comm := λ a b, begin cases a; cases b; change add₀ s _ _ = add₀ s _ _; dsimp[add₀]; try { rw add_comm a b }; refl end, add_assoc := λ a b c, begin change add₀ s (add₀ s a b) c = add₀ s a (add₀ s b c), set ab := add₀ s a b with hab, set bc := add₀ s b c with hbc, set abc := add₀ s ab c with habc, have hab' := (add₀_is_add' @hp @hc s hs).mpr hab, have hbc' := (add₀_is_add' @hp @hc s hs).mpr hbc, have habc' := (add₀_is_add' @hp @hc s hs).mpr habc, rw[← add₀_is_add' @hp @hc s hs], exact is_add_assoc @hp @hc hab' hbc' habc', end, left_distrib := λ a b c, begin apply mul_add₀ @hp @hc s hs hd, end, right_distrib := λ a b c, begin apply add₀_mul @hp @hc s hs hd, end, .. (by apply_instance : has_neg (spread α)), .. (by apply_instance : has_zero (spread α)), .. (by apply_instance : comm_monoid (spread α)) } end mul section le variables {α : Type*} [linear_order α] @[simp] def le : (spread α) → (spread α) → Prop | (zero) (zero) := true | (zero) (ps y) := true | (zero) (ng y) := false | (ps x) (zero) := false | (ps x) (ps y) := (x ≤ y) | (ps x) (ng y) := false | (ng x) (zero) := true | (ng x) (ps y) := true | (ng x) (ng y) := (y ≤ x) instance : has_le (spread α) := ⟨le⟩ instance : linear_order (spread α) := { le_refl := λ a, begin cases a with a, trivial, exact (le_refl a), exact (le_refl a) end, le_trans := λ a b c hab hbc, begin cases a; cases b; cases c; try { cases hab }; try { cases hbc }; try { trivial }; try { exact le_trans hab hbc }; try { exact le_trans hbc hab } end, le_antisymm := λ a b hab hba, begin cases a; cases b; try { cases hab }; try { cases hba }; try { cases (le_antisymm (hab : a ≤ b) (hba : b ≤ a)) }; try { cases (le_antisymm (hab : b ≤ a) (hba : a ≤ b)) }; refl, end, le_total := λ a b, begin cases a; cases b; try { cases (le_total a b) with h }; try { left, trivial }; try { right, trivial }; try { left, assumption }; try { right, assumption } end, decidable_le := λ a b, begin cases a; cases b; try { exact decidable.true }; try { exact decidable.false }; try { exact (by apply_instance : decidable (a ≤ b)) }; try { exact (by apply_instance : decidable (b ≤ a)) }, end, .. (by { apply_instance } : has_le (spread α)) } end le end spread @[derive decidable_eq] structure prat_f : Type := (num : pnat) (den : pnat) namespace prat_f @[ext] lemma ext {x y : prat_f} (hn : x.num = y.num) (hd : x.den = y.den) : x = y := begin cases x with a b, cases y with c d, cases (hn : a = c), cases (hd : b = d), refl end def one' (a : pnat) : prat_f := ⟨a,a⟩ instance : comm_monoid prat_f := { one := ⟨1,1⟩, mul := λ x y,⟨x.num * y.num, x.den * y.den⟩, one_mul := λ x, begin ext1, exact one_mul x.num, exact one_mul x.den, end, mul_one := λ x, begin ext1, exact mul_one x.num, exact mul_one x.den, end, mul_comm := λ x y, begin ext1, exact mul_comm x.num y.num, exact mul_comm x.den y.den end, mul_assoc := λ x y z, begin ext1, exact mul_assoc _ _ _, exact mul_assoc _ _ _ end } instance : has_inv prat_f := ⟨λ x, ⟨x.den, x.num⟩⟩ lemma inv_inv (x : prat_f) : (x⁻¹)⁻¹ = x := by { ext1; refl } lemma inv_mul (x y : prat_f) : (x * y)⁻¹ = x⁻¹ * y⁻¹ := by { ext1; refl } instance : add_comm_semigroup prat_f := { add := λ x y, ⟨x.num * y.den + x.den * y.num, x.den * y.den⟩, add_comm := λ x y, begin cases x with a b, cases y with c d, ext1, { change a * d + b * c = c * b + d * a, rw[add_comm, mul_comm b c, mul_comm a d] }, { exact mul_comm b d } end, add_assoc := λ x y z, begin cases x with a b, cases y with c d, cases z with e f, ext1, { change (a * d + b * c) * f + (b * d) * e = a * (d * f) + b * (c * f + d * e), rw[add_mul, mul_add, ← add_assoc, ← mul_assoc, ← mul_assoc, ← mul_assoc] },{ exact mul_assoc b d f } end } lemma add_def (x y : prat_f) : x + y = ⟨x.num * y.den + x.den * y.num, x.den * y.den⟩ := rfl lemma add_def' (a b c d : pnat) : (prat_f.mk a b) + (prat_f.mk c d) = (prat_f.mk (a * d + b * c) (b * d)) := by { rw[add_def] } lemma num_add (x y : prat_f) : (x + y).num = x.num * y.den + x.den * y.num := rfl lemma den_add (x y : prat_f) : (x + y).den = x.den * y.den := rfl lemma mul_add (x y z : prat_f) : x * (y + z) * (one' x.den) = x * y + x * z := begin cases x with a b, cases y with c d, cases z with e f, ext1, { change a * (c * f + d * e) * b = (a * c) * (b * f) + (b * d) * (a * e), rw[mul_add, add_mul, mul_comm b f, mul_comm d e, mul_comm (b * d) (a * e), mul_comm b d], repeat { rw[← mul_assoc] }, },{ change b * (d * f) * b = (b * d) * (b * f), rw[mul_comm b f], repeat { rw[← mul_assoc] } } end instance : preorder prat_f := { le := λ x y, x.num * y.den ≤ y.num * x.den, le_refl := λ x, le_refl _, le_trans := begin rintro ⟨a,b⟩ ⟨c,d⟩ ⟨e,f⟩ (hxy : a * d ≤ c * b) (hyz : c * f ≤ e * d), change a * f ≤ e * b, replace hxy := (mul_le_mul_iff_right f).mpr hxy, replace hyz := (mul_le_mul_iff_left b).mpr hyz, rw[← mul_assoc b c f, mul_comm b c] at hyz, have hxz := le_trans hxy hyz, rw[mul_assoc a d f, mul_comm d f, ← mul_assoc, ← mul_assoc, mul_comm b e] at hxz, exact (mul_le_mul_iff_right d).mp hxz, end } instance : decidable_rel ((≤) : prat_f → prat_f → Prop) := by { apply_instance } lemma add_le_add_iff_left (x : prat_f) {y z : prat_f} : x + y ≤ x + z ↔ y ≤ z := begin cases x with a b, cases y with c d, cases z with e f, change (a * d + b * c) * (b * f) ≤ (a * f + b * e) * (b * d) ↔ c * f ≤ e * d, rw[add_mul, add_mul, mul_comm b d, mul_assoc a f (d * b), mul_comm f (d * b)], repeat { rw[mul_assoc] }, rw[add_le_add_iff_left, mul_le_mul_iff_left, mul_comm b f], repeat { rw[← mul_assoc] }, rw[mul_le_mul_iff_right] end lemma mul_le_mul_iff_left (x : prat_f) {y z : prat_f} : x * y ≤ x * z ↔ y ≤ z := begin cases x with a b, cases y with c d, cases z with e f, change (a * c) * (b * f) ≤ (a * e) * (b * d) ↔ c * f ≤ e * d, rw[mul_comm b f, mul_comm b d, mul_assoc a c, mul_assoc a e, ← mul_assoc c, ← mul_assoc e], rw[mul_le_mul_iff_left a, mul_le_mul_iff_right b], end def fraceq : setoid prat_f := { r := λ x y, x.num * y.den = y.num * x.den, iseqv := begin split, { intro x, refl }, split, { rintro x y (h : x.num * y.den = y.num * x.den), exact h.symm }, { rintro ⟨a,b⟩ ⟨c,d⟩ ⟨e,f⟩ (hxy : a * d = c * b) (hyz : c * f = e * d), change a * f = e * b, replace hxy : (a * d) * f = (c * b) * f := congr_fun (congr_arg (*) hxy) f, replace hyz : b * (c * f) = b * (e * d) := congr_arg ((*) b) hyz, rw[← mul_assoc b c f, mul_comm b c] at hyz, have hxz := hxy.trans hyz, rw[mul_assoc a d f, mul_comm d f, ← mul_assoc, ← mul_assoc, mul_comm b e] at hxz, exact (mul_left_inj d).mp hxz, } end } lemma fraceq.rel_def (x y : prat_f) : fraceq.rel x y ↔ x.num * y.den = y.num * x.den := by { refl } instance : decidable_rel fraceq.rel := λ x y, by { rw[fraceq.rel_def], apply_instance } lemma mul_lift {x₀ y₀ x₁ y₁ : prat_f} (hx : fraceq.rel x₀ x₁) (hy : fraceq.rel y₀ y₁) : fraceq.rel (x₀ * y₀) (x₁ * y₁) := begin cases x₀ with a₀ b₀, cases x₁ with a₁ b₁, cases y₀ with c₀ d₀, cases y₁ with c₁ d₁, change a₀ * b₁ = a₁ * b₀ at hx, change c₀ * d₁ = c₁ * d₀ at hy, change (a₀ * c₀) * (b₁ * d₁) = (a₁ * c₁) * (b₀ * d₀), rw[mul_assoc a₀ c₀, ← mul_assoc c₀, mul_comm c₀,mul_assoc b₁, ← mul_assoc a₀], rw[hx, hy, mul_assoc a₁, ← mul_assoc b₀, mul_comm b₀ c₁], repeat { rw[mul_assoc] } end lemma add_lift {x₀ y₀ x₁ y₁ : prat_f} (hx : fraceq.rel x₀ x₁) (hy : fraceq.rel y₀ y₁) : fraceq.rel (x₀ + y₀) (x₁ + y₁) := begin cases x₀ with a₀ b₀, cases x₁ with a₁ b₁, cases y₀ with c₀ d₀, cases y₁ with c₁ d₁, change a₀ * b₁ = a₁ * b₀ at hx, change c₀ * d₁ = c₁ * d₀ at hy, change (a₀ * d₀ + b₀ * c₀) * (b₁ * d₁) = (a₁ * d₁ + b₁ * c₁) * (b₀ * d₀), rw[add_mul, add_mul], rw[mul_assoc a₀ d₀, ← mul_assoc d₀, mul_comm d₀ b₁,mul_assoc b₁, ← mul_assoc a₀, hx], rw[mul_assoc b₀ c₀, ← mul_assoc c₀, mul_comm c₀ b₁,mul_assoc b₁, hy], rw[mul_comm d₀ d₁, mul_assoc a₁ b₀, ← mul_assoc b₀, mul_comm b₀ d₁], rw[mul_comm b₀, mul_assoc b₁, mul_assoc c₁, mul_comm d₀ b₀], repeat { rw[mul_assoc] } end lemma le_lift {x₀ y₀ x₁ y₁ : prat_f} (hx : fraceq.rel x₀ x₁) (hy : fraceq.rel y₀ y₁) : x₀ ≤ y₀ ↔ x₁ ≤ y₁ := begin cases x₀ with a₀ b₀, cases x₁ with a₁ b₁, cases y₀ with c₀ d₀, cases y₁ with c₁ d₁, change a₀ * b₁ = a₁ * b₀ at hx, change c₀ * d₁ = c₁ * d₀ at hy, change (a₀ * d₀ ≤ c₀ * b₀) ↔ (a₁ * d₁ ≤ c₁ * b₁), conv { to_lhs, rw[← mul_le_mul_iff_right (b₁ * d₁)], rw[mul_assoc a₀, ← mul_assoc d₀, mul_comm d₀ b₁, mul_assoc b₁, ← mul_assoc a₀, hx], rw[mul_comm c₀, mul_assoc b₀ c₀, ← mul_assoc c₀ b₁, mul_comm c₀ b₁], }, conv { to_rhs, rw[← mul_le_mul_iff_right (b₀ * d₀)], rw[mul_comm _ (b₀ * d₀), mul_assoc c₁ b₁, mul_comm b₁, mul_comm b₀], rw[mul_assoc d₀ b₀ b₁, ← mul_assoc c₁, ← hy], rw[mul_comm d₀ b₀, mul_comm (b₀ * d₀), mul_assoc a₁, ← mul_assoc d₁, mul_comm d₁ b₀], rw[mul_assoc b₀, mul_comm d₁ d₀, mul_comm (c₀ * d₁)], }, repeat { rw[mul_assoc] }, end lemma mul_one' (x : prat_f) (n : pnat): fraceq.rel x (x * (one' n)) := begin cases x with a b, change a * (b * n) = (a * n) * b, rw[mul_comm b n, mul_assoc], end end prat_f def prat_r := quotient prat_f.fraceq namespace prat_r local attribute [instance] prat_f.fraceq instance : ordered_comm_monoid prat_r := { one := quotient.mk' 1, mul := quotient.map₂ (*) (λ x₀ x₁ hx y₀ y₁ hy, prat_f.mul_lift hx hy), one_mul := λ x, begin rcases x, change quot.mk setoid.r (1 * x) = _, rw[one_mul] end, mul_one := λ x, begin rcases x, change quot.mk setoid.r (x * 1) = _, rw[mul_one] end, mul_comm := λ x y, begin rcases x, rcases y, change quot.mk setoid.r (x * y) = quot.mk setoid.r (y * x), rw[mul_comm x y] end, mul_assoc := λ x y z, begin rcases x, rcases y, rcases z, change quot.mk setoid.r ((x * y) * z) = quot.mk setoid.r (x * (y * z)), rw[mul_assoc] end, le := quotient.lift₂ (≤) (λ x₀ y₀ x₁ y₁ hx hy, (begin rw[← iff_eq_eq], exact prat_f.le_lift hx hy end)), le_refl := by { rintro ⟨x⟩, exact le_refl x }, le_trans := by { rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ (hxy : x ≤ y) (hyz : y ≤ z), exact le_trans hxy hyz }, le_antisymm := begin rintro ⟨⟨a,b⟩⟩ ⟨⟨c,d⟩⟩ (hxy : a * d ≤ c * b) (hyx : c * b ≤ a * d), have h : prat_f.fraceq.rel ⟨a,b⟩ ⟨c,d⟩ := le_antisymm hxy hyx, exact quot.sound h end, mul_le_mul_left := begin rintro ⟨x⟩ ⟨y⟩ (hxy : x ≤ y) ⟨z⟩, exact (prat_f.mul_le_mul_iff_left z).mpr hxy end } instance : add_comm_semigroup prat_r := { add := quotient.map₂ (+) (λ x₀ x₁ hx y₀ y₁ hy, prat_f.add_lift hx hy), add_comm := λ x y, begin rcases x, rcases y, change quot.mk setoid.r (x + y) = quot.mk setoid.r (y + x), rw[add_comm x y] end, add_assoc := λ x y z, begin rcases x, rcases y, rcases z, change quot.mk setoid.r ((x + y) + z) = quot.mk setoid.r (x + (y + z)), rw[add_assoc] end } instance : add_left_cancel_semigroup prat_r := { add_left_cancel := begin rintro ⟨x⟩ ⟨y⟩ ⟨z⟩ h, change quot.mk setoid.r (x + y) = quot.mk setoid.r (x + z) at h, replace h := quotient.exact h, apply quot.sound, rcases x with ⟨a,b⟩, rcases y with ⟨c,d⟩, rcases z with ⟨e,f⟩, change c * f = e * d, change (a * d + b * c) * (b * f) = (a * f + b * e) * (b * d) at h, rw[mul_comm b f, mul_comm b d, ← mul_assoc, ← mul_assoc] at h, replace h := mul_right_cancel h, rw[add_mul, add_mul, mul_assoc a f d, mul_comm f d, ← mul_assoc a d f] at h, replace h := _root_.add_left_cancel h, rw[mul_assoc, mul_assoc] at h, exact mul_left_cancel h end, .. (by apply_instance : add_comm_semigroup prat_r) } lemma mul_add (x y z : prat_r) : x * (y + z) = (x * y) + (x * z) := begin rcases x, rcases y, rcases z, change quot.mk setoid.r (x * (y + z)) = quot.mk setoid.r ((x * y) + (x * z)), rw[← prat_f.mul_add], apply quot.sound, change prat_f.fraceq.rel _ _, apply prat_f.mul_one' end lemma add_mul (x y z : prat_r) : (x + y) * z = (x * z) + (y * z) := by { rw[mul_comm (x + y), mul_comm x, mul_comm y, mul_add] } instance : linear_order prat_r := { le_total := begin rintro ⟨⟨a,b⟩⟩ ⟨⟨c,d⟩⟩, change a * d ≤ c * b ∨ c * b ≤ a * d, apply le_total end, decidable_le := λ x y, begin apply quotient.rec_on_subsingleton₂ x y, { intros u v, change decidable (u ≤ v), apply_instance }, { intros u v, change subsingleton (decidable (u ≤ v)), apply_instance } end, .. (by { apply_instance } : ordered_comm_monoid prat_r) } lemma lt_add_right (x y : prat_r) : x < x + y := begin apply lt_of_not_ge, intro h, rcases x with ⟨x⟩, rcases y with ⟨y⟩, change x + y ≤ x at h, rcases x with ⟨a,b⟩, rcases y with ⟨c,d⟩, change (a * d + b * c) * b ≤ a * (b * d) at h, rw[_root_.add_mul, mul_assoc a d b, mul_comm d b] at h, exact (not_le_of_gt (pnat.lt_add_right (a * (b * d)) (b * c * b))) h, end end prat_r def rat_r := spread prat_r #check spread.comm_ring₀ prat_r (λ x y, ne_of_gt (prat_r.lt_add_right x y)) (λ x y z h, add_left_cancel h)
06176ec5b46854ddc141f87bd1709b3f382b1a11
56e5b79a7ab4f2c52e6eb94f76d8100a25273cf3
/src/evaluation.lean
4f97950a15cbec1d54ef0857fc43ee7e828a475b
[ "Apache-2.0" ]
permissive
DyeKuu/lean-tpe-public
3a9968f286ca182723ef7e7d97e155d8cb6b1e70
750ade767ab28037e80b7a80360d213a875038f8
refs/heads/master
1,682,842,633,115
1,621,330,793,000
1,621,330,793,000
368,475,816
0
0
Apache-2.0
1,621,330,745,000
1,621,330,744,000
null
UTF-8
Lean
false
false
49,255
lean
/- Copyright (c) 2020 Jason Rute. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author(s): Jason Rute and Jesse Michael Han REPL for interacting with Lean -/ import data.nat.basic import system.io import tactic.core import tactic import utils import .tactic_state import basic.queue section tactic_state open interaction_monad.result setup_tactic_parser /- set this to tt to enable tracing `tactic.set_bool_option` is tactic state specific, and is difficult to globally set -/ meta def num_goals' : tactic_state → option ℕ := λ ts, match tactic.num_goals ts with | (success val _) := pure val | _ := none end -- TODO(jesse): this is a hack. might be better to do this in python meta def consume_with_parser {α} (p : lean.parser α) : string → io string := λ inp, do { io.run_tactic' $ do prod.snd <$> (lean.parser.run_with_input (with_input p inp) "") } -- TODO(jesse): performance meta def consume_spaces : string → string | arg@⟨[]⟩ := arg | arg@⟨(x::xs)⟩ := if x = ' ' then consume_spaces ⟨xs⟩ else arg -- WARNING: this is a hack meta def remove_indents_with_split (c : char := '\t'): string → string := λ str, let strs := str.split (= '\t') in string.intercalate (⟨['\t']⟩ : string) (consume_spaces <$> strs) meta def postprocess_tactic_state : tactic_state → tactic string := λ ts, do let main : tactic string := do { let ts_str := ts.to_format.to_string, tabbed_ts_str ← do { if (num_goals' ts).get_or_else 0 ≤ 1 then pure $ ts_str.replace_char '\n' '\t' else tactic.unsafe_run_io $ (λ x, string.replace_char x '\n' '\t') <$> (consume_with_parser small_nat >=> consume_with_parser ident) ts_str}, pure $ remove_indents_with_split '\t' tabbed_ts_str }, main <|> (let msg := "[postprocess_tactic_state] WARNING: POSTPROCESSING FAILED" in tactic.trace msg *> tactic.fail msg) end tactic_state meta def add_open_namespace : name → tactic unit := λ nm, do env ← tactic.get_env, tactic.set_env (env.execute_open nm) meta def add_open_namespaces (nms : list name) : tactic unit := nms.mmap' add_open_namespace section run_with_state' namespace interaction_monad open interaction_monad.result meta def run_with_state' {σ₁ σ₂ : Type} {α : Type*} (state : σ₁) (tac : interaction_monad σ₁ α) : interaction_monad σ₂ α := λ s, match (tac state) with | (success val _) := success val s | (exception fn pos _) := exception fn pos s end end interaction_monad end run_with_state' namespace tactic open interaction_monad.result meta def run (tac : tactic unit) : tactic (interaction_monad.result tactic_state unit) := do { σ ← get_state, match tac σ with | r@(success _ new_state) := interaction_monad.set_state new_state *> pure r | r@(exception fn pos new_state) := pure r end } -- meta instance has_format_result {α σ} [has_to_format σ] [has_to_format α] : has_to_format (interaction_monad.result σ α) := ⟨by mk_to_format `interaction_monad.result⟩ -- ayyy meta instance has_to_format_tactic_result {α : Type*} [has_to_format α] : has_to_format (interaction_monad.result tactic_state α) := ⟨λ r, match r with | (success val new_state) := format!"SUCCESS!\nNEW_STATE: {new_state}\nVAL: {val}" | (exception fn pos old_state) := do { let msg := (fn.get_or_else (λ _, format.of_string "n/a")) (), format!"EXCEPTION!\nMSG: {msg}\nPOS: {pos}\nOLD_STATE: {old_state}" } end ⟩ meta instance has_to_tactic_format_tactic_result {α : Type*} [has_to_format α] : has_to_tactic_format (interaction_monad.result tactic_state α) := ⟨λ σ, pure $ has_to_format.to_format σ⟩ end tactic section parse_eval_tac setup_tactic_parser open tactic meta def parse_eval_tac (ps : parser_state) (tactic_string : string) : tactic (tactic unit × format) := do { let itactic_string := "{" ++ tactic_string ++ "}", texpr ← (reflected_value.expr ∘ prod.fst) <$> (interaction_monad.run_with_state' ps $ with_input parser.itactic_reflected itactic_string), prod.mk <$> (eval_expr (tactic unit) texpr) <*> has_to_tactic_format.to_tactic_format texpr } end parse_eval_tac section frontend open tactic lean lean.parser interactive meta def read_eval_print_loop (ps : parser_state) : tactic unit := do trace "\nTactic state:", trace_state, let rest : tactic unit := do {trace "\nEnter a tactic command:", tactic_string <- tactic.unsafe_run_io $ io.get_line, (t, fmt) ← parse_eval_tac ps tactic_string, trace "", trace ("Running tactic:\n" ++ fmt.to_string), tactic.run t >>= eval_trace, -- runs the tactic on the goal. It is crashing read_eval_print_loop}, --- loops forever done <|> rest --- like main_t, but sets the goal and environment to a user-supplied theorem in mathlib --- note: if the environment contains all declarations in mathlib, --- and olean files exist, --- we don't need to supply the lean file as env.decl_olean will find it automatically. meta def main_t_at : parser_state → tactic unit := λ ps, do { trace "enter declaration to prove", goal_nm_string ← tactic.unsafe_run_io $ io.get_line, ⟨nm, _⟩ ← interaction_monad.run_with_state' ps $ with_input ident goal_nm_string, env ← get_env, decl ← env.get nm, let g := decl.type, set_goal_to g, lean_file ← env.decl_olean nm, set_env_core $ environment.for_decl_of_imported_module lean_file nm, read_eval_print_loop ps } @[user_command] meta def main_app_at (meta_info : decl_meta_info) (_ : parse (tk "main_app_at")) : lean.parser unit := get_state >>= of_tactic ∘ (main_t_at) end frontend section main setup_tactic_parser open tactic meta def main_t : parser_state → tactic unit := λ ps, do trace "Enter a goal:", set_goal_to `(true), goal_string <- tactic.unsafe_run_io $ io.get_line, trace "GOAL STRING: " *> trace goal_string, (goal_pexpr, _) ← interaction_monad.run_with_state' ps $ with_input types.texpr goal_string, eval_trace ps.cur_pos, set_goal_to <e> goal_pexpr, (read_eval_print_loop ps) *> main_t ps -- loops forever @[user_command] meta def main_app (meta_info : decl_meta_info) (_ : parse (tk "main_app")) : lean.parser unit := (get_state >>= of_tactic ∘ main_t) end main section parse_tac setup_tactic_parser open tactic /-- Parse a reflected interactive tactic from a string. The result can be evaluated to a `tactic unit` by using `eval_expr (tactic unit)`. -/ meta def parse_itactic_reflected (tactic_string : string) : tactic expr := let itactic_string := "{ " ++ tactic_string ++ " }" in lean.parser.run $ do get_state >>= λ ps, of_tactic $ do tactic.set_env ps.env, -- eval_trace format!"[parse_itactic_reflected] TRYING TO PARSE {itactic_string}", (reflected_value.expr ∘ prod.fst) <$> (@interaction_monad.run_with_state' parser_state _ _ ps $ with_input parser.itactic_reflected itactic_string) /-- Parse an interactive tactic from a string. -/ meta def parse_itactic (tactic_string : string) : tactic (tactic unit) := do rtac ← parse_itactic_reflected tactic_string, eval_expr (tactic unit) rtac end parse_tac section evaluation_harness meta def run_tac_with_tactic_state (tac : tactic unit) (ts : tactic_state) : tactic (result _ _) := do { tactic.write ts, pure $ tac ts } meta structure EvaluationInput : Type := (decl_nm : name) (ts_data : tactic_state_data) (tactic_string : string) (open_namespaces : list name) /- (before_state, action, after_state) tuple -/ meta structure EvaluationResult : Type := (before_state : tactic_state) (tactic_string : string) (result : result tactic_state unit) meta instance : has_to_format EvaluationResult := ⟨λ ⟨σ, tac_str, r⟩, format.join [ -- hmm. why doesn't the highlighting work? format.highlight "INPUT STATE:\n" format.color.pink, σ.to_format, "\n\n", format.highlight "ACTION:\n" format.color.pink, tac_str, "\n\n", format.highlight "RESULT:\n" format.color.pink, (has_to_format.to_format r) ] ⟩ /-- Creates an empty tactic state. -/ meta def mk_tactic_state : tactic tactic_state := tactic.unsafe_run_io $ io.run_tactic' $ tactic.exact `(trivial) *> tactic.read /-- creates tactic_state_data as if we were proving the declaration (currently only theorems are supported) with name `decl_nm`. -/ meta def get_tsd_at_decl (decl_nm : name) : tactic tactic_state_data := do { env ← tactic.get_env, decl ← env.get decl_nm, mk_tactic_state >>= tactic.write, ts ← tactic.read, tactic.set_goal_to decl.type, result ← tactic_state_data.get, tactic.write ts, pure result } meta def run_evaluation : EvaluationInput → tactic EvaluationResult := λ ⟨decl, ts_data, tactic_string, ns⟩, (tactic.unsafe_run_io ∘ io.run_tactic') $ do { tac ← parse_itactic tactic_string, env ← get_env_at_decl decl, tactic.set_env_core env, add_open_namespaces ns, ts ← rebuild_tactic_state ts_data *> tactic.read, EvaluationResult.mk ts tactic_string <$> run_tac_with_tactic_state tac ts } section greedy_proof_search meta structure ModelAPI (input_format : Type := json) : Type := (query : input_format → io json) /- for testing -/ meta def dummy_api {α} : ModelAPI α := ⟨λ _, pure $ json.of_string "[DummyAPI] FAILURE"⟩ namespace tactic open interaction_monad interaction_monad.result /- capture but backtrack the state -/ meta def capture' {α} (t : tactic α) : tactic (tactic_result α) := λ s, match t s with | (success r s') := success (success r s') s | (exception f p s') := success (exception f p s') s end end tactic meta def tactic_hash : tactic ℕ := do { gs ← tactic.get_goals, hs ← gs.mmap $ λ g, do { tactic.set_goal_to g, es ← (::) <$> tactic.target <*> tactic.local_context, pure $ es.foldl (λ acc e, acc + e.hash) 0}, pure $ hs.sum } meta def compare_tactic_state : tactic_state → tactic_state → tactic bool := λ ts₁ ts₂, do { ts ← tactic.read, h₁ ← (tactic.write ts₁ *> tactic_hash), h₂ ← (tactic.write ts₂ *> tactic_hash), tactic.write ts, pure $ h₁ = h₂ } -- let done_handler : state_t GreedyProofSearchState tactic bool := do { -- state_t.lift $ do { -- tactic.done, -- tactic.result >>= (λ x, tactic.guard_sorry x <|> -- eval_trace format! "[greedy_proof_search_step] WARNING: result contains sorry" *> tactic.failed), -- tactic.result >>= (λ x, tactic.type_check x <|> -- eval_trace format! "[greedy_proof_search_step] WARNING: result failed typechecking" *> tactic.failed) -- }, meta def validate_proof (pf : expr) : tactic unit := do { let tac (e : expr) : tactic unit := do { mk_tactic_state >>= tactic.write, guard (bnot pf.has_meta_var), tactic.guard_sorry e, tactic.type_check e }, result ← tactic.capture' (tac pf), match result with | (interaction_monad.result.success r s') := pure () | (interaction_monad.result.exception f p s') := tactic.fail "[validate_proof] ERROR: VALIDATION FAILED" end } meta def tactic_state.is_done (state : tactic_state) : tactic bool := do { ts ← tactic.read, result_flag ← do { tactic.write state, (do { tactic.done *> pure tt }) <|> pure ff }, tactic.write ts, pure result_flag } meta def tactic_result.is_done {α} (tr : tactic_result α) : tactic bool := do { match tr with | (interaction_monad.result.success val state) := state.is_done | (interaction_monad.result.exception _ _ _) := pure ff end } meta def get_tac_and_capture_result (next_candidate : string) (timeout : ℕ := 5000) : tactic (tactic_result unit) := do { tac ← do { env ← tactic.get_env, eval_trace format!"[get_tac_and_capture_result] PARSING TACTIC: {next_candidate}", tac ← parse_itactic next_candidate, eval_trace format!"[get_tac_and_capture_result] PARSE SUCCESSFUL", tactic.set_env env, pure tac }, eval_trace format!"[get_tac_and_capture_result] TRYING TACTIC: {next_candidate}", result ← tactic.capture' (tactic.try_for_time timeout $ tactic.try_for 200000 tac), -- if `tac` fails, exception is captured here eval_trace format!"[get_tac_and_capture_result] RESULT: {result}", /- use tactic state hashing to fail on no-ops modulo permutation -/ result ← match result with | (interaction_monad.result.success val ts') := do { ts ← tactic.read, mcond (compare_tactic_state ts ts') (pure $ interaction_monad.mk_exception "tactic state no-op" none ts') (pure result) } | exc := pure exc end, pure result } meta def try_get_tac_and_capture_result (tac_string : string) (timeout : ℕ := 5000) : tactic (tactic_result unit) := do { get_tac_and_capture_result tac_string timeout <|> do { let msg : format := format!"[try_get_tac_and_capture_result] parse_itactic failed on {tac_string}", eval_trace msg, interaction_monad.mk_exception msg none <$> tactic.read } } -- caller of this function is responsible for inspecting results and stopping the search meta def run_all_beam_candidates (get_candidates : json → tactic (list (string × native.float))) (msg : json) (tac_timeout : ℕ := 5000) : tactic (list (tactic_result unit × string × native.float) × list string) := do { let try_candidate_state := (list (string × native.float) × (list $ option $ tactic_result unit × string × native.float)), let stop : option (tactic_result unit × string × native.float) → state_t try_candidate_state tactic bool := λ arg, match arg with | some ⟨result, candidate⟩ := do { state_t.lift result.is_done } | none := pure ff end, /- TODO(jesse): get rid of this state_t and just use `run_async <$> ...` instead -/ let try_candidate : state_t try_candidate_state tactic (option $ tactic_result unit × string × native.float) := do { state_t.lift $ eval_trace format!"[try_candidate] ENTERING", ts ← state_t.lift tactic.read, state_t.lift $ eval_trace format!"[try_candidate] READ TACTIC STATE", ⟨rest, _⟩ ← state_t.get, match rest with | [] := do { state_t.lift $ eval_trace format!"[try_candidate] END OF LOOP", pure $ some ⟨interaction_monad.fail "all candidates failed" ts, "FAILURE", 0.0⟩ } | (next_candidate::candidates) := do { state_t.modify (λ ⟨_, rs⟩, ⟨candidates, rs⟩), result ← monad_lift $ try_get_tac_and_capture_result next_candidate.fst tac_timeout, when (interaction_monad.result.is_success $ result) $ state_t.modify $ λ ⟨candidates, rs⟩, ⟨candidates, rs ++ [some $ ⟨result, next_candidate⟩]⟩, state_t.lift $ eval_trace format!"[try_candidate] CAPTURED RESULT: {result}", pure $ some ⟨result, next_candidate⟩ } end }, -- let find_successful_candidates -- (candidates : list (string × native.float)) -- : tactic (list (tactic_result unit × string × native.float)) := do { -- tasks ← candidates.mmap (λ arg, flip prod.mk arg <$> tactic.run_async (try_get_tac_and_capture_result arg.fst : tactic $ tactic_result unit)), -- tactic.using_new_ref ff $ λ flag, do -- tasks.iterM [] $ λ acc ⟨task, tac_string, score⟩, do { -- mcond (tactic.read_ref flag) (pure acc) $ do { -- let result := task.get, -- if (interaction_monad.result.is_success result) then do { -- whenM (result.is_done) $ tactic.write_ref flag tt, -- pure $ acc ++ [⟨result, tac_string, score⟩] -- } else do { -- pure acc -- } -- } -- } -- }, -- this is responsible for gracefully handling "error" JSON messages and should return an empty list of candidates unwrapped_candidates ← get_candidates msg, -- eval_trace format!"[run_all_beam_candidates] UNWRAPPED CANDIDATES: {unwrapped_candidates}", dedup_unwrapped_candidates ← list.dedup' unwrapped_candidates, eval_trace format!"[run_all_beam_candidates] DEDUP_UNWRAPPED CANDIDATES: {dedup_unwrapped_candidates}", let candidates := list.filter (λ x, ¬ "tidy".is_prefix_of (prod.fst x)) dedup_unwrapped_candidates, eval_trace format!"[run_all_beam_candidates] CANDIDATES: {candidates}", -- old failure callback -- let failure_callback := do { -- -- do ts ← state_t.lift tactic.read, pure ⟨interaction_monad.fail "all candidates failed" ts, "FAILURE", 0.0⟩ -- } -- successful_candidates ← (prod.snd <$> prod.snd <$> state_t.run (iterate_until try_candidate stop candidates.length $ pure none) ⟨candidates, []⟩), -- successful_candidates ← find_successful_candidates candidates, eval_trace format!"[run_all_beam_candidates] EXITING TRY_CANDIDATE LOOP", eval_trace format!"[run_all_beam_candidates] SUCCESSFUL CANDIDATES: {successful_candidates}", pure ⟨successful_candidates.filter_map id, prod.fst <$> candidates⟩ } meta def run_best_beam_candidate (get_candidates : json → tactic (list string)) (msg : json) (tac_timeout : ℕ := 5000) : tactic (tactic_result unit × string × list string) := do { let try_candidates : state_t (list string) tactic ((tactic_result unit) × string) := do { ts ← state_t.lift (tactic.read), (next_candidate::candidates) ← state_t.get | pure (interaction_monad.fail "all candidates failed" ts, "FAILURE"), state_t.modify (λ _, candidates), flip prod.mk next_candidate <$> (state_t.lift $ try_get_tac_and_capture_result next_candidate tac_timeout) -- let get_tac_and_capture_result : state_t (list string) tactic ((tactic_result unit) × string) := do { -- tac ← state_t.lift $ do { -- env ← tactic.get_env, -- eval_trace format!"[run_best_beam_candidate] PARSING TACTIC: {next_candidate}", -- tac ← parse_itactic next_candidate, -- this is the only possible point of program failure -- eval_trace format!"[run_best_beam_candidate] PARSE SUCCESSFUL", -- tactic.set_env env, -- pure tac -- }, -- state_t.lift $ do -- eval_trace format!"[run_best_beam_candidate] TRYING TACTIC: {next_candidate}", -- result ← tactic.capture' (tactic.try_for 200000 tac), -- if `tac` fails, exception is captured here -- eval_trace format!"[run_best_beam_candidate] RESULT: {result}", -- result ← match result with -- | (interaction_monad.result.success val ts') := do { -- ts ← tactic.read, -- -- ite ((format.to_string $ has_to_format.to_format ts) = (format.to_string $ has_to_format.to_format ts')) -- mcond (compare_tactic_state ts ts') -- (pure $ interaction_monad.mk_exception "tactic state no-op" none ts') -- (pure result) -- } -- | exc := pure exc -- end, -- pure ⟨result, next_candidate⟩ -- }, -- get_tac_and_capture_result <|> -- handle `parse_itactic` failure here -- let msg : format := format!"[run_best_beam_candidate.try_candidates] parse_itactic failed on {next_candidate}" in do -- state_t.lift (eval_trace msg), -- (pure ⟨interaction_monad.mk_exception -- msg none ts, next_candidate⟩) }, let stop : tactic_result unit × string → state_t (list string) tactic bool := pure ∘ interaction_monad.result.is_success ∘ prod.fst, candidates ← list.filter (λ x, ¬ "tidy".is_prefix_of x) <$> (get_candidates msg >>= list.dedup), eval_trace format!"[run_best_beam_candidate] CANDIDATES: {candidates}", try_candidates_result@⟨result, tac_string⟩ ← ((prod.fst <$> state_t.run (iterate_until try_candidates stop) candidates) <|> do { old_state ← tactic.read, pure (prod.mk (interaction_monad.mk_exception "all candidates failed" none old_state) "all failed") }), eval_trace format!"[run_best_beam_candidate] TRY_CANDIDATES_RESULT: {try_candidates_result}", pure ⟨result, tac_string, candidates⟩ } -- TODO(jesse): finalize JSON format for serialize_ts/decode_response protocol meta structure GreedyProofSearchState : Type := (depth : ℕ := 0) (tactics : list string := []) (predictions : list (list string) := []) (states : list tactic_state := []) -- TODO(jesse): this might make the logs extremely verbose (success : bool := ff) (all_failed : bool := ff) (task_id : string := "") (global_timeout : bool := ff) (tac_timeout : ℕ := 5) (fuel_exhausted : bool := ff) (decl_goal : string := "") attribute [derive has_to_format] GreedyProofSearchState meta instance : has_mark_global_timeout GreedyProofSearchState := ⟨λ σ, {global_timeout := tt, ..σ}⟩ meta instance : has_register_task_id GreedyProofSearchState := ⟨λ σ task, {task_id := task, ..σ}⟩ meta instance : has_set_tac_timeout GreedyProofSearchState := ⟨λ σ timeout, {tac_timeout := timeout, ..σ}⟩ meta instance : has_get_tac_timeout GreedyProofSearchState := ⟨GreedyProofSearchState.tac_timeout⟩ meta instance : has_mark_fuel_exhausted GreedyProofSearchState := ⟨λ σ, {fuel_exhausted := tt, ..σ}⟩ meta instance : has_register_decl_goal GreedyProofSearchState := ⟨λ σ decl_goal, {decl_goal := decl_goal, ..σ}⟩ meta def serialize_list_string : list string → json := λ xs, json.array $ json.of_string <$> xs -- we supply our own instance since the default derive handler is too verbose meta instance : has_to_tactic_json GreedyProofSearchState := let fn : GreedyProofSearchState → tactic json := λ σ, do { (serialized_states : list string) ← do { σ.states.mmap postprocess_tactic_state }, pure $ json.object $ [ ("depth", json.of_int σ.depth) , ("tactics", serialize_list_string σ.tactics) , ("predictions", json.array $ serialize_list_string <$> σ.predictions) -- store only pretty-printed tactic states for now, with newlines replaced by tabs , ("states", json.array $ json.of_string <$> serialized_states) , ("success", json.of_bool σ.success) , ("all_failed", json.of_bool σ.all_failed) , ("task_id", json.of_string σ.task_id) , ("global_timeout", json.of_bool σ.global_timeout) , ("fuel_exhausted", json.of_bool σ.fuel_exhausted) , ("decl_goal", json.of_string σ.decl_goal) ] } in ⟨fn⟩ namespace GreedyProofSearchState meta def add_tac : GreedyProofSearchState → string → GreedyProofSearchState := λ σ tac, {tactics := σ.tactics ++ [tac], ..σ} meta def bump_depth : GreedyProofSearchState → GreedyProofSearchState := λ σ, {depth := nat.succ σ.depth, ..σ} meta def add_prediction : GreedyProofSearchState → list string → GreedyProofSearchState := λ σ pred, {predictions := σ.predictions ++ [pred], ..σ} meta def add_state : GreedyProofSearchState → tactic_state → GreedyProofSearchState := λ σ ts, {states := σ.states ++ [ts], ..σ} meta def mark_all_failed : GreedyProofSearchState → GreedyProofSearchState := λ σ, {all_failed := tt, ..σ} end GreedyProofSearchState meta def greedy_proof_search_step {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) -- note(jesse): this is responsible for e.g. selecting a candidate from the beam (decode_response : json → ℕ → tactic (tactic_result unit × string × list string)) : state_t GreedyProofSearchState tactic (bool × GreedyProofSearchState) := do { state_t.lift $ eval_trace "[greedy_proof_search_step] ENTERING", let handle_response (response : tactic_result unit × string × list string) : state_t GreedyProofSearchState tactic unit := match response with | response@⟨result, tac_string, candidates⟩ := do { if not result.is_success then do { -- let msg := format!"[greedy_proof_search_step.handle_response] UNEXPECTED -- interaction_monad.result.exception: {result}", -- eval_trace msg *> tactic.fail msg modify $ λ σ, σ.mark_all_failed, old_state ← state_t.lift $ tactic.read, modify $ λ σ, σ.add_state old_state, modify $ λ σ, σ.add_prediction candidates } else do { (interaction_monad.result.success _ ts) ← pure result, -- state_t.lift $ tactic.unsafe_run_io $ io.run_tactic' $ _ modify $ λ σ, σ.bump_depth, modify $ λ σ, σ.add_tac tac_string, modify $ λ σ, σ.add_prediction candidates, old_state ← state_t.lift $ tactic.read, modify $ λ σ, σ.add_state old_state } } end, let get_response_and_resume : state_t GreedyProofSearchState tactic bool := do { tac_timeout_seconds ← GreedyProofSearchState.tac_timeout <$> get, response@⟨result, tac_string, candidates⟩ ← state_t.lift $ do { ts_msg ← tactic.read >>= serialize_ts, eval_trace "[greedy_proof_search_step] QUERYING API", response_msg ← tactic.unsafe_run_io $ api.query ts_msg, eval_trace format!"[greedy_proof_search_step] RESPONSE MSG {response_msg}", eval_trace format!"[greedy_proof_search_step] RUNNING DECODE RESPONSE WITH TIMEOUT {tac_timeout_seconds*1000}", response ← decode_response response_msg $ tac_timeout_seconds*1000, pure response }, state_t.lift $ eval_trace "[greedy_proof_search_step] HANDLING RESPONSE", handle_response response, state_t.lift $ eval_trace "[greedy_proof_search_step] HANDLED RESPONSE", state_t.lift $ do { eval_trace format!"DECODED RESPONSE: {result}", when result.is_success $ tactic.resume result, eval_trace format!"RESUMED" }, let done_handler : state_t GreedyProofSearchState tactic bool := do { state_t.lift $ do { tactic.done, tactic.result >>= (λ x, tactic.guard_sorry x <|> eval_trace format! "[greedy_proof_search_step] WARNING: result contains sorry" *> tactic.failed), tactic.result >>= (λ x, tactic.type_check x <|> eval_trace format! "[greedy_proof_search_step] WARNING: result failed typechecking" *> tactic.failed) }, modify $ λ σ, {success := tt, ..σ}, pure tt } <|> pure ff, let tactic_exception_handler : state_t GreedyProofSearchState tactic bool := do { pure (bnot result.is_success) }, done_flag ← done_handler, exception_flag ← tactic_exception_handler, pure (done_flag || exception_flag) }, done_flag ← get_response_and_resume, -- let done_handler : state_t GreedyProofSearchState tactic bool := do { -- state_t.lift done, -- modify $ λ σ, {success := tt, ..σ}, -- pure tt -- }, -- done_flag ← done_handler <|> pure ff, state_t.lift $ eval_trace format! "DONE FLAG: {done_flag}", -- pure ⟨done_flag⟩ prod.mk done_flag <$> get /- in second branch, no predictions succeeded and the proof search halts early -/ } /- TODO(jesse): record proof search state + search statistics; wrap this in a state_t -/ /- `decode_response` should not modify the tactic state and currently should only return successful `tactic_result`s -/ /- in the full BFS case, `decode_response` should return a list of `tactic_result unit`s, which may be ```success` or `exception` these should then be logged by the `handle_response` function in `greedy_proof_search_step`, and the successful applications should be added to the search queue. -/ meta def greedy_proof_search_core {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) (decode_response : json → ℕ → tactic (tactic_result unit × string × list string)) (fuel := 100000) : state_t GreedyProofSearchState tactic unit := let fuel_exhausted_callback : state_t GreedyProofSearchState tactic (bool × GreedyProofSearchState) := do { state_t.modify has_mark_fuel_exhausted.mark_fuel_exhausted, prod.mk ff <$> get } in iterate_until (greedy_proof_search_step api serialize_ts decode_response) (λ x, pure $ x.fst = tt) fuel fuel_exhausted_callback *> pure () meta def greedy_proof_search {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) (decode_response : json → ℕ → tactic (tactic_result unit × string × list string)) (fuel := 100000) (verbose := ff) : tactic unit := do { ⟨_, σ⟩ ← state_t.run (greedy_proof_search_core api serialize_ts decode_response fuel) {}, when verbose $ eval_trace σ } end greedy_proof_search section bfs meta structure BFSNode : Type := (state : tactic_state) (score : ℤ := 0) (tactics : list string := []) (depth : ℕ := 0) attribute [derive has_to_format] BFSNode namespace BFSNode meta def of_current_state (score : ℤ := 0) (tacs : list string := []) : tactic BFSNode := do { ts ← tactic.read, pure $ ⟨ts, score, tacs, 0⟩ } end BFSNode meta structure BFSState : Type := (depth : ℕ := 0) (num_queries : ℕ := 0) (tactics : list string := []) (predictions : list (list string) := []) (states : list tactic_state := []) -- TODO(jesse): this might make the logs extremely verbose (success : bool := ff) (all_failed : bool := ff) (task_id : string := "") (max_width : ℕ := 25) -- max qsize (max_depth : ℕ := 50) (nodes : pqueue BFSNode.score := pqueue.empty) (api_failure_count : ℕ := 0) (all_failed_count : ℕ := 0) (global_timeout : bool := ff) (tac_timeout : ℕ := 5) (fuel_exhausted : bool := ff) (decl_goal : string := "") attribute [derive has_to_format] BFSState meta instance : has_mark_global_timeout BFSState := ⟨λ σ, {global_timeout := tt, ..σ}⟩ meta instance : has_register_task_id BFSState := ⟨λ σ task, {task_id := task, ..σ}⟩ meta instance : has_set_tac_timeout BFSState := ⟨λ σ timeout, {tac_timeout := timeout, ..σ}⟩ meta instance : has_mark_fuel_exhausted BFSState := ⟨λ σ, {fuel_exhausted := tt, ..σ}⟩ meta instance : has_get_tac_timeout BFSState := ⟨BFSState.tac_timeout⟩ meta instance : has_register_decl_goal BFSState := ⟨λ σ decl_goal, {decl_goal := decl_goal, ..σ}⟩ -- meta instance : has_to_tactic_json GreedyProofSearchState := -- let fn : GreedyProofSearchState → tactic json := λ σ, do { -- let serialize_list_string : list string → json := λ xs, -- json.array $ json.of_string <$> xs, -- (serialized_states : list string) ← do { -- σ.states.mmap postprocess_tactic_state -- }, -- pure $ json.object $ -- [ -- ("depth", json.of_int σ.depth) -- , ("tactics", serialize_list_string σ.tactics) -- , ("predictions", json.array $ serialize_list_string <$> σ.predictions) -- -- store only pretty-printed tactic states for now, with newlines replaced by tabs -- , ("states", json.array $ json.of_string <$> serialized_states) -- , ("success", json.of_bool σ.success) -- , ("all_failed", json.of_bool σ.all_failed) -- , ("task_id", json.of_string σ.task_id) -- ] -- } in ⟨fn⟩ -- TODO(jesse): upgrade to full instance meta instance : has_to_tactic_json BFSState := let fn : BFSState → tactic json := λ σ, do { (serialized_states : list string) ← do { σ.states.mmap $ λ x, tactic.with_full_names $ postprocess_tactic_state x }, pure $ json.object [ ("depth", json.of_int (σ.depth)) , ("tactics", json.array $ (json.of_string <$> σ.tactics)) -- , ("predictions", json.array $ serialize_list_string <$> σ.predictions) , ("states", json.array $ json.of_string <$> serialized_states) , ("success", json.of_bool (σ.success)) , ("num_queries", json.of_int (σ.num_queries)) , ("task_id", json.of_string $ σ.task_id) , ("api_failure_count", json.of_int $ σ.api_failure_count) , ("all_failed_count", json.of_int $ σ.all_failed_count) , ("global_timeout", json.of_bool (σ.global_timeout)) , ("fuel_exhausted", json.of_bool σ.fuel_exhausted) , ("decl_goal", json.of_string σ.decl_goal) ] } in ⟨fn⟩ section BFSState namespace BFSState meta def register_task_id : BFSState → string → BFSState := λ σ task_id, {task_id := task_id, ..σ} meta def bump_num_queries : BFSState → BFSState := λ σ, {num_queries := nat.succ σ.num_queries, ..σ} meta def push_nodes : BFSState → list BFSNode → BFSState := λ σ nodes, {nodes := σ.nodes.enqueue_many nodes, ..σ} meta def push_node : BFSState → BFSNode → BFSState := λ S σ, S.push_nodes [σ] meta def add_tac : BFSState → string → BFSState := λ σ tac, {tactics := σ.tactics ++ [tac], ..σ} meta def add_tacs : BFSState → list string → BFSState := λ σ tacs, {tactics := σ.tactics ++ tacs, ..σ} meta def bump_depth : BFSState → BFSState := -- λ ⟨d, tacs, preds⟩, ⟨nat.succ d, tacs, preds⟩ λ σ, {depth := nat.succ σ.depth, ..σ} meta def add_prediction : BFSState → list string → BFSState := -- λ ⟨d, tacs, preds⟩ pred, ⟨d, tacs, preds ++ [pred]⟩ λ σ pred, {predictions := σ.predictions ++ [pred], ..σ} meta def add_state : BFSState → tactic_state → BFSState := λ σ ts, {states := σ.states ++ [ts], ..σ} meta def mark_all_failed : BFSState → BFSState := λ σ, {all_failed := tt, ..σ} meta def mark_success : BFSState → BFSState := λ σ, {success := tt, ..σ} meta def of_current_state (score : ℤ := 0) (max_width : ℕ := 25) (max_depth : ℕ := 50) (tac_timeout : ℕ := 5000) : tactic BFSState := do { init_node ← BFSNode.of_current_state score, pure {nodes := pqueue.empty.enqueue init_node, max_width := max_width, max_depth := max_depth, tac_timeout := tac_timeout} } meta def bump_api_failure_count : BFSState → BFSState := λ σ, {api_failure_count := σ.api_failure_count + 1, ..σ} meta def bump_all_failed_count : BFSState → BFSState := λ σ, {all_failed_count := σ.all_failed_count + 1, ..σ} end BFSState end BFSState meta def score_of_float : native.float → int := λ x, native.float.floor ((1000.0 : native.float) * x) meta def pop_node : state_t BFSState tactic BFSNode := do { tss ← BFSState.nodes <$> get, match tss.dequeue with | (some (next, new_nodes)) := do { modify $ λ S, {nodes := new_nodes, ..S}, pure next } | none := state_t.lift ∘ tactic.fail $ format!"[pop_node] pqueue empty" end } /- Each step of BFS does the following: - pops a node off the queue - expands the node, producing a list of descendant nodes - if any descendant node represents a completed proof search, extract the result and use it to fill the main goal - this is accomplished by setting the tactic state -/ meta def bfs_step {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) -- note(jesse): this is responsible for e.g. selecting a candidate from the beam (decode_response : json → ℕ → tactic (list (tactic_result unit × string × native.float) × list string)) : state_t BFSState tactic (bool × BFSState) := do { σ ← get, state_t.lift $ eval_trace format!"[bfs_step] ENTERING, QUEUE STATE: {σ.nodes}", (some next_node) ← (some <$> pop_node <|> pure none) | (state_t.lift $ eval_trace format!"[bfs_step] queue empty") *> pure ⟨tt, σ⟩, -- yikes ts ← state_t.lift $ tactic.read, state_t.lift $ tactic.write next_node.state, let handle_response (response : list (tactic_result unit × string × native.float) × (list string)) : state_t BFSState tactic unit := match response with | response@⟨successes, candidates⟩ := do { modify $ λ σ, σ.add_prediction candidates, modify $ λ σ, σ.bump_num_queries, when (successes.length = 0) $ modify $ λ σ, σ.bump_all_failed_count, when (candidates.length = 0) $ modify $ λ σ, σ.bump_api_failure_count -- successes.mmap' $ λ ⟨result, tac_string, score⟩, do { -- pure () -- } } end, let get_response_and_resume : state_t BFSState tactic bool := do { -- TODO(jesse): `successes` needs to be generalized from `string` to an arbitrary datatype `α` -- for the best-first case. for now, we just score everything 0 to get this working tac_timeout_seconds ← BFSState.tac_timeout <$> get, decl_nm ← BFSState.task_id <$> get, response@⟨successes, candidates⟩ ← state_t.lift $ do { ts_msg ← tactic.read >>= serialize_ts, eval_trace "[bfs_step] QUERYING API", response_msg ← tactic.unsafe_run_io $ api.query ts_msg, eval_trace format!"[bfs_step] RESPONSE MSG {response_msg}", eval_trace format!"[bfs_step] RUNNING DECODE RESPONSE WITH TAC_TIMEOUT {tac_timeout_seconds * 1000}", do {env ← tactic.get_env, d ← env.get decl_nm, tactic.trace format! "[run_proof_search_step] WARNING: GOT DECL {decl_nm}"} <|> do {tactic.trace format! "[run_proof_search_step] NO GOT DECL {decl_nm}"}, decoded_response@⟨successes, _⟩ ← decode_response response_msg $ tac_timeout_seconds * 1000, eval_trace $ format!"[bfs_step] SUCCESSFUL CANDIDATES: {successes}", pure decoded_response }, handle_response response, -- turn the successes into a list of new BFSNodes (new_nodes : list BFSNode) ← successes.mmap (λ ⟨tr, tac, score⟩, match tr with | (interaction_monad.result.success _ state) := do { -- assumes that higher float score is better let scale_factor := (-100000.0 : native.float), let int_score : int := native.float.floor $ (score * scale_factor) + next_node.score, pure $ BFSNode.mk state int_score (next_node.tactics ++ [tac]) (next_node.depth + 1) } | exc := state_t.lift (tactic.fail format!"[bfs_step] UNEXPECTED TACTIC RESULT WHEN CONVERTING TO new_nodes: {exc}") end ), monad_lift $ eval_trace format! "[bfs_step] NODES BEFORE SORTING: {new_nodes}", let new_nodes : list BFSNode := @list.merge_sort _ (λ x y : BFSNode, x.score < y.score) _ new_nodes, monad_lift $ eval_trace format! "[bfs_step] NODES AFTER SORTING: {new_nodes}", /- loop through the new nodes. if any of them are finished (no open goals), the proof search is done. otherwise, we add all of them to the BFSState pqueue and continue the search. -/ -- modify (λ σ, σ.push_nodes new_nodes), -- for_ new_nodes $ λ ⟨state, score⟩, do { -- } let BFSM := state_t BFSState tactic, let push_node_state := (list BFSNode), /- note(jesse): this version of `push_node_state_tac` does not quite replicate the behavior of greedy_proof_search at max_width := 1, because it will loop over all the successful candidates anyways and check if the proof is finished regardless of the state of the queue -/ -- let push_node_state_tac : state_t push_node_state BFSM (option BFSNode) := do { -- (next_node::xs) ← get | pure none, -- done_flag ← state_t.lift $ state_t.lift $ next_node.state.is_done, -- result ← if done_flag then pure (some next_node) else do { -- q ← BFSState.nodes <$> state_t.lift get, -- let qsize := q.size, -- state_t.lift $ state_t.lift $ eval_trace format!"[push_tac] QSIZE: {qsize}", -- state_t.lift $ state_t.lift $ eval_trace format!"[push_tac] QUEUE: {q}", -- size_exceeded ← (do σ ← state_t.lift get, -- pure $ to_bool $ (σ.max_width <= σ.nodes.size ∨ σ.max_depth < next_node.tactics.length)), -- -- TODO(jesse): more informative trace message -- -- TODO(jesse): currently we are erasing open tactic_states which exceed the depth limit. -- -- consider storing them in a pqueue of "frozen" nodes instead, and display them in the trace -- when size_exceeded $ monad_lift $ eval_trace format!"[push_tac] SIZE EXCEEDED", -- unless size_exceeded $ do { -- state_t.lift $ state_t.lift $ eval_trace format!"[push_tac] PUSHING NODE", -- state_t.lift $ state_t.modify (λ σ, σ.push_node next_node) -- }, -- pure none -- }, -- state_t.modify (λ _, xs), -- pure result -- }, /- note(jesse): this version of `push_node_state_tac` checks that the queue is OK before proceeding with the rest of the loop currently, if max_width := 0 (this is an off-by-one misnomer), this reproduces the logic of greedy_proof_search. -/ let push_node_state_tac : state_t push_node_state BFSM (option BFSNode) := do { limits_exceeded ← do { σ ← state_t.lift get, pure $ to_bool $ (σ.max_width < σ.nodes.size ∨ σ.max_depth < next_node.tactics.length) }, if limits_exceeded then do { monad_lift $ eval_trace format!"[push_tac] SIZE EXCEEDED", pure none } else do { (next_node::xs) ← get | pure none, done_flag ← monad_lift $ next_node.state.is_done, if done_flag then pure (some next_node) else do { q ← BFSState.nodes <$> state_t.lift get, let qsize := q.size, -- monad_lift $ eval_trace format!"[push_tac] QSIZE: {qsize}", -- monad_lift $ eval_trace format!"[push_tac] QUEUE: {q}", -- monad_lift $ eval_trace format!"[push_tac] PUSHING NODE", state_t.lift $ do { state_t.modify (λ σ : BFSState, σ.push_node next_node), state_t.modify $ λ σ, if σ.depth < next_node.depth then {depth := next_node.depth, ..σ} else σ /- note(jesse, January 22 2021, 01:08 AM) temporarily disabling for faster evals -/ -- state_t.modify $ λ σ, σ.add_state next_node.state -- TODO(jesse): store previous states per-node, not globally }, state_t.modify (λ _, xs), pure none } } }, (done_node) ← prod.fst <$> state_t.run (iterate_until push_node_state_tac (pure ∘ option.is_some) (new_nodes.length) (pure none)) new_nodes, match done_node with | (some node) := do { state_t.lift $ tactic.write node.state, state_t.modify (λ σ, σ.mark_success), state_t.modify (λ σ, σ.add_tacs node.tactics), pure tt } | none := pure ff end }, done_flag ← get_response_and_resume, state_t.lift $ eval_trace format! "DONE FLAG: {done_flag}", -- if we are done, then the state has already been set to the successful one -- otherwise, backtrack to the original state unlessM (pure done_flag) $ state_t.lift (tactic.write ts), prod.mk done_flag <$> get } meta def bfs_core {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) (decode_response : json → ℕ → tactic (list (tactic_result unit × string × native.float) × list string)) (fuel := 100000) : state_t BFSState tactic unit := let fuel_exhausted_callback : state_t BFSState tactic (bool × BFSState) := do { state_t.modify has_mark_fuel_exhausted.mark_fuel_exhausted, prod.mk ff <$> get } in do { ts₀ ← monad_lift $ tactic.read, [g] ← monad_lift $ tactic.get_goals, iterate_until (bfs_step api serialize_ts decode_response) (λ x, pure $ x.fst = tt) fuel fuel_exhausted_callback *> pure (), σ ← get, when σ.success $ do {pf ← monad_lift $ tactic.get_assignment g >>= tactic.instantiate_mvars, (monad_lift (do {-- tactic.set_goals [g], pf ← tactic.get_assignment g >>= tactic.instantiate_mvars, tgt ← tactic.infer_type pf, ts₁ ← tactic.read, tactic.write ts₀, -- important to backtrack to the old state for validation validate_proof pf, tactic.write ts₁ }) <|> (do monad_lift (eval_trace "[bfs_core] WARNING: VALIDATE_PROOF FAILED"), modify $ λ σ, {success := ff, ..σ})) } } meta def bfs {input_format : Type} (api : ModelAPI input_format) (serialize_ts : tactic_state → tactic input_format) (decode_response : json → ℕ → tactic (list (tactic_result unit × string × native.float) × list string)) (fuel := 100000) (verbose : bool := ff) (max_width : ℕ := 25) (max_depth : ℕ := 50) : tactic unit := do init_state ← BFSState.of_current_state 0 max_width max_depth, σ ← prod.snd <$> state_t.run (bfs_core api serialize_ts decode_response fuel) init_state, when verbose $ eval_trace σ end bfs namespace io.process meta instance : has_to_format spawn_args := ⟨λ args, args.cmd ++ " " ++ string.intercalate " " args.args⟩ end io.process section run_proof_search -- warning: do not use, buggy meta def try_import (m : module_info.module_name) : tactic unit := do let env := environment.from_imported_module_name m, env.fold (pure () : tactic unit) (λ decl acc, acc *> tactic.try (tactic.add_decl decl)) meta def run_proof_search_step {search_state : Type} (search_core : state_t search_state tactic unit) (decl_nm : name) (open_ns : list name) (show_trace : bool) (global_timeout : ℕ) (init_state : tactic search_state) [has_mark_global_timeout search_state] [has_register_decl_goal search_state] : io (search_state × string) := do io.run_tactic' $ do { tsd ← get_tsd_at_decl decl_nm, eval_trace format!"[run_proof_search_step] GOT TSD AT DECL {decl_nm}", --- set the environment at decl env ← get_env_at_decl decl_nm, eval_trace format!"[run_proof_search_step] GOT ENV AT DECL {decl_nm}", tactic.set_env_core env, eval_trace format!"[run_proof_search_step] SET ENV AT DECL {decl_nm}", add_open_namespaces open_ns, eval_trace format!"[run_proof_search_step] ADDED OPEN NAMESPACES {open_ns}", /- note(jesse, January 14 2021, 09:52 AM): commented out because now we should always have namespaces in the .names files -/ -- additionally open namespaces in decl_nm -- for_ decl_nm.components -- (λ nm, do env ← tactic.get_env, when (env.is_namespace nm) $ -- (eval_trace format! "[run_proof_search_step] ADDING OPEN NAMESPACE {nm}") *> -- add_open_namespace nm), -- eval_trace "[run_proof_search_step] GOT TSD", -- eval_trace format!"[run_proof_search_step] SET ENV AT DECL {decl_nm}", rebuild_tactic_state tsd, eval_trace format!"[run_proof_search_step] REBUILT TACTIC STATE, ENTERING SEARCH CORE WITH TIMEOUT {global_timeout * 1000}", decl_goal_string ← format.to_string <$> (tactic.target >>= tactic.pp), tactic.read >>= λ ts, eval_trace format!"[run_proof_search_step] TACTIC STATE BEFORE SEARCH CORE: {ts}", env ← tactic.get_env, do {d ← env.get decl_nm, tactic.trace "[run_proof_search_step] WARNING: GOT DECL"} <|> do {tactic.trace "[run_proof_search_step] NO GOT DECL"}, σ₀ ← flip has_register_decl_goal.register_decl_goal decl_goal_string <$> init_state, σ ← (prod.snd <$> tactic.try_for_time (global_timeout * 1000) (state_t.run (search_core) σ₀) <|> do { eval_trace format!"[run_proof_search_step] GLOBAL TIMEOUT REACHED, ABORTING ", pure (has_mark_global_timeout.mark_global_timeout σ₀) }), -- pure $ {task_id := decl_nm.to_string, ..σ} pure ⟨σ, decl_nm.to_string⟩ } -- to be called in an environment which imports all declarations in `mathlib` -- ideally called on a shard of the test theorems meta def run_proof_search_core {search_state : Type} [has_to_tactic_json search_state] (search_core : state_t search_state tactic unit) (decl_nms : list (name × list name)) (process_search_state : search_state → io unit) (show_trace : bool) (global_timeout : ℕ) -- seconds -- (register_task_id : search_state → string → search_state) [has_register_task_id search_state] [has_mark_global_timeout search_state] [has_register_decl_goal search_state] (init_state : tactic search_state) : io unit := do { let run_proof_search_core_body : name → list name → io unit := λ decl_nm open_ns, do { when (decl_nm.length > 0) $ do when show_trace $ io.put_str_ln' format!"[run_proof_search_core] OUTER LOOP: PROCESSING DECL {decl_nm}", env₀ ← io.run_tactic' $ tactic.get_env, when show_trace $ io.put_str_ln' format!"[run_proof_search_core] GOT ENV", ⟨search_state, decl_nm⟩ ← (run_proof_search_step search_core decl_nm open_ns show_trace global_timeout init_state), let search_state := has_register_task_id.register_task_id search_state decl_nm, when show_trace $ io.put_str_ln' format!"[run_proof_search_core] GOT SEARCH STATE", io.run_tactic' $ tactic.set_env_core env₀, process_search_state search_state }, for_ decl_nms (λ ⟨decl_nm, open_ns⟩, do run_proof_search_core_body decl_nm open_ns <|> io.put_str_ln' format!"[run_proof_search_core] WARNING: SKIPPING {decl_nm}" )} end run_proof_search end evaluation_harness section playground -- example : ℤ → bool -- | (of_int k) := if -- set_option pp.notation false -- #reduce (-3 : ℤ) -- example (x : ℕ) : nat.zero.gcd x = x := -- begin -- simp [nat.gcd] -- end end playground
f6e4305cdbb73f36822a5d8471486f1237176a1f
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
/src/Lean/Meta/Reduce.lean
27765dc65588d48625d4e2de897feeca99aa49ef
[ "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,735
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 -/ import Lean.Meta.Basic import Lean.Meta.FunInfo import Lean.Util.MonadCache namespace Lean.Meta partial def reduce (e : Expr) (explicitOnly skipTypes skipProofs := true) : MetaM Expr := let rec visit (e : Expr) : MonadCacheT Expr Expr MetaM Expr := checkCache e fun _ => Core.withIncRecDepth do if (← (pure skipTypes <&&> isType e)) then return e else if (← (pure skipProofs <&&> isProof e)) then return e else let e ← whnf e match e with | Expr.app .. => let f ← visit e.getAppFn let nargs := e.getAppNumArgs let finfo ← getFunInfoNArgs f nargs let mut args := e.getAppArgs for i in [:args.size] do if i < finfo.paramInfo.size then let info := finfo.paramInfo[i]! if !explicitOnly || info.isExplicit then args ← args.modifyM i visit else args ← args.modifyM i visit if f.isConstOf ``Nat.succ && args.size == 1 && args[0]!.isNatLit then return mkRawNatLit (args[0]!.natLit?.get! + 1) else return mkAppN f args | Expr.lam .. => lambdaTelescope e fun xs b => do mkLambdaFVars xs (← visit b) | Expr.forallE .. => forallTelescope e fun xs b => do mkForallFVars xs (← visit b) | Expr.proj n i s .. => return mkProj n i (← visit s) | _ => return e visit e |>.run def reduceAll (e : Expr) : MetaM Expr := reduce e false false false end Lean.Meta
10d753186d4cf0f036b88921eb67a98bdb34fab4
d1a52c3f208fa42c41df8278c3d280f075eb020c
/stage0/src/Std/Data/BinomialHeap.lean
9961fe5c0d242b1bdf06bc10d8a3cd62874e7233
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
8,422
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, Jannis Limperg -/ namespace Std universe u namespace BinomialHeapImp structure HeapNodeAux (α : Type u) (h : Type u) where val : α rank : Nat children : List h -- A `Heap` is a forest of binomial trees. inductive Heap (α : Type u) : Type u where | heap (ns : List (HeapNodeAux α (Heap α))) : Heap α deriving Inhabited open Heap -- A `HeapNode` is a binomial tree. If a `HeapNode` has rank `k`, its children -- have ranks between `0` and `k - 1`. They are ordered by rank. Additionally, -- the value of each child must be less than or equal to the value of its -- parent node. abbrev HeapNode α := HeapNodeAux α (Heap α) variable {α : Type u} def hRank : List (HeapNode α) → Nat | [] => 0 | h::_ => h.rank def isEmpty : Heap α → Bool | heap [] => true | _ => false def empty : Heap α := heap [] def singleton (a : α) : Heap α := heap [{ val := a, rank := 1, children := [] }] -- Combine two binomial trees of rank `r`, creating a binomial tree of rank -- `r + 1`. @[specialize] def combine (le : α → α → Bool) (n₁ n₂ : HeapNode α) : HeapNode α := if le n₂.val n₁.val then { n₂ with rank := n₂.rank + 1, children := n₂.children ++ [heap [n₁]] } else { n₁ with rank := n₁.rank + 1, children := n₁.children ++ [heap [n₂]] } -- Merge two forests of binomial trees. The forests are assumed to be ordered -- by rank and `mergeNodes` maintains this invariant. @[specialize] partial def mergeNodes (le : α → α → Bool) : List (HeapNode α) → List (HeapNode α) → List (HeapNode α) | [], h => h | h, [] => h | f@(h₁ :: t₁), s@(h₂ :: t₂) => if h₁.rank < h₂.rank then h₁ :: mergeNodes le t₁ s else if h₂.rank < h₁.rank then h₂ :: mergeNodes le t₂ f else let merged := combine le h₁ h₂ let r := merged.rank if r != hRank t₁ then if r != hRank t₂ then merged :: mergeNodes le t₁ t₂ else mergeNodes le (merged :: t₁) t₂ else if r != hRank t₂ then mergeNodes le t₁ (merged :: t₂) else merged :: mergeNodes le t₁ t₂ @[specialize] def merge (le : α → α → Bool) : Heap α → Heap α → Heap α | heap h₁, heap h₂ => heap (mergeNodes le h₁ h₂) @[specialize] def head? (le : α → α → Bool) : Heap α → Option α | heap [] => none | heap (h::hs) => some $ hs.foldl (init := h.val) fun r n => if le r n.val then r else n.val @[inline] def head [Inhabited α] (le : α → α → Bool) (h : Heap α) : α := head? le h |>.getD arbitrary @[specialize] def findMin (le : α → α → Bool) : List (HeapNode α) → Nat → HeapNode α × Nat → HeapNode α × Nat | [], _, r => r | h::hs, idx, (h', idx') => if le h'.val h.val then findMin le hs (idx+1) (h', idx') else findMin le hs (idx+1) (h, idx) -- It is important that we check `le h'.val h.val` here, not the other way -- around. This ensures that head? and findMin find the same element even -- when we have `le h'.val h.val` and `le h.val h'.val` (i.e. le is not -- irreflexive). def deleteMin (le : α → α → Bool) : Heap α → Option (α × Heap α) | heap [] => none | heap [h] => let tail := match h.children with | [] => empty | (h::hs) => hs.foldl (merge le) h some (h.val, tail) | heap hhs@(h::hs) => let (min, minIdx) := findMin le hs 1 (h, 0) let rest := hhs.eraseIdx minIdx let tail := min.children.foldl (merge le) (heap rest) some (min.val, tail) @[inline] def tail? (le : α → α → Bool) (h : Heap α) : Option (Heap α) := deleteMin le h |>.map (·.snd) @[inline] def tail (le : α → α → Bool) (h : Heap α) : Heap α := tail? le h |>.getD empty partial def toList (le : α → α → Bool) (h : Heap α) : List α := match deleteMin le h with | none => [] | some (hd, tl) => hd :: toList le tl partial def toArray (le : α → α → Bool) (h : Heap α) : Array α := go #[] h where go (acc : Array α) (h : Heap α) : Array α := match deleteMin le h with | none => acc | some (hd, tl) => go (acc.push hd) tl partial def toListUnordered : Heap α → List α | heap ns => ns.bind fun n => n.val :: n.children.bind toListUnordered partial def toArrayUnordered (h : Heap α) : Array α := go #[] h where go (acc : Array α) : Heap α → Array α | heap ns => Id.run <| do let mut acc := acc for n in ns do acc := acc.push n.val for h in n.children do acc := go acc h return acc inductive WellFormed (le : α → α → Bool) : Heap α → Prop where | empty : WellFormed le empty | singleton (a) : WellFormed le (singleton a) | merge (h₁ h₂) : WellFormed le h₁ → WellFormed le h₂ → WellFormed le (merge le h₁ h₂) | deleteMin (a) (h tl) : WellFormed le h → deleteMin le h = some (a, tl) → WellFormed le tl theorem WellFormed.tail? {le} (h tl : Heap α) (hwf : WellFormed le h) (eq : tail? le h = some tl) : WellFormed le tl := by simp only [BinomialHeapImp.tail?] at eq match eq₂: BinomialHeapImp.deleteMin le h with | none => rw [eq₂] at eq; cases eq | some (a, tl) => rw [eq₂] at eq; cases eq exact deleteMin _ _ _ hwf eq₂ theorem WellFormed.tail {le} (h : Heap α) (hwf : WellFormed le h) : WellFormed le (tail le h) := by simp only [BinomialHeapImp.tail] match eq: BinomialHeapImp.tail? le h with | none => exact empty | some tl => exact tail? _ _ hwf eq end BinomialHeapImp open BinomialHeapImp def BinomialHeap (α : Type u) (le : α → α → Bool) := { h : Heap α // WellFormed le h } @[inline] def mkBinomialHeap (α : Type u) (le : α → α → Bool) : BinomialHeap α le := ⟨empty, WellFormed.empty⟩ namespace BinomialHeap variable {α : Type u} {le : α → α → Bool} @[inline] def empty : BinomialHeap α le := mkBinomialHeap α le @[inline] def isEmpty : BinomialHeap α le → Bool | ⟨b, _⟩ => BinomialHeapImp.isEmpty b /- O(1) -/ @[inline] def singleton (a : α) : BinomialHeap α le := ⟨BinomialHeapImp.singleton a, WellFormed.singleton a⟩ /- O(log n) -/ @[inline] def merge : BinomialHeap α le → BinomialHeap α le → BinomialHeap α le | ⟨b₁, h₁⟩, ⟨b₂, h₂⟩ => ⟨BinomialHeapImp.merge le b₁ b₂, WellFormed.merge b₁ b₂ h₁ h₂⟩ /- O(log n) -/ @[inline] def insert (a : α) (h : BinomialHeap α le) : BinomialHeap α le := merge (singleton a) h /- O(n log n) -/ def ofList (le : α → α → Bool) (as : List α) : BinomialHeap α le := as.foldl (flip insert) empty /- O(n log n) -/ def ofArray (le : α → α → Bool) (as : Array α) : BinomialHeap α le := as.foldl (flip insert) empty /- O(log n) -/ @[inline] def deleteMin : BinomialHeap α le → Option (α × BinomialHeap α le) | ⟨b, h⟩ => match eq: BinomialHeapImp.deleteMin le b with | none => none | some (a, tl) => some (a, ⟨tl, WellFormed.deleteMin a b tl h eq⟩) /- O(log n) -/ @[inline] def head [Inhabited α] : BinomialHeap α le → α | ⟨b, _⟩ => BinomialHeapImp.head le b /- O(log n) -/ @[inline] def head? : BinomialHeap α le → Option α | ⟨b, _⟩ => BinomialHeapImp.head? le b /- O(log n) -/ @[inline] def tail? : BinomialHeap α le → Option (BinomialHeap α le) | ⟨b, h⟩ => match eq: BinomialHeapImp.tail? le b with | none => none | some tl => some ⟨tl, WellFormed.tail? b tl h eq⟩ /- O(log n) -/ @[inline] def tail : BinomialHeap α le → BinomialHeap α le | ⟨b, h⟩ => ⟨BinomialHeapImp.tail le b, WellFormed.tail b h⟩ /- O(n log n) -/ @[inline] def toList : BinomialHeap α le → List α | ⟨b, _⟩ => BinomialHeapImp.toList le b /- O(n log n) -/ @[inline] def toArray : BinomialHeap α le → Array α | ⟨b, _⟩ => BinomialHeapImp.toArray le b /- O(n) -/ @[inline] def toListUnordered : BinomialHeap α le → List α | ⟨b, _⟩ => BinomialHeapImp.toListUnordered b /- O(n) -/ @[inline] def toArrayUnordered : BinomialHeap α le → Array α | ⟨b, _⟩ => BinomialHeapImp.toArrayUnordered b end BinomialHeap end Std
7ccbed0c53876ea84955b0603f420253949dda99
ca37452420f42eb9a19643a034c532fb39187bd0
/kruskal.lean
09bccae16e6a742ce9c23e572e822d96a9b7fda6
[]
no_license
minchaowu/Kruskal.lean
0096fd12c6732dcb55214907e7241df27d22a51e
0ec4a724c18d8fa2bc1e81dfc026a045888526d5
refs/heads/master
1,589,975,750,330
1,481,928,508,000
1,481,928,508,000
70,121,484
0
0
null
null
null
null
UTF-8
Lean
false
false
6,490
lean
import data.fin data.list open fin nat function list eq.ops inductive finite_tree : Type := | node : finite_tree | cons : Π {n : ℕ}, (fin n → finite_tree) → finite_tree namespace finite_tree definition size : finite_tree → ℕ | node := 1 | (@cons n ts) := Suml (upto n) (λ i, size (ts i)) + 1 theorem exists_eq_cons_of_ne_nil {A : Type} {l : list A} : l ≠ [] → ∃ a, ∃ l', l = a::l' := list.rec_on l (λ H, absurd rfl H) (λ a, λ l', λ IH, λ H, exists.intro a (exists.intro l' rfl)) lemma map_val_upto (n : nat) : map fin.val (upto n) = list.upto n := map_dmap_of_inv_of_pos (val_mk n) (@lt_of_mem_upto n) lemma length_upto (n : nat) : length (upto n) = n := -- in the latest library calc length (upto n) = length (list.upto n) : (map_val_upto n ▸ length_map fin.val (upto n))⁻¹ ... = n : list.length_upto n lemma upto_ne_nil_of_ne_zero (n : nat) (Hn : n ≠ 0) : upto n ≠ [] := begin intro Hup, apply Hn, rewrite [-(@length_nil (fin n)), -Hup], apply eq.symm !length_upto end theorem pos_of_size (t : finite_tree) : 0 < size t := finite_tree.induction_on t dec_trivial (λ n, λ ts, λ IH, by+ apply dec_trivial) theorem pos_of_Suml {n : ℕ} (H : n ≠ 0) (ts : fin n → finite_tree) : 0 < Suml (upto n) (λ i, size (ts i)) := have upto n ≠ nil, from upto_ne_nil_of_ne_zero n H, have ∃ a, ∃ l', fin.upto n = a::l', from exists_eq_cons_of_ne_nil this, obtain a ha, from this, obtain l' hl', from ha, let f := λ i, size (ts i) in have Suml (a::l') f = f a + Suml l' f, from Suml_cons f a l', have f a > 0, from pos_of_size (ts a), have f a + Suml l' f > 0, from add_pos_left this (Suml l' f), by+ simp theorem le_of_elt_Suml {n : ℕ} (ts : fin n → finite_tree) (k : fin n) : size (ts k) ≤ Suml (upto n) (λ i, size (ts i)) := -- what if n = 0? have k ∈ upto n, from mem_upto n k, have ∃s t, upto n = s ++ (k::t), from mem_split this, obtain (s t) hst, from this, have Suml (upto n) (λ i, size (ts i)) = Suml (s ++ (k::t)) (λ i, size (ts i)), by+ simp, have Suml (s ++ (k::t)) (λ i, size (ts i)) = Suml s (λ i, size (ts i)) + Suml (k::t) (λ i, size (ts i)), from Suml_append s (k::t) (λ i, size (ts i)), have Suml (k::t) (λ i, size (ts i)) = size (ts k) + Suml t (λ i, size (ts i)), from Suml_cons (λ i, size (ts i)) k t, have size (ts k) ≤ size (ts k) + Suml t (λ i, size (ts i)), from le_add_right (size (ts k)) (Suml t (λ i, size (ts i))), have le1 : size (ts k) ≤ Suml (k::t) (λ i, size (ts i)), by+ simp, have Suml (k::t) (λ i, size (ts i)) ≤ Suml s (λ i, size (ts i)) + Suml (k::t) (λ i, size (ts i)), from le_add_left (Suml (k::t) (λ i, size (ts i))) (Suml s (λ i, size (ts i))), have size (ts k) ≤ Suml s (λ i, size (ts i)) + Suml (k::t) (λ i, size (ts i)), from le.trans le1 this, by+ simp definition embeds : finite_tree → finite_tree → Prop | embeds node _ := true | embeds (cons ts) node := false | embeds (cons ts) (cons us) := (∃ j, embeds (cons ts) (us j)) ∨ (∃ f, injective f ∧ ∀ i, embeds (ts i) (us (f i))) /- -- here is a "hands on" definition of the same predicate: definition embeds (s t : finite_tree) : Prop := (finite_tree.rec (finite_tree.rec true (λ m ss embss, false)) (λ n ts embts, finite_tree.rec true (λ m ss embss, (∃ j, embts j (cons ss)) ∨ (∃ f, injective f ∧ ∀ i, embts (f i) (ss i))))) t s -/ infix ` ≼ `:50 := embeds -- \preceq proposition node_embeds (t : finite_tree) : node ≼ t := by induction t; repeat (apply trivial) proposition not_cons_embeds_node {n : ℕ} (ts : fin n → finite_tree) : ¬ cons ts ≼ node := not_false -- curiously, with either definition above, this doesn't work with = and rfl proposition cons_embeds_cons_iff {m n : ℕ} (ss : fin m → finite_tree) (ts : fin n → finite_tree) : cons ss ≼ cons ts ↔ (∃ j, cons ss ≼ ts j) ∨ (∃ f, injective f ∧ ∀ i, ss i ≼ ts (f i)) := !iff.refl proposition cons_embeds_cons_left {m n : ℕ} {ss : fin m → finite_tree} {ts : fin n → finite_tree} {j : fin n} (H : cons ss ≼ ts j) : cons ss ≼ cons ts := or.inl (exists.intro j H) proposition cons_embeds_cons_right {m n : ℕ} {ss : fin m → finite_tree} {ts : fin n → finite_tree} {f : fin m → fin n} (injf : injective f) (Hf : ∀ i, ss i ≼ ts (f i)) : cons ss ≼ cons ts := or.inr (exists.intro f (and.intro injf Hf)) proposition cons_embeds_cons_dest {m n : ℕ} {ss : fin m → finite_tree} {ts : fin n → finite_tree} (H : cons ss ≼ cons ts) : (∃ j, cons ss ≼ ts j) ∨ (∃ f, injective f ∧ ∀ i, ss i ≼ ts (f i)) := H proposition embeds_refl (t : finite_tree) : t ≼ t := finite_tree.induction_on t trivial (take n ts ih, cons_embeds_cons_right injective_id ih) private proposition embeds_trans_aux : ∀ {u s t}, t ≼ u → s ≼ t → s ≼ u := begin intro u, induction u with l us ihu, intro s t, cases s with n ss, intros, apply node_embeds, cases t, repeat (intros; contradiction), intro s t, cases s with n ss, intros, apply node_embeds, cases t with m ts, intros, contradiction, intro H₁, cases (cons_embeds_cons_dest H₁) with H₁₁ H₁₂, cases H₁₁ with i H₁₁, intro H₂, have cons ss ≼ us i, from ihu _ H₁₁ H₂, apply cons_embeds_cons_left this, cases H₁₂ with f Hf, cases Hf with injf Hf, intro H₂, cases (cons_embeds_cons_dest H₂) with H₂₁ H₂₂, cases H₂₁ with j H₂₁, have cons ss ≼ us (f j), from ihu _ (Hf j) H₂₁, apply cons_embeds_cons_left this, cases H₂₂ with g Hg, cases Hg with injg Hg, apply cons_embeds_cons_right, apply injective_compose injf injg, intro i, apply ihu _ (Hf (g i)) (Hg i) end proposition embeds_trans {s t u : finite_tree} (H₁ : s ≼ t) (H₂ : t ≼ u) : s ≼ u := embeds_trans_aux H₂ H₁ proposition cons_embeds_iff {m : ℕ} (ss : fin m → finite_tree) (t : finite_tree) : cons ss ≼ t ↔ ∃ n (ts : fin n → finite_tree), t = cons ts ∧ ((∃ j, cons ss ≼ ts j) ∨ (∃ f, injective f ∧ ∀ i, ss i ≼ ts (f i))) := begin apply iff.intro, intro H, cases t with n ts, contradiction, existsi n, existsi ts, split, reflexivity, apply cons_embeds_cons_dest H, intro H, cases H with n H, cases H with ts H, cases H with teq H, rewrite teq, exact H end end finite_tree
f2609d218dc2e8da0525c3fa1a8497f0e3f81c35
618003631150032a5676f229d13a079ac875ff77
/src/ring_theory/multiplicity.lean
808a05944fa3c6ddbe9951cbd0f7568908bfc64c
[ "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
17,347
lean
/- Copyright (c) 2018 Robert Y. Lewis. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Robert Y. Lewis, Chris Hughes -/ import algebra.associated import data.int.gcd import algebra.big_operators variables {α : Type*} open nat roption theorem nat.find_le {p q : ℕ → Prop} [decidable_pred p] [decidable_pred q] (h : ∀ n, q n → p n) (hp : ∃ n, p n) (hq : ∃ n, q n) : nat.find hp ≤ nat.find hq := nat.find_min' _ ((h _) (nat.find_spec hq)) /-- `multiplicity a b` returns the largest natural number `n` such that `a ^ n ∣ b`, as an `enat` or natural with infinity. If `∀ n, a ^ n ∣ b`, then it returns `⊤`-/ def multiplicity [comm_semiring α] [decidable_rel ((∣) : α → α → Prop)] (a b : α) : enat := ⟨∃ n : ℕ, ¬a ^ (n + 1) ∣ b, λ h, nat.find h⟩ namespace multiplicity section comm_semiring variables [comm_semiring α] @[reducible] def finite (a b : α) : Prop := ∃ n : ℕ, ¬a ^ (n + 1) ∣ b lemma finite_iff_dom [decidable_rel ((∣) : α → α → Prop)] {a b : α} : finite a b ↔ (multiplicity a b).dom := iff.rfl lemma finite_def {a b : α} : finite a b ↔ ∃ n : ℕ, ¬a ^ (n + 1) ∣ b := iff.rfl @[norm_cast] theorem int.coe_nat_multiplicity (a b : ℕ) : multiplicity (a : ℤ) (b : ℤ) = multiplicity a b := begin apply roption.ext', { repeat {rw [← finite_iff_dom, finite_def]}, norm_cast, simp }, { intros h1 h2, apply _root_.le_antisymm; { apply nat.find_le, norm_cast, simp }} end lemma not_finite_iff_forall {a b : α} : (¬ finite a b) ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨λ h n, nat.cases_on n (one_dvd _) (by simpa [finite, classical.not_not] using h), by simp [finite, multiplicity, classical.not_not]; tauto⟩ lemma not_unit_of_finite {a b : α} (h : finite a b) : ¬is_unit a := let ⟨n, hn⟩ := h in mt (is_unit_iff_forall_dvd.1 ∘ is_unit_pow (n + 1)) $ λ h, hn (h b) lemma ne_zero_of_finite {a b : α} (h : finite a b) : b ≠ 0 := let ⟨n, hn⟩ := h in λ hb, by simpa [hb] using hn lemma finite_of_finite_mul_left {a b c : α} : finite a (b * c) → finite a c := λ ⟨n, hn⟩, ⟨n, λ h, hn (dvd.trans h (by simp [_root_.mul_pow]))⟩ lemma finite_of_finite_mul_right {a b c : α} : finite a (b * c) → finite a b := by rw mul_comm; exact finite_of_finite_mul_left variable [decidable_rel ((∣) : α → α → Prop)] lemma pow_dvd_of_le_multiplicity {a b : α} {k : ℕ} : (k : enat) ≤ multiplicity a b → a ^ k ∣ b := nat.cases_on k (λ _, one_dvd _) (λ k ⟨h₁, h₂⟩, by_contradiction (λ hk, (nat.find_min _ (lt_of_succ_le (h₂ ⟨k, hk⟩)) hk))) lemma pow_multiplicity_dvd {a b : α} (h : finite a b) : a ^ get (multiplicity a b) h ∣ b := pow_dvd_of_le_multiplicity (by rw enat.coe_get) lemma is_greatest {a b : α} {m : ℕ} (hm : multiplicity a b < m) : ¬a ^ m ∣ b := λ h, have finite a b, from enat.dom_of_le_some (le_of_lt hm), by rw [← enat.coe_get (finite_iff_dom.1 this), enat.coe_lt_coe] at hm; exact nat.find_spec this (dvd.trans (pow_dvd_pow _ hm) h) lemma is_greatest' {a b : α} {m : ℕ} (h : finite a b) (hm : get (multiplicity a b) h < m) : ¬a ^ m ∣ b := is_greatest (by rwa [← enat.coe_lt_coe, enat.coe_get] at hm) lemma unique {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬a ^ (k + 1) ∣ b) : (k : enat) = multiplicity a b := le_antisymm (le_of_not_gt (λ hk', is_greatest hk' hk)) $ have finite a b, from ⟨k, hsucc⟩, by rw [← enat.coe_get (finite_iff_dom.1 this), enat.coe_le_coe]; exact nat.find_min' _ hsucc lemma unique' {a b : α} {k : ℕ} (hk : a ^ k ∣ b) (hsucc : ¬ a ^ (k + 1) ∣ b) : k = get (multiplicity a b) ⟨k, hsucc⟩ := by rw [← enat.coe_inj, enat.coe_get, unique hk hsucc] lemma le_multiplicity_of_pow_dvd {a b : α} {k : ℕ} (hk : a ^ k ∣ b) : (k : enat) ≤ multiplicity a b := le_of_not_gt $ λ hk', is_greatest hk' hk lemma pow_dvd_iff_le_multiplicity {a b : α} {k : ℕ} : a ^ k ∣ b ↔ (k : enat) ≤ multiplicity a b := ⟨le_multiplicity_of_pow_dvd, pow_dvd_of_le_multiplicity⟩ lemma multiplicity_lt_iff_neg_dvd {a b : α} {k : ℕ} : multiplicity a b < (k : enat) ↔ ¬ a ^ k ∣ b := by { rw [pow_dvd_iff_le_multiplicity, not_le] } lemma eq_some_iff {a b : α} {n : ℕ} : multiplicity a b = (n : enat) ↔ a ^ n ∣ b ∧ ¬a ^ (n + 1) ∣ b := ⟨λ h, let ⟨h₁, h₂⟩ := eq_some_iff.1 h in h₂ ▸ ⟨pow_multiplicity_dvd _, is_greatest (by conv_lhs {rw ← enat.coe_get h₁ }; rw [enat.coe_lt_coe]; exact lt_succ_self _)⟩, λ h, eq_some_iff.2 ⟨⟨n, h.2⟩, eq.symm $ unique' h.1 h.2⟩⟩ lemma eq_top_iff {a b : α} : multiplicity a b = ⊤ ↔ ∀ n : ℕ, a ^ n ∣ b := ⟨λ h n, nat.cases_on n (one_dvd _) (λ n, by_contradiction (not_exists.1 (eq_none_iff'.1 h) n : _)), λ h, eq_none_iff.2 (λ n ⟨⟨_, h₁⟩, _⟩, h₁ (h _))⟩ @[simp] protected lemma zero (a : α) : multiplicity a 0 = ⊤ := roption.eq_none_iff.2 (λ n ⟨⟨k, hk⟩, _⟩, hk (dvd_zero _)) lemma one_right {a : α} (ha : ¬is_unit a) : multiplicity a 1 = 0 := eq_some_iff.2 ⟨dvd_refl _, mt is_unit_iff_dvd_one.2 $ by simpa⟩ @[simp] lemma get_one_right {a : α} (ha : finite a 1) : get (multiplicity a 1) ha = 0 := get_eq_iff_eq_some.2 (eq_some_iff.2 ⟨dvd_refl _, by simpa [is_unit_iff_dvd_one.symm] using not_unit_of_finite ha⟩) @[simp] lemma multiplicity_unit {a : α} (b : α) (ha : is_unit a) : multiplicity a b = ⊤ := eq_top_iff.2 (λ _, is_unit_iff_forall_dvd.1 (is_unit_pow _ ha) _) @[simp] lemma one_left (b : α) : multiplicity 1 b = ⊤ := by simp [eq_top_iff] lemma multiplicity_eq_zero_of_not_dvd {a b : α} (ha : ¬a ∣ b) : multiplicity a b = 0 := eq_some_iff.2 (by simpa) lemma eq_top_iff_not_finite {a b : α} : multiplicity a b = ⊤ ↔ ¬ finite a b := roption.eq_none_iff' open_locale classical lemma multiplicity_le_multiplicity_iff {a b c d : α} : multiplicity a b ≤ multiplicity c d ↔ (∀ n : ℕ, a ^ n ∣ b → c ^ n ∣ d) := ⟨λ h n hab, (pow_dvd_of_le_multiplicity (le_trans (le_multiplicity_of_pow_dvd hab) h)), λ h, if hab : finite a b then by rw [← enat.coe_get (finite_iff_dom.1 hab)]; exact le_multiplicity_of_pow_dvd (h _ (pow_multiplicity_dvd _)) else have ∀ n : ℕ, c ^ n ∣ d, from λ n, h n (not_finite_iff_forall.1 hab _), by rw [eq_top_iff_not_finite.2 hab, eq_top_iff_not_finite.2 (not_finite_iff_forall.2 this)]⟩ lemma min_le_multiplicity_add {p a b : α} : min (multiplicity p a) (multiplicity p b) ≤ multiplicity p (a + b) := (le_total (multiplicity p a) (multiplicity p b)).elim (λ h, by rw [min_eq_left h, multiplicity_le_multiplicity_iff]; exact λ n hn, dvd_add hn (multiplicity_le_multiplicity_iff.1 h n hn)) (λ h, by rw [min_eq_right h, multiplicity_le_multiplicity_iff]; exact λ n hn, dvd_add (multiplicity_le_multiplicity_iff.1 h n hn) hn) lemma dvd_of_multiplicity_pos {a b : α} (h : (0 : enat) < multiplicity a b) : a ∣ b := by rw [← _root_.pow_one a]; exact pow_dvd_of_le_multiplicity (enat.pos_iff_one_le.1 h) lemma finite_nat_iff {a b : ℕ} : finite a b ↔ (a ≠ 1 ∧ 0 < b) := begin rw [← not_iff_not, not_finite_iff_forall, not_and_distrib, ne.def, not_not, not_lt, nat.le_zero_iff], exact ⟨λ h, or_iff_not_imp_right.2 (λ hb, have ha : a ≠ 0, from λ ha, by simpa [ha] using h 1, by_contradiction (λ ha1 : a ≠ 1, have ha_gt_one : 1 < a, from have ∀ a : ℕ, a ≤ 1 → a ≠ 0 → a ≠ 1 → false, from dec_trivial, lt_of_not_ge (λ ha', this a ha' ha ha1), not_lt_of_ge (le_of_dvd (nat.pos_of_ne_zero hb) (h b)) (by simp only [nat.pow_eq_pow]; exact lt_pow_self ha_gt_one b))), λ h, by cases h; simp *⟩ end lemma finite_int_iff_nat_abs_finite {a b : ℤ} : finite a b ↔ finite a.nat_abs b.nat_abs := begin rw [finite_def, finite_def], conv in (a ^ _ ∣ b) { rw [← int.nat_abs_dvd_abs_iff, int.nat_abs_pow, ← pow_eq_pow] } end lemma finite_int_iff {a b : ℤ} : finite a b ↔ (a.nat_abs ≠ 1 ∧ b ≠ 0) := begin have := int.nat_abs_eq a, have := @int.nat_abs_ne_zero_of_ne_zero b, rw [finite_int_iff_nat_abs_finite, finite_nat_iff, nat.pos_iff_ne_zero], split; finish end instance decidable_nat : decidable_rel (λ a b : ℕ, (multiplicity a b).dom) := λ a b, decidable_of_iff _ finite_nat_iff.symm instance decidable_int : decidable_rel (λ a b : ℤ, (multiplicity a b).dom) := λ a b, decidable_of_iff _ finite_int_iff.symm end comm_semiring section comm_ring variables [comm_ring α] [decidable_rel ((∣) : α → α → Prop)] open_locale classical @[simp] protected lemma neg (a b : α) : multiplicity a (-b) = multiplicity a b := roption.ext' (by simp only [multiplicity]; conv in (_ ∣ - _) {rw dvd_neg}) (λ h₁ h₂, enat.coe_inj.1 (by rw [enat.coe_get]; exact eq.symm (unique ((dvd_neg _ _).2 (pow_multiplicity_dvd _)) (mt (dvd_neg _ _).1 (is_greatest' _ (lt_succ_self _)))))) lemma multiplicity_add_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a + b) = multiplicity p b := begin apply le_antisymm, { apply enat.le_of_lt_add_one, cases enat.ne_top_iff.mp (enat.ne_top_of_lt h) with k hk, rw [hk], rw_mod_cast [multiplicity_lt_iff_neg_dvd], intro h_dvd, rw [← dvd_add_iff_right] at h_dvd, apply multiplicity.is_greatest _ h_dvd, rw [hk], apply_mod_cast nat.lt_succ_self, rw [pow_dvd_iff_le_multiplicity, enat.coe_add, ← hk], exact enat.add_one_le_of_lt h }, { convert min_le_multiplicity_add, rw [min_eq_right (le_of_lt h)] } end lemma multiplicity_sub_of_gt {p a b : α} (h : multiplicity p b < multiplicity p a) : multiplicity p (a - b) = multiplicity p b := by { rw [sub_eq_add_neg, multiplicity_add_of_gt]; rwa [multiplicity.neg] } lemma multiplicity_add_eq_min {p a b : α} (h : multiplicity p a ≠ multiplicity p b) : multiplicity p (a + b) = min (multiplicity p a) (multiplicity p b) := begin rcases lt_trichotomy (multiplicity p a) (multiplicity p b) with hab|hab|hab, { rw [add_comm, multiplicity_add_of_gt hab, min_eq_left], exact le_of_lt hab }, { contradiction }, { rw [multiplicity_add_of_gt hab, min_eq_right], exact le_of_lt hab}, end end comm_ring section integral_domain variables [integral_domain α] lemma finite_mul_aux {p : α} (hp : prime p) : ∀ {n m : ℕ} {a b : α}, ¬p ^ (n + 1) ∣ a → ¬p ^ (m + 1) ∣ b → ¬p ^ (n + m + 1) ∣ a * b | n m := λ a b ha hb ⟨s, hs⟩, have p ∣ a * b, from ⟨p ^ (n + m) * s, by simp [hs, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩, (hp.2.2 a b this).elim (λ ⟨x, hx⟩, have hn0 : 0 < n, from nat.pos_of_ne_zero (λ hn0, by clear _fun_match _fun_match; simpa [hx, hn0] using ha), have wf : (n - 1) < n, from nat.sub_lt_self hn0 dec_trivial, have hpx : ¬ p ^ (n - 1 + 1) ∣ x, from λ ⟨y, hy⟩, ha (hx.symm ▸ ⟨y, (domain.mul_left_inj hp.1).1 $ by rw [nat.sub_add_cancel hn0] at hy; simp [hy, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩), have 1 ≤ n + m, from le_trans hn0 (le_add_right n m), finite_mul_aux hpx hb ⟨s, (domain.mul_left_inj hp.1).1 begin rw [← nat.sub_add_comm hn0, nat.sub_add_cancel this], clear _fun_match _fun_match finite_mul_aux, simp [*, mul_comm, mul_assoc, mul_left_comm, _root_.pow_add] at * end⟩) (λ ⟨x, hx⟩, have hm0 : 0 < m, from nat.pos_of_ne_zero (λ hm0, by clear _fun_match _fun_match; simpa [hx, hm0] using hb), have wf : (m - 1) < m, from nat.sub_lt_self hm0 dec_trivial, have hpx : ¬ p ^ (m - 1 + 1) ∣ x, from λ ⟨y, hy⟩, hb (hx.symm ▸ ⟨y, (domain.mul_left_inj hp.1).1 $ by rw [nat.sub_add_cancel hm0] at hy; simp [hy, _root_.pow_add, mul_comm, mul_assoc, mul_left_comm]⟩), finite_mul_aux ha hpx ⟨s, (domain.mul_left_inj hp.1).1 begin rw [add_assoc, nat.sub_add_cancel hm0], clear _fun_match _fun_match finite_mul_aux, simp [*, mul_comm, mul_assoc, mul_left_comm, _root_.pow_add] at * end⟩) lemma finite_mul {p a b : α} (hp : prime p) : finite p a → finite p b → finite p (a * b) := λ ⟨n, hn⟩ ⟨m, hm⟩, ⟨n + m, finite_mul_aux hp hn hm⟩ lemma finite_mul_iff {p a b : α} (hp : prime p) : finite p (a * b) ↔ finite p a ∧ finite p b := ⟨λ h, ⟨finite_of_finite_mul_right h, finite_of_finite_mul_left h⟩, λ h, finite_mul hp h.1 h.2⟩ lemma finite_pow {p a : α} (hp : prime p) : Π {k : ℕ} (ha : finite p a), finite p (a ^ k) | 0 ha := ⟨0, by simp [mt is_unit_iff_dvd_one.2 hp.2.1]⟩ | (k+1) ha := by rw [_root_.pow_succ]; exact finite_mul hp ha (finite_pow ha) variable [decidable_rel ((∣) : α → α → Prop)] @[simp] lemma multiplicity_self {a : α} (ha : ¬is_unit a) (ha0 : a ≠ 0) : multiplicity a a = 1 := eq_some_iff.2 ⟨by simp, λ ⟨b, hb⟩, ha (is_unit_iff_dvd_one.2 ⟨b, (domain.mul_right_inj ha0).1 $ by clear _fun_match; simpa [_root_.pow_succ, mul_assoc] using hb⟩)⟩ @[simp] lemma get_multiplicity_self {a : α} (ha : finite a a) : get (multiplicity a a) ha = 1 := roption.get_eq_iff_eq_some.2 (eq_some_iff.2 ⟨by simp, λ ⟨b, hb⟩, by rw [← mul_one a, _root_.pow_add, _root_.pow_one, mul_assoc, mul_assoc, domain.mul_right_inj (ne_zero_of_finite ha)] at hb; exact mt is_unit_iff_dvd_one.2 (not_unit_of_finite ha) ⟨b, by clear _fun_match; simp * at *⟩⟩) protected lemma mul' {p a b : α} (hp : prime p) (h : (multiplicity p (a * b)).dom) : get (multiplicity p (a * b)) h = get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2 := have hdiva : p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 ∣ a, from pow_multiplicity_dvd _, have hdivb : p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2 ∣ b, from pow_multiplicity_dvd _, have hpoweq : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) = p ^ get (multiplicity p a) ((finite_mul_iff hp).1 h).1 * p ^ get (multiplicity p b) ((finite_mul_iff hp).1 h).2, by simp [_root_.pow_add], have hdiv : p ^ (get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) ∣ a * b, by rw [hpoweq]; apply mul_dvd_mul; assumption, have hsucc : ¬p ^ ((get (multiplicity p a) ((finite_mul_iff hp).1 h).1 + get (multiplicity p b) ((finite_mul_iff hp).1 h).2) + 1) ∣ a * b, from λ h, not_or (is_greatest' _ (lt_succ_self _)) (is_greatest' _ (lt_succ_self _)) (succ_dvd_or_succ_dvd_of_succ_sum_dvd_mul hp (by convert hdiva) (by convert hdivb) h), by rw [← enat.coe_inj, enat.coe_get, eq_some_iff]; exact ⟨hdiv, hsucc⟩ open_locale classical protected lemma mul {p a b : α} (hp : prime p) : multiplicity p (a * b) = multiplicity p a + multiplicity p b := if h : finite p a ∧ finite p b then by rw [← enat.coe_get (finite_iff_dom.1 h.1), ← enat.coe_get (finite_iff_dom.1 h.2), ← enat.coe_get (finite_iff_dom.1 (finite_mul hp h.1 h.2)), ← enat.coe_add, enat.coe_inj, multiplicity.mul' hp]; refl else begin rw [eq_top_iff_not_finite.2 (mt (finite_mul_iff hp).1 h)], cases not_and_distrib.1 h with h h; simp [eq_top_iff_not_finite.2 h] end lemma finset.prod {β : Type*} {p : α} (hp : prime p) (s : finset β) (f : β → α) : multiplicity p (s.prod f) = s.sum (λ x, multiplicity p (f x)) := begin classical, induction s using finset.induction with a s has ih h, { simp only [finset.sum_empty, finset.prod_empty], convert one_right hp.not_unit }, { simp [has, ← ih], convert multiplicity.mul hp } end protected lemma pow' {p a : α} (hp : prime p) (ha : finite p a) : ∀ {k : ℕ}, get (multiplicity p (a ^ k)) (finite_pow hp ha) = k * get (multiplicity p a) ha | 0 := by dsimp [_root_.pow_zero]; simp [one_right hp.not_unit]; refl | (k+1) := by dsimp only [_root_.pow_succ]; erw [multiplicity.mul' hp, pow', add_mul, one_mul, add_comm] lemma pow {p a : α} (hp : prime p) : ∀ {k : ℕ}, multiplicity p (a ^ k) = k •ℕ (multiplicity p a) | 0 := by simp [one_right hp.not_unit] | (succ k) := by simp [_root_.pow_succ, succ_nsmul, pow, multiplicity.mul hp] lemma multiplicity_pow_self {p : α} (h0 : p ≠ 0) (hu : ¬ is_unit p) (n : ℕ) : multiplicity p (p ^ n) = n := by { rw [eq_some_iff], use dvd_refl _, rw [pow_dvd_pow_iff h0 hu], apply nat.not_succ_le_self } lemma multiplicity_pow_self_of_prime {p : α} (hp : prime p) (n : ℕ) : multiplicity p (p ^ n) = n := multiplicity_pow_self hp.ne_zero hp.not_unit n end integral_domain end multiplicity section nat open multiplicity lemma multiplicity_eq_zero_of_coprime {p a b : ℕ} (hp : p ≠ 1) (hle : multiplicity p a ≤ multiplicity p b) (hab : nat.coprime a b) : multiplicity p a = 0 := begin rw [multiplicity_le_multiplicity_iff] at hle, rw [← le_zero_iff_eq, ← not_lt, enat.pos_iff_one_le, ← enat.coe_one, ← pow_dvd_iff_le_multiplicity], assume h, have := nat.dvd_gcd h (hle _ h), rw [coprime.gcd_eq_one hab, nat.dvd_one, _root_.pow_one] at this, exact hp this end end nat
7ce8e13ae40ca469987626feb53c69b803f3e0c6
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/data/finset/sigma.lean
e000ed62e556eca76454b4143dbaab3d9facedc5
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
6,407
lean
/- Copyright (c) 2017 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Mario Carneiro, Yaël Dillies, Bhavik Mehta -/ import data.finset.lattice import data.set.sigma /-! # Finite sets in a sigma type > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines a few `finset` constructions on `Σ i, α i`. ## Main declarations * `finset.sigma`: Given a finset `s` in `ι` and finsets `t i` in each `α i`, `s.sigma t` is the finset of the dependent sum `Σ i, α i` * `finset.sigma_lift`: Lifts maps `α i → β i → finset (γ i)` to a map `Σ i, α i → Σ i, β i → finset (Σ i, γ i)`. ## TODO `finset.sigma_lift` can be generalized to any alternative functor. But to make the generalization worth it, we must first refactor the functor library so that the `alternative` instance for `finset` is computable and universe-polymorphic. -/ open function multiset variables {ι : Type*} namespace finset section sigma variables {α : ι → Type*} {β : Type*} (s s₁ s₂ : finset ι) (t t₁ t₂ : Π i, finset (α i)) /-- `s.sigma t` is the finset of dependent pairs `⟨i, a⟩` such that `i ∈ s` and `a ∈ t i`. -/ protected def sigma : finset (Σ i, α i) := ⟨_, s.nodup.sigma $ λ i, (t i).nodup⟩ variables {s s₁ s₂ t t₁ t₂} @[simp] lemma mem_sigma {a : Σ i, α i} : a ∈ s.sigma t ↔ a.1 ∈ s ∧ a.2 ∈ t a.1 := mem_sigma @[simp, norm_cast] lemma coe_sigma (s : finset ι) (t : Π i, finset (α i)) : (s.sigma t : set (Σ i, α i)) = (s : set ι).sigma (λ i, t i) := set.ext $ λ _, mem_sigma @[simp] lemma sigma_nonempty : (s.sigma t).nonempty ↔ ∃ i ∈ s, (t i).nonempty := by simp [finset.nonempty] @[simp] lemma sigma_eq_empty : s.sigma t = ∅ ↔ ∀ i ∈ s, t i = ∅ := by simp only [← not_nonempty_iff_eq_empty, sigma_nonempty, not_exists] @[mono] lemma sigma_mono (hs : s₁ ⊆ s₂) (ht : ∀ i, t₁ i ⊆ t₂ i) : s₁.sigma t₁ ⊆ s₂.sigma t₂ := λ ⟨i, a⟩ h, let ⟨hi, ha⟩ := mem_sigma.1 h in mem_sigma.2 ⟨hs hi, ht i ha⟩ lemma pairwise_disjoint_map_sigma_mk : (s : set ι).pairwise_disjoint (λ i, (t i).map (embedding.sigma_mk i)) := begin intros i hi j hj hij, rw [function.on_fun, disjoint_left], simp_rw [mem_map, function.embedding.sigma_mk_apply], rintros _ ⟨y, hy, rfl⟩ ⟨z, hz, hz'⟩, exact hij (congr_arg sigma.fst hz'.symm) end @[simp] lemma disj_Union_map_sigma_mk : s.disj_Union (λ i, (t i).map (embedding.sigma_mk i)) pairwise_disjoint_map_sigma_mk = s.sigma t := rfl lemma sigma_eq_bUnion [decidable_eq (Σ i, α i)] (s : finset ι) (t : Π i, finset (α i)) : s.sigma t = s.bUnion (λ i, (t i).map $ embedding.sigma_mk i) := by { ext ⟨x, y⟩, simp [and.left_comm] } variables (s t) (f : (Σ i, α i) → β) lemma sup_sigma [semilattice_sup β] [order_bot β] : (s.sigma t).sup f = s.sup (λ i, (t i).sup $ λ b, f ⟨i, b⟩) := begin simp only [le_antisymm_iff, finset.sup_le_iff, mem_sigma, and_imp, sigma.forall], exact ⟨λ i a hi ha, (le_sup hi).trans' $ le_sup ha, λ i hi a ha, le_sup $ mem_sigma.2 ⟨hi, ha⟩⟩, end lemma inf_sigma [semilattice_inf β] [order_top β] : (s.sigma t).inf f = s.inf (λ i, (t i).inf $ λ b, f ⟨i, b⟩) := @sup_sigma _ _ βᵒᵈ _ _ _ _ _ end sigma section sigma_lift variables {α β γ : ι → Type*} [decidable_eq ι] /-- Lifts maps `α i → β i → finset (γ i)` to a map `Σ i, α i → Σ i, β i → finset (Σ i, γ i)`. -/ def sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i)) (a : sigma α) (b : sigma β) : finset (sigma γ) := dite (a.1 = b.1) (λ h, (f (h.rec a.2) b.2).map $ embedding.sigma_mk _) (λ _, ∅) lemma mem_sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i)) (a : sigma α) (b : sigma β) (x : sigma γ) : x ∈ sigma_lift f a b ↔ ∃ (ha : a.1 = x.1) (hb : b.1 = x.1), x.2 ∈ f (ha.rec a.2) (hb.rec b.2) := begin obtain ⟨⟨i, a⟩, j, b⟩ := ⟨a, b⟩, obtain rfl | h := decidable.eq_or_ne i j, { split, { simp_rw [sigma_lift, dif_pos rfl, mem_map, embedding.sigma_mk_apply], rintro ⟨x, hx, rfl⟩, exact ⟨rfl, rfl, hx⟩ }, { rintro ⟨⟨⟩, ⟨⟩, hx⟩, rw [sigma_lift, dif_pos rfl, mem_map], exact ⟨_, hx, by simp [sigma.ext_iff]⟩ } }, { rw [sigma_lift, dif_neg h], refine iff_of_false (not_mem_empty _) _, rintro ⟨⟨⟩, ⟨⟩, _⟩, exact h rfl } end lemma mk_mem_sigma_lift (f : Π ⦃i⦄, α i → β i → finset (γ i)) (i : ι) (a : α i) (b : β i) (x : γ i) : (⟨i, x⟩ : sigma γ) ∈ sigma_lift f ⟨i, a⟩ ⟨i, b⟩ ↔ x ∈ f a b := begin rw [sigma_lift, dif_pos rfl, mem_map], refine ⟨_, λ hx, ⟨_, hx, rfl⟩⟩, rintro ⟨x, hx, _, rfl⟩, exact hx, end lemma not_mem_sigma_lift_of_ne_left (f : Π ⦃i⦄, α i → β i → finset (γ i)) (a : sigma α) (b : sigma β) (x : sigma γ) (h : a.1 ≠ x.1) : x ∉ sigma_lift f a b := by { rw mem_sigma_lift, exact λ H, h H.fst } lemma not_mem_sigma_lift_of_ne_right (f : Π ⦃i⦄, α i → β i → finset (γ i)) {a : sigma α} (b : sigma β) {x : sigma γ} (h : b.1 ≠ x.1) : x ∉ sigma_lift f a b := by { rw mem_sigma_lift, exact λ H, h H.snd.fst } variables {f g : Π ⦃i⦄, α i → β i → finset (γ i)} {a : Σ i, α i} {b : Σ i, β i} lemma sigma_lift_nonempty : (sigma_lift f a b).nonempty ↔ ∃ h : a.1 = b.1, (f (h.rec a.2) b.2).nonempty := begin simp_rw nonempty_iff_ne_empty, convert dite_ne_right_iff, ext h, simp_rw ←nonempty_iff_ne_empty, exact map_nonempty.symm, end lemma sigma_lift_eq_empty : (sigma_lift f a b) = ∅ ↔ ∀ h : a.1 = b.1, (f (h.rec a.2) b.2) = ∅ := begin convert dite_eq_right_iff, exact forall_congr_eq (λ h, propext map_eq_empty.symm), end lemma sigma_lift_mono (h : ∀ ⦃i⦄ ⦃a : α i⦄ ⦃b : β i⦄, f a b ⊆ g a b) (a : Σ i, α i) (b : Σ i, β i) : sigma_lift f a b ⊆ sigma_lift g a b := begin rintro x hx, rw mem_sigma_lift at ⊢ hx, obtain ⟨ha, hb, hx⟩ := hx, exact ⟨ha, hb, h hx⟩, end variables (f a b) lemma card_sigma_lift : (sigma_lift f a b).card = dite (a.1 = b.1) (λ h, (f (h.rec a.2) b.2).card) (λ _, 0) := by { convert apply_dite _ _ _ _, ext h, exact (card_map _).symm } end sigma_lift end finset
cef627d9b3650a20e8353288fdfa4c98c8e5501f
cf39355caa609c0f33405126beee2739aa3cb77e
/tests/lean/run/export.lean
b86c085248c51f9dba73b3a5ec942cf2597dca0e
[ "Apache-2.0" ]
permissive
leanprover-community/lean
12b87f69d92e614daea8bcc9d4de9a9ace089d0e
cce7990ea86a78bdb383e38ed7f9b5ba93c60ce0
refs/heads/master
1,687,508,156,644
1,684,951,104,000
1,684,951,104,000
169,960,991
457
107
Apache-2.0
1,686,744,372,000
1,549,790,268,000
C++
UTF-8
Lean
false
false
136
lean
constants a b : nat namespace boo export nat (rec add) #check a + b #check nat.add end boo open boo #check a + b #check nat.rec
9ae1154507d5b4116a7e1a0185c7f49bad5c9b7a
d406927ab5617694ec9ea7001f101b7c9e3d9702
/src/model_theory/fraisse.lean
d819e48cea930869838b1f31e970c4b8a33b5dce
[ "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,506
lean
/- Copyright (c) 2022 Aaron Anderson. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Aaron Anderson -/ import model_theory.finitely_generated import model_theory.direct_limit import model_theory.bundled /-! # Fraïssé Classes and Fraïssé Limits This file pertains to the ages of countable first-order structures. The age of a structure is the class of all finitely-generated structures that embed into it. Of particular interest are Fraïssé classes, which are exactly the ages of countable ultrahomogeneous structures. To each is associated a unique (up to nonunique isomorphism) Fraïssé limit - the countable ultrahomogeneous structure with that age. ## Main Definitions * `first_order.language.age` is the class of finitely-generated structures that embed into a particular structure. * A class `K` has the `first_order.language.hereditary` when all finitely-generated structures that embed into structures in `K` are also in `K`. * A class `K` has the `first_order.language.joint_embedding` when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. * A class `K` has the `first_order.language.amalgamation` when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. * `first_order.language.is_fraisse` indicates that a class is nonempty, isomorphism-invariant, essentially countable, and satisfies the hereditary, joint embedding, and amalgamation properties. * `first_order.language.is_fraisse_limit` indicates that a structure is a Fraïssé limit for a given class. ## Main Results * We show that the age of any structure is isomorphism-invariant and satisfies the hereditary and joint-embedding properties. * `first_order.language.age.countable_quotient` shows that the age of any countable structure is essentially countable. * `first_order.language.exists_countable_is_age_of_iff` gives necessary and sufficient conditions for a class to be the age of a countable structure in a language with countably many functions. ## Implementation Notes * Classes of structures are formalized with `set (bundled L.Structure)`. * Some results pertain to countable limit structures, others to countably-generated limit structures. In the case of a language with countably many function symbols, these are equivalent. ## References - [W. Hodges, *A Shorter Model Theory*][Hodges97] - [K. Tent, M. Ziegler, *A Course in Model Theory*][Tent_Ziegler] ## TODO * Show existence and uniqueness of Fraïssé limits -/ universes u v w w' open_locale first_order open set category_theory namespace first_order namespace language open Structure substructure variables (L : language.{u v}) /-! ### The Age of a Structure and Fraïssé Classes-/ /-- The age of a structure `M` is the class of finitely-generated structures that embed into it. -/ def age (M : Type w) [L.Structure M] : set (bundled.{w} L.Structure) := { N | Structure.fg L N ∧ nonempty (N ↪[L] M) } variables {L} (K : set (bundled.{w} L.Structure)) /-- A class `K` has the hereditary property when all finitely-generated structures that embed into structures in `K` are also in `K`. -/ def hereditary : Prop := ∀ (M : bundled.{w} L.Structure), M ∈ K → L.age M ⊆ K /-- A class `K` has the joint embedding property when for every `M`, `N` in `K`, there is another structure in `K` into which both `M` and `N` embed. -/ def joint_embedding : Prop := directed_on (λ M N : bundled.{w} L.Structure, nonempty (M ↪[L] N)) K /-- A class `K` has the amalgamation property when for any pair of embeddings of a structure `M` in `K` into other structures in `K`, those two structures can be embedded into a fourth structure in `K` such that the resulting square of embeddings commutes. -/ def amalgamation : Prop := ∀ (M N P : bundled.{w} L.Structure) (MN : M ↪[L] N) (MP : M ↪[L] P), M ∈ K → N ∈ K → P ∈ K → ∃ (Q : bundled.{w} L.Structure) (NQ : N ↪[L] Q) (PQ : P ↪[L] Q), Q ∈ K ∧ NQ.comp MN = PQ.comp MP /-- A Fraïssé class is a nonempty, isomorphism-invariant, essentially countable class of structures satisfying the hereditary, joint embedding, and amalgamation properties. -/ class is_fraisse : Prop := (is_nonempty : K.nonempty) (fg : ∀ M : bundled.{w} L.Structure, M ∈ K → Structure.fg L M) (is_equiv_invariant : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) (is_essentially_countable : (quotient.mk '' K).countable) (hereditary : hereditary K) (joint_embedding : joint_embedding K) (amalgamation : amalgamation K) variables {K} (L) (M : Type w) [L.Structure M] lemma age.is_equiv_invariant (N P : bundled.{w} L.Structure) (h : nonempty (N ≃[L] P)) : N ∈ L.age M ↔ P ∈ L.age M := and_congr h.some.fg_iff ⟨nonempty.map (λ x, embedding.comp x h.some.symm.to_embedding), nonempty.map (λ x, embedding.comp x h.some.to_embedding)⟩ variables {L} {M} {N : Type w} [L.Structure N] lemma embedding.age_subset_age (MN : M ↪[L] N) : L.age M ⊆ L.age N := λ _, and.imp_right (nonempty.map MN.comp) lemma equiv.age_eq_age (MN : M ≃[L] N) : L.age M = L.age N := le_antisymm MN.to_embedding.age_subset_age MN.symm.to_embedding.age_subset_age lemma Structure.fg.mem_age_of_equiv {M N : bundled L.Structure} (h : Structure.fg L M) (MN : nonempty (M ≃[L] N)) : N ∈ L.age M := ⟨MN.some.fg_iff.1 h, ⟨MN.some.symm.to_embedding⟩⟩ lemma hereditary.is_equiv_invariant_of_fg (h : hereditary K) (fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) (M N : bundled.{w} L.Structure) (hn : nonempty (M ≃[L] N)) : M ∈ K ↔ N ∈ K := ⟨λ MK, h M MK ((fg M MK).mem_age_of_equiv hn), λ NK, h N NK ((fg N NK).mem_age_of_equiv ⟨hn.some.symm⟩)⟩ variable (M) lemma age.nonempty : (L.age M).nonempty := ⟨bundled.of (substructure.closure L (∅ : set M)), (fg_iff_Structure_fg _).1 (fg_closure set.finite_empty), ⟨substructure.subtype _⟩⟩ lemma age.hereditary : hereditary (L.age M) := λ N hN P hP, hN.2.some.age_subset_age hP lemma age.joint_embedding : joint_embedding (L.age M) := λ N hN P hP, ⟨bundled.of ↥(hN.2.some.to_hom.range ⊔ hP.2.some.to_hom.range), ⟨(fg_iff_Structure_fg _).1 ((hN.1.range hN.2.some.to_hom).sup (hP.1.range hP.2.some.to_hom)), ⟨subtype _⟩⟩, ⟨embedding.comp (inclusion le_sup_left) hN.2.some.equiv_range.to_embedding⟩, ⟨embedding.comp (inclusion le_sup_right) hP.2.some.equiv_range.to_embedding⟩⟩ /-- The age of a countable structure is essentially countable (has countably many isomorphism classes). -/ lemma age.countable_quotient [h : countable M] : (quotient.mk '' L.age M).countable := begin classical, refine (congr_arg _ (set.ext $ forall_quotient_iff.2 $ λ N, _)).mp (countable_range $ λ s : finset M, ⟦⟨closure L (s : set M), infer_instance⟩⟧), simp only [mem_image, mem_range, mem_set_of_eq, quotient.eq], split, { rintro ⟨s, hs⟩, use bundled.of ↥(closure L (s : set M)), exact ⟨⟨(fg_iff_Structure_fg _).1 (fg_closure s.finite_to_set), ⟨subtype _⟩⟩, hs⟩ }, { rintro ⟨P, ⟨⟨s, hs⟩, ⟨PM⟩⟩, hP2⟩, refine ⟨s.image PM, setoid.trans _ hP2⟩, rw [← embedding.coe_to_hom, finset.coe_image, closure_image PM.to_hom, hs, ← hom.range_eq_map], exact ⟨PM.equiv_range.symm⟩ } end /-- The age of a direct limit of structures is the union of the ages of the structures. -/ @[simp] theorem age_direct_limit {ι : Type w} [preorder ι] [is_directed ι (≤)] [nonempty ι] (G : ι → Type (max w w')) [Π i, L.Structure (G i)] (f : Π i j, i ≤ j → G i ↪[L] G j) [directed_system G (λ i j h, f i j h)] : L.age (direct_limit G f) = ⋃ (i : ι), L.age (G i) := begin classical, ext M, simp only [mem_Union], split, { rintro ⟨Mfg, ⟨e⟩⟩, obtain ⟨s, hs⟩ := Mfg.range e.to_hom, let out := @quotient.out _ (direct_limit.setoid G f), obtain ⟨i, hi⟩ := finset.exists_le (s.image (sigma.fst ∘ out)), have e' := ((direct_limit.of L ι G f i).equiv_range.symm.to_embedding), refine ⟨i, Mfg, ⟨e'.comp ((substructure.inclusion _).comp e.equiv_range.to_embedding)⟩⟩, rw [← hs, closure_le], intros x hx, refine ⟨f (out x).1 i (hi (out x).1 (finset.mem_image_of_mem _ hx)) (out x).2, _⟩, rw [embedding.coe_to_hom, direct_limit.of_apply, quotient.mk_eq_iff_out, direct_limit.equiv_iff G f _ (hi (out x).1 (finset.mem_image_of_mem _ hx)), directed_system.map_self], refl }, { rintro ⟨i, Mfg, ⟨e⟩⟩, exact ⟨Mfg, ⟨embedding.comp (direct_limit.of L ι G f i) e⟩⟩ } end /-- Sufficient conditions for a class to be the age of a countably-generated structure. -/ theorem exists_cg_is_age_of (hn : K.nonempty) (h : ∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) (hc : (quotient.mk '' K).countable) (fg : ∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) (hp : hereditary K) (jep : joint_embedding K) : ∃ (M : bundled.{w} L.Structure), Structure.cg L M ∧ L.age M = K := begin obtain ⟨F, hF⟩ := hc.exists_eq_range (hn.image _), simp only [set.ext_iff, forall_quotient_iff, mem_image, mem_range, quotient.eq] at hF, simp_rw [quotient.eq_mk_iff_out] at hF, have hF' : ∀ n : ℕ, (F n).out ∈ K, { intro n, obtain ⟨P, hP1, hP2⟩ := (hF (F n).out).2 ⟨n, setoid.refl _⟩, exact (h _ _ hP2).1 hP1 }, choose P hPK hP hFP using (λ (N : K) (n : ℕ), jep N N.2 (F (n + 1)).out (hF' _)), let G : ℕ → K := @nat.rec (λ _, K) (⟨(F 0).out, hF' 0⟩) (λ n N, ⟨P N n, hPK N n⟩), let f : Π (i j), i ≤ j → G i ↪[L] G j := directed_system.nat_le_rec (λ n, (hP _ n).some), refine ⟨bundled.of (direct_limit (λ n, G n) f), direct_limit.cg _ (λ n, (fg _ (G n).2).cg), (age_direct_limit _ _).trans (subset_antisymm (Union_subset (λ n N hN, hp (G n) (G n).2 hN)) (λ N KN, _))⟩, obtain ⟨n, ⟨e⟩⟩ := (hF N).1 ⟨N, KN, setoid.refl _⟩, refine mem_Union_of_mem n ⟨fg _ KN, ⟨embedding.comp _ e.symm.to_embedding⟩⟩, cases n, { exact embedding.refl _ _ }, { exact (hFP _ n).some } end theorem exists_countable_is_age_of_iff [countable (Σl, L.functions l)] : (∃ (M : bundled.{w} L.Structure), countable M ∧ L.age M = K) ↔ K.nonempty ∧ (∀ (M N : bundled.{w} L.Structure), nonempty (M ≃[L] N) → (M ∈ K ↔ N ∈ K)) ∧ (quotient.mk '' K).countable ∧ (∀ (M : bundled.{w} L.Structure), M ∈ K → Structure.fg L M) ∧ hereditary K ∧ joint_embedding K := begin split, { rintros ⟨M, h1, h2, rfl⟩, resetI, refine ⟨age.nonempty M, age.is_equiv_invariant L M, age.countable_quotient M, λ N hN, hN.1, age.hereditary M, age.joint_embedding M⟩, }, { rintros ⟨Kn, eqinv, cq, hfg, hp, jep⟩, obtain ⟨M, hM, rfl⟩ := exists_cg_is_age_of Kn eqinv cq hfg hp jep, exact ⟨M, Structure.cg_iff_countable.1 hM, rfl⟩ } end variables {K} (L) (M) /-- A structure `M` is ultrahomogeneous if every embedding of a finitely generated substructure into `M` extends to an automorphism of `M`. -/ def is_ultrahomogeneous : Prop := ∀ (S : L.substructure M) (hs : S.fg) (f : S ↪[L] M), ∃ (g : M ≃[L] M), f = g.to_embedding.comp S.subtype variables {L} (K) /-- A structure `M` is a Fraïssé limit for a class `K` if it is countably generated, ultrahomogeneous, and has age `K`. -/ @[protect_proj] structure is_fraisse_limit [countable (Σl, L.functions l)] [countable M] : Prop := (ultrahomogeneous : is_ultrahomogeneous L M) (age : L.age M = K) variables {L} {M} lemma is_ultrahomogeneous.amalgamation_age (h : L.is_ultrahomogeneous M) : amalgamation (L.age M) := begin rintros N P Q NP NQ ⟨Nfg, ⟨NM⟩⟩ ⟨Pfg, ⟨PM⟩⟩ ⟨Qfg, ⟨QM⟩⟩, obtain ⟨g, hg⟩ := h ((PM.comp NP).to_hom.range) (Nfg.range _) ((QM.comp NQ).comp (PM.comp NP).equiv_range.symm.to_embedding), let s := (g.to_hom.comp PM.to_hom).range ⊔ QM.to_hom.range, refine ⟨bundled.of s, embedding.comp (substructure.inclusion le_sup_left) ((g.to_embedding.comp PM).equiv_range).to_embedding, embedding.comp (substructure.inclusion le_sup_right) QM.equiv_range.to_embedding, ⟨(fg_iff_Structure_fg _).1 (fg.sup (Pfg.range _) (Qfg.range _)), ⟨substructure.subtype _⟩⟩, _⟩, ext n, have hgn := (embedding.ext_iff.1 hg) ((PM.comp NP).equiv_range n), simp only [embedding.comp_apply, equiv.coe_to_embedding, equiv.symm_apply_apply, substructure.coe_subtype, embedding.equiv_range_apply] at hgn, simp only [embedding.comp_apply, equiv.coe_to_embedding, substructure.coe_inclusion, set.coe_inclusion, embedding.equiv_range_apply, hgn], end lemma is_ultrahomogeneous.age_is_fraisse [countable M] (h : L.is_ultrahomogeneous M) : is_fraisse (L.age M) := ⟨age.nonempty M, λ _ hN, hN.1, age.is_equiv_invariant L M, age.countable_quotient M, age.hereditary M, age.joint_embedding M, h.amalgamation_age⟩ namespace is_fraisse_limit /-- If a class has a Fraïssé limit, it must be Fraïssé. -/ theorem is_fraisse [countable (Σl, L.functions l)] [countable M] (h : is_fraisse_limit K M) : is_fraisse K := (congr rfl h.age).mp h.ultrahomogeneous.age_is_fraisse end is_fraisse_limit end language end first_order
6fa0d3ca477d102fe98c27e55242d395b8f67228
034f05d7801df9252e04c34de9fe17863d8426fb
/.config.lean
6834e07a02a8e97f34aab215e10ccbc651ddfe9e
[ "MIT" ]
permissive
amxo/MT1300
2d03d0dccf7d391b3a5c29770a255b4db4d7b7a8
c7452de5fa57b0f01396c191c76a2b4bab54150c
refs/heads/main
1,677,948,578,026
1,613,195,046,000
1,613,195,046,000
338,482,907
0
0
MIT
1,613,184,292,000
1,613,184,292,000
null
UTF-8
Lean
false
false
248,662
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 is not set # 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=y # 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_ramips_mt7620 is not set CONFIG_TARGET_ramips_mt7621=y # CONFIG_TARGET_ramips_mt76x8 is not set # CONFIG_TARGET_ramips_rt288x is not set # CONFIG_TARGET_ramips_rt305x is not set # CONFIG_TARGET_ramips_rt3883 is not set # CONFIG_TARGET_MULTI_PROFILE is not set # CONFIG_TARGET_ramips_mt7621_Default is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_adslr_g7 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_afoundry_ew1200 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_alfa-network_quad-e4g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac57u is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac65p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asus_rt-ac85p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-001 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_asiarf_ap7621-nv1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-1166dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-2533dhpl is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_buffalo_wsr-600dhp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xzwifi_creativebox-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-860l-b1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-867-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-878-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_dlink_dir-882-a1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1167ghbk2-s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-1900gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_elecom_wrc-2533gst2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_rg21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_edimax_ra21s is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_firefly_firewrt is not set CONFIG_TARGET_ramips_mt7621_DEVICE_glinet_gl-mt1300=y # CONFIG_TARGET_ramips_mt7621_DEVICE_gehua_ghl-r-001 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_gnubee_gb-pc2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_hiwifi_hc5962 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax1167gr2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-ax2033gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-dx1167r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wn-gx300gr is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iodata_wnpr2600g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_jhr-ac876m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jcg_y2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_jdcloud_re-sp-01b is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_ea7500-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_linksys_re6500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mqmaker_witi is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mtc_wr1201 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_mt7621-eval-board is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mediatek_ap-mt7621a-v60 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-750gr3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m11g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_mikrotik_routerboard-m33g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_motorola_mr2600 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_ex6150 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6700-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6220 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6260 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6350 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6800 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_r6850 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac104 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wac124 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netgear_wndr3700-v5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_netis_wf2881 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_lenovo_newifi-d1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_newifi-d2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_d-team_pbr-m1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_phicomm_k2p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_planex_vr500 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_storylink_sap-g3200u3 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_samknows_whitebox-v8 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_totolink_a7000r is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re350-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_tplink_re650-v1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_telco-electronics_x1 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_thunder_timecloud is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_edgerouter-x-sfp is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_ubnt_unifi-nanohd is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_unielec_u7621-06-64m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_11acnas is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_wevo_w2914ns-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaoyu_xy-c5 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3p is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir3g-v2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mir4 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_mi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_xiaomi_redmi-router-ac2100 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youhua_wr1200js is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_youku_yk-l2 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zio_freezio is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we1326 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-we3526 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg2626 is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-16m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_zbtlink_zbt-wg3526-32m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a6ns-m is not set # CONFIG_TARGET_ramips_mt7621_DEVICE_iptime_a8004t is not set CONFIG_HAS_SUBTARGETS=y CONFIG_HAS_DEVICES=y CONFIG_TARGET_BOARD="ramips" CONFIG_TARGET_SUBTARGET="mt7621" CONFIG_TARGET_PROFILE="DEVICE_glinet_gl-mt1300" CONFIG_TARGET_ARCH_PACKAGES="mipsel_24kc" CONFIG_DEFAULT_TARGET_OPTIMIZATION="-Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc" CONFIG_CPU_TYPE="24kc" CONFIG_LINUX_5_4=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_kmod-gpio-button-hotplug=y CONFIG_DEFAULT_kmod-ipt-raw=y CONFIG_DEFAULT_kmod-leds-gpio=y CONFIG_DEFAULT_kmod-mt7615-firmware=y CONFIG_DEFAULT_kmod-mt7615e=y CONFIG_DEFAULT_kmod-nf-nathelper=y CONFIG_DEFAULT_kmod-nf-nathelper-extra=y CONFIG_DEFAULT_kmod-usb3=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-flowoffload=y CONFIG_DEFAULT_luci-app-nlbwmon=y CONFIG_DEFAULT_luci-app-ramfree=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_uci=y CONFIG_DEFAULT_uclient-fetch=y CONFIG_DEFAULT_urandom-seed=y CONFIG_DEFAULT_urngd=y CONFIG_DEFAULT_wget=y CONFIG_AUDIO_SUPPORT=y CONFIG_GPIO_SUPPORT=y CONFIG_PCI_SUPPORT=y CONFIG_USB_SUPPORT=y CONFIG_RTC_SUPPORT=y CONFIG_USES_DEVICETREE=y CONFIG_USES_INITRAMFS=y CONFIG_USES_SQUASHFS=y CONFIG_USES_MINOR=y CONFIG_HAS_MIPS16=y CONFIG_NAND_SUPPORT=y CONFIG_mipsel=y CONFIG_ARCH="mipsel" # # Target Images # CONFIG_TARGET_ROOTFS_INITRAMFS=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_NONE is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_GZIP is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_BZIP2 is not set CONFIG_TARGET_INITRAMFS_COMPRESSION_LZMA=y # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZO is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_LZ4 is not set # CONFIG_TARGET_INITRAMFS_COMPRESSION_XZ is not set CONFIG_EXTERNAL_CPIO="" # CONFIG_TARGET_INITRAMFS_FORCE is not set # # 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.1.1" CONFIG_TARGET_PREINIT_NETMASK="255.255.255.0" CONFIG_TARGET_PREINIT_BROADCAST="192.168.1.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 # # 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=y 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_UBIFS_EXTROOT=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=y 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=y CONFIG_PACKAGE_logd=y CONFIG_PACKAGE_mtd=y CONFIG_PACKAGE_netifd=y # CONFIG_PACKAGE_nft-qos 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_gotop=y 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_mt76-test 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 is not set # 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 is not set # CONFIG_PACKAGE_ath10k-firmware-qca9887-ct is not set # 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_jboot-tools 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_wil6210-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-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 is not set # 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-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-bme680 is not set # CONFIG_PACKAGE_kmod-iio-bme680-i2c is not set # CONFIG_PACKAGE_kmod-iio-bme680-spi 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-dht11 is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-i2c is not set # CONFIG_PACKAGE_kmod-iio-fxas21002c-spi 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-sps30 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=y # CONFIG_PACKAGE_kmod-leds-pca963x 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-asn1-decoder=y # 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=y # 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=y # 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=y 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 # CONFIG_PACKAGE_kmod-nft-queue 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-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-igc 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-sfc is not set # CONFIG_PACKAGE_kmod-sfc-falcon 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=y # 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 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=y # 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=y # CONFIG_PACKAGE_kmod-trelay is not set CONFIG_PACKAGE_kmod-tun=y # 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-dma-ralink 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-hsdma-mtk 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-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-sdhci-mt7620 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 # 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-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-hid is not set # CONFIG_PACKAGE_kmod-usb-ledtrig-usbport is not set # CONFIG_PACKAGE_kmod-usb-net is not set # CONFIG_PACKAGE_kmod-usb-net-aqc111 is not set # 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 is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-mbim is not set # CONFIG_PACKAGE_kmod-usb-net-cdc-ncm is not set # 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 is not set # 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 is not set # 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-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=y # 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 # # CONFIG_PACKAGE_kmod-dahdi is not set # 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-acx-mac80211 is not set # CONFIG_PACKAGE_kmod-adm8211 is not set # CONFIG_PACKAGE_kmod-ar5523 is not set # CONFIG_PACKAGE_kmod-ath is not set # CONFIG_PACKAGE_kmod-ath10k is not set # CONFIG_PACKAGE_kmod-ath10k-ct is not set # 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 is not set # 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-ipw2100 is not set # CONFIG_PACKAGE_kmod-ipw2200 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-libipw 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-mt76-core=y # CONFIG_PACKAGE_kmod-mt7601u is not set # CONFIG_PACKAGE_kmod-mt7603 is not set # CONFIG_PACKAGE_kmod-mt7603e is not set CONFIG_PACKAGE_kmod-mt7615-common=y CONFIG_PACKAGE_kmod-mt7615-firmware=y # CONFIG_PACKAGE_kmod-mt7615d is not set # CONFIG_PACKAGE_kmod-mt7615d_dbdc is not set CONFIG_PACKAGE_kmod-mt7615e=y # 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-mt76x2e 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-wil6210 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=y # # Standard Library # # CONFIG_PACKAGE_ruby-stdlib is not set # CONFIG_PACKAGE_ruby-benchmark is not set CONFIG_PACKAGE_ruby-bigdecimal=y # CONFIG_PACKAGE_ruby-bundler is not set # CONFIG_PACKAGE_ruby-cgi is not set # CONFIG_PACKAGE_ruby-csv is not set CONFIG_PACKAGE_ruby-date=y CONFIG_PACKAGE_ruby-dbm=y # CONFIG_PACKAGE_ruby-debuglib is not set # CONFIG_PACKAGE_ruby-delegate is not set # CONFIG_PACKAGE_ruby-dev is not set # CONFIG_PACKAGE_ruby-did-you-mean is not set CONFIG_PACKAGE_ruby-digest=y # CONFIG_RUBY_DIGEST_USE_OPENSSL is not set # CONFIG_PACKAGE_ruby-drb is not set CONFIG_PACKAGE_ruby-enc=y # CONFIG_PACKAGE_ruby-enc-extra is not set # CONFIG_PACKAGE_ruby-erb is not set # CONFIG_PACKAGE_ruby-etc is not set # CONFIG_PACKAGE_ruby-fcntl is not set # CONFIG_PACKAGE_ruby-fiddle is not set # CONFIG_PACKAGE_ruby-filelib is not set # CONFIG_PACKAGE_ruby-fileutils is not set # CONFIG_PACKAGE_ruby-forwardable is not set # CONFIG_PACKAGE_ruby-gdbm is not set # CONFIG_PACKAGE_ruby-gems is not set # CONFIG_PACKAGE_ruby-getoptlong is not set # CONFIG_PACKAGE_ruby-io-console is not set # CONFIG_PACKAGE_ruby-ipaddr is not set # CONFIG_PACKAGE_ruby-irb is not set # CONFIG_PACKAGE_ruby-json is not set # CONFIG_PACKAGE_ruby-logger is not set # CONFIG_PACKAGE_ruby-matrix is not set # CONFIG_PACKAGE_ruby-minitest is not set # CONFIG_PACKAGE_ruby-misc is not set # CONFIG_PACKAGE_ruby-mkmf is not set # CONFIG_PACKAGE_ruby-multithread is not set # CONFIG_PACKAGE_ruby-mutex_m is not set # CONFIG_PACKAGE_ruby-net is not set # CONFIG_PACKAGE_ruby-net-pop is not set # CONFIG_PACKAGE_ruby-net-smtp is not set # CONFIG_PACKAGE_ruby-net-telnet is not set # CONFIG_PACKAGE_ruby-nkf is not set # CONFIG_PACKAGE_ruby-observer is not set # CONFIG_PACKAGE_ruby-open3 is not set # CONFIG_PACKAGE_ruby-openssl is not set # CONFIG_PACKAGE_ruby-optparse is not set # CONFIG_PACKAGE_ruby-ostruct is not set # CONFIG_PACKAGE_ruby-powerassert is not set # CONFIG_PACKAGE_ruby-prettyprint is not set # CONFIG_PACKAGE_ruby-prime is not set CONFIG_PACKAGE_ruby-pstore=y CONFIG_PACKAGE_ruby-psych=y # CONFIG_PACKAGE_ruby-racc is not set # CONFIG_PACKAGE_ruby-rake is not set # CONFIG_PACKAGE_ruby-rbconfig is not set # CONFIG_PACKAGE_ruby-rdoc is not set # CONFIG_PACKAGE_ruby-readline is not set # CONFIG_PACKAGE_ruby-readline-ext is not set # CONFIG_PACKAGE_ruby-reline is not set # CONFIG_PACKAGE_ruby-rexml is not set # CONFIG_PACKAGE_ruby-rinda is not set # CONFIG_PACKAGE_ruby-ripper is not set # CONFIG_PACKAGE_ruby-rss is not set # CONFIG_PACKAGE_ruby-sdbm is not set # CONFIG_PACKAGE_ruby-singleton is not set # CONFIG_PACKAGE_ruby-socket is not set CONFIG_PACKAGE_ruby-stringio=y CONFIG_PACKAGE_ruby-strscan=y # CONFIG_PACKAGE_ruby-testunit is not set # CONFIG_PACKAGE_ruby-time is not set # CONFIG_PACKAGE_ruby-timeout is not set # CONFIG_PACKAGE_ruby-tracer is not set # CONFIG_PACKAGE_ruby-unicodenormalize is not set # CONFIG_PACKAGE_ruby-uri is not set # CONFIG_PACKAGE_ruby-webrick is not set # CONFIG_PACKAGE_ruby-xmlrpc is not set CONFIG_PACKAGE_ruby-yaml=y # CONFIG_PACKAGE_ruby-zlib 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=y # 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_libopenssl1.1 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_dahdi-tools-libtonezone 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=y CONFIG_PACKAGE_libcap-bin-capsh-shell="/bin/sh" # 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=y # # SSL support # CONFIG_LIBCURL_MBEDTLS=y # CONFIG_LIBCURL_WOLFSSL is not set # CONFIG_LIBCURL_OPENSSL is not set # CONFIG_LIBCURL_GNUTLS is not set # CONFIG_LIBCURL_NOSSL is not set # # Supported protocols # # CONFIG_LIBCURL_DICT is not set CONFIG_LIBCURL_FILE=y CONFIG_LIBCURL_FTP=y # CONFIG_LIBCURL_GOPHER is not set CONFIG_LIBCURL_HTTP=y CONFIG_LIBCURL_COOKIES=y # CONFIG_LIBCURL_IMAP is not set # CONFIG_LIBCURL_LDAP is not set # CONFIG_LIBCURL_POP3 is not set # CONFIG_LIBCURL_RTSP is not set # CONFIG_LIBCURL_SSH2 is not set CONFIG_LIBCURL_NO_SMB="!" # CONFIG_LIBCURL_SMTP is not set # CONFIG_LIBCURL_TELNET is not set # CONFIG_LIBCURL_TFTP is not set # CONFIG_LIBCURL_NGHTTP2 is not set # # Miscellaneous # CONFIG_LIBCURL_PROXY=y # CONFIG_LIBCURL_CRYPTO_AUTH is not set # CONFIG_LIBCURL_TLS_SRP is not set # CONFIG_LIBCURL_LIBIDN2 is not set # CONFIG_LIBCURL_THREADED_RESOLVER is not set # CONFIG_LIBCURL_ZLIB is not set # CONFIG_LIBCURL_UNIX_SOCKETS is not set # CONFIG_LIBCURL_LIBCURL_OPTION is not set # CONFIG_LIBCURL_VERBOSE is not set # CONFIG_PACKAGE_libcxx is not set # CONFIG_PACKAGE_libdaemon is not set # CONFIG_PACKAGE_libdaq is not set CONFIG_PACKAGE_libdb47=y # 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=y # 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=y CONFIG_PACKAGE_liblua=y CONFIG_PACKAGE_liblua5.3=y # 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=y # 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=y 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_libpri 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=y # 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=y # 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=y # 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-adguardhome is not set # 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=y # 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-control-timewol is not set # CONFIG_PACKAGE_luci-app-control-webrestriction is not set # CONFIG_PACKAGE_luci-app-control-weburl is not set # CONFIG_PACKAGE_luci-app-cshark is not set CONFIG_PACKAGE_luci-app-ddns=y # 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-fileassistant=y CONFIG_PACKAGE_luci-app-filebrowser=y CONFIG_PACKAGE_luci-app-filetransfer=y CONFIG_PACKAGE_luci-app-firewall=y CONFIG_PACKAGE_luci-app-flowoffload=y # 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=y # CONFIG_PACKAGE_luci-app-haproxy-tcp is not set # CONFIG_PACKAGE_luci-app-hd-idle is not set # CONFIG_PACKAGE_luci-app-hnet is not set # CONFIG_PACKAGE_luci-app-https-dns-proxy is not set # CONFIG_PACKAGE_luci-app-ipsec-server is not set # CONFIG_PACKAGE_luci-app-ipsec-vpnd is not set # CONFIG_PACKAGE_luci-app-jd-dailybonus 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-mtwifi 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-nginx-pingos 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-openclash=y # 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-passwall=y # # Configuration # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Shadowsocks_Server is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ShadowsocksR_Server is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Xray=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_Plus is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Trojan_GO is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_Brook is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_NaiveProxy is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_kcptun is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_haproxy=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_ChinaDNS_NG is not set CONFIG_PACKAGE_luci-app-passwall_INCLUDE_dns2socks=y # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_v2ray-plugin is not set # CONFIG_PACKAGE_luci-app-passwall_INCLUDE_simple-obfs is not set # end of Configuration # CONFIG_PACKAGE_luci-app-polipo is not set # CONFIG_PACKAGE_luci-app-pppoe-relay is not set # CONFIG_PACKAGE_luci-app-pppoe-server is not set # CONFIG_PACKAGE_luci-app-pptp-server 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-smartdns=y # CONFIG_PACKAGE_luci-app-socat 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-mudb-server is not set CONFIG_PACKAGE_luci-app-ssr-plus=y 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_NaiveProxy is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Trojan-go is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_Kcptun is not set # CONFIG_PACKAGE_luci-app-ssr-plus_INCLUDE_V2ray_plugin 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-syncthing is not set # CONFIG_PACKAGE_luci-app-timecontrol is not set # CONFIG_PACKAGE_luci-app-tinyproxy is not set # CONFIG_PACKAGE_luci-app-transmission is not set CONFIG_PACKAGE_luci-app-travelmate=y CONFIG_PACKAGE_luci-app-ttyd=y # CONFIG_PACKAGE_luci-app-udpxy is not set # CONFIG_PACKAGE_luci-app-uhttpd is not set # CONFIG_PACKAGE_luci-app-unblockmusic is not set # CONFIG_UnblockNeteaseMusic_Go is not set # 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-uugamebooster 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=y # CONFIG_PACKAGE_luci-app-watchcat is not set CONFIG_PACKAGE_luci-app-webadmin=y CONFIG_PACKAGE_luci-app-wifischedule=y # 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=y # 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 is not set # 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-autoreboot-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-ddns-bg is not set # CONFIG_PACKAGE_luci-i18n-ddns-ca is not set # CONFIG_PACKAGE_luci-i18n-ddns-cs is not set # CONFIG_PACKAGE_luci-i18n-ddns-de is not set # CONFIG_PACKAGE_luci-i18n-ddns-el is not set # CONFIG_PACKAGE_luci-i18n-ddns-en is not set # CONFIG_PACKAGE_luci-i18n-ddns-es is not set # CONFIG_PACKAGE_luci-i18n-ddns-fr is not set # CONFIG_PACKAGE_luci-i18n-ddns-he is not set # CONFIG_PACKAGE_luci-i18n-ddns-hi is not set # CONFIG_PACKAGE_luci-i18n-ddns-hu is not set # CONFIG_PACKAGE_luci-i18n-ddns-it is not set # CONFIG_PACKAGE_luci-i18n-ddns-ja is not set # CONFIG_PACKAGE_luci-i18n-ddns-ko is not set # CONFIG_PACKAGE_luci-i18n-ddns-mr is not set # CONFIG_PACKAGE_luci-i18n-ddns-ms is not set # CONFIG_PACKAGE_luci-i18n-ddns-no is not set # CONFIG_PACKAGE_luci-i18n-ddns-pl is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt is not set # CONFIG_PACKAGE_luci-i18n-ddns-pt-br is not set # CONFIG_PACKAGE_luci-i18n-ddns-ro is not set # CONFIG_PACKAGE_luci-i18n-ddns-ru is not set # CONFIG_PACKAGE_luci-i18n-ddns-sk is not set # CONFIG_PACKAGE_luci-i18n-ddns-sv is not set # CONFIG_PACKAGE_luci-i18n-ddns-tr is not set # CONFIG_PACKAGE_luci-i18n-ddns-uk is not set # CONFIG_PACKAGE_luci-i18n-ddns-vi is not set CONFIG_PACKAGE_luci-i18n-ddns-zh-cn=y # CONFIG_PACKAGE_luci-i18n-ddns-zh-tw is not set CONFIG_PACKAGE_luci-i18n-filebrowser-zh-cn=y 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-flowoffload-zh-cn=y CONFIG_PACKAGE_luci-i18n-guest-wifi-zh-cn=y 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-smartdns-zh-cn=y 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-vlmcsd-zh-cn=y CONFIG_PACKAGE_luci-i18n-vsftpd-zh-cn=y CONFIG_PACKAGE_luci-i18n-webadmin-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 CONFIG_PACKAGE_luci-i18n-zerotier-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=y # 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=y # 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_kamailio 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=y # # Configuration # # CONFIG_ZEROTIER_ENABLE_DEBUG is not set # CONFIG_ZEROTIER_ENABLE_SELFTEST is not set # end of Configuration # 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=y # CONFIG_PACKAGE_halog 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_naiveproxy is not set # 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_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-go 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_mt_wifi 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=y # 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=y # 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 is not set # 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 is not set # 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_brook is not set # CONFIG_PACKAGE_bwm-ng is not set # CONFIG_PACKAGE_bwping is not set # CONFIG_PACKAGE_chat is not set # CONFIG_PACKAGE_chinadns-ng 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=y # 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_microsocks=y # 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_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-adblock is not set 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_smartdns=y # 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_ssocks=y # CONFIG_PACKAGE_ssocksd 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_trafficshaper is not set CONFIG_PACKAGE_travelmate=y # CONFIG_PACKAGE_trojan is not set # CONFIG_PACKAGE_trojan-plus is not set # 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_uugamebooster is not set # CONFIG_PACKAGE_vallumd is not set # CONFIG_PACKAGE_verysync is not set CONFIG_PACKAGE_vlmcsd=y # 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_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 is not set # 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=y # 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 is not set # 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=y # 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_dahdi-cfg is not set # CONFIG_PACKAGE_dahdi-monitor is not set # 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=y # 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_nand-utils 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_ubi-utils=y # 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 is not set # 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_ykclient 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 CONFIG_OVERRIDE_PKGS="smartdns"
5aa06c1a4e1c4ea5d4bda83b8914eff7c3d17c53
43390109ab88557e6090f3245c47479c123ee500
/src/M1F/problem_bank/0503/Q0503.lean
028cfbe0505f5a96352cd14a1236c4b9c045a539
[ "Apache-2.0" ]
permissive
Ja1941/xena-UROP-2018
41f0956519f94d56b8bf6834a8d39473f4923200
b111fb87f343cf79eca3b886f99ee15c1dd9884b
refs/heads/master
1,662,355,955,139
1,590,577,325,000
1,590,577,325,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
5,279
lean
import algebra.group_power tactic.norm_num algebra.big_operators theorem Q3a (n : ℕ) : ∃ k, (n+1)+(n+2)+(n+3)+(n+4) = 4*k+2 := sorry lemma of_nat_pow : ∀ a b: ℕ, int.of_nat(a^b)=(int.of_nat a)^b := begin intros a b, induction b with k Hk, unfold monoid.pow, simp [int.of_nat_one], unfold monoid.pow nat.pow, -- pow_nat nat.pow has_pow_nat.pow_nat monoid.pow, --show int.of_nat (a^k*a) = (int.of_nat a) * (int.of_nat a)^k, rw [int.of_nat_mul,mul_comm,Hk,mul_comm], end theorem Q3helpful_lemma : ∀ (e : ℕ), 11^e ≥ 3^e := begin intro e, induction e with d Hd, exact dec_trivial, exact calc 11^(nat.succ d) = 11*11^d : rfl ... ≥ 3*11^d : nat.mul_le_mul_right (11^d) (dec_trivial) ... ≥ 3*3^d : nat.mul_le_mul_left 3 Hd ... = 3^(nat.succ d) : rfl end theorem Q3helpful_lemma2 : ∀ (e : ℕ ), (((11^e-3^e):ℕ):ℤ) = (11:ℤ)^e-(3:ℤ)^e := begin intro e, show int.of_nat (11^e - 3^e) = (11:ℤ)^e - (3:ℤ)^e, rw [int.of_nat_sub (Q3helpful_lemma e)], rw [of_nat_pow,of_nat_pow], refl, end theorem Q3b (n : ℕ) : 8 ∣ 11^n - 3^n := sorry theorem Q3ca (n : ℕ) : ∃ k, (n+1)+(n+2)+(n+3)+(n+4) = 4*k+2 := sorry def Q3sum (d : ℕ) (a b : ℤ) := finset.sum (finset.range (d+1)) (λ n, a^n*b^(d-n)) --finset.sum_image : -- ∀ {α : Type u_1} {β : Type u_2} {γ : Type u_3} {f : α → β} [_inst_1 : add_comm_monoid β] -- [_inst_2 : decidable_eq α] [_inst_3 : decidable_eq γ] {s : finset γ} {g : γ → α}, -- (∀ (x : γ), x ∈ s → ∀ (y : γ), y ∈ s → g x = g y → x = y) → -- finset.sum (finset.image g s) f = finset.sum s (λ (x : γ), f (g x)) lemma lt_of_in_finset {x y: ℕ} : x ∈ finset.range y → x < y := by simp --set_option pp.notation false lemma H8 (d : ℕ) : list.map (λ (i : ℕ), d - i) (list.range (d + 1)) = list.reverse (list.range (d + 1)) := begin admit, -- and ask Mario end lemma H7 : ∀ d : ℕ, (finset.range (d+1)).image (λ i,d-i) = finset.range (d+1) := begin -- statement about finsets intro d, unfold finset.image, unfold finset.range, show multiset.to_finset (multiset.map (λ (i : ℕ), d - i) (multiset.range (d + 1))) = {val := multiset.range (d + 1), nodup := _}, unfold multiset.to_finset, apply finset.eq_of_veq, show multiset.erase_dup (multiset.map (λ (i : ℕ), d - i) (multiset.range (d + 1))) = multiset.range (d + 1), -- now a statement about multisets have this2 := multiset.nodup_range (d+1), suffices : multiset.erase_dup (multiset.map (λ (i : ℕ), d - i) (multiset.range (d + 1))) = multiset.erase_dup (multiset.range (d + 1)), rw [this], exact multiset.erase_dup_eq_self.2 this2, apply congr_arg, clear this2, show multiset.map (λ (i : ℕ), d - i) (multiset.range (d + 1)) = ↑(list.range (d + 1)), rw ←multiset.coe_reverse, unfold multiset.range, rw multiset.coe_map, apply congr_arg, -- now a statement about lists exact H8 d, end lemma H0 (d : ℕ) (a b : ℤ) : Q3sum d a b = Q3sum d b a := begin unfold Q3sum, have : (finset.range (d+1)).image (λ i,d-i) = finset.range (d+1), exact H7 d, /- unfold finset.range, unfold multiset.range, rw ←multiset.coe_reverse, -/ rw ←this, -- aargh, rewrites both! have H53 : ∀ (x : ℕ), x ∈ finset.range(d+1) → ∀ (y : ℕ), y ∈ finset.range (d+1) → d-x = d-y → x=y, introv Hx Hy Hxy, have : (d-x)+x=d, exact nat.sub_add_cancel (nat.le_of_lt_succ (lt_of_in_finset Hx)), rw Hxy at this, rw ←nat.sub_add_comm (nat.le_of_lt_succ (lt_of_in_finset Hy)) at this, have this2 : (d+x-y)+y=d+x, exact nat.sub_add_cancel (le_trans (nat.le_of_lt_succ (lt_of_in_finset Hy)) (nat.le_add_right _ _)), rw this at this2, exact eq.symm (nat.add_left_cancel this2), rw [@finset.sum_image ℕ ℤ ℕ (λ (n : ℕ), a ^ n * b ^ (d - n)) _ _ _ (finset.range (d+1)) (λ i : ℕ, d-i) H53], rw [this], apply finset.sum_congr, introv H, have := lt_of_in_finset H, show a ^ (d - x) * b ^ (d - (d - x)) = b ^ x * a ^ (d - x), rw [nat.sub_sub_self (nat.le_of_lt_succ this)], apply mul_comm, end lemma H5 (e : ℕ) : finset.range (nat.succ e) = insert e (finset.range e) := begin exact finset.range_succ, end lemma H1 (d : ℕ) (aa b : ℤ) : b * Q3sum d aa b = Q3sum (d+1) aa b - aa^(d+1) := begin unfold Q3sum, rw finset.mul_sum, change d+1+1 with nat.succ(d+1), rw (@finset.range_succ (d+1)), rw finset.sum_insert, tactic.swap, intro H, apply lt_irrefl (d+1), exact lt_of_in_finset H, rw [nat.sub_self (d+1)], have : ∀ x : ℕ, x<(d+1) → b*(aa^x*b^(d-x))= aa^x*b^(d+1-x), intros x Hx, rw [mul_comm], have : d+1-x = (d-x)+1, rw [add_comm,nat.add_sub_assoc (nat.le_of_lt_succ Hx),add_comm], rw [this], rw [pow_succ],simp, rw [pow_zero,mul_one], rw [add_comm (aa^(d+1)),add_sub_cancel], apply finset.sum_congr, intros, apply this x, exact lt_of_in_finset H, end lemma H3 (d : ℕ) : 11 * Q3sum d 3 11 = Q3sum (d+1) 3 11 - 3^(d+1) := H1 d 3 11 lemma H2 (d : ℕ) : 3 * Q3sum d 3 11 = Q3sum (d+1) 3 11 - 11^(d+1) := begin rw [H0], rw H1 d 11 3, rw [H0] end lemma Q3cb_helper : ∀ d : ℕ, 8*Q3sum d 3 11 = 11^(d+1)-3^(d+1) := begin intro d, change (8:ℤ) with (11:ℤ)-3, rw [sub_mul,H3,H2], simp, end theorem Q3cbint (n : ℕ) : 8 ∣ (11:ℤ)^n - 3^n := sorry theorem Q3cb (n : ℕ) : 8 ∣ 11^n - 3^n := sorry
5039fe9c89139c7ccc94a66092e71cf97a0dbbc7
74addaa0e41490cbaf2abd313a764c96df57b05d
/Mathlib/data/finset/lattice_auto.lean
c21f5229d68e1d18bd6afaea1d6bcfe77eb47f73
[]
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
33,896
lean
/- Copyright (c) 2018 Mario Carneiro. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Mario Carneiro -/ import Mathlib.PrePort import Mathlib.Lean3Lib.init.default import Mathlib.data.finset.fold import Mathlib.data.multiset.lattice import Mathlib.order.order_dual import Mathlib.order.complete_lattice import Mathlib.PostPort universes u_1 u_2 u_3 u_4 u_5 namespace Mathlib /-! # Lattice operations on finsets -/ namespace finset /-! ### sup -/ /-- Supremum of a finite set: `sup {a, b, c} f = f a ⊔ f b ⊔ f c` -/ def sup {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] (s : finset β) (f : β → α) : α := fold has_sup.sup ⊥ f s theorem sup_def {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} : sup s f = multiset.sup (multiset.map f (val s)) := rfl @[simp] theorem sup_empty {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {f : β → α} : sup ∅ f = ⊥ := fold_empty @[simp] theorem sup_insert {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} [DecidableEq β] {b : β} : sup (insert b s) f = f b ⊔ sup s f := fold_insert_idem @[simp] theorem sup_singleton {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {f : β → α} {b : β} : sup (singleton b) f = f b := multiset.sup_singleton theorem sup_union {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s₁ : finset β} {s₂ : finset β} {f : β → α} [DecidableEq β] : sup (s₁ ∪ s₂) f = sup s₁ f ⊔ sup s₂ f := sorry theorem sup_congr {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s₁ : finset β} {s₂ : finset β} {f : β → α} {g : β → α} (hs : s₁ = s₂) (hfg : ∀ (a : β), a ∈ s₂ → f a = g a) : sup s₁ f = sup s₂ g := Eq._oldrec (fun (hfg : ∀ (a : β), a ∈ s₁ → f a = g a) => fold_congr hfg) hs hfg @[simp] theorem sup_le_iff {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} {a : α} : sup s f ≤ a ↔ ∀ (b : β), b ∈ s → f b ≤ a := sorry theorem sup_const {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} (h : finset.nonempty s) (c : α) : (sup s fun (_x : β) => c) = c := eq_of_forall_ge_iff fun (b : α) => iff.trans sup_le_iff (nonempty.forall_const h) theorem sup_le {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} {a : α} : (∀ (b : β), b ∈ s → f b ≤ a) → sup s f ≤ a := iff.mpr sup_le_iff theorem le_sup {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} {b : β} (hb : b ∈ s) : f b ≤ sup s f := iff.mp sup_le_iff (le_refl (sup s f)) b hb theorem sup_mono_fun {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} {g : β → α} (h : ∀ (b : β), b ∈ s → f b ≤ g b) : sup s f ≤ sup s g := sup_le fun (b : β) (hb : b ∈ s) => le_trans (h b hb) (le_sup hb) theorem sup_mono {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s₁ : finset β} {s₂ : finset β} {f : β → α} (h : s₁ ⊆ s₂) : sup s₁ f ≤ sup s₂ f := sup_le fun (b : β) (hb : b ∈ s₁) => le_sup (h hb) @[simp] theorem sup_lt_iff {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} [is_total α LessEq] {a : α} (ha : ⊥ < a) : sup s f < a ↔ ∀ (b : β), b ∈ s → f b < a := sorry theorem comp_sup_eq_sup_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [semilattice_sup_bot α] [semilattice_sup_bot γ] {s : finset β} {f : β → α} (g : α → γ) (g_sup : ∀ (x y : α), g (x ⊔ y) = g x ⊔ g y) (bot : g ⊥ = ⊥) : g (sup s f) = sup s (g ∘ f) := sorry theorem comp_sup_eq_sup_comp_of_is_total {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {s : finset β} {f : β → α} [is_total α LessEq] {γ : Type} [semilattice_sup_bot γ] (g : α → γ) (mono_g : monotone g) (bot : g ⊥ = ⊥) : g (sup s f) = sup s (g ∘ f) := comp_sup_eq_sup_comp g (monotone.map_sup mono_g) bot /-- Computating `sup` in a subtype (closed under `sup`) is the same as computing it in `α`. -/ theorem sup_coe {α : Type u_1} {β : Type u_2} [semilattice_sup_bot α] {P : α → Prop} {Pbot : P ⊥} {Psup : ∀ {x y : α}, P x → P y → P (x ⊔ y)} (t : finset β) (f : β → Subtype fun (x : α) => P x) : ↑(sup t f) = sup t fun (x : β) => ↑(f x) := sorry @[simp] theorem sup_to_finset {α : Type u_1} {β : Type u_2} [DecidableEq β] (s : finset α) (f : α → multiset β) : multiset.to_finset (sup s f) = sup s fun (x : α) => multiset.to_finset (f x) := comp_sup_eq_sup_comp multiset.to_finset multiset.to_finset_union rfl theorem subset_range_sup_succ (s : finset ℕ) : s ⊆ range (Nat.succ (sup s id)) := fun (n : ℕ) (hn : n ∈ s) => iff.mpr mem_range (nat.lt_succ_of_le (le_sup hn)) theorem exists_nat_subset_range (s : finset ℕ) : ∃ (n : ℕ), s ⊆ range n := Exists.intro (Nat.succ (sup s id)) (subset_range_sup_succ s) theorem sup_subset {α : Type u_1} {β : Type u_2} [semilattice_sup_bot β] {s : finset α} {t : finset α} (hst : s ⊆ t) (f : α → β) : sup s f ≤ sup t f := sorry theorem sup_closed_of_sup_closed {α : Type u_1} [semilattice_sup_bot α] {s : set α} (t : finset α) (htne : finset.nonempty t) (h_subset : ↑t ⊆ s) (h : ∀ {a b : α}, a ∈ s → b ∈ s → a ⊔ b ∈ s) : sup t id ∈ s := sorry theorem sup_le_of_le_directed {α : Type u_1} [semilattice_sup_bot α] (s : set α) (hs : set.nonempty s) (hdir : directed_on LessEq s) (t : finset α) : (∀ (x : α) (H : x ∈ t), ∃ (y : α), ∃ (H : y ∈ s), x ≤ y) → ∃ (x : α), x ∈ s ∧ sup t id ≤ x := sorry theorem sup_eq_supr {α : Type u_1} {β : Type u_2} [complete_lattice β] (s : finset α) (f : α → β) : sup s f = supr fun (a : α) => supr fun (H : a ∈ s) => f a := le_antisymm (sup_le fun (a : α) (ha : a ∈ s) => le_supr_of_le a (le_supr (fun (ha : a ∈ s) => f a) ha)) (supr_le fun (a : α) => supr_le fun (ha : a ∈ s) => le_sup ha) theorem sup_eq_Sup {α : Type u_1} [complete_lattice α] (s : finset α) : sup s id = Sup ↑s := sorry /-! ### inf -/ /-- Infimum of a finite set: `inf {a, b, c} f = f a ⊓ f b ⊓ f c` -/ def inf {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] (s : finset β) (f : β → α) : α := fold has_inf.inf ⊤ f s theorem inf_def {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} : inf s f = multiset.inf (multiset.map f (val s)) := rfl @[simp] theorem inf_empty {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {f : β → α} : inf ∅ f = ⊤ := fold_empty theorem le_inf_iff {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} {a : α} : a ≤ inf s f ↔ ∀ (b : β), b ∈ s → a ≤ f b := sup_le_iff @[simp] theorem inf_insert {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} [DecidableEq β] {b : β} : inf (insert b s) f = f b ⊓ inf s f := fold_insert_idem @[simp] theorem inf_singleton {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {f : β → α} {b : β} : inf (singleton b) f = f b := multiset.inf_singleton theorem inf_union {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s₁ : finset β} {s₂ : finset β} {f : β → α} [DecidableEq β] : inf (s₁ ∪ s₂) f = inf s₁ f ⊓ inf s₂ f := sup_union theorem inf_congr {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s₁ : finset β} {s₂ : finset β} {f : β → α} {g : β → α} (hs : s₁ = s₂) (hfg : ∀ (a : β), a ∈ s₂ → f a = g a) : inf s₁ f = inf s₂ g := Eq._oldrec (fun (hfg : ∀ (a : β), a ∈ s₁ → f a = g a) => fold_congr hfg) hs hfg theorem inf_le {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} {b : β} (hb : b ∈ s) : inf s f ≤ f b := iff.mp le_inf_iff (le_refl (inf s f)) b hb theorem le_inf {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} {a : α} : (∀ (b : β), b ∈ s → a ≤ f b) → a ≤ inf s f := iff.mpr le_inf_iff theorem inf_mono_fun {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} {g : β → α} (h : ∀ (b : β), b ∈ s → f b ≤ g b) : inf s f ≤ inf s g := le_inf fun (b : β) (hb : b ∈ s) => le_trans (inf_le hb) (h b hb) theorem inf_mono {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s₁ : finset β} {s₂ : finset β} {f : β → α} (h : s₁ ⊆ s₂) : inf s₂ f ≤ inf s₁ f := le_inf fun (b : β) (hb : b ∈ s₁) => inf_le (h hb) theorem lt_inf_iff {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} [h : is_total α LessEq] {a : α} (ha : a < ⊤) : a < inf s f ↔ ∀ (b : β), b ∈ s → a < f b := sup_lt_iff ha theorem comp_inf_eq_inf_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} [semilattice_inf_top α] [semilattice_inf_top γ] {s : finset β} {f : β → α} (g : α → γ) (g_inf : ∀ (x y : α), g (x ⊓ y) = g x ⊓ g y) (top : g ⊤ = ⊤) : g (inf s f) = inf s (g ∘ f) := comp_sup_eq_sup_comp g g_inf top theorem comp_inf_eq_inf_comp_of_is_total {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {s : finset β} {f : β → α} [h : is_total α LessEq] {γ : Type} [semilattice_inf_top γ] (g : α → γ) (mono_g : monotone g) (top : g ⊤ = ⊤) : g (inf s f) = inf s (g ∘ f) := comp_inf_eq_inf_comp g (monotone.map_inf mono_g) top /-- Computating `inf` in a subtype (closed under `inf`) is the same as computing it in `α`. -/ theorem inf_coe {α : Type u_1} {β : Type u_2} [semilattice_inf_top α] {P : α → Prop} {Ptop : P ⊤} {Pinf : ∀ {x y : α}, P x → P y → P (x ⊓ y)} (t : finset β) (f : β → Subtype fun (x : α) => P x) : ↑(inf t f) = inf t fun (x : β) => ↑(f x) := sorry theorem inf_eq_infi {α : Type u_1} {β : Type u_2} [complete_lattice β] (s : finset α) (f : α → β) : inf s f = infi fun (a : α) => infi fun (H : a ∈ s) => f a := sup_eq_supr s f theorem inf_eq_Inf {α : Type u_1} [complete_lattice α] (s : finset α) : inf s id = Inf ↑s := sorry /-! ### max and min of finite sets -/ /-- Let `s` be a finset in a linear order. Then `s.max` is the maximum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.max'`. -/ protected def max {α : Type u_1} [linear_order α] : finset α → Option α := fold (option.lift_or_get max) none some theorem max_eq_sup_with_bot {α : Type u_1} [linear_order α] (s : finset α) : finset.max s = sup s some := rfl @[simp] theorem max_empty {α : Type u_1} [linear_order α] : finset.max ∅ = none := rfl @[simp] theorem max_insert {α : Type u_1} [linear_order α] {a : α} {s : finset α} : finset.max (insert a s) = option.lift_or_get max (some a) (finset.max s) := fold_insert_idem @[simp] theorem max_singleton {α : Type u_1} [linear_order α] {a : α} : finset.max (singleton a) = some a := eq.mpr (id (Eq._oldrec (Eq.refl (finset.max (singleton a) = some a)) (Eq.symm (insert_emptyc_eq a)))) max_insert theorem max_of_mem {α : Type u_1} [linear_order α] {s : finset α} {a : α} (h : a ∈ s) : ∃ (b : α), b ∈ finset.max s := Exists.imp (fun (b : α) => Exists.fst) (le_sup h a rfl) theorem max_of_nonempty {α : Type u_1} [linear_order α] {s : finset α} (h : finset.nonempty s) : ∃ (a : α), a ∈ finset.max s := (fun (_a : finset.nonempty s) => Exists.dcases_on _a fun (w : α) (h_1 : w ∈ s) => idRhs (∃ (a : α), a ∈ finset.max s) (max_of_mem h_1)) h theorem max_eq_none {α : Type u_1} [linear_order α] {s : finset α} : finset.max s = none ↔ s = ∅ := sorry theorem mem_of_max {α : Type u_1} [linear_order α] {s : finset α} {a : α} : a ∈ finset.max s → a ∈ s := sorry theorem le_max_of_mem {α : Type u_1} [linear_order α] {s : finset α} {a : α} {b : α} (h₁ : a ∈ s) (h₂ : b ∈ finset.max s) : a ≤ b := sorry /-- Let `s` be a finset in a linear order. Then `s.min` is the minimum of `s` if `s` is not empty, and `none` otherwise. It belongs to `option α`. If you want to get an element of `α`, see `s.min'`. -/ protected def min {α : Type u_1} [linear_order α] : finset α → Option α := fold (option.lift_or_get min) none some theorem min_eq_inf_with_top {α : Type u_1} [linear_order α] (s : finset α) : finset.min s = inf s some := rfl @[simp] theorem min_empty {α : Type u_1} [linear_order α] : finset.min ∅ = none := rfl @[simp] theorem min_insert {α : Type u_1} [linear_order α] {a : α} {s : finset α} : finset.min (insert a s) = option.lift_or_get min (some a) (finset.min s) := fold_insert_idem @[simp] theorem min_singleton {α : Type u_1} [linear_order α] {a : α} : finset.min (singleton a) = some a := eq.mpr (id (Eq._oldrec (Eq.refl (finset.min (singleton a) = some a)) (Eq.symm (insert_emptyc_eq a)))) min_insert theorem min_of_mem {α : Type u_1} [linear_order α] {s : finset α} {a : α} (h : a ∈ s) : ∃ (b : α), b ∈ finset.min s := Exists.imp (fun (b : α) => Exists.fst) (inf_le h a rfl) theorem min_of_nonempty {α : Type u_1} [linear_order α] {s : finset α} (h : finset.nonempty s) : ∃ (a : α), a ∈ finset.min s := (fun (_a : finset.nonempty s) => Exists.dcases_on _a fun (w : α) (h_1 : w ∈ s) => idRhs (∃ (a : α), a ∈ finset.min s) (min_of_mem h_1)) h theorem min_eq_none {α : Type u_1} [linear_order α] {s : finset α} : finset.min s = none ↔ s = ∅ := sorry theorem mem_of_min {α : Type u_1} [linear_order α] {s : finset α} {a : α} : a ∈ finset.min s → a ∈ s := sorry theorem min_le_of_mem {α : Type u_1} [linear_order α] {s : finset α} {a : α} {b : α} (h₁ : b ∈ s) (h₂ : a ∈ finset.min s) : a ≤ b := sorry /-- Given a nonempty finset `s` in a linear order `α `, then `s.min' h` is its minimum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.min`, taking values in `option α`. -/ def min' {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) : α := option.get sorry /-- Given a nonempty finset `s` in a linear order `α `, then `s.max' h` is its maximum, as an element of `α`, where `h` is a proof of nonemptiness. Without this assumption, use instead `s.max`, taking values in `option α`. -/ def max' {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) : α := option.get sorry theorem min'_mem {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) : min' s H ∈ s := sorry theorem min'_le {α : Type u_1} [linear_order α] (s : finset α) (x : α) (H2 : x ∈ s) : min' s (Exists.intro x H2) ≤ x := min_le_of_mem H2 (option.get_mem (min'._match_2 s (Exists.intro x H2))) theorem le_min' {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) (x : α) (H2 : ∀ (y : α), y ∈ s → x ≤ y) : x ≤ min' s H := H2 (min' s H) (min'_mem s H) /-- `{a}.min' _` is `a`. -/ @[simp] theorem min'_singleton {α : Type u_1} [linear_order α] (a : α) : min' (singleton a) (singleton_nonempty a) = a := sorry theorem max'_mem {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) : max' s H ∈ s := sorry theorem le_max' {α : Type u_1} [linear_order α] (s : finset α) (x : α) (H2 : x ∈ s) : x ≤ max' s (Exists.intro x H2) := le_max_of_mem H2 (option.get_mem (max'._match_2 s (Exists.intro x H2))) theorem max'_le {α : Type u_1} [linear_order α] (s : finset α) (H : finset.nonempty s) (x : α) (H2 : ∀ (y : α), y ∈ s → y ≤ x) : max' s H ≤ x := H2 (max' s H) (max'_mem s H) /-- `{a}.max' _` is `a`. -/ @[simp] theorem max'_singleton {α : Type u_1} [linear_order α] (a : α) : max' (singleton a) (singleton_nonempty a) = a := sorry theorem min'_lt_max' {α : Type u_1} [linear_order α] (s : finset α) {i : α} {j : α} (H1 : i ∈ s) (H2 : j ∈ s) (H3 : i ≠ j) : min' s (Exists.intro i H1) < max' s (Exists.intro i H1) := sorry /-- If there's more than 1 element, the min' is less than the max'. An alternate version of `min'_lt_max'` which is sometimes more convenient. -/ theorem min'_lt_max'_of_card {α : Type u_1} [linear_order α] (s : finset α) (h₂ : 1 < card s) : min' s (iff.mp card_pos (lt_trans zero_lt_one h₂)) < max' s (iff.mp card_pos (lt_trans zero_lt_one h₂)) := sorry theorem max'_eq_of_dual_min' {α : Type u_1} [linear_order α] {s : finset α} (hs : finset.nonempty s) : max' s hs = coe_fn order_dual.of_dual (min' (image (⇑order_dual.to_dual) s) (nonempty.image hs ⇑order_dual.to_dual)) := sorry theorem min'_eq_of_dual_max' {α : Type u_1} [linear_order α] {s : finset α} (hs : finset.nonempty s) : min' s hs = coe_fn order_dual.of_dual (max' (image (⇑order_dual.to_dual) s) (nonempty.image hs ⇑order_dual.to_dual)) := sorry @[simp] theorem of_dual_max_eq_min_of_dual {α : Type u_1} [linear_order α] {a : α} {b : α} : coe_fn order_dual.of_dual (max a b) = min (coe_fn order_dual.of_dual a) (coe_fn order_dual.of_dual b) := rfl @[simp] theorem of_dual_min_eq_max_of_dual {α : Type u_1} [linear_order α] {a : α} {b : α} : coe_fn order_dual.of_dual (min a b) = max (coe_fn order_dual.of_dual a) (coe_fn order_dual.of_dual b) := rfl theorem exists_max_image {α : Type u_1} {β : Type u_2} [linear_order α] (s : finset β) (f : β → α) (h : finset.nonempty s) : ∃ (x : β), ∃ (H : x ∈ s), ∀ (x' : β), x' ∈ s → f x' ≤ f x := sorry theorem exists_min_image {α : Type u_1} {β : Type u_2} [linear_order α] (s : finset β) (f : β → α) (h : finset.nonempty s) : ∃ (x : β), ∃ (H : x ∈ s), ∀ (x' : β), x' ∈ s → f x ≤ f x' := exists_max_image s f h end finset namespace multiset theorem count_sup {α : Type u_1} {β : Type u_2} [DecidableEq β] (s : finset α) (f : α → multiset β) (b : β) : count b (finset.sup s f) = finset.sup s fun (a : α) => count b (f a) := sorry theorem mem_sup {α : Type u_1} {β : Type u_2} [DecidableEq β] {s : finset α} {f : α → multiset β} {x : β} : x ∈ finset.sup s f ↔ ∃ (v : α), ∃ (H : v ∈ s), x ∈ f v := sorry end multiset namespace finset theorem mem_sup {α : Type u_1} {β : Type u_2} [DecidableEq β] {s : finset α} {f : α → finset β} {x : β} : x ∈ sup s f ↔ ∃ (v : α), ∃ (H : v ∈ s), x ∈ f v := sorry theorem sup_eq_bUnion {α : Type u_1} {β : Type u_2} [DecidableEq β] (s : finset α) (t : α → finset β) : sup s t = finset.bUnion s t := sorry end finset /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `supr_eq_supr_finset'` for a version that works for `ι : Sort*`. -/ theorem supr_eq_supr_finset {α : Type u_1} {ι : Type u_4} [complete_lattice α] (s : ι → α) : (supr fun (i : ι) => s i) = supr fun (t : finset ι) => supr fun (i : ι) => supr fun (H : i ∈ t) => s i := sorry /-- Supremum of `s i`, `i : ι`, is equal to the supremum over `t : finset ι` of suprema `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `supr_eq_supr_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ theorem supr_eq_supr_finset' {α : Type u_1} {ι' : Sort u_5} [complete_lattice α] (s : ι' → α) : (supr fun (i : ι') => s i) = supr fun (t : finset (plift ι')) => supr fun (i : plift ι') => supr fun (H : i ∈ t) => s (plift.down i) := sorry /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version assumes `ι` is a `Type*`. See `infi_eq_infi_finset'` for a version that works for `ι : Sort*`. -/ theorem infi_eq_infi_finset {α : Type u_1} {ι : Type u_4} [complete_lattice α] (s : ι → α) : (infi fun (i : ι) => s i) = infi fun (t : finset ι) => infi fun (i : ι) => infi fun (H : i ∈ t) => s i := supr_eq_supr_finset fun (i : ι) => s i /-- Infimum of `s i`, `i : ι`, is equal to the infimum over `t : finset ι` of infima `⨆ i ∈ t, s i`. This version works for `ι : Sort*`. See `infi_eq_infi_finset` for a version that assumes `ι : Type*` but has no `plift`s. -/ theorem infi_eq_infi_finset' {α : Type u_1} {ι' : Sort u_5} [complete_lattice α] (s : ι' → α) : (infi fun (i : ι') => s i) = infi fun (t : finset (plift ι')) => infi fun (i : plift ι') => infi fun (H : i ∈ t) => s (plift.down i) := supr_eq_supr_finset' fun (i : ι') => s i namespace set /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version assumes `ι : Type*`. See also `Union_eq_Union_finset'` for a version that works for `ι : Sort*`. -/ theorem Union_eq_Union_finset {α : Type u_1} {ι : Type u_4} (s : ι → set α) : (Union fun (i : ι) => s i) = Union fun (t : finset ι) => Union fun (i : ι) => Union fun (H : i ∈ t) => s i := supr_eq_supr_finset s /-- Union of an indexed family of sets `s : ι → set α` is equal to the union of the unions of finite subfamilies. This version works for `ι : Sort*`. See also `Union_eq_Union_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ theorem Union_eq_Union_finset' {α : Type u_1} {ι' : Sort u_5} (s : ι' → set α) : (Union fun (i : ι') => s i) = Union fun (t : finset (plift ι')) => Union fun (i : plift ι') => Union fun (H : i ∈ t) => s (plift.down i) := supr_eq_supr_finset' s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version assumes `ι : Type*`. See also `Inter_eq_Inter_finset'` for a version that works for `ι : Sort*`. -/ theorem Inter_eq_Inter_finset {α : Type u_1} {ι : Type u_4} (s : ι → set α) : (Inter fun (i : ι) => s i) = Inter fun (t : finset ι) => Inter fun (i : ι) => Inter fun (H : i ∈ t) => s i := infi_eq_infi_finset s /-- Intersection of an indexed family of sets `s : ι → set α` is equal to the intersection of the intersections of finite subfamilies. This version works for `ι : Sort*`. See also `Inter_eq_Inter_finset` for a version that assumes `ι : Type*` but avoids `plift`s in the right hand side. -/ theorem Inter_eq_Inter_finset' {α : Type u_1} {ι' : Sort u_5} (s : ι' → set α) : (Inter fun (i : ι') => s i) = Inter fun (t : finset (plift ι')) => Inter fun (i : plift ι') => Inter fun (H : i ∈ t) => s (plift.down i) := infi_eq_infi_finset' s end set namespace finset /-! ### Interaction with big lattice/set operations -/ theorem supr_coe {α : Type u_1} {β : Type u_2} [has_Sup β] (f : α → β) (s : finset α) : (supr fun (x : α) => supr fun (H : x ∈ ↑s) => f x) = supr fun (x : α) => supr fun (H : x ∈ s) => f x := rfl theorem infi_coe {α : Type u_1} {β : Type u_2} [has_Inf β] (f : α → β) (s : finset α) : (infi fun (x : α) => infi fun (H : x ∈ ↑s) => f x) = infi fun (x : α) => infi fun (H : x ∈ s) => f x := rfl theorem supr_singleton {α : Type u_1} {β : Type u_2} [complete_lattice β] (a : α) (s : α → β) : (supr fun (x : α) => supr fun (H : x ∈ singleton a) => s x) = s a := sorry theorem infi_singleton {α : Type u_1} {β : Type u_2} [complete_lattice β] (a : α) (s : α → β) : (infi fun (x : α) => infi fun (H : x ∈ singleton a) => s x) = s a := sorry theorem supr_option_to_finset {α : Type u_1} {β : Type u_2} [complete_lattice β] (o : Option α) (f : α → β) : (supr fun (x : α) => supr fun (H : x ∈ option.to_finset o) => f x) = supr fun (x : α) => supr fun (H : x ∈ o) => f x := sorry theorem infi_option_to_finset {α : Type u_1} {β : Type u_2} [complete_lattice β] (o : Option α) (f : α → β) : (infi fun (x : α) => infi fun (H : x ∈ option.to_finset o) => f x) = infi fun (x : α) => infi fun (H : x ∈ o) => f x := supr_option_to_finset o fun (x : α) => f x theorem supr_union {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] {f : α → β} {s : finset α} {t : finset α} : (supr fun (x : α) => supr fun (H : x ∈ s ∪ t) => f x) = (supr fun (x : α) => supr fun (H : x ∈ s) => f x) ⊔ supr fun (x : α) => supr fun (H : x ∈ t) => f x := sorry theorem infi_union {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] {f : α → β} {s : finset α} {t : finset α} : (infi fun (x : α) => infi fun (H : x ∈ s ∪ t) => f x) = (infi fun (x : α) => infi fun (H : x ∈ s) => f x) ⊓ infi fun (x : α) => infi fun (H : x ∈ t) => f x := sorry theorem supr_insert {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] (a : α) (s : finset α) (t : α → β) : (supr fun (x : α) => supr fun (H : x ∈ insert a s) => t x) = t a ⊔ supr fun (x : α) => supr fun (H : x ∈ s) => t x := sorry theorem infi_insert {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] (a : α) (s : finset α) (t : α → β) : (infi fun (x : α) => infi fun (H : x ∈ insert a s) => t x) = t a ⊓ infi fun (x : α) => infi fun (H : x ∈ s) => t x := sorry theorem supr_finset_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} [complete_lattice β] [DecidableEq α] {f : γ → α} {g : α → β} {s : finset γ} : (supr fun (x : α) => supr fun (H : x ∈ image f s) => g x) = supr fun (y : γ) => supr fun (H : y ∈ s) => g (f y) := sorry theorem sup_finset_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} [complete_lattice β] [DecidableEq α] {f : γ → α} {g : α → β} {s : finset γ} : sup s (g ∘ f) = sup (image f s) g := sorry theorem infi_finset_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} [complete_lattice β] [DecidableEq α] {f : γ → α} {g : α → β} {s : finset γ} : (infi fun (x : α) => infi fun (H : x ∈ image f s) => g x) = infi fun (y : γ) => infi fun (H : y ∈ s) => g (f y) := sorry theorem supr_insert_update {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] {x : α} {t : finset α} (f : α → β) {s : β} (hx : ¬x ∈ t) : (supr fun (i : α) => supr fun (H : i ∈ insert x t) => function.update f x s i) = s ⊔ supr fun (i : α) => supr fun (H : i ∈ t) => f i := sorry theorem infi_insert_update {α : Type u_1} {β : Type u_2} [complete_lattice β] [DecidableEq α] {x : α} {t : finset α} (f : α → β) {s : β} (hx : ¬x ∈ t) : (infi fun (i : α) => infi fun (H : i ∈ insert x t) => function.update f x s i) = s ⊓ infi fun (i : α) => infi fun (H : i ∈ t) => f i := supr_insert_update f hx theorem supr_bUnion {α : Type u_1} {β : Type u_2} {γ : Type u_3} [complete_lattice β] [DecidableEq α] (s : finset γ) (t : γ → finset α) (f : α → β) : (supr fun (y : α) => supr fun (H : y ∈ finset.bUnion s t) => f y) = supr fun (x : γ) => supr fun (H : x ∈ s) => supr fun (y : α) => supr fun (H : y ∈ t x) => f y := sorry theorem infi_bUnion {α : Type u_1} {β : Type u_2} {γ : Type u_3} [complete_lattice β] [DecidableEq α] (s : finset γ) (t : γ → finset α) (f : α → β) : (infi fun (y : α) => infi fun (H : y ∈ finset.bUnion s t) => f y) = infi fun (x : γ) => infi fun (H : x ∈ s) => infi fun (y : α) => infi fun (H : y ∈ t x) => f y := supr_bUnion s t fun (y : α) => f y @[simp] theorem set_bUnion_coe {α : Type u_1} {β : Type u_2} (s : finset α) (t : α → set β) : (set.Union fun (x : α) => set.Union fun (H : x ∈ ↑s) => t x) = set.Union fun (x : α) => set.Union fun (H : x ∈ s) => t x := rfl @[simp] theorem set_bInter_coe {α : Type u_1} {β : Type u_2} (s : finset α) (t : α → set β) : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ ↑s) => t x) = set.Inter fun (x : α) => set.Inter fun (H : x ∈ s) => t x := rfl @[simp] theorem set_bUnion_singleton {α : Type u_1} {β : Type u_2} (a : α) (s : α → set β) : (set.Union fun (x : α) => set.Union fun (H : x ∈ singleton a) => s x) = s a := supr_singleton a s @[simp] theorem set_bInter_singleton {α : Type u_1} {β : Type u_2} (a : α) (s : α → set β) : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ singleton a) => s x) = s a := infi_singleton a s @[simp] theorem set_bUnion_preimage_singleton {α : Type u_1} {β : Type u_2} (f : α → β) (s : finset β) : (set.Union fun (y : β) => set.Union fun (H : y ∈ s) => f ⁻¹' singleton y) = f ⁻¹' ↑s := set.bUnion_preimage_singleton f ↑s @[simp] theorem set_bUnion_option_to_finset {α : Type u_1} {β : Type u_2} (o : Option α) (f : α → set β) : (set.Union fun (x : α) => set.Union fun (H : x ∈ option.to_finset o) => f x) = set.Union fun (x : α) => set.Union fun (H : x ∈ o) => f x := supr_option_to_finset o f @[simp] theorem set_bInter_option_to_finset {α : Type u_1} {β : Type u_2} (o : Option α) (f : α → set β) : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ option.to_finset o) => f x) = set.Inter fun (x : α) => set.Inter fun (H : x ∈ o) => f x := infi_option_to_finset o f theorem set_bUnion_union {α : Type u_1} {β : Type u_2} [DecidableEq α] (s : finset α) (t : finset α) (u : α → set β) : (set.Union fun (x : α) => set.Union fun (H : x ∈ s ∪ t) => u x) = (set.Union fun (x : α) => set.Union fun (H : x ∈ s) => u x) ∪ set.Union fun (x : α) => set.Union fun (H : x ∈ t) => u x := supr_union theorem set_bInter_inter {α : Type u_1} {β : Type u_2} [DecidableEq α] (s : finset α) (t : finset α) (u : α → set β) : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ s ∪ t) => u x) = (set.Inter fun (x : α) => set.Inter fun (H : x ∈ s) => u x) ∩ set.Inter fun (x : α) => set.Inter fun (H : x ∈ t) => u x := infi_union @[simp] theorem set_bUnion_insert {α : Type u_1} {β : Type u_2} [DecidableEq α] (a : α) (s : finset α) (t : α → set β) : (set.Union fun (x : α) => set.Union fun (H : x ∈ insert a s) => t x) = t a ∪ set.Union fun (x : α) => set.Union fun (H : x ∈ s) => t x := supr_insert a s t @[simp] theorem set_bInter_insert {α : Type u_1} {β : Type u_2} [DecidableEq α] (a : α) (s : finset α) (t : α → set β) : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ insert a s) => t x) = t a ∩ set.Inter fun (x : α) => set.Inter fun (H : x ∈ s) => t x := infi_insert a s t @[simp] theorem set_bUnion_finset_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} [DecidableEq α] {f : γ → α} {g : α → set β} {s : finset γ} : (set.Union fun (x : α) => set.Union fun (H : x ∈ image f s) => g x) = set.Union fun (y : γ) => set.Union fun (H : y ∈ s) => g (f y) := supr_finset_image @[simp] theorem set_bInter_finset_image {α : Type u_1} {β : Type u_2} {γ : Type u_3} [DecidableEq α] {f : γ → α} {g : α → set β} {s : finset γ} : (set.Inter fun (x : α) => set.Inter fun (H : x ∈ image f s) => g x) = set.Inter fun (y : γ) => set.Inter fun (H : y ∈ s) => g (f y) := infi_finset_image theorem set_bUnion_insert_update {α : Type u_1} {β : Type u_2} [DecidableEq α] {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : ¬x ∈ t) : (set.Union fun (i : α) => set.Union fun (H : i ∈ insert x t) => function.update f x s i) = s ∪ set.Union fun (i : α) => set.Union fun (H : i ∈ t) => f i := supr_insert_update f hx theorem set_bInter_insert_update {α : Type u_1} {β : Type u_2} [DecidableEq α] {x : α} {t : finset α} (f : α → set β) {s : set β} (hx : ¬x ∈ t) : (set.Inter fun (i : α) => set.Inter fun (H : i ∈ insert x t) => function.update f x s i) = s ∩ set.Inter fun (i : α) => set.Inter fun (H : i ∈ t) => f i := infi_insert_update f hx @[simp] theorem set_bUnion_bUnion {α : Type u_1} {β : Type u_2} {γ : Type u_3} [DecidableEq α] (s : finset γ) (t : γ → finset α) (f : α → set β) : (set.Union fun (y : α) => set.Union fun (H : y ∈ finset.bUnion s t) => f y) = set.Union fun (x : γ) => set.Union fun (H : x ∈ s) => set.Union fun (y : α) => set.Union fun (H : y ∈ t x) => f y := supr_bUnion s t f @[simp] theorem set_bInter_bUnion {α : Type u_1} {β : Type u_2} {γ : Type u_3} [DecidableEq α] (s : finset γ) (t : γ → finset α) (f : α → set β) : (set.Inter fun (y : α) => set.Inter fun (H : y ∈ finset.bUnion s t) => f y) = set.Inter fun (x : γ) => set.Inter fun (H : x ∈ s) => set.Inter fun (y : α) => set.Inter fun (H : y ∈ t x) => f y := infi_bUnion s t f end Mathlib
81314ae43ef6eb512e61a226b391db3ce879224e
ea11767c9c6a467c4b7710ec6f371c95cfc023fd
/src/monoidal_categories/braided_monoidal_functor.lean
ca3812ad999472fc52adb2e0be37849d23c920c8
[]
no_license
RitaAhmadi/lean-monoidal-categories
68a23f513e902038e44681336b87f659bbc281e0
81f43e1e0d623a96695aa8938951d7422d6d7ba6
refs/heads/master
1,651,458,686,519
1,529,824,613,000
1,529,824,613,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
349
lean
-- Copyright (c) 2017 Scott Morrison. All rights reserved. -- Released under Apache 2.0 license as described in the file LICENSE. -- Authors: Stephen Morgan, Scott Morrison import .braided_monoidal_category namespace categories.braided_monoidal_functor open categories.braided_monoidal_category -- PROJECT end categories.braided_monoidal_functor
13831f38d9f2bf371430e9dd7ef247821d95f2e2
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
/tests/lean/PPRoundtrip.lean
5062229bbcbbabecae20c2912455eef6aa29469a
[ "Apache-2.0" ]
permissive
WojciechKarpiel/lean4
7f89706b8e3c1f942b83a2c91a3a00b05da0e65b
f6e1314fa08293dea66a329e05b6c196a0189163
refs/heads/master
1,686,633,402,214
1,625,821,189,000
1,625,821,258,000
384,640,886
0
0
Apache-2.0
1,625,903,617,000
1,625,903,026,000
null
UTF-8
Lean
false
false
3,087
lean
import Lean open Lean open Lean.Elab open Lean.Elab.Term open Lean.Elab.Command open Std.Format open Std open Lean.PrettyPrinter open Lean.Meta def checkM (stx : TermElabM Syntax) (optionsPerPos : OptionsPerPos := {}) : TermElabM Unit := do let opts ← getOptions let stx ← stx let e ← elabTermAndSynthesize stx none <* throwErrorIfErrors let stx' ← delab Name.anonymous [] e optionsPerPos let f' ← PrettyPrinter.ppTerm stx' let s := f'.pretty' opts IO.println s let env ← getEnv match Parser.runParserCategory env `term s "<input>" with | Except.error e => throwErrorAt stx e | Except.ok stx'' => do let e' ← elabTermAndSynthesize stx'' none <* throwErrorIfErrors unless (← isDefEq e e') do throwErrorAt stx (m!"failed to round-trip" ++ line ++ fmt e ++ line ++ fmt e') -- set_option trace.PrettyPrinter.parenthesize true set_option format.width 20 -- #eval checkM `(?m) -- fails round-trip #eval checkM `(Sort) #eval checkM `(Type) #eval checkM `(Type 0) #eval checkM `(Type 1) -- TODO: we need support for parsing `?u` to roundtrip the terms containing universe metavariables. Just pretty printing them as `_` is bad for error and trace messages -- #eval checkM `(Type _) -- #eval checkM `(Type (_ + 2)) #eval checkM `(Nat) #eval checkM `(List Nat) #eval checkM `(id Nat) #eval checkM `(id (id (id Nat))) section set_option pp.explicit true #eval checkM `(List Nat) #eval checkM `(id Nat) end section set_option pp.universes true #eval checkM `(List Nat) #eval checkM `(id Nat) #eval checkM `(Sum Nat Nat) end #eval checkM `(id (id Nat)) (Std.RBMap.empty.insert 4 $ KVMap.empty.insert `pp.explicit true) -- specify the expected type of `a` in a way that is not erased by the delaborator def typeAs.{u} (α : Type u) (a : α) := () #eval checkM `(fun (a : Nat) => a) #eval checkM `(fun (a b : Nat) => a) #eval checkM `(fun (a : Nat) (b : Bool) => a) #eval checkM `(fun {a b : Nat} => a) -- implicit lambdas work as long as the expected type is preserved #eval checkM `(typeAs ({α : Type} → (a : α) → α) fun a => a) section set_option pp.explicit true #eval checkM `(fun {α : Type} [ToString α] (a : α) => toString a) end #eval checkM `((α : Type) → α) #eval checkM `((α β : Type) → α) -- group #eval checkM `((α β : Type) → Type) -- don't group #eval checkM `((α : Type) → (a : α) → α) #eval checkM `({α : Type} → α) #eval checkM `({α : Type} → [ToString α] → α) #eval checkM `(∀ x : Nat, x = x) #eval checkM `(∀ {x : Nat} [ToString Nat], x = x) set_option pp.binder_types false in #eval checkM `(∀ x : Nat, x = x) -- TODO: hide `ofNat` #eval checkM `(0) #eval checkM `(1) #eval checkM `(42) #eval checkM `("hi") set_option pp.structure_instance_type true in #eval checkM `({ type := Nat, val := 0 : PointedType }) #eval checkM `((1,2,3)) #eval checkM `((1,2).fst) #eval checkM `(1 < 2 || true) #eval checkM `(id (fun a => a) 0) #eval checkM `(typeAs Nat (do let x ← pure 1 discard <| pure 2 let y := 3 return x + y)) #eval checkM `(typeAs (Id Nat) (pure 1 >>= pure))
7756361b9efaeb549238997f36963b3b18f6b7ff
4950bf76e5ae40ba9f8491647d0b6f228ddce173
/src/data/real/ennreal.lean
8cd75fd1c55a675ade18a1fb664708fddc5ddbae
[ "Apache-2.0" ]
permissive
ntzwq/mathlib
ca50b21079b0a7c6781c34b62199a396dd00cee2
36eec1a98f22df82eaccd354a758ef8576af2a7f
refs/heads/master
1,675,193,391,478
1,607,822,996,000
1,607,822,996,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
55,178
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Johannes Hölzl, Yury Kudryashov -/ import data.real.nnreal import data.set.intervals /-! # Extended non-negative reals We define `ennreal := with_no ℝ≥0` to be the type of extended nonnegative real numbers, i.e., the interval `[0, +∞]`. This type is used as the codomain of a `measure_theory.measure`, and of the extended distance `edist` in a `emetric_space`. In this file we define some algebraic operations and a linear order on `ennreal` and prove basic properties of these operations, order, and conversions to/from `ℝ`, `ℝ≥0`, and `ℕ`. ## Main definitions * `ennreal`: the extended nonnegative real numbers `[0, ∞]`; defined as `with_top ℝ≥0`; it is equipped with the following structures: - coercion from `ℝ≥0` defined in the natural way; - the natural structure of a complete dense linear order: `↑p ≤ ↑q ↔ p ≤ q` and `∀ a, a ≤ ∞`; - `a + b` is defined so that `↑p + ↑q = ↑(p + q)` for `(p q : ℝ≥0)` and `a + ∞ = ∞ + a = ∞`; - `a * b` is defined so that `↑p * ↑q = ↑(p * q)` for `(p q : ℝ≥0)`, `0 * ∞ = ∞ * 0 = 0`, and `a * ∞ = ∞ * a = ∞` for `a ≠ 0`; - `a - b` is defined as the minimal `d` such that `a ≤ d + b`; this way we have `↑p - ↑q = ↑(p - q)`, `∞ - ↑p = ∞`, `↑p - ∞ = ∞ - ∞ = 0`; note that there is no negation, only subtraction; - `a⁻¹` is defined as `Inf {b | 1 ≤ a * b}`. This way we have `(↑p)⁻¹ = ↑(p⁻¹)` for `p : ℝ≥0`, `p ≠ 0`, `0⁻¹ = ∞`, and `∞⁻¹ = 0`. - `a / b` is defined as `a * b⁻¹`. The addition and multiplication defined this way together with `0 = ↑0` and `1 = ↑1` turn `ennreal` into a canonically ordered commutative semiring of characteristic zero. * Coercions to/from other types: - coercion `ℝ≥0 → ennreal` is defined as `has_coe`, so one can use `(p : ℝ≥0)` in a context that expects `a : ennreal`, and Lean will apply `coe` automatically; - `ennreal.to_nnreal` sends `↑p` to `p` and `∞` to `0`; - `ennreal.to_real := coe ∘ ennreal.to_nnreal` sends `↑p`, `p : ℝ≥0` to `(↑p : ℝ)` and `∞` to `0`; - `ennreal.of_real := coe ∘ nnreal.of_real` sends `x : ℝ` to `↑⟨max x 0, _⟩` - `ennreal.ne_top_equiv_nnreal` is an equivalence between `{a : ennreal // a ≠ 0}` and `ℝ≥0`. ## Implementation notes We define a `can_lift ennreal ℝ≥0` instance, so one of the ways to prove theorems about an `ennreal` number `a` is to consider the cases `a = ∞` and `a ≠ ∞`, and use the tactic `lift a to ℝ≥0 using ha` in the second case. This instance is even more useful if one already has `ha : a ≠ ∞` in the context, or if we have `(f : α → ennreal) (hf : ∀ x, f x ≠ ∞)`. ## Notations * `ℝ≥0`: type of nonnegative real numbers `[0, ∞)`; defined in `data.real.nnreal`; * `∞`: a localized notation in `ennreal` for `⊤ : ennreal`. -/ noncomputable theory open classical set open_locale classical big_operators nnreal variables {α : Type*} {β : Type*} /-- The extended nonnegative real numbers. This is usually denoted [0, ∞], and is relevant as the codomain of a measure. -/ @[derive canonically_ordered_comm_semiring, derive complete_linear_order, derive densely_ordered, derive nontrivial] def ennreal := with_top ℝ≥0 localized "notation `∞` := (⊤ : ennreal)" in ennreal namespace ennreal variables {a b c d : ennreal} {r p q : ℝ≥0} instance : inhabited ennreal := ⟨0⟩ instance : has_coe ℝ≥0 ennreal := ⟨ option.some ⟩ instance : can_lift ennreal ℝ≥0 := { coe := coe, cond := λ r, r ≠ ∞, prf := λ x hx, ⟨option.get $ option.ne_none_iff_is_some.1 hx, option.some_get _⟩ } @[simp] lemma none_eq_top : (none : ennreal) = ∞ := rfl @[simp] lemma some_eq_coe (a : ℝ≥0) : (some a : ennreal) = (↑a : ennreal) := rfl /-- `to_nnreal x` returns `x` if it is real, otherwise 0. -/ protected def to_nnreal : ennreal → ℝ≥0 | (some r) := r | none := 0 /-- `to_real x` returns `x` if it is real, `0` otherwise. -/ protected def to_real (a : ennreal) : real := coe (a.to_nnreal) /-- `of_real x` returns `x` if it is nonnegative, `0` otherwise. -/ protected def of_real (r : real) : ennreal := coe (nnreal.of_real r) @[simp, norm_cast] lemma to_nnreal_coe : (r : ennreal).to_nnreal = r := rfl @[simp] lemma coe_to_nnreal : ∀{a:ennreal}, a ≠ ∞ → ↑(a.to_nnreal) = a | (some r) h := rfl | none h := (h rfl).elim @[simp] lemma of_real_to_real {a : ennreal} (h : a ≠ ∞) : ennreal.of_real (a.to_real) = a := by simp [ennreal.to_real, ennreal.of_real, h] @[simp] lemma to_real_of_real {r : ℝ} (h : 0 ≤ r) : ennreal.to_real (ennreal.of_real r) = r := by simp [ennreal.to_real, ennreal.of_real, nnreal.coe_of_real _ h] lemma to_real_of_real' {r : ℝ} : ennreal.to_real (ennreal.of_real r) = max r 0 := rfl lemma coe_to_nnreal_le_self : ∀{a:ennreal}, ↑(a.to_nnreal) ≤ a | (some r) := by rw [some_eq_coe, to_nnreal_coe]; exact le_refl _ | none := le_top lemma coe_nnreal_eq (r : ℝ≥0) : (r : ennreal) = ennreal.of_real r := by { rw [ennreal.of_real, nnreal.of_real], cases r with r h, congr, dsimp, rw max_eq_left h } lemma of_real_eq_coe_nnreal {x : ℝ} (h : 0 ≤ x) : ennreal.of_real x = @coe ℝ≥0 ennreal _ (⟨x, h⟩ : ℝ≥0) := by { rw [coe_nnreal_eq], refl } @[simp] lemma of_real_coe_nnreal : ennreal.of_real p = p := (coe_nnreal_eq p).symm @[simp, norm_cast] lemma coe_zero : ↑(0 : ℝ≥0) = (0 : ennreal) := rfl @[simp, norm_cast] lemma coe_one : ↑(1 : ℝ≥0) = (1 : ennreal) := rfl @[simp] lemma to_real_nonneg {a : ennreal} : 0 ≤ a.to_real := by simp [ennreal.to_real] @[simp] lemma top_to_nnreal : ∞.to_nnreal = 0 := rfl @[simp] lemma top_to_real : ∞.to_real = 0 := rfl @[simp] lemma one_to_real : (1 : ennreal).to_real = 1 := rfl @[simp] lemma one_to_nnreal : (1 : ennreal).to_nnreal = 1 := rfl @[simp] lemma coe_to_real (r : ℝ≥0) : (r : ennreal).to_real = r := rfl @[simp] lemma zero_to_nnreal : (0 : ennreal).to_nnreal = 0 := rfl @[simp] lemma zero_to_real : (0 : ennreal).to_real = 0 := rfl @[simp] lemma of_real_zero : ennreal.of_real (0 : ℝ) = 0 := by simp [ennreal.of_real]; refl @[simp] lemma of_real_one : ennreal.of_real (1 : ℝ) = (1 : ennreal) := by simp [ennreal.of_real] lemma of_real_to_real_le {a : ennreal} : ennreal.of_real (a.to_real) ≤ a := if ha : a = ∞ then ha.symm ▸ le_top else le_of_eq (of_real_to_real ha) lemma forall_ennreal {p : ennreal → Prop} : (∀a, p a) ↔ (∀r:ℝ≥0, p r) ∧ p ∞ := ⟨assume h, ⟨assume r, h _, h _⟩, assume ⟨h₁, h₂⟩ a, match a with some r := h₁ _ | none := h₂ end⟩ lemma forall_ne_top {p : ennreal → Prop} : (∀ a ≠ ∞, p a) ↔ ∀ r : ℝ≥0, p r := option.ball_ne_none lemma exists_ne_top {p : ennreal → Prop} : (∃ a ≠ ∞, p a) ↔ ∃ r : ℝ≥0, p r := option.bex_ne_none lemma to_nnreal_eq_zero_iff (x : ennreal) : x.to_nnreal = 0 ↔ x = 0 ∨ x = ∞ := ⟨begin cases x, { simp [none_eq_top] }, { have A : some (0:ℝ≥0) = (0:ennreal) := rfl, simp [ennreal.to_nnreal, A] {contextual := tt} } end, by intro h; cases h; simp [h]⟩ lemma to_real_eq_zero_iff (x : ennreal) : x.to_real = 0 ↔ x = 0 ∨ x = ∞ := by simp [ennreal.to_real, to_nnreal_eq_zero_iff] @[simp] lemma coe_ne_top : (r : ennreal) ≠ ∞ := with_top.coe_ne_top @[simp] lemma top_ne_coe : ∞ ≠ (r : ennreal) := with_top.top_ne_coe @[simp] lemma of_real_ne_top {r : ℝ} : ennreal.of_real r ≠ ∞ := by simp [ennreal.of_real] @[simp] lemma of_real_lt_top {r : ℝ} : ennreal.of_real r < ∞ := lt_top_iff_ne_top.2 of_real_ne_top @[simp] lemma top_ne_of_real {r : ℝ} : ∞ ≠ ennreal.of_real r := by simp [ennreal.of_real] @[simp] lemma zero_ne_top : 0 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_zero : ∞ ≠ 0 := top_ne_coe @[simp] lemma one_ne_top : 1 ≠ ∞ := coe_ne_top @[simp] lemma top_ne_one : ∞ ≠ 1 := top_ne_coe @[simp, norm_cast] lemma coe_eq_coe : (↑r : ennreal) = ↑q ↔ r = q := with_top.coe_eq_coe @[simp, norm_cast] lemma coe_le_coe : (↑r : ennreal) ≤ ↑q ↔ r ≤ q := with_top.coe_le_coe @[simp, norm_cast] lemma coe_lt_coe : (↑r : ennreal) < ↑q ↔ r < q := with_top.coe_lt_coe lemma coe_mono : monotone (coe : ℝ≥0 → ennreal) := λ _ _, coe_le_coe.2 @[simp, norm_cast] lemma coe_eq_zero : (↑r : ennreal) = 0 ↔ r = 0 := coe_eq_coe @[simp, norm_cast] lemma zero_eq_coe : 0 = (↑r : ennreal) ↔ 0 = r := coe_eq_coe @[simp, norm_cast] lemma coe_eq_one : (↑r : ennreal) = 1 ↔ r = 1 := coe_eq_coe @[simp, norm_cast] lemma one_eq_coe : 1 = (↑r : ennreal) ↔ 1 = r := coe_eq_coe @[simp, norm_cast] lemma coe_nonneg : 0 ≤ (↑r : ennreal) ↔ 0 ≤ r := coe_le_coe @[simp, norm_cast] lemma coe_pos : 0 < (↑r : ennreal) ↔ 0 < r := coe_lt_coe @[simp, norm_cast] lemma coe_add : ↑(r + p) = (r + p : ennreal) := with_top.coe_add @[simp, norm_cast] lemma coe_mul : ↑(r * p) = (r * p : ennreal) := with_top.coe_mul @[simp, norm_cast] lemma coe_bit0 : (↑(bit0 r) : ennreal) = bit0 r := coe_add @[simp, norm_cast] lemma coe_bit1 : (↑(bit1 r) : ennreal) = bit1 r := by simp [bit1] lemma coe_two : ((2:ℝ≥0) : ennreal) = 2 := by norm_cast protected lemma zero_lt_one : 0 < (1 : ennreal) := canonically_ordered_semiring.zero_lt_one @[simp] lemma one_lt_two : (1 : ennreal) < 2 := coe_one ▸ coe_two ▸ by exact_mod_cast (@one_lt_two ℕ _ _) @[simp] lemma zero_lt_two : (0:ennreal) < 2 := lt_trans ennreal.zero_lt_one one_lt_two lemma two_ne_zero : (2:ennreal) ≠ 0 := (ne_of_lt zero_lt_two).symm lemma two_ne_top : (2:ennreal) ≠ ∞ := coe_two ▸ coe_ne_top /-- The set of `ennreal` numbers that are not equal to `∞` is equivalent to `ℝ≥0`. -/ def ne_top_equiv_nnreal : {a | a ≠ ∞} ≃ ℝ≥0 := { to_fun := λ x, ennreal.to_nnreal x, inv_fun := λ x, ⟨x, coe_ne_top⟩, left_inv := λ ⟨x, hx⟩, subtype.eq $ coe_to_nnreal hx, right_inv := λ x, to_nnreal_coe } lemma cinfi_ne_top [has_Inf α] (f : ennreal → α) : (⨅ x : {x // x ≠ ∞}, f x) = ⨅ x : ℝ≥0, f x := eq.symm $ infi_congr _ ne_top_equiv_nnreal.symm.surjective $ λ x, rfl lemma infi_ne_top [complete_lattice α] (f : ennreal → α) : (⨅ x ≠ ∞, f x) = ⨅ x : ℝ≥0, f x := by rw [infi_subtype', cinfi_ne_top] lemma csupr_ne_top [has_Sup α] (f : ennreal → α) : (⨆ x : {x // x ≠ ∞}, f x) = ⨆ x : ℝ≥0, f x := @cinfi_ne_top (order_dual α) _ _ lemma supr_ne_top [complete_lattice α] (f : ennreal → α) : (⨆ x ≠ ∞, f x) = ⨆ x : ℝ≥0, f x := @infi_ne_top (order_dual α) _ _ lemma infi_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} : (⨅ n, f n) = (⨅ n : ℝ≥0, f n) ⊓ f ∞ := le_antisymm (le_inf (le_infi $ assume i, infi_le _ _) (infi_le _ _)) (le_infi $ forall_ennreal.2 ⟨assume r, inf_le_left_of_le $ infi_le _ _, inf_le_right⟩) lemma supr_ennreal {α : Type*} [complete_lattice α] {f : ennreal → α} : (⨆ n, f n) = (⨆ n : ℝ≥0, f n) ⊔ f ∞ := @infi_ennreal (order_dual α) _ _ @[simp] lemma add_top : a + ∞ = ∞ := with_top.add_top @[simp] lemma top_add : ∞ + a = ∞ := with_top.top_add /-- Coercion `ℝ≥0 → ennreal` as a `ring_hom`. -/ def of_nnreal_hom : ℝ≥0 →+* ennreal := ⟨coe, coe_one, λ _ _, coe_mul, coe_zero, λ _ _, coe_add⟩ @[simp] lemma coe_of_nnreal_hom : ⇑of_nnreal_hom = coe := rfl @[simp, norm_cast] lemma coe_indicator {α} (s : set α) (f : α → ℝ≥0) (a : α) : ((s.indicator f a : ℝ≥0) : ennreal) = s.indicator (λ x, f x) a := (of_nnreal_hom : ℝ≥0 →+ ennreal).map_indicator _ _ _ @[simp, norm_cast] lemma coe_pow (n : ℕ) : (↑(r^n) : ennreal) = r^n := of_nnreal_hom.map_pow r n lemma add_eq_top : a + b = ∞ ↔ a = ∞ ∨ b = ∞ := with_top.add_eq_top lemma add_lt_top : a + b < ∞ ↔ a < ∞ ∧ b < ∞ := with_top.add_lt_top lemma to_nnreal_add {r₁ r₂ : ennreal} (h₁ : r₁ < ∞) (h₂ : r₂ < ∞) : (r₁ + r₂).to_nnreal = r₁.to_nnreal + r₂.to_nnreal := begin rw [← coe_eq_coe, coe_add, coe_to_nnreal, coe_to_nnreal, coe_to_nnreal]; apply @ne_top_of_lt ennreal _ _ ∞, exact h₂, exact h₁, exact add_lt_top.2 ⟨h₁, h₂⟩ end /- rw has trouble with the generic lt_top_iff_ne_top and bot_lt_iff_ne_bot (contrary to erw). This is solved with the next lemmas -/ protected lemma lt_top_iff_ne_top : a < ∞ ↔ a ≠ ∞ := lt_top_iff_ne_top protected lemma bot_lt_iff_ne_bot : 0 < a ↔ a ≠ 0 := bot_lt_iff_ne_bot lemma not_lt_top {x : ennreal} : ¬ x < ∞ ↔ x = ∞ := by rw [lt_top_iff_ne_top, not_not] lemma add_ne_top : a + b ≠ ∞ ↔ a ≠ ∞ ∧ b ≠ ∞ := by simpa only [lt_top_iff_ne_top] using add_lt_top lemma mul_top : a * ∞ = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.mul_top h } end lemma top_mul : ∞ * a = (if a = 0 then 0 else ∞) := begin split_ifs, { simp [h] }, { exact with_top.top_mul h } end @[simp] lemma top_mul_top : ∞ * ∞ = ∞ := with_top.top_mul_top lemma top_pow {n:ℕ} (h : 0 < n) : ∞^n = ∞ := nat.le_induction (pow_one _) (λ m hm hm', by rw [pow_succ, hm', top_mul_top]) _ (nat.succ_le_of_lt h) lemma mul_eq_top : a * b = ∞ ↔ (a ≠ 0 ∧ b = ∞) ∨ (a = ∞ ∧ b ≠ 0) := with_top.mul_eq_top_iff lemma mul_ne_top : a ≠ ∞ → b ≠ ∞ → a * b ≠ ∞ := by simp [(≠), mul_eq_top] {contextual := tt} lemma mul_lt_top : a < ∞ → b < ∞ → a * b < ∞ := by simpa only [ennreal.lt_top_iff_ne_top] using mul_ne_top lemma ne_top_of_mul_ne_top_left (h : a * b ≠ ∞) (hb : b ≠ 0) : a ≠ ∞ := by { simp [mul_eq_top, hb, not_or_distrib] at h ⊢, exact h.2 } lemma ne_top_of_mul_ne_top_right (h : a * b ≠ ∞) (ha : a ≠ 0) : b ≠ ∞ := ne_top_of_mul_ne_top_left (by rwa [mul_comm]) ha lemma lt_top_of_mul_lt_top_left (h : a * b < ∞) (hb : b ≠ 0) : a < ∞ := by { rw [ennreal.lt_top_iff_ne_top] at h ⊢, exact ne_top_of_mul_ne_top_left h hb } lemma lt_top_of_mul_lt_top_right (h : a * b < ∞) (ha : a ≠ 0) : b < ∞ := lt_top_of_mul_lt_top_left (by rwa [mul_comm]) ha lemma mul_lt_top_iff {a b : ennreal} : a * b < ∞ ↔ (a < ∞ ∧ b < ∞) ∨ a = 0 ∨ b = 0 := begin split, { intro h, rw [← or_assoc, or_iff_not_imp_right, or_iff_not_imp_right], intros hb ha, exact ⟨lt_top_of_mul_lt_top_left h hb, lt_top_of_mul_lt_top_right h ha⟩ }, { rintro (⟨ha, hb⟩|rfl|rfl); [exact mul_lt_top ha hb, simp, simp] } end @[simp] lemma mul_pos : 0 < a * b ↔ 0 < a ∧ 0 < b := by simp only [zero_lt_iff_ne_zero, ne.def, mul_eq_zero, not_or_distrib] lemma pow_eq_top : ∀ n:ℕ, a^n=∞ → a=∞ | 0 := by simp | (n+1) := λ o, (mul_eq_top.1 o).elim (λ h, pow_eq_top n h.2) and.left lemma pow_ne_top (h : a ≠ ∞) {n:ℕ} : a^n ≠ ∞ := mt (pow_eq_top n) h lemma pow_lt_top : a < ∞ → ∀ n:ℕ, a^n < ∞ := by simpa only [lt_top_iff_ne_top] using pow_ne_top @[simp, norm_cast] lemma coe_finset_sum {s : finset α} {f : α → ℝ≥0} : ↑(∑ a in s, f a) = (∑ a in s, f a : ennreal) := of_nnreal_hom.map_sum f s @[simp, norm_cast] lemma coe_finset_prod {s : finset α} {f : α → ℝ≥0} : ↑(∏ a in s, f a) = ((∏ a in s, f a) : ennreal) := of_nnreal_hom.map_prod f s section order @[simp] lemma bot_eq_zero : (⊥ : ennreal) = 0 := rfl @[simp] lemma coe_lt_top : coe r < ∞ := with_top.coe_lt_top r @[simp] lemma not_top_le_coe : ¬ ∞ ≤ ↑r := with_top.not_top_le_coe r lemma zero_lt_coe_iff : 0 < (↑p : ennreal) ↔ 0 < p := coe_lt_coe @[simp, norm_cast] lemma one_le_coe_iff : (1:ennreal) ≤ ↑r ↔ 1 ≤ r := coe_le_coe @[simp, norm_cast] lemma coe_le_one_iff : ↑r ≤ (1:ennreal) ↔ r ≤ 1 := coe_le_coe @[simp, norm_cast] lemma coe_lt_one_iff : (↑p : ennreal) < 1 ↔ p < 1 := coe_lt_coe @[simp, norm_cast] lemma one_lt_coe_iff : 1 < (↑p : ennreal) ↔ 1 < p := coe_lt_coe @[simp, norm_cast] lemma coe_nat (n : nat) : ((n : ℝ≥0) : ennreal) = n := with_top.coe_nat n @[simp] lemma nat_ne_top (n : nat) : (n : ennreal) ≠ ∞ := with_top.nat_ne_top n @[simp] lemma top_ne_nat (n : nat) : ∞ ≠ n := with_top.top_ne_nat n @[simp] lemma one_lt_top : 1 < ∞ := coe_lt_top lemma le_coe_iff : a ≤ ↑r ↔ (∃p:ℝ≥0, a = p ∧ p ≤ r) := with_top.le_coe_iff lemma coe_le_iff : ↑r ≤ a ↔ (∀p:ℝ≥0, a = p → r ≤ p) := with_top.coe_le_iff lemma lt_iff_exists_coe : a < b ↔ (∃p:ℝ≥0, a = p ∧ ↑p < b) := with_top.lt_iff_exists_coe @[simp, norm_cast] lemma coe_finset_sup {s : finset α} {f : α → ℝ≥0} : ↑(s.sup f) = s.sup (λ x, (f x : ennreal)) := finset.comp_sup_eq_sup_comp_of_is_total _ coe_mono rfl lemma pow_le_pow {n m : ℕ} (ha : 1 ≤ a) (h : n ≤ m) : a ^ n ≤ a ^ m := begin cases a, { cases m, { rw eq_bot_iff.mpr h, exact le_refl _ }, { rw [none_eq_top, top_pow (nat.succ_pos m)], exact le_top } }, { rw [some_eq_coe, ← coe_pow, ← coe_pow, coe_le_coe], exact pow_le_pow (by simpa using ha) h } end @[simp] lemma max_eq_zero_iff : max a b = 0 ↔ a = 0 ∧ b = 0 := by simp only [le_zero_iff_eq.symm, max_le_iff] @[simp] lemma max_zero_left : max 0 a = a := max_eq_right (zero_le a) @[simp] lemma max_zero_right : max a 0 = a := max_eq_left (zero_le a) -- TODO: why this is not a `rfl`? There is some hidden diamond here. @[simp] lemma sup_eq_max : a ⊔ b = max a b := eq_of_forall_ge_iff $ λ c, sup_le_iff.trans max_le_iff.symm protected lemma pow_pos : 0 < a → ∀ n : ℕ, 0 < a^n := canonically_ordered_semiring.pow_pos protected lemma pow_ne_zero : a ≠ 0 → ∀ n : ℕ, a^n ≠ 0 := by simpa only [zero_lt_iff_ne_zero] using ennreal.pow_pos @[simp] lemma not_lt_zero : ¬ a < 0 := by simp lemma add_lt_add_iff_left : a < ∞ → (a + c < a + b ↔ c < b) := with_top.add_lt_add_iff_left lemma add_lt_add_iff_right : a < ∞ → (c + a < b + a ↔ c < b) := with_top.add_lt_add_iff_right lemma lt_add_right (ha : a < ∞) (hb : 0 < b) : a < a + b := by rwa [← add_lt_add_iff_left ha, add_zero] at hb lemma le_of_forall_epsilon_le : ∀{a b : ennreal}, (∀ε:ℝ≥0, 0 < ε → b < ∞ → a ≤ b + ε) → a ≤ b | a none h := le_top | none (some a) h := have ∞ ≤ ↑a + ↑(1:ℝ≥0), from h 1 zero_lt_one coe_lt_top, by rw [← coe_add] at this; exact (not_top_le_coe this).elim | (some a) (some b) h := by simp only [none_eq_top, some_eq_coe, coe_add.symm, coe_le_coe, coe_lt_top, true_implies_iff] at *; exact nnreal.le_of_forall_epsilon_le h lemma lt_iff_exists_rat_btwn : a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ (nnreal.of_real q:ennreal) < b) := ⟨λ h, begin rcases lt_iff_exists_coe.1 h with ⟨p, rfl, _⟩, rcases exists_between h with ⟨c, pc, cb⟩, rcases lt_iff_exists_coe.1 cb with ⟨r, rfl, _⟩, rcases (nnreal.lt_iff_exists_rat_btwn _ _).1 (coe_lt_coe.1 pc) with ⟨q, hq0, pq, qr⟩, exact ⟨q, hq0, coe_lt_coe.2 pq, lt_trans (coe_lt_coe.2 qr) cb⟩ end, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ lemma lt_iff_exists_real_btwn : a < b ↔ (∃r:ℝ, 0 ≤ r ∧ a < ennreal.of_real r ∧ (ennreal.of_real r:ennreal) < b) := ⟨λ h, let ⟨q, q0, aq, qb⟩ := ennreal.lt_iff_exists_rat_btwn.1 h in ⟨q, rat.cast_nonneg.2 q0, aq, qb⟩, λ ⟨q, q0, qa, qb⟩, lt_trans qa qb⟩ lemma lt_iff_exists_nnreal_btwn : a < b ↔ (∃r:ℝ≥0, a < r ∧ (r : ennreal) < b) := with_top.lt_iff_exists_coe_btwn lemma lt_iff_exists_add_pos_lt : a < b ↔ (∃ r : ℝ≥0, 0 < r ∧ a + r < b) := begin refine ⟨λ hab, _, λ ⟨r, rpos, hr⟩, lt_of_le_of_lt (le_add_right (le_refl _)) hr⟩, cases a, { simpa using hab }, rcases lt_iff_exists_real_btwn.1 hab with ⟨c, c_nonneg, ac, cb⟩, let d : ℝ≥0 := ⟨c, c_nonneg⟩, have ad : a < d, { rw of_real_eq_coe_nnreal c_nonneg at ac, exact coe_lt_coe.1 ac }, refine ⟨d-a, nnreal.sub_pos.2 ad, _⟩, rw [some_eq_coe, ← coe_add], convert cb, have : nnreal.of_real c = d, by { rw [← nnreal.coe_eq, nnreal.coe_of_real _ c_nonneg], refl }, rw [add_comm, this], exact nnreal.sub_add_cancel_of_le (le_of_lt ad) end lemma coe_nat_lt_coe {n : ℕ} : (n : ennreal) < r ↔ ↑n < r := ennreal.coe_nat n ▸ coe_lt_coe lemma coe_lt_coe_nat {n : ℕ} : (r : ennreal) < n ↔ r < n := ennreal.coe_nat n ▸ coe_lt_coe @[norm_cast] lemma coe_nat_lt_coe_nat {m n : ℕ} : (m : ennreal) < n ↔ m < n := ennreal.coe_nat n ▸ coe_nat_lt_coe.trans nat.cast_lt lemma coe_nat_ne_top {n : ℕ} : (n : ennreal) ≠ ∞ := ennreal.coe_nat n ▸ coe_ne_top lemma coe_nat_mono : strict_mono (coe : ℕ → ennreal) := λ _ _, coe_nat_lt_coe_nat.2 @[norm_cast] lemma coe_nat_le_coe_nat {m n : ℕ} : (m : ennreal) ≤ n ↔ m ≤ n := coe_nat_mono.le_iff_le instance : char_zero ennreal := ⟨coe_nat_mono.injective⟩ protected lemma exists_nat_gt {r : ennreal} (h : r ≠ ∞) : ∃n:ℕ, r < n := begin lift r to ℝ≥0 using h, rcases exists_nat_gt r with ⟨n, hn⟩, exact ⟨n, coe_lt_coe_nat.2 hn⟩, end lemma add_lt_add (ac : a < c) (bd : b < d) : a + b < c + d := begin rcases exists_between ac with ⟨a', aa', a'c⟩, rcases lt_iff_exists_coe.1 aa' with ⟨aR, rfl, _⟩, rcases lt_iff_exists_coe.1 a'c with ⟨a'R, rfl, _⟩, rcases exists_between bd with ⟨b', bb', b'd⟩, rcases lt_iff_exists_coe.1 bb' with ⟨bR, rfl, _⟩, rcases lt_iff_exists_coe.1 b'd with ⟨b'R, rfl, _⟩, have I : ↑aR + ↑bR < ↑a'R + ↑b'R := begin rw [← coe_add, ← coe_add, coe_lt_coe], apply add_lt_add (coe_lt_coe.1 aa') (coe_lt_coe.1 bb') end, have J : ↑a'R + ↑b'R ≤ c + d := add_le_add (le_of_lt a'c) (le_of_lt b'd), apply lt_of_lt_of_le I J end @[norm_cast] lemma coe_min : ((min r p:ℝ≥0):ennreal) = min r p := coe_mono.map_min @[norm_cast] lemma coe_max : ((max r p:ℝ≥0):ennreal) = max r p := coe_mono.map_max end order section complete_lattice lemma coe_Sup {s : set ℝ≥0} : bdd_above s → (↑(Sup s) : ennreal) = (⨆a∈s, ↑a) := with_top.coe_Sup lemma coe_Inf {s : set ℝ≥0} : s.nonempty → (↑(Inf s) : ennreal) = (⨅a∈s, ↑a) := with_top.coe_Inf @[simp] lemma top_mem_upper_bounds {s : set ennreal} : ∞ ∈ upper_bounds s := assume x hx, le_top lemma coe_mem_upper_bounds {s : set ℝ≥0} : ↑r ∈ upper_bounds ((coe : ℝ≥0 → ennreal) '' s) ↔ r ∈ upper_bounds s := by simp [upper_bounds, ball_image_iff, -mem_image, *] {contextual := tt} end complete_lattice section mul lemma mul_le_mul : a ≤ b → c ≤ d → a * c ≤ b * d := canonically_ordered_semiring.mul_le_mul lemma mul_left_mono : monotone ((*) a) := λ b c, mul_le_mul (le_refl a) lemma mul_right_mono : monotone (λ x, x * a) := λ b c h, mul_le_mul h (le_refl a) lemma max_mul : max a b * c = max (a * c) (b * c) := mul_right_mono.map_max lemma mul_max : a * max b c = max (a * b) (a * c) := mul_left_mono.map_max lemma mul_eq_mul_left : a ≠ 0 → a ≠ ∞ → (a * b = a * c ↔ b = c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm, nnreal.mul_eq_mul_left] {contextual := tt}, end lemma mul_eq_mul_right : c ≠ 0 → c ≠ ∞ → (a * c = b * c ↔ a = b) := mul_comm c a ▸ mul_comm c b ▸ mul_eq_mul_left lemma mul_le_mul_left : a ≠ 0 → a ≠ ∞ → (a * b ≤ a * c ↔ b ≤ c) := begin cases a; cases b; cases c; simp [none_eq_top, some_eq_coe, mul_top, top_mul, -coe_mul, coe_mul.symm] {contextual := tt}, assume h, exact mul_le_mul_left (zero_lt_iff_ne_zero.2 h) end lemma mul_le_mul_right : c ≠ 0 → c ≠ ∞ → (a * c ≤ b * c ↔ a ≤ b) := mul_comm c a ▸ mul_comm c b ▸ mul_le_mul_left lemma mul_lt_mul_left : a ≠ 0 → a ≠ ∞ → (a * b < a * c ↔ b < c) := λ h0 ht, by simp only [mul_le_mul_left h0 ht, lt_iff_le_not_le] lemma mul_lt_mul_right : c ≠ 0 → c ≠ ∞ → (a * c < b * c ↔ a < b) := mul_comm c a ▸ mul_comm c b ▸ mul_lt_mul_left end mul section sub instance : has_sub ennreal := ⟨λa b, Inf {d | a ≤ d + b}⟩ @[norm_cast] lemma coe_sub : ↑(p - r) = (↑p:ennreal) - r := le_antisymm (le_Inf $ assume b (hb : ↑p ≤ b + r), coe_le_iff.2 $ by rintros d rfl; rwa [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add] at hb) (Inf_le $ show (↑p : ennreal) ≤ ↑(p - r) + ↑r, by rw [← coe_add, coe_le_coe, ← nnreal.sub_le_iff_le_add]) @[simp] lemma top_sub_coe : ∞ - ↑r = ∞ := top_unique $ le_Inf $ by simp [add_eq_top] @[simp] lemma sub_eq_zero_of_le (h : a ≤ b) : a - b = 0 := le_antisymm (Inf_le $ le_add_left h) (zero_le _) @[simp] lemma sub_self : a - a = 0 := sub_eq_zero_of_le $ le_refl _ @[simp] lemma zero_sub : 0 - a = 0 := le_antisymm (Inf_le $ zero_le $ 0 + a) (zero_le _) @[simp] lemma sub_infty : a - ∞ = 0 := le_antisymm (Inf_le $ by simp) (zero_le _) lemma sub_le_sub (h₁ : a ≤ b) (h₂ : d ≤ c) : a - c ≤ b - d := Inf_le_Inf $ assume e (h : b ≤ e + d), calc a ≤ b : h₁ ... ≤ e + d : h ... ≤ e + c : add_le_add (le_refl _) h₂ @[simp] lemma add_sub_self : ∀{a b : ennreal}, b < ∞ → (a + b) - b = a | a none := by simp [none_eq_top] | none (some b) := by simp [none_eq_top, some_eq_coe] | (some a) (some b) := by simp [some_eq_coe]; rw [← coe_add, ← coe_sub, coe_eq_coe, nnreal.add_sub_cancel] @[simp] lemma add_sub_self' (h : a < ∞) : (a + b) - a = b := by rw [add_comm, add_sub_self h] lemma add_right_inj (h : a < ∞) : a + b = a + c ↔ b = c := ⟨λ e, by simpa [h] using congr_arg (λ x, x - a) e, congr_arg _⟩ lemma add_left_inj (h : a < ∞) : b + a = c + a ↔ b = c := by rw [add_comm, add_comm c, add_right_inj h] @[simp] lemma sub_add_cancel_of_le : ∀{a b : ennreal}, b ≤ a → (a - b) + b = a := begin simp [forall_ennreal, le_coe_iff, -add_comm] {contextual := tt}, rintros r p x rfl h, rw [← coe_sub, ← coe_add, nnreal.sub_add_cancel_of_le h] end @[simp] lemma add_sub_cancel_of_le (h : b ≤ a) : b + (a - b) = a := by rwa [add_comm, sub_add_cancel_of_le] lemma sub_add_self_eq_max : (a - b) + b = max a b := match le_total a b with | or.inl h := by simp [h, max_eq_right] | or.inr h := by simp [h, max_eq_left] end lemma le_sub_add_self : a ≤ (a - b) + b := by { rw sub_add_self_eq_max, exact le_max_left a b } @[simp] protected lemma sub_le_iff_le_add : a - b ≤ c ↔ a ≤ c + b := iff.intro (assume h : a - b ≤ c, calc a ≤ (a - b) + b : le_sub_add_self ... ≤ c + b : add_le_add_right h _) (assume h : a ≤ c + b, calc a - b ≤ (c + b) - b : sub_le_sub h (le_refl _) ... ≤ c : Inf_le (le_refl (c + b))) protected lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c := add_comm c b ▸ ennreal.sub_le_iff_le_add lemma sub_eq_of_add_eq : b ≠ ∞ → a + b = c → c - b = a := λ hb hc, hc ▸ add_sub_self (lt_top_iff_ne_top.2 hb) protected lemma sub_le_of_sub_le (h : a - b ≤ c) : a - c ≤ b := ennreal.sub_le_iff_le_add.2 $ by { rw add_comm, exact ennreal.sub_le_iff_le_add.1 h } protected lemma sub_lt_sub_self : a ≠ ∞ → a ≠ 0 → 0 < b → a - b < a := match a, b with | none, _ := by { have := none_eq_top, assume h, contradiction } | (some a), none := by {intros, simp only [none_eq_top, sub_infty, zero_lt_iff_ne_zero], assumption} | (some a), (some b) := begin simp only [some_eq_coe, coe_sub.symm, coe_pos, coe_eq_zero, coe_lt_coe, ne.def], assume h₁ h₂, apply nnreal.sub_lt_self, exact zero_lt_iff_ne_zero.2 h₂ end end @[simp] lemma sub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b := by simpa [-ennreal.sub_le_iff_le_add] using @ennreal.sub_le_iff_le_add a b 0 @[simp] lemma zero_lt_sub_iff_lt : 0 < a - b ↔ b < a := by simpa [ennreal.bot_lt_iff_ne_bot, -sub_eq_zero_iff_le] using not_iff_not.2 (@sub_eq_zero_iff_le a b) lemma lt_sub_iff_add_lt : a < b - c ↔ a + c < b := begin cases a, { simp }, cases c, { simp }, cases b, { simp only [true_iff, coe_lt_top, some_eq_coe, top_sub_coe, none_eq_top, ← coe_add] }, simp only [some_eq_coe], rw [← coe_add, ← coe_sub, coe_lt_coe, coe_lt_coe, nnreal.lt_sub_iff_add_lt], end lemma sub_le_self (a b : ennreal) : a - b ≤ a := ennreal.sub_le_iff_le_add.2 $ le_add_right (le_refl a) @[simp] lemma sub_zero : a - 0 = a := eq.trans (add_zero (a - 0)).symm $ by simp /-- A version of triangle inequality for difference as a "distance". -/ lemma sub_le_sub_add_sub : a - c ≤ a - b + (b - c) := ennreal.sub_le_iff_le_add.2 $ calc a ≤ a - b + b : le_sub_add_self ... ≤ a - b + ((b - c) + c) : add_le_add_left le_sub_add_self _ ... = a - b + (b - c) + c : (add_assoc _ _ _).symm lemma sub_sub_cancel (h : a < ∞) (h2 : b ≤ a) : a - (a - b) = b := by rw [← add_left_inj (lt_of_le_of_lt (sub_le_self _ _) h), sub_add_cancel_of_le (sub_le_self _ _), add_sub_cancel_of_le h2] lemma sub_right_inj {a b c : ennreal} (ha : a < ∞) (hb : b ≤ a) (hc : c ≤ a) : a - b = a - c ↔ b = c := iff.intro begin assume h, have : a - (a - b) = a - (a - c), rw h, rw [sub_sub_cancel ha hb, sub_sub_cancel ha hc] at this, exact this end (λ h, by rw h) lemma sub_mul (h : 0 < b → b < a → c ≠ ∞) : (a - b) * c = a * c - b * c := begin cases le_or_lt a b with hab hab, { simp [hab, mul_right_mono hab] }, symmetry, cases eq_or_lt_of_le (zero_le b) with hb hb, { subst b, simp }, apply sub_eq_of_add_eq, { exact mul_ne_top (ne_top_of_lt hab) (h hb hab) }, rw [← add_mul, sub_add_cancel_of_le (le_of_lt hab)] end lemma mul_sub (h : 0 < c → c < b → a ≠ ∞) : a * (b - c) = a * b - a * c := by { simp only [mul_comm a], exact sub_mul h } lemma sub_mul_ge : a * c - b * c ≤ (a - b) * c := begin -- with `0 < b → b < a → c ≠ ∞` Lean names the first variable `a` by_cases h : ∀ (hb : 0 < b), b < a → c ≠ ∞, { rw [sub_mul h], exact le_refl _ }, { push_neg at h, rcases h with ⟨hb, hba, hc⟩, subst c, simp only [mul_top, if_neg (ne_of_gt hb), if_neg (ne_of_gt $ lt_trans hb hba), sub_self, zero_le] } end end sub section sum open finset /-- A sum of finite numbers is still finite -/ lemma sum_lt_top {s : finset α} {f : α → ennreal} : (∀a∈s, f a < ∞) → ∑ a in s, f a < ∞ := with_top.sum_lt_top /-- A sum of finite numbers is still finite -/ lemma sum_lt_top_iff {s : finset α} {f : α → ennreal} : ∑ a in s, f a < ∞ ↔ (∀a∈s, f a < ∞) := with_top.sum_lt_top_iff /-- A sum of numbers is infinite iff one of them is infinite -/ lemma sum_eq_top_iff {s : finset α} {f : α → ennreal} : (∑ x in s, f x) = ∞ ↔ (∃a∈s, f a = ∞) := with_top.sum_eq_top_iff /-- seeing `ennreal` as `nnreal` does not change their sum, unless one of the `ennreal` is infinity -/ lemma to_nnreal_sum {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ∞) : ennreal.to_nnreal (∑ a in s, f a) = ∑ a in s, ennreal.to_nnreal (f a) := begin rw [← coe_eq_coe, coe_to_nnreal, coe_finset_sum, sum_congr], { refl }, { intros x hx, exact (coe_to_nnreal (hf x hx).ne).symm }, { exact (sum_lt_top hf).ne } end /-- seeing `ennreal` as `real` does not change their sum, unless one of the `ennreal` is infinity -/ lemma to_real_sum {s : finset α} {f : α → ennreal} (hf : ∀a∈s, f a < ∞) : ennreal.to_real (∑ a in s, f a) = ∑ a in s, ennreal.to_real (f a) := by { rw [ennreal.to_real, to_nnreal_sum hf, nnreal.coe_sum], refl } end sum section interval variables {x y z : ennreal} {ε ε₁ ε₂ : ennreal} {s : set ennreal} protected lemma Ico_eq_Iio : (Ico 0 y) = (Iio y) := ext $ assume a, iff.intro (assume ⟨_, hx⟩, hx) (assume hx, ⟨zero_le _, hx⟩) lemma mem_Iio_self_add : x ≠ ∞ → 0 < ε → x ∈ Iio (x + ε) := assume xt ε0, lt_add_right (by rwa lt_top_iff_ne_top) ε0 lemma not_mem_Ioo_self_sub : x = 0 → x ∉ Ioo (x - ε) y := assume x0, by simp [x0] lemma mem_Ioo_self_sub_add : x ≠ ∞ → x ≠ 0 → 0 < ε₁ → 0 < ε₂ → x ∈ Ioo (x - ε₁) (x + ε₂) := assume xt x0 ε0 ε0', ⟨ennreal.sub_lt_sub_self xt x0 ε0, lt_add_right (by rwa [lt_top_iff_ne_top]) ε0'⟩ end interval section bit @[simp] lemma bit0_inj : bit0 a = bit0 b ↔ a = b := ⟨λh, begin rcases (lt_trichotomy a b) with h₁| h₂| h₃, { exact (absurd h (ne_of_lt (add_lt_add h₁ h₁))) }, { exact h₂ }, { exact (absurd h.symm (ne_of_lt (add_lt_add h₃ h₃))) } end, λh, congr_arg _ h⟩ @[simp] lemma bit0_eq_zero_iff : bit0 a = 0 ↔ a = 0 := by simpa only [bit0_zero] using @bit0_inj a 0 @[simp] lemma bit0_eq_top_iff : bit0 a = ∞ ↔ a = ∞ := by rw [bit0, add_eq_top, or_self] @[simp] lemma bit1_inj : bit1 a = bit1 b ↔ a = b := ⟨λh, begin unfold bit1 at h, rwa [add_left_inj, bit0_inj] at h, simp [lt_top_iff_ne_top] end, λh, congr_arg _ h⟩ @[simp] lemma bit1_ne_zero : bit1 a ≠ 0 := by unfold bit1; simp @[simp] lemma bit1_eq_one_iff : bit1 a = 1 ↔ a = 0 := by simpa only [bit1_zero] using @bit1_inj a 0 @[simp] lemma bit1_eq_top_iff : bit1 a = ∞ ↔ a = ∞ := by unfold bit1; rw add_eq_top; simp end bit section inv instance : has_inv ennreal := ⟨λa, Inf {b | 1 ≤ a * b}⟩ instance : has_div ennreal := ⟨λa b, a * b⁻¹⟩ lemma div_def : a / b = a * b⁻¹ := rfl lemma mul_div_assoc : (a * b) / c = a * (b / c) := mul_assoc _ _ _ @[simp] lemma inv_zero : (0 : ennreal)⁻¹ = ∞ := show Inf {b : ennreal | 1 ≤ 0 * b} = ∞, by simp; refl @[simp] lemma inv_top : ∞⁻¹ = 0 := bot_unique $ le_of_forall_le_of_dense $ λ a (h : a > 0), Inf_le $ by simp [*, ne_of_gt h, top_mul] @[simp, norm_cast] lemma coe_inv (hr : r ≠ 0) : (↑r⁻¹ : ennreal) = (↑r)⁻¹ := le_antisymm (le_Inf $ assume b (hb : 1 ≤ ↑r * b), coe_le_iff.2 $ by rintros b rfl; rwa [← coe_mul, ← coe_one, coe_le_coe, ← nnreal.inv_le hr] at hb) (Inf_le $ by simp; rw [← coe_mul, nnreal.mul_inv_cancel hr]; exact le_refl 1) lemma coe_inv_le : (↑r⁻¹ : ennreal) ≤ (↑r)⁻¹ := if hr : r = 0 then by simp only [hr, nnreal.inv_zero, inv_zero, coe_zero, zero_le] else by simp only [coe_inv hr, le_refl] @[norm_cast] lemma coe_inv_two : ((2⁻¹:ℝ≥0):ennreal) = 2⁻¹ := by rw [coe_inv (ne_of_gt _root_.zero_lt_two), coe_two] @[simp, norm_cast] lemma coe_div (hr : r ≠ 0) : (↑(p / r) : ennreal) = p / r := show ↑(p * r⁻¹) = ↑p * (↑r)⁻¹, by rw [coe_mul, coe_inv hr] @[simp] lemma inv_one : (1:ennreal)⁻¹ = 1 := by simpa only [coe_inv one_ne_zero, coe_one] using coe_eq_coe.2 nnreal.inv_one @[simp] lemma div_one {a : ennreal} : a / 1 = a := by simp [ennreal.div_def] protected lemma inv_pow {n : ℕ} : (a^n)⁻¹ = (a⁻¹)^n := begin by_cases a = 0; cases a; cases n; simp [*, none_eq_top, some_eq_coe, zero_pow, top_pow, nat.zero_lt_succ] at *, rw [← coe_inv h, ← coe_pow, ← coe_inv, nnreal.inv_pow, coe_pow], rw [← ne.def] at h, rw [← zero_lt_iff_ne_zero] at *, apply pow_pos h end @[simp] lemma inv_inv : (a⁻¹)⁻¹ = a := by by_cases a = 0; cases a; simp [*, none_eq_top, some_eq_coe, -coe_inv, (coe_inv _).symm] at * lemma inv_involutive : function.involutive (λ a:ennreal, a⁻¹) := λ a, ennreal.inv_inv lemma inv_bijective : function.bijective (λ a:ennreal, a⁻¹) := ennreal.inv_involutive.bijective @[simp] lemma inv_eq_inv : a⁻¹ = b⁻¹ ↔ a = b := inv_bijective.1.eq_iff @[simp] lemma inv_eq_top : a⁻¹ = ∞ ↔ a = 0 := inv_zero ▸ inv_eq_inv lemma inv_ne_top : a⁻¹ ≠ ∞ ↔ a ≠ 0 := by simp @[simp] lemma inv_lt_top {x : ennreal} : x⁻¹ < ∞ ↔ 0 < x := by { simp only [lt_top_iff_ne_top, inv_ne_top, zero_lt_iff_ne_zero] } lemma div_lt_top {x y : ennreal} (h1 : x < ∞) (h2 : 0 < y) : x / y < ∞ := mul_lt_top h1 (inv_lt_top.mpr h2) @[simp] lemma inv_eq_zero : a⁻¹ = 0 ↔ a = ∞ := inv_top ▸ inv_eq_inv lemma inv_ne_zero : a⁻¹ ≠ 0 ↔ a ≠ ∞ := by simp @[simp] lemma inv_pos : 0 < a⁻¹ ↔ a ≠ ∞ := zero_lt_iff_ne_zero.trans inv_ne_zero @[simp] lemma inv_lt_inv : a⁻¹ < b⁻¹ ↔ b < a := begin cases a; cases b; simp only [some_eq_coe, none_eq_top, inv_top], { simp only [lt_irrefl] }, { exact inv_pos.trans lt_top_iff_ne_top.symm }, { simp only [not_lt_zero, not_top_lt] }, { cases eq_or_lt_of_le (zero_le a) with ha ha; cases eq_or_lt_of_le (zero_le b) with hb hb, { subst a, subst b, simp }, { subst a, simp }, { subst b, simp [zero_lt_iff_ne_zero, lt_top_iff_ne_top, inv_ne_top] }, { rw [← coe_inv (ne_of_gt ha), ← coe_inv (ne_of_gt hb), coe_lt_coe, coe_lt_coe], simp only [nnreal.coe_lt_coe.symm] at *, exact inv_lt_inv ha hb } } end lemma inv_lt_iff_inv_lt : a⁻¹ < b ↔ b⁻¹ < a := by simpa only [inv_inv] using @inv_lt_inv a b⁻¹ lemma lt_inv_iff_lt_inv : a < b⁻¹ ↔ b < a⁻¹ := by simpa only [inv_inv] using @inv_lt_inv a⁻¹ b @[simp, priority 1100] -- higher than le_inv_iff_mul_le lemma inv_le_inv : a⁻¹ ≤ b⁻¹ ↔ b ≤ a := by simp only [le_iff_lt_or_eq, inv_lt_inv, inv_eq_inv, eq_comm] lemma inv_le_iff_inv_le : a⁻¹ ≤ b ↔ b⁻¹ ≤ a := by simpa only [inv_inv] using @inv_le_inv a b⁻¹ lemma le_inv_iff_le_inv : a ≤ b⁻¹ ↔ b ≤ a⁻¹ := by simpa only [inv_inv] using @inv_le_inv a⁻¹ b @[simp] lemma inv_lt_one : a⁻¹ < 1 ↔ 1 < a := inv_lt_iff_inv_lt.trans $ by rw [inv_one] @[simp] lemma div_top : a / ∞ = 0 := by simp only [div_def, inv_top, mul_zero] @[simp] lemma top_div_coe : ∞ / p = ∞ := by simp [div_def, top_mul] lemma top_div_of_ne_top (h : a ≠ ∞) : ∞ / a = ∞ := by { lift a to ℝ≥0 using h, exact top_div_coe } lemma top_div_of_lt_top (h : a < ∞) : ∞ / a = ∞ := top_div_of_ne_top h.ne lemma top_div : ∞ / a = if a = ∞ then 0 else ∞ := by by_cases a = ∞; simp [top_div_of_ne_top, *] @[simp] lemma zero_div : 0 / a = 0 := zero_mul a⁻¹ lemma div_eq_top : a / b = ∞ ↔ (a ≠ 0 ∧ b = 0) ∨ (a = ∞ ∧ b ≠ ∞) := by simp [ennreal.div_def, ennreal.mul_eq_top] lemma le_div_iff_mul_le (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : a ≤ c / b ↔ a * b ≤ c := begin cases b, { simp at ht, split, { assume ha, simp at ha, simp [ha] }, { contrapose, assume ha, simp at ha, have : a * ∞ = ∞, by simp [ennreal.mul_eq_top, ha], simp [this, ht] } }, by_cases hb : b ≠ 0, { have : (b : ennreal) ≠ 0, by simp [hb], rw [← ennreal.mul_le_mul_left this coe_ne_top], suffices : ↑b * a ≤ (↑b * ↑b⁻¹) * c ↔ a * ↑b ≤ c, { simpa [some_eq_coe, div_def, hb, mul_left_comm, mul_comm, mul_assoc] }, rw [← coe_mul, nnreal.mul_inv_cancel hb, coe_one, one_mul, mul_comm] }, { simp at hb, simp [hb] at h0, have : c / 0 = ∞, by simp [div_eq_top, h0], simp [hb, this] } end lemma div_le_iff_le_mul (hb0 : b ≠ 0 ∨ c ≠ ∞) (hbt : b ≠ ∞ ∨ c ≠ 0) : a / b ≤ c ↔ a ≤ c * b := begin suffices : a * b⁻¹ ≤ c ↔ a ≤ c / b⁻¹, by simpa [div_def], apply (le_div_iff_mul_le _ _).symm, simpa [inv_ne_zero] using hbt, simpa [inv_ne_zero] using hb0 end lemma div_le_of_le_mul (h : a ≤ b * c) : a / c ≤ b := begin by_cases h0 : c = 0, { have : a = 0, by simpa [h0] using h, simp [*] }, by_cases hinf : c = ∞, by simp [hinf], exact (div_le_iff_le_mul (or.inl h0) (or.inl hinf)).2 h end protected lemma div_lt_iff (h0 : b ≠ 0 ∨ c ≠ 0) (ht : b ≠ ∞ ∨ c ≠ ∞) : c / b < a ↔ c < a * b := lt_iff_lt_of_le_iff_le $ le_div_iff_mul_le h0 ht lemma mul_lt_of_lt_div (h : a < b / c) : a * c < b := by { contrapose! h, exact ennreal.div_le_of_le_mul h } lemma inv_le_iff_le_mul : (b = ∞ → a ≠ 0) → (a = ∞ → b ≠ 0) → (a⁻¹ ≤ b ↔ 1 ≤ a * b) := begin cases a; cases b; simp [none_eq_top, some_eq_coe, mul_top, top_mul] {contextual := tt}, by_cases a = 0; simp [*, -coe_mul, coe_mul.symm, -coe_inv, (coe_inv _).symm, nnreal.inv_le] end @[simp] lemma le_inv_iff_mul_le : a ≤ b⁻¹ ↔ a * b ≤ 1 := begin cases b, { by_cases a = 0; simp [*, none_eq_top, mul_top] }, by_cases b = 0; simp [*, some_eq_coe, le_div_iff_mul_le], suffices : a ≤ 1 / b ↔ a * b ≤ 1, { simpa [div_def, h] }, exact le_div_iff_mul_le (or.inl (mt coe_eq_coe.1 h)) (or.inl coe_ne_top) end lemma mul_inv_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a * a⁻¹ = 1 := begin lift a to ℝ≥0 using ht, norm_cast at h0, norm_cast, exact nnreal.mul_inv_cancel h0 end lemma inv_mul_cancel (h0 : a ≠ 0) (ht : a ≠ ∞) : a⁻¹ * a = 1 := mul_comm a a⁻¹ ▸ mul_inv_cancel h0 ht lemma mul_le_iff_le_inv {a b r : ennreal} (hr₀ : r ≠ 0) (hr₁ : r ≠ ∞) : (r * a ≤ b ↔ a ≤ r⁻¹ * b) := by rw [← @ennreal.mul_le_mul_left _ a _ hr₀ hr₁, ← mul_assoc, mul_inv_cancel hr₀ hr₁, one_mul] lemma le_of_forall_lt_one_mul_lt : ∀{x y : ennreal}, (∀a<1, a * x ≤ y) → x ≤ y := forall_ennreal.2 $ and.intro (assume r, forall_ennreal.2 $ and.intro (assume q h, coe_le_coe.2 $ nnreal.le_of_forall_lt_one_mul_lt $ assume a ha, begin rw [← coe_le_coe, coe_mul], exact h _ (coe_lt_coe.2 ha) end) (assume h, le_top)) (assume r hr, have ((1 / 2 : ℝ≥0) : ennreal) * ∞ ≤ r := hr _ (coe_lt_coe.2 ((@nnreal.coe_lt_coe (1/2) 1).1 one_half_lt_one)), have ne : ((1 / 2 : ℝ≥0) : ennreal) ≠ 0, begin rw [(≠), coe_eq_zero], refine zero_lt_iff_ne_zero.1 _, show 0 < (1 / 2 : ℝ), linarith, end, by rwa [mul_top, if_neg ne] at this) lemma div_add_div_same {a b c : ennreal} : a / c + b / c = (a + b) / c := eq.symm $ right_distrib a b (c⁻¹) lemma div_self (h0 : a ≠ 0) (hI : a ≠ ∞) : a / a = 1 := mul_inv_cancel h0 hI lemma mul_div_cancel (h0 : a ≠ 0) (hI : a ≠ ∞) : (b / a) * a = b := by rw [div_def, mul_assoc, inv_mul_cancel h0 hI, mul_one] lemma mul_div_cancel' (h0 : a ≠ 0) (hI : a ≠ ∞) : a * (b / a) = b := by rw [mul_comm, mul_div_cancel h0 hI] lemma inv_two_add_inv_two : (2:ennreal)⁻¹ + 2⁻¹ = 1 := by rw [← two_mul, ← div_def, div_self two_ne_zero two_ne_top] lemma add_halves (a : ennreal) : a / 2 + a / 2 = a := by rw [div_def, ← mul_add, inv_two_add_inv_two, mul_one] @[simp] lemma div_zero_iff : a / b = 0 ↔ a = 0 ∨ b = ∞ := by simp [div_def, mul_eq_zero] @[simp] lemma div_pos_iff : 0 < a / b ↔ a ≠ 0 ∧ b ≠ ∞ := by simp [zero_lt_iff_ne_zero, not_or_distrib] lemma half_pos {a : ennreal} (h : 0 < a) : 0 < a / 2 := by simp [ne_of_gt h] lemma one_half_lt_one : (2⁻¹:ennreal) < 1 := inv_lt_one.2 $ one_lt_two lemma half_lt_self {a : ennreal} (hz : a ≠ 0) (ht : a ≠ ∞) : a / 2 < a := begin lift a to ℝ≥0 using ht, have h : (2 : ennreal) = ((2 : ℝ≥0) : ennreal), from rfl, have h' : (2 : ℝ≥0) ≠ 0, from _root_.two_ne_zero', rw [h, ← coe_div h', coe_lt_coe], -- `norm_cast` fails to apply `coe_div` norm_cast at hz, exact nnreal.half_lt_self hz end lemma sub_half (h : a ≠ ∞) : a - a / 2 = a / 2 := begin lift a to ℝ≥0 using h, exact sub_eq_of_add_eq (mul_ne_top coe_ne_top $ by simp) (add_halves a) end lemma one_sub_inv_two : (1:ennreal) - 2⁻¹ = 2⁻¹ := by simpa only [div_def, one_mul] using sub_half one_ne_top lemma exists_inv_nat_lt {a : ennreal} (h : a ≠ 0) : ∃n:ℕ, (n:ennreal)⁻¹ < a := @inv_inv a ▸ by simp only [inv_lt_inv, ennreal.exists_nat_gt (inv_ne_top.2 h)] lemma exists_nat_pos_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n > 0, b < (n : ℕ) * a := begin have : b / a ≠ ∞, from mul_ne_top hb (inv_ne_top.2 ha), refine (ennreal.exists_nat_gt this).imp (λ n hn, _), have : 0 < (n : ennreal), from (zero_le _).trans_lt hn, refine ⟨coe_nat_lt_coe_nat.1 this, _⟩, rwa [← ennreal.div_lt_iff (or.inl ha) (or.inr hb)] end lemma exists_nat_mul_gt (ha : a ≠ 0) (hb : b ≠ ∞) : ∃ n : ℕ, b < n * a := (exists_nat_pos_mul_gt ha hb).imp $ λ n, Exists.snd lemma exists_nat_pos_inv_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) : ∃ n > 0, ((n : ℕ) : ennreal)⁻¹ * a < b := begin rcases exists_nat_pos_mul_gt hb ha with ⟨n, npos, hn⟩, have : (n : ennreal) ≠ 0 := nat.cast_ne_zero.2 npos.lt.ne', use [n, npos], rwa [← one_mul b, ← inv_mul_cancel this coe_nat_ne_top, mul_assoc, mul_lt_mul_left (inv_ne_zero.2 coe_nat_ne_top) (inv_ne_top.2 this)] end lemma exists_nnreal_pos_mul_lt (ha : a ≠ ∞) (hb : b ≠ 0) : ∃ n > 0, ↑(n : ℝ≥0) * a < b := begin rcases exists_nat_pos_inv_mul_lt ha hb with ⟨n, npos : 0 < n, hn⟩, use (n : ℝ≥0)⁻¹, simp [*, npos.ne', zero_lt_one] end end inv section real lemma to_real_add (ha : a ≠ ∞) (hb : b ≠ ∞) : (a+b).to_real = a.to_real + b.to_real := begin lift a to ℝ≥0 using ha, lift b to ℝ≥0 using hb, refl end lemma to_real_add_le : (a+b).to_real ≤ a.to_real + b.to_real := if ha : a = ∞ then by simp only [ha, top_add, top_to_real, zero_add, to_real_nonneg] else if hb : b = ∞ then by simp only [hb, add_top, top_to_real, add_zero, to_real_nonneg] else le_of_eq (to_real_add ha hb) lemma of_real_add {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : ennreal.of_real (p + q) = ennreal.of_real p + ennreal.of_real q := by rw [ennreal.of_real, ennreal.of_real, ennreal.of_real, ← coe_add, coe_eq_coe, nnreal.of_real_add hp hq] lemma of_real_add_le {p q : ℝ} : ennreal.of_real (p + q) ≤ ennreal.of_real p + ennreal.of_real q := coe_le_coe.2 nnreal.of_real_add_le @[simp] lemma to_real_le_to_real (ha : a ≠ ∞) (hb : b ≠ ∞) : a.to_real ≤ b.to_real ↔ a ≤ b := begin lift a to ℝ≥0 using ha, lift b to ℝ≥0 using hb, norm_cast end @[simp] lemma to_real_lt_to_real (ha : a ≠ ∞) (hb : b ≠ ∞) : a.to_real < b.to_real ↔ a < b := begin lift a to ℝ≥0 using ha, lift b to ℝ≥0 using hb, norm_cast end lemma to_real_max (hr : a ≠ ∞) (hp : b ≠ ∞) : ennreal.to_real (max a b) = max (ennreal.to_real a) (ennreal.to_real b) := (le_total a b).elim (λ h, by simp only [h, (ennreal.to_real_le_to_real hr hp).2 h, max_eq_right]) (λ h, by simp only [h, (ennreal.to_real_le_to_real hp hr).2 h, max_eq_left]) lemma to_nnreal_pos_iff : 0 < a.to_nnreal ↔ (0 < a ∧ a ≠ ∞) := begin cases a, { simp [none_eq_top] }, { simp [some_eq_coe] } end lemma to_real_pos_iff : 0 < a.to_real ↔ (0 < a ∧ a ≠ ∞):= (nnreal.coe_pos).trans to_nnreal_pos_iff lemma of_real_le_of_real {p q : ℝ} (h : p ≤ q) : ennreal.of_real p ≤ ennreal.of_real q := by simp [ennreal.of_real, nnreal.of_real_le_of_real h] lemma of_real_le_of_le_to_real {a : ℝ} {b : ennreal} (h : a ≤ ennreal.to_real b) : ennreal.of_real a ≤ b := (of_real_le_of_real h).trans of_real_to_real_le @[simp] lemma of_real_le_of_real_iff {p q : ℝ} (h : 0 ≤ q) : ennreal.of_real p ≤ ennreal.of_real q ↔ p ≤ q := by rw [ennreal.of_real, ennreal.of_real, coe_le_coe, nnreal.of_real_le_of_real_iff h] @[simp] lemma of_real_lt_of_real_iff {p q : ℝ} (h : 0 < q) : ennreal.of_real p < ennreal.of_real q ↔ p < q := by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff h] lemma of_real_lt_of_real_iff_of_nonneg {p q : ℝ} (hp : 0 ≤ p) : ennreal.of_real p < ennreal.of_real q ↔ p < q := by rw [ennreal.of_real, ennreal.of_real, coe_lt_coe, nnreal.of_real_lt_of_real_iff_of_nonneg hp] @[simp] lemma of_real_pos {p : ℝ} : 0 < ennreal.of_real p ↔ 0 < p := by simp [ennreal.of_real] @[simp] lemma of_real_eq_zero {p : ℝ} : ennreal.of_real p = 0 ↔ p ≤ 0 := by simp [ennreal.of_real] lemma of_real_le_iff_le_to_real {a : ℝ} {b : ennreal} (hb : b ≠ ∞) : ennreal.of_real a ≤ b ↔ a ≤ ennreal.to_real b := begin lift b to ℝ≥0 using hb, simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_le_iff_le_coe end lemma of_real_lt_iff_lt_to_real {a : ℝ} {b : ennreal} (ha : 0 ≤ a) (hb : b ≠ ∞) : ennreal.of_real a < b ↔ a < ennreal.to_real b := begin lift b to ℝ≥0 using hb, simpa [ennreal.of_real, ennreal.to_real] using nnreal.of_real_lt_iff_lt_coe ha end lemma le_of_real_iff_to_real_le {a : ennreal} {b : ℝ} (ha : a ≠ ∞) (hb : 0 ≤ b) : a ≤ ennreal.of_real b ↔ ennreal.to_real a ≤ b := begin lift a to ℝ≥0 using ha, simpa [ennreal.of_real, ennreal.to_real] using nnreal.le_of_real_iff_coe_le hb end lemma to_real_le_of_le_of_real {a : ennreal} {b : ℝ} (hb : 0 ≤ b) (h : a ≤ ennreal.of_real b) : ennreal.to_real a ≤ b := have ha : a ≠ ∞, from ne_top_of_le_ne_top of_real_ne_top h, (le_of_real_iff_to_real_le ha hb).1 h lemma lt_of_real_iff_to_real_lt {a : ennreal} {b : ℝ} (ha : a ≠ ∞) : a < ennreal.of_real b ↔ ennreal.to_real a < b := begin lift a to ℝ≥0 using ha, simpa [ennreal.of_real, ennreal.to_real] using nnreal.lt_of_real_iff_coe_lt end lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) : ennreal.of_real (p * q) = (ennreal.of_real p) * (ennreal.of_real q) := by { simp only [ennreal.of_real, coe_mul.symm, coe_eq_coe], exact nnreal.of_real_mul hp } lemma of_real_inv_of_pos {x : ℝ} (hx : 0 < x) : (ennreal.of_real x)⁻¹ = ennreal.of_real x⁻¹ := by rw [ennreal.of_real, ennreal.of_real, ←@coe_inv (nnreal.of_real x) (by simp [hx]), coe_eq_coe, nnreal.of_real_inv.symm] lemma of_real_div_of_pos {x y : ℝ} (hy : 0 < y) : ennreal.of_real (x / y) = ennreal.of_real x / ennreal.of_real y := by rw [div_def, of_real_inv_of_pos hy, mul_comm, ←of_real_mul (inv_nonneg.mpr (le_of_lt hy)), div_eq_mul_inv, mul_comm] lemma to_real_of_real_mul (c : ℝ) (a : ennreal) (h : 0 ≤ c) : ennreal.to_real ((ennreal.of_real c) * a) = c * ennreal.to_real a := begin cases a, { simp only [none_eq_top, ennreal.to_real, top_to_nnreal, nnreal.coe_zero, mul_zero, mul_top], by_cases h' : c ≤ 0, { rw [if_pos], { simp }, { convert of_real_zero, exact le_antisymm h' h } }, { rw [if_neg], refl, rw [of_real_eq_zero], assumption } }, { simp only [ennreal.to_real, ennreal.to_nnreal], simp only [some_eq_coe, ennreal.of_real, coe_mul.symm, to_nnreal_coe, nnreal.coe_mul], congr, apply nnreal.coe_of_real, exact h } end @[simp] lemma to_nnreal_mul_top (a : ennreal) : ennreal.to_nnreal (a * ∞) = 0 := begin by_cases h : a = 0, { rw [h, zero_mul, zero_to_nnreal] }, { rw [mul_top, if_neg h, top_to_nnreal] } end @[simp] lemma to_nnreal_top_mul (a : ennreal) : ennreal.to_nnreal (∞ * a) = 0 := by rw [mul_comm, to_nnreal_mul_top] @[simp] lemma to_real_mul_top (a : ennreal) : ennreal.to_real (a * ∞) = 0 := by rw [ennreal.to_real, to_nnreal_mul_top, nnreal.coe_zero] @[simp] lemma to_real_top_mul (a : ennreal) : ennreal.to_real (∞ * a) = 0 := by { rw mul_comm, exact to_real_mul_top _ } lemma to_real_eq_to_real (ha : a < ∞) (hb : b < ∞) : ennreal.to_real a = ennreal.to_real b ↔ a = b := begin lift a to ℝ≥0 using ha.ne, lift b to ℝ≥0 using hb.ne, simp only [coe_eq_coe, nnreal.coe_eq, coe_to_real], end /-- `ennreal.to_nnreal` as a `monoid_hom`. -/ def to_nnreal_hom : ennreal →* ℝ≥0 := { to_fun := ennreal.to_nnreal, map_one' := to_nnreal_coe, map_mul' := by rintro (_|x) (_|y); simp only [← coe_mul, none_eq_top, some_eq_coe, to_nnreal_top_mul, to_nnreal_mul_top, top_to_nnreal, mul_zero, zero_mul, to_nnreal_coe] } /-- `ennreal.to_real` as a `monoid_hom`. -/ def to_real_hom : ennreal →* ℝ := (nnreal.to_real_hom : ℝ≥0 →* ℝ).comp to_nnreal_hom lemma to_real_mul : (a * b).to_real = a.to_real * b.to_real := to_real_hom.map_mul a b lemma to_real_pow (a : ennreal) (n : ℕ) : (a ^ n).to_real = a.to_real ^ n := to_real_hom.map_pow a n lemma to_real_prod {ι : Type*} {s : finset ι} {f : ι → ennreal} : (∏ i in s, f i).to_real = ∏ i in s, (f i).to_real := to_real_hom.map_prod _ _ end real section infi variables {ι : Sort*} {f g : ι → ennreal} lemma infi_add : infi f + a = ⨅i, f i + a := le_antisymm (le_infi $ assume i, add_le_add (infi_le _ _) $ le_refl _) (ennreal.sub_le_iff_le_add.1 $ le_infi $ assume i, ennreal.sub_le_iff_le_add.2 $ infi_le _ _) lemma supr_sub : (⨆i, f i) - a = (⨆i, f i - a) := le_antisymm (ennreal.sub_le_iff_le_add.2 $ supr_le $ assume i, ennreal.sub_le_iff_le_add.1 $ le_supr _ i) (supr_le $ assume i, ennreal.sub_le_sub (le_supr _ _) (le_refl a)) lemma sub_infi : a - (⨅i, f i) = (⨆i, a - f i) := begin refine (eq_of_forall_ge_iff $ λ c, _), rw [ennreal.sub_le_iff_le_add, add_comm, infi_add], simp [ennreal.sub_le_iff_le_add, sub_eq_add_neg, add_comm], end lemma Inf_add {s : set ennreal} : Inf s + a = ⨅b∈s, b + a := by simp [Inf_eq_infi, infi_add] lemma add_infi {a : ennreal} : a + infi f = ⨅b, a + f b := by rw [add_comm, infi_add]; simp [add_comm] lemma infi_add_infi (h : ∀i j, ∃k, f k + g k ≤ f i + g j) : infi f + infi g = (⨅a, f a + g a) := suffices (⨅a, f a + g a) ≤ infi f + infi g, from le_antisymm (le_infi $ assume a, add_le_add (infi_le _ _) (infi_le _ _)) this, calc (⨅a, f a + g a) ≤ (⨅ a a', f a + g a') : le_infi $ assume a, le_infi $ assume a', let ⟨k, h⟩ := h a a' in infi_le_of_le k h ... ≤ infi f + infi g : by simp [add_infi, infi_add, -add_comm, -le_infi_iff]; exact le_refl _ lemma infi_sum {f : ι → α → ennreal} {s : finset α} [nonempty ι] (h : ∀(t : finset α) (i j : ι), ∃k, ∀a∈t, f k a ≤ f i a ∧ f k a ≤ f j a) : (⨅i, ∑ a in s, f i a) = ∑ a in s, ⨅i, f i a := finset.induction_on s (by simp) $ assume a s ha ih, have ∀ (i j : ι), ∃ (k : ι), f k a + ∑ b in s, f k b ≤ f i a + ∑ b in s, f j b, from assume i j, let ⟨k, hk⟩ := h (insert a s) i j in ⟨k, add_le_add (hk a (finset.mem_insert_self _ _)).left $ finset.sum_le_sum $ assume a ha, (hk _ $ finset.mem_insert_of_mem ha).right⟩, by simp [ha, ih.symm, infi_add_infi this] lemma infi_mul {ι} [nonempty ι] {f : ι → ennreal} {x : ennreal} (h : x ≠ ∞) : infi f * x = ⨅i, f i * x := begin by_cases h2 : x = 0, simp only [h2, mul_zero, infi_const], refine le_antisymm (le_infi $ λ i, mul_right_mono $ infi_le _ _) ((div_le_iff_le_mul (or.inl h2) $ or.inl h).mp $ le_infi $ λ i, (div_le_iff_le_mul (or.inl h2) $ or.inl h).mpr $ infi_le _ _) end lemma mul_infi {ι} [nonempty ι] {f : ι → ennreal} {x : ennreal} (h : x ≠ ∞) : x * infi f = ⨅i, x * f i := by { rw [mul_comm, infi_mul h], simp only [mul_comm], assumption } /-! `supr_mul`, `mul_supr` and variants are in `topology.instances.ennreal`. -/ end infi section supr lemma supr_coe_nat : (⨆n:ℕ, (n : ennreal)) = ∞ := (supr_eq_top _).2 $ assume b hb, ennreal.exists_nat_gt (lt_top_iff_ne_top.1 hb) end supr /-- `le_of_add_le_add_left` is normally applicable to `ordered_cancel_add_comm_monoid`, but it holds in `ennreal` with the additional assumption that `a < ∞`. -/ lemma le_of_add_le_add_left {a b c : ennreal} : a < ∞ → a + b ≤ a + c → b ≤ c := by cases a; cases b; cases c; simp [← ennreal.coe_add, ennreal.coe_le_coe] end ennreal
df5c0bce705ab3091288fec8beb9f8214ab17ff0
bdb33f8b7ea65f7705fc342a178508e2722eb851
/group_theory/order_of_element.lean
573cf5b05c3dbf5e2c3d632811d52fc0f1c6bc04
[ "Apache-2.0" ]
permissive
rwbarton/mathlib
939ae09bf8d6eb1331fc2f7e067d39567e10e33d
c13c5ea701bb1eec057e0a242d9f480a079105e9
refs/heads/master
1,584,015,335,862
1,524,142,167,000
1,524,142,167,000
130,614,171
0
0
Apache-2.0
1,548,902,667,000
1,524,437,371,000
Lean
UTF-8
Lean
false
false
6,491
lean
/- Copyright (c) 2018 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl -/ import data.set.finite group_theory.coset open set function variables {α : Type*} {s : set α} {a a₁ a₂ b c: α} -- TODO this lemma isn't used anywhere in this file, and should be moved elsewhere. namespace finset open finset lemma mem_range_iff_mem_finset_range_of_mod_eq [decidable_eq α] {f : ℤ → α} {a : α} {n : ℕ} (hn : 0 < n) (h : ∀i, f (i % n) = f i) : a ∈ set.range f ↔ a ∈ (finset.range n).image (λi, f i) := suffices (∃i, f (i % n) = a) ↔ ∃i, i < n ∧ f ↑i = a, by simpa [h], have hn' : 0 < (n : ℤ), from int.coe_nat_lt.mpr hn, iff.intro (assume ⟨i, hi⟩, have 0 ≤ i % ↑n, from int.mod_nonneg _ (ne_of_gt hn'), ⟨int.to_nat (i % n), by rw [←int.coe_nat_lt, int.to_nat_of_nonneg this]; exact ⟨int.mod_lt_of_pos i hn', hi⟩⟩) (assume ⟨i, hi, ha⟩, ⟨i, by rw [int.mod_eq_of_lt (int.coe_zero_le _) (int.coe_nat_lt_coe_nat_of_lt hi), ha]⟩) end finset section order_of variables [group α] [fintype α] [decidable_eq α] lemma exists_gpow_eq_one (a : α) : ∃i≠0, a ^ (i:ℤ) = 1 := have ¬ injective (λi, a ^ i), from not_injective_int_fintype, let ⟨i, j, a_eq, ne⟩ := show ∃(i j : ℤ), a ^ i = a ^ j ∧ i ≠ j, by rw [injective] at this; simpa [classical.not_forall] in have a ^ (i - j) = 1, by simp [gpow_add, gpow_neg, a_eq], ⟨i - j, sub_ne_zero.mpr ne, this⟩ lemma exists_pow_eq_one (a : α) : ∃i≠0, a ^ i = 1 := let ⟨i, hi, eq⟩ := exists_gpow_eq_one a in begin cases i, { exact ⟨i, by simp [int.of_nat_eq_coe, *] at *, eq⟩ }, { exact ⟨i + 1, dec_trivial, inv_eq_one.1 eq⟩ } end /-- `order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `a ^ n = 1` -/ def order_of (a : α) : ℕ := nat.find (exists_pow_eq_one a) lemma pow_order_of_eq_one (a : α) : a ^ order_of a = 1 := let ⟨h₁, h₂⟩ := nat.find_spec (exists_pow_eq_one a) in h₂ lemma order_of_ne_zero (a : α) : order_of a ≠ 0 := let ⟨h₁, h₂⟩ := nat.find_spec (exists_pow_eq_one a) in h₁ private lemma pow_injective_aux {n m : ℕ} (a : α) (h : n ≤ m) (hn : n < order_of a) (hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m := decidable.by_contradiction $ assume ne : n ≠ m, have h₁ : m - n ≠ 0, by simp [nat.sub_eq_iff_eq_add h, ne.symm], have h₂ : a ^ (m - n) = 1, by simp [pow_sub _ h, eq], have le : order_of a ≤ m - n, from nat.find_min' (exists_pow_eq_one a) ⟨h₁, h₂⟩, have lt : m - n < order_of a, from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm, lt_irrefl _ (lt_of_le_of_lt le lt) lemma pow_injective_of_lt_order_of {n m : ℕ} (a : α) (hn : n < order_of a) (hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m := (le_total n m).elim (assume h, pow_injective_aux a h hn hm eq) (assume h, (pow_injective_aux a h hm hn eq.symm).symm) lemma order_of_le_card_univ : order_of a ≤ fintype.card α := finset.card_le_of_inj_on ((^) a) (assume n _, fintype.complete _) (assume i j, pow_injective_of_lt_order_of a) lemma pow_eq_mod_order_of {n : ℕ} : a ^ n = a ^ (n % order_of a) := calc a ^ n = a ^ (n % order_of a + order_of a * (n / order_of a)) : by rw [nat.mod_add_div] ... = a ^ (n % order_of a) : by simp [pow_add, pow_mul, pow_order_of_eq_one] lemma gpow_eq_mod_order_of {i : ℤ} : a ^ i = a ^ (i % order_of a) := calc a ^ i = a ^ (i % order_of a + order_of a * (i / order_of a)) : by rw [int.mod_add_div] ... = a ^ (i % order_of a) : by simp [gpow_add, gpow_mul, pow_order_of_eq_one] lemma mem_range_gpow_iff_mem_range_order_of {a a' : α} : a' ∈ range ((^) a : ℤ → α) ↔ a' ∈ (finset.range (order_of a)).image ((^) a : ℕ → α) := finset.mem_range_iff_mem_finset_range_of_mod_eq (nat.pos_iff_ne_zero.mpr (order_of_ne_zero a)) (assume i, gpow_eq_mod_order_of.symm) instance decidable_range_gpow : decidable_pred (range ((^) a : ℤ → α)) := assume a', decidable_of_iff' (a' ∈ (finset.range (order_of a)).image ((^) a)) mem_range_gpow_iff_mem_range_order_of section local attribute [instance] set_fintype lemma order_eq_card_range_gpow : order_of a = fintype.card (range ((^) a : ℤ → α)) := begin refine (finset.card_eq_of_bijective _ _ _ _).symm, { exact λn hn, ⟨gpow a n, mem_range_self n⟩ }, { exact assume ⟨_, i, rfl⟩ _, have pos: (0:int) < order_of a, from int.coe_nat_lt.mpr $ nat.pos_iff_ne_zero.mpr $ order_of_ne_zero a, have 0 ≤ i % (order_of a), from int.mod_nonneg _ $ ne_of_gt pos, ⟨int.to_nat (i % order_of a), by rw [← int.coe_nat_lt, int.to_nat_of_nonneg this]; exact ⟨int.mod_lt_of_pos _ pos, subtype.eq gpow_eq_mod_order_of.symm⟩⟩ }, { intros, exact finset.mem_univ _ }, { exact assume i j hi hj eq, pow_injective_of_lt_order_of a hi hj $ by simpa using eq } end section classical local attribute [instance] classical.prop_decidable /- TODO: use cardinal theory, introduce `card : set α → ℕ`, or setup decidability for cosets -/ lemma order_of_dvd_card_univ : order_of a ∣ fintype.card α := have ft_prod : fintype (left_cosets (gpowers a) × (gpowers a)), from fintype.of_equiv α (gpowers.is_subgroup a).group_equiv_left_cosets_times_subgroup, have ft_s : fintype (gpowers a), from @fintype.fintype_prod_right _ _ _ ft_prod _, have ft_cosets : fintype (left_cosets (gpowers a)), from @fintype.fintype_prod_left _ _ _ ft_prod ⟨⟨1, is_submonoid.one_mem (gpowers a)⟩⟩, have ft : fintype (left_cosets (gpowers a) × (gpowers a)), from @prod.fintype _ _ ft_cosets ft_s, have eq₁ : fintype.card α = @fintype.card _ ft_cosets * @fintype.card _ ft_s, from calc fintype.card α = @fintype.card _ ft_prod : @fintype.card_congr _ _ _ ft_prod (gpowers.is_subgroup a).group_equiv_left_cosets_times_subgroup ... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) : congr_arg (@fintype.card _) $ subsingleton.elim _ _ ... = @fintype.card _ ft_cosets * @fintype.card _ ft_s : @fintype.card_prod _ _ ft_cosets ft_s, have eq₂ : order_of a = @fintype.card _ ft_s, from calc order_of a = _ : order_eq_card_range_gpow ... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _, dvd.intro (@fintype.card (left_cosets (gpowers a)) ft_cosets) $ by rw [eq₁, eq₂, mul_comm] end classical end end order_of
d2d0847779835b7d9d567534ed84198d8942677f
c777c32c8e484e195053731103c5e52af26a25d1
/src/analysis/normed_space/matrix_exponential.lean
529ec5ab24174ac28580215fee5a486a20b0dc46
[ "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
9,479
lean
/- Copyright (c) 2022 Eric Wieser. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Eric Wieser -/ import analysis.normed_space.exponential import analysis.matrix import linear_algebra.matrix.zpow import linear_algebra.matrix.hermitian import linear_algebra.matrix.symmetric import topology.uniform_space.matrix /-! # Lemmas about the matrix exponential In this file, we provide results about `exp` on `matrix`s over a topological or normed algebra. Note that generic results over all topological spaces such as `exp_zero` can be used on matrices without issue, so are not repeated here. The topological results specific to matrices are: * `matrix.exp_transpose` * `matrix.exp_conj_transpose` * `matrix.exp_diagonal` * `matrix.exp_block_diagonal` * `matrix.exp_block_diagonal'` Lemmas like `exp_add_of_commute` require a canonical norm on the type; while there are multiple sensible choices for the norm of a `matrix` (`matrix.normed_add_comm_group`, `matrix.frobenius_normed_add_comm_group`, `matrix.linfty_op_normed_add_comm_group`), none of them are canonical. In an application where a particular norm is chosen using `local attribute [instance]`, then the usual lemmas about `exp` are fine. When choosing a norm is undesirable, the results in this file can be used. In this file, we copy across the lemmas about `exp`, but hide the requirement for a norm inside the proof. * `matrix.exp_add_of_commute` * `matrix.exp_sum_of_commute` * `matrix.exp_nsmul` * `matrix.is_unit_exp` * `matrix.exp_units_conj` * `matrix.exp_units_conj'` Additionally, we prove some results about `matrix.has_inv` and `matrix.div_inv_monoid`, as the results for general rings are instead stated about `ring.inverse`: * `matrix.exp_neg` * `matrix.exp_zsmul` * `matrix.exp_conj` * `matrix.exp_conj'` ## Implementation notes This file runs into some sharp edges on typeclass search in lean 3, especially regarding pi types. To work around this, we copy a handful of instances for when lean can't find them by itself. Hopefully we will be able to remove these in Lean 4. ## TODO * Show that `matrix.det (exp 𝕂 A) = exp 𝕂 (matrix.trace A)` ## References * https://en.wikipedia.org/wiki/Matrix_exponential -/ open_locale matrix big_operators section hacks_for_pi_instance_search /-- A special case of `pi.topological_ring` for when `R` is not dependently typed. -/ instance function.topological_ring (I : Type*) (R : Type*) [non_unital_ring R] [topological_space R] [topological_ring R] : topological_ring (I → R) := pi.topological_ring /-- A special case of `function.algebra` for when A is a `ring` not a `semiring` -/ instance function.algebra_ring (I : Type*) {R : Type*} (A : Type*) [comm_semiring R] [ring A] [algebra R A] : algebra R (I → A) := pi.algebra _ _ /-- A special case of `pi.algebra` for when `f = λ i, matrix (m i) (m i) A`. -/ instance pi.matrix_algebra (I R A : Type*) (m : I → Type*) [comm_semiring R] [semiring A] [algebra R A] [Π i, fintype (m i)] [Π i, decidable_eq (m i)] : algebra R (Π i, matrix (m i) (m i) A) := @pi.algebra I R (λ i, matrix (m i) (m i) A) _ _ (λ i, matrix.algebra) /-- A special case of `pi.topological_ring` for when `f = λ i, matrix (m i) (m i) A`. -/ instance pi.matrix_topological_ring (I A : Type*) (m : I → Type*) [ring A] [topological_space A] [topological_ring A] [Π i, fintype (m i)] : topological_ring (Π i, matrix (m i) (m i) A) := @pi.topological_ring _ (λ i, matrix (m i) (m i) A) _ _ (λ i, matrix.topological_ring) end hacks_for_pi_instance_search variables (𝕂 : Type*) {m n p : Type*} {n' : m → Type*} {𝔸 : Type*} namespace matrix section topological section ring variables [fintype m] [decidable_eq m] [fintype n] [decidable_eq n] [Π i, fintype (n' i)] [Π i, decidable_eq (n' i)] [field 𝕂] [ring 𝔸] [topological_space 𝔸] [topological_ring 𝔸] [algebra 𝕂 𝔸] [t2_space 𝔸] lemma exp_diagonal (v : m → 𝔸) : exp 𝕂 (diagonal v) = diagonal (exp 𝕂 v) := by simp_rw [exp_eq_tsum, diagonal_pow, ←diagonal_smul, ←diagonal_tsum] lemma exp_block_diagonal (v : m → matrix n n 𝔸) : exp 𝕂 (block_diagonal v) = block_diagonal (exp 𝕂 v) := by simp_rw [exp_eq_tsum, ←block_diagonal_pow, ←block_diagonal_smul, ←block_diagonal_tsum] lemma exp_block_diagonal' (v : Π i, matrix (n' i) (n' i) 𝔸) : exp 𝕂 (block_diagonal' v) = block_diagonal' (exp 𝕂 v) := by simp_rw [exp_eq_tsum, ←block_diagonal'_pow, ←block_diagonal'_smul, ←block_diagonal'_tsum] lemma exp_conj_transpose [star_ring 𝔸] [has_continuous_star 𝔸] (A : matrix m m 𝔸) : exp 𝕂 Aᴴ = (exp 𝕂 A)ᴴ := (star_exp A).symm lemma is_hermitian.exp [star_ring 𝔸] [has_continuous_star 𝔸] {A : matrix m m 𝔸} (h : A.is_hermitian) : (exp 𝕂 A).is_hermitian := (exp_conj_transpose _ _).symm.trans $ congr_arg _ h end ring section comm_ring variables [fintype m] [decidable_eq m] [field 𝕂] [comm_ring 𝔸] [topological_space 𝔸] [topological_ring 𝔸] [algebra 𝕂 𝔸] [t2_space 𝔸] lemma exp_transpose (A : matrix m m 𝔸) : exp 𝕂 Aᵀ = (exp 𝕂 A)ᵀ := by simp_rw [exp_eq_tsum, transpose_tsum, transpose_smul, transpose_pow] lemma is_symm.exp {A : matrix m m 𝔸} (h : A.is_symm) : (exp 𝕂 A).is_symm := (exp_transpose _ _).symm.trans $ congr_arg _ h end comm_ring end topological section normed variables [is_R_or_C 𝕂] [fintype m] [decidable_eq m] [fintype n] [decidable_eq n] [Π i, fintype (n' i)] [Π i, decidable_eq (n' i)] [normed_ring 𝔸] [normed_algebra 𝕂 𝔸] [complete_space 𝔸] lemma exp_add_of_commute (A B : matrix m m 𝔸) (h : commute A B) : exp 𝕂 (A + B) = exp 𝕂 A ⬝ exp 𝕂 B := begin letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact exp_add_of_commute h, end lemma exp_sum_of_commute {ι} (s : finset ι) (f : ι → matrix m m 𝔸) (h : (s : set ι).pairwise $ λ i j, commute (f i) (f j)) : exp 𝕂 (∑ i in s, f i) = s.noncomm_prod (λ i, exp 𝕂 (f i)) (λ i hi j hj _, (h.of_refl hi hj).exp 𝕂) := begin letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact exp_sum_of_commute s f h, end lemma exp_nsmul (n : ℕ) (A : matrix m m 𝔸) : exp 𝕂 (n • A) = exp 𝕂 A ^ n := begin letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact exp_nsmul n A, end lemma is_unit_exp (A : matrix m m 𝔸) : is_unit (exp 𝕂 A) := begin letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact is_unit_exp _ A, end lemma exp_units_conj (U : (matrix m m 𝔸)ˣ) (A : matrix m m 𝔸) : exp 𝕂 (↑U ⬝ A ⬝ ↑(U⁻¹) : matrix m m 𝔸) = ↑U ⬝ exp 𝕂 A ⬝ ↑(U⁻¹) := begin letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact exp_units_conj _ U A, end lemma exp_units_conj' (U : (matrix m m 𝔸)ˣ) (A : matrix m m 𝔸) : exp 𝕂 (↑(U⁻¹) ⬝ A ⬝ U : matrix m m 𝔸) = ↑(U⁻¹) ⬝ exp 𝕂 A ⬝ U := exp_units_conj 𝕂 U⁻¹ A end normed section normed_comm variables [is_R_or_C 𝕂] [fintype m] [decidable_eq m] [fintype n] [decidable_eq n] [Π i, fintype (n' i)] [Π i, decidable_eq (n' i)] [normed_comm_ring 𝔸] [normed_algebra 𝕂 𝔸] [complete_space 𝔸] lemma exp_neg (A : matrix m m 𝔸) : exp 𝕂 (-A) = (exp 𝕂 A)⁻¹ := begin rw nonsing_inv_eq_ring_inverse, letI : semi_normed_ring (matrix m m 𝔸) := matrix.linfty_op_semi_normed_ring, letI : normed_ring (matrix m m 𝔸) := matrix.linfty_op_normed_ring, letI : normed_algebra 𝕂 (matrix m m 𝔸) := matrix.linfty_op_normed_algebra, exact (ring.inverse_exp _ A).symm, end lemma exp_zsmul (z : ℤ) (A : matrix m m 𝔸) : exp 𝕂 (z • A) = exp 𝕂 A ^ z := begin obtain ⟨n, rfl | rfl⟩ := z.eq_coe_or_neg, { rw [zpow_coe_nat, coe_nat_zsmul, exp_nsmul] }, { have : is_unit (exp 𝕂 A).det := (matrix.is_unit_iff_is_unit_det _).mp (is_unit_exp _ _), rw [matrix.zpow_neg this, zpow_coe_nat, neg_smul, exp_neg, coe_nat_zsmul, exp_nsmul] }, end lemma exp_conj (U : matrix m m 𝔸) (A : matrix m m 𝔸) (hy : is_unit U) : exp 𝕂 (U ⬝ A ⬝ U⁻¹) = U ⬝ exp 𝕂 A ⬝ U⁻¹ := let ⟨u, hu⟩ := hy in hu ▸ by simpa only [matrix.coe_units_inv] using exp_units_conj 𝕂 u A lemma exp_conj' (U : matrix m m 𝔸) (A : matrix m m 𝔸) (hy : is_unit U) : exp 𝕂 (U⁻¹ ⬝ A ⬝ U) = U⁻¹ ⬝ exp 𝕂 A ⬝ U := let ⟨u, hu⟩ := hy in hu ▸ by simpa only [matrix.coe_units_inv] using exp_units_conj' 𝕂 u A end normed_comm end matrix
873510e827442c81f590055684a364817d2a141f
d1a52c3f208fa42c41df8278c3d280f075eb020c
/stage0/src/Init/Data/List/Control.lean
53474987a6909063b12bbb381aa4e4fdddbb4fce
[ "Apache-2.0", "LLVM-exception", "NCSA", "LGPL-3.0-only", "LicenseRef-scancode-inner-net-2.0", "BSD-3-Clause", "LGPL-2.0-or-later", "Spencer-94", "LGPL-2.1-or-later", "HPND", "LicenseRef-scancode-pcre", "ISC", "LGPL-2.1-only", "LicenseRef-scancode-other-permissive", "SunPro", "CMU-Mach"...
permissive
cipher1024/lean4
6e1f98bb58e7a92b28f5364eb38a14c8d0aae393
69114d3b50806264ef35b57394391c3e738a9822
refs/heads/master
1,642,227,983,603
1,642,011,696,000
1,642,011,696,000
228,607,691
0
0
Apache-2.0
1,576,584,269,000
1,576,584,268,000
null
UTF-8
Lean
false
false
6,210
lean
/- Copyright (c) 2019 Microsoft Corporation. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Leonardo de Moura -/ prelude import Init.Control.Basic import Init.Data.List.Basic namespace List universe u v w u₁ u₂ /- Remark: we can define `mapM`, `mapM₂` and `forM` using `Applicative` instead of `Monad`. Example: ``` def mapM {m : Type u → Type v} [Applicative m] {α : Type w} {β : Type u} (f : α → m β) : List α → m (List β) | [] => pure [] | a::as => List.cons <$> (f a) <*> mapM as ``` However, we consider `f <$> a <*> b` an anti-idiom because the generated code may produce unnecessary closure allocations. Suppose `m` is a `Monad`, and it uses the default implementation for `Applicative.seq`. Then, the compiler expands `f <$> a <*> b <*> c` into something equivalent to ``` (Functor.map f a >>= fun g_1 => Functor.map g_1 b) >>= fun g_2 => Functor.map g_2 c ``` In an ideal world, the compiler may eliminate the temporary closures `g_1` and `g_2` after it inlines `Functor.map` and `Monad.bind`. However, this can easily fail. For example, suppose `Functor.map f a >>= fun g_1 => Functor.map g_1 b` expanded into a match-expression. This is not unreasonable and can happen in many different ways, e.g., we are using a monad that may throw exceptions. Then, the compiler has to decide whether it will create a join-point for the continuation of the match or float it. If the compiler decides to float, then it will be able to eliminate the closures, but it may not be feasible since floating match expressions may produce exponential blowup in the code size. Finally, we rarely use `mapM` with something that is not a `Monad`. Users that want to use `mapM` with `Applicative` should use `mapA` instead. -/ @[specialize] def mapM {m : Type u → Type v} [Monad m] {α : Type w} {β : Type u} (f : α → m β) : List α → m (List β) | [] => pure [] | a::as => return (← f a) :: (← mapM f as) @[specialize] def mapA {m : Type u → Type v} [Applicative m] {α : Type w} {β : Type u} (f : α → m β) : List α → m (List β) | [] => pure [] | a::as => List.cons <$> f a <*> mapA f as @[specialize] protected def forM {m : Type u → Type v} [Monad m] {α : Type w} (as : List α) (f : α → m PUnit) : m PUnit := match as with | [] => pure ⟨⟩ | a :: as => do f a; List.forM as f @[specialize] def forA {m : Type u → Type v} [Applicative m] {α : Type w} (as : List α) (f : α → m PUnit) : m PUnit := match as with | [] => pure ⟨⟩ | a :: as => f a *> forA as f @[specialize] def filterAuxM {m : Type → Type v} [Monad m] {α : Type} (f : α → m Bool) : List α → List α → m (List α) | [], acc => pure acc | h :: t, acc => do let b ← f h filterAuxM f t (cond b (h :: acc) acc) @[inline] def filterM {m : Type → Type v} [Monad m] {α : Type} (f : α → m Bool) (as : List α) : m (List α) := do let as ← filterAuxM f as [] pure as.reverse @[inline] def filterRevM {m : Type → Type v} [Monad m] {α : Type} (f : α → m Bool) (as : List α) : m (List α) := filterAuxM f as.reverse [] @[inline] def filterMapM {m : Type u → Type v} [Monad m] {α β : Type u} (f : α → m (Option β)) (as : List α) : m (List β) := let rec @[specialize] loop | [], bs => pure bs | a :: as, bs => do match (← f a) with | none => loop as bs | some b => loop as (b::bs) loop as.reverse [] @[specialize] protected def foldlM {m : Type u → Type v} [Monad m] {s : Type u} {α : Type w} : (f : s → α → m s) → (init : s) → List α → m s | f, s, [] => pure s | f, s, a :: as => do let s' ← f s a List.foldlM f s' as @[specialize] def foldrM {m : Type u → Type v} [Monad m] {s : Type u} {α : Type w} : (f : α → s → m s) → (init : s) → List α → m s | f, s, [] => pure s | f, s, a :: as => do let s' ← foldrM f s as f a s' @[specialize] def firstM {m : Type u → Type v} [Monad m] [Alternative m] {α : Type w} {β : Type u} (f : α → m β) : List α → m β | [] => failure | a::as => f a <|> firstM f as @[specialize] def anyM {m : Type → Type u} [Monad m] {α : Type v} (f : α → m Bool) : List α → m Bool | [] => pure false | a::as => do match (← f a) with | true => pure true | false => anyM f as @[specialize] def allM {m : Type → Type u} [Monad m] {α : Type v} (f : α → m Bool) : List α → m Bool | [] => pure true | a::as => do match (← f a) with | true => allM f as | false => pure false @[specialize] def findM? {m : Type → Type u} [Monad m] {α : Type} (p : α → m Bool) : List α → m (Option α) | [] => pure none | a::as => do match (← p a) with | true => pure (some a) | false => findM? p as @[specialize] def findSomeM? {m : Type u → Type v} [Monad m] {α : Type w} {β : Type u} (f : α → m (Option β)) : List α → m (Option β) | [] => pure none | a::as => do match (← f a) with | some b => pure (some b) | none => findSomeM? f as @[inline] protected def forIn {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (as : List α) (init : β) (f : α → β → m (ForInStep β)) : m β := let rec @[specialize] loop | [], b => pure b | a::as, b => do match (← f a b) with | ForInStep.done b => pure b | ForInStep.yield b => loop as b loop as init instance : ForIn m (List α) α where forIn := List.forIn @[simp] theorem forIn_nil [Monad m] (f : α → β → m (ForInStep β)) (b : β) : forIn [] b f = pure b := rfl @[simp] theorem forIn_cons [Monad m] (f : α → β → m (ForInStep β)) (a : α) (as : List α) (b : β) : forIn (a::as) b f = f a b >>= fun | ForInStep.done b => pure b | ForInStep.yield b => forIn as b f := rfl instance : ForM m (List α) α where forM := List.forM @[simp] theorem forM_nil [Monad m] (f : α → m PUnit) : forM [] f = pure ⟨⟩ := rfl @[simp] theorem forM_cons [Monad m] (f : α → m PUnit) (a : α) (as : List α) : forM (a::as) f = f a >>= fun _ => forM as f := rfl end List
67f009734cbb773b9bb679c093999f84df579617
8cae430f0a71442d02dbb1cbb14073b31048e4b0
/src/order/category/BddLat.lean
99d624ae156e348d0ad0ad730cd64b589098d66b
[ "Apache-2.0" ]
permissive
leanprover-community/mathlib
56a2cadd17ac88caf4ece0a775932fa26327ba0e
442a83d738cb208d3600056c489be16900ba701d
refs/heads/master
1,693,584,102,358
1,693,471,902,000
1,693,471,902,000
97,922,418
1,595
352
Apache-2.0
1,694,693,445,000
1,500,624,130,000
Lean
UTF-8
Lean
false
false
6,608
lean
/- Copyright (c) 2022 Yaël Dillies. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Yaël Dillies -/ import category_theory.adjunction.opposites import order.category.BddOrd import order.category.Lat import order.category.Semilat /-! # The category of bounded lattices > THIS FILE IS SYNCHRONIZED WITH MATHLIB4. > Any changes to this file require a corresponding PR to mathlib4. This file defines `BddLat`, the category of bounded lattices. In literature, this is sometimes called `Lat`, the category of lattices, because being a lattice is understood to entail having a bottom and a top element. -/ universes u open category_theory /-- The category of bounded lattices with bounded lattice morphisms. -/ structure BddLat := (to_Lat : Lat) [is_bounded_order : bounded_order to_Lat] namespace BddLat instance : has_coe_to_sort BddLat Type* := ⟨λ X, X.to_Lat⟩ instance (X : BddLat) : lattice X := X.to_Lat.str attribute [instance] BddLat.is_bounded_order /-- Construct a bundled `BddLat` from `lattice` + `bounded_order`. -/ def of (α : Type*) [lattice α] [bounded_order α] : BddLat := ⟨⟨α⟩⟩ @[simp] lemma coe_of (α : Type*) [lattice α] [bounded_order α] : ↥(of α) = α := rfl instance : inhabited BddLat := ⟨of punit⟩ instance : large_category.{u} BddLat := { hom := λ X Y, bounded_lattice_hom X Y, id := λ X, bounded_lattice_hom.id X, comp := λ X Y Z f g, g.comp f, id_comp' := λ X Y, bounded_lattice_hom.comp_id, comp_id' := λ X Y, bounded_lattice_hom.id_comp, assoc' := λ W X Y Z _ _ _, bounded_lattice_hom.comp_assoc _ _ _ } instance : concrete_category BddLat := { forget := ⟨coe_sort, λ X Y, coe_fn, λ X, rfl, λ X Y Z f g, rfl⟩, forget_faithful := ⟨λ X Y, by convert fun_like.coe_injective⟩ } instance has_forget_to_BddOrd : has_forget₂ BddLat BddOrd := { forget₂ := { obj := λ X, BddOrd.of X, map := λ X Y, bounded_lattice_hom.to_bounded_order_hom } } instance has_forget_to_Lat : has_forget₂ BddLat Lat := { forget₂ := { obj := λ X, ⟨X⟩, map := λ X Y, bounded_lattice_hom.to_lattice_hom } } instance has_forget_to_SemilatSup : has_forget₂ BddLat SemilatSup := { forget₂ := { obj := λ X, ⟨X⟩, map := λ X Y, bounded_lattice_hom.to_sup_bot_hom } } instance has_forget_to_SemilatInf : has_forget₂ BddLat SemilatInf := { forget₂ := { obj := λ X, ⟨X⟩, map := λ X Y, bounded_lattice_hom.to_inf_top_hom } } @[simp] lemma coe_forget_to_BddOrd (X : BddLat) : ↥((forget₂ BddLat BddOrd).obj X) = ↥X := rfl @[simp] lemma coe_forget_to_Lat (X : BddLat) : ↥((forget₂ BddLat Lat).obj X) = ↥X := rfl @[simp] lemma coe_forget_to_SemilatSup (X : BddLat) : ↥((forget₂ BddLat SemilatSup).obj X) = ↥X := rfl @[simp] lemma coe_forget_to_SemilatInf (X : BddLat) : ↥((forget₂ BddLat SemilatInf).obj X) = ↥X := rfl lemma forget_Lat_PartOrd_eq_forget_BddOrd_PartOrd : forget₂ BddLat Lat ⋙ forget₂ Lat PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl lemma forget_SemilatSup_PartOrd_eq_forget_BddOrd_PartOrd : forget₂ BddLat SemilatSup ⋙ forget₂ SemilatSup PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl lemma forget_SemilatInf_PartOrd_eq_forget_BddOrd_PartOrd : forget₂ BddLat SemilatInf ⋙ forget₂ SemilatInf PartOrd = forget₂ BddLat BddOrd ⋙ forget₂ BddOrd PartOrd := rfl /-- Constructs an equivalence between bounded lattices from an order isomorphism between them. -/ @[simps] def iso.mk {α β : BddLat.{u}} (e : α ≃o β) : α ≅ β := { hom := e, inv := e.symm, hom_inv_id' := by { ext, exact e.symm_apply_apply _ }, inv_hom_id' := by { ext, exact e.apply_symm_apply _ } } /-- `order_dual` as a functor. -/ @[simps] def dual : BddLat ⥤ BddLat := { obj := λ X, of Xᵒᵈ, map := λ X Y, bounded_lattice_hom.dual } /-- The equivalence between `BddLat` and itself induced by `order_dual` both ways. -/ @[simps functor inverse] def dual_equiv : BddLat ≌ BddLat := equivalence.mk dual dual (nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl) (nat_iso.of_components (λ X, iso.mk $ order_iso.dual_dual X) $ λ X Y f, rfl) end BddLat lemma BddLat_dual_comp_forget_to_BddOrd : BddLat.dual ⋙ forget₂ BddLat BddOrd = forget₂ BddLat BddOrd ⋙ BddOrd.dual := rfl lemma BddLat_dual_comp_forget_to_Lat : BddLat.dual ⋙ forget₂ BddLat Lat = forget₂ BddLat Lat ⋙ Lat.dual := rfl lemma BddLat_dual_comp_forget_to_SemilatSup : BddLat.dual ⋙ forget₂ BddLat SemilatSup = forget₂ BddLat SemilatInf ⋙ SemilatInf.dual := rfl lemma BddLat_dual_comp_forget_to_SemilatInf : BddLat.dual ⋙ forget₂ BddLat SemilatInf = forget₂ BddLat SemilatSup ⋙ SemilatSup.dual := rfl /-- The functor that adds a bottom and a top element to a lattice. This is the free functor. -/ def Lat_to_BddLat : Lat.{u} ⥤ BddLat := { obj := λ X, BddLat.of $ with_top $ with_bot X, map := λ X Y, lattice_hom.with_top_with_bot, map_id' := λ X, lattice_hom.with_top_with_bot_id, map_comp' := λ X Y Z _ _, lattice_hom.with_top_with_bot_comp _ _ } /-- `Lat_to_BddLat` is left adjoint to the forgetful functor, meaning it is the free functor from `Lat` to `BddLat`. -/ def Lat_to_BddLat_forget_adjunction : Lat_to_BddLat.{u} ⊣ forget₂ BddLat Lat := adjunction.mk_of_hom_equiv { hom_equiv := λ X Y, { to_fun := λ f, { to_fun := f ∘ some ∘ some, map_sup' := λ a b, (congr_arg f $ by refl).trans (f.map_sup' _ _), map_inf' := λ a b, (congr_arg f $ by refl).trans (f.map_inf' _ _) }, inv_fun := lattice_hom.with_top_with_bot', left_inv := λ f, bounded_lattice_hom.ext $ λ a, match a with | none := f.map_top'.symm | some none := f.map_bot'.symm | some (some a) := rfl end, right_inv := λ f, lattice_hom.ext $ λ a, rfl }, hom_equiv_naturality_left_symm' := λ X Y Z f g, bounded_lattice_hom.ext $ λ a, match a with | none := rfl | some none := rfl | some (some a) := rfl end, hom_equiv_naturality_right' := λ X Y Z f g, lattice_hom.ext $ λ a, rfl } /-- `Lat_to_BddLat` and `order_dual` commute. -/ @[simps] def Lat_to_BddLat_comp_dual_iso_dual_comp_Lat_to_BddLat : (Lat_to_BddLat.{u} ⋙ BddLat.dual) ≅ (Lat.dual ⋙ Lat_to_BddLat) := adjunction.left_adjoint_uniq (Lat_to_BddLat_forget_adjunction.comp BddLat.dual_equiv.to_adjunction) (Lat.dual_equiv.to_adjunction.comp Lat_to_BddLat_forget_adjunction)
ce50e06d77bda022948843b0a54af04665da96da
618003631150032a5676f229d13a079ac875ff77
/src/control/equiv_functor.lean
e0d1cc47e381a78a814b16cdd635593537cac8e3
[ "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
2,355
lean
/- Copyright (c) 2020 Scott Morrison. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Scott Morrison -/ import category_theory.category import data.equiv.functor /-! # Functions functorial with respect to equivalences An `equiv_functor` is a function from `Type → Type` equipped with the additional data of coherently mapping equivalences to equivalences. In categorical language, it is an endofunctor of the "core" of the category `Type`. -/ universes u₀ u₁ u₂ v₀ v₁ v₂ open function /-- An `equiv_functor` is only functorial with respect to equivalences. To construct an `equiv_functor`, it suffices to supply just the function `f α → f β` from an equivalence `α ≃ β`, and then prove the functor laws. It's then a consequence that this function is part of an equivalence, provided by `equiv_functor.map_equiv`. -/ class equiv_functor (f : Type u₀ → Type u₁) := (map : Π {α β}, (α ≃ β) → (f α → f β)) (map_refl' : Π α, map (equiv.refl α) = @id (f α) . obviously) (map_trans' : Π {α β γ} (k : α ≃ β) (h : β ≃ γ), map (k.trans h) = (map h) ∘ (map k) . obviously) restate_axiom equiv_functor.map_refl' restate_axiom equiv_functor.map_trans' attribute [simp] equiv_functor.map_refl namespace equiv_functor section variables (f : Type u₀ → Type u₁) [equiv_functor f] {α β : Type u₀} (e : α ≃ β) /-- An `equiv_functor` in fact takes every equiv to an equiv. -/ def map_equiv : f α ≃ f β := { to_fun := equiv_functor.map e, inv_fun := equiv_functor.map e.symm, left_inv := λ x, begin convert (congr_fun (equiv_functor.map_trans e e.symm) x).symm, simp, end, right_inv := λ y, begin convert (congr_fun (equiv_functor.map_trans e.symm e) y).symm, simp, end, } @[simp] lemma map_equiv_apply (x : f α) : map_equiv f e x = equiv_functor.map e x := rfl @[simp] lemma map_equiv_symm_apply (y : f β) : (map_equiv f e).symm y = equiv_functor.map e.symm y := rfl end @[priority 100] instance of_is_lawful_functor (f : Type u₀ → Type u₁) [functor f] [is_lawful_functor f] : equiv_functor f := { map := λ α β e, functor.map e, map_refl' := λ α, by { ext, apply is_lawful_functor.id_map, }, map_trans' := λ α β γ k h, by { ext x, apply (is_lawful_functor.comp_map k h x), } } end equiv_functor
0a217c93d967426ef285c0b1e7d9c9df9a8c6b27
e030b0259b777fedcdf73dd966f3f1556d392178
/library/init/wf.lean
547a202f10e084b70f989b7d32004371bb875f75
[ "Apache-2.0" ]
permissive
fgdorais/lean
17b46a095b70b21fa0790ce74876658dc5faca06
c3b7c54d7cca7aaa25328f0a5660b6b75fe26055
refs/heads/master
1,611,523,590,686
1,484,412,902,000
1,484,412,902,000
38,489,734
0
0
null
1,435,923,380,000
1,435,923,379,000
null
UTF-8
Lean
false
false
6,820
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 -/ prelude import init.data.nat.basic init.data.prod universe variables u v inductive acc {α : Type u} (r : α → α → Prop) : α → Prop | intro : ∀ x, (∀ y, r y x → acc y) → acc x namespace acc variables {α : Type u} {r : α → α → Prop} def inv {x y : α} (h₁ : acc r x) (h₂ : r y x) : acc r y := acc.rec_on h₁ (λ x₁ ac₁ ih h₂, ac₁ y h₂) h₂ -- dependent elimination for acc attribute [recursor] protected def drec {C : Π (a : α), acc r a → Type v} (h₁ : Π (x : α) (acx : Π (y : α), r y x → acc r y), (Π (y : α) (ryx : r y x), C y (acx y ryx)) → C x (acc.intro x acx)) {a : α} (h₂ : acc r a) : C a h₂ := acc.rec (λ x acx ih h₂, h₁ x acx (λ y ryx, ih y ryx (acx y ryx))) h₂ h₂ end acc inductive well_founded {α : Type u} (r : α → α → Prop) : Prop | intro : (∀ a, acc r a) → well_founded namespace well_founded def apply {α : Type u} {r : α → α → Prop} (wf : well_founded r) : ∀ a, acc r a := take a, well_founded.rec_on wf (λ p, p) a section parameters {α : Type u} {r : α → α → Prop} local infix `≺`:50 := r hypothesis hwf : well_founded r lemma recursion {C : α → Type v} (a : α) (h : Π x, (Π y, y ≺ x → C y) → C x) : C a := acc.rec_on (apply hwf a) (λ x₁ ac₁ ih, h x₁ ih) lemma induction {C : α → Prop} (a : α) (h : ∀ x, (∀ y, y ≺ x → C y) → C x) : C a := recursion a h variable {C : α → Type v} variable F : Π x, (Π y, y ≺ x → C y) → C x def fix_F (x : α) (a : acc r x) : C x := acc.rec_on a (λ x₁ ac₁ ih, F x₁ ih) lemma fix_F_eq (x : α) (r : acc r x) : fix_F F x r = F x (λ (y : α) (p : y ≺ x), fix_F F y (acc.inv r p)) := acc.drec (λ x r ih, rfl) r end variables {α : Type u} {C : α → Type v} {r : α → α → Prop} -- Well-founded fixpoint def fix (hwf : well_founded r) (F : Π x, (Π y, r y x → C y) → C x) (x : α) : C x := fix_F F x (apply hwf x) -- Well-founded fixpoint satisfies fixpoint equation lemma fix_eq (hwf : well_founded r) (F : Π x, (Π y, r y x → C y) → C x) (x : α) : fix hwf F x = F x (λ y h, fix hwf F y) := fix_F_eq F x (apply hwf x) end well_founded open well_founded -- Empty relation is well-founded def empty_wf {α : Type u} : well_founded empty_relation := well_founded.intro (λ (a : α), acc.intro a (λ (b : α) (lt : false), false.rec _ lt)) -- Subrelation of a well-founded relation is well-founded namespace subrelation section parameters {α : Type u} {r Q : α → α → Prop} parameters (h₁ : subrelation Q r) parameters (h₂ : well_founded r) def accessible {a : α} (ac : acc r a) : acc Q a := acc.rec_on ac (λ x ax ih, acc.intro x (λ (y : α) (lt : Q y x), ih y (h₁ lt))) def wf : well_founded Q := ⟨λ a, accessible (apply h₂ a)⟩ end end subrelation -- The inverse image of a well-founded relation is well-founded namespace inv_image section parameters {α : Type u} {β : Type v} {r : β → β → Prop} parameters (f : α → β) parameters (h : well_founded r) private def acc_aux {b : β} (ac : acc r b) : ∀ (x : α), f x = b → acc (inv_image r f) x := acc.rec_on ac (λ x acx ih z e, acc.intro z (λ y lt, eq.rec_on e (λ acx ih, ih (f y) lt y rfl) acx ih)) def accessible {a : α} (ac : acc r (f a)) : acc (inv_image r f) a := acc_aux ac a rfl def wf : well_founded (inv_image r f) := ⟨λ a, accessible (apply h (f a))⟩ end end inv_image -- The transitive closure of a well-founded relation is well-founded namespace tc section parameters {α : Type u} {r : α → α → Prop} local notation `r⁺` := tc r def accessible {z : α} (ac : acc r z) : acc (tc r) z := acc.rec_on ac (λ x acx ih, acc.intro x (λ y rel, tc.rec_on rel (λ a b rab acx ih, ih a rab) (λ a b c rab rbc ih₁ ih₂ acx ih, acc.inv (ih₂ acx ih) rab) acx ih)) def wf (h : well_founded r) : well_founded r⁺ := ⟨λ a, accessible (apply h a)⟩ end end tc -- less-than is well-founded def nat.lt_wf : well_founded nat.lt := ⟨nat.rec (acc.intro 0 (λ n h, absurd h (nat.not_lt_zero n))) (λ n ih, acc.intro (nat.succ n) (λ m h, or.elim (nat.eq_or_lt_of_le (nat.le_of_succ_le_succ h)) (λ e, eq.substr e ih) (acc.inv ih)))⟩ def measure {α : Type u} : (α → ℕ) → α → α → Prop := inv_image lt def measure_wf {α : Type u} (f : α → ℕ) : well_founded (measure f) := inv_image.wf f nat.lt_wf namespace prod open well_founded section variables {α : Type u} {β : Type v} variable (ra : α → α → Prop) variable (rb : β → β → Prop) -- Lexicographical order based on ra and rb inductive lex : α × β → α × β → Prop | left : ∀ {a₁} b₁ {a₂} b₂, ra a₁ a₂ → lex (a₁, b₁) (a₂, b₂) | right : ∀ a {b₁ b₂}, rb b₁ b₂ → lex (a, b₁) (a, b₂) -- relational product based on ra and rb inductive rprod : α × β → α × β → Prop | intro : ∀ {a₁ b₁ a₂ b₂}, ra a₁ a₂ → rb b₁ b₂ → rprod (a₁, b₁) (a₂, b₂) end section parameters {α : Type u} {β : Type v} parameters {ra : α → α → Prop} {rb : β → β → Prop} local infix `≺`:50 := lex ra rb def lex_accessible {a} (aca : acc ra a) (acb : ∀ b, acc rb b): ∀ b, acc (lex ra rb) (a, b) := acc.rec_on aca (λ xa aca iha b, acc.rec_on (acb b) (λ xb acb ihb, acc.intro (xa, xb) (λ p lt, have aux : xa = xa → xb = xb → acc (lex ra rb) p, from @prod.lex.rec_on α β ra rb (λ p₁ p₂, fst p₂ = xa → snd p₂ = xb → acc (lex ra rb) p₁) p (xa, xb) lt (λ a₁ b₁ a₂ b₂ h (eq₂ : a₂ = xa) (eq₃ : b₂ = xb), iha a₁ (eq.rec_on eq₂ h) b₁) (λ a b₁ b₂ h (eq₂ : a = xa) (eq₃ : b₂ = xb), eq.rec_on eq₂~>symm (ihb b₁ (eq.rec_on eq₃ h))), aux rfl rfl))) -- The lexicographical order of well founded relations is well-founded def lex_wf (ha : well_founded ra) (hb : well_founded rb) : well_founded (lex ra rb) := ⟨λ p, destruct p (λ a b, lex_accessible (apply ha a) (well_founded.apply hb) b)⟩ -- relational product is a subrelation of the lex def rprod_sub_lex : ∀ a b, rprod ra rb a b → lex ra rb a b := λ a b h, prod.rprod.rec_on h (λ a₁ b₁ a₂ b₂ h₁ h₂, lex.left rb b₁ b₂ h₁) -- The relational product of well founded relations is well-founded def rprod_wf (ha : well_founded ra) (hb : well_founded rb) : well_founded (rprod ra rb) := subrelation.wf (rprod_sub_lex) (lex_wf ha hb) end end prod
56928b654748d5543e9af35beb7154f5e04685cd
05b503addd423dd68145d68b8cde5cd595d74365
/src/measure_theory/measure_space.lean
a88871bc3ad2bbc5363f9c2b77174a3aa18e1a39
[ "Apache-2.0" ]
permissive
aestriplex/mathlib
77513ff2b176d74a3bec114f33b519069788811d
e2fa8b2b1b732d7c25119229e3cdfba8370cb00f
refs/heads/master
1,621,969,960,692
1,586,279,279,000
1,586,279,279,000
null
0
0
null
null
null
null
UTF-8
Lean
false
false
36,306
lean
/- Copyright (c) 2017 Johannes Hölzl. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Johannes Hölzl, Mario Carneiro -/ import data.set.lattice data.set.finite import topology.instances.ennreal measure_theory.outer_measure /-! # Measure spaces Measures are restricted to a measurable space (associated by the type class `measurable_space`). This allows us to prove equalities between measures by restricting to a generating set of the measurable space. On the other hand, the `μ.measure s` projection (i.e. the measure of `s` on the measure space `μ`) is the _outer_ measure generated by `μ`. This gives us a unrestricted monotonicity rule and it is somehow well-behaved on non-measurable sets. This allows us for the `lebesgue` measure space to have the `borel` measurable space, but still be a complete measure. -/ noncomputable theory open classical set filter finset function open_locale classical topological_space universes u v w x namespace measure_theory section of_measurable parameters {α : Type*} [measurable_space α] parameters (m : Π (s : set α), is_measurable s → ennreal) parameters (m0 : m ∅ is_measurable.empty = 0) include m0 /-- Measure projection which is ∞ for non-measurable sets. `measure'` is mainly used to derive the outer measure, for the main `measure` projection. -/ def measure' (s : set α) : ennreal := ⨅ h : is_measurable s, m s h lemma measure'_eq {s} (h : is_measurable s) : measure' s = m s h := by simp [measure', h] lemma measure'_empty : measure' ∅ = 0 := (measure'_eq is_measurable.empty).trans m0 lemma measure'_Union_nat {f : ℕ → set α} (hm : ∀i, is_measurable (f i)) (mU : m (⋃i, f i) (is_measurable.Union hm) = (∑i, m (f i) (hm i))) : measure' (⋃i, f i) = (∑i, measure' (f i)) := (measure'_eq _).trans $ mU.trans $ by congr; funext i; rw measure'_eq /-- outer measure of a measure -/ def outer_measure' : outer_measure α := outer_measure.of_function measure' measure'_empty lemma measure'_Union_le_tsum_nat' (mU : ∀ {f : ℕ → set α} (hm : ∀i, is_measurable (f i)), m (⋃i, f i) (is_measurable.Union hm) ≤ (∑i, m (f i) (hm i))) (s : ℕ → set α) : measure' (⋃i, s i) ≤ (∑i, measure' (s i)) := begin by_cases h : ∀i, is_measurable (s i), { rw [measure'_eq _ _ (is_measurable.Union h), congr_arg tsum _], {apply mU h}, funext i, apply measure'_eq _ _ (h i) }, { cases not_forall.1 h with i hi, exact le_trans (le_infi $ λ h, hi.elim h) (ennreal.le_tsum i) } end parameter (mU : ∀ {f : ℕ → set α} (hm : ∀i, is_measurable (f i)), pairwise (disjoint on f) → m (⋃i, f i) (is_measurable.Union hm) = (∑i, m (f i) (hm i))) include mU lemma measure'_Union {β} [encodable β] {f : β → set α} (hd : pairwise (disjoint on f)) (hm : ∀i, is_measurable (f i)) : measure' (⋃i, f i) = (∑i, measure' (f i)) := begin rw [encodable.Union_decode2, outer_measure.Union_aux], { exact measure'_Union_nat _ _ (λ n, encodable.Union_decode2_cases is_measurable.empty hm) (mU _ (measurable_space.Union_decode2_disjoint_on hd)) }, { apply measure'_empty }, end lemma measure'_union {s₁ s₂ : set α} (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : measure' (s₁ ∪ s₂) = measure' s₁ + measure' s₂ := begin rw [union_eq_Union, measure'_Union _ _ @mU (pairwise_disjoint_on_bool.2 hd) (bool.forall_bool.2 ⟨h₂, h₁⟩), tsum_fintype], change _+_ = _, simp end lemma measure'_mono {s₁ s₂ : set α} (h₁ : is_measurable s₁) (hs : s₁ ⊆ s₂) : measure' s₁ ≤ measure' s₂ := le_infi $ λ h₂, begin have := measure'_union _ _ @mU disjoint_diff h₁ (h₂.diff h₁), rw union_diff_cancel hs at this, rw ← measure'_eq m m0 _, exact le_iff_exists_add.2 ⟨_, this⟩ end lemma measure'_Union_le_tsum_nat : ∀ (s : ℕ → set α), measure' (⋃i, s i) ≤ (∑i, measure' (s i)) := measure'_Union_le_tsum_nat' $ λ f h, begin simp [Union_disjointed.symm] {single_pass := tt}, rw [mU (is_measurable.disjointed h) disjoint_disjointed], refine ennreal.tsum_le_tsum (λ i, _), rw [← measure'_eq m m0, ← measure'_eq m m0], exact measure'_mono _ _ @mU (is_measurable.disjointed h _) (inter_subset_left _ _) end lemma outer_measure'_eq {s : set α} (hs : is_measurable s) : outer_measure' s = m s hs := by rw ← measure'_eq m m0 hs; exact (le_antisymm (outer_measure.of_function_le _ _ _) $ le_infi $ λ f, le_infi $ λ hf, le_trans (measure'_mono _ _ @mU hs hf) $ measure'_Union_le_tsum_nat _ _ @mU _) lemma outer_measure'_eq_measure' {s : set α} (hs : is_measurable s) : outer_measure' s = measure' s := by rw [measure'_eq m m0 hs, outer_measure'_eq m m0 @mU hs] end of_measurable namespace outer_measure variables {α : Type*} [measurable_space α] (m : outer_measure α) def trim : outer_measure α := outer_measure' (λ s _, m s) m.empty theorem trim_ge : m ≤ m.trim := λ s, le_infi $ λ f, le_infi $ λ hs, le_trans (m.mono hs) $ le_trans (m.Union_nat f) $ ennreal.tsum_le_tsum $ λ i, le_infi $ λ hf, le_refl _ theorem trim_eq {s : set α} (hs : is_measurable s) : m.trim s = m s := le_antisymm (le_trans (of_function_le _ _ _) (infi_le _ hs)) (trim_ge _ _) theorem trim_congr {m₁ m₂ : outer_measure α} (H : ∀ {s : set α}, is_measurable s → m₁ s = m₂ s) : m₁.trim = m₂.trim := by unfold trim; congr; funext s hs; exact H hs theorem trim_le_trim {m₁ m₂ : outer_measure α} (H : m₁ ≤ m₂) : m₁.trim ≤ m₂.trim := λ s, infi_le_infi $ λ f, infi_le_infi $ λ hs, ennreal.tsum_le_tsum $ λ b, infi_le_infi $ λ hf, H _ theorem le_trim_iff {m₁ m₂ : outer_measure α} : m₁ ≤ m₂.trim ↔ ∀ s, is_measurable s → m₁ s ≤ m₂ s := le_of_function.trans $ forall_congr $ λ s, le_infi_iff theorem trim_eq_infi (s : set α) : m.trim s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), m t := begin refine le_antisymm (le_infi $ λ t, le_infi $ λ st, le_infi $ λ ht, _) (le_infi $ λ f, le_infi $ λ hf, _), { rw ← trim_eq m ht, exact (trim m).mono st }, { by_cases h : ∀i, is_measurable (f i), { refine infi_le_of_le _ (infi_le_of_le hf $ infi_le_of_le (is_measurable.Union h) _), rw congr_arg tsum _, {exact m.Union_nat _}, funext i, exact measure'_eq _ _ (h i) }, { cases not_forall.1 h with i hi, exact le_trans (le_infi $ λ h, hi.elim h) (ennreal.le_tsum i) } } end theorem trim_eq_infi' (s : set α) : m.trim s = ⨅ t : {t // s ⊆ t ∧ is_measurable t}, m t.1 := by simp [infi_subtype, infi_and, trim_eq_infi] theorem trim_trim (m : outer_measure α) : m.trim.trim = m.trim := le_antisymm (le_trim_iff.2 $ λ s hs, by simp [trim_eq _ hs, le_refl]) (trim_ge _) theorem trim_zero : (0 : outer_measure α).trim = 0 := ext $ λ s, le_antisymm (le_trans ((trim 0).mono (subset_univ s)) $ le_of_eq $ trim_eq _ is_measurable.univ) (zero_le _) theorem trim_add (m₁ m₂ : outer_measure α) : (m₁ + m₂).trim = m₁.trim + m₂.trim := ext $ λ s, begin simp [trim_eq_infi'], rw ennreal.infi_add_infi, rintro ⟨t₁, st₁, ht₁⟩ ⟨t₂, st₂, ht₂⟩, exact ⟨⟨_, subset_inter_iff.2 ⟨st₁, st₂⟩, ht₁.inter ht₂⟩, add_le_add' (m₁.mono' (inter_subset_left _ _)) (m₂.mono' (inter_subset_right _ _))⟩, end theorem trim_sum_ge {ι} (m : ι → outer_measure α) : sum (λ i, (m i).trim) ≤ (sum m).trim := λ s, by simp [trim_eq_infi]; exact λ t st ht, ennreal.tsum_le_tsum (λ i, infi_le_of_le t $ infi_le_of_le st $ infi_le _ ht) end outer_measure structure measure (α : Type*) [measurable_space α] extends outer_measure α := (m_Union {f : ℕ → set α} : (∀i, is_measurable (f i)) → pairwise (disjoint on f) → measure_of (⋃i, f i) = (∑i, measure_of (f i))) (trimmed : to_outer_measure.trim = to_outer_measure) /-- Measure projections for a measure space. For measurable sets this returns the measure assigned by the `measure_of` field in `measure`. But we can extend this to _all_ sets, but using the outer measure. This gives us monotonicity and subadditivity for all sets. -/ instance measure.has_coe_to_fun {α} [measurable_space α] : has_coe_to_fun (measure α) := ⟨λ _, set α → ennreal, λ m, m.to_outer_measure⟩ namespace measure def of_measurable {α} [measurable_space α] (m : Π (s : set α), is_measurable s → ennreal) (m0 : m ∅ is_measurable.empty = 0) (mU : ∀ {f : ℕ → set α} (h : ∀i, is_measurable (f i)), pairwise (disjoint on f) → m (⋃i, f i) (is_measurable.Union h) = (∑i, m (f i) (h i))) : measure α := { m_Union := λ f hf hd, show outer_measure' m m0 (Union f) = ∑ i, outer_measure' m m0 (f i), begin rw [outer_measure'_eq m m0 @mU, mU hf hd], congr, funext n, rw outer_measure'_eq m m0 @mU end, trimmed := show (outer_measure' m m0).trim = outer_measure' m m0, begin unfold outer_measure.trim, congr, funext s hs, exact outer_measure'_eq m m0 @mU hs end, ..outer_measure' m m0 } lemma of_measurable_apply {α} [measurable_space α] {m : Π (s : set α), is_measurable s → ennreal} {m0 : m ∅ is_measurable.empty = 0} {mU : ∀ {f : ℕ → set α} (h : ∀i, is_measurable (f i)), pairwise (disjoint on f) → m (⋃i, f i) (is_measurable.Union h) = (∑i, m (f i) (h i))} (s : set α) (hs : is_measurable s) : of_measurable m m0 @mU s = m s hs := outer_measure'_eq m m0 @mU hs @[ext] lemma ext {α} [measurable_space α] : ∀ {μ₁ μ₂ : measure α}, (∀s, is_measurable s → μ₁ s = μ₂ s) → μ₁ = μ₂ | ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h := by congr; rw [← h₁, ← h₂]; exact outer_measure.trim_congr h end measure section variables {α : Type*} {β : Type*} [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ : set α} @[simp] lemma to_outer_measure_apply (s) : μ.to_outer_measure s = μ s := rfl lemma measure_eq_trim (s) : μ s = μ.to_outer_measure.trim s := by rw μ.trimmed; refl lemma measure_eq_infi (s) : μ s = ⨅ t (st : s ⊆ t) (ht : is_measurable t), μ t := by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl lemma measure_eq_outer_measure' : μ s = outer_measure' (λ s _, μ s) μ.empty s := measure_eq_trim _ lemma to_outer_measure_eq_outer_measure' : μ.to_outer_measure = outer_measure' (λ s _, μ s) μ.empty := μ.trimmed.symm lemma measure_eq_measure' (hs : is_measurable s) : μ s = measure' (λ s _, μ s) μ.empty s := by rw [measure_eq_outer_measure', outer_measure'_eq_measure' (λ s _, μ s) _ μ.m_Union hs] @[simp] lemma measure_empty : μ ∅ = 0 := μ.empty lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h lemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 := by rw [← le_zero_iff_eq, ← h₂]; exact measure_mono h lemma exists_is_measurable_superset_of_measure_eq_zero {s : set α} (h : μ s = 0) : ∃t, s ⊆ t ∧ is_measurable t ∧ μ t = 0 := begin rw [measure_eq_infi] at h, have h := (infi_eq_bot _).1 h, choose t ht using show ∀n:ℕ, ∃t, s ⊆ t ∧ is_measurable t ∧ μ t < n⁻¹, { assume n, have : (0 : ennreal) < n⁻¹ := (zero_lt_iff_ne_zero.2 $ ennreal.inv_ne_zero.2 $ ennreal.nat_ne_top _), rcases h _ this with ⟨t, ht⟩, use [t], simpa [(>), infi_lt_iff, -add_comm] using ht }, refine ⟨⋂n, t n, subset_Inter (λn, (ht n).1), is_measurable.Inter (λn, (ht n).2.1), _⟩, refine eq_of_le_of_forall_le_of_dense bot_le (assume r hr, _), rcases ennreal.exists_inv_nat_lt (ne_of_gt hr) with ⟨n, hn⟩, calc μ (⋂n, t n) ≤ μ (t n) : measure_mono (Inter_subset _ _) ... ≤ n⁻¹ : le_of_lt (ht n).2.2 ... ≤ r : le_of_lt hn end theorem measure_Union_le {β} [encodable β] (s : β → set α) : μ (⋃i, s i) ≤ (∑i, μ (s i)) := μ.to_outer_measure.Union _ lemma measure_Union_null {β} [encodable β] {s : β → set α} : (∀ i, μ (s i) = 0) → μ (⋃i, s i) = 0 := μ.to_outer_measure.Union_null theorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ := μ.to_outer_measure.union _ _ lemma measure_union_null {s₁ s₂ : set α} : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 := μ.to_outer_measure.union_null lemma measure_Union {β} [encodable β] {f : β → set α} (hn : pairwise (disjoint on f)) (h : ∀i, is_measurable (f i)) : μ (⋃i, f i) = (∑i, μ (f i)) := by rw [measure_eq_measure' (is_measurable.Union h), measure'_Union (λ s _, μ s) _ μ.m_Union hn h]; simp [measure_eq_measure', h] lemma measure_union (hd : disjoint s₁ s₂) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : μ (s₁ ∪ s₂) = μ s₁ + μ s₂ := by rw [measure_eq_measure' (h₁.union h₂), measure'_union (λ s _, μ s) _ μ.m_Union hd h₁ h₂]; simp [measure_eq_measure', h₁, h₂] lemma measure_bUnion {s : set β} {f : β → set α} (hs : countable s) (hd : pairwise_on s (disjoint on f)) (h : ∀b∈s, is_measurable (f b)) : μ (⋃b∈s, f b) = ∑p:s, μ (f p.1) := begin haveI := hs.to_encodable, rw [← measure_Union, bUnion_eq_Union], { rintro ⟨i, hi⟩ ⟨j, hj⟩ ij x ⟨h₁, h₂⟩, exact hd i hi j hj (mt subtype.eq' ij:_) ⟨h₁, h₂⟩ }, { simpa } end lemma measure_sUnion {S : set (set α)} (hs : countable S) (hd : pairwise_on S disjoint) (h : ∀s∈S, is_measurable s) : μ (⋃₀ S) = ∑s:S, μ s.1 := by rw [sUnion_eq_bUnion, measure_bUnion hs hd h] lemma measure_diff {s₁ s₂ : set α} (h : s₂ ⊆ s₁) (h₁ : is_measurable s₁) (h₂ : is_measurable s₂) (h_fin : μ s₂ < ⊤) : μ (s₁ \ s₂) = μ s₁ - μ s₂ := begin refine (ennreal.add_sub_self' h_fin).symm.trans _, rw [← measure_union disjoint_diff h₂ (h₁.diff h₂), union_diff_cancel h] end lemma measure_Union_eq_supr_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : monotone s) : μ (⋃i, s i) = (⨆i, μ (s i)) := begin refine le_antisymm _ (supr_le $ λ i, measure_mono $ subset_Union _ _), rw [← Union_disjointed, measure_Union disjoint_disjointed (is_measurable.disjointed h), ennreal.tsum_eq_supr_nat], refine supr_le (λ n, _), cases n, {apply zero_le _}, suffices : (finset.range n.succ).sum (λ i, μ (disjointed s i)) = μ (s n), { rw this, exact le_supr _ n }, rw [← Union_disjointed_of_mono hs, measure_Union, tsum_eq_sum], { apply sum_congr rfl, intros i hi, simp [finset.mem_range.1 hi] }, { intros i hi, simp [mt finset.mem_range.2 hi] }, { rintro i j ij x ⟨⟨_, ⟨_, rfl⟩, h₁⟩, ⟨_, ⟨_, rfl⟩, h₂⟩⟩, exact disjoint_disjointed i j ij ⟨h₁, h₂⟩ }, { intro i, by_cases h' : i < n.succ; simp [h', is_measurable.empty], apply is_measurable.disjointed h } end lemma measure_Inter_eq_infi_nat {s : ℕ → set α} (h : ∀i, is_measurable (s i)) (hs : ∀i j, i ≤ j → s j ⊆ s i) (hfin : ∃i, μ (s i) < ⊤) : μ (⋂i, s i) = (⨅i, μ (s i)) := begin rcases hfin with ⟨k, hk⟩, rw [← ennreal.sub_sub_cancel (by exact hk) (infi_le _ k), ennreal.sub_infi, ← ennreal.sub_sub_cancel (by exact hk) (measure_mono (Inter_subset _ k)), ← measure_diff (Inter_subset _ k) (h k) (is_measurable.Inter h) (lt_of_le_of_lt (measure_mono (Inter_subset _ k)) hk), diff_Inter, measure_Union_eq_supr_nat], { congr, funext i, cases le_total k i with ik ik, { exact measure_diff (hs _ _ ik) (h k) (h i) (lt_of_le_of_lt (measure_mono (hs _ _ ik)) hk) }, { rw [diff_eq_empty.2 (hs _ _ ik), measure_empty, ennreal.sub_eq_zero_of_le (measure_mono (hs _ _ ik))] } }, { exact λ i, (h k).diff (h i) }, { exact λ i j ij, diff_subset_diff_right (hs _ _ ij) } end lemma measure_eq_inter_diff {μ : measure α} {s t : set α} (hs : is_measurable s) (ht : is_measurable t) : μ s = μ (s ∩ t) + μ (s \ t) := have hd : disjoint (s ∩ t) (s \ t) := assume a ⟨⟨_, hs⟩, _, hns⟩, hns hs , by rw [← measure_union hd (hs.inter ht) (hs.diff ht), inter_union_diff s t] lemma tendsto_measure_Union {μ : measure α} {s : ℕ → set α} (hs : ∀n, is_measurable (s n)) (hm : monotone s) : tendsto (μ ∘ s) at_top (𝓝 (μ (⋃n, s n))) := begin rw measure_Union_eq_supr_nat hs hm, exact tendsto_at_top_supr_nat (μ ∘ s) (assume n m hnm, measure_mono $ hm $ hnm) end lemma tendsto_measure_Inter {μ : measure α} {s : ℕ → set α} (hs : ∀n, is_measurable (s n)) (hm : ∀n m, n ≤ m → s m ⊆ s n) (hf : ∃i, μ (s i) < ⊤) : tendsto (μ ∘ s) at_top (𝓝 (μ (⋂n, s n))) := begin rw measure_Inter_eq_infi_nat hs hm hf, exact tendsto_at_top_infi_nat (μ ∘ s) (assume n m hnm, measure_mono $ hm _ _ $ hnm), end end def outer_measure.to_measure {α} (m : outer_measure α) [ms : measurable_space α] (h : ms ≤ m.caratheodory) : measure α := measure.of_measurable (λ s _, m s) m.empty (λ f hf hd, m.Union_eq_of_caratheodory (λ i, h _ (hf i)) hd) lemma le_to_outer_measure_caratheodory {α} [ms : measurable_space α] (μ : measure α) : ms ≤ μ.to_outer_measure.caratheodory := begin assume s hs, rw to_outer_measure_eq_outer_measure', refine outer_measure.caratheodory_is_measurable (λ t, le_infi $ λ ht, _), rw [← measure_eq_measure' (ht.inter hs), ← measure_eq_measure' (ht.diff hs), ← measure_union _ (ht.inter hs) (ht.diff hs), inter_union_diff], exact le_refl _, exact λ x ⟨⟨_, h₁⟩, _, h₂⟩, h₂ h₁ end lemma to_measure_to_outer_measure {α} (m : outer_measure α) [ms : measurable_space α] (h : ms ≤ m.caratheodory) : (m.to_measure h).to_outer_measure = m.trim := rfl @[simp] lemma to_measure_apply {α} (m : outer_measure α) [ms : measurable_space α] (h : ms ≤ m.caratheodory) {s : set α} (hs : is_measurable s) : m.to_measure h s = m s := m.trim_eq hs lemma to_outer_measure_to_measure {α : Type*} [ms : measurable_space α] {μ : measure α} : μ.to_outer_measure.to_measure (le_to_outer_measure_caratheodory _) = μ := measure.ext $ λ s, μ.to_outer_measure.trim_eq namespace measure variables {α : Type*} {β : Type*} {γ : Type*} [measurable_space α] [measurable_space β] [measurable_space γ] instance : has_zero (measure α) := ⟨{ to_outer_measure := 0, m_Union := λ f hf hd, tsum_zero.symm, trimmed := outer_measure.trim_zero }⟩ @[simp] theorem zero_to_outer_measure : (0 : measure α).to_outer_measure = 0 := rfl @[simp] theorem zero_apply (s : set α) : (0 : measure α) s = 0 := rfl instance : inhabited (measure α) := ⟨0⟩ instance : has_add (measure α) := ⟨λμ₁ μ₂, { to_outer_measure := μ₁.to_outer_measure + μ₂.to_outer_measure, m_Union := λs hs hd, show μ₁ (⋃ i, s i) + μ₂ (⋃ i, s i) = ∑ i, μ₁ (s i) + μ₂ (s i), by rw [ennreal.tsum_add, measure_Union hd hs, measure_Union hd hs], trimmed := by rw [outer_measure.trim_add, μ₁.trimmed, μ₂.trimmed] }⟩ @[simp] theorem add_to_outer_measure (μ₁ μ₂ : measure α) : (μ₁ + μ₂).to_outer_measure = μ₁.to_outer_measure + μ₂.to_outer_measure := rfl @[simp] theorem add_apply (μ₁ μ₂ : measure α) (s : set α) : (μ₁ + μ₂) s = μ₁ s + μ₂ s := rfl instance add_comm_monoid : add_comm_monoid (measure α) := { zero := 0, add := (+), add_assoc := assume a b c, ext $ assume s hs, add_assoc _ _ _, add_comm := assume a b, ext $ assume s hs, add_comm _ _, zero_add := assume a, ext $ assume s hs, zero_add _, add_zero := assume a, ext $ assume s hs, add_zero _ } instance : partial_order (measure α) := { le := λm₁ m₂, ∀ s, is_measurable s → m₁ s ≤ m₂ s, le_refl := assume m s hs, le_refl _, le_trans := assume m₁ m₂ m₃ h₁ h₂ s hs, le_trans (h₁ s hs) (h₂ s hs), le_antisymm := assume m₁ m₂ h₁ h₂, ext $ assume s hs, le_antisymm (h₁ s hs) (h₂ s hs) } theorem le_iff {μ₁ μ₂ : measure α} : μ₁ ≤ μ₂ ↔ ∀ s, is_measurable s → μ₁ s ≤ μ₂ s := iff.rfl theorem to_outer_measure_le {μ₁ μ₂ : measure α} : μ₁.to_outer_measure ≤ μ₂.to_outer_measure ↔ μ₁ ≤ μ₂ := by rw [← μ₂.trimmed, outer_measure.le_trim_iff]; refl theorem le_iff' {μ₁ μ₂ : measure α} : μ₁ ≤ μ₂ ↔ ∀ s, μ₁ s ≤ μ₂ s := to_outer_measure_le.symm section variables {m : set (measure α)} {μ : measure α} lemma Inf_caratheodory (s : set α) (hs : is_measurable s) : (Inf (measure.to_outer_measure '' m)).caratheodory.is_measurable s := begin rw [outer_measure.Inf_eq_of_function_Inf_gen], refine outer_measure.caratheodory_is_measurable (assume t, _), cases t.eq_empty_or_nonempty with ht ht, by simp [ht], simp only [outer_measure.Inf_gen_nonempty1 _ _ ht, le_infi_iff, ball_image_iff, to_outer_measure_apply, measure_eq_infi t], assume μ hμ u htu hu, have hm : ∀{s t}, s ⊆ t → outer_measure.Inf_gen (to_outer_measure '' m) s ≤ μ t, { assume s t hst, rw [outer_measure.Inf_gen_nonempty2 _ _ (mem_image_of_mem _ hμ)], refine infi_le_of_le (μ.to_outer_measure) (infi_le_of_le (mem_image_of_mem _ hμ) _), rw [to_outer_measure_apply], refine measure_mono hst }, rw [measure_eq_inter_diff hu hs], refine add_le_add' (hm $ inter_subset_inter_left _ htu) (hm $ diff_subset_diff_left htu) end instance : has_Inf (measure α) := ⟨λm, (Inf (to_outer_measure '' m)).to_measure $ Inf_caratheodory⟩ lemma Inf_apply {m : set (measure α)} {s : set α} (hs : is_measurable s) : Inf m s = Inf (to_outer_measure '' m) s := to_measure_apply _ _ hs private lemma Inf_le (h : μ ∈ m) : Inf m ≤ μ := have Inf (to_outer_measure '' m) ≤ μ.to_outer_measure := Inf_le (mem_image_of_mem _ h), assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s private lemma le_Inf (h : ∀μ' ∈ m, μ ≤ μ') : μ ≤ Inf m := have μ.to_outer_measure ≤ Inf (to_outer_measure '' m) := le_Inf $ ball_image_of_ball $ assume μ hμ, to_outer_measure_le.2 $ h _ hμ, assume s hs, by rw [Inf_apply hs, ← to_outer_measure_apply]; exact this s instance : has_Sup (measure α) := ⟨λs, Inf {μ' | ∀μ∈s, μ ≤ μ' }⟩ private lemma le_Sup (h : μ ∈ m) : μ ≤ Sup m := le_Inf $ assume μ' h', h' _ h private lemma Sup_le (h : ∀μ' ∈ m, μ' ≤ μ) : Sup m ≤ μ := Inf_le h instance : order_bot (measure α) := { bot := 0, bot_le := assume a s hs, bot_le, .. measure.partial_order } instance : order_top (measure α) := { top := (⊤ : outer_measure α).to_measure (by rw [outer_measure.top_caratheodory]; exact le_top), le_top := assume a s hs, by cases s.eq_empty_or_nonempty with h h; simp [h, to_measure_apply ⊤ _ hs, outer_measure.top_apply], .. measure.partial_order } instance : complete_lattice (measure α) := { Inf := Inf, Sup := Sup, inf := λa b, Inf {a, b}, sup := λa b, Sup {a, b}, le_Sup := assume s μ h, le_Sup h, Sup_le := assume s μ h, Sup_le h, Inf_le := assume s μ h, Inf_le h, le_Inf := assume s μ h, le_Inf h, le_sup_left := assume a b, le_Sup $ by simp, le_sup_right := assume a b, le_Sup $ by simp, sup_le := assume a b c hac hbc, Sup_le $ by simp [*, or_imp_distrib] {contextual := tt}, inf_le_left := assume a b, Inf_le $ by simp, inf_le_right := assume a b, Inf_le $ by simp, le_inf := assume a b c hac hbc, le_Inf $ by simp [*, or_imp_distrib] {contextual := tt}, .. measure.partial_order, .. measure.order_top, .. measure.order_bot } end def map (f : α → β) (μ : measure α) : measure β := if hf : measurable f then (μ.to_outer_measure.map f).to_measure $ λ s hs t, le_to_outer_measure_caratheodory μ _ (hf _ hs) (f ⁻¹' t) else 0 variables {μ ν : measure α} @[simp] theorem map_apply {f : α → β} (hf : measurable f) {s : set β} (hs : is_measurable s) : (map f μ : measure β) s = μ (f ⁻¹' s) := by rw [map, dif_pos hf, to_measure_apply _ _ hs]; refl @[simp] lemma map_id : map id μ = μ := ext $ λ s, map_apply measurable_id lemma map_map {g : β → γ} {f : α → β} (hg : measurable g) (hf : measurable f) : map g (map f μ) = map (g ∘ f) μ := ext $ λ s hs, by simp [hf, hg, hs, hg.preimage hs, hg.comp hf]; rw ← preimage_comp /-- The dirac measure. -/ def dirac (a : α) : measure α := (outer_measure.dirac a).to_measure (by simp) @[simp] lemma dirac_apply (a : α) {s : set α} (hs : is_measurable s) : (dirac a : measure α) s = ⨆ h : a ∈ s, 1 := to_measure_apply _ _ hs /-- Sum of an indexed family of measures. -/ def sum {ι : Type*} (f : ι → measure α) : measure α := (outer_measure.sum (λ i, (f i).to_outer_measure)).to_measure $ le_trans (by exact le_infi (λ i, le_to_outer_measure_caratheodory _)) (outer_measure.le_sum_caratheodory _) /-- Counting measure on any measurable space. -/ def count : measure α := sum dirac @[class] def is_complete {α} {_:measurable_space α} (μ : measure α) : Prop := ∀ s, μ s = 0 → is_measurable s /-- The "almost everywhere" filter of co-null sets. -/ def a_e (μ : measure α) : filter α := { sets := {s | μ (-s) = 0}, univ_sets := by simp [measure_empty], inter_sets := λ s t hs ht, by simp [compl_inter]; exact measure_union_null hs ht, sets_of_superset := λ s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs } lemma mem_a_e_iff (s : set α) : s ∈ μ.a_e.sets ↔ μ (- s) = 0 := iff.rfl end measure end measure_theory section is_complete open measure_theory variables {α : Type*} [measurable_space α] (μ : measure α) def is_null_measurable (s : set α) : Prop := ∃ t z, s = t ∪ z ∧ is_measurable t ∧ μ z = 0 theorem is_null_measurable_iff {μ : measure α} {s : set α} : is_null_measurable μ s ↔ ∃ t, t ⊆ s ∧ is_measurable t ∧ μ (s \ t) = 0 := begin split, { rintro ⟨t, z, rfl, ht, hz⟩, refine ⟨t, set.subset_union_left _ _, ht, measure_mono_null _ hz⟩, simp [union_diff_left, diff_subset] }, { rintro ⟨t, st, ht, hz⟩, exact ⟨t, _, (union_diff_cancel st).symm, ht, hz⟩ } end theorem is_null_measurable_measure_eq {μ : measure α} {s t : set α} (st : t ⊆ s) (hz : μ (s \ t) = 0) : μ s = μ t := begin refine le_antisymm _ (measure_mono st), have := measure_union_le t (s \ t), rw [union_diff_cancel st, hz] at this, simpa end theorem is_measurable.is_null_measurable {s : set α} (hs : is_measurable s) : is_null_measurable μ s := ⟨s, ∅, by simp, hs, μ.empty⟩ theorem is_null_measurable_of_complete [c : μ.is_complete] {s : set α} : is_null_measurable μ s ↔ is_measurable s := ⟨by rintro ⟨t, z, rfl, ht, hz⟩; exact is_measurable.union ht (c _ hz), λ h, h.is_null_measurable _⟩ variables {μ} theorem is_null_measurable.union_null {s z : set α} (hs : is_null_measurable μ s) (hz : μ z = 0) : is_null_measurable μ (s ∪ z) := begin rcases hs with ⟨t, z', rfl, ht, hz'⟩, exact ⟨t, z' ∪ z, set.union_assoc _ _ _, ht, le_zero_iff_eq.1 (le_trans (measure_union_le _ _) $ by simp [hz, hz'])⟩ end theorem null_is_null_measurable {z : set α} (hz : μ z = 0) : is_null_measurable μ z := by simpa using (is_measurable.empty.is_null_measurable _).union_null hz theorem is_null_measurable.Union_nat {s : ℕ → set α} (hs : ∀ i, is_null_measurable μ (s i)) : is_null_measurable μ (Union s) := begin choose t ht using assume i, is_null_measurable_iff.1 (hs i), simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩, refine is_null_measurable_iff.2 ⟨Union t, Union_subset_Union st, is_measurable.Union ht, measure_mono_null _ (measure_Union_null hz)⟩, rw [diff_subset_iff, ← Union_union_distrib], exact Union_subset_Union (λ i, by rw ← diff_subset_iff) end theorem is_measurable.diff_null {s z : set α} (hs : is_measurable s) (hz : μ z = 0) : is_null_measurable μ (s \ z) := begin rw measure_eq_infi at hz, choose f hf using show ∀ q : {q:ℚ//q>0}, ∃ t:set α, z ⊆ t ∧ is_measurable t ∧ μ t < (nnreal.of_real q.1 : ennreal), { rintro ⟨ε, ε0⟩, have : 0 < (nnreal.of_real ε : ennreal), { simpa using ε0 }, rw ← hz at this, simpa [infi_lt_iff] }, refine is_null_measurable_iff.2 ⟨s \ Inter f, diff_subset_diff_right (subset_Inter (λ i, (hf i).1)), hs.diff (is_measurable.Inter (λ i, (hf i).2.1)), measure_mono_null _ (le_zero_iff_eq.1 $ le_of_not_lt $ λ h, _)⟩, { exact Inter f }, { rw [diff_subset_iff, diff_union_self], exact subset.trans (diff_subset _ _) (subset_union_left _ _) }, rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨ε, ε0', ε0, h⟩, simp at ε0, apply not_le_of_lt (lt_trans (hf ⟨ε, ε0⟩).2.2 h), exact measure_mono (Inter_subset _ _) end theorem is_null_measurable.diff_null {s z : set α} (hs : is_null_measurable μ s) (hz : μ z = 0) : is_null_measurable μ (s \ z) := begin rcases hs with ⟨t, z', rfl, ht, hz'⟩, rw [set.union_diff_distrib], exact (ht.diff_null hz).union_null (measure_mono_null (diff_subset _ _) hz') end theorem is_null_measurable.compl {s : set α} (hs : is_null_measurable μ s) : is_null_measurable μ (-s) := begin rcases hs with ⟨t, z, rfl, ht, hz⟩, rw compl_union, exact ht.compl.diff_null hz end def null_measurable {α : Type u} [measurable_space α] (μ : measure α) : measurable_space α := { is_measurable := is_null_measurable μ, is_measurable_empty := is_measurable.empty.is_null_measurable _, is_measurable_compl := λ s hs, hs.compl, is_measurable_Union := λ f, is_null_measurable.Union_nat } def completion {α : Type u} [measurable_space α] (μ : measure α) : @measure_theory.measure α (null_measurable μ) := { to_outer_measure := μ.to_outer_measure, m_Union := λ s hs hd, show μ (Union s) = ∑ i, μ (s i), begin choose t ht using assume i, is_null_measurable_iff.1 (hs i), simp [forall_and_distrib] at ht, rcases ht with ⟨st, ht, hz⟩, rw is_null_measurable_measure_eq (Union_subset_Union st), { rw measure_Union _ ht, { congr, funext i, exact (is_null_measurable_measure_eq (st i) (hz i)).symm }, { rintro i j ij x ⟨h₁, h₂⟩, exact hd i j ij ⟨st i h₁, st j h₂⟩ } }, { refine measure_mono_null _ (measure_Union_null hz), rw [diff_subset_iff, ← Union_union_distrib], exact Union_subset_Union (λ i, by rw ← diff_subset_iff) } end, trimmed := begin letI := null_measurable μ, refine le_antisymm (λ s, _) (outer_measure.trim_ge _), rw outer_measure.trim_eq_infi, dsimp, clear _inst, rw measure_eq_infi s, exact infi_le_infi (λ t, infi_le_infi $ λ st, infi_le_infi2 $ λ ht, ⟨ht.is_null_measurable _, le_refl _⟩) end } instance completion.is_complete {α : Type u} [measurable_space α] (μ : measure α) : (completion μ).is_complete := λ z hz, null_is_null_measurable hz end is_complete namespace measure_theory section prio set_option default_priority 100 -- see Note [default priority] /-- A measure space is a measurable space equipped with a measure, referred to as `volume`. -/ class measure_space (α : Type*) extends measurable_space α := (μ {} : measure α) end prio section measure_space variables {α : Type*} [measure_space α] {s₁ s₂ : set α} open measure_space def volume : set α → ennreal := @μ α _ @[simp] lemma volume_empty : volume (∅ : set α) = 0 := μ.empty lemma volume_mono : s₁ ⊆ s₂ → volume s₁ ≤ volume s₂ := measure_mono lemma volume_mono_null : s₁ ⊆ s₂ → volume s₂ = 0 → volume s₁ = 0 := measure_mono_null theorem volume_Union_le {β} [encodable β] : ∀ (s : β → set α), volume (⋃i, s i) ≤ (∑i, volume (s i)) := measure_Union_le lemma volume_Union_null {β} [encodable β] {s : β → set α} : (∀ i, volume (s i) = 0) → volume (⋃i, s i) = 0 := measure_Union_null theorem volume_union_le : ∀ (s₁ s₂ : set α), volume (s₁ ∪ s₂) ≤ volume s₁ + volume s₂ := measure_union_le lemma volume_union_null : volume s₁ = 0 → volume s₂ = 0 → volume (s₁ ∪ s₂) = 0 := measure_union_null lemma volume_Union {β} [encodable β] {f : β → set α} : pairwise (disjoint on f) → (∀i, is_measurable (f i)) → volume (⋃i, f i) = (∑i, volume (f i)) := measure_Union lemma volume_union : disjoint s₁ s₂ → is_measurable s₁ → is_measurable s₂ → volume (s₁ ∪ s₂) = volume s₁ + volume s₂ := measure_union lemma volume_bUnion {β} {s : set β} {f : β → set α} : countable s → pairwise_on s (disjoint on f) → (∀b∈s, is_measurable (f b)) → volume (⋃b∈s, f b) = ∑p:s, volume (f p.1) := measure_bUnion lemma volume_sUnion {S : set (set α)} : countable S → pairwise_on S disjoint → (∀s∈S, is_measurable s) → volume (⋃₀ S) = ∑s:S, volume s.1 := measure_sUnion lemma volume_bUnion_finset {β} {s : finset β} {f : β → set α} (hd : pairwise_on ↑s (disjoint on f)) (hm : ∀b∈s, is_measurable (f b)) : volume (⋃b∈s, f b) = s.sum (λp, volume (f p)) := show volume (⋃b∈(↑s : set β), f b) = s.sum (λp, volume (f p)), begin rw [volume_bUnion (countable_finite (finset.finite_to_set s)) hd hm, tsum_eq_sum], { show s.attach.sum (λb:(↑s : set β), volume (f b)) = s.sum (λb, volume (f b)), exact @finset.sum_attach _ _ s _ (λb, volume (f b)) }, simp end lemma volume_diff : s₂ ⊆ s₁ → is_measurable s₁ → is_measurable s₂ → volume s₂ < ⊤ → volume (s₁ \ s₂) = volume s₁ - volume s₂ := measure_diff /-- `∀ₘ a:α, p a` states that the property `p` is almost everywhere true in the measure space associated with `α`. This means that the measure of the complementary of `p` is `0`. In a probability measure, the measure of `p` is `1`, when `p` is measurable. -/ def all_ae (p : α → Prop) : Prop := ∀ᶠ a in μ.a_e, p a notation `∀ₘ` binders `, ` r:(scoped P, all_ae P) := r lemma all_ae_congr {p q : α → Prop} (h : ∀ₘ a, p a ↔ q a) : (∀ₘ a, p a) ↔ (∀ₘ a, q a) := iff.intro (assume h', by filter_upwards [h, h'] assume a hpq hp, hpq.1 hp) (assume h', by filter_upwards [h, h'] assume a hpq hq, hpq.2 hq) lemma all_ae_iff {p : α → Prop} : (∀ₘ a, p a) ↔ volume { a | ¬ p a } = 0 := iff.rfl lemma volume_zero_iff_all_ae_nmem {s : set α} : volume s = 0 ↔ ∀ₘ a, a ∉ s := by simp only [all_ae_iff, not_not, set_of_mem_eq] lemma all_ae_of_all {p : α → Prop} : (∀a, p a) → ∀ₘ a, p a := univ_mem_sets' lemma all_ae_all_iff {ι : Type*} [encodable ι] {p : α → ι → Prop} : (∀ₘ a, ∀i, p a i) ↔ (∀i, ∀ₘ a, p a i) := begin refine iff.intro (assume h i, _) (assume h, _), { filter_upwards [h] assume a ha, ha i }, { have h := measure_Union_null h, rw [← compl_Inter] at h, filter_upwards [h] assume a, mem_Inter.1 } end @[simp] lemma all_ae_and_iff {p q : α → Prop} : (∀ₘ a, p a ∧ q a) ↔ (∀ₘ a, p a) ∧ ∀ₘ a, q a := eventually_and @[simp] lemma all_ae_imp_distrib_left {p : Prop} {q : α → Prop} : (∀ₘ a, p → q a) ↔ (p → ∀ₘ a, q a) := eventually_imp_distrib_left @[simp] lemma all_ae_or_distrib_left {p : Prop} {q : α → Prop} : (∀ₘ a, p ∨ q a) ↔ (p ∨ ∀ₘ a, q a) := eventually_or_distrib_left @[simp] lemma all_ae_or_distrib_right {p : α → Prop} {q : Prop} : (∀ₘ a, p a ∨ q) ↔ ((∀ₘ a, p a) ∨ q) := eventually_or_distrib_right variables {β : Type*} lemma all_ae_eq_refl (f : α → β) : ∀ₘ a, f a = f a := by { filter_upwards [], assume a, apply eq.refl } lemma all_ae_eq_symm {f g : α → β} : (∀ₘ a, f a = g a) → (∀ₘ a, g a = f a) := by { assume h, filter_upwards [h], assume a, apply eq.symm } lemma all_ae_eq_trans {f g h: α → β} (h₁ : ∀ₘ a, f a = g a) (h₂ : ∀ₘ a, g a = h a) : ∀ₘ a, f a = h a := by { filter_upwards [h₁, h₂], intro a, exact eq.trans } end measure_space end measure_theory
08aeb5f962f71329a9afa99d156134dbd80d0c6d
4727251e0cd73359b15b664c3170e5d754078599
/src/analysis/calculus/fderiv.lean
037c7bfb0deece5147dc6c23a6b140764cf81e0f
[ "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
134,543
lean
/- Copyright (c) 2019 Jeremy Avigad. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Jeremy Avigad, Sébastien Gouëzel, Yury Kudryashov -/ import analysis.asymptotics.asymptotic_equivalent import analysis.calculus.tangent_cone import analysis.normed_space.bounded_linear_maps import analysis.normed_space.units /-! # The Fréchet derivative Let `E` and `F` be normed spaces, `f : E → F`, and `f' : E →L[𝕜] F` a continuous 𝕜-linear map, where `𝕜` is a non-discrete normed field. Then `has_fderiv_within_at f f' s x` says that `f` has derivative `f'` at `x`, where the domain of interest is restricted to `s`. We also have `has_fderiv_at f f' x := has_fderiv_within_at f f' x univ` Finally, `has_strict_fderiv_at f f' x` means that `f : E → F` has derivative `f' : E →L[𝕜] F` in the sense of strict differentiability, i.e., `f y - f z - f'(y - z) = o(y - z)` as `y, z → x`. This notion is used in the inverse function theorem, and is defined here only to avoid proving theorems like `is_bounded_bilinear_map.has_fderiv_at` twice: first for `has_fderiv_at`, then for `has_strict_fderiv_at`. ## Main results In addition to the definition and basic properties of the derivative, this file contains the usual formulas (and existence assertions) for the derivative of * constants * the identity * bounded linear maps * bounded bilinear maps * sum of two functions * sum of finitely many functions * multiplication of a function by a scalar constant * negative of a function * subtraction of two functions * multiplication of a function by a scalar function * multiplication of two scalar functions * composition of functions (the chain rule) * inverse function (assuming that it exists; the inverse function theorem is in `inverse.lean`) For most binary operations we also define `const_op` and `op_const` theorems for the cases when the first or second argument is a constant. This makes writing chains of `has_deriv_at`'s easier, and they more frequently lead to the desired result. One can also interpret the derivative of a function `f : 𝕜 → E` as an element of `E` (by identifying a linear function from `𝕜` to `E` with its value at `1`). Results on the Fréchet derivative are translated to this more elementary point of view on the derivative in the file `deriv.lean`. The derivative of polynomials is handled there, as it is naturally one-dimensional. The simplifier is set up to prove automatically that some functions are differentiable, or differentiable at a point (but not differentiable on a set or within a set at a point, as checking automatically that the good domains are mapped one to the other when using composition is not something the simplifier can easily do). This means that one can write `example (x : ℝ) : differentiable ℝ (λ x, sin (exp (3 + x^2)) - 5 * cos x) := by simp`. If there are divisions, one needs to supply to the simplifier proofs that the denominators do not vanish, as in ```lean example (x : ℝ) (h : 1 + sin x ≠ 0) : differentiable_at ℝ (λ x, exp x / (1 + sin x)) x := by simp [h] ``` Of course, these examples only work once `exp`, `cos` and `sin` have been shown to be differentiable, in `analysis.special_functions.trigonometric`. The simplifier is not set up to compute the Fréchet derivative of maps (as these are in general complicated multidimensional linear maps), but it will compute one-dimensional derivatives, see `deriv.lean`. ## Implementation details The derivative is defined in terms of the `is_o` relation, but also characterized in terms of the `tendsto` relation. We also introduce predicates `differentiable_within_at 𝕜 f s x` (where `𝕜` is the base field, `f` the function to be differentiated, `x` the point at which the derivative is asserted to exist, and `s` the set along which the derivative is defined), as well as `differentiable_at 𝕜 f x`, `differentiable_on 𝕜 f s` and `differentiable 𝕜 f` to express the existence of a derivative. To be able to compute with derivatives, we write `fderiv_within 𝕜 f s x` and `fderiv 𝕜 f x` for some choice of a derivative if it exists, and the zero function otherwise. This choice only behaves well along sets for which the derivative is unique, i.e., those for which the tangent directions span a dense subset of the whole space. The predicates `unique_diff_within_at s x` and `unique_diff_on s`, defined in `tangent_cone.lean` express this property. We prove that indeed they imply the uniqueness of the derivative. This is satisfied for open subsets, and in particular for `univ`. This uniqueness only holds when the field is non-discrete, which we request at the very beginning: otherwise, a derivative can be defined, but it has no interesting properties whatsoever. To make sure that the simplifier can prove automatically that functions are differentiable, we tag many lemmas with the `simp` attribute, for instance those saying that the sum of differentiable functions is differentiable, as well as their product, their cartesian product, and so on. A notable exception is the chain rule: we do not mark as a simp lemma the fact that, if `f` and `g` are differentiable, then their composition also is: `simp` would always be able to match this lemma, by taking `f` or `g` to be the identity. Instead, for every reasonable function (say, `exp`), we add a lemma that if `f` is differentiable then so is `(λ x, exp (f x))`. This means adding some boilerplate lemmas, but these can also be useful in their own right. Tests for this ability of the simplifier (with more examples) are provided in `tests/differentiable.lean`. ## Tags derivative, differentiable, Fréchet, calculus -/ open filter asymptotics continuous_linear_map set metric open_locale topological_space classical nnreal filter asymptotics ennreal noncomputable theory section variables {𝕜 : Type*} [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] variables {G' : Type*} [normed_group G'] [normed_space 𝕜 G'] /-- A function `f` has the continuous linear map `f'` as derivative along the filter `L` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` converges along the filter `L`. This definition is designed to be specialized for `L = 𝓝 x` (in `has_fderiv_at`), giving rise to the usual notion of Fréchet derivative, and for `L = 𝓝[s] x` (in `has_fderiv_within_at`), giving rise to the notion of Fréchet derivative along the set `s`. -/ def has_fderiv_at_filter (f : E → F) (f' : E →L[𝕜] F) (x : E) (L : filter E) := is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L /-- A function `f` has the continuous linear map `f'` as derivative at `x` within a set `s` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x` inside `s`. -/ def has_fderiv_within_at (f : E → F) (f' : E →L[𝕜] F) (s : set E) (x : E) := has_fderiv_at_filter f f' x (𝓝[s] x) /-- A function `f` has the continuous linear map `f'` as derivative at `x` if `f x' = f x + f' (x' - x) + o (x' - x)` when `x'` tends to `x`. -/ def has_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) := has_fderiv_at_filter f f' x (𝓝 x) /-- A function `f` has derivative `f'` at `a` in the sense of *strict differentiability* if `f x - f y - f' (x - y) = o(x - y)` as `x, y → a`. This form of differentiability is required, e.g., by the inverse function theorem. Any `C^1` function on a vector space over `ℝ` is strictly differentiable but this definition works, e.g., for vector spaces over `p`-adic numbers. -/ def has_strict_fderiv_at (f : E → F) (f' : E →L[𝕜] F) (x : E) := is_o (λ p : E × E, f p.1 - f p.2 - f' (p.1 - p.2)) (λ p : E × E, p.1 - p.2) (𝓝 (x, x)) variables (𝕜) /-- A function `f` is differentiable at a point `x` within a set `s` if it admits a derivative there (possibly non-unique). -/ def differentiable_within_at (f : E → F) (s : set E) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_within_at f f' s x /-- A function `f` is differentiable at a point `x` if it admits a derivative there (possibly non-unique). -/ def differentiable_at (f : E → F) (x : E) := ∃f' : E →L[𝕜] F, has_fderiv_at f f' x /-- If `f` has a derivative at `x` within `s`, then `fderiv_within 𝕜 f s x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv_within (f : E → F) (s : set E) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_within_at f f' s x then classical.some h else 0 /-- If `f` has a derivative at `x`, then `fderiv 𝕜 f x` is such a derivative. Otherwise, it is set to `0`. -/ def fderiv (f : E → F) (x : E) : E →L[𝕜] F := if h : ∃f', has_fderiv_at f f' x then classical.some h else 0 /-- `differentiable_on 𝕜 f s` means that `f` is differentiable within `s` at any point of `s`. -/ def differentiable_on (f : E → F) (s : set E) := ∀x ∈ s, differentiable_within_at 𝕜 f s x /-- `differentiable 𝕜 f` means that `f` is differentiable at any point. -/ def differentiable (f : E → F) := ∀x, differentiable_at 𝕜 f x variables {𝕜} variables {f f₀ f₁ g : E → F} variables {f' f₀' f₁' g' : E →L[𝕜] F} variables (e : E →L[𝕜] F) variables {x : E} variables {s t : set E} variables {L L₁ L₂ : filter E} lemma fderiv_within_zero_of_not_differentiable_within_at (h : ¬ differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = 0 := have ¬ ∃ f', has_fderiv_within_at f f' s x, from h, by simp [fderiv_within, this] lemma fderiv_zero_of_not_differentiable_at (h : ¬ differentiable_at 𝕜 f x) : fderiv 𝕜 f x = 0 := have ¬ ∃ f', has_fderiv_at f f' x, from h, by simp [fderiv, this] section derivative_uniqueness /- In this section, we discuss the uniqueness of the derivative. We prove that the definitions `unique_diff_within_at` and `unique_diff_on` indeed imply the uniqueness of the derivative. -/ /-- If a function f has a derivative f' at x, a rescaled version of f around x converges to f', i.e., `n (f (x + (1/n) v) - f x)` converges to `f' v`. More generally, if `c n` tends to infinity and `c n * d n` tends to `v`, then `c n * (f (x + d n) - f x)` tends to `f' v`. This lemma expresses this fact, for functions having a derivative within a set. Its specific formulation is useful for tangent cone related discussions. -/ theorem has_fderiv_within_at.lim (h : has_fderiv_within_at f f' s x) {α : Type*} (l : filter α) {c : α → 𝕜} {d : α → E} {v : E} (dtop : ∀ᶠ n in l, x + d n ∈ s) (clim : tendsto (λ n, ∥c n∥) l at_top) (cdlim : tendsto (λ n, c n • d n) l (𝓝 v)) : tendsto (λn, c n • (f (x + d n) - f x)) l (𝓝 (f' v)) := begin have tendsto_arg : tendsto (λ n, x + d n) l (𝓝[s] x), { conv in (𝓝[s] x) { rw ← add_zero x }, rw [nhds_within, tendsto_inf], split, { apply tendsto_const_nhds.add (tangent_cone_at.lim_zero l clim cdlim) }, { rwa tendsto_principal } }, have : is_o (λ y, f y - f x - f' (y - x)) (λ y, y - x) (𝓝[s] x) := h, have : is_o (λ n, f (x + d n) - f x - f' ((x + d n) - x)) (λ n, (x + d n) - x) l := this.comp_tendsto tendsto_arg, have : is_o (λ n, f (x + d n) - f x - f' (d n)) d l := by simpa only [add_sub_cancel'], have : is_o (λn, c n • (f (x + d n) - f x - f' (d n))) (λn, c n • d n) l := (is_O_refl c l).smul_is_o this, have : is_o (λn, c n • (f (x + d n) - f x - f' (d n))) (λn, (1:ℝ)) l := 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))) l (𝓝 0) := (is_o_one_iff ℝ).1 this, have L2 : tendsto (λn, f' (c n • d n)) l (𝓝 (f' v)) := tendsto.comp f'.cont.continuous_at cdlim, have L3 : tendsto (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) l (𝓝 (0 + f' v)) := L1.add L2, have : (λn, (c n • (f (x + d n) - f x - f' (d n)) + f' (c n • d n))) = (λn, c n • (f (x + d n) - f x)), by { ext n, simp [smul_add, smul_sub] }, rwa [this, zero_add] at L3 end /-- If `f'` and `f₁'` are two derivatives of `f` within `s` at `x`, then they are equal on the tangent cone to `s` at `x` -/ theorem has_fderiv_within_at.unique_on (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : eq_on f' f₁' (tangent_cone_at 𝕜 s x) := λ y ⟨c, d, dtop, clim, cdlim⟩, tendsto_nhds_unique (hf.lim at_top dtop clim cdlim) (hg.lim at_top dtop clim cdlim) /-- `unique_diff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/ theorem unique_diff_within_at.eq (H : unique_diff_within_at 𝕜 s x) (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at f f₁' s x) : f' = f₁' := continuous_linear_map.ext_on H.1 (hf.unique_on hg) theorem unique_diff_on.eq (H : unique_diff_on 𝕜 s) (hx : x ∈ s) (h : has_fderiv_within_at f f' s x) (h₁ : has_fderiv_within_at f f₁' s x) : f' = f₁' := (H x hx).eq h h₁ end derivative_uniqueness section fderiv_properties /-! ### Basic properties of the derivative -/ theorem has_fderiv_at_filter_iff_tendsto : has_fderiv_at_filter f f' x L ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) := have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from λ x' hx', by { rw [sub_eq_zero.1 (norm_eq_zero.1 hx')], simp }, begin unfold has_fderiv_at_filter, rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h], exact tendsto_congr (λ _, div_eq_inv_mul _ _), end theorem has_fderiv_within_at_iff_tendsto : has_fderiv_within_at f f' s x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝[s] x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_tendsto : has_fderiv_at f f' x ↔ tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (𝓝 x) (𝓝 0) := has_fderiv_at_filter_iff_tendsto theorem has_fderiv_at_iff_is_o_nhds_zero : has_fderiv_at f f' x ↔ is_o (λh, f (x + h) - f x - f' h) (λh, h) (𝓝 0) := begin rw [has_fderiv_at, has_fderiv_at_filter, ← map_add_left_nhds_zero x, is_o_map], simp [(∘)] end /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. This version only assumes that `∥f x - f x₀∥ ≤ C * ∥x - x₀∥` in a neighborhood of `x`. -/ lemma has_fderiv_at.le_of_lip' {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀) {C : ℝ} (hC₀ : 0 ≤ C) (hlip : ∀ᶠ x in 𝓝 x₀, ∥f x - f x₀∥ ≤ C * ∥x - x₀∥) : ∥f'∥ ≤ C := begin refine le_of_forall_pos_le_add (λ ε ε0, op_norm_le_of_nhds_zero _ _), exact add_nonneg hC₀ ε0.le, rw [← map_add_left_nhds_zero x₀, eventually_map] at hlip, filter_upwards [is_o_iff.1 (has_fderiv_at_iff_is_o_nhds_zero.1 hf) ε0, hlip] with y hy hyC, rw add_sub_cancel' at hyC, calc ∥f' y∥ ≤ ∥f (x₀ + y) - f x₀∥ + ∥f (x₀ + y) - f x₀ - f' y∥ : norm_le_insert _ _ ... ≤ C * ∥y∥ + ε * ∥y∥ : add_le_add hyC hy ... = (C + ε) * ∥y∥ : (add_mul _ _ _).symm end /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. -/ lemma has_fderiv_at.le_of_lip {f : E → F} {f' : E →L[𝕜] F} {x₀ : E} (hf : has_fderiv_at f f' x₀) {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥f'∥ ≤ C := begin refine hf.le_of_lip' C.coe_nonneg _, filter_upwards [hs] with x hx using hlip.norm_sub_le hx (mem_of_mem_nhds hs), end theorem has_fderiv_at_filter.mono (h : has_fderiv_at_filter f f' x L₂) (hst : L₁ ≤ L₂) : has_fderiv_at_filter f f' x L₁ := h.mono hst theorem has_fderiv_within_at.mono (h : has_fderiv_within_at f f' t x) (hst : s ⊆ t) : has_fderiv_within_at f f' s x := h.mono (nhds_within_mono _ hst) theorem has_fderiv_at.has_fderiv_at_filter (h : has_fderiv_at f f' x) (hL : L ≤ 𝓝 x) : has_fderiv_at_filter f f' x L := h.mono hL theorem has_fderiv_at.has_fderiv_within_at (h : has_fderiv_at f f' x) : has_fderiv_within_at f f' s x := h.has_fderiv_at_filter inf_le_left lemma has_fderiv_within_at.differentiable_within_at (h : has_fderiv_within_at f f' s x) : differentiable_within_at 𝕜 f s x := ⟨f', h⟩ lemma has_fderiv_at.differentiable_at (h : has_fderiv_at f f' x) : differentiable_at 𝕜 f x := ⟨f', h⟩ @[simp] lemma has_fderiv_within_at_univ : has_fderiv_within_at f f' univ x ↔ has_fderiv_at f f' x := by { simp only [has_fderiv_within_at, nhds_within_univ], refl } lemma has_strict_fderiv_at.is_O_sub (hf : has_strict_fderiv_at f f' x) : is_O (λ p : E × E, f p.1 - f p.2) (λ p : E × E, p.1 - p.2) (𝓝 (x, x)) := hf.is_O.congr_of_sub.2 (f'.is_O_comp _ _) lemma has_fderiv_at_filter.is_O_sub (h : has_fderiv_at_filter f f' x L) : is_O (λ x', f x' - f x) (λ x', x' - x) L := h.is_O.congr_of_sub.2 (f'.is_O_sub _ _) protected lemma has_strict_fderiv_at.has_fderiv_at (hf : has_strict_fderiv_at f f' x) : has_fderiv_at f f' x := begin rw [has_fderiv_at, has_fderiv_at_filter, is_o_iff], exact (λ c hc, tendsto_id.prod_mk_nhds tendsto_const_nhds (is_o_iff.1 hf hc)) end protected lemma has_strict_fderiv_at.differentiable_at (hf : has_strict_fderiv_at f f' x) : differentiable_at 𝕜 f x := hf.has_fderiv_at.differentiable_at /-- If `f` is strictly differentiable at `x` with derivative `f'` and `K > ∥f'∥₊`, then `f` is `K`-Lipschitz in a neighborhood of `x`. -/ lemma has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt (hf : has_strict_fderiv_at f f' x) (K : ℝ≥0) (hK : ∥f'∥₊ < K) : ∃ s ∈ 𝓝 x, lipschitz_on_with K f s := begin have := hf.add_is_O_with (f'.is_O_with_comp _ _) hK, simp only [sub_add_cancel, is_O_with] at this, rcases exists_nhds_square this with ⟨U, Uo, xU, hU⟩, exact ⟨U, Uo.mem_nhds xU, lipschitz_on_with_iff_norm_sub_le.2 $ λ x hx y hy, hU (mk_mem_prod hx hy)⟩ end /-- If `f` is strictly differentiable at `x` with derivative `f'`, then `f` is Lipschitz in a neighborhood of `x`. See also `has_strict_fderiv_at.exists_lipschitz_on_with_of_nnnorm_lt` for a more precise statement. -/ lemma has_strict_fderiv_at.exists_lipschitz_on_with (hf : has_strict_fderiv_at f f' x) : ∃ K (s ∈ 𝓝 x), lipschitz_on_with K f s := (exists_gt _).imp hf.exists_lipschitz_on_with_of_nnnorm_lt /-- Directional derivative agrees with `has_fderiv`. -/ lemma has_fderiv_at.lim (hf : has_fderiv_at f f' x) (v : E) {α : Type*} {c : α → 𝕜} {l : filter α} (hc : tendsto (λ n, ∥c n∥) l at_top) : tendsto (λ n, (c n) • (f (x + (c n)⁻¹ • v) - f x)) l (𝓝 (f' v)) := begin refine (has_fderiv_within_at_univ.2 hf).lim _ (univ_mem' (λ _, trivial)) hc _, assume U hU, refine (eventually_ne_of_tendsto_norm_at_top hc (0:𝕜)).mono (λ y hy, _), convert mem_of_mem_nhds hU, dsimp only, rw [← mul_smul, mul_inv_cancel hy, one_smul] end theorem has_fderiv_at.unique (h₀ : has_fderiv_at f f₀' x) (h₁ : has_fderiv_at f f₁' x) : f₀' = f₁' := begin rw ← has_fderiv_within_at_univ at h₀ h₁, exact unique_diff_within_at_univ.eq h₀ h₁ end lemma has_fderiv_within_at_inter' (h : t ∈ 𝓝[s] x) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict'' s h] lemma has_fderiv_within_at_inter (h : t ∈ 𝓝 x) : has_fderiv_within_at f f' (s ∩ t) x ↔ has_fderiv_within_at f f' s x := by simp [has_fderiv_within_at, nhds_within_restrict' s h] lemma has_fderiv_within_at.union (hs : has_fderiv_within_at f f' s x) (ht : has_fderiv_within_at f f' t x) : has_fderiv_within_at f f' (s ∪ t) x := begin simp only [has_fderiv_within_at, nhds_within_union], exact hs.join ht, end lemma has_fderiv_within_at.nhds_within (h : has_fderiv_within_at f f' s x) (ht : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x := (has_fderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _)) lemma has_fderiv_within_at.has_fderiv_at (h : has_fderiv_within_at f f' s x) (hs : s ∈ 𝓝 x) : has_fderiv_at f f' x := by rwa [← univ_inter s, has_fderiv_within_at_inter hs, has_fderiv_within_at_univ] at h lemma differentiable_within_at.differentiable_at (h : differentiable_within_at 𝕜 f s x) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x := h.imp (λ f' hf', hf'.has_fderiv_at hs) lemma differentiable_within_at.has_fderiv_within_at (h : differentiable_within_at 𝕜 f s x) : has_fderiv_within_at f (fderiv_within 𝕜 f s x) s x := begin dunfold fderiv_within, dunfold differentiable_within_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_at.has_fderiv_at (h : differentiable_at 𝕜 f x) : has_fderiv_at f (fderiv 𝕜 f x) x := begin dunfold fderiv, dunfold differentiable_at at h, rw dif_pos h, exact classical.some_spec h end lemma differentiable_on.has_fderiv_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : has_fderiv_at f (fderiv 𝕜 f x) x := ((h x (mem_of_mem_nhds hs)).differentiable_at hs).has_fderiv_at lemma differentiable_on.differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : differentiable_at 𝕜 f x := (h.has_fderiv_at hs).differentiable_at lemma differentiable_on.eventually_differentiable_at (h : differentiable_on 𝕜 f s) (hs : s ∈ 𝓝 x) : ∀ᶠ y in 𝓝 x, differentiable_at 𝕜 f y := (eventually_eventually_nhds.2 hs).mono $ λ y, h.differentiable_at lemma has_fderiv_at.fderiv (h : has_fderiv_at f f' x) : fderiv 𝕜 f x = f' := by { ext, rw h.unique h.differentiable_at.has_fderiv_at } lemma fderiv_eq {f' : E → E →L[𝕜] F} (h : ∀ x, has_fderiv_at f (f' x) x) : fderiv 𝕜 f = f' := funext $ λ x, (h x).fderiv /-- Converse to the mean value inequality: if `f` is differentiable at `x₀` and `C`-lipschitz on a neighborhood of `x₀` then it its derivative at `x₀` has norm bounded by `C`. Version using `fderiv`. -/ lemma fderiv_at.le_of_lip {f : E → F} {x₀ : E} (hf : differentiable_at 𝕜 f x₀) {s : set E} (hs : s ∈ 𝓝 x₀) {C : ℝ≥0} (hlip : lipschitz_on_with C f s) : ∥fderiv 𝕜 f x₀∥ ≤ C := hf.has_fderiv_at.le_of_lip hs hlip lemma has_fderiv_within_at.fderiv_within (h : has_fderiv_within_at f f' s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = f' := (hxs.eq h h.differentiable_within_at.has_fderiv_within_at).symm /-- If `x` is not in the closure of `s`, then `f` has any derivative at `x` within `s`, as this statement is empty. -/ lemma has_fderiv_within_at_of_not_mem_closure (h : x ∉ closure s) : has_fderiv_within_at f f' s x := begin simp only [mem_closure_iff_nhds_within_ne_bot, ne_bot_iff, ne.def, not_not] at h, simp [has_fderiv_within_at, has_fderiv_at_filter, h, is_o, is_O_with], end lemma differentiable_within_at.mono (h : differentiable_within_at 𝕜 f t x) (st : s ⊆ t) : differentiable_within_at 𝕜 f s x := begin rcases h with ⟨f', hf'⟩, exact ⟨f', hf'.mono st⟩ end lemma differentiable_within_at_univ : differentiable_within_at 𝕜 f univ x ↔ differentiable_at 𝕜 f x := by simp only [differentiable_within_at, has_fderiv_within_at_univ, differentiable_at] lemma differentiable_within_at_inter (ht : t ∈ 𝓝 x) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict' s ht] lemma differentiable_within_at_inter' (ht : t ∈ 𝓝[s] x) : differentiable_within_at 𝕜 f (s ∩ t) x ↔ differentiable_within_at 𝕜 f s x := by simp only [differentiable_within_at, has_fderiv_within_at, has_fderiv_at_filter, nhds_within_restrict'' s ht] lemma differentiable_within_at.antimono (h : differentiable_within_at 𝕜 f s x) (hst : s ⊆ t) (hx : s ∈ 𝓝[t] x) : differentiable_within_at 𝕜 f t x := by rwa [← differentiable_within_at_inter' hx, inter_eq_self_of_subset_right hst] lemma has_fderiv_within_at.antimono (h : has_fderiv_within_at f f' s x) (hst : s ⊆ t) (hs : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) : has_fderiv_within_at f f' t x := begin have h' : has_fderiv_within_at f _ t x := (h.differentiable_within_at.antimono hst hx).has_fderiv_within_at, rwa hs.eq h (h'.mono hst), end lemma differentiable_at.differentiable_within_at (h : differentiable_at 𝕜 f x) : differentiable_within_at 𝕜 f s x := (differentiable_within_at_univ.2 h).mono (subset_univ _) lemma differentiable.differentiable_at (h : differentiable 𝕜 f) : differentiable_at 𝕜 f x := h x lemma differentiable_at.fderiv_within (h : differentiable_at 𝕜 f x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin apply has_fderiv_within_at.fderiv_within _ hxs, exact h.has_fderiv_at.has_fderiv_within_at end lemma differentiable_on.mono (h : differentiable_on 𝕜 f t) (st : s ⊆ t) : differentiable_on 𝕜 f s := λx hx, (h x (st hx)).mono st lemma differentiable_on_univ : differentiable_on 𝕜 f univ ↔ differentiable 𝕜 f := by { simp [differentiable_on, differentiable_within_at_univ], refl } lemma differentiable.differentiable_on (h : differentiable 𝕜 f) : differentiable_on 𝕜 f s := (differentiable_on_univ.2 h).mono (subset_univ _) lemma differentiable_on_of_locally_differentiable_on (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ differentiable_on 𝕜 f (s ∩ u)) : differentiable_on 𝕜 f s := begin assume x xs, rcases h x xs with ⟨t, t_open, xt, ht⟩, exact (differentiable_within_at_inter (is_open.mem_nhds t_open xt)).1 (ht x ⟨xs, xt⟩) end lemma fderiv_within_subset (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f t x) : fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x := ((differentiable_within_at.has_fderiv_within_at h).mono st).fderiv_within ht lemma fderiv_within_subset' (st : s ⊆ t) (ht : unique_diff_within_at 𝕜 s x) (hx : s ∈ 𝓝[t] x) (h : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 f s x = fderiv_within 𝕜 f t x := fderiv_within_subset st ht (h.antimono st hx) @[simp] lemma fderiv_within_univ : fderiv_within 𝕜 f univ = fderiv 𝕜 f := begin ext x : 1, by_cases h : differentiable_at 𝕜 f x, { apply has_fderiv_within_at.fderiv_within _ unique_diff_within_at_univ, rw has_fderiv_within_at_univ, apply h.has_fderiv_at }, { have : ¬ differentiable_within_at 𝕜 f univ x, by contrapose! h; rwa ← differentiable_within_at_univ, rw [fderiv_zero_of_not_differentiable_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end lemma fderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f (s ∩ t) x = fderiv_within 𝕜 f s x := begin by_cases h : differentiable_within_at 𝕜 f (s ∩ t) x, { apply fderiv_within_subset (inter_subset_left _ _) _ ((differentiable_within_at_inter ht).1 h), apply hs.inter ht }, { have : ¬ differentiable_within_at 𝕜 f s x, by contrapose! h; rw differentiable_within_at_inter; assumption, rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at this] } end lemma fderiv_within_of_mem_nhds (h : s ∈ 𝓝 x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin have : s = univ ∩ s, by simp only [univ_inter], rw [this, ← fderiv_within_univ], exact fderiv_within_inter h (unique_diff_on_univ _ (mem_univ _)) end lemma fderiv_within_of_open (hs : is_open s) (hx : x ∈ s) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := fderiv_within_of_mem_nhds (is_open.mem_nhds hs hx) lemma fderiv_within_eq_fderiv (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_at 𝕜 f x) : fderiv_within 𝕜 f s x = fderiv 𝕜 f x := begin rw ← fderiv_within_univ, exact fderiv_within_subset (subset_univ _) hs h.differentiable_within_at end lemma fderiv_mem_iff {f : E → F} {s : set (E →L[𝕜] F)} {x : E} : fderiv 𝕜 f x ∈ s ↔ (differentiable_at 𝕜 f x ∧ fderiv 𝕜 f x ∈ s) ∨ (0 : E →L[𝕜] F) ∈ s ∧ ¬differentiable_at 𝕜 f x := begin split, { intro hfx, by_cases hx : differentiable_at 𝕜 f x, { exact or.inl ⟨hx, hfx⟩ }, { rw [fderiv_zero_of_not_differentiable_at hx] at hfx, exact or.inr ⟨hfx, hx⟩ } }, { rintro (⟨hf, hf'⟩|⟨h₀, hx⟩), { exact hf' }, { rwa [fderiv_zero_of_not_differentiable_at hx] } } end end fderiv_properties section continuous /-! ### Deducing continuity from differentiability -/ theorem has_fderiv_at_filter.tendsto_nhds (hL : L ≤ 𝓝 x) (h : has_fderiv_at_filter f f' x L) : tendsto f L (𝓝 (f x)) := begin have : tendsto (λ x', f x' - f x) L (𝓝 0), { refine h.is_O_sub.trans_tendsto (tendsto.mono_left _ hL), rw ← sub_self x, exact tendsto_id.sub tendsto_const_nhds }, have := tendsto.add this tendsto_const_nhds, rw zero_add (f x) at this, exact this.congr (by simp) end theorem has_fderiv_within_at.continuous_within_at (h : has_fderiv_within_at f f' s x) : continuous_within_at f s x := has_fderiv_at_filter.tendsto_nhds inf_le_left h theorem has_fderiv_at.continuous_at (h : has_fderiv_at f f' x) : continuous_at f x := has_fderiv_at_filter.tendsto_nhds le_rfl h lemma differentiable_within_at.continuous_within_at (h : differentiable_within_at 𝕜 f s x) : continuous_within_at f s x := let ⟨f', hf'⟩ := h in hf'.continuous_within_at lemma differentiable_at.continuous_at (h : differentiable_at 𝕜 f x) : continuous_at f x := let ⟨f', hf'⟩ := h in hf'.continuous_at lemma differentiable_on.continuous_on (h : differentiable_on 𝕜 f s) : continuous_on f s := λx hx, (h x hx).continuous_within_at lemma differentiable.continuous (h : differentiable 𝕜 f) : continuous f := continuous_iff_continuous_at.2 $ λx, (h x).continuous_at protected lemma has_strict_fderiv_at.continuous_at (hf : has_strict_fderiv_at f f' x) : continuous_at f x := hf.has_fderiv_at.continuous_at lemma has_strict_fderiv_at.is_O_sub_rev {f' : E ≃L[𝕜] F} (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) x) : is_O (λ p : E × E, p.1 - p.2) (λ p : E × E, f p.1 - f p.2) (𝓝 (x, x)) := ((f'.is_O_comp_rev _ _).trans (hf.trans_is_O (f'.is_O_comp_rev _ _)).right_is_O_add).congr (λ _, rfl) (λ _, sub_add_cancel _ _) lemma has_fderiv_at_filter.is_O_sub_rev (hf : has_fderiv_at_filter f f' x L) {C} (hf' : antilipschitz_with C f') : is_O (λ x', x' - x) (λ x', f x' - f x) L := have is_O (λ x', x' - x) (λ x', f' (x' - x)) L, from is_O_iff.2 ⟨C, eventually_of_forall $ λ x', f'.to_linear_map.bound_of_antilipschitz hf' _⟩, (this.trans (hf.trans_is_O this).right_is_O_add).congr (λ _, rfl) (λ _, sub_add_cancel _ _) end continuous section congr /-! ### congr properties of the derivative -/ theorem filter.eventually_eq.has_strict_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) (h' : ∀ y, f₀' y = f₁' y) : has_strict_fderiv_at f₀ f₀' x ↔ has_strict_fderiv_at f₁ f₁' x := begin refine is_o_congr ((h.prod_mk_nhds h).mono _) (eventually_of_forall $ λ _, rfl), rintros p ⟨hp₁, hp₂⟩, simp only [*] end theorem has_strict_fderiv_at.congr_of_eventually_eq (h : has_strict_fderiv_at f f' x) (h₁ : f =ᶠ[𝓝 x] f₁) : has_strict_fderiv_at f₁ f' x := (h₁.has_strict_fderiv_at_iff (λ _, rfl)).1 h theorem filter.eventually_eq.has_fderiv_at_filter_iff (h₀ : f₀ =ᶠ[L] f₁) (hx : f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) : has_fderiv_at_filter f₀ f₀' x L ↔ has_fderiv_at_filter f₁ f₁' x L := is_o_congr (h₀.mono $ λ y hy, by simp only [hy, h₁, hx]) (eventually_of_forall $ λ _, rfl) lemma has_fderiv_at_filter.congr_of_eventually_eq (h : has_fderiv_at_filter f f' x L) (hL : f₁ =ᶠ[L] f) (hx : f₁ x = f x) : has_fderiv_at_filter f₁ f' x L := (hL.has_fderiv_at_filter_iff hx $ λ _, rfl).2 h theorem filter.eventually_eq.has_fderiv_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) : has_fderiv_at f₀ f' x ↔ has_fderiv_at f₁ f' x := h.has_fderiv_at_filter_iff h.eq_of_nhds (λ _, rfl) theorem filter.eventually_eq.differentiable_at_iff (h : f₀ =ᶠ[𝓝 x] f₁) : differentiable_at 𝕜 f₀ x ↔ differentiable_at 𝕜 f₁ x := exists_congr $ λ f', h.has_fderiv_at_iff theorem filter.eventually_eq.has_fderiv_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x := h.has_fderiv_at_filter_iff hx (λ _, rfl) theorem filter.eventually_eq.has_fderiv_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : has_fderiv_within_at f₀ f' s x ↔ has_fderiv_within_at f₁ f' s x := h.has_fderiv_within_at_iff (h.eq_of_nhds_within hx) theorem filter.eventually_eq.differentiable_within_at_iff (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : f₀ x = f₁ x) : differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x := exists_congr $ λ f', h.has_fderiv_within_at_iff hx theorem filter.eventually_eq.differentiable_within_at_iff_of_mem (h : f₀ =ᶠ[𝓝[s] x] f₁) (hx : x ∈ s) : differentiable_within_at 𝕜 f₀ s x ↔ differentiable_within_at 𝕜 f₁ s x := h.differentiable_within_at_iff (h.eq_of_nhds_within hx) lemma has_fderiv_within_at.congr_mono (h : has_fderiv_within_at f f' s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : has_fderiv_within_at f₁ f' t x := has_fderiv_at_filter.congr_of_eventually_eq (h.mono h₁) (filter.mem_inf_of_right ht) hx lemma has_fderiv_within_at.congr (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x := h.congr_mono hs hx (subset.refl _) lemma has_fderiv_within_at.congr' (h : has_fderiv_within_at f f' s x) (hs : ∀x ∈ s, f₁ x = f x) (hx : x ∈ s) : has_fderiv_within_at f₁ f' s x := h.congr hs (hs x hx) lemma has_fderiv_within_at.congr_of_eventually_eq (h : has_fderiv_within_at f f' s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : has_fderiv_within_at f₁ f' s x := has_fderiv_at_filter.congr_of_eventually_eq h h₁ hx lemma has_fderiv_at.congr_of_eventually_eq (h : has_fderiv_at f f' x) (h₁ : f₁ =ᶠ[𝓝 x] f) : has_fderiv_at f₁ f' x := has_fderiv_at_filter.congr_of_eventually_eq h h₁ (mem_of_mem_nhds h₁ : _) lemma differentiable_within_at.congr_mono (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : differentiable_within_at 𝕜 f₁ t x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at ht hx h₁).differentiable_within_at lemma differentiable_within_at.congr (h : differentiable_within_at 𝕜 f s x) (ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := differentiable_within_at.congr_mono h ht hx (subset.refl _) lemma differentiable_within_at.congr_of_eventually_eq (h : differentiable_within_at 𝕜 f s x) (h₁ : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : differentiable_within_at 𝕜 f₁ s x := (h.has_fderiv_within_at.congr_of_eventually_eq h₁ hx).differentiable_within_at lemma differentiable_on.congr_mono (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ t, f₁ x = f x) (h₁ : t ⊆ s) : differentiable_on 𝕜 f₁ t := λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁ lemma differentiable_on.congr (h : differentiable_on 𝕜 f s) (h' : ∀x ∈ s, f₁ x = f x) : differentiable_on 𝕜 f₁ s := λ x hx, (h x hx).congr h' (h' x hx) lemma differentiable_on_congr (h' : ∀x ∈ s, f₁ x = f x) : differentiable_on 𝕜 f₁ s ↔ differentiable_on 𝕜 f s := ⟨λ h, differentiable_on.congr h (λy hy, (h' y hy).symm), λ h, differentiable_on.congr h h'⟩ lemma differentiable_at.congr_of_eventually_eq (h : differentiable_at 𝕜 f x) (hL : f₁ =ᶠ[𝓝 x] f) : differentiable_at 𝕜 f₁ x := hL.differentiable_at_iff.2 h lemma differentiable_within_at.fderiv_within_congr_mono (h : differentiable_within_at 𝕜 f s x) (hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_diff_within_at 𝕜 t x) (h₁ : t ⊆ s) : fderiv_within 𝕜 f₁ t x = fderiv_within 𝕜 f s x := (has_fderiv_within_at.congr_mono h.has_fderiv_within_at hs hx h₁).fderiv_within hxt lemma filter.eventually_eq.fderiv_within_eq (hs : unique_diff_within_at 𝕜 s x) (hL : f₁ =ᶠ[𝓝[s] x] f) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := if h : differentiable_within_at 𝕜 f s x then has_fderiv_within_at.fderiv_within (h.has_fderiv_within_at.congr_of_eventually_eq hL hx) hs else have h' : ¬ differentiable_within_at 𝕜 f₁ s x, from mt (λ h, h.congr_of_eventually_eq (hL.mono $ λ x, eq.symm) hx.symm) h, by rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at h'] lemma fderiv_within_congr (hs : unique_diff_within_at 𝕜 s x) (hL : ∀y∈s, f₁ y = f y) (hx : f₁ x = f x) : fderiv_within 𝕜 f₁ s x = fderiv_within 𝕜 f s x := begin apply filter.eventually_eq.fderiv_within_eq hs _ hx, apply mem_of_superset self_mem_nhds_within, exact hL end lemma filter.eventually_eq.fderiv_eq (hL : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ x = fderiv 𝕜 f x := begin have A : f₁ x = f x := hL.eq_of_nhds, rw [← fderiv_within_univ, ← fderiv_within_univ], rw ← nhds_within_univ at hL, exact hL.fderiv_within_eq unique_diff_within_at_univ A end protected lemma filter.eventually_eq.fderiv (h : f₁ =ᶠ[𝓝 x] f) : fderiv 𝕜 f₁ =ᶠ[𝓝 x] fderiv 𝕜 f := h.eventually_eq_nhds.mono $ λ x h, h.fderiv_eq end congr section id /-! ### Derivative of the identity -/ theorem has_strict_fderiv_at_id (x : E) : has_strict_fderiv_at id (id 𝕜 E) x := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_at_filter_id (x : E) (L : filter E) : has_fderiv_at_filter id (id 𝕜 E) x L := (is_o_zero _ _).congr_left $ by simp theorem has_fderiv_within_at_id (x : E) (s : set E) : has_fderiv_within_at id (id 𝕜 E) s x := has_fderiv_at_filter_id _ _ theorem has_fderiv_at_id (x : E) : has_fderiv_at id (id 𝕜 E) x := has_fderiv_at_filter_id _ _ @[simp] lemma differentiable_at_id : differentiable_at 𝕜 id x := (has_fderiv_at_id x).differentiable_at @[simp] lemma differentiable_at_id' : differentiable_at 𝕜 (λ x, x) x := (has_fderiv_at_id x).differentiable_at lemma differentiable_within_at_id : differentiable_within_at 𝕜 id s x := differentiable_at_id.differentiable_within_at @[simp] lemma differentiable_id : differentiable 𝕜 (id : E → E) := λx, differentiable_at_id @[simp] lemma differentiable_id' : differentiable 𝕜 (λ (x : E), x) := λx, differentiable_at_id lemma differentiable_on_id : differentiable_on 𝕜 id s := differentiable_id.differentiable_on lemma fderiv_id : fderiv 𝕜 id x = id 𝕜 E := has_fderiv_at.fderiv (has_fderiv_at_id x) @[simp] lemma fderiv_id' : fderiv 𝕜 (λ (x : E), x) x = continuous_linear_map.id 𝕜 E := fderiv_id lemma fderiv_within_id (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 id s x = id 𝕜 E := begin rw differentiable_at.fderiv_within (differentiable_at_id) hxs, exact fderiv_id end lemma fderiv_within_id' (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λ (x : E), x) s x = continuous_linear_map.id 𝕜 E := fderiv_within_id hxs end id section const /-! ### derivative of a constant function -/ theorem has_strict_fderiv_at_const (c : F) (x : E) : has_strict_fderiv_at (λ _, c) (0 : E →L[𝕜] F) x := (is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self] theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) : has_fderiv_at_filter (λ x, c) (0 : E →L[𝕜] F) x L := (is_o_zero _ _).congr_left $ λ _, by simp only [zero_apply, sub_self] theorem has_fderiv_within_at_const (c : F) (x : E) (s : set E) : has_fderiv_within_at (λ x, c) (0 : E →L[𝕜] F) s x := has_fderiv_at_filter_const _ _ _ theorem has_fderiv_at_const (c : F) (x : E) : has_fderiv_at (λ x, c) (0 : E →L[𝕜] F) x := has_fderiv_at_filter_const _ _ _ @[simp] lemma differentiable_at_const (c : F) : differentiable_at 𝕜 (λx, c) x := ⟨0, has_fderiv_at_const c x⟩ lemma differentiable_within_at_const (c : F) : differentiable_within_at 𝕜 (λx, c) s x := differentiable_at.differentiable_within_at (differentiable_at_const _) lemma fderiv_const_apply (c : F) : fderiv 𝕜 (λy, c) x = 0 := has_fderiv_at.fderiv (has_fderiv_at_const c x) @[simp] lemma fderiv_const (c : F) : fderiv 𝕜 (λ (y : E), c) = 0 := by { ext m, rw fderiv_const_apply, refl } lemma fderiv_within_const_apply (c : F) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λy, c) s x = 0 := begin rw differentiable_at.fderiv_within (differentiable_at_const _) hxs, exact fderiv_const_apply _ end @[simp] lemma differentiable_const (c : F) : differentiable 𝕜 (λx : E, c) := λx, differentiable_at_const _ lemma differentiable_on_const (c : F) : differentiable_on 𝕜 (λx, c) s := (differentiable_const _).differentiable_on lemma has_fderiv_within_at_singleton (f : E → F) (x : E) : has_fderiv_within_at f (0 : E →L[𝕜] F) {x} x := by simp only [has_fderiv_within_at, nhds_within_singleton, has_fderiv_at_filter, is_o_pure, continuous_linear_map.zero_apply, sub_self] lemma has_fderiv_at_of_subsingleton [h : subsingleton E] (f : E → F) (x : E) : has_fderiv_at f (0 : E →L[𝕜] F) x := begin rw [← has_fderiv_within_at_univ, subsingleton_univ.eq_singleton_of_mem (mem_univ x)], exact has_fderiv_within_at_singleton f x end lemma differentiable_on_empty : differentiable_on 𝕜 f ∅ := λ x, false.elim lemma differentiable_on_singleton : differentiable_on 𝕜 f {x} := forall_eq.2 (has_fderiv_within_at_singleton f x).differentiable_within_at lemma set.subsingleton.differentiable_on (hs : s.subsingleton) : differentiable_on 𝕜 f s := hs.induction_on differentiable_on_empty (λ x, differentiable_on_singleton) end const section continuous_linear_map /-! ### Continuous linear maps There are currently two variants of these in mathlib, the bundled version (named `continuous_linear_map`, and denoted `E →L[𝕜] F`), and the unbundled version (with a predicate `is_bounded_linear_map`). We give statements for both versions. -/ protected theorem continuous_linear_map.has_strict_fderiv_at {x : E} : has_strict_fderiv_at e e x := (is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self] protected lemma continuous_linear_map.has_fderiv_at_filter : has_fderiv_at_filter e e x L := (is_o_zero _ _).congr_left $ λ x, by simp only [e.map_sub, sub_self] protected lemma continuous_linear_map.has_fderiv_within_at : has_fderiv_within_at e e s x := e.has_fderiv_at_filter protected lemma continuous_linear_map.has_fderiv_at : has_fderiv_at e e x := e.has_fderiv_at_filter @[simp] protected lemma continuous_linear_map.differentiable_at : differentiable_at 𝕜 e x := e.has_fderiv_at.differentiable_at protected lemma continuous_linear_map.differentiable_within_at : differentiable_within_at 𝕜 e s x := e.differentiable_at.differentiable_within_at @[simp] protected lemma continuous_linear_map.fderiv : fderiv 𝕜 e x = e := e.has_fderiv_at.fderiv protected lemma continuous_linear_map.fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 e s x = e := begin rw differentiable_at.fderiv_within e.differentiable_at hxs, exact e.fderiv end @[simp] protected lemma continuous_linear_map.differentiable : differentiable 𝕜 e := λx, e.differentiable_at protected lemma continuous_linear_map.differentiable_on : differentiable_on 𝕜 e s := e.differentiable.differentiable_on lemma is_bounded_linear_map.has_fderiv_at_filter (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at_filter f h.to_continuous_linear_map x L := h.to_continuous_linear_map.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_within_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_within_at f h.to_continuous_linear_map s x := h.has_fderiv_at_filter lemma is_bounded_linear_map.has_fderiv_at (h : is_bounded_linear_map 𝕜 f) : has_fderiv_at f h.to_continuous_linear_map x := h.has_fderiv_at_filter lemma is_bounded_linear_map.differentiable_at (h : is_bounded_linear_map 𝕜 f) : differentiable_at 𝕜 f x := h.has_fderiv_at.differentiable_at lemma is_bounded_linear_map.differentiable_within_at (h : is_bounded_linear_map 𝕜 f) : differentiable_within_at 𝕜 f s x := h.differentiable_at.differentiable_within_at lemma is_bounded_linear_map.fderiv (h : is_bounded_linear_map 𝕜 f) : fderiv 𝕜 f x = h.to_continuous_linear_map := has_fderiv_at.fderiv (h.has_fderiv_at) lemma is_bounded_linear_map.fderiv_within (h : is_bounded_linear_map 𝕜 f) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 f s x = h.to_continuous_linear_map := begin rw differentiable_at.fderiv_within h.differentiable_at hxs, exact h.fderiv end lemma is_bounded_linear_map.differentiable (h : is_bounded_linear_map 𝕜 f) : differentiable 𝕜 f := λx, h.differentiable_at lemma is_bounded_linear_map.differentiable_on (h : is_bounded_linear_map 𝕜 f) : differentiable_on 𝕜 f s := h.differentiable.differentiable_on end continuous_linear_map section composition /-! ### Derivative of the composition of two functions For composition lemmas, we put x explicit to help the elaborator, as otherwise Lean tends to get confused since there are too many possibilities for composition -/ variable (x) theorem has_fderiv_at_filter.comp {g : F → G} {g' : F →L[𝕜] G} {L' : filter F} (hg : has_fderiv_at_filter g g' (f x) L') (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L') : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := let eq₁ := (g'.is_O_comp _ _).trans_is_o hf in let eq₂ := (hg.comp_tendsto hL).trans_is_O hf.is_O_sub in by { refine eq₂.triangle (eq₁.congr_left (λ x', _)), simp } /- A readable version of the previous theorem, a general form of the chain rule. -/ example {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at_filter g g' (f x) (L.map f)) (hf : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (g ∘ f) (g'.comp f') x L := begin unfold has_fderiv_at_filter at hg, have : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', f x' - f x) L, from hg.comp_tendsto le_rfl, 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₁.triangle 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 : maps_to f s t) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := hg.comp x hf $ hf.continuous_within_at.tendsto_nhds_within hst theorem has_fderiv_at.comp_has_fderiv_within_at {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (g ∘ f) (g'.comp f') s x := hg.comp x hf hf.continuous_within_at /-- The chain rule. -/ theorem has_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_fderiv_at g g' (f x)) (hf : has_fderiv_at f f' x) : has_fderiv_at (g ∘ f) (g'.comp f') x := hg.comp x hf hf.continuous_at lemma differentiable_within_at.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : maps_to f s t) : differentiable_within_at 𝕜 (g ∘ f) s x := (hg.has_fderiv_within_at.comp x hf.has_fderiv_within_at h).differentiable_within_at lemma differentiable_within_at.comp' {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (g ∘ f) (s ∩ f⁻¹' t) x := hg.comp x (hf.mono (inter_subset_left _ _)) (inter_subset_right _ _) lemma differentiable_at.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (g ∘ f) x := (hg.has_fderiv_at.comp x hf.has_fderiv_at).differentiable_at lemma differentiable_at.comp_differentiable_within_at {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (g ∘ f) s x := hg.differentiable_within_at.comp x hf (maps_to_univ _ _) lemma fderiv_within.comp {g : F → G} {t : set F} (hg : differentiable_within_at 𝕜 g t (f x)) (hf : differentiable_within_at 𝕜 f s x) (h : maps_to f s t) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g ∘ f) s x = (fderiv_within 𝕜 g t (f x)).comp (fderiv_within 𝕜 f s x) := (hg.has_fderiv_within_at.comp x (hf.has_fderiv_within_at) h).fderiv_within hxs lemma fderiv.comp {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (g ∘ f) x = (fderiv 𝕜 g (f x)).comp (fderiv 𝕜 f x) := (hg.has_fderiv_at.comp x hf.has_fderiv_at).fderiv lemma fderiv.comp_fderiv_within {g : F → G} (hg : differentiable_at 𝕜 g (f x)) (hf : differentiable_within_at 𝕜 f s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (g ∘ f) s x = (fderiv 𝕜 g (f x)).comp (fderiv_within 𝕜 f s x) := (hg.has_fderiv_at.comp_has_fderiv_within_at x hf.has_fderiv_within_at).fderiv_within hxs lemma differentiable_on.comp {g : F → G} {t : set F} (hg : differentiable_on 𝕜 g t) (hf : differentiable_on 𝕜 f s) (st : maps_to f s t) : differentiable_on 𝕜 (g ∘ f) s := λx hx, differentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st lemma differentiable.comp {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable 𝕜 f) : differentiable 𝕜 (g ∘ f) := λx, differentiable_at.comp x (hg (f x)) (hf x) lemma differentiable.comp_differentiable_on {g : F → G} (hg : differentiable 𝕜 g) (hf : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (g ∘ f) s := hg.differentiable_on.comp hf (maps_to_univ _ _) /-- The chain rule for derivatives in the sense of strict differentiability. -/ protected lemma has_strict_fderiv_at.comp {g : F → G} {g' : F →L[𝕜] G} (hg : has_strict_fderiv_at g g' (f x)) (hf : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ x, g (f x)) (g'.comp f') x := ((hg.comp_tendsto (hf.continuous_at.prod_map' hf.continuous_at)).trans_is_O hf.is_O_sub).triangle $ by simpa only [g'.map_sub, f'.coe_comp'] using (g'.is_O_comp _ _).trans_is_o hf protected lemma differentiable.iterate {f : E → E} (hf : differentiable 𝕜 f) (n : ℕ) : differentiable 𝕜 (f^[n]) := nat.rec_on n differentiable_id (λ n ihn, ihn.comp hf) protected lemma differentiable_on.iterate {f : E → E} (hf : differentiable_on 𝕜 f s) (hs : maps_to f s s) (n : ℕ) : differentiable_on 𝕜 (f^[n]) s := nat.rec_on n differentiable_on_id (λ n ihn, ihn.comp hf hs) variable {x} protected lemma has_fderiv_at_filter.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_at_filter f f' x L) (hL : tendsto f L L) (hx : f x = x) (n : ℕ) : has_fderiv_at_filter (f^[n]) (f'^n) x L := begin induction n with n ihn, { exact has_fderiv_at_filter_id x L }, { rw [function.iterate_succ, pow_succ'], rw ← hx at ihn, exact ihn.comp x hf hL } end protected lemma has_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_at f f' x) (hx : f x = x) (n : ℕ) : has_fderiv_at (f^[n]) (f'^n) x := begin refine hf.iterate _ hx n, convert hf.continuous_at, exact hx.symm end protected lemma has_fderiv_within_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_fderiv_within_at f f' s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) : has_fderiv_within_at (f^[n]) (f'^n) s x := begin refine hf.iterate _ hx n, convert tendsto_inf.2 ⟨hf.continuous_within_at, _⟩, exacts [hx.symm, (tendsto_principal_principal.2 hs).mono_left inf_le_right] end protected lemma has_strict_fderiv_at.iterate {f : E → E} {f' : E →L[𝕜] E} (hf : has_strict_fderiv_at f f' x) (hx : f x = x) (n : ℕ) : has_strict_fderiv_at (f^[n]) (f'^n) x := begin induction n with n ihn, { exact has_strict_fderiv_at_id x }, { rw [function.iterate_succ, pow_succ'], rw ← hx at ihn, exact ihn.comp x hf } end protected lemma differentiable_at.iterate {f : E → E} (hf : differentiable_at 𝕜 f x) (hx : f x = x) (n : ℕ) : differentiable_at 𝕜 (f^[n]) x := (hf.has_fderiv_at.iterate hx n).differentiable_at protected lemma differentiable_within_at.iterate {f : E → E} (hf : differentiable_within_at 𝕜 f s x) (hx : f x = x) (hs : maps_to f s s) (n : ℕ) : differentiable_within_at 𝕜 (f^[n]) s x := (hf.has_fderiv_within_at.iterate hx hs n).differentiable_within_at end composition section cartesian_product /-! ### Derivative of the cartesian product of two functions -/ section prod variables {f₂ : E → G} {f₂' : E →L[𝕜] G} protected lemma has_strict_fderiv_at.prod (hf₁ : has_strict_fderiv_at f₁ f₁' x) (hf₂ : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod_left hf₂ lemma has_fderiv_at_filter.prod (hf₁ : has_fderiv_at_filter f₁ f₁' x L) (hf₂ : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x L := hf₁.prod_left hf₂ lemma has_fderiv_within_at.prod (hf₁ : has_fderiv_within_at f₁ f₁' s x) (hf₂ : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') s x := hf₁.prod hf₂ lemma has_fderiv_at.prod (hf₁ : has_fderiv_at f₁ f₁' x) (hf₂ : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λx, (f₁ x, f₂ x)) (f₁'.prod f₂') x := hf₁.prod hf₂ lemma has_fderiv_at_prod_mk_left (e₀ : E) (f₀ : F) : has_fderiv_at (λ e : E, (e, f₀)) (inl 𝕜 E F) e₀ := (has_fderiv_at_id e₀).prod (has_fderiv_at_const f₀ e₀) lemma has_fderiv_at_prod_mk_right (e₀ : E) (f₀ : F) : has_fderiv_at (λ f : F, (e₀, f)) (inr 𝕜 E F) f₀ := (has_fderiv_at_const e₀ f₀).prod (has_fderiv_at_id f₀) lemma differentiable_within_at.prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λx:E, (f₁ x, f₂ x)) s x := (hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λx:E, (f₁ x, f₂ x)) x := (hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).differentiable_at lemma differentiable_on.prod (hf₁ : differentiable_on 𝕜 f₁ s) (hf₂ : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λx:E, (f₁ x, f₂ x)) s := λx hx, differentiable_within_at.prod (hf₁ x hx) (hf₂ x hx) @[simp] lemma differentiable.prod (hf₁ : differentiable 𝕜 f₁) (hf₂ : differentiable 𝕜 f₂) : differentiable 𝕜 (λx:E, (f₁ x, f₂ x)) := λ x, differentiable_at.prod (hf₁ x) (hf₂ x) lemma differentiable_at.fderiv_prod (hf₁ : differentiable_at 𝕜 f₁ x) (hf₂ : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λx:E, (f₁ x, f₂ x)) x = (fderiv 𝕜 f₁ x).prod (fderiv 𝕜 f₂ x) := (hf₁.has_fderiv_at.prod hf₂.has_fderiv_at).fderiv lemma differentiable_at.fderiv_within_prod (hf₁ : differentiable_within_at 𝕜 f₁ s x) (hf₂ : differentiable_within_at 𝕜 f₂ s x) (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λx:E, (f₁ x, f₂ x)) s x = (fderiv_within 𝕜 f₁ s x).prod (fderiv_within 𝕜 f₂ s x) := (hf₁.has_fderiv_within_at.prod hf₂.has_fderiv_within_at).fderiv_within hxs end prod section fst variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} lemma has_strict_fderiv_at_fst : has_strict_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p := (fst 𝕜 E F).has_strict_fderiv_at protected lemma has_strict_fderiv_at.fst (h : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := has_strict_fderiv_at_fst.comp x h lemma has_fderiv_at_filter_fst {L : filter (E × F)} : has_fderiv_at_filter (@prod.fst E F) (fst 𝕜 E F) p L := (fst 𝕜 E F).has_fderiv_at_filter protected lemma has_fderiv_at_filter.fst (h : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x L := has_fderiv_at_filter_fst.comp x h tendsto_map lemma has_fderiv_at_fst : has_fderiv_at (@prod.fst E F) (fst 𝕜 E F) p := has_fderiv_at_filter_fst protected lemma has_fderiv_at.fst (h : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') x := h.fst lemma has_fderiv_within_at_fst {s : set (E × F)} : has_fderiv_within_at (@prod.fst E F) (fst 𝕜 E F) s p := has_fderiv_at_filter_fst protected lemma has_fderiv_within_at.fst (h : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λ x, (f₂ x).1) ((fst 𝕜 F G).comp f₂') s x := h.fst lemma differentiable_at_fst : differentiable_at 𝕜 prod.fst p := has_fderiv_at_fst.differentiable_at @[simp] protected lemma differentiable_at.fst (h : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λ x, (f₂ x).1) x := differentiable_at_fst.comp x h lemma differentiable_fst : differentiable 𝕜 (prod.fst : E × F → E) := λ x, differentiable_at_fst @[simp] protected lemma differentiable.fst (h : differentiable 𝕜 f₂) : differentiable 𝕜 (λ x, (f₂ x).1) := differentiable_fst.comp h lemma differentiable_within_at_fst {s : set (E × F)} : differentiable_within_at 𝕜 prod.fst s p := differentiable_at_fst.differentiable_within_at protected lemma differentiable_within_at.fst (h : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λ x, (f₂ x).1) s x := differentiable_at_fst.comp_differentiable_within_at x h lemma differentiable_on_fst {s : set (E × F)} : differentiable_on 𝕜 prod.fst s := differentiable_fst.differentiable_on protected lemma differentiable_on.fst (h : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λ x, (f₂ x).1) s := differentiable_fst.comp_differentiable_on h lemma fderiv_fst : fderiv 𝕜 prod.fst p = fst 𝕜 E F := has_fderiv_at_fst.fderiv lemma fderiv.fst (h : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λ x, (f₂ x).1) x = (fst 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.has_fderiv_at.fst.fderiv lemma fderiv_within_fst {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) : fderiv_within 𝕜 prod.fst s p = fst 𝕜 E F := has_fderiv_within_at_fst.fderiv_within hs lemma fderiv_within.fst (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) : fderiv_within 𝕜 (λ x, (f₂ x).1) s x = (fst 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) := h.has_fderiv_within_at.fst.fderiv_within hs end fst section snd variables {f₂ : E → F × G} {f₂' : E →L[𝕜] F × G} {p : E × F} lemma has_strict_fderiv_at_snd : has_strict_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p := (snd 𝕜 E F).has_strict_fderiv_at protected lemma has_strict_fderiv_at.snd (h : has_strict_fderiv_at f₂ f₂' x) : has_strict_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := has_strict_fderiv_at_snd.comp x h lemma has_fderiv_at_filter_snd {L : filter (E × F)} : has_fderiv_at_filter (@prod.snd E F) (snd 𝕜 E F) p L := (snd 𝕜 E F).has_fderiv_at_filter protected lemma has_fderiv_at_filter.snd (h : has_fderiv_at_filter f₂ f₂' x L) : has_fderiv_at_filter (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x L := has_fderiv_at_filter_snd.comp x h tendsto_map lemma has_fderiv_at_snd : has_fderiv_at (@prod.snd E F) (snd 𝕜 E F) p := has_fderiv_at_filter_snd protected lemma has_fderiv_at.snd (h : has_fderiv_at f₂ f₂' x) : has_fderiv_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') x := h.snd lemma has_fderiv_within_at_snd {s : set (E × F)} : has_fderiv_within_at (@prod.snd E F) (snd 𝕜 E F) s p := has_fderiv_at_filter_snd protected lemma has_fderiv_within_at.snd (h : has_fderiv_within_at f₂ f₂' s x) : has_fderiv_within_at (λ x, (f₂ x).2) ((snd 𝕜 F G).comp f₂') s x := h.snd lemma differentiable_at_snd : differentiable_at 𝕜 prod.snd p := has_fderiv_at_snd.differentiable_at @[simp] protected lemma differentiable_at.snd (h : differentiable_at 𝕜 f₂ x) : differentiable_at 𝕜 (λ x, (f₂ x).2) x := differentiable_at_snd.comp x h lemma differentiable_snd : differentiable 𝕜 (prod.snd : E × F → F) := λ x, differentiable_at_snd @[simp] protected lemma differentiable.snd (h : differentiable 𝕜 f₂) : differentiable 𝕜 (λ x, (f₂ x).2) := differentiable_snd.comp h lemma differentiable_within_at_snd {s : set (E × F)} : differentiable_within_at 𝕜 prod.snd s p := differentiable_at_snd.differentiable_within_at protected lemma differentiable_within_at.snd (h : differentiable_within_at 𝕜 f₂ s x) : differentiable_within_at 𝕜 (λ x, (f₂ x).2) s x := differentiable_at_snd.comp_differentiable_within_at x h lemma differentiable_on_snd {s : set (E × F)} : differentiable_on 𝕜 prod.snd s := differentiable_snd.differentiable_on protected lemma differentiable_on.snd (h : differentiable_on 𝕜 f₂ s) : differentiable_on 𝕜 (λ x, (f₂ x).2) s := differentiable_snd.comp_differentiable_on h lemma fderiv_snd : fderiv 𝕜 prod.snd p = snd 𝕜 E F := has_fderiv_at_snd.fderiv lemma fderiv.snd (h : differentiable_at 𝕜 f₂ x) : fderiv 𝕜 (λ x, (f₂ x).2) x = (snd 𝕜 F G).comp (fderiv 𝕜 f₂ x) := h.has_fderiv_at.snd.fderiv lemma fderiv_within_snd {s : set (E × F)} (hs : unique_diff_within_at 𝕜 s p) : fderiv_within 𝕜 prod.snd s p = snd 𝕜 E F := has_fderiv_within_at_snd.fderiv_within hs lemma fderiv_within.snd (hs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f₂ s x) : fderiv_within 𝕜 (λ x, (f₂ x).2) s x = (snd 𝕜 F G).comp (fderiv_within 𝕜 f₂ s x) := h.has_fderiv_within_at.snd.fderiv_within hs end snd section prod_map variables {f₂ : G → G'} {f₂' : G →L[𝕜] G'} {y : G} (p : E × G) protected theorem has_strict_fderiv_at.prod_map (hf : has_strict_fderiv_at f f' p.1) (hf₂ : has_strict_fderiv_at f₂ f₂' p.2) : has_strict_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p := (hf.comp p has_strict_fderiv_at_fst).prod (hf₂.comp p has_strict_fderiv_at_snd) protected theorem has_fderiv_at.prod_map (hf : has_fderiv_at f f' p.1) (hf₂ : has_fderiv_at f₂ f₂' p.2) : has_fderiv_at (prod.map f f₂) (f'.prod_map f₂') p := (hf.comp p has_fderiv_at_fst).prod (hf₂.comp p has_fderiv_at_snd) @[simp] protected theorem differentiable_at.prod_map (hf : differentiable_at 𝕜 f p.1) (hf₂ : differentiable_at 𝕜 f₂ p.2) : differentiable_at 𝕜 (λ p : E × G, (f p.1, f₂ p.2)) p := (hf.comp p differentiable_at_fst).prod (hf₂.comp p differentiable_at_snd) end prod_map end cartesian_product section const_smul variables {R : Type*} [semiring R] [module R F] [smul_comm_class 𝕜 R F] [has_continuous_const_smul R F] /-! ### Derivative of a function multiplied by a constant -/ theorem has_strict_fderiv_at.const_smul (h : has_strict_fderiv_at f f' x) (c : R) : has_strict_fderiv_at (λ x, c • f x) (c • f') x := (c • (1 : F →L[𝕜] F)).has_strict_fderiv_at.comp x h theorem has_fderiv_at_filter.const_smul (h : has_fderiv_at_filter f f' x L) (c : R) : has_fderiv_at_filter (λ x, c • f x) (c • f') x L := (c • (1 : F →L[𝕜] F)).has_fderiv_at_filter.comp x h tendsto_map theorem has_fderiv_within_at.const_smul (h : has_fderiv_within_at f f' s x) (c : R) : has_fderiv_within_at (λ x, c • f x) (c • f') s x := h.const_smul c theorem has_fderiv_at.const_smul (h : has_fderiv_at f f' x) (c : R) : has_fderiv_at (λ x, c • f x) (c • f') x := h.const_smul c lemma differentiable_within_at.const_smul (h : differentiable_within_at 𝕜 f s x) (c : R) : differentiable_within_at 𝕜 (λy, c • f y) s x := (h.has_fderiv_within_at.const_smul c).differentiable_within_at lemma differentiable_at.const_smul (h : differentiable_at 𝕜 f x) (c : R) : differentiable_at 𝕜 (λy, c • f y) x := (h.has_fderiv_at.const_smul c).differentiable_at lemma differentiable_on.const_smul (h : differentiable_on 𝕜 f s) (c : R) : differentiable_on 𝕜 (λy, c • f y) s := λx hx, (h x hx).const_smul c lemma differentiable.const_smul (h : differentiable 𝕜 f) (c : R) : differentiable 𝕜 (λy, c • f y) := λx, (h x).const_smul c lemma fderiv_within_const_smul (hxs : unique_diff_within_at 𝕜 s x) (h : differentiable_within_at 𝕜 f s x) (c : R) : fderiv_within 𝕜 (λy, c • f y) s x = c • fderiv_within 𝕜 f s x := (h.has_fderiv_within_at.const_smul c).fderiv_within hxs lemma fderiv_const_smul (h : differentiable_at 𝕜 f x) (c : R) : fderiv 𝕜 (λy, c • f y) x = c • fderiv 𝕜 f x := (h.has_fderiv_at.const_smul c).fderiv end const_smul section add /-! ### Derivative of the sum of two functions -/ theorem has_strict_fderiv_at.add (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (λ y, f y + g y) (f' + g') x := (hf.add hg).congr_left $ λ y, by simp; abel theorem has_fderiv_at_filter.add (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ y, f y + g y) (f' + g') x L := (hf.add hg).congr_left $ λ _, by simp; abel theorem has_fderiv_within_at.add (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ y, f y + g y) (f' + g') s x := hf.add hg theorem has_fderiv_at.add (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x + g x) (f' + g') x := hf.add hg lemma differentiable_within_at.add (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y + g y) s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y + g y) x := (hf.has_fderiv_at.add hg.has_fderiv_at).differentiable_at lemma differentiable_on.add (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y + g y) s := λx hx, (hf x hx).add (hg x hx) @[simp] lemma differentiable.add (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y + g y) := λx, (hf x).add (hg x) lemma fderiv_within_add (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y + g y) s x = fderiv_within 𝕜 f s x + fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.add hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_add (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y + g y) x = fderiv 𝕜 f x + fderiv 𝕜 g x := (hf.has_fderiv_at.add hg.has_fderiv_at).fderiv theorem has_strict_fderiv_at.add_const (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ y, f y + c) f' x := add_zero f' ▸ hf.add (has_strict_fderiv_at_const _ _) theorem has_fderiv_at_filter.add_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ y, f y + c) f' x L := add_zero f' ▸ hf.add (has_fderiv_at_filter_const _ _ _) theorem has_fderiv_within_at.add_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ y, f y + c) f' s x := hf.add_const c theorem has_fderiv_at.add_const (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (λ x, f x + c) f' x := hf.add_const c lemma differentiable_within_at.add_const (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, f y + c) s x := (hf.has_fderiv_within_at.add_const c).differentiable_within_at @[simp] lemma differentiable_within_at_add_const_iff (c : F) : differentiable_within_at 𝕜 (λ y, f y + c) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable_at.add_const (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, f y + c) x := (hf.has_fderiv_at.add_const c).differentiable_at @[simp] lemma differentiable_at_add_const_iff (c : F) : differentiable_at 𝕜 (λ y, f y + c) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable_on.add_const (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, f y + c) s := λx hx, (hf x hx).add_const c @[simp] lemma differentiable_on_add_const_iff (c : F) : differentiable_on 𝕜 (λ y, f y + c) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma differentiable.add_const (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, f y + c) := λx, (hf x).add_const c @[simp] lemma differentiable_add_const_iff (c : F) : differentiable 𝕜 (λ y, f y + c) ↔ differentiable 𝕜 f := ⟨λ h, by simpa using h.add_const (-c), λ h, h.add_const c⟩ lemma fderiv_within_add_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, f y + c) s x = fderiv_within 𝕜 f s x := if hf : differentiable_within_at 𝕜 f s x then (hf.has_fderiv_within_at.add_const c).fderiv_within hxs else by { rw [fderiv_within_zero_of_not_differentiable_within_at hf, fderiv_within_zero_of_not_differentiable_within_at], simpa } lemma fderiv_add_const (c : F) : fderiv 𝕜 (λy, f y + c) x = fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_add_const unique_diff_within_at_univ] theorem has_strict_fderiv_at.const_add (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ y, c + f y) f' x := zero_add f' ▸ (has_strict_fderiv_at_const _ _).add hf theorem has_fderiv_at_filter.const_add (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ y, c + f y) f' x L := zero_add f' ▸ (has_fderiv_at_filter_const _ _ _).add hf theorem has_fderiv_within_at.const_add (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ y, c + f y) f' s x := hf.const_add c theorem has_fderiv_at.const_add (hf : has_fderiv_at f f' x) (c : F): has_fderiv_at (λ x, c + f x) f' x := hf.const_add c lemma differentiable_within_at.const_add (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, c + f y) s x := (hf.has_fderiv_within_at.const_add c).differentiable_within_at @[simp] lemma differentiable_within_at_const_add_iff (c : F) : differentiable_within_at 𝕜 (λ y, c + f y) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable_at.const_add (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, c + f y) x := (hf.has_fderiv_at.const_add c).differentiable_at @[simp] lemma differentiable_at_const_add_iff (c : F) : differentiable_at 𝕜 (λ y, c + f y) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable_on.const_add (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, c + f y) s := λx hx, (hf x hx).const_add c @[simp] lemma differentiable_on_const_add_iff (c : F) : differentiable_on 𝕜 (λ y, c + f y) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma differentiable.const_add (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, c + f y) := λx, (hf x).const_add c @[simp] lemma differentiable_const_add_iff (c : F) : differentiable 𝕜 (λ y, c + f y) ↔ differentiable 𝕜 f := ⟨λ h, by simpa using h.const_add (-c), λ h, h.const_add c⟩ lemma fderiv_within_const_add (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, c + f y) s x = fderiv_within 𝕜 f s x := by simpa only [add_comm] using fderiv_within_add_const hxs c lemma fderiv_const_add (c : F) : fderiv 𝕜 (λy, c + f y) x = fderiv 𝕜 f x := by simp only [add_comm c, fderiv_add_const] end add section sum /-! ### Derivative of a finite sum of functions -/ open_locale big_operators variables {ι : Type*} {u : finset ι} {A : ι → (E → F)} {A' : ι → (E →L[𝕜] F)} theorem has_strict_fderiv_at.sum (h : ∀ i ∈ u, has_strict_fderiv_at (A i) (A' i) x) : has_strict_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x := begin dsimp [has_strict_fderiv_at] at *, convert is_o.sum h, simp [finset.sum_sub_distrib, continuous_linear_map.sum_apply] end theorem has_fderiv_at_filter.sum (h : ∀ i ∈ u, has_fderiv_at_filter (A i) (A' i) x L) : has_fderiv_at_filter (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x L := begin dsimp [has_fderiv_at_filter] at *, convert is_o.sum h, simp [continuous_linear_map.sum_apply] end theorem has_fderiv_within_at.sum (h : ∀ i ∈ u, has_fderiv_within_at (A i) (A' i) s x) : has_fderiv_within_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) s x := has_fderiv_at_filter.sum h theorem has_fderiv_at.sum (h : ∀ i ∈ u, has_fderiv_at (A i) (A' i) x) : has_fderiv_at (λ y, ∑ i in u, A i y) (∑ i in u, A' i) x := has_fderiv_at_filter.sum h theorem differentiable_within_at.sum (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) : differentiable_within_at 𝕜 (λ y, ∑ i in u, A i y) s x := has_fderiv_within_at.differentiable_within_at $ has_fderiv_within_at.sum $ λ i hi, (h i hi).has_fderiv_within_at @[simp] theorem differentiable_at.sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) : differentiable_at 𝕜 (λ y, ∑ i in u, A i y) x := has_fderiv_at.differentiable_at $ has_fderiv_at.sum $ λ i hi, (h i hi).has_fderiv_at theorem differentiable_on.sum (h : ∀ i ∈ u, differentiable_on 𝕜 (A i) s) : differentiable_on 𝕜 (λ y, ∑ i in u, A i y) s := λ x hx, differentiable_within_at.sum $ λ i hi, h i hi x hx @[simp] theorem differentiable.sum (h : ∀ i ∈ u, differentiable 𝕜 (A i)) : differentiable 𝕜 (λ y, ∑ i in u, A i y) := λ x, differentiable_at.sum $ λ i hi, h i hi x theorem fderiv_within_sum (hxs : unique_diff_within_at 𝕜 s x) (h : ∀ i ∈ u, differentiable_within_at 𝕜 (A i) s x) : fderiv_within 𝕜 (λ y, ∑ i in u, A i y) s x = (∑ i in u, fderiv_within 𝕜 (A i) s x) := (has_fderiv_within_at.sum (λ i hi, (h i hi).has_fderiv_within_at)).fderiv_within hxs theorem fderiv_sum (h : ∀ i ∈ u, differentiable_at 𝕜 (A i) x) : fderiv 𝕜 (λ y, ∑ i in u, A i y) x = (∑ i in u, fderiv 𝕜 (A i) x) := (has_fderiv_at.sum (λ i hi, (h i hi).has_fderiv_at)).fderiv end sum section pi /-! ### Derivatives of functions `f : E → Π i, F' i` In this section we formulate `has_*fderiv*_pi` theorems as `iff`s, and provide two versions of each theorem: * the version without `'` deals with `φ : Π i, E → F' i` and `φ' : Π i, E →L[𝕜] F' i` and is designed to deduce differentiability of `λ x i, φ i x` from differentiability of each `φ i`; * the version with `'` deals with `Φ : E → Π i, F' i` and `Φ' : E →L[𝕜] Π i, F' i` and is designed to deduce differentiability of the components `λ x, Φ x i` from differentiability of `Φ`. -/ variables {ι : Type*} [fintype ι] {F' : ι → Type*} [Π i, normed_group (F' i)] [Π i, normed_space 𝕜 (F' i)] {φ : Π i, E → F' i} {φ' : Π i, E →L[𝕜] F' i} {Φ : E → Π i, F' i} {Φ' : E →L[𝕜] Π i, F' i} @[simp] lemma has_strict_fderiv_at_pi' : has_strict_fderiv_at Φ Φ' x ↔ ∀ i, has_strict_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x := begin simp only [has_strict_fderiv_at, continuous_linear_map.coe_pi], exact is_o_pi end @[simp] lemma has_strict_fderiv_at_pi : has_strict_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔ ∀ i, has_strict_fderiv_at (φ i) (φ' i) x := has_strict_fderiv_at_pi' @[simp] lemma has_fderiv_at_filter_pi' : has_fderiv_at_filter Φ Φ' x L ↔ ∀ i, has_fderiv_at_filter (λ x, Φ x i) ((proj i).comp Φ') x L := begin simp only [has_fderiv_at_filter, continuous_linear_map.coe_pi], exact is_o_pi end lemma has_fderiv_at_filter_pi : has_fderiv_at_filter (λ x i, φ i x) (continuous_linear_map.pi φ') x L ↔ ∀ i, has_fderiv_at_filter (φ i) (φ' i) x L := has_fderiv_at_filter_pi' @[simp] lemma has_fderiv_at_pi' : has_fderiv_at Φ Φ' x ↔ ∀ i, has_fderiv_at (λ x, Φ x i) ((proj i).comp Φ') x := has_fderiv_at_filter_pi' lemma has_fderiv_at_pi : has_fderiv_at (λ x i, φ i x) (continuous_linear_map.pi φ') x ↔ ∀ i, has_fderiv_at (φ i) (φ' i) x := has_fderiv_at_filter_pi @[simp] lemma has_fderiv_within_at_pi' : has_fderiv_within_at Φ Φ' s x ↔ ∀ i, has_fderiv_within_at (λ x, Φ x i) ((proj i).comp Φ') s x := has_fderiv_at_filter_pi' lemma has_fderiv_within_at_pi : has_fderiv_within_at (λ x i, φ i x) (continuous_linear_map.pi φ') s x ↔ ∀ i, has_fderiv_within_at (φ i) (φ' i) s x := has_fderiv_at_filter_pi @[simp] lemma differentiable_within_at_pi : differentiable_within_at 𝕜 Φ s x ↔ ∀ i, differentiable_within_at 𝕜 (λ x, Φ x i) s x := ⟨λ h i, (has_fderiv_within_at_pi'.1 h.has_fderiv_within_at i).differentiable_within_at, λ h, (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).differentiable_within_at⟩ @[simp] lemma differentiable_at_pi : differentiable_at 𝕜 Φ x ↔ ∀ i, differentiable_at 𝕜 (λ x, Φ x i) x := ⟨λ h i, (has_fderiv_at_pi'.1 h.has_fderiv_at i).differentiable_at, λ h, (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).differentiable_at⟩ lemma differentiable_on_pi : differentiable_on 𝕜 Φ s ↔ ∀ i, differentiable_on 𝕜 (λ x, Φ x i) s := ⟨λ h i x hx, differentiable_within_at_pi.1 (h x hx) i, λ h x hx, differentiable_within_at_pi.2 (λ i, h i x hx)⟩ lemma differentiable_pi : differentiable 𝕜 Φ ↔ ∀ i, differentiable 𝕜 (λ x, Φ x i) := ⟨λ h i x, differentiable_at_pi.1 (h x) i, λ h x, differentiable_at_pi.2 (λ i, h i x)⟩ -- TODO: find out which version (`φ` or `Φ`) works better with `rw`/`simp` lemma fderiv_within_pi (h : ∀ i, differentiable_within_at 𝕜 (φ i) s x) (hs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λ x i, φ i x) s x = pi (λ i, fderiv_within 𝕜 (φ i) s x) := (has_fderiv_within_at_pi.2 (λ i, (h i).has_fderiv_within_at)).fderiv_within hs lemma fderiv_pi (h : ∀ i, differentiable_at 𝕜 (φ i) x) : fderiv 𝕜 (λ x i, φ i x) x = pi (λ i, fderiv 𝕜 (φ i) x) := (has_fderiv_at_pi.2 (λ i, (h i).has_fderiv_at)).fderiv end pi section neg /-! ### Derivative of the negative of a function -/ theorem has_strict_fderiv_at.neg (h : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ x, -f x) (-f') x := (-1 : F →L[𝕜] F).has_strict_fderiv_at.comp x h theorem has_fderiv_at_filter.neg (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter (λ x, -f x) (-f') x L := (-1 : F →L[𝕜] F).has_fderiv_at_filter.comp x h tendsto_map theorem has_fderiv_within_at.neg (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ x, -f x) (-f') s x := h.neg theorem has_fderiv_at.neg (h : has_fderiv_at f f' x) : has_fderiv_at (λ x, -f x) (-f') x := h.neg lemma differentiable_within_at.neg (h : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λy, -f y) s x := h.has_fderiv_within_at.neg.differentiable_within_at @[simp] lemma differentiable_within_at_neg_iff : differentiable_within_at 𝕜 (λy, -f y) s x ↔ differentiable_within_at 𝕜 f s x := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable_at.neg (h : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λy, -f y) x := h.has_fderiv_at.neg.differentiable_at @[simp] lemma differentiable_at_neg_iff : differentiable_at 𝕜 (λy, -f y) x ↔ differentiable_at 𝕜 f x := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable_on.neg (h : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λy, -f y) s := λx hx, (h x hx).neg @[simp] lemma differentiable_on_neg_iff : differentiable_on 𝕜 (λy, -f y) s ↔ differentiable_on 𝕜 f s := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma differentiable.neg (h : differentiable 𝕜 f) : differentiable 𝕜 (λy, -f y) := λx, (h x).neg @[simp] lemma differentiable_neg_iff : differentiable 𝕜 (λy, -f y) ↔ differentiable 𝕜 f := ⟨λ h, by simpa only [neg_neg] using h.neg, λ h, h.neg⟩ lemma fderiv_within_neg (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (λy, -f y) s x = - fderiv_within 𝕜 f s x := if h : differentiable_within_at 𝕜 f s x then h.has_fderiv_within_at.neg.fderiv_within hxs else by { rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at, neg_zero], simpa } @[simp] lemma fderiv_neg : fderiv 𝕜 (λy, -f y) x = - fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_neg unique_diff_within_at_univ] end neg section sub /-! ### Derivative of the difference of two functions -/ theorem has_strict_fderiv_at.sub (hf : has_strict_fderiv_at f f' x) (hg : has_strict_fderiv_at g g' x) : has_strict_fderiv_at (λ x, f x - g x) (f' - g') x := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem has_fderiv_at_filter.sub (hf : has_fderiv_at_filter f f' x L) (hg : has_fderiv_at_filter g g' x L) : has_fderiv_at_filter (λ x, f x - g x) (f' - g') x L := by simpa only [sub_eq_add_neg] using hf.add hg.neg theorem has_fderiv_within_at.sub (hf : has_fderiv_within_at f f' s x) (hg : has_fderiv_within_at g g' s x) : has_fderiv_within_at (λ x, f x - g x) (f' - g') s x := hf.sub hg theorem has_fderiv_at.sub (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x) : has_fderiv_at (λ x, f x - g x) (f' - g') x := hf.sub hg lemma differentiable_within_at.sub (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : differentiable_within_at 𝕜 (λ y, f y - g y) s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : differentiable_at 𝕜 (λ y, f y - g y) x := (hf.has_fderiv_at.sub hg.has_fderiv_at).differentiable_at lemma differentiable_on.sub (hf : differentiable_on 𝕜 f s) (hg : differentiable_on 𝕜 g s) : differentiable_on 𝕜 (λy, f y - g y) s := λx hx, (hf x hx).sub (hg x hx) @[simp] lemma differentiable.sub (hf : differentiable 𝕜 f) (hg : differentiable 𝕜 g) : differentiable 𝕜 (λy, f y - g y) := λx, (hf x).sub (hg x) lemma fderiv_within_sub (hxs : unique_diff_within_at 𝕜 s x) (hf : differentiable_within_at 𝕜 f s x) (hg : differentiable_within_at 𝕜 g s x) : fderiv_within 𝕜 (λy, f y - g y) s x = fderiv_within 𝕜 f s x - fderiv_within 𝕜 g s x := (hf.has_fderiv_within_at.sub hg.has_fderiv_within_at).fderiv_within hxs lemma fderiv_sub (hf : differentiable_at 𝕜 f x) (hg : differentiable_at 𝕜 g x) : fderiv 𝕜 (λy, f y - g y) x = fderiv 𝕜 f x - fderiv 𝕜 g x := (hf.has_fderiv_at.sub hg.has_fderiv_at).fderiv theorem has_strict_fderiv_at.sub_const (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ x, f x - c) f' x := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem has_fderiv_at_filter.sub_const (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ x, f x - c) f' x L := by simpa only [sub_eq_add_neg] using hf.add_const (-c) theorem has_fderiv_within_at.sub_const (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ x, f x - c) f' s x := hf.sub_const c theorem has_fderiv_at.sub_const (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (λ x, f x - c) f' x := hf.sub_const c lemma differentiable_within_at.sub_const (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, f y - c) s x := (hf.has_fderiv_within_at.sub_const c).differentiable_within_at @[simp] lemma differentiable_within_at_sub_const_iff (c : F) : differentiable_within_at 𝕜 (λ y, f y - c) s x ↔ differentiable_within_at 𝕜 f s x := by simp only [sub_eq_add_neg, differentiable_within_at_add_const_iff] lemma differentiable_at.sub_const (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, f y - c) x := (hf.has_fderiv_at.sub_const c).differentiable_at @[simp] lemma differentiable_at_sub_const_iff (c : F) : differentiable_at 𝕜 (λ y, f y - c) x ↔ differentiable_at 𝕜 f x := by simp only [sub_eq_add_neg, differentiable_at_add_const_iff] lemma differentiable_on.sub_const (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, f y - c) s := λx hx, (hf x hx).sub_const c @[simp] lemma differentiable_on_sub_const_iff (c : F) : differentiable_on 𝕜 (λ y, f y - c) s ↔ differentiable_on 𝕜 f s := by simp only [sub_eq_add_neg, differentiable_on_add_const_iff] lemma differentiable.sub_const (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, f y - c) := λx, (hf x).sub_const c @[simp] lemma differentiable_sub_const_iff (c : F) : differentiable 𝕜 (λ y, f y - c) ↔ differentiable 𝕜 f := by simp only [sub_eq_add_neg, differentiable_add_const_iff] lemma fderiv_within_sub_const (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, f y - c) s x = fderiv_within 𝕜 f s x := by simp only [sub_eq_add_neg, fderiv_within_add_const hxs] lemma fderiv_sub_const (c : F) : fderiv 𝕜 (λy, f y - c) x = fderiv 𝕜 f x := by simp only [sub_eq_add_neg, fderiv_add_const] theorem has_strict_fderiv_at.const_sub (hf : has_strict_fderiv_at f f' x) (c : F) : has_strict_fderiv_at (λ x, c - f x) (-f') x := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_fderiv_at_filter.const_sub (hf : has_fderiv_at_filter f f' x L) (c : F) : has_fderiv_at_filter (λ x, c - f x) (-f') x L := by simpa only [sub_eq_add_neg] using hf.neg.const_add c theorem has_fderiv_within_at.const_sub (hf : has_fderiv_within_at f f' s x) (c : F) : has_fderiv_within_at (λ x, c - f x) (-f') s x := hf.const_sub c theorem has_fderiv_at.const_sub (hf : has_fderiv_at f f' x) (c : F) : has_fderiv_at (λ x, c - f x) (-f') x := hf.const_sub c lemma differentiable_within_at.const_sub (hf : differentiable_within_at 𝕜 f s x) (c : F) : differentiable_within_at 𝕜 (λ y, c - f y) s x := (hf.has_fderiv_within_at.const_sub c).differentiable_within_at @[simp] lemma differentiable_within_at_const_sub_iff (c : F) : differentiable_within_at 𝕜 (λ y, c - f y) s x ↔ differentiable_within_at 𝕜 f s x := by simp [sub_eq_add_neg] lemma differentiable_at.const_sub (hf : differentiable_at 𝕜 f x) (c : F) : differentiable_at 𝕜 (λ y, c - f y) x := (hf.has_fderiv_at.const_sub c).differentiable_at @[simp] lemma differentiable_at_const_sub_iff (c : F) : differentiable_at 𝕜 (λ y, c - f y) x ↔ differentiable_at 𝕜 f x := by simp [sub_eq_add_neg] lemma differentiable_on.const_sub (hf : differentiable_on 𝕜 f s) (c : F) : differentiable_on 𝕜 (λy, c - f y) s := λx hx, (hf x hx).const_sub c @[simp] lemma differentiable_on_const_sub_iff (c : F) : differentiable_on 𝕜 (λ y, c - f y) s ↔ differentiable_on 𝕜 f s := by simp [sub_eq_add_neg] lemma differentiable.const_sub (hf : differentiable 𝕜 f) (c : F) : differentiable 𝕜 (λy, c - f y) := λx, (hf x).const_sub c @[simp] lemma differentiable_const_sub_iff (c : F) : differentiable 𝕜 (λ y, c - f y) ↔ differentiable 𝕜 f := by simp [sub_eq_add_neg] lemma fderiv_within_const_sub (hxs : unique_diff_within_at 𝕜 s x) (c : F) : fderiv_within 𝕜 (λy, c - f y) s x = -fderiv_within 𝕜 f s x := by simp only [sub_eq_add_neg, fderiv_within_const_add, fderiv_within_neg, hxs] lemma fderiv_const_sub (c : F) : fderiv 𝕜 (λy, c - f y) x = -fderiv 𝕜 f x := by simp only [← fderiv_within_univ, fderiv_within_const_sub unique_diff_within_at_univ] end sub section bilinear_map /-! ### Derivative of a bounded bilinear map -/ variables {b : E × F → G} {u : set (E × F) } open normed_field lemma is_bounded_bilinear_map.has_strict_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_strict_fderiv_at b (h.deriv p) p := begin rw has_strict_fderiv_at, set T := (E × F) × (E × F), have : is_o (λ q : T, b (q.1 - q.2)) (λ q : T, ∥q.1 - q.2∥ * 1) (𝓝 (p, p)), { refine (h.is_O'.comp_tendsto le_top).trans_is_o _, simp only [(∘)], refine (is_O_refl (λ q : T, ∥q.1 - q.2∥) _).mul_is_o (is_o.norm_left $ (is_o_one_iff _).2 _), rw [← sub_self p], exact continuous_at_fst.sub continuous_at_snd }, simp only [mul_one, is_o_norm_right] at this, refine (is_o.congr_of_sub _).1 this, clear this, convert_to is_o (λ q : T, h.deriv (p - q.2) (q.1 - q.2)) (λ q : T, q.1 - q.2) (𝓝 (p, p)), { ext ⟨⟨x₁, y₁⟩, ⟨x₂, y₂⟩⟩, rcases p with ⟨x, y⟩, simp only [is_bounded_bilinear_map_deriv_coe, prod.mk_sub_mk, h.map_sub_left, h.map_sub_right], abel }, have : is_o (λ q : T, p - q.2) (λ q, (1:ℝ)) (𝓝 (p, p)), from (is_o_one_iff _).2 (sub_self p ▸ tendsto_const_nhds.sub continuous_at_snd), apply is_bounded_bilinear_map_apply.is_O_comp.trans_is_o, refine is_o.trans_is_O _ (is_O_const_mul_self 1 _ _).of_norm_right, refine is_o.mul_is_O _ (is_O_refl _ _), exact (((h.is_bounded_linear_map_deriv.is_O_id ⊤).comp_tendsto le_top : _).trans_is_o this).norm_left end lemma is_bounded_bilinear_map.has_fderiv_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_at b (h.deriv p) p := (h.has_strict_fderiv_at p).has_fderiv_at lemma is_bounded_bilinear_map.has_fderiv_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : has_fderiv_within_at b (h.deriv p) u p := (h.has_fderiv_at p).has_fderiv_within_at lemma is_bounded_bilinear_map.differentiable_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_at 𝕜 b p := (h.has_fderiv_at p).differentiable_at lemma is_bounded_bilinear_map.differentiable_within_at (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : differentiable_within_at 𝕜 b u p := (h.differentiable_at p).differentiable_within_at lemma is_bounded_bilinear_map.fderiv (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) : fderiv 𝕜 b p = h.deriv p := has_fderiv_at.fderiv (h.has_fderiv_at p) lemma is_bounded_bilinear_map.fderiv_within (h : is_bounded_bilinear_map 𝕜 b) (p : E × F) (hxs : unique_diff_within_at 𝕜 u p) : fderiv_within 𝕜 b u p = h.deriv p := begin rw differentiable_at.fderiv_within (h.differentiable_at p) hxs, exact h.fderiv p end lemma is_bounded_bilinear_map.differentiable (h : is_bounded_bilinear_map 𝕜 b) : differentiable 𝕜 b := λx, h.differentiable_at x lemma is_bounded_bilinear_map.differentiable_on (h : is_bounded_bilinear_map 𝕜 b) : differentiable_on 𝕜 b u := h.differentiable.differentiable_on end bilinear_map section clm_comp_apply /-! ### Derivative of the pointwise composition/application of continuous linear maps -/ variables {H : Type*} [normed_group H] [normed_space 𝕜 H] {c : E → G →L[𝕜] H} {c' : E →L[𝕜] G →L[𝕜] H} {d : E → F →L[𝕜] G} {d' : E →L[𝕜] F →L[𝕜] G} {u : E → G} {u' : E →L[𝕜] G} lemma has_strict_fderiv_at.clm_comp (hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := begin rw add_comm, exact (is_bounded_bilinear_map_comp.has_strict_fderiv_at (d x, c x)).comp x (hd.prod hc) end lemma has_fderiv_within_at.clm_comp (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') s x := begin rw add_comm, exact (is_bounded_bilinear_map_comp.has_fderiv_at (d x, c x)).comp_has_fderiv_within_at x (hd.prod hc) end lemma has_fderiv_at.clm_comp (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, (c y).comp (d y)) ((compL 𝕜 F G H (c x)).comp d' + ((compL 𝕜 F G H).flip (d x)).comp c') x := begin rw add_comm, exact (is_bounded_bilinear_map_comp.has_fderiv_at (d x, c x)).comp x (hd.prod hc) end lemma differentiable_within_at.clm_comp (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : differentiable_within_at 𝕜 (λ y, (c y).comp (d y)) s x := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : differentiable_at 𝕜 (λ y, (c y).comp (d y)) x := (hc.has_fderiv_at.clm_comp hd.has_fderiv_at).differentiable_at lemma differentiable_on.clm_comp (hc : differentiable_on 𝕜 c s) (hd : differentiable_on 𝕜 d s) : differentiable_on 𝕜 (λ y, (c y).comp (d y)) s := λx hx, (hc x hx).clm_comp (hd x hx) lemma differentiable.clm_comp (hc : differentiable 𝕜 c) (hd : differentiable 𝕜 d) : differentiable 𝕜 (λ y, (c y).comp (d y)) := λx, (hc x).clm_comp (hd x) lemma fderiv_within_clm_comp (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : fderiv_within 𝕜 (λ y, (c y).comp (d y)) s x = (compL 𝕜 F G H (c x)).comp (fderiv_within 𝕜 d s x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv_within 𝕜 c s x) := (hc.has_fderiv_within_at.clm_comp hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_clm_comp (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : fderiv 𝕜 (λ y, (c y).comp (d y)) x = (compL 𝕜 F G H (c x)).comp (fderiv 𝕜 d x) + ((compL 𝕜 F G H).flip (d x)).comp (fderiv 𝕜 c x) := (hc.has_fderiv_at.clm_comp hd.has_fderiv_at).fderiv lemma has_strict_fderiv_at.clm_apply (hc : has_strict_fderiv_at c c' x) (hu : has_strict_fderiv_at u u' x) : has_strict_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (is_bounded_bilinear_map_apply.has_strict_fderiv_at (c x, u x)).comp x (hc.prod hu) lemma has_fderiv_within_at.clm_apply (hc : has_fderiv_within_at c c' s x) (hu : has_fderiv_within_at u u' s x) : has_fderiv_within_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) s x := (is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp_has_fderiv_within_at x (hc.prod hu) lemma has_fderiv_at.clm_apply (hc : has_fderiv_at c c' x) (hu : has_fderiv_at u u' x) : has_fderiv_at (λ y, (c y) (u y)) ((c x).comp u' + c'.flip (u x)) x := (is_bounded_bilinear_map_apply.has_fderiv_at (c x, u x)).comp x (hc.prod hu) lemma differentiable_within_at.clm_apply (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) : differentiable_within_at 𝕜 (λ y, (c y) (u y)) s x := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).differentiable_within_at lemma differentiable_at.clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) : differentiable_at 𝕜 (λ y, (c y) (u y)) x := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).differentiable_at lemma differentiable_on.clm_apply (hc : differentiable_on 𝕜 c s) (hu : differentiable_on 𝕜 u s) : differentiable_on 𝕜 (λ y, (c y) (u y)) s := λx hx, (hc x hx).clm_apply (hu x hx) lemma differentiable.clm_apply (hc : differentiable 𝕜 c) (hu : differentiable 𝕜 u) : differentiable 𝕜 (λ y, (c y) (u y)) := λx, (hc x).clm_apply (hu x) lemma fderiv_within_clm_apply (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hu : differentiable_within_at 𝕜 u s x) : fderiv_within 𝕜 (λ y, (c y) (u y)) s x = ((c x).comp (fderiv_within 𝕜 u s x) + (fderiv_within 𝕜 c s x).flip (u x)) := (hc.has_fderiv_within_at.clm_apply hu.has_fderiv_within_at).fderiv_within hxs lemma fderiv_clm_apply (hc : differentiable_at 𝕜 c x) (hu : differentiable_at 𝕜 u x) : fderiv 𝕜 (λ y, (c y) (u y)) x = ((c x).comp (fderiv 𝕜 u x) + (fderiv 𝕜 c x).flip (u x)) := (hc.has_fderiv_at.clm_apply hu.has_fderiv_at).fderiv end clm_comp_apply section smul /-! ### Derivative of the product of a scalar-valued function and a vector-valued function If `c` is a differentiable scalar-valued function and `f` is a differentiable vector-valued function, then `λ x, c x • f x` is differentiable as well. Lemmas in this section works for function `c` taking values in the base field, as well as in a normed algebra over the base field: e.g., they work for `c : E → ℂ` and `f : E → F` provided that `F` is a complex normed vector space. -/ variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] [normed_space 𝕜' F] [is_scalar_tower 𝕜 𝕜' F] variables {c : E → 𝕜'} {c' : E →L[𝕜] 𝕜'} theorem has_strict_fderiv_at.smul (hc : has_strict_fderiv_at c c' x) (hf : has_strict_fderiv_at f f' x) : has_strict_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x := (is_bounded_bilinear_map_smul.has_strict_fderiv_at (c x, f x)).comp x $ hc.prod hf theorem has_fderiv_within_at.smul (hc : has_fderiv_within_at c c' s x) (hf : has_fderiv_within_at f f' s x) : has_fderiv_within_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) s x := (is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp_has_fderiv_within_at x $ hc.prod hf theorem has_fderiv_at.smul (hc : has_fderiv_at c c' x) (hf : has_fderiv_at f f' x) : has_fderiv_at (λ y, c y • f y) (c x • f' + c'.smul_right (f x)) x := (is_bounded_bilinear_map_smul.has_fderiv_at (c x, f x)).comp x $ hc.prod hf lemma differentiable_within_at.smul (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : differentiable_within_at 𝕜 (λ y, c y • f y) s x := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜 (λ y, c y • f y) x := (hc.has_fderiv_at.smul hf.has_fderiv_at).differentiable_at lemma differentiable_on.smul (hc : differentiable_on 𝕜 c s) (hf : differentiable_on 𝕜 f s) : differentiable_on 𝕜 (λ y, c y • f y) s := λx hx, (hc x hx).smul (hf x hx) @[simp] lemma differentiable.smul (hc : differentiable 𝕜 c) (hf : differentiable 𝕜 f) : differentiable 𝕜 (λ y, c y • f y) := λx, (hc x).smul (hf x) lemma fderiv_within_smul (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hf : differentiable_within_at 𝕜 f s x) : fderiv_within 𝕜 (λ y, c y • f y) s x = c x • fderiv_within 𝕜 f s x + (fderiv_within 𝕜 c s x).smul_right (f x) := (hc.has_fderiv_within_at.smul hf.has_fderiv_within_at).fderiv_within hxs lemma fderiv_smul (hc : differentiable_at 𝕜 c x) (hf : differentiable_at 𝕜 f x) : fderiv 𝕜 (λ y, c y • f y) x = c x • fderiv 𝕜 f x + (fderiv 𝕜 c x).smul_right (f x) := (hc.has_fderiv_at.smul hf.has_fderiv_at).fderiv theorem has_strict_fderiv_at.smul_const (hc : has_strict_fderiv_at c c' x) (f : F) : has_strict_fderiv_at (λ y, c y • f) (c'.smul_right f) x := by simpa only [smul_zero, zero_add] using hc.smul (has_strict_fderiv_at_const f x) theorem has_fderiv_within_at.smul_const (hc : has_fderiv_within_at c c' s x) (f : F) : has_fderiv_within_at (λ y, c y • f) (c'.smul_right f) s x := by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_within_at_const f x s) theorem has_fderiv_at.smul_const (hc : has_fderiv_at c c' x) (f : F) : has_fderiv_at (λ y, c y • f) (c'.smul_right f) x := by simpa only [smul_zero, zero_add] using hc.smul (has_fderiv_at_const f x) lemma differentiable_within_at.smul_const (hc : differentiable_within_at 𝕜 c s x) (f : F) : differentiable_within_at 𝕜 (λ y, c y • f) s x := (hc.has_fderiv_within_at.smul_const f).differentiable_within_at lemma differentiable_at.smul_const (hc : differentiable_at 𝕜 c x) (f : F) : differentiable_at 𝕜 (λ y, c y • f) x := (hc.has_fderiv_at.smul_const f).differentiable_at lemma differentiable_on.smul_const (hc : differentiable_on 𝕜 c s) (f : F) : differentiable_on 𝕜 (λ y, c y • f) s := λx hx, (hc x hx).smul_const f lemma differentiable.smul_const (hc : differentiable 𝕜 c) (f : F) : differentiable 𝕜 (λ y, c y • f) := λx, (hc x).smul_const f lemma fderiv_within_smul_const (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (f : F) : fderiv_within 𝕜 (λ y, c y • f) s x = (fderiv_within 𝕜 c s x).smul_right f := (hc.has_fderiv_within_at.smul_const f).fderiv_within hxs lemma fderiv_smul_const (hc : differentiable_at 𝕜 c x) (f : F) : fderiv 𝕜 (λ y, c y • f) x = (fderiv 𝕜 c x).smul_right f := (hc.has_fderiv_at.smul_const f).fderiv end smul section mul /-! ### Derivative of the product of two functions -/ variables {𝔸 𝔸' : Type*} [normed_ring 𝔸] [normed_comm_ring 𝔸'] [normed_algebra 𝕜 𝔸] [normed_algebra 𝕜 𝔸'] {a b : E → 𝔸} {a' b' : E →L[𝕜] 𝔸} {c d : E → 𝔸'} {c' d' : E →L[𝕜] 𝔸'} theorem has_strict_fderiv_at.mul' {x : E} (ha : has_strict_fderiv_at a a' x) (hb : has_strict_fderiv_at b b' x) : has_strict_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_strict_fderiv_at (a x, b x)).comp x (ha.prod hb) theorem has_strict_fderiv_at.mul (hc : has_strict_fderiv_at c c' x) (hd : has_strict_fderiv_at d d' x) : has_strict_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x := by { convert hc.mul' hd, ext z, apply mul_comm } theorem has_fderiv_within_at.mul' (ha : has_fderiv_within_at a a' s x) (hb : has_fderiv_within_at b b' s x) : has_fderiv_within_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) s x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp_has_fderiv_within_at x (ha.prod hb) theorem has_fderiv_within_at.mul (hc : has_fderiv_within_at c c' s x) (hd : has_fderiv_within_at d d' s x) : has_fderiv_within_at (λ y, c y * d y) (c x • d' + d x • c') s x := by { convert hc.mul' hd, ext z, apply mul_comm } theorem has_fderiv_at.mul' (ha : has_fderiv_at a a' x) (hb : has_fderiv_at b b' x) : has_fderiv_at (λ y, a y * b y) (a x • b' + a'.smul_right (b x)) x := ((continuous_linear_map.lmul 𝕜 𝔸).is_bounded_bilinear_map.has_fderiv_at (a x, b x)).comp x (ha.prod hb) theorem has_fderiv_at.mul (hc : has_fderiv_at c c' x) (hd : has_fderiv_at d d' x) : has_fderiv_at (λ y, c y * d y) (c x • d' + d x • c') x := by { convert hc.mul' hd, ext z, apply mul_comm } lemma differentiable_within_at.mul (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) : differentiable_within_at 𝕜 (λ y, a y * b y) s x := (ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).differentiable_within_at @[simp] lemma differentiable_at.mul (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) : differentiable_at 𝕜 (λ y, a y * b y) x := (ha.has_fderiv_at.mul' hb.has_fderiv_at).differentiable_at lemma differentiable_on.mul (ha : differentiable_on 𝕜 a s) (hb : differentiable_on 𝕜 b s) : differentiable_on 𝕜 (λ y, a y * b y) s := λx hx, (ha x hx).mul (hb x hx) @[simp] lemma differentiable.mul (ha : differentiable 𝕜 a) (hb : differentiable 𝕜 b) : differentiable 𝕜 (λ y, a y * b y) := λx, (ha x).mul (hb x) lemma fderiv_within_mul' (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (hb : differentiable_within_at 𝕜 b s x) : fderiv_within 𝕜 (λ y, a y * b y) s x = a x • fderiv_within 𝕜 b s x + (fderiv_within 𝕜 a s x).smul_right (b x) := (ha.has_fderiv_within_at.mul' hb.has_fderiv_within_at).fderiv_within hxs lemma fderiv_within_mul (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (hd : differentiable_within_at 𝕜 d s x) : fderiv_within 𝕜 (λ y, c y * d y) s x = c x • fderiv_within 𝕜 d s x + d x • fderiv_within 𝕜 c s x := (hc.has_fderiv_within_at.mul hd.has_fderiv_within_at).fderiv_within hxs lemma fderiv_mul' (ha : differentiable_at 𝕜 a x) (hb : differentiable_at 𝕜 b x) : fderiv 𝕜 (λ y, a y * b y) x = a x • fderiv 𝕜 b x + (fderiv 𝕜 a x).smul_right (b x) := (ha.has_fderiv_at.mul' hb.has_fderiv_at).fderiv lemma fderiv_mul (hc : differentiable_at 𝕜 c x) (hd : differentiable_at 𝕜 d x) : fderiv 𝕜 (λ y, c y * d y) x = c x • fderiv 𝕜 d x + d x • fderiv 𝕜 c x := (hc.has_fderiv_at.mul hd.has_fderiv_at).fderiv theorem has_strict_fderiv_at.mul_const' (ha : has_strict_fderiv_at a a' x) (b : 𝔸) : has_strict_fderiv_at (λ y, a y * b) (a'.smul_right b) x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_strict_fderiv_at).comp x ha theorem has_strict_fderiv_at.mul_const (hc : has_strict_fderiv_at c c' x) (d : 𝔸') : has_strict_fderiv_at (λ y, c y * d) (d • c') x := by { convert hc.mul_const' d, ext z, apply mul_comm } theorem has_fderiv_within_at.mul_const' (ha : has_fderiv_within_at a a' s x) (b : 𝔸) : has_fderiv_within_at (λ y, a y * b) (a'.smul_right b) s x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp_has_fderiv_within_at x ha theorem has_fderiv_within_at.mul_const (hc : has_fderiv_within_at c c' s x) (d : 𝔸') : has_fderiv_within_at (λ y, c y * d) (d • c') s x := by { convert hc.mul_const' d, ext z, apply mul_comm } theorem has_fderiv_at.mul_const' (ha : has_fderiv_at a a' x) (b : 𝔸) : has_fderiv_at (λ y, a y * b) (a'.smul_right b) x := (((continuous_linear_map.lmul 𝕜 𝔸).flip b).has_fderiv_at).comp x ha theorem has_fderiv_at.mul_const (hc : has_fderiv_at c c' x) (d : 𝔸') : has_fderiv_at (λ y, c y * d) (d • c') x := by { convert hc.mul_const' d, ext z, apply mul_comm } lemma differentiable_within_at.mul_const (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : differentiable_within_at 𝕜 (λ y, a y * b) s x := (ha.has_fderiv_within_at.mul_const' b).differentiable_within_at lemma differentiable_at.mul_const (ha : differentiable_at 𝕜 a x) (b : 𝔸) : differentiable_at 𝕜 (λ y, a y * b) x := (ha.has_fderiv_at.mul_const' b).differentiable_at lemma differentiable_on.mul_const (ha : differentiable_on 𝕜 a s) (b : 𝔸) : differentiable_on 𝕜 (λ y, a y * b) s := λx hx, (ha x hx).mul_const b lemma differentiable.mul_const (ha : differentiable 𝕜 a) (b : 𝔸) : differentiable 𝕜 (λ y, a y * b) := λx, (ha x).mul_const b lemma fderiv_within_mul_const' (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : fderiv_within 𝕜 (λ y, a y * b) s x = (fderiv_within 𝕜 a s x).smul_right b := (ha.has_fderiv_within_at.mul_const' b).fderiv_within hxs lemma fderiv_within_mul_const (hxs : unique_diff_within_at 𝕜 s x) (hc : differentiable_within_at 𝕜 c s x) (d : 𝔸') : fderiv_within 𝕜 (λ y, c y * d) s x = d • fderiv_within 𝕜 c s x := (hc.has_fderiv_within_at.mul_const d).fderiv_within hxs lemma fderiv_mul_const' (ha : differentiable_at 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (λ y, a y * b) x = (fderiv 𝕜 a x).smul_right b := (ha.has_fderiv_at.mul_const' b).fderiv lemma fderiv_mul_const (hc : differentiable_at 𝕜 c x) (d : 𝔸') : fderiv 𝕜 (λ y, c y * d) x = d • fderiv 𝕜 c x := (hc.has_fderiv_at.mul_const d).fderiv theorem has_strict_fderiv_at.const_mul (ha : has_strict_fderiv_at a a' x) (b : 𝔸) : has_strict_fderiv_at (λ y, b * a y) (b • a') x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_strict_fderiv_at).comp x ha theorem has_fderiv_within_at.const_mul (ha : has_fderiv_within_at a a' s x) (b : 𝔸) : has_fderiv_within_at (λ y, b * a y) (b • a') s x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp_has_fderiv_within_at x ha theorem has_fderiv_at.const_mul (ha : has_fderiv_at a a' x) (b : 𝔸) : has_fderiv_at (λ y, b * a y) (b • a') x := (((continuous_linear_map.lmul 𝕜 𝔸) b).has_fderiv_at).comp x ha lemma differentiable_within_at.const_mul (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : differentiable_within_at 𝕜 (λ y, b * a y) s x := (ha.has_fderiv_within_at.const_mul b).differentiable_within_at lemma differentiable_at.const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) : differentiable_at 𝕜 (λ y, b * a y) x := (ha.has_fderiv_at.const_mul b).differentiable_at lemma differentiable_on.const_mul (ha : differentiable_on 𝕜 a s) (b : 𝔸) : differentiable_on 𝕜 (λ y, b * a y) s := λx hx, (ha x hx).const_mul b lemma differentiable.const_mul (ha : differentiable 𝕜 a) (b : 𝔸) : differentiable 𝕜 (λ y, b * a y) := λx, (ha x).const_mul b lemma fderiv_within_const_mul (hxs : unique_diff_within_at 𝕜 s x) (ha : differentiable_within_at 𝕜 a s x) (b : 𝔸) : fderiv_within 𝕜 (λ y, b * a y) s x = b • fderiv_within 𝕜 a s x := (ha.has_fderiv_within_at.const_mul b).fderiv_within hxs lemma fderiv_const_mul (ha : differentiable_at 𝕜 a x) (b : 𝔸) : fderiv 𝕜 (λ y, b * a y) x = b • fderiv 𝕜 a x := (ha.has_fderiv_at.const_mul b).fderiv end mul section algebra_inverse variables {R : Type*} [normed_ring R] [normed_algebra 𝕜 R] [complete_space R] open normed_ring continuous_linear_map ring /-- At an invertible element `x` of a normed algebra `R`, the Fréchet derivative of the inversion operation is the linear map `λ t, - x⁻¹ * t * x⁻¹`. -/ lemma has_fderiv_at_ring_inverse (x : Rˣ) : has_fderiv_at ring.inverse (-lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹) x := begin have h_is_o : is_o (λ (t : R), inverse (↑x + t) - ↑x⁻¹ + ↑x⁻¹ * t * ↑x⁻¹) (λ (t : R), t) (𝓝 0), { refine (inverse_add_norm_diff_second_order x).trans_is_o ((is_o_norm_norm).mp _), simp only [norm_pow, norm_norm], have h12 : 1 < 2 := by norm_num, convert (asymptotics.is_o_pow_pow h12).comp_tendsto tendsto_norm_zero, ext, simp }, have h_lim : tendsto (λ (y:R), y - x) (𝓝 x) (𝓝 0), { refine tendsto_zero_iff_norm_tendsto_zero.mpr _, exact tendsto_iff_norm_tendsto_zero.mp tendsto_id }, simp only [has_fderiv_at, has_fderiv_at_filter], convert h_is_o.comp_tendsto h_lim, ext y, simp only [coe_comp', function.comp_app, lmul_left_right_apply, neg_apply, inverse_unit x, units.inv_mul, add_sub_cancel'_right, mul_sub, sub_mul, one_mul, sub_neg_eq_add] end lemma differentiable_at_inverse (x : Rˣ) : differentiable_at 𝕜 (@ring.inverse R _) x := (has_fderiv_at_ring_inverse x).differentiable_at lemma fderiv_inverse (x : Rˣ) : fderiv 𝕜 (@ring.inverse R _) x = - lmul_left_right 𝕜 R ↑x⁻¹ ↑x⁻¹ := (has_fderiv_at_ring_inverse x).fderiv end algebra_inverse namespace continuous_linear_equiv /-! ### Differentiability of linear equivs, and invariance of differentiability -/ variable (iso : E ≃L[𝕜] F) protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x := iso.to_continuous_linear_map.has_strict_fderiv_at protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x := iso.to_continuous_linear_map.has_fderiv_within_at protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x := iso.to_continuous_linear_map.has_fderiv_at_filter protected lemma differentiable_at : differentiable_at 𝕜 iso x := iso.has_fderiv_at.differentiable_at protected lemma differentiable_within_at : differentiable_within_at 𝕜 iso s x := iso.differentiable_at.differentiable_within_at protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 iso s x = iso := iso.to_continuous_linear_map.fderiv_within hxs protected lemma differentiable : differentiable 𝕜 iso := λx, iso.differentiable_at protected lemma differentiable_on : differentiable_on 𝕜 iso s := iso.differentiable.differentiable_on lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} : differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x := begin refine ⟨λ H, _, λ H, iso.differentiable.differentiable_at.comp_differentiable_within_at x H⟩, have : differentiable_within_at 𝕜 (iso.symm ∘ (iso ∘ f)) s x := iso.symm.differentiable.differentiable_at.comp_differentiable_within_at x H, rwa [← function.comp.assoc iso.symm iso f, iso.symm_comp_self] at this, end lemma comp_differentiable_at_iff {f : G → E} {x : G} : differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x := by rw [← differentiable_within_at_univ, ← differentiable_within_at_univ, iso.comp_differentiable_within_at_iff] lemma comp_differentiable_on_iff {f : G → E} {s : set G} : differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s := begin rw [differentiable_on, differentiable_on], simp only [iso.comp_differentiable_within_at_iff], end lemma comp_differentiable_iff {f : G → E} : differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f := begin rw [← differentiable_on_univ, ← differentiable_on_univ], exact iso.comp_differentiable_on_iff end lemma comp_has_fderiv_within_at_iff {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} : has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x := begin refine ⟨λ H, _, λ H, iso.has_fderiv_at.comp_has_fderiv_within_at x H⟩, have A : f = iso.symm ∘ (iso ∘ f), by { rw [← function.comp.assoc, iso.symm_comp_self], refl }, have B : f' = (iso.symm : F →L[𝕜] E).comp ((iso : E →L[𝕜] F).comp f'), by rw [← continuous_linear_map.comp_assoc, iso.coe_symm_comp_coe, continuous_linear_map.id_comp], rw [A, B], exact iso.symm.has_fderiv_at.comp_has_fderiv_within_at x H end lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x := begin refine ⟨λ H, _, λ H, iso.has_strict_fderiv_at.comp x H⟩, convert iso.symm.has_strict_fderiv_at.comp x H; ext z; apply (iso.symm_apply_apply _).symm end lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x := by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff] lemma comp_has_fderiv_within_at_iff' {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} : has_fderiv_within_at (iso ∘ f) f' s x ↔ has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x := by rw [← iso.comp_has_fderiv_within_at_iff, ← continuous_linear_map.comp_assoc, iso.coe_comp_coe_symm, continuous_linear_map.id_comp] lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x := by rw [← has_fderiv_within_at_univ, ← has_fderiv_within_at_univ, iso.comp_has_fderiv_within_at_iff'] lemma comp_fderiv_within {f : G → E} {s : set G} {x : G} (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) := begin by_cases h : differentiable_within_at 𝕜 f s x, { rw [fderiv.comp_fderiv_within x iso.differentiable_at h hxs, iso.fderiv] }, { have : ¬differentiable_within_at 𝕜 (iso ∘ f) s x, from mt iso.comp_differentiable_within_at_iff.1 h, rw [fderiv_within_zero_of_not_differentiable_within_at h, fderiv_within_zero_of_not_differentiable_within_at this, continuous_linear_map.comp_zero] } end lemma comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := begin rw [← fderiv_within_univ, ← fderiv_within_univ], exact iso.comp_fderiv_within unique_diff_within_at_univ, end end continuous_linear_equiv namespace linear_isometry_equiv /-! ### Differentiability of linear isometry equivs, and invariance of differentiability -/ variable (iso : E ≃ₗᵢ[𝕜] F) protected lemma has_strict_fderiv_at : has_strict_fderiv_at iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).has_strict_fderiv_at protected lemma has_fderiv_within_at : has_fderiv_within_at iso (iso : E →L[𝕜] F) s x := (iso : E ≃L[𝕜] F).has_fderiv_within_at protected lemma has_fderiv_at : has_fderiv_at iso (iso : E →L[𝕜] F) x := (iso : E ≃L[𝕜] F).has_fderiv_at protected lemma differentiable_at : differentiable_at 𝕜 iso x := iso.has_fderiv_at.differentiable_at protected lemma differentiable_within_at : differentiable_within_at 𝕜 iso s x := iso.differentiable_at.differentiable_within_at protected lemma fderiv : fderiv 𝕜 iso x = iso := iso.has_fderiv_at.fderiv protected lemma fderiv_within (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 iso s x = iso := (iso : E ≃L[𝕜] F).fderiv_within hxs protected lemma differentiable : differentiable 𝕜 iso := λx, iso.differentiable_at protected lemma differentiable_on : differentiable_on 𝕜 iso s := iso.differentiable.differentiable_on lemma comp_differentiable_within_at_iff {f : G → E} {s : set G} {x : G} : differentiable_within_at 𝕜 (iso ∘ f) s x ↔ differentiable_within_at 𝕜 f s x := (iso : E ≃L[𝕜] F).comp_differentiable_within_at_iff lemma comp_differentiable_at_iff {f : G → E} {x : G} : differentiable_at 𝕜 (iso ∘ f) x ↔ differentiable_at 𝕜 f x := (iso : E ≃L[𝕜] F).comp_differentiable_at_iff lemma comp_differentiable_on_iff {f : G → E} {s : set G} : differentiable_on 𝕜 (iso ∘ f) s ↔ differentiable_on 𝕜 f s := (iso : E ≃L[𝕜] F).comp_differentiable_on_iff lemma comp_differentiable_iff {f : G → E} : differentiable 𝕜 (iso ∘ f) ↔ differentiable 𝕜 f := (iso : E ≃L[𝕜] F).comp_differentiable_iff lemma comp_has_fderiv_within_at_iff {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] E} : has_fderiv_within_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') s x ↔ has_fderiv_within_at f f' s x := (iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff lemma comp_has_strict_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_strict_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_strict_fderiv_at f f' x := (iso : E ≃L[𝕜] F).comp_has_strict_fderiv_at_iff lemma comp_has_fderiv_at_iff {f : G → E} {x : G} {f' : G →L[𝕜] E} : has_fderiv_at (iso ∘ f) ((iso : E →L[𝕜] F).comp f') x ↔ has_fderiv_at f f' x := (iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff lemma comp_has_fderiv_within_at_iff' {f : G → E} {s : set G} {x : G} {f' : G →L[𝕜] F} : has_fderiv_within_at (iso ∘ f) f' s x ↔ has_fderiv_within_at f ((iso.symm : F →L[𝕜] E).comp f') s x := (iso : E ≃L[𝕜] F).comp_has_fderiv_within_at_iff' lemma comp_has_fderiv_at_iff' {f : G → E} {x : G} {f' : G →L[𝕜] F} : has_fderiv_at (iso ∘ f) f' x ↔ has_fderiv_at f ((iso.symm : F →L[𝕜] E).comp f') x := (iso : E ≃L[𝕜] F).comp_has_fderiv_at_iff' lemma comp_fderiv_within {f : G → E} {s : set G} {x : G} (hxs : unique_diff_within_at 𝕜 s x) : fderiv_within 𝕜 (iso ∘ f) s x = (iso : E →L[𝕜] F).comp (fderiv_within 𝕜 f s x) := (iso : E ≃L[𝕜] F).comp_fderiv_within hxs lemma comp_fderiv {f : G → E} {x : G} : fderiv 𝕜 (iso ∘ f) x = (iso : E →L[𝕜] F).comp (fderiv 𝕜 f x) := (iso : E ≃L[𝕜] F).comp_fderiv end linear_isometry_equiv /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a` in the strict sense, then `g` has the derivative `f'⁻¹` at `a` in the strict sense. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_strict_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : continuous_at g a) (hf : has_strict_fderiv_at f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : has_strict_fderiv_at g (f'.symm : F →L[𝕜] E) a := begin replace hg := hg.prod_map' hg, replace hfg := hfg.prod_mk_nhds hfg, have : is_O (λ p : F × F, g p.1 - g p.2 - f'.symm (p.1 - p.2)) (λ p : F × F, f' (g p.1 - g p.2) - (p.1 - p.2)) (𝓝 (a, a)), { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl), simp }, refine this.trans_is_o _, clear this, refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _) (eventually_of_forall $ λ _, rfl)).trans_is_O _, { rintros p ⟨hp1, hp2⟩, simp [hp1, hp2] }, { refine (hf.is_O_sub_rev.comp_tendsto hg).congr' (eventually_of_forall $ λ _, rfl) (hfg.mono _), rintros p ⟨hp1, hp2⟩, simp only [(∘), hp1, hp2] } end /-- If `f (g y) = y` for `y` in some neighborhood of `a`, `g` is continuous at `a`, and `f` has an invertible derivative `f'` at `g a`, then `g` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ theorem has_fderiv_at.of_local_left_inverse {f : E → F} {f' : E ≃L[𝕜] F} {g : F → E} {a : F} (hg : continuous_at g a) (hf : has_fderiv_at f (f' : E →L[𝕜] F) (g a)) (hfg : ∀ᶠ y in 𝓝 a, f (g y) = y) : has_fderiv_at g (f'.symm : F →L[𝕜] E) a := begin have : is_O (λ x : F, g x - g a - f'.symm (x - a)) (λ x : F, f' (g x - g a) - (x - a)) (𝓝 a), { refine ((f'.symm : F →L[𝕜] E).is_O_comp _ _).congr (λ x, _) (λ _, rfl), simp }, refine this.trans_is_o _, clear this, refine ((hf.comp_tendsto hg).symm.congr' (hfg.mono _) (eventually_of_forall $ λ _, rfl)).trans_is_O _, { rintros p hp, simp [hp, hfg.self_of_nhds] }, { refine ((hf.is_O_sub_rev f'.antilipschitz).comp_tendsto hg).congr' (eventually_of_forall $ λ _, rfl) (hfg.mono _), rintros p hp, simp only [(∘), hp, hfg.self_of_nhds] } end /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible derivative `f'` in the sense of strict differentiability at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_strict_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : has_strict_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) : has_strict_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha) /-- If `f` is a local homeomorphism defined on a neighbourhood of `f.symm a`, and `f` has an invertible derivative `f'` at `f.symm a`, then `f.symm` has the derivative `f'⁻¹` at `a`. This is one of the easy parts of the inverse function theorem: it assumes that we already have an inverse function. -/ lemma local_homeomorph.has_fderiv_at_symm (f : local_homeomorph E F) {f' : E ≃L[𝕜] F} {a : F} (ha : a ∈ f.target) (htff' : has_fderiv_at f (f' : E →L[𝕜] F) (f.symm a)) : has_fderiv_at f.symm (f'.symm : F →L[𝕜] E) a := htff'.of_local_left_inverse (f.symm.continuous_at ha) (f.eventually_right_inverse ha) lemma has_fderiv_within_at.eventually_ne (h : has_fderiv_within_at f f' s x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) : ∀ᶠ z in 𝓝[s \ {x}] x, f z ≠ f x := begin rw [nhds_within, diff_eq, ← inf_principal, ← inf_assoc, eventually_inf_principal], have A : is_O (λ z, z - x) (λ z, f' (z - x)) (𝓝[s] x) := (is_O_iff.2 $ hf'.imp $ λ C hC, eventually_of_forall $ λ z, hC _), have : (λ z, f z - f x) ~[𝓝[s] x] (λ z, f' (z - x)) := h.trans_is_O A, simpa [not_imp_not, sub_eq_zero] using (A.trans this.is_O_symm).eq_zero_imp end lemma has_fderiv_at.eventually_ne (h : has_fderiv_at f f' x) (hf' : ∃ C, ∀ z, ∥z∥ ≤ C * ∥f' z∥) : ∀ᶠ z in 𝓝[≠] x, f z ≠ f x := by simpa only [compl_eq_univ_diff] using (has_fderiv_within_at_univ.2 h).eventually_ne hf' end section /- In the special case of a normed space over the reals, we can use scalar multiplication in the `tendsto` characterization of the Fréchet derivative. -/ variables {E : Type*} [normed_group E] [normed_space ℝ E] variables {F : Type*} [normed_group F] [normed_space ℝ F] variables {f : E → F} {f' : E →L[ℝ] F} {x : E} theorem has_fderiv_at_filter_real_equiv {L : filter E} : tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (𝓝 0) ↔ tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (𝓝 0) := begin symmetry, rw [tendsto_iff_norm_tendsto_zero], refine tendsto_congr (λ x', _), have : ∥x' - x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _), simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this] end lemma has_fderiv_at.lim_real (hf : has_fderiv_at f f' x) (v : E) : tendsto (λ (c:ℝ), c • (f (x + c⁻¹ • v) - f x)) at_top (𝓝 (f' v)) := begin apply hf.lim v, rw tendsto_at_top_at_top, exact λ b, ⟨b, λ a ha, le_trans ha (le_abs_self _)⟩ end end section tangent_cone variables {𝕜 : Type*} [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.maps_to_tangent_cone {x : E} (h : has_fderiv_within_at f f' s x) : maps_to f' (tangent_cone_at 𝕜 s x) (tangent_cone_at 𝕜 (f '' s) (f x)) := begin rintros v ⟨c, d, dtop, clim, cdlim⟩, refine ⟨c, (λn, f (x + d n) - f x), mem_of_superset dtop _, clim, h.lim at_top dtop clim cdlim⟩, simp [-mem_image, mem_image_of_mem] {contextual := tt} end /-- If a set has the unique differentiability property at a point x, then the image of this set under a map with onto derivative has also the unique differentiability property at the image point. -/ lemma has_fderiv_within_at.unique_diff_within_at {x : E} (h : has_fderiv_within_at f f' s x) (hs : unique_diff_within_at 𝕜 s x) (h' : dense_range f') : unique_diff_within_at 𝕜 (f '' s) (f x) := begin refine ⟨h'.dense_of_maps_to f'.continuous hs.1 _, h.continuous_within_at.mem_closure_image hs.2⟩, show submodule.span 𝕜 (tangent_cone_at 𝕜 s x) ≤ (submodule.span 𝕜 (tangent_cone_at 𝕜 (f '' s) (f x))).comap ↑f', rw [submodule.span_le], exact h.maps_to_tangent_cone.mono (subset.refl _) submodule.subset_span end lemma unique_diff_on.image {f' : E → E →L[𝕜] F} (hs : unique_diff_on 𝕜 s) (hf' : ∀ x ∈ s, has_fderiv_within_at f (f' x) s x) (hd : ∀ x ∈ s, dense_range (f' x)) : unique_diff_on 𝕜 (f '' s) := ball_image_iff.2 $ λ x hx, (hf' x hx).unique_diff_within_at (hs x hx) (hd x hx) lemma has_fderiv_within_at.unique_diff_within_at_of_continuous_linear_equiv {x : E} (e' : E ≃L[𝕜] F) (h : has_fderiv_within_at f (e' : E →L[𝕜] F) s x) (hs : unique_diff_within_at 𝕜 s x) : unique_diff_within_at 𝕜 (f '' s) (f x) := h.unique_diff_within_at hs e'.surjective.dense_range lemma continuous_linear_equiv.unique_diff_on_image (e : E ≃L[𝕜] F) (h : unique_diff_on 𝕜 s) : unique_diff_on 𝕜 (e '' s) := h.image (λ x _, e.has_fderiv_within_at) (λ x hx, e.surjective.dense_range) @[simp] lemma continuous_linear_equiv.unique_diff_on_image_iff (e : E ≃L[𝕜] F) : unique_diff_on 𝕜 (e '' s) ↔ unique_diff_on 𝕜 s := ⟨λ h, e.symm_image_image s ▸ e.symm.unique_diff_on_image h, e.unique_diff_on_image⟩ @[simp] lemma continuous_linear_equiv.unique_diff_on_preimage_iff (e : F ≃L[𝕜] E) : unique_diff_on 𝕜 (e ⁻¹' s) ↔ unique_diff_on 𝕜 s := by rw [← e.image_symm_eq_preimage, e.symm.unique_diff_on_image_iff] end tangent_cone section restrict_scalars /-! ### Restricting from `ℂ` to `ℝ`, or generally from `𝕜'` to `𝕜` If a function is differentiable over `ℂ`, then it is differentiable over `ℝ`. In this paragraph, we give variants of this statement, in the general situation where `ℂ` and `ℝ` are replaced respectively by `𝕜'` and `𝕜` where `𝕜'` is a normed algebra over `𝕜`. -/ variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜] variables {𝕜' : Type*} [nondiscrete_normed_field 𝕜'] [normed_algebra 𝕜 𝕜'] variables {E : Type*} [normed_group E] [normed_space 𝕜 E] [normed_space 𝕜' E] variables [is_scalar_tower 𝕜 𝕜' E] variables {F : Type*} [normed_group F] [normed_space 𝕜 F] [normed_space 𝕜' F] variables [is_scalar_tower 𝕜 𝕜' F] variables {f : E → F} {f' : E →L[𝕜'] F} {s : set E} {x : E} lemma has_strict_fderiv_at.restrict_scalars (h : has_strict_fderiv_at f f' x) : has_strict_fderiv_at f (f'.restrict_scalars 𝕜) x := h lemma has_fderiv_at_filter.restrict_scalars {L} (h : has_fderiv_at_filter f f' x L) : has_fderiv_at_filter f (f'.restrict_scalars 𝕜) x L := h lemma has_fderiv_at.restrict_scalars (h : has_fderiv_at f f' x) : has_fderiv_at f (f'.restrict_scalars 𝕜) x := h lemma has_fderiv_within_at.restrict_scalars (h : has_fderiv_within_at f f' s x) : has_fderiv_within_at f (f'.restrict_scalars 𝕜) s x := h lemma differentiable_at.restrict_scalars (h : differentiable_at 𝕜' f x) : differentiable_at 𝕜 f x := (h.has_fderiv_at.restrict_scalars 𝕜).differentiable_at lemma differentiable_within_at.restrict_scalars (h : differentiable_within_at 𝕜' f s x) : differentiable_within_at 𝕜 f s x := (h.has_fderiv_within_at.restrict_scalars 𝕜).differentiable_within_at lemma differentiable_on.restrict_scalars (h : differentiable_on 𝕜' f s) : differentiable_on 𝕜 f s := λx hx, (h x hx).restrict_scalars 𝕜 lemma differentiable.restrict_scalars (h : differentiable 𝕜' f) : differentiable 𝕜 f := λx, (h x).restrict_scalars 𝕜 lemma has_fderiv_within_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_within_at f g' s x) (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_within_at f f' s x := by { rw ← H at h, exact h } lemma has_fderiv_at_of_restrict_scalars {g' : E →L[𝕜] F} (h : has_fderiv_at f g' x) (H : f'.restrict_scalars 𝕜 = g') : has_fderiv_at f f' x := by { rw ← H at h, exact h } lemma differentiable_at.fderiv_restrict_scalars (h : differentiable_at 𝕜' f x) : fderiv 𝕜 f x = (fderiv 𝕜' f x).restrict_scalars 𝕜 := (h.has_fderiv_at.restrict_scalars 𝕜).fderiv lemma differentiable_within_at_iff_restrict_scalars (hf : differentiable_within_at 𝕜 f s x) (hs : unique_diff_within_at 𝕜 s x) : differentiable_within_at 𝕜' f s x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv_within 𝕜 f s x := begin split, { rintros ⟨g', hg'⟩, exact ⟨g', hs.eq (hg'.restrict_scalars 𝕜) hf.has_fderiv_within_at⟩, }, { rintros ⟨f', hf'⟩, exact ⟨f', has_fderiv_within_at_of_restrict_scalars 𝕜 hf.has_fderiv_within_at hf'⟩, }, end lemma differentiable_at_iff_restrict_scalars (hf : differentiable_at 𝕜 f x) : differentiable_at 𝕜' f x ↔ ∃ (g' : E →L[𝕜'] F), g'.restrict_scalars 𝕜 = fderiv 𝕜 f x := begin rw [← differentiable_within_at_univ, ← fderiv_within_univ], exact differentiable_within_at_iff_restrict_scalars 𝕜 hf.differentiable_within_at unique_diff_within_at_univ, end end restrict_scalars /-! ### Support of derivatives -/ section support open function variables (𝕜 : Type*) {E F : Type*} [nondiscrete_normed_field 𝕜] variables [normed_group E] [normed_space 𝕜 E] [normed_group F] [normed_space 𝕜 F] {f : E → F} lemma support_fderiv_subset : support (fderiv 𝕜 f) ⊆ tsupport f := begin intros x, rw [← not_imp_not], intro h2x, rw [not_mem_closure_support_iff_eventually_eq] at h2x, exact nmem_support.mpr (h2x.fderiv_eq.trans $ fderiv_const_apply 0), end lemma has_compact_support.fderiv (hf : has_compact_support f) : has_compact_support (fderiv 𝕜 f) := hf.mono' $ support_fderiv_subset 𝕜 end support
1e1b150e786ab06eb94f12760d60ca3d269b765c
a721fe7446524f18ba361625fc01033d9c8b7a78
/src/principia/mygroup/gareth.lean
6bc608cabd2e6cd8c2c2d1d013dfb455658d224a
[]
no_license
Sterrs/leaning
8fd80d1f0a6117a220bb2e57ece639b9a63deadc
3901cc953694b33adda86cb88ca30ba99594db31
refs/heads/master
1,627,023,822,744
1,616,515,221,000
1,616,515,221,000
245,512,190
2
0
null
1,616,429,050,000
1,583,527,118,000
Lean
UTF-8
Lean
false
false
5,293
lean
-- Gareth's question import ..logic import .basic class gareth (α : Type) extends has_mul α, has_inv α, inhabited α := (mul_assoc (x y z : α): x * y * z = x * (y * z)) (exists_inv (x : α): x * (x⁻¹) * x = x) (inv_unique (x y : α): x * y * x = x → y = x⁻¹) namespace gareth variables {α : Type} [gareth α] (x y z : α) theorem inv_inv : x⁻¹⁻¹ = x := begin symmetry, apply inv_unique, apply inv_unique, conv { to_lhs, congr, rw ←mul_assoc, congr, rw [←mul_assoc, exists_inv], }, rw exists_inv, end theorem inv_cancel : x⁻¹ = y⁻¹ ↔ x = y := begin split; assume h, { rw ←inv_inv y, apply inv_unique, rw ←h, conv { to_lhs, congr, congr, skip, rw ←inv_inv x, }, apply exists_inv, }, { rw h, }, end theorem right_mul : x = y → x * z = y * z := begin assume h, congr, assumption, end theorem left_mul : x = y → z * x = z * y := begin assume h, congr, assumption, end theorem id_inv : (x * x⁻¹)⁻¹ = x * x⁻¹ := begin symmetry, apply inv_unique, conv { congr, congr, rw [←mul_assoc, exists_inv], }, rw [←mul_assoc, exists_inv], end -- We consider the following relation on α def R := x * x⁻¹ = y * y⁻¹ infix ` ≅ `:50 := R theorem cong_def : x ≅ y ↔ x * x⁻¹ = y * y⁻¹ := by refl -- It's an equivalence relation @[refl] theorem cong_refl : x ≅ x := by from rfl @[symm] theorem cong_symm : x ≅ y → y ≅ x := begin assume h, rw cong_def, symmetry, assumption, end @[trans] theorem cong_trans : x ≅ y → y ≅ z → x ≅ z := begin assume hxy hyz, rw cong_def at ⊢ hxy, rw hxy, assumption, end lemma cong_iff_right_multiple : x ≅ y ↔ ∃ z, x = y * z := begin split; assume h, { rw cong_def at h, existsi y⁻¹ * x, rw [←mul_assoc, ←h], symmetry, apply exists_inv, }, { cases h with z h, rw [cong_def, ←id_inv], symmetry, apply inv_unique, conv { to_lhs, rw mul_assoc, congr, skip, rw ←mul_assoc, congr, rw [h, ←mul_assoc, exists_inv, ←h], }, rw [←mul_assoc, exists_inv], }, end lemma invs_cong_iff_left_multiple : x⁻¹ ≅ y⁻¹ ↔ ∃ z, x = z * y := begin split; assume h, { rw [cong_def, inv_inv x, inv_inv y] at h, existsi x * y⁻¹, rw [mul_assoc, ←h, ←mul_assoc, exists_inv], }, { cases h with z h, rw cong_def, rw ←id_inv, symmetry, apply inv_unique, rw inv_inv x, rw inv_inv y, conv { to_lhs, congr, rw mul_assoc, congr, skip, rw h, rw mul_assoc, congr, skip, rw ←mul_assoc, rw exists_inv, }, rw ←h, rw mul_assoc, rw ←mul_assoc x, rw exists_inv, }, end lemma useful : x⁻¹ * x = (x * x)⁻¹ * x * x := begin suffices : x⁻¹ ≅ (x * x)⁻¹, rwa [cong_def, inv_inv x, inv_inv (x * x), ←mul_assoc] at this, symmetry, rw invs_cong_iff_left_multiple, existsi x, refl, end theorem cong_inv : x ≅ x⁻¹ := begin rw cong_iff_right_multiple, existsi x * x, symmetry, rw ←inv_cancel, apply inv_unique, conv { to_rhs, rw ←exists_inv x, rw mul_assoc }, rw mul_assoc, apply left_mul, rw useful, apply right_mul, symmetry, apply inv_unique, conv { to_lhs, rw mul_assoc, congr, skip, rw mul_assoc, congr, skip, rw [←mul_assoc, ←mul_assoc, exists_inv], }, rw mul_assoc, conv { to_lhs, congr, skip, rw [←mul_assoc, exists_inv], }, end theorem id_swap : x * x⁻¹ = x⁻¹ * x := begin conv { to_rhs, congr, skip, rw ←inv_inv x, }, apply cong_inv, end -- Could this be earlier? lemma cong_inv_iff_left_multiple : x ≅ y⁻¹ ↔ ∃ z, x = z * y := begin split; assume h, { rw cong_def at h, rw inv_inv at h, existsi x * y⁻¹, rw [mul_assoc, ←h, id_swap, ←mul_assoc, exists_inv], }, { cases h with z h, rw [cong_def, inv_inv, ←id_swap, ←id_inv], symmetry, apply inv_unique, rw [id_swap, id_swap y], conv { to_lhs, congr, rw mul_assoc, congr, skip, rw [h, mul_assoc], congr, skip, rw [←mul_assoc, exists_inv], }, rw [←h, mul_assoc, ←mul_assoc x, exists_inv], }, end theorem cong_comm : x * y ≅ y * x := begin transitivity x, { rw cong_iff_right_multiple, existsi y, refl, }, transitivity x⁻¹, apply cong_inv, symmetry, rw cong_inv_iff_left_multiple, existsi y, refl, end -- It turns out everything is related theorem cong_trivial : x ≅ y := begin transitivity x * y, { symmetry, rw cong_iff_right_multiple, existsi y, refl, }, { transitivity y * x, apply cong_comm, rw cong_iff_right_multiple, existsi x, refl, }, end -- So set the identitiy to be this unique value theorem id_unique : x * x⁻¹ = y * y⁻¹ := cong_trivial x y -- Instantiate it as a mygroup class instance: hidden.mygroup α := { e := (default α) * (default α)⁻¹, mul_assoc := mul_assoc, mul_id := λ a, by rw [id_unique (default α) a⁻¹, inv_inv, ←mul_assoc, exists_inv], mul_inv := λ a, id_unique _ _ } end gareth
6e52805b661f888c42a5fd1a2642de1c986b34c1
03577f7aaac416af2e8f734149669af300dc499c
/lean_exercises/q2.lean
c3c34a1fc40016809003adc48dbe3aa24dd0f925
[]
no_license
nymarya/algorithms
b4dc73389de588e6934da15b0e0b67ae354907aa
1df987f82273a8ffe2b2042552bbb1428bf165bf
refs/heads/master
1,609,629,118,479
1,600,087,537,000
1,600,087,537,000
99,489,969
0
1
null
null
null
null
UTF-8
Lean
false
false
764
lean
open group open tactic -- books -- https://leanprover.github.io/logic_and_proof/logic_and_proof.pdf -- https://leanprover.github.io/theorem_proving_in_lean/inductive_types.html -- https://github.com/leanprover/lean/blob/master/library/init/algebra/group.lean #print group universe u variables {α : Type u} -- https://proofwiki.org/wiki/Definition:Abelian_Group class abelian (α : Type u ) extends group α := (mul_comm: ∀ a b: α , a * b = b * a ) #print abelian -- theorem 01 theorem letter_a [abelian α] {a b c : α} : a * (b * c) = a * (c*b) := sorry -- theorem 02 theorem letter_b [abelian α] {a b c : α} : ¬∃ y a * (b * c) = a * (c*b) := sorry -- theorem 01 theorem letter_c [abelian α] {a b c : α} : a * (b * c) = a * (c*b) := sorry
08be83e95fb0aa3cd04e53bb1a2760e53bfdf4fb
367134ba5a65885e863bdc4507601606690974c1
/src/number_theory/fermat4.lean
d3967f28675a55658243053da15068f77cff4821
[ "Apache-2.0" ]
permissive
kodyvajjha/mathlib
9bead00e90f68269a313f45f5561766cfd8d5cad
b98af5dd79e13a38d84438b850a2e8858ec21284
refs/heads/master
1,624,350,366,310
1,615,563,062,000
1,615,563,062,000
162,666,963
0
0
Apache-2.0
1,545,367,651,000
1,545,367,651,000
null
UTF-8
Lean
false
false
12,442
lean
/- Copyright (c) 2020 Paul van Wamelen. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Author: Paul van Wamelen. -/ import number_theory.pythagorean_triples import ring_theory.coprime /-! # Fermat's Last Theorem for the case n = 4 There are no non-zero integers `a`, `b` and `c` such that `a ^ 4 + b ^ 4 = c ^ 4`. -/ noncomputable theory open_locale classical /-- Shorthand for three non-zero integers `a`, `b`, and `c` satisfying `a ^ 4 + b ^ 4 = c ^ 2`. We will show that no integers satisfy this equation. Clearly Fermat's Last theorem for n = 4 follows. -/ def fermat_42 (a b c : ℤ) : Prop := a ≠ 0 ∧ b ≠ 0 ∧ a ^ 4 + b ^ 4 = c ^ 2 namespace fermat_42 lemma comm {a b c : ℤ} : (fermat_42 a b c) ↔ (fermat_42 b a c) := by { delta fermat_42, rw add_comm, tauto } lemma mul {a b c k : ℤ} (hk0 : k ≠ 0) : fermat_42 a b c ↔ fermat_42 (k * a) (k * b) (k ^ 2 * c) := begin delta fermat_42, split, { intro f42, split, { exact mul_ne_zero hk0 f42.1 }, split, { exact mul_ne_zero hk0 f42.2.1 }, { calc (k * a) ^ 4 + (k * b) ^ 4 = k ^ 4 * (a ^ 4 + b ^ 4) : by ring ... = k ^ 4 * c ^ 2 : by rw f42.2.2 ... = (k ^ 2 * c) ^ 2 : by ring }}, { intro f42, split, { exact right_ne_zero_of_mul f42.1 }, split, { exact right_ne_zero_of_mul f42.2.1 }, apply (mul_right_inj' (pow_ne_zero 4 hk0)).mp, { calc k ^ 4 * (a ^ 4 + b ^ 4) = (k * a) ^ 4 + (k * b) ^ 4 : by ring ... = (k ^ 2 * c) ^ 2 : by rw f42.2.2 ... = k ^ 4 * c ^ 2 : by ring }} end lemma ne_zero {a b c : ℤ} (h : fermat_42 a b c) : c ≠ 0 := begin apply ne_zero_pow (dec_trivial : 2 ≠ 0), apply ne_of_gt, rw [← h.2.2, (by ring : a ^ 4 + b ^ 4 = (a ^ 2) ^ 2 + (b ^ 2) ^ 2)], exact add_pos (pow_two_pos_of_ne_zero _ (pow_ne_zero 2 h.1)) (pow_two_pos_of_ne_zero _ (pow_ne_zero 2 h.2.1)) end /-- We say a solution to `a ^ 4 + b ^ 4 = c ^ 2` is minimal if there is no other solution with a smaller `c` (in absolute value). -/ def minimal (a b c : ℤ) : Prop := (fermat_42 a b c) ∧ ∀ (a1 b1 c1 : ℤ), (fermat_42 a1 b1 c1) → int.nat_abs c ≤ int.nat_abs c1 /-- if we have a solution to `a ^ 4 + b ^ 4 = c ^ 2` then there must be a minimal one. -/ lemma exists_minimal {a b c : ℤ} (h : fermat_42 a b c) : ∃ (a0 b0 c0), (minimal a0 b0 c0) := begin let S : set ℕ := { n | ∃ (s : ℤ × ℤ × ℤ), fermat_42 s.1 s.2.1 s.2.2 ∧ n = int.nat_abs s.2.2}, have S_nonempty : S.nonempty, { use int.nat_abs c, rw set.mem_set_of_eq, use ⟨a, ⟨b, c⟩⟩, tauto }, let m : ℕ := nat.find S_nonempty, have m_mem : m ∈ S := nat.find_spec S_nonempty, rcases m_mem with ⟨s0, hs0, hs1⟩, use [s0.1, s0.2.1, s0.2.2, hs0], intros a1 b1 c1 h1, rw ← hs1, apply nat.find_min', use ⟨a1, ⟨b1, c1⟩⟩, tauto end /-- a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` must have `a` and `b` coprime. -/ lemma coprime_of_minimal {a b c : ℤ} (h : minimal a b c) : is_coprime a b := begin apply int.gcd_eq_one_iff_coprime.mp, by_contradiction hab, obtain ⟨p, hp, hpa, hpb⟩ := nat.prime.not_coprime_iff_dvd.mp hab, obtain ⟨a1, rfl⟩ := (int.coe_nat_dvd_left.mpr hpa), obtain ⟨b1, rfl⟩ := (int.coe_nat_dvd_left.mpr hpb), have hpc : (p : ℤ) ^ 2 ∣ c, { apply (int.pow_dvd_pow_iff (dec_trivial : 0 < 2)).mp, rw ← h.1.2.2, apply dvd.intro (a1 ^ 4 + b1 ^ 4), ring }, obtain ⟨c1, rfl⟩ := hpc, have hf : fermat_42 a1 b1 c1, exact (fermat_42.mul (int.coe_nat_ne_zero.mpr (nat.prime.ne_zero hp))).mpr h.1, apply nat.le_lt_antisymm (h.2 _ _ _ hf), rw [int.nat_abs_mul, lt_mul_iff_one_lt_left, int.nat_abs_pow, int.nat_abs_of_nat], { exact nat.one_lt_pow _ _ (show 0 < 2, from dec_trivial) (nat.prime.one_lt hp) }, { exact (nat.pos_of_ne_zero (int.nat_abs_ne_zero_of_ne_zero (ne_zero hf))) }, end /-- We can swap `a` and `b` in a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2`. -/ lemma minimal_comm {a b c : ℤ} : (minimal a b c) → (minimal b a c) := λ ⟨h1, h2⟩, ⟨fermat_42.comm.mp h1, h2⟩ /-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has positive `c`. -/ lemma neg_of_minimal {a b c : ℤ} : (minimal a b c) → (minimal a b (-c)) := begin rintros ⟨⟨ha, hb, heq⟩, h2⟩, split, { apply and.intro ha (and.intro hb _), rw heq, exact (neg_square c).symm }, rwa (int.nat_abs_neg c), end /-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd. -/ lemma exists_odd_minimal {a b c : ℤ} (h : fermat_42 a b c) : ∃ (a0 b0 c0), (minimal a0 b0 c0) ∧ a0 % 2 = 1 := begin obtain ⟨a0, b0, c0, hf⟩ := exists_minimal h, cases int.mod_two_eq_zero_or_one a0 with hap hap, { cases int.mod_two_eq_zero_or_one b0 with hbp hbp, { exfalso, have h1 : 2 ∣ (int.gcd a0 b0 : ℤ), { exact int.dvd_gcd (int.dvd_of_mod_eq_zero hap) (int.dvd_of_mod_eq_zero hbp) }, rw int.gcd_eq_one_iff_coprime.mpr (coprime_of_minimal hf) at h1, revert h1, norm_num }, { exact ⟨b0, ⟨a0, ⟨c0, minimal_comm hf, hbp⟩⟩⟩ }}, exact ⟨a0, ⟨b0, ⟨c0 , hf, hap⟩⟩⟩, end /-- We can assume that a minimal solution to `a ^ 4 + b ^ 4 = c ^ 2` has `a` odd and `c` positive. -/ lemma exists_pos_odd_minimal {a b c : ℤ} (h : fermat_42 a b c) : ∃ (a0 b0 c0), (minimal a0 b0 c0) ∧ a0 % 2 = 1 ∧ 0 < c0 := begin obtain ⟨a0, b0, c0, hf, hc⟩ := exists_odd_minimal h, rcases lt_trichotomy 0 c0 with (h1 | rfl | h1), { use [a0, b0, c0], tauto }, { exfalso, exact ne_zero hf.1 rfl}, { use [a0, b0, -c0, neg_of_minimal hf, hc], exact neg_pos.mpr h1 }, end end fermat_42 lemma int.coprime_of_sqr_sum {r s : ℤ} (h2 : is_coprime s r) : is_coprime (r ^ 2 + s ^ 2) r := begin rw [pow_two, pow_two], exact (is_coprime.mul_left h2 h2).mul_add_left_left r end lemma int.coprime_of_sqr_sum' {r s : ℤ} (h : is_coprime r s) : is_coprime (r ^ 2 + s ^ 2) (r * s) := begin apply is_coprime.mul_right (int.coprime_of_sqr_sum (is_coprime_comm.mp h)), rw add_comm, apply int.coprime_of_sqr_sum h end namespace fermat_42 -- If we have a solution to a ^ 4 + b ^ 4 = c ^ 2, we can construct a smaller one. This -- implies there can't be a smallest solution. lemma not_minimal {a b c : ℤ} (h : minimal a b c) (ha2 : a % 2 = 1) (hc : 0 < c) : false := begin -- Use the fact that a ^ 2, b ^ 2, c form a pythagorean triple to obtain m and n such that -- a ^ 2 = m ^ 2 - n ^ 2, b ^ 2 = 2 * m * n and c = m ^ 2 + n ^ 2 -- first the formula: have ht : pythagorean_triple (a ^ 2) (b ^ 2) c, { calc ((a ^ 2) * (a ^ 2)) + ((b ^ 2) * (b ^ 2)) = a ^ 4 + b ^ 4 : by ring ... = c ^ 2 : by rw h.1.2.2 ... = c * c : by rw pow_two }, -- coprime requirement: have h2 : int.gcd (a ^ 2) (b ^ 2) = 1 := int.gcd_eq_one_iff_coprime.mpr (coprime_of_minimal h).pow, -- in order to reduce the possibilities we get from the classification of pythagorean triples -- it helps if we know the parity of a ^ 2 (and the sign of c): have ha22 : a ^ 2 % 2 = 1, { rw [pow_two, int.mul_mod, ha2], norm_num }, obtain ⟨m, n, ht1, ht2, ht3, ht4, ht5, ht6⟩ := pythagorean_triple.coprime_classification' ht h2 ha22 hc, -- Now a, n, m form a pythagorean triple and so we can obtain r and s such that -- a = r ^ 2 - s ^ 2, n = 2 * r * s and m = r ^ 2 + s ^ 2 -- formula: have htt : pythagorean_triple a n m, { delta pythagorean_triple, rw [← pow_two, ← pow_two, ← pow_two], exact (add_eq_of_eq_sub ht1) }, -- a and n are coprime, because a ^ 2 = m ^ 2 - n ^ 2 and m and n are coprime. have h3 : int.gcd a n = 1, { apply int.gcd_eq_one_iff_coprime.mpr, apply @is_coprime.of_mul_left_left _ _ _ a, rw [← pow_two, ht1, (by ring : m ^ 2 - n ^ 2 = m ^ 2 + (-n) * n)], exact (int.gcd_eq_one_iff_coprime.mp ht4).pow_left.add_mul_right_left (-n) }, -- m is positive because b is non-zero and b ^ 2 = 2 * m * n and we already have 0 ≤ m. have hb20 : b ^ 2 ≠ 0 := mt pow_eq_zero h.1.2.1, have h4 : 0 < m, { apply lt_of_le_of_ne ht6, rintro rfl, revert hb20, rw ht2, simp }, obtain ⟨r, s, htt1, htt2, htt3, htt4, htt5, htt6⟩ := pythagorean_triple.coprime_classification' htt h3 ha2 h4, -- Now use the fact that (b / 2) ^ 2 = m * r * s, and m, r and s are pairwise coprime to obtain -- i, j and k such that m = i ^ 2, r = j ^ 2 and s = k ^ 2. -- m and r * s are coprime because m = r ^ 2 + s ^ 2 and r and s are coprime. have hcp : int.gcd m (r * s) = 1, { rw htt3, exact int.gcd_eq_one_iff_coprime.mpr (int.coprime_of_sqr_sum' (int.gcd_eq_one_iff_coprime.mp htt4)) }, -- b is even because b ^ 2 = 2 * m * n. have hb2 : 2 ∣ b, { apply @int.prime.dvd_pow' _ 2 _ (by norm_num : nat.prime 2), rw [ht2, mul_assoc], exact dvd_mul_right 2 (m * n) }, cases hb2 with b' hb2', have hs : b' ^ 2 = m * (r * s), { apply (mul_right_inj' (by norm_num : (4 : ℤ) ≠ 0)).mp, calc 4 * b' ^ 2 = (2 * b') * (2 * b') : by ring ... = 2 * m * (2 * r * s) : by rw [← hb2', ← pow_two, ht2, htt2] ... = 4 * (m * (r * s)) : by ring }, have hrsz : r * s ≠ 0, -- because b ^ 2 is not zero and (b / 2) ^ 2 = m * (r * s) { by_contradiction hrsz, revert hb20, rw [ht2, htt2, mul_assoc, @mul_assoc _ _ _ r s, (not_not.mp hrsz)], simp }, have h2b0 : b' ≠ 0, { apply ne_zero_pow (dec_trivial : 2 ≠ 0), rw hs, apply mul_ne_zero, { exact ne_of_gt h4}, { exact hrsz } }, obtain ⟨i, hi⟩ := int.sqr_of_gcd_eq_one hcp hs.symm, -- use m is positive to exclude m = - i ^ 2 have hi' : ¬ m = - i ^ 2, { by_contradiction h1, have hit : - i ^ 2 ≤ 0, apply neg_nonpos.mpr (pow_two_nonneg i), rw ← h1 at hit, apply absurd h4 (not_lt.mpr hit) }, replace hi : m = i ^ 2, { apply or.resolve_right hi hi' }, rw mul_comm at hs, rw [int.gcd_comm] at hcp, -- obtain d such that r * s = d ^ 2 obtain ⟨d, hd⟩ := int.sqr_of_gcd_eq_one hcp hs.symm, -- (b / 2) ^ 2 and m are positive so r * s is positive have hd' : ¬ r * s = - d ^ 2, { by_contradiction h1, rw h1 at hs, have h2 : b' ^ 2 ≤ 0, { rw [hs, (by ring : - d ^ 2 * m = - (d ^ 2 * m))], apply neg_nonpos.mpr, apply (zero_le_mul_right h4).mpr (pow_two_nonneg d) }, have h2' : 0 ≤ b' ^ 2, { apply pow_two_nonneg b' }, exact absurd (lt_of_le_of_ne h2' (ne.symm (pow_ne_zero _ h2b0))) (not_lt.mpr h2) }, replace hd : r * s = d ^ 2, { apply or.resolve_right hd hd' }, -- r = +/- j ^ 2 obtain ⟨j, hj⟩ := int.sqr_of_gcd_eq_one htt4 hd, have hj0 : j ≠ 0, { intro h0, rw [h0, zero_pow (dec_trivial : 0 < 2), neg_zero, or_self] at hj, apply left_ne_zero_of_mul hrsz hj }, rw mul_comm at hd, rw [int.gcd_comm] at htt4, -- s = +/- k ^ 2 obtain ⟨k, hk⟩ := int.sqr_of_gcd_eq_one htt4 hd, have hk0 : k ≠ 0, { intro h0, rw [h0, zero_pow (dec_trivial : 0 < 2), neg_zero, or_self] at hk, apply right_ne_zero_of_mul hrsz hk }, have hj2 : r ^ 2 = j ^ 4, { cases hj with hjp hjp; { rw hjp, ring } }, have hk2 : s ^ 2 = k ^ 4, { cases hk with hkp hkp; { rw hkp, ring } }, -- from m = r ^ 2 + s ^ 2 we now get a new solution to a ^ 4 + b ^ 4 = c ^ 2: have hh : i ^ 2 = j ^ 4 + k ^ 4, { rw [← hi, htt3, hj2, hk2] }, have hn : n ≠ 0, { rw ht2 at hb20, apply right_ne_zero_of_mul hb20 }, -- and it has a smaller c: from c = m ^ 2 + n ^ 2 we see that m is smaller than c, and i ^ 2 = m. have hic : int.nat_abs i < int.nat_abs c, { apply int.coe_nat_lt.mp, rw ← (int.eq_nat_abs_of_zero_le (le_of_lt hc)), apply gt_of_gt_of_ge _ (int.abs_le_self_pow_two i), rw [← hi, ht3], apply gt_of_gt_of_ge _ (int.le_self_pow_two m), exact lt_add_of_pos_right (m ^ 2) (pow_two_pos_of_ne_zero n hn) }, have hic' : int.nat_abs c ≤ int.nat_abs i, { apply (h.2 j k i), exact ⟨hj0, hk0, hh.symm⟩ }, apply absurd (not_le_of_lt hic) (not_not.mpr hic') end end fermat_42 lemma not_fermat_42 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) : a ^ 4 + b ^ 4 ≠ c ^ 2 := begin intro h, obtain ⟨a0, b0, c0, ⟨hf, h2, hp⟩⟩ := fermat_42.exists_pos_odd_minimal (and.intro ha (and.intro hb h)), apply fermat_42.not_minimal hf h2 hp end theorem not_fermat_4 {a b c : ℤ} (ha : a ≠ 0) (hb : b ≠ 0) : a ^ 4 + b ^ 4 ≠ c ^ 4 := begin intro heq, apply @not_fermat_42 _ _ (c ^ 2) ha hb, rw heq, ring end
1e7cd286c84ca56b7bf6dac62f08b63988d776e1
d744d97b07fc1e61b0ebea192b2d624125898128
/src/option.lean
75af8150efd61d0cccf921d0777203989b80d70e
[ "MIT" ]
permissive
parkersullivan/leanstuff
019c757848dd8f5db185e6973969141aee6fef7c
3da132c44d365ecd933de64fa04ba66b9e620683
refs/heads/master
1,599,036,040,845
1,573,316,625,000
1,573,316,625,000
219,181,711
0
0
null
null
null
null
UTF-8
Lean
false
false
345
lean
namespace my_option inductive pol_option (α : Type) : Type | None : pol_option | Some (n : α ) : pol_option def op0 := pol_option.None nat def op1 := pol_option.Some 5 #check op0 def option_in {α : Type} [decidable_eq α] : pol_option α → α → bool | (pol_option.None α) n := ff | (pol_option.Some x) n := (n = x) end my_option
4c010235c3e69387af811fd0cfc6dc3285bad9b7
4727251e0cd73359b15b664c3170e5d754078599
/src/data/nat/log.lean
1d4a5049bf5122f46a693b2c5ae4d9cc0cd2fea3
[ "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
11,911
lean
/- Copyright (c) 2020 Simon Hudon. All rights reserved. Released under Apache 2.0 license as described in the file LICENSE. Authors: Simon Hudon, Yaël Dillies -/ import data.nat.pow import tactic.by_contra /-! # Natural number logarithms This file defines two `ℕ`-valued analogs of the logarithm of `n` with base `b`: * `log b n`: Lower logarithm, or floor **log**. Greatest `k` such that `b^k ≤ n`. * `clog b n`: Upper logarithm, or **c**eil **log**. Least `k` such that `n ≤ b^k`. These are interesting because, for `1 < b`, `nat.log b` and `nat.clog b` are respectively right and left adjoints of `nat.pow b`. See `pow_le_iff_le_log` and `le_pow_iff_clog_le`. -/ namespace nat /-! ### Floor logarithm -/ /-- `log b n`, is the logarithm of natural number `n` in base `b`. It returns the largest `k : ℕ` such that `b^k ≤ n`, so if `b^k = n`, it returns exactly `k`. -/ @[pp_nodot] def log (b : ℕ) : ℕ → ℕ | n := if h : b ≤ n ∧ 1 < b then have n / b < n, from div_lt_self ((zero_lt_one.trans h.2).trans_le h.1) h.2, log (n / b) + 1 else 0 private lemma log_eq_zero_aux {b n : ℕ} (hnb : n < b ∨ b ≤ 1) : log b n = 0 := begin rw [or_iff_not_and_not, not_lt, not_le] at hnb, rw [log, ←ite_not, if_pos hnb] end lemma log_of_lt {b n : ℕ} (hb : n < b) : log b n = 0 := log_eq_zero_aux (or.inl hb) lemma log_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n) : log b n = 0 := log_eq_zero_aux (or.inr hb) lemma log_of_one_lt_of_le {b n : ℕ} (h : 1 < b) (hn : b ≤ n) : log b n = log b (n / b) + 1 := by { rw log, exact if_pos ⟨hn, h⟩ } lemma log_eq_zero_iff {b n : ℕ} : log b n = 0 ↔ n < b ∨ b ≤ 1 := ⟨λ h_log, begin by_contra' h, have := log_of_one_lt_of_le h.2 h.1, rw h_log at this, exact succ_ne_zero _ this.symm end, log_eq_zero_aux⟩ lemma log_eq_one_iff {b n : ℕ} : log b n = 1 ↔ n < b * b ∧ 1 < b ∧ b ≤ n := -- This is best possible: if b = 2, n = 5, then 1 < b and b ≤ n but n > b * b. begin refine ⟨λ h_log, _, _⟩, { have bound : 1 < b ∧ b ≤ n, { contrapose h_log, rw [not_and_distrib, not_lt, not_le, or_comm, ←log_eq_zero_iff] at h_log, rw h_log, exact nat.zero_ne_one, }, cases bound with one_lt_b b_le_n, refine ⟨_, one_lt_b, b_le_n⟩, rw [log_of_one_lt_of_le one_lt_b b_le_n, succ_inj', log_eq_zero_iff, nat.div_lt_iff_lt_mul _ _ (lt_trans zero_lt_one one_lt_b)] at h_log, exact h_log.resolve_right (λ b_small, lt_irrefl _ (lt_of_lt_of_le one_lt_b b_small)), }, { rintros ⟨h, one_lt_b, b_le_n⟩, rw [log_of_one_lt_of_le one_lt_b b_le_n, succ_inj', log_eq_zero_iff, nat.div_lt_iff_lt_mul _ _ (lt_trans zero_lt_one one_lt_b)], exact or.inl h, }, end @[simp] lemma log_zero_left : ∀ n, log 0 n = 0 := log_of_left_le_one zero_le_one @[simp] lemma log_zero_right (b : ℕ) : log b 0 = 0 := by { rw log, cases b; refl } @[simp] lemma log_one_left : ∀ n, log 1 n = 0 := log_of_left_le_one le_rfl @[simp] lemma log_one_right (b : ℕ) : log b 1 = 0 := if h : b ≤ 1 then log_of_left_le_one h 1 else log_of_lt (not_le.mp h) /-- `pow b` and `log b` (almost) form a Galois connection. -/ lemma pow_le_iff_le_log {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : 0 < y) : b ^ x ≤ y ↔ x ≤ log b y := begin induction y using nat.strong_induction_on with y ih generalizing x, cases x, { exact iff_of_true hy (zero_le _) }, rw log, split_ifs, { have b_pos : 0 < b := zero_le_one.trans_lt hb, rw [succ_eq_add_one, add_le_add_iff_right, ←ih (y / b) (div_lt_self hy hb) (nat.div_pos h.1 b_pos), le_div_iff_mul_le _ _ b_pos, pow_succ'] }, { refine iff_of_false (λ hby, h ⟨le_trans _ hby, hb⟩) (not_succ_le_zero _), convert pow_mono hb.le (zero_lt_succ x), exact (pow_one b).symm } end lemma lt_pow_iff_log_lt {b : ℕ} (hb : 1 < b) {x y : ℕ} (hy : 0 < y) : y < b ^ x ↔ log b y < x := lt_iff_lt_of_le_iff_le (pow_le_iff_le_log hb hy) lemma log_pow {b : ℕ} (hb : 1 < b) (x : ℕ) : log b (b ^ x) = x := eq_of_forall_le_iff $ λ z, by { rw ←pow_le_iff_le_log hb (pow_pos (zero_lt_one.trans hb) _), exact (pow_right_strict_mono hb).le_iff_le } lemma log_pos {b n : ℕ} (hb : 1 < b) (hn : b ≤ n) : 0 < log b n := by { rwa [←succ_le_iff, ←pow_le_iff_le_log hb (hb.le.trans hn), pow_one] } lemma log_mul_base (b n : ℕ) (hb : 1 < b) (hn : 0 < n) : log b (n * b) = log b n + 1 := eq_of_forall_le_iff $ λ z, begin cases z, { simp }, have : 0 < b := zero_lt_one.trans hb, rw [←pow_le_iff_le_log hb, pow_succ', (strict_mono_mul_right_of_pos this).le_iff_le, pow_le_iff_le_log hb hn, nat.succ_le_succ_iff], simp [hn, this] end lemma lt_pow_succ_log_self {b : ℕ} (hb : 1 < b) (x : ℕ) : x < b ^ (log b x).succ := begin cases x.eq_zero_or_pos with hx hx, { simp only [hx, log_zero_right, pow_one], exact pos_of_gt hb }, rw [←not_le, pow_le_iff_le_log hb hx, not_le], exact lt_succ_self _, end lemma pow_log_le_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 0 < x) : b ^ log b x ≤ x := (pow_le_iff_le_log hb hx).2 le_rfl @[mono] lemma log_mono_right {b n m : ℕ} (h : n ≤ m) : log b n ≤ log b m := begin cases le_or_lt b 1 with hb hb, { rw log_of_left_le_one hb, exact zero_le _ }, { cases nat.eq_zero_or_pos n with hn hn, { rw [hn, log_zero_right], exact zero_le _ }, { rw ←pow_le_iff_le_log hb (hn.trans_le h), exact (pow_log_le_self hb hn).trans h } } end @[mono] lemma log_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : log b n ≤ log c n := begin cases n, { rw [log_zero_right, log_zero_right] }, rw ←pow_le_iff_le_log hc (zero_lt_succ n), calc c ^ log b n.succ ≤ b ^ log b n.succ : pow_le_pow_of_le_left (zero_lt_one.trans hc).le hb _ ... ≤ n.succ : pow_log_le_self (hc.trans_le hb) (zero_lt_succ n) end lemma log_monotone {b : ℕ} : monotone (log b) := λ x y, log_mono_right lemma log_antitone_left {n : ℕ} : antitone_on (λ b, log b n) (set.Ioi 1) := λ _ hc _ _ hb, log_anti_left (set.mem_Iio.1 hc) hb @[simp] lemma log_div_mul_self (b n : ℕ) : log b (n / b * b) = log b n := eq_of_forall_le_iff (λ z, ⟨λ h, h.trans (log_monotone (div_mul_le_self _ _)), λ h, begin rcases b with _|_|b, { rwa log_zero_left at * }, { rwa log_one_left at * }, rcases n.zero_le.eq_or_lt with rfl|hn, { rwa [nat.zero_div, zero_mul] }, cases le_or_lt b.succ.succ n with hb hb, { cases z, { apply zero_le }, rw [←pow_le_iff_le_log, pow_succ'] at h ⊢, { rwa [(strict_mono_mul_right_of_pos nat.succ_pos').le_iff_le, nat.le_div_iff_mul_le _ _ nat.succ_pos'] }, all_goals { simp [hn, nat.div_pos hb nat.succ_pos'] } }, { simpa [div_eq_of_lt, hb, log_of_lt] using h } end⟩) @[simp] lemma log_div_base (b n : ℕ) : log b (n / b) = log b n - 1 := begin cases lt_or_le n b with h h, { rw [div_eq_of_lt h, log_of_lt h, log_zero_right] }, rcases n.zero_le.eq_or_lt with rfl|hn, { rw [nat.zero_div, log_zero_right] }, rcases b with _|_|b, { rw [log_zero_left, log_zero_left] }, { rw [log_one_left, log_one_left] }, rw [←succ_inj', ←succ_inj'], simp_rw succ_eq_add_one, rw [nat.sub_add_cancel, ←log_mul_base]; { simp [succ_le_iff, log_pos, h, nat.div_pos] }, end private lemma add_pred_div_lt {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : (n + b - 1) / b < n := begin rw [div_lt_iff_lt_mul _ _ (zero_lt_one.trans hb), ←succ_le_iff, ←pred_eq_sub_one, succ_pred_eq_of_pos (add_pos (zero_lt_one.trans hn) (zero_lt_one.trans hb))], exact add_le_mul hn hb, end /-! ### Ceil logarithm -/ /-- `clog b n`, is the upper logarithm of natural number `n` in base `b`. It returns the smallest `k : ℕ` such that `n ≤ b^k`, so if `b^k = n`, it returns exactly `k`. -/ @[pp_nodot] def clog (b : ℕ) : ℕ → ℕ | n := if h : 1 < b ∧ 1 < n then have (n + b - 1)/b < n := add_pred_div_lt h.1 h.2, clog ((n + b - 1)/b) + 1 else 0 lemma clog_of_left_le_one {b : ℕ} (hb : b ≤ 1) (n : ℕ) : clog b n = 0 := by rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.1.not_le hb)] lemma clog_of_right_le_one {n : ℕ} (hn : n ≤ 1) (b : ℕ) : clog b n = 0 := by rw [clog, if_neg (λ h : 1 < b ∧ 1 < n, h.2.not_le hn)] @[simp] lemma clog_zero_left (n : ℕ) : clog 0 n = 0 := clog_of_left_le_one zero_le_one _ @[simp] lemma clog_zero_right (b : ℕ) : clog b 0 = 0 := clog_of_right_le_one zero_le_one _ @[simp] lemma clog_one_left (n : ℕ) : clog 1 n = 0 := clog_of_left_le_one le_rfl _ @[simp] lemma clog_one_right (b : ℕ) : clog b 1 = 0 := clog_of_right_le_one le_rfl _ lemma clog_of_two_le {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : clog b n = clog b ((n + b - 1)/b) + 1 := by rw [clog, if_pos (⟨hb, hn⟩ : 1 < b ∧ 1 < n)] lemma clog_pos {b n : ℕ} (hb : 1 < b) (hn : 2 ≤ n) : 0 < clog b n := by { rw clog_of_two_le hb hn, exact zero_lt_succ _ } lemma clog_eq_one {b n : ℕ} (hn : 2 ≤ n) (h : n ≤ b) : clog b n = 1 := begin rw [clog_of_two_le (hn.trans h) hn, clog_of_right_le_one], have n_pos : 0 < n := zero_lt_two.trans_le hn, rw [←lt_succ_iff, nat.div_lt_iff_lt_mul _ _ (n_pos.trans_le h), ←succ_le_iff, ←pred_eq_sub_one, succ_pred_eq_of_pos (add_pos n_pos (n_pos.trans_le h)), succ_mul, one_mul], exact add_le_add_right h _, end /--`clog b` and `pow b` form a Galois connection. -/ lemma le_pow_iff_clog_le {b : ℕ} (hb : 1 < b) {x y : ℕ} : x ≤ b ^ y ↔ clog b x ≤ y := begin induction x using nat.strong_induction_on with x ih generalizing y, cases y, { rw [pow_zero], refine ⟨λ h, (clog_of_right_le_one h b).le, _⟩, simp_rw ←not_lt, contrapose!, exact clog_pos hb }, have b_pos : 0 < b := zero_lt_two.trans_le hb, rw clog, split_ifs, { rw [succ_eq_add_one, add_le_add_iff_right, ←ih ((x + b - 1)/b) (add_pred_div_lt hb h.2), nat.div_le_iff_le_mul_add_pred b_pos, ← pow_succ, add_tsub_assoc_of_le (nat.succ_le_of_lt b_pos), add_le_add_iff_right] }, { exact iff_of_true ((not_lt.1 (not_and.1 h hb)).trans $ succ_le_of_lt $ pow_pos b_pos _) (zero_le _) } end lemma pow_lt_iff_lt_clog {b : ℕ} (hb : 1 < b) {x y : ℕ} : b ^ y < x ↔ y < clog b x := lt_iff_lt_of_le_iff_le (le_pow_iff_clog_le hb) lemma clog_pow (b x : ℕ) (hb : 1 < b) : clog b (b ^ x) = x := eq_of_forall_ge_iff $ λ z, by { rw ←le_pow_iff_clog_le hb, exact (pow_right_strict_mono hb).le_iff_le } lemma pow_pred_clog_lt_self {b : ℕ} (hb : 1 < b) {x : ℕ} (hx : 1 < x) : b ^ (clog b x).pred < x := begin rw [←not_le, le_pow_iff_clog_le hb, not_le], exact pred_lt (clog_pos hb hx).ne', end lemma le_pow_clog {b : ℕ} (hb : 1 < b) (x : ℕ) : x ≤ b ^ clog b x := (le_pow_iff_clog_le hb).2 le_rfl @[mono] lemma clog_mono_right (b : ℕ) {n m : ℕ} (h : n ≤ m) : clog b n ≤ clog b m := begin cases le_or_lt b 1 with hb hb, { rw clog_of_left_le_one hb, exact zero_le _ }, { rw ←le_pow_iff_clog_le hb, exact h.trans (le_pow_clog hb _) } end @[mono] lemma clog_anti_left {b c n : ℕ} (hc : 1 < c) (hb : c ≤ b) : clog b n ≤ clog c n := begin rw ← le_pow_iff_clog_le (lt_of_lt_of_le hc hb), calc n ≤ c ^ clog c n : le_pow_clog hc _ ... ≤ b ^ clog c n : pow_le_pow_of_le_left (zero_lt_one.trans hc).le hb _ end lemma clog_monotone (b : ℕ) : monotone (clog b) := λ x y, clog_mono_right _ lemma clog_antitone_left {n : ℕ} : antitone_on (λ b : ℕ, clog b n) (set.Ioi 1) := λ _ hc _ _ hb, clog_anti_left (set.mem_Iio.1 hc) hb lemma log_le_clog (b n : ℕ) : log b n ≤ clog b n := begin obtain hb | hb := le_or_lt b 1, { rw log_of_left_le_one hb, exact zero_le _}, cases n, { rw log_zero_right, exact zero_le _}, exact (pow_right_strict_mono hb).le_iff_le.1 ((pow_log_le_self hb $ succ_pos _).trans $ le_pow_clog hb _), end end nat