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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
2655fd43742d73bee2d5da8d789d5e1560cbb81c | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/binop_lazy.lean | d3a3cfd1021dccd639d3b75dfa901a22b6189444 | [
"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 | 265 | lean | def f : IO Unit :=
(do IO.println "case 1"; throw (IO.userError "failed"))
<|>
(do IO.println "case 2"; throw (IO.userError "failed"))
<|>
(do IO.println "case 3")
<|>
(let x := dbg_trace "hello"; 1
IO.println x)
#eval f -- should not print hello
|
06a263e46baaa64273a6b66bee9b625a78bd5cc7 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/tactic/field_simp.lean | 799934c18998d835cec9b56c586a1a8a15d5d9bc | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 4,743 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import tactic.interactive
import tactic.norm_num
/-!
# `field_simp` tactic
Tactic to clear denominators in algebraic expressions, based on `simp` with a specific simpset.
-/
namespace tactic
/-- Try to prove a goal of the form `x ≠ 0` by calling `assumption`, or `norm_num1` if `x` is
a numeral. -/
meta def field_simp.ne_zero : tactic unit := do
goal ← tactic.target,
match goal with
| `(%%e ≠ 0) := assumption <|> do n ← e.to_rat, `[norm_num1]
| _ := tactic.fail "goal should be of the form `x ≠ 0`"
end
namespace interactive
setup_tactic_parser
/--
The goal of `field_simp` is to reduce an expression in a field to an expression of the form `n / d`
where neither `n` nor `d` contains any division symbol, just using the simplifier (with a carefully
crafted simpset named `field_simps`) to reduce the number of division symbols whenever possible by
iterating the following steps:
- write an inverse as a division
- in any product, move the division to the right
- if there are several divisions in a product, group them together at the end and write them as a
single division
- reduce a sum to a common denominator
If the goal is an equality, this simpset will also clear the denominators, so that the proof
can normally be concluded by an application of `ring` or `ring_exp`.
`field_simp [hx, hy]` is a short form for
`simp [-one_div, -mul_eq_zero, hx, hy] with field_simps {discharger := tactic.field_simp.ne_zero}`
Note that this naive algorithm will not try to detect common factors in denominators to reduce the
complexity of the resulting expression. Instead, it relies on the ability of `ring` to handle
complicated expressions in the next step.
As always with the simplifier, reduction steps will only be applied if the preconditions of the
lemmas can be checked. This means that proofs that denominators are nonzero should be included. The
fact that a product is nonzero when all factors are, and that a power of a nonzero number is
nonzero, are included in the simpset, but more complicated assertions (especially dealing with sums)
should be given explicitly. If your expression is not completely reduced by the simplifier
invocation, check the denominators of the resulting expression and provide proofs that they are
nonzero to enable further progress.
To check that denominators are nonzero, `field_simp` will look for facts in the context, and
will try to apply `norm_num` to close numerical goals.
The invocation of `field_simp` removes the lemma `one_div` from the simpset, as this lemma
works against the algorithm explained above. It also removes
`mul_eq_zero : x * y = 0 ↔ x = 0 ∨ y = 0`, as `norm_num` can not work on disjunctions to
close goals of the form `24 ≠ 0`, and replaces it with `mul_ne_zero : x ≠ 0 → y ≠ 0 → x * y ≠ 0`
creating two goals instead of a disjunction.
For example,
```lean
example (a b c d x y : ℂ) (hx : x ≠ 0) (hy : y ≠ 0) :
a + b / x + c / x^2 + d / x^3 = a + x⁻¹ * (y * b / y + (d / x + c) / x) :=
begin
field_simp,
ring
end
```
Moreover, the `field_simp` tactic can also take care of inverses of units in
a general (commutative) monoid/ring and partial division `/ₚ`, see `algebra.group.units`
for the definition. Analogue to the case above, the lemma `one_divp` is removed from the simpset
as this works against the algorithm. If you have objects with a `is_unit x` instance like
`(x : R) (hx : is_unit x)`, you should lift them with
`lift x to Rˣ using id hx, rw is_unit.unit_of_coe_units, clear hx`
before using `field_simp`.
See also the `cancel_denoms` tactic, which tries to do a similar simplification for expressions
that have numerals in denominators.
The tactics are not related: `cancel_denoms` will only handle numeric denominators, and will try to
entirely remove (numeric) division from the expression by multiplying by a factor.
-/
meta def field_simp (no_dflt : parse only_flag) (hs : parse simp_arg_list)
(attr_names : parse with_ident_list)
(locat : parse location)
(cfg : simp_config_ext := {discharger := field_simp.ne_zero}) : tactic unit :=
let attr_names := `field_simps :: attr_names,
hs := simp_arg_type.except `one_div :: simp_arg_type.except `mul_eq_zero ::
simp_arg_type.except `one_divp :: hs in
propagate_tags (simp_core cfg.to_simp_config cfg.discharger no_dflt hs attr_names locat >> skip)
add_tactic_doc
{ name := "field_simp",
category := doc_category.tactic,
decl_names := [`tactic.interactive.field_simp],
tags := ["simplification", "arithmetic"] }
end interactive
end tactic
|
688b51cb2207dc8f092bbbd1e0feae270ce35492 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/topology/instances/ennreal.lean | ebe99c6920a31c20d7b014751335713df7a5a747 | [
"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 | 38,430 | 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 data.real.ennreal
/-!
# 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_bUnion (countable_encodable _) $ assume a ha, countable_insert (countable_singleton _),
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_neg (is_closed_eq continuous_id continuous_const)
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
@[elim_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}
@[elim_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_top_of_eq_top : (∃ a, f a = ∞) → (∑ a, f a) = ∞
| ⟨a, ha⟩ :=
begin
rw [ennreal.tsum_eq_supr_sum],
apply le_antisymm le_top,
convert le_supr (λ s:finset α, s.sum f) (finset.singleton a),
rw [finset.sum_singleton, ha]
end
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_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_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) :=
calc _ = (⨆s:finset ℕ, s.sum f) : ennreal.tsum_eq_supr_sum
... = (⨆i:ℕ, (finset.range i).sum f) : le_antisymm
(supr_le_supr2 $ assume s,
let ⟨n, hn⟩ := finset.exists_nat_subset_range s in
⟨n, finset.sum_le_sum_of_subset hn⟩)
(supr_le_supr2 $ assume i, ⟨finset.range i, le_refl _⟩)
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_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
|
c72a33fb89a43226ac428f5503fc26afb029e6dc | 4727251e0cd73359b15b664c3170e5d754078599 | /src/measure_theory/measure/measure_space_def.lean | 6868f5d4042af85ab69974e205fa9f10a46a97b1 | [
"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,579 | 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 measure_theory.measure.outer_measure
import order.filter.countable_Inter
import data.set.accumulate
/-!
# Measure spaces
This file defines measure spaces, the almost-everywhere filter and ae_measurable functions.
See `measure_theory.measure_space` for their properties and for extended documentation.
Given a measurable space `α`, a measure on `α` is a function that sends measurable sets to the
extended nonnegative reals that satisfies the following conditions:
1. `μ ∅ = 0`;
2. `μ` is countably additive. This means that the measure of a countable union of pairwise disjoint
sets is equal to the measure of the individual sets.
Every measure can be canonically extended to an outer measure, so that it assigns values to
all subsets, not just the measurable subsets. On the other hand, a measure that is countably
additive on measurable sets can be restricted to measurable sets to obtain a measure.
In this file a measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure.
Measures on `α` form a complete lattice, and are closed under scalar multiplication with `ℝ≥0∞`.
## Implementation notes
Given `μ : measure α`, `μ s` is the value of the *outer measure* applied to `s`.
This conveniently allows us to apply the measure to sets without proving that they are measurable.
We get countable subadditivity for all sets, but only countable additivity for measurable sets.
See the documentation of `measure_theory.measure_space` for ways to construct measures and proving
that two measure are equal.
A `measure_space` is a class that is a measurable space with a canonical measure.
The measure is denoted `volume`.
This file does not import `measure_theory.measurable_space`, but only `measurable_space_def`.
## References
* <https://en.wikipedia.org/wiki/Measure_(mathematics)>
* <https://en.wikipedia.org/wiki/Almost_everywhere>
## Tags
measure, almost everywhere, measure space
-/
noncomputable theory
open classical set filter (hiding map) function measurable_space
open_locale classical topological_space big_operators filter ennreal nnreal
variables {α β γ δ ι : Type*}
namespace measure_theory
/-- A measure is defined to be an outer measure that is countably additive on
measurable sets, with the additional assumption that the outer measure is the canonical
extension of the restricted measure. -/
structure measure (α : Type*) [measurable_space α] extends outer_measure α :=
(m_Union ⦃f : ℕ → set α⦄ :
(∀ i, measurable_set (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 α → ℝ≥0∞) :=
⟨λ m, m.to_outer_measure⟩
section
variables [measurable_space α] {μ μ₁ μ₂ : measure α} {s s₁ s₂ t : set α}
namespace measure
/-! ### General facts about measures -/
/-- Obtain a measure by giving a countably additive function that sends `∅` to `0`. -/
def of_measurable (m : Π (s : set α), measurable_set s → ℝ≥0∞)
(m0 : m ∅ measurable_set.empty = 0)
(mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) →
m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)) : measure α :=
{ m_Union := λ f hf hd,
show induced_outer_measure m _ m0 (Union f) =
∑' i, induced_outer_measure m _ m0 (f i), begin
rw [induced_outer_measure_eq m0 mU, mU hf hd],
congr, funext n, rw induced_outer_measure_eq m0 mU
end,
trimmed :=
show (induced_outer_measure m _ m0).trim = induced_outer_measure m _ m0, begin
unfold outer_measure.trim,
congr, funext s hs,
exact induced_outer_measure_eq m0 mU hs
end,
..induced_outer_measure m _ m0 }
lemma of_measurable_apply {m : Π (s : set α), measurable_set s → ℝ≥0∞}
{m0 : m ∅ measurable_set.empty = 0}
{mU : ∀ {{f : ℕ → set α}} (h : ∀ i, measurable_set (f i)), pairwise (disjoint on f) →
m (⋃ i, f i) (measurable_set.Union h) = ∑' i, m (f i) (h i)}
(s : set α) (hs : measurable_set s) : of_measurable m m0 mU s = m s hs :=
induced_outer_measure_eq m0 mU hs
lemma to_outer_measure_injective : injective (to_outer_measure : measure α → outer_measure α) :=
λ ⟨m₁, u₁, h₁⟩ ⟨m₂, u₂, h₂⟩ h, by { congr, exact h }
@[ext] lemma ext (h : ∀ s, measurable_set s → μ₁ s = μ₂ s) : μ₁ = μ₂ :=
to_outer_measure_injective $ by rw [← trimmed, outer_measure.trim_congr h, trimmed]
lemma ext_iff : μ₁ = μ₂ ↔ ∀ s, measurable_set s → μ₁ s = μ₂ s :=
⟨by { rintro rfl s hs, refl }, measure.ext⟩
end measure
@[simp] lemma coe_to_outer_measure : ⇑μ.to_outer_measure = μ := rfl
lemma to_outer_measure_apply (s : set α) : μ.to_outer_measure s = μ s := rfl
lemma measure_eq_trim (s : set α) : μ s = μ.to_outer_measure.trim s :=
by rw μ.trimmed; refl
lemma measure_eq_infi (s : set α) : μ s = ⨅ t (st : s ⊆ t) (ht : measurable_set t), μ t :=
by rw [measure_eq_trim, outer_measure.trim_eq_infi]; refl
/-- A variant of `measure_eq_infi` which has a single `infi`. This is useful when applying a
lemma next that only works for non-empty infima, in which case you can use
`nonempty_measurable_superset`. -/
lemma measure_eq_infi' (μ : measure α) (s : set α) :
μ s = ⨅ t : { t // s ⊆ t ∧ measurable_set t}, μ t :=
by simp_rw [infi_subtype, infi_and, subtype.coe_mk, ← measure_eq_infi]
lemma measure_eq_induced_outer_measure :
μ s = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty s :=
measure_eq_trim _
lemma to_outer_measure_eq_induced_outer_measure :
μ.to_outer_measure = induced_outer_measure (λ s _, μ s) measurable_set.empty μ.empty :=
μ.trimmed.symm
lemma measure_eq_extend (hs : measurable_set s) :
μ s = extend (λ t (ht : measurable_set t), μ t) s :=
(extend_eq _ hs).symm
@[simp] lemma measure_empty : μ ∅ = 0 := μ.empty
lemma nonempty_of_measure_ne_zero (h : μ s ≠ 0) : s.nonempty :=
ne_empty_iff_nonempty.1 $ λ h', h $ h'.symm ▸ measure_empty
lemma measure_mono (h : s₁ ⊆ s₂) : μ s₁ ≤ μ s₂ := μ.mono h
lemma measure_mono_null (h : s₁ ⊆ s₂) (h₂ : μ s₂ = 0) : μ s₁ = 0 :=
nonpos_iff_eq_zero.1 $ h₂ ▸ measure_mono h
lemma measure_mono_top (h : s₁ ⊆ s₂) (h₁ : μ s₁ = ∞) : μ s₂ = ∞ :=
top_unique $ h₁ ▸ measure_mono h
/-- For every set there exists a measurable superset of the same measure. -/
lemma exists_measurable_superset (μ : measure α) (s : set α) :
∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = μ s :=
by simpa only [← measure_eq_trim] using μ.to_outer_measure.exists_measurable_superset_eq_trim s
/-- For every set `s` and a countable collection of measures `μ i` there exists a measurable
superset `t ⊇ s` such that each measure `μ i` takes the same value on `s` and `t`. -/
lemma exists_measurable_superset_forall_eq {ι} [encodable ι] (μ : ι → measure α) (s : set α) :
∃ t, s ⊆ t ∧ measurable_set t ∧ ∀ i, μ i t = μ i s :=
by simpa only [← measure_eq_trim]
using outer_measure.exists_measurable_superset_forall_eq_trim (λ i, (μ i).to_outer_measure) s
lemma exists_measurable_superset₂ (μ ν : measure α) (s : set α) :
∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = μ s ∧ ν t = ν s :=
by simpa only [bool.forall_bool.trans and.comm]
using exists_measurable_superset_forall_eq (λ b, cond b μ ν) s
lemma exists_measurable_superset_of_null (h : μ s = 0) :
∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0 :=
h ▸ exists_measurable_superset μ s
lemma exists_measurable_superset_iff_measure_eq_zero :
(∃ t, s ⊆ t ∧ measurable_set t ∧ μ t = 0) ↔ μ s = 0 :=
⟨λ ⟨t, hst, _, ht⟩, measure_mono_null hst ht, exists_measurable_superset_of_null⟩
theorem measure_Union_le [encodable β] (s : β → set α) : μ (⋃ i, s i) ≤ ∑' i, μ (s i) :=
μ.to_outer_measure.Union _
lemma measure_bUnion_le {s : set β} (hs : countable s) (f : β → set α) :
μ (⋃ b ∈ s, f b) ≤ ∑' p : s, μ (f p) :=
begin
haveI := hs.to_encodable,
rw [bUnion_eq_Union],
apply measure_Union_le
end
lemma measure_bUnion_finset_le (s : finset β) (f : β → set α) :
μ (⋃ b ∈ s, f b) ≤ ∑ p in s, μ (f p) :=
begin
rw [← finset.sum_attach, finset.attach_eq_univ, ← tsum_fintype],
exact measure_bUnion_le s.countable_to_set f
end
lemma measure_Union_fintype_le [fintype β] (f : β → set α) :
μ (⋃ b, f b) ≤ ∑ p, μ (f p) :=
by { convert measure_bUnion_finset_le finset.univ f, simp }
lemma measure_bUnion_lt_top {s : set β} {f : β → set α} (hs : finite s)
(hfin : ∀ i ∈ s, μ (f i) ≠ ∞) : μ (⋃ i ∈ s, f i) < ∞ :=
begin
convert (measure_bUnion_finset_le hs.to_finset f).trans_lt _,
{ ext, rw [finite.mem_to_finset] },
apply ennreal.sum_lt_top, simpa only [finite.mem_to_finset]
end
lemma measure_Union_null [encodable β] {s : β → set α} :
(∀ i, μ (s i) = 0) → μ (⋃ i, s i) = 0 :=
μ.to_outer_measure.Union_null
@[simp] lemma measure_Union_null_iff [encodable ι] {s : ι → set α} :
μ (⋃ i, s i) = 0 ↔ ∀ i, μ (s i) = 0 :=
μ.to_outer_measure.Union_null_iff
lemma measure_bUnion_null_iff {s : set ι} (hs : countable s) {t : ι → set α} :
μ (⋃ i ∈ s, t i) = 0 ↔ ∀ i ∈ s, μ (t i) = 0 :=
μ.to_outer_measure.bUnion_null_iff hs
lemma measure_sUnion_null_iff {S : set (set α)} (hS : countable S) :
μ (⋃₀ S) = 0 ↔ ∀ s ∈ S, μ s = 0 :=
μ.to_outer_measure.sUnion_null_iff hS
theorem measure_union_le (s₁ s₂ : set α) : μ (s₁ ∪ s₂) ≤ μ s₁ + μ s₂ :=
μ.to_outer_measure.union _ _
lemma measure_union_null : μ s₁ = 0 → μ s₂ = 0 → μ (s₁ ∪ s₂) = 0 :=
μ.to_outer_measure.union_null
@[simp] lemma measure_union_null_iff : μ (s₁ ∪ s₂) = 0 ↔ μ s₁ = 0 ∧ μ s₂ = 0:=
⟨λ h, ⟨measure_mono_null (subset_union_left _ _) h, measure_mono_null (subset_union_right _ _) h⟩,
λ h, measure_union_null h.1 h.2⟩
lemma measure_union_lt_top (hs : μ s < ∞) (ht : μ t < ∞) : μ (s ∪ t) < ∞ :=
(measure_union_le s t).trans_lt (ennreal.add_lt_top.mpr ⟨hs, ht⟩)
@[simp] lemma measure_union_lt_top_iff : μ (s ∪ t) < ∞ ↔ μ s < ∞ ∧ μ t < ∞ :=
begin
refine ⟨λ h, ⟨_, _⟩, λ h, measure_union_lt_top h.1 h.2⟩,
{ exact (measure_mono (set.subset_union_left s t)).trans_lt h, },
{ exact (measure_mono (set.subset_union_right s t)).trans_lt h, },
end
lemma measure_union_ne_top (hs : μ s ≠ ∞) (ht : μ t ≠ ∞) : μ (s ∪ t) ≠ ∞ :=
(measure_union_lt_top hs.lt_top ht.lt_top).ne
@[simp] lemma measure_union_eq_top_iff : μ (s ∪ t) = ∞ ↔ μ s = ∞ ∨ μ t = ∞ :=
not_iff_not.1 $ by simp only [← lt_top_iff_ne_top, ← ne.def, not_or_distrib,
measure_union_lt_top_iff]
lemma exists_measure_pos_of_not_measure_Union_null [encodable β] {s : β → set α}
(hs : μ (⋃ n, s n) ≠ 0) : ∃ n, 0 < μ (s n) :=
begin
by_contra' h,
simp_rw nonpos_iff_eq_zero at h,
exact hs (measure_Union_null h),
end
lemma measure_inter_lt_top_of_left_ne_top (hs_finite : μ s ≠ ∞) : μ (s ∩ t) < ∞ :=
(measure_mono (set.inter_subset_left s t)).trans_lt hs_finite.lt_top
lemma measure_inter_lt_top_of_right_ne_top (ht_finite : μ t ≠ ∞) : μ (s ∩ t) < ∞ :=
inter_comm t s ▸ measure_inter_lt_top_of_left_ne_top ht_finite
lemma measure_inter_null_of_null_right (S : set α) {T : set α} (h : μ T = 0) : μ (S ∩ T) = 0 :=
measure_mono_null (inter_subset_right S T) h
lemma measure_inter_null_of_null_left {S : set α} (T : set α) (h : μ S = 0) : μ (S ∩ T) = 0 :=
measure_mono_null (inter_subset_left S T) h
/-! ### The almost everywhere filter -/
/-- The “almost everywhere” filter of co-null sets. -/
def measure.ae {α} {m : measurable_space α} (μ : measure α) : filter α :=
{ sets := {s | μ sᶜ = 0},
univ_sets := by simp,
inter_sets := λ s t hs ht, by simp only [compl_inter, mem_set_of_eq];
exact measure_union_null hs ht,
sets_of_superset := λ s t hs hst, measure_mono_null (set.compl_subset_compl.2 hst) hs }
notation `∀ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.eventually P (measure.ae μ)) := r
notation `∃ᵐ` binders ` ∂` μ `, ` r:(scoped P, filter.frequently P (measure.ae μ)) := r
notation f ` =ᵐ[`:50 μ:50 `] `:0 g:50 := f =ᶠ[measure.ae μ] g
notation f ` ≤ᵐ[`:50 μ:50 `] `:0 g:50 := f ≤ᶠ[measure.ae μ] g
lemma mem_ae_iff {s : set α} : s ∈ μ.ae ↔ μ sᶜ = 0 := iff.rfl
lemma ae_iff {p : α → Prop} : (∀ᵐ a ∂ μ, p a) ↔ μ { a | ¬ p a } = 0 := iff.rfl
lemma compl_mem_ae_iff {s : set α} : sᶜ ∈ μ.ae ↔ μ s = 0 := by simp only [mem_ae_iff, compl_compl]
lemma frequently_ae_iff {p : α → Prop} : (∃ᵐ a ∂μ, p a) ↔ μ {a | p a} ≠ 0 :=
not_congr compl_mem_ae_iff
lemma frequently_ae_mem_iff {s : set α} : (∃ᵐ a ∂μ, a ∈ s) ↔ μ s ≠ 0 :=
not_congr compl_mem_ae_iff
lemma measure_zero_iff_ae_nmem {s : set α} : μ s = 0 ↔ ∀ᵐ a ∂ μ, a ∉ s :=
compl_mem_ae_iff.symm
lemma ae_of_all {p : α → Prop} (μ : measure α) : (∀ a, p a) → ∀ᵐ a ∂ μ, p a :=
eventually_of_forall
--instance ae_is_measurably_generated : is_measurably_generated μ.ae :=
--⟨λ s hs, let ⟨t, hst, htm, htμ⟩ := exists_measurable_superset_of_null hs in
-- ⟨tᶜ, compl_mem_ae_iff.2 htμ, htm.compl, compl_subset_comm.1 hst⟩⟩
instance : countable_Inter_filter μ.ae :=
⟨begin
intros S hSc hS,
simp only [mem_ae_iff, compl_sInter, sUnion_image, bUnion_eq_Union] at hS ⊢,
haveI := hSc.to_encodable,
exact measure_Union_null (subtype.forall.2 hS)
end⟩
lemma ae_imp_iff {p : α → Prop} {q : Prop} : (∀ᵐ x ∂μ, q → p x) ↔ (q → ∀ᵐ x ∂μ, p x) :=
filter.eventually_imp_distrib_left
lemma ae_all_iff [encodable ι] {p : α → ι → Prop} :
(∀ᵐ a ∂ μ, ∀ i, p a i) ↔ (∀ i, ∀ᵐ a ∂ μ, p a i) :=
eventually_countable_forall
lemma ae_ball_iff {S : set ι} (hS : countable S) {p : Π (x : α) (i ∈ S), Prop} :
(∀ᵐ x ∂ μ, ∀ i ∈ S, p x i ‹_›) ↔ ∀ i ∈ S, ∀ᵐ x ∂ μ, p x i ‹_› :=
eventually_countable_ball hS
lemma ae_eq_refl (f : α → δ) : f =ᵐ[μ] f := eventually_eq.rfl
lemma ae_eq_symm {f g : α → δ} (h : f =ᵐ[μ] g) : g =ᵐ[μ] f :=
h.symm
lemma ae_eq_trans {f g h: α → δ} (h₁ : f =ᵐ[μ] g) (h₂ : g =ᵐ[μ] h) :
f =ᵐ[μ] h :=
h₁.trans h₂
lemma ae_le_of_ae_lt {f g : α → ℝ≥0∞} (h : ∀ᵐ x ∂μ, f x < g x) : f ≤ᵐ[μ] g :=
begin
rw [filter.eventually_le, ae_iff],
rw ae_iff at h,
refine measure_mono_null (λ x hx, _) h,
exact not_lt.2 (le_of_lt (not_le.1 hx)),
end
@[simp] lemma ae_eq_empty : s =ᵐ[μ] (∅ : set α) ↔ μ s = 0 :=
eventually_eq_empty.trans $ by simp only [ae_iff, not_not, set_of_mem_eq]
@[simp] lemma ae_eq_univ : s =ᵐ[μ] (univ : set α) ↔ μ sᶜ = 0 := eventually_eq_univ
lemma ae_le_set : s ≤ᵐ[μ] t ↔ μ (s \ t) = 0 :=
calc s ≤ᵐ[μ] t ↔ ∀ᵐ x ∂μ, x ∈ s → x ∈ t : iff.rfl
... ↔ μ (s \ t) = 0 : by simp [ae_iff]; refl
lemma ae_le_set_inter {s' t' : set α} (h : s ≤ᵐ[μ] t) (h' : s' ≤ᵐ[μ] t') :
(s ∩ s' : set α) ≤ᵐ[μ] (t ∩ t' : set α) :=
h.inter h'
@[simp] lemma union_ae_eq_right : (s ∪ t : set α) =ᵐ[μ] t ↔ μ (s \ t) = 0 :=
by simp [eventually_le_antisymm_iff, ae_le_set, union_diff_right,
diff_eq_empty.2 (set.subset_union_right _ _)]
lemma diff_ae_eq_self : (s \ t : set α) =ᵐ[μ] s ↔ μ (s ∩ t) = 0 :=
by simp [eventually_le_antisymm_iff, ae_le_set, diff_diff_right,
diff_diff, diff_eq_empty.2 (set.subset_union_right _ _)]
lemma diff_null_ae_eq_self (ht : μ t = 0) : (s \ t : set α) =ᵐ[μ] s :=
diff_ae_eq_self.mpr (measure_mono_null (inter_subset_right _ _) ht)
lemma ae_eq_set {s t : set α} :
s =ᵐ[μ] t ↔ μ (s \ t) = 0 ∧ μ (t \ s) = 0 :=
by simp [eventually_le_antisymm_iff, ae_le_set]
lemma ae_eq_set_inter {s' t' : set α} (h : s =ᵐ[μ] t) (h' : s' =ᵐ[μ] t') :
(s ∩ s' : set α) =ᵐ[μ] (t ∩ t' : set α) :=
h.inter h'
@[to_additive]
lemma _root_.set.mul_indicator_ae_eq_one {M : Type*} [has_one M] {f : α → M} {s : set α}
(h : s.mul_indicator f =ᵐ[μ] 1) : μ (s ∩ function.mul_support f) = 0 :=
by simpa [filter.eventually_eq, ae_iff] using h
/-- If `s ⊆ t` modulo a set of measure `0`, then `μ s ≤ μ t`. -/
@[mono] lemma measure_mono_ae (H : s ≤ᵐ[μ] t) : μ s ≤ μ t :=
calc μ s ≤ μ (s ∪ t) : measure_mono $ subset_union_left s t
... = μ (t ∪ s \ t) : by rw [union_diff_self, set.union_comm]
... ≤ μ t + μ (s \ t) : measure_union_le _ _
... = μ t : by rw [ae_le_set.1 H, add_zero]
alias measure_mono_ae ← filter.eventually_le.measure_le
/-- If two sets are equal modulo a set of measure zero, then `μ s = μ t`. -/
lemma measure_congr (H : s =ᵐ[μ] t) : μ s = μ t :=
le_antisymm H.le.measure_le H.symm.le.measure_le
alias measure_congr ← filter.eventually_eq.measure_eq
lemma measure_mono_null_ae (H : s ≤ᵐ[μ] t) (ht : μ t = 0) : μ s = 0 :=
nonpos_iff_eq_zero.1 $ ht ▸ H.measure_le
/-- A measurable set `t ⊇ s` such that `μ t = μ s`. It even satisfies `μ (t ∩ u) = μ (s ∩ u)` for
any measurable set `u` if `μ s ≠ ∞`, see `measure_to_measurable_inter`.
(This property holds without the assumption `μ s ≠ ∞` when the space is sigma-finite,
see `measure_to_measurable_inter_of_sigma_finite`).
If `s` is a null measurable set, then
we also have `t =ᵐ[μ] s`, see `null_measurable_set.to_measurable_ae_eq`.
This notion is sometimes called a "measurable hull" in the literature. -/
@[irreducible] def to_measurable (μ : measure α) (s : set α) : set α :=
if h : ∃ t ⊇ s, measurable_set t ∧ t =ᵐ[μ] s then h.some
else if h' : ∃ t ⊇ s, measurable_set t ∧ (∀ u, measurable_set u → μ (t ∩ u) = μ (s ∩ u))
then h'.some
else (exists_measurable_superset μ s).some
lemma subset_to_measurable (μ : measure α) (s : set α) : s ⊆ to_measurable μ s :=
begin
rw to_measurable, split_ifs with hs h's,
exacts [hs.some_spec.fst, h's.some_spec.fst, (exists_measurable_superset μ s).some_spec.1]
end
lemma ae_le_to_measurable : s ≤ᵐ[μ] to_measurable μ s := (subset_to_measurable _ _).eventually_le
@[simp] lemma measurable_set_to_measurable (μ : measure α) (s : set α) :
measurable_set (to_measurable μ s) :=
begin
rw to_measurable, split_ifs with hs h's,
exacts [hs.some_spec.snd.1, h's.some_spec.snd.1, (exists_measurable_superset μ s).some_spec.2.1]
end
@[simp] lemma measure_to_measurable (s : set α) : μ (to_measurable μ s) = μ s :=
begin
rw to_measurable, split_ifs with hs h's,
{ exact measure_congr hs.some_spec.snd.2 },
{ simpa only [inter_univ] using h's.some_spec.snd.2 univ measurable_set.univ },
{ exact (exists_measurable_superset μ s).some_spec.2.2 }
end
/-- A measure space is a measurable space equipped with a
measure, referred to as `volume`. -/
class measure_space (α : Type*) extends measurable_space α :=
(volume : measure α)
export measure_space (volume)
/-- `volume` is the canonical measure on `α`. -/
add_decl_doc volume
section measure_space
notation `∀ᵐ` binders `, ` r:(scoped P, filter.eventually P
(measure_theory.measure.ae measure_theory.measure_space.volume)) := r
notation `∃ᵐ` binders `, ` r:(scoped P, filter.frequently P
(measure_theory.measure.ae measure_theory.measure_space.volume)) := r
/-- The tactic `exact volume`, to be used in optional (`auto_param`) arguments. -/
meta def volume_tac : tactic unit := `[exact measure_theory.measure_space.volume]
end measure_space
end
end measure_theory
section
open measure_theory
/-!
# Almost everywhere measurable functions
A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. We define this property, called `ae_measurable f μ`. It's properties are discussed in
`measure_theory.measure_space`.
-/
variables {m : measurable_space α} [measurable_space β]
{f g : α → β} {μ ν : measure α}
/-- A function is almost everywhere measurable if it coincides almost everywhere with a measurable
function. -/
def ae_measurable {m : measurable_space α} (f : α → β) (μ : measure α . measure_theory.volume_tac) :
Prop :=
∃ g : α → β, measurable g ∧ f =ᵐ[μ] g
lemma measurable.ae_measurable (h : measurable f) : ae_measurable f μ :=
⟨f, h, ae_eq_refl f⟩
namespace ae_measurable
/-- Given an almost everywhere measurable function `f`, associate to it a measurable function
that coincides with it almost everywhere. `f` is explicit in the definition to make sure that
it shows in pretty-printing. -/
def mk (f : α → β) (h : ae_measurable f μ) : α → β := classical.some h
lemma measurable_mk (h : ae_measurable f μ) : measurable (h.mk f) :=
(classical.some_spec h).1
lemma ae_eq_mk (h : ae_measurable f μ) : f =ᵐ[μ] (h.mk f) :=
(classical.some_spec h).2
lemma congr (hf : ae_measurable f μ) (h : f =ᵐ[μ] g) : ae_measurable g μ :=
⟨hf.mk f, hf.measurable_mk, h.symm.trans hf.ae_eq_mk⟩
end ae_measurable
lemma ae_measurable_congr (h : f =ᵐ[μ] g) :
ae_measurable f μ ↔ ae_measurable g μ :=
⟨λ hf, ae_measurable.congr hf h, λ hg, ae_measurable.congr hg h.symm⟩
@[simp] lemma ae_measurable_const {b : β} : ae_measurable (λ a : α, b) μ :=
measurable_const.ae_measurable
lemma ae_measurable_id : ae_measurable id μ := measurable_id.ae_measurable
lemma ae_measurable_id' : ae_measurable (λ x, x) μ := measurable_id.ae_measurable
lemma measurable.comp_ae_measurable [measurable_space δ] {f : α → δ} {g : δ → β}
(hg : measurable g) (hf : ae_measurable f μ) : ae_measurable (g ∘ f) μ :=
⟨g ∘ hf.mk f, hg.comp hf.measurable_mk, eventually_eq.fun_comp hf.ae_eq_mk _⟩
end
|
26e58c6e201f794c27d17e19748426f122dc8e22 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/data/set/finite.lean | d47ff606d49a42266db7227ebb5904843b527987 | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 35,171 | 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.finset.sort
/-!
# Finite sets
This file defines predicates `finite : set α → Prop` and `infinite : set α → Prop` and proves some
basic facts about finite sets.
-/
open set function
universes u v w x
variables {α : Type u} {β : Type v} {ι : Sort w} {γ : Type x}
namespace set
/-- A set is finite if the subtype is a fintype, i.e. there is a
list that enumerates its members. -/
def finite (s : set α) : Prop := nonempty (fintype s)
/-- A set is infinite if it is not finite. -/
def infinite (s : set α) : Prop := ¬ finite s
/-- The subtype corresponding to a finite set is a finite type. Note
that because `finite` isn't a typeclass, this will not fire if it
is made into an instance -/
noncomputable def finite.fintype {s : set α} (h : finite s) : fintype s :=
classical.choice h
/-- Get a finset from a finite set -/
noncomputable def finite.to_finset {s : set α} (h : finite s) : finset α :=
@set.to_finset _ _ h.fintype
@[simp] theorem finite.mem_to_finset {s : set α} (h : finite s) {a : α} : a ∈ h.to_finset ↔ a ∈ s :=
@mem_to_finset _ _ h.fintype _
@[simp] theorem finite.to_finset.nonempty {s : set α} (h : finite s) :
h.to_finset.nonempty ↔ s.nonempty :=
show (∃ x, x ∈ h.to_finset) ↔ (∃ x, x ∈ s),
from exists_congr (λ _, h.mem_to_finset)
@[simp] lemma finite.coe_to_finset {s : set α} (h : finite s) : ↑h.to_finset = s :=
@set.coe_to_finset _ s h.fintype
@[simp] lemma finite.coe_sort_to_finset {s : set α} (h : finite s) :
(h.to_finset : Type*) = s :=
by rw [← finset.coe_sort_coe _, h.coe_to_finset]
@[simp] lemma finite_empty_to_finset (h : finite (∅ : set α)) : h.to_finset = ∅ :=
by rw [← finset.coe_inj, h.coe_to_finset, finset.coe_empty]
@[simp] lemma finite.to_finset_inj {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset = ht.to_finset ↔ s = t :=
by simp [←finset.coe_inj]
@[simp] lemma finite_to_finset_eq_empty_iff {s : set α} {h : finite s} :
h.to_finset = ∅ ↔ s = ∅ :=
by simp [←finset.coe_inj]
theorem finite.exists_finset {s : set α} : finite s →
∃ s' : finset α, ∀ a : α, a ∈ s' ↔ a ∈ s
| ⟨h⟩ := by exactI ⟨to_finset s, λ _, mem_to_finset⟩
theorem finite.exists_finset_coe {s : set α} (hs : finite s) :
∃ s' : finset α, ↑s' = s :=
⟨hs.to_finset, hs.coe_to_finset⟩
/-- Finite sets can be lifted to finsets. -/
instance : can_lift (set α) (finset α) :=
{ coe := coe,
cond := finite,
prf := λ s hs, hs.exists_finset_coe }
theorem finite_mem_finset (s : finset α) : finite {a | a ∈ s} :=
⟨fintype.of_finset s (λ _, iff.rfl)⟩
theorem finite.of_fintype [fintype α] (s : set α) : finite s :=
by classical; exact ⟨set_fintype s⟩
theorem exists_finite_iff_finset {p : set α → Prop} :
(∃ s, finite s ∧ p s) ↔ ∃ s : finset α, p ↑s :=
⟨λ ⟨s, hs, hps⟩, ⟨hs.to_finset, hs.coe_to_finset.symm ▸ hps⟩,
λ ⟨s, hs⟩, ⟨↑s, finite_mem_finset s, hs⟩⟩
lemma finite.fin_embedding {s : set α} (h : finite s) : ∃ (n : ℕ) (f : fin n ↪ α), range f = s :=
⟨_, (fintype.equiv_fin (h.to_finset : set α)).symm.as_embedding, by simp⟩
lemma finite.fin_param {s : set α} (h : finite s) :
∃ (n : ℕ) (f : fin n → α), injective f ∧ range f = s :=
let ⟨n, f, hf⟩ := h.fin_embedding in ⟨n, f, f.injective, hf⟩
/-- Membership of a subset of a finite type is decidable.
Using this as an instance leads to potential loops with `subtype.fintype` under certain decidability
assumptions, so it should only be declared a local instance. -/
def decidable_mem_of_fintype [decidable_eq α] (s : set α) [fintype s] (a) : decidable (a ∈ s) :=
decidable_of_iff _ mem_to_finset
instance fintype_empty : fintype (∅ : set α) :=
fintype.of_finset ∅ $ by simp
theorem empty_card : fintype.card (∅ : set α) = 0 := rfl
@[simp] theorem empty_card' {h : fintype.{u} (∅ : set α)} :
@fintype.card (∅ : set α) h = 0 :=
eq.trans (by congr) empty_card
@[simp] theorem finite_empty : @finite α ∅ := ⟨set.fintype_empty⟩
instance finite.inhabited : inhabited {s : set α // finite s} := ⟨⟨∅, finite_empty⟩⟩
/-- A `fintype` structure on `insert a s`. -/
def fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) : fintype (insert a s : set α) :=
fintype.of_finset ⟨a ::ₘ s.to_finset.1,
multiset.nodup_cons_of_nodup (by simp [h]) s.to_finset.2⟩ $ by simp
theorem card_fintype_insert' {a : α} (s : set α) [fintype s] (h : a ∉ s) :
@fintype.card _ (fintype_insert' s h) = fintype.card s + 1 :=
by rw [fintype_insert', fintype.card_of_finset];
simp [finset.card, to_finset]; refl
@[simp] theorem card_insert {a : α} (s : set α)
[fintype s] (h : a ∉ s) {d : fintype.{u} (insert a s : set α)} :
@fintype.card _ d = fintype.card s + 1 :=
by rw ← card_fintype_insert' s h; congr
lemma card_image_of_inj_on {s : set α} [fintype s]
{f : α → β} [fintype (f '' s)] (H : ∀x∈s, ∀y∈s, f x = f y → x = y) :
fintype.card (f '' s) = fintype.card s :=
by haveI := classical.prop_decidable; exact
calc fintype.card (f '' s) = (s.to_finset.image f).card : fintype.card_of_finset' _ (by simp)
... = s.to_finset.card : finset.card_image_of_inj_on
(λ x hx y hy hxy, H x (mem_to_finset.1 hx) y (mem_to_finset.1 hy) hxy)
... = fintype.card s : (fintype.card_of_finset' _ (λ a, mem_to_finset)).symm
lemma card_image_of_injective (s : set α) [fintype s]
{f : α → β} [fintype (f '' s)] (H : function.injective f) :
fintype.card (f '' s) = fintype.card s :=
card_image_of_inj_on $ λ _ _ _ _ h, H h
section
local attribute [instance] decidable_mem_of_fintype
instance fintype_insert [decidable_eq α] (a : α) (s : set α) [fintype s] :
fintype (insert a s : set α) :=
if h : a ∈ s then by rwa [insert_eq, union_eq_self_of_subset_left (singleton_subset_iff.2 h)]
else fintype_insert' _ h
end
@[simp] theorem finite.insert (a : α) {s : set α} : finite s → finite (insert a s)
| ⟨h⟩ := ⟨@set.fintype_insert _ (classical.dec_eq α) _ _ h⟩
lemma to_finset_insert [decidable_eq α] {a : α} {s : set α} (hs : finite s) :
(hs.insert a).to_finset = insert a hs.to_finset :=
finset.ext $ by simp
@[simp] lemma insert_to_finset [decidable_eq α] {a : α} {s : set α} [fintype s] :
(insert a s).to_finset = insert a s.to_finset :=
by simp [finset.ext_iff, mem_insert_iff]
@[elab_as_eliminator]
theorem finite.induction_on {C : set α → Prop} {s : set α} (h : finite s)
(H0 : C ∅) (H1 : ∀ {a s}, a ∉ s → finite s → C s → C (insert a s)) : C s :=
let ⟨t⟩ := h in by exactI
match s.to_finset, @mem_to_finset _ s _ with
| ⟨l, nd⟩, al := begin
change ∀ a, a ∈ l ↔ a ∈ s at al,
clear _let_match _match t h, revert s nd al,
refine multiset.induction_on l _ (λ a l IH, _); intros s nd al,
{ rw show s = ∅, from eq_empty_iff_forall_not_mem.2 (by simpa using al),
exact H0 },
{ rw ← show insert a {x | x ∈ l} = s, from set.ext (by simpa using al),
cases multiset.nodup_cons.1 nd with m nd',
refine H1 _ ⟨finset.subtype.fintype ⟨l, nd'⟩⟩ (IH nd' (λ _, iff.rfl)),
exact m }
end
end
@[elab_as_eliminator]
theorem finite.dinduction_on {C : ∀s:set α, finite s → Prop} {s : set α} (h : finite s)
(H0 : C ∅ finite_empty)
(H1 : ∀ {a s}, a ∉ s → ∀h:finite s, C s h → C (insert a s) (h.insert a)) :
C s h :=
have ∀h:finite s, C s h,
from finite.induction_on h (assume h, H0) (assume a s has hs ih h, H1 has hs (ih _)),
this h
instance fintype_singleton (a : α) : fintype ({a} : set α) :=
unique.fintype
@[simp] theorem card_singleton (a : α) :
fintype.card ({a} : set α) = 1 :=
fintype.card_of_subsingleton _
@[simp] theorem finite_singleton (a : α) : finite ({a} : set α) :=
⟨set.fintype_singleton _⟩
lemma subsingleton.finite {s : set α} (h : s.subsingleton) : finite s :=
h.induction_on finite_empty finite_singleton
instance fintype_pure : ∀ a : α, fintype (pure a : set α) :=
set.fintype_singleton
theorem finite_pure (a : α) : finite (pure a : set α) :=
⟨set.fintype_pure a⟩
instance fintype_univ [fintype α] : fintype (@univ α) :=
fintype.of_equiv α $ (equiv.set.univ α).symm
theorem finite_univ [fintype α] : finite (@univ α) := ⟨set.fintype_univ⟩
/-- If `(set.univ : set α)` is finite then `α` is a finite type. -/
noncomputable def fintype_of_univ_finite (H : (univ : set α).finite ) :
fintype α :=
@fintype.of_equiv _ (univ : set α) H.fintype (equiv.set.univ _)
lemma univ_finite_iff_nonempty_fintype :
(univ : set α).finite ↔ nonempty (fintype α) :=
begin
split,
{ intro h, exact ⟨fintype_of_univ_finite h⟩ },
{ rintro ⟨_i⟩, exactI finite_univ }
end
theorem infinite_univ_iff : (@univ α).infinite ↔ _root_.infinite α :=
⟨λ h₁, ⟨λ h₂, h₁ $ @finite_univ α h₂⟩, λ ⟨h₁⟩ h₂, h₁ (fintype_of_univ_finite h₂)⟩
theorem infinite_univ [h : _root_.infinite α] : infinite (@univ α) :=
infinite_univ_iff.2 h
theorem infinite_coe_iff {s : set α} : _root_.infinite s ↔ infinite s :=
⟨λ ⟨h₁⟩ h₂, h₁ h₂.some, λ h₁, ⟨λ h₂, h₁ ⟨h₂⟩⟩⟩
theorem infinite.to_subtype {s : set α} (h : infinite s) : _root_.infinite s :=
infinite_coe_iff.2 h
/-- Embedding of `ℕ` into an infinite set. -/
noncomputable def infinite.nat_embedding (s : set α) (h : infinite s) : ℕ ↪ s :=
by { haveI := h.to_subtype, exact infinite.nat_embedding s }
lemma infinite.exists_subset_card_eq {s : set α} (hs : infinite s) (n : ℕ) :
∃ t : finset α, ↑t ⊆ s ∧ t.card = n :=
⟨((finset.range n).map (hs.nat_embedding _)).map (embedding.subtype _), by simp⟩
lemma infinite.nonempty {s : set α} (h : s.infinite) : s.nonempty :=
let a := infinite.nat_embedding s h 37 in ⟨a.1, a.2⟩
instance fintype_union [decidable_eq α] (s t : set α) [fintype s] [fintype t] :
fintype (s ∪ t : set α) :=
fintype.of_finset (s.to_finset ∪ t.to_finset) $ by simp
theorem finite.union {s t : set α} : finite s → finite t → finite (s ∪ t)
| ⟨hs⟩ ⟨ht⟩ := ⟨@set.fintype_union _ (classical.dec_eq α) _ _ hs ht⟩
lemma finite.sup {s t : set α} : finite s → finite t → finite (s ⊔ t) := finite.union
lemma infinite_of_finite_compl {α : Type} [_root_.infinite α] {s : set α}
(hs : sᶜ.finite) : s.infinite :=
λ h, set.infinite_univ (by simpa using hs.union h)
lemma finite.infinite_compl {α : Type} [_root_.infinite α] {s : set α}
(hs : s.finite) : sᶜ.infinite :=
λ h, set.infinite_univ (by simpa using hs.union h)
instance fintype_sep (s : set α) (p : α → Prop) [fintype s] [decidable_pred p] :
fintype ({a ∈ s | p a} : set α) :=
fintype.of_finset (s.to_finset.filter p) $ by simp
instance fintype_inter (s t : set α) [fintype s] [decidable_pred (∈ t)] : fintype (s ∩ t : set α) :=
set.fintype_sep s t
/-- A `fintype` structure on a set defines a `fintype` structure on its subset. -/
def fintype_subset (s : set α) {t : set α} [fintype s] [decidable_pred (∈ t)] (h : t ⊆ s) :
fintype t :=
by rw ← inter_eq_self_of_subset_right h; apply_instance
theorem finite.subset {s : set α} : finite s → ∀ {t : set α}, t ⊆ s → finite t
| ⟨hs⟩ t h := ⟨@set.fintype_subset _ _ _ hs (classical.dec_pred t) h⟩
lemma finite.union_iff {s t : set α} : finite (s ∪ t) ↔ finite s ∧ finite t :=
⟨λ h, ⟨h.subset (subset_union_left _ _), h.subset (subset_union_right _ _)⟩,
λ ⟨hs, ht⟩, hs.union ht⟩
lemma finite.diff {s t u : set α} (hs : s.finite) (ht : t.finite) (h : u \ t ≤ s) : u.finite :=
begin
refine finite.subset (ht.union hs) _,
exact diff_subset_iff.mp h
end
theorem finite.inter_of_left {s : set α} (h : finite s) (t : set α) : finite (s ∩ t) :=
h.subset (inter_subset_left _ _)
theorem finite.inter_of_right {s : set α} (h : finite s) (t : set α) : finite (t ∩ s) :=
h.subset (inter_subset_right _ _)
theorem finite.inf_of_left {s : set α} (h : finite s) (t : set α) : finite (s ⊓ t) :=
h.inter_of_left t
theorem finite.inf_of_right {s : set α} (h : finite s) (t : set α) : finite (t ⊓ s) :=
h.inter_of_right t
theorem infinite_mono {s t : set α} (h : s ⊆ t) : infinite s → infinite t :=
mt (λ ht, ht.subset h)
instance fintype_image [decidable_eq β] (s : set α) (f : α → β) [fintype s] : fintype (f '' s) :=
fintype.of_finset (s.to_finset.image f) $ by simp
instance fintype_range [decidable_eq β] (f : α → β) [fintype α] : fintype (range f) :=
fintype.of_finset (finset.univ.image f) $ by simp [range]
theorem finite_range (f : α → β) [fintype α] : finite (range f) :=
by haveI := classical.dec_eq β; exact ⟨by apply_instance⟩
theorem finite.image {s : set α} (f : α → β) : finite s → finite (f '' s)
| ⟨h⟩ := ⟨@set.fintype_image _ _ (classical.dec_eq β) _ _ h⟩
theorem infinite_of_infinite_image (f : α → β) {s : set α} (hs : (f '' s).infinite) :
s.infinite :=
mt (finite.image f) hs
lemma finite.dependent_image {s : set α} (hs : finite s) (F : Π i ∈ s, β) :
finite {y : β | ∃ x (hx : x ∈ s), y = F x hx} :=
begin
letI : fintype s := hs.fintype,
convert finite_range (λ x : s, F x x.2),
simp only [set_coe.exists, subtype.coe_mk, eq_comm],
end
theorem finite.of_preimage {f : α → β} {s : set β} (h : finite (f ⁻¹' s)) (hf : surjective f) :
finite s :=
hf.image_preimage s ▸ h.image _
instance fintype_map {α β} [decidable_eq β] :
∀ (s : set α) (f : α → β) [fintype s], fintype (f <$> s) := set.fintype_image
theorem finite.map {α β} {s : set α} :
∀ (f : α → β), finite s → finite (f <$> s) := finite.image
/-- If a function `f` has a partial inverse and sends a set `s` to a set with `[fintype]` instance,
then `s` has a `fintype` structure as well. -/
def fintype_of_fintype_image (s : set α)
{f : α → β} {g} (I : is_partial_inv f g) [fintype (f '' s)] : fintype s :=
fintype.of_finset ⟨_, @multiset.nodup_filter_map β α g _
(@injective_of_partial_inv_right _ _ f g I) (f '' s).to_finset.2⟩ $ λ a,
begin
suffices : (∃ b x, f x = b ∧ g b = some a ∧ x ∈ s) ↔ a ∈ s,
by simpa [exists_and_distrib_left.symm, and.comm, and.left_comm, and.assoc],
rw exists_swap,
suffices : (∃ x, x ∈ s ∧ g (f x) = some a) ↔ a ∈ s, {simpa [and.comm, and.left_comm, and.assoc]},
simp [I _, (injective_of_partial_inv I).eq_iff]
end
theorem finite_of_finite_image {s : set α} {f : α → β} (hi : set.inj_on f s) :
finite (f '' s) → finite s | ⟨h⟩ :=
⟨@fintype.of_injective _ _ h (λa:s, ⟨f a.1, mem_image_of_mem f a.2⟩) $
assume a b eq, subtype.eq $ hi a.2 b.2 $ subtype.ext_iff_val.1 eq⟩
theorem finite_image_iff {s : set α} {f : α → β} (hi : inj_on f s) :
finite (f '' s) ↔ finite s :=
⟨finite_of_finite_image hi, finite.image _⟩
theorem infinite_image_iff {s : set α} {f : α → β} (hi : inj_on f s) :
infinite (f '' s) ↔ infinite s :=
not_congr $ finite_image_iff hi
theorem infinite_of_inj_on_maps_to {s : set α} {t : set β} {f : α → β}
(hi : inj_on f s) (hm : maps_to f s t) (hs : infinite s) : infinite t :=
infinite_mono (maps_to'.mp hm) $ (infinite_image_iff hi).2 hs
theorem infinite.exists_ne_map_eq_of_maps_to {s : set α} {t : set β} {f : α → β}
(hs : infinite s) (hf : maps_to f s t) (ht : finite t) :
∃ (x ∈ s) (y ∈ s), x ≠ y ∧ f x = f y :=
begin
unfreezingI { contrapose! ht },
exact infinite_of_inj_on_maps_to (λ x hx y hy, not_imp_not.1 (ht x hx y hy)) hf hs
end
theorem infinite.exists_lt_map_eq_of_maps_to [linear_order α] {s : set α} {t : set β} {f : α → β}
(hs : infinite s) (hf : maps_to f s t) (ht : finite t) :
∃ (x ∈ s) (y ∈ s), x < y ∧ f x = f y :=
let ⟨x, hx, y, hy, hxy, hf⟩ := hs.exists_ne_map_eq_of_maps_to hf ht
in hxy.lt_or_lt.elim (λ hxy, ⟨x, hx, y, hy, hxy, hf⟩) (λ hyx, ⟨y, hy, x, hx, hyx, hf.symm⟩)
theorem infinite_range_of_injective [_root_.infinite α] {f : α → β} (hi : injective f) :
infinite (range f) :=
by { rw [←image_univ, infinite_image_iff (inj_on_of_injective hi _)], exact infinite_univ }
theorem infinite_of_injective_forall_mem [_root_.infinite α] {s : set β} {f : α → β}
(hi : injective f) (hf : ∀ x : α, f x ∈ s) : infinite s :=
by { rw ←range_subset_iff at hf, exact infinite_mono hf (infinite_range_of_injective hi) }
theorem finite.preimage {s : set β} {f : α → β}
(I : set.inj_on f (f⁻¹' s)) (h : finite s) : finite (f ⁻¹' s) :=
finite_of_finite_image I (h.subset (image_preimage_subset f s))
theorem finite.preimage_embedding {s : set β} (f : α ↪ β) (h : s.finite) : (f ⁻¹' s).finite :=
finite.preimage (λ _ _ _ _ h', f.injective h') h
lemma finite_option {s : set (option α)} : finite s ↔ finite {x : α | some x ∈ s} :=
⟨λ h, h.preimage_embedding embedding.some,
λ h, ((h.image some).insert none).subset $
λ x, option.cases_on x (λ _, or.inl rfl) (λ x hx, or.inr $ mem_image_of_mem _ hx)⟩
instance fintype_Union [decidable_eq α] {ι : Type*} [fintype ι]
(f : ι → set α) [∀ i, fintype (f i)] : fintype (⋃ i, f i) :=
fintype.of_finset (finset.univ.bUnion (λ i, (f i).to_finset)) $ by simp
theorem finite_Union {ι : Type*} [fintype ι] {f : ι → set α} (H : ∀i, finite (f i)) :
finite (⋃ i, f i) :=
⟨@set.fintype_Union _ (classical.dec_eq α) _ _ _ (λ i, finite.fintype (H i))⟩
/-- A union of sets with `fintype` structure over a set with `fintype` structure has a `fintype`
structure. -/
def fintype_bUnion [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) (H : ∀ i ∈ s, fintype (f i)) : fintype (⋃ i ∈ s, f i) :=
by rw bUnion_eq_Union; exact
@set.fintype_Union _ _ _ _ _ (by rintro ⟨i, hi⟩; exact H i hi)
instance fintype_bUnion' [decidable_eq α] {ι : Type*} {s : set ι} [fintype s]
(f : ι → set α) [H : ∀ i, fintype (f i)] : fintype (⋃ i ∈ s, f i) :=
fintype_bUnion _ (λ i _, H i)
theorem finite.sUnion {s : set (set α)} (h : finite s) (H : ∀t∈s, finite t) : finite (⋃₀ s) :=
by rw sUnion_eq_Union; haveI := finite.fintype h;
apply finite_Union; simpa using H
theorem finite.bUnion {α} {ι : Type*} {s : set ι} {f : Π i ∈ s, set α} :
finite s → (∀ i ∈ s, finite (f i ‹_›)) → finite (⋃ i∈s, f i ‹_›)
| ⟨hs⟩ h := by rw [bUnion_eq_Union]; exactI finite_Union (λ i, h _ _)
theorem finite_Union_Prop {p : Prop} {f : p → set α} (hf : ∀ h, finite (f h)) :
finite (⋃ h : p, f h) :=
by by_cases p; simp *
instance fintype_lt_nat (n : ℕ) : fintype {i | i < n} :=
fintype.of_finset (finset.range n) $ by simp
instance fintype_le_nat (n : ℕ) : fintype {i | i ≤ n} :=
by simpa [nat.lt_succ_iff] using set.fintype_lt_nat (n+1)
lemma finite_le_nat (n : ℕ) : finite {i | i ≤ n} := ⟨set.fintype_le_nat _⟩
lemma finite_lt_nat (n : ℕ) : finite {i | i < n} := ⟨set.fintype_lt_nat _⟩
instance fintype_prod (s : set α) (t : set β) [fintype s] [fintype t] : fintype (set.prod s t) :=
fintype.of_finset (s.to_finset.product t.to_finset) $ by simp
lemma finite.prod {s : set α} {t : set β} : finite s → finite t → finite (set.prod s t)
| ⟨hs⟩ ⟨ht⟩ := by exactI ⟨set.fintype_prod s t⟩
/-- `image2 f s t` is finitype if `s` and `t` are. -/
instance fintype_image2 [decidable_eq γ] (f : α → β → γ) (s : set α) (t : set β)
[hs : fintype s] [ht : fintype t] : fintype (image2 f s t : set γ) :=
by { rw ← image_prod, apply set.fintype_image }
lemma finite.image2 (f : α → β → γ) {s : set α} {t : set β} (hs : finite s) (ht : finite t) :
finite (image2 f s t) :=
by { rw ← image_prod, exact (hs.prod ht).image _ }
/-- If `s : set α` is a set with `fintype` instance and `f : α → set β` is a function such that
each `f a`, `a ∈ s`, has a `fintype` structure, then `s >>= f` has a `fintype` structure. -/
def fintype_bind {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) (H : ∀ a ∈ s, fintype (f a)) : fintype (s >>= f) :=
set.fintype_bUnion _ H
instance fintype_bind' {α β} [decidable_eq β] (s : set α) [fintype s]
(f : α → set β) [H : ∀ a, fintype (f a)] : fintype (s >>= f) :=
fintype_bind _ _ (λ i _, H i)
theorem finite.bind {α β} {s : set α} {f : α → set β} (h : finite s) (hf : ∀ a ∈ s, finite (f a)) :
finite (s >>= f) :=
h.bUnion hf
instance fintype_seq [decidable_eq β] (f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f.seq s) :=
by { rw seq_def, apply set.fintype_bUnion' }
instance fintype_seq' {α β : Type u} [decidable_eq β]
(f : set (α → β)) (s : set α) [fintype f] [fintype s] :
fintype (f <*> s) :=
set.fintype_seq f s
theorem finite.seq {f : set (α → β)} {s : set α} (hf : finite f) (hs : finite s) :
finite (f.seq s) :=
by { rw seq_def, exact hf.bUnion (λ f _, hs.image _) }
theorem finite.seq' {α β : Type u} {f : set (α → β)} {s : set α} (hf : finite f) (hs : finite s) :
finite (f <*> s) :=
hf.seq hs
/-- There are finitely many subsets of a given finite set -/
lemma finite.finite_subsets {α : Type u} {a : set α} (h : finite a) : finite {b | b ⊆ a} :=
begin
-- we just need to translate the result, already known for finsets,
-- to the language of finite sets
let s : set (set α) := coe '' (↑(finset.powerset (finite.to_finset h)) : set (finset α)),
have : finite s := (finite_mem_finset _).image _,
apply this.subset,
refine λ b hb, ⟨(h.subset hb).to_finset, _, finite.coe_to_finset _⟩,
simpa [finset.subset_iff]
end
lemma exists_min_image [linear_order β] (s : set α) (f : α → β) (h1 : finite s) :
s.nonempty → ∃ a ∈ s, ∀ b ∈ s, f a ≤ f b
| ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset]
using h1.to_finset.exists_min_image f ⟨x, h1.mem_to_finset.2 hx⟩
lemma exists_max_image [linear_order β] (s : set α) (f : α → β) (h1 : finite s) :
s.nonempty → ∃ a ∈ s, ∀ b ∈ s, f b ≤ f a
| ⟨x, hx⟩ := by simpa only [exists_prop, finite.mem_to_finset]
using h1.to_finset.exists_max_image f ⟨x, h1.mem_to_finset.2 hx⟩
theorem exists_lower_bound_image [hα : nonempty α] [linear_order β] (s : set α) (f : α → β)
(h : s.finite) : ∃ (a : α), ∀ b ∈ s, f a ≤ f b :=
begin
by_cases hs : set.nonempty s,
{ exact let ⟨x₀, H, hx₀⟩ := set.exists_min_image s f h hs in ⟨x₀, λ x hx, hx₀ x hx⟩ },
{ exact nonempty.elim hα (λ a, ⟨a, λ x hx, absurd (set.nonempty_of_mem hx) hs⟩) }
end
theorem exists_upper_bound_image [hα : nonempty α] [linear_order β] (s : set α) (f : α → β)
(h : s.finite) : ∃ (a : α), ∀ b ∈ s, f b ≤ f a :=
begin
by_cases hs : set.nonempty s,
{ exact let ⟨x₀, H, hx₀⟩ := set.exists_max_image s f h hs in ⟨x₀, λ x hx, hx₀ x hx⟩ },
{ exact nonempty.elim hα (λ a, ⟨a, λ x hx, absurd (set.nonempty_of_mem hx) hs⟩) }
end
end set
namespace finset
variables [decidable_eq β]
variables {s : finset α}
lemma finite_to_set (s : finset α) : set.finite (↑s : set α) :=
set.finite_mem_finset s
@[simp] lemma coe_bUnion {f : α → finset β} : ↑(s.bUnion f) = (⋃x ∈ (↑s : set α), ↑(f x) : set β) :=
by simp [set.ext_iff]
@[simp] lemma finite_to_set_to_finset {α : Type*} (s : finset α) :
(finite_to_set s).to_finset = s :=
by { ext, rw [set.finite.mem_to_finset, mem_coe] }
end finset
namespace set
/-- Finite product of finite sets is finite -/
lemma finite.pi {δ : Type*} [fintype δ] {κ : δ → Type*} {t : Π d, set (κ d)}
(ht : ∀ d, (t d).finite) :
(pi univ t).finite :=
begin
classical,
convert (fintype.pi_finset (λ d, (ht d).to_finset)).finite_to_set,
ext,
simp,
end
/-- A finite union of finsets is finite. -/
lemma union_finset_finite_of_range_finite (f : α → finset β) (h : (range f).finite) :
(⋃ a, (f a : set β)).finite :=
begin
classical,
have w : (⋃ (a : α), ↑(f a)) = (h.to_finset.bUnion id : set β),
{ ext x,
simp only [mem_Union, finset.mem_coe, finset.mem_bUnion, id.def],
use λ ⟨a, ha⟩, ⟨f a, h.mem_to_finset.2 (mem_range_self a), ha⟩,
rintro ⟨s, hs, hx⟩,
obtain ⟨a, rfl⟩ := h.mem_to_finset.1 hs,
exact ⟨a, hx⟩, },
rw w,
apply set.finite_mem_finset,
end
lemma finite_subset_Union {s : set α} (hs : finite s)
{ι} {t : ι → set α} (h : s ⊆ ⋃ i, t i) : ∃ I : set ι, finite I ∧ s ⊆ ⋃ i ∈ I, t i :=
begin
casesI hs,
choose f hf using show ∀ x : s, ∃ i, x.1 ∈ t i, {simpa [subset_def] using h},
refine ⟨range f, finite_range f, λ x hx, _⟩,
rw [bUnion_range, mem_Union],
exact ⟨⟨x, hx⟩, hf _⟩
end
lemma eq_finite_Union_of_finite_subset_Union {ι} {s : ι → set α} {t : set α} (tfin : finite t)
(h : t ⊆ ⋃ i, s i) :
∃ I : set ι, (finite I) ∧ ∃ σ : {i | i ∈ I} → set α,
(∀ i, finite (σ i)) ∧ (∀ i, σ i ⊆ s i) ∧ t = ⋃ i, σ i :=
let ⟨I, Ifin, hI⟩ := finite_subset_Union tfin h in
⟨I, Ifin, λ x, s x ∩ t,
λ i, tfin.subset (inter_subset_right _ _),
λ i, inter_subset_left _ _,
begin
ext x,
rw mem_Union,
split,
{ intro x_in,
rcases mem_Union.mp (hI x_in) with ⟨i, _, ⟨hi, rfl⟩, H⟩,
use [i, hi, H, x_in] },
{ rintros ⟨i, hi, H⟩,
exact H }
end⟩
/-- An increasing union distributes over finite intersection. -/
lemma Union_Inter_of_monotone {ι ι' α : Type*} [fintype ι] [linear_order ι']
[nonempty ι'] {s : ι → ι' → set α} (hs : ∀ i, monotone (s i)) :
(⋃ j : ι', ⋂ i : ι, s i j) = ⋂ i : ι, ⋃ j : ι', s i j :=
begin
ext x, refine ⟨λ hx, Union_Inter_subset hx, λ hx, _⟩,
simp only [mem_Inter, mem_Union, mem_Inter] at hx ⊢, choose j hj using hx,
obtain ⟨j₀⟩ := show nonempty ι', by apply_instance,
refine ⟨finset.univ.fold max j₀ j, λ i, hs i _ (hj i)⟩,
rw [finset.fold_op_rel_iff_or (@le_max_iff _ _)],
exact or.inr ⟨i, finset.mem_univ i, le_rfl⟩
end
instance nat.fintype_Iio (n : ℕ) : fintype (Iio n) :=
fintype.of_finset (finset.range n) $ by simp
/--
If `P` is some relation between terms of `γ` and sets in `γ`,
such that every finite set `t : set γ` has some `c : γ` related to it,
then there is a recursively defined sequence `u` in `γ`
so `u n` is related to the image of `{0, 1, ..., n-1}` under `u`.
(We use this later to show sequentially compact sets
are totally bounded.)
-/
lemma seq_of_forall_finite_exists {γ : Type*}
{P : γ → set γ → Prop} (h : ∀ t, finite t → ∃ c, P c t) :
∃ u : ℕ → γ, ∀ n, P (u n) (u '' Iio n) :=
⟨λ n, @nat.strong_rec_on' (λ _, γ) n $ λ n ih, classical.some $ h
(range $ λ m : Iio n, ih m.1 m.2)
(finite_range _),
λ n, begin
classical,
refine nat.strong_rec_on' n (λ n ih, _),
rw nat.strong_rec_on_beta', convert classical.some_spec (h _ _),
ext x, split,
{ rintros ⟨m, hmn, rfl⟩, exact ⟨⟨m, hmn⟩, rfl⟩ },
{ rintros ⟨⟨m, hmn⟩, rfl⟩, exact ⟨m, hmn, rfl⟩ }
end⟩
lemma finite_range_ite {p : α → Prop} [decidable_pred p] {f g : α → β} (hf : finite (range f))
(hg : finite (range g)) : finite (range (λ x, if p x then f x else g x)) :=
(hf.union hg).subset range_ite_subset
lemma finite_range_const {c : β} : finite (range (λ x : α, c)) :=
(finite_singleton c).subset range_const_subset
lemma range_find_greatest_subset {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ}:
range (λ x, nat.find_greatest (P x) b) ⊆ ↑(finset.range (b + 1)) :=
by { rw range_subset_iff, assume x, simp [nat.lt_succ_iff, nat.find_greatest_le] }
lemma finite_range_find_greatest {P : α → ℕ → Prop} [∀ x, decidable_pred (P x)] {b : ℕ} :
finite (range (λ x, nat.find_greatest (P x) b)) :=
(finset.range (b + 1)).finite_to_set.subset range_find_greatest_subset
lemma card_lt_card {s t : set α} [fintype s] [fintype t] (h : s ⊂ t) :
fintype.card s < fintype.card t :=
fintype.card_lt_of_injective_not_surjective (set.inclusion h.1) (set.inclusion_injective h.1) $
λ hst, (ssubset_iff_subset_ne.1 h).2 (eq_of_inclusion_surjective hst)
lemma card_le_of_subset {s t : set α} [fintype s] [fintype t] (hsub : s ⊆ t) :
fintype.card s ≤ fintype.card t :=
fintype.card_le_of_injective (set.inclusion hsub) (set.inclusion_injective hsub)
lemma eq_of_subset_of_card_le {s t : set α} [fintype s] [fintype t]
(hsub : s ⊆ t) (hcard : fintype.card t ≤ fintype.card s) : s = t :=
(eq_or_ssubset_of_subset hsub).elim id
(λ h, absurd hcard $ not_le_of_lt $ card_lt_card h)
lemma subset_iff_to_finset_subset (s t : set α) [fintype s] [fintype t] :
s ⊆ t ↔ s.to_finset ⊆ t.to_finset :=
by simp
@[simp, mono] lemma finite.to_finset_mono {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset ⊆ ht.to_finset ↔ s ⊆ t :=
begin
split,
{ intros h x,
rw [←finite.mem_to_finset hs, ←finite.mem_to_finset ht],
exact λ hx, h hx },
{ intros h x,
rw [finite.mem_to_finset hs, finite.mem_to_finset ht],
exact λ hx, h hx }
end
@[simp, mono] lemma finite.to_finset_strict_mono {s t : set α} {hs : finite s} {ht : finite t} :
hs.to_finset ⊂ ht.to_finset ↔ s ⊂ t :=
begin
rw [←lt_eq_ssubset, ←finset.lt_iff_ssubset, lt_iff_le_and_ne, lt_iff_le_and_ne],
simp
end
lemma card_range_of_injective [fintype α] {f : α → β} (hf : injective f)
[fintype (range f)] : fintype.card (range f) = fintype.card α :=
eq.symm $ fintype.card_congr $ equiv.of_injective f hf
lemma finite.exists_maximal_wrt [partial_order β] (f : α → β) (s : set α) (h : set.finite s) :
s.nonempty → ∃a∈s, ∀a'∈s, f a ≤ f a' → f a = f a' :=
begin
classical,
refine h.induction_on _ _,
{ assume h, exact absurd h empty_not_nonempty },
assume a s his _ ih _,
cases s.eq_empty_or_nonempty with h h,
{ use a, simp [h] },
rcases ih h with ⟨b, hb, ih⟩,
by_cases f b ≤ f a,
{ refine ⟨a, set.mem_insert _ _, assume c hc hac, le_antisymm hac _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ refl },
{ rwa [← ih c hcs (le_trans h hac)] } },
{ refine ⟨b, set.mem_insert_of_mem _ hb, assume c hc hbc, _⟩,
rcases set.mem_insert_iff.1 hc with rfl | hcs,
{ exact (h hbc).elim },
{ exact ih c hcs hbc } }
end
lemma finite.card_to_finset {s : set α} [fintype s] (h : s.finite) :
h.to_finset.card = fintype.card s :=
by { rw [← finset.card_attach, finset.attach_eq_univ, ← fintype.card], congr' 2, funext,
rw set.finite.mem_to_finset }
section decidable_eq
lemma to_finset_compl {α : Type*} [fintype α] [decidable_eq α]
(s : set α) [fintype (sᶜ : set α)] [fintype s] : sᶜ.to_finset = (s.to_finset)ᶜ :=
by ext; simp
lemma to_finset_inter {α : Type*} [decidable_eq α] (s t : set α) [fintype (s ∩ t : set α)]
[fintype s] [fintype t] : (s ∩ t).to_finset = s.to_finset ∩ t.to_finset :=
by ext; simp
lemma to_finset_union {α : Type*} [decidable_eq α] (s t : set α) [fintype (s ∪ t : set α)]
[fintype s] [fintype t] : (s ∪ t).to_finset = s.to_finset ∪ t.to_finset :=
by ext; simp
lemma to_finset_ne_eq_erase {α : Type*} [decidable_eq α] [fintype α] (a : α)
[fintype {x : α | x ≠ a}] : {x : α | x ≠ a}.to_finset = finset.univ.erase a :=
by ext; simp
lemma card_ne_eq [fintype α] (a : α) [fintype {x : α | x ≠ a}] :
fintype.card {x : α | x ≠ a} = fintype.card α - 1 :=
begin
haveI := classical.dec_eq α,
rw [←to_finset_card, to_finset_ne_eq_erase, finset.card_erase_of_mem (finset.mem_univ _),
finset.card_univ, nat.pred_eq_sub_one],
end
end decidable_eq
section
variables [semilattice_sup α] [nonempty α] {s : set α}
/--A finite set is bounded above.-/
protected lemma finite.bdd_above (hs : finite s) : bdd_above s :=
finite.induction_on hs bdd_above_empty $ λ a s _ _ h, h.insert a
/--A finite union of sets which are all bounded above is still bounded above.-/
lemma finite.bdd_above_bUnion {I : set β} {S : β → set α} (H : finite I) :
(bdd_above (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_above (S i)) :=
finite.induction_on H
(by simp only [bUnion_empty, bdd_above_empty, ball_empty_iff])
(λ a s ha _ hs, by simp only [bUnion_insert, ball_insert_iff, bdd_above_union, hs])
end
section
variables [semilattice_inf α] [nonempty α] {s : set α}
/--A finite set is bounded below.-/
protected lemma finite.bdd_below (hs : finite s) : bdd_below s :=
@finite.bdd_above (order_dual α) _ _ _ hs
/--A finite union of sets which are all bounded below is still bounded below.-/
lemma finite.bdd_below_bUnion {I : set β} {S : β → set α} (H : finite I) :
(bdd_below (⋃i∈I, S i)) ↔ (∀i ∈ I, bdd_below (S i)) :=
@finite.bdd_above_bUnion (order_dual α) _ _ _ _ _ H
end
end set
namespace finset
/-- A finset is bounded above. -/
protected lemma bdd_above [semilattice_sup α] [nonempty α] (s : finset α) :
bdd_above (↑s : set α) :=
s.finite_to_set.bdd_above
/-- A finset is bounded below. -/
protected lemma bdd_below [semilattice_inf α] [nonempty α] (s : finset α) :
bdd_below (↑s : set α) :=
s.finite_to_set.bdd_below
end finset
namespace fintype
variables [fintype α] {p q : α → Prop} [decidable_pred p] [decidable_pred q]
@[simp]
lemma card_subtype_compl : fintype.card {x // ¬ p x} = fintype.card α - fintype.card {x // p x} :=
begin
classical,
rw [fintype.card_of_subtype (set.to_finset pᶜ), set.to_finset_compl p, finset.card_compl,
fintype.card_of_subtype (set.to_finset p)];
intros; simp; refl
end
/-- If two subtypes of a fintype have equal cardinality, so do their complements. -/
lemma card_compl_eq_card_compl (h : fintype.card {x // p x} = fintype.card {x // q x}) :
fintype.card {x // ¬ p x} = fintype.card {x // ¬ q x} :=
by simp only [card_subtype_compl, h]
end fintype
/--
If a set `s` does not contain any elements between any pair of elements `x, z ∈ s` with `x ≤ z`
(i.e if given `x, y, z ∈ s` such that `x ≤ y ≤ z`, then `y` is either `x` or `z`), then `s` is
finite.
-/
lemma set.finite_of_forall_between_eq_endpoints {α : Type*} [linear_order α] (s : set α)
(h : ∀ (x ∈ s) (y ∈ s) (z ∈ s), x ≤ y → y ≤ z → x = y ∨ y = z) :
set.finite s :=
begin
by_contra hinf,
change s.infinite at hinf,
rcases hinf.exists_subset_card_eq 3 with ⟨t, hts, ht⟩,
let f := t.order_iso_of_fin ht,
let x := f 0,
let y := f 1,
let z := f 2,
have := h x (hts x.2) y (hts y.2) z (hts z.2)
(f.monotone $ by dec_trivial) (f.monotone $ by dec_trivial),
have key₁ : (0 : fin 3) ≠ 1 := by dec_trivial,
have key₂ : (1 : fin 3) ≠ 2 := by dec_trivial,
cases this,
{ dsimp only [x, y] at this, exact key₁ (f.injective $ subtype.coe_injective this) },
{ dsimp only [y, z] at this, exact key₂ (f.injective $ subtype.coe_injective this) }
end
|
1b18a0f5f862315cb9e40ad55a7e92c15f37b4c1 | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/run/univ1.lean | 5095b95be7a3dc631c01b582fdc6d6822b6fa204 | [
"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 | 650 | lean | namespace S1
axiom I : Type*
definition F (X : Type*) : Type* := (X → Prop) → Prop
axiom {u} unfoldd : I.{u} → F I.{u}
axiom {l} foldd : F I.{l} → I.{l}
axiom iso1 : ∀x, foldd (unfoldd x) = x
end S1
namespace S2
universe variables u
axiom I : Type.{u}
definition F (X : Type*) : Type* := (X → Prop) → Prop
axiom unfoldd : I → F I
axiom foldd : F I → I
axiom iso1 : ∀x, foldd (unfoldd x) = x
end S2
namespace S3
section
parameter I : Type*
definition F (X : Type*) : Type* := (X → Prop) → Prop
parameter unfoldd : I → F I
parameter foldd : F I → I
parameter iso1 : ∀x, foldd (unfoldd x) = x
end
end S3
|
e6e794a9e30bd2af3cb8a4b31ffe4528af1f37da | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/data/num/basic.lean | d6f554625cec7b07a11eb6593f3f4ca25ecf1651 | [
"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 | 17,287 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Mario Carneiro
Binary representation of integers using inductive types.
Note: Unlike in Coq, where this representation is preferred because of
the reliance on kernel reduction, in Lean this representation is discouraged
in favor of the "Peano" natural numbers `nat`, and the purpose of this
collection of theorems is to show the equivalence of the different approaches.
-/
import data.vector data.bitvec
/-- The type of positive binary numbers.
13 = 1101(base 2) = bit1 (bit0 (bit1 one)) -/
@[derive has_reflect, derive decidable_eq]
inductive pos_num : Type
| one : pos_num
| bit1 : pos_num → pos_num
| bit0 : pos_num → pos_num
instance : has_one pos_num := ⟨pos_num.one⟩
/-- The type of nonnegative binary numbers, using `pos_num`.
13 = 1101(base 2) = pos (bit1 (bit0 (bit1 one))) -/
@[derive has_reflect, derive decidable_eq]
inductive num : Type
| zero : num
| pos : pos_num → num
instance : has_zero num := ⟨num.zero⟩
instance : has_one num := ⟨num.pos 1⟩
/-- Representation of integers using trichotomy around zero.
13 = 1101(base 2) = pos (bit1 (bit0 (bit1 one)))
-13 = -1101(base 2) = neg (bit1 (bit0 (bit1 one))) -/
@[derive has_reflect, derive decidable_eq]
inductive znum : Type
| zero : znum
| pos : pos_num → znum
| neg : pos_num → znum
instance : has_zero znum := ⟨znum.zero⟩
instance : has_one znum := ⟨znum.pos 1⟩
/-- See `snum`. -/
@[derive has_reflect, derive decidable_eq]
inductive nzsnum : Type
| msb : bool → nzsnum
| bit : bool → nzsnum → nzsnum
/-- Alternative representation of integers using a sign bit at the end.
The convention on sign here is to have the argument to `msb` denote
the sign of the MSB itself, with all higher bits set to the negation
of this sign. The result is interpreted in two's complement.
13 = ..0001101(base 2) = nz (bit1 (bit0 (bit1 (msb tt))))
-13 = ..1110011(base 2) = nz (bit1 (bit1 (bit0 (msb ff))))
As with `num`, a special case must be added for zero, which has no msb,
but by two's complement symmetry there is a second special case for -1.
Here the `bool` field indicates the sign of the number.
0 = ..0000000(base 2) = zero ff
-1 = ..1111111(base 2) = zero tt -/
@[derive has_reflect, derive decidable_eq]
inductive snum : Type
| zero : bool → snum
| nz : nzsnum → snum
instance : has_coe nzsnum snum := ⟨snum.nz⟩
instance : has_zero snum := ⟨snum.zero ff⟩
instance : has_one nzsnum := ⟨nzsnum.msb tt⟩
instance : has_one snum := ⟨snum.nz 1⟩
namespace pos_num
def bit (b : bool) : pos_num → pos_num := cond b bit1 bit0
def succ : pos_num → pos_num
| 1 := bit0 one
| (bit1 n) := bit0 (succ n)
| (bit0 n) := bit1 n
def is_one : pos_num → bool
| 1 := tt
| _ := ff
protected def add : pos_num → pos_num → pos_num
| 1 b := succ b
| a 1 := succ a
| (bit0 a) (bit0 b) := bit0 (add a b)
| (bit1 a) (bit1 b) := bit0 (succ (add a b))
| (bit0 a) (bit1 b) := bit1 (add a b)
| (bit1 a) (bit0 b) := bit1 (add a b)
instance : has_add pos_num := ⟨pos_num.add⟩
def pred' : pos_num → num
| 1 := 0
| (bit0 n) := num.pos (num.cases_on (pred' n) 1 bit1)
| (bit1 n) := num.pos (bit0 n)
def pred (a : pos_num) : pos_num :=
num.cases_on (pred' a) 1 id
def size : pos_num → pos_num
| 1 := 1
| (bit0 n) := succ (size n)
| (bit1 n) := succ (size n)
def nat_size : pos_num → nat
| 1 := 1
| (bit0 n) := nat.succ (nat_size n)
| (bit1 n) := nat.succ (nat_size n)
protected def mul (a : pos_num) : pos_num → pos_num
| 1 := a
| (bit0 b) := bit0 (mul b)
| (bit1 b) := bit0 (mul b) + a
instance : has_mul pos_num := ⟨pos_num.mul⟩
def of_nat_succ : ℕ → pos_num
| 0 := 1
| (nat.succ n) := succ (of_nat_succ n)
def of_nat (n : ℕ) : pos_num := of_nat_succ (nat.pred n)
open ordering
def cmp : pos_num → pos_num → ordering
| 1 1 := eq
| _ 1 := gt
| 1 _ := lt
| (bit0 a) (bit0 b) := cmp a b
| (bit0 a) (bit1 b) := ordering.cases_on (cmp a b) lt lt gt
| (bit1 a) (bit0 b) := ordering.cases_on (cmp a b) lt gt gt
| (bit1 a) (bit1 b) := cmp a b
instance : has_lt pos_num := ⟨λa b, cmp a b = ordering.lt⟩
instance : has_le pos_num := ⟨λa b, ¬ b < a⟩
instance decidable_lt : @decidable_rel pos_num (<)
| a b := by dsimp [(<)]; apply_instance
instance decidable_le : @decidable_rel pos_num (≤)
| a b := by dsimp [(≤)]; apply_instance
end pos_num
section
variables {α : Type*} [has_zero α] [has_one α] [has_add α]
def cast_pos_num : pos_num → α
| 1 := 1
| (pos_num.bit0 a) := bit0 (cast_pos_num a)
| (pos_num.bit1 a) := bit1 (cast_pos_num a)
def cast_num : num → α
| 0 := 0
| (num.pos p) := cast_pos_num p
@[priority 0] instance pos_num_coe : has_coe pos_num α := ⟨cast_pos_num⟩
@[priority 0] instance num_nat_coe : has_coe num α := ⟨cast_num⟩
instance : has_repr pos_num := ⟨λ n, repr (n : ℕ)⟩
instance : has_repr num := ⟨λ n, repr (n : ℕ)⟩
end
namespace num
open pos_num
def succ' : num → pos_num
| 0 := 1
| (pos p) := succ p
def succ (n : num) : num := pos (succ' n)
protected def add : num → num → num
| 0 a := a
| b 0 := b
| (pos a) (pos b) := pos (a + b)
instance : has_add num := ⟨num.add⟩
protected def bit0 : num → num
| 0 := 0
| (pos n) := pos (pos_num.bit0 n)
protected def bit1 : num → num
| 0 := 1
| (pos n) := pos (pos_num.bit1 n)
def bit (b : bool) : num → num := cond b num.bit1 num.bit0
def size : num → num
| 0 := 0
| (pos n) := pos (pos_num.size n)
def nat_size : num → nat
| 0 := 0
| (pos n) := pos_num.nat_size n
protected def mul : num → num → num
| 0 _ := 0
| _ 0 := 0
| (pos a) (pos b) := pos (a * b)
instance : has_mul num := ⟨num.mul⟩
open ordering
def cmp : num → num → ordering
| 0 0 := eq
| _ 0 := gt
| 0 _ := lt
| (pos a) (pos b) := pos_num.cmp a b
instance : has_lt num := ⟨λa b, cmp a b = ordering.lt⟩
instance : has_le num := ⟨λa b, ¬ b < a⟩
instance decidable_lt : @decidable_rel num (<)
| a b := by dsimp [(<)]; apply_instance
instance decidable_le : @decidable_rel num (≤)
| a b := by dsimp [(≤)]; apply_instance
def to_znum : num → znum
| 0 := 0
| (pos a) := znum.pos a
def to_znum_neg : num → znum
| 0 := 0
| (pos a) := znum.neg a
def of_nat' : ℕ → num :=
nat.binary_rec 0 (λ b n, cond b num.bit1 num.bit0)
end num
namespace znum
open pos_num
def zneg : znum → znum
| 0 := 0
| (pos a) := neg a
| (neg a) := pos a
instance : has_neg znum := ⟨zneg⟩
def abs : znum → num
| 0 := 0
| (pos a) := num.pos a
| (neg a) := num.pos a
def succ : znum → znum
| 0 := 1
| (pos a) := pos (pos_num.succ a)
| (neg a) := (pos_num.pred' a).to_znum_neg
def pred : znum → znum
| 0 := neg 1
| (pos a) := (pos_num.pred' a).to_znum
| (neg a) := neg (pos_num.succ a)
protected def bit0 : znum → znum
| 0 := 0
| (pos n) := pos (pos_num.bit0 n)
| (neg n) := neg (pos_num.bit0 n)
protected def bit1 : znum → znum
| 0 := 1
| (pos n) := pos (pos_num.bit1 n)
| (neg n) := neg (num.cases_on (pred' n) 1 pos_num.bit1)
protected def bitm1 : znum → znum
| 0 := neg 1
| (pos n) := pos (num.cases_on (pred' n) 1 pos_num.bit1)
| (neg n) := neg (pos_num.bit1 n)
def of_int' : ℤ → znum
| (n : ℕ) := num.to_znum (num.of_nat' n)
| -[1+ n] := num.to_znum_neg (num.of_nat' (n+1))
end znum
namespace pos_num
open znum
def sub' : pos_num → pos_num → znum
| a 1 := (pred' a).to_znum
| 1 b := (pred' b).to_znum_neg
| (bit0 a) (bit0 b) := (sub' a b).bit0
| (bit0 a) (bit1 b) := (sub' a b).bitm1
| (bit1 a) (bit0 b) := (sub' a b).bit1
| (bit1 a) (bit1 b) := (sub' a b).bit0
def of_znum' : znum → option pos_num
| (znum.pos p) := some p
| _ := none
def of_znum : znum → pos_num
| (znum.pos p) := p
| _ := 1
protected def sub (a b : pos_num) : pos_num :=
match sub' a b with
| (znum.pos p) := p
| _ := 1
end
instance : has_sub pos_num := ⟨pos_num.sub⟩
end pos_num
namespace num
def ppred : num → option num
| 0 := none
| (pos p) := some p.pred'
def pred : num → num
| 0 := 0
| (pos p) := p.pred'
def div2 : num → num
| 0 := 0
| 1 := 0
| (pos (pos_num.bit0 p)) := pos p
| (pos (pos_num.bit1 p)) := pos p
def of_znum' : znum → option num
| 0 := some 0
| (znum.pos p) := some (pos p)
| (znum.neg p) := none
def of_znum : znum → num
| (znum.pos p) := pos p
| _ := 0
def sub' : num → num → znum
| 0 0 := 0
| (pos a) 0 := znum.pos a
| 0 (pos b) := znum.neg b
| (pos a) (pos b) := a.sub' b
def psub (a b : num) : option num :=
of_znum' (sub' a b)
protected def sub (a b : num) : num :=
of_znum (sub' a b)
instance : has_sub num := ⟨num.sub⟩
end num
namespace znum
open pos_num
protected def add : znum → znum → znum
| 0 a := a
| b 0 := b
| (pos a) (pos b) := pos (a + b)
| (pos a) (neg b) := sub' a b
| (neg a) (pos b) := sub' b a
| (neg a) (neg b) := neg (a + b)
instance : has_add znum := ⟨znum.add⟩
protected def mul : znum → znum → znum
| 0 a := 0
| b 0 := 0
| (pos a) (pos b) := pos (a * b)
| (pos a) (neg b) := neg (a * b)
| (neg a) (pos b) := neg (a * b)
| (neg a) (neg b) := pos (a * b)
instance : has_mul znum := ⟨znum.mul⟩
open ordering
def cmp : znum → znum → ordering
| 0 0 := eq
| (pos a) (pos b) := pos_num.cmp a b
| (neg a) (neg b) := pos_num.cmp b a
| (pos _) _ := gt
| (neg _) _ := lt
| _ (pos _) := lt
| _ (neg _) := gt
instance : has_lt znum := ⟨λa b, cmp a b = ordering.lt⟩
instance : has_le znum := ⟨λa b, ¬ b < a⟩
instance decidable_lt : @decidable_rel znum (<)
| a b := by dsimp [(<)]; apply_instance
instance decidable_le : @decidable_rel znum (≤)
| a b := by dsimp [(≤)]; apply_instance
end znum
namespace pos_num
def divmod_aux (d : pos_num) (q r : num) : num × num :=
match num.of_znum' (num.sub' r (num.pos d)) with
| some r' := (num.bit1 q, r')
| none := (num.bit0 q, r)
end
def divmod (d : pos_num) : pos_num → num × num
| (bit0 n) := let (q, r₁) := divmod n in
divmod_aux d q (num.bit0 r₁)
| (bit1 n) := let (q, r₁) := divmod n in
divmod_aux d q (num.bit1 r₁)
| 1 := divmod_aux d 0 1
def div' (n d : pos_num) : num := (divmod d n).1
def mod' (n d : pos_num) : num := (divmod d n).2
def sqrt_aux1 (b : pos_num) (r n : num) : num × num :=
match num.of_znum' (n.sub' (r + num.pos b)) with
| some n' := (r.div2 + num.pos b, n')
| none := (r.div2, n)
end
def sqrt_aux : pos_num → num → num → num
| b@(bit0 b') r n := let (r', n') := sqrt_aux1 b r n in sqrt_aux b' r' n'
| b@(bit1 b') r n := let (r', n') := sqrt_aux1 b r n in sqrt_aux b' r' n'
| 1 r n := (sqrt_aux1 1 r n).1
/-
def sqrt_aux : ℕ → ℕ → ℕ → ℕ
| b r n := if b0 : b = 0 then r else
let b' := shiftr b 2 in
have b' < b, from sqrt_aux_dec b0,
match (n - (r + b : ℕ) : ℤ) with
| (n' : ℕ) := sqrt_aux b' (div2 r + b) n'
| _ := sqrt_aux b' (div2 r) n
end
/-- `sqrt n` is the square root of a natural number `n`. If `n` is not a
perfect square, it returns the largest `k:ℕ` such that `k*k ≤ n`. -/
def sqrt (n : ℕ) : ℕ :=
match size n with
| 0 := 0
| succ s := sqrt_aux (shiftl 1 (bit0 (div2 s))) 0 n
end
-/
end pos_num
namespace num
def div : num → num → num
| 0 _ := 0
| _ 0 := 0
| (pos n) (pos d) := pos_num.div' n d
def mod : num → num → num
| 0 _ := 0
| n 0 := n
| (pos n) (pos d) := pos_num.mod' n d
instance : has_div num := ⟨num.div⟩
instance : has_mod num := ⟨num.mod⟩
def gcd_aux : nat → num → num → num
| 0 a b := b
| (nat.succ n) 0 b := b
| (nat.succ n) a b := gcd_aux n (b % a) a
def gcd (a b : num) : num :=
if a ≤ b then
gcd_aux (a.nat_size + b.nat_size) a b
else
gcd_aux (b.nat_size + a.nat_size) b a
end num
namespace znum
def div : znum → znum → znum
| 0 _ := 0
| _ 0 := 0
| (pos n) (pos d) := num.to_znum (pos_num.div' n d)
| (pos n) (neg d) := num.to_znum_neg (pos_num.div' n d)
| (neg n) (pos d) := neg (pos_num.pred' n / num.pos d).succ'
| (neg n) (neg d) := pos (pos_num.pred' n / num.pos d).succ'
def mod : znum → znum → znum
| 0 d := 0
| (pos n) d := num.to_znum (num.pos n % d.abs)
| (neg n) d := d.abs.sub' (pos_num.pred' n % d.abs).succ
instance : has_div znum := ⟨znum.div⟩
instance : has_mod znum := ⟨znum.mod⟩
def gcd (a b : znum) : num := a.abs.gcd b.abs
end znum
section
variables {α : Type*} [has_zero α] [has_one α] [has_add α] [has_neg α]
def cast_znum : znum → α
| 0 := 0
| (znum.pos p) := p
| (znum.neg p) := -p
@[priority 0] instance znum_coe : has_coe znum α := ⟨cast_znum⟩
instance : has_repr znum := ⟨λ n, repr (n : ℤ)⟩
end
/- The snum representation uses a bit string, essentially a list of 0 (ff) and 1 (tt) bits,
and the negation of the MSB is sign-extended to all higher bits. -/
namespace nzsnum
notation a :: b := bit a b
def sign : nzsnum → bool
| (msb b) := bnot b
| (b :: p) := sign p
@[pattern] def not : nzsnum → nzsnum
| (msb b) := msb (bnot b)
| (b :: p) := bnot b :: not p
prefix ~ := not
def bit0 : nzsnum → nzsnum := bit ff
def bit1 : nzsnum → nzsnum := bit tt
def head : nzsnum → bool
| (msb b) := b
| (b :: p) := b
def tail : nzsnum → snum
| (msb b) := snum.zero (bnot b)
| (b :: p) := p
end nzsnum
namespace snum
open nzsnum
def sign : snum → bool
| (zero z) := z
| (nz p) := p.sign
@[pattern] def not : snum → snum
| (zero z) := zero (bnot z)
| (nz p) := ~p
prefix ~ := not
@[pattern] def bit : bool → snum → snum
| b (zero z) := if b = z then zero b else msb b
| b (nz p) := p.bit b
notation a :: b := bit a b
def bit0 : snum → snum := bit ff
def bit1 : snum → snum := bit tt
theorem bit_zero (b) : b :: zero b = zero b := by cases b; refl
theorem bit_one (b) : b :: zero (bnot b) = msb b := by cases b; refl
end snum
namespace nzsnum
open snum
def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))
(s : Π b p, C p → C (b :: p)) : Π p : nzsnum, C p
| (msb b) := by rw ←bit_one; exact s b (snum.zero (bnot b)) (z (bnot b))
| (bit b p) := s b p (drec' p)
end nzsnum
namespace snum
open nzsnum
def head : snum → bool
| (zero z) := z
| (nz p) := p.head
def tail : snum → snum
| (zero z) := zero z
| (nz p) := p.tail
def drec' {C : snum → Sort*} (z : Π b, C (snum.zero b))
(s : Π b p, C p → C (b :: p)) : Π p, C p
| (zero b) := z b
| (nz p) := p.drec' z s
def rec' {α} (z : bool → α) (s : bool → snum → α → α) : snum → α :=
drec' z s
def bits : snum → Π n, vector bool n
| p 0 := vector.nil
| p (n+1) := head p :: bits (tail p) n
def test_bit : nat → snum → bool
| 0 p := head p
| (n+1) p := test_bit n (tail p)
def succ : snum → snum :=
rec' (λ b, cond b 0 1) (λb p succp, cond b (ff :: succp) (tt :: p))
def pred : snum → snum :=
rec' (λ b, cond b (~1) ~0) (λb p predp, cond b (ff :: p) (tt :: predp))
protected def neg (n : snum) : snum := succ ~n
instance : has_neg snum := ⟨snum.neg⟩
-- First bit is 0 or 1 (tt), second bit is 0 or -1 (tt)
def czadd : bool → bool → snum → snum
| ff ff p := p
| ff tt p := pred p
| tt ff p := succ p
| tt tt p := p
def cadd : snum → snum → bool → snum :=
rec' (λ a p c, czadd c a p) $ λa p IH,
rec' (λb c, czadd c b (a :: p)) $ λb q _ c,
bitvec.xor3 a b c :: IH q (bitvec.carry a b c)
protected def add (a b : snum) : snum := cadd a b ff
instance : has_add snum := ⟨snum.add⟩
protected def sub (a b : snum) : snum := a + -b
instance : has_sub snum := ⟨snum.sub⟩
protected def mul (a : snum) : snum → snum :=
rec' (λ b, cond b (-a) 0) $ λb q IH,
cond b (bit0 IH + a) (bit0 IH)
instance : has_mul snum := ⟨snum.mul⟩
end snum
namespace int
def of_snum : snum → ℤ :=
snum.rec' (λ a, cond a (-1) 0) (λa p IH, cond a (bit1 IH) (bit0 IH))
instance snum_coe : has_coe snum ℤ := ⟨of_snum⟩
end int
instance : has_lt snum := ⟨λa b, (a : ℤ) < b⟩
instance : has_le snum := ⟨λa b, (a : ℤ) ≤ b⟩
|
6f86780171d81abc72842e7547bbe2925d3b7fac | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/array1.lean | 4e98c3c25cf838f0ea675f2ce423b489e66b307b | [
"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 | 2,254 | lean | #check @Array.mk
def v : Array Nat := Array.mk [1, 2, 3, 4]
def w : Array Nat :=
(mkArray 9 1).push 3
#check @Array.casesOn
def f : Fin w.size → Nat :=
w.get
def arraySum (a : Array Nat) : Nat :=
a.foldl Nat.add 0
#eval mkArray 4 1
#eval Array.map (fun x => x+10) v
#eval f ⟨1, sorry⟩
#eval f ⟨9, sorry⟩
#eval (((mkArray 1 1).push 2).push 3).foldl (fun x y => x + y) 0
#eval arraySum (mkArray 10 1)
axiom axLt {a b : Nat} : a < b
#eval #[1, 2, 3].insertAt 0 10
#eval #[1, 2, 3].insertAt 1 10
#eval #[1, 2, 3].insertAt 2 10
#eval #[1, 2, 3].insertAt 3 10
#eval #[].insertAt 0 10
def tst1 : IO Unit :=
#[1, 2, 3, 4].forRevM IO.println
#eval tst1
#eval #[1, 2].extract 0 1
#eval #[1, 2].extract 0 0
#eval #[1, 2].extract 0 2
#eval #[1, 2, 3, 4].filterMap fun x => if x % 2 == 0 then some (x + 10) else none
def tst : IO (List Nat) :=
[1, 2, 3, 4].filterMapM fun x => do
IO.println x;
(if x % 2 == 0 then pure $ some (x + 10) else pure none)
#eval tst
#eval #[1, 3, 6, 2].getMax? (fun a b => a < b)
#eval #[].getMax? (fun (a b : Nat) => a < b)
#eval #[1, 8].getMax? (fun a b => a < b)
#eval #[8, 1].getMax? (fun a b => a < b)
#eval #[1, 6, 5, 3, 8, 2, 0].partition fun x => x % 2 == 0
def check (b : Bool) : IO Unit :=
unless b do throw $ IO.userError "check failed"
#eval check $ #[].isPrefixOf #[2, 3]
#eval check $ (#[] : Array Nat).isPrefixOf #[]
#eval check $ #[2, 3].isPrefixOf #[2, 3]
#eval check $ #[2, 3].isPrefixOf #[2, 3, 4, 5]
#eval check $ ! #[2, 4].isPrefixOf #[2, 3]
#eval check $ ! #[2, 3, 4].isPrefixOf #[2, 3]
#eval check $ ! #[2].isPrefixOf #[]
#eval check $ ! #[4, 3].isPrefixOf #[2, 3, 4, 5]
#eval check $ #[1, 2, 3].allDiff
#eval check $ !#[1, 2, 1, 3].allDiff
#eval check $ #[1, 2, 4, 3].allDiff
#eval check $ (#[] : Array Nat).allDiff
#eval check $ !#[1, 1].allDiff
#eval check $ !#[1, 2, 3, 4, 5, 1].allDiff
#eval check $ #[1, 2, 3, 4, 5].allDiff
#eval check $ !#[1, 2, 3, 4, 5, 5].allDiff
#eval check $ !#[1, 3, 3, 4, 5].allDiff
#eval check $ !#[1, 2, 3, 4, 5, 3].allDiff
#eval check $ !#[1, 2, 3, 4, 5, 4].allDiff
#eval check $ #[1, 2, 3, 4, 5, 6].allDiff
#eval check $ Array.zip #[1, 2] #[3, 4, 6] == #[(1, 3), (2, 4)]
theorem ex1 (a b c : Nat) : #[a, b].push c = #[a, 0, c].set! 1 b :=
rfl
|
895e63a40cde6d0e4c8cf8c0ec7e43dca7aadbd9 | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /library/standard/logic/connectives/function.lean | b245ec02351977bbf7c24ce9f2fc7e0228287994 | [
"Apache-2.0"
] | permissive | codyroux/lean | 7f8dff750722c5382bdd0a9a9275dc4bb2c58dd3 | 0cca265db19f7296531e339192e9b9bae4a31f8b | refs/heads/master | 1,610,909,964,159 | 1,407,084,399,000 | 1,416,857,075,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,628 | 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
namespace function
section
parameters {A : Type} {B : Type} {C : Type} {D : Type} {E : Type}
abbreviation compose (f : B → C) (g : A → B) : A → C :=
λx, f (g x)
abbreviation id (a : A) : A :=
a
abbreviation on_fun (f : B → B → C) (g : A → B) : A → A → C :=
λx y, f (g x) (g y)
abbreviation combine (f : A → B → C) (op : C → D → E) (g : A → B → D) : A → B → E :=
λx y, op (f x y) (g x y)
end
abbreviation const {A : Type} (B : Type) (a : A) : B → A :=
λx, a
abbreviation dcompose {A : Type} {B : A → Type} {C : Π {x : A}, B x → Type} (f : Π {x : A} (y : B x), C y) (g : Πx, B x) : Πx, C (g x) :=
λx, f (g x)
abbreviation flip {A : Type} {B : Type} {C : A → B → Type} (f : Πx y, C x y) : Πy x, C x y :=
λy x, f x y
abbreviation app {A : Type} {B : A → Type} (f : Πx, B x) (x : A) : B x :=
f x
-- Yet another trick to anotate an expression with a type
abbreviation is_typeof (A : Type) (a : A) : A :=
a
precedence `∘`:60
precedence `∘'`:60
precedence `on`:1
precedence `$`:1
precedence `-[`:1
precedence `]-`:1
precedence `⟨`:1
infixr ∘ := compose
infixr ∘' := dcompose
infixl on := on_fun
notation `typeof` t `:` T := is_typeof T t
infixr $ := app
notation f `-[` op `]-` g := combine f op g
-- Trick for using any binary function as infix operator
notation a `⟨` f `⟩` b := f a b
end
|
7414b1f0dd05f343293e54aa0896b576070355b1 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/baseIO.lean | 0c6f1284eba5b77d943b88ede5a2fce55568bbcd | [
"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 | 120 | lean | set_option trace.Compiler.saveBase true
def test : BaseIO UInt32 := do
let ref ← IO.mkRef 42
ref.set 10
ref.get
|
6e7fdf0ccb3d6ea9825b0ac2080ac446948d90b4 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/analytic/basic.lean | ce82b42524bcdfb15568d9773aa5d2f9a1eb8382 | [
"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 | 66,451 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.calculus.formal_multilinear_series
import analysis.specific_limits.normed
import logic.equiv.fin
import topology.algebra.infinite_sum.module
/-!
# Analytic functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ℝ≥0∞` such that `‖p n‖ * r^n` grows subexponentially.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_is_O`: if `‖p n‖ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.is_o_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.is_o_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`‖p n‖ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_is_O`: if `r ≠ 0` and `‖p n‖ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partial_sum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `has_fpower_series_on_ball f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `has_fpower_series_at f p x`: on some ball of center `x` with positive radius, holds
`has_fpower_series_on_ball f p x r`.
* `analytic_at 𝕜 f x`: there exists a power series `p` such that holds
`has_fpower_series_at f p x`.
* `analytic_on 𝕜 f s`: the function `f` is analytic at every point of `s`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`has_fpower_series_on_ball.continuous_on` and `has_fpower_series_at.continuous_at` and
`analytic_at.continuous_at`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `formal_multilinear_series.has_fpower_series_on_ball`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.change_origin y`. See `has_fpower_series_on_ball.change_origin`. It follows in particular that
the set of points at which a given function is analytic is open, see `is_open_analytic_at`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable theory
variables {𝕜 E F G : Type*}
open_locale topology classical big_operators nnreal filter ennreal
open set filter asymptotics
namespace formal_multilinear_series
variables [ring 𝕜] [add_comm_group E] [add_comm_group F] [module 𝕜 E] [module 𝕜 F]
variables [topological_space E] [topological_space F]
variables [topological_add_group E] [topological_add_group F]
variables [has_continuous_const_smul 𝕜 E] [has_continuous_const_smul 𝕜 F]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `‖x‖ < p.radius`. -/
protected def sum (p : formal_multilinear_series 𝕜 E F) (x : E) : F := ∑' n : ℕ , p n (λ i, x)
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partial_sum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partial_sum (p : formal_multilinear_series 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k in finset.range n, p k (λ(i : fin k), x)
/-- The partial sums of a formal multilinear series are continuous. -/
lemma partial_sum_continuous (p : formal_multilinear_series 𝕜 E F) (n : ℕ) :
continuous (p.partial_sum n) :=
by continuity
end formal_multilinear_series
/-! ### The radius of a formal multilinear series -/
variables [nontrivially_normed_field 𝕜]
[normed_add_comm_group E] [normed_space 𝕜 E]
[normed_add_comm_group F] [normed_space 𝕜 F]
[normed_add_comm_group G] [normed_space 𝕜 G]
namespace formal_multilinear_series
variables (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ ‖pₙ‖ ‖y‖ⁿ`
converges for all `‖y‖ < r`. This implies that `Σ pₙ yⁿ` converges for all `‖y‖ < r`, but these
definitions are *not* equivalent in general. -/
def radius (p : formal_multilinear_series 𝕜 E F) : ℝ≥0∞ :=
⨆ (r : ℝ≥0) (C : ℝ) (hr : ∀ n, ‖p n‖ * r ^ n ≤ C), (r : ℝ≥0∞)
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound (C : ℝ) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
le_supr_of_le r $ le_supr_of_le C $ (le_supr (λ _, (r : ℝ≥0∞)) h)
/-- If `‖pₙ‖ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound_nnreal (C : ℝ≥0) {r : ℝ≥0} (h : ∀ (n : ℕ), ‖p n‖₊ * r^n ≤ C) :
(r : ℝ≥0∞) ≤ p.radius :=
p.le_radius_of_bound C $ λ n, by exact_mod_cast (h n)
/-- If `‖pₙ‖ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_is_O (h : (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : ↑r ≤ p.radius :=
exists.elim (is_O_one_nat_at_top_iff.1 h) $ λ C hC, p.le_radius_of_bound C $
λ n, (le_abs_self _).trans (hC n)
lemma le_radius_of_eventually_le (C) (h : ∀ᶠ n in at_top, ‖p n‖ * r ^ n ≤ C) : ↑r ≤ p.radius :=
p.le_radius_of_is_O $ is_O.of_bound C $ h.mono $ λ n hn, by simpa
lemma le_radius_of_summable_nnnorm (h : summable (λ n, ‖p n‖₊ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_bound_nnreal (∑' n, ‖p n‖₊ * r ^ n) $ λ n, le_tsum' h _
lemma le_radius_of_summable (h : summable (λ n, ‖p n‖ * r ^ n)) : ↑r ≤ p.radius :=
p.le_radius_of_summable_nnnorm $ by { simp only [← coe_nnnorm] at h, exact_mod_cast h }
lemma radius_eq_top_of_forall_nnreal_is_O
(h : ∀ r : ℝ≥0, (λ n, ‖p n‖ * r^n) =O[at_top] (λ n, (1 : ℝ))) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le $ λ r, p.le_radius_of_is_O (h r)
lemma radius_eq_top_of_eventually_eq_zero (h : ∀ᶠ n in at_top, p n = 0) : p.radius = ∞ :=
p.radius_eq_top_of_forall_nnreal_is_O $
λ r, (is_O_zero _ _).congr' (h.mono $ λ n hn, by simp [hn]) eventually_eq.rfl
lemma radius_eq_top_of_forall_image_add_eq_zero (n : ℕ) (hn : ∀ m, p (m + n) = 0) : p.radius = ∞ :=
p.radius_eq_top_of_eventually_eq_zero $ mem_at_top_sets.2
⟨n, λ k hk, tsub_add_cancel_of_le hk ▸ hn _⟩
@[simp] lemma const_formal_multilinear_series_radius {v : F} :
(const_formal_multilinear_series 𝕜 E v).radius = ⊤ :=
(const_formal_multilinear_series 𝕜 E v).radius_eq_top_of_forall_image_add_eq_zero 1
(by simp [const_formal_multilinear_series])
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `‖p n‖ rⁿ = o(aⁿ)`. -/
lemma is_o_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, (λ n, ‖p n‖ * r ^ n) =o[at_top] (pow a) :=
begin
rw (tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 4,
simp only [radius, lt_supr_iff] at h,
rcases h with ⟨t, C, hC, rt⟩,
rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at rt,
have : 0 < (t : ℝ), from r.coe_nonneg.trans_lt rt,
rw [← div_lt_one this] at rt,
refine ⟨_, rt, C, or.inr zero_lt_one, λ n, _⟩,
calc |‖p n‖ * r ^ n| = (‖p n‖ * t ^ n) * (r / t) ^ n :
by field_simp [mul_right_comm, abs_mul, this.ne']
... ≤ C * (r / t) ^ n : mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (div_nonneg r.2 t.2) _)
end
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ = o(1)`. -/
lemma is_o_one_of_lt_radius (h : ↑r < p.radius) :
(λ n, ‖p n‖ * r ^ n) =o[at_top] (λ _, 1 : ℕ → ℝ) :=
let ⟨a, ha, hp⟩ := p.is_o_of_lt_radius h in
hp.trans $ (is_o_pow_pow_of_lt_left ha.1.le ha.2).congr (λ n, rfl) one_pow
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `‖p n‖ * r ^ n ≤ C * a ^ n`. -/
lemma norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r^n ≤ C * a^n :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 1 5).mp (p.is_o_of_lt_radius h)
with ⟨a, ha, C, hC, H⟩,
exact ⟨a, ha, C, hC, λ n, (le_abs_self _).trans (H n)⟩
end
/-- If `r ≠ 0` and `‖pₙ‖ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
lemma lt_radius_of_is_O (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : (λ n, ‖p n‖ * r ^ n) =O[at_top] (pow a)) :
↑r < p.radius :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ‖p n‖ * r ^ n) 1).out 2 5).mp ⟨a, ha, hp⟩
with ⟨a, ha, C, hC, hp⟩,
rw [← pos_iff_ne_zero, ← nnreal.coe_pos] at h₀,
lift a to ℝ≥0 using ha.1.le,
have : (r : ℝ) < r / a :=
by simpa only [div_one] using (div_lt_div_left h₀ zero_lt_one ha.1).2 ha.2,
norm_cast at this,
rw [← ennreal.coe_lt_coe] at this,
refine this.trans_le (p.le_radius_of_bound C $ λ n, _),
rw [nnreal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)],
exact (le_abs_self _).trans (hp n)
end
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma norm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ * r^n ≤ C :=
let ⟨a, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
in ⟨C, hC, λ n, (h n).trans $ mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma norm_le_div_pow_of_pos_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h0 : 0 < r) (h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖ ≤ C / r ^ n :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h in
⟨C, hC, λ n, iff.mpr (le_div_iff (pow_pos h0 _)) (hp n)⟩
/-- For `r` strictly smaller than the radius of `p`, then `‖pₙ‖ rⁿ` is bounded. -/
lemma nnnorm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ℝ≥0∞) < p.radius) : ∃ C > 0, ∀ n, ‖p n‖₊ * r^n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
in ⟨⟨C, hC.lt.le⟩, hC, by exact_mod_cast hp⟩
lemma le_radius_of_tendsto (p : formal_multilinear_series 𝕜 E F) {l : ℝ}
(h : tendsto (λ n, ‖p n‖ * r^n) at_top (𝓝 l)) : ↑r ≤ p.radius :=
p.le_radius_of_is_O (h.is_O_one _)
lemma le_radius_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : summable (λ n, ‖p n‖ * r^n)) : ↑r ≤ p.radius :=
p.le_radius_of_tendsto hs.tendsto_at_top_zero
lemma not_summable_norm_of_radius_lt_nnnorm (p : formal_multilinear_series 𝕜 E F) {x : E}
(h : p.radius < ‖x‖₊) : ¬ summable (λ n, ‖p n‖ * ‖x‖^n) :=
λ hs, not_le_of_lt h (p.le_radius_of_summable_norm hs)
lemma summable_norm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ‖p n‖ * r ^ n) :=
begin
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h,
exact summable_of_nonneg_of_le (λ n, mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg _)) hp
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _),
end
lemma summable_norm_apply (p : formal_multilinear_series 𝕜 E F)
{x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, ‖p n (λ _, x)‖) :=
begin
rw mem_emetric_ball_zero_iff at hx,
refine summable_of_nonneg_of_le (λ _, norm_nonneg _) (λ n, ((p n).le_op_norm _).trans_eq _)
(p.summable_norm_mul_pow hx),
simp
end
lemma summable_nnnorm_mul_pow (p : formal_multilinear_series 𝕜 E F)
{r : ℝ≥0} (h : ↑r < p.radius) :
summable (λ n : ℕ, ‖p n‖₊ * r ^ n) :=
by { rw ← nnreal.summable_coe, push_cast, exact p.summable_norm_mul_pow h }
protected lemma summable [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
summable (λ n : ℕ, p n (λ _, x)) :=
summable_of_summable_norm (p.summable_norm_apply hx)
lemma radius_eq_top_of_summable_norm (p : formal_multilinear_series 𝕜 E F)
(hs : ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n)) : p.radius = ∞ :=
ennreal.eq_top_of_forall_nnreal_le (λ r, p.le_radius_of_summable_norm (hs r))
lemma radius_eq_top_iff_summable_norm (p : formal_multilinear_series 𝕜 E F) :
p.radius = ∞ ↔ ∀ r : ℝ≥0, summable (λ n, ‖p n‖ * r^n) :=
begin
split,
{ intros h r,
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ :=
p.norm_mul_pow_le_mul_pow_of_lt_radius
(show (r:ℝ≥0∞) < p.radius, from h.symm ▸ ennreal.coe_lt_top),
refine (summable_of_norm_bounded (λ n, (C : ℝ) * a ^ n)
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _) (λ n, _)),
specialize hp n,
rwa real.norm_of_nonneg (mul_nonneg (norm_nonneg _) (pow_nonneg r.coe_nonneg n)) },
{ exact p.radius_eq_top_of_summable_norm }
end
/-- If the radius of `p` is positive, then `‖pₙ‖` grows at most geometrically. -/
lemma le_mul_pow_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
∃ C r (hC : 0 < C) (hr : 0 < r), ∀ n, ‖p n‖ ≤ C * r ^ n :=
begin
rcases ennreal.lt_iff_exists_nnreal_btwn.1 h with ⟨r, r0, rlt⟩,
have rpos : 0 < (r : ℝ), by simp [ennreal.coe_pos.1 r0],
rcases norm_le_div_pow_of_pos_of_lt_radius p rpos rlt with ⟨C, Cpos, hCp⟩,
refine ⟨C, r ⁻¹, Cpos, by simp [rpos], λ n, _⟩,
convert hCp n,
exact inv_pow _ _,
end
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
lemma min_radius_le_radius_add (p q : formal_multilinear_series 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
rw lt_min_iff at hr,
have := ((p.is_o_one_of_lt_radius hr.1).add (q.is_o_one_of_lt_radius hr.2)).is_O,
refine (p + q).le_radius_of_is_O ((is_O_of_le _ $ λ n, _).trans this),
rw [← add_mul, norm_mul, norm_mul, norm_norm],
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
end
@[simp] lemma radius_neg (p : formal_multilinear_series 𝕜 E F) : (-p).radius = p.radius :=
by simp [radius]
protected lemma has_sum [complete_space F]
(p : formal_multilinear_series 𝕜 E F) {x : E} (hx : x ∈ emetric.ball (0 : E) p.radius) :
has_sum (λ n : ℕ, p n (λ _, x)) (p.sum x) :=
(p.summable hx).has_sum
lemma radius_le_radius_continuous_linear_map_comp
(p : formal_multilinear_series 𝕜 E F) (f : F →L[𝕜] G) :
p.radius ≤ (f.comp_formal_multilinear_series p).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
apply le_radius_of_is_O,
apply (is_O.trans_is_o _ (p.is_o_one_of_lt_radius hr)).is_O,
refine is_O.mul (@is_O_with.is_O _ _ _ _ _ (‖f‖) _ _ _ _) (is_O_refl _ _),
apply is_O_with.of_bound (eventually_of_forall (λ n, _)),
simpa only [norm_norm] using f.norm_comp_continuous_multilinear_map_le (p n)
end
end formal_multilinear_series
/-! ### Expanding a function as a power series -/
section
variables {f g : E → F} {p pf pg : formal_multilinear_series 𝕜 E F} {x : E} {r r' : ℝ≥0∞}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `‖y‖ < r`.
-/
structure has_fpower_series_on_ball
(f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) (r : ℝ≥0∞) : Prop :=
(r_le : r ≤ p.radius)
(r_pos : 0 < r)
(has_sum : ∀ {y}, y ∈ emetric.ball (0 : E) r → has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)))
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def has_fpower_series_at (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) :=
∃ r, has_fpower_series_on_ball f p x r
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def analytic_at (f : E → F) (x : E) :=
∃ (p : formal_multilinear_series 𝕜 E F), has_fpower_series_at f p x
/-- Given a function `f : E → F`, we say that `f` is analytic on a set `s` if it is analytic around
every point of `s`. -/
def analytic_on (f : E → F) (s : set E) :=
∀ x, x ∈ s → analytic_at 𝕜 f x
variable {𝕜}
lemma has_fpower_series_on_ball.has_fpower_series_at (hf : has_fpower_series_on_ball f p x r) :
has_fpower_series_at f p x := ⟨r, hf⟩
lemma has_fpower_series_at.analytic_at (hf : has_fpower_series_at f p x) : analytic_at 𝕜 f x :=
⟨p, hf⟩
lemma has_fpower_series_on_ball.analytic_at (hf : has_fpower_series_on_ball f p x r) :
analytic_at 𝕜 f x :=
hf.has_fpower_series_at.analytic_at
lemma has_fpower_series_on_ball.congr (hf : has_fpower_series_on_ball f p x r)
(hg : eq_on f g (emetric.ball x r)) :
has_fpower_series_on_ball g p x r :=
{ r_le := hf.r_le,
r_pos := hf.r_pos,
has_sum := λ y hy,
begin
convert hf.has_sum hy,
apply hg.symm,
simpa [edist_eq_coe_nnnorm_sub] using hy,
end }
/-- If a function `f` has a power series `p` around `x`, then the function `z ↦ f (z - y)` has the
same power series around `x + y`. -/
lemma has_fpower_series_on_ball.comp_sub (hf : has_fpower_series_on_ball f p x r) (y : E) :
has_fpower_series_on_ball (λ z, f (z - y)) p (x + y) r :=
{ r_le := hf.r_le,
r_pos := hf.r_pos,
has_sum := λ z hz, by { convert hf.has_sum hz, abel } }
lemma has_fpower_series_on_ball.has_sum_sub (hf : has_fpower_series_on_ball f p x r) {y : E}
(hy : y ∈ emetric.ball x r) :
has_sum (λ n : ℕ, p n (λ i, y - x)) (f y) :=
have y - x ∈ emetric.ball (0 : E) r, by simpa [edist_eq_coe_nnnorm_sub] using hy,
by simpa only [add_sub_cancel'_right] using hf.has_sum this
lemma has_fpower_series_on_ball.radius_pos (hf : has_fpower_series_on_ball f p x r) :
0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
lemma has_fpower_series_at.radius_pos (hf : has_fpower_series_at f p x) :
0 < p.radius :=
let ⟨r, hr⟩ := hf in hr.radius_pos
lemma has_fpower_series_on_ball.mono
(hf : has_fpower_series_on_ball f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) :
has_fpower_series_on_ball f p x r' :=
⟨le_trans hr hf.1, r'_pos, λ y hy, hf.has_sum (emetric.ball_subset_ball hr hy)⟩
lemma has_fpower_series_at.congr (hf : has_fpower_series_at f p x) (hg : f =ᶠ[𝓝 x] g) :
has_fpower_series_at g p x :=
begin
rcases hf with ⟨r₁, h₁⟩,
rcases emetric.mem_nhds_iff.mp hg with ⟨r₂, h₂pos, h₂⟩,
exact ⟨min r₁ r₂, (h₁.mono (lt_min h₁.r_pos h₂pos) inf_le_left).congr
(λ y hy, h₂ (emetric.ball_subset_ball inf_le_right hy))⟩
end
protected lemma has_fpower_series_at.eventually (hf : has_fpower_series_at f p x) :
∀ᶠ r : ℝ≥0∞ in 𝓝[>] 0, has_fpower_series_on_ball f p x r :=
let ⟨r, hr⟩ := hf in
mem_of_superset (Ioo_mem_nhds_within_Ioi (left_mem_Ico.2 hr.r_pos)) $
λ r' hr', hr.mono hr'.1 hr'.2.le
lemma has_fpower_series_on_ball.eventually_has_sum (hf : has_fpower_series_on_ball f p x r) :
∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) :=
by filter_upwards [emetric.ball_mem_nhds (0 : E) hf.r_pos] using λ _, hf.has_sum
lemma has_fpower_series_at.eventually_has_sum (hf : has_fpower_series_at f p x) :
∀ᶠ y in 𝓝 0, has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)) :=
let ⟨r, hr⟩ := hf in hr.eventually_has_sum
lemma has_fpower_series_on_ball.eventually_has_sum_sub (hf : has_fpower_series_on_ball f p x r) :
∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) :=
by filter_upwards [emetric.ball_mem_nhds x hf.r_pos] with y using hf.has_sum_sub
lemma has_fpower_series_at.eventually_has_sum_sub (hf : has_fpower_series_at f p x) :
∀ᶠ y in 𝓝 x, has_sum (λn:ℕ, p n (λ(i : fin n), y - x)) (f y) :=
let ⟨r, hr⟩ := hf in hr.eventually_has_sum_sub
lemma has_fpower_series_on_ball.eventually_eq_zero
(hf : has_fpower_series_on_ball f (0 : formal_multilinear_series 𝕜 E F) x r) :
∀ᶠ z in 𝓝 x, f z = 0 :=
by filter_upwards [hf.eventually_has_sum_sub] with z hz using hz.unique has_sum_zero
lemma has_fpower_series_at.eventually_eq_zero
(hf : has_fpower_series_at f (0 : formal_multilinear_series 𝕜 E F) x) :
∀ᶠ z in 𝓝 x, f z = 0 :=
let ⟨r, hr⟩ := hf in hr.eventually_eq_zero
lemma has_fpower_series_on_ball_const {c : F} {e : E} :
has_fpower_series_on_ball (λ _, c) (const_formal_multilinear_series 𝕜 E c) e ⊤ :=
begin
refine ⟨by simp, with_top.zero_lt_top, λ y hy, has_sum_single 0 (λ n hn, _)⟩,
simp [const_formal_multilinear_series_apply hn]
end
lemma has_fpower_series_at_const {c : F} {e : E} :
has_fpower_series_at (λ _, c) (const_formal_multilinear_series 𝕜 E c) e :=
⟨⊤, has_fpower_series_on_ball_const⟩
lemma analytic_at_const {v : F} : analytic_at 𝕜 (λ _, v) x :=
⟨const_formal_multilinear_series 𝕜 E v, has_fpower_series_at_const⟩
lemma analytic_on_const {v : F} {s : set E} : analytic_on 𝕜 (λ _, v) s :=
λ z _, analytic_at_const
lemma has_fpower_series_on_ball.add
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg),
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).add (hg.has_sum hy) }
lemma has_fpower_series_at.add
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f + g) (pf + pg) x :=
begin
rcases (hf.eventually.and hg.eventually).exists with ⟨r, hr⟩,
exact ⟨r, hr.1.add hr.2⟩
end
lemma analytic_at.add (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f + g) x :=
let ⟨pf, hpf⟩ := hf, ⟨qf, hqf⟩ := hg in (hpf.add hqf).analytic_at
lemma has_fpower_series_on_ball.neg (hf : has_fpower_series_on_ball f pf x r) :
has_fpower_series_on_ball (-f) (-pf) x r :=
{ r_le := by { rw pf.radius_neg, exact hf.r_le },
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).neg }
lemma has_fpower_series_at.neg
(hf : has_fpower_series_at f pf x) : has_fpower_series_at (-f) (-pf) x :=
let ⟨rf, hrf⟩ := hf in hrf.neg.has_fpower_series_at
lemma analytic_at.neg (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (-f) x :=
let ⟨pf, hpf⟩ := hf in hpf.neg.analytic_at
lemma has_fpower_series_on_ball.sub
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f - g) (pf - pg) x r :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_at.sub
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f - g) (pf - pg) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_at.sub (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f - g) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_on.mono {s t : set E} (hf : analytic_on 𝕜 f t) (hst : s ⊆ t) :
analytic_on 𝕜 f s :=
λ z hz, hf z (hst hz)
lemma analytic_on.add {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) :
analytic_on 𝕜 (f + g) s :=
λ z hz, (hf z hz).add (hg z hz)
lemma analytic_on.sub {s : set E} (hf : analytic_on 𝕜 f s) (hg : analytic_on 𝕜 g s) :
analytic_on 𝕜 (f - g) s :=
λ z hz, (hf z hz).sub (hg z hz)
lemma has_fpower_series_on_ball.coeff_zero (hf : has_fpower_series_on_ball f pf x r)
(v : fin 0 → E) : pf 0 v = f x :=
begin
have v_eq : v = (λ i, 0) := subsingleton.elim _ _,
have zero_mem : (0 : E) ∈ emetric.ball (0 : E) r, by simp [hf.r_pos],
have : ∀ i ≠ 0, pf i (λ j, 0) = 0,
{ assume i hi,
have : 0 < i := pos_iff_ne_zero.2 hi,
exact continuous_multilinear_map.map_coord_zero _ (⟨0, this⟩ : fin i) rfl },
have A := (hf.has_sum zero_mem).unique (has_sum_single _ this),
simpa [v_eq] using A.symm,
end
lemma has_fpower_series_at.coeff_zero (hf : has_fpower_series_at f pf x) (v : fin 0 → E) :
pf 0 v = f x :=
let ⟨rf, hrf⟩ := hf in hrf.coeff_zero v
/-- If a function `f` has a power series `p` on a ball and `g` is linear, then `g ∘ f` has the
power series `g ∘ p` on the same ball. -/
lemma _root_.continuous_linear_map.comp_has_fpower_series_on_ball
(g : F →L[𝕜] G) (h : has_fpower_series_on_ball f p x r) :
has_fpower_series_on_ball (g ∘ f) (g.comp_formal_multilinear_series p) x r :=
{ r_le := h.r_le.trans (p.radius_le_radius_continuous_linear_map_comp _),
r_pos := h.r_pos,
has_sum := λ y hy, by simpa only [continuous_linear_map.comp_formal_multilinear_series_apply,
continuous_linear_map.comp_continuous_multilinear_map_coe, function.comp_app]
using g.has_sum (h.has_sum hy) }
/-- If a function `f` is analytic on a set `s` and `g` is linear, then `g ∘ f` is analytic
on `s`. -/
lemma _root_.continuous_linear_map.comp_analytic_on {s : set E}
(g : F →L[𝕜] G) (h : analytic_on 𝕜 f s) :
analytic_on 𝕜 (g ∘ f) s :=
begin
rintros x hx,
rcases h x hx with ⟨p, r, hp⟩,
exact ⟨g.comp_formal_multilinear_series p, r, g.comp_has_fpower_series_on_ball hp⟩,
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `‖y‖` and `n`. See also
`has_fpower_series_on_ball.uniform_geometric_approx` for a weaker version. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ‖p n‖ * r' ^n ≤ C * a^n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le),
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), λ y hy n, _⟩,
have yr' : ‖y‖ < r', by { rw ball_zero_eq at hy, exact hy },
have hr'0 : 0 < (r' : ℝ), from (norm_nonneg _).trans_lt yr',
have : y ∈ emetric.ball (0 : E) r,
{ refine mem_emetric_ball_zero_iff.2 (lt_trans _ h),
exact_mod_cast yr' },
rw [norm_sub_rev, ← mul_div_right_comm],
have ya : a * (‖y‖ / ↑r') ≤ a,
from mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg),
suffices : ‖p.partial_sum n y - f (x + y)‖ ≤ C * (a * (‖y‖ / r')) ^ n / (1 - a * (‖y‖ / r')),
{ refine this.trans _,
apply_rules [div_le_div_of_le_left, sub_pos.2, div_nonneg, mul_nonneg, pow_nonneg, hC.lt.le,
ha.1.le, norm_nonneg, nnreal.coe_nonneg, ha.2, (sub_le_sub_iff_left _).2]; apply_instance },
apply norm_sub_le_of_geometric_bound_of_has_sum (ya.trans_lt ha.2) _ (hf.has_sum this),
assume n,
calc ‖(p n) (λ (i : fin n), y)‖ ≤ ‖p n‖ * (∏ i : fin n, ‖y‖) :
continuous_multilinear_map.le_op_norm _ _
... = (‖p n‖ * r' ^ n) * (‖y‖ / r') ^ n : by field_simp [hr'0.ne', mul_right_comm]
... ≤ (C * a ^ n) * (‖y‖ / r') ^ n :
mul_le_mul_of_nonneg_right (hp n) (pow_nonneg (div_nonneg (norm_nonneg _) r'.coe_nonneg) _)
... ≤ C * (a * (‖y‖ / r')) ^ n : by rw [mul_pow, mul_assoc]
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine ⟨a, ha, C, hC, λ y hy n, (hp y hy n).trans _⟩,
have yr' : ‖y‖ < r', by rwa ball_zero_eq at hy,
refine mul_le_mul_of_nonneg_left (pow_le_pow_of_le_left _ _ _) hC.lt.le,
exacts [mul_nonneg ha.1.le (div_nonneg (norm_nonneg y) r'.coe_nonneg),
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)]
end
/-- Taylor formula for an analytic function, `is_O` version. -/
lemma has_fpower_series_at.is_O_sub_partial_sum_pow (hf : has_fpower_series_at f p x) (n : ℕ) :
(λ y : E, f (x + y) - p.partial_sum n y) =O[𝓝 0] (λ y, ‖y‖ ^ n) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * (a * (‖y‖ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine is_O_iff.2 ⟨C * (a / r') ^ n, _⟩,
replace r'0 : 0 < (r' : ℝ), by exact_mod_cast r'0,
filter_upwards [metric.ball_mem_nhds (0 : E) r'0] with y hy,
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n,
end
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. This lemma formulates this property using `is_O` and
`filter.principal` on `E × E`. -/
lemma has_fpower_series_on_ball.is_O_image_sub_image_sub_deriv_principal
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
(λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓟 (emetric.ball (x, x) r')]
(λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) :=
begin
lift r' to ℝ≥0 using ne_top_of_lt hr,
rcases (zero_le r').eq_or_lt with rfl|hr'0,
{ simp only [is_O_bot, emetric.ball_zero, principal_empty, ennreal.coe_zero] },
obtain ⟨a, ha, C, hC : 0 < C, hp⟩ :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ (n : ℕ), ‖p n‖ * ↑r' ^ n ≤ C * a ^ n,
from p.norm_mul_pow_le_mul_pow_of_lt_radius (hr.trans_le hf.r_le),
simp only [← le_div_iff (pow_pos (nnreal.coe_pos.2 hr'0) _)] at hp,
set L : E × E → ℝ := λ y,
(C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * (a / (1 - a) ^ 2 + 2 / (1 - a)),
have hL : ∀ y ∈ emetric.ball (x, x) r',
‖f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))‖ ≤ L y,
{ intros y hy',
have hy : y ∈ emetric.ball x r ×ˢ emetric.ball x r,
{ rw [emetric.ball_prod_same], exact emetric.ball_subset_ball hr.le hy' },
set A : ℕ → F := λ n, p n (λ _, y.1 - x) - p n (λ _, y.2 - x),
have hA : has_sum (λ n, A (n + 2)) (f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))),
{ convert (has_sum_nat_add_iff' 2).2 ((hf.has_sum_sub hy.1).sub (hf.has_sum_sub hy.2)) using 1,
rw [finset.sum_range_succ, finset.sum_range_one, hf.coeff_zero, hf.coeff_zero, sub_self,
zero_add, ← subsingleton.pi_single_eq (0 : fin 1) (y.1 - x), pi.single,
← subsingleton.pi_single_eq (0 : fin 1) (y.2 - x), pi.single, ← (p 1).map_sub, ← pi.single,
subsingleton.pi_single_eq, sub_sub_sub_cancel_right] },
rw [emetric.mem_ball, edist_eq_coe_nnnorm_sub, ennreal.coe_lt_coe] at hy',
set B : ℕ → ℝ := λ n,
(C * (a / r') ^ 2) * (‖y - (x, x)‖ * ‖y.1 - y.2‖) * ((n + 2) * a ^ n),
have hAB : ∀ n, ‖A (n + 2)‖ ≤ B n := λ n,
calc ‖A (n + 2)‖ ≤ ‖p (n + 2)‖ * ↑(n + 2) * ‖y - (x, x)‖ ^ (n + 1) * ‖y.1 - y.2‖ :
by simpa only [fintype.card_fin, pi_norm_const (_ : E), prod.norm_def, pi.sub_def,
prod.fst_sub, prod.snd_sub, sub_sub_sub_cancel_right]
using (p $ n + 2).norm_image_sub_le (λ _, y.1 - x) (λ _, y.2 - x)
... = ‖p (n + 2)‖ * ‖y - (x, x)‖ ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) :
by { rw [pow_succ ‖y - (x, x)‖], ring }
... ≤ (C * a ^ (n + 2) / r' ^ (n + 2)) * r' ^ n * (↑(n + 2) * ‖y - (x, x)‖ * ‖y.1 - y.2‖) :
by apply_rules [mul_le_mul_of_nonneg_right, mul_le_mul, hp, pow_le_pow_of_le_left,
hy'.le, norm_nonneg, pow_nonneg, div_nonneg, mul_nonneg, nat.cast_nonneg,
hC.le, r'.coe_nonneg, ha.1.le]
... = B n :
by { field_simp [B, pow_succ, hr'0.ne'], simp only [mul_assoc, mul_comm, mul_left_comm] },
have hBL : has_sum B (L y),
{ apply has_sum.mul_left,
simp only [add_mul],
have : ‖a‖ < 1, by simp only [real.norm_eq_abs, abs_of_pos ha.1, ha.2],
convert (has_sum_coe_mul_geometric_of_norm_lt_1 this).add
((has_sum_geometric_of_norm_lt_1 this).mul_left 2) },
exact hA.norm_le_of_bounded hBL hAB },
suffices : L =O[𝓟 (emetric.ball (x, x) r')] (λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖),
{ refine (is_O.of_bound 1 (eventually_principal.2 $ λ y hy, _)).trans this,
rw one_mul,
exact (hL y hy).trans (le_abs_self _) },
simp_rw [L, mul_right_comm _ (_ * _)],
exact (is_O_refl _ _).const_mul_left _,
end
/-- If `f` has formal power series `∑ n, pₙ` on a ball of radius `r`, then for `y, z` in any smaller
ball, the norm of the difference `f y - f z - p 1 (λ _, y - z)` is bounded above by
`C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖`. -/
lemma has_fpower_series_on_ball.image_sub_sub_deriv_le
(hf : has_fpower_series_on_ball f p x r) (hr : r' < r) :
∃ C, ∀ (y z ∈ emetric.ball x r'),
‖f y - f z - (p 1 (λ _, y - z))‖ ≤ C * (max ‖y - x‖ ‖z - x‖) * ‖y - z‖ :=
by simpa only [is_O_principal, mul_assoc, norm_mul, norm_norm, prod.forall,
emetric.mem_ball, prod.edist_eq, max_lt_iff, and_imp, @forall_swap (_ < _) E]
using hf.is_O_image_sub_image_sub_deriv_principal hr
/-- If `f` has formal power series `∑ n, pₙ` at `x`, then
`f y - f z - p 1 (λ _, y - z) = O(‖(y, z) - (x, x)‖ * ‖y - z‖)` as `(y, z) → (x, x)`.
In particular, `f` is strictly differentiable at `x`. -/
lemma has_fpower_series_at.is_O_image_sub_norm_mul_norm_sub (hf : has_fpower_series_at f p x) :
(λ y : E × E, f y.1 - f y.2 - (p 1 (λ _, y.1 - y.2))) =O[𝓝 (x, x)]
(λ y, ‖y - (x, x)‖ * ‖y.1 - y.2‖) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
refine (hf.is_O_image_sub_image_sub_deriv_principal h).mono _,
exact le_principal_iff.2 (emetric.ball_mem_nhds _ r'0)
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n y)
(λ y, f (x + y)) at_top (metric.ball (0 : E) r') :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ‖f (x + y) - p.partial_sum n y‖ ≤ C * a ^ n),
from hf.uniform_geometric_approx h,
refine metric.tendsto_uniformly_on_iff.2 (λ ε εpos, _),
have L : tendsto (λ n, (C : ℝ) * a^n) at_top (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_at_top_nhds_0_of_lt_1 ha.1.le ha.2),
rw mul_zero at L,
refine (L.eventually (gt_mem_nhds εpos)).mono (λ n hn y hy, _),
rw dist_eq_norm,
exact (hp y hy n).trans_lt hn
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y))
at_top (emetric.ball (0 : E) r) :=
begin
assume u hu x hx,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩,
have : emetric.ball (0 : E) r' ∈ 𝓝 x :=
is_open.mem_nhds emetric.is_open_ball xr',
refine ⟨emetric.ball (0 : E) r', mem_nhds_within_of_mem_nhds this, _⟩,
simpa [metric.emetric_ball_nnreal] using hf.tendsto_uniformly_on hr' u hu
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ℝ≥0∞) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (metric.ball (x : E) r') :=
begin
convert (hf.tendsto_uniformly_on h).comp (λ y, y - x),
{ simp [(∘)] },
{ ext z, simp [dist_eq_norm] }
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on'
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (emetric.ball (x : E) r) :=
begin
have A : continuous_on (λ (y : E), y - x) (emetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuous_on,
convert (hf.tendsto_locally_uniformly_on).comp (λ (y : E), y - x) _ A,
{ ext z, simp },
{ assume z, simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] }
end
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
protected lemma has_fpower_series_on_ball.continuous_on
(hf : has_fpower_series_on_ball f p x r) : continuous_on f (emetric.ball x r) :=
hf.tendsto_locally_uniformly_on'.continuous_on $ eventually_of_forall $ λ n,
((p.partial_sum_continuous n).comp (continuous_id.sub continuous_const)).continuous_on
protected lemma has_fpower_series_at.continuous_at (hf : has_fpower_series_at f p x) :
continuous_at f x :=
let ⟨r, hr⟩ := hf in hr.continuous_on.continuous_at (emetric.ball_mem_nhds x (hr.r_pos))
protected lemma analytic_at.continuous_at (hf : analytic_at 𝕜 f x) : continuous_at f x :=
let ⟨p, hp⟩ := hf in hp.continuous_at
protected lemma analytic_on.continuous_on {s : set E} (hf : analytic_on 𝕜 f s) :
continuous_on f s :=
λ x hx, (hf x hx).continuous_at.continuous_within_at
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
protected lemma formal_multilinear_series.has_fpower_series_on_ball [complete_space F]
(p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
has_fpower_series_on_ball p.sum p 0 p.radius :=
{ r_le := le_rfl,
r_pos := h,
has_sum := λ y hy, by { rw zero_add, exact p.has_sum hy } }
lemma has_fpower_series_on_ball.sum (h : has_fpower_series_on_ball f p x r)
{y : E} (hy : y ∈ emetric.ball (0 : E) r) : f (x + y) = p.sum y :=
(h.has_sum hy).tsum_eq.symm
/-- The sum of a converging power series is continuous in its disk of convergence. -/
protected lemma formal_multilinear_series.continuous_on [complete_space F] :
continuous_on p.sum (emetric.ball 0 p.radius) :=
begin
cases (zero_le p.radius).eq_or_lt with h h,
{ simp [← h, continuous_on_empty] },
{ exact (p.has_fpower_series_on_ball h).continuous_on }
end
end
/-!
### Uniqueness of power series
If a function `f : E → F` has two representations as power series at a point `x : E`, corresponding
to formal multilinear series `p₁` and `p₂`, then these representations agree term-by-term. That is,
for any `n : ℕ` and `y : E`, `p₁ n (λ i, y) = p₂ n (λ i, y)`. In the one-dimensional case, when
`f : 𝕜 → E`, the continuous multilinear maps `p₁ n` and `p₂ n` are given by
`formal_multilinear_series.mk_pi_field`, and hence are determined completely by the value of
`p₁ n (λ i, 1)`, so `p₁ = p₂`. Consequently, the radius of convergence for one series can be
transferred to the other.
-/
section uniqueness
open continuous_multilinear_map
lemma asymptotics.is_O.continuous_multilinear_map_apply_eq_zero {n : ℕ} {p : E [×n]→L[𝕜] F}
(h : (λ y, p (λ i, y)) =O[𝓝 0] (λ y, ‖y‖ ^ (n + 1))) (y : E) :
p (λ i, y) = 0 :=
begin
obtain ⟨c, c_pos, hc⟩ := h.exists_pos,
obtain ⟨t, ht, t_open, z_mem⟩ := eventually_nhds_iff.mp (is_O_with_iff.mp hc),
obtain ⟨δ, δ_pos, δε⟩ := (metric.is_open_iff.mp t_open) 0 z_mem,
clear h hc z_mem,
cases n,
{ exact norm_eq_zero.mp (by simpa only [fin0_apply_norm, norm_eq_zero, norm_zero, zero_pow',
ne.def, nat.one_ne_zero, not_false_iff, mul_zero, norm_le_zero_iff]
using ht 0 (δε (metric.mem_ball_self δ_pos))), },
{ refine or.elim (em (y = 0)) (λ hy, by simpa only [hy] using p.map_zero) (λ hy, _),
replace hy := norm_pos_iff.mpr hy,
refine norm_eq_zero.mp (le_antisymm (le_of_forall_pos_le_add (λ ε ε_pos, _)) (norm_nonneg _)),
have h₀ := mul_pos c_pos (pow_pos hy (n.succ + 1)),
obtain ⟨k, k_pos, k_norm⟩ := normed_field.exists_norm_lt 𝕜
(lt_min (mul_pos δ_pos (inv_pos.mpr hy)) (mul_pos ε_pos (inv_pos.mpr h₀))),
have h₁ : ‖k • y‖ < δ,
{ rw norm_smul,
exact inv_mul_cancel_right₀ hy.ne.symm δ ▸ mul_lt_mul_of_pos_right
(lt_of_lt_of_le k_norm (min_le_left _ _)) hy },
have h₂ := calc
‖p (λ i, k • y)‖ ≤ c * ‖k • y‖ ^ (n.succ + 1)
: by simpa only [norm_pow, norm_norm]
using ht (k • y) (δε (mem_ball_zero_iff.mpr h₁))
... = ‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))
: by { simp only [norm_smul, mul_pow], rw pow_succ, ring },
have h₃ : ‖k‖ * (c * ‖y‖ ^ (n.succ + 1)) < ε, from inv_mul_cancel_right₀ h₀.ne.symm ε ▸
mul_lt_mul_of_pos_right (lt_of_lt_of_le k_norm (min_le_right _ _)) h₀,
calc ‖p (λ i, y)‖ = ‖(k⁻¹) ^ n.succ‖ * ‖p (λ i, k • y)‖
: by simpa only [inv_smul_smul₀ (norm_pos_iff.mp k_pos),
norm_smul, finset.prod_const, finset.card_fin] using
congr_arg norm (p.map_smul_univ (λ (i : fin n.succ), k⁻¹) (λ (i : fin n.succ), k • y))
... ≤ ‖(k⁻¹) ^ n.succ‖ * (‖k‖ ^ n.succ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1))))
: mul_le_mul_of_nonneg_left h₂ (norm_nonneg _)
... = ‖(k⁻¹ * k) ^ n.succ‖ * (‖k‖ * (c * ‖y‖ ^ (n.succ + 1)))
: by { rw ←mul_assoc, simp [norm_mul, mul_pow] }
... ≤ 0 + ε
: by { rw inv_mul_cancel (norm_pos_iff.mp k_pos), simpa using h₃.le }, },
end
/-- If a formal multilinear series `p` represents the zero function at `x : E`, then the
terms `p n (λ i, y)` appearing the in sum are zero for any `n : ℕ`, `y : E`. -/
lemma has_fpower_series_at.apply_eq_zero {p : formal_multilinear_series 𝕜 E F} {x : E}
(h : has_fpower_series_at 0 p x) (n : ℕ) :
∀ y : E, p n (λ i, y) = 0 :=
begin
refine nat.strong_rec_on n (λ k hk, _),
have psum_eq : p.partial_sum (k + 1) = (λ y, p k (λ i, y)),
{ funext z,
refine finset.sum_eq_single _ (λ b hb hnb, _) (λ hn, _),
{ have := finset.mem_range_succ_iff.mp hb,
simp only [hk b (this.lt_of_ne hnb), pi.zero_apply, zero_apply] },
{ exact false.elim (hn (finset.mem_range.mpr (lt_add_one k))) } },
replace h := h.is_O_sub_partial_sum_pow k.succ,
simp only [psum_eq, zero_sub, pi.zero_apply, asymptotics.is_O_neg_left] at h,
exact h.continuous_multilinear_map_apply_eq_zero,
end
/-- A one-dimensional formal multilinear series representing the zero function is zero. -/
lemma has_fpower_series_at.eq_zero {p : formal_multilinear_series 𝕜 𝕜 E} {x : 𝕜}
(h : has_fpower_series_at 0 p x) : p = 0 :=
by { ext n x, rw ←mk_pi_field_apply_one_eq_self (p n), simp [h.apply_eq_zero n 1] }
/-- One-dimensional formal multilinear series representing the same function are equal. -/
theorem has_fpower_series_at.eq_formal_multilinear_series
{p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {x : 𝕜}
(h₁ : has_fpower_series_at f p₁ x) (h₂ : has_fpower_series_at f p₂ x) :
p₁ = p₂ :=
sub_eq_zero.mp (has_fpower_series_at.eq_zero (by simpa only [sub_self] using h₁.sub h₂))
lemma has_fpower_series_at.eq_formal_multilinear_series_of_eventually
{p q : formal_multilinear_series 𝕜 𝕜 E} {f g : 𝕜 → E} {x : 𝕜} (hp : has_fpower_series_at f p x)
(hq : has_fpower_series_at g q x) (heq : ∀ᶠ z in 𝓝 x, f z = g z) :
p = q :=
(hp.congr heq).eq_formal_multilinear_series hq
/-- A one-dimensional formal multilinear series representing a locally zero function is zero. -/
lemma has_fpower_series_at.eq_zero_of_eventually {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E}
{x : 𝕜} (hp : has_fpower_series_at f p x) (hf : f =ᶠ[𝓝 x] 0) : p = 0 :=
(hp.congr hf).eq_zero
/-- If a function `f : 𝕜 → E` has two power series representations at `x`, then the given radii in
which convergence is guaranteed may be interchanged. This can be useful when the formal multilinear
series in one representation has a particularly nice form, but the other has a larger radius. -/
theorem has_fpower_series_on_ball.exchange_radius
{p₁ p₂ : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {r₁ r₂ : ℝ≥0∞} {x : 𝕜}
(h₁ : has_fpower_series_on_ball f p₁ x r₁) (h₂ : has_fpower_series_on_ball f p₂ x r₂) :
has_fpower_series_on_ball f p₁ x r₂ :=
h₂.has_fpower_series_at.eq_formal_multilinear_series h₁.has_fpower_series_at ▸ h₂
/-- If a function `f : 𝕜 → E` has power series representation `p` on a ball of some radius and for
each positive radius it has some power series representation, then `p` converges to `f` on the whole
`𝕜`. -/
theorem has_fpower_series_on_ball.r_eq_top_of_exists {f : 𝕜 → E} {r : ℝ≥0∞} {x : 𝕜}
{p : formal_multilinear_series 𝕜 𝕜 E} (h : has_fpower_series_on_ball f p x r)
(h' : ∀ (r' : ℝ≥0) (hr : 0 < r'),
∃ p' : formal_multilinear_series 𝕜 𝕜 E, has_fpower_series_on_ball f p' x r') :
has_fpower_series_on_ball f p x ∞ :=
{ r_le := ennreal.le_of_forall_pos_nnreal_lt $ λ r hr hr',
let ⟨p', hp'⟩ := h' r hr in (h.exchange_radius hp').r_le,
r_pos := ennreal.coe_lt_top,
has_sum := λ y hy, let ⟨r', hr'⟩ := exists_gt ‖y‖₊, ⟨p', hp'⟩ := h' r' hr'.ne_bot.bot_lt
in (h.exchange_radius hp').has_sum $ mem_emetric_ball_zero_iff.mpr (ennreal.coe_lt_coe.2 hr') }
end uniqueness
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `fin n` of cardinal `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.change_origin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace formal_multilinear_series
section
variables (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
/-- A term of `formal_multilinear_series.change_origin_series`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Each term of `p.change_origin x`
is itself an analytic function of `x` given by the series `p.change_origin_series`. Each term in
`change_origin_series` is the sum of `change_origin_series_term`'s over all `s` of cardinality `l`.
The definition is such that
`p.change_origin_series_term k l s hs (λ _, x) (λ _, y) = p (k + l) (s.piecewise (λ _, x) (λ _, y))`
-/
def change_origin_series_term (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l) :
E [×l]→L[𝕜] E [×k]→L[𝕜] F :=
continuous_multilinear_map.curry_fin_finset 𝕜 E F hs
(by erw [finset.card_compl, fintype.card_fin, hs, add_tsub_cancel_right]) (p $ k + l)
lemma change_origin_series_term_apply (k l : ℕ) (s : finset (fin (k + l))) (hs : s.card = l)
(x y : E) :
p.change_origin_series_term k l s hs (λ _, x) (λ _, y) =
p (k + l) (s.piecewise (λ _, x) (λ _, y)) :=
continuous_multilinear_map.curry_fin_finset_apply_const _ _ _ _ _
@[simp] lemma norm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
‖p.change_origin_series_term k l s hs‖ = ‖p (k + l)‖ :=
by simp only [change_origin_series_term, linear_isometry_equiv.norm_map]
@[simp] lemma nnnorm_change_origin_series_term (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) :
‖p.change_origin_series_term k l s hs‖₊ = ‖p (k + l)‖₊ :=
by simp only [change_origin_series_term, linear_isometry_equiv.nnnorm_map]
lemma nnnorm_change_origin_series_term_apply_le (k l : ℕ) (s : finset (fin (k + l)))
(hs : s.card = l) (x y : E) :
‖p.change_origin_series_term k l s hs (λ _, x) (λ _, y)‖₊ ≤ ‖p (k + l)‖₊ * ‖x‖₊ ^ l * ‖y‖₊ ^ k :=
begin
rw [← p.nnnorm_change_origin_series_term k l s hs, ← fin.prod_const, ← fin.prod_const],
apply continuous_multilinear_map.le_of_op_nnnorm_le,
apply continuous_multilinear_map.le_op_nnnorm
end
/-- The power series for `f.change_origin k`.
Given a formal multilinear series `p` and a point `x` in its ball of convergence,
`p.change_origin x` is a formal multilinear series such that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense. Its `k`-th term is the sum of
the series `p.change_origin_series k`. -/
def change_origin_series (k : ℕ) : formal_multilinear_series 𝕜 E (E [×k]→L[𝕜] F) :=
λ l, ∑ s : {s : finset (fin (k + l)) // finset.card s = l}, p.change_origin_series_term k l s s.2
lemma nnnorm_change_origin_series_le_tsum (k l : ℕ) :
‖p.change_origin_series k l‖₊ ≤
∑' (x : {s : finset (fin (k + l)) // s.card = l}), ‖p (k + l)‖₊ :=
(nnnorm_sum_le _ _).trans_eq $ by simp only [tsum_fintype, nnnorm_change_origin_series_term]
lemma nnnorm_change_origin_series_apply_le_tsum (k l : ℕ) (x : E) :
‖p.change_origin_series k l (λ _, x)‖₊ ≤
∑' s : {s : finset (fin (k + l)) // s.card = l}, ‖p (k + l)‖₊ * ‖x‖₊ ^ l :=
begin
rw [nnreal.tsum_mul_right, ← fin.prod_const],
exact (p.change_origin_series k l).le_of_op_nnnorm_le _
(p.nnnorm_change_origin_series_le_tsum _ _)
end
/--
Changing the origin of a formal multilinear series `p`, so that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense.
-/
def change_origin (x : E) : formal_multilinear_series 𝕜 E F :=
λ k, (p.change_origin_series k).sum x
/-- An auxiliary equivalence useful in the proofs about
`formal_multilinear_series.change_origin_series`: the set of triples `(k, l, s)`, where `s` is a
`finset (fin (k + l))` of cardinality `l` is equivalent to the set of pairs `(n, s)`, where `s` is a
`finset (fin n)`.
The forward map sends `(k, l, s)` to `(k + l, s)` and the inverse map sends `(n, s)` to
`(n - finset.card s, finset.card s, s)`. The actual definition is less readable because of problems
with non-definitional equalities. -/
@[simps] def change_origin_index_equiv :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l}) ≃ Σ n : ℕ, finset (fin n) :=
{ to_fun := λ s, ⟨s.1 + s.2.1, s.2.2⟩,
inv_fun := λ s, ⟨s.1 - s.2.card, s.2.card, ⟨s.2.map
(fin.cast $ (tsub_add_cancel_of_le $ card_finset_fin_le s.2).symm).to_equiv.to_embedding,
finset.card_map _⟩⟩,
left_inv :=
begin
rintro ⟨k, l, ⟨s : finset (fin $ k + l), hs : s.card = l⟩⟩,
dsimp only [subtype.coe_mk],
-- Lean can't automatically generalize `k' = k + l - s.card`, `l' = s.card`, so we explicitly
-- formulate the generalized goal
suffices : ∀ k' l', k' = k → l' = l → ∀ (hkl : k + l = k' + l') hs',
(⟨k', l', ⟨finset.map (fin.cast hkl).to_equiv.to_embedding s, hs'⟩⟩ :
(Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l})) = ⟨k, l, ⟨s, hs⟩⟩,
{ apply this; simp only [hs, add_tsub_cancel_right] },
rintro _ _ rfl rfl hkl hs',
simp only [equiv.refl_to_embedding, fin.cast_refl, finset.map_refl, eq_self_iff_true,
order_iso.refl_to_equiv, and_self, heq_iff_eq]
end,
right_inv :=
begin
rintro ⟨n, s⟩,
simp [tsub_add_cancel_of_le (card_finset_fin_le s), fin.cast_to_equiv]
end }
lemma change_origin_series_summable_aux₁ {r r' : ℝ≥0} (hr : (r + r' : ℝ≥0∞) < p.radius) :
summable (λ s : Σ k l : ℕ, {s : finset (fin (k + l)) // s.card = l},
‖p (s.1 + s.2.1)‖₊ * r ^ s.2.1 * r' ^ s.1) :=
begin
rw ← change_origin_index_equiv.symm.summable_iff,
dsimp only [(∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst],
have : ∀ n : ℕ, has_sum
(λ s : finset (fin n), ‖p (n - s.card + s.card)‖₊ * r ^ s.card * r' ^ (n - s.card))
(‖p n‖₊ * (r + r') ^ n),
{ intro n,
-- TODO: why `simp only [tsub_add_cancel_of_le (card_finset_fin_le _)]` fails?
convert_to has_sum (λ s : finset (fin n), ‖p n‖₊ * (r ^ s.card * r' ^ (n - s.card))) _,
{ ext1 s, rw [tsub_add_cancel_of_le (card_finset_fin_le _), mul_assoc] },
rw ← fin.sum_pow_mul_eq_add_pow,
exact (has_sum_fintype _).mul_left _ },
refine nnreal.summable_sigma.2 ⟨λ n, (this n).summable, _⟩,
simp only [(this _).tsum_eq],
exact p.summable_nnnorm_mul_pow hr
end
lemma change_origin_series_summable_aux₂ (hr : (r : ℝ≥0∞) < p.radius) (k : ℕ) :
summable (λ s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * r ^ s.1) :=
begin
rcases ennreal.lt_iff_exists_add_pos_lt.1 hr with ⟨r', h0, hr'⟩,
simpa only [mul_inv_cancel_right₀ (pow_pos h0 _).ne']
using ((nnreal.summable_sigma.1
(p.change_origin_series_summable_aux₁ hr')).1 k).mul_right (r' ^ k)⁻¹
end
lemma change_origin_series_summable_aux₃ {r : ℝ≥0} (hr : ↑r < p.radius) (k : ℕ) :
summable (λ l : ℕ, ‖p.change_origin_series k l‖₊ * r ^ l) :=
begin
refine nnreal.summable_of_le (λ n, _)
(nnreal.summable_sigma.1 $ p.change_origin_series_summable_aux₂ hr k).2,
simp only [nnreal.tsum_mul_right],
exact mul_le_mul' (p.nnnorm_change_origin_series_le_tsum _ _) le_rfl
end
lemma le_change_origin_series_radius (k : ℕ) :
p.radius ≤ (p.change_origin_series k).radius :=
ennreal.le_of_forall_nnreal_lt $ λ r hr,
le_radius_of_summable_nnnorm _ (p.change_origin_series_summable_aux₃ hr k)
lemma nnnorm_change_origin_le (k : ℕ) (h : (‖x‖₊ : ℝ≥0∞) < p.radius) :
‖p.change_origin x k‖₊ ≤
∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1 :=
begin
refine tsum_of_nnnorm_bounded _ (λ l, p.nnnorm_change_origin_series_apply_le_tsum k l x),
have := p.change_origin_series_summable_aux₂ h k,
refine has_sum.sigma this.has_sum (λ l, _),
exact ((nnreal.summable_sigma.1 this).1 l).has_sum
end
/-- The radius of convergence of `p.change_origin x` is at least `p.radius - ‖x‖`. In other words,
`p.change_origin x` is well defined on the largest ball contained in the original ball of
convergence.-/
lemma change_origin_radius : p.radius - ‖x‖₊ ≤ (p.change_origin x).radius :=
begin
refine ennreal.le_of_forall_pos_nnreal_lt (λ r h0 hr, _),
rw [lt_tsub_iff_right, add_comm] at hr,
have hr' : (‖x‖₊ : ℝ≥0∞) < p.radius, from (le_add_right le_rfl).trans_lt hr,
apply le_radius_of_summable_nnnorm,
have : ∀ k : ℕ, ‖p.change_origin x k‖₊ * r ^ k ≤
(∑' s : Σ l : ℕ, {s : finset (fin (k + l)) // s.card = l}, ‖p (k + s.1)‖₊ * ‖x‖₊ ^ s.1) * r ^ k,
from λ k, mul_le_mul_right' (p.nnnorm_change_origin_le k hr') (r ^ k),
refine nnreal.summable_of_le this _,
simpa only [← nnreal.tsum_mul_right]
using (nnreal.summable_sigma.1 (p.change_origin_series_summable_aux₁ hr)).2
end
end
-- From this point on, assume that the space is complete, to make sure that series that converge
-- in norm also converge in `F`.
variables [complete_space F] (p : formal_multilinear_series 𝕜 E F) {x y : E} {r R : ℝ≥0}
lemma has_fpower_series_on_ball_change_origin (k : ℕ) (hr : 0 < p.radius) :
has_fpower_series_on_ball (λ x, p.change_origin x k) (p.change_origin_series k) 0 p.radius :=
have _ := p.le_change_origin_series_radius k,
((p.change_origin_series k).has_fpower_series_on_ball (hr.trans_le this)).mono hr this
/-- Summing the series `p.change_origin x` at a point `y` gives back `p (x + y)`-/
theorem change_origin_eval (h : (‖x‖₊ + ‖y‖₊ : ℝ≥0∞) < p.radius) :
(p.change_origin x).sum y = (p.sum (x + y)) :=
begin
have radius_pos : 0 < p.radius := lt_of_le_of_lt (zero_le _) h,
have x_mem_ball : x ∈ emetric.ball (0 : E) p.radius,
from mem_emetric_ball_zero_iff.2 ((le_add_right le_rfl).trans_lt h),
have y_mem_ball : y ∈ emetric.ball (0 : E) (p.change_origin x).radius,
{ refine mem_emetric_ball_zero_iff.2 (lt_of_lt_of_le _ p.change_origin_radius),
rwa [lt_tsub_iff_right, add_comm] },
have x_add_y_mem_ball : x + y ∈ emetric.ball (0 : E) p.radius,
{ refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ h),
exact_mod_cast nnnorm_add_le x y },
set f : (Σ (k l : ℕ), {s : finset (fin (k + l)) // s.card = l}) → F :=
λ s, p.change_origin_series_term s.1 s.2.1 s.2.2 s.2.2.2 (λ _, x) (λ _, y),
have hsf : summable f,
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₁ h) _,
rintro ⟨k, l, s, hs⟩, dsimp only [subtype.coe_mk],
exact p.nnnorm_change_origin_series_term_apply_le _ _ _ _ _ _ },
have hf : has_sum f ((p.change_origin x).sum y),
{ refine has_sum.sigma_of_has_sum ((p.change_origin x).summable y_mem_ball).has_sum (λ k, _) hsf,
{ dsimp only [f],
refine continuous_multilinear_map.has_sum_eval _ _,
have := (p.has_fpower_series_on_ball_change_origin k radius_pos).has_sum x_mem_ball,
rw zero_add at this,
refine has_sum.sigma_of_has_sum this (λ l, _) _,
{ simp only [change_origin_series, continuous_multilinear_map.sum_apply],
apply has_sum_fintype },
{ refine summable_of_nnnorm_bounded _ (p.change_origin_series_summable_aux₂
(mem_emetric_ball_zero_iff.1 x_mem_ball) k) (λ s, _),
refine (continuous_multilinear_map.le_op_nnnorm _ _).trans_eq _,
simp } } },
refine hf.unique (change_origin_index_equiv.symm.has_sum_iff.1 _),
refine has_sum.sigma_of_has_sum (p.has_sum x_add_y_mem_ball) (λ n, _)
(change_origin_index_equiv.symm.summable_iff.2 hsf),
erw [(p n).map_add_univ (λ _, x) (λ _, y)],
convert has_sum_fintype _,
ext1 s,
dsimp only [f, change_origin_series_term, (∘), change_origin_index_equiv_symm_apply_fst,
change_origin_index_equiv_symm_apply_snd_fst, change_origin_index_equiv_symm_apply_snd_snd_coe],
rw continuous_multilinear_map.curry_fin_finset_apply_const,
have : ∀ m (hm : n = m), p n (s.piecewise (λ _, x) (λ _, y)) =
p m ((s.map (fin.cast hm).to_equiv.to_embedding).piecewise (λ _, x) (λ _, y)),
{ rintro m rfl, simp },
apply this
end
end formal_multilinear_series
section
variables [complete_space F] {f : E → F} {p : formal_multilinear_series 𝕜 E F} {x y : E}
{r : ℝ≥0∞}
/-- If a function admits a power series expansion `p` on a ball `B (x, r)`, then it also admits a
power series on any subball of this ball (even with a different center), given by `p.change_origin`.
-/
theorem has_fpower_series_on_ball.change_origin
(hf : has_fpower_series_on_ball f p x r) (h : (‖y‖₊ : ℝ≥0∞) < r) :
has_fpower_series_on_ball f (p.change_origin y) (x + y) (r - ‖y‖₊) :=
{ r_le := begin
apply le_trans _ p.change_origin_radius,
exact tsub_le_tsub hf.r_le le_rfl
end,
r_pos := by simp [h],
has_sum := λ z hz, begin
convert (p.change_origin y).has_sum _,
{ rw [mem_emetric_ball_zero_iff, lt_tsub_iff_right, add_comm] at hz,
rw [p.change_origin_eval (hz.trans_le hf.r_le), add_assoc, hf.sum],
refine mem_emetric_ball_zero_iff.2 (lt_of_le_of_lt _ hz),
exact_mod_cast nnnorm_add_le y z },
{ refine emetric.ball_subset_ball (le_trans _ p.change_origin_radius) hz,
exact tsub_le_tsub hf.r_le le_rfl }
end }
/-- If a function admits a power series expansion `p` on an open ball `B (x, r)`, then
it is analytic at every point of this ball. -/
lemma has_fpower_series_on_ball.analytic_at_of_mem
(hf : has_fpower_series_on_ball f p x r) (h : y ∈ emetric.ball x r) :
analytic_at 𝕜 f y :=
begin
have : (‖y - x‖₊ : ℝ≥0∞) < r, by simpa [edist_eq_coe_nnnorm_sub] using h,
have := hf.change_origin this,
rw [add_sub_cancel'_right] at this,
exact this.analytic_at
end
lemma has_fpower_series_on_ball.analytic_on (hf : has_fpower_series_on_ball f p x r) :
analytic_on 𝕜 f (emetric.ball x r) :=
λ y hy, hf.analytic_at_of_mem hy
variables (𝕜 f)
/-- For any function `f` from a normed vector space to a Banach space, the set of points `x` such
that `f` is analytic at `x` is open. -/
lemma is_open_analytic_at : is_open {x | analytic_at 𝕜 f x} :=
begin
rw is_open_iff_mem_nhds,
rintro x ⟨p, r, hr⟩,
exact mem_of_superset (emetric.ball_mem_nhds _ hr.r_pos) (λ y hy, hr.analytic_at_of_mem hy)
end
end
section
open formal_multilinear_series
variables {p : formal_multilinear_series 𝕜 𝕜 E} {f : 𝕜 → E} {z₀ : 𝕜}
/-- A function `f : 𝕜 → E` has `p` as power series expansion at a point `z₀` iff it is the sum of
`p` in a neighborhood of `z₀`. This makes some proofs easier by hiding the fact that
`has_fpower_series_at` depends on `p.radius`. -/
lemma has_fpower_series_at_iff : has_fpower_series_at f p z₀ ↔
∀ᶠ z in 𝓝 0, has_sum (λ n, z ^ n • p.coeff n) (f (z₀ + z)) :=
begin
refine ⟨λ ⟨r, r_le, r_pos, h⟩, eventually_of_mem (emetric.ball_mem_nhds 0 r_pos)
(λ _, by simpa using h), _⟩,
simp only [metric.eventually_nhds_iff],
rintro ⟨r, r_pos, h⟩,
refine ⟨p.radius ⊓ r.to_nnreal, by simp, _, _⟩,
{ simp only [r_pos.lt, lt_inf_iff, ennreal.coe_pos, real.to_nnreal_pos, and_true],
obtain ⟨z, z_pos, le_z⟩ := normed_field.exists_norm_lt 𝕜 r_pos.lt,
have : (‖z‖₊ : ennreal) ≤ p.radius,
by { simp only [dist_zero_right] at h,
apply formal_multilinear_series.le_radius_of_tendsto,
convert tendsto_norm.comp (h le_z).summable.tendsto_at_top_zero,
funext; simp [norm_smul, mul_comm] },
refine lt_of_lt_of_le _ this,
simp only [ennreal.coe_pos],
exact zero_lt_iff.mpr (nnnorm_ne_zero_iff.mpr (norm_pos_iff.mp z_pos)) },
{ simp only [emetric.mem_ball, lt_inf_iff, edist_lt_coe, apply_eq_pow_smul_coeff, and_imp,
dist_zero_right] at h ⊢,
refine λ y hyp hyr, h _,
simpa [nndist_eq_nnnorm, real.lt_to_nnreal_iff_coe_lt] using hyr }
end
lemma has_fpower_series_at_iff' : has_fpower_series_at f p z₀ ↔
∀ᶠ z in 𝓝 z₀, has_sum (λ n, (z - z₀) ^ n • p.coeff n) (f z) :=
begin
rw [← map_add_left_nhds_zero, eventually_map, has_fpower_series_at_iff],
congrm ∀ᶠ z in (𝓝 0 : filter 𝕜), has_sum (λ n, _) (f (z₀ + z)),
rw add_sub_cancel'
end
end
|
03704a123056e01f53fb268aa2dc50224fdd979f | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/let4.lean | 342198cc29206a92455ddeed5291280585106ab1 | [
"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 | 282 | lean | import data.num
constant f : num → num → num → num
check
let a := 10,
b := 10,
c := 10
in f a b (f a 10 c)
check
let a := 10,
b := let c := 10 in f a c (f a a (f 10 a c)),
d := 10,
e := f (f 10 10 d) (f d 10 10) a
in f a b (f e d 10)
|
7a68957f57d3d8d7884de9482447957a8c829def | 83c8119e3298c0bfc53fc195c41a6afb63d01513 | /tests/lean/run/slow_tc_synth.lean | 15673bc04fe06bc5c1b27a310b11499cdced2569 | [
"Apache-2.0"
] | permissive | anfelor/lean | 584b91c4e87a6d95f7630c2a93fb082a87319ed0 | 31cfc2b6bf7d674f3d0f73848b842c9c9869c9f1 | refs/heads/master | 1,610,067,141,310 | 1,585,992,232,000 | 1,585,992,232,000 | 251,683,543 | 0 | 0 | Apache-2.0 | 1,585,676,570,000 | 1,585,676,569,000 | null | UTF-8 | Lean | false | false | 3,185 | lean | -- Generalized version of type classes with type class parameters that are
-- common in mathlib.
-- a could be topological_space, b could be ring, ...,
-- y is topological_ring, and z is topological_group
class a (α : Type)
instance a1 (α) : a α := ⟨α⟩
instance a2 (α) : a α := ⟨α⟩
instance a3 (α) : a α := ⟨α⟩
instance a4 (α) : a α := ⟨α⟩
instance a5 (α) : a α := ⟨α⟩
instance a6 (α) : a α := ⟨α⟩
instance a7 (α) : a α := ⟨α⟩
instance a8 (α) : a α := ⟨α⟩
instance a9 (α) : a α := ⟨α⟩
instance a0 (α) : a α := ⟨α⟩
class b (α : Type)
instance b1 (α) : b α := ⟨α⟩
instance b2 (α) : b α := ⟨α⟩
instance b3 (α) : b α := ⟨α⟩
instance b4 (α) : b α := ⟨α⟩
instance b5 (α) : b α := ⟨α⟩
instance b6 (α) : b α := ⟨α⟩
instance b7 (α) : b α := ⟨α⟩
instance b8 (α) : b α := ⟨α⟩
instance b9 (α) : b α := ⟨α⟩
instance b0 (α) : b α := ⟨α⟩
class c (α : Type)
instance c1 (α) : c α := ⟨α⟩
instance c2 (α) : c α := ⟨α⟩
instance c3 (α) : c α := ⟨α⟩
instance c4 (α) : c α := ⟨α⟩
instance c5 (α) : c α := ⟨α⟩
instance c6 (α) : c α := ⟨α⟩
instance c7 (α) : c α := ⟨α⟩
instance c8 (α) : c α := ⟨α⟩
instance c9 (α) : c α := ⟨α⟩
instance c0 (α) : c α := ⟨α⟩
class d (α : Type)
instance d1 (α) : d α := ⟨α⟩
instance d2 (α) : d α := ⟨α⟩
instance d3 (α) : d α := ⟨α⟩
instance d4 (α) : d α := ⟨α⟩
instance d5 (α) : d α := ⟨α⟩
instance d6 (α) : d α := ⟨α⟩
instance d7 (α) : d α := ⟨α⟩
instance d8 (α) : d α := ⟨α⟩
instance d9 (α) : d α := ⟨α⟩
instance d0 (α) : d α := ⟨α⟩
class e (α : Type)
instance e1 (α) : e α := ⟨α⟩
instance e2 (α) : e α := ⟨α⟩
instance e3 (α) : e α := ⟨α⟩
instance e4 (α) : e α := ⟨α⟩
instance e5 (α) : e α := ⟨α⟩
instance e6 (α) : e α := ⟨α⟩
instance e7 (α) : e α := ⟨α⟩
instance e8 (α) : e α := ⟨α⟩
instance e9 (α) : e α := ⟨α⟩
instance e0 (α) : e α := ⟨α⟩
class f (α : Type)
instance f1 (α) : f α := ⟨α⟩
instance f2 (α) : f α := ⟨α⟩
instance f3 (α) : f α := ⟨α⟩
instance f4 (α) : f α := ⟨α⟩
instance f5 (α) : f α := ⟨α⟩
instance f6 (α) : f α := ⟨α⟩
instance f7 (α) : f α := ⟨α⟩
instance f8 (α) : f α := ⟨α⟩
instance f9 (α) : f α := ⟨α⟩
instance f0 (α) : f α := ⟨α⟩
class g (α : Type)
instance g1 (α) : g α := ⟨α⟩
instance g2 (α) : g α := ⟨α⟩
instance g3 (α) : g α := ⟨α⟩
instance g4 (α) : g α := ⟨α⟩
instance g5 (α) : g α := ⟨α⟩
instance g6 (α) : g α := ⟨α⟩
instance g7 (α) : g α := ⟨α⟩
instance g8 (α) : g α := ⟨α⟩
instance g9 (α) : g α := ⟨α⟩
instance g0 (α) : g α := ⟨α⟩
class y (α : Type) [a α] [b α] [c α] [d α] [e α] [f α] [g α]
instance y1 (α) : y α := ⟨α⟩
class z (α : Type) [a α] [b α] [c α] [d α] [e α] [f α]
instance z.to_y (α : Type) [a α] [b α] [c α] [d α] [e α] [f α] [g α] [z α] : y α :=
⟨α⟩
example : y unit :=
by apply_instance |
a65b668e5023782b075bb6d9dda0ce7dd1ea69dc | 76df16d6c3760cb415f1294caee997cc4736e09b | /lean/src/tactic/contra.lean | fe72624cd71598b12397b1a27135d3a1be1ada00 | [
"MIT"
] | permissive | uw-unsat/leanette-popl22-artifact | 70409d9cbd8921d794d27b7992bf1d9a4087e9fe | 80fea2519e61b45a283fbf7903acdf6d5528dbe7 | refs/heads/master | 1,681,592,449,670 | 1,637,037,431,000 | 1,637,037,431,000 | 414,331,908 | 6 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 401 | lean | import tactic.basic
open tactic.interactive
setup_tactic_parser
/-
`contra` is like `contradiction`, but it will `simp` a specified
hypothesis first (potentially with helping lemmas)
-/
@[interactive] meta def contra
(hs : parse tactic.simp_arg_list) (attr_names : parse with_ident_list) (locat : parse location) : tactic unit :=
do simp none none ff hs attr_names locat,
`[contradiction] |
76385144d34e7bb2fabde317605de0181199104d | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/data/pnat/basic.lean | 2037d220fdce11f08a443904a86d5aae8045c51e | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 19,017 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro, Neil Strickland
-/
import data.nat.prime
/-- `ℕ+` is the type of positive natural numbers. It is defined as a subtype,
and the VM representation of `ℕ+` is the same as `ℕ` because the proof
is not stored. -/
def pnat := {n : ℕ // 0 < n}
notation `ℕ+` := pnat
instance coe_pnat_nat : has_coe ℕ+ ℕ := ⟨subtype.val⟩
instance : has_repr ℕ+ := ⟨λ n, repr n.1⟩
namespace nat
/-- Convert a natural number to a positive natural number. The
positivity assumption is inferred by `dec_trivial`. -/
def to_pnat (n : ℕ) (h : 0 < n . tactic.exact_dec_trivial) : ℕ+ := ⟨n, h⟩
/-- Write a successor as an element of `ℕ+`. -/
def succ_pnat (n : ℕ) : ℕ+ := ⟨succ n, succ_pos n⟩
@[simp] theorem succ_pnat_coe (n : ℕ) : (succ_pnat n : ℕ) = succ n := rfl
theorem succ_pnat_inj {n m : ℕ} : succ_pnat n = succ_pnat m → n = m :=
λ h, by { let h' := congr_arg (coe : ℕ+ → ℕ) h, exact nat.succ.inj h' }
/-- Convert a natural number to a pnat. `n+1` is mapped to itself,
and `0` becomes `1`. -/
def to_pnat' (n : ℕ) : ℕ+ := succ_pnat (pred n)
@[simp] theorem to_pnat'_coe : ∀ (n : ℕ),
((to_pnat' n) : ℕ) = ite (0 < n) n 1
| 0 := rfl
| (m + 1) := by {rw [if_pos (succ_pos m)], refl}
namespace primes
instance coe_pnat : has_coe nat.primes ℕ+ := ⟨λ p, ⟨(p : ℕ), p.property.pos⟩⟩
theorem coe_pnat_nat (p : nat.primes) : ((p : ℕ+) : ℕ) = p := rfl
theorem coe_pnat_inj (p q : nat.primes) : (p : ℕ+) = (q : ℕ+) → p = q := λ h,
begin
replace h : ((p : ℕ+) : ℕ) = ((q : ℕ+) : ℕ) := congr_arg subtype.val h,
rw [coe_pnat_nat, coe_pnat_nat] at h,
exact subtype.eq h,
end
end primes
end nat
namespace pnat
open nat
/-- We now define a long list of structures on ℕ+ induced by
similar structures on ℕ. Most of these behave in a completely
obvious way, but there are a few things to be said about
subtraction, division and powers.
-/
instance : decidable_eq ℕ+ := λ (a b : ℕ+), by apply_instance
instance : decidable_linear_order ℕ+ :=
subtype.decidable_linear_order _
@[simp] lemma mk_le_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
(⟨n, hn⟩ : ℕ+) ≤ ⟨k, hk⟩ ↔ n ≤ k := iff.rfl
@[simp] lemma mk_lt_mk (n k : ℕ) (hn : 0 < n) (hk : 0 < k) :
(⟨n, hn⟩ : ℕ+) < ⟨k, hk⟩ ↔ n < k := iff.rfl
@[simp, norm_cast] lemma coe_le_coe (n k : ℕ+) : (n:ℕ) ≤ k ↔ n ≤ k := iff.rfl
@[simp, norm_cast] lemma coe_lt_coe (n k : ℕ+) : (n:ℕ) < k ↔ n < k := iff.rfl
@[simp] theorem pos (n : ℕ+) : 0 < (n : ℕ) := n.2
theorem eq {m n : ℕ+} : (m : ℕ) = n → m = n := subtype.eq
@[simp] lemma coe_inj {m n : ℕ+} : (m : ℕ) = n ↔ m = n := set_coe.ext_iff
@[simp] theorem mk_coe (n h) : ((⟨n, h⟩ : ℕ+) : ℕ) = n := rfl
instance : add_comm_semigroup ℕ+ :=
{ add := λ a b, ⟨(a + b : ℕ), add_pos a.pos b.pos⟩,
add_comm := λ a b, subtype.eq (add_comm a b),
add_assoc := λ a b c, subtype.eq (add_assoc a b c) }
@[simp] theorem add_coe (m n : ℕ+) : ((m + n : ℕ+) : ℕ) = m + n := rfl
instance coe_add_hom : is_add_hom (coe : ℕ+ → ℕ) := ⟨add_coe⟩
instance : add_left_cancel_semigroup ℕ+ :=
{ add_left_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
rw [add_coe, add_coe] at h,
exact eq ((add_right_inj (a : ℕ)).mp h)},
.. (pnat.add_comm_semigroup) }
instance : add_right_cancel_semigroup ℕ+ :=
{ add_right_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
rw [add_coe, add_coe] at h,
exact eq ((add_left_inj (b : ℕ)).mp h)},
.. (pnat.add_comm_semigroup) }
@[simp] theorem ne_zero (n : ℕ+) : (n : ℕ) ≠ 0 := ne_of_gt n.2
theorem to_pnat'_coe {n : ℕ} : 0 < n → (n.to_pnat' : ℕ) = n := succ_pred_eq_of_pos
@[simp] theorem coe_to_pnat' (n : ℕ+) : (n : ℕ).to_pnat' = n := eq (to_pnat'_coe n.pos)
instance : comm_monoid ℕ+ :=
{ mul := λ m n, ⟨m.1 * n.1, mul_pos m.2 n.2⟩,
mul_assoc := λ a b c, subtype.eq (mul_assoc _ _ _),
one := succ_pnat 0,
one_mul := λ a, subtype.eq (one_mul _),
mul_one := λ a, subtype.eq (mul_one _),
mul_comm := λ a b, subtype.eq (mul_comm _ _) }
theorem lt_add_one_iff : ∀ {a b : ℕ+}, a < b + 1 ↔ a ≤ b :=
λ a b, nat.lt_add_one_iff
theorem add_one_le_iff : ∀ {a b : ℕ+}, a + 1 ≤ b ↔ a < b :=
λ a b, nat.add_one_le_iff
@[simp] lemma one_le (n : ℕ+) : (1 : ℕ+) ≤ n := n.2
instance : order_bot ℕ+ :=
{ bot := 1,
bot_le := λ a, a.property,
..(by apply_instance : partial_order ℕ+) }
@[simp] lemma bot_eq_zero : (⊥ : ℕ+) = 1 := rfl
instance : inhabited ℕ+ := ⟨1⟩
-- Some lemmas that rewrite `pnat.mk n h`, for `n` an explicit numeral, into explicit numerals.
@[simp] lemma mk_one {h} : (⟨1, h⟩ : ℕ+) = (1 : ℕ+) := rfl
@[simp] lemma mk_bit0 (n) {h} : (⟨bit0 n, h⟩ : ℕ+) = (bit0 ⟨n, pos_of_bit0_pos h⟩ : ℕ+) := rfl
@[simp] lemma mk_bit1 (n) {h} {k} : (⟨bit1 n, h⟩ : ℕ+) = (bit1 ⟨n, k⟩ : ℕ+) := rfl
-- Some lemmas that rewrite inequalities between explicit numerals in `pnat`
-- into the corresponding inequalities in `nat`.
-- TODO: perhaps this should not be attempted by `simp`,
-- and instead we should expect `norm_num` to take care of these directly?
-- TODO: these lemmas are perhaps incomplete:
-- * 1 is not represented as a bit0 or bit1
-- * strict inequalities?
@[simp] lemma bit0_le_bit0 (n m : ℕ+) : (bit0 n) ≤ (bit0 m) ↔ (bit0 (n : ℕ)) ≤ (bit0 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit0_le_bit1 (n m : ℕ+) : (bit0 n) ≤ (bit1 m) ↔ (bit0 (n : ℕ)) ≤ (bit1 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit1_le_bit0 (n m : ℕ+) : (bit1 n) ≤ (bit0 m) ↔ (bit1 (n : ℕ)) ≤ (bit0 (m : ℕ)) :=
iff.rfl
@[simp] lemma bit1_le_bit1 (n m : ℕ+) : (bit1 n) ≤ (bit1 m) ↔ (bit1 (n : ℕ)) ≤ (bit1 (m : ℕ)) :=
iff.rfl
@[simp] theorem one_coe : ((1 : ℕ+) : ℕ) = 1 := rfl
@[simp] theorem mul_coe (m n : ℕ+) : ((m * n : ℕ+) : ℕ) = m * n := rfl
instance coe_mul_hom : is_monoid_hom (coe : ℕ+ → ℕ) :=
{map_one := one_coe, map_mul := mul_coe}
@[simp]
lemma coe_eq_one_iff {m : ℕ+} :
(m : ℕ) = 1 ↔ m = 1 := by { split; intro h; try { apply pnat.eq}; rw h; simp }
@[simp] lemma coe_bit0 (a : ℕ+) : ((bit0 a : ℕ+) : ℕ) = bit0 (a : ℕ) := rfl
@[simp] lemma coe_bit1 (a : ℕ+) : ((bit1 a : ℕ+) : ℕ) = bit1 (a : ℕ) := rfl
@[simp] theorem pow_coe (m : ℕ+) (n : ℕ) : ((m ^ n : ℕ+) : ℕ) = (m : ℕ) ^ n :=
by induction n with n ih;
[refl, rw [nat.pow_succ, pow_succ, mul_coe, mul_comm, ih]]
instance : left_cancel_semigroup ℕ+ :=
{ mul_left_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
exact eq ((nat.mul_right_inj a.pos).mp h)},
.. (pnat.comm_monoid) }
instance : right_cancel_semigroup ℕ+ :=
{ mul_right_cancel := λ a b c h, by {
replace h := congr_arg (coe : ℕ+ → ℕ) h,
exact eq ((nat.mul_left_inj b.pos).mp h)},
.. (pnat.comm_monoid) }
instance : ordered_cancel_comm_monoid ℕ+ :=
{ mul_le_mul_left := by { intros, apply nat.mul_le_mul_left, assumption },
le_of_mul_le_mul_left := by { intros a b c h, apply nat.le_of_mul_le_mul_left h a.property, },
.. (pnat.left_cancel_semigroup),
.. (pnat.right_cancel_semigroup),
.. (pnat.decidable_linear_order),
.. (pnat.comm_monoid)}
instance : distrib ℕ+ :=
{ left_distrib := λ a b c, eq (mul_add a b c),
right_distrib := λ a b c, eq (add_mul a b c),
..(pnat.add_comm_semigroup), ..(pnat.comm_monoid) }
/-- Subtraction a - b is defined in the obvious way when
a > b, and by a - b = 1 if a ≤ b.
-/
instance : has_sub ℕ+ := ⟨λ a b, to_pnat' (a - b : ℕ)⟩
theorem sub_coe (a b : ℕ+) : ((a - b : ℕ+) : ℕ) = ite (b < a) (a - b : ℕ) 1 :=
begin
change ((to_pnat' ((a : ℕ) - (b : ℕ)) : ℕ)) =
ite ((a : ℕ) > (b : ℕ)) ((a : ℕ) - (b : ℕ)) 1,
split_ifs with h,
{ exact to_pnat'_coe (nat.sub_pos_of_lt h) },
{ rw [nat.sub_eq_zero_iff_le.mpr (le_of_not_gt h)], refl }
end
theorem add_sub_of_lt {a b : ℕ+} : a < b → a + (b - a) = b :=
λ h, eq $ by { rw [add_coe, sub_coe, if_pos h],
exact nat.add_sub_of_le (le_of_lt h) }
/-- We define m % k and m / k in the same way as for nat
except that when m = n * k we take m % k = k and
m / k = n - 1. This ensures that m % k is always positive
and m = (m % k) + k * (m / k) in all cases. Later we
define a function div_exact which gives the usual m / k
in the case where k divides m.
-/
def mod_div_aux : ℕ+ → ℕ → ℕ → ℕ+ × ℕ
| k 0 q := ⟨k, q.pred⟩
| k (r + 1) q := ⟨⟨r + 1, nat.succ_pos r⟩, q⟩
lemma mod_div_aux_spec : ∀ (k : ℕ+) (r q : ℕ) (h : ¬ (r = 0 ∧ q = 0)),
(((mod_div_aux k r q).1 : ℕ) + k * (mod_div_aux k r q).2 = (r + k * q))
| k 0 0 h := (h ⟨rfl, rfl⟩).elim
| k 0 (q + 1) h := by {
change (k : ℕ) + (k : ℕ) * (q + 1).pred = 0 + (k : ℕ) * (q + 1),
rw [nat.pred_succ, nat.mul_succ, zero_add, add_comm]}
| k (r + 1) q h := rfl
def mod_div (m k : ℕ+) : ℕ+ × ℕ := mod_div_aux k ((m : ℕ) % (k : ℕ)) ((m : ℕ) / (k : ℕ))
def mod (m k : ℕ+) : ℕ+ := (mod_div m k).1
def div (m k : ℕ+) : ℕ := (mod_div m k).2
theorem mod_add_div (m k : ℕ+) : (m : ℕ) = (mod m k) + k * (div m k) :=
begin
let h₀ := nat.mod_add_div (m : ℕ) (k : ℕ),
have : ¬ ((m : ℕ) % (k : ℕ) = 0 ∧ (m : ℕ) / (k : ℕ) = 0),
by { rintro ⟨hr, hq⟩, rw [hr, hq, mul_zero, zero_add] at h₀,
exact (m.ne_zero h₀.symm).elim },
have := mod_div_aux_spec k ((m : ℕ) % (k : ℕ)) ((m : ℕ) / (k : ℕ)) this,
exact (this.trans h₀).symm,
end
theorem mod_coe (m k : ℕ+) :
((mod m k) : ℕ) = ite ((m : ℕ) % (k : ℕ) = 0) (k : ℕ) ((m : ℕ) % (k : ℕ)) :=
begin
dsimp [mod, mod_div],
cases (m : ℕ) % (k : ℕ),
{ rw [if_pos rfl], refl },
{ rw [if_neg n.succ_ne_zero], refl }
end
theorem div_coe (m k : ℕ+) :
((div m k) : ℕ) = ite ((m : ℕ) % (k : ℕ) = 0) ((m : ℕ) / (k : ℕ)).pred ((m : ℕ) / (k : ℕ)) :=
begin
dsimp [div, mod_div],
cases (m : ℕ) % (k : ℕ),
{ rw [if_pos rfl], refl },
{ rw [if_neg n.succ_ne_zero], refl }
end
theorem mod_le (m k : ℕ+) : mod m k ≤ m ∧ mod m k ≤ k :=
begin
change ((mod m k) : ℕ) ≤ (m : ℕ) ∧ ((mod m k) : ℕ) ≤ (k : ℕ),
rw [mod_coe], split_ifs,
{ have hm : (m : ℕ) > 0 := m.pos,
rw [← nat.mod_add_div (m : ℕ) (k : ℕ), h, zero_add] at hm ⊢,
by_cases h' : ((m : ℕ) / (k : ℕ)) = 0,
{ rw [h', mul_zero] at hm, exact (lt_irrefl _ hm).elim},
{ let h' := nat.mul_le_mul_left (k : ℕ)
(nat.succ_le_of_lt (nat.pos_of_ne_zero h')),
rw [mul_one] at h', exact ⟨h', le_refl (k : ℕ)⟩ } },
{ exact ⟨nat.mod_le (m : ℕ) (k : ℕ), le_of_lt (nat.mod_lt (m : ℕ) k.pos)⟩ }
end
instance : has_dvd ℕ+ := ⟨λ k m, (k : ℕ) ∣ (m : ℕ)⟩
theorem dvd_iff {k m : ℕ+} : k ∣ m ↔ (k : ℕ) ∣ (m : ℕ) := by {refl}
theorem dvd_iff' {k m : ℕ+} : k ∣ m ↔ mod m k = k :=
begin
change (k : ℕ) ∣ (m : ℕ) ↔ mod m k = k,
rw [nat.dvd_iff_mod_eq_zero], split,
{ intro h, apply eq, rw [mod_coe, if_pos h] },
{ intro h, by_cases h' : (m : ℕ) % (k : ℕ) = 0,
{ exact h'},
{ replace h : ((mod m k) : ℕ) = (k : ℕ) := congr_arg _ h,
rw [mod_coe, if_neg h'] at h,
exact (ne_of_lt (nat.mod_lt (m : ℕ) k.pos) h).elim } }
end
lemma le_of_dvd {m n : ℕ+} : m ∣ n → m ≤ n :=
by { rw dvd_iff', intro h, rw ← h, apply (mod_le n m).left }
def div_exact {m k : ℕ+} (h : k ∣ m) : ℕ+ :=
⟨(div m k).succ, nat.succ_pos _⟩
theorem mul_div_exact {m k : ℕ+} (h : k ∣ m) : k * (div_exact h) = m :=
begin
apply eq, rw [mul_coe],
change (k : ℕ) * (div m k).succ = m,
rw [mod_add_div m k, dvd_iff'.mp h, nat.mul_succ, add_comm],
end
theorem dvd_iff'' {k n : ℕ+} : k ∣ n ↔ ∃ m, k * m = n :=
⟨λ h, ⟨div_exact h, mul_div_exact h⟩,
λ ⟨m, h⟩, dvd.intro (m : ℕ)
((mul_coe k m).symm.trans (congr_arg subtype.val h))⟩
theorem dvd_intro {k n : ℕ+} (m : ℕ+) (h : k * m = n) : k ∣ n :=
dvd_iff''.mpr ⟨m, h⟩
@[simp]
theorem dvd_refl (m : ℕ+) : m ∣ m := dvd_intro 1 (mul_one m)
theorem dvd_antisymm {m n : ℕ+} : m ∣ n → n ∣ m → m = n :=
λ hmn hnm, subtype.eq (nat.dvd_antisymm hmn hnm)
protected theorem dvd_trans {k m n : ℕ+} : k ∣ m → m ∣ n → k ∣ n :=
@dvd_trans ℕ _ (k : ℕ) (m : ℕ) (n : ℕ)
theorem one_dvd (n : ℕ+) : 1 ∣ n := dvd_intro n (one_mul n)
theorem dvd_one_iff (n : ℕ+) : n ∣ 1 ↔ n = 1 :=
⟨λ h, dvd_antisymm h (one_dvd n), λ h, h.symm ▸ (dvd_refl 1)⟩
def gcd (n m : ℕ+) : ℕ+ :=
⟨nat.gcd (n : ℕ) (m : ℕ), nat.gcd_pos_of_pos_left (m : ℕ) n.pos⟩
def lcm (n m : ℕ+) : ℕ+ :=
⟨nat.lcm (n : ℕ) (m : ℕ),
by { let h := mul_pos n.pos m.pos,
rw [← gcd_mul_lcm (n : ℕ) (m : ℕ), mul_comm] at h,
exact pos_of_dvd_of_pos (dvd.intro (nat.gcd (n : ℕ) (m : ℕ)) rfl) h }⟩
@[simp] theorem gcd_coe (n m : ℕ+) : ((gcd n m) : ℕ) = nat.gcd n m := rfl
@[simp] theorem lcm_coe (n m : ℕ+) : ((lcm n m) : ℕ) = nat.lcm n m := rfl
theorem gcd_dvd_left (n m : ℕ+) : (gcd n m) ∣ n := nat.gcd_dvd_left (n : ℕ) (m : ℕ)
theorem gcd_dvd_right (n m : ℕ+) : (gcd n m) ∣ m := nat.gcd_dvd_right (n : ℕ) (m : ℕ)
theorem dvd_gcd {m n k : ℕ+} (hm : k ∣ m) (hn : k ∣ n) : k ∣ gcd m n :=
@nat.dvd_gcd (m : ℕ) (n : ℕ) (k : ℕ) hm hn
theorem dvd_lcm_left (n m : ℕ+) : n ∣ lcm n m := nat.dvd_lcm_left (n : ℕ) (m : ℕ)
theorem dvd_lcm_right (n m : ℕ+) : m ∣ lcm n m := nat.dvd_lcm_right (n : ℕ) (m : ℕ)
theorem lcm_dvd {m n k : ℕ+} (hm : m ∣ k) (hn : n ∣ k) : lcm m n ∣ k :=
@nat.lcm_dvd (m : ℕ) (n : ℕ) (k : ℕ) hm hn
theorem gcd_mul_lcm (n m : ℕ+) : (gcd n m) * (lcm n m) = n * m :=
subtype.eq (nat.gcd_mul_lcm (n : ℕ) (m : ℕ))
lemma eq_one_of_lt_two {n : ℕ+} : n < 2 → n = 1 :=
begin
intro h, apply le_antisymm, swap, apply pnat.one_le,
change n < 1 + 1 at h, rw pnat.lt_add_one_iff at h, apply h
end
section prime
/-! ### Prime numbers -/
def prime (p : ℕ+) : Prop := (p : ℕ).prime
lemma prime.one_lt {p : ℕ+} : p.prime → 1 < p := nat.prime.one_lt
lemma prime_two : (2 : ℕ+).prime := nat.prime_two
lemma dvd_prime {p m : ℕ+} (pp : p.prime) :
(m ∣ p ↔ m = 1 ∨ m = p) := by { rw pnat.dvd_iff, rw nat.dvd_prime pp, simp }
lemma prime.ne_one {p : ℕ+} : p.prime → p ≠ 1 :=
by { intro pp, intro contra, apply nat.prime.ne_one pp, rw pnat.coe_eq_one_iff, apply contra }
@[simp]
lemma not_prime_one : ¬ (1: ℕ+).prime := nat.not_prime_one
lemma prime.not_dvd_one {p : ℕ+} :
p.prime → ¬ p ∣ 1 := λ pp : p.prime, nat.prime.not_dvd_one pp
lemma exists_prime_and_dvd {n : ℕ+} : 2 ≤ n → (∃ (p : ℕ+), p.prime ∧ p ∣ n) :=
begin
intro h, cases nat.exists_prime_and_dvd h with p hp,
existsi (⟨p, nat.prime.pos hp.left⟩ : ℕ+), apply hp
end
end prime
section coprime
/-! ### Coprime numbers and gcd -/
/-- Two pnats are coprime if their gcd is 1. -/
def coprime (m n : ℕ+) : Prop := m.gcd n = 1
@[simp]
lemma coprime_coe {m n : ℕ+} : nat.coprime ↑m ↑n ↔ m.coprime n :=
by { unfold coprime, unfold nat.coprime, rw ← coe_inj, simp }
lemma coprime.mul {k m n : ℕ+} : m.coprime k → n.coprime k → (m * n).coprime k :=
by { repeat {rw ← coprime_coe}, rw mul_coe, apply nat.coprime.mul }
lemma coprime.mul_right {k m n : ℕ+} : k.coprime m → k.coprime n → k.coprime (m * n) :=
by { repeat {rw ← coprime_coe}, rw mul_coe, apply nat.coprime.mul_right }
lemma gcd_comm {m n : ℕ+} : m.gcd n = n.gcd m :=
by { apply eq, simp only [gcd_coe], apply nat.gcd_comm }
lemma gcd_eq_left_iff_dvd {m n : ℕ+} : m ∣ n ↔ m.gcd n = m :=
by { rw dvd_iff, rw nat.gcd_eq_left_iff_dvd, rw ← coe_inj, simp }
lemma gcd_eq_right_iff_dvd {m n : ℕ+} : m ∣ n ↔ n.gcd m = m :=
by { rw gcd_comm, apply gcd_eq_left_iff_dvd, }
lemma coprime.gcd_mul_left_cancel (m : ℕ+) {n k : ℕ+} :
k.coprime n → (k * m).gcd n = m.gcd n :=
begin
intro h, apply eq, simp only [gcd_coe, mul_coe],
apply nat.coprime.gcd_mul_left_cancel, simpa
end
lemma coprime.gcd_mul_right_cancel (m : ℕ+) {n k : ℕ+} :
k.coprime n → (m * k).gcd n = m.gcd n :=
begin
rw mul_comm, apply coprime.gcd_mul_left_cancel,
end
lemma coprime.gcd_mul_left_cancel_right (m : ℕ+) {n k : ℕ+} :
k.coprime m → m.gcd (k * n) = m.gcd n :=
begin
intro h, iterate 2 {rw gcd_comm, symmetry}, apply coprime.gcd_mul_left_cancel _ h,
end
lemma coprime.gcd_mul_right_cancel_right (m : ℕ+) {n k : ℕ+} :
k.coprime m → m.gcd (n * k) = m.gcd n :=
begin
rw mul_comm, apply coprime.gcd_mul_left_cancel_right,
end
@[simp]
lemma one_gcd {n : ℕ+} : gcd 1 n = 1 :=
by { rw ← gcd_eq_left_iff_dvd, apply one_dvd }
@[simp]
lemma gcd_one {n : ℕ+} : gcd n 1 = 1 := by { rw gcd_comm, apply one_gcd }
@[symm]
lemma coprime.symm {m n : ℕ+} : m.coprime n → n.coprime m :=
by { unfold coprime, rw gcd_comm, simp }
@[simp]
lemma one_coprime {n : ℕ+} : (1 : ℕ+).coprime n := one_gcd
@[simp]
lemma coprime_one {n : ℕ+} : n.coprime 1 := coprime.symm one_coprime
lemma coprime.coprime_dvd_left {m k n : ℕ+} :
m ∣ k → k.coprime n → m.coprime n :=
by { rw dvd_iff, repeat {rw ← coprime_coe}, apply nat.coprime.coprime_dvd_left }
lemma coprime.factor_eq_gcd_left {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n):
a = (a * b).gcd m :=
begin
rw gcd_eq_left_iff_dvd at am,
conv_lhs {rw ← am}, symmetry,
apply coprime.gcd_mul_right_cancel a,
apply coprime.coprime_dvd_left bn cop.symm,
end
lemma coprime.factor_eq_gcd_right {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n):
a = (b * a).gcd m :=
begin
rw mul_comm, apply coprime.factor_eq_gcd_left cop am bn,
end
lemma coprime.factor_eq_gcd_left_right {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n):
a = m.gcd (a * b) :=
begin
rw gcd_comm, apply coprime.factor_eq_gcd_left cop am bn,
end
lemma coprime.factor_eq_gcd_right_right {a b m n : ℕ+} (cop : m.coprime n) (am : a ∣ m) (bn : b ∣ n):
a = m.gcd (b * a) :=
begin
rw gcd_comm, apply coprime.factor_eq_gcd_right cop am bn,
end
lemma coprime.gcd_mul (k : ℕ+) {m n : ℕ+} (h: m.coprime n) :
k.gcd (m * n) = k.gcd m * k.gcd n :=
begin
rw ← coprime_coe at h, apply eq,
simp only [gcd_coe, mul_coe], apply nat.coprime.gcd_mul k h
end
lemma gcd_eq_left {m n : ℕ+} : m ∣ n → m.gcd n = m :=
by { rw dvd_iff, intro h, apply eq, simp only [gcd_coe], apply nat.gcd_eq_left h }
lemma coprime.pow {m n : ℕ+} (k l : ℕ) (h : m.coprime n) : (m ^ k).coprime (n ^ l) :=
begin
rw ← coprime_coe at *, simp only [pow_coe], apply nat.coprime.pow, apply h
end
end coprime
end pnat
|
0dd861790f06eb012cdeb52477bd1a3a67b13ddb | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/Tactic/Meta.lean | 30d3fefc2d4e1efa6f049f39e8a603f04402e5fa | [
"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 | 670 | 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.SyntheticMVars
import Lean.Elab.Tactic.Basic
namespace Lean.Elab
open Term
/-- Apply the give tactic code to `mvarId` in `MetaM`. -/
def runTactic (mvarId : MVarId) (tacticCode : Syntax) (ctx : Context := {}) (s : State := {}) : MetaM (List MVarId × State) := do
instantiateMVarDeclMVars mvarId
let go : TermElabM (List MVarId) :=
withSynthesize (mayPostpone := false) do Tactic.run mvarId (Tactic.evalTactic tacticCode *> Tactic.pruneSolvedGoals)
go.run ctx s
end Lean.Elab
|
77757de0bf55b6c86038572dfd11782938ac0483 | 95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990 | /src/algebra/field.lean | d1eb2ddfda6108836da8e64b6956b0d7c09ef3f1 | [
"Apache-2.0"
] | permissive | uniformity1/mathlib | 829341bad9dfa6d6be9adaacb8086a8a492e85a4 | dd0e9bd8f2e5ec267f68e72336f6973311909105 | refs/heads/master | 1,588,592,015,670 | 1,554,219,842,000 | 1,554,219,842,000 | 179,110,702 | 0 | 0 | Apache-2.0 | 1,554,220,076,000 | 1,554,220,076,000 | null | UTF-8 | Lean | false | false | 8,510 | 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 algebra.ring logic.basic
open set
universe u
variables {α : Type u}
instance division_ring.to_domain [s : division_ring α] : domain α :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := λ a b h,
classical.by_contradiction $ λ hn,
division_ring.mul_ne_zero (mt or.inl hn) (mt or.inr hn) h
..s }
namespace units
variables [division_ring α] {a b : α}
/-- Embed an element of a division ring into the unit group.
By combining this function with the operations on units,
or the `/ₚ` operation, it is possible to write a division
as a partial function with three arguments. -/
def mk0 (a : α) (ha : a ≠ 0) : units α :=
⟨a, a⁻¹, mul_inv_cancel ha, inv_mul_cancel ha⟩
@[simp] theorem inv_eq_inv (u : units α) : (↑u⁻¹ : α) = u⁻¹ :=
(mul_left_inj u).1 $ by rw [units.mul_inv, mul_inv_cancel]; apply units.ne_zero
@[simp] theorem mk0_val (ha : a ≠ 0) : (mk0 a ha : α) = a := rfl
@[simp] theorem mk0_inv (ha : a ≠ 0) : ((mk0 a ha)⁻¹ : α) = a⁻¹ := rfl
@[simp] lemma mk0_coe (u : units α) (h : (u : α) ≠ 0) : mk0 (u : α) h = u :=
units.ext rfl
@[simp] lemma units.mk0_inj [field α] {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) :
units.mk0 a ha = units.mk0 b hb ↔ a = b :=
⟨λ h, by injection h, λ h, units.ext h⟩
end units
section division_ring
variables [s : division_ring α] {a b c : α}
include s
lemma div_eq_mul_inv : a / b = a * b⁻¹ := rfl
attribute [simp] div_one zero_div div_self
theorem divp_eq_div (a : α) (u : units α) : a /ₚ u = a / u :=
congr_arg _ $ units.inv_eq_inv _
@[simp] theorem divp_mk0 (a : α) {b : α} (hb : b ≠ 0) :
a /ₚ units.mk0 b hb = a / b :=
divp_eq_div _ _
lemma inv_div (ha : a ≠ 0) (hb : b ≠ 0) : (a / b)⁻¹ = b / a :=
(mul_inv_eq (inv_ne_zero hb) ha).trans $ by rw division_ring.inv_inv hb; refl
lemma inv_div_left (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ / b = (b * a)⁻¹ :=
(mul_inv_eq ha hb).symm
lemma neg_inv (h : a ≠ 0) : - a⁻¹ = (- a)⁻¹ :=
by rw [inv_eq_one_div, inv_eq_one_div, div_neg_eq_neg_div _ h]
lemma division_ring.inv_comm_of_comm (h : a ≠ 0) (H : a * b = b * a) : a⁻¹ * b = b * a⁻¹ :=
begin
have : a⁻¹ * (b * a) * a⁻¹ = a⁻¹ * (a * b) * a⁻¹ :=
congr_arg (λ x:α, a⁻¹ * x * a⁻¹) H.symm,
rwa [mul_assoc, mul_assoc, mul_inv_cancel, mul_one,
← mul_assoc, inv_mul_cancel, one_mul] at this; exact h
end
lemma div_ne_zero (ha : a ≠ 0) (hb : b ≠ 0) : a / b ≠ 0 :=
division_ring.mul_ne_zero ha (inv_ne_zero hb)
lemma div_ne_zero_iff (hb : b ≠ 0) : a / b ≠ 0 ↔ a ≠ 0 :=
⟨mt (λ h, by rw [h, zero_div]), λ ha, div_ne_zero ha hb⟩
lemma div_eq_zero_iff (hb : b ≠ 0) : a / b = 0 ↔ a = 0 :=
by haveI := classical.prop_decidable; exact
not_iff_not.1 (div_ne_zero_iff hb)
lemma add_div (a b c : α) : (a + b) / c = a / c + b / c :=
(div_add_div_same _ _ _).symm
lemma div_right_inj (hc : c ≠ 0) : a / c = b / c ↔ a = b :=
by rw [← divp_mk0 _ hc, ← divp_mk0 _ hc, divp_right_inj]
lemma sub_div (a b c : α) : (a - b) / c = a / c - b / c :=
(div_sub_div_same _ _ _).symm
lemma division_ring.inv_inj (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ = b⁻¹ ↔ a = b :=
⟨λ h, by rw [← division_ring.inv_inv ha, ← division_ring.inv_inv hb, h], congr_arg (λx,x⁻¹)⟩
lemma division_ring.inv_eq_iff (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ = b ↔ b⁻¹ = a :=
by rw [← division_ring.inv_inj (inv_ne_zero ha) hb,
eq_comm, division_ring.inv_inv ha]
lemma div_neg (a : α) (hb : b ≠ 0) : a / -b = -(a / b) :=
by rw [← division_ring.neg_div_neg_eq _ (neg_ne_zero.2 hb), neg_neg, neg_div]
lemma div_eq_iff_mul_eq (hb : b ≠ 0) : a / b = c ↔ c * b = a :=
⟨λ h, by rw [← h, div_mul_cancel _ hb],
λ h, by rw [← h, mul_div_cancel _ hb]⟩
end division_ring
instance field.to_integral_domain [F : field α] : integral_domain α :=
{ ..F, ..division_ring.to_domain }
section
variables [field α] {a b c d : α}
lemma div_eq_inv_mul : a / b = b⁻¹ * a := mul_comm _ _
lemma inv_add_inv {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ + b⁻¹ = (a + b) / (a * b) :=
by rw [inv_eq_one_div, inv_eq_one_div, one_div_add_one_div ha hb]
lemma inv_sub_inv {a b : α} (ha : a ≠ 0) (hb : b ≠ 0) : a⁻¹ - b⁻¹ = (b - a) / (a * b) :=
by rw [inv_eq_one_div, inv_eq_one_div, div_sub_div _ _ ha hb, one_mul, mul_one]
lemma mul_div_right_comm (a b c : α) : (a * b) / c = (a / c) * b :=
(div_mul_eq_mul_div _ _ _).symm
lemma mul_comm_div (a b c : α) : (a / b) * c = a * (c / b) :=
by rw [← mul_div_assoc, mul_div_right_comm]
lemma div_mul_comm (a b c : α) : (a / b) * c = (c / b) * a :=
by rw [div_mul_eq_mul_div, mul_comm, mul_div_right_comm]
lemma mul_div_comm (a b c : α) : a * (b / c) = b * (a / c) :=
by rw [← mul_div_assoc, mul_comm, mul_div_assoc]
lemma field.div_right_comm (a : α) (hb : b ≠ 0) (hc : c ≠ 0) : (a / b) / c = (a / c) / b :=
by rw [field.div_div_eq_div_mul _ hb hc, field.div_div_eq_div_mul _ hc hb, mul_comm]
lemma field.div_div_div_cancel_right (a : α) (hb : b ≠ 0) (hc : c ≠ 0) : (a / c) / (b / c) = a / b :=
by rw [field.div_div_eq_mul_div _ hb hc, div_mul_cancel _ hc]
lemma field.div_mul_div_cancel (a : α) (hb : b ≠ 0) (hc : c ≠ 0) : (a / c) * (c / b) = a / b :=
by rw [← mul_div_assoc, div_mul_cancel _ hc]
lemma div_eq_div_iff (hb : b ≠ 0) (hd : d ≠ 0) : a / b = c / d ↔ a * d = c * b :=
(domain.mul_right_inj (mul_ne_zero' hb hd)).symm.trans $
by rw [← mul_assoc, div_mul_cancel _ hb,
← mul_assoc, mul_right_comm, div_mul_cancel _ hd]
lemma field.div_div_cancel (ha : a ≠ 0) (hb : b ≠ 0) : a / (a / b) = b :=
by rw [div_eq_mul_inv, inv_div ha hb, mul_div_cancel' _ ha]
end
section
variables [discrete_field α] {a b c : α}
attribute [simp] inv_zero div_zero
lemma div_right_comm (a b c : α) : (a / b) / c = (a / c) / b :=
if b0 : b = 0 then by simp only [b0, div_zero, zero_div] else
if c0 : c = 0 then by simp only [c0, div_zero, zero_div] else
field.div_right_comm _ b0 c0
lemma div_div_div_cancel_right (a b : α) (hc : c ≠ 0) : (a / c) / (b / c) = a / b :=
if b0 : b = 0 then by simp only [b0, div_zero, zero_div] else
field.div_div_div_cancel_right _ b0 hc
lemma div_mul_div_cancel (a : α) (hb : b ≠ 0) (hc : c ≠ 0) : (a / c) * (c / b) = a / b :=
if b0 : b = 0 then by simp only [b0, div_zero, mul_zero] else
field.div_mul_div_cancel _ b0 hc
lemma div_div_cancel (ha : a ≠ 0) : a / (a / b) = b :=
if b0 : b = 0 then by simp only [b0, div_zero] else
field.div_div_cancel ha b0
@[simp] lemma inv_eq_zero (a : α) : a⁻¹ = 0 ↔ a = 0 :=
classical.by_cases (assume : a = 0, by simp [*])(assume : a ≠ 0, by simp [*, inv_ne_zero])
lemma neg_inv' (a : α) : (-a)⁻¹ = - a⁻¹ :=
begin
by_cases a = 0,
{ rw [h, neg_zero, inv_zero, neg_zero] },
{ rw [neg_inv h] }
end
end
@[reducible] def is_field_hom {α β} [division_ring α] [division_ring β] (f : α → β) := is_ring_hom f
namespace is_field_hom
open is_ring_hom
section
variables {β : Type*} [division_ring α] [division_ring β]
variables (f : α → β) [is_field_hom f] {x y : α}
lemma map_ne_zero : f x ≠ 0 ↔ x ≠ 0 :=
⟨mt $ λ h, h.symm ▸ map_zero f,
λ x0 h, one_ne_zero $ calc
1 = f (x * x⁻¹) : by rw [mul_inv_cancel x0, map_one f]
... = 0 : by rw [map_mul f, h, zero_mul]⟩
lemma map_eq_zero : f x = 0 ↔ x = 0 :=
by haveI := classical.dec; exact not_iff_not.1 (map_ne_zero f)
lemma map_inv' (h : x ≠ 0) : f x⁻¹ = (f x)⁻¹ :=
(domain.mul_left_inj ((map_ne_zero f).2 h)).1 $
by rw [mul_inv_cancel ((map_ne_zero f).2 h), ← map_mul f, mul_inv_cancel h, map_one f]
lemma map_div' (h : y ≠ 0) : f (x / y) = f x / f y :=
(map_mul f).trans $ congr_arg _ $ map_inv' f h
lemma injective : function.injective f :=
(is_add_group_hom.injective_iff _).2
(λ a ha, classical.by_contradiction $ λ ha0,
by simpa [ha, is_ring_hom.map_mul f, is_ring_hom.map_one f, zero_ne_one]
using congr_arg f (mul_inv_cancel ha0))
end
section
variables {β : Type*} [discrete_field α] [discrete_field β]
variables (f : α → β) [is_field_hom f] {x y : α}
lemma map_inv : f x⁻¹ = (f x)⁻¹ :=
classical.by_cases (by rintro rfl; simp only [map_zero f, inv_zero]) (map_inv' f)
lemma map_div : f (x / y) = f x / f y :=
(map_mul f).trans $ congr_arg _ $ map_inv f
end
end is_field_hom
|
e8bbfcaf87d81eb4d8c6e9a70376b0599de915b2 | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/measure_theory/prod_group.lean | c82ab9cbb1cfa0ea102b4a294edfa376f79ade87 | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,580 | lean | /-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.prod
import measure_theory.group
/-!
# Measure theory in the product of groups
In this file we show properties about measure theory in products of topological groups
and properties of iterated integrals in topological groups.
These lemmas show the uniqueness of left invariant measures on locally compact groups, up to
scaling. In this file we follow the proof and refer to the book *Measure Theory* by Paul Halmos.
The idea of the proof is to use the translation invariance of measures to prove `μ(F) = c * μ(E)`
for two sets `E` and `F`, where `c` is a constant that does not depend on `μ`. Let `e` and `f` be
the characteristic functions of `E` and `F`.
Assume that `μ` and `ν` are left-invariant measures. Then the map `(x, y) ↦ (y * x, x⁻¹)`
preserves the measure `μ.prod ν`, which means that
```
∫ x, ∫ y, h x y ∂ν ∂μ = ∫ x, ∫ y, h (y * x) x⁻¹ ∂ν ∂μ
```
If we apply this to `h x y := e x * f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E)`, we can rewrite the RHS to
`μ(F)`, and the LHS to `c * μ(E)`, where `c = c(ν)` does not depend on `μ`.
Applying this to `μ` and to `ν` gives `μ (F) / μ (E) = ν (F) / ν (E)`, which is the uniqueness up to
scalar multiplication.
The proof in [Halmos] seems to contain an omission in §60 Th. A, see
`measure_theory.measure_lintegral_div_measure` and
https://math.stackexchange.com/questions/3974485/does-right-translation-preserve-finiteness-for-a-left-invariant-measure
-/
noncomputable theory
open topological_space set (hiding prod_eq) function
open_locale classical
namespace measure_theory
open measure
variables {G : Type*} [topological_space G] [measurable_space G] [second_countable_topology G]
[borel_space G] [group G] [topological_group G]
variables {μ ν : measure G} [sigma_finite ν] [sigma_finite μ]
/-- This condition is part of the definition of a measurable group in [Halmos, §59].
There, the map in this lemma is called `S`. -/
lemma map_prod_mul_eq (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.1, z.1 * z.2)) (μ.prod ν) = μ.prod ν :=
begin
refine (prod_eq _).symm, intros s t hs ht,
simp_rw [map_apply (measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht),
prod_apply ((measurable_fst.prod_mk (measurable_fst.mul measurable_snd)) (hs.prod ht)),
preimage_preimage],
conv_lhs { congr, skip, funext, rw [mk_preimage_prod_right_fn_eq_if ((*) x), measure_if] },
simp_rw [hν _ ht, lintegral_indicator _ hs, set_lintegral_const, mul_comm]
end
/-- The function we are mapping along is `SR` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_mul_eq_swap (hμ : is_mul_left_invariant μ) :
map (λ z : G × G, (z.2, z.2 * z.1)) (μ.prod ν) = ν.prod μ :=
begin
rw [← prod_swap],
simp_rw [map_map (measurable_snd.prod_mk (measurable_snd.mul measurable_fst)) measurable_swap],
exact map_prod_mul_eq hμ
end
/-- The function we are mapping along is `S⁻¹` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq`. -/
lemma map_prod_inv_mul_eq (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.1, z.1⁻¹ * z.2)) (μ.prod ν) = μ.prod ν :=
(homeomorph.shear_mul_right G).to_measurable_equiv.map_apply_eq_iff_map_symm_apply_eq.mp $
map_prod_mul_eq hν
/-- The function we are mapping along is `S⁻¹R` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_inv_mul_eq_swap (hμ : is_mul_left_invariant μ) :
map (λ z : G × G, (z.2, z.2⁻¹ * z.1)) (μ.prod ν) = ν.prod μ :=
begin
rw [← prod_swap],
simp_rw
[map_map (measurable_snd.prod_mk $ measurable_snd.inv.mul measurable_fst) measurable_swap],
exact map_prod_inv_mul_eq hμ
end
/-- The function we are mapping along is `S⁻¹RSR` in [Halmos, §59],
where `S` is the map in `map_prod_mul_eq` and `R` is `prod.swap`. -/
lemma map_prod_mul_inv_eq (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν) :
map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod ν) = μ.prod ν :=
begin
let S := (homeomorph.shear_mul_right G).to_measurable_equiv,
suffices : map ((λ z : G × G, (z.2, z.2⁻¹ * z.1)) ∘ (λ z : G × G, (z.2, z.2 * z.1))) (μ.prod ν) =
μ.prod ν,
{ convert this, ext1 ⟨x, y⟩, simp },
simp_rw [← map_map (measurable_snd.prod_mk (measurable_snd.inv.mul measurable_fst))
(measurable_snd.prod_mk (measurable_snd.mul measurable_fst)), map_prod_mul_eq_swap hμ,
map_prod_inv_mul_eq_swap hν]
end
lemma measure_null_of_measure_inv_null (hμ : is_mul_left_invariant μ)
{E : set G} (hE : is_measurable E) (h2E : μ ((λ x, x⁻¹) ⁻¹' E) = 0) : μ E = 0 :=
begin
have hf : measurable (λ z : G × G, (z.2 * z.1, z.1⁻¹)) :=
(measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv,
suffices : map (λ z : G × G, (z.2 * z.1, z.1⁻¹)) (μ.prod μ) (E.prod E) = 0,
{ simpa only [map_prod_mul_inv_eq hμ hμ, prod_prod hE hE, mul_eq_zero, or_self] using this },
simp_rw [map_apply hf (hE.prod hE), prod_apply_symm (hf (hE.prod hE)), preimage_preimage,
mk_preimage_prod],
convert lintegral_zero, ext1 x, refine measure_mono_null (inter_subset_right _ _) h2E
end
lemma measure_inv_null (hμ : is_mul_left_invariant μ) {E : set G} (hE : is_measurable E) :
μ ((λ x, x⁻¹) ⁻¹' E) = 0 ↔ μ E = 0 :=
begin
refine ⟨measure_null_of_measure_inv_null hμ hE, _⟩,
intro h2E,
apply measure_null_of_measure_inv_null hμ (measurable_inv hE),
convert h2E using 2,
exact set.inv_inv
end
lemma measurable_measure_mul_right {E : set G} (hE : is_measurable E) :
measurable (λ x, μ ((λ y, y * x) ⁻¹' E)) :=
begin
suffices :
measurable (λ y, μ ((λ x, (x, y)) ⁻¹' ((λ z : G × G, (1, z.1 * z.2)) ⁻¹' set.prod univ E))),
{ convert this, ext1 x, congr' 1 with y : 1, simp },
apply measurable_measure_prod_mk_right,
exact measurable_const.prod_mk (measurable_fst.mul measurable_snd) (is_measurable.univ.prod hE)
end
lemma lintegral_lintegral_mul_inv (hμ : is_mul_left_invariant μ) (hν : is_mul_left_invariant ν)
(f : G → G → ennreal) (hf : measurable (uncurry f)) :
∫⁻ x, ∫⁻ y, f (y * x) x⁻¹ ∂ν ∂μ = ∫⁻ x, ∫⁻ y, f x y ∂ν ∂μ :=
begin
have h2f : measurable (uncurry $ λ x y, f (y * x) x⁻¹) :=
hf.comp ((measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv),
simp_rw [lintegral_lintegral h2f, lintegral_lintegral hf],
conv_rhs { rw [← map_prod_mul_inv_eq hμ hν] },
symmetry, exact lintegral_map hf ((measurable_snd.mul measurable_fst).prod_mk measurable_fst.inv)
end
lemma measure_mul_right_null (hμ : is_mul_left_invariant μ) {E : set G} (hE : is_measurable E)
(y : G) : μ ((λ x, x * y) ⁻¹' E) = 0 ↔ μ E = 0 :=
begin
rw [← measure_inv_null hμ hE, ← hμ y⁻¹ (measurable_inv hE),
← measure_inv_null hμ (measurable_mul_right y hE)],
convert iff.rfl using 3, ext x, simp,
end
lemma measure_mul_right_ne_zero (hμ : is_mul_left_invariant μ) {E : set G} (hE : is_measurable E)
(h2E : μ E ≠ 0) (y : G) : μ ((λ x, x * y) ⁻¹' E) ≠ 0 :=
(not_iff_not_of_iff (measure_mul_right_null hμ hE y)).mpr h2E
/-- A technical lemma relating two different measures. This is basically [Halmos, §60 Th. A].
Note that if `f` is the characteristic function of a measurable set `F` this states that
`μ F = c * μ E` for a constant `c` that does not depend on `μ`.
There seems to be a gap in the last step of the proof in [Halmos].
In the last line, the equality `g(x⁻¹)ν(Ex⁻¹) = f(x)` holds if we can prove that
`0 < ν(Ex⁻¹) < ∞`. The first inequality follows from §59, Th. D, but I couldn't find the second
inequality. For this reason, we use a compact `E` instead of a measurable `E` as in [Halmos], and
additionally assume that `ν` is a regular measure (we only need that it is finite on compact
sets). -/
lemma measure_lintegral_div_measure [t2_space G] (hμ : is_mul_left_invariant μ)
(hν : is_mul_left_invariant ν) (h2ν : regular ν) {E : set G} (hE : is_compact E) (h2E : ν E ≠ 0)
(f : G → ennreal) (hf : measurable f) :
μ E * ∫⁻ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E) ∂ν = ∫⁻ x, f x ∂μ :=
begin
have Em := hE.is_measurable,
symmetry,
set g := λ y, f y⁻¹ / ν ((λ h, h * y⁻¹) ⁻¹' E),
have hg : measurable g := (hf.comp measurable_inv).ennreal_div
((measurable_measure_mul_right Em).comp measurable_inv),
rw [← set_lintegral_one, ← lintegral_indicator _ Em,
← lintegral_lintegral_mul (measurable_const.indicator Em) hg,
← lintegral_lintegral_mul_inv hμ hν],
swap, { exact ((measurable_const.indicator Em).comp measurable_fst).ennreal_mul
(hg.comp measurable_snd) },
have mE : ∀ x : G, measurable (λ y, ((λ z, z * x) ⁻¹' E).indicator (λ z, (1 : ennreal)) y) :=
λ x, measurable_const.indicator (measurable_mul_right _ Em),
have : ∀ x y, E.indicator (λ (z : G), (1 : ennreal)) (y * x) =
((λ z, z * x) ⁻¹' E).indicator (λ (b : G), 1) y,
{ intros x y, symmetry, convert indicator_comp_right (λ y, y * x), ext1 z, simp },
have h3E : ∀ y, ν ((λ x, x * y) ⁻¹' E) ≠ ⊤ :=
λ y, ennreal.lt_top_iff_ne_top.mp (h2ν.lt_top_of_is_compact $
(homeomorph.mul_right _).compact_preimage.mpr hE),
simp_rw [this, lintegral_mul_const _ (mE _), lintegral_indicator _ (measurable_mul_right _ Em),
set_lintegral_one, g, inv_inv,
ennreal.mul_div_cancel' (measure_mul_right_ne_zero hν Em h2E _) (h3E _)]
end
/-- This is roughly the uniqueness (up to a scalar) of left invariant Borel measures on a second
countable locally compact group. The uniqueness of Haar measure is proven from this in
`measure_theory.measure.haar_measure_unique` -/
lemma measure_mul_measure_eq [t2_space G] (hμ : is_mul_left_invariant μ)
(hν : is_mul_left_invariant ν) (h2ν : regular ν) {E F : set G}
(hE : is_compact E) (hF : is_measurable F) (h2E : ν E ≠ 0) : μ E * ν F = ν E * μ F :=
begin
have h1 := measure_lintegral_div_measure hν hν h2ν hE h2E (F.indicator (λ x, 1))
(measurable_const.indicator hF),
have h2 := measure_lintegral_div_measure hμ hν h2ν hE h2E (F.indicator (λ x, 1))
(measurable_const.indicator hF),
rw [lintegral_indicator _ hF, set_lintegral_one] at h1 h2,
rw [← h1, mul_left_comm, h2],
end
end measure_theory
|
a365a1c6599548fa6afa65f3f5b2045fac10f615 | a7eef317ddec01b9fc6cfbb876fe7ac00f205ac7 | /src/algebra/homology/homology.lean | 1bc3cb3e8b821024f88fac487e7dfb0073d7df32 | [
"Apache-2.0"
] | permissive | kmill/mathlib | ea5a007b67ae4e9e18dd50d31d8aa60f650425ee | 1a419a9fea7b959317eddd556e1bb9639f4dcc05 | refs/heads/master | 1,668,578,197,719 | 1,593,629,163,000 | 1,593,629,163,000 | 276,482,939 | 0 | 0 | null | 1,593,637,960,000 | 1,593,637,959,000 | null | UTF-8 | Lean | false | false | 5,008 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Markus Himmel
-/
import algebra.homology.chain_complex
import category_theory.limits.shapes.images
import category_theory.limits.shapes.kernels
/-!
# Cohomology groups for cochain complexes
We setup that part of the theory of cohomology groups which works in
any category with kernels and images.
We define the cohomology groups themselves, and show that they induce maps on kernels.
Under the additional assumption that our category has equalizers and functorial images, we construct
induced morphisms on images and functorial induced morphisms in cohomology.
-/
universes v u
namespace cochain_complex
open category_theory
open category_theory.limits
variables {V : Type u} [category.{v} V] [has_zero_morphisms V]
section
variable [has_kernels V]
/-- The map induced by a chain map between the kernels of the differentials. -/
def kernel_map {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
kernel (C.d i) ⟶ kernel (C'.d i) :=
kernel.lift _ (kernel.ι _ ≫ f.f i)
begin
rw [category.assoc, ←comm_at f, ←category.assoc, kernel.condition, has_zero_morphisms.zero_comp],
end
@[simp, reassoc]
lemma kernel_map_condition {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
kernel_map f i ≫ kernel.ι (C'.d i) = kernel.ι (C.d i) ≫ f.f i :=
by simp [kernel_map]
@[simp]
lemma kernel_map_id (C : cochain_complex V) (i : ℤ) :
kernel_map (𝟙 C) i = 𝟙 _ :=
(cancel_mono (kernel.ι (C.d i))).1 $ by simp
@[simp]
lemma kernel_map_comp {C C' C'' : cochain_complex V} (f : C ⟶ C')
(g : C' ⟶ C'') (i : ℤ) :
kernel_map (f ≫ g) i = kernel_map f i ≫ kernel_map g i :=
(cancel_mono (kernel.ι (C''.d i))).1 $ by simp
/-- The kernels of the differentials of a cochain complex form a ℤ-graded object. -/
def kernel_functor : cochain_complex V ⥤ graded_object ℤ V :=
{ obj := λ C i, kernel (C.d i),
map := λ X Y f i, kernel_map f i }
end
section
variables [has_images V] [has_image_maps V]
/-- A morphism of cochain complexes induces a morphism on the images of the differentials in every
degree. -/
abbreviation image_map {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
image (C.d i) ⟶ image (C'.d i) :=
image.map (arrow.hom_mk' (cochain_complex.comm_at f i).symm)
@[simp]
lemma image_map_ι {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
image_map f i ≫ image.ι (C'.d i) = image.ι (C.d i) ≫ f.f (i + 1) :=
image.map_hom_mk'_ι (cochain_complex.comm_at f i).symm
end
/-!
At this point we assume that we have all images, and all equalizers.
We need to assume all equalizers, not just kernels, so that
`factor_thru_image` is an epimorphism.
-/
variables [has_kernels V] [has_images V] [has_equalizers V]
/--
The connecting morphism from the image of `d i` to the kernel of `d (i+1)`.
-/
def image_to_kernel_map (C : cochain_complex V) (i : ℤ) :
image (C.d i) ⟶ kernel (C.d (i+1)) :=
kernel.lift _ (image.ι (C.d i)) $ (cancel_epi (factor_thru_image (C.d i))).1 $ by simp
@[simp, reassoc]
lemma image_to_kernel_map_condition (C : cochain_complex V) (i : ℤ) :
image_to_kernel_map C i ≫ kernel.ι (C.d (i + 1)) = image.ι (C.d i) :=
by simp [image_to_kernel_map]
@[reassoc]
lemma induced_maps_commute [has_image_maps V] {C C' : cochain_complex V} (f : C ⟶ C')
(i : ℤ) :
image_to_kernel_map C i ≫ kernel_map f (i + 1) = image_map f i ≫ image_to_kernel_map C' i :=
by { ext, simp }
variables [has_cokernels V]
/-- The `i`-th cohomology group of the cochain complex `C`. -/
def cohomology (C : cochain_complex V) (i : ℤ) : V :=
cokernel (image_to_kernel_map C (i-1))
variables [has_image_maps V]
/-- A morphism of cochain complexes induces a morphism in cohomology at every degree. -/
def cohomology_map {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
C.cohomology i ⟶ C'.cohomology i :=
cokernel.desc _ (kernel_map f (i - 1 + 1) ≫ cokernel.π _) $ by simp [induced_maps_commute_assoc]
@[simp, reassoc]
lemma cohomology_map_condition {C C' : cochain_complex V} (f : C ⟶ C') (i : ℤ) :
cokernel.π (image_to_kernel_map C (i - 1)) ≫ cohomology_map f i =
kernel_map f (i - 1 + 1) ≫ cokernel.π _ :=
by simp [cohomology_map]
@[simp]
lemma cohomology_map_id (C : cochain_complex V) (i : ℤ) :
cohomology_map (𝟙 C) i = 𝟙 (cohomology C i) :=
begin
ext,
simp only [cohomology_map_condition, kernel_map_id, category.id_comp],
erw [category.comp_id]
end
@[simp]
lemma cohomology_map_comp {C C' C'' : cochain_complex V} (f : C ⟶ C') (g : C' ⟶ C'') (i : ℤ) :
cohomology_map (f ≫ g) i = cohomology_map f i ≫ cohomology_map g i :=
by { ext, simp }
/-- The cohomology functor from cochain complexes to `ℤ` graded objects in `V`. -/
def cohomology_functor : cochain_complex V ⥤ graded_object ℤ V :=
{ obj := λ C i, cohomology C i,
map := λ C C' f i, cohomology_map f i }
end cochain_complex
|
2cff2572f6237ae706e40604db97c705040cdeae | 75c54c8946bb4203e0aaf196f918424a17b0de99 | /src/cantor_space.lean | d60bf6d6a84caa3fc60e42f0517fcf8902b7f6f5 | [
"Apache-2.0"
] | permissive | urkud/flypitch | 261e2a45f1038130178575406df8aea78255ba77 | 2250f5eda14b6ef9fc3e4e1f4a9ac4005634de5c | refs/heads/master | 1,653,266,469,246 | 1,577,819,679,000 | 1,577,819,679,000 | 259,862,235 | 1 | 0 | Apache-2.0 | 1,588,147,244,000 | 1,588,147,244,000 | null | UTF-8 | Lean | false | false | 22,249 | lean | /-
Copyright (c) 2019 The Flypitch Project. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jesse Han, Floris van Doorn
-/
import .regular_open_algebra
universes u v
local attribute [instance] classical.prop_decidable
/- Some facts about Cantor spaces: topological spaces of the form (set α) -/
open topological_space lattice
@[instance, priority 1000]def Prop_space : topological_space Prop := ⊥
instance discrete_Prop : discrete_topology Prop := ⟨rfl⟩
instance product_topology {α : Type*} : topological_space (set α) :=
Pi.topological_space
lemma eq_true_of_provable {p : Prop} (h : p) : (p = true) := by simp[h]
lemma eq_false_of_provable_neg {p : Prop} (h : ¬ p) : (p = false) := by finish
@[reducible, simp]noncomputable def Prop_to_bool (p : Prop) : bool :=
by {haveI := classical.prop_decidable p, by_cases p, exact true, exact false}
@[simp]lemma Prop_to_bool_true : Prop_to_bool true = tt := by simp
@[simp]lemma Prop_to_bool_false : Prop_to_bool false = ff := by simp
noncomputable def equiv_Prop_bool : equiv Prop bool :=
{ to_fun := Prop_to_bool,
inv_fun := λ b, by {cases b, exact false, exact true},
left_inv := λ p, by {by_cases p, rw[eq_true_of_provable h, Prop_to_bool_true],
rw[eq_false_of_provable_neg h, Prop_to_bool_false]},
right_inv := λ x, by cases x; finish }
noncomputable instance Prop_encodable : encodable Prop :=
@encodable.of_equiv _ _ (by apply_instance) equiv_Prop_bool
instance Prop_separable : separable_space Prop :=
{ exists_countable_closure_eq_univ :=
by {use set.univ, refine ⟨set.countable_encodable _, by simp⟩}}
@[ematch]lemma is_open_of_compl_closed {α : Type*} [topological_space α] {S : set α} (H : (: is_closed (-S) :)) : is_open S :=
by rwa[<-is_closed_compl_iff]
@[ematch]lemma is_closed_of_compl_open {α : Type*} [topological_space α] {S : set α} (H : (: is_open (-S) :)) : is_closed S :=
by rwa[<-is_open_compl_iff]
def clopens (α : Type*) [topological_space α] : Type* := {S : set α // is_clopen S}
instance clopens_lattice {α : Type*} [topological_space α] : lattice (clopens α) :=
{ sup := λ S₁ S₂, ⟨S₁.1 ∪ S₂.1, by {apply is_clopen_union, tidy}⟩,
le := λ S₁ S₂, S₁.1 ⊆ S₂.1,
lt := λ S₁ S₂, S₁.1 ⊆ S₂.1 ∧ S₁.1 ≠ S₂.1,
le_refl := by tidy,
le_trans := by tidy,
lt_iff_le_not_le :=
by {intros; split; intros,
{split, {from a_1.left},
intro H, apply a_1.right, refine le_antisymm _ _, from a_1.left, from ‹_›},
{/- `tidy` says -/ cases a_1, cases b, cases a, cases a_property,
cases b_property, dsimp at *, fsplit,
work_on_goal 0 { assumption }, intros a, induction a, solve_by_elim}},
le_antisymm := by {intros, apply subtype.eq, refine le_antisymm _ _; from ‹_›},
le_sup_left := by {intros, simp, intros x Hx, left, from ‹_›},
le_sup_right := by {intros, simp, intros x Hx, right, from ‹_›},
sup_le := by {intros, intros x Hx, cases Hx, from a_1 ‹_›, from a_2 ‹_›},
inf := λ S₁ S₂, ⟨S₁.1 ∩ S₂.1, by {apply is_clopen_inter, from S₁.property, from S₂.property}⟩,
inf_le_left := by {intros, simp, intros x Hx, from Hx.left},
inf_le_right := by {intros, simp, intros x Hx, from Hx.right},
le_inf := by {intros, simp, intros x Hx, from ⟨a_1 ‹_›, a_2 ‹_›⟩}}
instance clopens_bounded_lattice {α : Type*} [topological_space α] : bounded_lattice (clopens α) :=
{top := ⟨set.univ, is_clopen_univ⟩,
le_top := by tidy,
bot := ⟨∅, is_clopen_empty⟩,
bot_le := by tidy,
.. clopens_lattice}
noncomputable def finset_clopens_mk {α : Type*} [topological_space α] {X : finset (set α)} (H : ∀ S ∈ X, is_clopen S) : finset (clopens α) :=
begin
apply finset.image, show finset _, from finset.attach X,
intro x, cases x with x Hx, use x, from H x Hx
end
lemma is_clopen_finite_inter {α : Type*} [topological_space α] {X : finset (set α)}
(H_X : ∀ S ∈ X, is_clopen S) : is_clopen (finset.inf X id) :=
begin
revert H_X, apply finset.induction_on X, intro _, from is_clopen_univ,
intros a A H_a H_A IH, simp at ⊢ IH, apply is_clopen_inter,
from IH a (or.inl rfl), apply H_A, intros S H_S, from IH S (or.inr H_S)
end
lemma is_clopen_finite_inter' {α α' : Type*} [topological_space α] {X : finset α'} {f : α' → set (α)} (H_f : ∀ x ∈ X, is_clopen (f x)) : is_clopen (finset.inf X f) :=
begin
revert H_f, apply finset.induction_on X, intro _, from is_clopen_univ,
intros a A H_a H_A IH, simp at ⊢ IH, apply is_clopen_inter,
from IH a (or.inl rfl), apply H_A, intros S H_S, from IH S (or.inr H_S)
end
namespace cantor_space
section cantor_space
variables {α : Type*}
def principal_open (x : α) : set (set α) := {S | x ∈ S}
def co_principal_open (x : α) : set (set α) := {S | x ∉ S}
@[simp]lemma neg_principal_open {x : α} : co_principal_open x = -(principal_open x) :=
by unfold principal_open; refl
@[simp]lemma neg_co_principal_open {x : α} : - (co_principal_open x) = principal_open x :=
by {simp[principal_open]}
-- lemma is_open_induced_iff' {α β : Type*} {f : α → β} [t : topological_space β] {s : set α} {f : α → β} :
-- (∃t, is_open t ∧ f ⁻¹' t = s) ↔ @topological_space.is_open α (t.induced f) s := is_open_induced_iff.symm
def opens_over (x : α) : set(set(set α)) := {principal_open x, co_principal_open x, set.univ, ∅}
@[simp]lemma principal_open_mem_opens_over {x : α} : principal_open x ∈ opens_over x :=
by {right,right,right, from set.mem_singleton _}
@[simp]lemma co_principal_open_mem_opens_over {x : α} : co_principal_open x ∈ opens_over x :=
by {right,right,left, refl}
@[simp]lemma univ_mem_opens_over {x : α} : set.univ ∈ opens_over x :=
by {right,left, refl}
@[simp]lemma empty_mem_opens_over {x : α} : ∅ ∈ opens_over x :=
by {left, refl}
/-- Given a : α, τ is the topology induced by pulling back the
discrete topology on Prop along the a'th projection map -/
def τ (a : α) : topological_space (set α) :=
induced (λS, a ∈ S) (by apply_instance : topological_space Prop)
lemma fiber_over_false {α : Type*} {a : α} : (λ x : set α, a ∈ x) ⁻¹' {false} = {y | a ∉ y} :=
begin
ext, split; simp[set.mem_preimage]
end
lemma fiber_over_true {α : Type*} {a : α} : (λ x : set α, a ∈ x) ⁻¹' {true} = {y | a ∈ y} :=
begin
ext, split; simp[set.mem_preimage]
end
lemma opens_over_sub_τ (a : α) : opens_over a ⊆ (τ a).is_open :=
begin
unfold τ, intros S HS, unfold opens_over at HS,
repeat{cases HS}, apply is_open_empty, apply _root_.is_open_univ,
apply is_open_induced_iff.mpr, fsplit, exact {false}, fsplit,
apply is_open_discrete,
{ext1, ext1, dsimp at *, fsplit,
work_on_goal 0 { intros a_1 a_2, cases a_1,
work_on_goal 1 { assumption } }, work_on_goal 1 { intros a_1 },
rwa[<-a_1], rwa[fiber_over_false]},
apply is_open_induced_iff.mpr, fsplit, exact {true}, fsplit,
apply is_open_discrete,
{ext1, ext1, fsplit,
work_on_goal 0 { intros a_1, cases a_1, work_on_goal 0 { cc },
dsimp at a_1, cases a_1 }, intros a_1, rwa[fiber_over_true]},
end
lemma opens_over_le_τ (a : α) : τ a ≤ generate_from (opens_over a) :=
by { rw [le_generate_from_iff_subset_is_open], exact opens_over_sub_τ a }
lemma τ_le_product_topology (a : α) : product_topology ≤ τ a :=
infi_le _ _
lemma le_iff_opens_sub {β : Type*} {τ₁ τ₂ : topological_space β} :
τ₂ ≤ τ₁ ↔ {S | τ₁.is_open S} ⊆ {S | τ₂.is_open S} := by refl
lemma τ_le_opens_over (a : α) : generate_from (opens_over a) ≤ τ a :=
begin
apply le_iff_opens_sub.mpr, rintros X ⟨H_w, H_h_left, rfl⟩,
by_cases htrue : true ∈ H_w; by_cases hfalse : false ∈ H_w,
{ constructor, unfold opens_over, repeat{split}, right,left,
ext, by_cases a ∈ x, split, from λ _, trivial, intro, simp[h], from ‹_›,
split, from λ _, trivial, intro, simp[h], from ‹_›},
{ constructor, unfold opens_over, repeat{split}, right, right, right,
simp, ext, by_cases a ∈ x, split, intro H, simp[principal_open], from ‹_›,
intro H, simp*, split; intros, simp [h, hfalse] at a_1, cases a_1,
simp[principal_open, *, -a_1] at a_1, cases a_1},
{ constructor, unfold opens_over, repeat{split}, right, right, left,
simp, ext, split; intros; simp[*, -a_1] at a_1; by_cases a ∈ x,
tidy {tactics := with_cc}, },
{ have : H_w = ∅, ext, split; intros, by_cases x; simp* at a_1; cases a_1, cases a_1,
subst this, simp, by apply @is_open_empty _ (generate_from _)}
end
@[simp]lemma is_open_generated_from_basic {β : Type*} [topological_space β] {s : set (set β)} {x ∈ s} :
is_open (generate_from s) x := by {constructor, from ‹_›}
lemma is_open_principal_open {a : α} : is_open (principal_open a) :=
by { apply (le_trans (τ_le_product_topology _) (opens_over_le_τ a)), simp[opens_over] }
lemma is_open_co_principal_open {a : α} : is_open (co_principal_open a) :=
by { apply (le_trans (τ_le_product_topology _) (opens_over_le_τ a)), simp[opens_over] }
lemma is_closed_principal_open {a : α} : is_closed (principal_open a) :=
by {apply is_closed_of_compl_open, from is_open_co_principal_open}
lemma is_closed_co_principal_open {a : α} : is_closed (co_principal_open a) :=
by {apply is_closed_of_compl_open,
simp only [neg_principal_open, lattice.neg_neg], from is_open_principal_open}
lemma is_clopen_principal_open {a : α} : is_clopen (principal_open a) :=
⟨is_open_principal_open, is_closed_principal_open⟩
lemma is_clopen_co_principal_open {a : α} : is_clopen (co_principal_open a) :=
⟨is_open_co_principal_open, is_closed_co_principal_open⟩
@[reducible]def principal_open_finset (F : finset α) : set (set α) := {S | F.to_set ⊆ S}
lemma mem_principal_open_finset_iff {F : finset α} {x : set α} : x ∈ (principal_open_finset F) ↔ (↑F : set α) ⊆ x := by refl
@[simp]lemma principal_open_finset_insert {F : finset α} {a : α} : principal_open_finset (insert a F) = principal_open_finset {a} ∩ principal_open_finset F :=
begin
ext x, /- `tidy` says -/ dsimp at *, fsplit, work_on_goal 0 { intros a_1, fsplit, work_on_goal 0 { intros a_2 a_3, cases a_3, work_on_goal 0 { induction a_3 }, work_on_goal 1 { cases a_3 } }, work_on_goal 1 { intros a_2 a_3 } }, work_on_goal 2 { intros a_1 a_2 a_3, cases a_1 },
{ unfold finset.to_set at a_1, exact a_1 (by simp : a_2 ∈ _) },
{ unfold finset.to_set at a_1, exact a_1 (by finish : a_2 ∈ _) },
{ unfold finset.to_set at *, simp[set.mem_insert_iff] at a_3,
cases a_3 with a_3₁ a_3₂,
{ finish },
{ exact a_1_right ‹_› } }
end
lemma principal_open_finset_eq_inter (F : finset α) : principal_open_finset F = (finset.inf F (principal_open)) :=
begin
apply finset.induction_on F,
{tidy},
intros a A h_a IH, simp, rw[<-IH], ext, split; intros,
tidy, apply a_1_left, simp[finset.to_set]
end
@[reducible] def co_principal_open_finset (F : finset α) : set (set α) := {S | F.to_set ⊆ (-S)}
@[simp]lemma co_principal_open_finset_insert {F : finset α} {a : α} : co_principal_open_finset (insert a F) = co_principal_open_finset {a} ∩ co_principal_open_finset F :=
begin
ext x, /- `tidy` says -/ dsimp at *, fsplit, work_on_goal 0 { intros a_1, fsplit, work_on_goal 0 { intros a_2 a_3, cases a_3, work_on_goal 0 { induction a_3 }, work_on_goal 1 { cases a_3 } }, work_on_goal 1 { intros a_2 a_3 } }, work_on_goal 2 { intros a_1 a_2 a_3, cases a_1 },
{ unfold finset.to_set at a_1, exact a_1 (by simp : a_2 ∈ _) },
{ unfold finset.to_set at a_1, exact a_1 (by finish : a_2 ∈ _) },
{ unfold finset.to_set at *, simp[set.mem_insert_iff] at a_3,
cases a_3 with a_3₁ a_3₂,
{ finish },
{ exact a_1_right ‹_› } }
end
lemma co_principal_open_finset_eq_inter (F : finset α) : co_principal_open_finset F = (finset.inf F (co_principal_open)) :=
begin
apply finset.induction_on F,
{tidy},
intros a A h_a IH, simp, rw[<-IH], ext, split; intros,
tidy, apply a_1_left, simp[finset.to_set], from a_1
end
lemma is_clopen_principal_open_finset (F : finset α) : is_clopen (principal_open_finset F) :=
begin
rw[principal_open_finset_eq_inter], apply is_clopen_finite_inter',
from λ _ _, is_clopen_principal_open
end
lemma is_clopen_co_principal_open_finset (F : finset α) : is_clopen (co_principal_open_finset F) :=
begin
rw[co_principal_open_finset_eq_inter], apply is_clopen_finite_inter',
from λ _ _, is_clopen_co_principal_open
end
lemma product_topology_generate_from : (product_topology : topological_space (set α)) = generate_from (⋃(a : α), opens_over a) :=
begin
apply le_antisymm,
{ unfold product_topology Pi.topological_space,
apply generate_from_mono,
intros X HX, rcases HX with ⟨W, ⟨H₁, H₂⟩⟩, simp, cases H₁ with a Ha,
use τ a, split, use a, refl, apply opens_over_le_τ a, constructor, cc },
refine le_infi _, intro a,
refine le_trans _ (τ_le_opens_over a), apply generate_from_mono,
intros X H, constructor, simp, use a, exact H
end
def standard_basis : set (set (set α)) :=
{T : set (set α) | ∃ p_ins p_out : finset α, T = (finset.inf p_ins principal_open) ∩ (finset.inf p_out co_principal_open) ∧ p_ins ∩ p_out = ∅} ∪ {∅}
lemma ins₁_out₂_disjoint {x : set α} {p_ins₁ p_out₁ p_ins₂ p_out₂ : finset α}
(H_mem₁ : x ∈ finset.inf p_ins₁ principal_open ∩ finset.inf p_out₁ co_principal_open)
(H_mem₂ : x ∈ finset.inf p_ins₂ principal_open ∩ finset.inf p_out₂ co_principal_open)
(H_disjoint₁ : p_ins₁ ∩ p_out₁ = ∅) (H_disjoint₂ : p_ins₂ ∩ p_out₂ = ∅)
{a : α} (Ha_left : a ∈ p_ins₁)
(Ha_right : a ∈ p_out₂) : false :=
begin
rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter] at H_mem₁ H_mem₂,
suffices : a ∉ x ∧ a ∈ x, from (not_and_self _).mp this, split,
rw[set.mem_inter_iff] at H_mem₂, apply H_mem₂.right ‹_›,
rw[set.mem_inter_iff] at H_mem₁, apply H_mem₁.left ‹_›
end
@[simp]lemma principal_open_mem_standard_basis {a : α} : (principal_open a) ∈ (@standard_basis α) :=
by {simp[standard_basis], right, use {a}, use ∅, tidy}
@[simp]lemma co_principal_open_mem_standard_basis {a : α} : co_principal_open a ∈ (@standard_basis α) :=
by {simp[standard_basis], right, use ∅, use {a}, tidy}
lemma univ_mem_standard_basis : set.univ ∈ (@standard_basis α) :=
by {simp[standard_basis], use ∅, use ∅, tidy}
lemma intersection_standard_basis_nonempty' {α : Type*} {p_ins p_out : finset α} {H : p_ins ∩ p_out = ∅} : ∃ X, X ∈ finset.inf p_ins principal_open ∩ finset.inf p_out co_principal_open :=
begin
use p_ins.to_set, rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter],
simp[finset.to_set], intros x Hx, simp, intro H', apply ((finset.ext).mp H x).mp,
rw[finset.mem_inter], from ⟨‹_›,‹_›⟩
end
lemma intersection_standard_basis_nonempty {α : Type*} {T : set (set α)} {p_ins p_out : finset α} {H_eq : T = finset.inf p_ins principal_open ∩ finset.inf p_out co_principal_open} {H : p_ins ∩ p_out = ∅} : ¬⋂₀ finset.to_set (finset.image principal_open p_ins ∪ finset.image co_principal_open p_out) = ∅ :=
begin
intro H', simp[finset.to_set] at H', replace H' := (set.ext_iff _ _).mp H',
cases @intersection_standard_basis_nonempty' _ p_ins p_out ‹_› with a H_a, subst H_eq,
rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter] at H_a, cases H_a,
specialize H' a, apply H'.mp, simp, simp[not_forall] at H',
rcases H' with ⟨s, ⟨⟨w', Hw'_1, Hw'_2⟩, H_a'⟩⟩; intros t Ht; cases Ht;
rcases Ht with ⟨w, H_w, H_w_eq⟩; subst H_w_eq, tidy
end
lemma standard_basis_reindex {α : Type*} {T : set (set α)} {p_ins p_out : finset α} {H_eq : T = finset.inf p_ins principal_open ∩ finset.inf p_out co_principal_open} {H : p_ins ∩ p_out = ∅} : ⋂₀ finset.to_set (finset.image principal_open p_ins ∪ finset.image co_principal_open p_out) = T :=
begin
subst H_eq, rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter],
simp[finset.to_set], ext; split; intro H',
{rw[set.mem_sInter] at H',
simp[principal_open_finset, co_principal_open_finset], split,
intros a Ha, specialize H' (principal_open a), apply H',
right, use a, from ⟨‹_›, rfl⟩,
intros a Ha, specialize H' (co_principal_open a), apply H',
left, use a, from ⟨‹_›, rfl⟩,},
{rw[set.mem_sInter], intros T hT, simp at hT, cases hT,
simp[finset.to_set] at H', tidy}
end
lemma is_topological_basis_standard_basis : @is_topological_basis (set α) _ standard_basis :=
begin
repeat{split},
{intros t₁ H₁ t₂ H₂ x Hx, cases H₁; cases H₂,
{rcases H₁ with ⟨p_ins₁, p_out₁, H₁, H₁'⟩, rcases H₂ with ⟨p_ins₂, p_out₂, H₂, H₂'⟩,
use (finset.inf (p_ins₁ ∪ p_ins₂) principal_open) ∩ (finset.inf (p_out₁ ∪ p_out₂) co_principal_open), split, swap, split,
split, rw[<-principal_open_finset_eq_inter], unfold principal_open_finset,
simp, intros a Ha, simp[finset.to_set] at Ha, subst H₁, subst H₂,
simp at Hx, rcases Hx with ⟨⟨Hx1, Hx2⟩, Hx3, Hx4⟩, cases Ha,
rw[<-principal_open_finset_eq_inter] at Hx1, apply Hx1, from Ha,
rw[<-principal_open_finset_eq_inter] at Hx3, apply Hx3, from Ha,
rw[<-co_principal_open_finset_eq_inter], unfold co_principal_open_finset,
simp, intros a Ha, simp[finset.to_set] at Ha, subst H₁, subst H₂,
simp at Hx, rcases Hx with ⟨⟨Hx1, Hx2⟩, Hx3, Hx4⟩, cases Ha,
rw[<-co_principal_open_finset_eq_inter] at Hx2, apply Hx2, from Ha,
rw[<-co_principal_open_finset_eq_inter] at Hx4, apply Hx4, from Ha,
rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter],
intros a Ha, unfold principal_open_finset co_principal_open_finset at Ha,
cases Ha with Ha₁ Ha₂, substs H₁ H₂, split,
rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter],
split, intros x Hx, apply Ha₁, simp[finset.to_set], left, from Hx,
intros x Hx, apply Ha₂, simp[finset.to_set], left, from Hx,
rw[<-principal_open_finset_eq_inter, <-co_principal_open_finset_eq_inter],
split, intros x Hx, apply Ha₁, simp[finset.to_set], right, from Hx,
intros x Hx, apply Ha₂, simp[finset.to_set], right, from Hx,
use (p_ins₁ ∪ p_ins₂), use (p_out₁ ∪ p_out₂), refine ⟨rfl, _⟩,
simp only [finset.inter_distrib_left, finset.inter_distrib_right],
ext1, split; intro Ha, swap, cases Ha, simp [H₁', H₂'] at Ha,
repeat{cases Ha}; exfalso; substs H₁ H₂; cases Hx,
from ins₁_out₂_disjoint Hx_left Hx_right ‹_› ‹_› Ha_left Ha_right,
from ins₁_out₂_disjoint Hx_right Hx_left ‹_› ‹_› Ha_right Ha_left
},
{replace H₂ := set.mem_singleton_iff.mp H₂, subst H₂, exfalso, simpa using Hx},
{replace H₁ := set.mem_singleton_iff.mp H₁, subst H₁, exfalso, simpa using Hx},
{replace H₁ := set.mem_singleton_iff.mp H₁, subst H₁, exfalso, simpa using Hx}
},
{ext, split; intros, trivial, rw[set.mem_sUnion], use set.univ,
use univ_mem_standard_basis},
{rw[product_topology_generate_from], refine le_antisymm _ _, swap,
{apply generate_from_mono,
intros X H_X, rcases H_X with ⟨w, ⟨a, H_w⟩, H_X⟩,
unfold standard_basis, simp, subst H_w, repeat{cases H_X}, left, refl,
right, use ∅, use ∅, {simp, refl}, right, use ∅, use {a},
{/- `tidy` says -/ simp, ext1, fsplit, work_on_goal 0
{ intros a_1, fsplit, work_on_goal 0 { fsplit },
fsplit, work_on_goal 0 { assumption }, fsplit },
intros a_1 a_2, cases a_1, cases a_1_right, solve_by_elim}, right, use {a}, use ∅,
{/- `tidy` says -/ simp, ext1, fsplit, work_on_goal 0
{ intros a_1, fsplit, work_on_goal 0 { fsplit, work_on_goal 0 { assumption }, fsplit },
fsplit }, intros a_1, cases a_1, cases a_1_left, assumption}},
{
apply le_generate_from_iff_subset_is_open.mpr, intros T hT, unfold standard_basis at hT,
cases hT with hT h_empty, swap, rw[set.mem_singleton_iff] at h_empty, subst h_empty,
apply @is_open_empty _ (generate_from _),
simp, have := is_topological_basis_of_subbasis (product_topology_generate_from), swap, from α,
rw[<-product_topology_generate_from],
apply is_open_of_is_topological_basis this, simp,
rcases hT with ⟨p_ins, p_out, H_eq, H⟩,
use ((finset.image principal_open p_ins) ∪ (finset.image co_principal_open p_out)).to_set,
split, split, from finset.finite_to_set _, split,
apply finset.induction_on p_ins, apply finset.induction_on p_out,
simp, intros x Hx, cases Hx, intros a A H_a H_A, simp, intros x Hx,
simp[finset.to_set] at Hx, cases Hx, rw[set.mem_Union], use a, rw[Hx],
rw[<-neg_principal_open], from co_principal_open_mem_opens_over,
rw[set.mem_Union], cases Hx with a Hx, use a, rw[<-Hx.right],
rw[<-neg_principal_open], from co_principal_open_mem_opens_over,
intros a A H_a H_A, simp, intros x Hx, simp[finset.to_set] at Hx, cases Hx,
rw[Hx], rw[set.mem_Union], use a, from principal_open_mem_opens_over,
cases Hx with Hx Hx', rw[set.mem_Union], cases Hx with a Hx,
use a, rw[<-Hx.right, <-neg_principal_open], from co_principal_open_mem_opens_over,
cases Hx' with a Hx, rw[set.mem_Union],
use a, rw[<-Hx.right], from principal_open_mem_opens_over,
by {apply intersection_standard_basis_nonempty; from ‹_›},
by {apply standard_basis_reindex; from ‹_›}
}}
end
open cardinal
lemma countable_chain_condition_set {α : Type u} : countable_chain_condition (set α) :=
begin
apply countable_chain_condition_pi, intros s hs,
apply countable_chain_condition_of_countable, apply le_of_lt,
convert @power_lt_omega (mk (ulift Prop)) (mk s) _ _ using 1,
{ refine quotient.sound ⟨equiv.arrow_congr (equiv.refl _) equiv.ulift.symm⟩ },
{ rw [prop_eq_two], convert cardinal.nat_lt_omega 2, rw [nat.cast_bit0, nat.cast_one] },
rwa lt_omega_iff_finite
end
end cantor_space
end cantor_space
|
93f824fd05f61ad4d091d529ab373c47d44ffc9a | c45b34bfd44d8607a2e8762c926e3cfaa7436201 | /uexp/src/uexp/ucongr.lean | f7baedb474abd9a3c3f16de2a17a19574abd1209 | [
"BSD-2-Clause"
] | permissive | Shamrock-Frost/Cosette | b477c442c07e45082348a145f19ebb35a7f29392 | 24cbc4adebf627f13f5eac878f04ffa20d1209af | refs/heads/master | 1,619,721,304,969 | 1,526,082,841,000 | 1,526,082,841,000 | 121,695,605 | 1 | 0 | null | 1,518,737,210,000 | 1,518,737,210,000 | null | UTF-8 | Lean | false | false | 10,766 | lean | import .u_semiring
import .cosette_lemmas
import .cosette_tactics
/- congruence procedure for u-semiring -/
open tactic
private meta def flip_ueq : expr → tactic unit
| `(%%a * %%b) := flip_ueq a >> flip_ueq b
| `(%%t₁ ≃ %%t₂) :=
if t₁ > t₂ then return ()
else do h ← to_expr ``(eq_symm %%t₁ %%t₂),
try $ rewrite_target h,
return ()
| _ := return ()
-- walk the product and normalize equal pred,
-- we maintain an invariant, a ≃ b (a > b)
meta def unify_ueq : tactic unit := do
t ← tactic.target,
match t with
| `(%%a = %%b) := flip_ueq a >> flip_ueq b
| _ := failed
end
meta def remove_all_unit : tactic unit :=
`[repeat {rw time_one <|> rw time_one'}]
-- collect ueq (equality predicate) from prod
meta def collect_ueq : expr → tactic (list expr)
| `(%%a * %%b) :=
do l ← collect_ueq a,
r ← collect_ueq b,
return (l ++ r)
| e := match e with
| `(%%a ≃ %%b) := return [e]
| _ := return []
end
-- collect ueq from lhs of goal
meta def collect_lhs_ueq : tactic (list expr) :=
target >>= λ e,
match e with
| `(%%a = _ ) := collect_ueq a
| _ := return []
end
-- make sure all product is right assoc
meta def right_assoc :=
`[repeat {rewrite time_assoc}]
-- make sure ueq is in front of relation
private meta def ueq_right_order : list expr → bool
| [x] := tt
| (a :: b :: xs) :=
if ((¬(is_ueq a)) && (is_ueq b)) then ff
else ueq_right_order (b::xs)
| [] := tt
-- find the index of relation that is behind ueq
private meta def idx_of_bad : nat → list expr → tactic nat :=
λ pos l,
match l with
| [x] := failure
| (a :: b :: xs) :=
if ((¬(is_ueq a)) && (is_ueq b)) then return (pos+1)
else idx_of_bad (pos+1) (b::xs)
| []:= failure
end
private meta def all_ueq (l: list expr) : tactic bool :=
list.foldl (λ v e, do v' ← v, return $ v' && (is_ueq e)) (return tt) l
private meta def no_ueq (l: list expr) : tactic bool :=
list.foldl (λ v e, do v' ← v, return $ v' && ¬ (is_ueq e)) (return tt) l
meta def add_unit_if_needed : tactic unit := do
lhs ← get_lhs,
l ← ra_product_to_repr lhs,
all_u ← all_ueq l,
no_u ← no_ueq l,
if all_u then applyc `add_unit -- add unit when there is no relation expr
else if no_u then applyc `add_unit_l -- add unit when there is no ueq
else return ()
meta def move_ueq_step : tactic unit := do
lhs ← get_lhs,
l ← ra_product_to_repr lhs,
if ueq_right_order l then do
failed
else do
idx ← idx_of_bad 0 l,
swap_element_forward (idx - 1) l
-- move ueq, TODO: revisit here to get general SPNF form
meta def move_ueq: tactic unit :=
`[right_assoc,
add_unit_if_needed,
repeat {move_ueq_step},
repeat {apply ueq_left_assoc_lem},
repeat {apply ueq_right_assoc_lem},
repeat {apply ueq_right_assoc_lem'},
apply ueq_symm,
repeat {move_ueq_step},
repeat {apply ueq_left_assoc_lem},
repeat {apply ueq_right_assoc_lem},
repeat {apply ueq_right_assoc_lem'}
]
meta def rw_trans : tactic unit :=
do
ueq_dict ← collect_lhs_ueq,
t ← get_lhs,
match t with
| `(((%%a ≃ %%b) * ((%%c ≃ %%d) * _)) * _ * _ ) :=
if (b = c) then
if (a > d) then do
ne ← to_expr ``(%%a ≃ %%d),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_1
else fail "fail to apply ueq_trans_1"
else if (a = c) then
if (b > d) then do
ne ← to_expr ``(%%b ≃ %%d),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_2_g
else if (d > b) then do
ne ← to_expr ``(%%d ≃ %%b),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_2_l
else fail "fail to apply ueq_trans_2_l"
else if (b = d) then
if (a > c) then do
ne ← to_expr ``(%%a ≃ %%c),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_3_g
else if (c > a) then do
ne ← to_expr ``(%%c ≃ %%a),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_3_l
else fail "fail to apply ueq_trans_3_l"
else if (a = d) then
if (c > b) then do
ne ← to_expr ``(%%c ≃ %%b),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_4
else fail "fail to apply ueq_trans_4"
else return () -- do nothing if cannot use trans of ueq
| `((%%a ≃ %%b) * (%%c ≃ %%d) * _ * _) :=
if (b = c) then
if (a > d) then do
ne ← to_expr ``(%%a ≃ %%d),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_1'
else fail "fail to apply ueq_trans_1'"
else if (a = c) then
if (b > d) then do
ne ← to_expr ``(%%b ≃ %%d),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_2_g'
else if (d > b) then do
ne ← to_expr ``(%%d ≃ %%b),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_2_l'
else fail "fail to apply ueq_trans_2_l'"
else if (b = d) then
if (a > c) then do
ne ← to_expr ``(%%a ≃ %%c),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_3_g'
else if (c > a) then do
ne ← to_expr ``(%%c ≃ %%a),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_3_l'
else fail "fail to apply ueq_trans_3_l'"
else if (a = d) then
if (c > b) then do
ne ← to_expr ``(%%c ≃ %%b),
if expr_in ne ueq_dict then return ()
else applyc `ueq_trans_4'
else fail "fail to apply ueq_trans_4'"
else return () -- do nothing if cannot use trans of ueq
| _ := fail "rw_trans fail"
end
meta def ucongr_step : tactic unit := do
repr ← get_lhs_repr1,
let l := list.length repr in
let inner_loop : nat → tactic unit → tactic unit :=
λ iter_num next_iter, do
next_iter,
forward_i_to_j (1+iter_num) 1,
rw_trans in
let outter_loop : nat → tactic unit → tactic unit :=
λ iter_num next_iter, do
next_iter,
forward_i_to_j iter_num 0,
nat.repeat inner_loop (l-1) $ return ()
in do nat.repeat outter_loop l $ return ()
meta def ucongr_lhs : tactic unit := do
ucongr_step,
new_ueq ← get_lhs_repr2,
repeat $ applyc `move_ueq_between_com,
if list.length new_ueq > 1 then do -- progress!
ucongr_lhs
else return ()
meta def subst_step : tactic unit := do
l ← get_lhs,
match l with
| `((%%a ≃ %%b) * %%c * %%d * %%e) := do
ty ← infer_type a,
let body := expr.subst_var a e,
let em : expr := (expr.lam `x binder_info.default ty body),
lem ← to_expr ``(@ueq_subst_in_spnf _ %%a %%b %%c %%d %%em),
try $ rewrite_target lem,
l' ← get_lhs_expr3,
beta_reduction l'
| `((%%a ≃ %%b) * %%c * %%e) := do
ty ← infer_type a,
let body := expr.subst_var a e,
let em : expr := (expr.lam `x binder_info.default ty body),
lem ← to_expr ``(@ueq_subst_in_spnf' _ %%a %%b %%c %%em),
try $ rewrite_target lem,
l' ← get_lhs_expr3,
beta_reduction l'
| _ := return ()
end
private meta def ueq_toporder (e₁ e₂: expr) : bool :=
match e₁ with
| `(%%a ≃ %%b) := match e₂ with
| `(%%c ≃ %%d) := if (d > a) || (d = a) then ff else tt
| _ := tt
end
| _ := tt
end
-- topology sort ueqs, so that we can do a single pass of substition
meta def topsort_lhs : tactic unit := do
repr ← get_lhs_repr1,
sorted ← return $ list.qsort ueq_toporder repr,
origin ← repr_to_product repr,
new ← repr_to_product sorted,
eq_lemma ← to_expr ``(%%origin = %%new),
eq_lemma_name ← mk_fresh_name,
tactic.assert eq_lemma_name eq_lemma,
try ac_refl,
eq_lemma ← resolve_name eq_lemma_name >>= to_expr,
rewrite_target eq_lemma,
clear eq_lemma
meta def subst_lhs : tactic unit := do
topsort_lhs,
repr ← get_lhs_repr1,
let l := list.length repr in
let loop : nat → tactic unit:=
λ iter_num, do
forward_i_to_j iter_num 0,
subst_step in
repeat_or_sol loop l
private meta def remove_dup_step : tactic unit :=
`[repeat {rw ueq_dedup<|> rw ueq_dedup'}]
-- assuming LHS and RHS are already in SPNF
meta def remove_dup_ueq : tactic unit := do
repr ← get_lhs_repr1,
sorted ← return $ list.qsort (λ x y, x > y) repr,
origin ← repr_to_product repr,
new ← repr_to_product sorted,
eq_lemma ← to_expr ``(%%origin = %%new),
eq_lemma_name ← mk_fresh_name,
tactic.assert eq_lemma_name eq_lemma,
try ac_refl,
eq_lemma ← resolve_name eq_lemma_name >>= to_expr,
rewrite_target eq_lemma,
clear eq_lemma,
r2 ← get_lhs_repr1,
remove_dup_step
private meta def remove_pred_step : tactic unit :=
`[repeat {rw pred_cancel <|> rw pred_cancel'}]
meta def remove_dup_pred : tactic unit := do
repr ← get_lhs_repr3,
sorted ← return $ list.qsort (λ x y, x > y) repr,
origin ← repr_to_product repr,
new ← repr_to_product sorted,
eq_lemma ← to_expr ``(%%origin = %%new),
eq_lemma_name ← mk_fresh_name,
tactic.assert eq_lemma_name eq_lemma,
try ac_refl,
eq_lemma ← resolve_name eq_lemma_name >>= to_expr,
rewrite_target eq_lemma,
clear eq_lemma,
remove_pred_step
meta def ucongr : tactic unit := do
solved_or_continue $ (do split_pairs,
solved_or_continue $ (do unify_ueq,
move_ueq,
applyc `add_unit_m,
remove_dup_ueq,
solved_or_continue $ (do applyc `ueq_symm,
remove_dup_ueq,
solved_or_continue $ (do ucongr_lhs,
solved_or_continue $ (do applyc `ueq_symm,
ucongr_lhs,
solved_or_continue $ (do subst_lhs,
solved_or_continue $ (do applyc `ueq_symm,
subst_lhs,
solved_or_continue $ (do remove_dup_pred,
solved_or_continue $ (do applyc `ueq_symm,
remove_dup_pred,
solved_or_continue ac_refl)))))))))
|
22e58062995b58efa84f5511286603e511e44199 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/CancellativeMonoid.lean | 5ad2152ab206c6c192930492d8faef4fcfbd004a | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,889 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section CancellativeMonoid
structure CancellativeMonoid (A : Type) : Type :=
(op : (A → (A → A)))
(e : A)
(lunit_e : (∀ {x : A} , (op e x) = x))
(runit_e : (∀ {x : A} , (op x e) = x))
(associative_op : (∀ {x y z : A} , (op (op x y) z) = (op x (op y z))))
(leftCancellative : (∀ {x y z : A} , ((op z x) = (op z y) → x = y)))
(rightCancellative : (∀ {x y z : A} , ((op x z) = (op y z) → x = y)))
open CancellativeMonoid
structure Sig (AS : Type) : Type :=
(opS : (AS → (AS → AS)))
(eS : AS)
structure Product (A : Type) : Type :=
(opP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(eP : (Prod A A))
(lunit_eP : (∀ {xP : (Prod A A)} , (opP eP xP) = xP))
(runit_eP : (∀ {xP : (Prod A A)} , (opP xP eP) = xP))
(associative_opP : (∀ {xP yP zP : (Prod A A)} , (opP (opP xP yP) zP) = (opP xP (opP yP zP))))
(leftCancellativeP : (∀ {xP yP zP : (Prod A A)} , ((opP zP xP) = (opP zP yP) → xP = yP)))
(rightCancellativeP : (∀ {xP yP zP : (Prod A A)} , ((opP xP zP) = (opP yP zP) → xP = yP)))
structure Hom {A1 : Type} {A2 : Type} (Ca1 : (CancellativeMonoid A1)) (Ca2 : (CancellativeMonoid A2)) : Type :=
(hom : (A1 → A2))
(pres_op : (∀ {x1 x2 : A1} , (hom ((op Ca1) x1 x2)) = ((op Ca2) (hom x1) (hom x2))))
(pres_e : (hom (e Ca1)) = (e Ca2))
structure RelInterp {A1 : Type} {A2 : Type} (Ca1 : (CancellativeMonoid A1)) (Ca2 : (CancellativeMonoid A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_op : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((op Ca1) x1 x2) ((op Ca2) y1 y2))))))
(interp_e : (interp (e Ca1) (e Ca2)))
inductive CancellativeMonoidTerm : Type
| opL : (CancellativeMonoidTerm → (CancellativeMonoidTerm → CancellativeMonoidTerm))
| eL : CancellativeMonoidTerm
open CancellativeMonoidTerm
inductive ClCancellativeMonoidTerm (A : Type) : Type
| sing : (A → ClCancellativeMonoidTerm)
| opCl : (ClCancellativeMonoidTerm → (ClCancellativeMonoidTerm → ClCancellativeMonoidTerm))
| eCl : ClCancellativeMonoidTerm
open ClCancellativeMonoidTerm
inductive OpCancellativeMonoidTerm (n : ℕ) : Type
| v : ((fin n) → OpCancellativeMonoidTerm)
| opOL : (OpCancellativeMonoidTerm → (OpCancellativeMonoidTerm → OpCancellativeMonoidTerm))
| eOL : OpCancellativeMonoidTerm
open OpCancellativeMonoidTerm
inductive OpCancellativeMonoidTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpCancellativeMonoidTerm2)
| sing2 : (A → OpCancellativeMonoidTerm2)
| opOL2 : (OpCancellativeMonoidTerm2 → (OpCancellativeMonoidTerm2 → OpCancellativeMonoidTerm2))
| eOL2 : OpCancellativeMonoidTerm2
open OpCancellativeMonoidTerm2
def simplifyCl {A : Type} : ((ClCancellativeMonoidTerm A) → (ClCancellativeMonoidTerm A))
| (opCl eCl x) := x
| (opCl x eCl) := x
| (opCl x1 x2) := (opCl (simplifyCl x1) (simplifyCl x2))
| eCl := eCl
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpCancellativeMonoidTerm n) → (OpCancellativeMonoidTerm n))
| (opOL eOL x) := x
| (opOL x eOL) := x
| (opOL x1 x2) := (opOL (simplifyOpB x1) (simplifyOpB x2))
| eOL := eOL
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpCancellativeMonoidTerm2 n A) → (OpCancellativeMonoidTerm2 n A))
| (opOL2 eOL2 x) := x
| (opOL2 x eOL2) := x
| (opOL2 x1 x2) := (opOL2 (simplifyOp x1) (simplifyOp x2))
| eOL2 := eOL2
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((CancellativeMonoid A) → (CancellativeMonoidTerm → A))
| Ca (opL x1 x2) := ((op Ca) (evalB Ca x1) (evalB Ca x2))
| Ca eL := (e Ca)
def evalCl {A : Type} : ((CancellativeMonoid A) → ((ClCancellativeMonoidTerm A) → A))
| Ca (sing x1) := x1
| Ca (opCl x1 x2) := ((op Ca) (evalCl Ca x1) (evalCl Ca x2))
| Ca eCl := (e Ca)
def evalOpB {A : Type} {n : ℕ} : ((CancellativeMonoid A) → ((vector A n) → ((OpCancellativeMonoidTerm n) → A)))
| Ca vars (v x1) := (nth vars x1)
| Ca vars (opOL x1 x2) := ((op Ca) (evalOpB Ca vars x1) (evalOpB Ca vars x2))
| Ca vars eOL := (e Ca)
def evalOp {A : Type} {n : ℕ} : ((CancellativeMonoid A) → ((vector A n) → ((OpCancellativeMonoidTerm2 n A) → A)))
| Ca vars (v2 x1) := (nth vars x1)
| Ca vars (sing2 x1) := x1
| Ca vars (opOL2 x1 x2) := ((op Ca) (evalOp Ca vars x1) (evalOp Ca vars x2))
| Ca vars eOL2 := (e Ca)
def inductionB {P : (CancellativeMonoidTerm → Type)} : ((∀ (x1 x2 : CancellativeMonoidTerm) , ((P x1) → ((P x2) → (P (opL x1 x2))))) → ((P eL) → (∀ (x : CancellativeMonoidTerm) , (P x))))
| popl pel (opL x1 x2) := (popl _ _ (inductionB popl pel x1) (inductionB popl pel x2))
| popl pel eL := pel
def inductionCl {A : Type} {P : ((ClCancellativeMonoidTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClCancellativeMonoidTerm A)) , ((P x1) → ((P x2) → (P (opCl x1 x2))))) → ((P eCl) → (∀ (x : (ClCancellativeMonoidTerm A)) , (P x)))))
| psing popcl pecl (sing x1) := (psing x1)
| psing popcl pecl (opCl x1 x2) := (popcl _ _ (inductionCl psing popcl pecl x1) (inductionCl psing popcl pecl x2))
| psing popcl pecl eCl := pecl
def inductionOpB {n : ℕ} {P : ((OpCancellativeMonoidTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpCancellativeMonoidTerm n)) , ((P x1) → ((P x2) → (P (opOL x1 x2))))) → ((P eOL) → (∀ (x : (OpCancellativeMonoidTerm n)) , (P x)))))
| pv popol peol (v x1) := (pv x1)
| pv popol peol (opOL x1 x2) := (popol _ _ (inductionOpB pv popol peol x1) (inductionOpB pv popol peol x2))
| pv popol peol eOL := peol
def inductionOp {n : ℕ} {A : Type} {P : ((OpCancellativeMonoidTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpCancellativeMonoidTerm2 n A)) , ((P x1) → ((P x2) → (P (opOL2 x1 x2))))) → ((P eOL2) → (∀ (x : (OpCancellativeMonoidTerm2 n A)) , (P x))))))
| pv2 psing2 popol2 peol2 (v2 x1) := (pv2 x1)
| pv2 psing2 popol2 peol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 popol2 peol2 (opOL2 x1 x2) := (popol2 _ _ (inductionOp pv2 psing2 popol2 peol2 x1) (inductionOp pv2 psing2 popol2 peol2 x2))
| pv2 psing2 popol2 peol2 eOL2 := peol2
def stageB : (CancellativeMonoidTerm → (Staged CancellativeMonoidTerm))
| (opL x1 x2) := (stage2 opL (codeLift2 opL) (stageB x1) (stageB x2))
| eL := (Now eL)
def stageCl {A : Type} : ((ClCancellativeMonoidTerm A) → (Staged (ClCancellativeMonoidTerm A)))
| (sing x1) := (Now (sing x1))
| (opCl x1 x2) := (stage2 opCl (codeLift2 opCl) (stageCl x1) (stageCl x2))
| eCl := (Now eCl)
def stageOpB {n : ℕ} : ((OpCancellativeMonoidTerm n) → (Staged (OpCancellativeMonoidTerm n)))
| (v x1) := (const (code (v x1)))
| (opOL x1 x2) := (stage2 opOL (codeLift2 opOL) (stageOpB x1) (stageOpB x2))
| eOL := (Now eOL)
def stageOp {n : ℕ} {A : Type} : ((OpCancellativeMonoidTerm2 n A) → (Staged (OpCancellativeMonoidTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (opOL2 x1 x2) := (stage2 opOL2 (codeLift2 opOL2) (stageOp x1) (stageOp x2))
| eOL2 := (Now eOL2)
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(opT : ((Repr A) → ((Repr A) → (Repr A))))
(eT : (Repr A))
end CancellativeMonoid |
f6154f64d0ec9d02c558e2b4333cd43ba5973183 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/analysis/convex/topology.lean | 5c6c9d9fa3dd3f69104435af93636ef4a6bd2b5c | [
"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 | 8,569 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudriashov
-/
import analysis.convex.basic
import analysis.normed_space.finite_dimension
import topology.path_connected
/-!
# Topological and metric properties of convex sets
We prove the following facts:
* `convex.interior` : interior of a convex set is convex;
* `convex.closure` : closure of a convex set is convex;
* `set.finite.compact_convex_hull` : convex hull of a finite set is compact;
* `set.finite.is_closed_convex_hull` : convex hull of a finite set is closed;
* `convex_on_dist` : distance to a fixed point is convex on any convex set;
* `convex_hull_ediam`, `convex_hull_diam` : convex hull of a set has the same (e)metric diameter
as the original set;
* `bounded_convex_hull` : convex hull of a set is bounded if and only if the original set
is bounded.
* `bounded_std_simplex`, `is_closed_std_simplex`, `compact_std_simplex`: topological properties
of the standard simplex;
-/
variables {ι : Type*} {E : Type*}
open set
lemma real.convex_iff_is_preconnected {s : set ℝ} : convex s ↔ is_preconnected s :=
real.convex_iff_ord_connected.trans is_preconnected_iff_ord_connected.symm
alias real.convex_iff_is_preconnected ↔ convex.is_preconnected is_preconnected.convex
/-! ### Standard simplex -/
section std_simplex
variables [fintype ι]
/-- Every vector in `std_simplex ι` has `max`-norm at most `1`. -/
lemma std_simplex_subset_closed_ball :
std_simplex ι ⊆ metric.closed_ball 0 1 :=
begin
assume f hf,
rw [metric.mem_closed_ball, dist_zero_right],
refine (nnreal.coe_one ▸ nnreal.coe_le_coe.2 $ finset.sup_le $ λ x hx, _),
change abs (f x) ≤ 1,
rw [abs_of_nonneg $ hf.1 x],
exact (mem_Icc_of_mem_std_simplex hf x).2
end
variable (ι)
/-- `std_simplex ι` is bounded. -/
lemma bounded_std_simplex : metric.bounded (std_simplex ι) :=
(metric.bounded_iff_subset_ball 0).2 ⟨1, std_simplex_subset_closed_ball⟩
/-- `std_simplex ι` is closed. -/
lemma is_closed_std_simplex : is_closed (std_simplex ι) :=
(std_simplex_eq_inter ι).symm ▸ is_closed.inter
(is_closed_Inter $ λ i, is_closed_le continuous_const (continuous_apply i))
(is_closed_eq (continuous_finset_sum _ $ λ x _, continuous_apply x) continuous_const)
/-- `std_simplex ι` is compact. -/
lemma compact_std_simplex : is_compact (std_simplex ι) :=
metric.compact_iff_closed_bounded.2 ⟨is_closed_std_simplex ι, bounded_std_simplex ι⟩
end std_simplex
/-! ### Topological vector space -/
section has_continuous_smul
variables [add_comm_group E] [module ℝ E] [topological_space E]
[topological_add_group E] [has_continuous_smul ℝ E]
/-- In a topological vector space, the interior of a convex set is convex. -/
lemma convex.interior {s : set E} (hs : convex s) : convex (interior s) :=
convex_iff_pointwise_add_subset.mpr $ λ a b ha hb hab,
have h : is_open (a • interior s + b • interior s), from
or.elim (classical.em (a = 0))
(λ heq,
have hne : b ≠ 0, by { rw [heq, zero_add] at hab, rw hab, exact one_ne_zero },
by { rw ← image_smul,
exact (is_open_map_smul' hne _ is_open_interior).add_left } )
(λ hne,
by { rw ← image_smul,
exact (is_open_map_smul' hne _ is_open_interior).add_right }),
(subset_interior_iff_subset_of_open h).mpr $ subset.trans
(by { simp only [← image_smul], apply add_subset_add; exact image_subset _ interior_subset })
(convex_iff_pointwise_add_subset.mp hs ha hb hab)
/-- In a topological vector space, the closure of a convex set is convex. -/
lemma convex.closure {s : set E} (hs : convex s) : convex (closure s) :=
λ x y hx hy a b ha hb hab,
let f : E → E → E := λ x' y', a • x' + b • y' in
have hf : continuous (λ p : E × E, f p.1 p.2), from
(continuous_const.smul continuous_fst).add (continuous_const.smul continuous_snd),
show f x y ∈ closure s, from
mem_closure_of_continuous2 hf hx hy (λ x' hx' y' hy', subset_closure
(hs hx' hy' ha hb hab))
/-- Convex hull of a finite set is compact. -/
lemma set.finite.compact_convex_hull {s : set E} (hs : finite s) :
is_compact (convex_hull s) :=
begin
rw [hs.convex_hull_eq_image],
apply (compact_std_simplex _).image,
haveI := hs.fintype,
apply linear_map.continuous_on_pi
end
/-- Convex hull of a finite set is closed. -/
lemma set.finite.is_closed_convex_hull [t2_space E] {s : set E} (hs : finite s) :
is_closed (convex_hull s) :=
hs.compact_convex_hull.is_closed
end has_continuous_smul
/-! ### Normed vector space -/
section normed_space
variables [normed_group E] [normed_space ℝ E]
lemma convex_on_dist (z : E) (s : set E) (hs : convex s) :
convex_on s (λz', dist z' z) :=
and.intro hs $
assume x y hx hy a b ha hb hab,
calc
dist (a • x + b • y) z = ∥ (a • x + b • y) - (a + b) • z ∥ :
by rw [hab, one_smul, normed_group.dist_eq]
... = ∥a • (x - z) + b • (y - z)∥ :
by rw [add_smul, smul_sub, smul_sub, sub_eq_add_neg, sub_eq_add_neg, sub_eq_add_neg, neg_add,
←add_assoc, add_assoc (a • x), add_comm (b • y)]; simp only [add_assoc]
... ≤ ∥a • (x - z)∥ + ∥b • (y - z)∥ :
norm_add_le (a • (x - z)) (b • (y - z))
... = a * dist x z + b * dist y z :
by simp [norm_smul, normed_group.dist_eq, real.norm_eq_abs, abs_of_nonneg ha, abs_of_nonneg hb]
lemma convex_ball (a : E) (r : ℝ) : convex (metric.ball a r) :=
by simpa only [metric.ball, sep_univ] using (convex_on_dist a _ convex_univ).convex_lt r
lemma convex_closed_ball (a : E) (r : ℝ) : convex (metric.closed_ball a r) :=
by simpa only [metric.closed_ball, sep_univ] using (convex_on_dist a _ convex_univ).convex_le r
/-- Given a point `x` in the convex hull of `s` and a point `y`, there exists a point
of `s` at distance at least `dist x y` from `y`. -/
lemma convex_hull_exists_dist_ge {s : set E} {x : E} (hx : x ∈ convex_hull s) (y : E) :
∃ x' ∈ s, dist x y ≤ dist x' y :=
(convex_on_dist y _ (convex_convex_hull _)).exists_ge_of_mem_convex_hull hx
/-- Given a point `x` in the convex hull of `s` and a point `y` in the convex hull of `t`,
there exist points `x' ∈ s` and `y' ∈ t` at distance at least `dist x y`. -/
lemma convex_hull_exists_dist_ge2 {s t : set E} {x y : E}
(hx : x ∈ convex_hull s) (hy : y ∈ convex_hull t) :
∃ (x' ∈ s) (y' ∈ t), dist x y ≤ dist x' y' :=
begin
rcases convex_hull_exists_dist_ge hx y with ⟨x', hx', Hx'⟩,
rcases convex_hull_exists_dist_ge hy x' with ⟨y', hy', Hy'⟩,
use [x', hx', y', hy'],
exact le_trans Hx' (dist_comm y x' ▸ dist_comm y' x' ▸ Hy')
end
/-- Emetric diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/
@[simp] lemma convex_hull_ediam (s : set E) :
emetric.diam (convex_hull s) = emetric.diam s :=
begin
refine (emetric.diam_le $ λ x hx y hy, _).antisymm (emetric.diam_mono $ subset_convex_hull s),
rcases convex_hull_exists_dist_ge2 hx hy with ⟨x', hx', y', hy', H⟩,
rw edist_dist,
apply le_trans (ennreal.of_real_le_of_real H),
rw ← edist_dist,
exact emetric.edist_le_diam_of_mem hx' hy'
end
/-- Diameter of the convex hull of a set `s` equals the emetric diameter of `s. -/
@[simp] lemma convex_hull_diam (s : set E) :
metric.diam (convex_hull s) = metric.diam s :=
by simp only [metric.diam, convex_hull_ediam]
/-- Convex hull of `s` is bounded if and only if `s` is bounded. -/
@[simp] lemma bounded_convex_hull {s : set E} :
metric.bounded (convex_hull s) ↔ metric.bounded s :=
by simp only [metric.bounded_iff_ediam_ne_top, convex_hull_ediam]
lemma convex.is_path_connected {s : set E} (hconv : convex s) (hne : s.nonempty) :
is_path_connected s :=
begin
refine is_path_connected_iff.mpr ⟨hne, _⟩,
intros x y x_in y_in,
let f := λ θ : ℝ, x + θ • (y - x),
have hf : continuous f, by continuity,
have h₀ : f 0 = x, by simp [f],
have h₁ : f 1 = y, by { dsimp [f], rw one_smul, abel },
have H := hconv.segment_subset x_in y_in,
rw segment_eq_image' at H,
exact joined_in.of_line hf.continuous_on h₀ h₁ H
end
@[priority 100]
instance normed_space.path_connected : path_connected_space E :=
path_connected_space_iff_univ.mpr $ convex_univ.is_path_connected ⟨(0 : E), trivial⟩
@[priority 100]
instance normed_space.loc_path_connected : loc_path_connected_space E :=
loc_path_connected_of_bases (λ x, metric.nhds_basis_ball)
(λ x r r_pos, (convex_ball x r).is_path_connected $ by simp [r_pos])
end normed_space
|
1bdf1fc3b3d250ab0d100a465ccf9913887a80c3 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/fin/tuple/default.lean | 8254c590aabd20b7139b5c24c618bf78eb6b7545 | [
"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 | 28 | lean | import data.fin.tuple.basic
|
096cacd4edb44e7bb8054d6f3b6335b3e043a741 | 618003631150032a5676f229d13a079ac875ff77 | /src/ring_theory/subsemiring.lean | ec75aecece67bbc7fcf7f902ca23a1830c36522d | [
"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 | 22,434 | 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 ring_theory.prod
import group_theory.submonoid
import data.equiv.ring
/-!
# Bundled subsemirings
We define bundled subsemirings and some standard constructions: `complete_lattice` structure,
`subtype` and `inclusion` ring homomorphisms, subsemiring kernel and range of a `ring_hom` etc.
-/
universes u v w
variables {R : Type u} {S : Type v} {T : Type w} [semiring R] [semiring S] [semiring T]
set_option old_structure_cmd true
/-- Subsemiring of a semiring `R` is a subset `s` that is both a multiplicative and an additive
submonoid. -/
structure subsemiring (R : Type u) [semiring R] extends submonoid R, add_submonoid R
/-- Reinterpret a `subsemiring` as a `submonoid`. -/
add_decl_doc subsemiring.to_submonoid
/-- Reinterpret a `subsemiring` as an `add_submonoid`. -/
add_decl_doc subsemiring.to_add_submonoid
namespace subsemiring
instance : has_coe (subsemiring R) (set R) := ⟨subsemiring.carrier⟩
instance : has_coe_to_sort (subsemiring R) := ⟨Type*, λ S, S.carrier⟩
instance : has_mem R (subsemiring R) := ⟨λ m S, m ∈ (S:set R)⟩
/-- Construct a `subsemiring R` from a set `s`, a submonoid `sm`, and an additive
submonoid `sa` such that `x ∈ s ↔ x ∈ sm ↔ x ∈ sa`. -/
protected def mk' (s : set R) (sm : submonoid R) (hm : ↑sm = s)
(sa : add_submonoid R) (ha : ↑sa = s) :
subsemiring R :=
{ carrier := s,
zero_mem' := ha ▸ sa.zero_mem,
one_mem' := hm ▸ sm.one_mem,
add_mem' := λ x y, by simpa only [← ha] using sa.add_mem,
mul_mem' := λ x y, by simpa only [← hm] using sm.mul_mem }
@[simp] lemma coe_mk' {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) :
(subsemiring.mk' s sm hm sa ha : set R) = s := rfl
@[simp] lemma mem_mk' {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) {x : R} :
x ∈ subsemiring.mk' s sm hm sa ha ↔ x ∈ s :=
iff.rfl
@[simp] lemma mk'_to_submonoid {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa = s) :
(subsemiring.mk' s sm hm sa ha).to_submonoid = sm :=
submonoid.ext' hm.symm
@[simp] lemma mk'_to_add_submonoid {s : set R} {sm : submonoid R} (hm : ↑sm = s)
{sa : add_submonoid R} (ha : ↑sa =s) :
(subsemiring.mk' s sm hm sa ha).to_add_submonoid = sa :=
add_submonoid.ext' ha.symm
end subsemiring
protected lemma subsemiring.exists {s : subsemiring R} {p : s → Prop} :
(∃ x : s, p x) ↔ ∃ x ∈ s, p ⟨x, ‹x ∈ s›⟩ :=
set_coe.exists
protected lemma subsemiring.forall {s : subsemiring R} {p : s → Prop} :
(∀ x : s, p x) ↔ ∀ x ∈ s, p ⟨x, ‹x ∈ s›⟩ :=
set_coe.forall
namespace subsemiring
variables (s : subsemiring R)
/-- Two subsemirings are equal if the underlying subsets are equal. -/
theorem ext' ⦃s t : subsemiring R⦄ (h : (s : set R) = t) : s = t :=
by cases s; cases t; congr'
/-- Two subsemirings are equal if and only if the underlying subsets are equal. -/
protected theorem ext'_iff {s t : subsemiring R} : s = t ↔ (s : set R) = t :=
⟨λ h, h ▸ rfl, λ h, ext' h⟩
/-- Two subsemirings are equal if they have the same elements. -/
theorem ext {S T : subsemiring R} (h : ∀ x, x ∈ S ↔ x ∈ T) : S = T := ext' $ set.ext h
/-- A subsemiring contains the semiring's 1. -/
theorem one_mem : (1 : R) ∈ s := s.one_mem'
/-- A subsemiring contains the semiring's 0. -/
theorem zero_mem : (0 : R) ∈ s := s.zero_mem'
/-- A subsemiring is closed under multiplication. -/
theorem mul_mem : ∀ {x y : R}, x ∈ s → y ∈ s → x * y ∈ s := s.mul_mem'
/-- A subsemiring is closed under addition. -/
theorem add_mem : ∀ {x y : R}, x ∈ s → y ∈ s → x + y ∈ s := s.add_mem'
/-- Product of a list of elements in a subsemiring is in the subsemiring. -/
lemma list_prod_mem {l : list R} : (∀x ∈ l, x ∈ s) → l.prod ∈ s :=
s.to_submonoid.list_prod_mem
/-- Sum of a list of elements in an `add_subsemiring` is in the `add_subsemiring`. -/
lemma list_sum_mem {l : list R} : (∀x ∈ l, x ∈ s) → l.sum ∈ s :=
s.to_add_submonoid.list_sum_mem
/-- Product of a multiset of elements in a subsemiring of a `comm_monoid` is in the subsemiring. -/
lemma multiset_prod_mem {R} [comm_semiring R] (s : subsemiring R) (m : multiset R) :
(∀a ∈ m, a ∈ s) → m.prod ∈ s :=
s.to_submonoid.multiset_prod_mem m
/-- Sum of a multiset of elements in an `add_subsemiring` of an `add_comm_monoid` is
in the `add_subsemiring`. -/
lemma multiset_sum_mem {R} [semiring R] (s : subsemiring R) (m : multiset R) :
(∀a ∈ m, a ∈ s) → m.sum ∈ s :=
s.to_add_submonoid.multiset_sum_mem m
/-- Product of elements of a subsemiring of a `comm_monoid` indexed by a `finset` is in the
subsemiring. -/
lemma prod_mem {R : Type*} [comm_semiring R] (s : subsemiring R)
{ι : Type*} {t : finset ι} {f : ι → R} (h : ∀c ∈ t, f c ∈ s) :
t.prod f ∈ s :=
s.to_submonoid.prod_mem h
/-- Sum of elements in an `add_subsemiring` of an `add_comm_monoid` indexed by a `finset`
is in the `add_subsemiring`. -/
lemma sum_mem {R : Type*} [semiring R] (s : subsemiring R)
{ι : Type*} {t : finset ι} {f : ι → R} (h : ∀c ∈ t, f c ∈ s) :
t.sum f ∈ s :=
s.to_add_submonoid.sum_mem h
lemma pow_mem {x : R} (hx : x ∈ s) (n : ℕ) : x^n ∈ s := s.to_submonoid.pow_mem hx n
lemma smul_mem {x : R} (hx : x ∈ s) (n : ℕ) :
n •ℕ x ∈ s := s.to_add_submonoid.smul_mem hx n
lemma coe_nat_mem (n : ℕ) : (n : R) ∈ s :=
by simp only [← nsmul_one, smul_mem, one_mem]
/-- A subsemiring of a semiring inherits a semiring structure -/
instance to_semiring : semiring s :=
{ mul_zero := λ x, subtype.eq $ mul_zero x,
zero_mul := λ x, subtype.eq $ zero_mul x,
right_distrib := λ x y z, subtype.eq $ right_distrib x y z,
left_distrib := λ x y z, subtype.eq $ left_distrib x y z,
.. s.to_submonoid.to_monoid, .. s.to_add_submonoid.to_add_comm_monoid }
@[simp, norm_cast] lemma coe_mul (x y : s) : (↑(x * y) : R) = ↑x * ↑y := rfl
@[simp, norm_cast] lemma coe_one : ((1 : s) : R) = 1 := rfl
/-- A subsemiring of a `comm_semiring` is a `comm_semiring`. -/
instance to_comm_semiring {R} [comm_semiring R] (s : subsemiring R) : comm_semiring s :=
{ mul_comm := λ _ _, subtype.eq $ mul_comm _ _, ..s.to_semiring}
/-- The natural ring hom from a subsemiring of monoid `R` to `R`. -/
def subtype : s →+* R :=
{ to_fun := coe, .. s.to_submonoid.subtype, .. s.to_add_submonoid.subtype }
@[simp] theorem coe_subtype : ⇑s.subtype = coe := rfl
instance : partial_order (subsemiring R) :=
{ le := λ s t, ∀ ⦃x⦄, x ∈ s → x ∈ t,
.. partial_order.lift (coe : subsemiring R → set R) ext' _ }
lemma le_def {s t : subsemiring R} : s ≤ t ↔ ∀ ⦃x : R⦄, x ∈ s → x ∈ t := iff.rfl
@[simp, norm_cast] lemma coe_subset_coe {s t : subsemiring R} : (s : set R) ⊆ t ↔ s ≤ t := iff.rfl
@[simp, norm_cast] lemma coe_ssubset_coe {s t : subsemiring R} : (s : set R) ⊂ t ↔ s < t := iff.rfl
@[simp, norm_cast]
lemma mem_coe {S : subsemiring R} {m : R} : m ∈ (S : set R) ↔ m ∈ S := iff.rfl
@[simp, norm_cast]
lemma coe_coe (s : subsemiring R) : ↥(s : set R) = s := rfl
@[simp] lemma mem_to_submonoid {s : subsemiring R} {x : R} : x ∈ s.to_submonoid ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_submonoid (s : subsemiring R) : (s.to_submonoid : set R) = s := rfl
@[simp] lemma mem_to_add_submonoid {s : subsemiring R} {x : R} :
x ∈ s.to_add_submonoid ↔ x ∈ s := iff.rfl
@[simp] lemma coe_to_add_submonoid (s : subsemiring R) : (s.to_add_submonoid : set R) = s := rfl
/-- The subsemiring `R` of the semiring `R`. -/
instance : has_top (subsemiring R) :=
⟨{ .. (⊤ : submonoid R), .. (⊤ : add_submonoid R) }⟩
@[simp] lemma mem_top (x : R) : x ∈ (⊤ : subsemiring R) := set.mem_univ x
@[simp] lemma coe_top : ((⊤ : subsemiring R) : set R) = set.univ := rfl
/-- The preimage of a subsemiring along a ring homomorphism is a subsemiring. -/
def comap (f : R →+* S) (s : subsemiring S) : subsemiring R :=
{ carrier := f ⁻¹' s,
.. s.to_submonoid.comap (f : R →* S), .. s.to_add_submonoid.comap (f : R →+ S) }
@[simp] lemma coe_comap (s : subsemiring S) (f : R →+* S) : (s.comap f : set R) = f ⁻¹' s := rfl
@[simp]
lemma mem_comap {s : subsemiring S} {f : R →+* S} {x : R} : x ∈ s.comap f ↔ f x ∈ s := iff.rfl
lemma comap_comap (s : subsemiring T) (g : S →+* T) (f : R →+* S) :
(s.comap g).comap f = s.comap (g.comp f) :=
rfl
/-- The image of a subsemiring along a ring homomorphism is a subsemiring. -/
def map (f : R →+* S) (s : subsemiring R) : subsemiring S :=
{ carrier := f '' s,
.. s.to_submonoid.map (f : R →* S), .. s.to_add_submonoid.map (f : R →+ S) }
@[simp] lemma coe_map (f : R →+* S) (s : subsemiring R) : (s.map f : set S) = f '' s := rfl
@[simp] lemma mem_map {f : R →+* S} {s : subsemiring R} {y : S} :
y ∈ s.map f ↔ ∃ x ∈ s, f x = y :=
set.mem_image_iff_bex
lemma map_map (g : S →+* T) (f : R →+* S) : (s.map f).map g = s.map (g.comp f) :=
ext' $ set.image_image _ _ _
lemma map_le_iff_le_comap {f : R →+* S} {s : subsemiring R} {t : subsemiring S} :
s.map f ≤ t ↔ s ≤ t.comap f :=
set.image_subset_iff
lemma gc_map_comap (f : R →+* S) : galois_connection (map f) (comap f) :=
λ S T, map_le_iff_le_comap
end subsemiring
namespace ring_hom
variables (g : S →+* T) (f : R →+* S)
/-- The range of a ring homomorphism is a subsemiring. -/
def srange : subsemiring S := (⊤ : subsemiring R).map f
@[simp] lemma coe_srange : (f.srange : set S) = set.range f := set.image_univ
@[simp] lemma mem_srange {f : R →+* S} {y : S} : y ∈ f.srange ↔ ∃ x, f x = y :=
by simp [srange]
lemma map_srange : f.srange.map g = (g.comp f).srange :=
(⊤ : subsemiring R).map_map g f
end ring_hom
namespace subsemiring
instance : has_bot (subsemiring R) := ⟨(nat.cast_ring_hom R).srange⟩
instance : inhabited (subsemiring R) := ⟨⊥⟩
lemma coe_bot : ((⊥ : subsemiring R) : set R) = set.range (coe : ℕ → R) :=
(nat.cast_ring_hom R).coe_srange
lemma mem_bot {x : R} : x ∈ (⊥ : subsemiring R) ↔ ∃ n : ℕ, ↑n=x := ring_hom.mem_srange
/-- The inf of two subsemirings is their intersection. -/
instance : has_inf (subsemiring R) :=
⟨λ s t,
{ carrier := s ∩ t,
.. s.to_submonoid ⊓ t.to_submonoid,
.. s.to_add_submonoid ⊓ t.to_add_submonoid }⟩
@[simp] lemma coe_inf (p p' : subsemiring R) : ((p ⊓ p' : subsemiring R) : set R) = p ∩ p' := rfl
@[simp] lemma mem_inf {p p' : subsemiring R} {x : R} : x ∈ p ⊓ p' ↔ x ∈ p ∧ x ∈ p' := iff.rfl
instance : has_Inf (subsemiring R) :=
⟨λ s, subsemiring.mk' (⋂ t ∈ s, ↑t) (⨅ t ∈ s, subsemiring.to_submonoid t) (by simp)
(⨅ t ∈ s, subsemiring.to_add_submonoid t) (by simp)⟩
@[simp, norm_cast] lemma coe_Inf (S : set (subsemiring R)) :
((Inf S : subsemiring R) : set R) = ⋂ s ∈ S, ↑s := rfl
lemma mem_Inf {S : set (subsemiring R)} {x : R} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p := set.mem_bInter_iff
@[simp] lemma Inf_to_submonoid (s : set (subsemiring R)) :
(Inf s).to_submonoid = ⨅ t ∈ s, subsemiring.to_submonoid t :=
mk'_to_submonoid _ _
@[simp] lemma Inf_to_add_submonoid (s : set (subsemiring R)) :
(Inf s).to_add_submonoid = ⨅ t ∈ s, subsemiring.to_add_submonoid t :=
mk'_to_add_submonoid _ _
/-- Subsemirings of a semiring form a complete lattice. -/
instance : complete_lattice (subsemiring R) :=
{ bot := (⊥),
bot_le := λ s x hx, let ⟨n, hn⟩ := mem_bot.1 hx in hn ▸ s.coe_nat_mem n,
top := (⊤),
le_top := λ s x hx, trivial,
inf := (⊓),
inf_le_left := λ s t x, and.left,
inf_le_right := λ s t x, and.right,
le_inf := λ s t₁ t₂ h₁ h₂ x hx, ⟨h₁ hx, h₂ hx⟩,
.. complete_lattice_of_Inf (subsemiring R)
(λ s, is_glb.of_image (λ s t, show (s : set R) ≤ t ↔ s ≤ t, from coe_subset_coe) is_glb_binfi)}
/-- The `subsemiring` generated by a set. -/
def closure (s : set R) : subsemiring R := Inf {S | s ⊆ S}
lemma mem_closure {x : R} {s : set R} : x ∈ closure s ↔ ∀ S : subsemiring R, s ⊆ S → x ∈ S :=
mem_Inf
/-- The subsemiring generated by a set includes the set. -/
@[simp] lemma subset_closure {s : set R} : s ⊆ closure s := λ x hx, mem_closure.2 $ λ S hS, hS hx
/-- A subsemiring `S` includes `closure s` if and only if it includes `s`. -/
@[simp]
lemma closure_le {s : set R} {t : subsemiring R} : closure s ≤ t ↔ s ⊆ t :=
⟨set.subset.trans subset_closure, λ h, Inf_le h⟩
/-- Subsemiring closure of a set is monotone in its argument: if `s ⊆ t`,
then `closure s ≤ closure t`. -/
lemma closure_mono ⦃s t : set R⦄ (h : s ⊆ t) : closure s ≤ closure t :=
closure_le.2 $ set.subset.trans h subset_closure
lemma closure_eq_of_le {s : set R} {t : subsemiring R} (h₁ : s ⊆ t) (h₂ : t ≤ closure s) :
closure s = t :=
le_antisymm (closure_le.2 h₁) h₂
/-- An induction principle for closure membership. If `p` holds for `0`, `1`, and all elements
of `s`, and is preserved under addition and multiplication, then `p` holds for all elements
of the closure of `s`. -/
@[elab_as_eliminator]
lemma closure_induction {s : set R} {p : R → Prop} {x} (h : x ∈ closure s)
(Hs : ∀ x ∈ s, p x) (H0 : p 0) (H1 : p 1)
(Hadd : ∀ x y, p x → p y → p (x + y)) (Hmul : ∀ x y, p x → p y → p (x * y)) : p x :=
(@closure_le _ _ _ ⟨p, H1, Hmul, H0, Hadd⟩).2 Hs h
variable (R)
/-- `closure` forms a Galois insertion with the coercion to set. -/
protected def gi : galois_insertion (@closure R _) coe :=
{ choice := λ s _, closure s,
gc := λ s t, closure_le,
le_l_u := λ s, subset_closure,
choice_eq := λ s h, rfl }
variable {R}
/-- Closure of a subsemiring `S` equals `S`. -/
lemma closure_eq (s : subsemiring R) : closure (s : set R) = s := (subsemiring.gi R).l_u_eq s
@[simp] lemma closure_empty : closure (∅ : set R) = ⊥ := (subsemiring.gi R).gc.l_bot
@[simp] lemma closure_univ : closure (set.univ : set R) = ⊤ := @coe_top R _ ▸ closure_eq ⊤
lemma closure_union (s t : set R) : closure (s ∪ t) = closure s ⊔ closure t :=
(subsemiring.gi R).gc.l_sup
lemma closure_Union {ι} (s : ι → set R) : closure (⋃ i, s i) = ⨆ i, closure (s i) :=
(subsemiring.gi R).gc.l_supr
lemma closure_sUnion (s : set (set R)) : closure (⋃₀ s) = ⨆ t ∈ s, closure t :=
(subsemiring.gi R).gc.l_Sup
lemma map_sup (s t : subsemiring R) (f : R →+* S) : (s ⊔ t).map f = s.map f ⊔ t.map f :=
(gc_map_comap f).l_sup
lemma map_supr {ι : Sort*} (f : R →+* S) (s : ι → subsemiring R) :
(supr s).map f = ⨆ i, (s i).map f :=
(gc_map_comap f).l_supr
lemma comap_inf (s t : subsemiring S) (f : R →+* S) : (s ⊓ t).comap f = s.comap f ⊓ t.comap f :=
(gc_map_comap f).u_inf
lemma comap_infi {ι : Sort*} (f : R →+* S) (s : ι → subsemiring S) :
(infi s).comap f = ⨅ i, (s i).comap f :=
(gc_map_comap f).u_infi
@[simp] lemma map_bot (f : R →+* S) : (⊥ : subsemiring R).map f = ⊥ :=
(gc_map_comap f).l_bot
@[simp] lemma comap_top (f : R →+* S) : (⊤ : subsemiring S).comap f = ⊤ :=
(gc_map_comap f).u_top
/-- Given `subsemiring`s `s`, `t` of semirings `R`, `S` respectively, `s.prod t` is `s × t`
as a subsemiring of `R × S`. -/
def prod (s : subsemiring R) (t : subsemiring S) : subsemiring (R × S) :=
{ carrier := (s : set R).prod t,
.. s.to_submonoid.prod t.to_submonoid, .. s.to_add_submonoid.prod t.to_add_submonoid}
@[norm_cast]
lemma coe_prod (s : subsemiring R) (t : subsemiring S) :
(s.prod t : set (R × S)) = (s : set R).prod (t : set S) :=
rfl
lemma mem_prod {s : subsemiring R} {t : subsemiring S} {p : R × S} :
p ∈ s.prod t ↔ p.1 ∈ s ∧ p.2 ∈ t := iff.rfl
@[mono] lemma prod_mono ⦃s₁ s₂ : subsemiring R⦄ (hs : s₁ ≤ s₂) ⦃t₁ t₂ : subsemiring S⦄
(ht : t₁ ≤ t₂) : s₁.prod t₁ ≤ s₂.prod t₂ :=
set.prod_mono hs ht
lemma prod_mono_right (s : subsemiring R) : monotone (λ t : subsemiring S, s.prod t) :=
prod_mono (le_refl s)
lemma prod_mono_left (t : subsemiring S) : monotone (λ s : subsemiring R, s.prod t) :=
λ s₁ s₂ hs, prod_mono hs (le_refl t)
lemma prod_top (s : subsemiring R) :
s.prod (⊤ : subsemiring S) = s.comap (ring_hom.fst R S) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_fst]
lemma top_prod (s : subsemiring S) :
(⊤ : subsemiring R).prod s = s.comap (ring_hom.snd R S) :=
ext $ λ x, by simp [mem_prod, monoid_hom.coe_snd]
@[simp]
lemma top_prod_top : (⊤ : subsemiring R).prod (⊤ : subsemiring S) = ⊤ :=
(top_prod _).trans $ comap_top _
/-- Product of subsemirings is isomorphic to their product as monoids. -/
def prod_equiv (s : subsemiring R) (t : subsemiring S) : s.prod t ≃+* s × t :=
{ map_mul' := λ x y, rfl, map_add' := λ x y, rfl, .. equiv.set.prod ↑s ↑t }
lemma mem_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subsemiring R} (hS : directed (≤) S)
{x : R} :
x ∈ (⨆ i, S i) ↔ ∃ i, x ∈ S i :=
begin
refine ⟨_, λ ⟨i, hi⟩, (le_def.1 $ le_supr S i) hi⟩,
let U : subsemiring R := subsemiring.mk' (⋃ i, (S i : set R))
(⨆ i, (S i).to_submonoid) (submonoid.coe_supr_of_directed $ hS.mono_comp _ (λ _ _, id))
(⨆ i, (S i).to_add_submonoid) (add_submonoid.coe_supr_of_directed $ hS.mono_comp _ (λ _ _, id)),
suffices : (⨆ i, S i) ≤ U, by simpa using @this x,
exact supr_le (λ i x hx, set.mem_Union.2 ⟨i, hx⟩),
end
lemma coe_supr_of_directed {ι} [hι : nonempty ι] {S : ι → subsemiring R} (hS : directed (≤) S) :
((⨆ i, S i : subsemiring R) : set R) = ⋃ i, ↑(S i) :=
set.ext $ λ x, by simp [mem_supr_of_directed hS]
lemma mem_Sup_of_directed_on {S : set (subsemiring R)} (Sne : S.nonempty)
(hS : directed_on (≤) S) {x : R} :
x ∈ Sup S ↔ ∃ s ∈ S, x ∈ s :=
begin
haveI : nonempty S := Sne.to_subtype,
rw [Sup_eq_supr, supr_subtype', mem_supr_of_directed, subtype.exists],
exact (directed_on_iff_directed _).1 hS
end
lemma coe_Sup_of_directed_on {S : set (subsemiring R)} (Sne : S.nonempty) (hS : directed_on (≤) S) :
(↑(Sup S) : set R) = ⋃ s ∈ S, ↑s :=
set.ext $ λ x, by simp [mem_Sup_of_directed_on Sne hS]
end subsemiring
namespace ring_hom
variables [semiring T] {s : subsemiring R}
open subsemiring
/-- Restriction of a ring homomorphism to a subsemiring of the domain. -/
def srestrict (f : R →+* S) (s : subsemiring R) : s →+* S := f.comp s.subtype
@[simp] lemma srestrict_apply (f : R →+* S) (x : s) : f.srestrict s x = f x := rfl
/-- Restriction of a ring homomorphism to a subsemiring of the codomain. -/
def cod_srestrict (f : R →+* S) (s : subsemiring S) (h : ∀ x, f x ∈ s) : R →+* s :=
{ to_fun := λ n, ⟨f n, h n⟩,
.. (f : R →* S).cod_mrestrict s.to_submonoid h,
.. (f : R →+ S).cod_mrestrict s.to_add_submonoid h }
/-- Restriction of a ring homomorphism to its range iterpreted as a subsemiring. -/
def srange_restrict (f : R →+* S) : R →+* f.srange :=
f.cod_srestrict f.srange $ λ x, ⟨x, subsemiring.mem_top x, rfl⟩
@[simp] lemma coe_srange_restrict (f : R →+* S) (x : R) :
(f.srange_restrict x : S) = f x :=
rfl
lemma srange_top_iff_surjective {f : R →+* S} :
f.srange = (⊤ : subsemiring S) ↔ function.surjective f :=
subsemiring.ext'_iff.trans $ iff.trans (by rw [coe_srange, coe_top]) set.range_iff_surjective
/-- The range of a surjective ring homomorphism is the whole of the codomain. -/
lemma srange_top_of_surjective (f : R →+* S) (hf : function.surjective f) :
f.srange = (⊤ : subsemiring S) :=
srange_top_iff_surjective.2 hf
/-- The subsemiring of elements `x : R` such that `f x = g x` -/
def eq_slocus (f g : R →+* S) : subsemiring R :=
{ carrier := {x | f x = g x}, .. (f : R →* S).eq_mlocus g, .. (f : R →+ S).eq_mlocus g }
/-- If two ring homomorphisms are equal on a set, then they are equal on its subsemiring closure. -/
lemma eq_on_sclosure {f g : R →+* S} {s : set R} (h : set.eq_on f g s) :
set.eq_on f g (closure s) :=
show closure s ≤ f.eq_slocus g, from closure_le.2 h
lemma eq_of_eq_on_stop {f g : R →+* S} (h : set.eq_on f g (⊤ : subsemiring R)) :
f = g :=
ext $ λ x, h trivial
lemma eq_of_eq_on_sdense {s : set R} (hs : closure s = ⊤) {f g : R →+* S} (h : s.eq_on f g) :
f = g :=
eq_of_eq_on_stop $ hs ▸ eq_on_sclosure h
lemma sclosure_preimage_le (f : R →+* S) (s : set S) :
closure (f ⁻¹' s) ≤ (closure s).comap f :=
closure_le.2 $ λ x hx, mem_coe.2 $ mem_comap.2 $ subset_closure hx
/-- The image under a ring homomorphism of the subsemiring generated by a set equals
the subsemiring generated by the image of the set. -/
lemma map_sclosure (f : R →+* S) (s : set R) :
(closure s).map f = closure (f '' s) :=
le_antisymm
(map_le_iff_le_comap.2 $ le_trans (closure_mono $ set.subset_preimage_image _ _)
(sclosure_preimage_le _ _))
(closure_le.2 $ set.image_subset _ subset_closure)
end ring_hom
namespace subsemiring
open ring_hom
/-- The ring homomorphism associated to an inclusion of subsemirings. -/
def inclusion {S T : subsemiring R} (h : S ≤ T) : S →* T :=
S.subtype.cod_srestrict _ (λ x, h x.2)
@[simp] lemma srange_subtype (s : subsemiring R) : s.subtype.srange = s :=
ext' $ (coe_srange _).trans $ set.range_coe_subtype s
@[simp]
lemma range_fst : (fst R S).srange = ⊤ :=
(fst R S).srange_top_of_surjective $ prod.fst_surjective
@[simp]
lemma range_snd : (snd R S).srange = ⊤ :=
(snd R S).srange_top_of_surjective $ prod.snd_surjective
@[simp]
lemma prod_bot_sup_bot_prod (s : subsemiring R) (t : subsemiring S) :
(s.prod ⊥) ⊔ (prod ⊥ t) = s.prod t :=
le_antisymm (sup_le (prod_mono_right s bot_le) (prod_mono_left t bot_le)) $
assume p hp, prod.fst_mul_snd p ▸ mul_mem _
((le_sup_left : s.prod ⊥ ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨hp.1, mem_coe.2 $ one_mem ⊥⟩)
((le_sup_right : prod ⊥ t ≤ s.prod ⊥ ⊔ prod ⊥ t) ⟨mem_coe.2 $ one_mem ⊥, hp.2⟩)
end subsemiring
namespace ring_equiv
variables {s t : subsemiring R}
/-- Makes the identity isomorphism from a proof two subsemirings of a multiplicative
monoid are equal. -/
def subsemiring_congr (h : s = t) : s ≃+* t :=
{ map_mul' := λ _ _, rfl, map_add' := λ _ _, rfl, ..equiv.set_congr $ subsemiring.ext'_iff.1 h }
end ring_equiv
|
d30059cb6f8b71010f47bac1fdd6ec1aff8aded4 | e151e9053bfd6d71740066474fc500a087837323 | /src/hott/algebra/group.lean | 9e386691ebc7767470fe1cfe360817c0e3aedd9b | [
"Apache-2.0"
] | permissive | daniel-carranza/hott3 | 15bac2d90589dbb952ef15e74b2837722491963d | 913811e8a1371d3a5751d7d32ff9dec8aa6815d9 | refs/heads/master | 1,610,091,349,670 | 1,596,222,336,000 | 1,596,222,336,000 | 241,957,822 | 0 | 0 | Apache-2.0 | 1,582,222,839,000 | 1,582,222,838,000 | null | UTF-8 | Lean | false | false | 7,492 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
Various multiplicative and additive structures. Partially modeled on Isabelle's library.
-/
import ..init .inf_group
universes u v w
hott_theory
set_option old_structure_cmd true
namespace hott
open is_trunc
variable {A : Type _}
/- semigroup -/
namespace algebra
@[hott, class] structure is_set_structure (A : Type _) :=
(is_set_carrier : is_set A)
attribute [instance] [priority 950] is_set_structure.is_set_carrier
@[hott, class] structure semigroup (A : Type _) extends is_set_structure A, inf_semigroup A
@[hott, class] structure comm_semigroup (A : Type _) extends semigroup A, comm_inf_semigroup A
@[hott, class] structure left_cancel_semigroup (A : Type _) extends
semigroup A, left_cancel_inf_semigroup A
@[hott, class] structure right_cancel_semigroup (A : Type _) extends
semigroup A, right_cancel_inf_semigroup A
/- additive semigroup -/
@[hott, class] def add_semigroup : Type _ → Type _ := semigroup
@[hott, instance, priority 900] def add_semigroup.is_set_carrier (A : Type _)
[H : add_semigroup A] : is_set A :=
@is_set_structure.is_set_carrier A (@semigroup.to_is_set_structure A H)
@[hott, reducible, instance] def add_inf_semigroup_of_add_semigroup (A : Type _)
[H : add_semigroup A] : add_inf_semigroup A :=
@semigroup.to_inf_semigroup A H
@[hott, class] def add_comm_semigroup : Type _ → Type _ := comm_semigroup
@[hott, reducible, instance] def add_semigroup_of_add_comm_semigroup (A : Type _)
[H : add_comm_semigroup A] : add_semigroup A :=
@comm_semigroup.to_semigroup A H
@[hott, reducible, instance] def add_comm_inf_semigroup_of_add_comm_semigroup (A : Type _)
[H : add_comm_semigroup A] : add_comm_inf_semigroup A :=
@comm_semigroup.to_comm_inf_semigroup A H
@[hott, class] def add_left_cancel_semigroup : Type _ → Type _ := left_cancel_semigroup
@[hott, reducible, instance] def add_semigroup_of_add_left_cancel_semigroup (A : Type _)
[H : add_left_cancel_semigroup A] : add_semigroup A :=
@left_cancel_semigroup.to_semigroup A H
@[hott, reducible, instance] def add_left_cancel_inf_semigroup_of_add_left_cancel_semigroup
(A : Type _) [H : add_left_cancel_semigroup A] : add_left_cancel_inf_semigroup A :=
@left_cancel_semigroup.to_left_cancel_inf_semigroup A H
@[hott, class] def add_right_cancel_semigroup : Type _ → Type _ := right_cancel_semigroup
@[hott, reducible, instance] def add_semigroup_of_add_right_cancel_semigroup (A : Type _)
[H : add_right_cancel_semigroup A] : add_semigroup A :=
@right_cancel_semigroup.to_semigroup A H
@[hott, reducible, instance] def add_right_cancel_inf_semigroup_of_add_right_cancel_semigroup
(A : Type _) [H : add_right_cancel_semigroup A] : add_right_cancel_inf_semigroup A :=
@right_cancel_semigroup.to_right_cancel_inf_semigroup A H
/- monoid -/
@[hott, class] structure monoid (A : Type _) extends semigroup A, inf_monoid A
@[hott, class] structure comm_monoid (A : Type _) extends
monoid A, comm_semigroup A, comm_inf_monoid A
/- additive monoid -/
@[hott, class] def add_monoid : Type _ → Type _ := monoid
@[hott, reducible, instance] def add_semigroup_of_add_monoid (A : Type _)
[H : add_monoid A] : add_semigroup A :=
@monoid.to_semigroup A H
@[hott, reducible, instance] def add_inf_monoid_of_add_monoid (A : Type _)
[H : add_monoid A] : add_inf_monoid A :=
@monoid.to_inf_monoid A H
@[hott, class] def add_comm_monoid : Type _ → Type _ := comm_monoid
@[hott, reducible, instance] def add_monoid_of_add_comm_monoid (A : Type _)
[H : add_comm_monoid A] : add_monoid A :=
@comm_monoid.to_monoid A H
@[hott, reducible, instance] def add_comm_semigroup_of_add_comm_monoid (A : Type _)
[H : add_comm_monoid A] : add_comm_semigroup A :=
@comm_monoid.to_comm_semigroup A H
@[hott, reducible, instance] def add_comm_inf_monoid_of_add_comm_monoid (A : Type _)
[H : add_comm_monoid A] : add_comm_inf_monoid A :=
@comm_monoid.to_comm_inf_monoid A H
@[hott] def add_monoid.to_monoid {A : Type _} [s : add_monoid A] : monoid A := s
@[hott] def add_comm_monoid.to_comm_monoid {A : Type _} [s : add_comm_monoid A] : comm_monoid A := s
@[hott] def monoid.to_add_monoid {A : Type _} [s : monoid A] : add_monoid A := s
@[hott] def comm_monoid.to_add_comm_monoid {A : Type _} [s : comm_monoid A] : add_comm_monoid A := s
/- group -/
@[hott, class] structure group (A : Type _) extends monoid A, inf_group A
@[hott] def group_of_inf_group (A : Type _) [s : inf_group A] [is_set A] : group A :=
{is_set_carrier := by apply_instance, ..s}
section group
variable [s : group A]
include s
@[hott, instance] def group.to_left_cancel_semigroup : left_cancel_semigroup A :=
{ mul_left_cancel := @mul_left_cancel A _, ..s }
@[hott, instance] def group.to_right_cancel_semigroup : right_cancel_semigroup A :=
{ mul_right_cancel := @mul_right_cancel A _, ..s }
end group
@[hott, class] structure ab_group (A : Type _) extends group A, comm_monoid A, ab_inf_group A
@[hott] def ab_group_of_ab_inf_group (A : Type _) [s : ab_inf_group A] [is_set A] : ab_group A :=
{ is_set_carrier := by apply_instance, ..s }
/- additive group -/
@[hott, class] def add_group : Type _ → Type _ := group
@[hott, reducible, instance] def add_semigroup_of_add_group (A : Type _)
[H : add_group A] : add_monoid A :=
@group.to_monoid A H
@[hott, reducible, instance] def add_inf_group_of_add_group (A : Type _)
[H : add_group A] : add_inf_group A :=
@group.to_inf_group A H
@[hott] def add_group.to_group {A : Type _} [s : add_group A] : group A := s
@[hott] def group.to_add_group {A : Type _} [s : group A] : add_group A := s
@[hott] def add_group_of_add_inf_group (A : Type _) [s : add_inf_group A] [is_set A] :
add_group A :=
{ is_set_carrier := by apply_instance, ..s}
section add_group
variables [s : add_group A]
include s
@[hott, reducible, instance] def add_group.to_add_left_cancel_semigroup :
add_left_cancel_semigroup A :=
@group.to_left_cancel_semigroup A s
@[hott, reducible, instance] def add_group.to_add_right_cancel_semigroup :
add_right_cancel_semigroup A :=
@group.to_right_cancel_semigroup A s
end add_group
@[hott, class] def add_ab_group : Type _ → Type _ := ab_group
@[hott, reducible, instance] def add_group_of_add_ab_group (A : Type _)
[H : add_ab_group A] : add_group A :=
@ab_group.to_group A H
@[hott, reducible, instance] def add_comm_monoid_of_add_ab_group (A : Type _)
[H : add_ab_group A] : add_comm_monoid A :=
@ab_group.to_comm_monoid A H
@[hott, reducible, instance] def add_ab_inf_group_of_add_ab_group (A : Type _)
[H : add_ab_group A] : add_ab_inf_group A :=
@ab_group.to_ab_inf_group A H
@[hott] def add_ab_group.to_ab_group {A : Type _} [s : add_ab_group A] : ab_group A := s
@[hott] def ab_group.to_add_ab_group {A : Type _} [s : ab_group A] : add_ab_group A := s
@[hott] def add_ab_group_of_add_ab_inf_group (A : Type _) [s : add_ab_inf_group A] [is_set A] :
add_ab_group A :=
{ is_set_carrier := by apply_instance, ..s}
@[hott] def group_of_add_group (A : Type _) [G : add_group A] : group A :=
{ mul := has_add.add,
mul_assoc := add.assoc,
one := has_zero.zero _,
one_mul := zero_add,
mul_one := add_zero,
inv := has_neg.neg,
mul_left_inv := add.left_inv,
is_set_carrier := by apply_instance }
end algebra
end hott
|
381257ac6188447f9aeb3b1b81972561aba09815 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/topology/continuous_function/algebra.lean | 8bde42566f7e98ceb83f675618075a509b188f16 | [
"Apache-2.0"
] | permissive | waynemunro/mathlib | e3fd4ff49f4cb43d4a8ded59d17be407bc5ee552 | 065a70810b5480d584033f7bbf8e0409480c2118 | refs/heads/master | 1,693,417,182,397 | 1,634,644,781,000 | 1,634,644,781,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 24,226 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Nicolò Cavalleri
-/
import topology.algebra.module
import topology.continuous_function.basic
import algebra.algebra.subalgebra
import tactic.field_simp
/-!
# Algebraic structures over continuous functions
In this file we define instances of algebraic structures over the type `continuous_map α β`
(denoted `C(α, β)`) of **bundled** continuous maps from `α` to `β`. For example, `C(α, β)`
is a group when `β` is a group, a ring when `β` is a ring, etc.
For each type of algebraic structure, we also define an appropriate subobject of `α → β`
with carrier `{ f : α → β | continuous f }`. For example, when `β` is a group, a subgroup
`continuous_subgroup α β` of `α → β` is constructed with carrier `{ f : α → β | continuous f }`.
Note that, rather than using the derived algebraic structures on these subobjects
(for example, when `β` is a group, the derived group structure on `continuous_subgroup α β`),
one should use `C(α, β)` with the appropriate instance of the structure.
-/
local attribute [elab_simple] continuous.comp
namespace continuous_functions
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
variables {f g : {f : α → β | continuous f }}
instance : has_coe_to_fun {f : α → β | continuous f} := ⟨_, subtype.val⟩
end continuous_functions
namespace continuous_map
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
@[to_additive]
instance has_mul [has_mul β] [has_continuous_mul β] : has_mul C(α, β) :=
⟨λ f g, ⟨f * g, continuous_mul.comp (f.continuous.prod_mk g.continuous : _)⟩⟩
@[simp, norm_cast, to_additive]
lemma coe_mul [has_mul β] [has_continuous_mul β] (f g : C(α, β)) :
((f * g : C(α, β)) : α → β) = (f : α → β) * (g : α → β) := rfl
@[to_additive]
instance [has_one β] : has_one C(α, β) := ⟨const (1 : β)⟩
@[simp, norm_cast, to_additive]
lemma coe_one [has_one β] :
((1 : C(α, β)) : α → β) = (1 : α → β) := rfl
@[simp, to_additive] lemma mul_comp {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ]
[semigroup γ] [has_continuous_mul γ] (f₁ f₂ : C(β, γ)) (g : C(α, β)) :
(f₁ * f₂).comp g = f₁.comp g * f₂.comp g :=
by { ext, simp, }
@[simp, to_additive] lemma one_comp {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ] [has_one γ] (g : C(α, β)) :
(1 : C(β, γ)).comp g = 1 :=
by { ext, simp, }
end continuous_map
section group_structure
/-!
### Group stucture
In this section we show that continuous functions valued in a topological group inherit
the structure of a group.
-/
section subtype
/-- The `submonoid` of continuous maps `α → β`. -/
@[to_additive "The `add_submonoid` of continuous maps `α → β`. "]
def continuous_submonoid (α : Type*) (β : Type*) [topological_space α] [topological_space β]
[monoid β] [has_continuous_mul β] : submonoid (α → β) :=
{ carrier := { f : α → β | continuous f },
one_mem' := @continuous_const _ _ _ _ 1,
mul_mem' := λ f g fc gc, continuous.comp
has_continuous_mul.continuous_mul (continuous.prod_mk fc gc : _) }
/-- The subgroup of continuous maps `α → β`. -/
@[to_additive "The `add_subgroup` of continuous maps `α → β`. "]
def continuous_subgroup (α : Type*) (β : Type*) [topological_space α] [topological_space β]
[group β] [topological_group β] : subgroup (α → β) :=
{ inv_mem' := λ f fc, continuous.comp (@topological_group.continuous_inv β _ _ _) fc,
..continuous_submonoid α β, }.
end subtype
namespace continuous_map
@[to_additive]
instance {α : Type*} {β : Type*} [topological_space α]
[topological_space β] [semigroup β] [has_continuous_mul β] : semigroup C(α, β) :=
{ mul_assoc := λ a b c, by ext; exact mul_assoc _ _ _,
..continuous_map.has_mul}
@[to_additive]
instance {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[monoid β] [has_continuous_mul β] : monoid C(α, β) :=
{ one_mul := λ a, by ext; exact one_mul _,
mul_one := λ a, by ext; exact mul_one _,
..continuous_map.semigroup,
..continuous_map.has_one }
/-- Coercion to a function as an `monoid_hom`. Similar to `monoid_hom.coe_fn`. -/
@[to_additive "Coercion to a function as an `add_monoid_hom`. Similar to `add_monoid_hom.coe_fn`.",
simps]
def coe_fn_monoid_hom {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[monoid β] [has_continuous_mul β] : C(α, β) →* (α → β) :=
{ to_fun := coe_fn, map_one' := coe_one, map_mul' := coe_mul }
/-- Composition on the left by a (continuous) homomorphism of topological monoids, as a
`monoid_hom`. Similar to `monoid_hom.comp_left`. -/
@[to_additive "Composition on the left by a (continuous) homomorphism of topological `add_monoid`s,
as an `add_monoid_hom`. Similar to `add_monoid_hom.comp_left`.", simps]
protected def _root_.monoid_hom.comp_left_continuous (α : Type*) {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [monoid β] [has_continuous_mul β]
[topological_space γ] [monoid γ] [has_continuous_mul γ] (g : β →* γ) (hg : continuous g) :
C(α, β) →* C(α, γ) :=
{ to_fun := λ f, (⟨g, hg⟩ : C(β, γ)).comp f,
map_one' := ext $ λ x, g.map_one,
map_mul' := λ f₁ f₂, ext $ λ x, g.map_mul _ _ }
/-- Composition on the right as a `monoid_hom`. Similar to `monoid_hom.comp_hom'`. -/
@[to_additive "Composition on the right as an `add_monoid_hom`. Similar to
`add_monoid_hom.comp_hom'`.", simps]
def comp_monoid_hom' {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ]
[monoid γ] [has_continuous_mul γ] (g : C(α, β)) : C(β, γ) →* C(α, γ) :=
{ to_fun := λ f, f.comp g, map_one' := one_comp g, map_mul' := λ f₁ f₂, mul_comp f₁ f₂ g }
@[simp, norm_cast]
lemma coe_pow {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[monoid β] [has_continuous_mul β] (f : C(α, β)) (n : ℕ) :
((f^n : C(α, β)) : α → β) = (f : α → β)^n :=
(coe_fn_monoid_hom : C(α, β) →* _).map_pow f n
@[simp] lemma pow_comp {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ]
[monoid γ] [has_continuous_mul γ] (f : C(β, γ)) (n : ℕ) (g : C(α, β)) :
(f^n).comp g = (f.comp g)^n :=
(comp_monoid_hom' g).map_pow f n
@[to_additive]
instance {α : Type*} {β : Type*} [topological_space α]
[topological_space β] [comm_monoid β] [has_continuous_mul β] : comm_monoid C(α, β) :=
{ one_mul := λ a, by ext; exact one_mul _,
mul_one := λ a, by ext; exact mul_one _,
mul_comm := λ a b, by ext; exact mul_comm _ _,
..continuous_map.semigroup,
..continuous_map.has_one }
open_locale big_operators
@[simp, to_additive] lemma coe_prod {α : Type*} {β : Type*} [comm_monoid β]
[topological_space α] [topological_space β] [has_continuous_mul β]
{ι : Type*} (s : finset ι) (f : ι → C(α, β)) :
⇑(∏ i in s, f i) = (∏ i in s, (f i : α → β)) :=
(coe_fn_monoid_hom : C(α, β) →* _).map_prod f s
@[to_additive]
lemma prod_apply {α : Type*} {β : Type*} [comm_monoid β]
[topological_space α] [topological_space β] [has_continuous_mul β]
{ι : Type*} (s : finset ι) (f : ι → C(α, β)) (a : α) :
(∏ i in s, f i) a = (∏ i in s, f i a) :=
by simp
@[to_additive]
instance {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[group β] [topological_group β] : group C(α, β) :=
{ inv := λ f, ⟨λ x, (f x)⁻¹, continuous_inv.comp f.continuous⟩,
mul_left_inv := λ a, by ext; exact mul_left_inv _,
..continuous_map.monoid }
@[simp, norm_cast, to_additive]
lemma coe_inv {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[group β] [topological_group β] (f : C(α, β)) :
((f⁻¹ : C(α, β)) : α → β) = (f⁻¹ : α → β) :=
rfl
@[simp, norm_cast, to_additive]
lemma coe_div {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[group β] [topological_group β] (f g : C(α, β)) :
((f / g : C(α, β)) : α → β) = (f : α → β) / (g : α → β) :=
by { simp only [div_eq_mul_inv], refl, }
@[simp, to_additive] lemma inv_comp {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ]
[group γ] [topological_group γ] (f : C(β, γ)) (g : C(α, β)) :
(f⁻¹).comp g = (f.comp g)⁻¹ :=
by { ext, simp, }
@[simp, to_additive] lemma div_comp {α : Type*} {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [topological_space γ]
[group γ] [topological_group γ] (f g : C(β, γ)) (h : C(α, β)) :
(f / g).comp h = (f.comp h) / (g.comp h) :=
by { ext, simp, }
@[to_additive]
instance {α : Type*} {β : Type*} [topological_space α]
[topological_space β] [comm_group β] [topological_group β] : comm_group C(α, β) :=
{ ..continuous_map.group,
..continuous_map.comm_monoid }
end continuous_map
end group_structure
section ring_structure
/-!
### Ring stucture
In this section we show that continuous functions valued in a topological ring `R` inherit
the structure of a ring.
-/
section subtype
/-- The subsemiring of continuous maps `α → β`. -/
def continuous_subsemiring (α : Type*) (R : Type*) [topological_space α] [topological_space R]
[semiring R] [topological_ring R] : subsemiring (α → R) :=
{ ..continuous_add_submonoid α R,
..continuous_submonoid α R }.
/-- The subring of continuous maps `α → β`. -/
def continuous_subring (α : Type*) (R : Type*) [topological_space α] [topological_space R]
[ring R] [topological_ring R] : subring (α → R) :=
{ ..continuous_subsemiring α R,
..continuous_add_subgroup α R }.
end subtype
namespace continuous_map
instance {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[semiring β] [topological_ring β] : semiring C(α, β) :=
{ left_distrib := λ a b c, by ext; exact left_distrib _ _ _,
right_distrib := λ a b c, by ext; exact right_distrib _ _ _,
zero_mul := λ a, by ext; exact zero_mul _,
mul_zero := λ a, by ext; exact mul_zero _,
..continuous_map.add_comm_monoid,
..continuous_map.monoid }
instance {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[ring β] [topological_ring β] : ring C(α, β) :=
{ ..continuous_map.semiring,
..continuous_map.add_comm_group, }
instance {α : Type*} {β : Type*} [topological_space α]
[topological_space β] [comm_ring β] [topological_ring β] : comm_ring C(α, β) :=
{ ..continuous_map.semiring,
..continuous_map.add_comm_group,
..continuous_map.comm_monoid,}
/-- Composition on the left by a (continuous) homomorphism of topological rings, as a `ring_hom`.
Similar to `ring_hom.comp_left`. -/
@[simps] protected def _root_.ring_hom.comp_left_continuous (α : Type*) {β : Type*} {γ : Type*}
[topological_space α] [topological_space β] [semiring β] [topological_ring β]
[topological_space γ] [semiring γ] [topological_ring γ] (g : β →+* γ) (hg : continuous g) :
C(α, β) →+* C(α, γ) :=
{ .. g.to_monoid_hom.comp_left_continuous α hg,
.. g.to_add_monoid_hom.comp_left_continuous α hg }
/-- Coercion to a function as a `ring_hom`. -/
@[simps]
def coe_fn_ring_hom {α : Type*} {β : Type*} [topological_space α] [topological_space β]
[ring β] [topological_ring β] : C(α, β) →+* (α → β) :=
{ to_fun := coe_fn,
..(coe_fn_monoid_hom : C(α, β) →* _),
..(coe_fn_add_monoid_hom : C(α, β) →+ _) }
end continuous_map
end ring_structure
local attribute [ext] subtype.eq
section module_structure
/-!
### Semiodule stucture
In this section we show that continuous functions valued in a topological module `M` over a
topological semiring `R` inherit the structure of a module.
-/
section subtype
variables (α : Type*) [topological_space α]
variables (R : Type*) [semiring R] [topological_space R]
variables (M : Type*) [topological_space M] [add_comm_group M]
variables [module R M] [has_continuous_smul R M] [topological_add_group M]
/-- The `R`-submodule of continuous maps `α → M`. -/
def continuous_submodule : submodule R (α → M) :=
{ carrier := { f : α → M | continuous f },
smul_mem' := λ c f hf, continuous_smul.comp
(continuous.prod_mk (continuous_const : continuous (λ x, c)) hf),
..continuous_add_subgroup α M }
end subtype
namespace continuous_map
variables {α : Type*} [topological_space α]
{R : Type*} [semiring R] [topological_space R]
{M : Type*} [topological_space M] [add_comm_monoid M]
{M₂ : Type*} [topological_space M₂] [add_comm_monoid M₂]
instance
[module R M] [has_continuous_smul R M] :
has_scalar R C(α, M) :=
⟨λ r f, ⟨r • f, f.continuous.const_smul r⟩⟩
@[simp, norm_cast]
lemma coe_smul [module R M] [has_continuous_smul R M]
(c : R) (f : C(α, M)) : ⇑(c • f) = c • f := rfl
lemma smul_apply [module R M] [has_continuous_smul R M]
(c : R) (f : C(α, M)) (a : α) : (c • f) a = c • (f a) :=
by simp
@[simp] lemma smul_comp {α : Type*} {β : Type*}
[topological_space α] [topological_space β]
[module R M] [has_continuous_smul R M] (r : R) (f : C(β, M)) (g : C(α, β)) :
(r • f).comp g = r • (f.comp g) :=
by { ext, simp, }
variables [has_continuous_add M] [module R M] [has_continuous_smul R M]
variables [has_continuous_add M₂] [module R M₂] [has_continuous_smul R M₂]
instance module : module R C(α, M) :=
{ smul := (•),
smul_add := λ c f g, by { ext, exact smul_add c (f x) (g x) },
add_smul := λ c₁ c₂ f, by { ext, exact add_smul c₁ c₂ (f x) },
mul_smul := λ c₁ c₂ f, by { ext, exact mul_smul c₁ c₂ (f x) },
one_smul := λ f, by { ext, exact one_smul R (f x) },
zero_smul := λ f, by { ext, exact zero_smul _ _ },
smul_zero := λ r, by { ext, exact smul_zero _ } }
variables (R)
/-- Composition on the left by a continuous linear map, as a `linear_map`.
Similar to `linear_map.comp_left`. -/
@[simps] protected def _root_.continuous_linear_map.comp_left_continuous (α : Type*)
[topological_space α] (g : M →L[R] M₂) :
C(α, M) →ₗ[R] C(α, M₂) :=
{ map_smul' := λ c f, ext $ λ x, g.map_smul' c _,
.. g.to_linear_map.to_add_monoid_hom.comp_left_continuous α g.continuous }
/-- Coercion to a function as a `linear_map`. -/
@[simps]
def coe_fn_linear_map : C(α, M) →ₗ[R] (α → M) :=
{ to_fun := coe_fn,
map_smul' := coe_smul,
..(coe_fn_add_monoid_hom : C(α, M) →+ _) }
end continuous_map
end module_structure
section algebra_structure
/-!
### Algebra structure
In this section we show that continuous functions valued in a topological algebra `A` over a ring
`R` inherit the structure of an algebra. Note that the hypothesis that `A` is a topological algebra
is obtained by requiring that `A` be both a `has_continuous_smul` and a `topological_ring`.-/
section subtype
variables {α : Type*} [topological_space α]
{R : Type*} [comm_semiring R]
{A : Type*} [topological_space A] [semiring A]
[algebra R A] [topological_ring A]
/-- The `R`-subalgebra of continuous maps `α → A`. -/
def continuous_subalgebra : subalgebra R (α → A) :=
{ carrier := { f : α → A | continuous f },
algebra_map_mem' := λ r, (continuous_const : continuous $ λ (x : α), algebra_map R A r),
..continuous_subsemiring α A }
end subtype
section continuous_map
variables {α : Type*} [topological_space α]
{R : Type*} [comm_semiring R]
{A : Type*} [topological_space A] [semiring A]
[algebra R A] [topological_ring A]
{A₂ : Type*} [topological_space A₂] [semiring A₂]
[algebra R A₂] [topological_ring A₂]
/-- Continuous constant functions as a `ring_hom`. -/
def continuous_map.C : R →+* C(α, A) :=
{ to_fun := λ c : R, ⟨λ x: α, ((algebra_map R A) c), continuous_const⟩,
map_one' := by ext x; exact (algebra_map R A).map_one,
map_mul' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_mul _ _,
map_zero' := by ext x; exact (algebra_map R A).map_zero,
map_add' := λ c₁ c₂, by ext x; exact (algebra_map R A).map_add _ _ }
@[simp] lemma continuous_map.C_apply (r : R) (a : α) : continuous_map.C r a = algebra_map R A r :=
rfl
variables [topological_space R] [has_continuous_smul R A] [has_continuous_smul R A₂]
instance continuous_map.algebra : algebra R C(α, A) :=
{ to_ring_hom := continuous_map.C,
commutes' := λ c f, by ext x; exact algebra.commutes' _ _,
smul_def' := λ c f, by ext x; exact algebra.smul_def' _ _, }
variables (R)
/-- Composition on the left by a (continuous) homomorphism of topological `R`-algebras, as an
`alg_hom`. Similar to `alg_hom.comp_left`. -/
@[simps] protected def alg_hom.comp_left_continuous {α : Type*} [topological_space α]
(g : A →ₐ[R] A₂) (hg : continuous g) :
C(α, A) →ₐ[R] C(α, A₂) :=
{ commutes' := λ c, continuous_map.ext $ λ _, g.commutes' _,
.. g.to_ring_hom.comp_left_continuous α hg }
/-- Coercion to a function as an `alg_hom`. -/
@[simps]
def continuous_map.coe_fn_alg_hom : C(α, A) →ₐ[R] (α → A) :=
{ to_fun := coe_fn,
commutes' := λ r, rfl,
-- `..(continuous_map.coe_fn_ring_hom : C(α, A) →+* _)` times out for some reason
map_zero' := continuous_map.coe_zero,
map_one' := continuous_map.coe_one,
map_add' := continuous_map.coe_add,
map_mul' := continuous_map.coe_mul }
instance: is_scalar_tower R A C(α, A) :=
{ smul_assoc := λ _ _ _, by { ext, simp } }
variables {R}
/--
A version of `separates_points` for subalgebras of the continuous functions,
used for stating the Stone-Weierstrass theorem.
-/
abbreviation subalgebra.separates_points (s : subalgebra R C(α, A)) : Prop :=
set.separates_points ((λ f : C(α, A), (f : α → A)) '' (s : set C(α, A)))
lemma subalgebra.separates_points_monotone :
monotone (λ s : subalgebra R C(α, A), s.separates_points) :=
λ s s' r h x y n,
begin
obtain ⟨f, m, w⟩ := h n,
rcases m with ⟨f, ⟨m, rfl⟩⟩,
exact ⟨_, ⟨f, ⟨r m, rfl⟩⟩, w⟩,
end
@[simp] lemma algebra_map_apply (k : R) (a : α) :
algebra_map R C(α, A) k a = k • 1 :=
by { rw algebra.algebra_map_eq_smul_one, refl, }
variables {𝕜 : Type*} [topological_space 𝕜]
/--
A set of continuous maps "separates points strongly"
if for each pair of distinct points there is a function with specified values on them.
We give a slightly unusual formulation, where the specified values are given by some
function `v`, and we ask `f x = v x ∧ f y = v y`. This avoids needing a hypothesis `x ≠ y`.
In fact, this definition would work perfectly well for a set of non-continuous functions,
but as the only current use case is in the Stone-Weierstrass theorem,
writing it this way avoids having to deal with casts inside the set.
(This may need to change if we do Stone-Weierstrass on non-compact spaces,
where the functions would be continuous functions vanishing at infinity.)
-/
def set.separates_points_strongly (s : set C(α, 𝕜)) : Prop :=
∀ (v : α → 𝕜) (x y : α), ∃ f : s, (f x : 𝕜) = v x ∧ f y = v y
variables [field 𝕜] [topological_ring 𝕜]
/--
Working in continuous functions into a topological field,
a subalgebra of functions that separates points also separates points strongly.
By the hypothesis, we can find a function `f` so `f x ≠ f y`.
By an affine transformation in the field we can arrange so that `f x = a` and `f x = b`.
-/
lemma subalgebra.separates_points.strongly {s : subalgebra 𝕜 C(α, 𝕜)} (h : s.separates_points) :
(s : set C(α, 𝕜)).separates_points_strongly :=
λ v x y,
begin
by_cases n : x = y,
{ subst n,
use ((v x) • 1 : C(α, 𝕜)),
{ apply s.smul_mem,
apply s.one_mem, },
{ simp, }, },
obtain ⟨f, ⟨f, ⟨m, rfl⟩⟩, w⟩ := h n,
replace w : f x - f y ≠ 0 := sub_ne_zero_of_ne w,
let a := v x,
let b := v y,
let f' := ((b - a) * (f x - f y)⁻¹) • (continuous_map.C (f x) - f) + continuous_map.C a,
refine ⟨⟨f', _⟩, _, _⟩,
{ simp only [f', set_like.mem_coe, subalgebra.mem_to_submodule],
-- TODO should there be a tactic for this?
-- We could add an attribute `@[subobject_mem]`, and a tactic
-- ``def subobject_mem := `[solve_by_elim with subobject_mem { max_depth := 10 }]``
solve_by_elim
[subalgebra.add_mem, subalgebra.smul_mem, subalgebra.sub_mem, subalgebra.algebra_map_mem]
{ max_depth := 6 }, },
{ simp [f'], },
{ simp [f', inv_mul_cancel_right₀ w], },
end
end continuous_map
-- TODO[gh-6025]: make this an instance once safe to do so
lemma continuous_map.subsingleton_subalgebra (α : Type*) [topological_space α]
(R : Type*) [comm_semiring R] [topological_space R] [topological_ring R]
[subsingleton α] : subsingleton (subalgebra R C(α, R)) :=
begin
fsplit,
intros s₁ s₂,
by_cases n : nonempty α,
{ obtain ⟨x⟩ := n,
ext f,
have h : f = algebra_map R C(α, R) (f x),
{ ext x', simp only [mul_one, algebra.id.smul_eq_mul, algebra_map_apply], congr, },
rw h,
simp only [subalgebra.algebra_map_mem], },
{ ext f,
have h : f = 0,
{ ext x', exact false.elim (n ⟨x'⟩), },
subst h,
simp only [subalgebra.zero_mem], },
end
end algebra_structure
section module_over_continuous_functions
/-!
### Structure as module over scalar functions
If `M` is a module over `R`, then we show that the space of continuous functions from `α` to `M`
is naturally a module over the ring of continuous functions from `α` to `R`. -/
namespace continuous_map
instance has_scalar' {α : Type*} [topological_space α]
{R : Type*} [semiring R] [topological_space R]
{M : Type*} [topological_space M] [add_comm_monoid M]
[module R M] [has_continuous_smul R M] :
has_scalar C(α, R) C(α, M) :=
⟨λ f g, ⟨λ x, (f x) • (g x), (continuous.smul f.2 g.2)⟩⟩
instance module' {α : Type*} [topological_space α]
(R : Type*) [ring R] [topological_space R] [topological_ring R]
(M : Type*) [topological_space M] [add_comm_monoid M] [has_continuous_add M]
[module R M] [has_continuous_smul R M] :
module C(α, R) C(α, M) :=
{ smul := (•),
smul_add := λ c f g, by ext x; exact smul_add (c x) (f x) (g x),
add_smul := λ c₁ c₂ f, by ext x; exact add_smul (c₁ x) (c₂ x) (f x),
mul_smul := λ c₁ c₂ f, by ext x; exact mul_smul (c₁ x) (c₂ x) (f x),
one_smul := λ f, by ext x; exact one_smul R (f x),
zero_smul := λ f, by ext x; exact zero_smul _ _,
smul_zero := λ r, by ext x; exact smul_zero _, }
end continuous_map
end module_over_continuous_functions
/-!
We now provide formulas for `f ⊓ g` and `f ⊔ g`, where `f g : C(α, β)`,
in terms of `continuous_map.abs`.
-/
section
variables {R : Type*} [linear_ordered_field R]
-- TODO:
-- This lemma (and the next) could go all the way back in `algebra.order.field`,
-- except that it is tedious to prove without tactics.
-- Rather than stranding it at some intermediate location,
-- it's here, immediately prior to the point of use.
lemma min_eq_half_add_sub_abs_sub {x y : R} : min x y = 2⁻¹ * (x + y - |x - y|) :=
by cases le_total x y with h h; field_simp [h, abs_of_nonneg, abs_of_nonpos, mul_two]; abel
lemma max_eq_half_add_add_abs_sub {x y : R} : max x y = 2⁻¹ * (x + y + |x - y|) :=
by cases le_total x y with h h; field_simp [h, abs_of_nonneg, abs_of_nonpos, mul_two]; abel
end
namespace continuous_map
section lattice
variables {α : Type*} [topological_space α]
variables {β : Type*} [linear_ordered_field β] [topological_space β]
[order_topology β] [topological_ring β]
lemma inf_eq (f g : C(α, β)) : f ⊓ g = (2⁻¹ : β) • (f + g - |f - g|) :=
ext (λ x, by simpa using min_eq_half_add_sub_abs_sub)
-- Not sure why this is grosser than `inf_eq`:
lemma sup_eq (f g : C(α, β)) : f ⊔ g = (2⁻¹ : β) • (f + g + |f - g|) :=
ext (λ x, by simpa [mul_add] using @max_eq_half_add_add_abs_sub _ _ (f x) (g x))
end lattice
end continuous_map
|
ee3f9bc14560f74743df2c81dd5057bf33a0539a | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /tests/lean/run/task_test_io.lean | 3a7bd2775ca6afe1bce4024d6b326f9c167d2615 | [
"Apache-2.0"
] | permissive | dupuisf/lean4 | d082d13b01243e1de29ae680eefb476961221eef | 6a39c65bd28eb0e28c3870188f348c8914502718 | refs/heads/master | 1,676,948,755,391 | 1,610,665,114,000 | 1,610,665,114,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 922 | lean | #lang lean4
#eval id (α := IO _) do
let t1 ← IO.asTask $ Nat.forM 10 fun _ => IO.println "hi";
let t2 ← IO.asTask $ Nat.forM 10 fun _ => IO.println "ho";
IO.ofExcept t1.get
#eval id (α := IO _) do
let t1 ← IO.mapTask IO.println (Task.spawn fun _ => "ha");
pure ()
#eval id (α := IO _) do
let t1 ← IO.bindTask (Task.spawn fun _ => "hu") fun s =>
IO.asTask (IO.println s);
pure ()
#eval id (α := IO _) do
let t1 ← IO.asTask do {
let c ← IO.checkCanceled;
IO.println (if c then "canceled!" else "done!")
};
pure ()
#eval id (α := IO _) do
let t1 ← IO.asTask do {
let c ← IO.checkCanceled;
IO.println (if c then "canceled! 2" else "done! 2")
};
IO.cancel t1;
discard $ IO.wait t1;
pure ()
#eval IO.waitAny [
Task.spawn fun _ => dbgSleep 2 fun _ => "A",
Task.spawn fun _ => dbgSleep 3 fun _ => "B",
Task.spawn fun _ => dbgSleep 1 fun _ => "C"
]
|
96784c8463b66c829cc1446b84da64ff3d2cbc5e | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/PreSemiring.lean | b26b6a27c1eb735c7d040bd5066f4c33e9773d05 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,602 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section PreSemiring
structure PreSemiring (A : Type) : Type :=
(times : (A → (A → A)))
(plus : (A → (A → A)))
(associative_times : (∀ {x y z : A} , (times (times x y) z) = (times x (times y z))))
(leftDistributive_times_plus : (∀ {x y z : A} , (times x (plus y z)) = (plus (times x y) (times x z))))
(commutative_plus : (∀ {x y : A} , (plus x y) = (plus y x)))
(associative_plus : (∀ {x y z : A} , (plus (plus x y) z) = (plus x (plus y z))))
(rightDistributive_times_plus : (∀ {x y z : A} , (times (plus y z) x) = (plus (times y x) (times z x))))
open PreSemiring
structure Sig (AS : Type) : Type :=
(timesS : (AS → (AS → AS)))
(plusS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(timesP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(plusP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(associative_timesP : (∀ {xP yP zP : (Prod A A)} , (timesP (timesP xP yP) zP) = (timesP xP (timesP yP zP))))
(leftDistributive_times_plusP : (∀ {xP yP zP : (Prod A A)} , (timesP xP (plusP yP zP)) = (plusP (timesP xP yP) (timesP xP zP))))
(commutative_plusP : (∀ {xP yP : (Prod A A)} , (plusP xP yP) = (plusP yP xP)))
(associative_plusP : (∀ {xP yP zP : (Prod A A)} , (plusP (plusP xP yP) zP) = (plusP xP (plusP yP zP))))
(rightDistributive_times_plusP : (∀ {xP yP zP : (Prod A A)} , (timesP (plusP yP zP) xP) = (plusP (timesP yP xP) (timesP zP xP))))
structure Hom {A1 : Type} {A2 : Type} (Pr1 : (PreSemiring A1)) (Pr2 : (PreSemiring A2)) : Type :=
(hom : (A1 → A2))
(pres_times : (∀ {x1 x2 : A1} , (hom ((times Pr1) x1 x2)) = ((times Pr2) (hom x1) (hom x2))))
(pres_plus : (∀ {x1 x2 : A1} , (hom ((plus Pr1) x1 x2)) = ((plus Pr2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Pr1 : (PreSemiring A1)) (Pr2 : (PreSemiring A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_times : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((times Pr1) x1 x2) ((times Pr2) y1 y2))))))
(interp_plus : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((plus Pr1) x1 x2) ((plus Pr2) y1 y2))))))
inductive PreSemiringTerm : Type
| timesL : (PreSemiringTerm → (PreSemiringTerm → PreSemiringTerm))
| plusL : (PreSemiringTerm → (PreSemiringTerm → PreSemiringTerm))
open PreSemiringTerm
inductive ClPreSemiringTerm (A : Type) : Type
| sing : (A → ClPreSemiringTerm)
| timesCl : (ClPreSemiringTerm → (ClPreSemiringTerm → ClPreSemiringTerm))
| plusCl : (ClPreSemiringTerm → (ClPreSemiringTerm → ClPreSemiringTerm))
open ClPreSemiringTerm
inductive OpPreSemiringTerm (n : ℕ) : Type
| v : ((fin n) → OpPreSemiringTerm)
| timesOL : (OpPreSemiringTerm → (OpPreSemiringTerm → OpPreSemiringTerm))
| plusOL : (OpPreSemiringTerm → (OpPreSemiringTerm → OpPreSemiringTerm))
open OpPreSemiringTerm
inductive OpPreSemiringTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpPreSemiringTerm2)
| sing2 : (A → OpPreSemiringTerm2)
| timesOL2 : (OpPreSemiringTerm2 → (OpPreSemiringTerm2 → OpPreSemiringTerm2))
| plusOL2 : (OpPreSemiringTerm2 → (OpPreSemiringTerm2 → OpPreSemiringTerm2))
open OpPreSemiringTerm2
def simplifyCl {A : Type} : ((ClPreSemiringTerm A) → (ClPreSemiringTerm A))
| (timesCl x1 x2) := (timesCl (simplifyCl x1) (simplifyCl x2))
| (plusCl x1 x2) := (plusCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpPreSemiringTerm n) → (OpPreSemiringTerm n))
| (timesOL x1 x2) := (timesOL (simplifyOpB x1) (simplifyOpB x2))
| (plusOL x1 x2) := (plusOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpPreSemiringTerm2 n A) → (OpPreSemiringTerm2 n A))
| (timesOL2 x1 x2) := (timesOL2 (simplifyOp x1) (simplifyOp x2))
| (plusOL2 x1 x2) := (plusOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((PreSemiring A) → (PreSemiringTerm → A))
| Pr (timesL x1 x2) := ((times Pr) (evalB Pr x1) (evalB Pr x2))
| Pr (plusL x1 x2) := ((plus Pr) (evalB Pr x1) (evalB Pr x2))
def evalCl {A : Type} : ((PreSemiring A) → ((ClPreSemiringTerm A) → A))
| Pr (sing x1) := x1
| Pr (timesCl x1 x2) := ((times Pr) (evalCl Pr x1) (evalCl Pr x2))
| Pr (plusCl x1 x2) := ((plus Pr) (evalCl Pr x1) (evalCl Pr x2))
def evalOpB {A : Type} {n : ℕ} : ((PreSemiring A) → ((vector A n) → ((OpPreSemiringTerm n) → A)))
| Pr vars (v x1) := (nth vars x1)
| Pr vars (timesOL x1 x2) := ((times Pr) (evalOpB Pr vars x1) (evalOpB Pr vars x2))
| Pr vars (plusOL x1 x2) := ((plus Pr) (evalOpB Pr vars x1) (evalOpB Pr vars x2))
def evalOp {A : Type} {n : ℕ} : ((PreSemiring A) → ((vector A n) → ((OpPreSemiringTerm2 n A) → A)))
| Pr vars (v2 x1) := (nth vars x1)
| Pr vars (sing2 x1) := x1
| Pr vars (timesOL2 x1 x2) := ((times Pr) (evalOp Pr vars x1) (evalOp Pr vars x2))
| Pr vars (plusOL2 x1 x2) := ((plus Pr) (evalOp Pr vars x1) (evalOp Pr vars x2))
def inductionB {P : (PreSemiringTerm → Type)} : ((∀ (x1 x2 : PreSemiringTerm) , ((P x1) → ((P x2) → (P (timesL x1 x2))))) → ((∀ (x1 x2 : PreSemiringTerm) , ((P x1) → ((P x2) → (P (plusL x1 x2))))) → (∀ (x : PreSemiringTerm) , (P x))))
| ptimesl pplusl (timesL x1 x2) := (ptimesl _ _ (inductionB ptimesl pplusl x1) (inductionB ptimesl pplusl x2))
| ptimesl pplusl (plusL x1 x2) := (pplusl _ _ (inductionB ptimesl pplusl x1) (inductionB ptimesl pplusl x2))
def inductionCl {A : Type} {P : ((ClPreSemiringTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClPreSemiringTerm A)) , ((P x1) → ((P x2) → (P (timesCl x1 x2))))) → ((∀ (x1 x2 : (ClPreSemiringTerm A)) , ((P x1) → ((P x2) → (P (plusCl x1 x2))))) → (∀ (x : (ClPreSemiringTerm A)) , (P x)))))
| psing ptimescl ppluscl (sing x1) := (psing x1)
| psing ptimescl ppluscl (timesCl x1 x2) := (ptimescl _ _ (inductionCl psing ptimescl ppluscl x1) (inductionCl psing ptimescl ppluscl x2))
| psing ptimescl ppluscl (plusCl x1 x2) := (ppluscl _ _ (inductionCl psing ptimescl ppluscl x1) (inductionCl psing ptimescl ppluscl x2))
def inductionOpB {n : ℕ} {P : ((OpPreSemiringTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpPreSemiringTerm n)) , ((P x1) → ((P x2) → (P (timesOL x1 x2))))) → ((∀ (x1 x2 : (OpPreSemiringTerm n)) , ((P x1) → ((P x2) → (P (plusOL x1 x2))))) → (∀ (x : (OpPreSemiringTerm n)) , (P x)))))
| pv ptimesol pplusol (v x1) := (pv x1)
| pv ptimesol pplusol (timesOL x1 x2) := (ptimesol _ _ (inductionOpB pv ptimesol pplusol x1) (inductionOpB pv ptimesol pplusol x2))
| pv ptimesol pplusol (plusOL x1 x2) := (pplusol _ _ (inductionOpB pv ptimesol pplusol x1) (inductionOpB pv ptimesol pplusol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpPreSemiringTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpPreSemiringTerm2 n A)) , ((P x1) → ((P x2) → (P (timesOL2 x1 x2))))) → ((∀ (x1 x2 : (OpPreSemiringTerm2 n A)) , ((P x1) → ((P x2) → (P (plusOL2 x1 x2))))) → (∀ (x : (OpPreSemiringTerm2 n A)) , (P x))))))
| pv2 psing2 ptimesol2 pplusol2 (v2 x1) := (pv2 x1)
| pv2 psing2 ptimesol2 pplusol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 ptimesol2 pplusol2 (timesOL2 x1 x2) := (ptimesol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 x2))
| pv2 psing2 ptimesol2 pplusol2 (plusOL2 x1 x2) := (pplusol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 x2))
def stageB : (PreSemiringTerm → (Staged PreSemiringTerm))
| (timesL x1 x2) := (stage2 timesL (codeLift2 timesL) (stageB x1) (stageB x2))
| (plusL x1 x2) := (stage2 plusL (codeLift2 plusL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClPreSemiringTerm A) → (Staged (ClPreSemiringTerm A)))
| (sing x1) := (Now (sing x1))
| (timesCl x1 x2) := (stage2 timesCl (codeLift2 timesCl) (stageCl x1) (stageCl x2))
| (plusCl x1 x2) := (stage2 plusCl (codeLift2 plusCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpPreSemiringTerm n) → (Staged (OpPreSemiringTerm n)))
| (v x1) := (const (code (v x1)))
| (timesOL x1 x2) := (stage2 timesOL (codeLift2 timesOL) (stageOpB x1) (stageOpB x2))
| (plusOL x1 x2) := (stage2 plusOL (codeLift2 plusOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpPreSemiringTerm2 n A) → (Staged (OpPreSemiringTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (timesOL2 x1 x2) := (stage2 timesOL2 (codeLift2 timesOL2) (stageOp x1) (stageOp x2))
| (plusOL2 x1 x2) := (stage2 plusOL2 (codeLift2 plusOL2) (stageOp x1) (stageOp x2))
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(timesT : ((Repr A) → ((Repr A) → (Repr A))))
(plusT : ((Repr A) → ((Repr A) → (Repr A))))
end PreSemiring |
2fac244e3800e06b471ac84f05e4c3d4e045830f | 26ac254ecb57ffcb886ff709cf018390161a9225 | /src/measure_theory/borel_space.lean | 2872c50f41812ac8ee470312a694bade85d41e22 | [
"Apache-2.0"
] | permissive | eric-wieser/mathlib | 42842584f584359bbe1fc8b88b3ff937c8acd72d | d0df6b81cd0920ad569158c06a3fd5abb9e63301 | refs/heads/master | 1,669,546,404,255 | 1,595,254,668,000 | 1,595,254,668,000 | 281,173,504 | 0 | 0 | Apache-2.0 | 1,595,263,582,000 | 1,595,263,581,000 | null | UTF-8 | Lean | false | false | 29,479 | lean | /-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Yury Kudryashov
-/
import measure_theory.measurable_space
import topology.instances.ennreal
import analysis.normed_space.basic
/-!
# Borel (measurable) space
## Main definitions
* `borel α` : the least `σ`-algebra that contains all open sets;
* `class borel_space` : a space with `topological_space` and `measurable_space` structures
such that `‹measurable_space α› = borel α`;
* `class opens_measurable_space` : a space with `topological_space` and `measurable_space`
structures such that all open sets are measurable; equivalently, `borel α ≤ ‹measurable_space α›`.
* `borel_space` instances on `empty`, `unit`, `bool`, `nat`, `int`, `rat`;
* `measurable` and `borel_space` instances on `ℝ`, `ℝ≥0`, `ennreal`.
## Main statements
* `is_open.is_measurable`, `is_closed.is_measurable`: open and closed sets are measurable;
* `continuous.measurable` : a continuous function is measurable;
* `continuous.measurable2` : if `f : α → β` and `g : α → γ` are measurable and `op : β × γ → δ`
is continuous, then `λ x, op (f x, g y)` is measurable;
* `measurable.add` etc : dot notation for arithmetic operations on `measurable` predicates,
and similarly for `dist` and `edist`;
* `measurable.ennreal*` : special cases for arithmetic operations on `ennreal`s.
-/
noncomputable theory
open classical set
open_locale classical big_operators
universes u v w x y
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} {ι : Sort y} {s t u : set α}
open measurable_space topological_space
/-- `measurable_space` structure generated by `topological_space`. -/
def borel (α : Type u) [topological_space α] : measurable_space α :=
generate_from {s : set α | is_open s}
lemma borel_eq_top_of_discrete [topological_space α] [discrete_topology α] :
borel α = ⊤ :=
top_le_iff.1 $ λ s hs, generate_measurable.basic s (is_open_discrete s)
lemma borel_eq_top_of_encodable [topological_space α] [t1_space α] [encodable α] :
borel α = ⊤ :=
begin
refine (top_le_iff.1 $ λ s hs, bUnion_of_singleton s ▸ _),
apply is_measurable.bUnion s.countable_encodable,
intros x hx,
apply is_measurable.of_compl,
apply generate_measurable.basic,
exact is_closed_singleton
end
lemma borel_eq_generate_from_of_subbasis {s : set (set α)}
[t : topological_space α] [second_countable_topology α] (hs : t = generate_from s) :
borel α = generate_from s :=
le_antisymm
(generate_from_le $ assume u (hu : t.is_open u),
begin
rw [hs] at hu,
induction hu,
case generate_open.basic : u hu
{ exact generate_measurable.basic u hu },
case generate_open.univ
{ exact @is_measurable.univ α (generate_from s) },
case generate_open.inter : s₁ s₂ _ _ hs₁ hs₂
{ exact @is_measurable.inter α (generate_from s) _ _ hs₁ hs₂ },
case generate_open.sUnion : f hf ih {
rcases is_open_sUnion_countable f (by rwa hs) with ⟨v, hv, vf, vu⟩,
rw ← vu,
exact @is_measurable.sUnion α (generate_from s) _ hv
(λ x xv, ih _ (vf xv)) }
end)
(generate_from_le $ assume u hu, generate_measurable.basic _ $
show t.is_open u, by rw [hs]; exact generate_open.basic _ hu)
lemma borel_eq_generate_Iio (α)
[topological_space α] [second_countable_topology α]
[linear_order α] [order_topology α] :
borel α = generate_from (range Iio) :=
begin
refine le_antisymm _ (generate_from_le _),
{ rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals α _ _ _),
have H : ∀ a:α, is_measurable (measurable_space.generate_from (range Iio)) (Iio a) :=
λ a, generate_measurable.basic _ ⟨_, rfl⟩,
refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩; [skip, apply H],
by_cases h : ∃ a', ∀ b, a < b ↔ a' ≤ b,
{ rcases h with ⟨a', ha'⟩,
rw (_ : Ioi a = (Iio a')ᶜ), {exact (H _).compl _},
simp [set.ext_iff, ha'] },
{ rcases is_open_Union_countable
(λ a' : {a' : α // a < a'}, {b | a'.1 < b})
(λ a', is_open_lt' _) with ⟨v, ⟨hv⟩, vu⟩,
simp [set.ext_iff] at vu,
have : Ioi a = ⋃ x : v, (Iio x.1.1)ᶜ,
{ simp [set.ext_iff],
refine λ x, ⟨λ ax, _, λ ⟨a', ⟨h, av⟩, ax⟩, lt_of_lt_of_le h ax⟩,
rcases (vu x).2 _ with ⟨a', h₁, h₂⟩,
{ exact ⟨a', h₁, le_of_lt h₂⟩ },
refine not_imp_comm.1 (λ h, _) h,
exact ⟨x, λ b, ⟨λ ab, le_of_not_lt (λ h', h ⟨b, ab, h'⟩),
lt_of_lt_of_le ax⟩⟩ },
rw this, resetI,
apply is_measurable.Union,
exact λ _, (H _).compl _ } },
{ simp, rintro _ a rfl,
exact generate_measurable.basic _ is_open_Iio }
end
lemma borel_eq_generate_Ioi (α)
[topological_space α] [second_countable_topology α]
[linear_order α] [order_topology α] :
borel α = generate_from (range Ioi) :=
begin
refine le_antisymm _ (generate_from_le _),
{ rw borel_eq_generate_from_of_subbasis (@order_topology.topology_eq_generate_intervals α _ _ _),
have H : ∀ a:α, is_measurable (measurable_space.generate_from (range (λ a, {x | a < x})))
{x | a < x} := λ a, generate_measurable.basic _ ⟨_, rfl⟩,
refine generate_from_le _, rintro _ ⟨a, rfl | rfl⟩, {apply H},
by_cases h : ∃ a', ∀ b, b < a ↔ b ≤ a',
{ rcases h with ⟨a', ha'⟩,
rw (_ : Iio a = (Ioi a')ᶜ), {exact (H _).compl _},
simp [set.ext_iff, ha'] },
{ rcases is_open_Union_countable
(λ a' : {a' : α // a' < a}, {b | b < a'.1})
(λ a', is_open_gt' _) with ⟨v, ⟨hv⟩, vu⟩,
simp [set.ext_iff] at vu,
have : Iio a = ⋃ x : v, (Ioi x.1.1)ᶜ,
{ simp [set.ext_iff],
refine λ x, ⟨λ ax, _, λ ⟨a', ⟨h, av⟩, ax⟩, lt_of_le_of_lt ax h⟩,
rcases (vu x).2 _ with ⟨a', h₁, h₂⟩,
{ exact ⟨a', h₁, le_of_lt h₂⟩ },
refine not_imp_comm.1 (λ h, _) h,
exact ⟨x, λ b, ⟨λ ab, le_of_not_lt (λ h', h ⟨b, ab, h'⟩),
λ h, lt_of_le_of_lt h ax⟩⟩ },
rw this, resetI,
apply is_measurable.Union,
exact λ _, (H _).compl _ } },
{ simp, rintro _ a rfl,
exact generate_measurable.basic _ (is_open_lt' _) }
end
lemma borel_comap {f : α → β} {t : topological_space β} :
@borel α (t.induced f) = (@borel β t).comap f :=
comap_generate_from.symm
lemma continuous.borel_measurable [topological_space α] [topological_space β]
{f : α → β} (hf : continuous f) :
@measurable α β (borel α) (borel β) f :=
measurable.of_le_map $ generate_from_le $
λ s hs, generate_measurable.basic (f ⁻¹' s) (hf s hs)
/-- A space with `measurable_space` and `topological_space` structures such that
all open sets are measurable. -/
class opens_measurable_space (α : Type*) [topological_space α] [h : measurable_space α] : Prop :=
(borel_le : borel α ≤ h)
/-- A space with `measurable_space` and `topological_space` structures such that
the `σ`-algebra of measurable sets is exactly the `σ`-algebra generated by open sets. -/
class borel_space (α : Type*) [topological_space α] [measurable_space α] : Prop :=
(measurable_eq : ‹measurable_space α› = borel α)
/-- In a `borel_space` all open sets are measurable. -/
@[priority 100]
instance borel_space.opens_measurable {α : Type*} [topological_space α] [measurable_space α]
[borel_space α] : opens_measurable_space α :=
⟨ge_of_eq $ borel_space.measurable_eq⟩
instance subtype.borel_space {α : Type*} [topological_space α] [measurable_space α]
[hα : borel_space α] (s : set α) :
borel_space s :=
⟨by { rw [hα.1, subtype.measurable_space, ← borel_comap], refl }⟩
instance subtype.opens_measurable_space {α : Type*} [topological_space α] [measurable_space α]
[h : opens_measurable_space α] (s : set α) :
opens_measurable_space s :=
⟨by { rw [borel_comap], exact comap_mono h.1 }⟩
section
variables [topological_space α] [measurable_space α] [opens_measurable_space α]
[topological_space β] [measurable_space β] [opens_measurable_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[measurable_space δ]
lemma is_open.is_measurable (h : is_open s) : is_measurable s :=
opens_measurable_space.borel_le _ $ generate_measurable.basic _ h
lemma is_measurable_interior : is_measurable (interior s) := is_open_interior.is_measurable
lemma is_closed.is_measurable (h : is_closed s) : is_measurable s :=
is_measurable.compl_iff.1 $ h.is_measurable
lemma is_compact.is_measurable [t2_space α] (h : is_compact s) : is_measurable s :=
h.is_closed.is_measurable
lemma is_measurable_closure : is_measurable (closure s) :=
is_closed_closure.is_measurable
@[priority 100] -- see Note [lower instance priority]
instance opens_measurable_space.to_measurable_singleton_class [t1_space α] :
measurable_singleton_class α :=
⟨λ x, is_closed_singleton.is_measurable⟩
section order_closed_topology
variables [preorder α] [order_closed_topology α] {a b : α}
lemma is_measurable_Ici : is_measurable (Ici a) := is_closed_Ici.is_measurable
lemma is_measurable_Iic : is_measurable (Iic a) := is_closed_Iic.is_measurable
lemma is_measurable_Icc : is_measurable (Icc a b) := is_closed_Icc.is_measurable
end order_closed_topology
section order_closed_topology
variables [linear_order α] [order_closed_topology α] {a b : α}
lemma is_measurable_Iio : is_measurable (Iio a) := is_open_Iio.is_measurable
lemma is_measurable_Ioi : is_measurable (Ioi a) := is_open_Ioi.is_measurable
lemma is_measurable_Ioo : is_measurable (Ioo a b) := is_open_Ioo.is_measurable
lemma is_measurable_Ioc : is_measurable (Ioc a b) := is_measurable_Ioi.inter is_measurable_Iic
lemma is_measurable_Ico : is_measurable (Ico a b) := is_measurable_Ici.inter is_measurable_Iio
end order_closed_topology
lemma is_measurable_interval [decidable_linear_order α] [order_closed_topology α] {a b : α} :
is_measurable (interval a b) :=
is_measurable_Icc
instance prod.opens_measurable_space [second_countable_topology α] [second_countable_topology β] :
opens_measurable_space (α × β) :=
begin
refine ⟨_⟩,
rcases is_open_generated_countable_inter α with ⟨a, ha₁, ha₂, ha₃, ha₄, ha₅⟩,
rcases is_open_generated_countable_inter β with ⟨b, hb₁, hb₂, hb₃, hb₄, hb₅⟩,
have : prod.topological_space = generate_from {g | ∃u∈a, ∃v∈b, g = set.prod u v},
{ rw [ha₅, hb₅], exact prod_generate_from_generate_from_eq ha₄ hb₄ },
rw [borel_eq_generate_from_of_subbasis this],
apply generate_from_le,
rintros _ ⟨u, hu, v, hv, rfl⟩,
have hu : is_open u, by { rw [ha₅], exact generate_open.basic _ hu },
have hv : is_open v, by { rw [hb₅], exact generate_open.basic _ hv },
exact hu.is_measurable.prod hv.is_measurable
end
/-- A continuous function from an `opens_measurable_space` to a `borel_space`
is measurable. -/
lemma continuous.measurable {f : α → γ} (hf : continuous f) :
measurable f :=
hf.borel_measurable.mono opens_measurable_space.borel_le
(le_of_eq $ borel_space.measurable_eq)
/-- A homeomorphism between two Borel spaces is a measurable equivalence.-/
def homeomorph.to_measurable_equiv {α : Type*} {β : Type*} [topological_space α]
[measurable_space α] [borel_space α] [topological_space β] [measurable_space β]
[borel_space β] (h : α ≃ₜ β) :
measurable_equiv α β :=
{ measurable_to_fun := h.continuous_to_fun.measurable,
measurable_inv_fun := h.continuous_inv_fun.measurable,
.. h }
lemma measurable_of_continuous_on_compl_singleton [t1_space α] {f : α → γ} (a : α)
(hf : continuous_on f {x | x ≠ a}) :
measurable f :=
measurable_of_measurable_on_compl_singleton a
(continuous_on_iff_continuous_restrict.1 hf).measurable
lemma continuous.measurable2 [second_countable_topology α] [second_countable_topology β]
{f : δ → α} {g : δ → β} {c : α → β → γ}
(h : continuous (λp:α×β, c p.1 p.2)) (hf : measurable f) (hg : measurable g) :
measurable (λa, c (f a) (g a)) :=
h.measurable.comp (hf.prod_mk hg)
lemma measurable.smul [semiring α] [second_countable_topology α]
[add_comm_monoid γ] [second_countable_topology γ]
[semimodule α γ] [topological_semimodule α γ]
{f : δ → α} {g : δ → γ} (hf : measurable f) (hg : measurable g) :
measurable (λ c, f c • g c) :=
continuous_smul.measurable2 hf hg
lemma measurable.const_smul {α : Type*} [topological_space α] [semiring α]
[add_comm_monoid γ] [semimodule α γ] [topological_semimodule α γ]
{f : δ → γ} (hf : measurable f) (c : α) :
measurable (λ x, c • f x) :=
(continuous_const.smul continuous_id).measurable.comp hf
lemma measurable_const_smul_iff {α : Type*} [topological_space α]
[division_ring α] [add_comm_monoid γ]
[semimodule α γ] [topological_semimodule α γ]
{f : δ → γ} {c : α} (hc : c ≠ 0) :
measurable (λ x, c • f x) ↔ measurable f :=
⟨λ h, by simpa only [smul_smul, inv_mul_cancel hc, one_smul] using h.const_smul c⁻¹,
λ h, h.const_smul c⟩
lemma is_measurable_le' [partial_order α] [order_closed_topology α] [second_countable_topology α] :
is_measurable {p : α × α | p.1 ≤ p.2} :=
order_closed_topology.is_closed_le'.is_measurable
lemma is_measurable_le [partial_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
is_measurable {a | f a ≤ g a} :=
hf.prod_mk hg is_measurable_le'
lemma measurable.max [decidable_linear_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λa, max (f a) (g a)) :=
hg.piecewise (is_measurable_le hf hg) hf
lemma measurable.min [decidable_linear_order α] [order_closed_topology α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λa, min (f a) (g a)) :=
hf.piecewise (is_measurable_le hf hg) hg
end
section borel_space
variables [topological_space α] [measurable_space α] [borel_space α]
[topological_space β] [measurable_space β] [borel_space β]
[topological_space γ] [measurable_space γ] [borel_space γ]
[measurable_space δ]
lemma prod_le_borel_prod : prod.measurable_space ≤ borel (α × β) :=
begin
rw [‹borel_space α›.measurable_eq, ‹borel_space β›.measurable_eq],
refine sup_le _ _,
{ exact comap_le_iff_le_map.mpr continuous_fst.borel_measurable },
{ exact comap_le_iff_le_map.mpr continuous_snd.borel_measurable }
end
instance prod.borel_space [second_countable_topology α] [second_countable_topology β] :
borel_space (α × β) :=
⟨le_antisymm prod_le_borel_prod opens_measurable_space.borel_le⟩
@[to_additive]
lemma measurable_mul [monoid α] [topological_monoid α] [second_countable_topology α] :
measurable (λ p : α × α, p.1 * p.2) :=
continuous_mul.measurable
@[to_additive]
lemma measurable.mul [monoid α] [topological_monoid α] [second_countable_topology α]
{f : δ → α} {g : δ → α} : measurable f → measurable g → measurable (λa, f a * g a) :=
continuous_mul.measurable2
@[to_additive]
lemma finset.measurable_prod {ι : Type*} [comm_monoid α] [topological_monoid α]
[second_countable_topology α] {f : ι → δ → α} (s : finset ι) (hf : ∀i, measurable (f i)) :
measurable (λa, ∏ i in s, f i a) :=
finset.induction_on s
(by simp only [finset.prod_empty, measurable_const])
(assume i s his ih, by simpa [his] using (hf i).mul ih)
@[to_additive]
lemma measurable_inv [group α] [topological_group α] : measurable (has_inv.inv : α → α) :=
continuous_inv.measurable
@[to_additive]
lemma measurable.inv [group α] [topological_group α] {f : δ → α} (hf : measurable f) :
measurable (λa, (f a)⁻¹) :=
measurable_inv.comp hf
lemma measurable_inv' {α : Type*} [normed_field α] [measurable_space α] [borel_space α] :
measurable (has_inv.inv : α → α) :=
measurable_of_continuous_on_compl_singleton 0 normed_field.continuous_on_inv
lemma measurable.inv' {α : Type*} [normed_field α] [measurable_space α] [borel_space α]
{f : δ → α} (hf : measurable f) :
measurable (λa, (f a)⁻¹) :=
measurable_inv'.comp hf
@[to_additive]
lemma measurable.of_inv [group α] [topological_group α] {f : δ → α}
(hf : measurable (λ a, (f a)⁻¹)) : measurable f :=
by simpa only [inv_inv] using hf.inv
@[simp, to_additive]
lemma measurable_inv_iff [group α] [topological_group α] {f : δ → α} :
measurable (λ a, (f a)⁻¹) ↔ measurable f :=
⟨measurable.of_inv, measurable.inv⟩
lemma measurable.sub [add_group α] [topological_add_group α] [second_countable_topology α]
{f g : δ → α} (hf : measurable f) (hg : measurable g) :
measurable (λ x, f x - g x) :=
hf.add hg.neg
lemma measurable.is_lub [linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_lub {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_lub (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_Ioi α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp only [set.preimage, mem_Ioi, lt_is_lub_iff (hg _), exists_range_iff, set_of_exists],
exact is_measurable.Union (λ i, hf i (is_open_lt' _).is_measurable)
end
lemma measurable.is_glb [linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} {g : δ → α} (hf : ∀ i, measurable (f i))
(hg : ∀ b, is_glb {a | ∃ i, f i b = a} (g b)) :
measurable g :=
begin
change ∀ b, is_glb (range $ λ i, f i b) (g b) at hg,
rw [‹borel_space α›.measurable_eq, borel_eq_generate_Iio α],
apply measurable_generate_from,
rintro _ ⟨a, rfl⟩,
simp only [set.preimage, mem_Iio, is_glb_lt_iff (hg _), exists_range_iff, set_of_exists],
exact is_measurable.Union (λ i, hf i (is_open_gt' _).is_measurable)
end
lemma measurable_supr [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨆ i, f i b) :=
measurable.is_lub hf $ λ b, is_lub_supr
lemma measurable_infi [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨅ i, f i b) :=
measurable.is_glb hf $ λ b, is_glb_infi
lemma measurable.supr_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨆ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact supr_pos h end)
(assume h : ¬p, begin convert measurable_const, funext, exact supr_neg h end)
lemma measurable.infi_Prop {α} [measurable_space α] [complete_lattice α]
(p : Prop) {f : δ → α} (hf : measurable f) :
measurable (λ b, ⨅ h : p, f b) :=
classical.by_cases
(assume h : p, begin convert hf, funext, exact infi_pos h end )
(assume h : ¬p, begin convert measurable_const, funext, exact infi_neg h end)
lemma measurable_bsupr [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] (p : ι → Prop) {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨆ i (hi : p i), f i b) :=
measurable_supr $ λ i, (hf i).supr_Prop (p i)
lemma measurable_binfi [complete_linear_order α] [order_topology α] [second_countable_topology α]
{ι} [encodable ι] (p : ι → Prop) {f : ι → δ → α} (hf : ∀ i, measurable (f i)) :
measurable (λ b, ⨅ i (hi : p i), f i b) :=
measurable_infi $ λ i, (hf i).infi_Prop (p i)
/-- Convert a `homeomorph` to a `measurable_equiv`. -/
def homemorph.to_measurable_equiv (h : α ≃ₜ β) :
measurable_equiv α β :=
{ to_equiv := h.to_equiv,
measurable_to_fun := h.continuous_to_fun.measurable,
measurable_inv_fun := h.continuous_inv_fun.measurable }
end borel_space
instance empty.borel_space : borel_space empty := ⟨borel_eq_top_of_discrete.symm⟩
instance unit.borel_space : borel_space unit := ⟨borel_eq_top_of_discrete.symm⟩
instance bool.borel_space : borel_space bool := ⟨borel_eq_top_of_discrete.symm⟩
instance nat.borel_space : borel_space ℕ := ⟨borel_eq_top_of_discrete.symm⟩
instance int.borel_space : borel_space ℤ := ⟨borel_eq_top_of_discrete.symm⟩
instance rat.borel_space : borel_space ℚ := ⟨borel_eq_top_of_encodable.symm⟩
instance real.measurable_space : measurable_space ℝ := borel ℝ
instance real.borel_space : borel_space ℝ := ⟨rfl⟩
instance nnreal.measurable_space : measurable_space nnreal := borel nnreal
instance nnreal.borel_space : borel_space nnreal := ⟨rfl⟩
instance ennreal.measurable_space : measurable_space ennreal := borel ennreal
instance ennreal.borel_space : borel_space ennreal := ⟨rfl⟩
section metric_space
variables [metric_space α] [measurable_space α] [opens_measurable_space α] {x : α} {ε : ℝ}
lemma is_measurable_ball : is_measurable (metric.ball x ε) :=
metric.is_open_ball.is_measurable
lemma is_measurable_closed_ball : is_measurable (metric.closed_ball x ε) :=
metric.is_closed_ball.is_measurable
lemma measurable_dist [second_countable_topology α] :
measurable (λp:α×α, dist p.1 p.2) :=
continuous_dist.measurable
lemma measurable.dist [second_countable_topology α] [measurable_space β] {f g : β → α}
(hf : measurable f) (hg : measurable g) : measurable (λ b, dist (f b) (g b)) :=
continuous_dist.measurable2 hf hg
lemma measurable_nndist [second_countable_topology α] : measurable (λp:α×α, nndist p.1 p.2) :=
continuous_nndist.measurable
lemma measurable.nndist [second_countable_topology α] [measurable_space β] {f g : β → α} :
measurable f → measurable g → measurable (λ b, nndist (f b) (g b)) :=
continuous_nndist.measurable2
end metric_space
section emetric_space
variables [emetric_space α] [measurable_space α] [opens_measurable_space α] {x : α} {ε : ennreal}
lemma is_measurable_eball : is_measurable (emetric.ball x ε) :=
emetric.is_open_ball.is_measurable
lemma measurable_edist [second_countable_topology α] :
measurable (λp:α×α, edist p.1 p.2) :=
continuous_edist.measurable
lemma measurable.edist [second_countable_topology α] [measurable_space β] {f g : β → α} :
measurable f → measurable g → measurable (λ b, edist (f b) (g b)) :=
continuous_edist.measurable2
end emetric_space
namespace real
open measurable_space
lemma borel_eq_generate_from_Ioo_rat :
borel ℝ = generate_from (⋃(a b : ℚ) (h : a < b), {Ioo a b}) :=
borel_eq_generate_from_of_subbasis is_topological_basis_Ioo_rat.2.2
lemma borel_eq_generate_from_Iio_rat :
borel ℝ = generate_from (⋃a:ℚ, {Iio a}) :=
begin
let g, swap,
apply le_antisymm (_ : _ ≤ g) (measurable_space.generate_from_le (λ t, _)),
{ rw borel_eq_generate_from_Ioo_rat,
refine generate_from_le (λ t, _),
simp only [mem_Union], rintro ⟨a, b, h, H⟩,
rw [mem_singleton_iff.1 H],
rw (set.ext (λ x, _) : Ioo (a:ℝ) b = (⋃c>a, (Iio c)ᶜ) ∩ Iio b),
{ have hg : ∀q:ℚ, g.is_measurable (Iio q) :=
λ q, generate_measurable.basic _ (by simp; exact ⟨_, rfl⟩),
refine @is_measurable.inter _ g _ _ _ (hg _),
refine @is_measurable.bUnion _ _ g _ _ (countable_encodable _) (λ c h, _),
exact @is_measurable.compl _ _ g (hg _) },
{ simp [Ioo, Iio],
refine and_congr _ iff.rfl,
exact ⟨λ h,
let ⟨c, ac, cx⟩ := exists_rat_btwn h in
⟨c, rat.cast_lt.1 ac, le_of_lt cx⟩,
λ ⟨c, ac, cx⟩, lt_of_lt_of_le (rat.cast_lt.2 ac) cx⟩ } },
{ simp, rintro r rfl,
exact is_open_Iio.is_measurable }
end
end real
lemma measurable.sub_nnreal [measurable_space α] {f g : α → nnreal} :
measurable f → measurable g → measurable (λ a, f a - g a) :=
nnreal.continuous_sub.measurable2
lemma measurable.nnreal_of_real [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, nnreal.of_real (f x)) :=
nnreal.continuous_of_real.measurable.comp hf
lemma measurable.nnreal_coe [measurable_space α] {f : α → nnreal} (hf : measurable f) :
measurable (λ x, (f x : ℝ)) :=
nnreal.continuous_coe.measurable.comp hf
lemma measurable.ennreal_coe [measurable_space α] {f : α → nnreal} (hf : measurable f) :
measurable (λ x, (f x : ennreal)) :=
(ennreal.continuous_coe.2 continuous_id).measurable.comp hf
lemma measurable.ennreal_of_real [measurable_space α] {f : α → ℝ} (hf : measurable f) :
measurable (λ x, ennreal.of_real (f x)) :=
ennreal.continuous_of_real.measurable.comp hf
/-- The set of finite `ennreal` numbers is `measurable_equiv` to `nnreal`. -/
def measurable_equiv.ennreal_equiv_nnreal : measurable_equiv {r : ennreal | r ≠ ⊤} nnreal :=
ennreal.ne_top_homeomorph_nnreal.to_measurable_equiv
namespace ennreal
open filter
lemma measurable_coe : measurable (coe : nnreal → ennreal) :=
measurable_id.ennreal_coe
lemma measurable_of_measurable_nnreal [measurable_space α] {f : ennreal → α}
(h : measurable (λp:nnreal, f p)) : measurable f :=
measurable_of_measurable_on_compl_singleton ⊤
(measurable_equiv.ennreal_equiv_nnreal.symm.measurable_coe_iff.1 h)
/-- `ennreal` is `measurable_equiv` to `nnreal ⊕ unit`. -/
def ennreal_equiv_sum :
measurable_equiv ennreal (nnreal ⊕ unit) :=
{ measurable_to_fun := measurable_of_measurable_nnreal measurable_inl,
measurable_inv_fun := measurable_sum measurable_coe (@measurable_const ennreal unit _ _ ⊤),
.. equiv.option_equiv_sum_punit nnreal }
lemma measurable_of_measurable_nnreal_nnreal [measurable_space α] [measurable_space β]
(f : ennreal → ennreal → β) {g : α → ennreal} {h : α → ennreal}
(h₁ : measurable (λp:nnreal × nnreal, f p.1 p.2))
(h₂ : measurable (λr:nnreal, f ⊤ r))
(h₃ : measurable (λr:nnreal, f r ⊤))
(hg : measurable g) (hh : measurable h) : measurable (λa, f (g a) (h a)) :=
let e : measurable_equiv (ennreal × ennreal)
(((nnreal × nnreal) ⊕ (nnreal × unit)) ⊕ ((unit × nnreal) ⊕ (unit × unit))) :=
(measurable_equiv.prod_congr ennreal_equiv_sum ennreal_equiv_sum).trans
(measurable_equiv.sum_prod_sum _ _ _ _) in
have measurable (λp:ennreal×ennreal, f p.1 p.2),
begin
refine e.symm.measurable_coe_iff.1 (measurable_sum (measurable_sum _ _) (measurable_sum _ _)),
{ show measurable (λp:nnreal × nnreal, f p.1 p.2),
exact h₁ },
{ show measurable (λp:nnreal × unit, f p.1 ⊤),
exact h₃.comp (measurable.fst measurable_id) },
{ show measurable ((λp:nnreal, f ⊤ p) ∘ (λp:unit × nnreal, p.2)),
exact h₂.comp (measurable.snd measurable_id) },
{ show measurable (λp:unit × unit, f ⊤ ⊤),
exact measurable_const }
end,
this.comp (measurable.prod_mk hg hh)
lemma measurable_of_real : measurable ennreal.of_real :=
ennreal.continuous_of_real.measurable
end ennreal
lemma measurable.ennreal_mul {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a * g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (*) _ _ _,
{ simp only [ennreal.coe_mul.symm],
exact ennreal.measurable_coe.comp measurable_mul },
{ simp [ennreal.top_mul],
exact measurable_const.piecewise
(is_closed_eq continuous_id continuous_const).is_measurable
measurable_const },
{ simp [ennreal.mul_top],
exact measurable_const.piecewise
(is_closed_eq continuous_id continuous_const).is_measurable
measurable_const }
end
lemma measurable.ennreal_add {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a + g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (+) _ _ _,
{ simp only [ennreal.coe_add.symm],
exact ennreal.measurable_coe.comp measurable_add },
{ simp [measurable_const] },
{ simp [measurable_const] }
end
lemma measurable.ennreal_sub {α : Type*} [measurable_space α] {f g : α → ennreal} :
measurable f → measurable g → measurable (λa, f a - g a) :=
begin
refine ennreal.measurable_of_measurable_nnreal_nnreal (has_sub.sub) _ _ _,
{ simp only [ennreal.coe_sub.symm],
exact ennreal.measurable_coe.comp nnreal.continuous_sub.measurable },
{ simp [measurable_const] },
{ simp [measurable_const] }
end
section normed_group
variables [measurable_space α] [normed_group α] [opens_measurable_space α] [measurable_space β]
lemma measurable_norm : measurable (norm : α → ℝ) :=
continuous_norm.measurable
lemma measurable.norm {f : β → α} (hf : measurable f) : measurable (λa, norm (f a)) :=
measurable_norm.comp hf
lemma measurable_nnnorm : measurable (nnnorm : α → nnreal) :=
continuous_nnnorm.measurable
lemma measurable.nnnorm {f : β → α} (hf : measurable f) : measurable (λa, nnnorm (f a)) :=
measurable_nnnorm.comp hf
lemma measurable.ennnorm {f : β → α} (hf : measurable f) :
measurable (λa, (nnnorm (f a) : ennreal)) :=
hf.nnnorm.ennreal_coe
end normed_group
|
123e96fa74c516ae63d60d085c9c1c446ba8ae36 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /test/lint_simp_comm.lean | a2883c1b82978a51b170fc0146bd53403c819389 | [
"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 | 1,048 | lean | import tactic.lint
/-! ## Commutativity lemmas should be rejected -/
attribute [simp] add_comm add_left_comm
open tactic
#eval do
decl ← get_decl ``add_comm,
res ← linter.simp_comm.test decl,
-- linter complains
guard res.is_some
open tactic
#eval do
decl ← get_decl ``add_left_comm,
res ← linter.simp_comm.test decl,
-- linter complains
guard res.is_some
/-! ## Floris' trick should be accepted -/
@[simp] lemma list.filter_congr_decidable {α} (s : list α) (p : α → Prop) (h : decidable_pred p)
[decidable_pred p] : @list.filter α p h s = s.filter p :=
by congr
-- lemma is unproblematic
example : @list.filter _ (λ x, x > 0) (λ _, classical.prop_decidable _) [1,2,3] = [1,2,3] :=
begin
-- can rewrite once
simp only [list.filter_congr_decidable],
-- but not twice
success_if_fail { simp only [list.filter_congr_decidable] },
refl
end
open tactic
set_option pp.all true
#eval do
decl ← get_decl ``list.filter_congr_decidable,
res ← linter.simp_comm.test decl,
-- linter does not complain
guard res.is_none
|
6bcee3e33618b686c74ca7059f91327782179ce9 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/run/blast10.lean | ec0073890f51865db467b0faa95c96b45705d77a | [
"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 | 181 | lean | import data.list
set_option blast.strategy "unit"
definition lemma1 : true :=
by blast
open perm
definition lemma2 (l : list nat) : l ~ l :=
by blast
print lemma1
print lemma2
|
298ea6ad99ce9f80a1b520d87f146d4441c083f0 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /src/Lean/Server/Utils.lean | bdb4404b348a5796032f3ec2a54fb06aabfe2e63 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 4,796 | lean | /-
Copyright (c) 2020 Wojciech Nawrocki. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki, Marc Huisinga
-/
import Lean.Data.Lsp.Communication
import Lean.Data.Lsp.Diagnostics
import Lean.Data.Lsp.Extra
import Lean.Data.Lsp.TextSync
import Lean.Server.InfoUtils
namespace IO
def throwServerError (err : String) : IO α :=
throw (userError err)
namespace FS.Stream
/-- Chains two streams by creating a new stream s.t. writing to it
just writes to `a` but reading from it also duplicates the read output
into `b`, c.f. `a | tee b` on Unix.
NB: if `a` is written to but this stream is never read from,
the output will *not* be duplicated. Use this if you only care
about the data that was actually read. -/
def chainRight (a : Stream) (b : Stream) (flushEagerly : Bool := false) : Stream :=
{ a with
flush := a.flush *> b.flush
read := fun sz => do
let bs ← a.read sz
b.write bs
if flushEagerly then b.flush
pure bs
getLine := do
let ln ← a.getLine
b.putStr ln
if flushEagerly then b.flush
pure ln }
/-- Like `tee a | b` on Unix. See `chainOut`. -/
def chainLeft (a : Stream) (b : Stream) (flushEagerly : Bool := false) : Stream :=
{ b with
flush := a.flush *> b.flush
write := fun bs => do
a.write bs
if flushEagerly then a.flush
b.write bs
putStr := fun s => do
a.putStr s
if flushEagerly then a.flush
b.putStr s }
/-- Prefixes all written outputs with `pre`. -/
def withPrefix (a : Stream) (pre : String) : Stream :=
{ a with
write := fun bs => do
a.putStr pre
a.write bs
putStr := fun s =>
a.putStr (pre ++ s) }
end FS.Stream
end IO
namespace Lean.Server
structure DocumentMeta where
uri : Lsp.DocumentUri
version : Nat
text : FileMap
deriving Inhabited
def DocumentMeta.mkInputContext (doc : DocumentMeta) : Parser.InputContext where
input := doc.text.source
fileName := (System.Uri.fileUriToPath? doc.uri).getD doc.uri |>.toString
fileMap := doc.text
def replaceLspRange (text : FileMap) (r : Lsp.Range) (newText : String) : FileMap :=
let start := text.lspPosToUtf8Pos r.start
let «end» := text.lspPosToUtf8Pos r.«end»
let pre := text.source.extract 0 start
let post := text.source.extract «end» text.source.endPos
(pre ++ newText ++ post).toFileMap
open IO
/-- Duplicates an I/O stream to a log file `fName` in LEAN_SERVER_LOG_DIR
if that envvar is set. -/
def maybeTee (fName : String) (isOut : Bool) (h : FS.Stream) : IO FS.Stream := do
match (← IO.getEnv "LEAN_SERVER_LOG_DIR") with
| none => pure h
| some logDir =>
IO.FS.createDirAll logDir
let hTee ← FS.Handle.mk (System.mkFilePath [logDir, fName]) FS.Mode.write true
let hTee := FS.Stream.ofHandle hTee
pure $ if isOut then
hTee.chainLeft h true
else
h.chainRight hTee true
open Lsp
/-- Returns the document contents with the change applied. -/
def applyDocumentChange (oldText : FileMap) : (change : Lsp.TextDocumentContentChangeEvent) → FileMap
| TextDocumentContentChangeEvent.rangeChange (range : Range) (newText : String) =>
replaceLspRange oldText range newText
| TextDocumentContentChangeEvent.fullChange (newText : String) =>
newText.toFileMap
/-- Returns the document contents with all changes applied. -/
def foldDocumentChanges (changes : Array Lsp.TextDocumentContentChangeEvent) (oldText : FileMap) : FileMap :=
changes.foldl applyDocumentChange oldText
def publishDiagnostics (m : DocumentMeta) (diagnostics : Array Lsp.Diagnostic) (hOut : FS.Stream) : IO Unit :=
hOut.writeLspNotification {
method := "textDocument/publishDiagnostics"
param := {
uri := m.uri
version? := m.version
diagnostics := diagnostics
: PublishDiagnosticsParams
}
}
def publishProgress (m : DocumentMeta) (processing : Array LeanFileProgressProcessingInfo) (hOut : FS.Stream) : IO Unit :=
hOut.writeLspNotification {
method := "$/lean/fileProgress"
param := {
textDocument := { uri := m.uri, version? := m.version }
processing
: LeanFileProgressParams
}
}
def publishProgressAtPos (m : DocumentMeta) (pos : String.Pos) (hOut : FS.Stream) (kind : LeanFileProgressKind := LeanFileProgressKind.processing) : IO Unit :=
publishProgress m #[{ range := ⟨m.text.utf8PosToLspPos pos, m.text.utf8PosToLspPos m.text.source.endPos⟩, kind := kind }] hOut
def publishProgressDone (m : DocumentMeta) (hOut : FS.Stream) : IO Unit :=
publishProgress m #[] hOut
end Lean.Server
def String.Range.toLspRange (text : Lean.FileMap) (r : String.Range) : Lean.Lsp.Range :=
⟨text.utf8PosToLspPos r.start, text.utf8PosToLspPos r.stop⟩
|
b386f9a5f95c6106cf61a1104fa91ab4a5a28b50 | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /src/Lean/Elab/InfoTree.lean | 68b2935eea16822a7de3dc23d0ab098cc5d88d51 | [
"Apache-2.0"
] | permissive | williamdemeo/lean4 | 72161c58fe65c3ad955d6a3050bb7d37c04c0d54 | 6d00fcf1d6d873e195f9220c668ef9c58e9c4a35 | refs/heads/master | 1,678,305,356,877 | 1,614,708,995,000 | 1,614,708,995,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 9,457 | lean | /-
Copyright (c) 2020 Wojciech Nawrocki. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki, Leonardo de Moura
-/
import Lean.Data.Position
import Lean.Expr
import Lean.Message
import Lean.Data.Json
import Lean.Meta.Basic
import Lean.Meta.PPGoal
namespace Lean.Elab
open Std (PersistentArray PersistentArray.empty PersistentHashMap)
/- Context after executing `liftTermElabM`.
Note that the term information collected during elaboration may contain metavariables, and their
assignments are stored at `mctx`. -/
structure ContextInfo where
env : Environment
fileMap : FileMap
mctx : MetavarContext := {}
options : Options := {}
currNamespace : Name := Name.anonymous
openDecls : List OpenDecl := []
deriving Inhabited
structure TermInfo where
lctx : LocalContext -- The local context when the term was elaborated.
expr : Expr
stx : Syntax
deriving Inhabited
structure FieldInfo where
name : Name
lctx : LocalContext
val : Expr
stx : Syntax
deriving Inhabited
/- We store the list of goals before and after the execution of a tactic.
We also store the metavariable context at each time since, we want to unassigned metavariables
at tactic execution time to be displayed as `?m...`. -/
structure TacticInfo where
mctxBefore : MetavarContext
goalsBefore : List MVarId
stx : Syntax
mctxAfter : MetavarContext
goalsAfter : List MVarId
deriving Inhabited
structure MacroExpansionInfo where
lctx : LocalContext -- The local context when the macro was expanded.
before : Syntax
after : Syntax
deriving Inhabited
inductive Info where
| ofTacticInfo (i : TacticInfo)
| ofTermInfo (i : TermInfo)
| ofMacroExpansionInfo (i : MacroExpansionInfo)
| ofFieldInfo (i : FieldInfo)
deriving Inhabited
inductive InfoTree where
| context (i : ContextInfo) (t : InfoTree) -- The context object is created by `liftTermElabM` at `Command.lean`
| node (i : Info) (children : PersistentArray InfoTree) -- The children contains information for nested term elaboration and tactic evaluation
| ofJson (j : Json) -- For user data
| hole (mvarId : MVarId) -- The elaborator creates holes (aka metavariables) for tactics and postponed terms
deriving Inhabited
structure InfoState where
enabled : Bool := false
assignment : PersistentHashMap MVarId InfoTree := {} -- map from holeId to InfoTree
trees : PersistentArray InfoTree := {}
deriving Inhabited
class MonadInfoTree (m : Type → Type) where
getInfoState : m InfoState
modifyInfoState : (InfoState → InfoState) → m Unit
export MonadInfoTree (getInfoState modifyInfoState)
instance (m n) [MonadLift m n] [MonadInfoTree m] : MonadInfoTree n where
getInfoState := liftM (getInfoState : m _)
modifyInfoState f := liftM (modifyInfoState f : m _)
partial def InfoTree.substitute (tree : InfoTree) (assignment : PersistentHashMap MVarId InfoTree) : InfoTree :=
match tree with
| node i c => node i <| c.map (substitute · assignment)
| context i t => context i (substitute t assignment)
| ofJson j => ofJson j
| hole id => match assignment.find? id with
| none => hole id
| some tree => substitute tree assignment
def ContextInfo.runMetaM (info : ContextInfo) (lctx : LocalContext) (x : MetaM α) : IO α := do
let x := x.run { lctx := lctx } { mctx := info.mctx }
let ((a, _), _) ← x.toIO { options := info.options, currNamespace := info.currNamespace, openDecls := info.openDecls } { env := info.env }
return a
def ContextInfo.toPPContext (info : ContextInfo) (lctx : LocalContext) : PPContext :=
{ env := info.env, mctx := info.mctx, lctx := lctx,
opts := info.options, currNamespace := info.currNamespace, openDecls := info.openDecls }
def ContextInfo.ppSyntax (info : ContextInfo) (lctx : LocalContext) (stx : Syntax) : IO Format := do
ppTerm (info.toPPContext lctx) stx
private def formatStxRange (cinfo : ContextInfo) (stx : Syntax) : Format := do
let pos := stx.getPos?.getD 0
let endPos := stx.getTailPos?.getD pos
return f!"{fmtPos pos stx.getHeadInfo}-{fmtPos endPos stx.getTailInfo}"
where fmtPos pos info :=
let pos := format <| cinfo.fileMap.toPosition pos
match info with
| SourceInfo.original .. => pos
| _ => f!"{pos}†"
def TermInfo.format (cinfo : ContextInfo) (info : TermInfo) : IO Format := do
cinfo.runMetaM info.lctx do
return f!"{← Meta.ppExpr info.expr} : {← Meta.ppExpr (← Meta.inferType info.expr)} @ {formatStxRange cinfo info.stx}"
def FieldInfo.format (cinfo : ContextInfo) (info : FieldInfo) : IO Format := do
cinfo.runMetaM info.lctx do
return f!"{info.name} : {← Meta.ppExpr (← Meta.inferType info.val)} := {← Meta.ppExpr info.val} @ {formatStxRange cinfo info.stx}"
def ContextInfo.ppGoals (cinfo : ContextInfo) (goals : List MVarId) : IO Format :=
if goals.isEmpty then
return "no goals"
else
cinfo.runMetaM {} (return Std.Format.prefixJoin "\n" (← goals.mapM Meta.ppGoal))
def TacticInfo.format (cinfo : ContextInfo) (info : TacticInfo) : IO Format := do
let cinfoB := { cinfo with mctx := info.mctxBefore }
let cinfoA := { cinfo with mctx := info.mctxAfter }
let goalsBefore ← cinfoB.ppGoals info.goalsBefore
let goalsAfter ← cinfoA.ppGoals info.goalsAfter
return f!"Tactic @ {formatStxRange cinfo info.stx}\nbefore {goalsBefore}\nafter {goalsAfter}"
def MacroExpansionInfo.format (cinfo : ContextInfo) (info : MacroExpansionInfo) : IO Format := do
let before ← cinfo.ppSyntax info.lctx info.before
let after ← cinfo.ppSyntax info.lctx info.after
return f!"Macro expansion\n{before}\n===>\n{after}"
def Info.format (cinfo : ContextInfo) : Info → IO Format
| ofTacticInfo i => i.format cinfo
| ofTermInfo i => i.format cinfo
| ofMacroExpansionInfo i => i.format cinfo
| ofFieldInfo i => i.format cinfo
partial def InfoTree.format (tree : InfoTree) (cinfo? : Option ContextInfo := none) : IO Format := do
match tree with
| ofJson j => return toString j
| hole id => return toString id
| context i t => format t i
| node i cs => match cinfo? with
| none => return "<context-not-available>"
| some cinfo =>
if cs.size == 0 then
i.format cinfo
else
return f!"{← i.format cinfo}{Std.Format.nestD <| Std.Format.prefixJoin "\n" (← cs.toList.mapM fun c => format c cinfo?)}"
section
variable [Monad m] [MonadInfoTree m]
@[inline] private def modifyInfoTrees (f : PersistentArray InfoTree → PersistentArray InfoTree) : m Unit :=
modifyInfoState fun s => { s with trees := f s.trees }
private def getResetInfoTrees : m (PersistentArray InfoTree) := do
let trees := (← getInfoState).trees
modifyInfoTrees fun _ => {}
return trees
def pushInfoTree (t : InfoTree) : m Unit := do
if (← getInfoState).enabled then
modifyInfoTrees fun ts => ts.push t
def mkInfoNode (info : Info) : m Unit := do
if (← getInfoState).enabled then
modifyInfoTrees fun ts => PersistentArray.empty.push <| InfoTree.node info ts
@[inline] def withInfoContext' [MonadFinally m] (x : m α) (mkInfo : α → m (Sum Info MVarId)) : m α := do
if (← getInfoState).enabled then
let treesSaved ← getResetInfoTrees
Prod.fst <$> MonadFinally.tryFinally' x fun a? => do
match a? with
| none => modifyInfoTrees fun _ => treesSaved
| some a => modifyInfoTrees fun trees =>
match (← mkInfo a) with
| Sum.inl info => treesSaved.push <| InfoTree.node info trees
| Sum.inr mvaId => treesSaved.push <| InfoTree.hole mvaId
else
x
@[inline] def withInfoContext [MonadFinally m] (x : m α) (mkInfo : m Info) : m α := do
if (← getInfoState).enabled then
let treesSaved ← getResetInfoTrees
Prod.fst <$> MonadFinally.tryFinally' x fun _ => do
modifyInfoTrees fun trees => treesSaved.push <| InfoTree.node (← mkInfo) trees
else
x
def getInfoHoleIdAssignment? (mvarId : MVarId) : m (Option InfoTree) :=
return (← getInfoState).assignment[mvarId]
def assignInfoHoleId (mvarId : MVarId) (infoTree : InfoTree) : m Unit := do
assert! (← getInfoHoleIdAssignment? mvarId).isNone
modifyInfoState fun s => { s with assignment := s.assignment.insert mvarId infoTree }
end
def withMacroExpansionInfo [MonadFinally m] [Monad m] [MonadInfoTree m] [MonadLCtx m] (before after : Syntax) (x : m α) : m α :=
let mkInfo : m Info := do
return Info.ofMacroExpansionInfo {
lctx := (← getLCtx)
before := before
after := after
}
withInfoContext x mkInfo
@[inline] def withInfoHole [MonadFinally m] [Monad m] [MonadInfoTree m] (mvarId : MVarId) (x : m α) : m α := do
if (← getInfoState).enabled then
let treesSaved ← getResetInfoTrees
Prod.fst <$> MonadFinally.tryFinally' x fun a? => modifyInfoState fun s =>
if s.trees.size > 0 then
{ s with trees := treesSaved, assignment := s.assignment.insert mvarId s.trees[s.trees.size - 1] }
else
{ s with trees := treesSaved }
else
x
def enableInfoTree [MonadInfoTree m] (flag := true) : m Unit :=
modifyInfoState fun s => { s with enabled := flag }
def getInfoTrees [MonadInfoTree m] [Monad m] : m (PersistentArray InfoTree) :=
return (← getInfoState).trees
end Lean.Elab
|
252fcc6e25a4f7b6af7c0c7d6ab09e776b2c1881 | c512f72c3704cbf8f34addab0d4482633dc46bbe | /src/combinator.lean | f48c69767e26b7aeb84a24465a7fe9ece3c864e8 | [] | no_license | iehality/abstract-computability | 7479c2786ecac8e00f3d7be00cbd7cd4a4ae43fc | 19c1a32e748e733c65f3e9e6395e4e56e4330cca | refs/heads/main | 1,680,113,399,119 | 1,616,950,483,000 | 1,616,950,483,000 | 346,220,308 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 872 | lean | import pca
import re
namespace pca
universe variable u
variables {α : Type u}
variables [pca α]
def pair : α := 0 →∅ Λ 1, (Λ 2, (#2 * #0 * #1))
notation `⟪`a`, `b`⟫` := 𝚜 (𝚜 i (𝚔 a)) (𝚔 b)
def π₀ : α := 0 →∅ #0 * &submodel.k
def π₁ : α := 0 →∅ #0 * (&submodel.k * &submodel.i)
@[simp] lemma pair_e [pca α] (a b : α) : ↓pair * ↓a * ↓b = ↓⟪a, b⟫ :=
by simp [pair, lam, expr, if_neg (show 2 ≠ 0, from dec_trivial), if_neg (show 2 ≠ 1, from dec_trivial)]
@[simp] lemma pair_pi0 [pca α] (a b : α) : ↓π₀ * ↓⟪a, b⟫ = ↓a := by simp [π₀, lam, expr]
@[simp] lemma pair_pi1 [pca α] (a b : α) : ↓π₁ * ↓⟪a, b⟫ = ↓b := by simp [π₁, lam, expr]
def top [pca α] : α := 0 →∅ Λ 1, #0
def bot [pca α] : α := 0 →∅ Λ 1, #1
notation `𝚃` := top
notation `𝙵` := bot
end pca |
f1d2810bf80a5e5b8e19cbee7cb535983d1cdbc4 | 05b503addd423dd68145d68b8cde5cd595d74365 | /src/ring_theory/free_comm_ring.lean | 089f3891b918db8bd1a903b70f1627085a08dbea | [
"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 | 15,975 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Johan Commelin
-/
import group_theory.free_abelian_group data.equiv.functor data.mv_polynomial
import ring_theory.ideal_operations ring_theory.free_ring
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
universes u v
variables (α : Type u)
def free_comm_ring (α : Type u) : Type u :=
free_abelian_group $ multiplicative $ multiset α
namespace free_comm_ring
instance : comm_ring (free_comm_ring α) := free_abelian_group.comm_ring _
instance : inhabited (free_comm_ring α) := ⟨0⟩
variables {α}
def of (x : α) : free_comm_ring α :=
free_abelian_group.of ([x] : multiset α)
@[elab_as_eliminator] protected lemma induction_on
{C : free_comm_ring α → Prop} (z : free_comm_ring α)
(hn1 : C (-1)) (hb : ∀ b, C (of b))
(ha : ∀ x y, C x → C y → C (x + y))
(hm : ∀ x y, C x → C y → C (x * y)) : C z :=
have hn : ∀ x, C x → C (-x), from λ x ih, neg_one_mul x ▸ hm _ _ hn1 ih,
have h1 : C 1, from neg_neg (1 : free_comm_ring α) ▸ hn _ hn1,
free_abelian_group.induction_on z
(add_left_neg (1 : free_comm_ring α) ▸ ha _ _ hn1 h1)
(λ m, multiset.induction_on m h1 $ λ a m ih, hm _ _ (hb a) ih)
(λ m ih, hn _ ih)
ha
section lift
variables {β : Type v} [comm_ring β] (f : α → β)
/-- Lift a map `α → R` to a ring homomorphism `free_comm_ring α → R`.
For a version producing a bundled homomorphism, see `lift_hom`. -/
def lift : free_comm_ring α → β :=
free_abelian_group.lift $ λ s, (s.map f).prod
@[simp] lemma lift_zero : lift f 0 = 0 := rfl
@[simp] lemma lift_one : lift f 1 = 1 :=
free_abelian_group.lift.of _ _
@[simp] lemma lift_of (x : α) : lift f (of x) = f x :=
(free_abelian_group.lift.of _ _).trans $ mul_one _
@[simp] lemma lift_add (x y) : lift f (x + y) = lift f x + lift f y :=
free_abelian_group.lift.add _ _ _
@[simp] lemma lift_neg (x) : lift f (-x) = -lift f x :=
free_abelian_group.lift.neg _ _
@[simp] lemma lift_sub (x y) : lift f (x - y) = lift f x - lift f y :=
free_abelian_group.lift.sub _ _ _
@[simp] lemma lift_mul (x y) : lift f (x * y) = lift f x * lift f y :=
begin
refine free_abelian_group.induction_on y (mul_zero _).symm _ _ _,
{ intros s2, conv { to_lhs, dsimp only [(*), mul_zero_class.mul, semiring.mul, ring.mul, semigroup.mul, comm_ring.mul] },
rw [free_abelian_group.lift.of, lift, free_abelian_group.lift.of],
refine free_abelian_group.induction_on x (zero_mul _).symm _ _ _,
{ intros s1, iterate 3 { rw free_abelian_group.lift.of },
calc _ = multiset.prod ((multiset.map f s1) + (multiset.map f s2)) :
by {congr' 1, exact multiset.map_add _ _ _}
... = _ : multiset.prod_add _ _ },
{ intros s1 ih, iterate 3 { rw free_abelian_group.lift.neg }, rw [ih, neg_mul_eq_neg_mul] },
{ intros x1 x2 ih1 ih2, iterate 3 { rw free_abelian_group.lift.add }, rw [ih1, ih2, add_mul] } },
{ intros s2 ih, rw [mul_neg_eq_neg_mul_symm, lift_neg, lift_neg, mul_neg_eq_neg_mul_symm, ih] },
{ intros y1 y2 ih1 ih2, rw [mul_add, lift_add, lift_add, mul_add, ih1, ih2] },
end
/-- Lift of a map `f : α → β` to `free_comm_ring α` as a ring homomorphism.
We don't use it as the canonical form because Lean fails to coerce it to a function. -/
def lift_hom : free_comm_ring α →+* β := ⟨lift f, lift_one f, lift_mul f, lift_zero f, lift_add f⟩
instance : is_ring_hom (lift f) := (lift_hom f).is_ring_hom
@[simp] lemma coe_lift_hom : ⇑(lift_hom f : free_comm_ring α →+* β) = lift f := rfl
@[simp] lemma lift_pow (x) (n : ℕ) : lift f (x ^ n) = lift f x ^ n :=
(lift_hom f).map_pow _ _
@[simp] lemma lift_comp_of (f : free_comm_ring α → β) [is_ring_hom f] : lift (f ∘ of) = f :=
funext $ λ x, free_comm_ring.induction_on x
(by rw [lift_neg, lift_one, is_ring_hom.map_neg f, is_ring_hom.map_one f])
(lift_of _)
(λ x y ihx ihy, by rw [lift_add, is_ring_hom.map_add f, ihx, ihy])
(λ x y ihx ihy, by rw [lift_mul, is_ring_hom.map_mul f, ihx, ihy])
end lift
variables {β : Type v} (f : α → β)
/-- A map `f : α → β` produces a ring homomorphism `free_comm_ring α → free_comm_ring β`. -/
def map : free_comm_ring α →+* free_comm_ring β :=
lift_hom $ of ∘ f
lemma map_zero : map f 0 = 0 := rfl
lemma map_one : map f 1 = 1 := rfl
lemma map_of (x : α) : map f (of x) = of (f x) := lift_of _ _
lemma map_add (x y) : map f (x + y) = map f x + map f y := lift_add _ _ _
lemma map_neg (x) : map f (-x) = -map f x := lift_neg _ _
lemma map_sub (x y) : map f (x - y) = map f x - map f y := lift_sub _ _ _
lemma map_mul (x y) : map f (x * y) = map f x * map f y := lift_mul _ _ _
lemma map_pow (x) (n : ℕ) : map f (x ^ n) = (map f x) ^ n := lift_pow _ _ _
def is_supported (x : free_comm_ring α) (s : set α) : Prop :=
x ∈ ring.closure (of '' s)
section is_supported
variables {x y : free_comm_ring α} {s t : set α}
theorem is_supported_upwards (hs : is_supported x s) (hst : s ⊆ t) :
is_supported x t :=
ring.closure_mono (set.monotone_image hst) hs
theorem is_supported_add (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x + y) s :=
is_add_submonoid.add_mem hxs hys
theorem is_supported_neg (hxs : is_supported x s) :
is_supported (-x) s :=
is_add_subgroup.neg_mem hxs
theorem is_supported_sub (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x - y) s :=
is_add_subgroup.sub_mem _ _ _ hxs hys
theorem is_supported_mul (hxs : is_supported x s) (hys : is_supported y s) :
is_supported (x * y) s :=
is_submonoid.mul_mem hxs hys
theorem is_supported_zero : is_supported 0 s :=
is_add_submonoid.zero_mem _
theorem is_supported_one : is_supported 1 s :=
is_submonoid.one_mem _
theorem is_supported_int {i : ℤ} {s : set α} : is_supported ↑i s :=
int.induction_on i is_supported_zero
(λ i hi, by rw [int.cast_add, int.cast_one]; exact is_supported_add hi is_supported_one)
(λ i hi, by rw [int.cast_sub, int.cast_one]; exact is_supported_sub hi is_supported_one)
end is_supported
def restriction (s : set α) [decidable_pred s] (x : free_comm_ring α) : free_comm_ring s :=
lift (λ p, if H : p ∈ s then of ⟨p, H⟩ else 0) x
section restriction
variables (s : set α) [decidable_pred s] (x y : free_comm_ring α)
@[simp] lemma restriction_of (p) : restriction s (of p) = if H : p ∈ s then of ⟨p, H⟩ else 0 := lift_of _ _
@[simp] lemma restriction_zero : restriction s 0 = 0 := lift_zero _
@[simp] lemma restriction_one : restriction s 1 = 1 := lift_one _
@[simp] lemma restriction_add : restriction s (x + y) = restriction s x + restriction s y := lift_add _ _ _
@[simp] lemma restriction_neg : restriction s (-x) = -restriction s x := lift_neg _ _
@[simp] lemma restriction_sub : restriction s (x - y) = restriction s x - restriction s y := lift_sub _ _ _
@[simp] lemma restriction_mul : restriction s (x * y) = restriction s x * restriction s y := lift_mul _ _ _
end restriction
theorem is_supported_of {p} {s : set α} : is_supported (of p) s ↔ p ∈ s :=
suffices is_supported (of p) s → p ∈ s, from ⟨this, λ hps, ring.subset_closure ⟨p, hps, rfl⟩⟩,
assume hps : is_supported (of p) s, begin
classical,
have : ∀ x, is_supported x s →
∃ (n : ℤ), lift (λ a, if a ∈ s then (0 : polynomial ℤ) else polynomial.X) x = n,
{ intros x hx, refine ring.in_closure.rec_on hx _ _ _ _,
{ use 1, rw [lift_one], norm_cast },
{ use -1, rw [lift_neg, lift_one], norm_cast },
{ rintros _ ⟨z, hzs, rfl⟩ _ _, use 0, rw [lift_mul, lift_of, if_pos hzs, zero_mul], norm_cast },
{ rintros x y ⟨q, hq⟩ ⟨r, hr⟩, refine ⟨q+r, _⟩, rw [lift_add, hq, hr], norm_cast } },
specialize this (of p) hps, rw [lift_of] at this, split_ifs at this, { exact h },
exfalso, apply ne.symm int.zero_ne_one,
rcases this with ⟨w, H⟩, rw polynomial.int_cast_eq_C at H,
have : polynomial.X.coeff 1 = (polynomial.C ↑w).coeff 1, by rw H,
rwa [polynomial.coeff_C, if_neg one_ne_zero, polynomial.coeff_X, if_pos rfl] at this,
apply_instance
end
theorem map_subtype_val_restriction {x} (s : set α) [decidable_pred s] (hxs : is_supported x s) :
map (subtype.val : s → α) (restriction s x) = x :=
begin
refine ring.in_closure.rec_on hxs _ _ _ _,
{ rw restriction_one, refl },
{ rw [restriction_neg, map_neg, restriction_one], refl },
{ rintros _ ⟨p, hps, rfl⟩ n ih, rw [restriction_mul, restriction_of, dif_pos hps, map_mul, map_of, ih] },
{ intros x y ihx ihy, rw [restriction_add, map_add, ihx, ihy] }
end
theorem exists_finite_support (x : free_comm_ring α) : ∃ s : set α, set.finite s ∧ is_supported x s :=
free_comm_ring.induction_on x
⟨∅, set.finite_empty, is_supported_neg is_supported_one⟩
(λ p, ⟨{p}, set.finite_singleton p, is_supported_of.2 $ finset.mem_singleton_self _⟩)
(λ x y ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩, ⟨s ∪ t, set.finite_union hfs hft, is_supported_add
(is_supported_upwards hxs $ set.subset_union_left s t)
(is_supported_upwards hxt $ set.subset_union_right s t)⟩)
(λ x y ⟨s, hfs, hxs⟩ ⟨t, hft, hxt⟩, ⟨s ∪ t, set.finite_union hfs hft, is_supported_mul
(is_supported_upwards hxs $ set.subset_union_left s t)
(is_supported_upwards hxt $ set.subset_union_right s t)⟩)
theorem exists_finset_support (x : free_comm_ring α) : ∃ s : finset α, is_supported x ↑s :=
let ⟨s, hfs, hxs⟩ := exists_finite_support x in ⟨hfs.to_finset, by rwa finset.coe_to_finset⟩
end free_comm_ring
namespace free_ring
open function
variable (α)
def to_free_comm_ring {α} : free_ring α → free_comm_ring α :=
free_ring.lift free_comm_ring.of
instance to_free_comm_ring.is_ring_hom : is_ring_hom (@to_free_comm_ring α) :=
free_ring.is_ring_hom free_comm_ring.of
instance : has_coe (free_ring α) (free_comm_ring α) := ⟨to_free_comm_ring⟩
instance coe.is_ring_hom : is_ring_hom (coe : free_ring α → free_comm_ring α) :=
free_ring.to_free_comm_ring.is_ring_hom _
@[simp] protected lemma coe_zero : ↑(0 : free_ring α) = (0 : free_comm_ring α) := rfl
@[simp] protected lemma coe_one : ↑(1 : free_ring α) = (1 : free_comm_ring α) := rfl
variable {α}
@[simp] protected lemma coe_of (a : α) : ↑(free_ring.of a) = free_comm_ring.of a :=
free_ring.lift_of _ _
@[simp] protected lemma coe_neg (x : free_ring α) : ↑(-x) = -(x : free_comm_ring α) :=
free_ring.lift_neg _ _
@[simp] protected lemma coe_add (x y : free_ring α) : ↑(x + y) = (x : free_comm_ring α) + y :=
free_ring.lift_add _ _ _
@[simp] protected lemma coe_sub (x y : free_ring α) : ↑(x - y) = (x : free_comm_ring α) - y :=
free_ring.lift_sub _ _ _
@[simp] protected lemma coe_mul (x y : free_ring α) : ↑(x * y) = (x : free_comm_ring α) * y :=
free_ring.lift_mul _ _ _
variable (α)
protected lemma coe_surjective : surjective (coe : free_ring α → free_comm_ring α) :=
λ x,
begin
apply free_comm_ring.induction_on x,
{ use -1, refl },
{ intro x, use free_ring.of x, refl },
{ rintros _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, use x + y, exact free_ring.lift_add _ _ _ },
{ rintros _ _ ⟨x, rfl⟩ ⟨y, rfl⟩, use x * y, exact free_ring.lift_mul _ _ _ }
end
lemma coe_eq :
(coe : free_ring α → free_comm_ring α) =
@functor.map free_abelian_group _ _ _ (λ (l : list α), (l : multiset α)) :=
begin
funext,
apply @free_abelian_group.lift.ext _ _ _
(coe : free_ring α → free_comm_ring α) _ _ (free_abelian_group.lift.is_add_group_hom _),
intros x,
change free_ring.lift free_comm_ring.of (free_abelian_group.of x) = _,
change _ = free_abelian_group.of (↑x),
induction x with hd tl ih, {refl},
simp only [*, free_ring.lift, free_comm_ring.of, free_abelian_group.of, free_abelian_group.lift,
free_group.of, free_group.to_group, free_group.to_group.aux,
mul_one, free_group.quot_lift_mk, abelianization.lift.of, bool.cond_tt, list.prod_cons,
cond, list.prod_nil, list.map] at *,
refl
end
def subsingleton_equiv_free_comm_ring [subsingleton α] :
free_ring α ≃+* free_comm_ring α :=
@ring_equiv.of' (free_ring α) (free_comm_ring α) _ _
(functor.map_equiv free_abelian_group (multiset.subsingleton_equiv α)) $
begin
delta functor.map_equiv,
rw congr_arg is_ring_hom _,
work_on_goal 2 { symmetry, exact coe_eq α },
apply_instance
end
instance [subsingleton α] : comm_ring (free_ring α) :=
{ mul_comm := λ x y,
by rw [← (subsingleton_equiv_free_comm_ring α).left_inv (y * x),
is_ring_hom.map_mul ((subsingleton_equiv_free_comm_ring α)).to_fun,
mul_comm,
← is_ring_hom.map_mul ((subsingleton_equiv_free_comm_ring α)).to_fun,
(subsingleton_equiv_free_comm_ring α).left_inv],
.. free_ring.ring α }
end free_ring
def free_comm_ring_equiv_mv_polynomial_int :
free_comm_ring α ≃+* mv_polynomial α ℤ :=
{ to_fun := free_comm_ring.lift $ λ a, mv_polynomial.X a,
inv_fun := mv_polynomial.eval₂ coe free_comm_ring.of,
left_inv :=
begin
intro x,
haveI : is_semiring_hom (coe : int → free_comm_ring α) :=
(int.cast_ring_hom _).is_semiring_hom,
refine free_abelian_group.induction_on x rfl _ _ _,
{ intro s,
refine multiset.induction_on s _ _,
{ unfold free_comm_ring.lift,
rw [free_abelian_group.lift.of],
exact mv_polynomial.eval₂_one _ _ },
{ intros hd tl ih,
show mv_polynomial.eval₂ coe free_comm_ring.of
(free_comm_ring.lift (λ a, mv_polynomial.X a)
(free_comm_ring.of hd * free_abelian_group.of tl)) =
free_comm_ring.of hd * free_abelian_group.of tl,
rw [free_comm_ring.lift_mul, free_comm_ring.lift_of,
mv_polynomial.eval₂_mul, mv_polynomial.eval₂_X, ih] } },
{ intros s ih,
rw [free_comm_ring.lift_neg, ← neg_one_mul, mv_polynomial.eval₂_mul,
← mv_polynomial.C_1, ← mv_polynomial.C_neg, mv_polynomial.eval₂_C,
int.cast_neg, int.cast_one, neg_one_mul, ih] },
{ intros x₁ x₂ ih₁ ih₂, rw [free_comm_ring.lift_add, mv_polynomial.eval₂_add, ih₁, ih₂] }
end,
right_inv :=
begin
intro x,
haveI : is_semiring_hom (coe : int → free_comm_ring α) :=
(int.cast_ring_hom _).is_semiring_hom,
have : ∀ i : ℤ, free_comm_ring.lift (λ (a : α), mv_polynomial.X a) ↑i = mv_polynomial.C i,
{ exact λ i, int.induction_on i
(by rw [int.cast_zero, free_comm_ring.lift_zero, mv_polynomial.C_0])
(λ i ih, by rw [int.cast_add, int.cast_one, free_comm_ring.lift_add,
free_comm_ring.lift_one, ih, mv_polynomial.C_add, mv_polynomial.C_1])
(λ i ih, by rw [int.cast_sub, int.cast_one, free_comm_ring.lift_sub,
free_comm_ring.lift_one, ih, mv_polynomial.C_sub, mv_polynomial.C_1]) },
apply mv_polynomial.induction_on x,
{ intro i, rw [mv_polynomial.eval₂_C, this] },
{ intros p q ihp ihq, rw [mv_polynomial.eval₂_add, free_comm_ring.lift_add, ihp, ihq] },
{ intros p a ih,
rw [mv_polynomial.eval₂_mul, mv_polynomial.eval₂_X,
free_comm_ring.lift_mul, free_comm_ring.lift_of, ih] }
end,
.. free_comm_ring.lift_hom $ λ a, mv_polynomial.X a }
def free_comm_ring_pempty_equiv_int : free_comm_ring pempty.{u+1} ≃+* ℤ :=
ring_equiv.trans (free_comm_ring_equiv_mv_polynomial_int _) (mv_polynomial.pempty_ring_equiv _)
def free_comm_ring_punit_equiv_polynomial_int : free_comm_ring punit.{u+1} ≃+* polynomial ℤ :=
ring_equiv.trans (free_comm_ring_equiv_mv_polynomial_int _) (mv_polynomial.punit_ring_equiv _)
open free_ring
def free_ring_pempty_equiv_int : free_ring pempty.{u+1} ≃+* ℤ :=
ring_equiv.trans (subsingleton_equiv_free_comm_ring _) free_comm_ring_pempty_equiv_int
def free_ring_punit_equiv_polynomial_int : free_ring punit.{u+1} ≃+* polynomial ℤ :=
ring_equiv.trans (subsingleton_equiv_free_comm_ring _) free_comm_ring_punit_equiv_polynomial_int
|
60259ec398e9116bd8b3c2e5eb0f1814c78517bb | 9ad8d18fbe5f120c22b5e035bc240f711d2cbd7e | /src/algebra/convolution.lean | ff9b0f7ac5dfdc776dd0bcebca3674ca22c4fa63 | [] | no_license | agusakov/lean_lib | c0e9cc29fc7d2518004e224376adeb5e69b5cc1a | f88d162da2f990b87c4d34f5f46bbca2bbc5948e | refs/heads/master | 1,642,141,461,087 | 1,557,395,798,000 | 1,557,395,798,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 19,157 | lean | /-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
This file sets up a framework for convolution. The first ingredient
is an additive monoid `M` with the property that for any `m ∈ M`, the
set `{⟨x,y⟩ : x + y = m}` is finite. If `M` has this property and `R`
is a ring and `f,g : M → R` then we can define `(f * g) m` to be the
sum of `(f x) * (g y)` for all pairs `⟨x,y⟩` with `x + y = m`. If
`M = ℕ` then this rule gives us the power series ring `R[[x]]`.
The first part of this file defines a typeclass `sum_set M` for
additive monoids `M` with the finiteness property mentioned above,
and derives some additional properties of such monoids.
We then define convolution. In order to cover some additional
applications, we work in a context slightly more general than outlined
above. First, we define `convolution.map M P := M → P`, and attach
the convolution structure to the name `convolution.map`. This is
intended to accomodate the fact that we might want to use pointwise
products on `M → P` in some other contexts. I am not sure whether
this is the best way to address that issue. Also, we will assume
that we have a biadditive map `m₁₂ : P₁ → P₂ → P₁₂` of additive
commutative monoids, and we will use it to define a convolution
operation `map M P₁ → map M P₂ → map M P₁₂`. We can recover the
ring structure on `map M R` by taking `P₁ = P₂ = P₁₂ = R`.
-/
import data.fintype data.finsupp algebra.big_operators algebra.pi_instances
import data.list_extra algebra.biadditive algebra.prod_equiv
import tactic.squeeze tactic.pi_instances
namespace convolution
open finset
class sum_set (M : Type*) [add_monoid M] :=
(els : M → finset (M × M))
(mem_els : forall (m : M) (xy : M × M), xy ∈ els m ↔ xy.1 + xy.2 = m)
namespace sum_set
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
variable (m : M)
def incl (x : M) : (M × M) ↪ (M × M × M) :=
⟨prod.mk x,λ yz₀ yz₁ e, by {injection e}⟩
def incr (z : M) : (M × M) ↪ (M × M × M) :=
⟨λ xy, ⟨xy.1,xy.2,z⟩,λ ⟨x₀,y₀⟩ ⟨x₁,y₁⟩ e,
by {injection e with ex eyz,injection eyz with ey ez,
change x₀ = x₁ at ex,change y₀ = y₁ at ey,rw[ex,ey],}⟩
variable (M)
def twist : M × M ↪ M × M :=
⟨λ xy, ⟨xy.2,xy.1⟩,
λ ⟨x₀,y₀⟩ ⟨x₁,y₁⟩ e,
by {injection e with hy hx,
change x₀ = x₁ at hx, change y₀ = y₁ at hy, rw[hx,hy],}⟩
variable {M}
def els3 : finset (M × M × M) :=
(els m).bind (λ xv,(els xv.2).map (incl xv.1))
def els3' : finset (M × M × M) :=
(els m).bind (λ uz,(els uz.1).map (incr uz.2))
lemma els3_disjoint (m : M)
(xv₁ : M × M) (h₁ : xv₁ ∈ els m) (xv₂ : M × M) (h₂ : xv₂ ∈ els m)
(h : xv₁ ≠ xv₂) :
(els xv₁.2).map (incl xv₁.1) ∩ (els xv₂.2).map (incl xv₂.1) = ∅ :=
begin
rcases xv₁ with ⟨x₁,v₁⟩,
rcases xv₂ with ⟨x₂,v₂⟩,
apply eq_empty_iff_forall_not_mem.mpr,intros w hw,apply h,
rcases (mem_inter.mp hw) with ⟨hw₁,hw₂⟩,
rcases mem_map.mp hw₁ with ⟨yz₁,⟨w_sum₁,w_eq₁⟩⟩,
rcases mem_map.mp hw₂ with ⟨yz₂,⟨w_sum₂,w_eq₂⟩⟩,
injection (w_eq₁.trans w_eq₂.symm) with ex eyz,
change x₁ = x₂ at ex,
replace w_sum₁ := (mem_els v₁ _).mp w_sum₁,
replace w_sum₂ := (mem_els v₂ _).mp w_sum₂,
rw[eyz] at w_sum₁,
have ev : v₁ = v₂ := w_sum₁.symm.trans w_sum₂,
rw[ex,ev],
end
lemma els3'_disjoint (m : M)
(uz₁ : M × M) (h₁ : uz₁ ∈ els m) (uz₂ : M × M) (h₂ : uz₂ ∈ els m)
(h : uz₁ ≠ uz₂) :
(els uz₁.1).map (incr uz₁.2) ∩ (els uz₂.1).map (incr uz₂.2) = ∅ :=
begin
rcases uz₁ with ⟨u₁,z₁⟩,
rcases uz₂ with ⟨u₂,z₂⟩,
apply eq_empty_iff_forall_not_mem.mpr,intros w hw,apply h,
rcases (mem_inter.mp hw) with ⟨hw₁,hw₂⟩,
rcases mem_map.mp hw₁ with ⟨xy₁,⟨w_sum₁,w_eq₁⟩⟩,
rcases mem_map.mp hw₂ with ⟨xy₂,⟨w_sum₂,w_eq₂⟩⟩,
injection (w_eq₁.trans w_eq₂.symm) with ex eyz,
injection eyz with ey ez,
change z₁ = z₂ at ez,
replace w_sum₁ := (mem_els u₁ _).mp w_sum₁,
replace w_sum₂ := (mem_els u₂ _).mp w_sum₂,
rw[ex,ey] at w_sum₁,
have eu : u₁ = u₂ := w_sum₁.symm.trans w_sum₂,
rw[eu,ez],
end
lemma mem_els3 (xyz : M × M × M) :
xyz ∈ els3 m ↔ xyz.1 + xyz.2.1 + xyz.2.2 = m :=
begin
rcases xyz with ⟨x,y,z⟩,
change (⟨x,y,z⟩ : M × M × M) ∈ els3 m ↔ x + y + z = m,
split,
{intro hw,
rcases mem_bind.mp hw with ⟨xv,⟨hxv,h⟩⟩,
replace hxv := (mem_els m xv).mp hxv,
rcases mem_map.mp h with ⟨yz,⟨hyz,h'⟩⟩,
replace hyz := (mem_els _ yz).mp hyz,
injection h' with ex eyz, rw[eyz] at hyz,
rw[← hyz,ex,← add_assoc] at hxv,exact hxv,
},
{intro e,
apply mem_bind.mpr,
use ⟨x,y + z⟩,
have : x + (y + z) = m := by {rw[← add_assoc,e]},
use (mem_els m ⟨x,y + z⟩).mpr this,
apply mem_map.mpr,
use ⟨y,z⟩, use (mem_els _ _).mpr rfl,refl,
}
end
lemma els3_assoc : els3 m = els3' m :=
begin
ext ⟨x,y,z⟩,rw[mem_els3],
change x + y + z = m ↔ (⟨x,y,z⟩ : M × M × M) ∈ els3' m,
split,
{intro e,
apply mem_bind.mpr,use ⟨x + y,z⟩,use (mem_els m _).mpr e,
apply mem_map.mpr,
use ⟨x,y⟩, use (mem_els _ _).mpr rfl,refl,
},
{intro hw,
rcases mem_bind.mp hw with ⟨uz,⟨huz,h⟩⟩,
replace huz := (mem_els m uz).mp huz,
rcases mem_map.mp h with ⟨xy,⟨hxy,h'⟩⟩,
replace hxy := (mem_els _ xy).mp hxy,
injection h' with hx hyz,injection hyz with hy hz,
rw[hx,hy] at hxy, rw[← hxy,hz] at huz,
exact huz,
}
end
lemma els_zero_left :
(els m).filter (λ xy, 0 = xy.1) = finset.singleton ⟨0,m⟩ :=
begin
ext ⟨x,y⟩,
rw[mem_filter,mem_els,mem_singleton],
split,
{rintro ⟨h,h'⟩,change x + y = m at h, change 0 = x at h',
rw[← h'] at h ⊢,rw[zero_add] at h,rw[h],
},{
intro e,injection e with ex ey,rw[ex,ey],
split,{change 0 + m = m,rw[zero_add],},{refl}
}
end
lemma els_zero_right :
(els m).filter (λ xy, 0 = xy.2) = finset.singleton ⟨m,0⟩ :=
begin
ext ⟨x,y⟩,
rw[mem_filter,mem_els,mem_singleton],
split,
{rintro ⟨h,h'⟩,change x + y = m at h, change 0 = y at h',
rw[← h'] at h ⊢,rw[add_zero] at h,rw[h],
},{
intro e,injection e with ex ey,rw[ex,ey],
split,{change m + 0 = m,rw[add_zero],},{refl}
}
end
instance : sum_set ℕ := {
els := λ m, (range m.succ).image (λ i, ⟨i,m - i⟩),
mem_els := λ m ⟨x,y⟩, begin
split,
{intro h,rcases mem_image.mp h with ⟨i,⟨i_is_le,e⟩⟩,
replace i_is_le : i ≤ m := mem_range_succ.mp i_is_le,
injection e with ex ey,rw[← ex,← ey],
exact nat.add_sub_of_le i_is_le,
},
{intro e,rw[mem_image],use x,
use mem_range_succ.mpr (e ▸ (nat.le_add_right x y)),congr,
exact nat.sub_eq_of_eq_add e.symm,
}
end
}
def shuffle (M₁ : Type*) (M₂ : Type*) :
(M₁ × M₁) × (M₂ × M₂) ↪ (M₁ × M₂) × (M₁ × M₂) := {
to_fun := λ x, ⟨⟨x.1.1,x.2.1⟩,⟨x.1.2,x.2.2⟩⟩,
inj := begin
rintros ⟨⟨x₁,x₂⟩,⟨x₃,x₄⟩⟩ ⟨⟨y₁,y₂⟩,⟨y₃,y₄⟩⟩ e,
injection e with e₁₃ e₂₄,
injection e₁₃ with e₁ e₃, injection e₂₄ with e₂ e₄,
change x₁ = y₁ at e₁, change x₂ = y₂ at e₂,
change x₃ = y₃ at e₃, change x₄ = y₄ at e₄,
rw[e₁,e₂,e₃,e₄],
end
}
instance product
(M₁ : Type*) [add_monoid M₁] [sum_set M₁]
(M₂ : Type*) [add_monoid M₂] [sum_set M₂] : sum_set (M₁ × M₂) := {
els := λ m, (finset.product (els m.1) (els m.2)).map (shuffle M₁ M₂),
mem_els := begin
rintros ⟨m₁,m₂⟩ ⟨⟨x₁,x₃⟩,⟨x₂,x₄⟩⟩,
simp only[],split,
{intro h₁,rcases (mem_map.mp h₁) with ⟨⟨⟨y₁,y₂⟩,⟨y₃,y₄⟩⟩,⟨h₂,e⟩⟩,
dsimp[shuffle] at e,injection e with e₁₃ e₂₄,
injection e₁₃ with e₁ e₃, injection e₂₄ with e₂ e₄,
rw[← e₁,← e₂,← e₃,← e₄],
change prod.mk (y₁ + y₂) (y₃ + y₄) = prod.mk m₁ m₂,
rcases mem_product.mp h₂ with ⟨h₃,h₄⟩,
replace h₃ : y₁ + y₂ = m₁ := (mem_els _ _).mp h₃,
replace h₄ : y₃ + y₄ = m₂ := (mem_els _ _).mp h₄,
rw[h₃,h₄],
},{
intro e,injection e with e₁ e₂,
apply mem_map.mpr, use ⟨⟨x₁,x₂⟩,⟨x₃,x₄⟩⟩,
have h₁ : (prod.mk x₁ x₂) ∈ els m₁ := (mem_els _ _).mpr e₁,
have h₂ : (prod.mk x₃ x₄) ∈ els m₂ := (mem_els _ _).mpr e₂,
use mem_product.mpr ⟨h₁,h₂⟩,refl,
}
end
}
end sum_set
namespace sum_set
variables {M : Type*} [add_comm_monoid M] [decidable_eq M] [sum_set M]
variable (m : M)
lemma els_twist :
(els m).map (twist M) = els m :=
begin
ext ⟨x,y⟩,rw[mem_els],split,
{intro h,rcases mem_map.mp h with ⟨⟨y',x'⟩,⟨yx_sum,e⟩⟩,
change (⟨x',y'⟩ : M × M) = ⟨x,y⟩ at e,injection e with ex ey,
replace yx_sum : y' + x' = m := (mem_els _ _).mp yx_sum,
rw[ex,ey,add_comm y x] at yx_sum,exact yx_sum,
},{
intro e,rw[add_comm] at e,change y + x = m at e,
apply mem_map.mpr,use ⟨y,x⟩,
use (mem_els _ _).mpr e,refl,
}
end
end sum_set
def map (M : Type*) (P : Type*) := M → P
namespace map
variables (M : Type*) (P : Type*)
instance : has_coe_to_fun (map M P) := ⟨λ _, M → P,id⟩
variables {M} {P}
instance [has_zero P] : has_zero (map M P) :=
by {dsimp[map],apply_instance}
@[simp]
lemma zero_apply [has_zero P] {m : M} :
(0 : map M P) m = 0 := rfl
instance [has_add P] : has_add (map M P) :=
by {dsimp[map],apply_instance}
@[simp]
lemma add_apply [has_add P] {a₁ a₂ : map M P} {m : M} :
(a₁ + a₂) m = a₁ m + a₂ m := rfl
instance [add_semigroup P] : add_semigroup (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_semigroup P] : add_comm_semigroup (map M P) :=
by {dsimp[map],apply_instance}
instance [add_monoid P] : add_monoid (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_monoid P] : add_comm_monoid (map M P) :=
by {dsimp[map],apply_instance}
instance [add_group P] : add_group (map M P) :=
by {dsimp[map],apply_instance}
instance [add_comm_group P] : add_comm_group (map M P) :=
by {dsimp[map],apply_instance}
instance [has_zero M] [decidable_eq M] [has_zero P] [has_one P] : has_one (map M P) :=
⟨λ m, ite (m = 0) 1 0⟩
@[simp]
lemma one_apply [has_zero M] [decidable_eq M] [has_zero P] [has_one P] (m : M) :
(1 : map M P) m = ite (m = 0) 1 0 := rfl
@[simp]
lemma one_apply_zero [has_zero M] [decidable_eq M] [has_zero P] [has_one P] :
(1 : map M P) 0 = 1 := by { dsimp[has_one.one],rw[if_pos rfl] }
lemma one_apply_nz [has_zero M] [decidable_eq M] [has_zero P] [has_one P]
{m : M} (h : m ≠ 0) : (1 : map M P) m = 0 :=
by { dsimp[has_one.one],rw[if_neg h] }
@[extensionality]
lemma ext : ∀ {a₁ a₂ : map M P}, (∀ m, a₁ m = a₂ m) → a₁ = a₂ := @funext _ _
section single
variables [decidable_eq M]
def single [has_zero P] (m : M) (p : P) : (map M P) :=
λ x, ite (m = x) p (0 : P)
lemma single_apply [has_zero P] {m : M} {p : P} (x : M) :
(single m p) x = ite (m = x) p 0 := rfl
@[simp] lemma single_eq_same [has_zero P] {m : M} {p : P} :
(single m p) m = p := if_pos rfl
@[simp] lemma single_eq_of_ne [has_zero P] {m x : M} {p : P} (h : m ≠ x) :
(single m p) x = 0 := if_neg h
@[simp] lemma single_zero [has_zero P] {m : M} : single m (0 : P) = 0 :=
by {ext x,dsimp[single],split_ifs; refl}
lemma single_add [add_monoid P] {m : M} {p₁ p₂ : P} :
single m (p₁ + p₂) = single m p₁ + single m p₂ :=
by {ext x,dsimp[single],split_ifs,refl,rw[zero_add],}
def delta [has_zero P] [has_zero M] (p : P) : map M P := single (0 : M) p
lemma delta_apply [has_zero P] [has_zero M] {p : P} {x : M} :
(delta p) x = ite ((0 : M) = x) p (0 : P) := rfl
lemma delta_eq_zero [has_zero P] [has_zero M] {p : P} :
(delta p) (0 : M) = p := if_pos rfl
lemma delta_eq_of_ne [has_zero P] [has_zero M] {p : P} {x : M} (h : 0 ≠ x) :
(delta p) x = 0 := single_eq_of_ne h
lemma delta_zero [has_zero P] [has_zero M] :
((delta (0 : P)) : map M P) = 0 := single_zero
lemma delta_add [add_monoid P] [has_zero M] {p₁ p₂ : P} :
(delta (p₁ + p₂) : map M P) = delta p₁ + delta p₂ := single_add
end single
end map
section convolve
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
open sum_set
open map
variables {P₁ : Type*} {P₂ : Type*} {P₃ : Type*}
variables {P₁₂ : Type*} {P₂₃ : Type*} {P₁₂₃ : Type*}
variables [add_comm_monoid P₁] [add_comm_monoid P₂] [add_comm_monoid P₃]
variables [add_comm_monoid P₁₂] [add_comm_monoid P₂₃] [add_comm_monoid P₁₂₃]
variables (m₁₂ : P₁ → P₂ → P₁₂) [is_biadditive m₁₂]
variables (m₂₃ : P₂ → P₃ → P₂₃) [is_biadditive m₂₃]
variables (m₁₂₃ : P₁₂ → P₃ → P₁₂₃) [is_biadditive m₁₂₃]
variables (m'₁₂₃ : P₁ → P₂₃ → P₁₂₃) [is_biadditive m'₁₂₃]
def convolve (u₁ : map M P₁) (u₂ : map M P₂) : (map M P₁₂) :=
λ m, (els m).sum (λ x, m₁₂ (u₁ x.1) (u₂ x.2))
lemma zero_convolve (p₂ : map M P₂) : convolve m₁₂ 0 p₂ = 0 := begin
ext m,dsimp[convolve],
have : (els m).sum (λ x, (0 : P₁₂)) = 0 := sum_const_zero,
rw[← this],congr,funext x,rw[is_biadditive.zero_mul m₁₂],
end
lemma convolve_zero (p₁ : map M P₁) : convolve m₁₂ p₁ 0 = 0 := begin
ext m,dsimp[convolve],
have : (els m).sum (λ x, (0 : P₁₂)) = 0 := sum_const_zero,
rw[← this],congr,funext x,rw[is_biadditive.mul_zero m₁₂],
end
lemma add_convolve (p₁ q₁ : map M P₁) (p₂ : map M P₂) :
convolve m₁₂ (p₁ + q₁) p₂ = convolve m₁₂ p₁ p₂ + convolve m₁₂ q₁ p₂ := begin
ext m,
dsimp[convolve],rw[← sum_add_distrib],congr,funext x,
rw[is_biadditive.add_mul m₁₂],
end
lemma convolve_add (p₁ : map M P₁) (p₂ q₂ : map M P₂) :
convolve m₁₂ p₁ (p₂ + q₂) = convolve m₁₂ p₁ p₂ + convolve m₁₂ p₁ q₂ := begin
ext m,
dsimp[convolve],rw[← sum_add_distrib],congr,funext x,
rw[is_biadditive.mul_add m₁₂],
end
instance biadditive_convolve:
is_biadditive (convolve m₁₂ : (map M P₁) → (map M P₂) → (map M P₁₂)) := {
zero_mul := zero_convolve m₁₂,
add_mul := add_convolve m₁₂,
mul_zero := convolve_zero m₁₂,
mul_add := convolve_add m₁₂,
}
lemma convolve_assoc (p₁ : map M P₁) (p₂ : map M P₂) (p₃ : map M P₃)
(m_assoc : ∀ (p₁ : P₁) (p₂ : P₂) (p₃ : P₃), m₁₂₃ (m₁₂ p₁ p₂) p₃ = m'₁₂₃ p₁ (m₂₃ p₂ p₃)) :
convolve m₁₂₃ (convolve m₁₂ p₁ p₂) p₃ =
convolve m'₁₂₃ p₁ (convolve m₂₃ p₂ p₃) :=
begin
ext m,
let f' : M × M × M → P₁₂₃ := λ x, m₁₂₃ (m₁₂ (p₁ x.1) (p₂ x.2.1)) (p₃ x.2.2),
let f : M × M × M → P₁₂₃ := λ x, m'₁₂₃ (p₁ x.1) (m₂₃ (p₂ x.2.1) (p₃ x.2.2)),
have ef : f' = f := by {funext x,apply m_assoc},
have em' : (els3' m).sum f' = (convolve m₁₂₃ (convolve m₁₂ p₁ p₂) p₃) m :=
begin
dsimp[convolve,els3'],
rw[sum_bind (els3'_disjoint m)],congr,ext ⟨x,v⟩,
rw[is_biadditive.sum_mul m₁₂₃,sum_map],congr,
end,
have em : (els3 m).sum f = (convolve m'₁₂₃ p₁ (convolve m₂₃ p₂ p₃)) m :=
begin
dsimp[convolve,els3],
rw[sum_bind (els3_disjoint m)],congr,ext ⟨u,z⟩,
rw[is_biadditive.mul_sum m'₁₂₃,sum_map],congr,
end,
rw[← em,← em',ef,els3_assoc],
end
lemma delta_convolve (p₁ : P₁) (u₂ : map M P₂) (m : M) :
(convolve m₁₂ (delta p₁) u₂) m = m₁₂ p₁ (u₂ m) :=
begin
dsimp[convolve],
let f : M × M → P₁₂ := λ x, m₁₂ (delta p₁ x.1) (u₂ x.2),
let f' : M × M → P₁₂ := λ x, ite (0 = x.1) (f x) 0,
have ef : f = f' :=
by {ext x,dsimp[f,f'],
split_ifs with hx,{refl},{rw[delta_eq_of_ne hx,is_biadditive.zero_mul m₁₂]}},
change (els m).sum f = m₁₂ p₁ (u₂ m),
rw[ef],
have : ((els m).filter (λ (x : M × M), 0 = x.1)).sum f = (els m).sum f' :=
sum_filter (λ (x : M × M), 0 = x.1) f,
rw[← this],rw[els_zero_left,sum_singleton],
dsimp[f],rw[delta_eq_zero],
end
lemma convolve_delta (u₁ : M → P₁) (p₂ : P₂) (m : M) :
(convolve m₁₂ u₁ (delta p₂)) m = m₁₂ (u₁ m) p₂ :=
begin
dsimp[convolve],
let f : M × M → P₁₂ := λ x, m₁₂ (u₁ x.1) (delta p₂ x.2),
let f' : M × M → P₁₂ := λ x, ite (0 = x.2) (f x) 0,
have ef : f = f' :=
by {ext x,dsimp[f,f'],
split_ifs with hx,{refl},{rw[delta_eq_of_ne hx,is_biadditive.mul_zero m₁₂]}},
change (els m).sum f = m₁₂ (u₁ m) p₂,
rw[ef],
have : ((els m).filter (λ (x : M × M), 0 = x.2)).sum f = (els m).sum f' :=
sum_filter (λ x, 0 = x.2) f,
rw[← this,els_zero_right,sum_singleton],
dsimp[f],rw[delta_eq_zero],
end
lemma delta_convolve_delta (p₁ : P₁) (p₂ : P₂) :
(convolve m₁₂ (delta p₁) (delta p₂) : map M P₁₂) = delta (m₁₂ p₁ p₂) :=
by { ext m, rw[delta_convolve,delta_apply,delta_apply],
split_ifs,refl,rw[is_biadditive.mul_zero m₁₂]}
end convolve
namespace map
variables {M : Type*} [add_monoid M] [decidable_eq M] [sum_set M]
instance to_semiring {R : Type*} [semiring R] : semiring (map M R) := {
one := delta (1 : R),
mul := convolve ((*) : R → R → R),
zero_mul := λ a, zero_convolve (*) a,
mul_zero := λ a, convolve_zero (*) a,
one_mul := λ a, begin
ext m,
change convolve (*) (delta (1 : R)) a m = a m,
rw[delta_convolve,one_mul],
end,
mul_one := λ a, begin
ext m,
change convolve (*) a (delta (1 : R)) m = a m,
rw[convolve_delta,mul_one],
end,
mul_assoc := λ a b c, convolve_assoc (*) (*) (*) (*) a b c (mul_assoc),
left_distrib := λ a b c, convolve_add (*) a b c,
right_distrib := λ a b c, add_convolve (*) a b c,
.. (by apply_instance : add_comm_monoid (map M R))
}
instance to_ring {R : Type*} [ring R] : ring (map M R) := {
.. (by apply_instance : add_comm_group (map M R)),
.. (by apply_instance : semiring (map M R))
}
end map
namespace map
open sum_set
variables {M : Type*} [add_comm_monoid M] [decidable_eq M] [sum_set M]
instance to_comm_semiring {R : Type*} [comm_semiring R] : comm_semiring (map M R) := {
mul_comm := λ a₁ a₂, begin
let f : M × M → R := λ x, (a₁ x.1) * (a₂ x.2),
let f' : M × M → R := λ x, (a₂ x.1) * (a₁ x.2),
have ef : (λ x, f (twist M x)) = f' := by {
ext x,dsimp[f,f',twist],rw[mul_comm],
},
ext m, change (els m).sum f = (els m).sum f',
rw[← ef, ← sum_map (els m) (twist M) f,els_twist],
end,
.. map.to_semiring
}
instance to_comm_ring {R : Type*} [comm_ring R] : comm_ring (map M R) := {
.. (by apply_instance : add_comm_group (map M R)),
.. (by apply_instance : comm_semiring (map M R))
}
end map
end convolution
|
afd8a680b9ffba46906ee9630f8f319929c68c86 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/interactive/num2.lean | 06c5e02270c16fb04a7edbec2fd4dace1b3de730 | [
"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 | 1,453 | 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
----------------------------------------------------------------------------------------------------
import logic.inhabited
-- pos_num and num are two auxiliary datatypes used when parsing numerals such as 13, 0, 26.
-- The parser will generate the terms (pos (bit1 (bit1 (bit0 one)))), zero, and (pos (bit0 (bit1 (bit1 one)))).
-- This representation can be coerced in whatever we want (e.g., naturals, integers, reals, etc).
inductive pos_num : Type :=
one : pos_num|
bit1 : pos_num → pos_num|
bit0 : pos_num → pos_num
theorem pos_num.is_inhabited [instance] : inhabited pos_num :=
inhabited.mk pos_num.one
namespace pos_num
definition inc (a : pos_num) : pos_num :=
rec (bit0 one) (λn r, bit0 r) (λn r, bit1 n) a
definition num_bits (a : pos_num) : pos_num :=
rec one (λn r, inc r) (λn r, inc r) a
end pos_num
inductive num : Type :=
zero : num,
pos : pos_num → num
theorem num.is_inhabited [instance] : inhabited num :=
inhabited.mk num.zero
namespace num
definition inc (a : num) : num :=
rec (pos pos_num.one) (λp, pos (pos_num.inc p)) a
definition num_bits (a : num) : num :=
rec (pos pos_num.one) (λp, pos (pos_num.num_bits p)) a
end num
|
066d6c8d730a6fc66ef863cecbbb126cff25848c | a46270e2f76a375564f3b3e9c1bf7b635edc1f2c | /7.2.lean | 67649b0fc8dc794d1b9d8a42e106000216f47a0a | [
"CC0-1.0"
] | permissive | wudcscheme/lean-exercise | 88ea2506714eac343de2a294d1132ee8ee6d3a20 | 5b23b9be3d361fff5e981d5be3a0a1175504b9f6 | refs/heads/master | 1,678,958,930,293 | 1,583,197,205,000 | 1,583,197,205,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,212 | lean | #check option.cases_on
def comp {α β γ : Type*} (f: α -> option β) (g: β -> option γ) (x: α): option γ :=
option.cases_on (f x) option.none (λ y, g y)
#print comp
#reduce comp (λ x, some (x*x)) (λ x, some (x+1)) 10
example: comp (λ x, some (x*x)) (λ x, some (x+1)) 10 = some 101 := by rsimp
#reduce comp (λ x, none) (λ x, some (x+1)) 10
example: comp (λ x, none) (λ x, some (x+1)) 10 = none := by rsimp
def pipe {α β : Type*} (x: option α) (f: α -> option β): option β :=
option.cases_on x option.none (λ y, f y)
#print pipe
infixl `>>`:50 := pipe
#reduce (some 10) >> (λ x, some $ x*x) >> (λ x, some $ x+1).
#reduce (some 10) >> (λ x, none) >> (λ x, some $ x+1).
#reduce none >> (λ x, some $ x*x) >> (λ x, some $x+1).
def ibool: inhabited bool := inhabited.mk tt
def inat: inhabited ℕ := inhabited.mk 0
theorem ipair: ∀α β : Type*, inhabited α × inhabited β -> inhabited (α × β) := begin
intros α β h,
cases h with a b,
from inhabited.mk (a.default, b.default)
end
theorem ifun: ∀ α β : Type*, (α -> inhabited β) -> inhabited (α -> β) := begin
intros α β f,
from inhabited.mk (λ x: α, (f x).default)
end
|
9d3a0ac9e8f4e80ca5db92f2ef84b74f94feba89 | b7f22e51856f4989b970961f794f1c435f9b8f78 | /hott/types/list.hlean | f5aee10151d2d8d83aced5fca6a9bab3656bae47 | [
"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 | 36,105 | hlean | /-
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
Basic properties of lists.
Ported from the standard library (list.basic and list.comb)
Some lemmas are commented out, their proofs need to be repaired when needed
-/
import .pointed .nat .pi
open eq lift nat is_trunc pi pointed sum function prod option sigma algebra
inductive list (T : Type) : Type :=
| nil {} : list T
| cons : T → list T → list T
definition pointed_list [instance] (A : Type) : pointed (list A) :=
pointed.mk list.nil
namespace list
notation h :: t := cons h t
notation `[` l:(foldr `, ` (h t, cons h t) nil `]`) := l
universe variable u
variable {T : Type.{u}}
lemma cons_ne_nil (a : T) (l : list T) : a::l ≠ [] :=
by contradiction
lemma head_eq_of_cons_eq {A : Type} {h₁ h₂ : A} {t₁ t₂ : list A} :
(h₁::t₁) = (h₂::t₂) → h₁ = h₂ :=
assume Peq, down (list.no_confusion Peq (assume Pheq Pteq, Pheq))
lemma tail_eq_of_cons_eq {A : Type} {h₁ h₂ : A} {t₁ t₂ : list A} :
(h₁::t₁) = (h₂::t₂) → t₁ = t₂ :=
assume Peq, down (list.no_confusion Peq (assume Pheq Pteq, Pteq))
/- append -/
definition append : list T → list T → list T
| [] l := l
| (h :: s) t := h :: (append s t)
notation l₁ ++ l₂ := append l₁ l₂
theorem append_nil_left (t : list T) : [] ++ t = t := idp
theorem append_cons (x : T) (s t : list T) : (x::s) ++ t = x :: (s ++ t) := idp
theorem append_nil_right : ∀ (t : list T), t ++ [] = t
| [] := rfl
| (a :: l) := calc
(a :: l) ++ [] = a :: (l ++ []) : rfl
... = a :: l : append_nil_right l
theorem append.assoc : ∀ (s t u : list T), s ++ t ++ u = s ++ (t ++ u)
| [] t u := rfl
| (a :: l) t u :=
show a :: (l ++ t ++ u) = (a :: l) ++ (t ++ u),
by rewrite (append.assoc l t u)
/- length -/
definition length : list T → nat
| [] := 0
| (a :: l) := length l + 1
theorem length_nil : length (@nil T) = 0 := idp
theorem length_cons (x : T) (t : list T) : length (x::t) = length t + 1 := idp
theorem length_append : ∀ (s t : list T), length (s ++ t) = length s + length t
| [] t := calc
length ([] ++ t) = length t : rfl
... = length [] + length t : by rewrite [length_nil, zero_add]
| (a :: s) t := calc
length (a :: s ++ t) = length (s ++ t) + 1 : rfl
... = length s + length t + 1 : length_append
... = (length s + 1) + length t : succ_add
... = length (a :: s) + length t : rfl
theorem eq_nil_of_length_eq_zero : ∀ {l : list T}, length l = 0 → l = []
| [] H := rfl
| (a::s) H := by contradiction
theorem ne_nil_of_length_eq_succ : ∀ {l : list T} {n : nat}, length l = succ n → l ≠ []
| [] n h := by contradiction
| (a::l) n h := by contradiction
-- add_rewrite length_nil length_cons
/- concat -/
definition concat : Π (x : T), list T → list T
| a [] := [a]
| a (b :: l) := b :: concat a l
theorem concat_nil (x : T) : concat x [] = [x] := idp
theorem concat_cons (x y : T) (l : list T) : concat x (y::l) = y::(concat x l) := idp
theorem concat_eq_append (a : T) : ∀ (l : list T), concat a l = l ++ [a]
| [] := rfl
| (b :: l) :=
show b :: (concat a l) = (b :: l) ++ (a :: []),
by rewrite concat_eq_append
theorem concat_ne_nil (a : T) : ∀ (l : list T), concat a l ≠ [] :=
by intro l; induction l; repeat contradiction
theorem length_concat (a : T) : ∀ (l : list T), length (concat a l) = length l + 1
| [] := rfl
| (x::xs) := by rewrite [concat_cons, *length_cons, length_concat]
theorem concat_append (a : T) : ∀ (l₁ l₂ : list T), concat a l₁ ++ l₂ = l₁ ++ a :: l₂
| [] := λl₂, rfl
| (x::xs) := λl₂, begin rewrite [concat_cons,append_cons, concat_append] end
theorem append_concat (a : T) : ∀(l₁ l₂ : list T), l₁ ++ concat a l₂ = concat a (l₁ ++ l₂)
| [] := λl₂, rfl
| (x::xs) := λl₂, begin rewrite [+append_cons, concat_cons, append_concat] end
/- last -/
definition last : Π l : list T, l ≠ [] → T
| [] h := absurd rfl h
| [a] h := a
| (a₁::a₂::l) h := last (a₂::l) !cons_ne_nil
lemma last_singleton (a : T) (h : [a] ≠ []) : last [a] h = a :=
rfl
lemma last_cons_cons (a₁ a₂ : T) (l : list T) (h : a₁::a₂::l ≠ [])
: last (a₁::a₂::l) h = last (a₂::l) !cons_ne_nil :=
rfl
theorem last_congr {l₁ l₂ : list T} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) (h₃ : l₁ = l₂)
: last l₁ h₁ = last l₂ h₂ :=
apd011 last h₃ !is_prop.elimo
theorem last_concat {x : T} : ∀ {l : list T} (h : concat x l ≠ []), last (concat x l) h = x
| [] h := rfl
| [a] h := rfl
| (a₁::a₂::l) h :=
begin
change last (a₁::a₂::concat x l) !cons_ne_nil = x,
rewrite last_cons_cons,
change last (concat x (a₂::l)) (cons_ne_nil a₂ (concat x l)) = x,
apply last_concat
end
-- add_rewrite append_nil append_cons
/- reverse -/
definition reverse : list T → list T
| [] := []
| (a :: l) := concat a (reverse l)
theorem reverse_nil : reverse (@nil T) = [] := idp
theorem reverse_cons (x : T) (l : list T) : reverse (x::l) = concat x (reverse l) := idp
theorem reverse_singleton (x : T) : reverse [x] = [x] := idp
theorem reverse_append : ∀ (s t : list T), reverse (s ++ t) = (reverse t) ++ (reverse s)
| [] t2 := calc
reverse ([] ++ t2) = reverse t2 : rfl
... = (reverse t2) ++ [] : append_nil_right
... = (reverse t2) ++ (reverse []) : by rewrite reverse_nil
| (a2 :: s2) t2 := calc
reverse ((a2 :: s2) ++ t2) = concat a2 (reverse (s2 ++ t2)) : rfl
... = concat a2 (reverse t2 ++ reverse s2) : reverse_append
... = (reverse t2 ++ reverse s2) ++ [a2] : concat_eq_append
... = reverse t2 ++ (reverse s2 ++ [a2]) : append.assoc
... = reverse t2 ++ concat a2 (reverse s2) : concat_eq_append
... = reverse t2 ++ reverse (a2 :: s2) : rfl
theorem reverse_reverse : ∀ (l : list T), reverse (reverse l) = l
| [] := rfl
| (a :: l) := calc
reverse (reverse (a :: l)) = reverse (concat a (reverse l)) : rfl
... = reverse (reverse l ++ [a]) : concat_eq_append
... = reverse [a] ++ reverse (reverse l) : reverse_append
... = reverse [a] ++ l : reverse_reverse
... = a :: l : rfl
theorem concat_eq_reverse_cons (x : T) (l : list T) : concat x l = reverse (x :: reverse l) :=
calc
concat x l = concat x (reverse (reverse l)) : reverse_reverse
... = reverse (x :: reverse l) : rfl
theorem length_reverse : ∀ (l : list T), length (reverse l) = length l
| [] := rfl
| (x::xs) := begin unfold reverse, rewrite [length_concat, length_cons, length_reverse] end
/- head and tail -/
definition head [h : pointed T] : list T → T
| [] := pt
| (a :: l) := a
theorem head_cons [h : pointed T] (a : T) (l : list T) : head (a::l) = a := idp
theorem head_append [h : pointed T] (t : list T) : ∀ {s : list T}, s ≠ [] → head (s ++ t) = head s
| [] H := absurd rfl H
| (a :: s) H :=
show head (a :: (s ++ t)) = head (a :: s),
by rewrite head_cons
definition tail : list T → list T
| [] := []
| (a :: l) := l
theorem tail_nil : tail (@nil T) = [] := idp
theorem tail_cons (a : T) (l : list T) : tail (a::l) = l := idp
theorem cons_head_tail [h : pointed T] {l : list T} : l ≠ [] → (head l)::(tail l) = l :=
list.cases_on l
(suppose [] ≠ [], absurd rfl this)
(take x l, suppose x::l ≠ [], rfl)
/- list membership -/
definition mem : T → list T → Type.{u}
| a [] := lift empty
| a (b :: l) := a = b ⊎ mem a l
notation e ∈ s := mem e s
notation e ∉ s := ¬ e ∈ s
theorem mem_nil_iff (x : T) : x ∈ [] ↔ empty :=
iff.intro down up
theorem not_mem_nil (x : T) : x ∉ [] :=
iff.mp !mem_nil_iff
theorem mem_cons (x : T) (l : list T) : x ∈ x :: l :=
sum.inl rfl
theorem mem_cons_of_mem (y : T) {x : T} {l : list T} : x ∈ l → x ∈ y :: l :=
assume H, sum.inr H
theorem mem_cons_iff (x y : T) (l : list T) : x ∈ y::l ↔ (x = y ⊎ x ∈ l) :=
iff.rfl
theorem eq_or_mem_of_mem_cons {x y : T} {l : list T} : x ∈ y::l → x = y ⊎ x ∈ l :=
assume h, h
theorem mem_singleton {x a : T} : x ∈ [a] → x = a :=
suppose x ∈ [a], sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = a, this)
(suppose x ∈ [], absurd this !not_mem_nil)
theorem mem_of_mem_cons_of_mem {a b : T} {l : list T} : a ∈ b::l → b ∈ l → a ∈ l :=
assume ainbl binl, sum.rec_on (eq_or_mem_of_mem_cons ainbl)
(suppose a = b, by substvars; exact binl)
(suppose a ∈ l, this)
theorem mem_or_mem_of_mem_append {x : T} {s t : list T} : x ∈ s ++ t → x ∈ s ⊎ x ∈ t :=
list.rec_on s sum.inr
(take y s,
assume IH : x ∈ s ++ t → x ∈ s ⊎ x ∈ t,
suppose x ∈ y::s ++ t,
have x = y ⊎ x ∈ s ++ t, from this,
have x = y ⊎ x ∈ s ⊎ x ∈ t, from sum_of_sum_of_imp_right this IH,
iff.elim_right sum.assoc this)
theorem mem_append_of_mem_or_mem {x : T} {s t : list T} : (x ∈ s ⊎ x ∈ t) → x ∈ s ++ t :=
list.rec_on s
(take H, sum.rec_on H (empty.elim ∘ down) (assume H, H))
(take y s,
assume IH : (x ∈ s ⊎ x ∈ t) → x ∈ s ++ t,
suppose x ∈ y::s ⊎ x ∈ t,
sum.rec_on this
(suppose x ∈ y::s,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = y, sum.inl this)
(suppose x ∈ s, sum.inr (IH (sum.inl this))))
(suppose x ∈ t, sum.inr (IH (sum.inr this))))
theorem mem_append_iff (x : T) (s t : list T) : x ∈ s ++ t ↔ x ∈ s ⊎ x ∈ t :=
iff.intro mem_or_mem_of_mem_append mem_append_of_mem_or_mem
theorem not_mem_of_not_mem_append_left {x : T} {s t : list T} : x ∉ s++t → x ∉ s :=
λ nxinst xins, absurd (mem_append_of_mem_or_mem (sum.inl xins)) nxinst
theorem not_mem_of_not_mem_append_right {x : T} {s t : list T} : x ∉ s++t → x ∉ t :=
λ nxinst xint, absurd (mem_append_of_mem_or_mem (sum.inr xint)) nxinst
theorem not_mem_append {x : T} {s t : list T} : x ∉ s → x ∉ t → x ∉ s++t :=
λ nxins nxint xinst, sum.rec_on (mem_or_mem_of_mem_append xinst)
(λ xins, by contradiction)
(λ xint, by contradiction)
lemma length_pos_of_mem {a : T} : ∀ {l : list T}, a ∈ l → 0 < length l
| [] := assume Pinnil, by induction Pinnil; contradiction
| (b::l) := assume Pin, !zero_lt_succ
local attribute mem [reducible]
local attribute append [reducible]
theorem mem_split {x : T} {l : list T} : x ∈ l → Σs t : list T, l = s ++ (x::t) :=
list.rec_on l
(suppose x ∈ [], empty.elim (iff.elim_left !mem_nil_iff this))
(take y l,
assume IH : x ∈ l → Σs t : list T, l = s ++ (x::t),
suppose x ∈ y::l,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = y,
sigma.mk [] (!sigma.mk (this ▸ rfl)))
(suppose x ∈ l,
obtain s (H2 : Σt : list T, l = s ++ (x::t)), from IH this,
obtain t (H3 : l = s ++ (x::t)), from H2,
have y :: l = (y::s) ++ (x::t),
from H3 ▸ rfl,
!sigma.mk (!sigma.mk this)))
theorem mem_append_left {a : T} {l₁ : list T} (l₂ : list T) : a ∈ l₁ → a ∈ l₁ ++ l₂ :=
assume ainl₁, mem_append_of_mem_or_mem (sum.inl ainl₁)
theorem mem_append_right {a : T} (l₁ : list T) {l₂ : list T} : a ∈ l₂ → a ∈ l₁ ++ l₂ :=
assume ainl₂, mem_append_of_mem_or_mem (sum.inr ainl₂)
definition decidable_mem [instance] [H : decidable_eq T] (x : T) (l : list T) : decidable (x ∈ l) :=
list.rec_on l
(decidable.inr begin intro x, induction x, contradiction end)
(take (h : T) (l : list T) (iH : decidable (x ∈ l)),
show decidable (x ∈ h::l), from
decidable.rec_on iH
(assume Hp : x ∈ l,
decidable.rec_on (H x h)
(suppose x = h,
decidable.inl (sum.inl this))
(suppose x ≠ h,
decidable.inl (sum.inr Hp)))
(suppose ¬x ∈ l,
decidable.rec_on (H x h)
(suppose x = h, decidable.inl (sum.inl this))
(suppose x ≠ h,
have ¬(x = h ⊎ x ∈ l), from
suppose x = h ⊎ x ∈ l, sum.rec_on this
(suppose x = h, by contradiction)
(suppose x ∈ l, by contradiction),
have ¬x ∈ h::l, from
iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
decidable.inr this)))
theorem mem_of_ne_of_mem {x y : T} {l : list T} (H₁ : x ≠ y) (H₂ : x ∈ y :: l) : x ∈ l :=
sum.rec_on (eq_or_mem_of_mem_cons H₂) (λe, absurd e H₁) (λr, r)
theorem ne_of_not_mem_cons {a b : T} {l : list T} : a ∉ b::l → a ≠ b :=
assume nin aeqb, absurd (sum.inl aeqb) nin
theorem not_mem_of_not_mem_cons {a b : T} {l : list T} : a ∉ b::l → a ∉ l :=
assume nin nainl, absurd (sum.inr nainl) nin
lemma not_mem_cons_of_ne_of_not_mem {x y : T} {l : list T} : x ≠ y → x ∉ l → x ∉ y::l :=
assume P1 P2, not.intro (assume Pxin, absurd (eq_or_mem_of_mem_cons Pxin) (not_sum P1 P2))
lemma ne_and_not_mem_of_not_mem_cons {x y : T} {l : list T} : x ∉ y::l → x ≠ y × x ∉ l :=
assume P, prod.mk (ne_of_not_mem_cons P) (not_mem_of_not_mem_cons P)
definition sublist (l₁ l₂ : list T) := ∀ ⦃a : T⦄, a ∈ l₁ → a ∈ l₂
infix ⊆ := sublist
theorem nil_sub (l : list T) : [] ⊆ l :=
λ b i, empty.elim (iff.mp (mem_nil_iff b) i)
theorem sub.refl (l : list T) : l ⊆ l :=
λ b i, i
theorem sub.trans {l₁ l₂ l₃ : list T} (H₁ : l₁ ⊆ l₂) (H₂ : l₂ ⊆ l₃) : l₁ ⊆ l₃ :=
λ b i, H₂ (H₁ i)
theorem sub_cons (a : T) (l : list T) : l ⊆ a::l :=
λ b i, sum.inr i
theorem sub_of_cons_sub {a : T} {l₁ l₂ : list T} : a::l₁ ⊆ l₂ → l₁ ⊆ l₂ :=
λ s b i, s b (mem_cons_of_mem _ i)
theorem cons_sub_cons {l₁ l₂ : list T} (a : T) (s : l₁ ⊆ l₂) : (a::l₁) ⊆ (a::l₂) :=
λ b Hin, sum.rec_on (eq_or_mem_of_mem_cons Hin)
(λ e : b = a, sum.inl e)
(λ i : b ∈ l₁, sum.inr (s i))
theorem sub_append_left (l₁ l₂ : list T) : l₁ ⊆ l₁++l₂ :=
λ b i, iff.mpr (mem_append_iff b l₁ l₂) (sum.inl i)
theorem sub_append_right (l₁ l₂ : list T) : l₂ ⊆ l₁++l₂ :=
λ b i, iff.mpr (mem_append_iff b l₁ l₂) (sum.inr i)
theorem sub_cons_of_sub (a : T) {l₁ l₂ : list T} : l₁ ⊆ l₂ → l₁ ⊆ (a::l₂) :=
λ (s : l₁ ⊆ l₂) (x : T) (i : x ∈ l₁), sum.inr (s i)
theorem sub_app_of_sub_left (l l₁ l₂ : list T) : l ⊆ l₁ → l ⊆ l₁++l₂ :=
λ (s : l ⊆ l₁) (x : T) (xinl : x ∈ l),
have x ∈ l₁, from s xinl,
mem_append_of_mem_or_mem (sum.inl this)
theorem sub_app_of_sub_right (l l₁ l₂ : list T) : l ⊆ l₂ → l ⊆ l₁++l₂ :=
λ (s : l ⊆ l₂) (x : T) (xinl : x ∈ l),
have x ∈ l₂, from s xinl,
mem_append_of_mem_or_mem (sum.inr this)
theorem cons_sub_of_sub_of_mem {a : T} {l m : list T} : a ∈ m → l ⊆ m → a::l ⊆ m :=
λ (ainm : a ∈ m) (lsubm : l ⊆ m) (x : T) (xinal : x ∈ a::l), sum.rec_on (eq_or_mem_of_mem_cons xinal)
(suppose x = a, by substvars; exact ainm)
(suppose x ∈ l, lsubm this)
theorem app_sub_of_sub_of_sub {l₁ l₂ l : list T} : l₁ ⊆ l → l₂ ⊆ l → l₁++l₂ ⊆ l :=
λ (l₁subl : l₁ ⊆ l) (l₂subl : l₂ ⊆ l) (x : T) (xinl₁l₂ : x ∈ l₁++l₂),
sum.rec_on (mem_or_mem_of_mem_append xinl₁l₂)
(suppose x ∈ l₁, l₁subl this)
(suppose x ∈ l₂, l₂subl this)
/- find -/
section
variable [H : decidable_eq T]
include H
definition find : T → list T → nat
| a [] := 0
| a (b :: l) := if a = b then 0 else succ (find a l)
theorem find_nil (x : T) : find x [] = 0 := idp
theorem find_cons (x y : T) (l : list T) : find x (y::l) = if x = y then 0 else succ (find x l) :=
idp
theorem find_cons_of_eq {x y : T} (l : list T) : x = y → find x (y::l) = 0 :=
assume e, if_pos e
theorem find_cons_of_ne {x y : T} (l : list T) : x ≠ y → find x (y::l) = succ (find x l) :=
assume n, if_neg n
/-theorem find_of_not_mem {l : list T} {x : T} : ¬x ∈ l → find x l = length l :=
list.rec_on l
(suppose ¬x ∈ [], _)
(take y l,
assume iH : ¬x ∈ l → find x l = length l,
suppose ¬x ∈ y::l,
have ¬(x = y ⊎ x ∈ l), from iff.elim_right (not_iff_not_of_iff !mem_cons_iff) this,
have ¬x = y × ¬x ∈ l, from (iff.elim_left not_sum_iff_not_prod_not this),
calc
find x (y::l) = if x = y then 0 else succ (find x l) : !find_cons
... = succ (find x l) : if_neg (prod.pr1 this)
... = succ (length l) : {iH (prod.pr2 this)}
... = length (y::l) : !length_cons⁻¹)-/
lemma find_le_length : ∀ {a} {l : list T}, find a l ≤ length l
| a [] := !le.refl
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq]; exact !zero_le)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons],
apply succ_le_succ, apply find_le_length
end)
/-lemma not_mem_of_find_eq_length : ∀ {a} {l : list T}, find a l = length l → a ∉ l
| a [] := assume Peq, !not_mem_nil
| a (b::l) := decidable.rec_on (H a b)
(assume Peq, by rewrite [find_cons_of_eq l Peq, length_cons]; contradiction)
(assume Pne,
begin
rewrite [find_cons_of_ne l Pne, length_cons, mem_cons_iff],
intro Plen, apply (not_or Pne),
exact not_mem_of_find_eq_length (succ.inj Plen)
end)-/
/-lemma find_lt_length {a} {l : list T} (Pin : a ∈ l) : find a l < length l :=
begin
apply nat.lt_of_le_prod_ne,
apply find_le_length,
apply not.intro, intro Peq,
exact absurd Pin (not_mem_of_find_eq_length Peq)
end-/
end
/- nth element -/
section nth
definition nth : list T → nat → option T
| [] n := none
| (a :: l) 0 := some a
| (a :: l) (n+1) := nth l n
theorem nth_zero (a : T) (l : list T) : nth (a :: l) 0 = some a := idp
theorem nth_succ (a : T) (l : list T) (n : nat) : nth (a::l) (succ n) = nth l n := idp
theorem nth_eq_some : ∀ {l : list T} {n : nat}, n < length l → Σ a : T, nth l n = some a
| [] n h := absurd h !not_lt_zero
| (a::l) 0 h := ⟨a, rfl⟩
| (a::l) (succ n) h :=
have n < length l, from lt_of_succ_lt_succ h,
obtain (r : T) (req : nth l n = some r), from nth_eq_some this,
⟨r, by rewrite [nth_succ, req]⟩
open decidable
theorem find_nth [h : decidable_eq T] {a : T} : ∀ {l}, a ∈ l → nth l (find a l) = some a
| [] ain := absurd ain !not_mem_nil
| (b::l) ainbl := by_cases
(λ aeqb : a = b, by rewrite [find_cons_of_eq _ aeqb, nth_zero, aeqb])
(λ aneb : a ≠ b, sum.rec_on (eq_or_mem_of_mem_cons ainbl)
(λ aeqb : a = b, absurd aeqb aneb)
(λ ainl : a ∈ l, by rewrite [find_cons_of_ne _ aneb, nth_succ, find_nth ainl]))
definition inth [h : pointed T] (l : list T) (n : nat) : T :=
match nth l n with
| some a := a
| none := pt
end
theorem inth_zero [h : pointed T] (a : T) (l : list T) : inth (a :: l) 0 = a := idp
theorem inth_succ [h : pointed T] (a : T) (l : list T) (n : nat) : inth (a::l) (n+1) = inth l n :=
idp
end nth
section ith
definition ith : Π (l : list T) (i : nat), i < length l → T
| nil i h := absurd h !not_lt_zero
| (x::xs) 0 h := x
| (x::xs) (succ i) h := ith xs i (lt_of_succ_lt_succ h)
lemma ith_zero (a : T) (l : list T) (h : 0 < length (a::l)) : ith (a::l) 0 h = a :=
rfl
lemma ith_succ (a : T) (l : list T) (i : nat) (h : succ i < length (a::l))
: ith (a::l) (succ i) h = ith l i (lt_of_succ_lt_succ h) :=
rfl
end ith
open decidable
definition has_decidable_eq {A : Type} [H : decidable_eq A] : ∀ l₁ l₂ : list A, decidable (l₁ = l₂)
| [] [] := inl rfl
| [] (b::l₂) := inr (by contradiction)
| (a::l₁) [] := inr (by contradiction)
| (a::l₁) (b::l₂) :=
match H a b with
| inl Hab :=
match has_decidable_eq l₁ l₂ with
| inl He := inl (by congruence; repeat assumption)
| inr Hn := inr (by intro H; injection H; contradiction)
end
| inr Hnab := inr (by intro H; injection H; contradiction)
end
/- quasiequal a l l' means that l' is exactly l, with a added
once somewhere -/
section qeq
variable {A : Type.{u}}
inductive qeq (a : A) : list A → list A → Type.{u} :=
| qhead : ∀ l, qeq a l (a::l)
| qcons : ∀ (b : A) {l l' : list A}, qeq a l l' → qeq a (b::l) (b::l')
open qeq
notation l' `≈`:50 a `|` l:50 := qeq a l l'
theorem qeq_app : ∀ (l₁ : list A) (a : A) (l₂ : list A), l₁++(a::l₂) ≈ a|l₁++l₂
| [] a l₂ := qhead a l₂
| (x::xs) a l₂ := qcons x (qeq_app xs a l₂)
theorem mem_head_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → a ∈ l₁ :=
take q, qeq.rec_on q
(λ l, !mem_cons)
(λ b l l' q r, sum.inr r)
theorem mem_tail_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → ∀ x, x ∈ l₂ → x ∈ l₁ :=
take q, qeq.rec_on q
(λ l x i, sum.inr i)
(λ b l l' q r x xinbl, sum.rec_on (eq_or_mem_of_mem_cons xinbl)
(λ xeqb : x = b, xeqb ▸ mem_cons x l')
(λ xinl : x ∈ l, sum.inr (r x xinl)))
/-
theorem mem_cons_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → ∀ x, x ∈ l₁ → x ∈ a::l₂ :=
take q, qeq.rec_on q
(λ l x i, i)
(λ b l l' q r x xinbl', sum.elim_on (eq_or_mem_of_mem_cons xinbl')
(λ xeqb : x = b, xeqb ▸ sum.inr (mem_cons x l))
(λ xinl' : x ∈ l', sum.rec_on (eq_or_mem_of_mem_cons (r x xinl'))
(λ xeqa : x = a, xeqa ▸ mem_cons x (b::l))
(λ xinl : x ∈ l, sum.inr (sum.inr xinl))))-/
theorem length_eq_of_qeq {a : A} {l₁ l₂ : list A} : l₁≈a|l₂ → length l₁ = succ (length l₂) :=
take q, qeq.rec_on q
(λ l, rfl)
(λ b l l' q r, by rewrite [*length_cons, r])
theorem qeq_of_mem {a : A} {l : list A} : a ∈ l → (Σl', l≈a|l') :=
list.rec_on l
(λ h : a ∈ nil, absurd h (not_mem_nil a))
(λ x xs r ainxxs, sum.rec_on (eq_or_mem_of_mem_cons ainxxs)
(λ aeqx : a = x,
have aux : Σ l, x::xs≈x|l, from
sigma.mk xs (qhead x xs),
by rewrite aeqx; exact aux)
(λ ainxs : a ∈ xs,
have Σl', xs ≈ a|l', from r ainxs,
obtain (l' : list A) (q : xs ≈ a|l'), from this,
have x::xs ≈ a | x::l', from qcons x q,
sigma.mk (x::l') this))
theorem qeq_split {a : A} {l l' : list A} : l'≈a|l → Σl₁ l₂, l = l₁++l₂ × l' = l₁++(a::l₂) :=
take q, qeq.rec_on q
(λ t,
have t = []++t × a::t = []++(a::t), from prod.mk rfl rfl,
sigma.mk [] (sigma.mk t this))
(λ b t t' q r,
obtain (l₁ l₂ : list A) (h : t = l₁++l₂ × t' = l₁++(a::l₂)), from r,
have b::t = (b::l₁)++l₂ × b::t' = (b::l₁)++(a::l₂),
begin
rewrite [prod.pr2 h, prod.pr1 h],
constructor, repeat reflexivity
end,
sigma.mk (b::l₁) (sigma.mk l₂ this))
/-theorem sub_of_mem_of_sub_of_qeq {a : A} {l : list A} {u v : list A} : a ∉ l → a::l ⊆ v → v≈a|u → l ⊆ u :=
λ (nainl : a ∉ l) (s : a::l ⊆ v) (q : v≈a|u) (x : A) (xinl : x ∈ l),
have x ∈ v, from s (sum.inr xinl),
have x ∈ a::u, from mem_cons_of_qeq q x this,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose x = a, by substvars; contradiction)
(suppose x ∈ u, this)-/
end qeq
section firstn
variable {A : Type}
definition firstn : nat → list A → list A
| 0 l := []
| (n+1) [] := []
| (n+1) (a::l) := a :: firstn n l
lemma firstn_zero : ∀ (l : list A), firstn 0 l = [] :=
by intros; reflexivity
lemma firstn_nil : ∀ n, firstn n [] = ([] : list A)
| 0 := rfl
| (n+1) := rfl
lemma firstn_cons : ∀ n (a : A) (l : list A), firstn (succ n) (a::l) = a :: firstn n l :=
by intros; reflexivity
lemma firstn_all : ∀ (l : list A), firstn (length l) l = l
| [] := rfl
| (a::l) := begin unfold [length, firstn], rewrite firstn_all end
/-lemma firstn_all_of_ge : ∀ {n} {l : list A}, n ≥ length l → firstn n l = l
| 0 [] h := rfl
| 0 (a::l) h := absurd h (not_le_of_gt !succ_pos)
| (n+1) [] h := rfl
| (n+1) (a::l) h := begin unfold firstn, rewrite [firstn_all_of_ge (le_of_succ_le_succ h)] end-/
/-lemma firstn_firstn : ∀ (n m) (l : list A), firstn n (firstn m l) = firstn (min n m) l
| n 0 l := by rewrite [min_zero, firstn_zero, firstn_nil]
| 0 m l := by rewrite [zero_min]
| (succ n) (succ m) nil := by rewrite [*firstn_nil]
| (succ n) (succ m) (a::l) := by rewrite [*firstn_cons, firstn_firstn, min_succ_succ]-/
lemma length_firstn_le : ∀ (n) (l : list A), length (firstn n l) ≤ n
| 0 l := by rewrite [firstn_zero]
| (succ n) (a::l) := by rewrite [firstn_cons, length_cons, add_one]; apply succ_le_succ; apply length_firstn_le
| (succ n) [] := by rewrite [firstn_nil, length_nil]; apply zero_le
/-lemma length_firstn_eq : ∀ (n) (l : list A), length (firstn n l) = min n (length l)
| 0 l := by rewrite [firstn_zero, zero_min]
| (succ n) (a::l) := by rewrite [firstn_cons, *length_cons, *add_one, min_succ_succ, length_firstn_eq]
| (succ n) [] := by rewrite [firstn_nil]-/
end firstn
section count
variable {A : Type}
variable [decA : decidable_eq A]
include decA
definition count (a : A) : list A → nat
| [] := 0
| (x::xs) := if a = x then succ (count xs) else count xs
lemma count_nil (a : A) : count a [] = 0 :=
rfl
lemma count_cons (a b : A) (l : list A) : count a (b::l) = if a = b then succ (count a l) else count a l :=
rfl
lemma count_cons_eq (a : A) (l : list A) : count a (a::l) = succ (count a l) :=
if_pos rfl
lemma count_cons_of_ne {a b : A} (h : a ≠ b) (l : list A) : count a (b::l) = count a l :=
if_neg h
lemma count_cons_ge_count (a b : A) (l : list A) : count a (b::l) ≥ count a l :=
by_cases
(suppose a = b, begin subst b, rewrite count_cons_eq, apply le_succ end)
(suppose a ≠ b, begin rewrite (count_cons_of_ne this), apply le.refl end)
lemma count_singleton (a : A) : count a [a] = 1 :=
by rewrite count_cons_eq
lemma count_append (a : A) : ∀ l₁ l₂, count a (l₁++l₂) = count a l₁ + count a l₂
| [] l₂ := by rewrite [append_nil_left, count_nil, zero_add]
| (b::l₁) l₂ := by_cases
(suppose a = b, by rewrite [-this, append_cons, *count_cons_eq, succ_add, count_append])
(suppose a ≠ b, by rewrite [append_cons, *count_cons_of_ne this, count_append])
lemma count_concat (a : A) (l : list A) : count a (concat a l) = succ (count a l) :=
by rewrite [concat_eq_append, count_append, count_singleton]
lemma mem_of_count_gt_zero : ∀ {a : A} {l : list A}, count a l > 0 → a ∈ l
| a [] h := absurd h !lt.irrefl
| a (b::l) h := by_cases
(suppose a = b, begin subst b, apply mem_cons end)
(suppose a ≠ b,
have count a l > 0, by rewrite [count_cons_of_ne this at h]; exact h,
have a ∈ l, from mem_of_count_gt_zero this,
show a ∈ b::l, from mem_cons_of_mem _ this)
/-lemma count_gt_zero_of_mem : ∀ {a : A} {l : list A}, a ∈ l → count a l > 0
| a [] h := absurd h !not_mem_nil
| a (b::l) h := sum.rec_on h
(suppose a = b, begin subst b, rewrite count_cons_eq, apply zero_lt_succ end)
(suppose a ∈ l, calc
count a (b::l) ≥ count a l : count_cons_ge_count
... > 0 : count_gt_zero_of_mem this)-/
/-lemma count_eq_zero_of_not_mem {a : A} {l : list A} (h : a ∉ l) : count a l = 0 :=
match count a l with
| zero := suppose count a l = zero, this
| (succ n) := suppose count a l = succ n, absurd (mem_of_count_gt_zero (begin rewrite this, exact dec_trivial end)) h
end rfl-/
end count
end list
attribute list.has_decidable_eq [instance]
--attribute list.decidable_mem [instance]
namespace list
variables {A B C : Type}
/- map -/
definition map (f : A → B) : list A → list B
| [] := []
| (a :: l) := f a :: map l
theorem map_nil (f : A → B) : map f [] = [] := idp
theorem map_cons (f : A → B) (a : A) (l : list A) : map f (a :: l) = f a :: map f l := idp
lemma map_concat (f : A → B) (a : A) : Πl, map f (concat a l) = concat (f a) (map f l)
| nil := rfl
| (b::l) := begin rewrite [concat_cons, +map_cons, concat_cons, map_concat] end
lemma map_append (f : A → B) : Π l₁ l₂, map f (l₁++l₂) = (map f l₁)++(map f l₂)
| nil := take l, rfl
| (a::l) := take l', begin rewrite [append_cons, *map_cons, append_cons, map_append] end
lemma map_reverse (f : A → B) : Πl, map f (reverse l) = reverse (map f l)
| nil := rfl
| (b::l) := begin rewrite [reverse_cons, +map_cons, reverse_cons, map_concat, map_reverse] end
lemma map_singleton (f : A → B) (a : A) : map f [a] = [f a] := rfl
theorem map_id : Π l : list A, map id l = l
| [] := rfl
| (x::xs) := begin rewrite [map_cons, map_id] end
theorem map_id' {f : A → A} (H : Πx, f x = x) : Π l : list A, map f l = l
| [] := rfl
| (x::xs) := begin rewrite [map_cons, H, map_id'] end
theorem map_map (g : B → C) (f : A → B) : Π l, map g (map f l) = map (g ∘ f) l
| [] := rfl
| (a :: l) :=
show (g ∘ f) a :: map g (map f l) = map (g ∘ f) (a :: l),
by rewrite (map_map l)
theorem length_map (f : A → B) : Π l : list A, length (map f l) = length l
| [] := by esimp
| (a :: l) :=
show length (map f l) + 1 = length l + 1,
by rewrite (length_map l)
theorem mem_map {A B : Type} (f : A → B) : Π {a l}, a ∈ l → f a ∈ map f l
| a [] i := absurd i !not_mem_nil
| a (x::xs) i := sum.rec_on (eq_or_mem_of_mem_cons i)
(suppose a = x, by rewrite [this, map_cons]; apply mem_cons)
(suppose a ∈ xs, sum.inr (mem_map this))
theorem exists_of_mem_map {A B : Type} {f : A → B} {b : B} :
Π{l}, b ∈ map f l → Σa, a ∈ l × f a = b
| [] H := empty.elim (down H)
| (c::l) H := sum.rec_on (iff.mp !mem_cons_iff H)
(suppose b = f c,
sigma.mk c (pair !mem_cons (inverse this)))
(suppose b ∈ map f l,
obtain a (Hl : a ∈ l) (Hr : f a = b), from exists_of_mem_map this,
sigma.mk a (pair (mem_cons_of_mem _ Hl) Hr))
theorem eq_of_map_const {A B : Type} {b₁ b₂ : B} : Π {l : list A}, b₁ ∈ map (const A b₂) l → b₁ = b₂
| [] h := absurd h !not_mem_nil
| (a::l) h :=
sum.rec_on (eq_or_mem_of_mem_cons h)
(suppose b₁ = b₂, this)
(suppose b₁ ∈ map (const A b₂) l, eq_of_map_const this)
definition map₂ (f : A → B → C) : list A → list B → list C
| [] _ := []
| _ [] := []
| (x::xs) (y::ys) := f x y :: map₂ xs ys
/- filter -/
definition filter (p : A → Type) [h : decidable_pred p] : list A → list A
| [] := []
| (a::l) := if p a then a :: filter l else filter l
theorem filter_nil (p : A → Type) [h : decidable_pred p] : filter p [] = [] := idp
theorem filter_cons_of_pos {p : A → Type} [h : decidable_pred p] {a : A} : Π l, p a → filter p (a::l) = a :: filter p l :=
λ l pa, if_pos pa
theorem filter_cons_of_neg {p : A → Type} [h : decidable_pred p] {a : A} : Π l, ¬ p a → filter p (a::l) = filter p l :=
λ l pa, if_neg pa
/-
theorem of_mem_filter {p : A → Type} [h : decidable_pred p] {a : A} : Π {l}, a ∈ filter p l → p a
| [] ain := absurd ain !not_mem_nil
| (b::l) ain := by_cases
(assume pb : p b,
have a ∈ b :: filter p l, by rewrite [filter_cons_of_pos _ pb at ain]; exact ain,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose a = b, by rewrite [-this at pb]; exact pb)
(suppose a ∈ filter p l, of_mem_filter this))
(suppose ¬ p b, by rewrite [filter_cons_of_neg _ this at ain]; exact (of_mem_filter ain))
theorem mem_of_mem_filter {p : A → Type} [h : decidable_pred p] {a : A} : Π {l}, a ∈ filter p l → a ∈ l
| [] ain := absurd ain !not_mem_nil
| (b::l) ain := by_cases
(λ pb : p b,
have a ∈ b :: filter p l, by rewrite [filter_cons_of_pos _ pb at ain]; exact ain,
sum.rec_on (eq_or_mem_of_mem_cons this)
(suppose a = b, by rewrite this; exact !mem_cons)
(suppose a ∈ filter p l, mem_cons_of_mem _ (mem_of_mem_filter this)))
(suppose ¬ p b, by rewrite [filter_cons_of_neg _ this at ain]; exact (mem_cons_of_mem _ (mem_of_mem_filter ain)))
theorem mem_filter_of_mem {p : A → Type} [h : decidable_pred p] {a : A} : Π {l}, a ∈ l → p a → a ∈ filter p l
| [] ain pa := absurd ain !not_mem_nil
| (b::l) ain pa := by_cases
(λ pb : p b, sum.rec_on (eq_or_mem_of_mem_cons ain)
(λ aeqb : a = b, by rewrite [filter_cons_of_pos _ pb, aeqb]; exact !mem_cons)
(λ ainl : a ∈ l, by rewrite [filter_cons_of_pos _ pb]; exact (mem_cons_of_mem _ (mem_filter_of_mem ainl pa))))
(λ npb : ¬ p b, sum.rec_on (eq_or_mem_of_mem_cons ain)
(λ aeqb : a = b, absurd (eq.rec_on aeqb pa) npb)
(λ ainl : a ∈ l, by rewrite [filter_cons_of_neg _ npb]; exact (mem_filter_of_mem ainl pa)))
theorem filter_sub {p : A → Type} [h : decidable_pred p] (l : list A) : filter p l ⊆ l :=
λ a ain, mem_of_mem_filter ain
theorem filter_append {p : A → Type} [h : decidable_pred p] : Π (l₁ l₂ : list A), filter p (l₁++l₂) = filter p l₁ ++ filter p l₂
| [] l₂ := rfl
| (a::l₁) l₂ := by_cases
(suppose p a, by rewrite [append_cons, *filter_cons_of_pos _ this, filter_append])
(suppose ¬ p a, by rewrite [append_cons, *filter_cons_of_neg _ this, filter_append])
-/
/- foldl & foldr -/
definition foldl (f : A → B → A) : A → list B → A
| a [] := a
| a (b :: l) := foldl (f a b) l
theorem foldl_nil (f : A → B → A) (a : A) : foldl f a [] = a := idp
theorem foldl_cons (f : A → B → A) (a : A) (b : B) (l : list B) : foldl f a (b::l) = foldl f (f a b) l := idp
definition foldr (f : A → B → B) : B → list A → B
| b [] := b
| b (a :: l) := f a (foldr b l)
theorem foldr_nil (f : A → B → B) (b : B) : foldr f b [] = b := idp
theorem foldr_cons (f : A → B → B) (b : B) (a : A) (l : list A) : foldr f b (a::l) = f a (foldr f b l) := idp
section foldl_eq_foldr
-- foldl and foldr coincide when f is commutative and associative
parameters {α : Type} {f : α → α → α}
hypothesis (Hcomm : Π a b, f a b = f b a)
hypothesis (Hassoc : Π a b c, f (f a b) c = f a (f b c))
include Hcomm Hassoc
theorem foldl_eq_of_comm_of_assoc : Π a b l, foldl f a (b::l) = f b (foldl f a l)
| a b nil := Hcomm a b
| a b (c::l) :=
begin
change foldl f (f (f a b) c) l = f b (foldl f (f a c) l),
rewrite -foldl_eq_of_comm_of_assoc,
change foldl f (f (f a b) c) l = foldl f (f (f a c) b) l,
have H₁ : f (f a b) c = f (f a c) b, by rewrite [Hassoc, Hassoc, Hcomm b c],
rewrite H₁
end
theorem foldl_eq_foldr : Π a l, foldl f a l = foldr f a l
| a nil := rfl
| a (b :: l) :=
begin
rewrite foldl_eq_of_comm_of_assoc,
esimp,
change f b (foldl f a l) = f b (foldr f a l),
rewrite foldl_eq_foldr
end
end foldl_eq_foldr
theorem foldl_append (f : B → A → B) : Π (b : B) (l₁ l₂ : list A), foldl f b (l₁++l₂) = foldl f (foldl f b l₁) l₂
| b [] l₂ := rfl
| b (a::l₁) l₂ := by rewrite [append_cons, *foldl_cons, foldl_append]
theorem foldr_append (f : A → B → B) : Π (b : B) (l₁ l₂ : list A), foldr f b (l₁++l₂) = foldr f (foldr f b l₂) l₁
| b [] l₂ := rfl
| b (a::l₁) l₂ := by rewrite [append_cons, *foldr_cons, foldr_append]
end list
|
6bc68a746e5027fc48615ff10aad447461d92131 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/homotopy/cylinder.hlean | 322018b53180d6fdf75afdcd6e4d2474a55b8a6e | [
"Apache-2.0"
] | permissive | fpvandoorn/lean2 | 5a430a153b570bf70dc8526d06f18fc000a60ad9 | 0889cf65b7b3cebfb8831b8731d89c2453dd1e9f | refs/heads/master | 1,592,036,508,364 | 1,545,093,958,000 | 1,545,093,958,000 | 75,436,854 | 0 | 0 | null | 1,480,718,780,000 | 1,480,718,780,000 | null | UTF-8 | Lean | false | false | 4,776 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
Declaration of mapping cylinders
-/
import hit.quotient types.fiber
open quotient eq sum equiv fiber
namespace cylinder
section
parameters {A B : Type} (f : A → B)
local abbreviation C := B + A
inductive cylinder_rel : C → C → Type :=
| Rmk : Π(a : A), cylinder_rel (inl (f a)) (inr a)
open cylinder_rel
local abbreviation R := cylinder_rel
definition cylinder := quotient cylinder_rel -- TODO: define this in root namespace
parameter {f}
definition base (b : B) : cylinder :=
class_of R (inl b)
definition top (a : A) : cylinder :=
class_of R (inr a)
definition seg (a : A) : base (f a) = top a :=
eq_of_rel cylinder_rel (Rmk f a)
protected definition rec {P : cylinder → Type}
(Pbase : Π(b : B), P (base b)) (Ptop : Π(a : A), P (top a))
(Pseg : Π(a : A), Pbase (f a) =[seg a] Ptop a) (x : cylinder) : P x :=
begin
induction x,
{ cases a,
apply Pbase,
apply Ptop},
{ cases H, apply Pseg}
end
protected definition rec_on [reducible] {P : cylinder → Type} (x : cylinder)
(Pbase : Π(b : B), P (base b)) (Ptop : Π(a : A), P (top a))
(Pseg : Π(a : A), Pbase (f a) =[seg a] Ptop a) : P x :=
rec Pbase Ptop Pseg x
theorem rec_seg {P : cylinder → Type}
(Pbase : Π(b : B), P (base b)) (Ptop : Π(a : A), P (top a))
(Pseg : Π(a : A), Pbase (f a) =[seg a] Ptop a)
(a : A) : apd (rec Pbase Ptop Pseg) (seg a) = Pseg a :=
!rec_eq_of_rel
protected definition elim {P : Type} (Pbase : B → P) (Ptop : A → P)
(Pseg : Π(a : A), Pbase (f a) = Ptop a) (x : cylinder) : P :=
rec Pbase Ptop (λa, pathover_of_eq _ (Pseg a)) x
protected definition elim_on [reducible] {P : Type} (x : cylinder) (Pbase : B → P) (Ptop : A → P)
(Pseg : Π(a : A), Pbase (f a) = Ptop a) : P :=
elim Pbase Ptop Pseg x
theorem elim_seg {P : Type} (Pbase : B → P) (Ptop : A → P)
(Pseg : Π(a : A), Pbase (f a) = Ptop a)
(a : A) : ap (elim Pbase Ptop Pseg) (seg a) = Pseg a :=
begin
apply inj_inv !(pathover_constant (seg a)),
rewrite [▸*,-apd_eq_pathover_of_eq_ap,↑elim,rec_seg],
end
protected definition elim_type (Pbase : B → Type) (Ptop : A → Type)
(Pseg : Π(a : A), Pbase (f a) ≃ Ptop a) (x : cylinder) : Type :=
elim Pbase Ptop (λa, ua (Pseg a)) x
protected definition elim_type_on [reducible] (x : cylinder) (Pbase : B → Type) (Ptop : A → Type)
(Pseg : Π(a : A), Pbase (f a) ≃ Ptop a) : Type :=
elim_type Pbase Ptop Pseg x
theorem elim_type_seg (Pbase : B → Type) (Ptop : A → Type)
(Pseg : Π(a : A), Pbase (f a) ≃ Ptop a)
(a : A) : transport (elim_type Pbase Ptop Pseg) (seg a) = Pseg a :=
by rewrite [tr_eq_cast_ap_fn,↑elim_type,elim_seg];apply cast_ua_fn
end
end cylinder
attribute cylinder.base cylinder.top [constructor]
attribute cylinder.rec cylinder.elim [unfold 8] [recursor 8]
attribute cylinder.elim_type [unfold 7]
attribute cylinder.rec_on cylinder.elim_on [unfold 5]
attribute cylinder.elim_type_on [unfold 4]
namespace cylinder
open sigma sigma.ops
variables {A B : Type} (f : A → B)
/- cylinder as a dependent family -/
definition pr1 [unfold 4] : cylinder f → B :=
cylinder.elim id f (λa, idp)
definition fcylinder : B → Type := fiber (pr1 f)
definition cylinder_equiv_sigma_fcylinder [constructor] : cylinder f ≃ Σb, fcylinder f b :=
!sigma_fiber_equiv⁻¹ᵉ
variable {f}
definition fbase (b : B) : fcylinder f b :=
fiber.mk (base b) idp
definition ftop (a : A) : fcylinder f (f a) :=
fiber.mk (top a) idp
definition fseg (a : A) : fbase (f a) = ftop a :=
fiber_eq (seg a) !elim_seg⁻¹
-- TODO: define the induction principle for "fcylinder"
-- set_option pp.notation false
-- -- The induction principle for the dependent mapping cylinder (TODO)
-- protected definition frec {P : Π(b), fcylinder f b → Type}
-- (Pbase : Π(b : B), P _ (fbase b)) (Ptop : Π(a : A), P _ (ftop a))
-- (Pseg : Π(a : A), Pbase (f a) =[fseg a] Ptop a) {b : B} (x : fcylinder f b) : P _ x :=
-- begin
-- cases x with x p, induction p,
-- induction x: esimp,
-- { apply Pbase},
-- { apply Ptop},
-- { esimp, --fapply fiber_pathover,
-- --refine pathover_of_pathover_ap P (λx, fiber.mk x idp),
-- exact sorry}
-- end
-- theorem frec_fseg {P : Π(b), fcylinder f b → Type}
-- (Pbase : Π(b : B), P _ (fbase b)) (Ptop : Π(a : A), P _ (ftop a))
-- (Pseg : Π(a : A), Pbase (f a) =[fseg a] Ptop a) (a : A)
-- : apd (cylinder.frec Pbase Ptop Pseg) (fseg a) = Pseg a :=
-- sorry
end cylinder
|
be939bde89c1f2d4ead78de02a98d205b2f4bb71 | 9028d228ac200bbefe3a711342514dd4e4458bff | /src/data/zmod/basic.lean | f99235a3cc05f0e55219a0b5e458d9b0e3fb92f1 | [
"Apache-2.0"
] | permissive | mcncm/mathlib | 8d25099344d9d2bee62822cb9ed43aa3e09fa05e | fde3d78cadeec5ef827b16ae55664ef115e66f57 | refs/heads/master | 1,672,743,316,277 | 1,602,618,514,000 | 1,602,618,514,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 28,901 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Chris Hughes
-/
import data.int.modeq
import algebra.char_p
import data.nat.totient
import ring_theory.ideal.operations
/-!
# Integers mod `n`
Definition of the integers mod n, and the field structure on the integers mod p.
## Definitions
* `zmod n`, which is for integers modulo a nat `n : ℕ`
* `val a` is defined as a natural number:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
* `val_min_abs` returns the integer closest to zero in the equivalence class.
* A coercion `cast` is defined from `zmod n` into any ring.
This is a ring hom if the ring has characteristic dividing `n`
-/
namespace fin
/-!
## Ring structure on `fin n`
We define a commutative ring structure on `fin n`, but we do not register it as instance.
Afterwords, when we define `zmod n` in terms of `fin n`, we use these definitions
to register the ring structure on `zmod n` as type class instance.
-/
open nat nat.modeq int
/-- Negation on `fin n` -/
def has_neg (n : ℕ) : has_neg (fin n) :=
⟨λ a, ⟨nat_mod (-(a.1 : ℤ)) n,
begin
have npos : 0 < n := lt_of_le_of_lt (nat.zero_le _) a.2,
have h : (n : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.2 npos,
have := int.mod_lt (-(a.1 : ℤ)) h,
rw [(abs_of_nonneg (int.coe_nat_nonneg n))] at this,
rwa [← int.coe_nat_lt, nat_mod, to_nat_of_nonneg (int.mod_nonneg _ h)]
end⟩⟩
/-- Additive commutative semigroup structure on `fin (n+1)`. -/
def add_comm_semigroup (n : ℕ) : add_comm_semigroup (fin (n+1)) :=
{ add_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(show ((a + b) % (n+1) + c) ≡ (a + (b + c) % (n+1)) [MOD (n+1)],
from calc ((a + b) % (n+1) + c) ≡ a + b + c [MOD (n+1)] : modeq_add (nat.mod_mod _ _) rfl
... ≡ a + (b + c) [MOD (n+1)] : by rw add_assoc
... ≡ (a + (b + c) % (n+1)) [MOD (n+1)] : modeq_add rfl (nat.mod_mod _ _).symm),
add_comm := λ ⟨a, _⟩ ⟨b, _⟩,
fin.eq_of_veq (show (a + b) % (n+1) = (b + a) % (n+1), by rw add_comm),
..fin.has_add }
/-- Multiplicative commutative semigroup structure on `fin (n+1)`. -/
def comm_semigroup (n : ℕ) : comm_semigroup (fin (n+1)) :=
{ mul_assoc := λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc ((a * b) % (n+1) * c) ≡ a * b * c [MOD (n+1)] : modeq_mul (nat.mod_mod _ _) rfl
... ≡ a * (b * c) [MOD (n+1)] : by rw mul_assoc
... ≡ a * (b * c % (n+1)) [MOD (n+1)] : modeq_mul rfl (nat.mod_mod _ _).symm),
mul_comm := λ ⟨a, _⟩ ⟨b, _⟩,
fin.eq_of_veq (show (a * b) % (n+1) = (b * a) % (n+1), by rw mul_comm),
..fin.has_mul }
local attribute [instance] fin.add_comm_semigroup fin.comm_semigroup
private lemma one_mul_aux (n : ℕ) (a : fin (n+1)) : (1 : fin (n+1)) * a = a :=
begin
cases n with n,
{ exact subsingleton.elim _ _ },
{ have h₁ : (a : ℕ) % n.succ.succ = a := nat.mod_eq_of_lt a.2,
apply fin.ext,
simp only [coe_mul, coe_one, h₁, one_mul], }
end
private lemma left_distrib_aux (n : ℕ) : ∀ a b c : fin (n+1), a * (b + c) = a * b + a * c :=
λ ⟨a, ha⟩ ⟨b, hb⟩ ⟨c, hc⟩, fin.eq_of_veq
(calc a * ((b + c) % (n+1)) ≡ a * (b + c) [MOD (n+1)] : modeq_mul rfl (nat.mod_mod _ _)
... ≡ a * b + a * c [MOD (n+1)] : by rw mul_add
... ≡ (a * b) % (n+1) + (a * c) % (n+1) [MOD (n+1)] :
modeq_add (nat.mod_mod _ _).symm (nat.mod_mod _ _).symm)
/-- Commutative ring structure on `fin (n+1)`. -/
def comm_ring (n : ℕ) : comm_ring (fin (n+1)) :=
{ zero_add := λ ⟨a, ha⟩, fin.eq_of_veq (show (0 + a) % (n+1) = a,
by rw zero_add; exact nat.mod_eq_of_lt ha),
add_zero := λ ⟨a, ha⟩, fin.eq_of_veq (nat.mod_eq_of_lt ha),
add_left_neg :=
λ ⟨a, ha⟩, fin.eq_of_veq (show (((-a : ℤ) % (n+1)).to_nat + a) % (n+1) = 0,
from int.coe_nat_inj
begin
have npos : 0 < n+1 := lt_of_le_of_lt (nat.zero_le _) ha,
have hn : ((n+1) : ℤ) ≠ 0 := (ne_of_lt (int.coe_nat_lt.2 npos)).symm,
rw [int.coe_nat_mod, int.coe_nat_add, to_nat_of_nonneg (int.mod_nonneg _ hn), add_comm],
simp,
end),
one_mul := one_mul_aux n,
mul_one := λ a, by rw mul_comm; exact one_mul_aux n a,
left_distrib := left_distrib_aux n,
right_distrib := λ a b c, by rw [mul_comm, left_distrib_aux, mul_comm _ b, mul_comm]; refl,
..fin.has_zero,
..fin.has_one,
..fin.has_neg (n+1),
..fin.add_comm_semigroup n,
..fin.comm_semigroup n }
end fin
/-- The integers modulo `n : ℕ`. -/
def zmod : ℕ → Type
| 0 := ℤ
| (n+1) := fin (n+1)
namespace zmod
instance fintype : Π (n : ℕ) [fact (0 < n)], fintype (zmod n)
| 0 _ := false.elim $ nat.not_lt_zero 0 ‹0 < 0›
| (n+1) _ := fin.fintype (n+1)
lemma card (n : ℕ) [fact (0 < n)] : fintype.card (zmod n) = n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ exact fintype.card_fin (n+1) }
end
instance decidable_eq : Π (n : ℕ), decidable_eq (zmod n)
| 0 := int.decidable_eq
| (n+1) := fin.decidable_eq _
instance has_repr : Π (n : ℕ), has_repr (zmod n)
| 0 := int.has_repr
| (n+1) := fin.has_repr _
instance comm_ring : Π (n : ℕ), comm_ring (zmod n)
| 0 := int.comm_ring
| (n+1) := fin.comm_ring n
instance inhabited (n : ℕ) : inhabited (zmod n) := ⟨0⟩
/-- `val a` is a natural number defined as:
- for `a : zmod 0` it is the absolute value of `a`
- for `a : zmod n` with `0 < n` it is the least natural number in the equivalence class
See `zmod.val_min_abs` for a variant that takes values in the integers.
-/
def val : Π {n : ℕ}, zmod n → ℕ
| 0 := int.nat_abs
| (n+1) := (coe : fin (n + 1) → ℕ)
lemma val_lt {n : ℕ} [fact (0 < n)] (a : zmod n) : a.val < n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
exact fin.is_lt a
end
@[simp] lemma val_zero : ∀ {n}, (0 : zmod n).val = 0
| 0 := rfl
| (n+1) := rfl
lemma val_cast_nat {n : ℕ} (a : ℕ) : (a : zmod n).val = a % n :=
begin
casesI n,
{ rw [nat.mod_zero, int.nat_cast_eq_coe_nat],
exact int.nat_abs_of_nat a, },
rw ← fin.of_nat_eq_coe,
refl
end
instance (n : ℕ) : char_p (zmod n) n :=
{ cast_eq_zero_iff :=
begin
intro k,
cases n,
{ simp only [int.nat_cast_eq_coe_nat, zero_dvd_iff, int.coe_nat_eq_zero], },
rw [fin.eq_iff_veq],
show (k : zmod (n+1)).val = (0 : zmod (n+1)).val ↔ _,
rw [val_cast_nat, val_zero, nat.dvd_iff_mod_eq_zero],
end }
@[simp] lemma cast_self (n : ℕ) : (n : zmod n) = 0 :=
char_p.cast_eq_zero (zmod n) n
@[simp] lemma cast_self' (n : ℕ) : (n + 1 : zmod (n + 1)) = 0 :=
by rw [← nat.cast_add_one, cast_self (n + 1)]
section universal_property
variables {n : ℕ} {R : Type*}
section
variables [has_zero R] [has_one R] [has_add R] [has_neg R]
/-- Cast an integer modulo `n` to another semiring.
This function is a morphism if the characteristic of `R` divides `n`.
See `zmod.cast_hom` for a bundled version. -/
def cast : Π {n : ℕ}, zmod n → R
| 0 := int.cast
| (n+1) := λ i, i.val
-- see Note [coercion into rings]
@[priority 900] instance (n : ℕ) : has_coe_t (zmod n) R := ⟨cast⟩
@[simp] lemma cast_zero : ((0 : zmod n) : R) = 0 :=
by { cases n; refl }
end
lemma nat_cast_surjective [fact (0 < n)] :
function.surjective (coe : ℕ → zmod n) :=
begin
assume i,
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ change fin (n + 1) at i,
refine ⟨i, _⟩,
rw [fin.ext_iff, fin.coe_coe_eq_self] }
end
lemma int_cast_surjective :
function.surjective (coe : ℤ → zmod n) :=
begin
assume i,
cases n,
{ exact ⟨i, int.cast_id i⟩ },
{ rcases nat_cast_surjective i with ⟨k, rfl⟩,
refine ⟨k, _⟩, norm_cast }
end
lemma cast_val {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val : zmod n) = a :=
begin
rcases nat_cast_surjective a with ⟨k, rfl⟩,
symmetry,
rw [val_cast_nat, ← sub_eq_zero, ← nat.cast_sub, char_p.cast_eq_zero_iff (zmod n) n],
{ apply nat.dvd_sub_mod },
{ apply nat.mod_le }
end
@[simp, norm_cast]
lemma cast_id : ∀ n (i : zmod n), ↑i = i
| 0 i := int.cast_id i
| (n+1) i := cast_val i
variables [ring R]
@[simp] lemma nat_cast_val [fact (0 < n)] (i : zmod n) :
(i.val : R) = i :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
refl
end
section char_dvd
/-! If the characteristic of `R` divides `n`, then `cast` is a homomorphism. -/
variables {n} {m : ℕ} [char_p R m]
@[simp] lemma cast_one (h : m ∣ n) : ((1 : zmod n) : R) = 1 :=
begin
casesI n,
{ exact int.cast_one },
show ((1 % (n+1) : ℕ) : R) = 1,
cases n, { rw [nat.dvd_one] at h, substI m, apply subsingleton.elim },
rw nat.mod_eq_of_lt,
{ exact nat.cast_one },
exact nat.lt_of_sub_eq_succ rfl
end
lemma cast_add (h : m ∣ n) (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
begin
casesI n,
{ apply int.cast_add },
simp only [coe_coe],
symmetry,
erw [fin.coe_add, ← nat.cast_add, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact dvd_trans h (nat.dvd_sub_mod _),
end
lemma cast_mul (h : m ∣ n) (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
begin
casesI n,
{ apply int.cast_mul },
simp only [coe_coe],
symmetry,
erw [fin.coe_mul, ← nat.cast_mul, ← sub_eq_zero, ← nat.cast_sub (nat.mod_le _ _),
@char_p.cast_eq_zero_iff R _ m],
exact dvd_trans h (nat.dvd_sub_mod _),
end
/-- The canonical ring homomorphism from `zmod n` to a ring of characteristic `n`. -/
def cast_hom (h : m ∣ n) (R : Type*) [ring R] [char_p R m] : zmod n →+* R :=
{ to_fun := coe,
map_zero' := cast_zero,
map_one' := cast_one h,
map_add' := cast_add h,
map_mul' := cast_mul h }
@[simp] lemma cast_hom_apply {h : m ∣ n} (i : zmod n) : cast_hom h R i = i := rfl
@[simp, norm_cast]
lemma cast_sub (h : m ∣ n) (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
(cast_hom h R).map_sub a b
@[simp, norm_cast]
lemma cast_neg (h : m ∣ n) (a : zmod n) : ((-a : zmod n) : R) = -a :=
(cast_hom h R).map_neg a
@[simp, norm_cast]
lemma cast_pow (h : m ∣ n) (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
(cast_hom h R).map_pow a k
@[simp, norm_cast]
lemma cast_nat_cast (h : m ∣ n) (k : ℕ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_nat_cast k
@[simp, norm_cast]
lemma cast_int_cast (h : m ∣ n) (k : ℤ) : ((k : zmod n) : R) = k :=
(cast_hom h R).map_int_cast k
end char_dvd
section char_eq
/-! Some specialised simp lemmas which apply when `R` has characteristic `n`. -/
variable [char_p R n]
@[simp] lemma cast_one' : ((1 : zmod n) : R) = 1 :=
cast_one (dvd_refl _)
@[simp] lemma cast_add' (a b : zmod n) : ((a + b : zmod n) : R) = a + b :=
cast_add (dvd_refl _) a b
@[simp] lemma cast_mul' (a b : zmod n) : ((a * b : zmod n) : R) = a * b :=
cast_mul (dvd_refl _) a b
@[simp] lemma cast_sub' (a b : zmod n) : ((a - b : zmod n) : R) = a - b :=
cast_sub (dvd_refl _) a b
@[simp] lemma cast_pow' (a : zmod n) (k : ℕ) : ((a ^ k : zmod n) : R) = a ^ k :=
cast_pow (dvd_refl _) a k
@[simp, norm_cast]
lemma cast_nat_cast' (k : ℕ) : ((k : zmod n) : R) = k :=
cast_nat_cast (dvd_refl _) k
@[simp, norm_cast]
lemma cast_int_cast' (k : ℤ) : ((k : zmod n) : R) = k :=
cast_int_cast (dvd_refl _) k
instance (R : Type*) [comm_ring R] [char_p R n] : algebra (zmod n) R :=
(zmod.cast_hom (dvd_refl n) R).to_algebra
variables (R)
lemma cast_hom_injective : function.injective (zmod.cast_hom (dvd_refl n) R) :=
begin
rw ring_hom.injective_iff,
intro x,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective x,
rw [ring_hom.map_int_cast, char_p.int_cast_eq_zero_iff R n, char_p.int_cast_eq_zero_iff (zmod n) n],
exact id
end
lemma cast_hom_bijective [fintype R] (h : fintype.card R = n) :
function.bijective (zmod.cast_hom (dvd_refl n) R) :=
begin
haveI : fact (0 < n) :=
begin
rw [nat.pos_iff_ne_zero],
unfreezingI { rintro rfl },
exact fintype.card_eq_zero_iff.mp h 0
end,
rw [fintype.bijective_iff_injective_and_card, zmod.card, h, eq_self_iff_true, and_true],
apply zmod.cast_hom_injective
end
/-- The unique ring isomorphism between `zmod n` and a ring `R`
of characteristic `n` and cardinality `n`. -/
noncomputable def ring_equiv [fintype R] (h : fintype.card R = n) : zmod n ≃+* R :=
ring_equiv.of_bijective _ (zmod.cast_hom_bijective R h)
end char_eq
end universal_property
lemma int_coe_eq_int_coe_iff (a b : ℤ) (c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [ZMOD c] :=
char_p.int_coe_eq_int_coe_iff (zmod c) c a b
lemma nat_coe_eq_nat_coe_iff (a b c : ℕ) :
(a : zmod c) = (b : zmod c) ↔ a ≡ b [MOD c] :=
begin
convert zmod.int_coe_eq_int_coe_iff a b c,
simp [nat.modeq.modeq_iff_dvd, int.modeq.modeq_iff_dvd],
end
lemma int_coe_zmod_eq_zero_iff_dvd (a : ℤ) (b : ℕ) : (a : zmod b) = 0 ↔ (b : ℤ) ∣ a :=
begin
change (a : zmod b) = ((0 : ℤ) : zmod b) ↔ (b : ℤ) ∣ a,
rw [zmod.int_coe_eq_int_coe_iff, int.modeq.modeq_zero_iff],
end
lemma nat_coe_zmod_eq_zero_iff_dvd (a b : ℕ) : (a : zmod b) = 0 ↔ b ∣ a :=
begin
change (a : zmod b) = ((0 : ℕ) : zmod b) ↔ b ∣ a,
rw [zmod.nat_coe_eq_nat_coe_iff, nat.modeq.modeq_zero_iff],
end
@[push_cast, simp]
lemma cast_mod_int (a : ℤ) (b : ℕ) : ((a % b : ℤ) : zmod b) = (a : zmod b) :=
begin
rw zmod.int_coe_eq_int_coe_iff,
apply int.modeq.mod_modeq,
end
@[simp] lemma coe_to_nat (p : ℕ) :
∀ {z : ℤ} (h : 0 ≤ z), (z.to_nat : zmod p) = z
| (n : ℕ) h := by simp only [int.cast_coe_nat, int.to_nat_coe_nat]
| -[1+n] h := false.elim h
lemma val_injective (n : ℕ) [fact (0 < n)] :
function.injective (zmod.val : zmod n → ℕ) :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹_› },
assume a b h,
ext,
exact h
end
lemma val_one_eq_one_mod (n : ℕ) : (1 : zmod n).val = 1 % n :=
by rw [← nat.cast_one, val_cast_nat]
lemma val_one (n : ℕ) [fact (1 < n)] : (1 : zmod n).val = 1 :=
by { rw val_one_eq_one_mod, exact nat.mod_eq_of_lt ‹1 < n› }
lemma val_add {n : ℕ} [fact (0 < n)] (a b : zmod n) : (a + b).val = (a.val + b.val) % n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ apply fin.val_add }
end
lemma val_mul {n : ℕ} (a b : zmod n) : (a * b).val = (a.val * b.val) % n :=
begin
cases n,
{ rw nat.mod_zero, apply int.nat_abs_mul },
{ apply fin.val_mul }
end
instance nontrivial (n : ℕ) [fact (1 < n)] : nontrivial (zmod n) :=
⟨⟨0, 1, assume h, zero_ne_one $
calc 0 = (0 : zmod n).val : by rw val_zero
... = (1 : zmod n).val : congr_arg zmod.val h
... = 1 : val_one n ⟩⟩
/-- The inversion on `zmod n`.
It is setup in such a way that `a * a⁻¹` is equal to `gcd a.val n`.
In particular, if `a` is coprime to `n`, and hence a unit, `a * a⁻¹ = 1`. -/
def inv : Π (n : ℕ), zmod n → zmod n
| 0 i := int.sign i
| (n+1) i := nat.gcd_a i.val (n+1)
instance (n : ℕ) : has_inv (zmod n) := ⟨inv n⟩
lemma inv_zero : ∀ (n : ℕ), (0 : zmod n)⁻¹ = 0
| 0 := int.sign_zero
| (n+1) := show (nat.gcd_a _ (n+1) : zmod (n+1)) = 0,
by { rw val_zero, unfold nat.gcd_a nat.xgcd nat.xgcd_aux, refl }
lemma mul_inv_eq_gcd {n : ℕ} (a : zmod n) :
a * a⁻¹ = nat.gcd a.val n :=
begin
cases n,
{ calc a * a⁻¹ = a * int.sign a : rfl
... = a.nat_abs : by rw [int.mul_sign, int.nat_cast_eq_coe_nat]
... = a.val.gcd 0 : by rw nat.gcd_zero_right; refl },
{ set k := n.succ,
calc a * a⁻¹ = a * a⁻¹ + k * nat.gcd_b (val a) k : by rw [cast_self, zero_mul, add_zero]
... = ↑(↑a.val * nat.gcd_a (val a) k + k * nat.gcd_b (val a) k) :
by { push_cast, rw cast_val, refl }
... = nat.gcd a.val k : (congr_arg coe (nat.gcd_eq_gcd_ab a.val k)).symm, }
end
@[simp] lemma cast_mod_nat (n : ℕ) (a : ℕ) : ((a % n : ℕ) : zmod n) = a :=
by conv {to_rhs, rw ← nat.mod_add_div a n}; simp
lemma eq_iff_modeq_nat (n : ℕ) {a b : ℕ} : (a : zmod n) = b ↔ a ≡ b [MOD n] :=
begin
cases n,
{ simp only [nat.modeq, int.coe_nat_inj', nat.mod_zero, int.nat_cast_eq_coe_nat], },
{ rw [fin.ext_iff, nat.modeq, ← val_cast_nat, ← val_cast_nat], exact iff.rfl, }
end
lemma coe_mul_inv_eq_one {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(x * x⁻¹ : zmod n) = 1 :=
begin
rw [nat.coprime, nat.gcd_comm, nat.gcd_rec] at h,
rw [mul_inv_eq_gcd, val_cast_nat, h, nat.cast_one],
end
/-- `unit_of_coprime` makes an element of `units (zmod n)` given
a natural number `x` and a proof that `x` is coprime to `n` -/
def unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) : units (zmod n) :=
⟨x, x⁻¹, coe_mul_inv_eq_one x h, by rw [mul_comm, coe_mul_inv_eq_one x h]⟩
@[simp] lemma cast_unit_of_coprime {n : ℕ} (x : ℕ) (h : nat.coprime x n) :
(unit_of_coprime x h : zmod n) = x := rfl
lemma val_coe_unit_coprime {n : ℕ} (u : units (zmod n)) :
nat.coprime (u : zmod n).val n :=
begin
cases n,
{ rcases int.units_eq_one_or u with rfl|rfl; exact dec_trivial },
apply nat.modeq.coprime_of_mul_modeq_one ((u⁻¹ : units (zmod (n+1))) : zmod (n+1)).val,
have := units.ext_iff.1 (mul_right_inv u),
rw [units.coe_one] at this,
rw [← eq_iff_modeq_nat, nat.cast_one, ← this], clear this,
rw [← cast_val ((u * u⁻¹ : units (zmod (n+1))) : zmod (n+1))],
rw [units.coe_mul, val_mul, cast_mod_nat],
end
@[simp] lemma inv_coe_unit {n : ℕ} (u : units (zmod n)) :
(u : zmod n)⁻¹ = (u⁻¹ : units (zmod n)) :=
begin
have := congr_arg (coe : ℕ → zmod n) (val_coe_unit_coprime u),
rw [← mul_inv_eq_gcd, nat.cast_one] at this,
let u' : units (zmod n) := ⟨u, (u : zmod n)⁻¹, this, by rwa mul_comm⟩,
have h : u = u', { apply units.ext, refl },
rw h,
refl
end
lemma mul_inv_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a * a⁻¹ = 1 :=
begin
rcases h with ⟨u, rfl⟩,
rw [inv_coe_unit, u.mul_inv],
end
lemma inv_mul_of_unit {n : ℕ} (a : zmod n) (h : is_unit a) :
a⁻¹ * a = 1 :=
by rw [mul_comm, mul_inv_of_unit a h]
/-- Equivalence between the units of `zmod n` and
the subtype of terms `x : zmod n` for which `x.val` is comprime to `n` -/
def units_equiv_coprime {n : ℕ} [fact (0 < n)] :
units (zmod n) ≃ {x : zmod n // nat.coprime x.val n} :=
{ to_fun := λ x, ⟨x, val_coe_unit_coprime x⟩,
inv_fun := λ x, unit_of_coprime x.1.val x.2,
left_inv := λ ⟨_, _, _, _⟩, units.ext (cast_val _),
right_inv := λ ⟨_, _⟩, by simp }
section totient
open_locale nat
@[simp] lemma card_units_eq_totient (n : ℕ) [fact (0 < n)] :
fintype.card (units (zmod n)) = φ n :=
calc fintype.card (units (zmod n)) = fintype.card {x : zmod n // x.val.coprime n} :
fintype.card_congr zmod.units_equiv_coprime
... = φ n :
begin
apply finset.card_congr (λ (a : {x : zmod n // x.val.coprime n}) _, a.1.val),
{ intro a, simp [(a : zmod n).val_lt, a.prop.symm] {contextual := tt} },
{ intros _ _ _ _ h, rw subtype.ext_iff_val, apply val_injective, exact h, },
{ intros b hb,
rw [finset.mem_filter, finset.mem_range] at hb,
refine ⟨⟨b, _⟩, finset.mem_univ _, _⟩,
{ let u := unit_of_coprime b hb.2.symm,
exact val_coe_unit_coprime u },
{ show zmod.val (b : zmod n) = b,
rw [val_cast_nat, nat.mod_eq_of_lt hb.1], } }
end
end totient
instance subsingleton_units : subsingleton (units (zmod 2)) :=
⟨λ x y, begin
cases x with x xi,
cases y with y yi,
revert x y xi yi,
exact dec_trivial
end⟩
lemma le_div_two_iff_lt_neg (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)]
{x : zmod n} (hx0 : x ≠ 0) : x.val ≤ (n / 2 : ℕ) ↔ (n / 2 : ℕ) < (-x).val :=
begin
haveI npos : fact (0 < n) := by
{ apply (nat.eq_zero_or_pos n).resolve_left,
unfreezingI { rintro rfl },
simpa [fact] using hn, },
have hn2 : (n : ℕ) / 2 < n := nat.div_lt_of_lt_mul ((lt_mul_iff_one_lt_left npos).2 dec_trivial),
have hn2' : (n : ℕ) - n / 2 = n / 2 + 1,
{ conv {to_lhs, congr, rw [← nat.succ_sub_one n, nat.succ_sub npos]},
rw [← nat.two_mul_odd_div_two hn, two_mul, ← nat.succ_add, nat.add_sub_cancel], },
have hxn : (n : ℕ) - x.val < n,
{ rw [nat.sub_lt_iff (le_of_lt x.val_lt) (le_refl _), nat.sub_self],
rw ← zmod.cast_val x at hx0,
exact nat.pos_of_ne_zero (λ h, by simpa [h] using hx0) },
by conv {to_rhs, rw [← nat.succ_le_iff, nat.succ_eq_add_one, ← hn2', ← zero_add (- x),
← zmod.cast_self, ← sub_eq_add_neg, ← zmod.cast_val x, ← nat.cast_sub (le_of_lt x.val_lt),
zmod.val_cast_nat, nat.mod_eq_of_lt hxn, nat.sub_le_sub_left_iff (le_of_lt x.val_lt)] }
end
lemma ne_neg_self (n : ℕ) [hn : fact ((n : ℕ) % 2 = 1)] {a : zmod n} (ha : a ≠ 0) : a ≠ -a :=
λ h, have a.val ≤ n / 2 ↔ (n : ℕ) / 2 < (-a).val := le_div_two_iff_lt_neg n ha,
by rwa [← h, ← not_lt, not_iff_self] at this
lemma neg_one_ne_one {n : ℕ} [fact (2 < n)] :
(-1 : zmod n) ≠ 1 :=
char_p.neg_one_ne_one (zmod n) n
@[simp] lemma neg_eq_self_mod_two : ∀ (a : zmod 2), -a = a := dec_trivial
@[simp] lemma nat_abs_mod_two (a : ℤ) : (a.nat_abs : zmod 2) = a :=
begin
cases a,
{ simp only [int.nat_abs_of_nat, int.cast_coe_nat, int.of_nat_eq_coe] },
{ simp only [neg_eq_self_mod_two, nat.cast_succ, int.nat_abs, int.cast_neg_succ_of_nat] }
end
@[simp] lemma val_eq_zero : ∀ {n : ℕ} (a : zmod n), a.val = 0 ↔ a = 0
| 0 a := int.nat_abs_eq_zero
| (n+1) a := by { rw fin.ext_iff, exact iff.rfl }
lemma val_cast_of_lt {n : ℕ} {a : ℕ} (h : a < n) : (a : zmod n).val = a :=
by rw [val_cast_nat, nat.mod_eq_of_lt h]
lemma neg_val' {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = (n - a.val) % n :=
begin
have : ((-a).val + a.val) % n = (n - a.val + a.val) % n,
{ rw [←val_add, add_left_neg, nat.sub_add_cancel (le_of_lt a.val_lt), nat.mod_self, val_zero], },
calc (-a).val = val (-a) % n : by rw nat.mod_eq_of_lt ((-a).val_lt)
... = (n - val a) % n : nat.modeq.modeq_add_cancel_right rfl this
end
lemma neg_val {n : ℕ} [fact (0 < n)] (a : zmod n) : (-a).val = if a = 0 then 0 else n - a.val :=
begin
rw neg_val',
by_cases h : a = 0, { rw [if_pos h, h, val_zero, nat.sub_zero, nat.mod_self] },
rw if_neg h,
apply nat.mod_eq_of_lt,
apply nat.sub_lt ‹0 < n›,
contrapose! h,
rwa [nat.le_zero_iff, val_eq_zero] at h,
end
/-- `val_min_abs x` returns the integer in the same equivalence class as `x` that is closest to `0`,
The result will be in the interval `(-n/2, n/2]`. -/
def val_min_abs : Π {n : ℕ}, zmod n → ℤ
| 0 x := x
| n@(_+1) x := if x.val ≤ n / 2 then x.val else (x.val : ℤ) - n
@[simp] lemma val_min_abs_def_zero (x : zmod 0) : val_min_abs x = x := rfl
lemma val_min_abs_def_pos {n : ℕ} [fact (0 < n)] (x : zmod n) :
val_min_abs x = if x.val ≤ n / 2 then x.val else x.val - n :=
begin
casesI n,
{ exfalso, exact nat.not_lt_zero 0 ‹0 < 0› },
{ refl }
end
@[simp] lemma coe_val_min_abs : ∀ {n : ℕ} (x : zmod n), (x.val_min_abs : zmod n) = x
| 0 x := int.cast_id x
| k@(n+1) x :=
begin
rw val_min_abs_def_pos,
split_ifs,
{ rw [int.cast_coe_nat, cast_val] },
{ rw [int.cast_sub, int.cast_coe_nat, cast_val, int.cast_coe_nat, cast_self, sub_zero], }
end
lemma nat_abs_val_min_abs_le {n : ℕ} [fact (0 < n)] (x : zmod n) : x.val_min_abs.nat_abs ≤ n / 2 :=
begin
rw zmod.val_min_abs_def_pos,
split_ifs with h, { exact h },
have : (x.val - n : ℤ) ≤ 0,
{ rw [sub_nonpos, int.coe_nat_le], exact le_of_lt x.val_lt, },
rw [← int.coe_nat_le, int.of_nat_nat_abs_of_nonpos this, neg_sub],
conv_lhs { congr, rw [← nat.mod_add_div n 2, int.coe_nat_add, int.coe_nat_mul,
int.coe_nat_bit0, int.coe_nat_one] },
suffices : ((n % 2 : ℕ) + (n / 2) : ℤ) ≤ (val x),
{ rw ← sub_nonneg at this ⊢, apply le_trans this (le_of_eq _), ring },
norm_cast,
calc (n : ℕ) % 2 + n / 2 ≤ 1 + n / 2 :
nat.add_le_add_right (nat.le_of_lt_succ (nat.mod_lt _ dec_trivial)) _
... ≤ x.val :
by { rw add_comm, exact nat.succ_le_of_lt (lt_of_not_ge h) }
end
@[simp] lemma val_min_abs_zero : ∀ n, (0 : zmod n).val_min_abs = 0
| 0 := by simp only [val_min_abs_def_zero]
| (n+1) := by simp only [val_min_abs_def_pos, if_true, int.coe_nat_zero, zero_le, val_zero]
@[simp] lemma val_min_abs_eq_zero {n : ℕ} (x : zmod n) :
x.val_min_abs = 0 ↔ x = 0 :=
begin
cases n, { simp },
split,
{ simp only [val_min_abs_def_pos, int.coe_nat_succ],
split_ifs with h h; assume h0,
{ apply val_injective, rwa [int.coe_nat_eq_zero] at h0, },
{ apply absurd h0, rw sub_eq_zero, apply ne_of_lt, exact_mod_cast x.val_lt } },
{ rintro rfl, rw val_min_abs_zero }
end
lemma cast_nat_abs_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val_min_abs.nat_abs : zmod n) = if a.val ≤ (n : ℕ) / 2 then a else -a :=
begin
have : (a.val : ℤ) - n ≤ 0,
by { erw [sub_nonpos, int.coe_nat_le], exact le_of_lt a.val_lt, },
rw [zmod.val_min_abs_def_pos],
split_ifs,
{ rw [int.nat_abs_of_nat, cast_val] },
{ rw [← int.cast_coe_nat, int.of_nat_nat_abs_of_nonpos this, int.cast_neg, int.cast_sub],
rw [int.cast_coe_nat, int.cast_coe_nat, cast_self, sub_zero, cast_val], }
end
@[simp] lemma nat_abs_val_min_abs_neg {n : ℕ} (a : zmod n) :
(-a).val_min_abs.nat_abs = a.val_min_abs.nat_abs :=
begin
cases n, { simp only [int.nat_abs_neg, val_min_abs_def_zero], },
by_cases ha0 : a = 0, { rw [ha0, neg_zero] },
by_cases haa : -a = a, { rw [haa] },
suffices hpa : (n+1 : ℕ) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
{ rw [val_min_abs_def_pos, val_min_abs_def_pos],
rw ← not_le at hpa,
simp only [if_neg ha0, neg_val, hpa, int.coe_nat_sub (le_of_lt a.val_lt)],
split_ifs,
all_goals { rw [← int.nat_abs_neg], congr' 1, ring } },
suffices : (((n+1 : ℕ) % 2) + 2 * ((n + 1) / 2)) - a.val ≤ (n+1) / 2 ↔ (n+1 : ℕ) / 2 < a.val,
by rwa [nat.mod_add_div] at this,
suffices : (n + 1) % 2 + (n + 1) / 2 ≤ val a ↔ (n + 1) / 2 < val a,
by rw [nat.sub_le_iff, two_mul, ← add_assoc, nat.add_sub_cancel, this],
cases (n + 1 : ℕ).mod_two_eq_zero_or_one with hn0 hn1,
{ split,
{ assume h,
apply lt_of_le_of_ne (le_trans (nat.le_add_left _ _) h),
contrapose! haa,
rw [← zmod.cast_val a, ← haa, neg_eq_iff_add_eq_zero, ← nat.cast_add],
rw [char_p.cast_eq_zero_iff (zmod (n+1)) (n+1)],
rw [← two_mul, ← zero_add (2 * _), ← hn0, nat.mod_add_div] },
{ rw [hn0, zero_add], exact le_of_lt } },
{ rw [hn1, add_comm, nat.succ_le_iff] }
end
lemma val_eq_ite_val_min_abs {n : ℕ} [fact (0 < n)] (a : zmod n) :
(a.val : ℤ) = a.val_min_abs + if a.val ≤ n / 2 then 0 else n :=
by { rw [zmod.val_min_abs_def_pos], split_ifs; simp only [add_zero, sub_add_cancel] }
lemma prime_ne_zero (p q : ℕ) [hp : fact p.prime] [hq : fact q.prime] (hpq : p ≠ q) :
(q : zmod p) ≠ 0 :=
by rwa [← nat.cast_zero, ne.def, eq_iff_modeq_nat, nat.modeq.modeq_zero_iff,
← hp.coprime_iff_not_dvd, nat.coprime_primes hp hq]
end zmod
namespace zmod
variables (p : ℕ) [fact p.prime]
private lemma mul_inv_cancel_aux (a : zmod p) (h : a ≠ 0) : a * a⁻¹ = 1 :=
begin
obtain ⟨k, rfl⟩ := nat_cast_surjective a,
apply coe_mul_inv_eq_one,
apply nat.coprime.symm,
rwa [nat.prime.coprime_iff_not_dvd ‹p.prime›, ← char_p.cast_eq_zero_iff (zmod p)]
end
/-- Field structure on `zmod p` if `p` is prime. -/
instance : field (zmod p) :=
{ mul_inv_cancel := mul_inv_cancel_aux p,
inv_zero := inv_zero p,
.. zmod.comm_ring p,
.. zmod.has_inv p,
.. zmod.nontrivial p }
end zmod
lemma ring_hom.ext_zmod {n : ℕ} {R : Type*} [semiring R] (f g : (zmod n) →+* R) : f = g :=
begin
ext a,
obtain ⟨k, rfl⟩ := zmod.int_cast_surjective a,
let φ : ℤ →+* R := f.comp (int.cast_ring_hom (zmod n)),
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom (zmod n)),
show φ k = ψ k,
rw φ.ext_int ψ,
end
namespace zmod
variables {n : ℕ} {R : Type*}
instance subsingleton_ring_hom [semiring R] : subsingleton ((zmod n) →+* R) :=
⟨ring_hom.ext_zmod⟩
instance subsingleton_ring_equiv [semiring R] : subsingleton (zmod n ≃+* R) :=
⟨λ f g, by { rw ring_equiv.coe_ring_hom_inj_iff, apply ring_hom.ext_zmod _ _ }⟩
lemma ring_hom_surjective [ring R] (f : R →+* (zmod n)) :
function.surjective f :=
begin
intros k,
rcases zmod.int_cast_surjective k with ⟨n, rfl⟩,
refine ⟨n, f.map_int_cast n⟩
end
lemma ring_hom_eq_of_ker_eq [comm_ring R] (f g : R →+* (zmod n))
(h : f.ker = g.ker) : f = g :=
by rw [← f.lift_of_surjective_comp (zmod.ring_hom_surjective f) g (le_of_eq h),
ring_hom.ext_zmod (f.lift_of_surjective _ _ _) (ring_hom.id _),
ring_hom.id_comp]
end zmod
|
f254e8bb23ade69ee3571f272a794ba9cecaccf4 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/algebra/periodic.lean | 0542863bc8bf425a729b4e0f20400b89645484ac | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 16,899 | lean | /-
Copyright (c) 2021 Benjamin Davidson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Benjamin Davidson
-/
import algebra.field.opposite
import algebra.module.basic
import algebra.order.archimedean
import data.int.parity
import group_theory.coset
/-!
# Periodicity
In this file we define and then prove facts about periodic and antiperiodic functions.
## Main definitions
* `function.periodic`: A function `f` is *periodic* if `∀ x, f (x + c) = f x`.
`f` is referred to as periodic with period `c` or `c`-periodic.
* `function.antiperiodic`: A function `f` is *antiperiodic* if `∀ x, f (x + c) = -f x`.
`f` is referred to as antiperiodic with antiperiod `c` or `c`-antiperiodic.
Note that any `c`-antiperiodic function will necessarily also be `2*c`-periodic.
## Tags
period, periodic, periodicity, antiperiodic
-/
variables {α β γ : Type*} {f g : α → β} {c c₁ c₂ x : α}
namespace function
/-! ### Periodicity -/
/-- A function `f` is said to be `periodic` with period `c` if for all `x`, `f (x + c) = f x`. -/
@[simp] def periodic [has_add α] (f : α → β) (c : α) : Prop :=
∀ x : α, f (x + c) = f x
lemma periodic.funext [has_add α]
(h : periodic f c) :
(λ x, f (x + c)) = f :=
funext h
lemma periodic.comp [has_add α]
(h : periodic f c) (g : β → γ) :
periodic (g ∘ f) c :=
by simp * at *
lemma periodic.comp_add_hom [has_add α] [has_add γ]
(h : periodic f c) (g : add_hom γ α) (g_inv : α → γ) (hg : right_inverse g_inv g) :
periodic (f ∘ g) (g_inv c) :=
λ x, by simp only [hg c, h (g x), add_hom.map_add, comp_app]
@[to_additive]
lemma periodic.mul [has_add α] [has_mul β]
(hf : periodic f c) (hg : periodic g c) :
periodic (f * g) c :=
by simp * at *
@[to_additive]
lemma periodic.div [has_add α] [has_div β]
(hf : periodic f c) (hg : periodic g c) :
periodic (f / g) c :=
by simp * at *
lemma periodic.const_smul [add_monoid α] [group γ] [distrib_mul_action γ α]
(h : periodic f c) (a : γ) :
periodic (λ x, f (a • x)) (a⁻¹ • c) :=
λ x, by simpa only [smul_add, smul_inv_smul] using h (a • x)
lemma periodic.const_smul₀ [add_comm_monoid α] [division_ring γ] [module γ α]
(h : periodic f c) (a : γ) :
periodic (λ x, f (a • x)) (a⁻¹ • c) :=
begin
intro x,
by_cases ha : a = 0, { simp only [ha, zero_smul] },
simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x),
end
lemma periodic.const_mul [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (a * x)) (a⁻¹ * c) :=
h.const_smul₀ a
lemma periodic.const_inv_smul [add_monoid α] [group γ] [distrib_mul_action γ α]
(h : periodic f c) (a : γ) :
periodic (λ x, f (a⁻¹ • x)) (a • c) :=
by simpa only [inv_inv] using h.const_smul a⁻¹
lemma periodic.const_inv_smul₀ [add_comm_monoid α] [division_ring γ] [module γ α]
(h : periodic f c) (a : γ) :
periodic (λ x, f (a⁻¹ • x)) (a • c) :=
by simpa only [inv_inv₀] using h.const_smul₀ a⁻¹
lemma periodic.const_inv_mul [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (a⁻¹ * x)) (a * c) :=
h.const_inv_smul₀ a
lemma periodic.mul_const [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (x * a)) (c * a⁻¹) :=
h.const_smul₀ $ mul_opposite.op a
lemma periodic.mul_const' [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (x * a)) (c / a) :=
by simpa only [div_eq_mul_inv] using h.mul_const a
lemma periodic.mul_const_inv [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (x * a⁻¹)) (c * a) :=
h.const_inv_smul₀ $ mul_opposite.op a
lemma periodic.div_const [division_ring α]
(h : periodic f c) (a : α) :
periodic (λ x, f (x / a)) (c * a) :=
by simpa only [div_eq_mul_inv] using h.mul_const_inv a
lemma periodic.add_period [add_semigroup α]
(h1 : periodic f c₁) (h2 : periodic f c₂) :
periodic f (c₁ + c₂) :=
by simp [*, ← add_assoc] at *
lemma periodic.sub_eq [add_group α]
(h : periodic f c) (x : α) :
f (x - c) = f x :=
by simpa only [sub_add_cancel] using (h (x - c)).symm
lemma periodic.sub_eq' [add_comm_group α]
(h : periodic f c) :
f (c - x) = f (-x) :=
by simpa only [sub_eq_neg_add] using h (-x)
lemma periodic.neg [add_group α]
(h : periodic f c) :
periodic f (-c) :=
by simpa only [sub_eq_add_neg, periodic] using h.sub_eq
lemma periodic.sub_period [add_comm_group α]
(h1 : periodic f c₁) (h2 : periodic f c₂) :
periodic f (c₁ - c₂) :=
let h := h2.neg in by simp [*, sub_eq_add_neg, add_comm c₁, ← add_assoc] at *
lemma periodic.nsmul [add_monoid α]
(h : periodic f c) (n : ℕ) :
periodic f (n • c) :=
by induction n; simp [nat.succ_eq_add_one, add_nsmul, ← add_assoc, zero_nsmul, *] at *
lemma periodic.nat_mul [semiring α]
(h : periodic f c) (n : ℕ) :
periodic f (n * c) :=
by simpa only [nsmul_eq_mul] using h.nsmul n
lemma periodic.neg_nsmul [add_group α]
(h : periodic f c) (n : ℕ) :
periodic f (-(n • c)) :=
(h.nsmul n).neg
lemma periodic.neg_nat_mul [ring α]
(h : periodic f c) (n : ℕ) :
periodic f (-(n * c)) :=
(h.nat_mul n).neg
lemma periodic.sub_nsmul_eq [add_group α]
(h : periodic f c) (n : ℕ) :
f (x - n • c) = f x :=
by simpa only [sub_eq_add_neg] using h.neg_nsmul n x
lemma periodic.sub_nat_mul_eq [ring α]
(h : periodic f c) (n : ℕ) :
f (x - n * c) = f x :=
by simpa only [nsmul_eq_mul] using h.sub_nsmul_eq n
lemma periodic.nsmul_sub_eq [add_comm_group α]
(h : periodic f c) (n : ℕ) :
f (n • c - x) = f (-x) :=
by simpa only [sub_eq_neg_add] using h.nsmul n (-x)
lemma periodic.nat_mul_sub_eq [ring α]
(h : periodic f c) (n : ℕ) :
f (n * c - x) = f (-x) :=
by simpa only [sub_eq_neg_add] using h.nat_mul n (-x)
lemma periodic.zsmul [add_group α]
(h : periodic f c) (n : ℤ) :
periodic f (n • c) :=
begin
cases n,
{ simpa only [int.of_nat_eq_coe, coe_nat_zsmul] using h.nsmul n },
{ simpa only [zsmul_neg_succ_of_nat] using (h.nsmul n.succ).neg },
end
lemma periodic.int_mul [ring α]
(h : periodic f c) (n : ℤ) :
periodic f (n * c) :=
by simpa only [zsmul_eq_mul] using h.zsmul n
lemma periodic.sub_zsmul_eq [add_group α]
(h : periodic f c) (n : ℤ) :
f (x - n • c) = f x :=
(h.zsmul n).sub_eq x
lemma periodic.sub_int_mul_eq [ring α]
(h : periodic f c) (n : ℤ) :
f (x - n * c) = f x :=
(h.int_mul n).sub_eq x
lemma periodic.zsmul_sub_eq [add_comm_group α]
(h : periodic f c) (n : ℤ) :
f (n • c - x) = f (-x) :=
by simpa only [sub_eq_neg_add] using h.zsmul n (-x)
lemma periodic.int_mul_sub_eq [ring α]
(h : periodic f c) (n : ℤ) :
f (n * c - x) = f (-x) :=
by simpa only [sub_eq_neg_add] using h.int_mul n (-x)
lemma periodic.eq [add_zero_class α]
(h : periodic f c) :
f c = f 0 :=
by simpa only [zero_add] using h 0
lemma periodic.neg_eq [add_group α]
(h : periodic f c) :
f (-c) = f 0 :=
h.neg.eq
lemma periodic.nsmul_eq [add_monoid α]
(h : periodic f c) (n : ℕ) :
f (n • c) = f 0 :=
(h.nsmul n).eq
lemma periodic.nat_mul_eq [semiring α]
(h : periodic f c) (n : ℕ) :
f (n * c) = f 0 :=
(h.nat_mul n).eq
lemma periodic.zsmul_eq [add_group α]
(h : periodic f c) (n : ℤ) :
f (n • c) = f 0 :=
(h.zsmul n).eq
lemma periodic.int_mul_eq [ring α]
(h : periodic f c) (n : ℤ) :
f (n * c) = f 0 :=
(h.int_mul n).eq
/-- If a function `f` is `periodic` with positive period `c`, then for all `x` there exists some
`y ∈ Ico 0 c` such that `f x = f y`. -/
lemma periodic.exists_mem_Ico₀ [linear_ordered_add_comm_group α] [archimedean α]
(h : periodic f c) (hc : 0 < c) (x) :
∃ y ∈ set.Ico 0 c, f x = f y :=
let ⟨n, H, _⟩ := exists_unique_zsmul_near_of_pos' hc x in
⟨x - n • c, H, (h.sub_zsmul_eq n).symm⟩
/-- If a function `f` is `periodic` with positive period `c`, then for all `x` there exists some
`y ∈ Ico a (a + c)` such that `f x = f y`. -/
lemma periodic.exists_mem_Ico [linear_ordered_add_comm_group α] [archimedean α]
(h : periodic f c) (hc : 0 < c) (x a) :
∃ y ∈ set.Ico a (a + c), f x = f y :=
let ⟨n, H, _⟩ := exists_unique_add_zsmul_mem_Ico hc x a in
⟨x + n • c, H, (h.zsmul n x).symm⟩
/-- If a function `f` is `periodic` with positive period `c`, then for all `x` there exists some
`y ∈ Ioc a (a + c)` such that `f x = f y`. -/
lemma periodic.exists_mem_Ioc [linear_ordered_add_comm_group α] [archimedean α]
(h : periodic f c) (hc : 0 < c) (x a) :
∃ y ∈ set.Ioc a (a + c), f x = f y :=
let ⟨n, H, _⟩ := exists_unique_add_zsmul_mem_Ioc hc x a in
⟨x + n • c, H, (h.zsmul n x).symm⟩
lemma periodic.image_Ioc [linear_ordered_add_comm_group α] [archimedean α]
(h : periodic f c) (hc : 0 < c) (a : α) :
f '' set.Ioc a (a + c) = set.range f :=
(set.image_subset_range _ _).antisymm $ set.range_subset_iff.2 $ λ x,
let ⟨y, hy, hyx⟩ := h.exists_mem_Ioc hc x a in ⟨y, hy, hyx.symm⟩
lemma periodic_with_period_zero [add_zero_class α]
(f : α → β) :
periodic f 0 :=
λ x, by rw add_zero
lemma periodic.map_vadd_zmultiples [add_comm_group α] (hf : periodic f c)
(a : add_subgroup.zmultiples c) (x : α) :
f (a +ᵥ x) = f x :=
by { rcases a with ⟨_, m, rfl⟩, simp [add_subgroup.vadd_def, add_comm _ x, hf.zsmul m x] }
lemma periodic.map_vadd_multiples [add_comm_monoid α] (hf : periodic f c)
(a : add_submonoid.multiples c) (x : α) :
f (a +ᵥ x) = f x :=
by { rcases a with ⟨_, m, rfl⟩, simp [add_submonoid.vadd_def, add_comm _ x, hf.nsmul m x] }
/-- Lift a periodic function to a function from the quotient group. -/
def periodic.lift [add_group α] (h : periodic f c) (x : α ⧸ add_subgroup.zmultiples c) : β :=
quotient.lift_on' x f $
λ a b ⟨k, hk⟩, (h.zsmul k _).symm.trans $ congr_arg f $ add_eq_of_eq_neg_add hk
@[simp] lemma periodic.lift_coe [add_group α] (h : periodic f c) (a : α) :
h.lift (a : α ⧸ add_subgroup.zmultiples c) = f a :=
rfl
/-! ### Antiperiodicity -/
/-- A function `f` is said to be `antiperiodic` with antiperiod `c` if for all `x`,
`f (x + c) = -f x`. -/
@[simp] def antiperiodic [has_add α] [has_neg β] (f : α → β) (c : α) : Prop :=
∀ x : α, f (x + c) = -f x
lemma antiperiodic.funext [has_add α] [has_neg β]
(h : antiperiodic f c) :
(λ x, f (x + c)) = -f :=
funext h
lemma antiperiodic.funext' [has_add α] [add_group β]
(h : antiperiodic f c) :
(λ x, -f (x + c)) = f :=
(eq_neg_iff_eq_neg.mp h.funext).symm
/-- If a function is `antiperiodic` with antiperiod `c`, then it is also `periodic` with period
`2 * c`. -/
lemma antiperiodic.periodic [semiring α] [add_group β]
(h : antiperiodic f c) :
periodic f (2 * c) :=
by simp [two_mul, ← add_assoc, h _]
lemma antiperiodic.eq [add_zero_class α] [has_neg β]
(h : antiperiodic f c) : f c = -f 0 :=
by simpa only [zero_add] using h 0
lemma antiperiodic.nat_even_mul_periodic [semiring α] [add_group β]
(h : antiperiodic f c) (n : ℕ) :
periodic f (n * (2 * c)) :=
h.periodic.nat_mul n
lemma antiperiodic.nat_odd_mul_antiperiodic [semiring α] [add_group β]
(h : antiperiodic f c) (n : ℕ) :
antiperiodic f (n * (2 * c) + c) :=
λ x, by rw [← add_assoc, h, h.periodic.nat_mul]
lemma antiperiodic.int_even_mul_periodic [ring α] [add_group β]
(h : antiperiodic f c) (n : ℤ) :
periodic f (n * (2 * c)) :=
h.periodic.int_mul n
lemma antiperiodic.int_odd_mul_antiperiodic [ring α] [add_group β]
(h : antiperiodic f c) (n : ℤ) :
antiperiodic f (n * (2 * c) + c) :=
λ x, by rw [← add_assoc, h, h.periodic.int_mul]
lemma antiperiodic.nat_mul_eq_of_eq_zero [comm_semiring α] [add_group β]
(h : antiperiodic f c) (hi : f 0 = 0) (n : ℕ) :
f (n * c) = 0 :=
begin
rcases nat.even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;
have hk : (k : α) * (2 * c) = 2 * k * c := by rw [mul_left_comm, ← mul_assoc],
{ simpa [hk, hi] using (h.nat_even_mul_periodic k).eq },
{ simpa [add_mul, hk, hi] using (h.nat_odd_mul_antiperiodic k).eq },
end
lemma antiperiodic.int_mul_eq_of_eq_zero [comm_ring α] [add_group β]
(h : antiperiodic f c) (hi : f 0 = 0) (n : ℤ) :
f (n * c) = 0 :=
begin
rcases int.even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;
have hk : (k : α) * (2 * c) = 2 * k * c := by rw [mul_left_comm, ← mul_assoc],
{ simpa [hk, hi] using (h.int_even_mul_periodic k).eq },
{ simpa [add_mul, hk, hi] using (h.int_odd_mul_antiperiodic k).eq },
end
lemma antiperiodic.sub_eq [add_group α] [add_group β]
(h : antiperiodic f c) (x : α) :
f (x - c) = -f x :=
by simp only [eq_neg_iff_eq_neg.mp (h (x - c)), sub_add_cancel]
lemma antiperiodic.sub_eq' [add_comm_group α] [add_group β]
(h : antiperiodic f c) :
f (c - x) = -f (-x) :=
by simpa only [sub_eq_neg_add] using h (-x)
lemma antiperiodic.neg [add_group α] [add_group β]
(h : antiperiodic f c) :
antiperiodic f (-c) :=
by simpa only [sub_eq_add_neg, antiperiodic] using h.sub_eq
lemma antiperiodic.neg_eq [add_group α] [add_group β]
(h : antiperiodic f c) :
f (-c) = -f 0 :=
by simpa only [zero_add] using h.neg 0
lemma antiperiodic.const_smul [add_monoid α] [has_neg β] [group γ] [distrib_mul_action γ α]
(h : antiperiodic f c) (a : γ) :
antiperiodic (λ x, f (a • x)) (a⁻¹ • c) :=
λ x, by simpa only [smul_add, smul_inv_smul] using h (a • x)
lemma antiperiodic.const_smul₀ [add_comm_monoid α] [has_neg β] [division_ring γ] [module γ α]
(h : antiperiodic f c) {a : γ} (ha : a ≠ 0) :
antiperiodic (λ x, f (a • x)) (a⁻¹ • c) :=
λ x, by simpa only [smul_add, smul_inv_smul₀ ha] using h (a • x)
lemma antiperiodic.const_mul [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (a * x)) (a⁻¹ * c) :=
h.const_smul₀ ha
lemma antiperiodic.const_inv_smul [add_monoid α] [has_neg β] [group γ] [distrib_mul_action γ α]
(h : antiperiodic f c) (a : γ) :
antiperiodic (λ x, f (a⁻¹ • x)) (a • c) :=
by simpa only [inv_inv] using h.const_smul a⁻¹
lemma antiperiodic.const_inv_smul₀ [add_comm_monoid α] [has_neg β] [division_ring γ] [module γ α]
(h : antiperiodic f c) {a : γ} (ha : a ≠ 0) :
antiperiodic (λ x, f (a⁻¹ • x)) (a • c) :=
by simpa only [inv_inv₀] using h.const_smul₀ (inv_ne_zero ha)
lemma antiperiodic.const_inv_mul [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (a⁻¹ * x)) (a * c) :=
h.const_inv_smul₀ ha
lemma antiperiodic.mul_const [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (x * a)) (c * a⁻¹) :=
h.const_smul₀ $ (mul_opposite.op_ne_zero_iff a).mpr ha
lemma antiperiodic.mul_const' [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (x * a)) (c / a) :=
by simpa only [div_eq_mul_inv] using h.mul_const ha
lemma antiperiodic.mul_const_inv [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (x * a⁻¹)) (c * a) :=
h.const_inv_smul₀ $ (mul_opposite.op_ne_zero_iff a).mpr ha
lemma antiperiodic.div_inv [division_ring α] [has_neg β]
(h : antiperiodic f c) {a : α} (ha : a ≠ 0) :
antiperiodic (λ x, f (x / a)) (c * a) :=
by simpa only [div_eq_mul_inv] using h.mul_const_inv ha
lemma antiperiodic.add [add_group α] [add_group β]
(h1 : antiperiodic f c₁) (h2 : antiperiodic f c₂) :
periodic f (c₁ + c₂) :=
by simp [*, ← add_assoc] at *
lemma antiperiodic.sub [add_comm_group α] [add_group β]
(h1 : antiperiodic f c₁) (h2 : antiperiodic f c₂) :
periodic f (c₁ - c₂) :=
let h := h2.neg in by simp [*, sub_eq_add_neg, add_comm c₁, ← add_assoc] at *
lemma periodic.add_antiperiod [add_group α] [add_group β]
(h1 : periodic f c₁) (h2 : antiperiodic f c₂) :
antiperiodic f (c₁ + c₂) :=
by simp [*, ← add_assoc] at *
lemma periodic.sub_antiperiod [add_comm_group α] [add_group β]
(h1 : periodic f c₁) (h2 : antiperiodic f c₂) :
antiperiodic f (c₁ - c₂) :=
let h := h2.neg in by simp [*, sub_eq_add_neg, add_comm c₁, ← add_assoc] at *
lemma periodic.add_antiperiod_eq [add_group α] [add_group β]
(h1 : periodic f c₁) (h2 : antiperiodic f c₂) :
f (c₁ + c₂) = -f 0 :=
(h1.add_antiperiod h2).eq
lemma periodic.sub_antiperiod_eq [add_comm_group α] [add_group β]
(h1 : periodic f c₁) (h2 : antiperiodic f c₂) :
f (c₁ - c₂) = -f 0 :=
(h1.sub_antiperiod h2).eq
lemma antiperiodic.mul [has_add α] [ring β]
(hf : antiperiodic f c) (hg : antiperiodic g c) :
periodic (f * g) c :=
by simp * at *
lemma antiperiodic.div [has_add α] [division_ring β]
(hf : antiperiodic f c) (hg : antiperiodic g c) :
periodic (f / g) c :=
by simp [*, neg_div_neg_eq] at *
end function
|
ba790af3d57e6b1729c5a5221ac3136d0cedc839 | 82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7 | /src/Init/Fix.lean | a01a955208f3170f3454c0a47ce73957559a0c17 | [
"Apache-2.0"
] | permissive | banksonian/lean4 | 3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc | 78da6b3aa2840693eea354a41e89fc5b212a5011 | refs/heads/master | 1,673,703,624,165 | 1,605,123,551,000 | 1,605,123,551,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,915 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Init.Data.UInt
universe u
def bfix1 {α β : Type u} (base : α → β) (rec : (α → β) → α → β) : Nat → α → β
| 0, a => base a
| n+1, a => rec (bfix1 base rec n) a
@[extern c inline "lean_fixpoint(#4, #5)"]
def fixCore1 {α β : Type u} (base : @& (α → β)) (rec : (α → β) → α → β) : α → β :=
bfix1 base rec usizeSz
@[inline] def fixCore {α β : Type u} (base : @& (α → β)) (rec : (α → β) → α → β) : α → β :=
fixCore1 base rec
@[inline] def fix1 {α β : Type u} [Inhabited β] (rec : (α → β) → α → β) : α → β :=
fixCore1 (fun _ => arbitrary β) rec
@[inline] def fix {α β : Type u} [Inhabited β] (rec : (α → β) → α → β) : α → β :=
fixCore1 (fun _ => arbitrary β) rec
def bfix2 {α₁ α₂ β : Type u} (base : α₁ → α₂ → β) (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : Nat → α₁ → α₂ → β
| 0, a₁, a₂ => base a₁ a₂
| n+1, a₁, a₂ => rec (bfix2 base rec n) a₁ a₂
@[extern c inline "lean_fixpoint2(#5, #6, #7)"]
def fixCore2 {α₁ α₂ β : Type u} (base : α₁ → α₂ → β) (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : α₁ → α₂ → β :=
bfix2 base rec usizeSz
@[inline] def fix2 {α₁ α₂ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → β) → α₁ → α₂ → β) : α₁ → α₂ → β :=
fixCore2 (fun _ _ => arbitrary β) rec
def bfix3 {α₁ α₂ α₃ β : Type u} (base : α₁ → α₂ → α₃ → β) (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : Nat → α₁ → α₂ → α₃ → β
| 0, a₁, a₂, a₃ => base a₁ a₂ a₃
| n+1, a₁, a₂, a₃ => rec (bfix3 base rec n) a₁ a₂ a₃
@[extern c inline "lean_fixpoint3(#6, #7, #8, #9)"]
def fixCore3 {α₁ α₂ α₃ β : Type u} (base : α₁ → α₂ → α₃ → β) (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : α₁ → α₂ → α₃ → β :=
bfix3 base rec usizeSz
@[inline] def fix3 {α₁ α₂ α₃ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → β) → α₁ → α₂ → α₃ → β) : α₁ → α₂ → α₃ → β :=
fixCore3 (fun _ _ _ => arbitrary β) rec
def bfix4 {α₁ α₂ α₃ α₄ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → β) (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : Nat → α₁ → α₂ → α₃ → α₄ → β
| 0, a₁, a₂, a₃, a₄ => base a₁ a₂ a₃ a₄
| n+1, a₁, a₂, a₃, a₄ => rec (bfix4 base rec n) a₁ a₂ a₃ a₄
@[extern c inline "lean_fixpoint4(#7, #8, #9, #10, #11)"]
def fixCore4 {α₁ α₂ α₃ α₄ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → β) (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : α₁ → α₂ → α₃ → α₄ → β :=
bfix4 base rec usizeSz
@[inline] def fix4 {α₁ α₂ α₃ α₄ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → β) → α₁ → α₂ → α₃ → α₄ → β) : α₁ → α₂ → α₃ → α₄ → β :=
fixCore4 (fun _ _ _ _ => arbitrary β) rec
def bfix5 {α₁ α₂ α₃ α₄ α₅ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : Nat → α₁ → α₂ → α₃ → α₄ → α₅ → β
| 0, a₁, a₂, a₃, a₄, a₅ => base a₁ a₂ a₃ a₄ a₅
| n+1, a₁, a₂, a₃, a₄, a₅ => rec (bfix5 base rec n) a₁ a₂ a₃ a₄ a₅
@[extern c inline "lean_fixpoint5(#8, #9, #10, #11, #12, #13)"]
def fixCore5 {α₁ α₂ α₃ α₄ α₅ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → β :=
bfix5 base rec usizeSz
@[inline] def fix5 {α₁ α₂ α₃ α₄ α₅ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → β :=
fixCore5 (fun _ _ _ _ _ => arbitrary β) rec
def bfix6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : Nat → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β
| 0, a₁, a₂, a₃, a₄, a₅, a₆ => base a₁ a₂ a₃ a₄ a₅ a₆
| n+1, a₁, a₂, a₃, a₄, a₅, a₆ => rec (bfix6 base rec n) a₁ a₂ a₃ a₄ a₅ a₆
@[extern c inline "lean_fixpoint6(#9, #10, #11, #12, #13, #14, #15)"]
def fixCore6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} (base : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β :=
bfix6 base rec usizeSz
@[inline] def fix6 {α₁ α₂ α₃ α₄ α₅ α₆ β : Type u} [Inhabited β] (rec : (α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) → α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β) : α₁ → α₂ → α₃ → α₄ → α₅ → α₆ → β :=
fixCore6 (fun _ _ _ _ _ _ => arbitrary β) rec
|
829d7ea8f39a9ece73b4a51c6f7cc92cc87d007d | bb31430994044506fa42fd667e2d556327e18dfe | /src/algebra/order/to_interval_mod.lean | 3a7b1cb9762a4067915627cd3d0bc63780ba6662 | [
"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 | 26,130 | lean | /-
Copyright (c) 2022 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers
-/
import algebra.module.basic
import algebra.order.archimedean
import algebra.periodic
import group_theory.quotient_group
/-!
# Reducing to an interval modulo its length
This file defines operations that reduce a number (in an `archimedean`
`linear_ordered_add_comm_group`) to a number in a given interval, modulo the length of that
interval.
## Main definitions
* `to_Ico_div a hb x` (where `hb : 0 < b`): The unique integer such that this multiple of `b`,
added to `x`, is in `Ico a (a + b)`.
* `to_Ico_mod a hb x` (where `hb : 0 < b`): Reduce `x` to the interval `Ico a (a + b)`.
* `to_Ioc_div a hb x` (where `hb : 0 < b`): The unique integer such that this multiple of `b`,
added to `x`, is in `Ioc a (a + b)`.
* `to_Ioc_mod a hb x` (where `hb : 0 < b`): Reduce `x` to the interval `Ioc a (a + b)`.
-/
noncomputable theory
section linear_ordered_add_comm_group
variables {α : Type*} [linear_ordered_add_comm_group α] [hα : archimedean α]
include hα
/-- The unique integer such that this multiple of `b`, added to `x`, is in `Ico a (a + b)`. -/
def to_Ico_div (a : α) {b : α} (hb : 0 < b) (x : α) : ℤ :=
(exists_unique_add_zsmul_mem_Ico hb x a).some
lemma add_to_Ico_div_zsmul_mem_Ico (a : α) {b : α} (hb : 0 < b) (x : α) :
x + to_Ico_div a hb x • b ∈ set.Ico a (a + b) :=
(exists_unique_add_zsmul_mem_Ico hb x a).some_spec.1
lemma eq_to_Ico_div_of_add_zsmul_mem_Ico {a b x : α} (hb : 0 < b) {y : ℤ}
(hy : x + y • b ∈ set.Ico a (a + b)) : y = to_Ico_div a hb x :=
(exists_unique_add_zsmul_mem_Ico hb x a).some_spec.2 y hy
/-- The unique integer such that this multiple of `b`, added to `x`, is in `Ioc a (a + b)`. -/
def to_Ioc_div (a : α) {b : α} (hb : 0 < b) (x : α) : ℤ :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some
lemma add_to_Ioc_div_zsmul_mem_Ioc (a : α) {b : α} (hb : 0 < b) (x : α) :
x + to_Ioc_div a hb x • b ∈ set.Ioc a (a + b) :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some_spec.1
lemma eq_to_Ioc_div_of_add_zsmul_mem_Ioc {a b x : α} (hb : 0 < b) {y : ℤ}
(hy : x + y • b ∈ set.Ioc a (a + b)) : y = to_Ioc_div a hb x :=
(exists_unique_add_zsmul_mem_Ioc hb x a).some_spec.2 y hy
/-- Reduce `x` to the interval `Ico a (a + b)`. -/
def to_Ico_mod (a : α) {b : α} (hb : 0 < b) (x : α) : α := x + to_Ico_div a hb x • b
/-- Reduce `x` to the interval `Ioc a (a + b)`. -/
def to_Ioc_mod (a : α) {b : α} (hb : 0 < b) (x : α) : α := x + to_Ioc_div a hb x • b
lemma to_Ico_mod_mem_Ico (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb x ∈ set.Ico a (a + b) :=
add_to_Ico_div_zsmul_mem_Ico a hb x
lemma to_Ico_mod_mem_Ico' {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod 0 hb x ∈ set.Ico 0 b :=
by { convert to_Ico_mod_mem_Ico 0 hb x, exact (zero_add b).symm, }
lemma to_Ioc_mod_mem_Ioc (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb x ∈ set.Ioc a (a + b) :=
add_to_Ioc_div_zsmul_mem_Ioc a hb x
lemma left_le_to_Ico_mod (a : α) {b : α} (hb : 0 < b) (x : α) : a ≤ to_Ico_mod a hb x :=
(set.mem_Ico.1 (to_Ico_mod_mem_Ico a hb x)).1
lemma left_lt_to_Ioc_mod (a : α) {b : α} (hb : 0 < b) (x : α) : a < to_Ioc_mod a hb x :=
(set.mem_Ioc.1 (to_Ioc_mod_mem_Ioc a hb x)).1
lemma to_Ico_mod_lt_right (a : α) {b : α} (hb : 0 < b) (x : α) : to_Ico_mod a hb x < a + b :=
(set.mem_Ico.1 (to_Ico_mod_mem_Ico a hb x)).2
lemma to_Ioc_mod_le_right (a : α) {b : α} (hb : 0 < b) (x : α) : to_Ioc_mod a hb x ≤ a + b :=
(set.mem_Ioc.1 (to_Ioc_mod_mem_Ioc a hb x)).2
@[simp] lemma self_add_to_Ico_div_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) :
x + to_Ico_div a hb x • b = to_Ico_mod a hb x :=
rfl
@[simp] lemma self_add_to_Ioc_div_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) :
x + to_Ioc_div a hb x • b = to_Ioc_mod a hb x :=
rfl
@[simp] lemma to_Ico_div_zsmul_add_self (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb x • b + x = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod]
@[simp] lemma to_Ioc_div_zsmul_add_self (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb x • b + x = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod]
@[simp] lemma to_Ico_mod_sub_self (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb x - x = to_Ico_div a hb x • b :=
by rw [to_Ico_mod, add_sub_cancel']
@[simp] lemma to_Ioc_mod_sub_self (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb x - x = to_Ioc_div a hb x • b :=
by rw [to_Ioc_mod, add_sub_cancel']
@[simp] lemma self_sub_to_Ico_mod (a : α) {b : α} (hb : 0 < b) (x : α) :
x - to_Ico_mod a hb x = -to_Ico_div a hb x • b :=
by rw [to_Ico_mod, sub_add_cancel', neg_smul]
@[simp] lemma self_sub_to_Ioc_mod (a : α) {b : α} (hb : 0 < b) (x : α) :
x - to_Ioc_mod a hb x = -to_Ioc_div a hb x • b :=
by rw [to_Ioc_mod, sub_add_cancel', neg_smul]
@[simp] lemma to_Ico_mod_sub_to_Ico_div_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb x - to_Ico_div a hb x • b = x :=
by rw [to_Ico_mod, add_sub_cancel]
@[simp] lemma to_Ioc_mod_sub_to_Ioc_div_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb x - to_Ioc_div a hb x • b = x :=
by rw [to_Ioc_mod, add_sub_cancel]
@[simp] lemma to_Ico_div_zsmul_sub_to_Ico_mod (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb x • b - to_Ico_mod a hb x = -x :=
by rw [←neg_sub, to_Ico_mod_sub_to_Ico_div_zsmul]
@[simp] lemma to_Ioc_div_zsmul_sub_to_Ioc_mod (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb x • b - to_Ioc_mod a hb x = -x :=
by rw [←neg_sub, to_Ioc_mod_sub_to_Ioc_div_zsmul]
lemma to_Ico_mod_eq_iff {a b x y : α} (hb : 0 < b) :
to_Ico_mod a hb x = y ↔ y ∈ set.Ico a (a + b) ∧ ∃ z : ℤ, y - x = z • b :=
begin
refine ⟨λ h, ⟨h ▸ to_Ico_mod_mem_Ico a hb x,
to_Ico_div a hb x,
h ▸ to_Ico_mod_sub_self a hb x⟩,
λ h, _⟩,
rcases h with ⟨hy, z, hz⟩,
rw sub_eq_iff_eq_add' at hz,
subst hz,
rw eq_to_Ico_div_of_add_zsmul_mem_Ico hb hy,
refl
end
lemma to_Ioc_mod_eq_iff {a b x y : α} (hb : 0 < b) :
to_Ioc_mod a hb x = y ↔ y ∈ set.Ioc a (a + b) ∧ ∃ z : ℤ, y - x = z • b :=
begin
refine ⟨λ h, ⟨h ▸ to_Ioc_mod_mem_Ioc a hb x,
to_Ioc_div a hb x,
h ▸ to_Ioc_mod_sub_self a hb x⟩,
λ h, _⟩,
rcases h with ⟨hy, z, hz⟩,
rw sub_eq_iff_eq_add' at hz,
subst hz,
rw eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb hy,
refl
end
@[simp] lemma to_Ico_div_apply_left (a : α) {b : α} (hb : 0 < b) : to_Ico_div a hb a = 0 :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
simp [hb]
end
@[simp] lemma to_Ioc_div_apply_left (a : α) {b : α} (hb : 0 < b) : to_Ioc_div a hb a = 1 :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
simp [hb]
end
@[simp] lemma to_Ico_mod_apply_left (a : α) {b : α} (hb : 0 < b) : to_Ico_mod a hb a = a :=
begin
rw [to_Ico_mod_eq_iff hb, set.left_mem_Ico],
refine ⟨lt_add_of_pos_right _ hb, 0, _⟩,
simp
end
@[simp] lemma to_Ioc_mod_apply_left (a : α) {b : α} (hb : 0 < b) : to_Ioc_mod a hb a = a + b :=
begin
rw [to_Ioc_mod_eq_iff hb, set.right_mem_Ioc],
refine ⟨lt_add_of_pos_right _ hb, 1, _⟩,
simp
end
lemma to_Ico_div_apply_right (a : α) {b : α} (hb : 0 < b) :
to_Ico_div a hb (a + b) = -1 :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
simp [hb]
end
lemma to_Ioc_div_apply_right (a : α) {b : α} (hb : 0 < b) :
to_Ioc_div a hb (a + b) = 0 :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
simp [hb]
end
lemma to_Ico_mod_apply_right (a : α) {b : α} (hb : 0 < b) : to_Ico_mod a hb (a + b) = a :=
begin
rw [to_Ico_mod_eq_iff hb, set.left_mem_Ico],
refine ⟨lt_add_of_pos_right _ hb, -1, _⟩,
simp
end
lemma to_Ioc_mod_apply_right (a : α) {b : α} (hb : 0 < b) :
to_Ioc_mod a hb (a + b) = a + b :=
begin
rw [to_Ioc_mod_eq_iff hb, set.right_mem_Ioc],
refine ⟨lt_add_of_pos_right _ hb, 0, _⟩,
simp
end
@[simp] lemma to_Ico_div_add_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_div a hb (x + m • b) = to_Ico_div a hb x - m :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
convert add_to_Ico_div_zsmul_mem_Ico a hb x using 1,
simp [sub_smul]
end
@[simp] lemma to_Ioc_div_add_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_div a hb (x + m • b) = to_Ioc_div a hb x - m :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
convert add_to_Ioc_div_zsmul_mem_Ioc a hb x using 1,
simp [sub_smul]
end
@[simp] lemma to_Ico_div_zsmul_add (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_div a hb (m • b + x) = to_Ico_div a hb x - m :=
by rw [add_comm, to_Ico_div_add_zsmul]
@[simp] lemma to_Ioc_div_zsmul_add (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_div a hb (m • b + x) = to_Ioc_div a hb x - m :=
by rw [add_comm, to_Ioc_div_add_zsmul]
@[simp] lemma to_Ico_div_sub_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_div a hb (x - m • b) = to_Ico_div a hb x + m :=
by rw [sub_eq_add_neg, ←neg_smul, to_Ico_div_add_zsmul, sub_neg_eq_add]
@[simp] lemma to_Ioc_div_sub_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_div a hb (x - m • b) = to_Ioc_div a hb x + m :=
by rw [sub_eq_add_neg, ←neg_smul, to_Ioc_div_add_zsmul, sub_neg_eq_add]
@[simp] lemma to_Ico_div_add_right (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb (x + b) = to_Ico_div a hb x - 1 :=
begin
convert to_Ico_div_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_div_add_right (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb (x + b) = to_Ioc_div a hb x - 1 :=
begin
convert to_Ioc_div_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ico_div_add_left (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb (b + x) = to_Ico_div a hb x - 1 :=
by rw [add_comm, to_Ico_div_add_right]
@[simp] lemma to_Ioc_div_add_left (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb (b + x) = to_Ioc_div a hb x - 1 :=
by rw [add_comm, to_Ioc_div_add_right]
@[simp] lemma to_Ico_div_sub (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb (x - b) = to_Ico_div a hb x + 1 :=
begin
convert to_Ico_div_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_div_sub (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb (x - b) = to_Ioc_div a hb x + 1 :=
begin
convert to_Ioc_div_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
lemma to_Ico_div_sub' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ico_div a hb (x - y) = to_Ico_div (a + y) hb x :=
begin
rw eq_comm,
apply eq_to_Ico_div_of_add_zsmul_mem_Ico,
rw sub_add_eq_add_sub,
obtain ⟨hc, ho⟩ := add_to_Ico_div_zsmul_mem_Ico (a + y) hb x,
rw add_right_comm at ho,
exact ⟨le_sub_iff_add_le.mpr hc, sub_lt_iff_lt_add.mpr ho⟩,
end
lemma to_Ioc_div_sub' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ioc_div a hb (x - y) = to_Ioc_div (a + y) hb x :=
begin
rw eq_comm,
apply eq_to_Ioc_div_of_add_zsmul_mem_Ioc,
rw sub_add_eq_add_sub,
obtain ⟨ho, hc⟩ := add_to_Ioc_div_zsmul_mem_Ioc (a + y) hb x,
rw add_right_comm at hc,
exact ⟨lt_sub_iff_add_lt.mpr ho, sub_le_iff_le_add.mpr hc⟩,
end
lemma to_Ico_div_add_right' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ico_div a hb (x + y) = to_Ico_div (a - y) hb x :=
by rw [←sub_neg_eq_add, to_Ico_div_sub', sub_eq_add_neg]
lemma to_Ioc_div_add_right' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ioc_div a hb (x + y) = to_Ioc_div (a - y) hb x :=
by rw [←sub_neg_eq_add, to_Ioc_div_sub', sub_eq_add_neg]
lemma to_Ico_div_neg (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb (-x) = 1 - to_Ioc_div (-a) hb x :=
begin
suffices : to_Ico_div a hb (-x) = -(to_Ioc_div (-(a + b)) hb x),
{ rwa [neg_add, ←sub_eq_add_neg, ←to_Ioc_div_add_right', to_Ioc_div_add_right, neg_sub] at this },
rw [eq_neg_iff_eq_neg, eq_comm],
apply eq_to_Ioc_div_of_add_zsmul_mem_Ioc,
obtain ⟨hc, ho⟩ := add_to_Ico_div_zsmul_mem_Ico a hb (-x),
rw [←neg_lt_neg_iff, neg_add (-x), neg_neg, ←neg_smul] at ho,
rw [←neg_le_neg_iff, neg_add (-x), neg_neg, ←neg_smul] at hc,
refine ⟨ho, hc.trans_eq _⟩,
rw [neg_add, neg_add_cancel_right],
end
lemma to_Ioc_div_neg (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb (-x) = 1 - to_Ico_div (-a) hb x :=
by rw [←neg_neg x, to_Ico_div_neg, neg_neg, neg_neg, sub_sub_cancel]
@[simp] lemma to_Ico_mod_add_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_mod a hb (x + m • b) = to_Ico_mod a hb x :=
begin
rw [to_Ico_mod, to_Ico_div_add_zsmul, to_Ico_mod, sub_smul],
abel
end
@[simp] lemma to_Ioc_mod_add_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_mod a hb (x + m • b) = to_Ioc_mod a hb x :=
begin
rw [to_Ioc_mod, to_Ioc_div_add_zsmul, to_Ioc_mod, sub_smul],
abel
end
@[simp] lemma to_Ico_mod_zsmul_add (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_mod a hb (m • b + x) = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod_add_zsmul]
@[simp] lemma to_Ioc_mod_zsmul_add (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_mod a hb (m • b + x) = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod_add_zsmul]
@[simp] lemma to_Ico_mod_sub_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ico_mod a hb (x - m • b) = to_Ico_mod a hb x :=
by rw [sub_eq_add_neg, ←neg_smul, to_Ico_mod_add_zsmul]
@[simp] lemma to_Ioc_mod_sub_zsmul (a : α) {b : α} (hb : 0 < b) (x : α) (m : ℤ) :
to_Ioc_mod a hb (x - m • b) = to_Ioc_mod a hb x :=
by rw [sub_eq_add_neg, ←neg_smul, to_Ioc_mod_add_zsmul]
@[simp] lemma to_Ico_mod_add_right (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb (x + b) = to_Ico_mod a hb x :=
begin
convert to_Ico_mod_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_mod_add_right (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb (x + b) = to_Ioc_mod a hb x :=
begin
convert to_Ioc_mod_add_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ico_mod_add_left (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb (b + x) = to_Ico_mod a hb x :=
by rw [add_comm, to_Ico_mod_add_right]
@[simp] lemma to_Ioc_mod_add_left (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb (b + x) = to_Ioc_mod a hb x :=
by rw [add_comm, to_Ioc_mod_add_right]
@[simp] lemma to_Ico_mod_sub (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb (x - b) = to_Ico_mod a hb x :=
begin
convert to_Ico_mod_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
@[simp] lemma to_Ioc_mod_sub (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb (x - b) = to_Ioc_mod a hb x :=
begin
convert to_Ioc_mod_sub_zsmul a hb x 1,
exact (one_zsmul _).symm
end
lemma to_Ico_mod_sub' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ico_mod a hb (x - y) = to_Ico_mod (a + y) hb x - y :=
by simp_rw [to_Ico_mod, to_Ico_div_sub', sub_add_eq_add_sub]
lemma to_Ioc_mod_sub' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ioc_mod a hb (x - y) = to_Ioc_mod (a + y) hb x - y :=
by simp_rw [to_Ioc_mod, to_Ioc_div_sub', sub_add_eq_add_sub]
lemma to_Ico_mod_add_right' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ico_mod a hb (x + y) = to_Ico_mod (a - y) hb x + y :=
by simp_rw [to_Ico_mod, to_Ico_div_add_right', add_right_comm]
lemma to_Ioc_mod_add_right' (a : α) {b : α} (hb : 0 < b) (x y : α) :
to_Ioc_mod a hb (x + y) = to_Ioc_mod (a - y) hb x + y :=
by simp_rw [to_Ioc_mod, to_Ioc_div_add_right', add_right_comm]
lemma to_Ico_mod_neg (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb (-x) = b - to_Ioc_mod (-a) hb x :=
begin
simp_rw [to_Ico_mod, to_Ioc_mod, to_Ico_div_neg, sub_smul, one_smul],
abel,
end
lemma to_Ioc_mod_neg (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb (-x) = b - to_Ico_mod (-a) hb x :=
begin
simp_rw [to_Ioc_mod, to_Ico_mod, to_Ioc_div_neg, sub_smul, one_smul],
abel,
end
lemma to_Ico_mod_eq_to_Ico_mod (a : α) {b x y : α} (hb : 0 < b) :
to_Ico_mod a hb x = to_Ico_mod a hb y ↔ ∃ z : ℤ, y - x = z • b :=
begin
refine ⟨λ h, ⟨to_Ico_div a hb x - to_Ico_div a hb y, _⟩, λ h, _⟩,
{ conv_lhs { rw [←to_Ico_mod_sub_to_Ico_div_zsmul a hb x,
←to_Ico_mod_sub_to_Ico_div_zsmul a hb y] },
rw [h, sub_smul],
abel },
{ rcases h with ⟨z, hz⟩,
rw sub_eq_iff_eq_add at hz,
rw [hz, to_Ico_mod_zsmul_add] }
end
lemma to_Ioc_mod_eq_to_Ioc_mod (a : α) {b x y : α} (hb : 0 < b) :
to_Ioc_mod a hb x = to_Ioc_mod a hb y ↔ ∃ z : ℤ, y - x = z • b :=
begin
refine ⟨λ h, ⟨to_Ioc_div a hb x - to_Ioc_div a hb y, _⟩, λ h, _⟩,
{ conv_lhs { rw [←to_Ioc_mod_sub_to_Ioc_div_zsmul a hb x,
←to_Ioc_mod_sub_to_Ioc_div_zsmul a hb y] },
rw [h, sub_smul],
abel },
{ rcases h with ⟨z, hz⟩,
rw sub_eq_iff_eq_add at hz,
rw [hz, to_Ioc_mod_zsmul_add] }
end
section Ico_Ioc
variables (a : α) {b : α} (hb : 0 < b) (x : α)
omit hα
/-- `mem_Ioo_mod a b x` means that `x` lies in the open interval `(a, a + b)` modulo `b`.
Equivalently (as shown below), `x` is not congruent to `a` modulo `b`, or `to_Ico_mod a hb` agrees
with `to_Ioc_mod a hb` at `x`, or `to_Ico_div a hb` agrees with `to_Ioc_div a hb` at `x`. -/
def mem_Ioo_mod (b x : α) : Prop := ∃ z : ℤ, x + z • b ∈ set.Ioo a (a + b)
include hα
lemma tfae_mem_Ioo_mod :
tfae [mem_Ioo_mod a b x,
to_Ico_mod a hb x = to_Ioc_mod a hb x,
to_Ico_mod a hb x + b ≠ to_Ioc_mod a hb x,
to_Ico_mod a hb x ≠ a] :=
begin
tfae_have : 1 → 2,
{ exact λ ⟨i, hi⟩,
((to_Ico_mod_eq_iff hb).2 ⟨set.Ioo_subset_Ico_self hi, i, add_sub_cancel' x _⟩).trans
((to_Ioc_mod_eq_iff hb).2 ⟨set.Ioo_subset_Ioc_self hi, i, add_sub_cancel' x _⟩).symm },
tfae_have : 2 → 3,
{ intro h, rw [h, ne, add_right_eq_self], exact hb.ne' },
tfae_have : 3 → 4,
{ refine mt (λ h, _),
rw [h, eq_comm, to_Ioc_mod_eq_iff, set.right_mem_Ioc],
refine ⟨lt_add_of_pos_right a hb, to_Ico_div a hb x + 1, _⟩,
conv_lhs { rw [← h, to_Ico_mod, add_assoc, ← add_one_zsmul, add_sub_cancel'] } },
tfae_have : 4 → 1,
{ have h' := to_Ico_mod_mem_Ico a hb x, exact λ h, ⟨_, h'.1.lt_of_ne' h, h'.2⟩ },
tfae_finish,
end
variables {a x}
lemma mem_Ioo_mod_iff_to_Ico_mod_eq_to_Ioc_mod :
mem_Ioo_mod a b x ↔ to_Ico_mod a hb x = to_Ioc_mod a hb x := (tfae_mem_Ioo_mod a hb x).out 0 1
lemma mem_Ioo_mod_iff_to_Ico_mod_add_period_ne_to_Ioc_mod :
mem_Ioo_mod a b x ↔ to_Ico_mod a hb x + b ≠ to_Ioc_mod a hb x := (tfae_mem_Ioo_mod a hb x).out 0 2
lemma mem_Ioo_mod_iff_to_Ico_mod_ne_left :
mem_Ioo_mod a b x ↔ to_Ico_mod a hb x ≠ a := (tfae_mem_Ioo_mod a hb x).out 0 3
lemma mem_Ioo_mod_iff_to_Ioc_mod_ne_right : mem_Ioo_mod a b x ↔ to_Ioc_mod a hb x ≠ a + b :=
begin
rw [mem_Ioo_mod_iff_to_Ico_mod_eq_to_Ioc_mod, to_Ico_mod_eq_iff hb],
obtain ⟨h₁, h₂⟩ := to_Ioc_mod_mem_Ioc a hb x,
exact ⟨λ h, h.1.2.ne, λ h, ⟨⟨h₁.le, h₂.lt_of_ne h⟩, _, add_sub_cancel' x _⟩⟩,
end
lemma mem_Ioo_mod_iff_to_Ico_div_eq_to_Ioc_div :
mem_Ioo_mod a b x ↔ to_Ico_div a hb x = to_Ioc_div a hb x :=
by rw [mem_Ioo_mod_iff_to_Ico_mod_eq_to_Ioc_mod hb,
to_Ico_mod, to_Ioc_mod, add_right_inj, (zsmul_strict_mono_left hb).injective.eq_iff]
lemma mem_Ioo_mod_iff_to_Ico_div_add_one_ne_to_Ioc_div :
mem_Ioo_mod a b x ↔ to_Ico_div a hb x + 1 ≠ to_Ioc_div a hb x :=
by rw [mem_Ioo_mod_iff_to_Ico_mod_add_period_ne_to_Ioc_mod hb, ne, ne, to_Ico_mod, to_Ioc_mod,
add_assoc, add_right_inj, ← add_one_zsmul, (zsmul_strict_mono_left hb).injective.eq_iff]
include hb
lemma mem_Ioo_mod_iff_sub_ne_zsmul : mem_Ioo_mod a b x ↔ ∀ z : ℤ, a - x ≠ z • b :=
begin
rw [mem_Ioo_mod_iff_to_Ico_mod_ne_left hb, ← not_iff_not],
push_neg, split; intro h,
{ rw ← h,
exact ⟨_, add_sub_cancel' x _⟩ },
{ rw [to_Ico_mod_eq_iff, set.left_mem_Ico],
exact ⟨lt_add_of_pos_right a hb, h⟩, },
end
lemma mem_Ioo_mod_iff_eq_mod_zmultiples :
mem_Ioo_mod a b x ↔ (x : α ⧸ add_subgroup.zmultiples b) ≠ a :=
begin
rw [mem_Ioo_mod_iff_sub_ne_zsmul hb, ne, eq_comm,
quotient_add_group.eq_iff_sub_mem, add_subgroup.mem_zmultiples_iff],
push_neg, simp_rw ne_comm,
end
lemma Ico_eq_locus_Ioc_eq_Union_Ioo :
{x | to_Ico_mod a hb x = to_Ioc_mod a hb x} = ⋃ z : ℤ, set.Ioo (a - z • b) (a + b - z • b) :=
begin
ext1, simp_rw [set.mem_set_of, set.mem_Union, ← set.add_mem_Ioo_iff_left],
exact (mem_Ioo_mod_iff_to_Ico_mod_eq_to_Ioc_mod hb).symm,
end
end Ico_Ioc
lemma to_Ico_mod_eq_self {a b x : α} (hb : 0 < b) : to_Ico_mod a hb x = x ↔ x ∈ set.Ico a (a + b) :=
begin
rw [to_Ico_mod_eq_iff, and_iff_left],
refine ⟨0, _⟩,
simp
end
lemma to_Ioc_mod_eq_self {a b x : α} (hb : 0 < b) : to_Ioc_mod a hb x = x ↔ x ∈ set.Ioc a (a + b) :=
begin
rw [to_Ioc_mod_eq_iff, and_iff_left],
refine ⟨0, _⟩,
simp
end
@[simp] lemma to_Ico_mod_to_Ico_mod (a₁ a₂ : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a₁ hb (to_Ico_mod a₂ hb x) = to_Ico_mod a₁ hb x :=
begin
rw to_Ico_mod_eq_to_Ico_mod,
exact ⟨-to_Ico_div a₂ hb x, self_sub_to_Ico_mod a₂ hb x⟩
end
@[simp] lemma to_Ico_mod_to_Ioc_mod (a₁ a₂ : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a₁ hb (to_Ioc_mod a₂ hb x) = to_Ico_mod a₁ hb x :=
begin
rw to_Ico_mod_eq_to_Ico_mod,
exact ⟨-to_Ioc_div a₂ hb x, self_sub_to_Ioc_mod a₂ hb x⟩
end
@[simp] lemma to_Ioc_mod_to_Ioc_mod (a₁ a₂ : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a₁ hb (to_Ioc_mod a₂ hb x) = to_Ioc_mod a₁ hb x :=
begin
rw to_Ioc_mod_eq_to_Ioc_mod,
exact ⟨-to_Ioc_div a₂ hb x, self_sub_to_Ioc_mod a₂ hb x⟩
end
@[simp] lemma to_Ioc_mod_to_Ico_mod (a₁ a₂ : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a₁ hb (to_Ico_mod a₂ hb x) = to_Ioc_mod a₁ hb x :=
begin
rw to_Ioc_mod_eq_to_Ioc_mod,
exact ⟨-to_Ico_div a₂ hb x, self_sub_to_Ico_mod a₂ hb x⟩
end
lemma to_Ico_mod_periodic (a : α) {b : α} (hb : 0 < b) : function.periodic (to_Ico_mod a hb) b :=
to_Ico_mod_add_right a hb
lemma to_Ioc_mod_periodic (a : α) {b : α} (hb : 0 < b) : function.periodic (to_Ioc_mod a hb) b :=
to_Ioc_mod_add_right a hb
/-- `to_Ico_mod` as an equiv from the quotient. -/
@[simps symm_apply]
def quotient_add_group.equiv_Ico_mod (a : α) {b : α} (hb : 0 < b) :
(α ⧸ add_subgroup.zmultiples b) ≃ set.Ico a (a + b) :=
{ to_fun := λ x, ⟨(to_Ico_mod_periodic a hb).lift x,
quotient_add_group.induction_on' x $ to_Ico_mod_mem_Ico a hb⟩,
inv_fun := coe,
right_inv := λ x, subtype.ext $ (to_Ico_mod_eq_self hb).mpr x.prop,
left_inv := λ x, begin
induction x using quotient_add_group.induction_on',
dsimp,
rw [quotient_add_group.eq_iff_sub_mem, to_Ico_mod_sub_self],
apply add_subgroup.zsmul_mem_zmultiples,
end }
@[simp]
lemma quotient_add_group.equiv_Ico_mod_coe (a : α) {b : α} (hb : 0 < b) (x : α) :
quotient_add_group.equiv_Ico_mod a hb ↑x = ⟨to_Ico_mod a hb x, to_Ico_mod_mem_Ico a hb _⟩ :=
rfl
/-- `to_Ioc_mod` as an equiv from the quotient. -/
@[simps symm_apply]
def quotient_add_group.equiv_Ioc_mod (a : α) {b : α} (hb : 0 < b) :
(α ⧸ add_subgroup.zmultiples b) ≃ set.Ioc a (a + b) :=
{ to_fun := λ x, ⟨(to_Ioc_mod_periodic a hb).lift x,
quotient_add_group.induction_on' x $ to_Ioc_mod_mem_Ioc a hb⟩,
inv_fun := coe,
right_inv := λ x, subtype.ext $ (to_Ioc_mod_eq_self hb).mpr x.prop,
left_inv := λ x, begin
induction x using quotient_add_group.induction_on',
dsimp,
rw [quotient_add_group.eq_iff_sub_mem, to_Ioc_mod_sub_self],
apply add_subgroup.zsmul_mem_zmultiples,
end }
@[simp]
lemma quotient_add_group.equiv_Ioc_mod_coe (a : α) {b : α} (hb : 0 < b) (x : α) :
quotient_add_group.equiv_Ioc_mod a hb ↑x = ⟨to_Ioc_mod a hb x, to_Ioc_mod_mem_Ioc a hb _⟩ :=
rfl
end linear_ordered_add_comm_group
section linear_ordered_field
variables {α : Type*} [linear_ordered_field α] [floor_ring α]
lemma to_Ico_div_eq_neg_floor (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_div a hb x = -⌊(x - a) / b⌋ :=
begin
refine (eq_to_Ico_div_of_add_zsmul_mem_Ico hb _).symm,
rw [set.mem_Ico, zsmul_eq_mul, int.cast_neg, neg_mul, ←sub_nonneg, add_comm, add_sub_assoc,
add_comm, ←sub_eq_add_neg],
refine ⟨int.sub_floor_div_mul_nonneg _ hb, _⟩,
rw [add_comm a, ←sub_lt_iff_lt_add, add_sub_assoc, add_comm, ←sub_eq_add_neg],
exact int.sub_floor_div_mul_lt _ hb
end
lemma to_Ioc_div_eq_floor (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_div a hb x = ⌊(a + b - x) / b⌋ :=
begin
refine (eq_to_Ioc_div_of_add_zsmul_mem_Ioc hb _).symm,
rw [set.mem_Ioc, zsmul_eq_mul, ←sub_nonneg, sub_add_eq_sub_sub],
refine ⟨_, int.sub_floor_div_mul_nonneg _ hb⟩,
rw [←add_lt_add_iff_right b, add_assoc, add_comm x, ←sub_lt_iff_lt_add, add_comm (_ * _),
←sub_lt_iff_lt_add],
exact int.sub_floor_div_mul_lt _ hb
end
lemma to_Ico_div_zero_one (x : α) : to_Ico_div (0 : α) zero_lt_one x = -⌊x⌋ :=
by simp [to_Ico_div_eq_neg_floor]
lemma to_Ico_mod_eq_add_fract_mul (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod a hb x = a + int.fract ((x - a) / b) * b :=
begin
rw [to_Ico_mod, to_Ico_div_eq_neg_floor, int.fract],
field_simp [hb.ne.symm],
ring
end
lemma to_Ico_mod_eq_fract_mul {b : α} (hb : 0 < b) (x : α) :
to_Ico_mod 0 hb x = int.fract (x / b) * b :=
by simp [to_Ico_mod_eq_add_fract_mul]
lemma to_Ioc_mod_eq_sub_fract_mul (a : α) {b : α} (hb : 0 < b) (x : α) :
to_Ioc_mod a hb x = a + b - int.fract ((a + b - x) / b) * b :=
begin
rw [to_Ioc_mod, to_Ioc_div_eq_floor, int.fract],
field_simp [hb.ne.symm],
ring
end
lemma to_Ico_mod_zero_one (x : α) : to_Ico_mod (0 : α) zero_lt_one x = int.fract x :=
by simp [to_Ico_mod_eq_add_fract_mul]
end linear_ordered_field
|
ff2e3f3ba62f6109164a133efe202e425e448679 | cf39355caa609c0f33405126beee2739aa3cb77e | /leanpkg/leanpkg/git.lean | 341de19aa0f264a764f7cbc8b9e5256a61c8615e | [
"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 | 1,444 | lean | /-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Gabriel Ebner
-/
import leanpkg.lean_version system.io
namespace leanpkg
def upstream_git_branch :=
if lean.is_release then
"lean-" ++ lean_version_string_core
else
"master"
def git_default_revision : option string → string
| none := upstream_git_branch
| (some branch) := branch
def git_parse_revision (git_repo_dir : string) (rev : string) : io string := do
rev ← io.cmd {cmd := "git", args := ["rev-parse", "-q", "--verify", rev], cwd := git_repo_dir},
return rev.pop_back -- remove newline at end
def git_head_revision (git_repo_dir : string) : io string :=
git_parse_revision git_repo_dir "HEAD"
def git_parse_origin_revision (git_repo_dir : string) (rev : string) : io string :=
(git_parse_revision git_repo_dir $ "origin/" ++ rev) <|> git_parse_revision git_repo_dir rev
<|> io.fail ("cannot find revision " ++ rev ++ " in repository " ++ git_repo_dir)
def git_latest_origin_revision (git_repo_dir : string) (branch : option string) : io string := do
io.cmd {cmd := "git", args := ["fetch"], cwd := git_repo_dir},
git_parse_origin_revision git_repo_dir (git_default_revision branch)
def git_revision_exists (git_repo_dir : string) (rev : string) : io bool := do
some _ ← optional (git_parse_revision git_repo_dir (rev ++ "^{commit}"))
| pure ff,
pure tt
end leanpkg
|
5160431ae0fb165fe3a36d94bbd3fd5e41e1c8fa | 94e33a31faa76775069b071adea97e86e218a8ee | /src/algebra/big_operators/multiset.lean | a57e533d9e30f4263499ec9dced2ac1810b3698a | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 15,079 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.group_with_zero.power
import data.list.big_operators
import data.multiset.basic
/-!
# Sums and products over multisets
In this file we define products and sums indexed by multisets. This is later used to define products
and sums indexed by finite sets.
## Main declarations
* `multiset.prod`: `s.prod f` is the product of `f i` over all `i ∈ s`. Not to be mistaken with
the cartesian product `multiset.product`.
* `multiset.sum`: `s.sum f` is the sum of `f i` over all `i ∈ s`.
-/
variables {ι α β γ : Type*}
namespace multiset
section comm_monoid
variables [comm_monoid α] {s t : multiset α} {a : α} {m : multiset ι} {f g : ι → α}
/-- Product of a multiset given a commutative monoid structure on `α`.
`prod {a, b, c} = a * b * c` -/
@[to_additive "Sum of a multiset given a commutative additive monoid structure on `α`.
`sum {a, b, c} = a + b + c`"]
def prod : multiset α → α := foldr (*) (λ x y z, by simp [mul_left_comm]) 1
@[to_additive]
lemma prod_eq_foldr (s : multiset α) : prod s = foldr (*) (λ x y z, by simp [mul_left_comm]) 1 s :=
rfl
@[to_additive]
lemma prod_eq_foldl (s : multiset α) : prod s = foldl (*) (λ x y z, by simp [mul_right_comm]) 1 s :=
(foldr_swap _ _ _ _).trans (by simp [mul_comm])
@[simp, norm_cast, to_additive] lemma coe_prod (l : list α) : prod ↑l = l.prod := prod_eq_foldl _
@[simp, to_additive]
lemma prod_to_list (s : multiset α) : s.to_list.prod = s.prod :=
begin
conv_rhs { rw ←coe_to_list s },
rw coe_prod,
end
@[simp, to_additive] lemma prod_zero : @prod α _ 0 = 1 := rfl
@[simp, to_additive]
lemma prod_cons (a : α) (s) : prod (a ::ₘ s) = a * prod s := foldr_cons _ _ _ _ _
@[simp, to_additive]
lemma prod_erase [decidable_eq α] (h : a ∈ s) : a * (s.erase a).prod = s.prod :=
by rw [← s.coe_to_list, coe_erase, coe_prod, coe_prod, list.prod_erase ((s.mem_to_list a).2 h)]
@[simp, to_additive]
lemma prod_singleton (a : α) : prod {a} = a :=
by simp only [mul_one, prod_cons, singleton_eq_cons, eq_self_iff_true, prod_zero]
@[to_additive]
lemma prod_pair (a b : α) : ({a, b} : multiset α).prod = a * b :=
by rw [insert_eq_cons, prod_cons, prod_singleton]
@[simp, to_additive]
lemma prod_add (s t : multiset α) : prod (s + t) = prod s * prod t :=
quotient.induction_on₂ s t $ λ l₁ l₂, by simp
lemma prod_nsmul (m : multiset α) : ∀ (n : ℕ), (n • m).prod = m.prod ^ n
| 0 := by { rw [zero_nsmul, pow_zero], refl }
| (n + 1) :=
by rw [add_nsmul, one_nsmul, pow_add, pow_one, prod_add, prod_nsmul n]
@[simp, to_additive] lemma prod_repeat (a : α) (n : ℕ) : (repeat a n).prod = a ^ n :=
by simp [repeat, list.prod_repeat]
@[to_additive]
lemma pow_count [decidable_eq α] (a : α) : a ^ s.count a = (s.filter (eq a)).prod :=
by rw [filter_eq, prod_repeat]
@[to_additive]
lemma prod_hom [comm_monoid β] (s : multiset α) {F : Type*} [monoid_hom_class F α β] (f : F) :
(s.map f).prod = f s.prod :=
quotient.induction_on s $ λ l, by simp only [l.prod_hom f, quot_mk_to_coe, coe_map, coe_prod]
@[to_additive]
lemma prod_hom' [comm_monoid β] (s : multiset ι) {F : Type*} [monoid_hom_class F α β] (f : F)
(g : ι → α) : (s.map $ λ i, f $ g i).prod = f (s.map g).prod :=
by { convert (s.map g).prod_hom f, exact (map_map _ _ _).symm }
@[to_additive]
lemma prod_hom₂ [comm_monoid β] [comm_monoid γ] (s : multiset ι) (f : α → β → γ)
(hf : ∀ a b c d, f (a * b) (c * d) = f a c * f b d) (hf' : f 1 1 = 1) (f₁ : ι → α) (f₂ : ι → β) :
(s.map $ λ i, f (f₁ i) (f₂ i)).prod = f (s.map f₁).prod (s.map f₂).prod :=
quotient.induction_on s $ λ l,
by simp only [l.prod_hom₂ f hf hf', quot_mk_to_coe, coe_map, coe_prod]
@[to_additive]
lemma prod_hom_rel [comm_monoid β] (s : multiset ι) {r : α → β → Prop} {f : ι → α} {g : ι → β}
(h₁ : r 1 1) (h₂ : ∀ ⦃a b c⦄, r b c → r (f a * b) (g a * c)) :
r (s.map f).prod (s.map g).prod :=
quotient.induction_on s $ λ l,
by simp only [l.prod_hom_rel h₁ h₂, quot_mk_to_coe, coe_map, coe_prod]
@[to_additive]
lemma prod_map_one : prod (m.map (λ i, (1 : α))) = 1 := by rw [map_const, prod_repeat, one_pow]
@[simp, to_additive]
lemma prod_map_mul : (m.map $ λ i, f i * g i).prod = (m.map f).prod * (m.map g).prod :=
m.prod_hom₂ (*) mul_mul_mul_comm (mul_one _) _ _
@[to_additive]
lemma prod_map_pow {n : ℕ} : (m.map $ λ i, f i ^ n).prod = (m.map f).prod ^ n :=
m.prod_hom' (pow_monoid_hom n : α →* α) f
@[to_additive]
lemma prod_map_prod_map (m : multiset β) (n : multiset γ) {f : β → γ → α} :
prod (m.map $ λ a, prod $ n.map $ λ b, f a b) = prod (n.map $ λ b, prod $ m.map $ λ a, f a b) :=
multiset.induction_on m (by simp) (λ a m ih, by simp [ih])
@[to_additive]
lemma prod_induction (p : α → Prop) (s : multiset α) (p_mul : ∀ a b, p a → p b → p (a * b))
(p_one : p 1) (p_s : ∀ a ∈ s, p a) :
p s.prod :=
begin
rw prod_eq_foldr,
exact foldr_induction (*) (λ x y z, by simp [mul_left_comm]) 1 p s p_mul p_one p_s,
end
@[to_additive]
lemma prod_induction_nonempty (p : α → Prop) (p_mul : ∀ a b, p a → p b → p (a * b))
(hs : s ≠ ∅) (p_s : ∀ a ∈ s, p a) :
p s.prod :=
begin
revert s,
refine multiset.induction _ _,
{ intro h,
exfalso,
simpa using h },
intros a s hs hsa hpsa,
rw prod_cons,
by_cases hs_empty : s = ∅,
{ simp [hs_empty, hpsa a] },
have hps : ∀ x, x ∈ s → p x, from λ x hxs, hpsa x (mem_cons_of_mem hxs),
exact p_mul a s.prod (hpsa a (mem_cons_self a s)) (hs hs_empty hps),
end
lemma dvd_prod : a ∈ s → a ∣ s.prod :=
quotient.induction_on s (λ l a h, by simpa using list.dvd_prod h) a
lemma prod_dvd_prod_of_le (h : s ≤ t) : s.prod ∣ t.prod :=
begin
obtain ⟨z, rfl⟩ := multiset.le_iff_exists_add.1 h,
simp only [prod_add, dvd_mul_right],
end
end comm_monoid
lemma prod_dvd_prod_of_dvd [comm_monoid β] {S : multiset α} (g1 g2 : α → β)
(h : ∀ a ∈ S, g1 a ∣ g2 a) :
(multiset.map g1 S).prod ∣ (multiset.map g2 S).prod :=
begin
apply multiset.induction_on' S, { simp },
intros a T haS _ IH,
simp [mul_dvd_mul (h a haS) IH]
end
section add_comm_monoid
variables [add_comm_monoid α]
/-- `multiset.sum`, the sum of the elements of a multiset, promoted to a morphism of
`add_comm_monoid`s. -/
def sum_add_monoid_hom : multiset α →+ α :=
{ to_fun := sum,
map_zero' := sum_zero,
map_add' := sum_add }
@[simp] lemma coe_sum_add_monoid_hom : (sum_add_monoid_hom : multiset α → α) = sum := rfl
end add_comm_monoid
section comm_monoid_with_zero
variables [comm_monoid_with_zero α]
lemma prod_eq_zero {s : multiset α} (h : (0 : α) ∈ s) : s.prod = 0 :=
begin
rcases multiset.exists_cons_of_mem h with ⟨s', hs'⟩,
simp [hs', multiset.prod_cons]
end
variables [no_zero_divisors α] [nontrivial α] {s : multiset α}
lemma prod_eq_zero_iff : s.prod = 0 ↔ (0 : α) ∈ s :=
quotient.induction_on s $ λ l, by { rw [quot_mk_to_coe, coe_prod], exact list.prod_eq_zero_iff }
lemma prod_ne_zero (h : (0 : α) ∉ s) : s.prod ≠ 0 := mt prod_eq_zero_iff.1 h
end comm_monoid_with_zero
section division_comm_monoid
variables [division_comm_monoid α] {m : multiset ι} {f g : ι → α}
@[to_additive] lemma prod_map_inv' (m : multiset α) : (m.map has_inv.inv).prod = m.prod⁻¹ :=
m.prod_hom (inv_monoid_hom : α →* α)
@[simp, to_additive] lemma prod_map_inv : (m.map $ λ i, (f i)⁻¹).prod = (m.map f).prod ⁻¹ :=
by { convert (m.map f).prod_map_inv', rw map_map }
@[simp, to_additive]
lemma prod_map_div : (m.map $ λ i, f i / g i).prod = (m.map f).prod / (m.map g).prod :=
m.prod_hom₂ (/) mul_div_mul_comm (div_one _) _ _
@[to_additive]
lemma prod_map_zpow {n : ℤ} : (m.map $ λ i, f i ^ n).prod = (m.map f).prod ^ n :=
by { convert (m.map f).prod_hom (zpow_group_hom _ : α →* α), rw map_map, refl }
end division_comm_monoid
section non_unital_non_assoc_semiring
variables [non_unital_non_assoc_semiring α] {a : α} {s : multiset ι} {f : ι → α}
lemma _root_.commute.multiset_sum_right (s : multiset α) (a : α) (h : ∀ b ∈ s, commute a b) :
commute a s.sum :=
begin
induction s using quotient.induction_on,
rw [quot_mk_to_coe, coe_sum],
exact commute.list_sum_right _ _ h,
end
lemma _root_.commute.multiset_sum_left (s : multiset α) (b : α) (h : ∀ a ∈ s, commute a b) :
commute s.sum b :=
(commute.multiset_sum_right _ _ $ λ a ha, (h _ ha).symm).symm
lemma sum_map_mul_left : sum (s.map (λ i, a * f i)) = a * sum (s.map f) :=
multiset.induction_on s (by simp) (λ i s ih, by simp [ih, mul_add])
lemma sum_map_mul_right : sum (s.map (λ i, f i * a)) = sum (s.map f) * a :=
multiset.induction_on s (by simp) (λ a s ih, by simp [ih, add_mul])
end non_unital_non_assoc_semiring
section semiring
variables [semiring α]
lemma dvd_sum {a : α} {s : multiset α} : (∀ x ∈ s, a ∣ x) → a ∣ s.sum :=
multiset.induction_on s (λ _, dvd_zero _)
(λ x s ih h, by { rw sum_cons, exact dvd_add
(h _ (mem_cons_self _ _)) (ih $ λ y hy, h _ $ mem_cons.2 $ or.inr hy) })
end semiring
/-! ### Order -/
section ordered_comm_monoid
variables [ordered_comm_monoid α] {s t : multiset α} {a : α}
@[to_additive sum_nonneg]
lemma one_le_prod_of_one_le : (∀ x ∈ s, (1 : α) ≤ x) → 1 ≤ s.prod :=
quotient.induction_on s $ λ l hl, by simpa using list.one_le_prod_of_one_le hl
@[to_additive]
lemma single_le_prod : (∀ x ∈ s, (1 : α) ≤ x) → ∀ x ∈ s, x ≤ s.prod :=
quotient.induction_on s $ λ l hl x hx, by simpa using list.single_le_prod hl x hx
@[to_additive sum_le_card_nsmul]
lemma prod_le_pow_card (s : multiset α) (n : α) (h : ∀ x ∈ s, x ≤ n) : s.prod ≤ n ^ s.card :=
begin
induction s using quotient.induction_on,
simpa using list.prod_le_pow_card _ _ h,
end
@[to_additive all_zero_of_le_zero_le_of_sum_eq_zero]
lemma all_one_of_le_one_le_of_prod_eq_one :
(∀ x ∈ s, (1 : α) ≤ x) → s.prod = 1 → ∀ x ∈ s, x = (1 : α) :=
begin
apply quotient.induction_on s,
simp only [quot_mk_to_coe, coe_prod, mem_coe],
exact λ l, list.all_one_of_le_one_le_of_prod_eq_one,
end
@[to_additive]
lemma prod_le_prod_of_rel_le (h : s.rel (≤) t) : s.prod ≤ t.prod :=
begin
induction h with _ _ _ _ rh _ rt,
{ refl },
{ rw [prod_cons, prod_cons],
exact mul_le_mul' rh rt }
end
@[to_additive]
lemma prod_map_le_prod (f : α → α) (h : ∀ x, x ∈ s → f x ≤ x) : (s.map f).prod ≤ s.prod :=
prod_le_prod_of_rel_le $ rel_map_left.2 $ rel_refl_of_refl_on h
@[to_additive]
lemma prod_le_sum_prod (f : α → α) (h : ∀ x, x ∈ s → x ≤ f x) : s.prod ≤ (s.map f).prod :=
@prod_map_le_prod αᵒᵈ _ _ f h
@[to_additive card_nsmul_le_sum]
lemma pow_card_le_prod (h : ∀ x ∈ s, a ≤ x) : a ^ s.card ≤ s.prod :=
by { rw [←multiset.prod_repeat, ←multiset.map_const], exact prod_map_le_prod _ h }
end ordered_comm_monoid
lemma prod_nonneg [ordered_comm_semiring α] {m : multiset α} (h : ∀ a ∈ m, (0 : α) ≤ a) :
0 ≤ m.prod :=
begin
revert h,
refine m.induction_on _ _,
{ rintro -, rw prod_zero, exact zero_le_one },
intros a s hs ih,
rw prod_cons,
exact mul_nonneg (ih _ $ mem_cons_self _ _) (hs $ λ a ha, ih _ $ mem_cons_of_mem ha),
end
@[to_additive]
lemma prod_eq_one_iff [canonically_ordered_monoid α] {m : multiset α} :
m.prod = 1 ↔ ∀ x ∈ m, x = (1 : α) :=
quotient.induction_on m $ λ l, by simpa using list.prod_eq_one_iff l
@[to_additive]
lemma le_prod_of_mem [canonically_ordered_monoid α] {m : multiset α} {a : α} (h : a ∈ m) :
a ≤ m.prod :=
begin
obtain ⟨m', rfl⟩ := exists_cons_of_mem h,
rw [prod_cons],
exact _root_.le_mul_right (le_refl a),
end
@[to_additive le_sum_of_subadditive_on_pred]
lemma le_prod_of_submultiplicative_on_pred [comm_monoid α] [ordered_comm_monoid β]
(f : α → β) (p : α → Prop) (h_one : f 1 = 1) (hp_one : p 1)
(h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)
(hp_mul : ∀ a b, p a → p b → p (a * b)) (s : multiset α) (hps : ∀ a, a ∈ s → p a) :
f s.prod ≤ (s.map f).prod :=
begin
revert s,
refine multiset.induction _ _,
{ simp [le_of_eq h_one] },
intros a s hs hpsa,
have hps : ∀ x, x ∈ s → p x, from λ x hx, hpsa x (mem_cons_of_mem hx),
have hp_prod : p s.prod, from prod_induction p s hp_mul hp_one hps,
rw [prod_cons, map_cons, prod_cons],
exact (h_mul a s.prod (hpsa a (mem_cons_self a s)) hp_prod).trans (mul_le_mul_left' (hs hps) _),
end
@[to_additive le_sum_of_subadditive]
lemma le_prod_of_submultiplicative [comm_monoid α] [ordered_comm_monoid β]
(f : α → β) (h_one : f 1 = 1) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : multiset α) :
f s.prod ≤ (s.map f).prod :=
le_prod_of_submultiplicative_on_pred f (λ i, true) h_one trivial (λ x y _ _ , h_mul x y) (by simp)
s (by simp)
@[to_additive le_sum_nonempty_of_subadditive_on_pred]
lemma le_prod_nonempty_of_submultiplicative_on_pred [comm_monoid α] [ordered_comm_monoid β]
(f : α → β) (p : α → Prop) (h_mul : ∀ a b, p a → p b → f (a * b) ≤ f a * f b)
(hp_mul : ∀ a b, p a → p b → p (a * b)) (s : multiset α) (hs_nonempty : s ≠ ∅)
(hs : ∀ a, a ∈ s → p a) :
f s.prod ≤ (s.map f).prod :=
begin
revert s,
refine multiset.induction _ _,
{ intro h,
exfalso,
exact h rfl },
rintros a s hs hsa_nonempty hsa_prop,
rw [prod_cons, map_cons, prod_cons],
by_cases hs_empty : s = ∅,
{ simp [hs_empty] },
have hsa_restrict : (∀ x, x ∈ s → p x), from λ x hx, hsa_prop x (mem_cons_of_mem hx),
have hp_sup : p s.prod,
from prod_induction_nonempty p hp_mul hs_empty hsa_restrict,
have hp_a : p a, from hsa_prop a (mem_cons_self a s),
exact (h_mul a _ hp_a hp_sup).trans (mul_le_mul_left' (hs hs_empty hsa_restrict) _),
end
@[to_additive le_sum_nonempty_of_subadditive]
lemma le_prod_nonempty_of_submultiplicative [comm_monoid α] [ordered_comm_monoid β]
(f : α → β) (h_mul : ∀ a b, f (a * b) ≤ f a * f b) (s : multiset α) (hs_nonempty : s ≠ ∅) :
f s.prod ≤ (s.map f).prod :=
le_prod_nonempty_of_submultiplicative_on_pred f (λ i, true) (by simp [h_mul]) (by simp) s
hs_nonempty (by simp)
@[simp] lemma sum_map_singleton (s : multiset α) : (s.map (λ a, ({a} : multiset α))).sum = s :=
multiset.induction_on s (by simp) (by simp [singleton_eq_cons])
lemma abs_sum_le_sum_abs [linear_ordered_add_comm_group α] {s : multiset α} :
abs s.sum ≤ (s.map abs).sum :=
le_sum_of_subadditive _ abs_zero abs_add s
end multiset
@[to_additive]
lemma map_multiset_prod [comm_monoid α] [comm_monoid β] {F : Type*} [monoid_hom_class F α β]
(f : F) (s : multiset α) : f s.prod = (s.map f).prod :=
(s.prod_hom f).symm
@[to_additive]
protected lemma monoid_hom.map_multiset_prod [comm_monoid α] [comm_monoid β] (f : α →* β)
(s : multiset α) : f s.prod = (s.map f).prod :=
(s.prod_hom f).symm
|
8fa008993784d9d72192396297be611d69c5ed5d | fcf3ffa92a3847189ca669cb18b34ef6b2ec2859 | /src/world5/level1.lean | a145a07336cad4b0a635eb3af0ae2cc93f4ed950 | [
"Apache-2.0"
] | permissive | nomoid/lean-proofs | 4a80a97888699dee42b092b7b959b22d9aa0c066 | b9f03a24623d1a1d111d6c2bbf53c617e2596d6a | refs/heads/master | 1,674,955,317,080 | 1,607,475,706,000 | 1,607,475,706,000 | 314,104,281 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 75 | lean | example (P Q : Type) (p : P) (h : P → Q) : Q :=
begin
exact h(p),
end |
50806ae2b837003c3cf337f383caa2f0c60ad307 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/normed/mul_action.lean | 9765c4e68b77f0698916032168e0afd2d78e296f | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 4,552 | lean | /-
Copyright (c) 2023 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import topology.metric_space.algebra
import analysis.normed.field.basic
/-!
# Lemmas for `has_bounded_smul` over normed additive groups
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Lemmas which hold only in `normed_space α β` are provided in another file.
Notably we prove that `non_unital_semi_normed_ring`s have bounded actions by left- and right-
multiplication. This allows downstream files to write general results about `bounded_smul`, and then
deduce `const_mul` and `mul_const` results as an immediate corollary.
-/
variables {α β : Type*}
section seminormed_add_group
variables [seminormed_add_group α] [seminormed_add_group β] [smul_zero_class α β]
variables [has_bounded_smul α β]
lemma norm_smul_le (r : α) (x : β) : ‖r • x‖ ≤ ‖r‖ * ‖x‖ :=
by simpa [smul_zero] using dist_smul_pair r 0 x
lemma nnnorm_smul_le (r : α) (x : β) : ‖r • x‖₊ ≤ ‖r‖₊ * ‖x‖₊ :=
norm_smul_le _ _
lemma dist_smul_le (s : α) (x y : β) : dist (s • x) (s • y) ≤ ‖s‖ * dist x y :=
by simpa only [dist_eq_norm, sub_zero] using dist_smul_pair s x y
lemma nndist_smul_le (s : α) (x y : β) : nndist (s • x) (s • y) ≤ ‖s‖₊ * nndist x y :=
dist_smul_le s x y
lemma edist_smul_le (s : α) (x y : β) : edist (s • x) (s • y) ≤ ‖s‖₊ • edist x y :=
by simpa only [edist_nndist, ennreal.coe_mul] using ennreal.coe_le_coe.mpr (nndist_smul_le s x y)
lemma lipschitz_with_smul (s : α) : lipschitz_with ‖s‖₊ ((•) s : β → β) :=
lipschitz_with_iff_dist_le_mul.2 $ dist_smul_le _
end seminormed_add_group
/-- Left multiplication is bounded. -/
instance non_unital_semi_normed_ring.to_has_bounded_smul [non_unital_semi_normed_ring α] :
has_bounded_smul α α :=
{ dist_smul_pair' := λ x y₁ y₂, by simpa [mul_sub, dist_eq_norm] using norm_mul_le x (y₁ - y₂),
dist_pair_smul' := λ x₁ x₂ y, by simpa [sub_mul, dist_eq_norm] using norm_mul_le (x₁ - x₂) y, }
/-- Right multiplication is bounded. -/
instance non_unital_semi_normed_ring.to_has_bounded_op_smul [non_unital_semi_normed_ring α] :
has_bounded_smul αᵐᵒᵖ α :=
{ dist_smul_pair' := λ x y₁ y₂,
by simpa [sub_mul, dist_eq_norm, mul_comm] using norm_mul_le (y₁ - y₂) x.unop,
dist_pair_smul' := λ x₁ x₂ y,
by simpa [mul_sub, dist_eq_norm, mul_comm] using norm_mul_le y (x₁ - x₂).unop, }
section semi_normed_ring
variables [semi_normed_ring α] [seminormed_add_comm_group β] [module α β]
lemma has_bounded_smul.of_norm_smul_le (h : ∀ (r : α) (x : β), ‖r • x‖ ≤ ‖r‖ * ‖x‖) :
has_bounded_smul α β :=
{ dist_smul_pair' := λ a b₁ b₂, by simpa [smul_sub, dist_eq_norm] using h a (b₁ - b₂),
dist_pair_smul' := λ a₁ a₂ b, by simpa [sub_smul, dist_eq_norm] using h (a₁ - a₂) b }
end semi_normed_ring
section normed_division_ring
variables [normed_division_ring α] [seminormed_add_group β]
variables [mul_action_with_zero α β] [has_bounded_smul α β]
lemma norm_smul (r : α) (x : β) : ‖r • x‖ = ‖r‖ * ‖x‖ :=
begin
by_cases h : r = 0,
{ simp [h, zero_smul α x] },
{ refine le_antisymm (norm_smul_le r x) _,
calc ‖r‖ * ‖x‖ = ‖r‖ * ‖r⁻¹ • r • x‖ : by rw [inv_smul_smul₀ h]
... ≤ ‖r‖ * (‖r⁻¹‖ * ‖r • x‖) :
mul_le_mul_of_nonneg_left (norm_smul_le _ _) (norm_nonneg _)
... = ‖r • x‖ :
by rw [norm_inv, ← mul_assoc, mul_inv_cancel (mt norm_eq_zero.1 h), one_mul] }
end
lemma nnnorm_smul (r : α) (x : β) : ‖r • x‖₊ = ‖r‖₊ * ‖x‖₊ :=
nnreal.eq $ norm_smul r x
end normed_division_ring
section normed_division_ring_module
variables [normed_division_ring α] [seminormed_add_comm_group β]
variables [module α β] [has_bounded_smul α β]
lemma dist_smul₀ (s : α) (x y : β) : dist (s • x) (s • y) = ‖s‖ * dist x y :=
by simp_rw [dist_eq_norm, (norm_smul _ _).symm, smul_sub]
lemma nndist_smul₀ (s : α) (x y : β) : nndist (s • x) (s • y) = ‖s‖₊ * nndist x y :=
nnreal.eq $ dist_smul₀ s x y
lemma edist_smul₀ (s : α) (x y : β) : edist (s • x) (s • y) = ‖s‖₊ • edist x y :=
by simp only [edist_nndist, nndist_smul₀, ennreal.coe_mul, ennreal.smul_def, smul_eq_mul]
end normed_division_ring_module
|
d9e26251dc62a261a863ee44281ba24ca82f0130 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/SemiRng.lean | 4e55cf776e4c89ed9dce9279387867f9ffabda65 | [] | no_license | ysharoda/Deriving-Definitions | 3e149e6641fae440badd35ac110a0bd705a49ad2 | dfecb27572022de3d4aa702cae8db19957523a59 | refs/heads/master | 1,679,127,857,700 | 1,615,939,007,000 | 1,615,939,007,000 | 229,785,731 | 4 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,735 | lean | import init.data.nat.basic
import init.data.fin.basic
import data.vector
import .Prelude
open Staged
open nat
open fin
open vector
section SemiRng
structure SemiRng (A : Type) : Type :=
(times : (A → (A → A)))
(plus : (A → (A → A)))
(zero : A)
(lunit_zero : (∀ {x : A} , (plus zero x) = x))
(runit_zero : (∀ {x : A} , (plus x zero) = x))
(associative_plus : (∀ {x y z : A} , (plus (plus x y) z) = (plus x (plus y z))))
(commutative_plus : (∀ {x y : A} , (plus x y) = (plus y x)))
(associative_times : (∀ {x y z : A} , (times (times x y) z) = (times x (times y z))))
(leftDistributive_times_plus : (∀ {x y z : A} , (times x (plus y z)) = (plus (times x y) (times x z))))
(rightDistributive_times_plus : (∀ {x y z : A} , (times (plus y z) x) = (plus (times y x) (times z x))))
open SemiRng
structure Sig (AS : Type) : Type :=
(timesS : (AS → (AS → AS)))
(plusS : (AS → (AS → AS)))
(zeroS : AS)
structure Product (A : Type) : Type :=
(timesP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(plusP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(zeroP : (Prod A A))
(lunit_0P : (∀ {xP : (Prod A A)} , (plusP zeroP xP) = xP))
(runit_0P : (∀ {xP : (Prod A A)} , (plusP xP zeroP) = xP))
(associative_plusP : (∀ {xP yP zP : (Prod A A)} , (plusP (plusP xP yP) zP) = (plusP xP (plusP yP zP))))
(commutative_plusP : (∀ {xP yP : (Prod A A)} , (plusP xP yP) = (plusP yP xP)))
(associative_timesP : (∀ {xP yP zP : (Prod A A)} , (timesP (timesP xP yP) zP) = (timesP xP (timesP yP zP))))
(leftDistributive_times_plusP : (∀ {xP yP zP : (Prod A A)} , (timesP xP (plusP yP zP)) = (plusP (timesP xP yP) (timesP xP zP))))
(rightDistributive_times_plusP : (∀ {xP yP zP : (Prod A A)} , (timesP (plusP yP zP) xP) = (plusP (timesP yP xP) (timesP zP xP))))
structure Hom {A1 : Type} {A2 : Type} (Se1 : (SemiRng A1)) (Se2 : (SemiRng A2)) : Type :=
(hom : (A1 → A2))
(pres_times : (∀ {x1 x2 : A1} , (hom ((times Se1) x1 x2)) = ((times Se2) (hom x1) (hom x2))))
(pres_plus : (∀ {x1 x2 : A1} , (hom ((plus Se1) x1 x2)) = ((plus Se2) (hom x1) (hom x2))))
(pres_zero : (hom (zero Se1)) = (zero Se2))
structure RelInterp {A1 : Type} {A2 : Type} (Se1 : (SemiRng A1)) (Se2 : (SemiRng A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_times : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((times Se1) x1 x2) ((times Se2) y1 y2))))))
(interp_plus : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((plus Se1) x1 x2) ((plus Se2) y1 y2))))))
(interp_zero : (interp (zero Se1) (zero Se2)))
inductive SemiRngTerm : Type
| timesL : (SemiRngTerm → (SemiRngTerm → SemiRngTerm))
| plusL : (SemiRngTerm → (SemiRngTerm → SemiRngTerm))
| zeroL : SemiRngTerm
open SemiRngTerm
inductive ClSemiRngTerm (A : Type) : Type
| sing : (A → ClSemiRngTerm)
| timesCl : (ClSemiRngTerm → (ClSemiRngTerm → ClSemiRngTerm))
| plusCl : (ClSemiRngTerm → (ClSemiRngTerm → ClSemiRngTerm))
| zeroCl : ClSemiRngTerm
open ClSemiRngTerm
inductive OpSemiRngTerm (n : ℕ) : Type
| v : ((fin n) → OpSemiRngTerm)
| timesOL : (OpSemiRngTerm → (OpSemiRngTerm → OpSemiRngTerm))
| plusOL : (OpSemiRngTerm → (OpSemiRngTerm → OpSemiRngTerm))
| zeroOL : OpSemiRngTerm
open OpSemiRngTerm
inductive OpSemiRngTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpSemiRngTerm2)
| sing2 : (A → OpSemiRngTerm2)
| timesOL2 : (OpSemiRngTerm2 → (OpSemiRngTerm2 → OpSemiRngTerm2))
| plusOL2 : (OpSemiRngTerm2 → (OpSemiRngTerm2 → OpSemiRngTerm2))
| zeroOL2 : OpSemiRngTerm2
open OpSemiRngTerm2
def simplifyCl {A : Type} : ((ClSemiRngTerm A) → (ClSemiRngTerm A))
| (plusCl zeroCl x) := x
| (plusCl x zeroCl) := x
| (timesCl x1 x2) := (timesCl (simplifyCl x1) (simplifyCl x2))
| (plusCl x1 x2) := (plusCl (simplifyCl x1) (simplifyCl x2))
| zeroCl := zeroCl
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpSemiRngTerm n) → (OpSemiRngTerm n))
| (plusOL zeroOL x) := x
| (plusOL x zeroOL) := x
| (timesOL x1 x2) := (timesOL (simplifyOpB x1) (simplifyOpB x2))
| (plusOL x1 x2) := (plusOL (simplifyOpB x1) (simplifyOpB x2))
| zeroOL := zeroOL
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpSemiRngTerm2 n A) → (OpSemiRngTerm2 n A))
| (plusOL2 zeroOL2 x) := x
| (plusOL2 x zeroOL2) := x
| (timesOL2 x1 x2) := (timesOL2 (simplifyOp x1) (simplifyOp x2))
| (plusOL2 x1 x2) := (plusOL2 (simplifyOp x1) (simplifyOp x2))
| zeroOL2 := zeroOL2
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((SemiRng A) → (SemiRngTerm → A))
| Se (timesL x1 x2) := ((times Se) (evalB Se x1) (evalB Se x2))
| Se (plusL x1 x2) := ((plus Se) (evalB Se x1) (evalB Se x2))
| Se zeroL := (zero Se)
def evalCl {A : Type} : ((SemiRng A) → ((ClSemiRngTerm A) → A))
| Se (sing x1) := x1
| Se (timesCl x1 x2) := ((times Se) (evalCl Se x1) (evalCl Se x2))
| Se (plusCl x1 x2) := ((plus Se) (evalCl Se x1) (evalCl Se x2))
| Se zeroCl := (zero Se)
def evalOpB {A : Type} {n : ℕ} : ((SemiRng A) → ((vector A n) → ((OpSemiRngTerm n) → A)))
| Se vars (v x1) := (nth vars x1)
| Se vars (timesOL x1 x2) := ((times Se) (evalOpB Se vars x1) (evalOpB Se vars x2))
| Se vars (plusOL x1 x2) := ((plus Se) (evalOpB Se vars x1) (evalOpB Se vars x2))
| Se vars zeroOL := (zero Se)
def evalOp {A : Type} {n : ℕ} : ((SemiRng A) → ((vector A n) → ((OpSemiRngTerm2 n A) → A)))
| Se vars (v2 x1) := (nth vars x1)
| Se vars (sing2 x1) := x1
| Se vars (timesOL2 x1 x2) := ((times Se) (evalOp Se vars x1) (evalOp Se vars x2))
| Se vars (plusOL2 x1 x2) := ((plus Se) (evalOp Se vars x1) (evalOp Se vars x2))
| Se vars zeroOL2 := (zero Se)
def inductionB {P : (SemiRngTerm → Type)} : ((∀ (x1 x2 : SemiRngTerm) , ((P x1) → ((P x2) → (P (timesL x1 x2))))) → ((∀ (x1 x2 : SemiRngTerm) , ((P x1) → ((P x2) → (P (plusL x1 x2))))) → ((P zeroL) → (∀ (x : SemiRngTerm) , (P x)))))
| ptimesl pplusl p0l (timesL x1 x2) := (ptimesl _ _ (inductionB ptimesl pplusl p0l x1) (inductionB ptimesl pplusl p0l x2))
| ptimesl pplusl p0l (plusL x1 x2) := (pplusl _ _ (inductionB ptimesl pplusl p0l x1) (inductionB ptimesl pplusl p0l x2))
| ptimesl pplusl p0l zeroL := p0l
def inductionCl {A : Type} {P : ((ClSemiRngTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClSemiRngTerm A)) , ((P x1) → ((P x2) → (P (timesCl x1 x2))))) → ((∀ (x1 x2 : (ClSemiRngTerm A)) , ((P x1) → ((P x2) → (P (plusCl x1 x2))))) → ((P zeroCl) → (∀ (x : (ClSemiRngTerm A)) , (P x))))))
| psing ptimescl ppluscl p0cl (sing x1) := (psing x1)
| psing ptimescl ppluscl p0cl (timesCl x1 x2) := (ptimescl _ _ (inductionCl psing ptimescl ppluscl p0cl x1) (inductionCl psing ptimescl ppluscl p0cl x2))
| psing ptimescl ppluscl p0cl (plusCl x1 x2) := (ppluscl _ _ (inductionCl psing ptimescl ppluscl p0cl x1) (inductionCl psing ptimescl ppluscl p0cl x2))
| psing ptimescl ppluscl p0cl zeroCl := p0cl
def inductionOpB {n : ℕ} {P : ((OpSemiRngTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpSemiRngTerm n)) , ((P x1) → ((P x2) → (P (timesOL x1 x2))))) → ((∀ (x1 x2 : (OpSemiRngTerm n)) , ((P x1) → ((P x2) → (P (plusOL x1 x2))))) → ((P zeroOL) → (∀ (x : (OpSemiRngTerm n)) , (P x))))))
| pv ptimesol pplusol p0ol (v x1) := (pv x1)
| pv ptimesol pplusol p0ol (timesOL x1 x2) := (ptimesol _ _ (inductionOpB pv ptimesol pplusol p0ol x1) (inductionOpB pv ptimesol pplusol p0ol x2))
| pv ptimesol pplusol p0ol (plusOL x1 x2) := (pplusol _ _ (inductionOpB pv ptimesol pplusol p0ol x1) (inductionOpB pv ptimesol pplusol p0ol x2))
| pv ptimesol pplusol p0ol zeroOL := p0ol
def inductionOp {n : ℕ} {A : Type} {P : ((OpSemiRngTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpSemiRngTerm2 n A)) , ((P x1) → ((P x2) → (P (timesOL2 x1 x2))))) → ((∀ (x1 x2 : (OpSemiRngTerm2 n A)) , ((P x1) → ((P x2) → (P (plusOL2 x1 x2))))) → ((P zeroOL2) → (∀ (x : (OpSemiRngTerm2 n A)) , (P x)))))))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 (v2 x1) := (pv2 x1)
| pv2 psing2 ptimesol2 pplusol2 p0ol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 ptimesol2 pplusol2 p0ol2 (timesOL2 x1 x2) := (ptimesol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 x2))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 (plusOL2 x1 x2) := (pplusol2 _ _ (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 x1) (inductionOp pv2 psing2 ptimesol2 pplusol2 p0ol2 x2))
| pv2 psing2 ptimesol2 pplusol2 p0ol2 zeroOL2 := p0ol2
def stageB : (SemiRngTerm → (Staged SemiRngTerm))
| (timesL x1 x2) := (stage2 timesL (codeLift2 timesL) (stageB x1) (stageB x2))
| (plusL x1 x2) := (stage2 plusL (codeLift2 plusL) (stageB x1) (stageB x2))
| zeroL := (Now zeroL)
def stageCl {A : Type} : ((ClSemiRngTerm A) → (Staged (ClSemiRngTerm A)))
| (sing x1) := (Now (sing x1))
| (timesCl x1 x2) := (stage2 timesCl (codeLift2 timesCl) (stageCl x1) (stageCl x2))
| (plusCl x1 x2) := (stage2 plusCl (codeLift2 plusCl) (stageCl x1) (stageCl x2))
| zeroCl := (Now zeroCl)
def stageOpB {n : ℕ} : ((OpSemiRngTerm n) → (Staged (OpSemiRngTerm n)))
| (v x1) := (const (code (v x1)))
| (timesOL x1 x2) := (stage2 timesOL (codeLift2 timesOL) (stageOpB x1) (stageOpB x2))
| (plusOL x1 x2) := (stage2 plusOL (codeLift2 plusOL) (stageOpB x1) (stageOpB x2))
| zeroOL := (Now zeroOL)
def stageOp {n : ℕ} {A : Type} : ((OpSemiRngTerm2 n A) → (Staged (OpSemiRngTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (timesOL2 x1 x2) := (stage2 timesOL2 (codeLift2 timesOL2) (stageOp x1) (stageOp x2))
| (plusOL2 x1 x2) := (stage2 plusOL2 (codeLift2 plusOL2) (stageOp x1) (stageOp x2))
| zeroOL2 := (Now zeroOL2)
structure StagedRepr (A : Type) (Repr : (Type → Type)) : Type :=
(timesT : ((Repr A) → ((Repr A) → (Repr A))))
(plusT : ((Repr A) → ((Repr A) → (Repr A))))
(zeroT : (Repr A))
end SemiRng |
c2bd809fbfb4312bf56e8eeccc5c83c8378306c8 | 206422fb9edabf63def0ed2aa3f489150fb09ccb | /src/measure_theory/haar_measure.lean | 23d9097b58b526367c1fe2039bd4ab977a98ada4 | [
"Apache-2.0"
] | permissive | hamdysalah1/mathlib | b915f86b2503feeae268de369f1b16932321f097 | 95454452f6b3569bf967d35aab8d852b1ddf8017 | refs/heads/master | 1,677,154,116,545 | 1,611,797,994,000 | 1,611,797,994,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 31,055 | lean | /-
Copyright (c) 2020 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import measure_theory.content
import measure_theory.prod_group
/-!
# Haar measure
In this file we prove the existence of Haar measure for a locally compact Hausdorff topological
group.
For the construction, we follow the write-up by Jonathan Gleason,
*Existence and Uniqueness of Haar Measure*.
This is essentially the same argument as in
https://en.wikipedia.org/wiki/Haar_measure#A_construction_using_compact_subsets.
We construct the Haar measure first on compact sets. For this we define `(K : U)` as the (smallest)
number of left-translates of `U` are needed to cover `K` (`index` in the formalization).
Then we define a function `h` on compact sets as `lim_U (K : U) / (K₀ : U)`,
where `U` becomes a smaller and smaller open neighborhood of `1`, and `K₀` is a fixed compact set
with nonempty interior. This function is `chaar` in the formalization, and we define the limit
formally using Tychonoff's theorem.
This function `h` forms a content, which we can extend to an outer measure `μ`
(`haar_outer_measure`), and obtain the Haar measure from that (`haar_measure`).
We normalize the Haar measure so that the measure of `K₀` is `1`.
We show that for second countable spaces any left invariant Borel measure is a scalar multiple of
the Haar measure.
Note that `μ` need not coincide with `h` on compact sets, according to
[halmos1950measure, ch. X, §53 p.233]. However, we know that `h(K)` lies between `μ(Kᵒ)` and `μ(K)`,
where `ᵒ` denotes the interior.
## Main Declarations
* `haar_measure`: the Haar measure on a locally compact Hausdorff group. This is a left invariant
regular measure. It takes as argument a compact set of the group (with non-empty interior),
and is normalized so that the measure of the given set is 1.
* `haar_measure_self`: the Haar measure is normalized.
* `is_left_invariant_haar_measure`: the Haar measure is left invariant.
* `regular_haar_measure`: the Haar measure is a regular measure.
## References
* Paul Halmos (1950), Measure Theory, §53
* Jonathan Gleason, Existence and Uniqueness of Haar Measure
- Note: step 9, page 8 contains a mistake: the last defined `μ` does not extend the `μ` on compact
sets, see Halmos (1950) p. 233, bottom of the page. This makes some other steps (like step 11)
invalid.
* https://en.wikipedia.org/wiki/Haar_measure
-/
noncomputable theory
open set has_inv function topological_space measurable_space
open_locale nnreal classical
variables {G : Type*} [group G]
namespace measure_theory
namespace measure
/-! We put the internal functions in the construction of the Haar measure in a namespace,
so that the chosen names don't clash with other declarations.
We first define a couple of the functions before proving the properties (that require that `G`
is a topological group). -/
namespace haar
/-- The index or Haar covering number or ratio of `K` w.r.t. `V`, denoted `(K : V)`:
it is the smallest number of (left) translates of `V` that is necessary to cover `K`.
It is defined to be 0 if no finite number of translates cover `K`. -/
def index (K V : set G) : ℕ :=
Inf $ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V }
lemma index_empty {V : set G} : index ∅ V = 0 :=
begin
simp only [index, nat.Inf_eq_zero], left, use ∅,
simp only [finset.card_empty, empty_subset, mem_set_of_eq, eq_self_iff_true, and_self],
end
variables [topological_space G]
/-- `prehaar K₀ U K` is a weighted version of the index, defined as `(K : U)/(K₀ : U)`.
In the applications `K₀` is compact with non-empty interior, `U` is open containing `1`,
and `K` is any compact set.
The argument `K` is a (bundled) compact set, so that we can consider `prehaar K₀ U` as an
element of `haar_product` (below). -/
def prehaar (K₀ U : set G) (K : compacts G) : ℝ := (index K.1 U : ℝ) / index K₀ U
lemma prehaar_empty (K₀ : positive_compacts G) {U : set G} : prehaar K₀.1 U ⊥ = 0 :=
by { simp only [prehaar, compacts.bot_val, index_empty, nat.cast_zero, zero_div] }
lemma prehaar_nonneg (K₀ : positive_compacts G) {U : set G} (K : compacts G) :
0 ≤ prehaar K₀.1 U K :=
by apply div_nonneg; norm_cast; apply zero_le
/-- `haar_product K₀` is the product of intervals `[0, (K : K₀)]`, for all compact sets `K`.
For all `U`, we can show that `prehaar K₀ U ∈ haar_product K₀`. -/
def haar_product (K₀ : set G) : set (compacts G → ℝ) :=
pi univ (λ K, Icc 0 $ index K.1 K₀)
@[simp] lemma mem_prehaar_empty {K₀ : set G} {f : compacts G → ℝ} :
f ∈ haar_product K₀ ↔ ∀ K : compacts G, f K ∈ Icc (0 : ℝ) (index K.1 K₀) :=
by simp only [haar_product, pi, forall_prop_of_true, mem_univ, mem_set_of_eq]
/-- The closure of the collection of elements of the form `prehaar K₀ U`,
for `U` open neighbourhoods of `1`, contained in `V`. The closure is taken in the space
`compacts G → ℝ`, with the topology of pointwise convergence.
We show that the intersection of all these sets is nonempty, and the Haar measure
on compact sets is defined to be an element in the closure of this intersection. -/
def cl_prehaar (K₀ : set G) (V : open_nhds_of (1 : G)) : set (compacts G → ℝ) :=
closure $ prehaar K₀ '' { U : set G | U ⊆ V.1 ∧ is_open U ∧ (1 : G) ∈ U }
variables [topological_group G]
/-!
### Lemmas about `index`
-/
/-- If `K` is compact and `V` has nonempty interior, then the index `(K : V)` is well-defined,
there is a finite set `t` satisfying the desired properties. -/
lemma index_defined {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) :
∃ n : ℕ, n ∈ finset.card '' {t : finset G | K ⊆ ⋃ g ∈ t, (λ h, g * h) ⁻¹' V } :=
by { rcases compact_covered_by_mul_left_translates hK hV with ⟨t, ht⟩, exact ⟨t.card, t, ht, rfl⟩ }
lemma index_elim {K V : set G} (hK : is_compact K) (hV : (interior V).nonempty) :
∃ (t : finset G), K ⊆ (⋃ g ∈ t, (λ h, g * h) ⁻¹' V) ∧ finset.card t = index K V :=
by { have := nat.Inf_mem (index_defined hK hV), rwa [mem_image] at this }
lemma le_index_mul (K₀ : positive_compacts G) (K : compacts G) {V : set G}
(hV : (interior V).nonempty) : index K.1 V ≤ index K.1 K₀.1 * index K₀.1 V :=
begin
rcases index_elim K.2 K₀.2.2 with ⟨s, h1s, h2s⟩,
rcases index_elim K₀.2.1 hV with ⟨t, h1t, h2t⟩,
rw [← h2s, ← h2t, mul_comm],
refine le_trans _ finset.mul_card_le,
apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq], refine subset.trans h1s _,
apply bUnion_subset, intros g₁ hg₁, rw preimage_subset_iff, intros g₂ hg₂,
have := h1t hg₂,
rcases this with ⟨_, ⟨g₃, rfl⟩, A, ⟨hg₃, rfl⟩, h2V⟩, rw [mem_preimage, ← mul_assoc] at h2V,
exact mem_bUnion (finset.mul_mem_mul hg₃ hg₁) h2V
end
lemma index_pos (K : positive_compacts G) {V : set G} (hV : (interior V).nonempty) :
0 < index K.1 V :=
begin
unfold index, rw [nat.Inf_def, nat.find_pos, mem_image],
{ rintro ⟨t, h1t, h2t⟩, rw [finset.card_eq_zero] at h2t, subst h2t,
cases K.2.2 with g hg,
show g ∈ (∅ : set G), convert h1t (interior_subset hg), symmetry, apply bUnion_empty },
{ exact index_defined K.2.1 hV }
end
lemma index_mono {K K' V : set G} (hK' : is_compact K') (h : K ⊆ K')
(hV : (interior V).nonempty) : index K V ≤ index K' V :=
begin
rcases index_elim hK' hV with ⟨s, h1s, h2s⟩,
apply nat.Inf_le, rw [mem_image], refine ⟨s, subset.trans h h1s, h2s⟩
end
lemma index_union_le (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty) :
index (K₁.1 ∪ K₂.1) V ≤ index K₁.1 V + index K₂.1 V :=
begin
rcases index_elim K₁.2 hV with ⟨s, h1s, h2s⟩,
rcases index_elim K₂.2 hV with ⟨t, h1t, h2t⟩,
rw [← h2s, ← h2t],
refine le_trans _ (finset.card_union_le _ _),
apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq],
apply union_subset; refine subset.trans (by assumption) _; apply bUnion_subset_bUnion_left;
intros g hg; simp only [mem_def] at hg;
simp only [mem_def, multiset.mem_union, finset.union_val, hg, or_true, true_or]
end
lemma index_union_eq (K₁ K₂ : compacts G) {V : set G} (hV : (interior V).nonempty)
(h : disjoint (K₁.1 * V⁻¹) (K₂.1 * V⁻¹)) :
index (K₁.1 ∪ K₂.1) V = index K₁.1 V + index K₂.1 V :=
begin
apply le_antisymm (index_union_le K₁ K₂ hV),
rcases index_elim (K₁.2.union K₂.2) hV with ⟨s, h1s, h2s⟩, rw [← h2s],
have : ∀(K : set G) , K ⊆ (⋃ g ∈ s, (λ h, g * h) ⁻¹' V) →
index K V ≤ (s.filter (λ g, ((λ (h : G), g * h) ⁻¹' V ∩ K).nonempty)).card,
{ intros K hK, apply nat.Inf_le, refine ⟨_, _, rfl⟩, rw [mem_set_of_eq],
intros g hg, rcases hK hg with ⟨_, ⟨g₀, rfl⟩, _, ⟨h1g₀, rfl⟩, h2g₀⟩,
simp only [mem_preimage] at h2g₀,
simp only [mem_Union], use g₀, split,
{ simp only [finset.mem_filter, h1g₀, true_and], use g,
simp only [hg, h2g₀, mem_inter_eq, mem_preimage, and_self] },
exact h2g₀ },
refine le_trans (add_le_add (this K₁.1 $ subset.trans (subset_union_left _ _) h1s)
(this K₂.1 $ subset.trans (subset_union_right _ _) h1s)) _,
rw [← finset.card_union_eq, finset.filter_union_right],
{ apply finset.card_le_of_subset, apply finset.filter_subset },
apply finset.disjoint_filter.mpr,
rintro g₁ h1g₁ ⟨g₂, h1g₂, h2g₂⟩ ⟨g₃, h1g₃, h2g₃⟩,
simp only [mem_preimage] at h1g₃ h1g₂,
apply @h g₁⁻¹,
split; simp only [set.mem_inv, set.mem_mul, exists_exists_and_eq_and, exists_and_distrib_left],
{ refine ⟨_, h2g₂, (g₁ * g₂)⁻¹, _, _⟩, simp only [inv_inv, h1g₂],
simp only [mul_inv_rev, mul_inv_cancel_left] },
{ refine ⟨_, h2g₃, (g₁ * g₃)⁻¹, _, _⟩, simp only [inv_inv, h1g₃],
simp only [mul_inv_rev, mul_inv_cancel_left] }
end
lemma mul_left_index_le {K : set G} (hK : is_compact K) {V : set G} (hV : (interior V).nonempty)
(g : G) : index ((λ h, g * h) '' K) V ≤ index K V :=
begin
rcases index_elim hK hV with ⟨s, h1s, h2s⟩, rw [← h2s],
apply nat.Inf_le, rw [mem_image],
refine ⟨s.map (equiv.mul_right g⁻¹).to_embedding, _, finset.card_map _⟩,
{ simp only [mem_set_of_eq], refine subset.trans (image_subset _ h1s) _,
rintro _ ⟨g₁, ⟨_, ⟨g₂, rfl⟩, ⟨_, ⟨hg₂, rfl⟩, hg₁⟩⟩, rfl⟩,
simp only [mem_preimage] at hg₁, simp only [exists_prop, mem_Union, finset.mem_map,
equiv.coe_mul_right, exists_exists_and_eq_and, mem_preimage, equiv.to_embedding_apply],
refine ⟨_, hg₂, _⟩, simp only [mul_assoc, hg₁, inv_mul_cancel_left] }
end
lemma is_left_invariant_index {K : set G} (hK : is_compact K) (g : G) {V : set G}
(hV : (interior V).nonempty) : index ((λ h, g * h) '' K) V = index K V :=
begin
refine le_antisymm (mul_left_index_le hK hV g) _,
convert mul_left_index_le (hK.image $ continuous_mul_left g) hV g⁻¹,
rw [image_image], symmetry, convert image_id' _, ext h, apply inv_mul_cancel_left
end
/-!
### Lemmas about `prehaar`
-/
lemma prehaar_le_index (K₀ : positive_compacts G) {U : set G} (K : compacts G)
(hU : (interior U).nonempty) : prehaar K₀.1 U K ≤ index K.1 K₀.1 :=
begin
unfold prehaar, rw [div_le_iff]; norm_cast,
{ apply le_index_mul K₀ K hU },
{ exact index_pos K₀ hU }
end
lemma prehaar_pos (K₀ : positive_compacts G) {U : set G} (hU : (interior U).nonempty)
{K : set G} (h1K : is_compact K) (h2K : (interior K).nonempty) : 0 < prehaar K₀.1 U ⟨K, h1K⟩ :=
by { apply div_pos; norm_cast, apply index_pos ⟨K, h1K, h2K⟩ hU, exact index_pos K₀ hU }
lemma prehaar_mono {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty)
{K₁ K₂ : compacts G} (h : K₁.1 ⊆ K₂.1) : prehaar K₀.1 U K₁ ≤ prehaar K₀.1 U K₂ :=
begin
simp only [prehaar], rw [div_le_div_right], exact_mod_cast index_mono K₂.2 h hU,
exact_mod_cast index_pos K₀ hU
end
lemma prehaar_self {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty) :
prehaar K₀.1 U ⟨K₀.1, K₀.2.1⟩ = 1 :=
by { simp only [prehaar], rw [div_self], apply ne_of_gt, exact_mod_cast index_pos K₀ hU }
lemma prehaar_sup_le {K₀ : positive_compacts G} {U : set G} (K₁ K₂ : compacts G)
(hU : (interior U).nonempty) : prehaar K₀.1 U (K₁ ⊔ K₂) ≤ prehaar K₀.1 U K₁ + prehaar K₀.1 U K₂ :=
begin
simp only [prehaar], rw [div_add_div_same, div_le_div_right],
exact_mod_cast index_union_le K₁ K₂ hU, exact_mod_cast index_pos K₀ hU
end
lemma prehaar_sup_eq {K₀ : positive_compacts G} {U : set G} {K₁ K₂ : compacts G}
(hU : (interior U).nonempty) (h : disjoint (K₁.1 * U⁻¹) (K₂.1 * U⁻¹)) :
prehaar K₀.1 U (K₁ ⊔ K₂) = prehaar K₀.1 U K₁ + prehaar K₀.1 U K₂ :=
by { simp only [prehaar], rw [div_add_div_same], congr', exact_mod_cast index_union_eq K₁ K₂ hU h }
lemma is_left_invariant_prehaar {K₀ : positive_compacts G} {U : set G} (hU : (interior U).nonempty)
(g : G) (K : compacts G) : prehaar K₀.1 U (K.map _ $ continuous_mul_left g) = prehaar K₀.1 U K :=
by simp only [prehaar, compacts.map_val, is_left_invariant_index K.2 _ hU]
/-!
### Lemmas about `haar_product`
-/
lemma prehaar_mem_haar_product (K₀ : positive_compacts G) {U : set G}
(hU : (interior U).nonempty) : prehaar K₀.1 U ∈ haar_product K₀.1 :=
by { rintro ⟨K, hK⟩ h2K, rw [mem_Icc], exact ⟨prehaar_nonneg K₀ _, prehaar_le_index K₀ _ hU⟩ }
lemma nonempty_Inter_cl_prehaar (K₀ : positive_compacts G) :
(haar_product K₀.1 ∩ ⋂ (V : open_nhds_of (1 : G)), cl_prehaar K₀.1 V).nonempty :=
begin
have : is_compact (haar_product K₀.1), { apply compact_univ_pi, intro K, apply compact_Icc },
refine this.inter_Inter_nonempty (cl_prehaar K₀.1) (λ s, is_closed_closure) (λ t, _),
let V₀ := ⋂ (V ∈ t), (V : open_nhds_of 1).1,
have h1V₀ : is_open V₀,
{ apply is_open_bInter, apply finite_mem_finset, rintro ⟨V, hV⟩ h2V, exact hV.1 },
have h2V₀ : (1 : G) ∈ V₀, { simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, exact hV.2 },
refine ⟨prehaar K₀.1 V₀, _⟩,
split,
{ apply prehaar_mem_haar_product K₀, use 1, rwa h1V₀.interior_eq },
{ simp only [mem_Inter], rintro ⟨V, hV⟩ h2V, apply subset_closure,
apply mem_image_of_mem, rw [mem_set_of_eq],
exact ⟨subset.trans (Inter_subset _ ⟨V, hV⟩) (Inter_subset _ h2V), h1V₀, h2V₀⟩ },
end
/-!
### The Haar measure on compact sets
-/
/-- The Haar measure on compact sets, defined to be an arbitrary element in the intersection of
all the sets `cl_prehaar K₀ V` in `haar_product K₀`. -/
def chaar (K₀ : positive_compacts G) (K : compacts G) : ℝ :=
classical.some (nonempty_Inter_cl_prehaar K₀) K
lemma chaar_mem_haar_product (K₀ : positive_compacts G) : chaar K₀ ∈ haar_product K₀.1 :=
(classical.some_spec (nonempty_Inter_cl_prehaar K₀)).1
lemma chaar_mem_cl_prehaar (K₀ : positive_compacts G) (V : open_nhds_of (1 : G)) :
chaar K₀ ∈ cl_prehaar K₀.1 V :=
by { have := (classical.some_spec (nonempty_Inter_cl_prehaar K₀)).2, rw [mem_Inter] at this,
exact this V }
lemma chaar_nonneg (K₀ : positive_compacts G) (K : compacts G) : 0 ≤ chaar K₀ K :=
by { have := chaar_mem_haar_product K₀ K (mem_univ _), rw mem_Icc at this, exact this.1 }
lemma chaar_empty (K₀ : positive_compacts G) : chaar K₀ ⊥ = 0 :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f ⊥, have : continuous eval := continuous_apply ⊥,
show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_empty },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
lemma chaar_self (K₀ : positive_compacts G) : chaar K₀ ⟨K₀.1, K₀.2.1⟩ = 1 :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f ⟨K₀.1, K₀.2.1⟩,
have : continuous eval := continuous_apply _,
show chaar K₀ ∈ eval ⁻¹' {(1 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, apply prehaar_self,
rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton }
end
lemma chaar_mono {K₀ : positive_compacts G} {K₁ K₂ : compacts G} (h : K₁.1 ⊆ K₂.1) :
chaar K₀ K₁ ≤ chaar K₀ K₂ :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f K₂ - f K₁,
have : continuous eval := (continuous_apply K₂).sub (continuous_apply K₁),
rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)),
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg],
apply prehaar_mono _ h, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_Ici },
end
lemma chaar_sup_le {K₀ : positive_compacts G} (K₁ K₂ : compacts G) :
chaar K₀ (K₁ ⊔ K₂) ≤ chaar K₀ K₁ + chaar K₀ K₂ :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂),
have : continuous eval :=
((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub
(continuous_apply (K₁ ⊔ K₂)),
rw [← sub_nonneg], show chaar K₀ ∈ eval ⁻¹' (Ici (0 : ℝ)),
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩, simp only [mem_preimage, mem_Ici, eval, sub_nonneg],
apply prehaar_sup_le, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_Ici },
end
lemma chaar_sup_eq [t2_space G] {K₀ : positive_compacts G} {K₁ K₂ : compacts G}
(h : disjoint K₁.1 K₂.1) : chaar K₀ (K₁ ⊔ K₂) = chaar K₀ K₁ + chaar K₀ K₂ :=
begin
rcases compact_compact_separated K₁.2 K₂.2 (disjoint_iff.mp h) with
⟨U₁, U₂, h1U₁, h1U₂, h2U₁, h2U₂, hU⟩,
rw [← disjoint_iff_inter_eq_empty] at hU,
rcases compact_open_separated_mul K₁.2 h1U₁ h2U₁ with ⟨V₁, h1V₁, h2V₁, h3V₁⟩,
rcases compact_open_separated_mul K₂.2 h1U₂ h2U₂ with ⟨V₂, h1V₂, h2V₂, h3V₂⟩,
let eval : (compacts G → ℝ) → ℝ := λ f, f K₁ + f K₂ - f (K₁ ⊔ K₂),
have : continuous eval :=
((@continuous_add ℝ _ _ _).comp ((continuous_apply K₁).prod_mk (continuous_apply K₂))).sub
(continuous_apply (K₁ ⊔ K₂)),
rw [eq_comm, ← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
let V := V₁ ∩ V₂,
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀
⟨V⁻¹, (is_open_inter h1V₁ h1V₂).preimage continuous_inv,
by simp only [mem_inv, one_inv, h2V₁, h2V₂, V, mem_inter_eq, true_and]⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩,
simp only [mem_preimage, eval, sub_eq_zero, mem_singleton_iff], rw [eq_comm],
apply prehaar_sup_eq,
{ rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ refine disjoint_of_subset _ _ hU,
{ refine subset.trans (mul_subset_mul subset.rfl _) h3V₁,
exact subset.trans (inv_subset.mpr h1U) (inter_subset_left _ _) },
{ refine subset.trans (mul_subset_mul subset.rfl _) h3V₂,
exact subset.trans (inv_subset.mpr h1U) (inter_subset_right _ _) }}},
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
lemma is_left_invariant_chaar {K₀ : positive_compacts G} (g : G) (K : compacts G) :
chaar K₀ (K.map _ $ continuous_mul_left g) = chaar K₀ K :=
begin
let eval : (compacts G → ℝ) → ℝ := λ f, f (K.map _ $ continuous_mul_left g) - f K,
have : continuous eval := (continuous_apply (K.map _ _)).sub (continuous_apply K),
rw [← sub_eq_zero], show chaar K₀ ∈ eval ⁻¹' {(0 : ℝ)},
apply mem_of_subset_of_mem _ (chaar_mem_cl_prehaar K₀ ⟨set.univ, is_open_univ, mem_univ _⟩),
unfold cl_prehaar, rw is_closed.closure_subset_iff,
{ rintro _ ⟨U, ⟨h1U, h2U, h3U⟩, rfl⟩,
simp only [mem_singleton_iff, mem_preimage, eval, sub_eq_zero],
apply is_left_invariant_prehaar, rw h2U.interior_eq, exact ⟨1, h3U⟩ },
{ apply continuous_iff_is_closed.mp this, exact is_closed_singleton },
end
/-- The function `chaar` interpreted in `ennreal` -/
@[reducible] def echaar (K₀ : positive_compacts G) (K : compacts G) : ennreal :=
show nnreal, from ⟨chaar K₀ K, chaar_nonneg _ _⟩
/-! We only prove the properties for `echaar` that we use at least twice below. -/
/-- The variant of `chaar_sup_le` for `echaar` -/
lemma echaar_sup_le {K₀ : positive_compacts G} (K₁ K₂ : compacts G) :
echaar K₀ (K₁ ⊔ K₂) ≤ echaar K₀ K₁ + echaar K₀ K₂ :=
by { norm_cast, simp only [←nnreal.coe_le_coe, nnreal.coe_add, subtype.coe_mk, chaar_sup_le]}
/-- The variant of `chaar_mono` for `echaar` -/
lemma echaar_mono {K₀ : positive_compacts G} ⦃K₁ K₂ : compacts G⦄ (h : K₁.1 ⊆ K₂.1) :
echaar K₀ K₁ ≤ echaar K₀ K₂ :=
by { norm_cast, simp only [←nnreal.coe_le_coe, subtype.coe_mk, chaar_mono, h] }
/-- The variant of `chaar_self` for `echaar` -/
lemma echaar_self {K₀ : positive_compacts G} : echaar K₀ ⟨K₀.1, K₀.2.1⟩ = 1 :=
by { simp_rw [← ennreal.coe_one, echaar, ennreal.coe_eq_coe, chaar_self], refl }
/-- The variant of `is_left_invariant_chaar` for `echaar` -/
lemma is_left_invariant_echaar {K₀ : positive_compacts G} (g : G) (K : compacts G) :
echaar K₀ (K.map _ $ continuous_mul_left g) = echaar K₀ K :=
by simpa only [ennreal.coe_eq_coe, ←nnreal.coe_eq] using is_left_invariant_chaar g K
end haar
open haar
/-!
### The Haar outer measure
-/
variables [topological_space G] [t2_space G] [topological_group G]
/-- The Haar outer measure on `G`. It is not normalized, and is mainly used to construct
`haar_measure`, which is a normalized measure. -/
def haar_outer_measure (K₀ : positive_compacts G) : outer_measure G :=
outer_measure.of_content (echaar K₀) $
by { rw echaar, norm_cast, rw [←nnreal.coe_eq, nnreal.coe_zero, subtype.coe_mk, chaar_empty] }
lemma haar_outer_measure_eq_infi (K₀ : positive_compacts G) (A : set G) :
haar_outer_measure K₀ A = ⨅ (U : set G) (hU : is_open U) (h : A ⊆ U),
inner_content (echaar K₀) ⟨U, hU⟩ :=
outer_measure.of_content_eq_infi echaar_sup_le A
lemma echaar_le_haar_outer_measure {K₀ : positive_compacts G} (K : compacts G) :
echaar K₀ K ≤ haar_outer_measure K₀ K.1 :=
outer_measure.le_of_content_compacts echaar_sup_le K
lemma haar_outer_measure_of_is_open {K₀ : positive_compacts G} (U : set G) (hU : is_open U) :
haar_outer_measure K₀ U = inner_content (echaar K₀) ⟨U, hU⟩ :=
outer_measure.of_content_opens echaar_sup_le ⟨U, hU⟩
lemma haar_outer_measure_le_echaar {K₀ : positive_compacts G} {U : set G} (hU : is_open U)
(K : compacts G) (h : U ⊆ K.1) : haar_outer_measure K₀ U ≤ echaar K₀ K :=
(outer_measure.of_content_le echaar_sup_le echaar_mono ⟨U, hU⟩ K h : _)
lemma haar_outer_measure_exists_open {K₀ : positive_compacts G} {A : set G}
(hA : haar_outer_measure K₀ A < ⊤) {ε : ℝ≥0} (hε : 0 < ε) :
∃ U : opens G, A ⊆ U ∧ haar_outer_measure K₀ U ≤ haar_outer_measure K₀ A + ε :=
outer_measure.of_content_exists_open echaar_sup_le hA hε
lemma haar_outer_measure_exists_compact {K₀ : positive_compacts G} {U : opens G}
(hU : haar_outer_measure K₀ U < ⊤) {ε : ℝ≥0} (hε : 0 < ε) :
∃ K : compacts G, K.1 ⊆ U ∧ haar_outer_measure K₀ U ≤ haar_outer_measure K₀ K.1 + ε :=
outer_measure.of_content_exists_compact echaar_sup_le hU hε
lemma haar_outer_measure_caratheodory {K₀ : positive_compacts G} (A : set G) :
(haar_outer_measure K₀).caratheodory.is_measurable' A ↔ ∀ (U : opens G),
haar_outer_measure K₀ (U ∩ A) + haar_outer_measure K₀ (U \ A) ≤ haar_outer_measure K₀ U :=
outer_measure.of_content_caratheodory echaar_sup_le A
lemma one_le_haar_outer_measure_self {K₀ : positive_compacts G} : 1 ≤ haar_outer_measure K₀ K₀.1 :=
begin
rw [haar_outer_measure_eq_infi],
refine le_binfi _, intros U hU, refine le_infi _, intros h2U,
refine le_trans _ (le_bsupr ⟨K₀.1, K₀.2.1⟩ h2U), simp_rw [echaar_self, le_rfl]
end
lemma haar_outer_measure_pos_of_is_open {K₀ : positive_compacts G}
{U : set G} (hU : is_open U) (h2U : U.nonempty) : 0 < haar_outer_measure K₀ U :=
outer_measure.of_content_pos_of_is_mul_left_invariant echaar_sup_le is_left_invariant_echaar
⟨K₀.1, K₀.2.1⟩ (by simp only [echaar_self, ennreal.zero_lt_one]) hU h2U
lemma haar_outer_measure_self_pos {K₀ : positive_compacts G} :
0 < haar_outer_measure K₀ K₀.1 :=
(haar_outer_measure_pos_of_is_open is_open_interior K₀.2.2).trans_le
((haar_outer_measure K₀).mono interior_subset)
lemma haar_outer_measure_lt_top_of_is_compact [locally_compact_space G] {K₀ : positive_compacts G}
{K : set G} (hK : is_compact K) : haar_outer_measure K₀ K < ⊤ :=
begin
rcases exists_compact_superset hK with ⟨F, h1F, h2F⟩,
refine ((haar_outer_measure K₀).mono h2F).trans_lt _,
refine (haar_outer_measure_le_echaar is_open_interior ⟨F, h1F⟩ interior_subset).trans_lt
ennreal.coe_lt_top
end
variables [S : measurable_space G] [borel_space G]
include S
lemma haar_caratheodory_measurable (K₀ : positive_compacts G) :
S ≤ (haar_outer_measure K₀).caratheodory :=
begin
rw [@borel_space.measurable_eq G _ _], refine generate_from_le _,
intros U hU, rw haar_outer_measure_caratheodory, intro U',
rw haar_outer_measure_of_is_open ((U' : set G) ∩ U) (is_open_inter U'.prop hU),
simp only [inner_content, supr_subtype'], rw [opens.coe_mk],
haveI : nonempty {L : compacts G // L.1 ⊆ U' ∩ U} := ⟨⟨⊥, empty_subset _⟩⟩,
rw [ennreal.supr_add],
refine supr_le _, rintro ⟨L, hL⟩, simp only [subset_inter_iff] at hL,
have : ↑U' \ U ⊆ U' \ L.1 := diff_subset_diff_right hL.2,
refine le_trans (add_le_add_left ((haar_outer_measure K₀).mono' this) _) _,
rw haar_outer_measure_of_is_open (↑U' \ L.1) (is_open_diff U'.2 L.2.is_closed),
simp only [inner_content, supr_subtype'], rw [opens.coe_mk],
haveI : nonempty {M : compacts G // M.1 ⊆ ↑U' \ L.1} := ⟨⟨⊥, empty_subset _⟩⟩,
rw [ennreal.add_supr], refine supr_le _, rintro ⟨M, hM⟩, simp only [subset_diff] at hM,
have : (L ⊔ M).1 ⊆ U',
{ simp only [union_subset_iff, compacts.sup_val, hM, hL, and_self] },
rw haar_outer_measure_of_is_open ↑U' U'.2,
refine le_trans (ge_of_eq _) (le_inner_content _ _ this), norm_cast,
simp only [←nnreal.coe_eq, nnreal.coe_add, subtype.coe_mk], exact chaar_sup_eq hM.2.symm
end
/-!
### The Haar measure
-/
/-- the Haar measure on `G`, scaled so that `haar_measure K₀ K₀ = 1`. -/
def haar_measure (K₀ : positive_compacts G) : measure G :=
(haar_outer_measure K₀ K₀.1)⁻¹ •
(haar_outer_measure K₀).to_measure (haar_caratheodory_measurable K₀)
lemma haar_measure_apply {K₀ : positive_compacts G} {s : set G} (hs : is_measurable s) :
haar_measure K₀ s = haar_outer_measure K₀ s / haar_outer_measure K₀ K₀.1 :=
by { simp only [haar_measure, hs, div_eq_mul_inv, mul_comm, to_measure_apply,
algebra.id.smul_eq_mul, pi.smul_apply, measure.coe_smul] }
lemma is_mul_left_invariant_haar_measure (K₀ : positive_compacts G) :
is_mul_left_invariant (haar_measure K₀) :=
begin
intros g A hA,
rw [haar_measure_apply hA, haar_measure_apply (measurable_mul_left g hA)],
congr' 1,
exact outer_measure.is_mul_left_invariant_of_content echaar_sup_le is_left_invariant_echaar g A
end
lemma haar_measure_self [locally_compact_space G] {K₀ : positive_compacts G} :
haar_measure K₀ K₀.1 = 1 :=
begin
rw [haar_measure_apply K₀.2.1.is_measurable, ennreal.div_self],
{ rw [← pos_iff_ne_zero], exact haar_outer_measure_self_pos },
{ exact ne_of_lt (haar_outer_measure_lt_top_of_is_compact K₀.2.1) }
end
lemma haar_measure_pos_of_is_open [locally_compact_space G] {K₀ : positive_compacts G}
{U : set G} (hU : is_open U) (h2U : U.nonempty) : 0 < haar_measure K₀ U :=
begin
rw [haar_measure_apply hU.is_measurable, ennreal.div_pos_iff],
refine ⟨_, ne_of_lt $ haar_outer_measure_lt_top_of_is_compact K₀.2.1⟩,
rw [← pos_iff_ne_zero], apply haar_outer_measure_pos_of_is_open hU h2U
end
lemma regular_haar_measure [locally_compact_space G] {K₀ : positive_compacts G} :
(haar_measure K₀).regular :=
begin
apply measure.regular.smul, split,
{ intros K hK, rw [to_measure_apply _ _ hK.is_measurable],
apply haar_outer_measure_lt_top_of_is_compact hK },
{ intros A hA, rw [to_measure_apply _ _ hA, haar_outer_measure_eq_infi],
refine binfi_le_binfi _, intros U hU, refine infi_le_infi _, intro h2U,
rw [to_measure_apply _ _ hU.is_measurable, haar_outer_measure_of_is_open U hU], refl' },
{ intros U hU, rw [to_measure_apply _ _ hU.is_measurable, haar_outer_measure_of_is_open U hU],
dsimp only [inner_content], refine bsupr_le (λ K hK, _),
refine le_supr_of_le K.1 _, refine le_supr_of_le K.2 _, refine le_supr_of_le hK _,
rw [to_measure_apply _ _ K.2.is_measurable], apply echaar_le_haar_outer_measure },
{ rw ennreal.inv_lt_top, apply haar_outer_measure_self_pos }
end
instance [locally_compact_space G] [separable_space G] (K₀ : positive_compacts G) :
sigma_finite (haar_measure K₀) :=
regular_haar_measure.sigma_finite
section unique
variables [locally_compact_space G] [second_countable_topology G] {μ : measure G} [sigma_finite μ]
/-- The Haar measure is unique up to scaling. More precisely: every σ-finite left invariant measure
is a scalar multiple of the Haar measure. -/
theorem haar_measure_unique (hμ : is_mul_left_invariant μ)
(K₀ : positive_compacts G) : μ = μ K₀.1 • haar_measure K₀ :=
begin
ext1 s hs,
have := measure_mul_measure_eq hμ (is_mul_left_invariant_haar_measure K₀)
regular_haar_measure K₀.2.1 hs,
rw [haar_measure_self, one_mul] at this,
rw [← this (by norm_num), smul_apply],
end
theorem regular_of_left_invariant (hμ : is_mul_left_invariant μ) {K} (hK : is_compact K)
(h2K : (interior K).nonempty) (hμK : μ K < ⊤) : regular μ :=
begin
rw [haar_measure_unique hμ ⟨K, hK, h2K⟩],
exact regular.smul regular_haar_measure hμK
end
end unique
end measure
end measure_theory
|
0796e4fcd28d0accf77ac9050a40499963b211c8 | 8cb37a089cdb4af3af9d8bf1002b417e407a8e9e | /library/init/meta/converter/conv.lean | 18a0d8c3313d20522edc27c2f3a9e065d642f1dd | [
"Apache-2.0"
] | permissive | kbuzzard/lean | ae3c3db4bb462d750dbf7419b28bafb3ec983ef7 | ed1788fd674bb8991acffc8fca585ec746711928 | refs/heads/master | 1,620,983,366,617 | 1,618,937,600,000 | 1,618,937,600,000 | 359,886,396 | 1 | 0 | Apache-2.0 | 1,618,936,987,000 | 1,618,936,987,000 | null | UTF-8 | Lean | false | false | 4,377 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Converter monad for building simplifiers.
-/
prelude
import init.meta.tactic init.meta.simp_tactic init.meta.interactive
import init.meta.congr_lemma init.meta.match_tactic
open tactic
universe u
/-- `conv α` is a tactic for discharging goals of the form `lhs ~ rhs` for some relation `~` (usually equality) and fixed lhs, rhs.
Known in the literature as a __conversion__ tactic.
So for example, if one had the lemma `p : x = y`, then the conversion for `p` would be one that solves `p`.
-/
meta def conv (α : Type u) :=
tactic α
meta instance : monad conv :=
by dunfold conv; apply_instance
meta instance : monad_fail conv :=
by dunfold conv; apply_instance
meta instance : alternative conv :=
by dunfold conv; apply_instance
namespace conv
/-- Applies the conversion `c`. Returns `(rhs,p)` where `p : r lhs rhs`. Throws away the return value of `c`.-/
meta def convert (c : conv unit) (lhs : expr) (rel : name := `eq) : tactic (expr × expr) :=
do lhs_type ← infer_type lhs,
rhs ← mk_meta_var lhs_type,
new_target ← mk_app rel [lhs, rhs],
new_g ← mk_meta_var new_target,
gs ← get_goals,
set_goals [new_g],
c,
try $ any_goals reflexivity,
n ← num_goals,
when (n ≠ 0) (fail "convert tactic failed, there are unsolved goals"),
set_goals gs,
rhs ← instantiate_mvars rhs,
new_g ← instantiate_mvars new_g,
return (rhs, new_g)
meta def lhs : conv expr :=
do (_, lhs, rhs) ← target_lhs_rhs,
return lhs
meta def rhs : conv expr :=
do (_, lhs, rhs) ← target_lhs_rhs,
return rhs
/-- `⊢ lhs = rhs` ~~> `⊢ lhs' = rhs` using `h : lhs = lhs'`. -/
meta def update_lhs (new_lhs : expr) (h : expr) : conv unit :=
do transitivity,
rhs >>= unify new_lhs,
exact h,
t ← target >>= instantiate_mvars,
change t
/-- Change `lhs` to something definitionally equal to it. -/
meta def change (new_lhs : expr) : conv unit :=
do (r, lhs, rhs) ← target_lhs_rhs,
new_target ← mk_app r [new_lhs, rhs],
tactic.change new_target
/-- Use reflexivity to prove. -/
meta def skip : conv unit :=
reflexivity
/-- Put LHS in WHNF. -/
meta def whnf : conv unit :=
lhs >>= tactic.whnf >>= change
/-- dsimp the LHS. -/
meta def dsimp (s : option simp_lemmas := none) (u : list name := []) (cfg : dsimp_config := {}) : conv unit :=
do s ← match s with
| some s := return s
| none := simp_lemmas.mk_default
end,
l ← lhs,
s.dsimplify u l cfg >>= change
private meta def congr_aux : list congr_arg_kind → list expr → tactic (list expr × list expr)
| [] [] := return ([], [])
| (k::ks) (a::as) := do
(gs, largs) ← congr_aux ks as,
match k with
-- parameter for the congruence lemma
| congr_arg_kind.fixed := return $ (gs, a::largs)
-- parameter which is a subsingleton
| congr_arg_kind.fixed_no_param := return $ (gs, largs)
| congr_arg_kind.eq := do
a_type ← infer_type a,
rhs ← mk_meta_var a_type,
g_type ← mk_app `eq [a, rhs],
g ← mk_meta_var g_type, -- proof that `a = rhs`
return (g::gs, a::rhs::g::largs)
| congr_arg_kind.cast := return $ (gs, a::largs)
| _ := fail "congr tactic failed, unsupported congruence lemma"
end
| ks as := fail "congr tactic failed, unsupported congruence lemma"
/-- Take the target equality `f x y = X` and try to apply the congruence lemma for `f` to it (namely `x = x' → y = y' → f x y = f x' y'`). -/
meta def congr : conv unit :=
do (r, lhs, rhs) ← target_lhs_rhs,
guard (r = `eq),
let fn := lhs.get_app_fn,
let args := lhs.get_app_args,
cgr_lemma ← mk_congr_lemma_simp fn (some args.length),
g::gs ← get_goals,
(new_gs, lemma_args) ← congr_aux cgr_lemma.arg_kinds args,
let g_val := cgr_lemma.proof.mk_app lemma_args,
unify g g_val,
set_goals $ new_gs ++ gs,
return ()
/-- Create a conversion from the function extensionality tactic.-/
meta def funext : conv unit :=
iterate' $ do
(r, lhs, rhs) ← target_lhs_rhs,
guard (r = `eq),
(expr.lam n _ _ _) ← return lhs,
tactic.applyc `funext,
intro n,
return ()
end conv
|
73501b21eddf461f33701d469a32cf2a6f5ba266 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/convex/slope.lean | b8e68c71b0c0e03f47f8f6e48c712aa78dc3f13d | [
"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 | 16,321 | lean | /-
Copyright (c) 2021 Yury Kudriashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudriashov, Malo Jaffré
-/
import analysis.convex.function
import tactic.field_simp
import tactic.linarith
/-!
# Slopes of convex functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file relates convexity/concavity of functions in a linearly ordered field and the monotonicity
of their slopes.
The main use is to show convexity/concavity from monotonicity of the derivative.
-/
variables {𝕜 : Type*} [linear_ordered_field 𝕜] {s : set 𝕜} {f : 𝕜 → 𝕜}
/-- If `f : 𝕜 → 𝕜` is convex, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
lemma convex_on.slope_mono_adjacent (hf : convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y) :=
begin
have hxz := hxy.trans hyz,
rw ←sub_pos at hxy hxz hyz,
suffices : f y / (y - x) + f y / (z - y) ≤ f x / (y - x) + f z / (z - y),
{ ring_nf at this ⊢, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a • x + b • z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
hf.2 hx hz
(show 0 ≤ a, by apply div_nonneg; linarith)
(show 0 ≤ b, by apply div_nonneg; linarith)
(show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_le_mul_of_nonneg_left key hxz.le,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key ⊢,
rw div_le_div_right,
{ linarith },
{ nlinarith }
end
/-- If `f : 𝕜 → 𝕜` is concave, then for any three points `x < y < z` the slope of the secant line of
`f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
lemma concave_on.slope_anti_adjacent (hf : concave_on 𝕜 s f) {x y z : 𝕜} (hx : x ∈ s)
(hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x) :=
begin
rw [←neg_le_neg_iff, ←neg_sub_neg (f x), ←neg_sub_neg (f y)],
simp_rw [←pi.neg_apply, ←neg_div, neg_sub],
exact convex_on.slope_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- If `f : 𝕜 → 𝕜` is strictly convex, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_convex_on.slope_strict_mono_adjacent (hf : strict_convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
begin
have hxz := hxy.trans hyz,
have hxz' := hxz.ne,
rw ←sub_pos at hxy hxz hyz,
suffices : f y / (y - x) + f y / (z - y) < f x / (y - x) + f z / (z - y),
{ ring_nf at this ⊢, linarith },
set a := (z - y) / (z - x),
set b := (y - x) / (z - x),
have hy : a • x + b • z = y, by { field_simp, rw div_eq_iff; [ring, linarith] },
have key, from
hf.2 hx hz hxz' (div_pos hyz hxz) (div_pos hxy hxz)
(show a + b = 1, by { field_simp, rw div_eq_iff; [ring, linarith] }),
rw hy at key,
replace key := mul_lt_mul_of_pos_left key hxz,
field_simp [hxy.ne', hyz.ne', hxz.ne', mul_comm (z - x) _] at key ⊢,
rw div_lt_div_right,
{ linarith },
{ nlinarith }
end
/-- If `f : 𝕜 → 𝕜` is strictly concave, then for any three points `x < y < z` the slope of the
secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_concave_on.slope_anti_adjacent (hf : strict_concave_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
begin
rw [←neg_lt_neg_iff, ←neg_sub_neg (f x), ←neg_sub_neg (f y)],
simp_rw [←pi.neg_apply, ←neg_div, neg_sub],
exact strict_convex_on.slope_strict_mono_adjacent hf.neg hx hz hxy hyz,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
less than the slope of the secant line of `f` on `[x, z]`, then `f` is convex. -/
lemma convex_on_of_slope_mono_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y)) :
convex_on 𝕜 s f :=
linear_order.convex_on_of_lt hs $ λ x hx z hz hxz a b ha hb hab,
begin
let y := a * x + b * z,
have hxy : x < y,
{ rw [← one_mul x, ← hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [← one_mul z, ← hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) ≤ (f z - f y) * (y - x),
from (div_le_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, ← sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, ← sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
rwa [sub_mul, sub_mul, sub_le_iff_le_add', ← add_sub_assoc, le_sub_iff_add_le, ← mul_add,
sub_add_sub_cancel, ← le_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
greater than the slope of the secant line of `f` on `[x, z]`, then `f` is concave. -/
lemma concave_on_of_slope_anti_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x)) : concave_on 𝕜 s f :=
begin
rw ←neg_convex_on_iff,
refine convex_on_of_slope_mono_adjacent hs (λ x y z hx hz hxy hyz, _),
rw ←neg_le_neg_iff,
simp_rw [←neg_div, neg_sub, pi.neg_apply, neg_sub_neg],
exact hf hx hz hxy hyz,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
strictly less than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly convex. -/
lemma strict_convex_on_of_slope_strict_mono_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) < (f z - f y) / (z - y)) :
strict_convex_on 𝕜 s f :=
linear_order.strict_convex_on_of_lt hs $ λ x hx z hz hxz a b ha hb hab,
begin
let y := a * x + b * z,
have hxy : x < y,
{ rw [← one_mul x, ← hab, add_mul],
exact add_lt_add_left ((mul_lt_mul_left hb).2 hxz) _ },
have hyz : y < z,
{ rw [← one_mul z, ← hab, add_mul],
exact add_lt_add_right ((mul_lt_mul_left ha).2 hxz) _ },
have : (f y - f x) * (z - y) < (f z - f y) * (y - x),
from (div_lt_div_iff (sub_pos.2 hxy) (sub_pos.2 hyz)).1 (hf hx hz hxy hyz),
have hxz : 0 < z - x, from sub_pos.2 (hxy.trans hyz),
have ha : (z - y) / (z - x) = a,
{ rw [eq_comm, ← sub_eq_iff_eq_add'] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
have hb : (y - x) / (z - x) = b,
{ rw [eq_comm, ← sub_eq_iff_eq_add] at hab,
simp_rw [div_eq_iff hxz.ne', y, ←hab], ring },
rwa [sub_mul, sub_mul, sub_lt_iff_lt_add', ← add_sub_assoc, lt_sub_iff_add_lt, ← mul_add,
sub_add_sub_cancel, ← lt_div_iff hxz, add_div, mul_div_assoc, mul_div_assoc, mul_comm (f x),
mul_comm (f z), ha, hb] at this,
end
/-- If for any three points `x < y < z`, the slope of the secant line of `f : 𝕜 → 𝕜` on `[x, y]` is
strictly greater than the slope of the secant line of `f` on `[x, z]`, then `f` is strictly concave.
-/
lemma strict_concave_on_of_slope_strict_anti_adjacent (hs : convex 𝕜 s)
(hf : ∀ {x y z : 𝕜}, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) < (f y - f x) / (y - x)) : strict_concave_on 𝕜 s f :=
begin
rw ←neg_strict_convex_on_iff,
refine strict_convex_on_of_slope_strict_mono_adjacent hs (λ x y z hx hz hxy hyz, _),
rw ←neg_lt_neg_iff,
simp_rw [←neg_div, neg_sub, pi.neg_apply, neg_sub_neg],
exact hf hx hz hxy hyz,
end
/-- A function `f : 𝕜 → 𝕜` is convex iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is less than the slope of the secant line of `f` on `[x, z]`. -/
lemma convex_on_iff_slope_mono_adjacent :
convex_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) ≤ (f z - f y) / (z - y) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_mono_adjacent⟩, λ h, convex_on_of_slope_mono_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is concave iff for any three points `x < y < z` the slope of the secant
line of `f` on `[x, y]` is greater than the slope of the secant line of `f` on `[x, z]`. -/
lemma concave_on_iff_slope_anti_adjacent :
concave_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) ≤ (f y - f x) / (y - x) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_anti_adjacent⟩, λ h, concave_on_of_slope_anti_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is strictly convex iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly less than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_convex_on_iff_slope_strict_mono_adjacent :
strict_convex_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f y - f x) / (y - x) < (f z - f y) / (z - y) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_strict_mono_adjacent⟩,
λ h, strict_convex_on_of_slope_strict_mono_adjacent h.1 h.2⟩
/-- A function `f : 𝕜 → 𝕜` is strictly concave iff for any three points `x < y < z` the slope of
the secant line of `f` on `[x, y]` is strictly greater than the slope of the secant line of `f` on
`[x, z]`. -/
lemma strict_concave_on_iff_slope_strict_anti_adjacent :
strict_concave_on 𝕜 s f ↔ convex 𝕜 s ∧
∀ ⦃x y z : 𝕜⦄, x ∈ s → z ∈ s → x < y → y < z →
(f z - f y) / (z - y) < (f y - f x) / (y - x) :=
⟨λ h, ⟨h.1, λ x y z, h.slope_anti_adjacent⟩,
λ h, strict_concave_on_of_slope_strict_anti_adjacent h.1 h.2⟩
lemma convex_on.secant_mono_aux1 (hf : convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(z - x) * f y ≤ (z - y) * f x + (y - x) * f z :=
begin
have hxy' : 0 < y - x := by linarith,
have hyz' : 0 < z - y := by linarith,
have hxz' : 0 < z - x := by linarith,
rw ← le_div_iff' hxz',
have ha : 0 ≤ (z - y) / (z - x) := by positivity,
have hb : 0 ≤ (y - x) / (z - x) := by positivity,
calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) : _
... ≤ (z - y) / (z - x) * f x + (y - x) / (z - x) * f z : hf.2 hx hz ha hb _
... = ((z - y) * f x + (y - x) * f z) / (z - x) : _,
{ congr' 1,
field_simp [hxy'.ne', hyz'.ne', hxz'.ne'],
ring },
{ field_simp [hxy'.ne', hyz'.ne', hxz'.ne'] },
{ field_simp [hxy'.ne', hyz'.ne', hxz'.ne'] }
end
lemma convex_on.secant_mono_aux2 (hf : convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) ≤ (f z - f x) / (z - x) :=
begin
have hxy' : 0 < y - x := by linarith,
have hxz' : 0 < z - x := by linarith,
rw div_le_div_iff hxy' hxz',
linarith only [hf.secant_mono_aux1 hx hz hxy hyz],
end
lemma convex_on.secant_mono_aux3 (hf : convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f x) / (z - x) ≤ (f z - f y) / (z - y) :=
begin
have hyz' : 0 < z - y := by linarith,
have hxz' : 0 < z - x := by linarith,
rw div_le_div_iff hxz' hyz',
linarith only [hf.secant_mono_aux1 hx hz hxy hyz],
end
lemma convex_on.secant_mono (hf : convex_on 𝕜 s f)
{a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x ≤ y) :
(f x - f a) / (x - a) ≤ (f y - f a) / (y - a) :=
begin
rcases eq_or_lt_of_le hxy with rfl | hxy,
{ simp },
cases lt_or_gt_of_ne hxa with hxa hxa,
{ cases lt_or_gt_of_ne hya with hya hya,
{ convert hf.secant_mono_aux3 hx ha hxy hya using 1;
rw ← neg_div_neg_eq;
field_simp, },
{ convert hf.slope_mono_adjacent hx hy hxa hya using 1,
rw ← neg_div_neg_eq;
field_simp, } },
{ exact hf.secant_mono_aux2 ha hy hxa hxy, },
end
lemma strict_convex_on.secant_strict_mono_aux1 (hf : strict_convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(z - x) * f y < (z - y) * f x + (y - x) * f z :=
begin
have hxy' : 0 < y - x := by linarith,
have hyz' : 0 < z - y := by linarith,
have hxz' : 0 < z - x := by linarith,
rw ← lt_div_iff' hxz',
have ha : 0 < (z - y) / (z - x) := by positivity,
have hb : 0 < (y - x) / (z - x) := by positivity,
calc f y = f ((z - y) / (z - x) * x + (y - x) / (z - x) * z) : _
... < (z - y) / (z - x) * f x + (y - x) / (z - x) * f z : hf.2 hx hz (by linarith) ha hb _
... = ((z - y) * f x + (y - x) * f z) / (z - x) : _,
{ congr' 1,
field_simp [hxy'.ne', hyz'.ne', hxz'.ne'],
ring },
{ field_simp [hxy'.ne', hyz'.ne', hxz'.ne'] },
{ field_simp [hxy'.ne', hyz'.ne', hxz'.ne'] }
end
lemma strict_convex_on.secant_strict_mono_aux2 (hf : strict_convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f y - f x) / (y - x) < (f z - f x) / (z - x) :=
begin
have hxy' : 0 < y - x := by linarith,
have hxz' : 0 < z - x := by linarith,
rw div_lt_div_iff hxy' hxz',
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz],
end
lemma strict_convex_on.secant_strict_mono_aux3 (hf : strict_convex_on 𝕜 s f)
{x y z : 𝕜} (hx : x ∈ s) (hz : z ∈ s) (hxy : x < y) (hyz : y < z) :
(f z - f x) / (z - x) < (f z - f y) / (z - y) :=
begin
have hyz' : 0 < z - y := by linarith,
have hxz' : 0 < z - x := by linarith,
rw div_lt_div_iff hxz' hyz',
linarith only [hf.secant_strict_mono_aux1 hx hz hxy hyz],
end
lemma strict_convex_on.secant_strict_mono (hf : strict_convex_on 𝕜 s f)
{a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x < y) :
(f x - f a) / (x - a) < (f y - f a) / (y - a) :=
begin
cases lt_or_gt_of_ne hxa with hxa hxa,
{ cases lt_or_gt_of_ne hya with hya hya,
{ convert hf.secant_strict_mono_aux3 hx ha hxy hya using 1;
rw ← neg_div_neg_eq;
field_simp, },
{ convert hf.slope_strict_mono_adjacent hx hy hxa hya using 1,
rw ← neg_div_neg_eq;
field_simp, } },
{ exact hf.secant_strict_mono_aux2 ha hy hxa hxy, },
end
lemma strict_concave_on.secant_strict_mono (hf : strict_concave_on 𝕜 s f)
{a x y : 𝕜} (ha : a ∈ s) (hx : x ∈ s) (hy : y ∈ s) (hxa : x ≠ a) (hya : y ≠ a) (hxy : x < y) :
(f y - f a) / (y - a) < (f x - f a) / (x - a) :=
begin
have key := hf.neg.secant_strict_mono ha hx hy hxa hya hxy,
simp only [pi.neg_apply] at key,
rw ← neg_lt_neg_iff,
convert key using 1; field_simp,
end
/-- If `f` is convex on a set `s` in a linearly ordered field, and `f x < f y` for two points
`x < y` in `s`, then `f` is strictly monotone on `s ∩ [y, ∞)`. -/
lemma convex_on.strict_mono_of_lt (hf : convex_on 𝕜 s f)
{x y : 𝕜} (hx : x ∈ s) (hxy : x < y) (hxy' : f x < f y) :
strict_mono_on f (s ∩ set.Ici y) :=
begin
intros u hu v hv huv,
have step1 : ∀ {z : 𝕜}, z ∈ s ∩ set.Ioi y → f y < f z,
{ refine λ z hz, hf.lt_right_of_left_lt hx hz.1 _ hxy',
rw open_segment_eq_Ioo (hxy.trans hz.2),
exact ⟨hxy, hz.2⟩ },
rcases eq_or_lt_of_le hu.2 with rfl | hu2,
{ exact step1 ⟨hv.1, huv⟩ },
{ refine hf.lt_right_of_left_lt _ hv.1 _ (step1 ⟨hu.1, hu2⟩),
{ apply hf.1.segment_subset hx hu.1,
rw segment_eq_Icc (hxy.le.trans hu.2),
exact ⟨hxy.le, hu.2⟩ },
{ rw open_segment_eq_Ioo (hu2.trans huv),
exact ⟨hu2, huv⟩ } },
end
|
ab71fc664b89c6aa207d240733b6c6002f9ad117 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/finite/card.lean | 4adac16398fddbbf5bf83da96ec58db4bb2d52ca | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 4,279 | lean | /-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import data.finite.basic
import set_theory.cardinal.finite
/-!
# Cardinality of finite types
The cardinality of a finite type `α` is given by `nat.card α`. This function has
the "junk value" of `0` for infinite types, but to ensure the function has valid
output, one just needs to know that it's possible to produce a `finite` instance
for the type. (Note: we could have defined a `finite.card` that required you to
supply a `finite` instance, but (a) the function would be `noncomputable` anyway
so there is no need to supply the instance and (b) the function would have a more
complicated dependent type that easily leads to "motive not type correct" errors.)
## Implementation notes
Theorems about `nat.card` are sometimes incidentally true for both finite and infinite
types. If removing a finiteness constraint results in no loss in legibility, we remove
it. We generally put such theorems into the `set_theory.cardinal.finite` module.
-/
noncomputable theory
open_locale classical
variables {α β γ : Type*}
/-- There is (noncomputably) an equivalence between a finite type `α` and `fin (nat.card α)`. -/
def finite.equiv_fin (α : Type*) [finite α] : α ≃ fin (nat.card α) :=
begin
have := (finite.exists_equiv_fin α).some_spec.some,
rwa nat.card_eq_of_equiv_fin this,
end
/-- Similar to `finite.equiv_fin` but with control over the term used for the cardinality. -/
def finite.equiv_fin_of_card_eq [finite α] {n : ℕ} (h : nat.card α = n) : α ≃ fin n :=
by { subst h, apply finite.equiv_fin }
lemma nat.card_eq (α : Type*) :
nat.card α = if h : finite α then by exactI @fintype.card α (fintype.of_finite α) else 0 :=
begin
casesI finite_or_infinite α,
{ letI := fintype.of_finite α,
simp only [*, nat.card_eq_fintype_card, dif_pos] },
{ simp [*, not_finite_iff_infinite.mpr h] },
end
lemma finite.card_pos_iff [finite α] :
0 < nat.card α ↔ nonempty α :=
begin
haveI := fintype.of_finite α,
simp only [nat.card_eq_fintype_card],
exact fintype.card_pos_iff,
end
namespace finite
lemma card_eq [finite α] [finite β] : nat.card α = nat.card β ↔ nonempty (α ≃ β) :=
by { haveI := fintype.of_finite α, haveI := fintype.of_finite β, simp [fintype.card_eq] }
lemma card_le_one_iff_subsingleton [finite α] : nat.card α ≤ 1 ↔ subsingleton α :=
by { haveI := fintype.of_finite α, simp [fintype.card_le_one_iff_subsingleton] }
lemma one_lt_card_iff_nontrivial [finite α] : 1 < nat.card α ↔ nontrivial α :=
by { haveI := fintype.of_finite α, simp [fintype.one_lt_card_iff_nontrivial] }
lemma one_lt_card [finite α] [h : nontrivial α] : 1 < nat.card α :=
one_lt_card_iff_nontrivial.mpr h
@[simp] lemma card_option [finite α] : nat.card (option α) = nat.card α + 1 :=
by { haveI := fintype.of_finite α, simp }
lemma card_le_of_injective [finite β] (f : α → β) (hf : function.injective f) :
nat.card α ≤ nat.card β :=
by { haveI := fintype.of_finite β, haveI := fintype.of_injective f hf,
simpa using fintype.card_le_of_injective f hf }
lemma card_le_of_embedding [finite β] (f : α ↪ β) : nat.card α ≤ nat.card β :=
card_le_of_injective _ f.injective
lemma card_le_of_surjective [finite α] (f : α → β) (hf : function.surjective f) :
nat.card β ≤ nat.card α :=
by { haveI := fintype.of_finite α, haveI := fintype.of_surjective f hf,
simpa using fintype.card_le_of_surjective f hf }
lemma card_eq_zero_iff [finite α] : nat.card α = 0 ↔ is_empty α :=
by { haveI := fintype.of_finite α, simp [fintype.card_eq_zero_iff] }
lemma card_sum [finite α] [finite β] : nat.card (α ⊕ β) = nat.card α + nat.card β :=
by { haveI := fintype.of_finite α, haveI := fintype.of_finite β, simp }
end finite
theorem finite.card_subtype_le [finite α] (p : α → Prop) :
nat.card {x // p x} ≤ nat.card α :=
by { haveI := fintype.of_finite α, simpa using fintype.card_subtype_le p }
theorem finite.card_subtype_lt [finite α] {p : α → Prop} {x : α} (hx : ¬ p x) :
nat.card {x // p x} < nat.card α :=
by { haveI := fintype.of_finite α, simpa using fintype.card_subtype_lt hx }
|
1dad5388409aef40db660d587dc857900136075b | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/group_theory/perm/concrete_cycle.lean | 55dc4f27eba1b9cbf8de2489843acd5b80faa47c | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 19,615 | lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import group_theory.perm.list
import data.list.cycle
import group_theory.perm.cycle_type
/-!
# Properties of cyclic permutations constructed from lists/cycles
In the following, `{α : Type*} [fintype α] [decidable_eq α]`.
## Main definitions
* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle α`
* `equiv.perm.to_list`: the list formed by iterating application of a permutation
* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation
* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm α`
and the terms of `cycle α` that correspond to them
* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`
but with evaluation via choosing over fintypes
* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`
* A `has_repr` instance for any `perm α`, by representing the `finset` of
`cycle α` that correspond to the cycle factors.
## Main results
* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as
a permutation, is cyclic
* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle α`
corresponding to each cyclic `f : perm α`
## Implementation details
The forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness
result, relying on the `fintype` instance of a `cycle.nodup` subtype.
It is unclear if this works faster than the `equiv.perm.to_cycle`, which relies
on recursion over `finset.univ`.
Running `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`
to show it takes a long time. TODO: is this because computing the cycle factors is slow?
-/
open equiv equiv.perm list
namespace list
variables {α : Type*} [decidable_eq α] {l l' : list α}
lemma form_perm_disjoint_iff (hl : nodup l) (hl' : nodup l')
(hn : 2 ≤ l.length) (hn' : 2 ≤ l'.length) :
perm.disjoint (form_perm l) (form_perm l') ↔ l.disjoint l' :=
begin
rw [disjoint_iff_eq_or_eq, list.disjoint],
split,
{ rintro h x hx hx',
specialize h x,
rw [form_perm_apply_mem_eq_self_iff _ hl _ hx,
form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h,
rcases h with hl | hl'; linarith },
{ intros h x,
by_cases hx : x ∈ l, by_cases hx' : x ∈ l',
{ exact (h hx hx').elim },
all_goals { have := form_perm_eq_self_of_not_mem _ _ ‹_›, tauto } }
end
lemma is_cycle_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
is_cycle (form_perm l) :=
begin
cases l with x l,
{ norm_num at hn },
induction l with y l IH generalizing x,
{ norm_num at hn },
{ use x,
split,
{ rwa form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _) },
{ intros w hw,
have : w ∈ (x :: y :: l) := mem_of_form_perm_ne_self _ _ hw,
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem this,
use k,
simp only [zpow_coe_nat, form_perm_pow_apply_head _ _ hl k, nat.mod_eq_of_lt hk] } }
end
lemma pairwise_same_cycle_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
pairwise (l.form_perm.same_cycle) l :=
pairwise.imp_mem.mpr (pairwise_of_forall (λ x y hx hy, (is_cycle_form_perm hl hn).same_cycle
((form_perm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)
((form_perm_apply_mem_ne_self_iff _ hl _ hy).mpr hn)))
lemma cycle_of_form_perm (hl : nodup l) (hn : 2 ≤ l.length) (x) :
cycle_of l.attach.form_perm x = l.attach.form_perm :=
have hn : 2 ≤ l.attach.length := by rwa ← length_attach at hn,
have hl : l.attach.nodup := by rwa ← nodup_attach at hl,
(is_cycle_form_perm hl hn).cycle_of_eq
((form_perm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)
lemma cycle_type_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
cycle_type l.attach.form_perm = {l.length} :=
begin
rw ←length_attach at hn,
rw ←nodup_attach at hl,
rw cycle_type_eq [l.attach.form_perm],
{ simp only [map, function.comp_app],
rw [support_form_perm_of_nodup _ hl, card_to_finset, erase_dup_eq_self.mpr hl],
{ simpa },
{ intros x h,
simpa [h, nat.succ_le_succ_iff] using hn } },
{ simp },
{ simpa using is_cycle_form_perm hl hn },
{ simp }
end
lemma form_perm_apply_mem_eq_next (hl : nodup l) (x : α) (hx : x ∈ l) :
form_perm l x = next l x hx :=
begin
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx,
rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]
end
end list
namespace cycle
variables {α : Type*} [decidable_eq α] (s s' : cycle α)
/--
A cycle `s : cycle α` , given `nodup s` can be interpreted as a `equiv.perm α`
where each element in the list is permuted to the next one, defined as `form_perm`.
-/
def form_perm : Π (s : cycle α) (h : nodup s), equiv.perm α :=
λ s, quot.hrec_on s (λ l h, form_perm l)
(λ l₁ l₂ (h : l₁ ~r l₂),
begin
ext,
{ exact h.nodup_iff },
{ intros h₁ h₂ _,
exact heq_of_eq (form_perm_eq_of_is_rotated h₁ h) }
end)
@[simp] lemma form_perm_coe (l : list α) (hl : l.nodup) :
form_perm (l : cycle α) hl = l.form_perm := rfl
lemma form_perm_subsingleton (s : cycle α) (h : subsingleton s) :
form_perm s h.nodup = 1 :=
begin
induction s using quot.induction_on,
simp only [form_perm_coe, mk_eq_coe],
simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h,
cases s with hd tl,
{ simp },
{ simp only [length_eq_zero, add_le_iff_nonpos_left, list.length, nonpos_iff_eq_zero] at h,
simp [h] }
end
lemma is_cycle_form_perm (s : cycle α) (h : nodup s) (hn : nontrivial s) :
is_cycle (form_perm s h) :=
begin
induction s using quot.induction_on,
exact list.is_cycle_form_perm h (length_nontrivial hn)
end
lemma support_form_perm [fintype α] (s : cycle α) (h : nodup s) (hn : nontrivial s) :
support (form_perm s h) = s.to_finset :=
begin
induction s using quot.induction_on,
refine support_form_perm_of_nodup s h _,
rintro _ rfl,
simpa [nat.succ_le_succ_iff] using length_nontrivial hn
end
lemma form_perm_eq_self_of_not_mem (s : cycle α) (h : nodup s) (x : α) (hx : x ∉ s) :
form_perm s h x = x :=
begin
induction s using quot.induction_on,
simpa using list.form_perm_eq_self_of_not_mem _ _ hx
end
lemma form_perm_apply_mem_eq_next (s : cycle α) (h : nodup s) (x : α) (hx : x ∈ s) :
form_perm s h x = next s h x hx :=
begin
induction s using quot.induction_on,
simpa using list.form_perm_apply_mem_eq_next h _ _
end
lemma form_perm_reverse (s : cycle α) (h : nodup s) :
form_perm s.reverse (nodup_reverse_iff.mpr h) = (form_perm s h)⁻¹ :=
begin
induction s using quot.induction_on,
simpa using form_perm_reverse _ h
end
lemma form_perm_eq_form_perm_iff {α : Type*} [decidable_eq α]
{s s' : cycle α} {hs : s.nodup} {hs' : s'.nodup} :
s.form_perm hs = s'.form_perm hs' ↔ s = s' ∨ s.subsingleton ∧ s'.subsingleton :=
begin
rw [cycle.length_subsingleton_iff, cycle.length_subsingleton_iff],
revert s s',
intros s s',
apply quotient.induction_on₂' s s',
intros l l',
simpa using form_perm_eq_form_perm_iff
end
end cycle
variables {α : Type*}
namespace equiv.perm
variables [fintype α] [decidable_eq α] (p : equiv.perm α) (x : α)
/--
`equiv.perm.to_list (f : perm α) (x : α)` generates the list `[x, f x, f (f x), ...]`
until looping. That means when `f x = x`, `to_list f x = []`.
-/
def to_list : list α :=
(list.range (cycle_of p x).support.card).map (λ k, (p ^ k) x)
@[simp] lemma to_list_one : to_list (1 : perm α) x = [] :=
by simp [to_list, cycle_of_one]
@[simp] lemma to_list_eq_nil_iff {p : perm α} {x} : to_list p x = [] ↔ x ∉ p.support :=
by simp [to_list]
@[simp] lemma length_to_list : length (to_list p x) = (cycle_of p x).support.card :=
by simp [to_list]
lemma to_list_ne_singleton (y : α) : to_list p x ≠ [y] :=
begin
intro H,
simpa [card_support_ne_one] using congr_arg length H
end
lemma two_le_length_to_list_iff_mem_support {p : perm α} {x : α} :
2 ≤ length (to_list p x) ↔ x ∈ p.support :=
by simp
lemma length_to_list_pos_of_mem_support (h : x ∈ p.support) : 0 < length (to_list p x) :=
zero_lt_two.trans_le (two_le_length_to_list_iff_mem_support.mpr h)
lemma nth_le_to_list (n : ℕ) (hn : n < length (to_list p x)) :
nth_le (to_list p x) n hn = (p ^ n) x :=
by simp [to_list]
lemma to_list_nth_le_zero (h : x ∈ p.support) :
(to_list p x).nth_le 0 (length_to_list_pos_of_mem_support _ _ h) = x :=
by simp [to_list]
variables {p} {x}
lemma mem_to_list_iff {y : α} :
y ∈ to_list p x ↔ same_cycle p x y ∧ x ∈ p.support :=
begin
simp only [to_list, mem_range, mem_map],
split,
{ rintro ⟨n, hx, rfl⟩,
refine ⟨⟨n, rfl⟩, _⟩,
contrapose! hx,
rw ←support_cycle_of_eq_nil_iff at hx,
simp [hx] },
{ rintro ⟨h, hx⟩,
simpa using same_cycle.nat_of_mem_support _ h hx }
end
lemma nodup_to_list (p : perm α) (x : α) :
nodup (to_list p x) :=
begin
by_cases hx : p x = x,
{ rw [←not_mem_support, ←to_list_eq_nil_iff] at hx,
simp [hx] },
have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx,
rw nodup_iff_nth_le_inj,
rintros n m hn hm,
rw [length_to_list, ←order_of_is_cycle hc] at hm hn,
rw [←cycle_of_apply_self, ←ne.def, ←mem_support] at hx,
rw [nth_le_to_list, nth_le_to_list,
←cycle_of_pow_apply_self p x n, ←cycle_of_pow_apply_self p x m],
cases n; cases m,
{ simp },
{ rw [←hc.mem_support_pos_pow_iff_of_lt_order_of m.zero_lt_succ hm,
mem_support, cycle_of_pow_apply_self] at hx,
simp [hx.symm] },
{ rw [←hc.mem_support_pos_pow_iff_of_lt_order_of n.zero_lt_succ hn,
mem_support, cycle_of_pow_apply_self] at hx,
simp [hx] },
intro h,
have hn' : ¬ order_of (p.cycle_of x) ∣ n.succ := nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn,
have hm' : ¬ order_of (p.cycle_of x) ∣ m.succ := nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm,
rw ←hc.support_pow_eq_iff at hn' hm',
rw [←nat.mod_eq_of_lt hn, ←nat.mod_eq_of_lt hm, ←pow_inj_mod],
refine support_congr _ _,
{ rw [hm', hn'],
exact finset.subset.refl _ },
{ rw hm',
intros y hy,
obtain ⟨k, rfl⟩ := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy),
rw [←mul_apply, (commute.pow_pow_self _ _ _).eq, mul_apply, h, ←mul_apply, ←mul_apply,
(commute.pow_pow_self _ _ _).eq] }
end
lemma next_to_list_eq_apply (p : perm α) (x y : α) (hy : y ∈ to_list p x) :
next (to_list p x) y hy = p y :=
begin
rw mem_to_list_iff at hy,
obtain ⟨k, hk, hk'⟩ := hy.left.nat_of_mem_support _ hy.right,
rw ←nth_le_to_list p x k (by simpa using hk) at hk',
simp_rw ←hk',
rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, ←mul_apply, ←pow_succ,
length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), order_of_is_cycle],
exact is_cycle_cycle_of _ (mem_support.mp hy.right)
end
lemma to_list_pow_apply_eq_rotate (p : perm α) (x : α) (k : ℕ) :
p.to_list ((p ^ k) x) = (p.to_list x).rotate k :=
begin
apply ext_le,
{ simp },
{ intros n hn hn',
rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,
pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply] }
end
lemma same_cycle.to_list_is_rotated {f : perm α} {x y : α} (h : same_cycle f x y) :
to_list f x ~r to_list f y :=
begin
by_cases hx : x ∈ f.support,
{ obtain ⟨_ | k, hk, hy⟩ := h.nat_of_mem_support _ hx,
{ simp only [coe_one, id.def, pow_zero] at hy,
simp [hy] },
use k.succ,
rw [←to_list_pow_apply_eq_rotate, hy] },
{ rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff],
rwa ←h.mem_support_iff }
end
lemma pow_apply_mem_to_list_iff_mem_support {n : ℕ} :
(p ^ n) x ∈ p.to_list x ↔ x ∈ p.support :=
begin
rw [mem_to_list_iff, and_iff_right_iff_imp],
refine λ _, same_cycle.symm _,
rw same_cycle_pow_left_iff
end
lemma to_list_form_perm_nil (x : α) :
to_list (form_perm ([] : list α)) x = [] :=
by simp
lemma to_list_form_perm_singleton (x y : α) :
to_list (form_perm [x]) y = [] :=
by simp
lemma to_list_form_perm_nontrivial (l : list α) (hl : 2 ≤ l.length) (hn : nodup l) :
to_list (form_perm l) (l.nth_le 0 (zero_lt_two.trans_le hl)) = l :=
begin
have hc : l.form_perm.is_cycle := list.is_cycle_form_perm hn hl,
have hs : l.form_perm.support = l.to_finset,
{ refine support_form_perm_of_nodup _ hn _,
rintro _ rfl,
simpa [nat.succ_le_succ_iff] using hl },
rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, erase_dup_eq_self.mpr hn],
{ refine list.ext_le (by simp) (λ k hk hk', _),
simp [form_perm_pow_apply_nth_le _ hn, nat.mod_eq_of_lt hk'] },
{ simpa [hs] using nth_le_mem _ _ _ }
end
lemma to_list_form_perm_is_rotated_self (l : list α) (hl : 2 ≤ l.length) (hn : nodup l)
(x : α) (hx : x ∈ l):
to_list (form_perm l) x ~r l :=
begin
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx,
have hr : l ~r l.rotate k := ⟨k, rfl⟩,
rw form_perm_eq_of_is_rotated hn hr,
rw ←nth_le_rotate' l k k,
simp only [nat.mod_eq_of_lt hk, tsub_add_cancel_of_le hk.le, nat.mod_self],
rw [to_list_form_perm_nontrivial],
{ simp },
{ simpa using hl },
{ simpa using hn }
end
lemma form_perm_to_list (f : perm α) (x : α) :
form_perm (to_list f x) = f.cycle_of x :=
begin
by_cases hx : f x = x,
{ rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),
form_perm_nil] },
ext y,
by_cases hy : same_cycle f x y,
{ obtain ⟨k, hk, rfl⟩ := hy.nat_of_mem_support _ (mem_support.mpr hx),
rw [cycle_of_apply_apply_pow_self, list.form_perm_apply_mem_eq_next (nodup_to_list f x),
next_to_list_eq_apply, pow_succ, mul_apply],
rw mem_to_list_iff,
exact ⟨⟨k, rfl⟩, mem_support.mpr hx⟩ },
{ rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem],
simp [mem_to_list_iff, hy] }
end
lemma is_cycle.exists_unique_cycle {f : perm α} (hf : is_cycle f) :
∃! (s : cycle α), ∃ (h : s.nodup), s.form_perm h = f :=
begin
obtain ⟨x, hx, hy⟩ := id hf,
refine ⟨f.to_list x, ⟨nodup_to_list f x, _⟩, _⟩,
{ simp [form_perm_to_list, hf.cycle_of_eq hx] },
{ rintro ⟨l⟩ ⟨hn, rfl⟩,
simp only [cycle.mk_eq_coe, cycle.coe_eq_coe, subtype.coe_mk, cycle.form_perm_coe],
refine (to_list_form_perm_is_rotated_self _ _ hn _ _).symm,
{ contrapose! hx,
suffices : form_perm l = 1,
{ simp [this] },
rw form_perm_eq_one_iff _ hn,
exact nat.le_of_lt_succ hx },
{ rw ←mem_to_finset,
refine support_form_perm_le l _,
simpa using hx } }
end
lemma is_cycle.exists_unique_cycle_subtype {f : perm α} (hf : is_cycle f) :
∃! (s : {s : cycle α // s.nodup}), (s : cycle α).form_perm s.prop = f :=
begin
obtain ⟨s, ⟨hs, rfl⟩, hs'⟩ := hf.exists_unique_cycle,
refine ⟨⟨s, hs⟩, rfl, _⟩,
rintro ⟨t, ht⟩ ht',
simpa using hs' _ ⟨ht, ht'⟩
end
lemma is_cycle.exists_unique_cycle_nontrivial_subtype {f : perm α} (hf : is_cycle f) :
∃! (s : {s : cycle α // s.nodup ∧ s.nontrivial}), (s : cycle α).form_perm s.prop.left = f :=
begin
obtain ⟨⟨s, hn⟩, hs, hs'⟩ := hf.exists_unique_cycle_subtype,
refine ⟨⟨s, hn, _⟩, _, _⟩,
{ rw hn.nontrivial_iff,
subst f,
intro H,
refine hf.ne_one _,
simpa using cycle.form_perm_subsingleton _ H },
{ simpa using hs },
{ rintro ⟨t, ht, ht'⟩ ht'',
simpa using hs' ⟨t, ht⟩ ht'' }
end
/--
Given a cyclic `f : perm α`, generate the `cycle α` in the order
of application of `f`. Implemented by finding an element `x : α`
in the support of `f` in `finset.univ`, and iterating on using
`equiv.perm.to_list f x`.
-/
def to_cycle (f : perm α) (hf : is_cycle f) : cycle α :=
multiset.rec_on (finset.univ : finset α).val
(quot.mk _ [])
(λ x s l, if f x = x then l else to_list f x)
(by { intros x y m s,
refine heq_of_eq _,
split_ifs with hx hy hy; try { refl },
{ have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy,
exact quotient.sound' hc.to_list_is_rotated }})
lemma to_cycle_eq_to_list (f : perm α) (hf : is_cycle f) (x : α) (hx : f x ≠ x) :
to_cycle f hf = to_list f x :=
begin
have key : (finset.univ : finset α).val = x ::ₘ finset.univ.val.erase x,
{ simp },
rw [to_cycle, key],
simp [hx]
end
lemma nodup_to_cycle (f : perm α) (hf : is_cycle f) : (to_cycle f hf).nodup :=
begin
obtain ⟨x, hx, -⟩ := id hf,
simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _
end
lemma nontrivial_to_cycle (f : perm α) (hf : is_cycle f) : (to_cycle f hf).nontrivial :=
begin
obtain ⟨x, hx, -⟩ := id hf,
simp [to_cycle_eq_to_list f hf x hx, hx, cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]
end
/--
Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by `equiv.perm.to_cycle`.
-/
def iso_cycle : {f : perm α // is_cycle f} ≃ {s : cycle α // s.nodup ∧ s.nontrivial} :=
{ to_fun := λ f, ⟨to_cycle (f : perm α) f.prop, nodup_to_cycle f f.prop,
nontrivial_to_cycle _ f.prop⟩,
inv_fun := λ s, ⟨(s : cycle α).form_perm s.prop.left,
(s : cycle α).is_cycle_form_perm _ s.prop.right⟩,
left_inv := λ f, by
{ obtain ⟨x, hx, -⟩ := id f.prop,
simpa [to_cycle_eq_to_list (f : perm α) f.prop x hx, form_perm_to_list, subtype.ext_iff]
using f.prop.cycle_of_eq hx },
right_inv := λ s, by
{ rcases s with ⟨⟨s⟩, hn, ht⟩,
obtain ⟨x, -, -, hx, -⟩ := id ht,
have hl : 2 ≤ s.length := by simpa using cycle.length_nontrivial ht,
simp only [cycle.mk_eq_coe, cycle.nodup_coe_iff, cycle.mem_coe_iff, subtype.coe_mk,
cycle.form_perm_coe] at hn hx ⊢,
rw to_cycle_eq_to_list _ _ x,
{ refine quotient.sound' _,
exact to_list_form_perm_is_rotated_self _ hl hn _ hx },
{ rw [←mem_support, support_form_perm_of_nodup _ hn],
{ simpa using hx },
{ rintro _ rfl,
simpa [nat.succ_le_succ_iff] using hl } } } }
/--
Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by finding this `cycle α` using `fintype.choose`.
-/
def iso_cycle' : {f : perm α // is_cycle f} ≃ {s : cycle α // s.nodup ∧ s.nontrivial} :=
{ to_fun := λ f, fintype.choose _ f.prop.exists_unique_cycle_nontrivial_subtype,
inv_fun := λ s, ⟨(s : cycle α).form_perm s.prop.left,
(s : cycle α).is_cycle_form_perm _ s.prop.right⟩,
left_inv := λ f, by simpa [subtype.ext_iff]
using fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype,
right_inv := λ ⟨s, hs, ht⟩, by
{ simp [subtype.coe_mk],
convert fintype.choose_subtype_eq (λ (s' : cycle α), s'.nodup ∧ s'.nontrivial) _,
ext ⟨s', hs', ht'⟩,
simp [cycle.form_perm_eq_form_perm_iff, (iff_not_comm.mp hs.nontrivial_iff),
(iff_not_comm.mp hs'.nontrivial_iff), ht] } }
notation `c[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) :=
cycle.form_perm ↑l (cycle.nodup_coe_iff.mpr dec_trivial)
instance repr_perm [has_repr α] : has_repr (perm α) :=
⟨λ f, repr (multiset.pmap (λ (g : perm α) (hg : g.is_cycle),
iso_cycle ⟨g, hg⟩) -- to_cycle is faster?
(perm.cycle_factors_finset f).val
(λ g hg, (mem_cycle_factors_finset_iff.mp (finset.mem_def.mpr hg)).left))⟩
end equiv.perm
|
b4fea7a6695c061e6e1db86cabbb597c5931a701 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/group_theory/commutator.lean | c8f5200998a4a54bf407e1247e661bf4376a8cb6 | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 8,893 | lean | /-
Copyright (c) 2021 Jordan Brown, Thomas Browning, Patrick Lutz. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jordan Brown, Thomas Browning, Patrick Lutz
-/
import data.bracket
import group_theory.subgroup.basic
import tactic.group
/-!
# Commutators of Subgroups
If `G` is a group and `H₁ H₂ : subgroup G` then the commutator `⁅H₁, H₂⁆ : subgroup G`
is the subgroup of `G` generated by the commutators `h₁ * h₂ * h₁⁻¹ * h₂⁻¹`.
## Main definitions
* `⁅g₁, g₂⁆` : the commutator of the elements `g₁` and `g₂`
(defined by `commutator_element` elsewhere).
* `⁅H₁, H₂⁆` : the commutator of the subgroups `H₁` and `H₂`.
-/
variables {G G' F : Type*} [group G] [group G'] [monoid_hom_class F G G'] (f : F) {g₁ g₂ g₃ g : G}
lemma commutator_element_eq_one_iff_mul_comm : ⁅g₁, g₂⁆ = 1 ↔ g₁ * g₂ = g₂ * g₁ :=
by rw [commutator_element_def, mul_inv_eq_one, mul_inv_eq_iff_eq_mul]
lemma commutator_element_eq_one_iff_commute : ⁅g₁, g₂⁆ = 1 ↔ commute g₁ g₂ :=
commutator_element_eq_one_iff_mul_comm
lemma commute.commutator_eq (h : commute g₁ g₂) : ⁅g₁, g₂⁆ = 1 :=
commutator_element_eq_one_iff_commute.mpr h
variables (g₁ g₂ g₃ g)
@[simp] lemma commutator_element_one_right : ⁅g, (1 : G)⁆ = 1 :=
(commute.one_right g).commutator_eq
@[simp] lemma commutator_element_one_left : ⁅(1 : G), g⁆ = 1 :=
(commute.one_left g).commutator_eq
@[simp] lemma commutator_element_inv : ⁅g₁, g₂⁆⁻¹ = ⁅g₂, g₁⁆ :=
by simp_rw [commutator_element_def, mul_inv_rev, inv_inv, mul_assoc]
lemma map_commutator_element : (f ⁅g₁, g₂⁆ : G') = ⁅f g₁, f g₂⁆ :=
by simp_rw [commutator_element_def, map_mul f, map_inv f]
lemma conjugate_commutator_element : g₃ * ⁅g₁, g₂⁆ * g₃⁻¹ = ⁅g₃ * g₁ * g₃⁻¹, g₃ * g₂ * g₃⁻¹⁆ :=
map_commutator_element (mul_aut.conj g₃).to_monoid_hom g₁ g₂
namespace subgroup
/-- The commutator of two subgroups `H₁` and `H₂`. -/
instance commutator : has_bracket (subgroup G) (subgroup G) :=
⟨λ H₁ H₂, closure {g | ∃ (g₁ ∈ H₁) (g₂ ∈ H₂), ⁅g₁, g₂⁆ = g}⟩
lemma commutator_def (H₁ H₂ : subgroup G) :
⁅H₁, H₂⁆ = closure {g | ∃ (g₁ ∈ H₁) (g₂ ∈ H₂), ⁅g₁, g₂⁆ = g} := rfl
variables {g₁ g₂ g₃} {H₁ H₂ H₃ K₁ K₂ : subgroup G}
lemma commutator_mem_commutator (h₁ : g₁ ∈ H₁) (h₂ : g₂ ∈ H₂) : ⁅g₁, g₂⁆ ∈ ⁅H₁, H₂⁆ :=
subset_closure ⟨g₁, h₁, g₂, h₂, rfl⟩
lemma commutator_le : ⁅H₁, H₂⁆ ≤ H₃ ↔ ∀ (g₁ ∈ H₁) (g₂ ∈ H₂), ⁅g₁, g₂⁆ ∈ H₃ :=
H₃.closure_le.trans ⟨λ h a b c d, h ⟨a, b, c, d, rfl⟩, λ h g ⟨a, b, c, d, h_eq⟩, h_eq ▸ h a b c d⟩
lemma commutator_mono (h₁ : H₁ ≤ K₁) (h₂ : H₂ ≤ K₂) : ⁅H₁, H₂⁆ ≤ ⁅K₁, K₂⁆ :=
commutator_le.mpr (λ g₁ hg₁ g₂ hg₂, commutator_mem_commutator (h₁ hg₁) (h₂ hg₂))
lemma commutator_eq_bot_iff_le_centralizer : ⁅H₁, H₂⁆ = ⊥ ↔ H₁ ≤ H₂.centralizer :=
begin
rw [eq_bot_iff, commutator_le],
refine forall_congr (λ p, forall_congr (λ hp, forall_congr (λ q, forall_congr (λ hq, _)))),
rw [mem_bot, commutator_element_eq_one_iff_mul_comm, eq_comm],
end
/-- **The Three Subgroups Lemma** (via the Hall-Witt identity) -/
lemma commutator_commutator_eq_bot_of_rotate
(h1 : ⁅⁅H₂, H₃⁆, H₁⁆ = ⊥) (h2 : ⁅⁅H₃, H₁⁆, H₂⁆ = ⊥) : ⁅⁅H₁, H₂⁆, H₃⁆ = ⊥ :=
begin
simp_rw [commutator_eq_bot_iff_le_centralizer, commutator_le,
mem_centralizer_iff_commutator_eq_one, ←commutator_element_def] at h1 h2 ⊢,
intros x hx y hy z hz,
transitivity x * z * ⁅y, ⁅z⁻¹, x⁻¹⁆⁆⁻¹ * z⁻¹ * y * ⁅x⁻¹, ⁅y⁻¹, z⁆⁆⁻¹ * y⁻¹ * x⁻¹,
{ group },
{ rw [h1 _ (H₂.inv_mem hy) _ hz _ (H₁.inv_mem hx), h2 _ (H₃.inv_mem hz) _ (H₁.inv_mem hx) _ hy],
group },
end
variables (H₁ H₂)
lemma commutator_comm_le : ⁅H₁, H₂⁆ ≤ ⁅H₂, H₁⁆ :=
commutator_le.mpr (λ g₁ h₁ g₂ h₂,
commutator_element_inv g₂ g₁ ▸ ⁅H₂, H₁⁆.inv_mem_iff.mpr (commutator_mem_commutator h₂ h₁))
lemma commutator_comm : ⁅H₁, H₂⁆ = ⁅H₂, H₁⁆ :=
le_antisymm (commutator_comm_le H₁ H₂) (commutator_comm_le H₂ H₁)
section normal
instance commutator_normal [h₁ : H₁.normal] [h₂ : H₂.normal] : normal ⁅H₁, H₂⁆ :=
begin
let base : set G := {x | ∃ (g₁ ∈ H₁) (g₂ ∈ H₂), ⁅g₁, g₂⁆ = x},
change (closure base).normal,
suffices h_base : base = group.conjugates_of_set base,
{ rw h_base,
exact subgroup.normal_closure_normal },
refine set.subset.antisymm group.subset_conjugates_of_set (λ a h, _),
simp_rw [group.mem_conjugates_of_set_iff, is_conj_iff] at h,
rcases h with ⟨b, ⟨c, hc, e, he, rfl⟩, d, rfl⟩,
exact ⟨_, h₁.conj_mem c hc d, _, h₂.conj_mem e he d, (conjugate_commutator_element c e d).symm⟩,
end
lemma commutator_def' [H₁.normal] [H₂.normal] :
⁅H₁, H₂⁆ = normal_closure {g | ∃ (g₁ ∈ H₁) (g₂ ∈ H₂), ⁅g₁, g₂⁆ = g} :=
le_antisymm closure_le_normal_closure (normal_closure_le_normal subset_closure)
lemma commutator_le_right [h : H₂.normal] : ⁅H₁, H₂⁆ ≤ H₂ :=
commutator_le.mpr (λ g₁ h₁ g₂ h₂, H₂.mul_mem (h.conj_mem g₂ h₂ g₁) (H₂.inv_mem h₂))
lemma commutator_le_left [H₁.normal] : ⁅H₁, H₂⁆ ≤ H₁ :=
commutator_comm H₂ H₁ ▸ commutator_le_right H₂ H₁
@[simp] lemma commutator_bot_left : ⁅(⊥ : subgroup G), H₁⁆ = ⊥ :=
le_bot_iff.mp (commutator_le_left ⊥ H₁)
@[simp] lemma commutator_bot_right : ⁅H₁, ⊥⁆ = (⊥ : subgroup G) :=
le_bot_iff.mp (commutator_le_right H₁ ⊥)
lemma commutator_le_inf [normal H₁] [normal H₂] : ⁅H₁, H₂⁆ ≤ H₁ ⊓ H₂ :=
le_inf (commutator_le_left H₁ H₂) (commutator_le_right H₁ H₂)
end normal
lemma map_commutator (f : G →* G') : map f ⁅H₁, H₂⁆ = ⁅map f H₁, map f H₂⁆ :=
begin
simp_rw [le_antisymm_iff, map_le_iff_le_comap, commutator_le, mem_comap, map_commutator_element],
split,
{ intros p hp q hq,
exact commutator_mem_commutator (mem_map_of_mem _ hp) (mem_map_of_mem _ hq), },
{ rintros _ ⟨p, hp, rfl⟩ _ ⟨q, hq, rfl⟩,
rw ← map_commutator_element,
exact mem_map_of_mem _ (commutator_mem_commutator hp hq) }
end
variables {H₁ H₂}
lemma commutator_le_map_commutator {f : G →* G'} {K₁ K₂ : subgroup G'}
(h₁ : K₁ ≤ H₁.map f) (h₂ : K₂ ≤ H₂.map f) : ⁅K₁, K₂⁆ ≤ ⁅H₁, H₂⁆.map f :=
(commutator_mono h₁ h₂).trans (ge_of_eq (map_commutator H₁ H₂ f))
variables (H₁ H₂)
instance commutator_characteristic [h₁ : characteristic H₁] [h₂ : characteristic H₂] :
characteristic ⁅H₁, H₂⁆ :=
characteristic_iff_le_map.mpr (λ ϕ, commutator_le_map_commutator
(characteristic_iff_le_map.mp h₁ ϕ) (characteristic_iff_le_map.mp h₂ ϕ))
lemma commutator_prod_prod (K₁ K₂ : subgroup G') :
⁅H₁.prod K₁, H₂.prod K₂⁆ = ⁅H₁, H₂⁆.prod ⁅K₁, K₂⁆ :=
begin
apply le_antisymm,
{ rw commutator_le,
rintros ⟨p₁, p₂⟩ ⟨hp₁, hp₂⟩ ⟨q₁, q₂⟩ ⟨hq₁, hq₂⟩,
exact ⟨commutator_mem_commutator hp₁ hq₁, commutator_mem_commutator hp₂ hq₂⟩ },
{ rw prod_le_iff, split;
{ rw map_commutator,
apply commutator_mono;
simp [le_prod_iff, map_map, monoid_hom.fst_comp_inl, monoid_hom.snd_comp_inl,
monoid_hom.fst_comp_inr, monoid_hom.snd_comp_inr ], }, }
end
/-- The commutator of direct product is contained in the direct product of the commutators.
See `commutator_pi_pi_of_finite` for equality given `fintype η`.
-/
lemma commutator_pi_pi_le {η : Type*} {Gs : η → Type*} [∀ i, group (Gs i)]
(H K : Π i, subgroup (Gs i)) :
⁅subgroup.pi set.univ H, subgroup.pi set.univ K⁆ ≤ subgroup.pi set.univ (λ i, ⁅H i, K i⁆) :=
commutator_le.mpr $ λ p hp q hq i hi, commutator_mem_commutator (hp i hi) (hq i hi)
/-- The commutator of a finite direct product is contained in the direct product of the commutators.
-/
lemma commutator_pi_pi_of_finite {η : Type*} [finite η] {Gs : η → Type*}
[∀ i, group (Gs i)] (H K : Π i, subgroup (Gs i)) :
⁅subgroup.pi set.univ H, subgroup.pi set.univ K⁆ = subgroup.pi set.univ (λ i, ⁅H i, K i⁆) :=
begin
classical,
apply le_antisymm (commutator_pi_pi_le H K),
{ rw pi_le_iff, intros i hi,
rw map_commutator,
apply commutator_mono;
{ rw le_pi_iff,
intros j hj,
rintros _ ⟨_, ⟨x, hx, rfl⟩, rfl⟩,
by_cases h : j = i,
{ subst h, simpa using hx, },
{ simp [h, one_mem] }, }, },
end
end subgroup
|
1fab0f472b6939cc3b8e894cd527d4ac218e9d4c | 947b78d97130d56365ae2ec264df196ce769371a | /tests/lean/run/29.lean | 605f2ce0c4b122a84f15dbb8ed5c706ff25b4487 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 117 | lean | new_frontend
def foo : Nat -> Nat -> Nat -> List Nat
| _, _, 0 => [1]
| 0, _, _ => [2]
| n, d, k+1 => foo n d k
|
fb8e1b6facece4a46c17e8d85b5156973f41b3ba | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/topology/category/Top/limits.lean | e227bd9f53d48c69c82204c874f5d07e8dc7977a | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 41,059 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Scott Morrison, Mario Carneiro, Andrew Yang
-/
import topology.category.Top.epi_mono
import category_theory.limits.preserves.limits
import category_theory.category.ulift
import category_theory.limits.shapes.types
import category_theory.limits.concrete_category
/-!
# The category of topological spaces has all limits and colimits
Further, these limits and colimits are preserved by the forgetful functor --- that is, the
underlying types are just the limits in the category of types.
-/
open topological_space
open category_theory
open category_theory.limits
open opposite
universes u v w
noncomputable theory
namespace Top
variables {J : Type v} [small_category J]
local notation `forget` := forget Top
/--
A choice of limit cone for a functor `F : J ⥤ Top`.
Generally you should just use `limit.cone F`, unless you need the actual definition
(which is in terms of `types.limit_cone`).
-/
def limit_cone (F : J ⥤ Top.{max v u}) : cone F :=
{ X := Top.of {u : Π j : J, F.obj j | ∀ {i j : J} (f : i ⟶ j), F.map f (u i) = u j},
π :=
{ app := λ j,
{ to_fun := λ u, u.val j,
continuous_to_fun := show continuous ((λ u : Π j : J, F.obj j, u j) ∘ subtype.val),
by continuity } } }
/--
A choice of limit cone for a functor `F : J ⥤ Top` whose topology is defined as an
infimum of topologies infimum.
Generally you should just use `limit.cone F`, unless you need the actual definition
(which is in terms of `types.limit_cone`).
-/
def limit_cone_infi (F : J ⥤ Top.{max v u}) : cone F :=
{ X := ⟨(types.limit_cone (F ⋙ forget)).X, ⨅j,
(F.obj j).str.induced ((types.limit_cone (F ⋙ forget)).π.app j)⟩,
π :=
{ app := λ j, ⟨(types.limit_cone (F ⋙ forget)).π.app j,
continuous_iff_le_induced.mpr (infi_le _ _)⟩,
naturality' := λ j j' f, continuous_map.coe_injective
((types.limit_cone (F ⋙ forget)).π.naturality f) } }
/--
The chosen cone `Top.limit_cone F` for a functor `F : J ⥤ Top` is a limit cone.
Generally you should just use `limit.is_limit F`, unless you need the actual definition
(which is in terms of `types.limit_cone_is_limit`).
-/
def limit_cone_is_limit (F : J ⥤ Top.{max v u}) : is_limit (limit_cone F) :=
{ lift := λ S, { to_fun := λ x, ⟨λ j, S.π.app _ x, λ i j f, by { dsimp, erw ← S.w f, refl }⟩ },
uniq' := λ S m h, by { ext : 3, simpa [← h] } }
/--
The chosen cone `Top.limit_cone_infi F` for a functor `F : J ⥤ Top` is a limit cone.
Generally you should just use `limit.is_limit F`, unless you need the actual definition
(which is in terms of `types.limit_cone_is_limit`).
-/
def limit_cone_infi_is_limit (F : J ⥤ Top.{max v u}) : is_limit (limit_cone_infi F) :=
by { refine is_limit.of_faithful forget (types.limit_cone_is_limit _) (λ s, ⟨_, _⟩) (λ s, rfl),
exact continuous_iff_coinduced_le.mpr (le_infi $ λ j,
coinduced_le_iff_le_induced.mp $ (continuous_iff_coinduced_le.mp (s.π.app j).continuous :
_) ) }
instance Top_has_limits_of_size : has_limits_of_size.{v} Top.{max v u} :=
{ has_limits_of_shape := λ J 𝒥, by exactI
{ has_limit := λ F, has_limit.mk { cone := limit_cone F, is_limit := limit_cone_is_limit F } } }
instance Top_has_limits : has_limits Top.{u} := Top.Top_has_limits_of_size.{u u}
instance forget_preserves_limits_of_size :
preserves_limits_of_size.{v v} (forget : Top.{max v u} ⥤ Type (max v u)) :=
{ preserves_limits_of_shape := λ J 𝒥,
{ preserves_limit := λ F,
by exactI preserves_limit_of_preserves_limit_cone
(limit_cone_is_limit F) (types.limit_cone_is_limit (F ⋙ forget)) } }
instance forget_preserves_limits : preserves_limits (forget : Top.{u} ⥤ Type u) :=
Top.forget_preserves_limits_of_size.{u u}
/--
A choice of colimit cocone for a functor `F : J ⥤ Top`.
Generally you should just use `colimit.coone F`, unless you need the actual definition
(which is in terms of `types.colimit_cocone`).
-/
def colimit_cocone (F : J ⥤ Top.{max v u}) : cocone F :=
{ X := ⟨(types.colimit_cocone (F ⋙ forget)).X, ⨆ j,
(F.obj j).str.coinduced ((types.colimit_cocone (F ⋙ forget)).ι.app j)⟩,
ι :=
{ app := λ j, ⟨(types.colimit_cocone (F ⋙ forget)).ι.app j,
continuous_iff_coinduced_le.mpr (le_supr _ j)⟩,
naturality' := λ j j' f, continuous_map.coe_injective
((types.colimit_cocone (F ⋙ forget)).ι.naturality f) } }
/--
The chosen cocone `Top.colimit_cocone F` for a functor `F : J ⥤ Top` is a colimit cocone.
Generally you should just use `colimit.is_colimit F`, unless you need the actual definition
(which is in terms of `types.colimit_cocone_is_colimit`).
-/
def colimit_cocone_is_colimit (F : J ⥤ Top.{max v u}) : is_colimit (colimit_cocone F) :=
by { refine is_colimit.of_faithful forget (types.colimit_cocone_is_colimit _) (λ s, ⟨_, _⟩)
(λ s, rfl),
exact continuous_iff_le_induced.mpr (supr_le $ λ j,
coinduced_le_iff_le_induced.mp $ (continuous_iff_coinduced_le.mp (s.ι.app j).continuous :
_) ) }
instance Top_has_colimits_of_size : has_colimits_of_size.{v} Top.{max v u} :=
{ has_colimits_of_shape := λ J 𝒥, by exactI
{ has_colimit := λ F, has_colimit.mk { cocone := colimit_cocone F, is_colimit :=
colimit_cocone_is_colimit F } } }
instance Top_has_colimits : has_colimits Top.{u} := Top.Top_has_colimits_of_size.{u u}
instance forget_preserves_colimits_of_size :
preserves_colimits_of_size.{v v} (forget : Top.{max v u} ⥤ Type (max v u)) :=
{ preserves_colimits_of_shape := λ J 𝒥,
{ preserves_colimit := λ F,
by exactI preserves_colimit_of_preserves_colimit_cocone
(colimit_cocone_is_colimit F) (types.colimit_cocone_is_colimit (F ⋙ forget)) } }
instance forget_preserves_colimits : preserves_colimits (forget : Top.{u} ⥤ Type u) :=
Top.forget_preserves_colimits_of_size.{u u}
/-- The projection from the product as a bundled continous map. -/
abbreviation pi_π {ι : Type v} (α : ι → Top.{max v u}) (i : ι) : Top.of (Π i, α i) ⟶ α i :=
⟨λ f, f i, continuous_apply i⟩
/-- The explicit fan of a family of topological spaces given by the pi type. -/
@[simps X π_app]
def pi_fan {ι : Type v} (α : ι → Top.{max v u}) : fan α :=
fan.mk (Top.of (Π i, α i)) (pi_π α)
/-- The constructed fan is indeed a limit -/
def pi_fan_is_limit {ι : Type v} (α : ι → Top.{max v u}) : is_limit (pi_fan α) :=
{ lift := λ S, { to_fun := λ s i, S.π.app ⟨i⟩ s },
uniq' := by { intros S m h, ext x i, simp [← h ⟨i⟩] },
fac' := λ s j, by { cases j, tidy, }, }
/--
The product is homeomorphic to the product of the underlying spaces,
equipped with the product topology.
-/
def pi_iso_pi {ι : Type v} (α : ι → Top.{max v u}) : ∏ α ≅ Top.of (Π i, α i) :=
(limit.is_limit _).cone_point_unique_up_to_iso (pi_fan_is_limit α)
@[simp, reassoc]
lemma pi_iso_pi_inv_π {ι : Type v} (α : ι → Top.{max v u}) (i : ι) :
(pi_iso_pi α).inv ≫ pi.π α i = pi_π α i :=
by simp [pi_iso_pi]
@[simp]
lemma pi_iso_pi_inv_π_apply {ι : Type v} (α : ι → Top.{max v u}) (i : ι) (x : Π i, α i) :
(pi.π α i : _) ((pi_iso_pi α).inv x) = x i :=
concrete_category.congr_hom (pi_iso_pi_inv_π α i) x
@[simp]
lemma pi_iso_pi_hom_apply {ι : Type v} (α : ι → Top.{max v u}) (i : ι) (x : ∏ α) :
(pi_iso_pi α).hom x i = (pi.π α i : _) x :=
begin
have := pi_iso_pi_inv_π α i,
rw iso.inv_comp_eq at this,
exact concrete_category.congr_hom this x
end
/-- The inclusion to the coproduct as a bundled continous map. -/
abbreviation sigma_ι {ι : Type v} (α : ι → Top.{max v u}) (i : ι) : α i ⟶ Top.of (Σ i, α i) :=
⟨sigma.mk i⟩
/-- The explicit cofan of a family of topological spaces given by the sigma type. -/
@[simps X ι_app]
def sigma_cofan {ι : Type v} (α : ι → Top.{max v u}) : cofan α :=
cofan.mk (Top.of (Σ i, α i)) (sigma_ι α)
/-- The constructed cofan is indeed a colimit -/
def sigma_cofan_is_colimit {ι : Type v} (α : ι → Top.{max v u}) : is_colimit (sigma_cofan α) :=
{ desc := λ S, { to_fun := λ s, S.ι.app ⟨s.1⟩ s.2,
continuous_to_fun := by { continuity, dsimp only, continuity } },
uniq' := by { intros S m h, ext ⟨i, x⟩, simp [← h ⟨i⟩] },
fac' := λ s j, by { cases j, tidy, }, }
/--
The coproduct is homeomorphic to the disjoint union of the topological spaces.
-/
def sigma_iso_sigma {ι : Type v} (α : ι → Top.{max v u}) : ∐ α ≅ Top.of (Σ i, α i) :=
(colimit.is_colimit _).cocone_point_unique_up_to_iso (sigma_cofan_is_colimit α)
@[simp, reassoc]
lemma sigma_iso_sigma_hom_ι {ι : Type v} (α : ι → Top.{max v u}) (i : ι) :
sigma.ι α i ≫ (sigma_iso_sigma α).hom = sigma_ι α i :=
by simp [sigma_iso_sigma]
@[simp]
lemma sigma_iso_sigma_hom_ι_apply {ι : Type v} (α : ι → Top.{max v u}) (i : ι) (x : α i) :
(sigma_iso_sigma α).hom ((sigma.ι α i : _) x) = sigma.mk i x :=
concrete_category.congr_hom (sigma_iso_sigma_hom_ι α i) x
@[simp]
lemma sigma_iso_sigma_inv_apply {ι : Type v} (α : ι → Top.{max v u}) (i : ι) (x : α i) :
(sigma_iso_sigma α).inv ⟨i, x⟩ = (sigma.ι α i : _) x :=
by { rw [← sigma_iso_sigma_hom_ι_apply, ← comp_app], simp, }
lemma induced_of_is_limit {F : J ⥤ Top.{max v u}} (C : cone F) (hC : is_limit C) :
C.X.topological_space = ⨅ j, (F.obj j).topological_space.induced (C.π.app j) :=
begin
let homeo := homeo_of_iso (hC.cone_point_unique_up_to_iso (limit_cone_infi_is_limit F)),
refine homeo.inducing.induced.trans _,
change induced homeo (⨅ (j : J), _) = _,
simpa [induced_infi, induced_compose],
end
lemma limit_topology (F : J ⥤ Top.{max v u}) :
(limit F).topological_space = ⨅ j, (F.obj j).topological_space.induced (limit.π F j) :=
induced_of_is_limit _ (limit.is_limit F)
section prod
/-- The first projection from the product. -/
abbreviation prod_fst {X Y : Top.{u}} : Top.of (X × Y) ⟶ X := ⟨prod.fst⟩
/-- The second projection from the product. -/
abbreviation prod_snd {X Y : Top.{u}} : Top.of (X × Y) ⟶ Y := ⟨prod.snd⟩
/-- The explicit binary cofan of `X, Y` given by `X × Y`. -/
def prod_binary_fan (X Y : Top.{u}) : binary_fan X Y :=
binary_fan.mk prod_fst prod_snd
/-- The constructed binary fan is indeed a limit -/
def prod_binary_fan_is_limit (X Y : Top.{u}) : is_limit (prod_binary_fan X Y) :=
{ lift := λ (S : binary_fan X Y), { to_fun := λ s, (S.fst s, S.snd s) },
fac' := begin
rintros S (_|_),
tidy
end,
uniq' := begin
intros S m h,
ext x,
{ specialize h ⟨walking_pair.left⟩,
apply_fun (λ e, (e x)) at h,
exact h },
{ specialize h ⟨walking_pair.right⟩,
apply_fun (λ e, (e x)) at h,
exact h },
end }
/--
The homeomorphism between `X ⨯ Y` and the set-theoretic product of `X` and `Y`,
equipped with the product topology.
-/
def prod_iso_prod (X Y : Top.{u}) : X ⨯ Y ≅ Top.of (X × Y) :=
(limit.is_limit _).cone_point_unique_up_to_iso (prod_binary_fan_is_limit X Y)
@[simp, reassoc] lemma prod_iso_prod_hom_fst (X Y : Top.{u}) :
(prod_iso_prod X Y).hom ≫ prod_fst = limits.prod.fst :=
by simpa [← iso.eq_inv_comp, prod_iso_prod]
@[simp, reassoc] lemma prod_iso_prod_hom_snd (X Y : Top.{u}) :
(prod_iso_prod X Y).hom ≫ prod_snd = limits.prod.snd :=
by simpa [← iso.eq_inv_comp, prod_iso_prod]
@[simp] lemma prod_iso_prod_hom_apply {X Y : Top.{u}} (x : X ⨯ Y) :
(prod_iso_prod X Y).hom x =
((limits.prod.fst : X ⨯ Y ⟶ _) x, (limits.prod.snd : X ⨯ Y ⟶ _) x) :=
begin
ext,
{ exact concrete_category.congr_hom (prod_iso_prod_hom_fst X Y) x },
{ exact concrete_category.congr_hom (prod_iso_prod_hom_snd X Y) x }
end
@[simp, reassoc, elementwise] lemma prod_iso_prod_inv_fst (X Y : Top.{u}) :
(prod_iso_prod X Y).inv ≫ limits.prod.fst = prod_fst :=
by simp [iso.inv_comp_eq]
@[simp, reassoc, elementwise] lemma prod_iso_prod_inv_snd (X Y : Top.{u}) :
(prod_iso_prod X Y).inv ≫ limits.prod.snd = prod_snd :=
by simp [iso.inv_comp_eq]
lemma prod_topology {X Y : Top} :
(X ⨯ Y).topological_space =
induced (limits.prod.fst : X ⨯ Y ⟶ _) X.topological_space ⊓
induced (limits.prod.snd : X ⨯ Y ⟶ _) Y.topological_space :=
begin
let homeo := homeo_of_iso (prod_iso_prod X Y),
refine homeo.inducing.induced.trans _,
change induced homeo (_ ⊓ _) = _,
simpa [induced_compose]
end
lemma range_prod_map {W X Y Z : Top.{u}} (f : W ⟶ Y) (g : X ⟶ Z) :
set.range (limits.prod.map f g) =
(limits.prod.fst : Y ⨯ Z ⟶ _) ⁻¹' (set.range f) ∩
(limits.prod.snd : Y ⨯ Z ⟶ _) ⁻¹' (set.range g) :=
begin
ext,
split,
{ rintros ⟨y, rfl⟩,
simp only [set.mem_preimage, set.mem_range, set.mem_inter_eq, ←comp_apply],
simp only [limits.prod.map_fst, limits.prod.map_snd,
exists_apply_eq_apply, comp_apply, and_self] },
{ rintros ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩,
use (prod_iso_prod W X).inv (x₁, x₂),
apply concrete.limit_ext,
rintro ⟨⟨⟩⟩,
{ simp only [← comp_apply, category.assoc], erw limits.prod.map_fst, simp [hx₁] },
{ simp only [← comp_apply, category.assoc], erw limits.prod.map_snd, simp [hx₂] } }
end
lemma inducing_prod_map {W X Y Z : Top} {f : W ⟶ X} {g : Y ⟶ Z}
(hf : inducing f) (hg : inducing g) : inducing (limits.prod.map f g) :=
begin
constructor,
simp only [prod_topology, induced_compose, ←coe_comp, limits.prod.map_fst, limits.prod.map_snd,
induced_inf],
simp only [coe_comp],
rw [← @induced_compose _ _ _ _ _ f, ← @induced_compose _ _ _ _ _ g, ← hf.induced, ← hg.induced]
end
lemma embedding_prod_map {W X Y Z : Top} {f : W ⟶ X} {g : Y ⟶ Z}
(hf : embedding f) (hg : embedding g) : embedding (limits.prod.map f g) :=
⟨inducing_prod_map hf.to_inducing hg.to_inducing,
begin
haveI := (Top.mono_iff_injective _).mpr hf.inj,
haveI := (Top.mono_iff_injective _).mpr hg.inj,
exact (Top.mono_iff_injective _).mp infer_instance
end⟩
end prod
section pullback
variables {X Y Z : Top.{u}}
/-- The first projection from the pullback. -/
abbreviation pullback_fst (f : X ⟶ Z) (g : Y ⟶ Z) : Top.of { p : X × Y // f p.1 = g p.2 } ⟶ X :=
⟨prod.fst ∘ subtype.val⟩
/-- The second projection from the pullback. -/
abbreviation pullback_snd (f : X ⟶ Z) (g : Y ⟶ Z) : Top.of { p : X × Y // f p.1 = g p.2 } ⟶ Y :=
⟨prod.snd ∘ subtype.val⟩
/-- The explicit pullback cone of `X, Y` given by `{ p : X × Y // f p.1 = g p.2 }`. -/
def pullback_cone (f : X ⟶ Z) (g : Y ⟶ Z) : pullback_cone f g :=
pullback_cone.mk (pullback_fst f g) (pullback_snd f g) (by { ext ⟨x, h⟩, simp [h] })
/-- The constructed cone is a limit. -/
def pullback_cone_is_limit (f : X ⟶ Z) (g : Y ⟶ Z) :
is_limit (pullback_cone f g) := pullback_cone.is_limit_aux' _
begin
intro s,
split, swap,
exact { to_fun := λ x, ⟨⟨s.fst x, s.snd x⟩,
by simpa using concrete_category.congr_hom s.condition x⟩ },
refine ⟨_,_,_⟩,
{ ext, delta pullback_cone, simp },
{ ext, delta pullback_cone, simp },
{ intros m h₁ h₂,
ext x,
{ simpa using concrete_category.congr_hom h₁ x },
{ simpa using concrete_category.congr_hom h₂ x } }
end
/-- The pullback of two maps can be identified as a subspace of `X × Y`. -/
def pullback_iso_prod_subtype (f : X ⟶ Z) (g : Y ⟶ Z) :
pullback f g ≅ Top.of { p : X × Y // f p.1 = g p.2 } :=
(limit.is_limit _).cone_point_unique_up_to_iso (pullback_cone_is_limit f g)
@[simp, reassoc] lemma pullback_iso_prod_subtype_inv_fst (f : X ⟶ Z) (g : Y ⟶ Z) :
(pullback_iso_prod_subtype f g).inv ≫ pullback.fst = pullback_fst f g :=
by simpa [pullback_iso_prod_subtype]
@[simp] lemma pullback_iso_prod_subtype_inv_fst_apply (f : X ⟶ Z) (g : Y ⟶ Z)
(x : { p : X × Y // f p.1 = g p.2 }) :
(pullback.fst : pullback f g ⟶ _) ((pullback_iso_prod_subtype f g).inv x) = (x : X × Y).fst :=
concrete_category.congr_hom (pullback_iso_prod_subtype_inv_fst f g) x
@[simp, reassoc] lemma pullback_iso_prod_subtype_inv_snd (f : X ⟶ Z) (g : Y ⟶ Z) :
(pullback_iso_prod_subtype f g).inv ≫ pullback.snd = pullback_snd f g :=
by simpa [pullback_iso_prod_subtype]
@[simp] lemma pullback_iso_prod_subtype_inv_snd_apply (f : X ⟶ Z) (g : Y ⟶ Z)
(x : { p : X × Y // f p.1 = g p.2 }) :
(pullback.snd : pullback f g ⟶ _) ((pullback_iso_prod_subtype f g).inv x) = (x : X × Y).snd :=
concrete_category.congr_hom (pullback_iso_prod_subtype_inv_snd f g) x
lemma pullback_iso_prod_subtype_hom_fst (f : X ⟶ Z) (g : Y ⟶ Z) :
(pullback_iso_prod_subtype f g).hom ≫ pullback_fst f g = pullback.fst :=
by rw [←iso.eq_inv_comp, pullback_iso_prod_subtype_inv_fst]
lemma pullback_iso_prod_subtype_hom_snd (f : X ⟶ Z) (g : Y ⟶ Z) :
(pullback_iso_prod_subtype f g).hom ≫ pullback_snd f g = pullback.snd :=
by rw [←iso.eq_inv_comp, pullback_iso_prod_subtype_inv_snd]
@[simp] lemma pullback_iso_prod_subtype_hom_apply {f : X ⟶ Z} {g : Y ⟶ Z}
(x : pullback f g) : (pullback_iso_prod_subtype f g).hom x =
⟨⟨(pullback.fst : pullback f g ⟶ _) x, (pullback.snd : pullback f g ⟶ _) x⟩,
by simpa using concrete_category.congr_hom pullback.condition x⟩ :=
begin
ext,
exacts [concrete_category.congr_hom (pullback_iso_prod_subtype_hom_fst f g) x,
concrete_category.congr_hom (pullback_iso_prod_subtype_hom_snd f g) x]
end
lemma pullback_topology {X Y Z : Top.{u}} (f : X ⟶ Z) (g : Y ⟶ Z) :
(pullback f g).topological_space =
induced (pullback.fst : pullback f g ⟶ _) X.topological_space ⊓
induced (pullback.snd : pullback f g ⟶ _) Y.topological_space :=
begin
let homeo := homeo_of_iso (pullback_iso_prod_subtype f g),
refine homeo.inducing.induced.trans _,
change induced homeo (induced _ (_ ⊓ _)) = _,
simpa [induced_compose]
end
lemma range_pullback_to_prod {X Y Z : Top} (f : X ⟶ Z) (g : Y ⟶ Z) :
set.range (prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) =
{ x | (limits.prod.fst ≫ f) x = (limits.prod.snd ≫ g) x } :=
begin
ext x,
split,
{ rintros ⟨y, rfl⟩,
simp only [←comp_apply, set.mem_set_of_eq],
congr' 1,
simp [pullback.condition] },
{ intro h,
use (pullback_iso_prod_subtype f g).inv ⟨⟨_, _⟩, h⟩,
apply concrete.limit_ext,
rintro ⟨⟨⟩⟩; simp }
end
lemma inducing_pullback_to_prod {X Y Z : Top} (f : X ⟶ Z) (g : Y ⟶ Z) :
inducing ⇑(prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) :=
⟨by simp [prod_topology, pullback_topology, induced_compose, ←coe_comp]⟩
lemma embedding_pullback_to_prod {X Y Z : Top} (f : X ⟶ Z) (g : Y ⟶ Z) :
embedding ⇑(prod.lift pullback.fst pullback.snd : pullback f g ⟶ X ⨯ Y) :=
⟨inducing_pullback_to_prod f g, (Top.mono_iff_injective _).mp infer_instance⟩
/-- If the map `S ⟶ T` is mono, then there is a description of the image of `W ×ₛ X ⟶ Y ×ₜ Z`. -/
lemma range_pullback_map {W X Y Z S T : Top} (f₁ : W ⟶ S) (f₂ : X ⟶ S)
(g₁ : Y ⟶ T) (g₂ : Z ⟶ T) (i₁ : W ⟶ Y) (i₂ : X ⟶ Z) (i₃ : S ⟶ T) [H₃ : mono i₃]
(eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) :
set.range (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) =
(pullback.fst : pullback g₁ g₂ ⟶ _) ⁻¹' (set.range i₁) ∩
(pullback.snd : pullback g₁ g₂ ⟶ _) ⁻¹' (set.range i₂) :=
begin
ext,
split,
{ rintro ⟨y, rfl⟩, simp, },
rintros ⟨⟨x₁, hx₁⟩, ⟨x₂, hx₂⟩⟩,
have : f₁ x₁ = f₂ x₂,
{ apply (Top.mono_iff_injective _).mp H₃,
simp only [←comp_apply, eq₁, eq₂],
simp only [comp_apply, hx₁, hx₂],
simp only [←comp_apply, pullback.condition] },
use (pullback_iso_prod_subtype f₁ f₂).inv ⟨⟨x₁, x₂⟩, this⟩,
apply concrete.limit_ext,
rintros (_|_|_),
{ simp only [Top.comp_app, limit.lift_π_apply, category.assoc, pullback_cone.mk_π_app_one,
hx₁, pullback_iso_prod_subtype_inv_fst_apply, subtype.coe_mk],
simp only [← comp_apply],
congr,
apply limit.w _ walking_cospan.hom.inl },
{ simp [hx₁] },
{ simp [hx₂] },
end
lemma pullback_fst_range {X Y S : Top} (f : X ⟶ S) (g : Y ⟶ S) :
set.range (pullback.fst : pullback f g ⟶ _) = { x : X | ∃ y : Y, f x = g y} :=
begin
ext x,
split,
{ rintro ⟨y, rfl⟩,
use (pullback.snd : pullback f g ⟶ _) y,
exact concrete_category.congr_hom pullback.condition y },
{ rintro ⟨y, eq⟩,
use (Top.pullback_iso_prod_subtype f g).inv ⟨⟨x, y⟩, eq⟩,
simp },
end
lemma pullback_snd_range {X Y S : Top} (f : X ⟶ S) (g : Y ⟶ S) :
set.range (pullback.snd : pullback f g ⟶ _) = { y : Y | ∃ x : X, f x = g y} :=
begin
ext y,
split,
{ rintro ⟨x, rfl⟩,
use (pullback.fst : pullback f g ⟶ _) x,
exact concrete_category.congr_hom pullback.condition x },
{ rintro ⟨x, eq⟩,
use (Top.pullback_iso_prod_subtype f g).inv ⟨⟨x, y⟩, eq⟩,
simp },
end
/--
If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are embeddings,
then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an embedding.
W ⟶ Y
↘ ↘
S ⟶ T
↗ ↗
X ⟶ Z
-/
lemma pullback_map_embedding_of_embeddings {W X Y Z S T : Top}
(f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z}
(H₁ : embedding i₁) (H₂ : embedding i₂) (i₃ : S ⟶ T)
(eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) :
embedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) :=
begin
refine embedding_of_embedding_compose (continuous_map.continuous_to_fun _)
(show continuous (prod.lift pullback.fst pullback.snd : pullback g₁ g₂ ⟶ Y ⨯ Z), from
continuous_map.continuous_to_fun _) _,
suffices : embedding
(prod.lift pullback.fst pullback.snd ≫ limits.prod.map i₁ i₂ : pullback f₁ f₂ ⟶ _),
{ simpa [←coe_comp] using this },
rw coe_comp,
refine embedding.comp (embedding_prod_map H₁ H₂)
(embedding_pullback_to_prod _ _)
end
/--
If there is a diagram where the morphisms `W ⟶ Y` and `X ⟶ Z` are open embeddings, and `S ⟶ T`
is mono, then the induced morphism `W ×ₛ X ⟶ Y ×ₜ Z` is also an open embedding.
W ⟶ Y
↘ ↘
S ⟶ T
↗ ↗
X ⟶ Z
-/
lemma pullback_map_open_embedding_of_open_embeddings {W X Y Z S T : Top}
(f₁ : W ⟶ S) (f₂ : X ⟶ S) (g₁ : Y ⟶ T) (g₂ : Z ⟶ T) {i₁ : W ⟶ Y} {i₂ : X ⟶ Z}
(H₁ : open_embedding i₁) (H₂ : open_embedding i₂) (i₃ : S ⟶ T) [H₃ : mono i₃]
(eq₁ : f₁ ≫ i₃ = i₁ ≫ g₁) (eq₂ : f₂ ≫ i₃ = i₂ ≫ g₂) :
open_embedding (pullback.map f₁ f₂ g₁ g₂ i₁ i₂ i₃ eq₁ eq₂) :=
begin
split,
{ apply pullback_map_embedding_of_embeddings
f₁ f₂ g₁ g₂ H₁.to_embedding H₂.to_embedding i₃ eq₁ eq₂ },
{ rw range_pullback_map,
apply is_open.inter; apply continuous.is_open_preimage,
continuity,
exacts [H₁.open_range, H₂.open_range] }
end
lemma snd_embedding_of_left_embedding {X Y S : Top}
{f : X ⟶ S} (H : embedding f) (g : Y ⟶ S) :
embedding ⇑(pullback.snd : pullback f g ⟶ Y) :=
begin
convert (homeo_of_iso (as_iso (pullback.snd : pullback (𝟙 S) g ⟶ _))).embedding.comp
(pullback_map_embedding_of_embeddings f g (𝟙 _) g H
(homeo_of_iso (iso.refl _)).embedding (𝟙 _) rfl (by simp)),
erw ←coe_comp,
simp
end
lemma fst_embedding_of_right_embedding {X Y S : Top}
(f : X ⟶ S) {g : Y ⟶ S} (H : embedding g) :
embedding ⇑(pullback.fst : pullback f g ⟶ X) :=
begin
convert (homeo_of_iso (as_iso (pullback.fst : pullback f (𝟙 S) ⟶ _))).embedding.comp
(pullback_map_embedding_of_embeddings f g f (𝟙 _)
(homeo_of_iso (iso.refl _)).embedding H (𝟙 _) rfl (by simp)),
erw ←coe_comp,
simp
end
lemma embedding_of_pullback_embeddings {X Y S : Top}
{f : X ⟶ S} {g : Y ⟶ S} (H₁ : embedding f) (H₂ : embedding g) :
embedding (limit.π (cospan f g) walking_cospan.one) :=
begin
convert H₂.comp (snd_embedding_of_left_embedding H₁ g),
erw ←coe_comp,
congr,
exact (limit.w _ walking_cospan.hom.inr).symm
end
lemma snd_open_embedding_of_left_open_embedding {X Y S : Top}
{f : X ⟶ S} (H : open_embedding f) (g : Y ⟶ S) :
open_embedding ⇑(pullback.snd : pullback f g ⟶ Y) :=
begin
convert (homeo_of_iso (as_iso (pullback.snd : pullback (𝟙 S) g ⟶ _))).open_embedding.comp
(pullback_map_open_embedding_of_open_embeddings f g (𝟙 _) g H
(homeo_of_iso (iso.refl _)).open_embedding (𝟙 _) rfl (by simp)),
erw ←coe_comp,
simp
end
lemma fst_open_embedding_of_right_open_embedding {X Y S : Top}
(f : X ⟶ S) {g : Y ⟶ S} (H : open_embedding g) :
open_embedding ⇑(pullback.fst : pullback f g ⟶ X) :=
begin
convert (homeo_of_iso (as_iso (pullback.fst : pullback f (𝟙 S) ⟶ _))).open_embedding.comp
(pullback_map_open_embedding_of_open_embeddings f g f (𝟙 _)
(homeo_of_iso (iso.refl _)).open_embedding H (𝟙 _) rfl (by simp)),
erw ←coe_comp,
simp
end
/-- If `X ⟶ S`, `Y ⟶ S` are open embeddings, then so is `X ×ₛ Y ⟶ S`. -/
lemma open_embedding_of_pullback_open_embeddings {X Y S : Top}
{f : X ⟶ S} {g : Y ⟶ S} (H₁ : open_embedding f) (H₂ : open_embedding g) :
open_embedding (limit.π (cospan f g) walking_cospan.one) :=
begin
convert H₂.comp (snd_open_embedding_of_left_open_embedding H₁ g),
erw ←coe_comp,
congr,
exact (limit.w _ walking_cospan.hom.inr).symm
end
lemma fst_iso_of_right_embedding_range_subset {X Y S : Top} (f : X ⟶ S) {g : Y ⟶ S}
(hg : embedding g) (H : set.range f ⊆ set.range g) : is_iso (pullback.fst : pullback f g ⟶ X) :=
begin
let : (pullback f g : Top) ≃ₜ X :=
(homeomorph.of_embedding _ (fst_embedding_of_right_embedding f hg)).trans
{ to_fun := coe,
inv_fun := (λ x, ⟨x,
by { rw pullback_fst_range, exact ⟨_, (H (set.mem_range_self x)).some_spec.symm⟩ }⟩),
left_inv := λ ⟨_,_⟩, rfl,
right_inv := λ x, rfl },
convert is_iso.of_iso (iso_of_homeo this),
ext,
refl
end
lemma snd_iso_of_left_embedding_range_subset {X Y S : Top} {f : X ⟶ S} (hf : embedding f)
(g : Y ⟶ S) (H : set.range g ⊆ set.range f) : is_iso (pullback.snd : pullback f g ⟶ Y) :=
begin
let : (pullback f g : Top) ≃ₜ Y :=
(homeomorph.of_embedding _ (snd_embedding_of_left_embedding hf g)).trans
{ to_fun := coe,
inv_fun := (λ x, ⟨x,
by { rw pullback_snd_range, exact ⟨_, (H (set.mem_range_self x)).some_spec⟩ }⟩),
left_inv := λ ⟨_,_⟩, rfl,
right_inv := λ x, rfl },
convert is_iso.of_iso (iso_of_homeo this),
ext,
refl
end
lemma pullback_snd_image_fst_preimage (f : X ⟶ Z) (g : Y ⟶ Z) (U : set X) :
(pullback.snd : pullback f g ⟶ _) '' ((pullback.fst : pullback f g ⟶ _) ⁻¹' U) =
g ⁻¹' (f '' U) :=
begin
ext x,
split,
{ rintros ⟨y, hy, rfl⟩,
exact ⟨(pullback.fst : pullback f g ⟶ _) y, hy,
concrete_category.congr_hom pullback.condition y⟩ },
{ rintros ⟨y, hy, eq⟩,
exact ⟨(Top.pullback_iso_prod_subtype f g).inv ⟨⟨_,_⟩, eq⟩, by simpa, by simp⟩ },
end
lemma pullback_fst_image_snd_preimage (f : X ⟶ Z) (g : Y ⟶ Z) (U : set Y) :
(pullback.fst : pullback f g ⟶ _) '' ((pullback.snd : pullback f g ⟶ _) ⁻¹' U) =
f ⁻¹' (g '' U) :=
begin
ext x,
split,
{ rintros ⟨y, hy, rfl⟩,
exact ⟨(pullback.snd : pullback f g ⟶ _) y, hy,
(concrete_category.congr_hom pullback.condition y).symm⟩ },
{ rintros ⟨y, hy, eq⟩,
exact ⟨(Top.pullback_iso_prod_subtype f g).inv ⟨⟨_,_⟩,eq.symm⟩, by simpa, by simp⟩ },
end
end pullback
--TODO: Add analogous constructions for `coprod` and `pushout`.
lemma coinduced_of_is_colimit {F : J ⥤ Top.{max v u}} (c : cocone F) (hc : is_colimit c) :
c.X.topological_space = ⨆ j, (F.obj j).topological_space.coinduced (c.ι.app j) :=
begin
let homeo := homeo_of_iso (hc.cocone_point_unique_up_to_iso (colimit_cocone_is_colimit F)),
ext,
refine homeo.symm.is_open_preimage.symm.trans (iff.trans _ is_open_supr_iff.symm),
exact is_open_supr_iff
end
lemma colimit_topology (F : J ⥤ Top.{max v u}) :
(colimit F).topological_space = ⨆ j, (F.obj j).topological_space.coinduced (colimit.ι F j) :=
coinduced_of_is_colimit _ (colimit.is_colimit F)
lemma colimit_is_open_iff (F : J ⥤ Top.{max v u}) (U : set ((colimit F : _) : Type (max v u))) :
is_open U ↔ ∀ j, is_open (colimit.ι F j ⁻¹' U) :=
begin
conv_lhs { rw colimit_topology F },
exact is_open_supr_iff
end
lemma coequalizer_is_open_iff (F : walking_parallel_pair ⥤ Top.{u})
(U : set ((colimit F : _) : Type u)) :
is_open U ↔ is_open (colimit.ι F walking_parallel_pair.one ⁻¹' U) :=
begin
rw colimit_is_open_iff.{u},
split,
{ intro H, exact H _ },
{ intros H j,
cases j,
{ rw ←colimit.w F walking_parallel_pair_hom.left,
exact (F.map walking_parallel_pair_hom.left).continuous_to_fun.is_open_preimage _ H },
{ exact H } }
end
end Top
namespace Top
section cofiltered_limit
variables {J : Type v} [small_category J] [is_cofiltered J] (F : J ⥤ Top.{max v u})
(C : cone F) (hC : is_limit C)
include hC
/--
Given a *compatible* collection of topological bases for the factors in a cofiltered limit
which contain `set.univ` and are closed under intersections, the induced *naive* collection
of sets in the limit is, in fact, a topological basis.
-/
theorem is_topological_basis_cofiltered_limit
(T : Π j, set (set (F.obj j))) (hT : ∀ j, is_topological_basis (T j))
(univ : ∀ (i : J), set.univ ∈ T i)
(inter : ∀ i (U1 U2 : set (F.obj i)), U1 ∈ T i → U2 ∈ T i → U1 ∩ U2 ∈ T i)
(compat : ∀ (i j : J) (f : i ⟶ j) (V : set (F.obj j)) (hV : V ∈ T j), (F.map f) ⁻¹' V ∈ T i) :
is_topological_basis { U : set C.X | ∃ j (V : set (F.obj j)), V ∈ T j ∧ U = C.π.app j ⁻¹' V } :=
begin
classical,
-- The limit cone for `F` whose topology is defined as an infimum.
let D := limit_cone_infi F,
-- The isomorphism between the cone point of `C` and the cone point of `D`.
let E : C.X ≅ D.X := hC.cone_point_unique_up_to_iso (limit_cone_infi_is_limit _),
have hE : inducing E.hom := (Top.homeo_of_iso E).inducing,
-- Reduce to the assertion of the theorem with `D` instead of `C`.
suffices : is_topological_basis
{ U : set D.X | ∃ j (V : set (F.obj j)), V ∈ T j ∧ U = D.π.app j ⁻¹' V },
{ convert this.inducing hE,
ext U0,
split,
{ rintro ⟨j, V, hV, rfl⟩,
refine ⟨D.π.app j ⁻¹' V, ⟨j, V, hV, rfl⟩, rfl⟩ },
{ rintro ⟨W, ⟨j, V, hV, rfl⟩, rfl⟩,
refine ⟨j, V, hV, rfl⟩ } },
-- Using `D`, we can apply the characterization of the topological basis of a
-- topology defined as an infimum...
convert is_topological_basis_infi hT (λ j (x : D.X), D.π.app j x),
ext U0,
split,
{ rintros ⟨j, V, hV, rfl⟩,
let U : Π i, set (F.obj i) := λ i, if h : i = j then (by {rw h, exact V}) else set.univ,
refine ⟨U,{j},_,_⟩,
{ rintro i h,
rw finset.mem_singleton at h,
dsimp [U],
rw dif_pos h,
subst h,
exact hV },
{ dsimp [U],
simp } },
{ rintros ⟨U, G, h1, h2⟩,
obtain ⟨j, hj⟩ := is_cofiltered.inf_objs_exists G,
let g : ∀ e (he : e ∈ G), j ⟶ e := λ _ he, (hj he).some,
let Vs : J → set (F.obj j) := λ e, if h : e ∈ G then F.map (g e h) ⁻¹' (U e) else set.univ,
let V : set (F.obj j) := ⋂ (e : J) (he : e ∈ G), Vs e,
refine ⟨j, V, _, _⟩,
{ -- An intermediate claim used to apply induction along `G : finset J` later on.
have : ∀ (S : set (set (F.obj j))) (E : finset J) (P : J → set (F.obj j))
(univ : set.univ ∈ S)
(inter : ∀ A B : set (F.obj j), A ∈ S → B ∈ S → A ∩ B ∈ S)
(cond : ∀ (e : J) (he : e ∈ E), P e ∈ S), (⋂ e (he : e ∈ E), P e) ∈ S,
{ intros S E,
apply E.induction_on,
{ intros P he hh,
simpa },
{ intros a E ha hh1 hh2 hh3 hh4 hh5,
rw finset.set_bInter_insert,
refine hh4 _ _ (hh5 _ (finset.mem_insert_self _ _)) (hh1 _ hh3 hh4 _),
intros e he,
exact hh5 e (finset.mem_insert_of_mem he) } },
-- use the intermediate claim to finish off the goal using `univ` and `inter`.
refine this _ _ _ (univ _) (inter _) _,
intros e he,
dsimp [Vs],
rw dif_pos he,
exact compat j e (g e he) (U e) (h1 e he), },
{ -- conclude...
rw h2,
dsimp [V],
rw set.preimage_Inter,
congr' 1,
ext1 e,
rw set.preimage_Inter,
congr' 1,
ext1 he,
dsimp [Vs],
rw [dif_pos he, ← set.preimage_comp],
congr' 1,
change _ = ⇑(D.π.app j ≫ F.map (g e he)),
rw D.w } }
end
end cofiltered_limit
section topological_konig
/-!
## Topological Kőnig's lemma
A topological version of Kőnig's lemma is that the inverse limit of nonempty compact Hausdorff
spaces is nonempty. (Note: this can be generalized further to inverse limits of nonempty compact
T0 spaces, where all the maps are closed maps; see [Stone1979] --- however there is an erratum
for Theorem 4 that the element in the inverse limit can have cofinally many components that are
not closed points.)
We give this in a more general form, which is that cofiltered limits
of nonempty compact Hausdorff spaces are nonempty
(`nonempty_limit_cone_of_compact_t2_cofiltered_system`).
This also applies to inverse limits, where `{J : Type u} [preorder J] [is_directed J (≤)]` and
`F : Jᵒᵖ ⥤ Top`.
The theorem is specialized to nonempty finite types (which are compact Hausdorff with the
discrete topology) in `nonempty_sections_of_fintype_cofiltered_system` and
`nonempty_sections_of_fintype_inverse_system`.
(See <https://stacks.math.columbia.edu/tag/086J> for the Set version.)
-/
variables {J : Type u} [small_category J]
variables (F : J ⥤ Top.{u})
private abbreviation finite_diagram_arrow {J : Type u} [small_category J] (G : finset J) :=
Σ' (X Y : J) (mX : X ∈ G) (mY : Y ∈ G), X ⟶ Y
private abbreviation finite_diagram (J : Type u) [small_category J] :=
Σ (G : finset J), finset (finite_diagram_arrow G)
/--
Partial sections of a cofiltered limit are sections when restricted to
a finite subset of objects and morphisms of `J`.
-/
def partial_sections {J : Type u} [small_category J] (F : J ⥤ Top.{u})
{G : finset J} (H : finset (finite_diagram_arrow G)) : set (Π j, F.obj j) :=
{ u | ∀ {f : finite_diagram_arrow G} (hf : f ∈ H), F.map f.2.2.2.2 (u f.1) = u f.2.1 }
lemma partial_sections.nonempty [is_cofiltered J] [h : Π (j : J), nonempty (F.obj j)]
{G : finset J} (H : finset (finite_diagram_arrow G)) :
(partial_sections F H).nonempty :=
begin
classical,
use λ (j : J), if hj : j ∈ G
then F.map (is_cofiltered.inf_to G H hj) (h (is_cofiltered.inf G H)).some
else (h _).some,
rintros ⟨X, Y, hX, hY, f⟩ hf,
dsimp only,
rwa [dif_pos hX, dif_pos hY, ←comp_app, ←F.map_comp,
@is_cofiltered.inf_to_commutes _ _ _ G H],
end
lemma partial_sections.directed :
directed superset (λ (G : finite_diagram J), partial_sections F G.2) :=
begin
classical,
intros A B,
let ιA : finite_diagram_arrow A.1 → finite_diagram_arrow (A.1 ⊔ B.1) :=
λ f, ⟨f.1, f.2.1, finset.mem_union_left _ f.2.2.1, finset.mem_union_left _ f.2.2.2.1,
f.2.2.2.2⟩,
let ιB : finite_diagram_arrow B.1 → finite_diagram_arrow (A.1 ⊔ B.1) :=
λ f, ⟨f.1, f.2.1, finset.mem_union_right _ f.2.2.1, finset.mem_union_right _ f.2.2.2.1,
f.2.2.2.2⟩,
refine ⟨⟨A.1 ⊔ B.1, A.2.image ιA ⊔ B.2.image ιB⟩, _, _⟩,
{ rintro u hu f hf,
have : ιA f ∈ A.2.image ιA ⊔ B.2.image ιB,
{ apply finset.mem_union_left,
rw finset.mem_image,
refine ⟨f, hf, rfl⟩ },
exact hu this },
{ rintro u hu f hf,
have : ιB f ∈ A.2.image ιA ⊔ B.2.image ιB,
{ apply finset.mem_union_right,
rw finset.mem_image,
refine ⟨f, hf, rfl⟩ },
exact hu this }
end
lemma partial_sections.closed [Π (j : J), t2_space (F.obj j)]
{G : finset J} (H : finset (finite_diagram_arrow G)) :
is_closed (partial_sections F H) :=
begin
have : partial_sections F H =
⋂ {f : finite_diagram_arrow G} (hf : f ∈ H), { u | F.map f.2.2.2.2 (u f.1) = u f.2.1 },
{ ext1,
simp only [set.mem_Inter, set.mem_set_of_eq],
refl, },
rw this,
apply is_closed_bInter,
intros f hf,
apply is_closed_eq,
continuity,
end
/--
Cofiltered limits of nonempty compact Hausdorff spaces are nonempty topological spaces.
--/
lemma nonempty_limit_cone_of_compact_t2_cofiltered_system
[is_cofiltered J]
[Π (j : J), nonempty (F.obj j)]
[Π (j : J), compact_space (F.obj j)]
[Π (j : J), t2_space (F.obj j)] :
nonempty (Top.limit_cone.{u} F).X :=
begin
classical,
obtain ⟨u, hu⟩ := is_compact.nonempty_Inter_of_directed_nonempty_compact_closed
(λ G, partial_sections F _)
(partial_sections.directed F)
(λ G, partial_sections.nonempty F _)
(λ G, is_closed.is_compact (partial_sections.closed F _))
(λ G, partial_sections.closed F _),
use u,
intros X Y f,
let G : finite_diagram J :=
⟨{X, Y},
{⟨X, Y,
by simp only [true_or, eq_self_iff_true, finset.mem_insert],
by simp only [eq_self_iff_true, or_true, finset.mem_insert, finset.mem_singleton],
f⟩}⟩,
exact hu _ ⟨G, rfl⟩ (finset.mem_singleton_self _),
end
end topological_konig
end Top
section fintype_konig
/-- This bootstraps `nonempty_sections_of_fintype_inverse_system`. In this version,
the `F` functor is between categories of the same universe, and it is an easy
corollary to `Top.nonempty_limit_cone_of_compact_t2_inverse_system`. -/
lemma nonempty_sections_of_fintype_cofiltered_system.init
{J : Type u} [small_category J] [is_cofiltered J] (F : J ⥤ Type u)
[hf : Π (j : J), fintype (F.obj j)] [hne : Π (j : J), nonempty (F.obj j)] :
F.sections.nonempty :=
begin
let F' : J ⥤ Top := F ⋙ Top.discrete,
haveI : Π (j : J), fintype (F'.obj j) := hf,
haveI : Π (j : J), nonempty (F'.obj j) := hne,
obtain ⟨⟨u, hu⟩⟩ := Top.nonempty_limit_cone_of_compact_t2_cofiltered_system F',
exact ⟨u, λ _ _ f, hu f⟩,
end
/-- The cofiltered limit of nonempty finite types is nonempty.
See `nonempty_sections_of_fintype_inverse_system` for a specialization to inverse limits. -/
theorem nonempty_sections_of_fintype_cofiltered_system
{J : Type u} [category.{w} J] [is_cofiltered J] (F : J ⥤ Type v)
[Π (j : J), fintype (F.obj j)] [Π (j : J), nonempty (F.obj j)] :
F.sections.nonempty :=
begin
-- Step 1: lift everything to the `max u v w` universe.
let J' : Type (max w v u) := as_small.{max w v} J,
let down : J' ⥤ J := as_small.down,
let F' : J' ⥤ Type (max u v w) := down ⋙ F ⋙ ulift_functor.{(max u w) v},
haveI : ∀ i, nonempty (F'.obj i) := λ i, ⟨⟨classical.arbitrary (F.obj (down.obj i))⟩⟩,
haveI : ∀ i, fintype (F'.obj i) := λ i, fintype.of_equiv (F.obj (down.obj i)) equiv.ulift.symm,
-- Step 2: apply the bootstrap theorem
obtain ⟨u, hu⟩ := nonempty_sections_of_fintype_cofiltered_system.init F',
-- Step 3: interpret the results
use λ j, (u ⟨j⟩).down,
intros j j' f,
have h := @hu (⟨j⟩ : J') (⟨j'⟩ : J') (ulift.up f),
simp only [as_small.down, functor.comp_map, ulift_functor_map, functor.op_map] at h,
simp_rw [←h],
refl,
end
/-- The inverse limit of nonempty finite types is nonempty.
See `nonempty_sections_of_fintype_cofiltered_system` for a generalization to cofiltered limits.
That version applies in almost all cases, and the only difference is that this version
allows `J` to be empty.
This may be regarded as a generalization of Kőnig's lemma.
To specialize: given a locally finite connected graph, take `Jᵒᵖ` to be `ℕ` and
`F j` to be length-`j` paths that start from an arbitrary fixed vertex.
Elements of `F.sections` can be read off as infinite rays in the graph. -/
theorem nonempty_sections_of_fintype_inverse_system
{J : Type u} [preorder J] [is_directed J (≤)] (F : Jᵒᵖ ⥤ Type v)
[Π (j : Jᵒᵖ), fintype (F.obj j)] [Π (j : Jᵒᵖ), nonempty (F.obj j)] :
F.sections.nonempty :=
begin
casesI is_empty_or_nonempty J,
{ haveI : is_empty Jᵒᵖ := ⟨λ j, is_empty_elim j.unop⟩, -- TODO: this should be a global instance
exact ⟨is_empty_elim, is_empty_elim⟩, },
{ exact nonempty_sections_of_fintype_cofiltered_system _, },
end
end fintype_konig
|
4e687b299ec82ca0e741c13fbddcc75db5b03baf | 94e33a31faa76775069b071adea97e86e218a8ee | /src/logic/equiv/transfer_instance.lean | 8613f86aa461064ebd1565feab1439bdf56987db | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 16,127 | 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 algebra.algebra.basic
import algebra.field.basic
import algebra.group.type_tags
import logic.equiv.basic
import ring_theory.ideal.local_ring
/-!
# Transfer algebraic structures across `equiv`s
In this file we prove theorems of the following form: if `β` has a
group structure and `α ≃ β` then `α` has a group structure, and
similarly for monoids, semigroups, rings, integral domains, fields and
so on.
Note that most of these constructions can also be obtained using the `transport` tactic.
## Tags
equiv, group, ring, field, module, algebra
-/
universes u v
variables {α : Type u} {β : Type v}
namespace equiv
section instances
variables (e : α ≃ β)
/-- Transfer `has_one` across an `equiv` -/
@[to_additive "Transfer `has_zero` across an `equiv`"]
protected def has_one [has_one β] : has_one α := ⟨e.symm 1⟩
@[to_additive]
lemma one_def [has_one β] : @has_one.one _ (equiv.has_one e) = e.symm 1 := rfl
/-- Transfer `has_mul` across an `equiv` -/
@[to_additive "Transfer `has_add` across an `equiv`"]
protected def has_mul [has_mul β] : has_mul α := ⟨λ x y, e.symm (e x * e y)⟩
@[to_additive]
lemma mul_def [has_mul β] (x y : α) :
@has_mul.mul _ (equiv.has_mul e) x y = e.symm (e x * e y) := rfl
/-- Transfer `has_div` across an `equiv` -/
@[to_additive "Transfer `has_sub` across an `equiv`"]
protected def has_div [has_div β] : has_div α := ⟨λ x y, e.symm (e x / e y)⟩
@[to_additive]
lemma div_def [has_div β] (x y : α) :
@has_div.div _ (equiv.has_div e) x y = e.symm (e x / e y) := rfl
/-- Transfer `has_inv` across an `equiv` -/
@[to_additive "Transfer `has_neg` across an `equiv`"]
protected def has_inv [has_inv β] : has_inv α := ⟨λ x, e.symm (e x)⁻¹⟩
@[to_additive]
lemma inv_def [has_inv β] (x : α) : @has_inv.inv _ (equiv.has_inv e) x = e.symm (e x)⁻¹ := rfl
/-- Transfer `has_smul` across an `equiv` -/
protected def has_smul (R : Type*) [has_smul R β] : has_smul R α :=
⟨λ r x, e.symm (r • (e x))⟩
lemma smul_def {R : Type*} [has_smul R β] (r : R) (x : α) :
@has_smul.smul _ _ (e.has_smul R) r x = e.symm (r • (e x)) := rfl
/-- Transfer `has_pow` across an `equiv` -/
@[to_additive has_smul]
protected def has_pow (N : Type*) [has_pow β N] : has_pow α N :=
⟨λ x n, e.symm (e x ^ n)⟩
lemma pow_def {N : Type*} [has_pow β N] (n : N) (x : α) :
@has_pow.pow _ _ (e.has_pow N) x n = e.symm (e x ^ n) := rfl
/--
An equivalence `e : α ≃ β` gives a multiplicative equivalence `α ≃* β`
where the multiplicative structure on `α` is
the one obtained by transporting a multiplicative structure on `β` back along `e`.
-/
@[to_additive
"An equivalence `e : α ≃ β` gives a additive equivalence `α ≃+ β`
where the additive structure on `α` is
the one obtained by transporting an additive structure on `β` back along `e`."]
def mul_equiv (e : α ≃ β) [has_mul β] :
by { letI := equiv.has_mul e, exact α ≃* β } :=
begin
introsI,
exact
{ map_mul' := λ x y, by { apply e.symm.injective, simp, refl, },
..e }
end
@[simp, to_additive] lemma mul_equiv_apply (e : α ≃ β) [has_mul β] (a : α) :
(mul_equiv e) a = e a := rfl
@[to_additive] lemma mul_equiv_symm_apply (e : α ≃ β) [has_mul β] (b : β) :
by { letI := equiv.has_mul e, exact (mul_equiv e).symm b = e.symm b } :=
begin
intros, refl,
end
/--
An equivalence `e : α ≃ β` gives a ring equivalence `α ≃+* β`
where the ring structure on `α` is
the one obtained by transporting a ring structure on `β` back along `e`.
-/
def ring_equiv (e : α ≃ β) [has_add β] [has_mul β] :
by { letI := equiv.has_add e, letI := equiv.has_mul e, exact α ≃+* β } :=
begin
introsI,
exact
{ map_add' := λ x y, by { apply e.symm.injective, simp, refl, },
map_mul' := λ x y, by { apply e.symm.injective, simp, refl, },
..e }
end
@[simp] lemma ring_equiv_apply (e : α ≃ β) [has_add β] [has_mul β] (a : α) :
(ring_equiv e) a = e a := rfl
lemma ring_equiv_symm_apply (e : α ≃ β) [has_add β] [has_mul β] (b : β) :
by { letI := equiv.has_add e, letI := equiv.has_mul e, exact (ring_equiv e).symm b = e.symm b } :=
begin
intros, refl,
end
/-- Transfer `semigroup` across an `equiv` -/
@[to_additive "Transfer `add_semigroup` across an `equiv`"]
protected def semigroup [semigroup β] : semigroup α :=
let mul := e.has_mul in
by resetI; apply e.injective.semigroup _; intros; exact e.apply_symm_apply _
/-- Transfer `semigroup_with_zero` across an `equiv` -/
protected def semigroup_with_zero [semigroup_with_zero β] : semigroup_with_zero α :=
let mul := e.has_mul, zero := e.has_zero in
by resetI; apply e.injective.semigroup_with_zero _; intros; exact e.apply_symm_apply _
/-- Transfer `comm_semigroup` across an `equiv` -/
@[to_additive "Transfer `add_comm_semigroup` across an `equiv`"]
protected def comm_semigroup [comm_semigroup β] : comm_semigroup α :=
let mul := e.has_mul in
by resetI; apply e.injective.comm_semigroup _; intros; exact e.apply_symm_apply _
/-- Transfer `mul_zero_class` across an `equiv` -/
protected def mul_zero_class [mul_zero_class β] : mul_zero_class α :=
let zero := e.has_zero, mul := e.has_mul in
by resetI; apply e.injective.mul_zero_class _; intros; exact e.apply_symm_apply _
/-- Transfer `mul_one_class` across an `equiv` -/
@[to_additive "Transfer `add_zero_class` across an `equiv`"]
protected def mul_one_class [mul_one_class β] : mul_one_class α :=
let one := e.has_one, mul := e.has_mul in
by resetI; apply e.injective.mul_one_class _; intros; exact e.apply_symm_apply _
/-- Transfer `mul_zero_one_class` across an `equiv` -/
protected def mul_zero_one_class [mul_zero_one_class β] : mul_zero_one_class α :=
let zero := e.has_zero, one := e.has_one,mul := e.has_mul in
by resetI; apply e.injective.mul_zero_one_class _; intros; exact e.apply_symm_apply _
/-- Transfer `monoid` across an `equiv` -/
@[to_additive "Transfer `add_monoid` across an `equiv`"]
protected def monoid [monoid β] : monoid α :=
let one := e.has_one, mul := e.has_mul, pow := e.has_pow ℕ in
by resetI; apply e.injective.monoid _; intros; exact e.apply_symm_apply _
/-- Transfer `comm_monoid` across an `equiv` -/
@[to_additive "Transfer `add_comm_monoid` across an `equiv`"]
protected def comm_monoid [comm_monoid β] : comm_monoid α :=
let one := e.has_one, mul := e.has_mul, pow := e.has_pow ℕ in
by resetI; apply e.injective.comm_monoid _; intros; exact e.apply_symm_apply _
/-- Transfer `group` across an `equiv` -/
@[to_additive "Transfer `add_group` across an `equiv`"]
protected def group [group β] : group α :=
let one := e.has_one, mul := e.has_mul, inv := e.has_inv, div := e.has_div,
npow := e.has_pow ℕ, zpow := e.has_pow ℤ in
by resetI; apply e.injective.group _; intros; exact e.apply_symm_apply _
/-- Transfer `comm_group` across an `equiv` -/
@[to_additive "Transfer `add_comm_group` across an `equiv`"]
protected def comm_group [comm_group β] : comm_group α :=
let one := e.has_one, mul := e.has_mul, inv := e.has_inv, div := e.has_div,
npow := e.has_pow ℕ, zpow := e.has_pow ℤ in
by resetI; apply e.injective.comm_group _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_non_assoc_semiring` across an `equiv` -/
protected def non_unital_non_assoc_semiring [non_unital_non_assoc_semiring β] :
non_unital_non_assoc_semiring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, nsmul := e.has_smul ℕ in
by resetI; apply e.injective.non_unital_non_assoc_semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_semiring` across an `equiv` -/
protected def non_unital_semiring [non_unital_semiring β] : non_unital_semiring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, nsmul := e.has_smul ℕ in
by resetI; apply e.injective.non_unital_semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `add_monoid_with_one` across an `equiv` -/
protected def add_monoid_with_one [add_monoid_with_one β] : add_monoid_with_one α :=
{ nat_cast := λ n, e.symm n,
nat_cast_zero := show e.symm _ = _, by simp [zero_def],
nat_cast_succ := λ n, show e.symm _ = e.symm (e (e.symm _) + _), by simp [add_def, one_def],
.. e.add_monoid, .. e.has_one }
/-- Transfer `add_group_with_one` across an `equiv` -/
protected def add_group_with_one [add_group_with_one β] : add_group_with_one α :=
{ int_cast := λ n, e.symm n,
int_cast_of_nat := λ n, by rw [int.cast_coe_nat]; refl,
int_cast_neg_succ_of_nat := λ n, congr_arg e.symm $
(int.cast_neg_succ_of_nat _).trans $ congr_arg _ (e.apply_symm_apply _).symm,
.. e.add_monoid_with_one, .. e.add_group }
/-- Transfer `non_assoc_semiring` across an `equiv` -/
protected def non_assoc_semiring [non_assoc_semiring β] : non_assoc_semiring α :=
let mul := e.has_mul, add_monoid_with_one := e.add_monoid_with_one in
by resetI; apply e.injective.non_assoc_semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `semiring` across an `equiv` -/
protected def semiring [semiring β] : semiring α :=
let mul := e.has_mul, add_monoid_with_one := e.add_monoid_with_one, npow := e.has_pow ℕ in
by resetI; apply e.injective.semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_comm_semiring` across an `equiv` -/
protected def non_unital_comm_semiring [non_unital_comm_semiring β] : non_unital_comm_semiring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, nsmul := e.has_smul ℕ in
by resetI; apply e.injective.non_unital_comm_semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `comm_semiring` across an `equiv` -/
protected def comm_semiring [comm_semiring β] : comm_semiring α :=
let mul := e.has_mul, add_monoid_with_one := e.add_monoid_with_one, npow := e.has_pow ℕ in
by resetI; apply e.injective.comm_semiring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_non_assoc_ring` across an `equiv` -/
protected def non_unital_non_assoc_ring [non_unital_non_assoc_ring β] :
non_unital_non_assoc_ring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, neg := e.has_neg, sub := e.has_sub,
nsmul := e.has_smul ℕ, zsmul := e.has_smul ℤ in
by resetI; apply e.injective.non_unital_non_assoc_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_ring` across an `equiv` -/
protected def non_unital_ring [non_unital_ring β] :
non_unital_ring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, neg := e.has_neg, sub := e.has_sub,
nsmul := e.has_smul ℕ, zsmul := e.has_smul ℤ in
by resetI; apply e.injective.non_unital_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_assoc_ring` across an `equiv` -/
protected def non_assoc_ring [non_assoc_ring β] :
non_assoc_ring α :=
let add_group_with_one := e.add_group_with_one, mul := e.has_mul in
by resetI; apply e.injective.non_assoc_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `ring` across an `equiv` -/
protected def ring [ring β] : ring α :=
let mul := e.has_mul, add_group_with_one := e.add_group_with_one, npow := e.has_pow ℕ in
by resetI; apply e.injective.ring _; intros; exact e.apply_symm_apply _
/-- Transfer `non_unital_comm_ring` across an `equiv` -/
protected def non_unital_comm_ring [non_unital_comm_ring β] : non_unital_comm_ring α :=
let zero := e.has_zero, add := e.has_add, mul := e.has_mul, neg := e.has_neg,
sub := e.has_sub, nsmul := e.has_smul ℕ, zsmul := e.has_smul ℤ in
by resetI; apply e.injective.non_unital_comm_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `comm_ring` across an `equiv` -/
protected def comm_ring [comm_ring β] : comm_ring α :=
let mul := e.has_mul, add_group_with_one := e.add_group_with_one, npow := e.has_pow ℕ in
by resetI; apply e.injective.comm_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `nontrivial` across an `equiv` -/
protected theorem nontrivial [nontrivial β] : nontrivial α :=
e.surjective.nontrivial
/-- Transfer `is_domain` across an `equiv` -/
protected theorem is_domain [ring α] [ring β] [is_domain β] (e : α ≃+* β) : is_domain α :=
function.injective.is_domain e.to_ring_hom e.injective
/-- Transfer `division_ring` across an `equiv` -/
protected def division_ring [division_ring β] : division_ring α :=
let add_group_with_one := e.add_group_with_one, mul := e.has_mul,
inv := e.has_inv, div := e.has_div, mul := e.has_mul, npow := e.has_pow ℕ, zpow := e.has_pow ℤ in
by resetI; apply e.injective.division_ring _; intros; exact e.apply_symm_apply _
/-- Transfer `field` across an `equiv` -/
protected def field [field β] : field α :=
let add_group_with_one := e.add_group_with_one, mul := e.has_mul, neg := e.has_neg,
inv := e.has_inv, div := e.has_div, mul := e.has_mul, npow := e.has_pow ℕ, zpow := e.has_pow ℤ in
by resetI; apply e.injective.field _; intros; exact e.apply_symm_apply _
section R
variables (R : Type*)
include R
section
variables [monoid R]
/-- Transfer `mul_action` across an `equiv` -/
protected def mul_action (e : α ≃ β) [mul_action R β] : mul_action R α :=
{ one_smul := by simp [smul_def],
mul_smul := by simp [smul_def, mul_smul],
..e.has_smul R }
/-- Transfer `distrib_mul_action` across an `equiv` -/
protected def distrib_mul_action (e : α ≃ β) [add_comm_monoid β] :
begin
letI := equiv.add_comm_monoid e,
exact Π [distrib_mul_action R β], distrib_mul_action R α
end :=
begin
intros,
letI := equiv.add_comm_monoid e,
exact (
{ smul_zero := by simp [zero_def, smul_def],
smul_add := by simp [add_def, smul_def, smul_add],
..equiv.mul_action R e } : distrib_mul_action R α)
end
end
section
variables [semiring R]
/-- Transfer `module` across an `equiv` -/
protected def module (e : α ≃ β) [add_comm_monoid β] :
begin
letI := equiv.add_comm_monoid e,
exact Π [module R β], module R α
end :=
begin
introsI,
exact (
{ zero_smul := by simp [zero_def, smul_def],
add_smul := by simp [add_def, smul_def, add_smul],
..equiv.distrib_mul_action R e } : module R α)
end
/--
An equivalence `e : α ≃ β` gives a linear equivalence `α ≃ₗ[R] β`
where the `R`-module structure on `α` is
the one obtained by transporting an `R`-module structure on `β` back along `e`.
-/
def linear_equiv (e : α ≃ β) [add_comm_monoid β] [module R β] :
begin
letI := equiv.add_comm_monoid e,
letI := equiv.module R e,
exact α ≃ₗ[R] β
end :=
begin
introsI,
exact
{ map_smul' := λ r x, by { apply e.symm.injective, simp, refl, },
..equiv.add_equiv e }
end
end
section
variables [comm_semiring R]
/-- Transfer `algebra` across an `equiv` -/
protected def algebra (e : α ≃ β) [semiring β] :
begin
letI := equiv.semiring e,
exact Π [algebra R β], algebra R α
end :=
begin
introsI,
fapply ring_hom.to_algebra',
{ exact ((ring_equiv e).symm : β →+* α).comp (algebra_map R β), },
{ intros r x,
simp only [function.comp_app, ring_hom.coe_comp],
have p := ring_equiv_symm_apply e,
dsimp at p,
erw p, clear p,
apply (ring_equiv e).injective,
simp only [(ring_equiv e).map_mul],
simp [algebra.commutes], }
end
/--
An equivalence `e : α ≃ β` gives an algebra equivalence `α ≃ₐ[R] β`
where the `R`-algebra structure on `α` is
the one obtained by transporting an `R`-algebra structure on `β` back along `e`.
-/
def alg_equiv (e : α ≃ β) [semiring β] [algebra R β] :
begin
letI := equiv.semiring e,
letI := equiv.algebra R e,
exact α ≃ₐ[R] β
end :=
begin
introsI,
exact
{ commutes' := λ r, by { apply e.symm.injective, simp, refl, },
..equiv.ring_equiv e }
end
end
end R
end instances
end equiv
namespace ring_equiv
protected lemma local_ring {A B : Type*} [comm_semiring A] [local_ring A] [comm_semiring B]
(e : A ≃+* B) : local_ring B :=
begin
haveI := e.symm.to_equiv.nontrivial,
exact local_ring.of_surjective (e : A →+* B) e.surjective
end
end ring_equiv
|
f3e12f1f4f271ae45b415aec59a1ac996ae5b2ed | f10d66a159ce037d07005bd6021cee6bbd6d5ff0 | /to_multiset.lean | 237b4025841af25d5d63d489b1da5077bf8177bd | [] | no_license | johoelzl/mason-stother | 0c78bca183eb729d7f0f93e87ce073bc8cd8808d | 573ecfaada288176462c03c87b80ad05bdab4644 | refs/heads/master | 1,631,751,973,492 | 1,528,923,934,000 | 1,528,923,934,000 | 109,133,224 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 11,356 | lean | import data.finsupp .to_finsupp
open classical
local attribute [instance] prop_decidable
noncomputable theory
local infix ^ := monoid.pow
universe u
variable α : Type u
namespace multiset
--simp correct?
theorem multiset.not_mem_empty (a : α) : a ∉ (∅ : finset α) := id --why does this work?
lemma map_id_eq {f : multiset α} : f.map id = f :=
begin
apply multiset.induction_on f,
{
simp
},
{
simp
}
end
lemma prod_mul_prod_eq_add_prod [comm_monoid α] {a b : multiset α} : a.prod * b.prod = (a + b).prod :=
begin
simp,
end
open finsupp
def to_finsupp {α : Type u} (m : multiset α) : α →₀ ℕ :=
(m.map $ λa, single a 1).sum
lemma to_finsupp_add {α : Type u} (m n : multiset α) :
(m + n).to_finsupp = m.to_finsupp + n.to_finsupp :=
calc (m + n).to_finsupp = ((m.map $ λa, single a 1) + (n.map $ λa, single a 1)).sum :
by rw [← multiset.map_add]; refl
... = m.to_finsupp + n.to_finsupp :
by rw [multiset.sum_add]; refl
lemma to_finsupp_prod {α : Type*} [comm_monoid α] (m : multiset α) :
m.prod = (finsupp.prod (m.to_finsupp) (λ k n, k ^ n) ) :=
begin
apply multiset.induction_on m,
{
simp [to_finsupp, prod_zero_index],
},
{
intros a s h1,
simp [*, to_finsupp] at *,
rw [prod_add_index, prod_single_index],
repeat {simp [pow_add]}
}
end
lemma to_finsupp_support {α : Type u} (m : multiset α) : m.to_finsupp.support = m.to_finset :=
begin
apply multiset.induction_on m,
{
simp [*, to_finsupp, to_finset] at *,
exact rfl,
},
{
intros a s h1,
simp [*, to_finsupp, to_finset] at *,
apply finset.subset.antisymm,
{
intros y h2,
have h3 : support (single a 1 + sum (map (λ (a : α), single a 1) s)) ⊆ support (single a 1) ∪ support (sum (map (λ (a : α), single a 1) s)),
from support_add,
have h4 : y ∈ support (single a 1) ∪ support (sum (map (λ (a : α), single a 1) s)),
from mem_of_subset h3 h2,
rw [h1, finset.mem_union] at h4,
cases h4,
{
rw [support_single_ne_zero] at h4,
simp * at *,
exact ne.symm zero_ne_one,
},
{
simp,
by_cases h5 : (y = a),
{
simp *,
},
{
have h5 : y ∈ s,
{
rw ←mem_erase_dup,
exact h4,
},
simp *,
}
}
},
{
intros y h2,
have h3 : support (single a 1 + sum (map (λ (a : α), single a 1) s)) ⊆ support (single a 1) ∪ support (sum (map (λ (a : α), single a 1) s)),
from support_add,
have h4 : y ∈ support (single a 1) ∪ support (sum (map (λ (a : α), single a 1) s)),
{
rw [finset.mem_union],
by_cases h4 : (y = a),
{
subst h4,
rw [support_single_ne_zero],
simp,
exact ne.symm zero_ne_one,
},
{
rw h1,
have h5 : y ∈ erase_dup s,
{
rw mem_erase_dup,
have : y ∈ erase_dup (a :: s),
exact h2,
rw mem_erase_dup at this,
simp * at *,
},
simp * at *,
}
},
rw [h1, finset.mem_union] at h4,
have h5 : support (single a 1 + sum (map (λ (a : α), single a 1) s)) =
support (single a 1) ∪ support (sum (map (λ (a : α), single a 1) s)),
{
apply finset.subset.antisymm,
{
exact h3,
},
{
intros x h5,
simp at h5,
cases h5,
{
simp,
by_contradiction h6,
have : (single a 1).val x = 0,
from nat.eq_zero_of_add_eq_zero_right h6,
exact h5 this,
},
{
simp,
by_contradiction h6,
have : (sum (map (λ (a : α), single a 1) s)).val x = 0,
from nat.eq_zero_of_add_eq_zero_left h6,
exact h5 this,
},
}
},
rw h5,
simp * at *,
}
},
end
lemma to_finsupp_support_subset {α : Type u} (m : multiset α) : m.to_finsupp.support.val ⊆ m :=
begin
intros x h1,
rw to_finsupp_support at h1,
rw ← mem_to_finset,
exact h1,
end
lemma to_finsupp_predicate {α : Type u} (m : multiset α) (p : α → Prop) :
(∀x ∈ m, p x) ↔ (∀x ∈ (m.to_finsupp).support, p x) :=
iff.intro
begin
intros h1 x h2,
rw [to_finsupp_support, mem_to_finset] at h2,
exact h1 _ h2,
end
begin
intros h1 x h2,
rw [to_finsupp_support] at h1,
have h3 : x ∈ to_finset m → p x,
from h1 x,
rw [mem_to_finset] at h3,
exact h3 h2,
end
lemma sum_map_eq_zero_iff_forall_eq_zero (f : α → multiset α) (s : multiset α) : sum (map f s) = 0 ↔ ∀ x ∈ s, f x = 0 :=
begin
split,
{
apply multiset.induction_on s,
{
simp * at *,
},
{
intros a s h1 h2 y h3,
simp * at *,
cases h3,
{
simp * at *,
},
{
exact h1 y h3,
}
}
},
{
intros h1,
revert h1,
apply multiset.induction_on s,
{
simp * at *,
},
{
intros a s h1 h2,
simp * at *,
apply h1,
intros x h3,
apply h2,
simp * at *,
}
}
end
lemma sum_map_singleton {α : Type u} {s : multiset α} : sum (map (λ x, {x}) s) = s :=
begin
apply multiset.induction_on s,
{
simp * at *,
},
{
intros a s h1,
simp * at *,
rw add_comm,
exact singleton_add _ _,
}
end
lemma finset_prod_eq_map_prod {α β : Type u} [comm_monoid β] {s : finset α} (f : α → β) : finset.prod s f = (map f s.val).prod :=
begin
exact rfl, --nice
end
lemma prod_ne_zero_of_forall_mem_ne_zero {α : Type u} [integral_domain α] (s : multiset α) (h : ∀x : α, x ∈ s → x ≠ 0) : s.prod ≠ 0 :=
begin
revert h,
apply multiset.induction_on s,
{
simp,
},
{
intros a s h1 h2,
simp * at *,
apply mul_ne_zero,
{
apply h2 a,
simp,
},
{
apply h1,
intros x h3,
apply h2 x,
simp *,
}
}
end
lemma sub_erase_dup_add_erase_dup_eq {α : Type u} (s : multiset α) : s - s.erase_dup + s.erase_dup = s :=
multiset.sub_add_cancel (erase_dup_le _)
lemma sum_map_mul {α β: Type u} [semiring β] (a : β) (f : α → β) (s : multiset α):
multiset.sum (multiset.map (λ (b : α), a * f b) s) =
a * multiset.sum (multiset.map (λ (b : α), f b) s):=
begin
apply multiset.induction_on s,
{
simp * at *,
},
{
intros a s h,
simp [*, mul_add],
}
end
--Naming correct or dvd_sum_of_forall_mem_dvd
lemma dvd_sum [comm_semiring α] (s : multiset α) (p : α) : (∀x ∈ s, p ∣ x) → p ∣ s.sum :=
begin
apply multiset.induction_on s,
{
simp * at *,
},
{
intros a s h1 h2,
simp * at *,
apply dvd_add,
{
apply h2,
simp,
},
{
apply h1,
intros x h3,
apply h2,
simp [h3],
}
}
end
lemma forall_pow_count_dvd_prod {α : Type u} [comm_semiring α] (s : multiset α) : ∀x : α , x ^ count x s ∣ prod s :=
begin
intros x,
by_cases hx : x ∈ s,
{
apply multiset.induction_on s,
{
simp,
},
{
intros a s h,
simp,
by_cases h1 : x = a,
{
subst h1,
rw [count_cons_self, pow_succ],
apply mul_dvd_mul_left,
assumption,
},
{
rw count_cons_of_ne h1,
apply dvd_mul_of_dvd_right,
exact h,
}
}
},
{
rw ←count_eq_zero at hx,
simp *,
}
end
lemma pow_count_sub_one_dvd_pow_count {α : Type u} [comm_semiring α] (s : multiset α) (x : α) : x ^ (count x s - 1) ∣ x ^ count x s :=
begin
by_cases h1 : (count x s) ≥ 1,
{
rw [←nat.sub_add_cancel h1] {occs := occurrences.pos [2]},
rw [pow_add],
apply dvd_mul_of_dvd_left,
simp,
},
{
have : count x s < 1,
from lt_of_not_ge h1,
have : nat.succ (count x s) ≤ 1,
from this,
have : count x s ≤ 0,
from nat.le_of_succ_le_succ this,
have : count x s = 0,
from nat.eq_zero_of_le_zero this,
simp *,
}
end
lemma prod_dvd_prod_of_le [comm_semiring α] {p q : multiset (α)} (h : p ≤ q) : p.prod ∣ q.prod :=
begin
have h1 : p + (q - p) = q,
from multiset.add_sub_of_le h,
rw ← h1,
simp,
end
lemma prod_sub_dvd_prod [comm_semiring α] {s t : multiset α} : (s - t).prod ∣ s.prod :=
begin
apply prod_dvd_prod_of_le,
apply sub_le_self,
end
lemma dvd_prod_of_mem {α : Type u} [comm_semiring α] (s : multiset α) {x : α} (h : x ∈ s) : x ∣ s.prod :=
begin
rcases (exists_cons_of_mem h) with ⟨t, ht⟩,
subst ht,
simp * at *,
end
lemma erase_dup_eq_zero_iff_eq_zero {α : Type u} (s : multiset α) : s.erase_dup = 0 ↔ s = 0 :=
begin
split,
{
intro h,
have : s ⊆ erase_dup s,
from subset_erase_dup s,
simp * at *,
exact eq_zero_of_subset_zero this,
},
{
intro h,
subst h,
simp,
}
end
inductive rel_multiset {α β : Type u} (r : α → β → Prop) : multiset α → multiset β → Prop
| nil : rel_multiset ∅ ∅
| cons : ∀a b xs ys, r a b → rel_multiset xs ys → rel_multiset (a::xs) (b::ys)
lemma rel_multiset_def {α β : Type u} {r : α → β → Prop} {x : multiset α} {y : multiset β} :
rel_multiset r x y ↔
((x = ∅ ∧ y = ∅) ∨ (∃a b x' y', r a b ∧ rel_multiset r x' y' ∧ x = a :: x' ∧ y = b :: y')) :=
iff.intro
(assume h,
match x, y, h with
| _, _, (rel_multiset.nil r) := or.inl ⟨rfl, rfl⟩
| _, _, (rel_multiset.cons a b x y r r') := or.inr ⟨a, b, x, y, r, r', rfl, rfl⟩
end)
(assume h,
match x, y, h with
| _, _, or.inl ⟨rfl, rfl⟩ := rel_multiset.nil r
| _, _, or.inr ⟨a, b, x, y, r, r', rfl, rfl⟩ := rel_multiset.cons a b x y r r'
end)
open multiset
lemma multiset.cons_ne_empty {α : Type u} (a : α) (as : multiset α) : a :: as ≠ ∅ :=
assume h,
have a ∈ a :: as, by simp,
have a ∈ (∅ : multiset α), from h ▸ this,
not_mem_zero a this
--Can we do an induction on rel_multiset?
lemma rel_multiset.cons_right {α β: Type u} {r : α → β → Prop} {as : multiset α} {bs : multiset β} {b : β} :
rel_multiset r as (b :: bs) → ∃a' as', as = (a' :: as') ∧ r a' b ∧ rel_multiset r as' bs :=
begin
generalize hbs' : (b :: bs) = bs',
intro h,
induction h generalizing bs,
case rel_multiset.nil { exact (multiset.cons_ne_empty _ _ hbs').elim },
case rel_multiset.cons : a b' as bs' hr₁ hr' ih {
by_cases b_b' : b = b',
{ subst b_b',
have h : bs = bs', from (cons_inj_right b).1 hbs',
subst h,
exact ⟨_, _, rfl, hr₁, hr'⟩ },
exact (
have b ∈ b' :: bs', by rw [← hbs']; simp,
have b ∈ bs', by simpa [b_b'],
have b :: bs'.erase b = bs', from cons_erase this,
let ⟨a'', as'', eq, hr₂, hr''⟩ := ih this in
have ih' : rel_multiset r (a :: as'') (b' :: bs'.erase b),
from rel_multiset.cons _ _ _ _ hr₁ hr'',
have b' :: bs'.erase b = bs,
by rw [← erase_cons_tail, ← hbs', erase_cons_head]; exact ne.symm b_b',
⟨a'', a :: as'', by simp [eq, cons_swap], hr₂, this ▸ ih'⟩
)
}
end
end multiset |
f6ffebf650134cf86dbd6f3a29d5726168fc0b1e | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /tests/lean/run/tree_height.lean | af93029df015984c4fc0c692c8eeaa23010252db | [
"Apache-2.0"
] | permissive | davidmueller13/lean | 65a3ed141b4088cd0a268e4de80eb6778b21a0e9 | c626e2e3c6f3771e07c32e82ee5b9e030de5b050 | refs/heads/master | 1,611,278,313,401 | 1,444,021,177,000 | 1,444,021,177,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,096 | lean | import logic data.nat
open eq.ops nat
inductive tree (A : Type) :=
| leaf : A → tree A
| node : tree A → tree A → tree A
namespace tree
definition height {A : Type} (t : tree A) : nat :=
tree.rec_on t
(λ a, zero)
(λ t₁ t₂ h₁ h₂, succ (max h₁ h₂))
definition height_lt {A : Type} : tree A → tree A → Prop :=
inv_image lt (@height A)
definition height_lt.wf (A : Type) : well_founded (@height_lt A) :=
inv_image.wf height lt.wf
theorem height_lt.node_left {A : Type} (t₁ t₂ : tree A) : height_lt t₁ (node t₁ t₂) :=
lt_succ_of_le (le_max_left (height t₁) (height t₂))
theorem height_lt.node_right {A : Type} (t₁ t₂ : tree A) : height_lt t₂ (node t₁ t₂) :=
lt_succ_of_le (le_max_right (height t₁) (height t₂))
theorem height_lt.trans {A : Type} : transitive (@height_lt A) :=
inv_image.trans lt height @lt.trans
example : height_lt (leaf 2) (node (leaf 1) (leaf 2)) :=
!height_lt.node_right
example : height_lt (leaf 2) (node (node (leaf 1) (leaf 2)) (leaf 3)) :=
height_lt.trans !height_lt.node_right !height_lt.node_left
end tree
|
0ce11d9b9e6c5f310bd24a34618a93c1874e72c9 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/data/real/cau_seq_completion.lean | 69f6c32cf9c215dc8835ad312185abf058f93f45 | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 10,025 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Robert Y. Lewis
-/
import data.real.cau_seq
/-!
# Cauchy completion
This file generalizes the Cauchy completion of `(ℚ, abs)` to the completion of a commutative ring
with absolute value.
-/
namespace cau_seq.completion
open cau_seq
section
parameters {α : Type*} [linear_ordered_field α]
parameters {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv]
def Cauchy := @quotient (cau_seq _ abv) cau_seq.equiv
def mk : cau_seq _ abv → Cauchy := quotient.mk
@[simp] theorem mk_eq_mk (f) : @eq Cauchy ⟦f⟧ (mk f) := rfl
theorem mk_eq {f g} : mk f = mk g ↔ f ≈ g := quotient.eq
def of_rat (x : β) : Cauchy := mk (const abv x)
instance : has_zero Cauchy := ⟨of_rat 0⟩
instance : has_one Cauchy := ⟨of_rat 1⟩
instance : inhabited Cauchy := ⟨0⟩
theorem of_rat_zero : of_rat 0 = 0 := rfl
theorem of_rat_one : of_rat 1 = 1 := rfl
@[simp] theorem mk_eq_zero {f} : mk f = 0 ↔ lim_zero f :=
by have : mk f = 0 ↔ lim_zero (f - 0) := quotient.eq;
rwa sub_zero at this
instance : has_add Cauchy :=
⟨λ x y, quotient.lift_on₂ x y (λ f g, mk (f + g)) $
λ f₁ g₁ f₂ g₂ hf hg, quotient.sound $
by simpa [(≈), setoid.r, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]
using add_lim_zero hf hg⟩
@[simp] theorem mk_add (f g : cau_seq β abv) : mk f + mk g = mk (f + g) := rfl
instance : has_neg Cauchy :=
⟨λ x, quotient.lift_on x (λ f, mk (-f)) $
λ f₁ f₂ hf, quotient.sound $
by simpa [(≈), setoid.r] using neg_lim_zero hf⟩
@[simp] theorem mk_neg (f : cau_seq β abv) : -mk f = mk (-f) := rfl
instance : has_mul Cauchy :=
⟨λ x y, quotient.lift_on₂ x y (λ f g, mk (f * g)) $
λ f₁ g₁ f₂ g₂ hf hg, quotient.sound $
by simpa [(≈), setoid.r, mul_add, mul_comm, add_assoc, sub_eq_add_neg] using
add_lim_zero (mul_lim_zero_right g₁ hf) (mul_lim_zero_right f₂ hg)⟩
@[simp] theorem mk_mul (f g : cau_seq β abv) : mk f * mk g = mk (f * g) := rfl
instance : has_sub Cauchy :=
⟨λ x y, quotient.lift_on₂ x y (λ f g, mk (f - g)) $
λ f₁ g₁ f₂ g₂ hf hg, quotient.sound $ show ((f₁ - g₁) - (f₂ - g₂)).lim_zero,
by simpa [sub_eq_add_neg, add_assoc, add_comm, add_left_comm] using sub_lim_zero hf hg⟩
@[simp] theorem mk_sub (f g : cau_seq β abv) : mk f - mk g = mk (f - g) := rfl
theorem of_rat_add (x y : β) : of_rat (x + y) = of_rat x + of_rat y :=
congr_arg mk (const_add _ _)
theorem of_rat_neg (x : β) : of_rat (-x) = -of_rat x :=
congr_arg mk (const_neg _)
theorem of_rat_mul (x y : β) : of_rat (x * y) = of_rat x * of_rat y :=
congr_arg mk (const_mul _ _)
private lemma zero_def : 0 = mk 0 := rfl
private lemma one_def : 1 = mk 1 := rfl
instance : comm_ring Cauchy :=
by refine { neg := has_neg.neg, sub := has_sub.sub, sub_eq_add_neg := _,
add := (+), zero := (0 : Cauchy), mul := (*), one := 1, nsmul := nsmul_rec, npow := npow_rec,
gsmul := gsmul_rec, .. }; try { intros; refl };
{ repeat {refine λ a, quotient.induction_on a (λ _, _)},
simp [zero_def, one_def, mul_left_comm, mul_comm, mul_add, add_comm, add_left_comm,
sub_eq_add_neg] }
theorem of_rat_sub (x y : β) : of_rat (x - y) = of_rat x - of_rat y :=
congr_arg mk (const_sub _ _)
end
open_locale classical
section
parameters {α : Type*} [linear_ordered_field α]
parameters {β : Type*} [field β] {abv : β → α} [is_absolute_value abv]
local notation `Cauchy` := @Cauchy _ _ _ _ abv _
noncomputable instance : has_inv Cauchy :=
⟨λ x, quotient.lift_on x
(λ f, mk $ if h : lim_zero f then 0 else inv f h) $
λ f g fg, begin
have := lim_zero_congr fg,
by_cases hf : lim_zero f,
{ simp [hf, this.1 hf, setoid.refl] },
{ have hg := mt this.2 hf, simp [hf, hg],
have If : mk (inv f hf) * mk f = 1 := mk_eq.2 (inv_mul_cancel hf),
have Ig : mk (inv g hg) * mk g = 1 := mk_eq.2 (inv_mul_cancel hg),
rw [mk_eq.2 fg, ← Ig] at If,
rw mul_comm at Ig,
rw [← mul_one (mk (inv f hf)), ← Ig, ← mul_assoc, If,
mul_assoc, Ig, mul_one] }
end⟩
@[simp] theorem inv_zero : (0 : Cauchy)⁻¹ = 0 :=
congr_arg mk $ by rw dif_pos; [refl, exact zero_lim_zero]
@[simp] theorem inv_mk {f} (hf) : (@mk α _ β _ abv _ f)⁻¹ = mk (inv f hf) :=
congr_arg mk $ by rw dif_neg
lemma cau_seq_zero_ne_one : ¬ (0 : cau_seq _ abv) ≈ 1 := λ h,
have lim_zero (1 - 0), from setoid.symm h,
have lim_zero 1, by simpa,
one_ne_zero $ const_lim_zero.1 this
lemma zero_ne_one : (0 : Cauchy) ≠ 1 :=
λ h, cau_seq_zero_ne_one $ mk_eq.1 h
protected theorem inv_mul_cancel {x : Cauchy} : x ≠ 0 → x⁻¹ * x = 1 :=
quotient.induction_on x $ λ f hf, begin
simp at hf, simp [hf],
exact quotient.sound (cau_seq.inv_mul_cancel hf)
end
noncomputable def field : field Cauchy :=
{ inv := has_inv.inv,
mul_inv_cancel := λ x x0, by rw [mul_comm, cau_seq.completion.inv_mul_cancel x0],
exists_pair_ne := ⟨0, 1, zero_ne_one⟩,
inv_zero := inv_zero,
.. Cauchy.comm_ring }
local attribute [instance] field
theorem of_rat_inv (x : β) : of_rat (x⁻¹) = ((of_rat x)⁻¹ : Cauchy) :=
congr_arg mk $ by split_ifs with h; [simp [const_lim_zero.1 h], refl]
theorem of_rat_div (x y : β) : of_rat (x / y) = (of_rat x / of_rat y : Cauchy) :=
by simp only [div_eq_inv_mul, of_rat_inv, of_rat_mul]
end
end cau_seq.completion
variables {α : Type*} [linear_ordered_field α]
namespace cau_seq
section
variables (β : Type*) [ring β] (abv : β → α) [is_absolute_value abv]
class is_complete :=
(is_complete : ∀ s : cau_seq β abv, ∃ b : β, s ≈ const abv b)
end
section
variables {β : Type*} [ring β] {abv : β → α} [is_absolute_value abv]
variable [is_complete β abv]
lemma complete : ∀ s : cau_seq β abv, ∃ b : β, s ≈ const abv b :=
is_complete.is_complete
noncomputable def lim (s : cau_seq β abv) := classical.some (complete s)
lemma equiv_lim (s : cau_seq β abv) : s ≈ const abv (lim s) :=
classical.some_spec (complete s)
lemma eq_lim_of_const_equiv {f : cau_seq β abv} {x : β} (h : cau_seq.const abv x ≈ f) : x = lim f :=
const_equiv.mp $ setoid.trans h $ equiv_lim f
lemma lim_eq_of_equiv_const {f : cau_seq β abv} {x : β} (h : f ≈ cau_seq.const abv x) : lim f = x :=
(eq_lim_of_const_equiv $ setoid.symm h).symm
lemma lim_eq_lim_of_equiv {f g : cau_seq β abv} (h : f ≈ g) : lim f = lim g :=
lim_eq_of_equiv_const $ setoid.trans h $ equiv_lim g
@[simp] lemma lim_const (x : β) : lim (const abv x) = x :=
lim_eq_of_equiv_const $ setoid.refl _
lemma lim_add (f g : cau_seq β abv) : lim f + lim g = lim (f + g) :=
eq_lim_of_const_equiv $ show lim_zero (const abv (lim f + lim g) - (f + g)),
by rw [const_add, add_sub_comm];
exact add_lim_zero (setoid.symm (equiv_lim f)) (setoid.symm (equiv_lim g))
lemma lim_mul_lim (f g : cau_seq β abv) : lim f * lim g = lim (f * g) :=
eq_lim_of_const_equiv $ show lim_zero (const abv (lim f * lim g) - f * g),
from have h : const abv (lim f * lim g) - f * g = (const abv (lim f) - f) * g
+ const abv (lim f) * (const abv (lim g) - g) :=
by simp [const_mul (lim f), mul_add, add_mul, sub_eq_add_neg, add_comm, add_left_comm],
by rw h; exact add_lim_zero (mul_lim_zero_left _ (setoid.symm (equiv_lim _)))
(mul_lim_zero_right _ (setoid.symm (equiv_lim _)))
lemma lim_mul (f : cau_seq β abv) (x : β) : lim f * x = lim (f * const abv x) :=
by rw [← lim_mul_lim, lim_const]
lemma lim_neg (f : cau_seq β abv) : lim (-f) = -lim f :=
lim_eq_of_equiv_const (show lim_zero (-f - const abv (-lim f)),
by rw [const_neg, sub_neg_eq_add, add_comm, ← sub_eq_add_neg];
exact setoid.symm (equiv_lim f))
lemma lim_eq_zero_iff (f : cau_seq β abv) : lim f = 0 ↔ lim_zero f :=
⟨assume h,
by have hf := equiv_lim f;
rw h at hf;
exact (lim_zero_congr hf).mpr (const_lim_zero.mpr rfl),
assume h,
have h₁ : f = (f - const abv 0) := ext (λ n, by simp [sub_apply, const_apply]),
by rw h₁ at h; exact lim_eq_of_equiv_const h ⟩
end
section
variables {β : Type*} [field β] {abv : β → α} [is_absolute_value abv] [is_complete β abv]
lemma lim_inv {f : cau_seq β abv} (hf : ¬ lim_zero f) : lim (inv f hf) = (lim f)⁻¹ :=
have hl : lim f ≠ 0 := by rwa ← lim_eq_zero_iff at hf,
lim_eq_of_equiv_const $ show lim_zero (inv f hf - const abv (lim f)⁻¹),
from have h₁ : ∀ (g f : cau_seq β abv) (hf : ¬ lim_zero f), lim_zero (g - f * inv f hf * g) :=
λ g f hf, by rw [← one_mul g, ← mul_assoc, ← sub_mul, mul_one, mul_comm, mul_comm f];
exact mul_lim_zero_right _ (setoid.symm (cau_seq.inv_mul_cancel _)),
have h₂ : lim_zero ((inv f hf - const abv (lim f)⁻¹) - (const abv (lim f) - f) *
(inv f hf * const abv (lim f)⁻¹)) :=
by rw [sub_mul, ← sub_add, sub_sub, sub_add_eq_sub_sub, sub_right_comm, sub_add];
exact show lim_zero (inv f hf - const abv (lim f) * (inv f hf * const abv (lim f)⁻¹)
- (const abv (lim f)⁻¹ - f * (inv f hf * const abv (lim f)⁻¹))),
from sub_lim_zero
(by rw [← mul_assoc, mul_right_comm, const_inv hl]; exact h₁ _ _ _)
(by rw [← mul_assoc]; exact h₁ _ _ _),
(lim_zero_congr h₂).mpr $ mul_lim_zero_left _ (setoid.symm (equiv_lim f))
end
section
variables [is_complete α abs]
lemma lim_le {f : cau_seq α abs} {x : α}
(h : f ≤ cau_seq.const abs x) : lim f ≤ x :=
cau_seq.const_le.1 $ cau_seq.le_of_eq_of_le (setoid.symm (equiv_lim f)) h
lemma le_lim {f : cau_seq α abs} {x : α}
(h : cau_seq.const abs x ≤ f) : x ≤ lim f :=
cau_seq.const_le.1 $ cau_seq.le_of_le_of_eq h (equiv_lim f)
lemma lt_lim {f : cau_seq α abs} {x : α}
(h : cau_seq.const abs x < f) : x < lim f :=
cau_seq.const_lt.1 $ cau_seq.lt_of_lt_of_eq h (equiv_lim f)
lemma lim_lt {f : cau_seq α abs} {x : α}
(h : f < cau_seq.const abs x) : lim f < x :=
cau_seq.const_lt.1 $ cau_seq.lt_of_eq_of_lt (setoid.symm (equiv_lim f)) h
end
end cau_seq
|
6c2ff480628da0245c7af0f58bf20da52a855b3b | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/countable/basic.lean | f167ba762df1a5f33d1e0f00ddd64495d0acdf56 | [
"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,277 | lean | /-
Copyright (c) 2022 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import logic.equiv.nat
import logic.equiv.fin
import data.countable.defs
/-!
# Countable types
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file we provide basic instances of the `countable` typeclass defined elsewhere.
-/
universes u v w
open function
instance : countable ℤ := countable.of_equiv ℕ equiv.int_equiv_nat.symm
/-!
### Definition in terms of `function.embedding`
-/
section embedding
variables {α : Sort u} {β : Sort v}
lemma countable_iff_nonempty_embedding : countable α ↔ nonempty (α ↪ ℕ) :=
⟨λ ⟨⟨f, hf⟩⟩, ⟨⟨f, hf⟩⟩, λ ⟨f⟩, ⟨⟨f, f.2⟩⟩⟩
lemma nonempty_embedding_nat (α) [countable α] : nonempty (α ↪ ℕ) :=
countable_iff_nonempty_embedding.1 ‹_›
protected lemma function.embedding.countable [countable β] (f : α ↪ β) : countable α :=
f.injective.countable
end embedding
/-!
### Operations on `Type*`s
-/
section type
variables {α : Type u} {β : Type v} {π : α → Type w}
instance [countable α] [countable β] : countable (α ⊕ β) :=
begin
rcases exists_injective_nat α with ⟨f, hf⟩,
rcases exists_injective_nat β with ⟨g, hg⟩,
exact (equiv.nat_sum_nat_equiv_nat.injective.comp $ hf.sum_map hg).countable
end
instance [countable α] : countable (option α) :=
countable.of_equiv _ (equiv.option_equiv_sum_punit α).symm
instance [countable α] [countable β] : countable (α × β) :=
begin
rcases exists_injective_nat α with ⟨f, hf⟩,
rcases exists_injective_nat β with ⟨g, hg⟩,
exact (nat.mkpair_equiv.injective.comp $ hf.prod_map hg).countable
end
instance [countable α] [Π a, countable (π a)] : countable (sigma π) :=
begin
rcases exists_injective_nat α with ⟨f, hf⟩,
choose g hg using λ a, exists_injective_nat (π a),
exact ((equiv.sigma_equiv_prod ℕ ℕ).injective.comp $ hf.sigma_map hg).countable
end
end type
section sort
variables {α : Sort u} {β : Sort v} {π : α → Sort w}
/-!
### Operations on and `Sort*`s
-/
@[priority 500]
instance set_coe.countable {α} [countable α] (s : set α) : countable s := subtype.countable
instance [countable α] [countable β] : countable (psum α β) :=
countable.of_equiv (plift α ⊕ plift β) (equiv.plift.sum_psum equiv.plift)
instance [countable α] [countable β] : countable (pprod α β) :=
countable.of_equiv (plift α × plift β) (equiv.plift.prod_pprod equiv.plift)
instance [countable α] [Π a, countable (π a)] : countable (psigma π) :=
countable.of_equiv (Σ a : plift α, plift (π a.down)) (equiv.psigma_equiv_sigma_plift π).symm
instance [finite α] [Π a, countable (π a)] : countable (Π a, π a) :=
begin
haveI : ∀ n, countable (fin n → ℕ),
{ intro n, induction n with n ihn,
{ apply_instance },
{ exactI countable.of_equiv _ (equiv.pi_fin_succ _ _).symm } },
rcases finite.exists_equiv_fin α with ⟨n, ⟨e⟩⟩,
have f := λ a, (nonempty_embedding_nat (π a)).some,
exact ((embedding.Pi_congr_right f).trans (equiv.Pi_congr_left' _ e).to_embedding).countable
end
end sort
|
f1b835fae40a09ec7277f887b54f9ac0f1cf809b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/meta/widget/replace_save_info_auto.lean | a50427af4f981d9120411e6073da733c52f1245d | [] | 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 | 251 | lean | /-
Copyright (c) E.W.Ayers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: E.W.Ayers
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.meta.widget.interactive_expr
namespace Mathlib
end Mathlib |
c21f1faa92848aae866a9f79a5ffed8361579e13 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /tests/lean/quot_bug.lean | 814c14dc454db90ebb58d00832c646d6afd4f096 | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 229 | lean | open quot
variables {A : Type} {B : A → Type}
variable f : Π a : A, B a
#reduce λ x, quot.lift_on ⟦f⟧ (λf : (Πx : A, B x), f) _ x
example (x : A) : quot.lift_on ⟦f⟧ (λf : (Πx : A, B x), f) sorry x = f x :=
rfl
|
b2c48f62f3bcc2198008fc02696fa4b2db1c44aa | 57aec6ee746bc7e3a3dd5e767e53bd95beb82f6d | /src/Init/Coe.lean | 20ea449df0a13cd9366921405c1d81958fa14f26 | [
"Apache-2.0"
] | permissive | collares/lean4 | 861a9269c4592bce49b71059e232ff0bfe4594cc | 52a4f535d853a2c7c7eea5fee8a4fa04c682c1ee | refs/heads/master | 1,691,419,031,324 | 1,618,678,138,000 | 1,618,678,138,000 | 358,989,750 | 0 | 0 | Apache-2.0 | 1,618,696,333,000 | 1,618,696,333,000 | null | UTF-8 | Lean | false | false | 6,376 | 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.Core
universes u v w w'
class Coe (α : Sort u) (β : Sort v) where
coe : α → β
/-- Auxiliary class that contains the transitive closure of `Coe`. -/
class CoeTC (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the beginning of a sequence of coercions. -/
class CoeHead (α : Sort u) (β : Sort v) where
coe : α → β
/- Expensive coercion that can only appear at the end of a sequence of coercions. -/
class CoeTail (α : Sort u) (β : Sort v) where
coe : α → β
/-- Auxiliary class that contains `CoeHead` + `CoeTC` + `CoeTail`. -/
class CoeHTCT (α : Sort u) (β : Sort v) where
coe : α → β
class CoeDep (α : Sort u) (a : α) (β : Sort v) where
coe : β
/- Combines CoeHead, CoeTC, CoeTail, CoeDep -/
class CoeT (α : Sort u) (a : α) (β : Sort v) where
coe : β
class CoeFun (α : Sort u) (γ : outParam (α → Sort v)) where
coe : (a : α) → γ a
class CoeSort (α : Sort u) (β : outParam (Sort v)) where
coe : α → β
abbrev coeB {α : Sort u} {β : Sort v} [Coe α β] (a : α) : β :=
Coe.coe a
abbrev coeHead {α : Sort u} {β : Sort v} [CoeHead α β] (a : α) : β :=
CoeHead.coe a
abbrev coeTail {α : Sort u} {β : Sort v} [CoeTail α β] (a : α) : β :=
CoeTail.coe a
abbrev coeD {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : β :=
CoeDep.coe a
abbrev coeTC {α : Sort u} {β : Sort v} [CoeTC α β] (a : α) : β :=
CoeTC.coe a
/-- Apply coercion manually. -/
abbrev coe {α : Sort u} {β : Sort v} (a : α) [CoeT α a β] : β :=
CoeT.coe a
prefix:max "↑" => coe
abbrev coeFun {α : Sort u} {γ : α → Sort v} (a : α) [CoeFun α γ] : γ a :=
CoeFun.coe a
abbrev coeSort {α : Sort u} {β : Sort v} (a : α) [CoeSort α β] : β :=
CoeSort.coe a
instance coeTrans {α : Sort u} {β : Sort v} {δ : Sort w} [Coe β δ] [CoeTC α β] : CoeTC α δ where
coe a := coeB (coeTC a : β)
instance coeBase {α : Sort u} {β : Sort v} [Coe α β] : CoeTC α β where
coe a := coeB a
instance coeOfHeafOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} {γ : Sort w'} [CoeHead α β] [CoeTail δ γ] [CoeTC β δ] : CoeHTCT α γ where
coe a := coeTail (coeTC (coeHead a : β) : δ)
instance coeOfHeadOfTC {α : Sort u} {β : Sort v} {δ : Sort w} [CoeHead α β] [CoeTC β δ] : CoeHTCT α δ where
coe a := coeTC (coeHead a : β)
instance coeOfTCOfTail {α : Sort u} {β : Sort v} {δ : Sort w} [CoeTail β δ] [CoeTC α β] : CoeHTCT α δ where
coe a := coeTail (coeTC a : β)
instance coeOfHead {α : Sort u} {β : Sort v} [CoeHead α β] : CoeHTCT α β where
coe a := coeHead a
instance coeOfTail {α : Sort u} {β : Sort v} [CoeTail α β] : CoeHTCT α β where
coe a := coeTail a
instance coeOfTC {α : Sort u} {β : Sort v} [CoeTC α β] : CoeHTCT α β where
coe a := coeTC a
instance coeOfHTCT {α : Sort u} {β : Sort v} [CoeHTCT α β] (a : α) : CoeT α a β where
coe := CoeHTCT.coe a
instance coeOfDep {α : Sort u} {β : Sort v} (a : α) [CoeDep α a β] : CoeT α a β where
coe := coeD a
instance coeId {α : Sort u} (a : α) : CoeT α a α where
coe := a
/- Basic instances -/
@[inline] instance boolToProp : Coe Bool Prop where
coe b := b = true
instance boolToSort : CoeSort Bool Prop where
coe b := b
@[inline] instance coeDecidableEq (x : Bool) : Decidable (coe x) :=
inferInstanceAs (Decidable (x = true))
instance decPropToBool (p : Prop) [Decidable p] : CoeDep Prop p Bool where
coe := decide p
instance optionCoe {α : Type u} : CoeTail α (Option α) where
coe := some
instance subtypeCoe {α : Sort u} {p : α → Prop} : CoeHead { x // p x } α where
coe v := v.val
/- Coe & OfNat bridge -/
/-
Remark: one may question why we use `OfNat α` instead of `Coe Nat α`.
Reason: `OfNat` is for implementing polymorphic numeric literals, and we may
want to have numeric literals for a type α and **no** coercion from `Nat` to `α`. -/
instance hasOfNatOfCoe [Coe α β] [OfNat α n] : OfNat β n where
ofNat := coe (OfNat.ofNat n : α)
@[inline] def liftCoeM {m : Type u → Type v} {n : Type u → Type w} {α β : Type u} [MonadLiftT m n] [∀ a, CoeT α a β] [Monad n] (x : m α) : n β := do
let a ← liftM x
pure (coe a)
@[inline] def coeM {m : Type u → Type v} {α β : Type u} [∀ a, CoeT α a β] [Monad m] (x : m α) : m β := do
let a ← x
pure <| coe a
instance [CoeFun α β] (a : α) : CoeDep α a (β a) where
coe := coeFun a
instance [CoeFun α (fun _ => β)] : CoeTail α β where
coe a := coeFun a
instance [CoeSort α β] : CoeTail α β where
coe a := coeSort a
/- Coe and heterogeneous operators, we use `CoeHTCT` instead of `CoeT` to avoid expensive coercions such as `CoeDep` -/
instance [CoeHTCT α β] [Add β] : HAdd α β β where
hAdd a b := Add.add a b
instance [CoeHTCT α β] [Add β] : HAdd β α β where
hAdd a b := Add.add a b
instance [CoeHTCT α β] [Sub β] : HSub α β β where
hSub a b := Sub.sub a b
instance [CoeHTCT α β] [Sub β] : HSub β α β where
hSub a b := Sub.sub a b
instance [CoeHTCT α β] [Mul β] : HMul α β β where
hMul a b := Mul.mul a b
instance [CoeHTCT α β] [Mul β] : HMul β α β where
hMul a b := Mul.mul a b
instance [CoeHTCT α β] [Div β] : HDiv α β β where
hDiv a b := Div.div a b
instance [CoeHTCT α β] [Div β] : HDiv β α β where
hDiv a b := Div.div a b
instance [CoeHTCT α β] [Mod β] : HMod α β β where
hMod a b := Mod.mod a b
instance [CoeHTCT α β] [Mod β] : HMod β α β where
hMod a b := Mod.mod a b
instance [CoeHTCT α β] [Append β] : HAppend α β β where
hAppend a b := Append.append a b
instance [CoeHTCT α β] [Append β] : HAppend β α β where
hAppend a b := Append.append a b
instance [CoeHTCT α β] [OrElse β] : HOrElse α β β where
hOrElse a b := OrElse.orElse a b
instance [CoeHTCT α β] [OrElse β] : HOrElse β α β where
hOrElse a b := OrElse.orElse a b
instance [CoeHTCT α β] [AndThen β] : HAndThen α β β where
hAndThen a b := AndThen.andThen a b
instance [CoeHTCT α β] [AndThen β] : HAndThen β α β where
hAndThen a b := AndThen.andThen a b
|
7b8a05adc232adc24681aab1e572ceaea5828649 | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/multiset/antidiagonal.lean | d8f3ce7cffb2c45123a50810aad9edc479c9381f | [
"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 | 2,986 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
-/
import data.multiset.powerset
/-!
# The antidiagonal on a multiset.
The antidiagonal of a multiset `s` consists of all pairs `(t₁, t₂)`
such that `t₁ + t₂ = s`. These pairs are counted with multiplicities.
-/
namespace multiset
open list
variables {α β : Type*}
/-- The antidiagonal of a multiset `s` consists of all pairs `(t₁, t₂)`
such that `t₁ + t₂ = s`. These pairs are counted with multiplicities. -/
def antidiagonal (s : multiset α) : multiset (multiset α × multiset α) :=
quot.lift_on s
(λ l, (revzip (powerset_aux l) : multiset (multiset α × multiset α)))
(λ l₁ l₂ h, quot.sound (revzip_powerset_aux_perm h))
theorem antidiagonal_coe (l : list α) :
@antidiagonal α l = revzip (powerset_aux l) := rfl
@[simp] theorem antidiagonal_coe' (l : list α) :
@antidiagonal α l = revzip (powerset_aux' l) :=
quot.sound revzip_powerset_aux_perm_aux'
/-- A pair `(t₁, t₂)` of multisets is contained in `antidiagonal s`
if and only if `t₁ + t₂ = s`. -/
@[simp] theorem mem_antidiagonal {s : multiset α} {x : multiset α × multiset α} :
x ∈ antidiagonal s ↔ x.1 + x.2 = s :=
quotient.induction_on s $ λ l, begin
simp [antidiagonal_coe], refine ⟨λ h, revzip_powerset_aux h, λ h, _⟩,
haveI := classical.dec_eq α,
simp [revzip_powerset_aux_lemma l revzip_powerset_aux, h.symm],
cases x with x₁ x₂,
exact ⟨_, le_add_right _ _, by rw add_sub_cancel_left _ _⟩
end
@[simp] theorem antidiagonal_map_fst (s : multiset α) :
(antidiagonal s).map prod.fst = powerset s :=
quotient.induction_on s $ λ l,
by simp [powerset_aux']
@[simp] theorem antidiagonal_map_snd (s : multiset α) :
(antidiagonal s).map prod.snd = powerset s :=
quotient.induction_on s $ λ l,
by simp [powerset_aux']
@[simp] theorem antidiagonal_zero : @antidiagonal α 0 = (0, 0) ::ₘ 0 := rfl
@[simp] theorem antidiagonal_cons (a : α) (s) : antidiagonal (a ::ₘ s) =
map (prod.map id (cons a)) (antidiagonal s) +
map (prod.map (cons a) id) (antidiagonal s) :=
quotient.induction_on s $ λ l, begin
simp only [revzip, reverse_append, quot_mk_to_coe, coe_eq_coe, powerset_aux'_cons, cons_coe,
coe_map, antidiagonal_coe', coe_add],
rw [← zip_map, ← zip_map, zip_append, (_ : _++_=_)],
{congr; simp}, {simp}
end
@[simp] theorem card_antidiagonal (s : multiset α) :
card (antidiagonal s) = 2 ^ card s :=
by have := card_powerset s;
rwa [← antidiagonal_map_fst, card_map] at this
lemma prod_map_add [comm_semiring β] {s : multiset α} {f g : α → β} :
prod (s.map (λa, f a + g a)) =
sum ((antidiagonal s).map (λp, (p.1.map f).prod * (p.2.map g).prod)) :=
begin
refine s.induction_on _ _,
{ simp },
{ assume a s ih,
simp [ih, add_mul, mul_comm, mul_left_comm, mul_assoc, sum_map_mul_left.symm],
cc },
end
end multiset
|
2376bf95552a9a2432fde4a5897a84a0fb290ba5 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/data/int/basic.lean | 278cee5e1c266a38eb6e32df9cb11d4707677b20 | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 47,782 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The integers, with addition, multiplication, and subtraction.
-/
import data.nat.basic
import algebra.order_functions
open nat
namespace int
instance : inhabited ℤ := ⟨int.zero⟩
instance : nontrivial ℤ :=
⟨⟨0, 1, int.zero_ne_one⟩⟩
instance : comm_ring int :=
{ add := int.add,
add_assoc := int.add_assoc,
zero := int.zero,
zero_add := int.zero_add,
add_zero := int.add_zero,
neg := int.neg,
add_left_neg := int.add_left_neg,
add_comm := int.add_comm,
mul := int.mul,
mul_assoc := int.mul_assoc,
one := int.one,
one_mul := int.one_mul,
mul_one := int.mul_one,
left_distrib := int.distrib_left,
right_distrib := int.distrib_right,
mul_comm := int.mul_comm }
/- Extra instances to short-circuit type class resolution -/
-- instance : has_sub int := by apply_instance -- This is in core
instance : add_comm_monoid int := by apply_instance
instance : add_monoid int := by apply_instance
instance : monoid int := by apply_instance
instance : comm_monoid int := by apply_instance
instance : comm_semigroup int := by apply_instance
instance : semigroup int := by apply_instance
instance : add_comm_semigroup int := by apply_instance
instance : add_semigroup int := by apply_instance
instance : comm_semiring int := by apply_instance
instance : semiring int := by apply_instance
instance : ring int := by apply_instance
instance : distrib int := by apply_instance
instance : decidable_linear_ordered_comm_ring int :=
{ add_le_add_left := @int.add_le_add_left,
mul_pos := @int.mul_pos,
zero_lt_one := int.zero_lt_one,
.. int.comm_ring, .. int.decidable_linear_order, .. int.nontrivial }
instance : decidable_linear_ordered_add_comm_group int :=
by apply_instance
theorem abs_eq_nat_abs : ∀ a : ℤ, abs a = nat_abs a
| (n : ℕ) := abs_of_nonneg $ coe_zero_le _
| -[1+ n] := abs_of_nonpos $ le_of_lt $ neg_succ_lt_zero _
theorem nat_abs_abs (a : ℤ) : nat_abs (abs a) = nat_abs a :=
by rw [abs_eq_nat_abs]; refl
theorem sign_mul_abs (a : ℤ) : sign a * abs a = a :=
by rw [abs_eq_nat_abs, sign_mul_nat_abs]
@[simp] lemma default_eq_zero : default ℤ = 0 := rfl
meta instance : has_to_format ℤ := ⟨λ z, to_string z⟩
meta instance : has_reflect ℤ := by tactic.mk_has_reflect_instance
attribute [simp] int.coe_nat_add int.coe_nat_mul int.coe_nat_zero int.coe_nat_one int.coe_nat_succ
attribute [simp] int.of_nat_eq_coe int.bodd
@[simp] theorem add_def {a b : ℤ} : int.add a b = a + b := rfl
@[simp] theorem mul_def {a b : ℤ} : int.mul a b = a * b := rfl
@[simp] theorem coe_nat_mul_neg_succ (m n : ℕ) : (m : ℤ) * -[1+ n] = -(m * succ n) := rfl
@[simp] theorem neg_succ_mul_coe_nat (m n : ℕ) : -[1+ m] * n = -(succ m * n) := rfl
@[simp] theorem neg_succ_mul_neg_succ (m n : ℕ) : -[1+ m] * -[1+ n] = succ m * succ n := rfl
@[simp, norm_cast]
theorem coe_nat_le {m n : ℕ} : (↑m : ℤ) ≤ ↑n ↔ m ≤ n := coe_nat_le_coe_nat_iff m n
@[simp, norm_cast]
theorem coe_nat_lt {m n : ℕ} : (↑m : ℤ) < ↑n ↔ m < n := coe_nat_lt_coe_nat_iff m n
@[simp, norm_cast]
theorem coe_nat_inj' {m n : ℕ} : (↑m : ℤ) = ↑n ↔ m = n := int.coe_nat_eq_coe_nat_iff m n
@[simp] theorem coe_nat_pos {n : ℕ} : (0 : ℤ) < n ↔ 0 < n :=
by rw [← int.coe_nat_zero, coe_nat_lt]
@[simp] theorem coe_nat_eq_zero {n : ℕ} : (n : ℤ) = 0 ↔ n = 0 :=
by rw [← int.coe_nat_zero, coe_nat_inj']
theorem coe_nat_ne_zero {n : ℕ} : (n : ℤ) ≠ 0 ↔ n ≠ 0 :=
not_congr coe_nat_eq_zero
lemma coe_nat_nonneg (n : ℕ) : 0 ≤ (n : ℤ) := coe_nat_le.2 (nat.zero_le _)
lemma coe_nat_ne_zero_iff_pos {n : ℕ} : (n : ℤ) ≠ 0 ↔ 0 < n :=
⟨λ h, nat.pos_of_ne_zero (coe_nat_ne_zero.1 h),
λ h, (ne_of_lt (coe_nat_lt.2 h)).symm⟩
lemma coe_nat_succ_pos (n : ℕ) : 0 < (n.succ : ℤ) := int.coe_nat_pos.2 (succ_pos n)
@[simp, norm_cast] theorem coe_nat_abs (n : ℕ) : abs (n : ℤ) = n :=
abs_of_nonneg (coe_nat_nonneg n)
/- succ and pred -/
/-- Immediate successor of an integer: `succ n = n + 1` -/
def succ (a : ℤ) := a + 1
/-- Immediate predecessor of an integer: `pred n = n - 1` -/
def pred (a : ℤ) := a - 1
theorem nat_succ_eq_int_succ (n : ℕ) : (nat.succ n : ℤ) = int.succ n := rfl
theorem pred_succ (a : ℤ) : pred (succ a) = a := add_sub_cancel _ _
theorem succ_pred (a : ℤ) : succ (pred a) = a := sub_add_cancel _ _
theorem neg_succ (a : ℤ) : -succ a = pred (-a) := neg_add _ _
theorem succ_neg_succ (a : ℤ) : succ (-succ a) = -a :=
by rw [neg_succ, succ_pred]
theorem neg_pred (a : ℤ) : -pred a = succ (-a) :=
by rw [eq_neg_of_eq_neg (neg_succ (-a)).symm, neg_neg]
theorem pred_neg_pred (a : ℤ) : pred (-pred a) = -a :=
by rw [neg_pred, pred_succ]
theorem pred_nat_succ (n : ℕ) : pred (nat.succ n) = n := pred_succ n
theorem neg_nat_succ (n : ℕ) : -(nat.succ n : ℤ) = pred (-n) := neg_succ n
theorem succ_neg_nat_succ (n : ℕ) : succ (-nat.succ n) = -n := succ_neg_succ n
theorem lt_succ_self (a : ℤ) : a < succ a :=
lt_add_of_pos_right _ zero_lt_one
theorem pred_self_lt (a : ℤ) : pred a < a :=
sub_lt_self _ zero_lt_one
theorem add_one_le_iff {a b : ℤ} : a + 1 ≤ b ↔ a < b := iff.rfl
theorem lt_add_one_iff {a b : ℤ} : a < b + 1 ↔ a ≤ b :=
@add_le_add_iff_right _ _ a b 1
lemma le_add_one {a b : ℤ} (h : a ≤ b) : a ≤ b + 1 :=
le_of_lt (int.lt_add_one_iff.mpr h)
theorem sub_one_lt_iff {a b : ℤ} : a - 1 < b ↔ a ≤ b :=
sub_lt_iff_lt_add.trans lt_add_one_iff
theorem le_sub_one_iff {a b : ℤ} : a ≤ b - 1 ↔ a < b :=
le_sub_iff_add_le
@[elab_as_eliminator] protected lemma induction_on {p : ℤ → Prop}
(i : ℤ) (hz : p 0) (hp : ∀i : ℕ, p i → p (i + 1)) (hn : ∀i : ℕ, p (-i) → p (-i - 1)) : p i :=
begin
induction i,
{ induction i,
{ exact hz },
{ exact hp _ i_ih } },
{ have : ∀n:ℕ, p (- n),
{ intro n, induction n,
{ simp [hz] },
{ convert hn _ n_ih using 1, simp [sub_eq_neg_add] } },
exact this (i + 1) }
end
protected def induction_on' {C : ℤ → Sort*} (z : ℤ) (b : ℤ) :
C b → (∀ k, b ≤ k → C k → C (k + 1)) → (∀ k ≤ b, C k → C (k - 1)) → C z :=
λ H0 Hs Hp,
begin
rw ←sub_add_cancel z b,
induction (z - b),
{ induction a with n ih, { rwa [of_nat_zero, zero_add] },
rw [of_nat_succ, add_assoc, add_comm 1 b, ←add_assoc],
exact Hs _ (le_add_of_nonneg_left (of_nat_nonneg _)) ih },
{ induction a with n ih,
{ rw [neg_succ_of_nat_eq, ←of_nat_eq_coe, of_nat_zero, zero_add, neg_add_eq_sub],
exact Hp _ (le_refl _) H0 },
{ rw [neg_succ_of_nat_coe', nat.succ_eq_add_one, ←neg_succ_of_nat_coe, sub_add_eq_add_sub],
exact Hp _ (le_of_lt (add_lt_of_neg_of_le (neg_succ_lt_zero _) (le_refl _))) ih } }
end
/- nat abs -/
attribute [simp] nat_abs nat_abs_of_nat nat_abs_zero nat_abs_one
theorem nat_abs_add_le (a b : ℤ) : nat_abs (a + b) ≤ nat_abs a + nat_abs b :=
begin
have : ∀ (a b : ℕ), nat_abs (sub_nat_nat a (nat.succ b)) ≤ nat.succ (a + b),
{ refine (λ a b : ℕ, sub_nat_nat_elim a b.succ
(λ m n i, n = b.succ → nat_abs i ≤ (m + b).succ) _ _ rfl);
intros i n e,
{ subst e, rw [add_comm _ i, add_assoc],
exact nat.le_add_right i (b.succ + b).succ },
{ apply succ_le_succ,
rw [← succ.inj e, ← add_assoc, add_comm],
apply nat.le_add_right } },
cases a; cases b with b b; simp [nat_abs, nat.succ_add];
try {refl}; [skip, rw add_comm a b]; apply this
end
theorem nat_abs_neg_of_nat (n : ℕ) : nat_abs (neg_of_nat n) = n :=
by cases n; refl
theorem nat_abs_mul (a b : ℤ) : nat_abs (a * b) = (nat_abs a) * (nat_abs b) :=
by cases a; cases b;
simp only [← int.mul_def, int.mul, nat_abs_neg_of_nat, eq_self_iff_true, int.nat_abs]
@[simp] lemma nat_abs_mul_self' (a : ℤ) : (nat_abs a * nat_abs a : ℤ) = a * a :=
by rw [← int.coe_nat_mul, nat_abs_mul_self]
theorem neg_succ_of_nat_eq' (m : ℕ) : -[1+ m] = -m - 1 :=
by simp [neg_succ_of_nat_eq, sub_eq_neg_add]
lemma nat_abs_ne_zero_of_ne_zero {z : ℤ} (hz : z ≠ 0) : z.nat_abs ≠ 0 :=
λ h, hz $ int.eq_zero_of_nat_abs_eq_zero h
@[simp] lemma nat_abs_eq_zero {a : ℤ} : a.nat_abs = 0 ↔ a = 0 :=
⟨int.eq_zero_of_nat_abs_eq_zero, λ h, h.symm ▸ rfl⟩
lemma nat_abs_lt_nat_abs_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) :
a.nat_abs < b.nat_abs :=
begin
lift b to ℕ using le_trans w₁ (le_of_lt w₂),
lift a to ℕ using w₁,
simpa using w₂,
end
/- / -/
@[simp] theorem of_nat_div (m n : ℕ) : of_nat (m / n) = (of_nat m) / (of_nat n) := rfl
@[simp, norm_cast] theorem coe_nat_div (m n : ℕ) : ((m / n : ℕ) : ℤ) = m / n := rfl
theorem neg_succ_of_nat_div (m : ℕ) {b : ℤ} (H : 0 < b) :
-[1+m] / b = -(m / b + 1) :=
match b, eq_succ_of_zero_lt H with ._, ⟨n, rfl⟩ := rfl end
@[simp] protected theorem div_neg : ∀ (a b : ℤ), a / -b = -(a / b)
| (m : ℕ) 0 := show of_nat (m / 0) = -(m / 0 : ℕ), by rw nat.div_zero; refl
| (m : ℕ) (n+1:ℕ) := rfl
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := (neg_neg _).symm
| -[1+ m] 0 := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
theorem div_of_neg_of_pos {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b = -((-a - 1) / b + 1) :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ :=
by change (- -[1+ m] : ℤ) with (m+1 : ℤ); rw add_sub_cancel; refl
end
protected theorem div_nonneg {a b : ℤ} (Ha : 0 ≤ a) (Hb : 0 ≤ b) : 0 ≤ a / b :=
match a, b, eq_coe_of_zero_le Ha, eq_coe_of_zero_le Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := coe_zero_le _
end
protected theorem div_nonpos {a b : ℤ} (Ha : 0 ≤ a) (Hb : b ≤ 0) : a / b ≤ 0 :=
nonpos_of_neg_nonneg $ by rw [← int.div_neg]; exact int.div_nonneg Ha (neg_nonneg_of_nonpos Hb)
theorem div_neg' {a b : ℤ} (Ha : a < 0) (Hb : 0 < b) : a / b < 0 :=
match a, b, eq_neg_succ_of_lt_zero Ha, eq_succ_of_zero_lt Hb with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩ := neg_succ_lt_zero _
end
-- Will be generalized to Euclidean domains.
protected theorem zero_div : ∀ (b : ℤ), 0 / b = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
local attribute [simp] -- Will be generalized to Euclidean domains.
protected theorem div_zero : ∀ (a : ℤ), a / 0 = 0
| 0 := rfl
| (n+1:ℕ) := rfl
| -[1+ n] := rfl
@[simp] protected theorem div_one : ∀ (a : ℤ), a / 1 = a
| 0 := rfl
| (n+1:ℕ) := congr_arg of_nat (nat.div_one _)
| -[1+ n] := congr_arg neg_succ_of_nat (nat.div_one _)
theorem div_eq_zero_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a / b = 0 :=
match a, b, eq_coe_of_zero_le H1, eq_succ_of_zero_lt (lt_of_le_of_lt H1 H2), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.div_eq_of_lt $ lt_of_coe_nat_lt_coe_nat H2
end
theorem div_eq_zero_of_lt_abs {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < abs b) : a / b = 0 :=
match b, abs b, abs_eq_nat_abs b, H2 with
| (n : ℕ), ._, rfl, H2 := div_eq_zero_of_lt H1 H2
| -[1+ n], ._, rfl, H2 := neg_injective $ by rw [← int.div_neg]; exact div_eq_zero_of_lt H1 H2
end
protected theorem add_mul_div_right (a b : ℤ) {c : ℤ} (H : c ≠ 0) :
(a + b * c) / c = a / c + b :=
have ∀ {k n : ℕ} {a : ℤ}, (a + n * k.succ) / k.succ = a / k.succ + n, from
λ k n a, match a with
| (m : ℕ) := congr_arg of_nat $ nat.add_mul_div_right _ _ k.succ_pos
| -[1+ m] := show ((n * k.succ:ℕ) - m.succ : ℤ) / k.succ =
n - (m / k.succ + 1 : ℕ), begin
cases lt_or_ge m (n*k.succ) with h h,
{ rw [← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.div_lt_iff_lt_mul _ _ k.succ_pos).2 h)],
apply congr_arg of_nat,
rw [mul_comm, nat.mul_sub_div], rwa mul_comm },
{ change (↑(n * nat.succ k) - (m + 1) : ℤ) / ↑(nat.succ k) =
↑n - ((m / nat.succ k : ℕ) + 1),
rw [← sub_sub, ← sub_sub, ← neg_sub (m:ℤ), ← neg_sub _ (n:ℤ),
← int.coe_nat_sub h,
← int.coe_nat_sub ((nat.le_div_iff_mul_le _ _ k.succ_pos).2 h),
← neg_succ_of_nat_coe', ← neg_succ_of_nat_coe'],
{ apply congr_arg neg_succ_of_nat,
rw [mul_comm, nat.sub_mul_div], rwa mul_comm } }
end
end,
have ∀ {a b c : ℤ}, 0 < c → (a + b * c) / c = a / c + b, from
λ a b c H, match c, eq_succ_of_zero_lt H, b with
| ._, ⟨k, rfl⟩, (n : ℕ) := this
| ._, ⟨k, rfl⟩, -[1+ n] :=
show (a - n.succ * k.succ) / k.succ = (a / k.succ) - n.succ, from
eq_sub_of_add_eq $ by rw [← this, sub_add_cancel]
end,
match lt_trichotomy c 0 with
| or.inl hlt := neg_inj.1 $ by rw [← int.div_neg, neg_add, ← int.div_neg, ← neg_mul_neg];
apply this (neg_pos_of_neg hlt)
| or.inr (or.inl heq) := absurd heq H
| or.inr (or.inr hgt) := this hgt
end
protected theorem add_mul_div_left (a : ℤ) {b : ℤ} (c : ℤ) (H : b ≠ 0) :
(a + b * c) / b = a / b + c :=
by rw [mul_comm, int.add_mul_div_right _ _ H]
@[simp] protected theorem mul_div_cancel (a : ℤ) {b : ℤ} (H : b ≠ 0) : a * b / b = a :=
by have := int.add_mul_div_right 0 a H;
rwa [zero_add, int.zero_div, zero_add] at this
@[simp] protected theorem mul_div_cancel_left {a : ℤ} (b : ℤ) (H : a ≠ 0) : a * b / a = b :=
by rw [mul_comm, int.mul_div_cancel _ H]
@[simp] protected theorem div_self {a : ℤ} (H : a ≠ 0) : a / a = 1 :=
by have := int.mul_div_cancel 1 H; rwa one_mul at this
/- mod -/
theorem of_nat_mod (m n : nat) : (m % n : ℤ) = of_nat (m % n) := rfl
@[simp, norm_cast] theorem coe_nat_mod (m n : ℕ) : (↑(m % n) : ℤ) = ↑m % ↑n := rfl
theorem neg_succ_of_nat_mod (m : ℕ) {b : ℤ} (bpos : 0 < b) :
-[1+m] % b = b - 1 - m % b :=
by rw [sub_sub, add_comm]; exact
match b, eq_succ_of_zero_lt bpos with ._, ⟨n, rfl⟩ := rfl end
@[simp] theorem mod_neg : ∀ (a b : ℤ), a % -b = a % b
| (m : ℕ) n := @congr_arg ℕ ℤ _ _ (λ i, ↑(m % i)) (nat_abs_neg _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λ i, sub_nat_nat i (nat.succ (m % i))) (nat_abs_neg _)
@[simp] theorem mod_abs (a b : ℤ) : a % (abs b) = a % b :=
abs_by_cases (λ i, a % i = a % b) rfl (mod_neg _ _)
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem zero_mod (b : ℤ) : 0 % b = 0 :=
congr_arg of_nat $ nat.zero_mod _
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_zero : ∀ (a : ℤ), a % 0 = a
| (m : ℕ) := congr_arg of_nat $ nat.mod_zero _
| -[1+ m] := congr_arg neg_succ_of_nat $ nat.mod_zero _
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_one : ∀ (a : ℤ), a % 1 = 0
| (m : ℕ) := congr_arg of_nat $ nat.mod_one _
| -[1+ m] := show (1 - (m % 1).succ : ℤ) = 0, by rw nat.mod_one; refl
theorem mod_eq_of_lt {a b : ℤ} (H1 : 0 ≤ a) (H2 : a < b) : a % b = a :=
match a, b, eq_coe_of_zero_le H1, eq_coe_of_zero_le (le_trans H1 (le_of_lt H2)), H2 with
| ._, ._, ⟨m, rfl⟩, ⟨n, rfl⟩, H2 :=
congr_arg of_nat $ nat.mod_eq_of_lt (lt_of_coe_nat_lt_coe_nat H2)
end
theorem mod_nonneg : ∀ (a : ℤ) {b : ℤ}, b ≠ 0 → 0 ≤ a % b
| (m : ℕ) n H := coe_zero_le _
| -[1+ m] n H :=
sub_nonneg_of_le $ coe_nat_le_coe_nat_of_le $ nat.mod_lt _ (nat_abs_pos_of_ne_zero H)
theorem mod_lt_of_pos (a : ℤ) {b : ℤ} (H : 0 < b) : a % b < b :=
match a, b, eq_succ_of_zero_lt H with
| (m : ℕ), ._, ⟨n, rfl⟩ := coe_nat_lt_coe_nat_of_lt (nat.mod_lt _ (nat.succ_pos _))
| -[1+ m], ._, ⟨n, rfl⟩ := sub_lt_self _ (coe_nat_lt_coe_nat_of_lt $ nat.succ_pos _)
end
theorem mod_lt (a : ℤ) {b : ℤ} (H : b ≠ 0) : a % b < abs b :=
by rw [← mod_abs]; exact mod_lt_of_pos _ (abs_pos_of_ne_zero H)
theorem mod_add_div_aux (m n : ℕ) : (n - (m % n + 1) - (n * (m / n) + n) : ℤ) = -[1+ m] :=
begin
rw [← sub_sub, neg_succ_of_nat_coe, sub_sub (n:ℤ)],
apply eq_neg_of_eq_neg,
rw [neg_sub, sub_sub_self, add_right_comm],
exact @congr_arg ℕ ℤ _ _ (λi, (i + 1 : ℤ)) (nat.mod_add_div _ _).symm
end
theorem mod_add_div : ∀ (a b : ℤ), a % b + b * (a / b) = a
| (m : ℕ) 0 := congr_arg of_nat (nat.mod_add_div _ _)
| (m : ℕ) (n+1:ℕ) := congr_arg of_nat (nat.mod_add_div _ _)
| 0 -[1+ n] := rfl
| (m+1:ℕ) -[1+ n] := show (_ + -(n+1) * -((m + 1) / (n + 1) : ℕ) : ℤ) = _,
by rw [neg_mul_neg]; exact congr_arg of_nat (nat.mod_add_div _ _)
| -[1+ m] 0 := by rw [mod_zero, int.div_zero]; refl
| -[1+ m] (n+1:ℕ) := mod_add_div_aux m n.succ
| -[1+ m] -[1+ n] := mod_add_div_aux m n.succ
theorem mod_def (a b : ℤ) : a % b = a - b * (a / b) :=
eq_sub_of_add_eq (mod_add_div _ _)
@[simp] theorem add_mul_mod_self {a b c : ℤ} : (a + b * c) % c = a % c :=
if cz : c = 0 then by rw [cz, mul_zero, add_zero] else
by rw [mod_def, mod_def, int.add_mul_div_right _ _ cz,
mul_add, mul_comm, add_sub_add_right_eq_sub]
@[simp] theorem add_mul_mod_self_left (a b c : ℤ) : (a + b * c) % b = a % b :=
by rw [mul_comm, add_mul_mod_self]
@[simp] theorem add_mod_self {a b : ℤ} : (a + b) % b = a % b :=
by have := add_mul_mod_self_left a b 1; rwa mul_one at this
@[simp] theorem add_mod_self_left {a b : ℤ} : (a + b) % a = b % a :=
by rw [add_comm, add_mod_self]
@[simp] theorem mod_add_mod (m n k : ℤ) : (m % n + k) % n = (m + k) % n :=
by have := (add_mul_mod_self_left (m % n + k) n (m / n)).symm;
rwa [add_right_comm, mod_add_div] at this
@[simp] theorem add_mod_mod (m n k : ℤ) : (m + n % k) % k = (m + n) % k :=
by rw [add_comm, mod_add_mod, add_comm]
lemma add_mod (a b n : ℤ) : (a + b) % n = ((a % n) + (b % n)) % n :=
by rw [add_mod_mod, mod_add_mod]
theorem add_mod_eq_add_mod_right {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
(m + i) % n = (k + i) % n :=
by rw [← mod_add_mod, ← mod_add_mod k, H]
theorem add_mod_eq_add_mod_left {m n k : ℤ} (i : ℤ) (H : m % n = k % n) :
(i + m) % n = (i + k) % n :=
by rw [add_comm, add_mod_eq_add_mod_right _ H, add_comm]
theorem mod_add_cancel_right {m n k : ℤ} (i) : (m + i) % n = (k + i) % n ↔
m % n = k % n :=
⟨λ H, by have := add_mod_eq_add_mod_right (-i) H;
rwa [add_neg_cancel_right, add_neg_cancel_right] at this,
add_mod_eq_add_mod_right _⟩
theorem mod_add_cancel_left {m n k i : ℤ} :
(i + m) % n = (i + k) % n ↔ m % n = k % n :=
by rw [add_comm, add_comm i, mod_add_cancel_right]
theorem mod_sub_cancel_right {m n k : ℤ} (i) : (m - i) % n = (k - i) % n ↔
m % n = k % n :=
mod_add_cancel_right _
theorem mod_eq_mod_iff_mod_sub_eq_zero {m n k : ℤ} : m % n = k % n ↔ (m - k) % n = 0 :=
(mod_sub_cancel_right k).symm.trans $ by simp
@[simp] theorem mul_mod_left (a b : ℤ) : (a * b) % b = 0 :=
by rw [← zero_add (a * b), add_mul_mod_self, zero_mod]
@[simp] theorem mul_mod_right (a b : ℤ) : (a * b) % a = 0 :=
by rw [mul_comm, mul_mod_left]
lemma mul_mod (a b n : ℤ) : (a * b) % n = ((a % n) * (b % n)) % n :=
begin
conv_lhs {
rw [←mod_add_div a n, ←mod_add_div b n, right_distrib, left_distrib, left_distrib,
mul_assoc, mul_assoc, ←left_distrib n _ _, add_mul_mod_self_left,
mul_comm _ (n * (b / n)), mul_assoc, add_mul_mod_self_left] }
end
local attribute [simp] -- Will be generalized to Euclidean domains.
theorem mod_self {a : ℤ} : a % a = 0 :=
by have := mul_mod_left 1 a; rwa one_mul at this
@[simp] theorem mod_mod_of_dvd (n : int) {m k : int} (h : m ∣ k) : n % k % m = n % m :=
begin
conv { to_rhs, rw ←mod_add_div n k },
rcases h with ⟨t, rfl⟩, rw [mul_assoc, add_mul_mod_self_left]
end
@[simp] theorem mod_mod (a b : ℤ) : a % b % b = a % b :=
by conv {to_rhs, rw [← mod_add_div a b, add_mul_mod_self_left]}
lemma sub_mod (a b n : ℤ) : (a - b) % n = ((a % n) - (b % n)) % n :=
begin
apply (mod_add_cancel_right b).mp,
rw [sub_add_cancel, ← add_mod_mod, sub_add_cancel, mod_mod]
end
/- properties of / and % -/
@[simp] theorem mul_div_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b / (a * c) = b / c :=
suffices ∀ (m k : ℕ) (b : ℤ), (m.succ * b / (m.succ * k) : ℤ) = b / k, from
match a, eq_succ_of_zero_lt H, c, eq_coe_or_neg c with
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inl rfl⟩ := this _ _ _
| ._, ⟨m, rfl⟩, ._, ⟨k, or.inr rfl⟩ :=
by rw [← neg_mul_eq_mul_neg, int.div_neg, int.div_neg];
apply congr_arg has_neg.neg; apply this
end,
λ m k b, match b, k with
| (n : ℕ), k := congr_arg of_nat (nat.mul_div_mul _ _ m.succ_pos)
| -[1+ n], 0 := by rw [int.coe_nat_zero, mul_zero, int.div_zero, int.div_zero]
| -[1+ n], k+1 := congr_arg neg_succ_of_nat $
show (m.succ * n + m) / (m.succ * k.succ) = n / k.succ, begin
apply nat.div_eq_of_lt_le,
{ refine le_trans _ (nat.le_add_right _ _),
rw [← nat.mul_div_mul _ _ m.succ_pos],
apply nat.div_mul_le_self },
{ change m.succ * n.succ ≤ _,
rw [mul_left_comm],
apply nat.mul_le_mul_left,
apply (nat.div_lt_iff_lt_mul _ _ k.succ_pos).1,
apply nat.lt_succ_self }
end
end
@[simp] theorem mul_div_mul_of_pos_left (a : ℤ) {b : ℤ} (c : ℤ) (H : 0 < b) :
a * b / (c * b) = a / c :=
by rw [mul_comm, mul_comm c, mul_div_mul_of_pos _ _ H]
@[simp] theorem mul_mod_mul_of_pos {a : ℤ} (b c : ℤ) (H : 0 < a) : a * b % (a * c) = a * (b % c) :=
by rw [mod_def, mod_def, mul_div_mul_of_pos _ _ H, mul_sub_left_distrib, mul_assoc]
theorem lt_div_add_one_mul_self (a : ℤ) {b : ℤ} (H : 0 < b) : a < (a / b + 1) * b :=
by rw [add_mul, one_mul, mul_comm]; apply lt_add_of_sub_left_lt;
rw [← mod_def]; apply mod_lt_of_pos _ H
theorem abs_div_le_abs : ∀ (a b : ℤ), abs (a / b) ≤ abs a :=
suffices ∀ (a : ℤ) (n : ℕ), abs (a / n) ≤ abs a, from
λ a b, match b, eq_coe_or_neg b with
| ._, ⟨n, or.inl rfl⟩ := this _ _
| ._, ⟨n, or.inr rfl⟩ := by rw [int.div_neg, abs_neg]; apply this
end,
λ a n, by rw [abs_eq_nat_abs, abs_eq_nat_abs]; exact
coe_nat_le_coe_nat_of_le (match a, n with
| (m : ℕ), n := nat.div_le_self _ _
| -[1+ m], 0 := nat.zero_le _
| -[1+ m], n+1 := nat.succ_le_succ (nat.div_le_self _ _)
end)
theorem div_le_self {a : ℤ} (b : ℤ) (Ha : 0 ≤ a) : a / b ≤ a :=
by have := le_trans (le_abs_self _) (abs_div_le_abs a b);
rwa [abs_of_nonneg Ha] at this
theorem mul_div_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : b * (a / b) = a :=
by have := mod_add_div a b; rwa [H, zero_add] at this
theorem div_mul_cancel_of_mod_eq_zero {a b : ℤ} (H : a % b = 0) : a / b * b = a :=
by rw [mul_comm, mul_div_cancel_of_mod_eq_zero H]
lemma mod_two_eq_zero_or_one (n : ℤ) : n % 2 = 0 ∨ n % 2 = 1 :=
have h : n % 2 < 2 := abs_of_nonneg (show 0 ≤ (2 : ℤ), from dec_trivial) ▸ int.mod_lt _ dec_trivial,
have h₁ : 0 ≤ n % 2 := int.mod_nonneg _ dec_trivial,
match (n % 2), h, h₁ with
| (0 : ℕ) := λ _ _, or.inl rfl
| (1 : ℕ) := λ _ _, or.inr rfl
| (k + 2 : ℕ) := λ h _, absurd h dec_trivial
| -[1+ a] := λ _ h₁, absurd h₁ dec_trivial
end
/- dvd -/
@[norm_cast] theorem coe_nat_dvd {m n : ℕ} : (↑m : ℤ) ∣ ↑n ↔ m ∣ n :=
⟨λ ⟨a, ae⟩, m.eq_zero_or_pos.elim
(λm0, by simp [m0] at ae; simp [ae, m0])
(λm0l, by {
cases eq_coe_of_zero_le (@nonneg_of_mul_nonneg_left ℤ _ m a
(by simp [ae.symm]) (by simpa using m0l)) with k e,
subst a, exact ⟨k, int.coe_nat_inj ae⟩ }),
λ ⟨k, e⟩, dvd.intro k $ by rw [e, int.coe_nat_mul]⟩
theorem coe_nat_dvd_left {n : ℕ} {z : ℤ} : (↑n : ℤ) ∣ z ↔ n ∣ z.nat_abs :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem coe_nat_dvd_right {n : ℕ} {z : ℤ} : z ∣ (↑n : ℤ) ↔ z.nat_abs ∣ n :=
by rcases nat_abs_eq z with eq | eq; rw eq; simp [coe_nat_dvd]
theorem dvd_antisymm {a b : ℤ} (H1 : 0 ≤ a) (H2 : 0 ≤ b) : a ∣ b → b ∣ a → a = b :=
begin
rw [← abs_of_nonneg H1, ← abs_of_nonneg H2, abs_eq_nat_abs, abs_eq_nat_abs],
rw [coe_nat_dvd, coe_nat_dvd, coe_nat_inj'],
apply nat.dvd_antisymm
end
theorem dvd_of_mod_eq_zero {a b : ℤ} (H : b % a = 0) : a ∣ b :=
⟨b / a, (mul_div_cancel_of_mod_eq_zero H).symm⟩
theorem mod_eq_zero_of_dvd : ∀ {a b : ℤ}, a ∣ b → b % a = 0
| a ._ ⟨c, rfl⟩ := mul_mod_right _ _
theorem dvd_iff_mod_eq_zero (a b : ℤ) : a ∣ b ↔ b % a = 0 :=
⟨mod_eq_zero_of_dvd, dvd_of_mod_eq_zero⟩
/-- If `a % b = c` then `b` divides `a - c`. -/
lemma dvd_sub_of_mod_eq {a b c : ℤ} (h : a % b = c) : b ∣ a - c :=
begin
have hx : a % b % b = c % b, { rw h },
rw [mod_mod, ←mod_sub_cancel_right c, sub_self, zero_mod] at hx,
exact dvd_of_mod_eq_zero hx
end
theorem nat_abs_dvd {a b : ℤ} : (a.nat_abs : ℤ) ∣ b ↔ a ∣ b :=
(nat_abs_eq a).elim (λ e, by rw ← e) (λ e, by rw [← neg_dvd_iff_dvd, ← e])
theorem dvd_nat_abs {a b : ℤ} : a ∣ b.nat_abs ↔ a ∣ b :=
(nat_abs_eq b).elim (λ e, by rw ← e) (λ e, by rw [← dvd_neg_iff_dvd, ← e])
instance decidable_dvd : @decidable_rel ℤ (∣) :=
assume a n, decidable_of_decidable_of_iff (by apply_instance) (dvd_iff_mod_eq_zero _ _).symm
protected theorem div_mul_cancel {a b : ℤ} (H : b ∣ a) : a / b * b = a :=
div_mul_cancel_of_mod_eq_zero (mod_eq_zero_of_dvd H)
protected theorem mul_div_cancel' {a b : ℤ} (H : a ∣ b) : a * (b / a) = b :=
by rw [mul_comm, int.div_mul_cancel H]
protected theorem mul_div_assoc (a : ℤ) : ∀ {b c : ℤ}, c ∣ b → (a * b) / c = a * (b / c)
| ._ c ⟨d, rfl⟩ := if cz : c = 0 then by simp [cz] else
by rw [mul_left_comm, int.mul_div_cancel_left _ cz, int.mul_div_cancel_left _ cz]
theorem div_dvd_div : ∀ {a b c : ℤ} (H1 : a ∣ b) (H2 : b ∣ c), b / a ∣ c / a
| a ._ ._ ⟨b, rfl⟩ ⟨c, rfl⟩ := if az : a = 0 then by simp [az] else
by rw [int.mul_div_cancel_left _ az, mul_assoc, int.mul_div_cancel_left _ az];
apply dvd_mul_right
protected theorem eq_mul_of_div_eq_right {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
a = b * c :=
by rw [← H2, int.mul_div_cancel' H1]
protected theorem div_eq_of_eq_mul_right {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = b * c) :
a / b = c :=
by rw [H2, int.mul_div_cancel_left _ H1]
protected theorem div_eq_iff_eq_mul_right {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = b * c :=
⟨int.eq_mul_of_div_eq_right H', int.div_eq_of_eq_mul_right H⟩
protected theorem div_eq_iff_eq_mul_left {a b c : ℤ} (H : b ≠ 0) (H' : b ∣ a) :
a / b = c ↔ a = c * b :=
by rw mul_comm; exact int.div_eq_iff_eq_mul_right H H'
protected theorem eq_mul_of_div_eq_left {a b c : ℤ} (H1 : b ∣ a) (H2 : a / b = c) :
a = c * b :=
by rw [mul_comm, int.eq_mul_of_div_eq_right H1 H2]
protected theorem div_eq_of_eq_mul_left {a b c : ℤ} (H1 : b ≠ 0) (H2 : a = c * b) :
a / b = c :=
int.div_eq_of_eq_mul_right H1 (by rw [mul_comm, H2])
theorem neg_div_of_dvd : ∀ {a b : ℤ} (H : b ∣ a), -a / b = -(a / b)
| ._ b ⟨c, rfl⟩ := if bz : b = 0 then by simp [bz] else
by rw [neg_mul_eq_mul_neg, int.mul_div_cancel_left _ bz, int.mul_div_cancel_left _ bz]
lemma add_div_of_dvd {a b c : ℤ} :
c ∣ a → c ∣ b → (a + b) / c = a / c + b / c :=
begin
intros h1 h2,
by_cases h3 : c = 0,
{ rw [h3, zero_dvd_iff] at *,
rw [h1, h2, h3], refl },
{ apply mul_right_cancel' h3,
rw add_mul, repeat {rw [int.div_mul_cancel]};
try {apply dvd_add}; assumption }
end
theorem div_sign : ∀ a b, a / sign b = a * sign b
| a (n+1:ℕ) := by unfold sign; simp
| a 0 := by simp [sign]
| a -[1+ n] := by simp [sign]
@[simp] theorem sign_mul : ∀ a b, sign (a * b) = sign a * sign b
| a 0 := by simp
| 0 b := by simp
| (m+1:ℕ) (n+1:ℕ) := rfl
| (m+1:ℕ) -[1+ n] := rfl
| -[1+ m] (n+1:ℕ) := rfl
| -[1+ m] -[1+ n] := rfl
protected theorem sign_eq_div_abs (a : ℤ) : sign a = a / (abs a) :=
if az : a = 0 then by simp [az] else
(int.div_eq_of_eq_mul_left (mt eq_zero_of_abs_eq_zero az)
(sign_mul_abs _).symm).symm
theorem mul_sign : ∀ (i : ℤ), i * sign i = nat_abs i
| (n+1:ℕ) := mul_one _
| 0 := mul_zero _
| -[1+ n] := mul_neg_one _
theorem le_of_dvd {a b : ℤ} (bpos : 0 < b) (H : a ∣ b) : a ≤ b :=
match a, b, eq_succ_of_zero_lt bpos, H with
| (m : ℕ), ._, ⟨n, rfl⟩, H := coe_nat_le_coe_nat_of_le $
nat.le_of_dvd n.succ_pos $ coe_nat_dvd.1 H
| -[1+ m], ._, ⟨n, rfl⟩, _ :=
le_trans (le_of_lt $ neg_succ_lt_zero _) (coe_zero_le _)
end
theorem eq_one_of_dvd_one {a : ℤ} (H : 0 ≤ a) (H' : a ∣ 1) : a = 1 :=
match a, eq_coe_of_zero_le H, H' with
| ._, ⟨n, rfl⟩, H' := congr_arg coe $
nat.eq_one_of_dvd_one $ coe_nat_dvd.1 H'
end
theorem eq_one_of_mul_eq_one_right {a b : ℤ} (H : 0 ≤ a) (H' : a * b = 1) : a = 1 :=
eq_one_of_dvd_one H ⟨b, H'.symm⟩
theorem eq_one_of_mul_eq_one_left {a b : ℤ} (H : 0 ≤ b) (H' : a * b = 1) : b = 1 :=
eq_one_of_mul_eq_one_right H (by rw [mul_comm, H'])
lemma of_nat_dvd_of_dvd_nat_abs {a : ℕ} : ∀ {z : ℤ} (haz : a ∣ z.nat_abs), ↑a ∣ z
| (int.of_nat _) haz := int.coe_nat_dvd.2 haz
| -[1+k] haz :=
begin
change ↑a ∣ -(k+1 : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
exact haz
end
lemma dvd_nat_abs_of_of_nat_dvd {a : ℕ} : ∀ {z : ℤ} (haz : ↑a ∣ z), a ∣ z.nat_abs
| (int.of_nat _) haz := int.coe_nat_dvd.1 (int.dvd_nat_abs.2 haz)
| -[1+k] haz :=
have haz' : (↑a:ℤ) ∣ (↑(k+1):ℤ), from dvd_of_dvd_neg haz,
int.coe_nat_dvd.1 haz'
lemma pow_dvd_of_le_of_pow_dvd {p m n : ℕ} {k : ℤ} (hmn : m ≤ n) (hdiv : ↑(p ^ n) ∣ k) :
↑(p ^ m) ∣ k :=
begin
induction k,
{ apply int.coe_nat_dvd.2,
apply pow_dvd_of_le_of_pow_dvd hmn,
apply int.coe_nat_dvd.1 hdiv },
{ change -[1+k] with -(↑(k+1) : ℤ),
apply dvd_neg_of_dvd,
apply int.coe_nat_dvd.2,
apply pow_dvd_of_le_of_pow_dvd hmn,
apply int.coe_nat_dvd.1,
apply dvd_of_dvd_neg,
exact hdiv }
end
lemma dvd_of_pow_dvd {p k : ℕ} {m : ℤ} (hk : 1 ≤ k) (hpk : ↑(p^k) ∣ m) : ↑p ∣ m :=
by rw ←nat.pow_one p; exact pow_dvd_of_le_of_pow_dvd hk hpk
/- / and ordering -/
protected theorem div_mul_le (a : ℤ) {b : ℤ} (H : b ≠ 0) : a / b * b ≤ a :=
le_of_sub_nonneg $ by rw [mul_comm, ← mod_def]; apply mod_nonneg _ H
protected theorem div_le_of_le_mul {a b c : ℤ} (H : 0 < c) (H' : a ≤ b * c) : a / c ≤ b :=
le_of_mul_le_mul_right (le_trans (int.div_mul_le _ (ne_of_gt H)) H') H
protected theorem mul_lt_of_lt_div {a b c : ℤ} (H : 0 < c) (H3 : a < b / c) : a * c < b :=
lt_of_not_ge $ mt (int.div_le_of_le_mul H) (not_le_of_gt H3)
protected theorem mul_le_of_le_div {a b c : ℤ} (H1 : 0 < c) (H2 : a ≤ b / c) : a * c ≤ b :=
le_trans (mul_le_mul_of_nonneg_right H2 (le_of_lt H1)) (int.div_mul_le _ (ne_of_gt H1))
protected theorem le_div_of_mul_le {a b c : ℤ} (H1 : 0 < c) (H2 : a * c ≤ b) : a ≤ b / c :=
le_of_lt_add_one $ lt_of_mul_lt_mul_right
(lt_of_le_of_lt H2 (lt_div_add_one_mul_self _ H1)) (le_of_lt H1)
protected theorem le_div_iff_mul_le {a b c : ℤ} (H : 0 < c) : a ≤ b / c ↔ a * c ≤ b :=
⟨int.mul_le_of_le_div H, int.le_div_of_mul_le H⟩
protected theorem div_le_div {a b c : ℤ} (H : 0 < c) (H' : a ≤ b) : a / c ≤ b / c :=
int.le_div_of_mul_le H (le_trans (int.div_mul_le _ (ne_of_gt H)) H')
protected theorem div_lt_of_lt_mul {a b c : ℤ} (H : 0 < c) (H' : a < b * c) : a / c < b :=
lt_of_not_ge $ mt (int.mul_le_of_le_div H) (not_le_of_gt H')
protected theorem lt_mul_of_div_lt {a b c : ℤ} (H1 : 0 < c) (H2 : a / c < b) : a < b * c :=
lt_of_not_ge $ mt (int.le_div_of_mul_le H1) (not_le_of_gt H2)
protected theorem div_lt_iff_lt_mul {a b c : ℤ} (H : 0 < c) : a / c < b ↔ a < b * c :=
⟨int.lt_mul_of_div_lt H, int.div_lt_of_lt_mul H⟩
protected theorem le_mul_of_div_le {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ a) (H3 : a / b ≤ c) :
a ≤ c * b :=
by rw [← int.div_mul_cancel H2]; exact mul_le_mul_of_nonneg_right H3 H1
protected theorem lt_div_of_mul_lt {a b c : ℤ} (H1 : 0 ≤ b) (H2 : b ∣ c) (H3 : a * b < c) :
a < c / b :=
lt_of_not_ge $ mt (int.le_mul_of_div_le H1 H2) (not_le_of_gt H3)
protected theorem lt_div_iff_mul_lt {a b : ℤ} (c : ℤ) (H : 0 < c) (H' : c ∣ b) :
a < b / c ↔ a * c < b :=
⟨int.mul_lt_of_lt_div H, int.lt_div_of_mul_lt (le_of_lt H) H'⟩
theorem div_pos_of_pos_of_dvd {a b : ℤ} (H1 : 0 < a) (H2 : 0 ≤ b) (H3 : b ∣ a) : 0 < a / b :=
int.lt_div_of_mul_lt H2 H3 (by rwa zero_mul)
theorem div_eq_div_of_mul_eq_mul {a b c d : ℤ} (H2 : d ∣ c) (H3 : b ≠ 0)
(H4 : d ≠ 0) (H5 : a * d = b * c) :
a / b = c / d :=
int.div_eq_of_eq_mul_right H3 $
by rw [← int.mul_div_assoc _ H2]; exact
(int.div_eq_of_eq_mul_left H4 H5.symm).symm
theorem eq_mul_div_of_mul_eq_mul_of_dvd_left {a b c d : ℤ} (hb : b ≠ 0) (hbc : b ∣ c)
(h : b * a = c * d) : a = c / b * d :=
begin
cases hbc with k hk,
subst hk,
rw [int.mul_div_cancel_left _ hb],
rw mul_assoc at h,
apply mul_left_cancel' hb h
end
/-- If an integer with larger absolute value divides an integer, it is
zero. -/
lemma eq_zero_of_dvd_of_nat_abs_lt_nat_abs {a b : ℤ} (w : a ∣ b) (h : nat_abs b < nat_abs a) :
b = 0 :=
begin
rw [←nat_abs_dvd, ←dvd_nat_abs, coe_nat_dvd] at w,
rw ←nat_abs_eq_zero,
exact eq_zero_of_dvd_of_lt w h
end
lemma eq_zero_of_dvd_of_nonneg_of_lt {a b : ℤ} (w₁ : 0 ≤ a) (w₂ : a < b) (h : b ∣ a) : a = 0 :=
eq_zero_of_dvd_of_nat_abs_lt_nat_abs h (nat_abs_lt_nat_abs_of_nonneg_of_lt w₁ w₂)
/-- If two integers are congruent to a sufficiently large modulus,
they are equal. -/
lemma eq_of_mod_eq_of_nat_abs_sub_lt_nat_abs {a b c : ℤ} (h1 : a % b = c)
(h2 : nat_abs (a - c) < nat_abs b) :
a = c :=
eq_of_sub_eq_zero (eq_zero_of_dvd_of_nat_abs_lt_nat_abs (dvd_sub_of_mod_eq h1) h2)
theorem of_nat_add_neg_succ_of_nat_of_lt {m n : ℕ}
(h : m < n.succ) : of_nat m + -[1+n] = -[1+ n - m] :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = (n - m).succ,
apply succ_sub,
apply le_of_lt_succ h,
simp [*, sub_nat_nat]
end
theorem of_nat_add_neg_succ_of_nat_of_ge {m n : ℕ}
(h : n.succ ≤ m) : of_nat m + -[1+n] = of_nat (m - n.succ) :=
begin
change sub_nat_nat _ _ = _,
have h' : n.succ - m = 0,
apply sub_eq_zero_of_le h,
simp [*, sub_nat_nat]
end
@[simp] theorem neg_add_neg (m n : ℕ) : -[1+m] + -[1+n] = -[1+nat.succ(m+n)] := rfl
/- to_nat -/
theorem to_nat_eq_max : ∀ (a : ℤ), (to_nat a : ℤ) = max a 0
| (n : ℕ) := (max_eq_left (coe_zero_le n)).symm
| -[1+ n] := (max_eq_right (le_of_lt (neg_succ_lt_zero n))).symm
@[simp] lemma to_nat_zero : (0 : ℤ).to_nat = 0 := rfl
@[simp] lemma to_nat_one : (1 : ℤ).to_nat = 1 := rfl
@[simp] theorem to_nat_of_nonneg {a : ℤ} (h : 0 ≤ a) : (to_nat a : ℤ) = a :=
by rw [to_nat_eq_max, max_eq_left h]
@[simp] lemma to_nat_sub_of_le (a b : ℤ) (h : b ≤ a) : (to_nat (a + -b) : ℤ) = a + - b :=
int.to_nat_of_nonneg (sub_nonneg_of_le h)
@[simp] theorem to_nat_coe_nat (n : ℕ) : to_nat ↑n = n := rfl
@[simp] lemma to_nat_coe_nat_add_one {n : ℕ} : ((n : ℤ) + 1).to_nat = n + 1 := rfl
theorem le_to_nat (a : ℤ) : a ≤ to_nat a :=
by rw [to_nat_eq_max]; apply le_max_left
@[simp] theorem to_nat_le {a : ℤ} {n : ℕ} : to_nat a ≤ n ↔ a ≤ n :=
by rw [(coe_nat_le_coe_nat_iff _ _).symm, to_nat_eq_max, max_le_iff];
exact and_iff_left (coe_zero_le _)
@[simp] theorem lt_to_nat {n : ℕ} {a : ℤ} : n < to_nat a ↔ (n : ℤ) < a :=
le_iff_le_iff_lt_iff_lt.1 to_nat_le
theorem to_nat_le_to_nat {a b : ℤ} (h : a ≤ b) : to_nat a ≤ to_nat b :=
by rw to_nat_le; exact le_trans h (le_to_nat b)
theorem to_nat_lt_to_nat {a b : ℤ} (hb : 0 < b) : to_nat a < to_nat b ↔ a < b :=
⟨λ h, begin cases a, exact lt_to_nat.1 h, exact lt_trans (neg_succ_of_nat_lt_zero a) hb, end,
λ h, begin rw lt_to_nat, cases a, exact h, exact hb end⟩
theorem lt_of_to_nat_lt {a b : ℤ} (h : to_nat a < to_nat b) : a < b :=
(to_nat_lt_to_nat $ lt_to_nat.1 $ lt_of_le_of_lt (nat.zero_le _) h).1 h
lemma to_nat_add {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) :
(a + b).to_nat = a.to_nat + b.to_nat :=
begin
lift a to ℕ using ha,
lift b to ℕ using hb,
norm_cast,
end
lemma to_nat_add_one {a : ℤ} (h : 0 ≤ a) : (a + 1).to_nat = a.to_nat + 1 :=
to_nat_add h (zero_le_one)
def to_nat' : ℤ → option ℕ
| (n : ℕ) := some n
| -[1+ n] := none
theorem mem_to_nat' : ∀ (a : ℤ) (n : ℕ), n ∈ to_nat' a ↔ a = n
| (m : ℕ) n := option.some_inj.trans coe_nat_inj'.symm
| -[1+ m] n := by split; intro h; cases h
lemma to_nat_zero_of_neg : ∀ {z : ℤ}, z < 0 → z.to_nat = 0
| (-[1+n]) _ := rfl
| (int.of_nat n) h := (not_le_of_gt h $ int.of_nat_nonneg n).elim
/- units -/
@[simp] theorem units_nat_abs (u : units ℤ) : nat_abs u = 1 :=
units.ext_iff.1 $ nat.units_eq_one ⟨nat_abs u, nat_abs ↑u⁻¹,
by rw [← nat_abs_mul, units.mul_inv]; refl,
by rw [← nat_abs_mul, units.inv_mul]; refl⟩
theorem units_eq_one_or (u : units ℤ) : u = 1 ∨ u = -1 :=
by simpa only [units.ext_iff, units_nat_abs] using nat_abs_eq u
lemma units_inv_eq_self (u : units ℤ) : u⁻¹ = u :=
(units_eq_one_or u).elim (λ h, h.symm ▸ rfl) (λ h, h.symm ▸ rfl)
/- bitwise ops -/
@[simp] lemma bodd_zero : bodd 0 = ff := rfl
@[simp] lemma bodd_one : bodd 1 = tt := rfl
@[simp] lemma bodd_two : bodd 2 = ff := rfl
@[simp, norm_cast] lemma bodd_coe (n : ℕ) : int.bodd n = nat.bodd n := rfl
@[simp] lemma bodd_sub_nat_nat (m n : ℕ) : bodd (sub_nat_nat m n) = bxor m.bodd n.bodd :=
by apply sub_nat_nat_elim m n (λ m n i, bodd i = bxor m.bodd n.bodd); intros;
simp; cases i.bodd; simp
@[simp] lemma bodd_neg_of_nat (n : ℕ) : bodd (neg_of_nat n) = n.bodd :=
by cases n; simp; refl
@[simp] lemma bodd_neg (n : ℤ) : bodd (-n) = bodd n :=
by cases n; simp [has_neg.neg, int.coe_nat_eq, int.neg, bodd, -of_nat_eq_coe]
@[simp] lemma bodd_add (m n : ℤ) : bodd (m + n) = bxor (bodd m) (bodd n) :=
by cases m with m m; cases n with n n; unfold has_add.add;
simp [int.add, -of_nat_eq_coe, bool.bxor_comm]
@[simp] lemma bodd_mul (m n : ℤ) : bodd (m * n) = bodd m && bodd n :=
by cases m with m m; cases n with n n;
simp [← int.mul_def, int.mul, -of_nat_eq_coe, bool.bxor_comm]
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| (n : ℕ) :=
by rw [show (cond (bodd n) 1 0 : ℤ) = (cond (bodd n) 1 0 : ℕ),
by cases bodd n; refl]; exact congr_arg of_nat n.bodd_add_div2
| -[1+ n] := begin
refine eq.trans _ (congr_arg neg_succ_of_nat n.bodd_add_div2),
dsimp [bodd], cases nat.bodd n; dsimp [cond, bnot, div2, int.mul],
{ change -[1+ 2 * nat.div2 n] = _, rw zero_add },
{ rw [zero_add, add_comm], refl }
end
theorem div2_val : ∀ n, div2 n = n / 2
| (n : ℕ) := congr_arg of_nat n.div2_val
| -[1+ n] := congr_arg neg_succ_of_nat n.div2_val
lemma bit0_val (n : ℤ) : bit0 n = 2 * n := (two_mul _).symm
lemma bit1_val (n : ℤ) : bit1 n = 2 * n + 1 := congr_arg (+(1:ℤ)) (bit0_val _)
lemma bit_val (b n) : bit b n = 2 * n + cond b 1 0 :=
by { cases b, apply (bit0_val n).trans (add_zero _).symm, apply bit1_val }
lemma bit_decomp (n : ℤ) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans $ (add_comm _ _).trans $ bodd_add_div2 _
def {u} bit_cases_on {C : ℤ → Sort u} (n) (h : ∀ b n, C (bit b n)) : C n :=
by rw [← bit_decomp n]; apply h
@[simp] lemma bit_zero : bit ff 0 = 0 := rfl
@[simp] lemma bit_coe_nat (b) (n : ℕ) : bit b n = nat.bit b n :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bit_neg_succ (b) (n : ℕ) : bit b -[1+ n] = -[1+ nat.bit (bnot b) n] :=
by rw [bit_val, nat.bit_val]; cases b; refl
@[simp] lemma bodd_bit (b n) : bodd (bit b n) = b :=
by rw bit_val; simp; cases b; cases bodd n; refl
@[simp] lemma div2_bit (b n) : div2 (bit b n) = n :=
begin
rw [bit_val, div2_val, add_comm, int.add_mul_div_left, (_ : (_/2:ℤ) = 0), zero_add],
cases b, all_goals {exact dec_trivial}
end
@[simp] lemma test_bit_zero (b) : ∀ n, test_bit (bit b n) 0 = b
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_zero
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_zero];
clear test_bit_zero; cases b; refl
@[simp] lemma test_bit_succ (m b) : ∀ n, test_bit (bit b n) (nat.succ m) = test_bit n m
| (n : ℕ) := by rw [bit_coe_nat]; apply nat.test_bit_succ
| -[1+ n] := by rw [bit_neg_succ]; dsimp [test_bit]; rw [nat.test_bit_succ]
private meta def bitwise_tac : tactic unit := `[
funext m,
funext n,
cases m with m m; cases n with n n; try {refl},
all_goals {
apply congr_arg of_nat <|> apply congr_arg neg_succ_of_nat,
try {dsimp [nat.land, nat.ldiff, nat.lor]},
try {rw [
show nat.bitwise (λ a b, a && bnot b) n m =
nat.bitwise (λ a b, b && bnot a) m n, from
congr_fun (congr_fun (@nat.bitwise_swap (λ a b, b && bnot a) rfl) n) m]},
apply congr_arg (λ f, nat.bitwise f m n),
funext a,
funext b,
cases a; cases b; refl
},
all_goals {unfold nat.land nat.ldiff nat.lor}
]
theorem bitwise_or : bitwise bor = lor := by bitwise_tac
theorem bitwise_and : bitwise band = land := by bitwise_tac
theorem bitwise_diff : bitwise (λ a b, a && bnot b) = ldiff := by bitwise_tac
theorem bitwise_xor : bitwise bxor = lxor := by bitwise_tac
@[simp] lemma bitwise_bit (f : bool → bool → bool) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) :=
begin
cases m with m m; cases n with n n;
repeat { rw [← int.coe_nat_eq] <|> rw bit_coe_nat <|> rw bit_neg_succ };
unfold bitwise nat_bitwise bnot;
[ induction h : f ff ff,
induction h : f ff tt,
induction h : f tt ff,
induction h : f tt tt ],
all_goals {
unfold cond, rw nat.bitwise_bit,
repeat { rw bit_coe_nat <|> rw bit_neg_succ <|> rw bnot_bnot } },
all_goals { unfold bnot {fail_if_unchanged := ff}; rw h; refl }
end
@[simp] lemma lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) :=
by rw [← bitwise_or, bitwise_bit]
@[simp] lemma land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) :=
by rw [← bitwise_and, bitwise_bit]
@[simp] lemma ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && bnot b) (ldiff m n) :=
by rw [← bitwise_diff, bitwise_bit]
@[simp] lemma lxor_bit (a m b n) : lxor (bit a m) (bit b n) = bit (bxor a b) (lxor m n) :=
by rw [← bitwise_xor, bitwise_bit]
@[simp] lemma lnot_bit (b) : ∀ n, lnot (bit b n) = bit (bnot b) (lnot n)
| (n : ℕ) := by simp [lnot]
| -[1+ n] := by simp [lnot]
@[simp] lemma test_bit_bitwise (f : bool → bool → bool) (m n k) :
test_bit (bitwise f m n) k = f (test_bit m k) (test_bit n k) :=
begin
induction k with k IH generalizing m n;
apply bit_cases_on m; intros a m';
apply bit_cases_on n; intros b n';
rw bitwise_bit,
{ simp [test_bit_zero] },
{ simp [test_bit_succ, IH] }
end
@[simp] lemma test_bit_lor (m n k) : test_bit (lor m n) k = test_bit m k || test_bit n k :=
by rw [← bitwise_or, test_bit_bitwise]
@[simp] lemma test_bit_land (m n k) : test_bit (land m n) k = test_bit m k && test_bit n k :=
by rw [← bitwise_and, test_bit_bitwise]
@[simp]
lemma test_bit_ldiff (m n k) : test_bit (ldiff m n) k = test_bit m k && bnot (test_bit n k) :=
by rw [← bitwise_diff, test_bit_bitwise]
@[simp] lemma test_bit_lxor (m n k) : test_bit (lxor m n) k = bxor (test_bit m k) (test_bit n k) :=
by rw [← bitwise_xor, test_bit_bitwise]
@[simp] lemma test_bit_lnot : ∀ n k, test_bit (lnot n) k = bnot (test_bit n k)
| (n : ℕ) k := by simp [lnot, test_bit]
| -[1+ n] k := by simp [lnot, test_bit]
lemma shiftl_add : ∀ (m : ℤ) (n : ℕ) (k : ℤ), shiftl m (n + k) = shiftl (shiftl m n) k
| (m : ℕ) n (k:ℕ) := congr_arg of_nat (nat.shiftl_add _ _ _)
| -[1+ m] n (k:ℕ) := congr_arg neg_succ_of_nat (nat.shiftl'_add _ _ _ _)
| (m : ℕ) n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl ↑m i = nat.shiftr (nat.shiftl m n) k)
(λ i n, congr_arg coe $
by rw [← nat.shiftl_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg coe $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl_sub, nat.sub_self]; refl)
| -[1+ m] n -[1+k] := sub_nat_nat_elim n k.succ
(λ n k i, shiftl -[1+ m] i = -[1+ nat.shiftr (nat.shiftl' tt m n) k])
(λ i n, congr_arg neg_succ_of_nat $
by rw [← nat.shiftl'_sub, nat.add_sub_cancel_left]; apply nat.le_add_right)
(λ i n, congr_arg neg_succ_of_nat $
by rw [add_assoc, nat.shiftr_add, ← nat.shiftl'_sub, nat.sub_self]; refl)
lemma shiftl_sub (m : ℤ) (n : ℕ) (k : ℤ) : shiftl m (n - k) = shiftr (shiftl m n) k :=
shiftl_add _ _ _
@[simp] lemma shiftl_neg (m n : ℤ) : shiftl m (-n) = shiftr m n := rfl
@[simp] lemma shiftr_neg (m n : ℤ) : shiftr m (-n) = shiftl m n := by rw [← shiftl_neg, neg_neg]
@[simp] lemma shiftl_coe_nat (m n : ℕ) : shiftl m n = nat.shiftl m n := rfl
@[simp] lemma shiftr_coe_nat (m n : ℕ) : shiftr m n = nat.shiftr m n := by cases n; refl
@[simp] lemma shiftl_neg_succ (m n : ℕ) : shiftl -[1+ m] n = -[1+ nat.shiftl' tt m n] := rfl
@[simp]
lemma shiftr_neg_succ (m n : ℕ) : shiftr -[1+ m] n = -[1+ nat.shiftr m n] := by cases n; refl
lemma shiftr_add : ∀ (m : ℤ) (n k : ℕ), shiftr m (n + k) = shiftr (shiftr m n) k
| (m : ℕ) n k := by rw [shiftr_coe_nat, shiftr_coe_nat,
← int.coe_nat_add, shiftr_coe_nat, nat.shiftr_add]
| -[1+ m] n k := by rw [shiftr_neg_succ, shiftr_neg_succ,
← int.coe_nat_add, shiftr_neg_succ, nat.shiftr_add]
lemma shiftl_eq_mul_pow : ∀ (m : ℤ) (n : ℕ), shiftl m n = m * ↑(2 ^ n)
| (m : ℕ) n := congr_arg coe (nat.shiftl_eq_mul_pow _ _)
| -[1+ m] n := @congr_arg ℕ ℤ _ _ (λi, -i) (nat.shiftl'_tt_eq_mul_pow _ _)
lemma shiftr_eq_div_pow : ∀ (m : ℤ) (n : ℕ), shiftr m n = m / ↑(2 ^ n)
| (m : ℕ) n := by rw shiftr_coe_nat; exact congr_arg coe (nat.shiftr_eq_div_pow _ _)
| -[1+ m] n := begin
rw [shiftr_neg_succ, neg_succ_of_nat_div, nat.shiftr_eq_div_pow], refl,
exact coe_nat_lt_coe_nat_of_lt (nat.pos_pow_of_pos _ dec_trivial)
end
lemma one_shiftl (n : ℕ) : shiftl 1 n = (2 ^ n : ℕ) :=
congr_arg coe (nat.one_shiftl _)
@[simp] lemma zero_shiftl : ∀ n : ℤ, shiftl 0 n = 0
| (n : ℕ) := congr_arg coe (nat.zero_shiftl _)
| -[1+ n] := congr_arg coe (nat.zero_shiftr _)
@[simp] lemma zero_shiftr (n) : shiftr 0 n = 0 := zero_shiftl _
/- Least upper bound property for integers -/
section classical
open_locale classical
theorem exists_least_of_bdd {P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → b ≤ z)
(Hinh : ∃ z : ℤ, P z) : ∃ lb : ℤ, P lb ∧ (∀ z : ℤ, P z → lb ≤ z) :=
let ⟨b, Hb⟩ := Hbdd in
have EX : ∃ n : ℕ, P (b + n), from
let ⟨elt, Helt⟩ := Hinh in
match elt, le.dest (Hb _ Helt), Helt with
| ._, ⟨n, rfl⟩, Hn := ⟨n, Hn⟩
end,
⟨b + (nat.find EX : ℤ), nat.find_spec EX, λ z h,
match z, le.dest (Hb _ h), h with
| ._, ⟨n, rfl⟩, h := add_le_add_left
(int.coe_nat_le.2 $ nat.find_min' _ h) _
end⟩
theorem exists_greatest_of_bdd {P : ℤ → Prop}
(Hbdd : ∃ b : ℤ, ∀ z : ℤ, P z → z ≤ b)
(Hinh : ∃ z : ℤ, P z) : ∃ ub : ℤ, P ub ∧ (∀ z : ℤ, P z → z ≤ ub) :=
have Hbdd' : ∃ (b : ℤ), ∀ (z : ℤ), P (-z) → b ≤ z, from
let ⟨b, Hb⟩ := Hbdd in ⟨-b, λ z h, neg_le.1 (Hb _ h)⟩,
have Hinh' : ∃ z : ℤ, P (-z), from
let ⟨elt, Helt⟩ := Hinh in ⟨-elt, by rw [neg_neg]; exact Helt⟩,
let ⟨lb, Plb, al⟩ := exists_least_of_bdd Hbdd' Hinh' in
⟨-lb, Plb, λ z h, le_neg.1 $ al _ $ by rwa neg_neg⟩
end classical
end int
|
d4de9de206ce5b3eabef81f410374e8577968c10 | 5382d69a781e8d7e4f53e2358896eb7649c9b298 | /util.lean | eaa8915576f954d24617a577024573972952a7ee | [] | no_license | evhub/lean-math-examples | c30249747a21fba3bc8793eba4928db47cf28768 | dec44bf581a1e9d5bf0b5261803a43fe8fd350e1 | refs/heads/master | 1,624,170,837,738 | 1,623,889,725,000 | 1,623,889,725,000 | 148,759,369 | 3 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,723 | lean | namespace util
open function nat
open classical (em prop_decidable)
local attribute [instance] prop_decidable
-- nat:
@[simp] theorem le_zero_elim {n: nat}:
n ≤ 0 ↔ n = 0 := begin
apply iff.intro,
apply eq_zero_of_le_zero,
intro h0,
rw [h0],
end
-- classical logic:
@[simp] theorem not_not_elim (P: Prop):
¬¬P ↔ P := begin
apply iff.intro,
{
intro hnn,
by_contra hn,
apply hnn,
exact hn,
},
{
intros h hn,
apply hn,
exact h,
},
end
theorem not_forall_not_elim {T: Type _} {P: T → Prop} (hnfa: ¬ ∀ x: T, ¬ P x):
∃ x: T, P x := begin
by_contra hnex,
apply hnfa,
intro x,
by_contra hnP,
apply hnex,
apply exists.intro x hnP,
end
@[simp] theorem not_and (A B: Prop):
¬(A ∧ B) ↔ ¬A ∨ ¬B := begin
apply iff.intro,
{
intro hAB,
cases (em A);
cases (em B),
{
apply false.elim,
apply hAB,
split;
assumption,
},
{
right,
assumption,
},
all_goals {
left,
assumption,
},
},
{
intros hor hand,
cases hor,
case or.inl {
apply hor,
exact hand.1,
},
case or.inr {
apply hor,
exact hand.2,
},
},
end
-- isempty:
@[reducible] def isempty (A: Sort _):
Prop := ¬ nonempty A
theorem isempty.elim {A: Sort _} (h: isempty A) (a: A):
∀ {P: Prop}, P := begin
intros,
apply false.elim,
apply h,
split,
exact a,
end
-- function classes:
attribute [class] injective
attribute [class] surjective
attribute [class] bijective
instance bijective_of_inj_sur {T T': Sort _} {f: T → T'} [hfi: injective f] [hfs: surjective f]:
bijective f := (| hfi, hfs |)
instance inj_of_bijective {T T': Sort _} {f: T → T'} [hf: bijective f]:
injective f := hf.1
instance sur_of_bijective {T T': Sort _} {f: T → T'} [hf: bijective f]:
surjective f := hf.2
-- id:
instance id.bijective {T: Sort _}:
bijective (@id T) := begin
split,
show injective id, by {
intros x y h,
simp at h,
exact h,
},
show surjective id, by {
intro x,
apply exists.intro x,
simp,
},
end
-- cast:
@[simp] theorem cast_cast_elim {T T': Sort _} {x: T} (h: T = T') (h': T' = T):
cast h' (cast h x) = x := begin
cases h,
refl,
end
theorem cast_eq_of_heq {T T': Sort _} {x: T} {x': T'}:
x == x' →
Σ' h: T = T',
cast h x = x' := begin
intro h,
cases h,
split,
refl,
refl,
end
theorem heq_of_cast_eq {T T': Sort _} {x: T} {x': T'} {h: T = T'}:
cast h x = x' →
x == x' := begin
intro hcast,
cases h,
cases hcast,
refl,
end
end util
|
084ba036035c435608edc5780348ee12b0d3c7e0 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/order/semiconj_Sup.lean | 3788b90f230dd867e660813246c91076f3bcbe85 | [
"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 | 5,396 | 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
-/
import order.conditionally_complete_lattice
import logic.function.conjugate
import order.ord_continuous
import data.equiv.mul_add
/-!
# Semiconjugate by `Sup`
In this file we prove two facts about semiconjugate (families of) functions.
First, if an order isomorphism `fa : α → α` is semiconjugate to an order embedding `fb : β → β` by
`g : α → β`, then `fb` is semiconjugate to `fa` by `y ↦ Sup {x | g x ≤ y}`, see
`semiconj.symm_adjoint`.
Second, consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`,
see `function.Sup_div_semiconj`. In the case of a conditionally complete lattice, a similar
statement holds true under an additional assumption that each set `{(f₁ g)⁻¹ (f₂ g x) | g : G}` is
bounded above, see `function.cSup_div_semiconj`.
The lemmas come from [Étienne Ghys, Groupes d'homeomorphismes du cercle et cohomologie
bornee][ghys87:groupes], Proposition 2.1 and 5.4 respectively. In the paper they are formulated for
homeomorphisms of the circle, so in order to apply results from this file one has to lift these
homeomorphisms to the real line first.
-/
variables {α : Type*} {β : Type*}
open set
/-- We say that `g : β → α` is an order right adjoint function for `f : α → β` if it sends each `y`
to a least upper bound for `{x | f x ≤ y}`. If `α` is a partial order, and `f : α → β` has
a right adjoint, then this right adjoint is unique. -/
def is_order_right_adjoint [preorder α] [preorder β] (f : α → β) (g : β → α) :=
∀ y, is_lub {x | f x ≤ y} (g y)
lemma is_order_right_adjoint_Sup [complete_lattice α] [preorder β] (f : α → β) :
is_order_right_adjoint f (λ y, Sup {x | f x ≤ y}) :=
λ y, is_lub_Sup _
lemma is_order_right_adjoint_cSup [conditionally_complete_lattice α] [preorder β] (f : α → β)
(hne : ∀ y, ∃ x, f x ≤ y) (hbdd : ∀ y, ∃ b, ∀ x, f x ≤ y → x ≤ b) :
is_order_right_adjoint f (λ y, Sup {x | f x ≤ y}) :=
λ y, is_lub_cSup (hne y) (hbdd y)
lemma is_order_right_adjoint.unique [partial_order α] [preorder β] {f : α → β} {g₁ g₂ : β → α}
(h₁ : is_order_right_adjoint f g₁) (h₂ : is_order_right_adjoint f g₂) :
g₁ = g₂ :=
funext $ λ y, (h₁ y).unique (h₂ y)
lemma is_order_right_adjoint.right_mono [preorder α] [preorder β] {f : α → β} {g : β → α}
(h : is_order_right_adjoint f g) :
monotone g :=
λ y₁ y₂ hy, (h y₁).mono (h y₂) $ λ x hx, le_trans hx hy
namespace function
/-- If an order automorphism `fa` is semiconjugate to an order embedding `fb` by a function `g`
and `g'` is an order right adjoint of `g` (i.e. `g' y = Sup {x | f x ≤ y}`), then `fb` is
semiconjugate to `fa` by `g'`.
This is a version of Proposition 2.1 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma semiconj.symm_adjoint [partial_order α] [preorder β]
{fa : α ≃o α}
{fb : β ↪o β} {g : α → β}
(h : function.semiconj g fa fb) {g' : β → α} (hg' : is_order_right_adjoint g g') :
function.semiconj g' fb fa :=
begin
refine λ y, (hg' _).unique _,
rw [← fa.surjective.image_preimage {x | g x ≤ fb y}, preimage_set_of_eq],
simp only [h.eq, fb.le_iff_le, fa.left_ord_continuous (hg' _)]
end
variable {G : Type*}
lemma semiconj_of_is_lub [partial_order α] [group G]
(f₁ f₂ : G →* (α ≃o α)) {h : α → α}
(H : ∀ x, is_lub (range (λ g', (f₁ g')⁻¹ (f₂ g' x))) (h x)) (g : G) :
function.semiconj h (f₂ g) (f₁ g) :=
begin
refine λ y, (H _).unique _,
have := (f₁ g).left_ord_continuous (H y),
rw [← range_comp, ← (equiv.mul_right g).surjective.range_comp _] at this,
simpa [(∘)] using this
end
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a complete lattice by order
isomorphisms. Then the map `x ↦ ⨆ g : G, (f₁ g)⁻¹ (f₂ g x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma Sup_div_semiconj [complete_lattice α] [group G]
(f₁ f₂ : G →* (α ≃o α)) (g : G) :
function.semiconj (λ x, ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_is_lub f₁ f₂ (λ x, is_lub_supr) _
/-- Consider two actions `f₁ f₂ : G → α → α` of a group on a conditionally complete lattice by order
isomorphisms. Suppose that each set $s(x)=\{f_1(g)^{-1} (f_2(g)(x)) | g \in G\}$ is bounded above.
Then the map `x ↦ Sup s(x)` semiconjugates each `f₁ g'` to `f₂ g'`.
This is a version of Proposition 5.4 from [Étienne Ghys, Groupes d'homeomorphismes du cercle et
cohomologie bornee][ghys87:groupes]. -/
lemma cSup_div_semiconj [conditionally_complete_lattice α] [group G]
(f₁ f₂ : G →* (α ≃o α))
(hbdd : ∀ x, bdd_above (range $ λ g, (f₁ g)⁻¹ (f₂ g x))) (g : G) :
function.semiconj (λ x, ⨆ g' : G, (f₁ g')⁻¹ (f₂ g' x)) (f₂ g) (f₁ g) :=
semiconj_of_is_lub f₁ f₂ (λ x, is_lub_cSup (range_nonempty _) (hbdd x)) _
end function
|
c53e9befbdb1159a808638ab7f84c6e3f322f673 | 6dacdff2020860f2468bb8dacf344e6b043d6a78 | /love/src/demo_group.lean | f4df69bdef808e837500b8735feec8ba691d1d2d | [] | no_license | alexjbest/talks | 514ca57af312a14cf68c30efa1c7228294edc190 | 84976b4329ea768c754da72cc15d5ce29332466d | refs/heads/master | 1,686,993,465,308 | 1,686,315,975,000 | 1,686,315,975,000 | 16,347,963 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,471 | lean | import algebra.group.basic
import data.bracket
import tactic.group
import tactic.gptf
/- Tactic : rw
## Summary
If `h` is a proof of `X = Y`, then `rw h,` will change
all `X`s in the goal to `Y`s.
Variants: `rw ← h` changes
`Y` to `X` and
`rw h at h2` changes `X` to `Y` in hypothesis `h2` instead
of the goal.
## Details
The `rw` tactic is a way to do "substituting in". There
are two distinct situations where use this tactics.
1) If `h : A = B` is a hypothesis (i.e., a proof of `A = B`)
in your local context (the box in the top right)
and if your goal contains one or more `A`s, then `rw h`
will change them all to `B`'s.
2) The `rw` tactic will also work with proofs of theorems
which are equalities (look for them in the drop down
menu on the left, within Theorem Statements).
Important note: if `h` is not a proof of the form `A = B`
or `A ↔ B` (for example if `h` is a function, an implication,
or perhaps even a proposition itself rather than its proof),
then `rw` is not the tactic you want to use. For example,
`rw (P = Q)` is never correct: `P = Q` is the true-false
statement itself, not the proof.
If `h : P = Q` is its proof, then `rw h` will work.
Pro tip 1: If `h : A = B` and you want to change
`B`s to `A`s instead, try `rw ←h` (get the arrow with `\l`,
note that this is a small letter L, not a number 1).
### Example:
If it looks like this in the top right hand box:
```
A B C : set X
h : A = B ∪ C
⊢ A ∪ B = B ∪ C
```
then
`rw h,`
will change the goal into `⊢ B ∪ C ∪ B = B ∪ C`.
### Example:
You can use `rw` to change a hypothesis as well.
For example, if your local context looks like this:
```
A B C D : set X
h1 : A = B ∩ C
h2 : B ∪ A = D
⊢ D = B
```
then `rw h1 at h2` will turn `h2` into `h2 : B ∪ B ∩ C = D` (remember operator precedence).
-/
/-
The next tactic we will learn is *rw* (from rewrite). It rewrites equalities. That is,
if we have a proof `h : x = 3` and we want to prove `⊢ x + 1 = 4`, then after `rw h` the goal
will become `⊢ 3 + 1 = 4`, which seems reasonable.
-/
/-
# Commutator identities
In these exercises we will write the proofs of the identities in
https://en.wikipedia.org/wiki/Commutator#Identities_(group_theory)
in the Lean interactive theorem prover.
-/
notation `[`x`, `y`]` := has_bracket.bracket x y -- hide
def commutator {G : Type*} [group G] : G → G → G := λ x y, x⁻¹ * y⁻¹ * x * y
instance group.has_bracket {G : Type*} [group G] : has_bracket G G := ⟨commutator⟩ -- hide
def conjugate {G : Type*} [group G] : G → G → G := λ x y, y⁻¹ * x * y
instance group.has_pow {G : Type*} [group G] : has_pow G G := ⟨conjugate⟩ -- hide
/- Axiom : The definition of commutator
commutator_def : [x, y] = x⁻¹ * y⁻¹ * x * y
-/
lemma commutator_def {G : Type*} [group G] {x y : G} : [x, y] = x⁻¹ * y⁻¹ * x * y := rfl
/- Axiom : The definition of conjugate
conjugate_def : y^x = x⁻¹ * y * x := rfl
-/
lemma conjugate_def {G : Type*} [group G] {x y : G} : y^x = x⁻¹ * y * x := rfl
/- Lemma
-/
lemma commutator_self {G : Type*} [group G] {x : G} : [x, x] = 1 :=
begin
rw [commutator_def, inv_mul_cancel_right, inv_mul_self],
end
/- Lemma
-/
lemma conjugate_self {G : Type*} [group G] {x : G} : x ^ x = x :=
begin
rw [conjugate_def, inv_mul_self, one_mul],
end
/- Lemma
-/
lemma commutator_inv {G : Type*} [group G] {x y : G} : [y, x] = [x, y]⁻¹ :=
begin
rw [commutator_def, commutator_def, mul_inv_rev, mul_inv_rev, mul_inv_rev, inv_inv, inv_inv,
mul_assoc, mul_assoc],
end
-- ex2
/- Lemma
-/
lemma commutator_mul {G : Type*} [group G] {x y z : G} : [x, z * y] = [x, y] * [x, z]^y :=
begin
rw [commutator_def, commutator_def, commutator_def, conjugate_def, mul_inv_rev],
assoc_rw [mul_inv_self],
rw mul_one,
assoc_rw [mul_inv_self],
rw mul_one,
simp [mul_assoc],
-- ac_refl, -- fails
end
-- ex3
/- Lemma
-/
lemma hall_witt {G : Type*} [group G] {x y z : G} :
[[x, y⁻¹], z] ^ y * [[y, z⁻¹], x] ^ z * [[z, x⁻¹], y] ^ x = 1 :=
begin
repeat { rw commutator_def, },
repeat{ rw conjugate_def, },
rw inv_inv,
rw inv_inv,
rw inv_inv,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw mul_inv_rev,
rw inv_inv,
rw inv_inv,
rw inv_inv,
assoc_rw [inv_mul_self],
assoc_rw [inv_mul_self],
assoc_rw [inv_mul_self],
simp [one_mul, mul_one],
end
-- { simp [mul_assoc] },
|
370c64f4211d66beb448f07b8604a6be7f6eb41b | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/category_theory/structured_arrow.lean | b478571ddaa5c3eec5df92b7164fe3ad8823f686 | [
"Apache-2.0"
] | permissive | ramonfmir/mathlib | c5dc8b33155473fab97c38bd3aa6723dc289beaa | 14c52e990c17f5a00c0cc9e09847af16fabbed25 | refs/heads/master | 1,661,979,343,526 | 1,660,830,384,000 | 1,660,830,384,000 | 182,072,989 | 0 | 0 | null | 1,555,585,876,000 | 1,555,585,876,000 | null | UTF-8 | Lean | false | false | 15,896 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Adam Topaz, Scott Morrison
-/
import category_theory.punit
import category_theory.comma
import category_theory.limits.shapes.terminal
/-!
# The category of "structured arrows"
For `T : C ⥤ D`, a `T`-structured arrow with source `S : D`
is just a morphism `S ⟶ T.obj Y`, for some `Y : C`.
These form a category with morphisms `g : Y ⟶ Y'` making the obvious diagram commute.
We prove that `𝟙 (T.obj Y)` is the initial object in `T`-structured objects with source `T.obj Y`.
-/
namespace category_theory
-- morphism levels before object levels. See note [category_theory universes].
universes v₁ v₂ v₃ v₄ u₁ u₂ u₃ u₄
variables {C : Type u₁} [category.{v₁} C] {D : Type u₂} [category.{v₂} D]
/--
The category of `T`-structured arrows with domain `S : D` (here `T : C ⥤ D`),
has as its objects `D`-morphisms of the form `S ⟶ T Y`, for some `Y : C`,
and morphisms `C`-morphisms `Y ⟶ Y'` making the obvious triangle commute.
-/
@[derive category, nolint has_nonempty_instance]
def structured_arrow (S : D) (T : C ⥤ D) := comma (functor.from_punit S) T
namespace structured_arrow
/-- The obvious projection functor from structured arrows. -/
@[simps]
def proj (S : D) (T : C ⥤ D) : structured_arrow S T ⥤ C := comma.snd _ _
variables {S S' S'' : D} {Y Y' : C} {T : C ⥤ D}
/-- Construct a structured arrow from a morphism. -/
def mk (f : S ⟶ T.obj Y) : structured_arrow S T := ⟨⟨⟨⟩⟩, Y, f⟩
@[simp] lemma mk_left (f : S ⟶ T.obj Y) : (mk f).left = ⟨⟨⟩⟩ := rfl
@[simp] lemma mk_right (f : S ⟶ T.obj Y) : (mk f).right = Y := rfl
@[simp] lemma mk_hom_eq_self (f : S ⟶ T.obj Y) : (mk f).hom = f := rfl
@[simp, reassoc] lemma w {A B : structured_arrow S T} (f : A ⟶ B) : A.hom ≫ T.map f.right = B.hom :=
by { have := f.w; tidy }
/--
To construct a morphism of structured arrows,
we need a morphism of the objects underlying the target,
and to check that the triangle commutes.
-/
@[simps]
def hom_mk {f f' : structured_arrow S T} (g : f.right ⟶ f'.right) (w : f.hom ≫ T.map g = f'.hom) :
f ⟶ f' :=
{ left := eq_to_hom (by ext),
right := g,
w' := by { dsimp, simpa using w.symm, }, }
/--
Given a structured arrow `X ⟶ F(U)`, and an arrow `U ⟶ Y`, we can construct a morphism of
structured arrow given by `(X ⟶ F(U)) ⟶ (X ⟶ F(U) ⟶ F(Y))`.
-/
def hom_mk' {F : C ⥤ D} {X : D} {Y : C}
(U : structured_arrow X F) (f : U.right ⟶ Y) :
U ⟶ mk (U.hom ≫ F.map f) := { right := f }
/--
To construct an isomorphism of structured arrows,
we need an isomorphism of the objects underlying the target,
and to check that the triangle commutes.
-/
@[simps]
def iso_mk {f f' : structured_arrow S T} (g : f.right ≅ f'.right)
(w : f.hom ≫ T.map g.hom = f'.hom) : f ≅ f' :=
comma.iso_mk (eq_to_iso (by ext)) g (by simpa [eq_to_hom_map] using w.symm)
lemma ext {A B : structured_arrow S T} (f g : A ⟶ B) : f.right = g.right → f = g :=
comma_morphism.ext _ _ (subsingleton.elim _ _)
lemma ext_iff {A B : structured_arrow S T} (f g : A ⟶ B) : f = g ↔ f.right = g.right :=
⟨λ h, h ▸ rfl, ext f g⟩
instance proj_faithful : faithful (proj S T) :=
{ map_injective' := λ X Y, ext }
/-- The converse of this is true with additional assumptions, see `mono_iff_mono_right`. -/
lemma mono_of_mono_right {A B : structured_arrow S T} (f : A ⟶ B) [h : mono f.right] : mono f :=
(proj S T).mono_of_mono_map h
lemma epi_of_epi_right {A B : structured_arrow S T} (f : A ⟶ B) [h : epi f.right] : epi f :=
(proj S T).epi_of_epi_map h
instance mono_hom_mk {A B : structured_arrow S T} (f : A.right ⟶ B.right) (w) [h : mono f] :
mono (hom_mk f w) :=
(proj S T).mono_of_mono_map h
instance epi_hom_mk {A B : structured_arrow S T} (f : A.right ⟶ B.right) (w) [h : epi f] :
epi (hom_mk f w) :=
(proj S T).epi_of_epi_map h
/-- Eta rule for structured arrows. Prefer `structured_arrow.eta`, since equality of objects tends
to cause problems. -/
lemma eq_mk (f : structured_arrow S T) : f = mk f.hom :=
by { cases f, congr, ext, }
/-- Eta rule for structured arrows. -/
@[simps]
def eta (f : structured_arrow S T) : f ≅ mk f.hom :=
iso_mk (iso.refl _) (by tidy)
/--
A morphism between source objects `S ⟶ S'`
contravariantly induces a functor between structured arrows,
`structured_arrow S' T ⥤ structured_arrow S T`.
Ideally this would be described as a 2-functor from `D`
(promoted to a 2-category with equations as 2-morphisms)
to `Cat`.
-/
@[simps]
def map (f : S ⟶ S') : structured_arrow S' T ⥤ structured_arrow S T :=
comma.map_left _ ((functor.const _).map f)
@[simp] lemma map_mk {f : S' ⟶ T.obj Y} (g : S ⟶ S') :
(map g).obj (mk f) = mk (g ≫ f) := rfl
@[simp] lemma map_id {f : structured_arrow S T} : (map (𝟙 S)).obj f = f :=
by { rw eq_mk f, simp, }
@[simp] lemma map_comp {f : S ⟶ S'} {f' : S' ⟶ S''} {h : structured_arrow S'' T} :
(map (f ≫ f')).obj h = (map f).obj ((map f').obj h) :=
by { rw eq_mk h, simp, }
instance proj_reflects_iso : reflects_isomorphisms (proj S T) :=
{ reflects := λ Y Z f t, by exactI
⟨⟨structured_arrow.hom_mk (inv ((proj S T).map f)) (by simp), by tidy⟩⟩ }
open category_theory.limits
local attribute [tidy] tactic.discrete_cases
/-- The identity structured arrow is initial. -/
def mk_id_initial [full T] [faithful T] : is_initial (mk (𝟙 (T.obj Y))) :=
{ desc := λ c, hom_mk (T.preimage c.X.hom) (by { dsimp, simp, }),
uniq' := λ c m _, begin
ext,
apply T.map_injective,
simpa only [hom_mk_right, T.image_preimage, ←w m] using (category.id_comp _).symm,
end }
variables {A : Type u₃} [category.{v₃} A] {B : Type u₄} [category.{v₄} B]
/-- The functor `(S, F ⋙ G) ⥤ (S, G)`. -/
@[simps]
def pre (S : D) (F : B ⥤ C) (G : C ⥤ D) : structured_arrow S (F ⋙ G) ⥤ structured_arrow S G :=
comma.pre_right _ F G
/-- The functor `(S, F) ⥤ (G(S), F ⋙ G)`. -/
@[simps] def post (S : C) (F : B ⥤ C) (G : C ⥤ D) :
structured_arrow S F ⥤ structured_arrow (G.obj S) (F ⋙ G) :=
{ obj := λ X, { right := X.right, hom := G.map X.hom },
map := λ X Y f, { right := f.right, w' :=
by { simp [functor.comp_map, ←G.map_comp, ← f.w] } } }
end structured_arrow
/--
The category of `S`-costructured arrows with target `T : D` (here `S : C ⥤ D`),
has as its objects `D`-morphisms of the form `S Y ⟶ T`, for some `Y : C`,
and morphisms `C`-morphisms `Y ⟶ Y'` making the obvious triangle commute.
-/
@[derive category, nolint has_nonempty_instance]
def costructured_arrow (S : C ⥤ D) (T : D) := comma S (functor.from_punit T)
namespace costructured_arrow
/-- The obvious projection functor from costructured arrows. -/
@[simps]
def proj (S : C ⥤ D) (T : D) : costructured_arrow S T ⥤ C := comma.fst _ _
variables {T T' T'' : D} {Y Y' : C} {S : C ⥤ D}
/-- Construct a costructured arrow from a morphism. -/
def mk (f : S.obj Y ⟶ T) : costructured_arrow S T := ⟨Y, ⟨⟨⟩⟩, f⟩
@[simp] lemma mk_left (f : S.obj Y ⟶ T) : (mk f).left = Y := rfl
@[simp] lemma mk_right (f : S.obj Y ⟶ T) : (mk f).right = ⟨⟨⟩⟩ := rfl
@[simp] lemma mk_hom_eq_self (f : S.obj Y ⟶ T) : (mk f).hom = f := rfl
@[simp, reassoc] lemma w {A B : costructured_arrow S T} (f : A ⟶ B) :
S.map f.left ≫ B.hom = A.hom :=
by tidy
/--
To construct a morphism of costructured arrows,
we need a morphism of the objects underlying the source,
and to check that the triangle commutes.
-/
@[simps]
def hom_mk {f f' : costructured_arrow S T} (g : f.left ⟶ f'.left) (w : S.map g ≫ f'.hom = f.hom) :
f ⟶ f' :=
{ left := g,
right := eq_to_hom (by ext),
w' := by simpa [eq_to_hom_map] using w, }
/--
To construct an isomorphism of costructured arrows,
we need an isomorphism of the objects underlying the source,
and to check that the triangle commutes.
-/
@[simps]
def iso_mk {f f' : costructured_arrow S T} (g : f.left ≅ f'.left)
(w : S.map g.hom ≫ f'.hom = f.hom) : f ≅ f' :=
comma.iso_mk g (eq_to_iso (by ext)) (by simpa [eq_to_hom_map] using w)
lemma ext {A B : costructured_arrow S T} (f g : A ⟶ B) (h : f.left = g.left) : f = g :=
comma_morphism.ext _ _ h (subsingleton.elim _ _)
lemma ext_iff {A B : costructured_arrow S T} (f g : A ⟶ B) : f = g ↔ f.left = g.left :=
⟨λ h, h ▸ rfl, ext f g⟩
instance proj_faithful : faithful (proj S T) :=
{ map_injective' := λ X Y, ext }
lemma mono_of_mono_left {A B : costructured_arrow S T} (f : A ⟶ B) [h : mono f.left] : mono f :=
(proj S T).mono_of_mono_map h
/-- The converse of this is true with additional assumptions, see `epi_iff_epi_left`. -/
lemma epi_of_epi_left {A B : costructured_arrow S T} (f : A ⟶ B) [h : epi f.left] : epi f :=
(proj S T).epi_of_epi_map h
instance mono_hom_mk {A B : costructured_arrow S T} (f : A.left ⟶ B.left) (w) [h : mono f] :
mono (hom_mk f w) :=
(proj S T).mono_of_mono_map h
instance epi_hom_mk {A B : costructured_arrow S T} (f : A.left ⟶ B.left) (w) [h : epi f] :
epi (hom_mk f w) :=
(proj S T).epi_of_epi_map h
/-- Eta rule for costructured arrows. Prefer `costructured_arrow.eta`, as equality of objects tends
to cause problems. -/
lemma eq_mk (f : costructured_arrow S T) : f = mk f.hom :=
by { cases f, congr, ext, }
/-- Eta rule for costructured arrows. -/
@[simps]
def eta (f : costructured_arrow S T) : f ≅ mk f.hom :=
iso_mk (iso.refl _) (by tidy)
/--
A morphism between target objects `T ⟶ T'`
covariantly induces a functor between costructured arrows,
`costructured_arrow S T ⥤ costructured_arrow S T'`.
Ideally this would be described as a 2-functor from `D`
(promoted to a 2-category with equations as 2-morphisms)
to `Cat`.
-/
@[simps]
def map (f : T ⟶ T') : costructured_arrow S T ⥤ costructured_arrow S T' :=
comma.map_right _ ((functor.const _).map f)
@[simp] lemma map_mk {f : S.obj Y ⟶ T} (g : T ⟶ T') :
(map g).obj (mk f) = mk (f ≫ g) := rfl
@[simp] lemma map_id {f : costructured_arrow S T} : (map (𝟙 T)).obj f = f :=
by { rw eq_mk f, simp, }
@[simp] lemma map_comp {f : T ⟶ T'} {f' : T' ⟶ T''} {h : costructured_arrow S T} :
(map (f ≫ f')).obj h = (map f').obj ((map f).obj h) :=
by { rw eq_mk h, simp, }
instance proj_reflects_iso : reflects_isomorphisms (proj S T) :=
{ reflects := λ Y Z f t, by exactI
⟨⟨costructured_arrow.hom_mk (inv ((proj S T).map f)) (by simp), by tidy⟩⟩ }
open category_theory.limits
local attribute [tidy] tactic.discrete_cases
/-- The identity costructured arrow is terminal. -/
def mk_id_terminal [full S] [faithful S] : is_terminal (mk (𝟙 (S.obj Y))) :=
{ lift := λ c, hom_mk (S.preimage c.X.hom) (by { dsimp, simp, }),
uniq' := begin
rintros c m -,
ext,
apply S.map_injective,
simpa only [hom_mk_left, S.image_preimage, ←w m] using (category.comp_id _).symm,
end }
variables {A : Type u₃} [category.{v₃} A] {B : Type u₄} [category.{v₄} B]
/-- The functor `(F ⋙ G, S) ⥤ (G, S)`. -/
@[simps]
def pre (F : B ⥤ C) (G : C ⥤ D) (S : D) : costructured_arrow (F ⋙ G) S ⥤ costructured_arrow G S :=
comma.pre_left F G _
/-- The functor `(F, S) ⥤ (F ⋙ G, G(S))`. -/
@[simps] def post (F : B ⥤ C) (G : C ⥤ D) (S : C) :
costructured_arrow F S ⥤ costructured_arrow (F ⋙ G) (G.obj S) :=
{ obj := λ X, { left := X.left, hom := G.map X.hom },
map := λ X Y f, { left := f.left, w' :=
by { simp [functor.comp_map, ←G.map_comp, ← f.w] } } }
end costructured_arrow
open opposite
namespace structured_arrow
/--
For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the
category of structured arrows `d ⟶ F.obj c` to the category of costructured arrows
`F.op.obj c ⟶ (op d)`.
-/
@[simps]
def to_costructured_arrow (F : C ⥤ D) (d : D) :
(structured_arrow d F)ᵒᵖ ⥤ costructured_arrow F.op (op d) :=
{ obj := λ X, @costructured_arrow.mk _ _ _ _ _ (op X.unop.right) F.op X.unop.hom.op,
map := λ X Y f, costructured_arrow.hom_mk (f.unop.right.op)
begin
dsimp,
rw [← op_comp, ← f.unop.w, functor.const_obj_map],
erw category.id_comp,
end }
/--
For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the
category of structured arrows `op d ⟶ F.op.obj c` to the category of costructured arrows
`F.obj c ⟶ d`.
-/
@[simps]
def to_costructured_arrow' (F : C ⥤ D) (d : D) :
(structured_arrow (op d) F.op)ᵒᵖ ⥤ costructured_arrow F d :=
{ obj := λ X, @costructured_arrow.mk _ _ _ _ _ (unop X.unop.right) F X.unop.hom.unop,
map := λ X Y f, costructured_arrow.hom_mk f.unop.right.unop
begin
dsimp,
rw [← quiver.hom.unop_op (F.map (quiver.hom.unop f.unop.right)), ← unop_comp, ← F.op_map,
← f.unop.w, functor.const_obj_map],
erw category.id_comp,
end }
end structured_arrow
namespace costructured_arrow
/--
For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the
category of costructured arrows `F.obj c ⟶ d` to the category of structured arrows
`op d ⟶ F.op.obj c`.
-/
@[simps]
def to_structured_arrow (F : C ⥤ D) (d : D) :
(costructured_arrow F d)ᵒᵖ ⥤ structured_arrow (op d) F.op :=
{ obj := λ X, @structured_arrow.mk _ _ _ _ _ (op X.unop.left) F.op X.unop.hom.op,
map := λ X Y f, structured_arrow.hom_mk f.unop.left.op
begin
dsimp,
rw [← op_comp, f.unop.w, functor.const_obj_map],
erw category.comp_id,
end }
/--
For a functor `F : C ⥤ D` and an object `d : D`, we obtain a contravariant functor from the
category of costructured arrows `F.op.obj c ⟶ op d` to the category of structured arrows
`d ⟶ F.obj c`.
-/
@[simps]
def to_structured_arrow' (F : C ⥤ D) (d : D) :
(costructured_arrow F.op (op d))ᵒᵖ ⥤ structured_arrow d F :=
{ obj := λ X, @structured_arrow.mk _ _ _ _ _ (unop X.unop.left) F X.unop.hom.unop,
map := λ X Y f, structured_arrow.hom_mk (f.unop.left.unop)
begin
dsimp,
rw [← quiver.hom.unop_op (F.map f.unop.left.unop), ← unop_comp, ← F.op_map,
f.unop.w, functor.const_obj_map],
erw category.comp_id,
end }
end costructured_arrow
/--
For a functor `F : C ⥤ D` and an object `d : D`, the category of structured arrows `d ⟶ F.obj c`
is contravariantly equivalent to the category of costructured arrows `F.op.obj c ⟶ op d`.
-/
def structured_arrow_op_equivalence (F : C ⥤ D) (d : D) :
(structured_arrow d F)ᵒᵖ ≌ costructured_arrow F.op (op d) :=
equivalence.mk (structured_arrow.to_costructured_arrow F d)
(costructured_arrow.to_structured_arrow' F d).right_op
(nat_iso.of_components (λ X, (@structured_arrow.iso_mk _ _ _ _ _ _
(structured_arrow.mk (unop X).hom) (unop X) (iso.refl _) (by tidy)).op)
(λ X Y f, quiver.hom.unop_inj $ begin ext, dsimp, simp end))
(nat_iso.of_components (λ X, @costructured_arrow.iso_mk _ _ _ _ _ _
(costructured_arrow.mk X.hom) X (iso.refl _) (by tidy))
(λ X Y f, begin ext, dsimp, simp end))
/--
For a functor `F : C ⥤ D` and an object `d : D`, the category of costructured arrows
`F.obj c ⟶ d` is contravariantly equivalent to the category of structured arrows
`op d ⟶ F.op.obj c`.
-/
def costructured_arrow_op_equivalence (F : C ⥤ D) (d : D) :
(costructured_arrow F d)ᵒᵖ ≌ structured_arrow (op d) F.op :=
equivalence.mk (costructured_arrow.to_structured_arrow F d)
(structured_arrow.to_costructured_arrow' F d).right_op
(nat_iso.of_components (λ X, (@costructured_arrow.iso_mk _ _ _ _ _ _
(costructured_arrow.mk (unop X).hom) (unop X) (iso.refl _) (by tidy)).op)
(λ X Y f, quiver.hom.unop_inj $ begin ext, dsimp, simp end))
(nat_iso.of_components (λ X, @structured_arrow.iso_mk _ _ _ _ _ _
(structured_arrow.mk X.hom) X (iso.refl _) (by tidy))
(λ X Y f, begin ext, dsimp, simp end))
end category_theory
|
ae8258de1315626655e3180dfade909bb6ca7ecd | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/error_pos_bug.lean | 46511afd7df58a0736b4f37728d269d891c1258c | [
"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 | 313 | lean | inductive category (ob : Type) : Type :=
mk : Π (hom : ob → ob → Type)
(comp : Π⦃a b c : ob⦄, hom b c → hom a b → hom a c),
category ob
inductive Category : Type := mk : Π (ob : Type), category ob → Category
definition MK (a b c : Category) : _ :=
Category.mk a (category.mk b c)
|
e96a41983fdc90a1a3d3ddb49437a5ec497853f7 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/limits/has_limits.lean | 37f6c18894d68d3a70c4aac5b1b3272e8568b26c | [
"Apache-2.0"
] | permissive | urkud/mathlib | eab80095e1b9f1513bfb7f25b4fa82fa4fd02989 | 6379d39e6b5b279df9715f8011369a301b634e41 | refs/heads/master | 1,658,425,342,662 | 1,658,078,703,000 | 1,658,078,703,000 | 186,910,338 | 0 | 0 | Apache-2.0 | 1,568,512,083,000 | 1,557,958,709,000 | Lean | UTF-8 | Lean | false | false | 43,178 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Mario Carneiro, Scott Morrison, Floris van Doorn
-/
import category_theory.limits.is_limit
import category_theory.category.ulift
/-!
# Existence of limits and colimits
In `category_theory.limits.is_limit` we defined `is_limit c`,
the data showing that a cone `c` is a limit cone.
The two main structures defined in this file are:
* `limit_cone F`, which consists of a choice of cone for `F` and the fact it is a limit cone, and
* `has_limit F`, asserting the mere existence of some limit cone for `F`.
`has_limit` is a propositional typeclass
(it's important that it is a proposition merely asserting the existence of a limit,
as otherwise we would have non-defeq problems from incompatible instances).
While `has_limit` only asserts the existence of a limit cone,
we happily use the axiom of choice in mathlib,
so there are convenience functions all depending on `has_limit F`:
* `limit F : C`, producing some limit object (of course all such are isomorphic)
* `limit.π F j : limit F ⟶ F.obj j`, the morphisms out of the limit,
* `limit.lift F c : c.X ⟶ limit F`, the universal morphism from any other `c : cone F`, etc.
Key to using the `has_limit` interface is that there is an `@[ext]` lemma stating that
to check `f = g`, for `f g : Z ⟶ limit F`, it suffices to check `f ≫ limit.π F j = g ≫ limit.π F j`
for every `j`.
This, combined with `@[simp]` lemmas, makes it possible to prove many easy facts about limits using
automation (e.g. `tidy`).
There are abbreviations `has_limits_of_shape J C` and `has_limits C`
asserting the existence of classes of limits.
Later more are introduced, for finite limits, special shapes of limits, etc.
Ideally, many results about limits should be stated first in terms of `is_limit`,
and then a result in terms of `has_limit` derived from this.
At this point, however, this is far from uniformly achieved in mathlib ---
often statements are only written in terms of `has_limit`.
## Implementation
At present we simply say everything twice, in order to handle both limits and colimits.
It would be highly desirable to have some automation support,
e.g. a `@[dualize]` attribute that behaves similarly to `@[to_additive]`.
## References
* [Stacks: Limits and colimits](https://stacks.math.columbia.edu/tag/002D)
-/
noncomputable theory
open category_theory category_theory.category category_theory.functor opposite
namespace category_theory.limits
-- morphism levels before object levels. See note [category_theory universes].
universes v₁ u₁ v₂ u₂ v₃ u₃ v v' v'' u u' u''
variables {J : Type u₁} [category.{v₁} J] {K : Type u₂} [category.{v₂} K]
variables {C : Type u} [category.{v} C]
variables {F : J ⥤ C}
section limit
/-- `limit_cone F` contains a cone over `F` together with the information that it is a limit. -/
@[nolint has_inhabited_instance]
structure limit_cone (F : J ⥤ C) :=
(cone : cone F)
(is_limit : is_limit cone)
/-- `has_limit F` represents the mere existence of a limit for `F`. -/
class has_limit (F : J ⥤ C) : Prop :=
mk' :: (exists_limit : nonempty (limit_cone F))
lemma has_limit.mk {F : J ⥤ C} (d : limit_cone F) : has_limit F :=
⟨nonempty.intro d⟩
/-- Use the axiom of choice to extract explicit `limit_cone F` from `has_limit F`. -/
def get_limit_cone (F : J ⥤ C) [has_limit F] : limit_cone F :=
classical.choice $ has_limit.exists_limit
variables (J C)
/-- `C` has limits of shape `J` if there exists a limit for every functor `F : J ⥤ C`. -/
class has_limits_of_shape : Prop :=
(has_limit : Π F : J ⥤ C, has_limit F . tactic.apply_instance)
/--
`C` has all limits of size `v₁ u₁` (`has_limits_of_size.{v₁ u₁} C`)
if it has limits of every shape `J : Type u₁` with `[category.{v₁} J]`.
-/
class has_limits_of_size (C : Type u) [category.{v} C] : Prop :=
(has_limits_of_shape :
Π (J : Type u₁) [𝒥 : category.{v₁} J], has_limits_of_shape J C . tactic.apply_instance)
/-- `C` has all (small) limits if it has limits of every shape that is as big as its hom-sets. -/
abbreviation has_limits (C : Type u) [category.{v} C] : Prop := has_limits_of_size.{v v} C
lemma has_limits.has_limits_of_shape {C : Type u} [category.{v} C] [has_limits C]
(J : Type v) [category.{v} J] :
has_limits_of_shape J C := has_limits_of_size.has_limits_of_shape J
variables {J C}
@[priority 100] -- see Note [lower instance priority]
instance has_limit_of_has_limits_of_shape
{J : Type u₁} [category.{v₁} J] [H : has_limits_of_shape J C] (F : J ⥤ C) : has_limit F :=
has_limits_of_shape.has_limit F
@[priority 100] -- see Note [lower instance priority]
instance has_limits_of_shape_of_has_limits
{J : Type u₁} [category.{v₁} J] [H : has_limits_of_size.{v₁ u₁} C] : has_limits_of_shape J C :=
has_limits_of_size.has_limits_of_shape J
/- Interface to the `has_limit` class. -/
/-- An arbitrary choice of limit cone for a functor. -/
def limit.cone (F : J ⥤ C) [has_limit F] : cone F := (get_limit_cone F).cone
/-- An arbitrary choice of limit object of a functor. -/
def limit (F : J ⥤ C) [has_limit F] := (limit.cone F).X
/-- The projection from the limit object to a value of the functor. -/
def limit.π (F : J ⥤ C) [has_limit F] (j : J) : limit F ⟶ F.obj j :=
(limit.cone F).π.app j
@[simp] lemma limit.cone_X {F : J ⥤ C} [has_limit F] :
(limit.cone F).X = limit F := rfl
@[simp] lemma limit.cone_π {F : J ⥤ C} [has_limit F] :
(limit.cone F).π.app = limit.π _ := rfl
@[simp, reassoc] lemma limit.w (F : J ⥤ C) [has_limit F] {j j' : J} (f : j ⟶ j') :
limit.π F j ≫ F.map f = limit.π F j' := (limit.cone F).w f
/-- Evidence that the arbitrary choice of cone provied by `limit.cone F` is a limit cone. -/
def limit.is_limit (F : J ⥤ C) [has_limit F] : is_limit (limit.cone F) :=
(get_limit_cone F).is_limit
/-- The morphism from the cone point of any other cone to the limit object. -/
def limit.lift (F : J ⥤ C) [has_limit F] (c : cone F) : c.X ⟶ limit F :=
(limit.is_limit F).lift c
@[simp] lemma limit.is_limit_lift {F : J ⥤ C} [has_limit F] (c : cone F) :
(limit.is_limit F).lift c = limit.lift F c := rfl
@[simp, reassoc] lemma limit.lift_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) :
limit.lift F c ≫ limit.π F j = c.π.app j :=
is_limit.fac _ c j
/--
Functoriality of limits.
Usually this morphism should be accessed through `lim.map`,
but may be needed separately when you have specified limits for the source and target functors,
but not necessarily for all functors of shape `J`.
-/
def lim_map {F G : J ⥤ C} [has_limit F] [has_limit G] (α : F ⟶ G) : limit F ⟶ limit G :=
is_limit.map _ (limit.is_limit G) α
@[simp, reassoc] lemma lim_map_π {F G : J ⥤ C} [has_limit F] [has_limit G] (α : F ⟶ G) (j : J) :
lim_map α ≫ limit.π G j = limit.π F j ≫ α.app j :=
limit.lift_π _ j
/-- The cone morphism from any cone to the arbitrary choice of limit cone. -/
def limit.cone_morphism {F : J ⥤ C} [has_limit F] (c : cone F) :
c ⟶ limit.cone F :=
(limit.is_limit F).lift_cone_morphism c
@[simp] lemma limit.cone_morphism_hom {F : J ⥤ C} [has_limit F] (c : cone F) :
(limit.cone_morphism c).hom = limit.lift F c := rfl
lemma limit.cone_morphism_π {F : J ⥤ C} [has_limit F] (c : cone F) (j : J) :
(limit.cone_morphism c).hom ≫ limit.π F j = c.π.app j :=
by simp
@[simp, reassoc] lemma limit.cone_point_unique_up_to_iso_hom_comp {F : J ⥤ C} [has_limit F]
{c : cone F} (hc : is_limit c) (j : J) :
(is_limit.cone_point_unique_up_to_iso hc (limit.is_limit _)).hom ≫ limit.π F j = c.π.app j :=
is_limit.cone_point_unique_up_to_iso_hom_comp _ _ _
@[simp, reassoc] lemma limit.cone_point_unique_up_to_iso_inv_comp {F : J ⥤ C} [has_limit F]
{c : cone F} (hc : is_limit c) (j : J) :
(is_limit.cone_point_unique_up_to_iso (limit.is_limit _) hc).inv ≫ limit.π F j = c.π.app j :=
is_limit.cone_point_unique_up_to_iso_inv_comp _ _ _
lemma limit.exists_unique {F : J ⥤ C} [has_limit F] (t : cone F) :
∃! (l : t.X ⟶ limit F), ∀ j, l ≫ limit.π F j = t.π.app j :=
(limit.is_limit F).exists_unique _
/--
Given any other limit cone for `F`, the chosen `limit F` is isomorphic to the cone point.
-/
def limit.iso_limit_cone {F : J ⥤ C} [has_limit F] (t : limit_cone F) :
limit F ≅ t.cone.X :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit F) t.is_limit
@[simp, reassoc] lemma limit.iso_limit_cone_hom_π
{F : J ⥤ C} [has_limit F] (t : limit_cone F) (j : J) :
(limit.iso_limit_cone t).hom ≫ t.cone.π.app j = limit.π F j :=
by { dsimp [limit.iso_limit_cone, is_limit.cone_point_unique_up_to_iso], tidy, }
@[simp, reassoc] lemma limit.iso_limit_cone_inv_π
{F : J ⥤ C} [has_limit F] (t : limit_cone F) (j : J) :
(limit.iso_limit_cone t).inv ≫ limit.π F j = t.cone.π.app j :=
by { dsimp [limit.iso_limit_cone, is_limit.cone_point_unique_up_to_iso], tidy, }
@[ext] lemma limit.hom_ext {F : J ⥤ C} [has_limit F] {X : C} {f f' : X ⟶ limit F}
(w : ∀ j, f ≫ limit.π F j = f' ≫ limit.π F j) : f = f' :=
(limit.is_limit F).hom_ext w
@[simp] lemma limit.lift_map {F G : J ⥤ C} [has_limit F] [has_limit G] (c : cone F) (α : F ⟶ G) :
limit.lift F c ≫ lim_map α = limit.lift G ((cones.postcompose α).obj c) :=
by { ext, rw [assoc, lim_map_π, limit.lift_π_assoc, limit.lift_π], refl }
@[simp] lemma limit.lift_cone {F : J ⥤ C} [has_limit F] :
limit.lift F (limit.cone F) = 𝟙 (limit F) :=
(limit.is_limit _).lift_self
/--
The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and cones with cone point `W`.
-/
def limit.hom_iso (F : J ⥤ C) [has_limit F] (W : C) :
ulift.{u₁} (W ⟶ limit F : Type v) ≅ (F.cones.obj (op W)) :=
(limit.is_limit F).hom_iso W
@[simp] lemma limit.hom_iso_hom (F : J ⥤ C) [has_limit F] {W : C} (f : ulift (W ⟶ limit F)) :
(limit.hom_iso F W).hom f = (const J).map f.down ≫ (limit.cone F).π :=
(limit.is_limit F).hom_iso_hom f
/--
The isomorphism (in `Type`) between
morphisms from a specified object `W` to the limit object,
and an explicit componentwise description of cones with cone point `W`.
-/
def limit.hom_iso' (F : J ⥤ C) [has_limit F] (W : C) :
ulift.{u₁} ((W ⟶ limit F) : Type v) ≅
{ p : Π j, W ⟶ F.obj j // ∀ {j j' : J} (f : j ⟶ j'), p j ≫ F.map f = p j' } :=
(limit.is_limit F).hom_iso' W
lemma limit.lift_extend {F : J ⥤ C} [has_limit F] (c : cone F) {X : C} (f : X ⟶ c.X) :
limit.lift F (c.extend f) = f ≫ limit.lift F c :=
by obviously
/--
If a functor `F` has a limit, so does any naturally isomorphic functor.
-/
lemma has_limit_of_iso {F G : J ⥤ C} [has_limit F] (α : F ≅ G) : has_limit G :=
has_limit.mk
{ cone := (cones.postcompose α.hom).obj (limit.cone F),
is_limit :=
{ lift := λ s, limit.lift F ((cones.postcompose α.inv).obj s),
fac' := λ s j,
begin
rw [cones.postcompose_obj_π, nat_trans.comp_app, limit.cone_π, ←category.assoc, limit.lift_π],
simp
end,
uniq' := λ s m w,
begin
apply limit.hom_ext, intro j,
rw [limit.lift_π, cones.postcompose_obj_π, nat_trans.comp_app, ←nat_iso.app_inv,
iso.eq_comp_inv],
simpa using w j
end } }
/-- If a functor `G` has the same collection of cones as a functor `F`
which has a limit, then `G` also has a limit. -/
-- See the construction of limits from products and equalizers
-- for an example usage.
lemma has_limit.of_cones_iso {J K : Type u₁} [category.{v₁} J] [category.{v₂} K] (F : J ⥤ C)
(G : K ⥤ C) (h : F.cones ≅ G.cones) [has_limit F] : has_limit G :=
has_limit.mk ⟨_, is_limit.of_nat_iso ((is_limit.nat_iso (limit.is_limit F)) ≪≫ h)⟩
/--
The limits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic,
if the functors are naturally isomorphic.
-/
def has_limit.iso_of_nat_iso {F G : J ⥤ C} [has_limit F] [has_limit G] (w : F ≅ G) :
limit F ≅ limit G :=
is_limit.cone_points_iso_of_nat_iso (limit.is_limit F) (limit.is_limit G) w
@[simp, reassoc]
lemma has_limit.iso_of_nat_iso_hom_π {F G : J ⥤ C} [has_limit F] [has_limit G]
(w : F ≅ G) (j : J) :
(has_limit.iso_of_nat_iso w).hom ≫ limit.π G j = limit.π F j ≫ w.hom.app j :=
is_limit.cone_points_iso_of_nat_iso_hom_comp _ _ _ _
@[simp, reassoc]
lemma has_limit.iso_of_nat_iso_inv_π {F G : J ⥤ C} [has_limit F] [has_limit G]
(w : F ≅ G) (j : J) :
(has_limit.iso_of_nat_iso w).inv ≫ limit.π F j = limit.π G j ≫ w.inv.app j :=
is_limit.cone_points_iso_of_nat_iso_inv_comp _ _ _ _
@[simp, reassoc]
lemma has_limit.lift_iso_of_nat_iso_hom {F G : J ⥤ C} [has_limit F] [has_limit G] (t : cone F)
(w : F ≅ G) :
limit.lift F t ≫ (has_limit.iso_of_nat_iso w).hom =
limit.lift G ((cones.postcompose w.hom).obj _) :=
is_limit.lift_comp_cone_points_iso_of_nat_iso_hom _ _ _
@[simp, reassoc]
lemma has_limit.lift_iso_of_nat_iso_inv {F G : J ⥤ C} [has_limit F] [has_limit G] (t : cone G)
(w : F ≅ G) :
limit.lift G t ≫ (has_limit.iso_of_nat_iso w).inv =
limit.lift F ((cones.postcompose w.inv).obj _) :=
is_limit.lift_comp_cone_points_iso_of_nat_iso_inv _ _ _
/--
The limits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic,
if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism.
-/
def has_limit.iso_of_equivalence {F : J ⥤ C} [has_limit F] {G : K ⥤ C} [has_limit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) : limit F ≅ limit G :=
is_limit.cone_points_iso_of_equivalence (limit.is_limit F) (limit.is_limit G) e w
@[simp]
lemma has_limit.iso_of_equivalence_hom_π {F : J ⥤ C} [has_limit F] {G : K ⥤ C} [has_limit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) :
(has_limit.iso_of_equivalence e w).hom ≫ limit.π G k =
limit.π F (e.inverse.obj k) ≫ w.inv.app (e.inverse.obj k) ≫ G.map (e.counit.app k) :=
begin
simp only [has_limit.iso_of_equivalence, is_limit.cone_points_iso_of_equivalence_hom],
dsimp,
simp,
end
@[simp]
lemma has_limit.iso_of_equivalence_inv_π {F : J ⥤ C} [has_limit F] {G : K ⥤ C} [has_limit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) :
(has_limit.iso_of_equivalence e w).inv ≫ limit.π F j =
limit.π G (e.functor.obj j) ≫ w.hom.app j :=
begin
simp only [has_limit.iso_of_equivalence, is_limit.cone_points_iso_of_equivalence_hom],
dsimp,
simp,
end
section pre
variables (F) [has_limit F] (E : K ⥤ J) [has_limit (E ⋙ F)]
/--
The canonical morphism from the limit of `F` to the limit of `E ⋙ F`.
-/
def limit.pre : limit F ⟶ limit (E ⋙ F) :=
limit.lift (E ⋙ F) ((limit.cone F).whisker E)
@[simp, reassoc] lemma limit.pre_π (k : K) :
limit.pre F E ≫ limit.π (E ⋙ F) k = limit.π F (E.obj k) :=
by { erw is_limit.fac, refl }
@[simp] lemma limit.lift_pre (c : cone F) :
limit.lift F c ≫ limit.pre F E = limit.lift (E ⋙ F) (c.whisker E) :=
by ext; simp
variables {L : Type u₃} [category.{v₃} L]
variables (D : L ⥤ K) [has_limit (D ⋙ E ⋙ F)]
@[simp] lemma limit.pre_pre : limit.pre F E ≫ limit.pre (E ⋙ F) D = limit.pre F (D ⋙ E) :=
by ext j; erw [assoc, limit.pre_π, limit.pre_π, limit.pre_π]; refl
variables {E F}
/---
If we have particular limit cones available for `E ⋙ F` and for `F`,
we obtain a formula for `limit.pre F E`.
-/
lemma limit.pre_eq (s : limit_cone (E ⋙ F)) (t : limit_cone F) :
limit.pre F E =
(limit.iso_limit_cone t).hom ≫ s.is_limit.lift ((t.cone).whisker E) ≫
(limit.iso_limit_cone s).inv :=
by tidy
end pre
section post
variables {D : Type u'} [category.{v'} D]
variables (F) [has_limit F] (G : C ⥤ D) [has_limit (F ⋙ G)]
/--
The canonical morphism from `G` applied to the limit of `F` to the limit of `F ⋙ G`.
-/
def limit.post : G.obj (limit F) ⟶ limit (F ⋙ G) :=
limit.lift (F ⋙ G) (G.map_cone (limit.cone F))
@[simp, reassoc] lemma limit.post_π (j : J) :
limit.post F G ≫ limit.π (F ⋙ G) j = G.map (limit.π F j) :=
by { erw is_limit.fac, refl }
@[simp] lemma limit.lift_post (c : cone F) :
G.map (limit.lift F c) ≫ limit.post F G = limit.lift (F ⋙ G) (G.map_cone c) :=
by { ext, rw [assoc, limit.post_π, ←G.map_comp, limit.lift_π, limit.lift_π], refl }
@[simp] lemma limit.post_post
{E : Type u''} [category.{v''} E] (H : D ⥤ E) [has_limit ((F ⋙ G) ⋙ H)] :
/- H G (limit F) ⟶ H (limit (F ⋙ G)) ⟶ limit ((F ⋙ G) ⋙ H) equals -/
/- H G (limit F) ⟶ limit (F ⋙ (G ⋙ H)) -/
H.map (limit.post F G) ≫ limit.post (F ⋙ G) H = limit.post F (G ⋙ H) :=
by ext; erw [assoc, limit.post_π, ←H.map_comp, limit.post_π, limit.post_π]; refl
end post
lemma limit.pre_post {D : Type u'} [category.{v'} D]
(E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D)
[has_limit F] [has_limit (E ⋙ F)] [has_limit (F ⋙ G)] [has_limit ((E ⋙ F) ⋙ G)] :
/- G (limit F) ⟶ G (limit (E ⋙ F)) ⟶ limit ((E ⋙ F) ⋙ G) vs -/
/- G (limit F) ⟶ limit F ⋙ G ⟶ limit (E ⋙ (F ⋙ G)) or -/
G.map (limit.pre F E) ≫ limit.post (E ⋙ F) G = limit.post F G ≫ limit.pre (F ⋙ G) E :=
by ext; erw [assoc, limit.post_π, ←G.map_comp, limit.pre_π, assoc, limit.pre_π, limit.post_π]; refl
open category_theory.equivalence
instance has_limit_equivalence_comp (e : K ≌ J) [has_limit F] : has_limit (e.functor ⋙ F) :=
has_limit.mk { cone := cone.whisker e.functor (limit.cone F),
is_limit := is_limit.whisker_equivalence (limit.is_limit F) e, }
local attribute [elab_simple] inv_fun_id_assoc -- not entirely sure why this is needed
/--
If a `E ⋙ F` has a limit, and `E` is an equivalence, we can construct a limit of `F`.
-/
lemma has_limit_of_equivalence_comp (e : K ≌ J) [has_limit (e.functor ⋙ F)] : has_limit F :=
begin
haveI : has_limit (e.inverse ⋙ e.functor ⋙ F) := limits.has_limit_equivalence_comp e.symm,
apply has_limit_of_iso (e.inv_fun_id_assoc F),
end
-- `has_limit_comp_equivalence` and `has_limit_of_comp_equivalence`
-- are proved in `category_theory/adjunction/limits.lean`.
section lim_functor
variables [has_limits_of_shape J C]
section
/-- `limit F` is functorial in `F`, when `C` has all limits of shape `J`. -/
@[simps obj]
def lim : (J ⥤ C) ⥤ C :=
{ obj := λ F, limit F,
map := λ F G α, lim_map α,
map_id' := λ F, by { ext, erw [lim_map_π, category.id_comp, category.comp_id] },
map_comp' := λ F G H α β,
by ext; erw [assoc, is_limit.fac, is_limit.fac, ←assoc, is_limit.fac, assoc]; refl }
end
variables {F} {G : J ⥤ C} (α : F ⟶ G)
-- We generate this manually since `simps` gives it a weird name.
@[simp] lemma lim_map_eq_lim_map : lim.map α = lim_map α := rfl
lemma limit.map_pre [has_limits_of_shape K C] (E : K ⥤ J) :
lim.map α ≫ limit.pre G E = limit.pre F E ≫ lim.map (whisker_left E α) :=
by { ext, simp }
lemma limit.map_pre' [has_limits_of_shape K C]
(F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) :
limit.pre F E₂ = limit.pre F E₁ ≫ lim.map (whisker_right α F) :=
by ext1; simp [← category.assoc]
lemma limit.id_pre (F : J ⥤ C) :
limit.pre F (𝟭 _) = lim.map (functor.left_unitor F).inv := by tidy
lemma limit.map_post {D : Type u'} [category.{v'} D] [has_limits_of_shape J D] (H : C ⥤ D) :
/- H (limit F) ⟶ H (limit G) ⟶ limit (G ⋙ H) vs
H (limit F) ⟶ limit (F ⋙ H) ⟶ limit (G ⋙ H) -/
H.map (lim_map α) ≫ limit.post G H = limit.post F H ≫ lim_map (whisker_right α H) :=
begin
ext,
simp only [whisker_right_app, lim_map_π, assoc, limit.post_π_assoc, limit.post_π, ← H.map_comp],
end
/--
The isomorphism between
morphisms from `W` to the cone point of the limit cone for `F`
and cones over `F` with cone point `W`
is natural in `F`.
-/
def lim_yoneda : lim ⋙ yoneda ⋙ (whiskering_right _ _ _).obj ulift_functor.{u₁}
≅ category_theory.cones J C :=
nat_iso.of_components (λ F, nat_iso.of_components (λ W, limit.hom_iso F (unop W)) (by tidy))
(by tidy)
end lim_functor
/--
We can transport limits of shape `J` along an equivalence `J ≌ J'`.
-/
lemma has_limits_of_shape_of_equivalence {J' : Type u₂} [category.{v₂} J']
(e : J ≌ J') [has_limits_of_shape J C] : has_limits_of_shape J' C :=
by { constructor, intro F, apply has_limit_of_equivalence_comp e, apply_instance }
variable (C)
/--
`has_limits_of_size_shrink.{v u} C` tries to obtain `has_limits_of_size.{v u} C`
from some other `has_limits_of_size C`.
-/
lemma has_limits_of_size_shrink [has_limits_of_size.{(max v₁ v₂) (max u₁ u₂)} C] :
has_limits_of_size.{v₁ u₁} C :=
⟨λ J hJ, by exactI has_limits_of_shape_of_equivalence
(ulift_hom_ulift_category.equiv.{v₂ u₂} J).symm⟩
@[priority 100]
instance has_smallest_limits_of_has_limits [has_limits C] :
has_limits_of_size.{0 0} C := has_limits_of_size_shrink.{0 0} C
end limit
section colimit
/-- `colimit_cocone F` contains a cocone over `F` together with the information that it is a
colimit. -/
@[nolint has_inhabited_instance]
structure colimit_cocone (F : J ⥤ C) :=
(cocone : cocone F)
(is_colimit : is_colimit cocone)
/-- `has_colimit F` represents the mere existence of a colimit for `F`. -/
class has_colimit (F : J ⥤ C) : Prop :=
mk' :: (exists_colimit : nonempty (colimit_cocone F))
lemma has_colimit.mk {F : J ⥤ C} (d : colimit_cocone F) : has_colimit F :=
⟨nonempty.intro d⟩
/-- Use the axiom of choice to extract explicit `colimit_cocone F` from `has_colimit F`. -/
def get_colimit_cocone (F : J ⥤ C) [has_colimit F] : colimit_cocone F :=
classical.choice $ has_colimit.exists_colimit
variables (J C)
/-- `C` has colimits of shape `J` if there exists a colimit for every functor `F : J ⥤ C`. -/
class has_colimits_of_shape : Prop :=
(has_colimit : Π F : J ⥤ C, has_colimit F . tactic.apply_instance)
/--
`C` has all colimits of size `v₁ u₁` (`has_colimits_of_size.{v₁ u₁} C`)
if it has colimits of every shape `J : Type u₁` with `[category.{v₁} J]`.
-/
class has_colimits_of_size (C : Type u) [category.{v} C] : Prop :=
(has_colimits_of_shape :
Π (J : Type u₁) [𝒥 : category.{v₁} J], has_colimits_of_shape J C . tactic.apply_instance)
/--
`C` has all (small) colimits if it has colimits of every shape that is as big as its hom-sets.
-/
abbreviation has_colimits (C : Type u) [category.{v} C] : Prop := has_colimits_of_size.{v v} C
lemma has_colimits.has_colimits_of_shape {C : Type u} [category.{v} C] [has_colimits C]
(J : Type v) [category.{v} J] :
has_colimits_of_shape J C := has_colimits_of_size.has_colimits_of_shape J
variables {J C}
@[priority 100] -- see Note [lower instance priority]
instance has_colimit_of_has_colimits_of_shape
{J : Type u₁} [category.{v₁} J] [H : has_colimits_of_shape J C] (F : J ⥤ C) : has_colimit F :=
has_colimits_of_shape.has_colimit F
@[priority 100] -- see Note [lower instance priority]
instance has_colimits_of_shape_of_has_colimits_of_size {J : Type u₁} [category.{v₁} J]
[H : has_colimits_of_size.{v₁ u₁} C] : has_colimits_of_shape J C :=
has_colimits_of_size.has_colimits_of_shape J
/- Interface to the `has_colimit` class. -/
/-- An arbitrary choice of colimit cocone of a functor. -/
def colimit.cocone (F : J ⥤ C) [has_colimit F] : cocone F := (get_colimit_cocone F).cocone
/-- An arbitrary choice of colimit object of a functor. -/
def colimit (F : J ⥤ C) [has_colimit F] := (colimit.cocone F).X
/-- The coprojection from a value of the functor to the colimit object. -/
def colimit.ι (F : J ⥤ C) [has_colimit F] (j : J) : F.obj j ⟶ colimit F :=
(colimit.cocone F).ι.app j
@[simp] lemma colimit.cocone_ι {F : J ⥤ C} [has_colimit F] (j : J) :
(colimit.cocone F).ι.app j = colimit.ι _ j := rfl
@[simp] lemma colimit.cocone_X {F : J ⥤ C} [has_colimit F] :
(colimit.cocone F).X = colimit F := rfl
@[simp, reassoc] lemma colimit.w (F : J ⥤ C) [has_colimit F] {j j' : J} (f : j ⟶ j') :
F.map f ≫ colimit.ι F j' = colimit.ι F j := (colimit.cocone F).w f
/-- Evidence that the arbitrary choice of cocone is a colimit cocone. -/
def colimit.is_colimit (F : J ⥤ C) [has_colimit F] : is_colimit (colimit.cocone F) :=
(get_colimit_cocone F).is_colimit
/-- The morphism from the colimit object to the cone point of any other cocone. -/
def colimit.desc (F : J ⥤ C) [has_colimit F] (c : cocone F) : colimit F ⟶ c.X :=
(colimit.is_colimit F).desc c
@[simp] lemma colimit.is_colimit_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) :
(colimit.is_colimit F).desc c = colimit.desc F c := rfl
/--
We have lots of lemmas describing how to simplify `colimit.ι F j ≫ _`,
and combined with `colimit.ext` we rely on these lemmas for many calculations.
However, since `category.assoc` is a `@[simp]` lemma, often expressions are
right associated, and it's hard to apply these lemmas about `colimit.ι`.
We thus use `reassoc` to define additional `@[simp]` lemmas, with an arbitrary extra morphism.
(see `tactic/reassoc_axiom.lean`)
-/
@[simp, reassoc] lemma colimit.ι_desc {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) :
colimit.ι F j ≫ colimit.desc F c = c.ι.app j :=
is_colimit.fac _ c j
/--
Functoriality of colimits.
Usually this morphism should be accessed through `colim.map`,
but may be needed separately when you have specified colimits for the source and target functors,
but not necessarily for all functors of shape `J`.
-/
def colim_map {F G : J ⥤ C} [has_colimit F] [has_colimit G] (α : F ⟶ G) : colimit F ⟶ colimit G :=
is_colimit.map (colimit.is_colimit F) _ α
@[simp, reassoc]
lemma ι_colim_map {F G : J ⥤ C} [has_colimit F] [has_colimit G] (α : F ⟶ G) (j : J) :
colimit.ι F j ≫ colim_map α = α.app j ≫ colimit.ι G j :=
colimit.ι_desc _ j
/-- The cocone morphism from the arbitrary choice of colimit cocone to any cocone. -/
def colimit.cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) :
(colimit.cocone F) ⟶ c :=
(colimit.is_colimit F).desc_cocone_morphism c
@[simp] lemma colimit.cocone_morphism_hom {F : J ⥤ C} [has_colimit F] (c : cocone F) :
(colimit.cocone_morphism c).hom = colimit.desc F c := rfl
lemma colimit.ι_cocone_morphism {F : J ⥤ C} [has_colimit F] (c : cocone F) (j : J) :
colimit.ι F j ≫ (colimit.cocone_morphism c).hom = c.ι.app j :=
by simp
@[simp, reassoc] lemma colimit.comp_cocone_point_unique_up_to_iso_hom {F : J ⥤ C} [has_colimit F]
{c : cocone F} (hc : is_colimit c) (j : J) :
colimit.ι F j ≫ (is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit _) hc).hom =
c.ι.app j :=
is_colimit.comp_cocone_point_unique_up_to_iso_hom _ _ _
@[simp, reassoc] lemma colimit.comp_cocone_point_unique_up_to_iso_inv {F : J ⥤ C} [has_colimit F]
{c : cocone F} (hc : is_colimit c) (j : J) :
colimit.ι F j ≫ (is_colimit.cocone_point_unique_up_to_iso hc (colimit.is_colimit _)).inv =
c.ι.app j :=
is_colimit.comp_cocone_point_unique_up_to_iso_inv _ _ _
lemma colimit.exists_unique {F : J ⥤ C} [has_colimit F] (t : cocone F) :
∃! (d : colimit F ⟶ t.X), ∀ j, colimit.ι F j ≫ d = t.ι.app j :=
(colimit.is_colimit F).exists_unique _
/--
Given any other colimit cocone for `F`, the chosen `colimit F` is isomorphic to the cocone point.
-/
def colimit.iso_colimit_cocone {F : J ⥤ C} [has_colimit F] (t : colimit_cocone F) :
colimit F ≅ t.cocone.X :=
is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit F) t.is_colimit
@[simp, reassoc] lemma colimit.iso_colimit_cocone_ι_hom
{F : J ⥤ C} [has_colimit F] (t : colimit_cocone F) (j : J) :
colimit.ι F j ≫ (colimit.iso_colimit_cocone t).hom = t.cocone.ι.app j :=
by { dsimp [colimit.iso_colimit_cocone, is_colimit.cocone_point_unique_up_to_iso], tidy, }
@[simp, reassoc] lemma colimit.iso_colimit_cocone_ι_inv
{F : J ⥤ C} [has_colimit F] (t : colimit_cocone F) (j : J) :
t.cocone.ι.app j ≫ (colimit.iso_colimit_cocone t).inv = colimit.ι F j :=
by { dsimp [colimit.iso_colimit_cocone, is_colimit.cocone_point_unique_up_to_iso], tidy, }
@[ext] lemma colimit.hom_ext {F : J ⥤ C} [has_colimit F] {X : C} {f f' : colimit F ⟶ X}
(w : ∀ j, colimit.ι F j ≫ f = colimit.ι F j ≫ f') : f = f' :=
(colimit.is_colimit F).hom_ext w
@[simp] lemma colimit.desc_cocone {F : J ⥤ C} [has_colimit F] :
colimit.desc F (colimit.cocone F) = 𝟙 (colimit F) :=
(colimit.is_colimit _).desc_self
/--
The isomorphism (in `Type`) between
morphisms from the colimit object to a specified object `W`,
and cocones with cone point `W`.
-/
def colimit.hom_iso (F : J ⥤ C) [has_colimit F] (W : C) :
ulift.{u₁} (colimit F ⟶ W : Type v) ≅ (F.cocones.obj W) :=
(colimit.is_colimit F).hom_iso W
@[simp] lemma colimit.hom_iso_hom (F : J ⥤ C) [has_colimit F] {W : C} (f : ulift (colimit F ⟶ W)) :
(colimit.hom_iso F W).hom f = (colimit.cocone F).ι ≫ (const J).map f.down :=
(colimit.is_colimit F).hom_iso_hom f
/--
The isomorphism (in `Type`) between
morphisms from the colimit object to a specified object `W`,
and an explicit componentwise description of cocones with cone point `W`.
-/
def colimit.hom_iso' (F : J ⥤ C) [has_colimit F] (W : C) :
ulift.{u₁} ((colimit F ⟶ W) : Type v) ≅
{ p : Π j, F.obj j ⟶ W // ∀ {j j'} (f : j ⟶ j'), F.map f ≫ p j' = p j } :=
(colimit.is_colimit F).hom_iso' W
lemma colimit.desc_extend (F : J ⥤ C) [has_colimit F] (c : cocone F) {X : C} (f : c.X ⟶ X) :
colimit.desc F (c.extend f) = colimit.desc F c ≫ f :=
begin
ext1, rw [←category.assoc], simp
end
/--
If `F` has a colimit, so does any naturally isomorphic functor.
-/
-- This has the isomorphism pointing in the opposite direction than in `has_limit_of_iso`.
-- This is intentional; it seems to help with elaboration.
lemma has_colimit_of_iso {F G : J ⥤ C} [has_colimit F] (α : G ≅ F) : has_colimit G :=
has_colimit.mk
{ cocone := (cocones.precompose α.hom).obj (colimit.cocone F),
is_colimit :=
{ desc := λ s, colimit.desc F ((cocones.precompose α.inv).obj s),
fac' := λ s j,
begin
rw [cocones.precompose_obj_ι, nat_trans.comp_app, colimit.cocone_ι],
rw [category.assoc, colimit.ι_desc, ←nat_iso.app_hom, ←iso.eq_inv_comp], refl
end,
uniq' := λ s m w,
begin
apply colimit.hom_ext, intro j,
rw [colimit.ι_desc, cocones.precompose_obj_ι, nat_trans.comp_app, ←nat_iso.app_inv,
iso.eq_inv_comp],
simpa using w j
end } }
/-- If a functor `G` has the same collection of cocones as a functor `F`
which has a colimit, then `G` also has a colimit. -/
lemma has_colimit.of_cocones_iso {K : Type u₁} [category.{v₂} K] (F : J ⥤ C)
(G : K ⥤ C) (h : F.cocones ≅ G.cocones)
[has_colimit F] : has_colimit G :=
has_colimit.mk ⟨_, is_colimit.of_nat_iso (is_colimit.nat_iso (colimit.is_colimit F) ≪≫ h)⟩
/--
The colimits of `F : J ⥤ C` and `G : J ⥤ C` are isomorphic,
if the functors are naturally isomorphic.
-/
def has_colimit.iso_of_nat_iso {F G : J ⥤ C} [has_colimit F] [has_colimit G] (w : F ≅ G) :
colimit F ≅ colimit G :=
is_colimit.cocone_points_iso_of_nat_iso (colimit.is_colimit F) (colimit.is_colimit G) w
@[simp, reassoc]
lemma has_colimit.iso_of_nat_iso_ι_hom {F G : J ⥤ C} [has_colimit F] [has_colimit G]
(w : F ≅ G) (j : J) :
colimit.ι F j ≫ (has_colimit.iso_of_nat_iso w).hom = w.hom.app j ≫ colimit.ι G j :=
is_colimit.comp_cocone_points_iso_of_nat_iso_hom _ _ _ _
@[simp, reassoc]
lemma has_colimit.iso_of_nat_iso_ι_inv {F G : J ⥤ C} [has_colimit F] [has_colimit G]
(w : F ≅ G) (j : J) :
colimit.ι G j ≫ (has_colimit.iso_of_nat_iso w).inv = w.inv.app j ≫ colimit.ι F j :=
is_colimit.comp_cocone_points_iso_of_nat_iso_inv _ _ _ _
@[simp, reassoc]
lemma has_colimit.iso_of_nat_iso_hom_desc {F G : J ⥤ C} [has_colimit F] [has_colimit G]
(t : cocone G) (w : F ≅ G) :
(has_colimit.iso_of_nat_iso w).hom ≫ colimit.desc G t =
colimit.desc F ((cocones.precompose w.hom).obj _) :=
is_colimit.cocone_points_iso_of_nat_iso_hom_desc _ _ _
@[simp, reassoc]
lemma has_colimit.iso_of_nat_iso_inv_desc {F G : J ⥤ C} [has_colimit F] [has_colimit G]
(t : cocone F) (w : F ≅ G) :
(has_colimit.iso_of_nat_iso w).inv ≫ colimit.desc F t =
colimit.desc G ((cocones.precompose w.inv).obj _) :=
is_colimit.cocone_points_iso_of_nat_iso_inv_desc _ _ _
/--
The colimits of `F : J ⥤ C` and `G : K ⥤ C` are isomorphic,
if there is an equivalence `e : J ≌ K` making the triangle commute up to natural isomorphism.
-/
def has_colimit.iso_of_equivalence {F : J ⥤ C} [has_colimit F] {G : K ⥤ C} [has_colimit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) : colimit F ≅ colimit G :=
is_colimit.cocone_points_iso_of_equivalence (colimit.is_colimit F) (colimit.is_colimit G) e w
@[simp]
lemma has_colimit.iso_of_equivalence_hom_π {F : J ⥤ C} [has_colimit F] {G : K ⥤ C} [has_colimit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (j : J) :
colimit.ι F j ≫ (has_colimit.iso_of_equivalence e w).hom =
F.map (e.unit.app j) ≫ w.inv.app _ ≫ colimit.ι G _ :=
begin
simp [has_colimit.iso_of_equivalence, is_colimit.cocone_points_iso_of_equivalence_inv],
dsimp,
simp,
end
@[simp]
lemma has_colimit.iso_of_equivalence_inv_π {F : J ⥤ C} [has_colimit F] {G : K ⥤ C} [has_colimit G]
(e : J ≌ K) (w : e.functor ⋙ G ≅ F) (k : K) :
colimit.ι G k ≫ (has_colimit.iso_of_equivalence e w).inv =
G.map (e.counit_inv.app k) ≫ w.hom.app (e.inverse.obj k) ≫ colimit.ι F (e.inverse.obj k) :=
begin
simp [has_colimit.iso_of_equivalence, is_colimit.cocone_points_iso_of_equivalence_inv],
dsimp,
simp,
end
section pre
variables (F) [has_colimit F] (E : K ⥤ J) [has_colimit (E ⋙ F)]
/--
The canonical morphism from the colimit of `E ⋙ F` to the colimit of `F`.
-/
def colimit.pre : colimit (E ⋙ F) ⟶ colimit F :=
colimit.desc (E ⋙ F) ((colimit.cocone F).whisker E)
@[simp, reassoc] lemma colimit.ι_pre (k : K) :
colimit.ι (E ⋙ F) k ≫ colimit.pre F E = colimit.ι F (E.obj k) :=
by { erw is_colimit.fac, refl, }
@[simp, reassoc] lemma colimit.pre_desc (c : cocone F) :
colimit.pre F E ≫ colimit.desc F c = colimit.desc (E ⋙ F) (c.whisker E) :=
by ext; rw [←assoc, colimit.ι_pre]; simp
variables {L : Type u₃} [category.{v₃} L]
variables (D : L ⥤ K) [has_colimit (D ⋙ E ⋙ F)]
@[simp] lemma colimit.pre_pre : colimit.pre (E ⋙ F) D ≫ colimit.pre F E = colimit.pre F (D ⋙ E) :=
begin
ext j,
rw [←assoc, colimit.ι_pre, colimit.ι_pre],
letI : has_colimit ((D ⋙ E) ⋙ F) := show has_colimit (D ⋙ E ⋙ F), by apply_instance,
exact (colimit.ι_pre F (D ⋙ E) j).symm
end
variables {E F}
/---
If we have particular colimit cocones available for `E ⋙ F` and for `F`,
we obtain a formula for `colimit.pre F E`.
-/
lemma colimit.pre_eq (s : colimit_cocone (E ⋙ F)) (t : colimit_cocone F) :
colimit.pre F E =
(colimit.iso_colimit_cocone s).hom ≫ s.is_colimit.desc ((t.cocone).whisker E) ≫
(colimit.iso_colimit_cocone t).inv :=
by tidy
end pre
section post
variables {D : Type u'} [category.{v'} D]
variables (F) [has_colimit F] (G : C ⥤ D) [has_colimit (F ⋙ G)]
/--
The canonical morphism from `G` applied to the colimit of `F ⋙ G`
to `G` applied to the colimit of `F`.
-/
def colimit.post : colimit (F ⋙ G) ⟶ G.obj (colimit F) :=
colimit.desc (F ⋙ G) (G.map_cocone (colimit.cocone F))
@[simp, reassoc] lemma colimit.ι_post (j : J) :
colimit.ι (F ⋙ G) j ≫ colimit.post F G = G.map (colimit.ι F j) :=
by { erw is_colimit.fac, refl, }
@[simp] lemma colimit.post_desc (c : cocone F) :
colimit.post F G ≫ G.map (colimit.desc F c) = colimit.desc (F ⋙ G) (G.map_cocone c) :=
by { ext, rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_desc, colimit.ι_desc], refl }
@[simp] lemma colimit.post_post
{E : Type u''} [category.{v''} E] (H : D ⥤ E) [has_colimit ((F ⋙ G) ⋙ H)] :
/- H G (colimit F) ⟶ H (colimit (F ⋙ G)) ⟶ colimit ((F ⋙ G) ⋙ H) equals -/
/- H G (colimit F) ⟶ colimit (F ⋙ (G ⋙ H)) -/
colimit.post (F ⋙ G) H ≫ H.map (colimit.post F G) = colimit.post F (G ⋙ H) :=
begin
ext,
rw [←assoc, colimit.ι_post, ←H.map_comp, colimit.ι_post],
exact (colimit.ι_post F (G ⋙ H) j).symm
end
end post
lemma colimit.pre_post {D : Type u'} [category.{v'} D]
(E : K ⥤ J) (F : J ⥤ C) (G : C ⥤ D)
[has_colimit F] [has_colimit (E ⋙ F)] [has_colimit (F ⋙ G)] [H : has_colimit ((E ⋙ F) ⋙ G)] :
/- G (colimit F) ⟶ G (colimit (E ⋙ F)) ⟶ colimit ((E ⋙ F) ⋙ G) vs -/
/- G (colimit F) ⟶ colimit F ⋙ G ⟶ colimit (E ⋙ (F ⋙ G)) or -/
colimit.post (E ⋙ F) G ≫ G.map (colimit.pre F E) =
(@@colimit.pre _ _ _ (F ⋙ G) _ E H ≫ colimit.post F G : _) :=
begin
ext,
rw [←assoc, colimit.ι_post, ←G.map_comp, colimit.ι_pre, ←assoc],
letI : has_colimit (E ⋙ F ⋙ G) := show has_colimit ((E ⋙ F) ⋙ G), by apply_instance,
erw [colimit.ι_pre (F ⋙ G) E j, colimit.ι_post]
end
open category_theory.equivalence
instance has_colimit_equivalence_comp (e : K ≌ J) [has_colimit F] : has_colimit (e.functor ⋙ F) :=
has_colimit.mk { cocone := cocone.whisker e.functor (colimit.cocone F),
is_colimit := is_colimit.whisker_equivalence (colimit.is_colimit F) e, }
/--
If a `E ⋙ F` has a colimit, and `E` is an equivalence, we can construct a colimit of `F`.
-/
lemma has_colimit_of_equivalence_comp (e : K ≌ J) [has_colimit (e.functor ⋙ F)] : has_colimit F :=
begin
haveI : has_colimit (e.inverse ⋙ e.functor ⋙ F) := limits.has_colimit_equivalence_comp e.symm,
apply has_colimit_of_iso (e.inv_fun_id_assoc F).symm,
end
section colim_functor
variables [has_colimits_of_shape J C]
section
local attribute [simp] colim_map
/-- `colimit F` is functorial in `F`, when `C` has all colimits of shape `J`. -/
@[simps obj]
def colim : (J ⥤ C) ⥤ C :=
{ obj := λ F, colimit F,
map := λ F G α, colim_map α,
map_id' := λ F, by { ext, erw [ι_colim_map, id_comp, comp_id] },
map_comp' := λ F G H α β,
by { ext, erw [←assoc, is_colimit.fac, is_colimit.fac, assoc, is_colimit.fac, ←assoc], refl } }
end
variables {F} {G : J ⥤ C} (α : F ⟶ G)
@[simp, reassoc] lemma colimit.ι_map (j : J) :
colimit.ι F j ≫ colim.map α = α.app j ≫ colimit.ι G j :=
by apply is_colimit.fac
@[simp] lemma colimit.map_desc (c : cocone G) :
colim.map α ≫ colimit.desc G c = colimit.desc F ((cocones.precompose α).obj c) :=
by ext; rw [←assoc, colimit.ι_map, assoc, colimit.ι_desc, colimit.ι_desc]; refl
lemma colimit.pre_map [has_colimits_of_shape K C] (E : K ⥤ J) :
colimit.pre F E ≫ colim.map α = colim.map (whisker_left E α) ≫ colimit.pre G E :=
by ext; rw [←assoc, colimit.ι_pre, colimit.ι_map, ←assoc, colimit.ι_map, assoc, colimit.ι_pre]; refl
lemma colimit.pre_map' [has_colimits_of_shape K C]
(F : J ⥤ C) {E₁ E₂ : K ⥤ J} (α : E₁ ⟶ E₂) :
colimit.pre F E₁ = colim.map (whisker_right α F) ≫ colimit.pre F E₂ :=
by ext1; simp [← category.assoc]
lemma colimit.pre_id (F : J ⥤ C) :
colimit.pre F (𝟭 _) = colim.map (functor.left_unitor F).hom := by tidy
lemma colimit.map_post {D : Type u'} [category.{v'} D] [has_colimits_of_shape J D] (H : C ⥤ D) :
/- H (colimit F) ⟶ H (colimit G) ⟶ colimit (G ⋙ H) vs
H (colimit F) ⟶ colimit (F ⋙ H) ⟶ colimit (G ⋙ H) -/
colimit.post F H ≫ H.map (colim.map α) = colim.map (whisker_right α H) ≫ colimit.post G H:=
begin
ext,
rw [←assoc, colimit.ι_post, ←H.map_comp, colimit.ι_map, H.map_comp],
rw [←assoc, colimit.ι_map, assoc, colimit.ι_post],
refl
end
/--
The isomorphism between
morphisms from the cone point of the colimit cocone for `F` to `W`
and cocones over `F` with cone point `W`
is natural in `F`.
-/
def colim_coyoneda : colim.op ⋙ coyoneda ⋙ (whiskering_right _ _ _).obj ulift_functor.{u₁} ≅
category_theory.cocones J C :=
nat_iso.of_components (λ F, nat_iso.of_components (colimit.hom_iso (unop F)) (by tidy))
(by tidy)
end colim_functor
/--
We can transport colimits of shape `J` along an equivalence `J ≌ J'`.
-/
lemma has_colimits_of_shape_of_equivalence {J' : Type u₂} [category.{v₂} J']
(e : J ≌ J') [has_colimits_of_shape J C] : has_colimits_of_shape J' C :=
by { constructor, intro F, apply has_colimit_of_equivalence_comp e, apply_instance }
variable (C)
/--
`has_colimits_of_size_shrink.{v u} C` tries to obtain `has_colimits_of_size.{v u} C`
from some other `has_colimits_of_size C`.
-/
lemma has_colimits_of_size_shrink [has_colimits_of_size.{(max v₁ v₂) (max u₁ u₂)} C] :
has_colimits_of_size.{v₁ u₁} C :=
⟨λ J hJ, by exactI has_colimits_of_shape_of_equivalence
(ulift_hom_ulift_category.equiv.{v₂ u₂} J).symm⟩
@[priority 100]
instance has_smallest_colimits_of_has_colimits [has_colimits C] :
has_colimits_of_size.{0 0} C := has_colimits_of_size_shrink.{0 0} C
end colimit
section opposite
/--
If `t : cone F` is a limit cone, then `t.op : cocone F.op` is a colimit cocone.
-/
def is_limit.op {t : cone F} (P : is_limit t) : is_colimit t.op :=
{ desc := λ s, (P.lift s.unop).op,
fac' := λ s j, congr_arg quiver.hom.op (P.fac s.unop (unop j)),
uniq' := λ s m w,
begin
rw ← P.uniq s.unop m.unop,
{ refl, },
{ dsimp, intro j, rw ← w, refl, }
end }
/--
If `t : cocone F` is a colimit cocone, then `t.op : cone F.op` is a limit cone.
-/
def is_colimit.op {t : cocone F} (P : is_colimit t) : is_limit t.op :=
{ lift := λ s, (P.desc s.unop).op,
fac' := λ s j, congr_arg quiver.hom.op (P.fac s.unop (unop j)),
uniq' := λ s m w,
begin
rw ← P.uniq s.unop m.unop,
{ refl, },
{ dsimp, intro j, rw ← w, refl, }
end }
/--
If `t : cone F.op` is a limit cone, then `t.unop : cocone F` is a colimit cocone.
-/
def is_limit.unop {t : cone F.op} (P : is_limit t) : is_colimit t.unop :=
{ desc := λ s, (P.lift s.op).unop,
fac' := λ s j, congr_arg quiver.hom.unop (P.fac s.op (op j)),
uniq' := λ s m w,
begin
rw ← P.uniq s.op m.op,
{ refl, },
{ dsimp, intro j, rw ← w, refl, }
end }
/--
If `t : cocone F.op` is a colimit cocone, then `t.unop : cone F.` is a limit cone.
-/
def is_colimit.unop {t : cocone F.op} (P : is_colimit t) : is_limit t.unop :=
{ lift := λ s, (P.desc s.op).unop,
fac' := λ s j, congr_arg quiver.hom.unop (P.fac s.op (op j)),
uniq' := λ s m w,
begin
rw ← P.uniq s.op m.op,
{ refl, },
{ dsimp, intro j, rw ← w, refl, }
end }
/--
`t : cone F` is a limit cone if and only is `t.op : cocone F.op` is a colimit cocone.
-/
def is_limit_equiv_is_colimit_op {t : cone F} : is_limit t ≃ is_colimit t.op :=
equiv_of_subsingleton_of_subsingleton
is_limit.op (λ P, P.unop.of_iso_limit (cones.ext (iso.refl _) (by tidy)))
/--
`t : cocone F` is a colimit cocone if and only is `t.op : cone F.op` is a limit cone.
-/
def is_colimit_equiv_is_limit_op {t : cocone F} : is_colimit t ≃ is_limit t.op :=
equiv_of_subsingleton_of_subsingleton
is_colimit.op (λ P, P.unop.of_iso_colimit (cocones.ext (iso.refl _) (by tidy)))
end opposite
end category_theory.limits
|
8c23bb6715135e28408931f061cd198d27bcdbc1 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/filter/pointwise.lean | 93454fa79871cffffd0a2614aefe6d207712fa19 | [] | 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 | 3,821 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.pointwise
import Mathlib.order.filter.basic
import Mathlib.PostPort
universes u v
namespace Mathlib
/-!
# Pointwise operations on filters.
The pointwise operations on filters have nice properties, such as
• `map m (f₁ * f₂) = map m f₁ * map m f₂`
• `𝓝 x * 𝓝 y = 𝓝 (x * y)`
-/
namespace filter
protected instance has_one {α : Type u} [HasOne α] : HasOne (filter α) :=
{ one := principal 1 }
@[simp] theorem mem_zero {α : Type u} [HasZero α] (s : set α) : s ∈ 0 ↔ 0 ∈ s := sorry
protected instance has_mul {α : Type u} [monoid α] : Mul (filter α) :=
{ mul :=
fun (f g : filter α) =>
mk (set_of fun (s : set α) => ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ * t₂ ⊆ s) sorry sorry sorry }
theorem mem_add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} {s : set α} : s ∈ f + g ↔ ∃ (t₁ : set α), ∃ (t₂ : set α), t₁ ∈ f ∧ t₂ ∈ g ∧ t₁ + t₂ ⊆ s :=
iff.rfl
theorem mul_mem_mul {α : Type u} [monoid α] {f : filter α} {g : filter α} {s : set α} {t : set α} (hs : s ∈ f) (ht : t ∈ g) : s * t ∈ f * g :=
Exists.intro s (Exists.intro t { left := hs, right := { left := ht, right := set.subset.refl (s * t) } })
protected theorem mul_le_mul {α : Type u} [monoid α] {f₁ : filter α} {f₂ : filter α} {g₁ : filter α} {g₂ : filter α} (hf : f₁ ≤ f₂) (hg : g₁ ≤ g₂) : f₁ * g₁ ≤ f₂ * g₂ := sorry
theorem ne_bot.add {α : Type u} [add_monoid α] {f : filter α} {g : filter α} : ne_bot f → ne_bot g → ne_bot (f + g) := sorry
protected theorem add_assoc {α : Type u} [add_monoid α] (f : filter α) (g : filter α) (h : filter α) : f + g + h = f + (g + h) := sorry
protected theorem one_mul {α : Type u} [monoid α] (f : filter α) : 1 * f = f := sorry
protected theorem add_zero {α : Type u} [add_monoid α] (f : filter α) : f + 0 = f := sorry
protected instance monoid {α : Type u} [monoid α] : monoid (filter α) :=
monoid.mk Mul.mul filter.mul_assoc 1 filter.one_mul filter.mul_one
protected theorem map_add {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_hom m] {f₁ : filter α} {f₂ : filter α} : map m (f₁ + f₂) = map m f₁ + map m f₂ := sorry
protected theorem map_one {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_monoid_hom m] : map m 1 = 1 := sorry
-- TODO: prove similar statements when `m` is group homomorphism etc.
theorem Mathlib.map.is_add_monoid_hom {α : Type u} {β : Type v} [add_monoid α] [add_monoid β] (m : α → β) [is_add_monoid_hom m] : is_add_monoid_hom (map m) :=
is_add_monoid_hom.mk (filter.map_zero m)
-- The other direction does not hold in general.
theorem comap_mul_comap_le {α : Type u} {β : Type v} [monoid α] [monoid β] (m : α → β) [is_mul_hom m] {f₁ : filter β} {f₂ : filter β} : comap m f₁ * comap m f₂ ≤ comap m (f₁ * f₂) := sorry
theorem tendsto.mul_mul {α : Type u} {β : Type v} [monoid α] [monoid β] {m : α → β} [is_mul_hom m] {f₁ : filter α} {g₁ : filter α} {f₂ : filter β} {g₂ : filter β} : tendsto m f₁ f₂ → tendsto m g₁ g₂ → tendsto m (f₁ * g₁) (f₂ * g₂) :=
fun (hf : tendsto m f₁ f₂) (hg : tendsto m g₁ g₂) =>
eq.mpr (id (Eq._oldrec (Eq.refl (tendsto m (f₁ * g₁) (f₂ * g₂))) (tendsto.equations._eqn_1 m (f₁ * g₁) (f₂ * g₂))))
(eq.mpr (id (Eq._oldrec (Eq.refl (map m (f₁ * g₁) ≤ f₂ * g₂)) (filter.map_mul m))) (filter.mul_le_mul hf hg))
|
1ba66bb983db8b2a4fd5389ae752ee9c66be83fe | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/fibrant_class1.lean | 270824c1c796d72dc690ee853af61aa132ecade7 | [
"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 | 566 | lean | import general_notation type
inductive fibrant [class] (T : Type) : Type :=
fibrant_mk : fibrant T
inductive path {A : Type'} [fA : fibrant A] (a : A) : A → Type :=
idpath : path a a
notation a ≈ b := path a b
axiom path_fibrant {A : Type'} [fA : fibrant A] (a b : A) : fibrant (path a b)
instance [persistent] path_fibrant
axiom imp_fibrant {A : Type'} {B : Type'} [C1 : fibrant A] [C2 : fibrant B] : fibrant (A → B)
instance imp_fibrant
definition test {A : Type} [fA : fibrant A] {x y : A} :
Π (z : A), y ≈ z → fibrant (x ≈ y → x ≈ z) := _
|
858332ebe068a623716f87a2c3f95d60d75715c9 | 4950bf76e5ae40ba9f8491647d0b6f228ddce173 | /src/topology/algebra/ordered.lean | fc7ef5ffcda12daac0c48c6491472bc5820d958d | [
"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 | 155,023 | 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 tactic.linarith
import tactic.tfae
import algebra.archimedean
import algebra.group.pi
import algebra.ordered_ring
import order.liminf_limsup
import data.set.intervals.image_preimage
import data.set.intervals.ord_connected
import data.set.intervals.surj_on
import data.set.intervals.pi
import topology.algebra.group
import topology.extend_from_subset
import order.filter.interval
/-!
# Theory of topology on ordered spaces
## 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`.
### Connected sets and Intermediate Value Theorem
* `is_preconnected_I??` : all intervals `I??` are preconnected,
* `is_preconnected.intermediate_value`, `intermediate_value_univ` : Intermediate Value Theorem for
connected sets and connected spaces, respectively;
* `intermediate_value_Icc`, `intermediate_value_Icc'`: Intermediate Value Theorem for functions
on closed intervals.
### Miscellaneous facts
* `is_compact.exists_forall_le`, `is_compact.exists_forall_ge` : extreme value theorem, a continuous
function on a compact set takes its minimum and maximum values.
* `is_closed.Icc_subset_of_forall_mem_nhds_within` : “Continuous induction” principle;
if `s ∩ [a, b]` is closed, `a ∈ s`, and for each `x ∈ [a, b) ∩ s` some of its right neighborhoods
is included `s`, then `[a, b] ⊆ s`.
* `is_closed.Icc_subset_of_forall_exists_gt`, `is_closed.mem_of_ge_of_forall_exists_gt` : two
other versions of the “continuous induction” principle.
## Implementation
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 classical set filter topological_space
open function (curry uncurry)
open_locale topological_space 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 α], topological_space (order_dual α) := id
section order_closed_topology
section preorder
variables [topological_space α] [preorder α] [t : order_closed_topology α]
include t
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_dual α) :=
⟨(@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
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} :=
by { rw [←closure_le_eq hf hg], exact closure_mono (λ b, le_of_lt) }
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'
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 (𝓝[Ici a] 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 (𝓝[Iic a] 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
private lemma is_closed_eq : is_closed {p : α × α | p.1 = p.2} :=
by simp only [le_antisymm_iff];
exact is_closed_inter t.is_closed_le' (is_closed_le continuous_snd continuous_fst)
@[priority 90] -- see Note [lower instance priority]
instance order_closed_topology.to_t2_space : t2_space α :=
{ t2 :=
have is_open {p : α × α | p.1 ≠ p.2}, from is_closed_eq,
assume a b h,
let ⟨u, v, hu, hv, ha, hb, h⟩ := is_open_prod_iff.mp this a b h in
⟨u, v, hu, hv, ha, hb,
set.eq_empty_iff_forall_not_mem.2 $ assume a ⟨h₁, h₂⟩,
have a ≠ a, from @h (a, a) ⟨h₁, h₂⟩,
this rfl⟩ }
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
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
variables [topological_space γ]
/-- Intermediate value theorem for two functions: if `f` and `g` are two continuous functions
on a preconnected space and `f a ≤ g a` and `g b ≤ f b`, then for some `x` we have `f x = g x`. -/
lemma intermediate_value_univ₂ [preconnected_space γ] {a b : γ} {f g : γ → α} (hf : continuous f)
(hg : continuous g) (ha : f a ≤ g a) (hb : g b ≤ f b) :
∃ x, f x = g x :=
begin
obtain ⟨x, h, hfg, hgf⟩ : (univ ∩ {x | f x ≤ g x ∧ g x ≤ f x}).nonempty,
from is_preconnected_closed_iff.1 preconnected_space.is_preconnected_univ _ _
(is_closed_le hf hg) (is_closed_le hg hf) (λ x hx, le_total _ _) ⟨a, trivial, ha⟩
⟨b, trivial, hb⟩,
exact ⟨x, le_antisymm hfg hgf⟩
end
/-- Intermediate value theorem for two functions: if `f` and `g` are two functions continuous
on a preconnected set `s` and for some `a b ∈ s` we have `f a ≤ g a` and `g b ≤ f b`,
then for some `x ∈ s` we have `f x = g x`. -/
lemma is_preconnected.intermediate_value₂ {s : set γ} (hs : is_preconnected s)
{a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f g : γ → α}
(hf : continuous_on f s) (hg : continuous_on g s) (ha' : f a ≤ g a) (hb' : g b ≤ f b) :
∃ x ∈ s, f x = g x :=
let ⟨x, hx⟩ := @intermediate_value_univ₂ α s _ _ _ _ (subtype.preconnected_space hs) ⟨a, ha⟩ ⟨b, hb⟩
_ _ (continuous_on_iff_continuous_restrict.1 hf) (continuous_on_iff_continuous_restrict.1 hg)
ha' hb'
in ⟨x, x.2, hx⟩
/-- Intermediate Value Theorem for continuous functions on connected sets. -/
lemma is_preconnected.intermediate_value {s : set γ} (hs : is_preconnected s)
{a b : γ} (ha : a ∈ s) (hb : b ∈ s) {f : γ → α} (hf : continuous_on f s) :
Icc (f a) (f b) ⊆ f '' s :=
λ x hx, mem_image_iff_bex.2 $ hs.intermediate_value₂ ha hb hf continuous_on_const hx.1 hx.2
/-- Intermediate Value Theorem for continuous functions on connected spaces. -/
lemma intermediate_value_univ [preconnected_space γ] (a b : γ) {f : γ → α} (hf : continuous f) :
Icc (f a) (f b) ⊆ range f :=
λ x hx, intermediate_value_univ₂ hf continuous_const hx.1 hx.2
/-- Intermediate Value Theorem for continuous functions on connected spaces. -/
lemma mem_range_of_exists_le_of_exists_ge [preconnected_space γ] {c : α} {f : γ → α}
(hf : continuous f) (h₁ : ∃ a, f a ≤ c) (h₂ : ∃ b, c ≤ f b) :
c ∈ range f :=
let ⟨a, ha⟩ := h₁, ⟨b, hb⟩ := h₂ in intermediate_value_univ a b hf ⟨ha, hb⟩
/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/
lemma is_preconnected.Icc_subset {s : set α} (hs : is_preconnected s)
{a b : α} (ha : a ∈ s) (hb : b ∈ s) :
Icc a b ⊆ s :=
by simpa only [image_id] using hs.intermediate_value ha hb continuous_on_id
/-- If a preconnected set contains endpoints of an interval, then it includes the whole interval. -/
lemma is_connected.Icc_subset {s : set α} (hs : is_connected s)
{a b : α} (ha : a ∈ s) (hb : b ∈ s) :
Icc a b ⊆ s :=
hs.2.Icc_subset ha hb
/-- If preconnected set in a linear order space is unbounded below and above, then it is the whole
space. -/
lemma is_preconnected.eq_univ_of_unbounded {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s)
(ha : ¬bdd_above s) :
s = univ :=
begin
refine eq_univ_of_forall (λ x, _),
obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := not_bdd_below_iff.1 hb x,
obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x,
exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
end
/-!
### 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 `𝓝[Ioi a] a` and
`𝓝[Ici a] 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 ∈ 𝓝[Ioi b] 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 ∈ 𝓝[Ioi b] b :=
mem_sets_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 ∈ 𝓝[Ioi b] b :=
mem_sets_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 ∈ 𝓝[Ioi b] b :=
mem_sets_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 = 𝓝[Ioi 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 = 𝓝[Ioi 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 ∈ 𝓝[Iio b] b :=
by simpa only [dual_Ioo] using @Ioo_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩
lemma Ico_mem_nhds_within_Iio {a b c : α} (H : b ∈ Ioc a c) :
Ico a c ∈ 𝓝[Iio b] b :=
mem_sets_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 ∈ 𝓝[Iio b] b :=
mem_sets_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 ∈ 𝓝[Iio b] b :=
mem_sets_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 = 𝓝[Iio b] b :=
by simpa only [dual_Ioc] using @nhds_within_Ioc_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h
@[simp] lemma nhds_within_Ioo_eq_nhds_within_Iio {a b : α} (h : a < b) :
𝓝[Ioo a b] b = 𝓝[Iio b] b :=
by simpa only [dual_Ioo] using @nhds_within_Ioo_eq_nhds_within_Ioi (order_dual α) _ _ _ _ _ h
@[simp] lemma continuous_within_at_Ico_iff_Iio [topological_space β] {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 [topological_space β] {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 ∈ 𝓝[Ici b] b :=
mem_nhds_within_of_mem_nhds $ mem_nhds_sets is_open_Ioo H
lemma Ioc_mem_nhds_within_Ici {a b c : α} (H : b ∈ Ioo a c) :
Ioc a c ∈ 𝓝[Ici b] b :=
mem_sets_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 ∈ 𝓝[Ici b] 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 ∈ 𝓝[Ici b] b :=
mem_sets_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 = 𝓝[Ici 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 = 𝓝[Ici 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 ∈ 𝓝[Iic b] b :=
mem_nhds_within_of_mem_nhds $ mem_nhds_sets is_open_Ioo H
lemma Ico_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioo a c) :
Ico a c ∈ 𝓝[Iic b] b :=
mem_sets_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 ∈ 𝓝[Iic b] b :=
by simpa only [dual_Ico] using @Ico_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ _ ⟨H.2, H.1⟩
lemma Icc_mem_nhds_within_Iic {a b c : α} (H : b ∈ Ioc a c) :
Icc a c ∈ 𝓝[Iic b] b :=
mem_sets_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 = 𝓝[Iic b] b :=
by simpa only [dual_Icc] using @nhds_within_Icc_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h
@[simp] lemma nhds_within_Ioc_eq_nhds_within_Iic {a b : α} (h : a < b) :
𝓝[Ioc a b] b = 𝓝[Iic b] b :=
by simpa only [dual_Ico] using @nhds_within_Ico_eq_nhds_within_Ici (order_dual α) _ _ _ _ _ h
@[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 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_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]
@[continuity] lemma continuous.min (hf : continuous f) (hg : continuous g) :
continuous (λb, min (f b) (g b)) :=
have ∀b∈frontier {b | f b ≤ g b}, f b = g b, from assume b hb, frontier_le_subset_eq hf hg hb,
continuous_if this hf hg
@[continuity] lemma continuous.max (hf : continuous f) (hg : continuous g) :
continuous (λb, max (f b) (g b)) :=
@continuous.min (order_dual α) _ _ _ _ _ _ _ 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 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 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)
end linear_order
end 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
instance {α : Type*} [topological_space α] [partial_order α] [order_topology α] :
order_topology (order_dual α) :=
⟨by convert @order_topology.topology_eq_generate_intervals α _ _ _;
conv in (_ ∨ _) { rw or.comm }; refl⟩
section partial_order
variables [topological_space α] [partial_order α] [t : order_topology α]
include t
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 :=
mem_nhds_sets (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 :=
mem_nhds_sets (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_binfi $ assume b hb, infi_le_of_le {c : α | b < c} $ infi_le _ ⟨hb, b, or.inl rfl⟩)
(le_binfi $ 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_left_of_le $ infi_le_of_le b $ infi_le _ h
| _, h, (or.inr rfl) := inf_le_right_of_le $ infi_le_of_le b $ infi_le _ h
end)
lemma tendsto_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 _); 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)
instance tendsto_Ixx_nhds_within (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
/-- Also known as squeeze or 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) :=
tendsto_order.2
⟨assume a' h',
have ∀ᶠ b in b, a' < g b, from (tendsto_order.1 hg).left a' h',
by filter_upwards [this, hgf] assume a, lt_of_lt_of_le,
assume a' h',
have ∀ᶠ b in b, h b < a', from (tendsto_order.1 hh).right a' h',
by filter_upwards [this, hfh] assume a h₁ h₂, lt_of_le_of_lt h₂ h₁⟩
/-- Also known as squeeze or 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)) :=
calc 𝓝 a = (⨅b<a, 𝓟 {c | b < c}) ⊓ (⨅b>a, 𝓟 {c | c < b}) : nhds_eq_order a
... = (⨅b<a, 𝓟 {c | b < c} ⊓ (⨅b>a, 𝓟 {c | c < b})) : binfi_inf hl
... = (⨅l<a, (⨅u>a, 𝓟 {c | c < u} ⊓ 𝓟 {c | l < c})) :
begin
congr, funext x,
congr, funext hx,
rw [inf_comm],
apply binfi_inf hu
end
... = _ : by simp [inter_comm]; refl
lemma tendsto_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 partial_order
theorem induced_order_topology' {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [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_sets.2 ⟨{x | f b < x},
mem_inf_sets_of_left $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ },
{ exact mem_comap_sets.2 ⟨{x | x < f b},
mem_inf_sets_of_right $ mem_infi_sets _ $ mem_infi_sets (hf.2 ab) $ mem_principal_self _,
λ x, hf.1⟩ } },
{ rw [← map_le_iff_le_comap],
refine le_inf _ _; refine le_infi (λ x, le_infi $ λ h, le_principal_iff.2 _); simp,
{ rcases H₁ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inl rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_le_of_lt xb (hf.2 hc) },
{ rcases H₂ h with ⟨b, ab, xb⟩,
refine mem_infi_sets _ (mem_infi_sets ⟨ab, b, or.inr rfl⟩ (mem_principal_sets.2 _)),
exact λ c hc, lt_of_lt_of_le (hf.2 hc) xb } },
end
theorem induced_order_topology {α : Type u} {β : Type v}
[partial_order α] [ta : topological_space β] [partial_order β] [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_sets_of_left (mem_infi_sets b _),
exact mem_infi_sets ab (mem_principal_self (Ioi ↑b)) },
{ refine ⟨Iio b, _, λ _, id⟩,
refine mem_inf_sets_of_right (mem_infi_sets b _),
exact mem_infi_sets 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_sets (Ioi ⟨x, hx⟩) (mem_infi_sets ⟨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 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_sets (Iio ⟨x, hx⟩) (mem_infi_sets ⟨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 a.2 y.2 ⟨le_of_lt h, le_of_not_gt hx⟩ } }
end
lemma nhds_top_order [topological_space α] [order_top α] [order_topology α] :
𝓝 (⊤:α) = (⨅l (h₂ : l < ⊤), 𝓟 (Ioi l)) :=
by simp [nhds_eq_order (⊤:α)]
lemma nhds_bot_order [topological_space α] [order_bot α] [order_topology α] :
𝓝 (⊥:α) = (⨅l (h₂ : ⊥ < l), 𝓟 (Iio l)) :=
by simp [nhds_eq_order (⊥:α)]
lemma tendsto_nhds_top_mono [topological_space β] [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],
exact λ x, lt_of_lt_of_le
end
lemma tendsto_nhds_bot_mono [topological_space β] [order_bot β] [order_topology β] {l : filter α}
{f g : α → β} (hf : tendsto f l (𝓝 ⊥)) (hg : g ≤ᶠ[l] f) :
tendsto g l (𝓝 ⊥) :=
@tendsto_nhds_top_mono α (order_dual β) _ _ _ _ _ _ hf hg
lemma tendsto_nhds_top_mono' [topological_space β] [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 β] [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 α] [order_topology α]
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 :=
begin
rw [nhds_eq_order a] at hs,
rcases hs with ⟨t₁, ht₁, t₂, ht₂, hts⟩,
-- First we show that `t₂` includes `(-∞, a]`, so it suffices to show `(l', ∞) ⊆ t₁`
suffices : ∃ l' ∈ Ico l a, Ioi l' ⊆ t₁,
{ have A : 𝓟 (Iic a) ≤ ⨅ b ∈ Ioi a, 𝓟 (Iio b),
from (le_infi $ λ b, le_infi $ λ hb, principal_mono.2 $ Iic_subset_Iio.2 hb),
have B : t₁ ∩ Iic a ⊆ s,
from subset.trans (inter_subset_inter_right _ (A ht₂)) hts,
from this.imp (λ l', Exists.imp $ λ hl' hl x hx, B ⟨hl hx.1, hx.2⟩) },
clear hts ht₂ t₂,
-- Now we find `l` such that `(l', ∞) ⊆ t₁`
rw [mem_binfi] at ht₁,
{ rcases ht₁ with ⟨b, hb, hb'⟩,
exact ⟨max b l, ⟨le_max_right _ _, max_lt hb hl⟩,
λ x hx, hb' $ Ioi_subset_Ioi (le_max_left _ _) hx⟩ },
{ intros b hb b' hb', simp only [mem_Iio] at hb hb',
use [max b b', max_lt hb hb'],
simp [le_refl] },
exact ⟨l, hl⟩
end
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 :=
begin
convert @exists_Ioc_subset_of_mem_nhds' (order_dual α) _ _ _ _ _ hs _ hu,
ext, rw [dual_Ico, dual_Ioc]
end
lemma exists_Ioc_subset_of_mem_nhds {a : α} {s : set α} (hs : s ∈ 𝓝 a) (h : ∃ l, l < a) :
∃ l < a, Ioc l a ⊆ s :=
let ⟨l', hl'⟩ := h in let ⟨l, hl⟩ := exists_Ioc_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.2, hl.snd⟩
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 in let ⟨l, hl⟩ := exists_Ico_subset_of_mem_nhds' hs hl' in ⟨l, hl.fst.1, hl.snd⟩
lemma mem_nhds_unbounded {a : α} {s : set α} (hu : ∃u, a < u) (hl : ∃l, l < a) :
s ∈ 𝓝 a ↔ (∃l u, l < a ∧ a < u ∧ ∀b, l < b → b < u → b ∈ s) :=
let ⟨l, hl'⟩ := hl, ⟨u, hu'⟩ := hu in
have 𝓝 a = (⨅p : {l // l < a} × {u // a < u}, 𝓟 (Ioo p.1.val p.2.val)),
by simp [nhds_order_unbounded hu hl, infi_subtype, infi_prod],
iff.intro
(assume hs, by rw [this] at hs; from infi_sets_induct hs
⟨l, u, hl', hu', by simp⟩
begin
intro p, rcases p with ⟨⟨l, hl⟩, ⟨u, hu⟩⟩,
simp [set.subset_def],
intros s₁ s₂ hs₁ l' hl' u' hu' hs₂,
refine ⟨max l l', _, min u u', _⟩;
simp [*, lt_min_iff, max_lt_iff] {contextual := tt}
end
(assume s₁ s₂ h ⟨l, u, h₁, h₂, h₃⟩, ⟨l, u, h₁, h₂, assume b hu hl, h $ h₃ _ hu hl⟩))
(assume ⟨l, u, hl, hu, h⟩,
by rw [this]; exact mem_infi_sets ⟨⟨l, hl⟩, ⟨u, hu⟩⟩ (assume b ⟨h₁, h₂⟩, h b h₁ h₂))
lemma order_separated {a₁ a₂ : α} (h : a₁ < a₂) :
∃u v : set α, is_open u ∧ is_open v ∧ a₁ ∈ u ∧ a₂ ∈ v ∧ (∀b₁∈u, ∀b₂∈v, b₁ < b₂) :=
match dense_or_discrete 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_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 order_topology.t2_space : t2_space α := by apply_instance
@[priority 100] -- see Note [lower instance priority]
instance order_topology.regular_space : regular_space α :=
{ regular := assume s a hs ha,
have hs' : sᶜ ∈ 𝓝 a, from mem_nhds_sets hs ha,
have ∃t:set α, is_open t ∧ (∀l∈ s, l < a → l ∈ t) ∧ 𝓝[t] a = ⊥,
from by_cases
(assume h : ∃l, l < a,
let ⟨l, hl, h⟩ := exists_Ioc_subset_of_mem_nhds hs' h in
match dense_or_discrete l a with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | a < b}, is_open_gt' _,
assume c hcs hca, show c < b,
from lt_of_not_ge $ assume hbc, h ⟨lt_of_lt_of_le hb₁ hbc, le_of_lt hca⟩ hcs,
inf_principal_eq_bot $ (𝓝 a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hb₂) $
assume x (hx : b < x), show ¬ x < b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' < a}, is_open_gt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (𝓝 a).sets_of_superset (mem_nhds_sets (is_open_lt' _) hl) $
assume x (hx : l < x), show ¬ x < a, from not_lt.2 $ h₁ _ hx⟩
end)
(assume : ¬ ∃l, l < a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
nhds_within_empty _⟩),
let ⟨t₁, ht₁o, ht₁s, ht₁a⟩ := this in
have ∃t:set α, is_open t ∧ (∀u∈ s, u>a → u ∈ t) ∧ 𝓝[t] a = ⊥,
from by_cases
(assume h : ∃u, u > a,
let ⟨u, hu, h⟩ := exists_Ico_subset_of_mem_nhds hs' h in
match dense_or_discrete a u with
| or.inl ⟨b, hb₁, hb₂⟩ := ⟨{a | b < a}, is_open_lt' _,
assume c hcs hca, show c > b,
from lt_of_not_ge $ assume hbc, h ⟨le_of_lt hca, lt_of_le_of_lt hbc hb₂⟩ hcs,
inf_principal_eq_bot $ (𝓝 a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hb₁) $
assume x (hx : b > x), show ¬ x > b, from not_lt.2 $ le_of_lt hx⟩
| or.inr ⟨h₁, h₂⟩ := ⟨{a' | a' > a}, is_open_lt' _, assume b hbs hba, hba,
inf_principal_eq_bot $ (𝓝 a).sets_of_superset (mem_nhds_sets (is_open_gt' _) hu) $
assume x (hx : u > x), show ¬ x > a, from not_lt.2 $ h₂ _ hx⟩
end)
(assume : ¬ ∃u, u > a, ⟨∅, is_open_empty, assume l _ hl, (this ⟨l, hl⟩).elim,
nhds_within_empty _⟩),
let ⟨t₂, ht₂o, ht₂s, ht₂a⟩ := this in
⟨t₁ ∪ t₂, is_open_union ht₁o ht₂o,
assume x hx,
have x ≠ a, from assume eq, ha $ eq ▸ hx,
(ne_iff_lt_or_gt.mp this).imp (ht₁s _ hx) (ht₂s _ hx),
by rw [nhds_within_union, ht₁a, ht₂a, bot_sup_eq]⟩,
..order_topology.t2_space }
/-- 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 l' u' : α} {s : set α}
(hl' : l' < a) (hu' : 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⟩,
refine ⟨l, u, ⟨la.2, au.1⟩, λx hx, _⟩,
cases le_total a x with hax hax,
{ exact hu ⟨hax, hx.2⟩ },
{ exact hl ⟨hx.1, hax⟩ } },
{ rintros ⟨l, u, ha, h⟩,
apply mem_sets_of_superset (mem_nhds_sets is_open_Ioo ha) 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_top_order α] [no_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝 a ↔ ∃l u, a ∈ Ioo l u ∧ Ioo l u ⊆ s :=
let ⟨l', hl'⟩ := no_bot a in let ⟨u', hu'⟩ := no_top a in mem_nhds_iff_exists_Ioo_subset' hl' hu'
lemma filter.eventually.exists_Ioo_subset [no_top_order α] [no_bot_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
lemma Iio_mem_nhds {a b : α} (h : a < b) : Iio b ∈ 𝓝 a :=
mem_nhds_sets is_open_Iio h
lemma Ioi_mem_nhds {a b : α} (h : a < b) : Ioi a ∈ 𝓝 b :=
mem_nhds_sets is_open_Ioi h
lemma Iic_mem_nhds {a b : α} (h : a < b) : Iic b ∈ 𝓝 a :=
mem_sets_of_superset (Iio_mem_nhds h) Iio_subset_Iic_self
lemma Ici_mem_nhds {a b : α} (h : a < b) : Ici a ∈ 𝓝 b :=
mem_sets_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 :=
mem_nhds_sets is_open_Ioo ⟨ha, hb⟩
lemma Ioc_mem_nhds {a b x : α} (ha : a < x) (hb : x < b) : Ioc a b ∈ 𝓝 x :=
mem_sets_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_sets_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_sets_of_superset (Ioo_mem_nhds ha hb) Ioo_subset_Icc_self
section pi
/-!
### Intervals in `Π i, π i` belong to `𝓝 x`
For each leamma `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*} [fintype ι] [Π 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 (finite.of_fintype _) (λ 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 (finite.of_fintype _) (λ 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.of_fintype _) (λ 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_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ 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, order_dual (π 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_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ 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_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ 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_sets_of_superset (set_pi_mem_nhds (finite.of_fintype _) (λ 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_top_order α] (x : α) :
disjoint (𝓝 x) at_top :=
begin
rw filter.disjoint_iff,
cases no_top x with a ha,
use [Iio a, Iio_mem_nhds ha, Ici a, mem_at_top a],
rw [inter_comm, Ici_inter_Iio, Ico_self]
end
@[simp] lemma inf_nhds_at_top [no_top_order α] (x : α) :
𝓝 x ⊓ at_top = ⊥ :=
disjoint_iff.1 (disjoint_nhds_at_top x)
lemma disjoint_nhds_at_bot [no_bot_order α] (x : α) :
disjoint (𝓝 x) at_bot :=
@disjoint_nhds_at_top (order_dual α) _ _ _ _ x
@[simp] lemma inf_nhds_at_bot [no_bot_order α] (x : α) :
𝓝 x ⊓ at_bot = ⊥ :=
@inf_nhds_at_top (order_dual α) _ _ _ _ x
lemma not_tendsto_nhds_of_tendsto_at_top [no_top_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_top_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_bot_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_bot_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 ∈ 𝓝[Ioi a] 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_sets_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 ∈ 𝓝[Ioi a] 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 ∈ 𝓝[Ioi a] 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_top_order α] {a : α} {s : set α} :
s ∈ 𝓝[Ioi a] a ↔ ∃u ∈ Ioi a, Ioo a u ⊆ s :=
let ⟨u', hu'⟩ := no_top 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_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ioi a] 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 ∈ 𝓝[Iio b] 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`
begin
have := @tfae_mem_nhds_within_Ioi (order_dual α) _ _ _ _ _ h s,
-- If we call `convert` here, it generates wrong equations, so we need to simplify first
simp only [exists_prop] at this ⊢,
rw [dual_Ioi, dual_Ioc, dual_Ioo] at this,
convert this; ext l; rw [dual_Ioo]
end
lemma mem_nhds_within_Iio_iff_exists_mem_Ico_Ioo_subset {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iio a] 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 ∈ 𝓝[Iio a] 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_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ioo l a ⊆ s :=
let ⟨l', hl'⟩ := no_bot 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_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iio a] a ↔ ∃l ∈ Iio a, Ico l a ⊆ s :=
begin
convert @mem_nhds_within_Ioi_iff_exists_Ioc_subset (order_dual α) _ _ _ _ _ _ _,
simp only [dual_Ioc], refl
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 ∈ 𝓝[Ici a] 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 : 4 → 5, from λ ⟨u, umem, hu⟩, ⟨u, umem.1, hu⟩,
tfae_have : 5 → 1,
{ rintros ⟨u, hau, hu⟩,
exact mem_sets_of_superset (Ico_mem_nhds_within_Ici ⟨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 ⟨hx.1, hx.2⟩, _⟩,
exact hx.1 },
tfae_finish
end
lemma mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset {a u' : α} {s : set α} (hu' : a < u') :
s ∈ 𝓝[Ici a] 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 ∈ 𝓝[Ici a] 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_top_order α] {a : α} {s : set α} :
s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, Ico a u ⊆ s :=
let ⟨u', hu'⟩ := no_top a in mem_nhds_within_Ici_iff_exists_Ico_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_Ici_iff_exists_Icc_subset' [no_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ici a] a ↔ ∃u ∈ Ioi a, 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 ∈ 𝓝[Iic b] 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`
begin
have := @tfae_mem_nhds_within_Ici (order_dual α) _ _ _ _ _ h s,
-- If we call `convert` here, it generates wrong equations, so we need to simplify first
simp only [exists_prop] at this ⊢,
rw [dual_Icc, dual_Ioc, dual_Ioi] at this,
convert this; ext l; rw [dual_Ico]
end
lemma mem_nhds_within_Iic_iff_exists_mem_Ico_Ioc_subset {a l' : α} {s : set α} (hl' : l' < a) :
s ∈ 𝓝[Iic a] 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 ∈ 𝓝[Iic a] 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_bot_order α] {a : α} {s : set α} :
s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Ioc l a ⊆ s :=
let ⟨l', hl'⟩ := no_bot 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_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l ∈ Iio a, Icc l a ⊆ s :=
begin
convert @mem_nhds_within_Ici_iff_exists_Icc_subset' (order_dual α) _ _ _ _ _ _ _,
simp_rw (show ∀ u : order_dual α, @Icc (order_dual α) _ a u = @Icc α _ u a, from λ u, dual_Icc),
refl,
end
/-- 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_top_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Ici a] 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
/-- 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_bot_order α] [densely_ordered α]
{a : α} {s : set α} : s ∈ 𝓝[Iic a] a ↔ ∃l, l < a ∧ Icc l a ⊆ s :=
begin
rw mem_nhds_within_Iic_iff_exists_Ioc_subset,
split,
{ rintros ⟨l, la, as⟩,
rcases exists_between la with ⟨v, hv⟩,
refine ⟨v, hv.2, λx hx, as ⟨lt_of_lt_of_le hv.1 hx.1, hx.2⟩⟩, },
{ rintros ⟨l, la, as⟩,
exact ⟨l, la, subset.trans Ioc_subset_Icc_self as⟩ }
end
end linear_order
section linear_ordered_ring
variables [topological_space α] [linear_ordered_ring α] [order_topology α]
variables {l : filter β} {f g : β → α}
/- TODO The theorems in this section ought to be written in the context of linearly ordered
(additive) commutative groups rather than linearly ordered rings; however, the former concept does
not currently exist in mathlib. -/
/-- In a linearly ordered ring with the order topology, if `f` tends to `C` and `g` tends to
`at_top` then `f + g` tends to `at_top`. -/
lemma tendsto_at_top_add_tendsto_left
{C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_top) :
tendsto (λ x, f x + g x) l at_top :=
begin
obtain ⟨C', hC'⟩ : ∃ C', C' < C := no_bot C,
refine tendsto_at_top_add_left_of_le' _ C' _ hg,
rw tendsto_order at hf,
exact (hf.1 C' hC').mp (eventually_of_forall (λ x hx, le_of_lt hx))
end
/-- In a linearly ordered ring with the order topology, if `f` tends to `C` and `g` tends to
`at_bot` then `f + g` tends to `at_bot`. -/
lemma tendsto_at_bot_add_tendsto_left
{C : α} (hf : tendsto f l (𝓝 C)) (hg : tendsto g l at_bot) :
tendsto (λ x, f x + g x) l at_bot :=
begin
obtain ⟨C', hC'⟩ : ∃ C', C < C' := no_top C,
refine tendsto_at_bot_add_left_of_ge' _ C' _ hg,
rw tendsto_order at hf,
exact (hf.2 C' hC').mp (eventually_of_forall (λ x hx, le_of_lt hx))
end
/-- In a linearly ordered ring with the order topology, if `f` tends to `at_top` and `g` tends to
`C` then `f + g` tends to `at_top`. -/
lemma tendsto_at_top_add_tendsto_right
{C : α} (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, f x + g x) l at_top :=
begin
convert tendsto_at_top_add_tendsto_left hg hf,
ext,
exact add_comm _ _,
end
/-- In a linearly ordered ring with the order topology, if `f` tends to `at_bot` and `g` tends to
`C` then `f + g` tends to `at_bot`. -/
lemma tendsto_at_bot_add_tendsto_right
{C : α} (hf : tendsto f l at_bot) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, f x + g x) l at_bot :=
begin
convert tendsto_at_bot_add_tendsto_left hg hf,
ext,
exact add_comm _ _,
end
end linear_ordered_ring
section linear_ordered_semiring
variables [linear_ordered_semiring α]
/-- The function `x^n` tends to `+∞` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_at_top`. -/
lemma tendsto_pow_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ n) at_top at_top :=
begin
rw tendsto_at_top_at_top,
intro b,
use max b 1,
intros x hx,
exact le_trans (le_of_max_le_left (by rwa pow_one x)) (pow_le_pow (le_of_max_le_right hx) hn),
end
variables [archimedean α]
variables {l : filter β} {f : β → α}
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `tendsto_at_top_mul_left'`). -/
lemma tendsto_at_top_mul_left {r : α} (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, r * f x) l at_top :=
begin
apply tendsto_at_top.2 (λb, _),
obtain ⟨n : ℕ, hn : 1 ≤ n •ℕ r⟩ := archimedean.arch 1 hr,
have hn' : 1 ≤ r * n, by rwa nsmul_eq_mul' at hn,
filter_upwards [tendsto_at_top.1 hf (n * max b 0)],
assume x hx,
calc b ≤ 1 * max b 0 : by { rw [one_mul], exact le_max_left _ _ }
... ≤ (r * n) * max b 0 : mul_le_mul_of_nonneg_right hn' (le_max_right _ _)
... = r * (n * max b 0) : by rw [mul_assoc]
... ≤ r * f x : mul_le_mul_of_nonneg_left hx (le_of_lt hr)
end
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. The archimedean assumption is convenient to get a
statement that works on `ℕ`, `ℤ` and `ℝ`, although not necessary (a version in ordered fields is
given in `tendsto_at_top_mul_right'`). -/
lemma tendsto_at_top_mul_right {r : α} (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, f x * r) l at_top :=
begin
apply tendsto_at_top.2 (λb, _),
obtain ⟨n : ℕ, hn : 1 ≤ n •ℕ r⟩ := archimedean.arch 1 hr,
have hn' : 1 ≤ (n : α) * r, by rwa nsmul_eq_mul at hn,
filter_upwards [tendsto_at_top.1 hf (max b 0 * n)],
assume x hx,
calc b ≤ max b 0 * 1 : by { rw [mul_one], exact le_max_left _ _ }
... ≤ max b 0 * (n * r) : mul_le_mul_of_nonneg_left hn' (le_max_right _ _)
... = (max b 0 * n) * r : by rw [mul_assoc]
... ≤ f x * r : mul_le_mul_of_nonneg_right hx (le_of_lt hr)
end
end linear_ordered_semiring
section linear_ordered_field
variables [linear_ordered_field α]
variables {l : filter β} {f g : β → α}
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the left) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`tendsto_at_top_mul_left` instead. -/
lemma tendsto_at_top_mul_left' {r : α} (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, r * f x) l at_top :=
begin
apply tendsto_at_top.2 (λb, _),
filter_upwards [tendsto_at_top.1 hf (b/r)],
assume x hx,
simpa [div_le_iff' hr] using hx
end
/-- If a function tends to infinity along a filter, then this function multiplied by a positive
constant (on the right) also tends to infinity. For a version working in `ℕ` or `ℤ`, use
`tendsto_at_top_mul_right` instead. -/
lemma tendsto_at_top_mul_right' {r : α} (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, f x * r) l at_top :=
by simpa [mul_comm] using tendsto_at_top_mul_left' hr hf
/-- If a function tends to infinity along a filter, then this function divided by a positive
constant also tends to infinity. -/
lemma tendsto_at_top_div {r : α} (hr : 0 < r) (hf : tendsto f l at_top) :
tendsto (λx, f x / r) l at_top :=
tendsto_at_top_mul_right' (inv_pos.2 hr) hf
variables [topological_space α] [order_topology α]
/-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to
a positive constant `C` then `f * g` tends to `at_top`. -/
lemma tendsto_mul_at_top {C : α} (hC : 0 < C) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_top :=
begin
refine tendsto_at_top_mono' _ _ (tendsto_at_top_mul_right' (half_pos hC) hf),
filter_upwards [hg (lt_mem_nhds (half_lt_self hC)), hf (eventually_ge_at_top 0)],
dsimp,
exact λ x hg hf, mul_le_mul_of_nonneg_left hg.le hf
end
/-- In a linearly ordered field with the order topology, if `f` tends to `at_top` and `g` tends to
a negative constant `C` then `f * g` tends to `at_bot`. -/
lemma tendsto_mul_at_bot {C : α} (hC : C < 0) (hf : tendsto f l at_top) (hg : tendsto g l (𝓝 C)) :
tendsto (λ x, (f x * g x)) l at_bot :=
begin
rw tendsto_at_bot,
rw tendsto_at_top at hf,
rw tendsto_order at hg,
intro b,
refine (hf (b/(C/2))).mp ((hg.2 (C/2) (by linarith)).mp ((hf 1).mp (eventually_of_forall _))),
intros x hx hltg hlef,
nlinarith [(div_le_iff_of_neg (div_neg_of_neg_of_pos hC zero_lt_two)).mp hlef],
end
end linear_ordered_field
section linear_ordered_field
variables [linear_ordered_field α] [topological_space α] [order_topology α]
/-- The function `x ↦ x⁻¹` tends to `+∞` on the right of `0`. -/
lemma tendsto_inv_zero_at_top : tendsto (λx:α, x⁻¹) (𝓝[set.Ioi (0:α)] 0) at_top :=
begin
apply tendsto_at_top.2 (λb, _),
refine mem_nhds_within_Ioi_iff_exists_Ioo_subset.2 ⟨(max b 1)⁻¹, by simp [zero_lt_one], λx hx, _⟩,
calc b ≤ max b 1 : le_max_left _ _
... ≤ x⁻¹ : begin
apply (le_inv _ hx.1).2 (le_of_lt hx.2),
exact lt_of_lt_of_le zero_lt_one (le_max_right _ _)
end
end
/-- The function `r ↦ r⁻¹` tends to `0` on the right as `r → +∞`. -/
lemma tendsto_inv_at_top_zero' : tendsto (λr:α, r⁻¹) at_top (𝓝[set.Ioi (0:α)] 0) :=
begin
assume s hs,
rw mem_nhds_within_Ioi_iff_exists_Ioc_subset at hs,
rcases hs with ⟨C, C0, hC⟩,
change 0 < C at C0,
refine filter.mem_map.2 (mem_sets_of_superset (mem_at_top C⁻¹) (λ x hx, hC _)),
have : 0 < x, from lt_of_lt_of_le (inv_pos.2 C0) hx,
exact ⟨inv_pos.2 this, (inv_le C0 this).1 hx⟩
end
lemma tendsto_inv_at_top_zero : tendsto (λr:α, r⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero'.mono_right inf_le_left
variables {l : filter β} {f : β → α}
lemma tendsto.inv_tendsto_at_top (h : tendsto f l at_top) : tendsto (f⁻¹) l (𝓝 0) :=
tendsto_inv_at_top_zero.comp h
lemma tendsto.inv_tendsto_zero (h : tendsto f l (𝓝[set.Ioi 0] 0)) : tendsto (f⁻¹) l at_top :=
tendsto_inv_zero_at_top.comp h
/-- The function `x^(-n)` tends to `0` at `+∞` for any positive natural `n`.
A version for positive real powers exists as `tendsto_rpow_neg_at_top`. -/
lemma tendsto_pow_neg_at_top {n : ℕ} (hn : 1 ≤ n) : tendsto (λ x : α, x ^ (-(n:ℤ))) at_top (𝓝 0) :=
tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) (λ x hx, (fpow_neg x n).symm))
(tendsto.inv_tendsto_at_top (tendsto_pow_at_top hn))
end linear_ordered_field
lemma preimage_neg [add_group α] : preimage (has_neg.neg : α → α) = image (has_neg.neg : α → α) :=
(image_eq_preimage_of_inverse neg_neg neg_neg).symm
lemma filter.map_neg [add_group α] : map (has_neg.neg : α → α) = comap (has_neg.neg : α → α) :=
funext $ assume f, map_eq_comap_of_inverse (funext neg_neg) (funext neg_neg)
section topological_add_group
variables [topological_space α] [ordered_add_comm_group α] [topological_add_group α]
lemma neg_preimage_closure {s : set α} : (λr:α, -r) ⁻¹' closure s = closure ((λr:α, -r) '' s) :=
have (λr:α, -r) ∘ (λr:α, -r) = id, from funext neg_neg,
by rw [preimage_neg]; exact
(subset.antisymm (image_closure_subset_closure_image continuous_neg) $
calc closure ((λ (r : α), -r) '' s) = (λr, -r) '' ((λr, -r) '' closure ((λ (r : α), -r) '' s)) :
by rw [←image_comp, this, image_id]
... ⊆ (λr, -r) '' closure ((λr, -r) '' ((λ (r : α), -r) '' s)) :
monotone_image $ image_closure_subset_closure_image continuous_neg
... = _ : by rw [←image_comp, this, image_id])
end topological_add_group
section order_topology
variables [topological_space α] [topological_space β]
[linear_order α] [linear_order β] [order_topology α] [order_topology β]
lemma is_lub.nhds_within_ne_bot {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
ne_bot (𝓝[s] a) :=
let ⟨a', ha'⟩ := hs in
forall_sets_nonempty_iff_ne_bot.mp $ assume t ht,
let ⟨t₁, ht₁, t₂, ht₂, ht⟩ := mem_inf_sets.mp ht in
by_cases
(assume h : a = a',
have a ∈ t₁, from mem_of_nhds ht₁,
have a ∈ t₂, from ht₂ $ by rwa [h],
⟨a, ht ⟨‹a ∈ t₁›, ‹a ∈ t₂›⟩⟩)
(assume : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left ‹a' ∈ s›) this.symm,
let ⟨l, hl, hlt₁⟩ := exists_Ioc_subset_of_mem_nhds ht₁ ⟨a', this⟩ in
have ∃a'∈s, l < a',
from classical.by_contradiction $ assume : ¬ ∃a'∈s, l < a',
have ∀a'∈s, a' ≤ l, from assume a ha, not_lt.1 $ assume ha', this ⟨a, ha, ha'⟩,
have ¬ l < a, from not_lt.2 $ ha.right this,
this ‹l < a›,
let ⟨a', ha', ha'l⟩ := this in
have a' ∈ t₁, from hlt₁ ⟨‹l < a'›, ha.left ha'⟩,
⟨a', ht ⟨‹a' ∈ t₁›, ht₂ ‹a' ∈ s›⟩⟩)
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 (order_dual α) _ _ _
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_sets hsf (mem_nhds_sets (is_open_lt' _) hba),
let ⟨x, ⟨hxs, hxb⟩⟩ := nonempty_of_mem_sets this in
have b < b, from lt_of_lt_of_le hxb $ hb hxs,
lt_irrefl b this⟩
lemma is_glb_of_mem_nhds : ∀ {s : set α} {a : α} {f : filter α},
a ∈ lower_bounds s → s ∈ f → ne_bot (f ⊓ 𝓝 a) → is_glb s a :=
@is_lub_of_mem_nhds (order_dual α) _ _ _
lemma is_lub_of_is_lub_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) (ha : is_lub s a) (hs : s.nonempty)
(hb : tendsto f (𝓝[s] a) (𝓝 b)) : is_lub (f '' s) b :=
have hnbot : ne_bot (𝓝[s] a), from ha.nhds_within_ne_bot hs,
have ∀a'∈s, ¬ b < f a',
from assume a' ha' h,
have ∀ᶠ x in 𝓝 b, x < f a', from mem_nhds_sets (is_open_gt' _) h,
let ⟨t₁, ht₁, t₂, ht₂, hs⟩ := mem_inf_sets.mp (hb this) in
by_cases
(assume h : a = a',
have a ∈ t₁ ∩ t₂, from ⟨mem_of_nhds ht₁, ht₂ $ by rwa [h]⟩,
have f a < f a', from hs this,
lt_irrefl (f a') $ by rwa [h] at this)
(assume h : a ≠ a',
have a' < a, from lt_of_le_of_ne (ha.left ha') h.symm,
have {x | a' < x} ∈ 𝓝 a, from mem_nhds_sets (is_open_lt' _) this,
have {x | a' < x} ∩ t₁ ∈ 𝓝 a, from inter_mem_sets this ht₁,
have ({x | a' < x} ∩ t₁) ∩ s ∈ 𝓝[s] a,
from inter_mem_inf_sets this (subset.refl s),
let ⟨x, ⟨hx₁, hx₂⟩, hx₃⟩ := hnbot.nonempty_of_mem this in
have hxa' : f x < f a', from hs ⟨hx₂, ht₂ hx₃⟩,
have ha'x : f a' ≤ f x, from hf _ ha' _ hx₃ $ le_of_lt hx₁,
lt_irrefl _ (lt_of_le_of_lt ha'x hxa')),
and.intro
(assume b' ⟨a', ha', h_eq⟩, h_eq ▸ not_lt.1 $ this _ ha')
(assume b' hb', by exactI (le_of_tendsto hb $
mem_inf_sets_of_right $ assume x hx, hb' $ mem_image_of_mem _ hx))
lemma is_glb_of_is_glb_of_tendsto {f : α → β} {s : set α} {a : α} {b : β}
(hf : ∀x∈s, ∀y∈s, x ≤ y → f x ≤ f y) : is_glb s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto (order_dual α) (order_dual β) _ _ _ _ _ _ f s a b
(λ x hx y hy, hf y hy x hx)
lemma is_glb_of_is_lub_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_lub s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_glb (f '' s) b :=
@is_lub_of_is_lub_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma is_lub_of_is_glb_of_tendsto : ∀ {f : α → β} {s : set α} {a : α} {b : β},
(∀x∈s, ∀y∈s, x ≤ y → f y ≤ f x) → is_glb s a → s.nonempty →
tendsto f (𝓝[s] a) (𝓝 b) → is_lub (f '' s) b :=
@is_glb_of_is_glb_of_tendsto α (order_dual β) _ _ _ _ _ _
lemma mem_closure_of_is_lub {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty) :
a ∈ closure s :=
by rw closure_eq_cluster_pts; exact ha.nhds_within_ne_bot hs
lemma mem_of_is_lub_of_is_closed {a : α} {s : set α} (ha : is_lub s a) (hs : s.nonempty)
(sc : is_closed s) : a ∈ s :=
by rw ←sc.closure_eq; exact mem_closure_of_is_lub ha hs
lemma mem_closure_of_is_glb {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty) :
a ∈ closure s :=
by rw closure_eq_cluster_pts; exact ha.nhds_within_ne_bot hs
lemma mem_of_is_glb_of_is_closed {a : α} {s : set α} (ha : is_glb s a) (hs : s.nonempty)
(sc : is_closed s) : a ∈ s :=
by rw ←sc.closure_eq; exact mem_closure_of_is_glb ha hs
/-- A compact set is bounded below -/
lemma is_compact.bdd_below {α : Type u} [topological_space α] [linear_order α]
[order_closed_topology α] [nonempty α] {s : set α} (hs : is_compact s) : bdd_below s :=
begin
by_contra H,
rcases hs.elim_finite_subcover_image (λ x (_ : x ∈ s), @is_open_Ioi _ _ _ _ x) _
with ⟨t, st, ft, ht⟩,
{ refine H (ft.bdd_below.imp $ λ C hC y hy, _),
rcases mem_bUnion_iff.1 (ht hy) with ⟨x, hx, xy⟩,
exact le_trans (hC hx) (le_of_lt xy) },
{ refine λ x hx, mem_bUnion_iff.2 (not_imp_comm.1 _ H),
exact λ h, ⟨x, λ y hy, le_of_not_lt (h.imp $ λ ys, ⟨_, hy, ys⟩)⟩ }
end
/-- A compact set is bounded above -/
lemma is_compact.bdd_above {α : Type u} [topological_space α] [linear_order α]
[order_topology α] : Π [nonempty α] {s : set α}, is_compact s → bdd_above s :=
@is_compact.bdd_below (order_dual α) _ _ _
end order_topology
section linear_order
variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α]
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`, unless `a` is a top
element. -/
lemma closure_Ioi' {a b : α} (hab : a < b) :
closure (Ioi a) = Ici a :=
begin
apply subset.antisymm,
{ exact closure_minimal Ioi_subset_Ici_self is_closed_Ici },
{ assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_glb is_glb_Ioi ⟨_, hab⟩ },
{ exact subset_closure (lt_of_le_of_ne hx (ne.symm h)) } }
end
/-- The closure of the interval `(a, +∞)` is the closed interval `[a, +∞)`. -/
@[simp] lemma closure_Ioi (a : α) [no_top_order α] :
closure (Ioi a) = Ici a :=
let ⟨b, hb⟩ := no_top a in closure_Ioi' hb
/-- The closure of the interval `(-∞, a)` is the closed interval `(-∞, a]`, unless `a` is a bottom
element. -/
lemma closure_Iio' {a b : α} (hab : b < a) :
closure (Iio a) = Iic a :=
begin
apply subset.antisymm,
{ exact closure_minimal Iio_subset_Iic_self is_closed_Iic },
{ assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_lub is_lub_Iio ⟨_, hab⟩ },
{ apply subset_closure, by simpa [h] using lt_or_eq_of_le hx } }
end
/-- The closure of the interval `(-∞, a)` is the interval `(-∞, a]`. -/
@[simp] lemma closure_Iio (a : α) [no_bot_order α] :
closure (Iio a) = Iic a :=
let ⟨b, hb⟩ := no_bot a in closure_Iio' hb
/-- 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 },
{ have hab' : (Ioo a b).nonempty, from nonempty_Ioo.2 hab,
assume x hx,
by_cases h : x = a,
{ rw h, exact mem_closure_of_is_glb (is_glb_Ioo hab) hab' },
by_cases h' : x = b,
{ rw h', refine mem_closure_of_is_lub (is_lub_Ioo hab) hab' },
exact subset_closure ⟨lt_of_le_of_ne hx.1 (ne.symm h), by simpa [h'] using lt_or_eq_of_le hx.2⟩ }
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 [no_bot_order α] {a : α} : interior (Ici a) = Ioi a :=
by rw [← compl_Iio, interior_compl, closure_Iio, compl_Iic]
@[simp] lemma interior_Iic [no_top_order α] {a : α} : interior (Iic a) = Iio a :=
by rw [← compl_Ioi, interior_compl, closure_Ioi, compl_Ici]
@[simp] lemma interior_Icc [no_bot_order α] [no_top_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_bot_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_top_order α] {a b : α} : interior (Ioc a b) = Ioo a b :=
by rw [← Ioi_inter_Iic, interior_inter, interior_Ioi, interior_Iic, Ioi_inter_Iio]
@[simp] lemma frontier_Ici [no_bot_order α] {a : α} : frontier (Ici a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Iic [no_top_order α] {a : α} : frontier (Iic a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Ioi [no_top_order α] {a : α} : frontier (Ioi a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Iio [no_bot_order α] {a : α} : frontier (Iio a) = {a} :=
by simp [frontier]
@[simp] lemma frontier_Icc [no_bot_order α] [no_top_order α] {a b : α} (h : a < b) :
frontier (Icc a b) = {a, b} :=
by simp [frontier, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ioo {a b : α} (h : a < b) : frontier (Ioo a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ico [no_bot_order α] {a b : α} (h : a < b) : frontier (Ico a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
@[simp] lemma frontier_Ioc [no_top_order α] {a b : α} (h : a < b) : frontier (Ioc a b) = {a, b} :=
by simp [frontier, h, le_of_lt h, Icc_diff_Ioo_same]
lemma nhds_within_Ioi_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : a ≤ b) :
ne_bot (𝓝[Ioi a] b) :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Ioi' H₁], exact H₂ }
lemma nhds_within_Ioi_ne_bot [no_top_order α] {a b : α} (H : a ≤ b) :
ne_bot (𝓝[Ioi a] b) :=
let ⟨c, hc⟩ := no_top a in nhds_within_Ioi_ne_bot' hc H
lemma nhds_within_Ioi_self_ne_bot' {a b : α} (H : a < b) :
ne_bot (𝓝[Ioi a] a) :=
nhds_within_Ioi_ne_bot' H (le_refl a)
@[instance]
lemma nhds_within_Ioi_self_ne_bot [no_top_order α] (a : α) :
ne_bot (𝓝[Ioi a] a) :=
nhds_within_Ioi_ne_bot (le_refl a)
lemma nhds_within_Iio_ne_bot' {a b c : α} (H₁ : a < c) (H₂ : b ≤ c) :
ne_bot (𝓝[Iio c] b) :=
mem_closure_iff_nhds_within_ne_bot.1 $ by { rw [closure_Iio' H₁], exact H₂ }
lemma nhds_within_Iio_ne_bot [no_bot_order α] {a b : α} (H : a ≤ b) :
ne_bot (𝓝[Iio b] a) :=
let ⟨c, hc⟩ := no_bot b in nhds_within_Iio_ne_bot' hc H
lemma nhds_within_Iio_self_ne_bot' {a b : α} (H : a < b) :
ne_bot (𝓝[Iio b] b) :=
nhds_within_Iio_ne_bot' H (le_refl b)
@[instance]
lemma nhds_within_Iio_self_ne_bot [no_bot_order α] (a : α) :
ne_bot (𝓝[Iio a] a) :=
nhds_within_Iio_ne_bot (le_refl a)
end linear_order
section linear_order
variables [topological_space α] [linear_order α] [order_topology α] [densely_ordered α]
{a b : α} {s : set α}
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 → α) (𝓝[Iio b] 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_sets_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 → α) (𝓝[Ioi a] a) = at_bot :=
begin
refine @comap_coe_nhds_within_Iio_of_Ioo_subset (order_dual α) _ _ _ _ _ _ ha (λ h, _),
rcases hs h with ⟨b, hab, h⟩,
use [b, hab],
rwa dual_Ioo
end
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 = 𝓝[Iio b] b :=
begin
rcases eq_empty_or_nonempty (Iio b) with (hb'|⟨a, ha⟩),
{ rw [filter_eq_bot_of_not_nonempty at_top, map_bot, hb', nhds_within_empty],
exact λ ⟨⟨x, hx⟩⟩, not_nonempty_iff_eq_empty.2 hb' ⟨x, hb hx⟩ },
{ rw [← comap_coe_nhds_within_Iio_of_Ioo_subset hb (λ _, hs a ha), map_comap],
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 = (𝓝[Ioi a] a) :=
begin
refine @map_coe_at_top_of_Ioo_subset (order_dual α) _ _ _ _ a s ha (λ b' hb', _),
rcases hs b' hb' with ⟨b, hab, hbs⟩,
use [b, hab],
rwa dual_Ioo
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 → α) (𝓝[Iio 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 → α) (𝓝[Ioi a] 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 → α) (𝓝[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 → α) (𝓝[Iio a] a) = at_top :=
@comap_coe_Ioi_nhds_within_Ioi (order_dual α) _ _ _ _ a
@[simp] lemma map_coe_Ioo_at_top {a b : α} (h : a < b) :
map (coe : Ioo a b → α) at_top = 𝓝[Iio b] 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 = 𝓝[Ioi a] 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 = 𝓝[Ioi a] 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 = 𝓝[Iio a] a :=
@map_coe_Ioi_at_bot (order_dual α) _ _ _ _ _
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 (𝓝[Iio b] 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 (𝓝[Ioi a] 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 (𝓝[Ioi a] 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 (𝓝[Iio a] 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 (𝓝[Iio b] 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 (𝓝[Ioi a] 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 (𝓝[Ioi a] 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 (𝓝[Iio a] a) :=
by rw [← comap_coe_Iio_nhds_within_Iio, tendsto_comap_iff]
end linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [order_topology α]
[complete_linear_order β] [topological_space β] [order_topology β] [nonempty γ]
lemma Sup_mem_closure {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) :
Sup s ∈ closure s :=
mem_closure_of_is_lub (is_lub_Sup _) hs
lemma Inf_mem_closure {α : Type u} [topological_space α] [complete_linear_order α]
[order_topology α] {s : set α} (hs : s.nonempty) :
Inf s ∈ closure s :=
mem_closure_of_is_glb (is_glb_Inf _) 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 :=
mem_of_is_lub_of_is_closed (is_lub_Sup _) 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 :=
mem_of_is_glb_of_is_closed (is_glb_Inf _) 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 map_Sup_of_continuous_at_of_monotone' {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_of_is_lub_of_tendsto
(is_lub_of_is_lub_of_tendsto (λ x hx y hy xy, Mf xy) (is_lub_Sup _) hs $
Cf.mono_left inf_le_left).Sup_eq.symm
/-- A monotone function `s` 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 map_Sup_of_continuous_at_of_monotone {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 map_Sup_of_continuous_at_of_monotone' Cf Mf 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 map_supr_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α}
(Cf : continuous_at f (supr g)) (Mf : monotone f) :
f (⨆ i, g i) = ⨆ i, f (g i) :=
by rw [supr, map_Sup_of_continuous_at_of_monotone' Cf Mf (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 map_supr_of_continuous_at_of_monotone {ι : 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, map_Sup_of_continuous_at_of_monotone Cf Mf 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 map_Inf_of_continuous_at_of_monotone' {f : α → β} {s : set α} (Cf : continuous_at f (Inf s))
(Mf : monotone f) (hs : s.nonempty) :
f (Inf s) = Inf (f '' s) :=
@map_Sup_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_dual hs
/-- A monotone function `s` 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 map_Inf_of_continuous_at_of_monotone {f : α → β} {s : set α} (Cf : continuous_at f (Inf s))
(Mf : monotone f) (ftop : f ⊤ = ⊤) :
f (Inf s) = Inf (f '' s) :=
@map_Sup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_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 map_infi_of_continuous_at_of_monotone' {ι : Sort*} [nonempty ι] {f : α → β} {g : ι → α}
(Cf : continuous_at f (infi g)) (Mf : monotone f) :
f (⨅ i, g i) = ⨅ i, f (g i) :=
@map_supr_of_continuous_at_of_monotone' (order_dual α) (order_dual β) _ _ _ _ _ _ ι _ f g Cf
Mf.order_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 map_infi_of_continuous_at_of_monotone {ι : Sort*} {f : α → β} {g : ι → α}
(Cf : continuous_at f (infi g)) (Mf : monotone f) (ftop : f ⊤ = ⊤) :
f (infi g) = infi (f ∘ g) :=
@map_supr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ ι f g Cf
Mf.order_dual 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_topology β] [nonempty γ]
lemma cSup_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_above s) : Sup s ∈ closure s :=
mem_closure_of_is_lub (is_lub_cSup hs B) hs
lemma cInf_mem_closure {s : set α} (hs : s.nonempty) (B : bdd_below s) : Inf s ∈ closure s :=
mem_closure_of_is_glb (is_glb_cInf hs B) hs
lemma is_closed.cSup_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_above s) :
Sup s ∈ s :=
mem_of_is_lub_of_is_closed (is_lub_cSup hs B) hs hc
lemma is_closed.cInf_mem {s : set α} (hc : is_closed s) (hs : s.nonempty) (B : bdd_below s) :
Inf s ∈ s :=
mem_of_is_glb_of_is_closed (is_glb_cInf hs B) 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 map_cSup_of_continuous_at_of_monotone {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_of_is_lub_of_tendsto (λx hx y hy xy, Mf xy) (is_lub_cSup ne H) 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 map_csupr_of_continuous_at_of_monotone {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, map_cSup_of_continuous_at_of_monotone Cf Mf (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 map_cInf_of_continuous_at_of_monotone {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) :=
@map_cSup_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ f s Cf
Mf.order_dual ne H
/-- A continuous monotone function sends indexed infimum to indexed infimum in conditionally
complete linear order, under a boundedness assumption. -/
lemma map_cinfi_of_continuous_at_of_monotone {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) :=
@map_csupr_of_continuous_at_of_monotone (order_dual α) (order_dual β) _ _ _ _ _ _ _ _ _ _
Cf Mf.order_dual H
/-- A bounded connected subset of a conditionally complete linear order includes the open interval
`(Inf s, Sup s)`. -/
lemma is_connected.Ioo_cInf_cSup_subset {s : set α} (hs : is_connected s) (hb : bdd_below s)
(ha : bdd_above s) :
Ioo (Inf s) (Sup s) ⊆ s :=
λ x hx, let ⟨y, ys, hy⟩ := (is_glb_lt_iff (is_glb_cInf hs.nonempty hb)).1 hx.1 in
let ⟨z, zs, hz⟩ := (lt_is_lub_iff (is_lub_cSup hs.nonempty ha)).1 hx.2 in
hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
lemma eq_Icc_cInf_cSup_of_connected_bdd_closed {s : set α} (hc : is_connected s) (hb : bdd_below s)
(ha : bdd_above s) (hcl : is_closed s) :
s = Icc (Inf s) (Sup s) :=
subset.antisymm (subset_Icc_cInf_cSup hb ha) $
hc.Icc_subset (hcl.cInf_mem hc.nonempty hb) (hcl.cSup_mem hc.nonempty ha)
lemma is_preconnected.Ioi_cInf_subset {s : set α} (hs : is_preconnected s) (hb : bdd_below s)
(ha : ¬bdd_above s) :
Ioi (Inf s) ⊆ s :=
begin
have sne : s.nonempty := @nonempty_of_not_bdd_above α _ s ⟨Inf ∅⟩ ha,
intros x hx,
obtain ⟨y, ys, hy⟩ : ∃ y ∈ s, y < x := (is_glb_lt_iff (is_glb_cInf sne hb)).1 hx,
obtain ⟨z, zs, hz⟩ : ∃ z ∈ s, x < z := not_bdd_above_iff.1 ha x,
exact hs.Icc_subset ys zs ⟨le_of_lt hy, le_of_lt hz⟩
end
lemma is_preconnected.Iio_cSup_subset {s : set α} (hs : is_preconnected s) (hb : ¬bdd_below s)
(ha : bdd_above s) :
Iio (Sup s) ⊆ s :=
@is_preconnected.Ioi_cInf_subset (order_dual α) _ _ _ s hs ha hb
/-- A preconnected set in a conditionally complete linear order is either one of the intervals
`[Inf s, Sup s]`, `[Inf s, Sup s)`, `(Inf s, Sup s]`, `(Inf s, Sup s)`, `[Inf s, +∞)`,
`(Inf s, +∞)`, `(-∞, Sup s]`, `(-∞, Sup s)`, `(-∞, +∞)`, or `∅`. The converse statement requires
`α` to be densely ordererd. -/
lemma is_preconnected.mem_intervals {s : set α} (hs : is_preconnected s) :
s ∈ ({Icc (Inf s) (Sup s), Ico (Inf s) (Sup s), Ioc (Inf s) (Sup s), Ioo (Inf s) (Sup s),
Ici (Inf s), Ioi (Inf s), Iic (Sup s), Iio (Sup s), univ, ∅} : set (set α)) :=
begin
rcases s.eq_empty_or_nonempty with rfl|hne,
{ apply_rules [or.inr, mem_singleton] },
have hs' : is_connected s := ⟨hne, hs⟩,
by_cases hb : bdd_below s; by_cases ha : bdd_above s,
{ rcases mem_Icc_Ico_Ioc_Ioo_of_subset_of_subset (hs'.Ioo_cInf_cSup_subset hb ha)
(subset_Icc_cInf_cSup hb ha) with hs|hs|hs|hs,
{ exact (or.inl hs) },
{ exact (or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inr $ or.inl hs) } },
{ refine (or.inr $ or.inr $ or.inr $ or.inr _),
cases mem_Ici_Ioi_of_subset_of_subset (hs.Ioi_cInf_subset hb ha) (λ x hx, cInf_le hb hx)
with hs hs,
{ exact or.inl hs },
{ exact or.inr (or.inl hs) } },
{ iterate 6 { apply or.inr },
cases mem_Iic_Iio_of_subset_of_subset (hs.Iio_cSup_subset hb ha) (λ x hx, le_cSup ha hx)
with hs hs,
{ exact or.inl hs },
{ exact or.inr (or.inl hs) } },
{ iterate 8 { apply or.inr },
exact or.inl (hs.eq_univ_of_unbounded hb ha) }
end
/-- A preconnected set is either one of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`,
`Iic`, `Iio`, or `univ`, or `∅`. The converse statement requires `α` to be densely ordererd. Though
one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of possible cases to improve
readability. -/
lemma set_of_is_preconnected_subset_of_ordered :
{s : set α | is_preconnected s} ⊆
-- bounded intervals
(range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪
-- unbounded intervals and `univ`
(range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) :=
begin
intros s hs,
rcases hs.mem_intervals with hs|hs|hs|hs|hs|hs|hs|hs|hs|hs,
{ exact (or.inl $ or.inl $ or.inl $ or.inl ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inl $ or.inr ⟨(Inf s, Sup s), hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inl ⟨Inf s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inl $ or.inr ⟨Inf s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) },
{ exact (or.inr $ or.inl $ or.inr ⟨Sup s, hs.symm⟩) },
{ exact (or.inr $ or.inr $ or.inl hs) },
{ exact (or.inr $ or.inr $ or.inr hs) }
end
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and the set `s ∩ [a, b)` has no maximal point, then `b ∈ s`. -/
lemma is_closed.mem_of_ge_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b))
(ha : a ∈ s) (hab : a ≤ b) (hgt : ∀ x ∈ s ∩ Ico a b, (s ∩ Ioc x b).nonempty) :
b ∈ s :=
begin
let S := s ∩ Icc a b,
replace ha : a ∈ S, from ⟨ha, left_mem_Icc.2 hab⟩,
have Sbd : bdd_above S, from ⟨b, λ z hz, hz.2.2⟩,
let c := Sup (s ∩ Icc a b),
have c_mem : c ∈ S, from hs.cSup_mem ⟨_, ha⟩ Sbd,
have c_le : c ≤ b, from cSup_le ⟨_, ha⟩ (λ x hx, hx.2.2),
cases eq_or_lt_of_le c_le with hc hc, from hc ▸ c_mem.1,
exfalso,
rcases hgt c ⟨c_mem.1, c_mem.2.1, hc⟩ with ⟨x, xs, cx, xb⟩,
exact not_lt_of_le (le_cSup Sbd ⟨xs, le_trans (le_cSup Sbd ha) (le_of_lt cx), xb⟩) cx
end
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `a ≤ x < y ≤ b`, `x ∈ s`, the set `s ∩ (x, y]`
is not empty, then `[a, b] ⊆ s`. -/
lemma is_closed.Icc_subset_of_forall_exists_gt {a b : α} {s : set α} (hs : is_closed (s ∩ Icc a b))
(ha : a ∈ s) (hgt : ∀ x ∈ s ∩ Ico a b, ∀ y ∈ Ioi x, (s ∩ Ioc x y).nonempty) :
Icc a b ⊆ s :=
begin
assume y hy,
have : is_closed (s ∩ Icc a y),
{ suffices : s ∩ Icc a y = s ∩ Icc a b ∩ Icc a y,
{ rw this, exact is_closed_inter hs is_closed_Icc },
rw [inter_assoc],
congr,
exact (inter_eq_self_of_subset_right $ Icc_subset_Icc_right hy.2).symm },
exact is_closed.mem_of_ge_of_forall_exists_gt this ha hy.1
(λ x hx, hgt x ⟨hx.1, Ico_subset_Ico_right hy.2 hx.2⟩ y hx.2.2)
end
section densely_ordered
variables [densely_ordered α] {a b : α}
/-- A "continuous induction principle" for a closed interval: if a set `s` meets `[a, b]`
on a closed subset, contains `a`, and for any `x ∈ s ∩ [a, b)` the set `s` includes some open
neighborhood of `x` within `(x, +∞)`, then `[a, b] ⊆ s`. -/
lemma is_closed.Icc_subset_of_forall_mem_nhds_within {a b : α} {s : set α}
(hs : is_closed (s ∩ Icc a b)) (ha : a ∈ s)
(hgt : ∀ x ∈ s ∩ Ico a b, s ∈ 𝓝[Ioi x] x) :
Icc a b ⊆ s :=
begin
apply hs.Icc_subset_of_forall_exists_gt ha,
rintros x ⟨hxs, hxab⟩ y hyxb,
have : s ∩ Ioc x y ∈ 𝓝[Ioi x] x,
from inter_mem_sets (hgt x ⟨hxs, hxab⟩) (Ioc_mem_nhds_within_Ioi ⟨le_refl _, hyxb⟩),
exact (nhds_within_Ioi_self_ne_bot' hxab.2).nonempty_of_mem this
end
/-- A closed interval in a densely ordered conditionally complete linear order is preconnected. -/
lemma is_preconnected_Icc : is_preconnected (Icc a b) :=
is_preconnected_closed_iff.2
begin
rintros s t hs ht hab ⟨x, hx⟩ ⟨y, hy⟩,
wlog hxy : x ≤ y := le_total x y using [x y s t, y x t s],
have xyab : Icc x y ⊆ Icc a b := Icc_subset_Icc hx.1.1 hy.1.2,
by_contradiction hst,
suffices : Icc x y ⊆ s,
from hst ⟨y, xyab $ right_mem_Icc.2 hxy, this $ right_mem_Icc.2 hxy, hy.2⟩,
apply (is_closed_inter hs is_closed_Icc).Icc_subset_of_forall_mem_nhds_within hx.2,
rintros z ⟨zs, hz⟩,
have zt : z ∈ tᶜ, from λ zt, hst ⟨z, xyab $ Ico_subset_Icc_self hz, zs, zt⟩,
have : tᶜ ∩ Ioc z y ∈ 𝓝[Ioi z] z,
{ rw [← nhds_within_Ioc_eq_nhds_within_Ioi hz.2],
exact mem_nhds_within.2 ⟨tᶜ, ht, zt, subset.refl _⟩},
apply mem_sets_of_superset this,
have : Ioc z y ⊆ s ∪ t, from λ w hw, hab (xyab ⟨le_trans hz.1 (le_of_lt hw.1), hw.2⟩),
exact λ w ⟨wt, wzy⟩, (this wzy).elim id (λ h, (wt h).elim)
end
lemma is_preconnected_interval : is_preconnected (interval a b) := is_preconnected_Icc
lemma is_preconnected_iff_ord_connected {s : set α} :
is_preconnected s ↔ ord_connected s :=
⟨λ h x hx y hy, h.Icc_subset hx hy, λ h, is_preconnected_of_forall_pair $ λ x y hx hy,
⟨interval x y, h.interval_subset hx hy, left_mem_interval, right_mem_interval,
is_preconnected_interval⟩⟩
alias is_preconnected_iff_ord_connected ↔
is_preconnected.ord_connected set.ord_connected.is_preconnected
lemma is_preconnected_Ici : is_preconnected (Ici a) := ord_connected_Ici.is_preconnected
lemma is_preconnected_Iic : is_preconnected (Iic a) := ord_connected_Iic.is_preconnected
lemma is_preconnected_Iio : is_preconnected (Iio a) := ord_connected_Iio.is_preconnected
lemma is_preconnected_Ioi : is_preconnected (Ioi a) := ord_connected_Ioi.is_preconnected
lemma is_preconnected_Ioo : is_preconnected (Ioo a b) := ord_connected_Ioo.is_preconnected
lemma is_preconnected_Ioc : is_preconnected (Ioc a b) := ord_connected_Ioc.is_preconnected
lemma is_preconnected_Ico : is_preconnected (Ico a b) := ord_connected_Ico.is_preconnected
@[priority 100]
instance ordered_connected_space : preconnected_space α :=
⟨ord_connected_univ.is_preconnected⟩
/-- In a dense conditionally complete linear order, the set of preconnected sets is exactly
the set of the intervals `Icc`, `Ico`, `Ioc`, `Ioo`, `Ici`, `Ioi`, `Iic`, `Iio`, `(-∞, +∞)`,
or `∅`. Though one can represent `∅` as `(Inf s, Inf s)`, we include it into the list of
possible cases to improve readability. -/
lemma set_of_is_preconnected_eq_of_ordered :
{s : set α | is_preconnected s} =
-- bounded intervals
(range (uncurry Icc) ∪ range (uncurry Ico) ∪ range (uncurry Ioc) ∪ range (uncurry Ioo)) ∪
-- unbounded intervals and `univ`
(range Ici ∪ range Ioi ∪ range Iic ∪ range Iio ∪ {univ, ∅}) :=
begin
refine subset.antisymm set_of_is_preconnected_subset_of_ordered _,
simp only [subset_def, -mem_range, forall_range_iff, uncurry, or_imp_distrib, forall_and_distrib,
mem_union, mem_set_of_eq, insert_eq, mem_singleton_iff, forall_eq, forall_true_iff, and_true,
is_preconnected_Icc, is_preconnected_Ico, is_preconnected_Ioc,
is_preconnected_Ioo, is_preconnected_Ioi, is_preconnected_Iio, is_preconnected_Ici,
is_preconnected_Iic, is_preconnected_univ, is_preconnected_empty],
end
variables {δ : Type*} [linear_order δ] [topological_space δ] [order_closed_topology δ]
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≤ t ≤ f b`.-/
lemma intermediate_value_Icc {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) :
Icc (f a) (f b) ⊆ f '' (Icc a b) :=
is_preconnected_Icc.intermediate_value (left_mem_Icc.2 hab) (right_mem_Icc.2 hab) hf
/--Intermediate Value Theorem for continuous functions on closed intervals, case `f a ≥ t ≥ f b`.-/
lemma intermediate_value_Icc' {a b : α} (hab : a ≤ b) {f : α → δ} (hf : continuous_on f (Icc a b)) :
Icc (f b) (f a) ⊆ f '' (Icc a b) :=
is_preconnected_Icc.intermediate_value (right_mem_Icc.2 hab) (left_mem_Icc.2 hab) hf
/-- A continuous function which tendsto `at_top` `at_top` and to `at_bot` `at_bot` is surjective. -/
lemma surjective_of_continuous {f : α → δ} (hf : continuous f) (h_top : tendsto f at_top at_top)
(h_bot : tendsto f at_bot at_bot) :
function.surjective f :=
λ p, mem_range_of_exists_le_of_exists_ge hf
(h_bot.eventually (eventually_le_at_bot p)).exists
(h_top.eventually (eventually_ge_at_top p)).exists
/-- A continuous function which tendsto `at_bot` `at_top` and to `at_top` `at_bot` is surjective. -/
lemma surjective_of_continuous' {f : α → δ} (hf : continuous f) (h_top : tendsto f at_bot at_top)
(h_bot : tendsto f at_top at_bot) :
function.surjective f :=
@surjective_of_continuous (order_dual α) _ _ _ _ _ _ _ _ _ hf h_top h_bot
end densely_ordered
lemma is_compact.Inf_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
Inf s ∈ s :=
hs.is_closed.cInf_mem ne_s hs.bdd_below
lemma is_compact.Sup_mem {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
Sup s ∈ s :=
@is_compact.Inf_mem (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.is_glb_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_glb s (Inf s) :=
is_glb_cInf ne_s hs.bdd_below
lemma is_compact.is_lub_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_lub s (Sup s) :=
@is_compact.is_glb_Inf (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.is_least_Inf {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_least s (Inf s) :=
⟨hs.Inf_mem ne_s, (hs.is_glb_Inf ne_s).1⟩
lemma is_compact.is_greatest_Sup {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
is_greatest s (Sup s) :=
@is_compact.is_least_Inf (order_dual α) _ _ _ _ hs ne_s
lemma is_compact.exists_is_least {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x, is_least s x :=
⟨_, hs.is_least_Inf ne_s⟩
lemma is_compact.exists_is_greatest {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x, is_greatest s x :=
⟨_, hs.is_greatest_Sup ne_s⟩
lemma is_compact.exists_is_glb {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x ∈ s, is_glb s x :=
⟨_, hs.Inf_mem ne_s, hs.is_glb_Inf ne_s⟩
lemma is_compact.exists_is_lub {s : set α} (hs : is_compact s) (ne_s : s.nonempty) :
∃ x ∈ s, is_lub s x :=
⟨_, hs.Sup_mem ne_s, hs.is_lub_Sup ne_s⟩
lemma is_compact.exists_Inf_image_eq {α : Type u} [topological_space α]
{s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) :
∃ x ∈ s, Inf (f '' s) = f x :=
let ⟨x, hxs, hx⟩ := (hs.image_of_continuous_on hf).Inf_mem (ne_s.image f)
in ⟨x, hxs, hx.symm⟩
lemma is_compact.exists_Sup_image_eq {α : Type u} [topological_space α]:
∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s →
∃ x ∈ s, Sup (f '' s) = f x :=
@is_compact.exists_Inf_image_eq (order_dual β) _ _ _ _ _
lemma eq_Icc_of_connected_compact {s : set α} (h₁ : is_connected s) (h₂ : is_compact s) :
s = Icc (Inf s) (Sup s) :=
eq_Icc_cInf_cSup_of_connected_bdd_closed h₁ h₂.bdd_below h₂.bdd_above h₂.is_closed
/-- The extreme value theorem: a continuous function realizes its minimum on a compact set -/
lemma is_compact.exists_forall_le {α : Type u} [topological_space α]
{s : set α} (hs : is_compact s) (ne_s : s.nonempty) {f : α → β} (hf : continuous_on f s) :
∃x∈s, ∀y∈s, f x ≤ f y :=
begin
rcases hs.exists_Inf_image_eq ne_s hf with ⟨x, hxs, hx⟩,
refine ⟨x, hxs, λ y hy, _⟩,
rw ← hx,
exact ((hs.image_of_continuous_on hf).is_glb_Inf (ne_s.image f)).1 (mem_image_of_mem _ hy)
end
/-- The extreme value theorem: a continuous function realizes its maximum on a compact set -/
lemma is_compact.exists_forall_ge {α : Type u} [topological_space α]:
∀ {s : set α}, is_compact s → s.nonempty → ∀ {f : α → β}, continuous_on f s →
∃x∈s, ∀y∈s, f y ≤ f x :=
@is_compact.exists_forall_le (order_dual β) _ _ _ _ _
/-- The extreme value theorem: if a continuous function `f` tends to infinity away from compact
sets, then it has a global minimum. -/
lemma continuous.exists_forall_le {α : Type*} [topological_space α] [nonempty α] {f : α → β}
(hf : continuous f) (hlim : tendsto f (cocompact α) at_top) :
∃ x, ∀ y, f x ≤ f y :=
begin
inhabit α,
obtain ⟨s : set α, hsc : is_compact s, hsf : ∀ x ∉ s, f (default α) ≤ f x⟩ :=
(has_basis_cocompact.tendsto_iff at_top_basis).1 hlim (f $ default α) trivial,
obtain ⟨x, -, hx⟩ :=
(hsc.insert (default α)).exists_forall_le (nonempty_insert _ _) hf.continuous_on,
refine ⟨x, λ y, _⟩,
by_cases hy : y ∈ s,
exacts [hx y (or.inr hy), (hx _ (or.inl rfl)).trans (hsf y hy)]
end
/-- The extreme value theorem: if a continuous function `f` tends to negative infinity away from
compactx sets, then it has a global maximum. -/
lemma continuous.exists_forall_ge {α : Type*} [topological_space α] [nonempty α] {f : α → β}
(hf : continuous f) (hlim : tendsto f (cocompact α) at_bot) :
∃ x, ∀ y, f y ≤ f x :=
@continuous.exists_forall_le (order_dual β) _ _ _ _ _ _ _ hf hlim
end conditionally_complete_linear_order
section liminf_limsup
section order_closed_topology
variables [semilattice_sup α] [topological_space α] [order_topology α]
lemma is_bounded_le_nhds (a : α) : (𝓝 a).is_bounded (≤) :=
match forall_le_or_exists_lt_sup a with
| or.inl h := ⟨a, eventually_of_forall h⟩
| or.inr ⟨b, hb⟩ := ⟨b, ge_mem_nhds hb⟩
end
lemma filter.tendsto.is_bounded_under_le {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (𝓝 a)) : f.is_bounded_under (≤) u :=
(is_bounded_le_nhds a).mono h
lemma is_cobounded_ge_nhds (a : α) : (𝓝 a).is_cobounded (≥) :=
(is_bounded_le_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_ge {f : filter β} {u : β → α} {a : α}
[ne_bot f] (h : tendsto u f (𝓝 a)) : f.is_cobounded_under (≥) u :=
h.is_bounded_under_le.is_cobounded_flip
end order_closed_topology
section order_closed_topology
variables [semilattice_inf α] [topological_space α] [order_topology α]
lemma is_bounded_ge_nhds (a : α) : (𝓝 a).is_bounded (≥) :=
@is_bounded_le_nhds (order_dual α) _ _ _ a
lemma filter.tendsto.is_bounded_under_ge {f : filter β} {u : β → α} {a : α}
(h : tendsto u f (𝓝 a)) : f.is_bounded_under (≥) u :=
(is_bounded_ge_nhds a).mono h
lemma is_cobounded_le_nhds (a : α) : (𝓝 a).is_cobounded (≤) :=
(is_bounded_ge_nhds a).is_cobounded_flip
lemma filter.tendsto.is_cobounded_under_le {f : filter β} {u : β → α} {a : α}
[ne_bot f] (h : tendsto u f (𝓝 a)) : f.is_cobounded_under (≤) u :=
h.is_bounded_under_ge.is_cobounded_flip
end order_closed_topology
section conditionally_complete_linear_order
variables [conditionally_complete_linear_order α]
theorem lt_mem_sets_of_Limsup_lt {f : filter α} {b} (h : f.is_bounded (≤)) (l : f.Limsup < b) :
∀ᶠ a in f, a < b :=
let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_cInf_lt h l in
mem_sets_of_superset h $ assume a hac, lt_of_le_of_lt hac hcb
theorem gt_mem_sets_of_Liminf_gt : ∀ {f : filter α} {b}, f.is_bounded (≥) → b < f.Liminf →
∀ᶠ a in f, b < a :=
@lt_mem_sets_of_Limsup_lt (order_dual α) _
variables [topological_space α] [order_topology α]
/-- If the liminf and the limsup of a filter coincide, then this filter converges to
their common value, at least if the filter is eventually bounded above and below. -/
theorem le_nhds_of_Limsup_eq_Liminf {f : filter α} {a : α}
(hl : f.is_bounded (≤)) (hg : f.is_bounded (≥)) (hs : f.Limsup = a) (hi : f.Liminf = a) :
f ≤ 𝓝 a :=
tendsto_order.2 $ and.intro
(assume b hb, gt_mem_sets_of_Liminf_gt hg $ hi.symm ▸ hb)
(assume b hb, lt_mem_sets_of_Limsup_lt hl $ hs.symm ▸ hb)
theorem Limsup_nhds (a : α) : Limsup (𝓝 a) = a :=
cInf_intro (is_bounded_le_nhds a)
(assume a' (h : {n : α | n ≤ a'} ∈ 𝓝 a), show a ≤ a', from @mem_of_nhds α _ a _ h)
(assume b (hba : a < b), show ∃c (h : {n : α | n ≤ c} ∈ 𝓝 a), c < b, from
match dense_or_discrete a b with
| or.inl ⟨c, hac, hcb⟩ := ⟨c, ge_mem_nhds hac, hcb⟩
| or.inr ⟨_, h⟩ := ⟨a, (𝓝 a).sets_of_superset (gt_mem_nhds hba) h, hba⟩
end)
theorem Liminf_nhds : ∀ (a : α), Liminf (𝓝 a) = a :=
@Limsup_nhds (order_dual α) _ _ _
/-- If a filter is converging, its limsup coincides with its limit. -/
theorem Liminf_eq_of_le_nhds {f : filter α} {a : α} [ne_bot f] (h : f ≤ 𝓝 a) : f.Liminf = a :=
have hb_ge : is_bounded (≥) f, from (is_bounded_ge_nhds a).mono h,
have hb_le : is_bounded (≤) f, from (is_bounded_le_nhds a).mono h,
le_antisymm
(calc f.Liminf ≤ f.Limsup : Liminf_le_Limsup hb_le hb_ge
... ≤ (𝓝 a).Limsup :
Limsup_le_Limsup_of_le h hb_ge.is_cobounded_flip (is_bounded_le_nhds a)
... = a : Limsup_nhds a)
(calc a = (𝓝 a).Liminf : (Liminf_nhds a).symm
... ≤ f.Liminf :
Liminf_le_Liminf_of_le h (is_bounded_ge_nhds a) hb_le.is_cobounded_flip)
/-- If a filter is converging, its liminf coincides with its limit. -/
theorem Limsup_eq_of_le_nhds : ∀ {f : filter α} {a : α} [ne_bot f], f ≤ 𝓝 a → f.Limsup = a :=
@Liminf_eq_of_le_nhds (order_dual α) _ _ _
/-- If a function has a limit, then its limsup coincides with its limit. -/
theorem filter.tendsto.limsup_eq {f : filter β} {u : β → α} {a : α} [ne_bot f]
(h : tendsto u f (𝓝 a)) : limsup f u = a :=
Limsup_eq_of_le_nhds h
/-- If a function has a limit, then its liminf coincides with its limit. -/
theorem filter.tendsto.liminf_eq {f : filter β} {u : β → α} {a : α} [ne_bot f]
(h : tendsto u f (𝓝 a)) : liminf f u = a :=
Liminf_eq_of_le_nhds h
end conditionally_complete_linear_order
section complete_linear_order
variables [complete_linear_order α] [topological_space α] [order_topology α]
-- In complete_linear_order, the above theorems take a simpler form
/-- If the liminf and the limsup of a function coincide, then the limit of the function
exists and has the same value -/
theorem tendsto_of_liminf_eq_limsup {f : filter β} {u : β → α} {a : α}
(hinf : liminf f u = a) (hsup : limsup f u = a) : tendsto u f (𝓝 a) :=
le_nhds_of_Limsup_eq_Liminf is_bounded_le_of_top is_bounded_ge_of_bot hsup hinf
/-- If a number `a` is less than or equal to the `liminf` of a function `f` at some filter
and is greater than or equal to the `limsup` of `f`, then `f` tends to `a` along this filter. -/
theorem tendsto_of_le_liminf_of_limsup_le {f : filter β} {u : β → α} {a : α}
(hinf : a ≤ liminf f u) (hsup : limsup f u ≤ a) :
tendsto u f (𝓝 a) :=
if hf : f = ⊥ then hf.symm ▸ tendsto_bot
else by haveI : ne_bot f := hf; exact tendsto_of_liminf_eq_limsup
(le_antisymm (le_trans liminf_le_limsup hsup) hinf)
(le_antisymm hsup (le_trans hinf liminf_le_limsup))
end complete_linear_order
end liminf_limsup
end order_topology
lemma order_topology_of_nhds_abs
{α : Type*} [linear_ordered_add_comm_group α] [topological_space α]
(h_nhds : ∀a:α, 𝓝 a = (⨅r>0, 𝓟 {b | abs (a - b) < r})) : order_topology α :=
order_topology.mk $ eq_of_nhds_eq_nhds $ assume a:α, le_antisymm_iff.mpr
begin
simp [infi_and, topological_space.nhds_generate_from,
h_nhds, le_infi_iff, -le_principal_iff, and_comm],
refine ⟨λ s ha b hs, _, λ r hr, _⟩,
{ rcases hs with rfl | rfl,
{ refine infi_le_of_le (a - b)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < a - b), _),
have : a + -c < a + -b :=
by simpa only [sub_eq_add_neg] using lt_of_le_of_lt (le_abs_self _) hc,
exact lt_of_neg_lt_neg (lt_of_add_lt_add_left this) },
{ refine infi_le_of_le (b - a)
(infi_le_of_le (lt_sub_left_of_add_lt $ by simpa using ha) $
principal_mono.mpr $ assume c (hc : abs (a - c) < b - a), _),
have : abs (c - a) < b - a, {rw abs_sub; simpa using hc},
have : c + -a < b + -a :=
by simpa only [sub_eq_add_neg] using lt_of_le_of_lt (le_abs_self _) this,
exact lt_of_add_lt_add_right this } },
{ have h : {b | abs (a - b) < r} = {b | a - r < b} ∩ {b | b < a + r},
from set.ext (assume b,
by simp [abs_lt, sub_lt, lt_sub_iff_add_lt, sub_lt_iff_lt_add']; cc),
rw [h, ← inf_principal],
apply le_inf _ _,
{ exact infi_le_of_le {b : α | a - r < b} (infi_le_of_le (sub_lt_self a hr) $
infi_le_of_le (a - r) $ infi_le _ (or.inl rfl)) },
{ exact infi_le_of_le {b : α | b < a + r} (infi_le_of_le (lt_add_of_pos_right _ hr) $
infi_le_of_le (a + r) $ infi_le _ (or.inr rfl)) } }
end
/-- $\lim_{x\to+\infty}|x|=+\infty$ -/
lemma tendsto_abs_at_top_at_top [linear_ordered_add_comm_group α] :
tendsto (abs : α → α) at_top at_top :=
tendsto_at_top_mono (λ n, le_abs_self _) tendsto_id
local notation `|` x `|` := abs x
lemma linear_ordered_add_comm_group.tendsto_nhds
[linear_ordered_add_comm_group α] [topological_space α] [order_topology α] {β : Type*}
(f : β → α) (x : filter β) (a : α) :
filter.tendsto f x (nhds a) ↔ ∀ ε > (0 : α), ∀ᶠ b in x, |f b - a| < ε :=
begin
rw (show _, from @tendsto_order α), -- does not work without `show` for some reason
split,
{ rintros ⟨hyp_lt_a, hyp_gt_a⟩ ε ε_pos,
suffices : {b : β | f b - a < ε ∧ a - f b < ε} ∈ x, by simpa only [abs_sub_lt_iff],
have set1 : {b : β | a - f b < ε} ∈ x,
{ have : {b : β | a - ε < f b} ∈ x, from hyp_lt_a (a - ε) (sub_lt_self a ε_pos),
have : ∀ b, a - f b < ε ↔ a - ε < f b, by { intro _, exact sub_lt },
simpa only [this] },
have set2 : {b : β | f b - a < ε} ∈ x,
{ have : {b : β | a + ε > f b} ∈ x, from hyp_gt_a (a + ε) (lt_add_of_pos_right a ε_pos),
have : ∀ b, f b - a < ε ↔ a + ε > f b, by { intro _, exact sub_lt_iff_lt_add' },
simpa only [this] },
exact (x.inter_sets set2 set1) },
{ assume hyp_ε_pos,
split,
{ assume a' a'_lt_a,
let ε := a - a',
have : {b : β | |f b - a| < ε} ∈ x, from hyp_ε_pos ε (sub_pos.elim_right a'_lt_a),
have : {b : β | f b - a < ε ∧ a - f b < ε} ∈ x, by simpa only [abs_sub_lt_iff] using this,
have : {b : β | a - f b < ε} ∈ x, from x.sets_of_superset this (set.inter_subset_right _ _),
have : ∀ b, a' < f b ↔ a - f b < ε, by {intro b, rw [sub_lt, sub_sub_self] },
simpa only [this] },
{ assume a' a'_gt_a,
let ε := a' - a,
have : {b : β | |f b - a| < ε} ∈ x, from hyp_ε_pos ε (sub_pos.elim_right a'_gt_a),
have : {b : β | f b - a < ε ∧ a - f b < ε} ∈ x, by simpa only [abs_sub_lt_iff] using this,
have : {b : β | f b - a < ε} ∈ x, from x.sets_of_superset this (set.inter_subset_left _ _),
have : ∀ b, f b < a' ↔ f b - a < ε, by { intro b, simp [lt_sub_iff_add_lt] },
simpa only [this] }}
end
/-!
Here is a counter-example to a version of the following with `conditionally_complete_lattice α`.
Take `α = [0, 1) → ℝ` with the natural lattice structure, `ι = ℕ`. Put `f n x = -x^n`. Then
`⨆ n, f n = 0` while none of `f n` is strictly greater than the constant function `-0.5`.
-/
lemma tendsto_at_top_csupr {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : monotone f) (hbdd : bdd_above $ range f) :
tendsto f at_top (𝓝 (⨆i, f i)) :=
begin
by_cases hi : nonempty ι,
{ resetI,
rw tendsto_order,
split,
{ intros a h,
cases exists_lt_of_lt_csupr h with N hN,
apply eventually.mono (mem_at_top N),
exact λ i hi, lt_of_lt_of_le hN (h_mono hi) },
{ exact λ a h, eventually_of_forall (λ n, lt_of_le_of_lt (le_csupr hbdd n) h) } },
{ exact tendsto_of_not_nonempty hi }
end
lemma tendsto_at_top_cinfi {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α]
{f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) (hbdd : bdd_below $ range f) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
@tendsto_at_top_csupr _ (order_dual α) _ _ _ _ _ @h_mono hbdd
lemma tendsto_at_top_supr {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_top (𝓝 (⨆i, f i)) :=
tendsto_at_top_csupr h_mono (order_top.bdd_above _)
lemma tendsto_at_top_infi {ι α : Type*} [preorder ι] [topological_space α]
[complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : ∀ ⦃i j⦄, i ≤ j → f j ≤ f i) :
tendsto f at_top (𝓝 (⨅i, f i)) :=
tendsto_at_top_cinfi @h_mono (order_bot.bdd_below _)
lemma tendsto_of_monotone {ι α : Type*} [preorder ι] [topological_space α]
[conditionally_complete_linear_order α] [order_topology α] {f : ι → α} (h_mono : monotone f) :
tendsto f at_top at_top ∨ (∃ l, tendsto f at_top (𝓝 l)) :=
if H : bdd_above (range f) then or.inr ⟨_, tendsto_at_top_csupr h_mono H⟩
else or.inl $ tendsto_at_top_at_top_of_monotone' h_mono H
lemma supr_eq_of_tendsto {α β} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : monotone f) :
tendsto f at_top (𝓝 a) → supr f = a :=
tendsto_nhds_unique (tendsto_at_top_supr hf)
lemma infi_eq_of_tendsto {α} [topological_space α] [complete_linear_order α] [order_topology α]
[nonempty β] [semilattice_sup β] {f : β → α} {a : α} (hf : ∀n m, n ≤ m → f m ≤ f n) :
tendsto f at_top (𝓝 a) → infi f = a :=
tendsto_nhds_unique (tendsto_at_top_infi hf)
@[to_additive] lemma tendsto_inv_nhds_within_Ioi [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ioi a] a) (𝓝[Iio (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iio [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iio a] a) (𝓝[Ioi (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ioi_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ioi (a⁻¹)] (a⁻¹)) (𝓝[Iio a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ioi _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iio_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iio (a⁻¹)] (a⁻¹)) (𝓝[Ioi a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iio _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Ici [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ici a] a) (𝓝[Iic (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Iic [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iic a] a) (𝓝[Ici (a⁻¹)] (a⁻¹)) :=
(continuous_inv.tendsto a).inf $ by simp [tendsto_principal_principal]
@[to_additive] lemma tendsto_inv_nhds_within_Ici_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Ici (a⁻¹)] (a⁻¹)) (𝓝[Iic a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Ici _ _ _ _ (a⁻¹)
@[to_additive] lemma tendsto_inv_nhds_within_Iic_inv [ordered_comm_group α]
[topological_space α] [topological_group α] {a : α} :
tendsto has_inv.inv (𝓝[Iic (a⁻¹)] (a⁻¹)) (𝓝[Ici a] a) :=
by simpa only [inv_inv] using @tendsto_inv_nhds_within_Iic _ _ _ _ (a⁻¹)
lemma nhds_left_sup_nhds_right (a : α) [topological_space α] [linear_order α] :
𝓝[Iic a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=
by rw [← nhds_within_union, Iic_union_Ici, nhds_within_univ]
lemma nhds_left'_sup_nhds_right (a : α) [topological_space α] [linear_order α] :
𝓝[Iio a] a ⊔ 𝓝[Ici a] a = 𝓝 a :=
by rw [← nhds_within_union, Iio_union_Ici, nhds_within_univ]
lemma nhds_left_sup_nhds_right' (a : α) [topological_space α] [linear_order α] :
𝓝[Iic a] a ⊔ 𝓝[Ioi a] a = 𝓝 a :=
by rw [← nhds_within_union, Iic_union_Ioi, nhds_within_univ]
lemma continuous_at_iff_continuous_left_right [topological_space α] [linear_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_at f a ↔ continuous_within_at f (Iic a) a ∧ continuous_within_at f (Ici a) a :=
by simp only [continuous_within_at, continuous_at, ← tendsto_sup, nhds_left_sup_nhds_right]
lemma continuous_on_Icc_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [regular_space β] {f : α → β} {a b : α}
{la lb : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) (hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
continuous_on (extend_from (Ioo a b) f) (Icc a b) :=
begin
apply continuous_on_extend_from,
{ rw closure_Ioo hab, },
{ intros x x_in,
rcases mem_Ioo_or_eq_endpoints_of_mem_Icc x_in with rfl | rfl | h,
{ use la,
simpa [hab] },
{ use lb,
simpa [hab] },
{ use [f x, hf x h] } }
end
lemma eq_lim_at_left_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [t2_space β] {f : α → β} {a b : α}
{la : β} (hab : a < b) (ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) :
extend_from (Ioo a b) f a = la :=
begin
apply extend_from_eq,
{ rw closure_Ioo hab,
simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc] },
{ simpa [hab] }
end
lemma eq_lim_at_right_extend_from_Ioo [topological_space α] [linear_order α] [densely_ordered α]
[order_topology α] [topological_space β] [t2_space β] {f : α → β} {a b : α}
{lb : β} (hab : a < b) (hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
extend_from (Ioo a b) f b = lb :=
begin
apply extend_from_eq,
{ rw closure_Ioo hab,
simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc] },
{ simpa [hab] }
end
lemma continuous_on_Ico_extend_from_Ioo [topological_space α]
[linear_order α] [densely_ordered α] [order_topology α] [topological_space β]
[regular_space β] {f : α → β} {a b : α} {la : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(ha : tendsto f (𝓝[Ioi a] a) (𝓝 la)) :
continuous_on (extend_from (Ioo a b) f) (Ico a b) :=
begin
apply continuous_on_extend_from,
{ rw [closure_Ioo hab], exact Ico_subset_Icc_self, },
{ intros x x_in,
rcases mem_Ioo_or_eq_left_of_mem_Ico x_in with rfl | h,
{ use la,
simpa [hab] },
{ use [f x, hf x h] } }
end
lemma continuous_on_Ioc_extend_from_Ioo [topological_space α]
[linear_order α] [densely_ordered α] [order_topology α] [topological_space β]
[regular_space β] {f : α → β} {a b : α} {lb : β} (hab : a < b) (hf : continuous_on f (Ioo a b))
(hb : tendsto f (𝓝[Iio b] b) (𝓝 lb)) :
continuous_on (extend_from (Ioo a b) f) (Ioc a b) :=
begin
have := @continuous_on_Ico_extend_from_Ioo (order_dual α) _ _ _ _ _ _ _ f _ _ _ hab,
erw [dual_Ico, dual_Ioi, dual_Ioo] at this,
exact this hf hb
end
lemma continuous_within_at_Ioi_iff_Ici {α β : Type*} [topological_space α] [partial_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_within_at f (Ioi a) a ↔ continuous_within_at f (Ici a) a :=
by simp only [← Ici_diff_left, continuous_within_at_diff_self]
lemma continuous_within_at_Iio_iff_Iic
{α β : Type*} [topological_space α] [linear_order α] [topological_space β] {a : α} {f : α → β} :
continuous_within_at f (Iio a) a ↔ continuous_within_at f (Iic a) a :=
begin
have := @continuous_within_at_Ioi_iff_Ici (order_dual α) _ _ _ _ _ f,
erw [dual_Ici, dual_Ioi] at this,
exact this,
end
lemma continuous_at_iff_continuous_left'_right' [topological_space α] [linear_order α]
[topological_space β] {a : α} {f : α → β} :
continuous_at f a ↔ continuous_within_at f (Iio a) a ∧ continuous_within_at f (Ioi a) a :=
by rw [continuous_within_at_Ioi_iff_Ici, continuous_within_at_Iio_iff_Iic,
continuous_at_iff_continuous_left_right]
/-!
### Continuity of monotone functions
In this section we prove the following fact: if `f` is a monotone function on a neighborhood of `a`
and the image of this neighborhood is a neighborhood of `f a`, then `f` is continuous at `a`, see
`continuous_at_of_mono_incr_on_of_image_mem_nhds`, as well as several similar facts.
-/
section linear_order
variables [linear_order α] [topological_space α] [order_topology α]
variables [linear_order β] [topological_space β] [order_topology β]
/-- If `f` is a function strictly monotonically increasing on a right neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(f a, b]`, `b > f a`, then `f` is
continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x ≤ 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
lemma strict_mono_incr_on.continuous_at_right_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) :
continuous_within_at f (Ici a) a :=
begin
have ha : a ∈ Ici a := left_mem_Ici,
have has : a ∈ s := mem_of_mem_nhds_within ha hs,
refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩,
{ filter_upwards [hs, self_mem_nhds_within],
intros x hxs hxa,
exact hb.trans_le ((h_mono.le_iff_le has hxs).2 hxa) },
{ rcases hfs b hb with ⟨c, hcs, hac, hcb⟩,
rw [h_mono.lt_iff_lt has hcs] at hac,
filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 hac)],
rintros x hx ⟨hax, hxc⟩,
exact ((h_mono.lt_iff_lt hx hcs).2 hxc).trans_le hcb }
end
/-- If `f` is a function monotonically increasing function on a right neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(f a, b)`, `b > f a`, then `f` is
continuous at `a` from the right.
The assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b` cannot be replaced by the weaker
assumption `hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b` we use for strictly monotone functions
because otherwise the function `ceil : ℝ → ℤ` would be a counter-example at `a = 0`. -/
lemma continuous_at_right_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a)
(hfs : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) :
continuous_within_at f (Ici a) a :=
begin
have ha : a ∈ Ici a := left_mem_Ici,
have has : a ∈ s := mem_of_mem_nhds_within ha hs,
refine tendsto_order.2 ⟨λ b hb, _, λ b hb, _⟩,
{ filter_upwards [hs, self_mem_nhds_within],
intros x hxs hxa,
exact hb.trans_le (h_mono _ has _ hxs hxa) },
{ rcases hfs b hb with ⟨c, hcs, hac, hcb⟩,
have : a < c, from not_le.1 (λ h, hac.not_le $ h_mono _ hcs _ has h),
filter_upwards [hs, Ico_mem_nhds_within_Ici (left_mem_Ico.2 this)],
rintros x hx ⟨hax, hxc⟩,
exact (h_mono _ hx _ hcs hxc.le).trans_lt hcb }
end
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a right
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right
neighborhood of `f a`, then `f` is continuous at `a` from the right. -/
lemma continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Ici a] a) (hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
begin
refine continuous_at_right_of_mono_incr_on_of_exists_between h_mono hs (λ b hb, _),
rcases (mem_nhds_within_Ici_iff_exists_mem_Ioc_Ico_subset hb).1 hfs with ⟨b', ⟨hab', hbb'⟩, hb'⟩,
rcases exists_between hab' with ⟨c', hc'⟩,
rcases mem_closure_iff.1 (hb' ⟨hc'.1.le, hc'.2⟩) (Ioo (f a) b') is_open_Ioo hc'
with ⟨_, hc, ⟨c, hcs, rfl⟩⟩,
exact ⟨c, hcs, hc.1, hc.2.trans_le hbb'⟩
end
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a right
neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of `f a`,
then `f` is continuous at `a` from the right. -/
lemma continuous_at_right_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Ici a] a)
(hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs $
mem_sets_of_superset hfs subset_closure
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
right neighborhood of `a` and the closure of the image of this neighborhood under `f` is a right
neighborhood of `f a`, then `f` is continuous at `a` from the right. -/
lemma strict_mono_incr_on.continuous_at_right_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : closure (f '' s) ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within
(λ x hx y hy, (h_mono.le_iff_le hx hy).2) hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
right neighborhood of `a` and the image of this neighborhood under `f` is a right neighborhood of
`f a`, then `f` is continuous at `a` from the right. -/
lemma strict_mono_incr_on.continuous_at_right_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a)
(hfs : f '' s ∈ 𝓝[Ici (f a)] (f a)) :
continuous_within_at f (Ici a) a :=
h_mono.continuous_at_right_of_closure_image_mem_nhds_within hs
(mem_sets_of_superset hfs subset_closure)
/-- If a function `f` is strictly monotonically increasing on a right neighborhood of `a` and the
image of this neighborhood under `f` includes `Ioi (f a)`, then `f` is continuous at `a` from the
right. -/
lemma strict_mono_incr_on.continuous_at_right_of_surj_on {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Ici a] a) (hfs : surj_on f s (Ioi (f a))) :
continuous_within_at f (Ici a) a :=
h_mono.continuous_at_right_of_exists_between hs $ λ b hb, let ⟨c, hcs, hcb⟩ := hfs hb in
⟨c, hcs, hcb.symm ▸ hb, hcb.le⟩
/-- If `f` is a function strictly monotonically increasing on a left neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, then `f` is
continuous at `a` from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` is required because otherwise the
function `f : ℝ → ℝ` given by `f x = if x < 0 then x else x + 1` would be a counter-example at
`a = 0`. -/
lemma strict_mono_incr_on.continuous_at_left_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_exists_between hs $
λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩
/-- If `f` is a function monotonically increasing function on a left neighborhood of `a` and the
image of this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, then `f` is
continuous at `a` from the left.
The assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)` cannot be replaced by the weaker
assumption `hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)` we use for strictly monotone functions
because otherwise the function `floor : ℝ → ℤ` would be a counter-example at `a = 0`. -/
lemma continuous_at_left_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝[Iic a] a)
(hfs : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) :
continuous_within_at f (Iic a) a :=
@continuous_at_right_of_mono_incr_on_of_exists_between (order_dual α) (order_dual β) _ _ _ _ _ _
f s a (λ x hx y hy, h_mono y hy x hx) hs $
λ b hb, let ⟨c, hcs, hcb, hca⟩ := hfs b hb in ⟨c, hcs, hca, hcb⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a left
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left
neighborhood of `f a`, then `f` is continuous at `a` from the left -/
lemma continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Iic a] a) (hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
@continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within (order_dual α) (order_dual β)
_ _ _ _ _ _ _ f s a (λ x hx y hy, h_mono y hy x hx) hs hfs
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a left
neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of `f a`,
then `f` is continuous at `a` from the left. -/
lemma continuous_at_left_of_mono_incr_on_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y)
(hs : s ∈ 𝓝[Iic a] a) (hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono hs
(mem_sets_of_superset hfs subset_closure)
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
left neighborhood of `a` and the closure of the image of this neighborhood under `f` is a left
neighborhood of `f a`, then `f` is continuous at `a` from the left. -/
lemma strict_mono_incr_on.continuous_at_left_of_closure_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : closure (f '' s) ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_closure_image_mem_nhds_within hs hfs
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
left neighborhood of `a` and the image of this neighborhood under `f` is a left neighborhood of
`f a`, then `f` is continuous at `a` from the left. -/
lemma strict_mono_incr_on.continuous_at_left_of_image_mem_nhds_within [densely_ordered β]
{f : α → β} {s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a)
(hfs : f '' s ∈ 𝓝[Iic (f a)] (f a)) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_image_mem_nhds_within hs hfs
/-- If a function `f` is strictly monotonically increasing on a left neighborhood of `a` and the
image of this neighborhood under `f` includes `Iio (f a)`, then `f` is continuous at `a` from the
left. -/
lemma strict_mono_incr_on.continuous_at_left_of_surj_on {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝[Iic a] a) (hfs : surj_on f s (Iio (f a))) :
continuous_within_at f (Iic a) a :=
h_mono.dual.continuous_at_right_of_surj_on hs hfs
/-- If a function `f` is strictly monotonically increasing on a neighborhood of `a` and the image of
this neighborhood under `f` meets every interval `[b, f a)`, `b < f a`, and every interval
`(f a, b]`, `b > f a`, then `f` is continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a)
(hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ico b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioc (f a) b) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨h_mono.continuous_at_left_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_l,
h_mono.continuous_at_right_of_exists_between (mem_nhds_within_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
neighborhood of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of
`f a`, then `f` is continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_closure_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨h_mono.continuous_at_left_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs)
(mem_nhds_within_of_mem_nhds hfs),
h_mono.continuous_at_right_of_closure_image_mem_nhds_within (mem_nhds_within_of_mem_nhds hs)
(mem_nhds_within_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is strictly monotonically increasing on a
neighborhood of `a` and the image of this set under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
lemma strict_mono_incr_on.continuous_at_of_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : strict_mono_incr_on f s) (hs : s ∈ 𝓝 a) (hfs : f '' s ∈ 𝓝 (f a)) :
continuous_at f a :=
h_mono.continuous_at_of_closure_image_mem_nhds hs (mem_sets_of_superset hfs subset_closure)
/-- If `f` is a function monotonically increasing function on a neighborhood of `a` and the image of
this neighborhood under `f` meets every interval `(b, f a)`, `b < f a`, and every interval `(f a,
b)`, `b > f a`, then `f` is continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_exists_between {f : α → β} {s : set α} {a : α}
(h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs_l : ∀ b < f a, ∃ c ∈ s, f c ∈ Ioo b (f a)) (hfs_r : ∀ b > f a, ∃ c ∈ s, f c ∈ Ioo (f a) b) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨continuous_at_left_of_mono_incr_on_of_exists_between h_mono
(mem_nhds_within_of_mem_nhds hs) hfs_l,
continuous_at_right_of_mono_incr_on_of_exists_between h_mono
(mem_nhds_within_of_mem_nhds hs) hfs_r⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood
of `a` and the closure of the image of this neighborhood under `f` is a neighborhood of `f a`, then
`f` is continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_closure_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs : closure (f '' s) ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_iff_continuous_left_right.2
⟨continuous_at_left_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono
(mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs),
continuous_at_right_of_mono_incr_on_of_closure_image_mem_nhds_within h_mono
(mem_nhds_within_of_mem_nhds hs) (mem_nhds_within_of_mem_nhds hfs)⟩
/-- If a function `f` with a densely ordered codomain is monotonically increasing on a neighborhood
of `a` and the image of this neighborhood under `f` is a neighborhood of `f a`, then `f` is
continuous at `a`. -/
lemma continuous_at_of_mono_incr_on_of_image_mem_nhds [densely_ordered β] {f : α → β}
{s : set α} {a : α} (h_mono : ∀ (x ∈ s) (y ∈ s), x ≤ y → f x ≤ f y) (hs : s ∈ 𝓝 a)
(hfs : f '' s ∈ 𝓝 (f a)) :
continuous_at f a :=
continuous_at_of_mono_incr_on_of_closure_image_mem_nhds h_mono hs
(mem_sets_of_superset hfs subset_closure)
/-- A monotone function with densely ordered codomain and a dense range is continuous. -/
lemma monotone.continuous_of_dense_range [densely_ordered β] {f : α → β}
(h_mono : monotone f) (h_dense : dense_range f) :
continuous f :=
continuous_iff_continuous_at.mpr $ λ a,
continuous_at_of_mono_incr_on_of_closure_image_mem_nhds (λ x hx y hy hxy, h_mono hxy)
univ_mem_sets $ by simp only [image_univ, h_dense.closure_eq, univ_mem_sets]
/-- A monotone surjective function with a densely ordered codomain is surjective. -/
lemma monotone.continuous_of_surjective [densely_ordered β] {f : α → β} (h_mono : monotone f)
(h_surj : function.surjective f) :
continuous f :=
h_mono.continuous_of_dense_range h_surj.dense_range
end linear_order
/-!
### Continuity of order isomorphisms
In this section we prove that an `order_iso` is continuous, hence it is a `homeomorph`. We prove
this for an `order_iso` between to partial orders with order topology.
-/
namespace order_iso
variables [partial_order α] [partial_order β] [topological_space α] [topological_space β]
[order_topology α] [order_topology β]
protected lemma continuous (e : α ≃o β) : continuous e :=
begin
rw [‹order_topology β›.topology_eq_generate_intervals],
refine continuous_generated_from (λ s hs, _),
rcases hs with ⟨a, rfl|rfl⟩,
{ rw e.preimage_Ioi, apply is_open_lt' },
{ rw e.preimage_Iio, apply is_open_gt' }
end
/-- An order isomorphism between two linear order `order_topology` spaces is a homeomorphism. -/
def to_homeomorph (e : α ≃o β) : α ≃ₜ β :=
{ continuous_to_fun := e.continuous,
continuous_inv_fun := e.symm.continuous,
.. e }
@[simp] lemma coe_to_homeomorph (e : α ≃o β) : ⇑e.to_homeomorph = e := rfl
@[simp] lemma coe_to_homeomorph_symm (e : α ≃o β) : ⇑e.to_homeomorph.symm = e.symm := rfl
end order_iso
section conditionally_complete_linear_order
variables
[conditionally_complete_linear_order α] [densely_ordered α] [topological_space α]
[order_topology α] [conditionally_complete_linear_order β] [topological_space β]
[order_topology β]
/-- If `f : α → β` is strictly monotone and continuous, and tendsto `at_top` `at_top` and to
`at_bot` `at_bot`, then it is a homeomorphism. -/
noncomputable def homeomorph_of_strict_mono_continuous
(f : α → β) (h_mono : strict_mono f) (h_cont : continuous f) (h_top : tendsto f at_top at_top)
(h_bot : tendsto f at_bot at_bot) :
homeomorph α β :=
(h_mono.order_iso_of_surjective f (surjective_of_continuous h_cont h_top h_bot)).to_homeomorph
@[simp] lemma coe_homeomorph_of_strict_mono_continuous
(f : α → β) (h_mono : strict_mono f) (h_cont : continuous f) (h_top : tendsto f at_top at_top)
(h_bot : tendsto f at_bot at_bot) :
(homeomorph_of_strict_mono_continuous f h_mono h_cont h_top h_bot : α → β) = f := rfl
/- Now we prove a relative version of the above result. This (`Ioo` to `univ`) is provided as a
sample; there are at least 16 possible variations with open intervals (`univ` to `Ioo`, `Ioi` to
`univ`, ...), not to mention the possibilities with closed or half-closed intervals. -/
variables {a b : α}
/-- If `f : α → β` is strictly monotone and continuous on the interval `Ioo a b` of `α`, and tends
to `at_top` within `𝓝[Iio b] b` and to `at_bot` within `𝓝[Ioi a] a`, then it restricts to a
homeomorphism from `Ioo a b` to `β`. -/
noncomputable def homeomorph_of_strict_mono_continuous_Ioo
(f : α → β) (h : a < b)
(h_mono : ∀ ⦃x y : α⦄, a < x → y < b → x < y → f x < f y)
(h_cont : continuous_on f (Ioo a b))
(h_top : tendsto f (𝓝[Iio b] b) at_top)
(h_bot : tendsto f (𝓝[Ioi a] a) at_bot) :
homeomorph (Ioo a b) β :=
by haveI : inhabited (Ioo a b) := inhabited_of_nonempty (nonempty_Ioo_subtype h); exact
homeomorph_of_strict_mono_continuous
(restrict f (Ioo a b))
(λ x y, h_mono x.2.1 y.2.2)
(continuous_on_iff_continuous_restrict.mp h_cont)
(by rwa [restrict_eq f (Ioo a b), ← tendsto_map'_iff, map_coe_Ioo_at_top h])
(by rwa [restrict_eq f (Ioo a b), ← tendsto_map'_iff, map_coe_Ioo_at_bot h])
@[simp] lemma coe_homeomorph_of_strict_mono_continuous_Ioo
(f : α → β) (h : a < b)
(h_mono : ∀ ⦃x y : α⦄, a < x → y < b → x < y → f x < f y)
(h_cont : continuous_on f (Ioo a b))
(h_top : tendsto f (𝓝[Iio b] b) at_top)
(h_bot : tendsto f (𝓝[Ioi a] a) at_bot) :
(homeomorph_of_strict_mono_continuous_Ioo f h h_mono h_cont h_top h_bot : Ioo a b → β)
= restrict f (Ioo a b) :=
rfl
end conditionally_complete_linear_order
|
0f57457c62abcb7d91208a53b8dd943c81438127 | 31f556cdeb9239ffc2fad8f905e33987ff4feab9 | /tests/lean/lcnfTypes.lean | 3fbf4f118f9c7bfba2c5582cd9ed2c252cf32659 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | tobiasgrosser/lean4 | ce0fd9cca0feba1100656679bf41f0bffdbabb71 | ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f | refs/heads/master | 1,673,103,412,948 | 1,664,930,501,000 | 1,664,930,501,000 | 186,870,185 | 0 | 0 | Apache-2.0 | 1,665,129,237,000 | 1,557,939,901,000 | Lean | UTF-8 | Lean | false | false | 4,436 | lean | import Lean
notation "◾" => lcErased
notation "⊤" => lcAny
open Lean Compiler LCNF Meta
def test (declName : Name) : MetaM Unit := do
IO.println s!"{declName} : {← ppExpr (← LCNF.getOtherDeclBaseType declName [])}"
inductive Vec (α : Type u) : Nat → Type u
| nil : Vec α 0
| cons : α → Vec α n → Vec α (n+1)
def Vec.zip : Vec α n → Vec β n → Vec (α × β) n
| .cons a as, .cons b bs => .cons (a, b) (zip as bs)
| .nil, .nil => .nil
def Tuple (α : Type u) : Nat → Type u
| 0 => PUnit
| 1 => α
| n+2 => α × Tuple α n
def mkConstTuple (a : α) : (n : Nat) → Tuple α n
| 0 => ⟨⟩
| 1 => a
| n+2 => (a, mkConstTuple a n)
#eval test ``Vec.zip
#eval test ``mkConstTuple
#eval test ``Fin.add
#eval test ``Vec.cons
#eval test ``Eq.rec
#eval test ``GetElem.getElem
inductive HList {α : Type v} (β : α → Type u) : List α → Type (max u v)
| nil : HList β []
| cons : β i → HList β is → HList β (i::is)
infix:67 " :: " => HList.cons
inductive Member : α → List α → Type _
| head : Member a (a::as)
| tail : Member a bs → Member a (b::bs)
def HList.get : HList β is → Member i is → β i
| a::as, .head => a
| _::as, .tail h => as.get h
inductive Ty where
| nat
| fn : Ty → Ty → Ty
abbrev Ty.denote : Ty → Type
| nat => Nat
| fn a b => a.denote → b.denote
inductive Term : List Ty → Ty → Type
| var : Member ty ctx → Term ctx ty
| const : Nat → Term ctx .nat
| plus : Term ctx .nat → Term ctx .nat → Term ctx .nat
| app : Term ctx (.fn dom ran) → Term ctx dom → Term ctx ran
| lam : Term (dom :: ctx) ran → Term ctx (.fn dom ran)
| «let» : Term ctx ty₁ → Term (ty₁ :: ctx) ty₂ → Term ctx ty₂
def Term.denote : Term ctx ty → HList Ty.denote ctx → ty.denote
| var h, env => env.get h
| const n, _ => n
| plus a b, env => a.denote env + b.denote env
| app f a, env => f.denote env (a.denote env)
| lam b, env => fun x => b.denote (x :: env)
| «let» a b, env => b.denote (a.denote env :: env)
def Term.constFold : Term ctx ty → Term ctx ty
| const n => const n
| var h => var h
| app f a => app f.constFold a.constFold
| lam b => lam b.constFold
| «let» a b => «let» a.constFold b.constFold
| plus a b =>
match a.constFold, b.constFold with
| const n, const m => const (n+m)
| a', b' => plus a' b'
#eval test ``Term.constFold
#eval test ``Term.denote
#eval test ``HList.get
#eval test ``Member.head
#eval test ``Ty.denote
#eval test ``MonadControl.liftWith
#eval test ``MonadControl.restoreM
#eval test ``Decidable.casesOn
#eval test ``getConstInfo
#eval test ``instMonadMetaM
#eval test ``Lean.Meta.inferType
#eval test ``Elab.Term.elabTerm
#eval test ``Nat.add
structure Magma where
carrier : Type
mul : carrier → carrier → carrier
#eval test ``Magma.mul
def weird1 (c : Bool) : (cond c List Array) Nat :=
match c with
| true => []
| false => #[]
#eval test ``weird1
def compatible (declName₁ declName₂ : Name) : MetaM Unit := do
let type₁ ← LCNF.getOtherDeclBaseType declName₁ []
let type₂ ← LCNF.getOtherDeclBaseType declName₂ []
unless LCNF.compatibleTypesQuick type₁ type₂ do
throwError "{declName₁} : {← ppExpr type₁}\ntype is not compatible with\n{declName₂} : {← ppExpr type₂}"
axiom monadList₁.{u} : Monad List.{u}
axiom monadList₂.{u} : Monad (fun α : Type u => List α)
set_option pp.all true
#eval compatible ``monadList₁ ``monadList₂
axiom lamAny₁ (c : Bool) : Monad (fun α : Type => cond c (List α) (Array α))
axiom lamAny₂ (c : Bool) : Monad (cond c List.{0} Array.{0})
#eval test ``lamAny₁
#eval test ``lamAny₂
#eval compatible ``lamAny₁ ``lamAny₂
def testMono (declName : Name) : MetaM Unit := do
let base ← LCNF.getOtherDeclBaseType declName []
let mono ← LCNF.toMonoType base |>.run {}
IO.println s!"{declName} : {← ppExpr mono}"
#eval testMono ``Term.constFold
#eval testMono ``Term.denote
#eval testMono ``HList.get
#eval testMono ``Member.head
#eval testMono ``Ty.denote
#eval testMono ``MonadControl.liftWith
#eval testMono ``MonadControl.restoreM
#eval testMono ``Decidable.casesOn
#eval testMono ``getConstInfo
#eval testMono ``instMonadMetaM
#eval testMono ``Lean.Meta.inferType
#eval testMono ``Elab.Term.elabTerm
#eval testMono ``Nat.add
|
3c06a717a4a80cceca55a47a9e7fc87a921cb56b | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/data/fintype/basic.lean | bf52d12d96ac9ded9c43d55c0d0c1fd4e16ada9e | [
"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 | 84,111 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import data.array.lemmas
import data.finset.option
import data.finset.pi
import data.finset.powerset
import data.finset.prod
import data.sym.basic
import data.ulift
import group_theory.perm.basic
import order.well_founded
import tactic.wlog
/-!
# Finite types
This file defines a typeclass to state that a type is finite.
## Main declarations
* `fintype α`: Typeclass saying that a type is finite. It takes as fields a `finset` and a proof
that all terms of type `α` are in it.
* `finset.univ`: The finset of all elements of a fintype.
* `fintype.card α`: Cardinality of a fintype. Equal to `finset.univ.card`.
* `perms_of_finset s`: The finset of permutations of the finset `s`.
* `fintype.trunc_equiv_fin`: A fintype `α` is computably equivalent to `fin (card α)`. The
`trunc`-free, noncomputable version is `fintype.equiv_fin`.
* `fintype.trunc_equiv_of_card_eq` `fintype.equiv_of_card_eq`: Two fintypes of same cardinality are
equivalent. See above.
* `fin.equiv_iff_eq`: `fin m ≃ fin n` iff `m = n`.
* `infinite α`: Typeclass saying that a type is infinite. Defined as `fintype α → false`.
* `not_fintype`: No `fintype` has an `infinite` instance.
* `infinite.nat_embedding`: An embedding of `ℕ` into an infinite type.
We also provide the following versions of the pigeonholes principle.
* `fintype.exists_ne_map_eq_of_card_lt` and `is_empty_of_card_lt`: Finitely many pigeons and
pigeonholes. Weak formulation.
* `fintype.exists_ne_map_eq_of_infinite`: Infinitely many pigeons in finitely many pigeonholes.
Weak formulation.
* `fintype.exists_infinite_fiber`: Infinitely many pigeons in finitely many pigeonholes. Strong
formulation.
Some more pigeonhole-like statements can be found in `data.fintype.card_embedding`.
## Instances
Among others, we provide `fintype` instances for
* A `subtype` of a fintype. See `fintype.subtype`.
* The `option` of a fintype.
* The product of two fintypes.
* The sum of two fintypes.
* `Prop`.
and `infinite` instances for
* specific types: `ℕ`, `ℤ`
* type constructors: `set α`, `finset α`, `multiset α`, `list α`, `α ⊕ β`, `α × β`
along with some machinery
* Types which have a surjection from/an injection to a `fintype` are themselves fintypes. See
`fintype.of_injective` and `fintype.of_surjective`.
* Types which have an injection from/a surjection to an `infinite` type are themselves `infinite`.
See `infinite.of_injective` and `infinite.of_surjective`.
-/
open_locale nat
universes u v
variables {α β γ : Type*}
/-- `fintype α` means that `α` is finite, i.e. there are only
finitely many distinct elements of type `α`. The evidence of this
is a finset `elems` (a list up to permutation without duplicates),
together with a proof that everything of type `α` is in the list. -/
class fintype (α : Type*) :=
(elems [] : finset α)
(complete : ∀ x : α, x ∈ elems)
namespace finset
variable [fintype α]
/-- `univ` is the universal finite set of type `finset α` implied from
the assumption `fintype α`. -/
def univ : finset α := fintype.elems α
@[simp] theorem mem_univ (x : α) : x ∈ (univ : finset α) :=
fintype.complete x
@[simp] theorem mem_univ_val : ∀ x, x ∈ (univ : finset α).1 := mem_univ
@[simp] lemma coe_univ : ↑(univ : finset α) = (set.univ : set α) :=
by ext; simp
lemma univ_nonempty_iff : (univ : finset α).nonempty ↔ nonempty α :=
by rw [← coe_nonempty, coe_univ, set.nonempty_iff_univ_nonempty]
lemma univ_nonempty [nonempty α] : (univ : finset α).nonempty :=
univ_nonempty_iff.2 ‹_›
lemma univ_eq_empty_iff : (univ : finset α) = ∅ ↔ is_empty α :=
by rw [← not_nonempty_iff, ← univ_nonempty_iff, not_nonempty_iff_eq_empty]
lemma univ_eq_empty [is_empty α] : (univ : finset α) = ∅ :=
univ_eq_empty_iff.2 ‹_›
@[simp] theorem subset_univ (s : finset α) : s ⊆ univ := λ a _, mem_univ a
instance : order_top (finset α) :=
{ top := univ,
le_top := subset_univ }
instance [decidable_eq α] : boolean_algebra (finset α) :=
{ compl := λ s, univ \ s,
inf_compl_le_bot := λ s x hx, by simpa using hx,
top_le_sup_compl := λ s x hx, by simp,
sdiff_eq := λ s t, by simp [ext_iff, compl],
..finset.order_top,
..finset.generalized_boolean_algebra }
lemma compl_eq_univ_sdiff [decidable_eq α] (s : finset α) : sᶜ = univ \ s := rfl
@[simp] lemma mem_compl [decidable_eq α] {s : finset α} {x : α} : x ∈ sᶜ ↔ x ∉ s :=
by simp [compl_eq_univ_sdiff]
@[simp, norm_cast] lemma coe_compl [decidable_eq α] (s : finset α) : ↑(sᶜ) = (↑s : set α)ᶜ :=
set.ext $ λ x, mem_compl
@[simp] theorem union_compl [decidable_eq α] (s : finset α) : s ∪ sᶜ = finset.univ :=
sup_compl_eq_top
@[simp] theorem insert_compl_self [decidable_eq α] (x : α) : insert x ({x}ᶜ : finset α) = univ :=
by { ext y, simp [eq_or_ne] }
@[simp] lemma compl_filter [decidable_eq α] (p : α → Prop) [decidable_pred p]
[Π x, decidable (¬p x)] :
(univ.filter p)ᶜ = univ.filter (λ x, ¬p x) :=
(filter_not _ _).symm
theorem eq_univ_iff_forall {s : finset α} : s = univ ↔ ∀ x, x ∈ s :=
by simp [ext_iff]
lemma compl_ne_univ_iff_nonempty [decidable_eq α] (s : finset α) : sᶜ ≠ univ ↔ s.nonempty :=
by simp [eq_univ_iff_forall, finset.nonempty]
lemma compl_singleton [decidable_eq α] (a : α) : ({a} : finset α)ᶜ = univ.erase a :=
by rw [compl_eq_univ_sdiff, sdiff_singleton_eq_erase]
@[simp] lemma univ_inter [decidable_eq α] (s : finset α) :
univ ∩ s = s := ext $ λ a, by simp
@[simp] lemma inter_univ [decidable_eq α] (s : finset α) :
s ∩ univ = s :=
by rw [inter_comm, univ_inter]
@[simp] lemma piecewise_univ [Π i : α, decidable (i ∈ (univ : finset α))]
{δ : α → Sort*} (f g : Π i, δ i) : univ.piecewise f g = f :=
by { ext i, simp [piecewise] }
lemma piecewise_compl [decidable_eq α] (s : finset α) [Π i : α, decidable (i ∈ s)]
[Π i : α, decidable (i ∈ sᶜ)] {δ : α → Sort*} (f g : Π i, δ i) :
sᶜ.piecewise f g = s.piecewise g f :=
by { ext i, simp [piecewise] }
@[simp] lemma piecewise_erase_univ {δ : α → Sort*} [decidable_eq α] (a : α) (f g : Π a, δ a) :
(finset.univ.erase a).piecewise f g = function.update f a (g a) :=
by rw [←compl_singleton, piecewise_compl, piecewise_singleton]
lemma univ_map_equiv_to_embedding {α β : Type*} [fintype α] [fintype β] (e : α ≃ β) :
univ.map e.to_embedding = univ :=
eq_univ_iff_forall.mpr (λ b, mem_map.mpr ⟨e.symm b, mem_univ _, by simp⟩)
@[simp] lemma univ_filter_exists (f : α → β) [fintype β]
[decidable_pred (λ y, ∃ x, f x = y)] [decidable_eq β] :
finset.univ.filter (λ y, ∃ x, f x = y) = finset.univ.image f :=
by { ext, simp }
/-- Note this is a special case of `(finset.image_preimage f univ _).symm`. -/
lemma univ_filter_mem_range (f : α → β) [fintype β]
[decidable_pred (λ y, y ∈ set.range f)] [decidable_eq β] :
finset.univ.filter (λ y, y ∈ set.range f) = finset.univ.image f :=
univ_filter_exists f
/-- A special case of `finset.sup_eq_supr` that omits the useless `x ∈ univ` binder. -/
lemma sup_univ_eq_supr [complete_lattice β] (f : α → β) : finset.univ.sup f = supr f :=
(sup_eq_supr _ f).trans $ congr_arg _ $ funext $ λ a, supr_pos (mem_univ _)
/-- A special case of `finset.inf_eq_infi` that omits the useless `x ∈ univ` binder. -/
lemma inf_univ_eq_infi [complete_lattice β] (f : α → β) : finset.univ.inf f = infi f :=
sup_univ_eq_supr (by exact f : α → order_dual β)
end finset
open finset function
namespace fintype
instance decidable_pi_fintype {α} {β : α → Type*} [∀ a, decidable_eq (β a)] [fintype α] :
decidable_eq (Π a, β a) :=
λ f g, decidable_of_iff (∀ a ∈ fintype.elems α, f a = g a)
(by simp [function.funext_iff, fintype.complete])
instance decidable_forall_fintype {p : α → Prop} [decidable_pred p] [fintype α] :
decidable (∀ a, p a) :=
decidable_of_iff (∀ a ∈ @univ α _, p a) (by simp)
instance decidable_exists_fintype {p : α → Prop} [decidable_pred p] [fintype α] :
decidable (∃ a, p a) :=
decidable_of_iff (∃ a ∈ @univ α _, p a) (by simp)
instance decidable_mem_range_fintype [fintype α] [decidable_eq β] (f : α → β) :
decidable_pred (∈ set.range f) :=
λ x, fintype.decidable_exists_fintype
section bundled_homs
instance decidable_eq_equiv_fintype [decidable_eq β] [fintype α] :
decidable_eq (α ≃ β) :=
λ a b, decidable_of_iff (a.1 = b.1) equiv.coe_fn_injective.eq_iff
instance decidable_eq_embedding_fintype [decidable_eq β] [fintype α] :
decidable_eq (α ↪ β) :=
λ a b, decidable_of_iff ((a : α → β) = b) function.embedding.coe_injective.eq_iff
@[to_additive]
instance decidable_eq_one_hom_fintype [decidable_eq β] [fintype α] [has_one α] [has_one β]:
decidable_eq (one_hom α β) :=
λ a b, decidable_of_iff ((a : α → β) = b) (injective.eq_iff one_hom.coe_inj)
@[to_additive]
instance decidable_eq_mul_hom_fintype [decidable_eq β] [fintype α] [has_mul α] [has_mul β]:
decidable_eq (mul_hom α β) :=
λ a b, decidable_of_iff ((a : α → β) = b) (injective.eq_iff mul_hom.coe_inj)
@[to_additive]
instance decidable_eq_monoid_hom_fintype [decidable_eq β] [fintype α]
[mul_one_class α] [mul_one_class β]:
decidable_eq (α →* β) :=
λ a b, decidable_of_iff ((a : α → β) = b) (injective.eq_iff monoid_hom.coe_inj)
instance decidable_eq_monoid_with_zero_hom_fintype [decidable_eq β] [fintype α]
[mul_zero_one_class α] [mul_zero_one_class β]:
decidable_eq (monoid_with_zero_hom α β) :=
λ a b, decidable_of_iff ((a : α → β) = b) (injective.eq_iff monoid_with_zero_hom.coe_inj)
instance decidable_eq_ring_hom_fintype [decidable_eq β] [fintype α]
[semiring α] [semiring β]:
decidable_eq (α →+* β) :=
λ a b, decidable_of_iff ((a : α → β) = b) (injective.eq_iff ring_hom.coe_inj)
end bundled_homs
instance decidable_injective_fintype [decidable_eq α] [decidable_eq β] [fintype α] :
decidable_pred (injective : (α → β) → Prop) := λ x, by unfold injective; apply_instance
instance decidable_surjective_fintype [decidable_eq β] [fintype α] [fintype β] :
decidable_pred (surjective : (α → β) → Prop) := λ x, by unfold surjective; apply_instance
instance decidable_bijective_fintype [decidable_eq α] [decidable_eq β] [fintype α] [fintype β] :
decidable_pred (bijective : (α → β) → Prop) := λ x, by unfold bijective; apply_instance
instance decidable_right_inverse_fintype [decidable_eq α] [fintype α] (f : α → β) (g : β → α) :
decidable (function.right_inverse f g) :=
show decidable (∀ x, g (f x) = x), by apply_instance
instance decidable_left_inverse_fintype [decidable_eq β] [fintype β] (f : α → β) (g : β → α) :
decidable (function.left_inverse f g) :=
show decidable (∀ x, f (g x) = x), by apply_instance
lemma exists_max [fintype α] [nonempty α] {β : Type*} [linear_order β] (f : α → β) :
∃ x₀ : α, ∀ x, f x ≤ f x₀ :=
by simpa using exists_max_image univ f univ_nonempty
lemma exists_min [fintype α] [nonempty α]
{β : Type*} [linear_order β] (f : α → β) :
∃ x₀ : α, ∀ x, f x₀ ≤ f x :=
by simpa using exists_min_image univ f univ_nonempty
/-- Construct a proof of `fintype α` from a universal multiset -/
def of_multiset [decidable_eq α] (s : multiset α) (H : ∀ x : α, x ∈ s) :
fintype α :=
⟨s.to_finset, by simpa using H⟩
/-- Construct a proof of `fintype α` from a universal list -/
def of_list [decidable_eq α] (l : list α) (H : ∀ x : α, x ∈ l) :
fintype α :=
⟨l.to_finset, by simpa using H⟩
theorem exists_univ_list (α) [fintype α] :
∃ l : list α, l.nodup ∧ ∀ x : α, x ∈ l :=
let ⟨l, e⟩ := quotient.exists_rep (@univ α _).1 in
by have := and.intro univ.2 mem_univ_val;
exact ⟨_, by rwa ←e at this⟩
/-- `card α` is the number of elements in `α`, defined when `α` is a fintype. -/
def card (α) [fintype α] : ℕ := (@univ α _).card
/-- If `l` lists all the elements of `α` without duplicates, then `α ≃ fin (l.length)`. -/
def equiv_fin_of_forall_mem_list {α} [decidable_eq α]
{l : list α} (h : ∀ x : α, x ∈ l) (nd : l.nodup) : α ≃ fin (l.length) :=
⟨λ a, ⟨_, list.index_of_lt_length.2 (h a)⟩,
λ i, l.nth_le i.1 i.2,
λ a, by simp,
λ ⟨i, h⟩, fin.eq_of_veq $ list.nodup_iff_nth_le_inj.1 nd _ _
(list.index_of_lt_length.2 (list.nth_le_mem _ _ _)) h $ by simp⟩
/-- There is (computably) a bijection between `α` and `fin (card α)`.
Since it is not unique, and depends on which permutation
of the universe list is used, the bijection is wrapped in `trunc` to
preserve computability.
See `fintype.equiv_fin` for the noncomputable version,
and `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq`
for an equiv `α ≃ fin n` given `fintype.card α = n`.
-/
def trunc_equiv_fin (α) [decidable_eq α] [fintype α] : trunc (α ≃ fin (card α)) :=
by unfold card finset.card; exact
quot.rec_on_subsingleton (@univ α _).1
(λ l (h : ∀ x : α, x ∈ l) (nd : l.nodup), trunc.mk (equiv_fin_of_forall_mem_list h nd))
mem_univ_val univ.2
/-- There is a (noncomputable) bijection between `α` and `fin (card α)`.
See `fintype.trunc_equiv_fin` for the computable version,
and `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq`
for an equiv `α ≃ fin n` given `fintype.card α = n`.
-/
noncomputable def equiv_fin (α) [fintype α] : α ≃ fin (card α) :=
by { letI := classical.dec_eq α, exact (trunc_equiv_fin α).out }
instance (α : Type*) : subsingleton (fintype α) :=
⟨λ ⟨s₁, h₁⟩ ⟨s₂, h₂⟩, by congr; simp [finset.ext_iff, h₁, h₂]⟩
/-- Given a predicate that can be represented by a finset, the subtype
associated to the predicate is a fintype. -/
protected def subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) :
fintype {x // p x} :=
⟨⟨multiset.pmap subtype.mk s.1 (λ x, (H x).1),
multiset.nodup_pmap (λ a _ b _, congr_arg subtype.val) s.2⟩,
λ ⟨x, px⟩, multiset.mem_pmap.2 ⟨x, (H x).2 px, rfl⟩⟩
theorem subtype_card {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x) :
@card {x // p x} (fintype.subtype s H) = s.card :=
multiset.card_pmap _ _ _
theorem card_of_subtype {p : α → Prop} (s : finset α) (H : ∀ x : α, x ∈ s ↔ p x)
[fintype {x // p x}] :
card {x // p x} = s.card :=
by { rw ← subtype_card s H, congr }
/-- Construct a fintype from a finset with the same elements. -/
def of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) : fintype p :=
fintype.subtype s H
@[simp] theorem card_of_finset {p : set α} (s : finset α) (H : ∀ x, x ∈ s ↔ x ∈ p) :
@fintype.card p (of_finset s H) = s.card :=
fintype.subtype_card s H
theorem card_of_finset' {p : set α} (s : finset α)
(H : ∀ x, x ∈ s ↔ x ∈ p) [fintype p] : fintype.card p = s.card :=
by rw ←card_of_finset s H; congr
/-- If `f : α → β` is a bijection and `α` is a fintype, then `β` is also a fintype. -/
def of_bijective [fintype α] (f : α → β) (H : function.bijective f) : fintype β :=
⟨univ.map ⟨f, H.1⟩,
λ b, let ⟨a, e⟩ := H.2 b in e ▸ mem_map_of_mem _ (mem_univ _)⟩
/-- If `f : α → β` is a surjection and `α` is a fintype, then `β` is also a fintype. -/
def of_surjective [decidable_eq β] [fintype α] (f : α → β) (H : function.surjective f) :
fintype β :=
⟨univ.image f, λ b, let ⟨a, e⟩ := H b in e ▸ mem_image_of_mem _ (mem_univ _)⟩
end fintype
section inv
namespace function
variables [fintype α] [decidable_eq β]
namespace injective
variables {f : α → β} (hf : function.injective f)
/--
The inverse of an `hf : injective` function `f : α → β`, of the type `↥(set.range f) → α`.
This is the computable version of `function.inv_fun` that requires `fintype α` and `decidable_eq β`,
or the function version of applying `(equiv.of_injective f hf).symm`.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms `a : α` to find the `f a = b`, so it is O(N) where
`N = fintype.card α`.
-/
def inv_of_mem_range : set.range f → α :=
λ b, finset.choose (λ a, f a = b) finset.univ ((exists_unique_congr (by simp)).mp
(hf.exists_unique_of_mem_range b.property))
lemma left_inv_of_inv_of_mem_range (b : set.range f) :
f (hf.inv_of_mem_range b) = b :=
(finset.choose_spec (λ a, f a = b) _ _).right
@[simp] lemma right_inv_of_inv_of_mem_range (a : α) :
hf.inv_of_mem_range (⟨f a, set.mem_range_self a⟩) = a :=
hf (finset.choose_spec (λ a', f a' = f a) _ _).right
lemma inv_fun_restrict [nonempty α] :
(set.range f).restrict (inv_fun f) = hf.inv_of_mem_range :=
begin
ext ⟨b, h⟩,
apply hf,
simp [hf.left_inv_of_inv_of_mem_range, @inv_fun_eq _ _ _ f b (set.mem_range.mp h)]
end
lemma inv_of_mem_range_surjective : function.surjective hf.inv_of_mem_range :=
λ a, ⟨⟨f a, set.mem_range_self a⟩, by simp⟩
end injective
namespace embedding
variables (f : α ↪ β) (b : set.range f)
/--
The inverse of an embedding `f : α ↪ β`, of the type `↥(set.range f) → α`.
This is the computable version of `function.inv_fun` that requires `fintype α` and `decidable_eq β`,
or the function version of applying `(equiv.of_injective f f.injective).symm`.
This function should not usually be used for actual computation because for most cases,
an explicit inverse can be stated that has better computational properties.
This function computes by checking all terms `a : α` to find the `f a = b`, so it is O(N) where
`N = fintype.card α`.
-/
def inv_of_mem_range : α :=
f.injective.inv_of_mem_range b
@[simp] lemma left_inv_of_inv_of_mem_range :
f (f.inv_of_mem_range b) = b :=
f.injective.left_inv_of_inv_of_mem_range b
@[simp] lemma right_inv_of_inv_of_mem_range (a : α) :
f.inv_of_mem_range ⟨f a, set.mem_range_self a⟩ = a :=
f.injective.right_inv_of_inv_of_mem_range a
lemma inv_fun_restrict [nonempty α] :
(set.range f).restrict (inv_fun f) = f.inv_of_mem_range :=
begin
ext ⟨b, h⟩,
apply f.injective,
simp [f.left_inv_of_inv_of_mem_range, @inv_fun_eq _ _ _ f b (set.mem_range.mp h)]
end
lemma inv_of_mem_range_surjective : function.surjective f.inv_of_mem_range :=
λ a, ⟨⟨f a, set.mem_range_self a⟩, by simp⟩
end embedding
end function
end inv
namespace fintype
/-- Given an injective function to a fintype, the domain is also a
fintype. This is noncomputable because injectivity alone cannot be
used to construct preimages. -/
noncomputable def of_injective [fintype β] (f : α → β) (H : function.injective f) : fintype α :=
by letI := classical.dec; exact
if hα : nonempty α then by letI := classical.inhabited_of_nonempty hα;
exact of_surjective (inv_fun f) (inv_fun_surjective H)
else ⟨∅, λ x, (hα ⟨x⟩).elim⟩
/-- If `f : α ≃ β` and `α` is a fintype, then `β` is also a fintype. -/
def of_equiv (α : Type*) [fintype α] (f : α ≃ β) : fintype β := of_bijective _ f.bijective
theorem of_equiv_card [fintype α] (f : α ≃ β) :
@card β (of_equiv α f) = card α :=
multiset.card_map _ _
theorem card_congr {α β} [fintype α] [fintype β] (f : α ≃ β) : card α = card β :=
by rw ← of_equiv_card f; congr
section
variables [fintype α] [fintype β]
/-- If the cardinality of `α` is `n`, there is computably a bijection between `α` and `fin n`.
See `fintype.equiv_fin_of_card_eq` for the noncomputable definition,
and `fintype.trunc_equiv_fin` and `fintype.equiv_fin` for the bijection `α ≃ fin (card α)`.
-/
def trunc_equiv_fin_of_card_eq [decidable_eq α] {n : ℕ} (h : fintype.card α = n) :
trunc (α ≃ fin n) :=
(trunc_equiv_fin α).map (λ e, e.trans (fin.cast h).to_equiv)
/-- If the cardinality of `α` is `n`, there is noncomputably a bijection between `α` and `fin n`.
See `fintype.trunc_equiv_fin_of_card_eq` for the computable definition,
and `fintype.trunc_equiv_fin` and `fintype.equiv_fin` for the bijection `α ≃ fin (card α)`.
-/
noncomputable def equiv_fin_of_card_eq {n : ℕ} (h : fintype.card α = n) :
α ≃ fin n :=
by { letI := classical.dec_eq α, exact (trunc_equiv_fin_of_card_eq h).out }
/-- Two `fintype`s with the same cardinality are (computably) in bijection.
See `fintype.equiv_of_card_eq` for the noncomputable version,
and `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq` for
the specialization to `fin`.
-/
def trunc_equiv_of_card_eq [decidable_eq α] [decidable_eq β] (h : card α = card β) :
trunc (α ≃ β) :=
(trunc_equiv_fin_of_card_eq h).bind (λ e, (trunc_equiv_fin β).map (λ e', e.trans e'.symm))
/-- Two `fintype`s with the same cardinality are (noncomputably) in bijection.
See `fintype.trunc_equiv_of_card_eq` for the computable version,
and `fintype.trunc_equiv_fin_of_card_eq` and `fintype.equiv_fin_of_card_eq` for
the specialization to `fin`.
-/
noncomputable def equiv_of_card_eq (h : card α = card β) : α ≃ β :=
by { letI := classical.dec_eq α, letI := classical.dec_eq β,
exact (trunc_equiv_of_card_eq h).out }
end
theorem card_eq {α β} [F : fintype α] [G : fintype β] : card α = card β ↔ nonempty (α ≃ β) :=
⟨λ h, by { haveI := classical.prop_decidable, exact (trunc_equiv_of_card_eq h).nonempty },
λ ⟨f⟩, card_congr f⟩
/-- Any subsingleton type with a witness is a fintype (with one term). -/
def of_subsingleton (a : α) [subsingleton α] : fintype α :=
⟨{a}, λ b, finset.mem_singleton.2 (subsingleton.elim _ _)⟩
@[simp] theorem univ_of_subsingleton (a : α) [subsingleton α] :
@univ _ (of_subsingleton a) = {a} := rfl
/-- Note: this lemma is specifically about `fintype.of_subsingleton`. For a statement about
arbitrary `fintype` instances, use either `fintype.card_le_one_iff_subsingleton` or
`fintype.card_unique`. -/
@[simp] theorem card_of_subsingleton (a : α) [subsingleton α] :
@fintype.card _ (of_subsingleton a) = 1 := rfl
@[simp] theorem card_unique [unique α] [h : fintype α] :
fintype.card α = 1 :=
subsingleton.elim (of_subsingleton $ default α) h ▸ card_of_subsingleton _
@[priority 100] -- see Note [lower instance priority]
instance of_is_empty [is_empty α] : fintype α := ⟨∅, is_empty_elim⟩
/-- Note: this lemma is specifically about `fintype.of_is_empty`. For a statement about
arbitrary `fintype` instances, use `fintype.univ_is_empty`. -/
-- no-lint since while `fintype.of_is_empty` can prove this, it isn't applicable for `dsimp`.
@[simp, nolint simp_nf] theorem univ_of_is_empty [is_empty α] : @univ α _ = ∅ := rfl
/-- Note: this lemma is specifically about `fintype.of_is_empty`. For a statement about
arbitrary `fintype` instances, use `fintype.card_eq_zero_iff`. -/
@[simp] theorem card_of_is_empty [is_empty α] : fintype.card α = 0 := rfl
open_locale classical
variables (α)
/-- Any subsingleton type is (noncomputably) a fintype (with zero or one term). -/
@[priority 5] -- see Note [lower instance priority]
noncomputable instance of_subsingleton' [subsingleton α] : fintype α :=
if h : nonempty α then
of_subsingleton (nonempty.some h)
else
@fintype.of_is_empty _ $ not_nonempty_iff.mp h
end fintype
namespace set
/-- Construct a finset enumerating a set `s`, given a `fintype` instance. -/
def to_finset (s : set α) [fintype s] : finset α :=
⟨(@finset.univ s _).1.map subtype.val,
multiset.nodup_map (λ a b, subtype.eq) finset.univ.2⟩
@[simp] theorem mem_to_finset {s : set α} [fintype s] {a : α} : a ∈ s.to_finset ↔ a ∈ s :=
by simp [to_finset]
@[simp] theorem mem_to_finset_val {s : set α} [fintype s] {a : α} : a ∈ s.to_finset.1 ↔ a ∈ s :=
mem_to_finset
-- We use an arbitrary `[fintype s]` instance here,
-- not necessarily coming from a `[fintype α]`.
@[simp]
lemma to_finset_card {α : Type*} (s : set α) [fintype s] :
s.to_finset.card = fintype.card s :=
multiset.card_map subtype.val finset.univ.val
@[simp] theorem coe_to_finset (s : set α) [fintype s] : (↑s.to_finset : set α) = s :=
set.ext $ λ _, mem_to_finset
@[simp] theorem to_finset_inj {s t : set α} [fintype s] [fintype t] :
s.to_finset = t.to_finset ↔ s = t :=
⟨λ h, by rw [←s.coe_to_finset, h, t.coe_to_finset], λ h, by simp [h]; congr⟩
@[simp, mono] theorem to_finset_mono {s t : set α} [fintype s] [fintype t] :
s.to_finset ⊆ t.to_finset ↔ s ⊆ t :=
by simp [finset.subset_iff, set.subset_def]
@[simp, mono] theorem to_finset_strict_mono {s t : set α} [fintype s] [fintype t] :
s.to_finset ⊂ t.to_finset ↔ s ⊂ t :=
begin
rw [←lt_eq_ssubset, ←finset.lt_iff_ssubset, lt_iff_le_and_ne, lt_iff_le_and_ne],
simp
end
@[simp] theorem to_finset_disjoint_iff [decidable_eq α] {s t : set α} [fintype s] [fintype t] :
disjoint s.to_finset t.to_finset ↔ disjoint s t :=
⟨λ h x hx, h (by simpa using hx), λ h x hx, h (by simpa using hx)⟩
end set
lemma finset.card_univ [fintype α] : (finset.univ : finset α).card = fintype.card α :=
rfl
lemma finset.eq_univ_of_card [fintype α] (s : finset α) (hs : s.card = fintype.card α) :
s = univ :=
eq_of_subset_of_card_le (subset_univ _) $ by rw [hs, finset.card_univ]
lemma finset.card_eq_iff_eq_univ [fintype α] (s : finset α) :
s.card = fintype.card α ↔ s = finset.univ :=
⟨s.eq_univ_of_card, by { rintro rfl, exact finset.card_univ, }⟩
lemma finset.card_le_univ [fintype α] (s : finset α) :
s.card ≤ fintype.card α :=
card_le_of_subset (subset_univ s)
lemma finset.card_lt_univ_of_not_mem [fintype α] {s : finset α} {x : α} (hx : x ∉ s) :
s.card < fintype.card α :=
card_lt_card ⟨subset_univ s, not_forall.2 ⟨x, λ hx', hx (hx' $ mem_univ x)⟩⟩
lemma finset.card_lt_iff_ne_univ [fintype α] (s : finset α) :
s.card < fintype.card α ↔ s ≠ finset.univ :=
s.card_le_univ.lt_iff_ne.trans (not_iff_not_of_iff s.card_eq_iff_eq_univ)
lemma finset.card_compl_lt_iff_nonempty [fintype α] [decidable_eq α] (s : finset α) :
sᶜ.card < fintype.card α ↔ s.nonempty :=
sᶜ.card_lt_iff_ne_univ.trans s.compl_ne_univ_iff_nonempty
lemma finset.card_univ_diff [decidable_eq α] [fintype α] (s : finset α) :
(finset.univ \ s).card = fintype.card α - s.card :=
finset.card_sdiff (subset_univ s)
lemma finset.card_compl [decidable_eq α] [fintype α] (s : finset α) :
sᶜ.card = fintype.card α - s.card :=
finset.card_univ_diff s
instance (n : ℕ) : fintype (fin n) :=
⟨finset.fin_range n, finset.mem_fin_range⟩
lemma fin.univ_def (n : ℕ) : (univ : finset (fin n)) = finset.fin_range n := rfl
@[simp] theorem fintype.card_fin (n : ℕ) : fintype.card (fin n) = n :=
list.length_fin_range n
@[simp] lemma finset.card_fin (n : ℕ) : finset.card (finset.univ : finset (fin n)) = n :=
by rw [finset.card_univ, fintype.card_fin]
/-- The cardinality of `fin (bit0 k)` is even, `fact` version.
This `fact` is needed as an instance by `matrix.special_linear_group.has_neg`. -/
lemma fintype.card_fin_even {k : ℕ} : fact (even (fintype.card (fin (bit0 k)))) :=
⟨by { rw [fintype.card_fin], exact even_bit0 k }⟩
lemma card_finset_fin_le {n : ℕ} (s : finset (fin n)) : s.card ≤ n :=
by simpa only [fintype.card_fin] using s.card_le_univ
lemma fin.equiv_iff_eq {m n : ℕ} : nonempty (fin m ≃ fin n) ↔ m = n :=
⟨λ ⟨h⟩, by simpa using fintype.card_congr h, λ h, ⟨equiv.cast $ h ▸ rfl ⟩ ⟩
@[simp] lemma fin.image_succ_above_univ {n : ℕ} (i : fin (n + 1)) :
univ.image i.succ_above = {i}ᶜ :=
by { ext m, simp }
@[simp] lemma fin.image_succ_univ (n : ℕ) : (univ : finset (fin n)).image fin.succ = {0}ᶜ :=
by rw [← fin.succ_above_zero, fin.image_succ_above_univ]
@[simp] lemma fin.image_cast_succ (n : ℕ) :
(univ : finset (fin n)).image fin.cast_succ = {fin.last n}ᶜ :=
by rw [← fin.succ_above_last, fin.image_succ_above_univ]
/-- Embed `fin n` into `fin (n + 1)` by prepending zero to the `univ` -/
lemma fin.univ_succ (n : ℕ) :
(univ : finset (fin (n + 1))) = insert 0 (univ.image fin.succ) :=
by simp
/-- Embed `fin n` into `fin (n + 1)` by appending a new `fin.last n` to the `univ` -/
lemma fin.univ_cast_succ (n : ℕ) :
(univ : finset (fin (n + 1))) = insert (fin.last n) (univ.image fin.cast_succ) :=
by simp
/-- Embed `fin n` into `fin (n + 1)` by inserting
around a specified pivot `p : fin (n + 1)` into the `univ` -/
lemma fin.univ_succ_above (n : ℕ) (p : fin (n + 1)) :
(univ : finset (fin (n + 1))) = insert p (univ.image (fin.succ_above p)) :=
by simp
@[instance, priority 10] def unique.fintype {α : Type*} [unique α] : fintype α :=
fintype.of_subsingleton (default α)
/-- Short-circuit instance to decrease search for `unique.fintype`,
since that relies on a subsingleton elimination for `unique`. -/
instance fintype.subtype_eq (y : α) : fintype {x // x = y} :=
fintype.subtype {y} (by simp)
/-- Short-circuit instance to decrease search for `unique.fintype`,
since that relies on a subsingleton elimination for `unique`. -/
instance fintype.subtype_eq' (y : α) : fintype {x // y = x} :=
fintype.subtype {y} (by simp [eq_comm])
@[simp] lemma univ_unique {α : Type*} [unique α] [f : fintype α] : @finset.univ α _ = {default α} :=
by rw [subsingleton.elim f (@unique.fintype α _)]; refl
@[simp] lemma univ_is_empty {α : Type*} [is_empty α] [fintype α] : @finset.univ α _ = ∅ :=
finset.ext is_empty_elim
@[simp] lemma fintype.card_subtype_eq (y : α) [fintype {x // x = y}] :
fintype.card {x // x = y} = 1 :=
fintype.card_unique
@[simp] lemma fintype.card_subtype_eq' (y : α) [fintype {x // y = x}] :
fintype.card {x // y = x} = 1 :=
fintype.card_unique
@[simp] theorem fintype.univ_empty : @univ empty _ = ∅ := rfl
@[simp] theorem fintype.card_empty : fintype.card empty = 0 := rfl
@[simp] theorem fintype.univ_pempty : @univ pempty _ = ∅ := rfl
@[simp] theorem fintype.card_pempty : fintype.card pempty = 0 := rfl
instance : fintype unit := fintype.of_subsingleton ()
theorem fintype.univ_unit : @univ unit _ = {()} := rfl
theorem fintype.card_unit : fintype.card unit = 1 := rfl
instance : fintype punit := fintype.of_subsingleton punit.star
@[simp] theorem fintype.univ_punit : @univ punit _ = {punit.star} := rfl
@[simp] theorem fintype.card_punit : fintype.card punit = 1 := rfl
instance : fintype bool := ⟨⟨tt ::ₘ ff ::ₘ 0, by simp⟩, λ x, by cases x; simp⟩
@[simp] theorem fintype.univ_bool : @univ bool _ = {tt, ff} := rfl
instance units_int.fintype : fintype (units ℤ) :=
⟨{1, -1}, λ x, by cases int.units_eq_one_or x; simp *⟩
@[simp] lemma units_int.univ : (finset.univ : finset (units ℤ)) = {1, -1} := rfl
instance additive.fintype : Π [fintype α], fintype (additive α) := id
instance multiplicative.fintype : Π [fintype α], fintype (multiplicative α) := id
@[simp] theorem fintype.card_units_int : fintype.card (units ℤ) = 2 := rfl
@[simp] theorem fintype.card_bool : fintype.card bool = 2 := rfl
instance {α : Type*} [fintype α] : fintype (option α) :=
⟨univ.insert_none, λ a, by simp⟩
@[simp] theorem fintype.card_option {α : Type*} [fintype α] :
fintype.card (option α) = fintype.card α + 1 :=
(finset.card_cons _).trans $ congr_arg2 _ (card_map _) rfl
instance {α : Type*} (β : α → Type*)
[fintype α] [∀ a, fintype (β a)] : fintype (sigma β) :=
⟨univ.sigma (λ _, univ), λ ⟨a, b⟩, by simp⟩
@[simp] lemma finset.univ_sigma_univ {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
(univ : finset α).sigma (λ a, (univ : finset (β a))) = univ := rfl
instance (α β : Type*) [fintype α] [fintype β] : fintype (α × β) :=
⟨univ.product univ, λ ⟨a, b⟩, by simp⟩
@[simp] lemma finset.univ_product_univ {α β : Type*} [fintype α] [fintype β] :
(univ : finset α).product (univ : finset β) = univ :=
rfl
@[simp] theorem fintype.card_prod (α β : Type*) [fintype α] [fintype β] :
fintype.card (α × β) = fintype.card α * fintype.card β :=
card_product _ _
/-- Given that `α × β` is a fintype, `α` is also a fintype. -/
def fintype.prod_left {α β} [decidable_eq α] [fintype (α × β)] [nonempty β] : fintype α :=
⟨(fintype.elems (α × β)).image prod.fst,
λ a, let ⟨b⟩ := ‹nonempty β› in by simp; exact ⟨b, fintype.complete _⟩⟩
/-- Given that `α × β` is a fintype, `β` is also a fintype. -/
def fintype.prod_right {α β} [decidable_eq β] [fintype (α × β)] [nonempty α] : fintype β :=
⟨(fintype.elems (α × β)).image prod.snd,
λ b, let ⟨a⟩ := ‹nonempty α› in by simp; exact ⟨a, fintype.complete _⟩⟩
instance (α : Type*) [fintype α] : fintype (ulift α) :=
fintype.of_equiv _ equiv.ulift.symm
@[simp] theorem fintype.card_ulift (α : Type*) [fintype α] :
fintype.card (ulift α) = fintype.card α :=
fintype.of_equiv_card _
instance (α : Type*) [fintype α] : fintype (plift α) :=
fintype.of_equiv _ equiv.plift.symm
@[simp] theorem fintype.card_plift (α : Type*) [fintype α] :
fintype.card (plift α) = fintype.card α :=
fintype.of_equiv_card _
lemma univ_sum_type {α β : Type*} [fintype α] [fintype β] [fintype (α ⊕ β)] [decidable_eq (α ⊕ β)] :
(univ : finset (α ⊕ β)) = map function.embedding.inl univ ∪ map function.embedding.inr univ :=
begin
rw [eq_comm, eq_univ_iff_forall], simp only [mem_union, mem_map, exists_prop, mem_univ, true_and],
rintro (x|y), exacts [or.inl ⟨x, rfl⟩, or.inr ⟨y, rfl⟩]
end
instance (α : Type u) (β : Type v) [fintype α] [fintype β] : fintype (α ⊕ β) :=
@fintype.of_equiv _ _ (@sigma.fintype _
(λ b, cond b (ulift α) (ulift.{(max u v) v} β)) _
(λ b, by cases b; apply ulift.fintype))
((equiv.sum_equiv_sigma_bool _ _).symm.trans
(equiv.sum_congr equiv.ulift equiv.ulift))
/-- Given that `α ⊕ β` is a fintype, `α` is also a fintype. This is non-computable as it uses
that `sum.inl` is an injection, but there's no clear inverse if `α` is empty. -/
noncomputable def fintype.sum_left {α β} [fintype (α ⊕ β)] : fintype α :=
fintype.of_injective (sum.inl : α → α ⊕ β) sum.inl_injective
/-- Given that `α ⊕ β` is a fintype, `β` is also a fintype. This is non-computable as it uses
that `sum.inr` is an injection, but there's no clear inverse if `β` is empty. -/
noncomputable def fintype.sum_right {α β} [fintype (α ⊕ β)] : fintype β :=
fintype.of_injective (sum.inr : β → α ⊕ β) sum.inr_injective
@[simp] theorem fintype.card_sum [fintype α] [fintype β] :
fintype.card (α ⊕ β) = fintype.card α + fintype.card β :=
begin
classical,
rw [←finset.card_univ, univ_sum_type, finset.card_union_eq],
{ simp [finset.card_univ] },
{ intros x hx,
suffices : (∃ (a : α), sum.inl a = x) ∧ ∃ (b : β), sum.inr b = x,
{ obtain ⟨⟨a, rfl⟩, ⟨b, hb⟩⟩ := this,
simpa using hb },
simpa using hx }
end
/-- If the subtype of all-but-one elements is a `fintype` then the type itself is a `fintype`. -/
def fintype_of_fintype_ne (a : α) [decidable_pred (= a)] (h : fintype {b // b ≠ a}) : fintype α :=
fintype.of_equiv _ $ equiv.sum_compl (= a)
section finset
/-! ### `fintype (s : finset α)` -/
instance finset.fintype_coe_sort {α : Type u} (s : finset α) : fintype s :=
⟨s.attach, s.mem_attach⟩
@[simp] lemma finset.univ_eq_attach {α : Type u} (s : finset α) :
(univ : finset s) = s.attach :=
rfl
end finset
namespace fintype
variables [fintype α] [fintype β]
lemma card_le_of_injective (f : α → β) (hf : function.injective f) : card α ≤ card β :=
finset.card_le_card_of_inj_on f (λ _ _, finset.mem_univ _) (λ _ _ _ _ h, hf h)
lemma card_le_of_embedding (f : α ↪ β) : card α ≤ card β := card_le_of_injective f f.2
lemma card_lt_of_injective_of_not_mem (f : α → β) (h : function.injective f)
{b : β} (w : b ∉ set.range f) : card α < card β :=
calc card α = (univ.map ⟨f, h⟩).card : (card_map _).symm
... < card β : finset.card_lt_univ_of_not_mem $
by rwa [← mem_coe, coe_map, coe_univ, set.image_univ]
lemma card_lt_of_injective_not_surjective (f : α → β) (h : function.injective f)
(h' : ¬function.surjective f) : card α < card β :=
let ⟨y, hy⟩ := not_forall.1 h' in card_lt_of_injective_of_not_mem f h hy
lemma card_le_of_surjective (f : α → β) (h : function.surjective f) : card β ≤ card α :=
card_le_of_injective _ (function.injective_surj_inv h)
/--
The pigeonhole principle for finitely many pigeons and pigeonholes.
This is the `fintype` version of `finset.exists_ne_map_eq_of_card_lt_of_maps_to`.
-/
lemma exists_ne_map_eq_of_card_lt (f : α → β) (h : fintype.card β < fintype.card α) :
∃ x y, x ≠ y ∧ f x = f y :=
let ⟨x, _, y, _, h⟩ := finset.exists_ne_map_eq_of_card_lt_of_maps_to h (λ x _, mem_univ (f x))
in ⟨x, y, h⟩
lemma card_eq_one_iff : card α = 1 ↔ (∃ x : α, ∀ y, y = x) :=
by rw [←card_unit, card_eq]; exact
⟨λ ⟨a⟩, ⟨a.symm (), λ y, a.injective (subsingleton.elim _ _)⟩,
λ ⟨x, hx⟩, ⟨⟨λ _, (), λ _, x, λ _, (hx _).trans (hx _).symm,
λ _, subsingleton.elim _ _⟩⟩⟩
lemma card_eq_zero_iff : card α = 0 ↔ is_empty α :=
by rw [card, finset.card_eq_zero, univ_eq_empty_iff]
lemma card_eq_zero [is_empty α] : card α = 0 := card_eq_zero_iff.2 ‹_›
lemma card_eq_one_iff_nonempty_unique : card α = 1 ↔ nonempty (unique α) :=
⟨λ h, let ⟨d, h⟩ := fintype.card_eq_one_iff.mp h in ⟨{ default := d, uniq := h}⟩,
λ ⟨h⟩, by exactI fintype.card_unique⟩
/-- A `fintype` with cardinality zero is equivalent to `empty`. -/
def card_eq_zero_equiv_equiv_empty : card α = 0 ≃ (α ≃ empty) :=
(equiv.of_iff card_eq_zero_iff).trans (equiv.equiv_empty_equiv α).symm
lemma card_pos_iff : 0 < card α ↔ nonempty α :=
pos_iff_ne_zero.trans $ not_iff_comm.mp $ not_nonempty_iff.trans card_eq_zero_iff.symm
lemma card_pos [h : nonempty α] : 0 < card α :=
card_pos_iff.mpr h
lemma card_ne_zero [nonempty α] : card α ≠ 0 :=
ne_of_gt card_pos
lemma card_le_one_iff : card α ≤ 1 ↔ (∀ a b : α, a = b) :=
let n := card α in
have hn : n = card α := rfl,
match n, hn with
| 0 := λ ha, ⟨λ h, λ a, (card_eq_zero_iff.1 ha.symm).elim a, λ _, ha ▸ nat.le_succ _⟩
| 1 := λ ha, ⟨λ h, λ a b, let ⟨x, hx⟩ := card_eq_one_iff.1 ha.symm in
by rw [hx a, hx b],
λ _, ha ▸ le_refl _⟩
| (n+2) := λ ha, ⟨λ h, by rw ← ha at h; exact absurd h dec_trivial,
(λ h, card_unit ▸ card_le_of_injective (λ _, ())
(λ _ _ _, h _ _))⟩
end
lemma card_le_one_iff_subsingleton : card α ≤ 1 ↔ subsingleton α :=
card_le_one_iff.trans subsingleton_iff.symm
lemma one_lt_card_iff_nontrivial : 1 < card α ↔ nontrivial α :=
begin
classical,
rw ←not_iff_not,
push_neg,
rw [not_nontrivial_iff_subsingleton, card_le_one_iff_subsingleton]
end
lemma exists_ne_of_one_lt_card (h : 1 < card α) (a : α) : ∃ b : α, b ≠ a :=
by { haveI : nontrivial α := one_lt_card_iff_nontrivial.1 h, exact exists_ne a }
lemma exists_pair_of_one_lt_card (h : 1 < card α) : ∃ (a b : α), a ≠ b :=
by { haveI : nontrivial α := one_lt_card_iff_nontrivial.1 h, exact exists_pair_ne α }
lemma card_eq_one_of_forall_eq {i : α} (h : ∀ j, j = i) : card α = 1 :=
fintype.card_eq_one_iff.2 ⟨i,h⟩
lemma one_lt_card [h : nontrivial α] : 1 < fintype.card α :=
fintype.one_lt_card_iff_nontrivial.mpr h
lemma injective_iff_surjective {f : α → α} : injective f ↔ surjective f :=
by haveI := classical.prop_decidable; exact
have ∀ {f : α → α}, injective f → surjective f,
from λ f hinj x,
have h₁ : image f univ = univ := eq_of_subset_of_card_le (subset_univ _)
((card_image_of_injective univ hinj).symm ▸ le_refl _),
have h₂ : x ∈ image f univ := h₁.symm ▸ mem_univ _,
exists_of_bex (mem_image.1 h₂),
⟨this,
λ hsurj, has_left_inverse.injective
⟨surj_inv hsurj, left_inverse_of_surjective_of_right_inverse
(this (injective_surj_inv _)) (right_inverse_surj_inv _)⟩⟩
lemma injective_iff_bijective {f : α → α} : injective f ↔ bijective f :=
by simp [bijective, injective_iff_surjective]
lemma surjective_iff_bijective {f : α → α} : surjective f ↔ bijective f :=
by simp [bijective, injective_iff_surjective]
lemma injective_iff_surjective_of_equiv {β : Type*} {f : α → β} (e : α ≃ β) :
injective f ↔ surjective f :=
have injective (e.symm ∘ f) ↔ surjective (e.symm ∘ f), from injective_iff_surjective,
⟨λ hinj, by simpa [function.comp] using
e.surjective.comp (this.1 (e.symm.injective.comp hinj)),
λ hsurj, by simpa [function.comp] using
e.injective.comp (this.2 (e.symm.surjective.comp hsurj))⟩
lemma card_of_bijective {f : α → β} (hf : bijective f) : card α = card β :=
card_congr (equiv.of_bijective f hf)
lemma bijective_iff_injective_and_card (f : α → β) :
bijective f ↔ injective f ∧ card α = card β :=
begin
split,
{ intro h, exact ⟨h.1, card_of_bijective h⟩ },
{ rintro ⟨hf, h⟩,
refine ⟨hf, _⟩,
rwa ←injective_iff_surjective_of_equiv (equiv_of_card_eq h) }
end
lemma bijective_iff_surjective_and_card (f : α → β) :
bijective f ↔ surjective f ∧ card α = card β :=
begin
split,
{ intro h, exact ⟨h.2, card_of_bijective h⟩ },
{ rintro ⟨hf, h⟩,
refine ⟨_, hf⟩,
rwa injective_iff_surjective_of_equiv (equiv_of_card_eq h) }
end
lemma right_inverse_of_left_inverse_of_card_le {f : α → β} {g : β → α}
(hfg : left_inverse f g) (hcard : card α ≤ card β) :
right_inverse f g :=
have hsurj : surjective f, from surjective_iff_has_right_inverse.2 ⟨g, hfg⟩,
right_inverse_of_injective_of_left_inverse
((bijective_iff_surjective_and_card _).2
⟨hsurj, le_antisymm hcard (card_le_of_surjective f hsurj)⟩ ).1
hfg
lemma left_inverse_of_right_inverse_of_card_le {f : α → β} {g : β → α}
(hfg : right_inverse f g) (hcard : card β ≤ card α) :
left_inverse f g :=
right_inverse_of_left_inverse_of_card_le hfg hcard
end fintype
lemma fintype.coe_image_univ [fintype α] [decidable_eq β] {f : α → β} :
↑(finset.image f finset.univ) = set.range f :=
by { ext x, simp }
instance list.subtype.fintype [decidable_eq α] (l : list α) : fintype {x // x ∈ l} :=
fintype.of_list l.attach l.mem_attach
instance multiset.subtype.fintype [decidable_eq α] (s : multiset α) : fintype {x // x ∈ s} :=
fintype.of_multiset s.attach s.mem_attach
instance finset.subtype.fintype (s : finset α) : fintype {x // x ∈ s} :=
⟨s.attach, s.mem_attach⟩
instance finset_coe.fintype (s : finset α) : fintype (↑s : set α) :=
finset.subtype.fintype s
@[simp] lemma fintype.card_coe (s : finset α) :
fintype.card s = s.card := card_attach
lemma finset.attach_eq_univ {s : finset α} : s.attach = finset.univ := rfl
instance plift.fintype_Prop (p : Prop) [decidable p] : fintype (plift p) :=
⟨if h : p then {⟨h⟩} else ∅, λ ⟨h⟩, by simp [h]⟩
instance Prop.fintype : fintype Prop :=
⟨⟨true ::ₘ false ::ₘ 0, by simp [true_ne_false]⟩,
classical.cases (by simp) (by simp)⟩
@[simp] lemma fintype.card_Prop : fintype.card Prop = 2 := rfl
instance subtype.fintype (p : α → Prop) [decidable_pred p] [fintype α] : fintype {x // p x} :=
fintype.subtype (univ.filter p) (by simp)
/-- A set on a fintype, when coerced to a type, is a fintype. -/
def set_fintype {α} [fintype α] (s : set α) [decidable_pred (∈ s)] : fintype s :=
subtype.fintype (λ x, x ∈ s)
lemma set_fintype_card_le_univ {α : Type*} [fintype α] (s : set α) [fintype ↥s] :
fintype.card ↥s ≤ fintype.card α :=
fintype.card_le_of_embedding (function.embedding.subtype s)
section
variables (α)
/-- The `units α` type is equivalent to a subtype of `α × α`. -/
@[simps]
def _root_.units_equiv_prod_subtype [monoid α] :
units α ≃ {p : α × α // p.1 * p.2 = 1 ∧ p.2 * p.1 = 1} :=
{ to_fun := λ u, ⟨(u, ↑u⁻¹), u.val_inv, u.inv_val⟩,
inv_fun := λ p, units.mk (p : α × α).1 (p : α × α).2 p.prop.1 p.prop.2,
left_inv := λ u, units.ext rfl,
right_inv := λ p, subtype.ext $ prod.ext rfl rfl}
/-- In a `group_with_zero` `α`, the unit group `units α` is equivalent to the subtype of nonzero
elements. -/
@[simps]
def _root_.units_equiv_ne_zero [group_with_zero α] : units α ≃ {a : α // a ≠ 0} :=
⟨λ a, ⟨a, a.ne_zero⟩, λ a, units.mk0 _ a.prop, λ _, units.ext rfl, λ _, subtype.ext rfl⟩
end
instance [monoid α] [fintype α] [decidable_eq α] : fintype (units α) :=
fintype.of_equiv _ (units_equiv_prod_subtype α).symm
lemma fintype.card_units [group_with_zero α] [fintype α] [fintype (units α)] :
fintype.card (units α) = fintype.card α - 1 :=
begin
classical,
rw [eq_comm, nat.sub_eq_iff_eq_add (fintype.card_pos_iff.2 ⟨(0 : α)⟩),
fintype.card_congr (units_equiv_ne_zero α)],
have := fintype.card_congr (equiv.sum_compl (= (0 : α))).symm,
rwa [fintype.card_sum, add_comm, fintype.card_subtype_eq] at this,
end
namespace function.embedding
/-- An embedding from a `fintype` to itself can be promoted to an equivalence. -/
noncomputable def equiv_of_fintype_self_embedding [fintype α] (e : α ↪ α) : α ≃ α :=
equiv.of_bijective e (fintype.injective_iff_bijective.1 e.2)
@[simp]
lemma equiv_of_fintype_self_embedding_to_embedding [fintype α] (e : α ↪ α) :
e.equiv_of_fintype_self_embedding.to_embedding = e :=
by { ext, refl, }
/-- If `‖β‖ < ‖α‖` there are no embeddings `α ↪ β`.
This is a formulation of the pigeonhole principle.
Note this cannot be an instance as it needs `h`. -/
@[simp] lemma is_empty_of_card_lt [fintype α] [fintype β]
(h : fintype.card β < fintype.card α) : is_empty (α ↪ β) :=
⟨λ f, let ⟨x, y, ne, feq⟩ := fintype.exists_ne_map_eq_of_card_lt f h in ne $ f.injective feq⟩
/-- A constructive embedding of a fintype `α` in another fintype `β` when `card α ≤ card β`. -/
def trunc_of_card_le [fintype α] [fintype β] [decidable_eq α] [decidable_eq β]
(h : fintype.card α ≤ fintype.card β) : trunc (α ↪ β) :=
(fintype.trunc_equiv_fin α).bind $ λ ea,
(fintype.trunc_equiv_fin β).map $ λ eb,
ea.to_embedding.trans ((fin.cast_le h).to_embedding.trans eb.symm.to_embedding)
lemma nonempty_of_card_le [fintype α] [fintype β]
(h : fintype.card α ≤ fintype.card β) : nonempty (α ↪ β) :=
by { classical, exact (trunc_of_card_le h).nonempty }
lemma exists_of_card_le_finset [fintype α] {s : finset β} (h : fintype.card α ≤ s.card) :
∃ (f : α ↪ β), set.range f ⊆ s :=
begin
rw ← fintype.card_coe at h,
rcases nonempty_of_card_le h with ⟨f⟩,
exact ⟨f.trans (embedding.subtype _), by simp [set.range_subset_iff]⟩
end
end function.embedding
@[simp]
lemma finset.univ_map_embedding {α : Type*} [fintype α] (e : α ↪ α) :
univ.map e = univ :=
by rw [←e.equiv_of_fintype_self_embedding_to_embedding, univ_map_equiv_to_embedding]
namespace fintype
lemma card_lt_of_surjective_not_injective [fintype α] [fintype β] (f : α → β)
(h : function.surjective f) (h' : ¬function.injective f) : card β < card α :=
card_lt_of_injective_not_surjective _ (function.injective_surj_inv h) $ λ hg,
have w : function.bijective (function.surj_inv h) := ⟨function.injective_surj_inv h, hg⟩,
h' $ (injective_iff_surjective_of_equiv (equiv.of_bijective _ w).symm).mpr h
variables [decidable_eq α] [fintype α] {δ : α → Type*}
/-- Given for all `a : α` a finset `t a` of `δ a`, then one can define the
finset `fintype.pi_finset t` of all functions taking values in `t a` for all `a`. This is the
analogue of `finset.pi` where the base finset is `univ` (but formally they are not the same, as
there is an additional condition `i ∈ finset.univ` in the `finset.pi` definition). -/
def pi_finset (t : Π a, finset (δ a)) : finset (Π a, δ a) :=
(finset.univ.pi t).map ⟨λ f a, f a (mem_univ a), λ _ _, by simp [function.funext_iff]⟩
@[simp] lemma mem_pi_finset {t : Π a, finset (δ a)} {f : Π a, δ a} :
f ∈ pi_finset t ↔ (∀ a, f a ∈ t a) :=
begin
split,
{ simp only [pi_finset, mem_map, and_imp, forall_prop_of_true, exists_prop, mem_univ,
exists_imp_distrib, mem_pi],
rintro g hg hgf a,
rw ← hgf,
exact hg a },
{ simp only [pi_finset, mem_map, forall_prop_of_true, exists_prop, mem_univ, mem_pi],
exact λ hf, ⟨λ a ha, f a, hf, rfl⟩ }
end
lemma pi_finset_subset (t₁ t₂ : Π a, finset (δ a)) (h : ∀ a, t₁ a ⊆ t₂ a) :
pi_finset t₁ ⊆ pi_finset t₂ :=
λ g hg, mem_pi_finset.2 $ λ a, h a $ mem_pi_finset.1 hg a
lemma pi_finset_disjoint_of_disjoint [∀ a, decidable_eq (δ a)]
(t₁ t₂ : Π a, finset (δ a)) {a : α} (h : disjoint (t₁ a) (t₂ a)) :
disjoint (pi_finset t₁) (pi_finset t₂) :=
disjoint_iff_ne.2 $ λ f₁ hf₁ f₂ hf₂ eq₁₂,
disjoint_iff_ne.1 h (f₁ a) (mem_pi_finset.1 hf₁ a) (f₂ a) (mem_pi_finset.1 hf₂ a) (congr_fun eq₁₂ a)
end fintype
/-! ### pi -/
/-- A dependent product of fintypes, indexed by a fintype, is a fintype. -/
instance pi.fintype {α : Type*} {β : α → Type*}
[decidable_eq α] [fintype α] [∀ a, fintype (β a)] : fintype (Π a, β a) :=
⟨fintype.pi_finset (λ _, univ), by simp⟩
@[simp] lemma fintype.pi_finset_univ {α : Type*} {β : α → Type*}
[decidable_eq α] [fintype α] [∀ a, fintype (β a)] :
fintype.pi_finset (λ a : α, (finset.univ : finset (β a))) = (finset.univ : finset (Π a, β a)) :=
rfl
instance d_array.fintype {n : ℕ} {α : fin n → Type*}
[∀ n, fintype (α n)] : fintype (d_array n α) :=
fintype.of_equiv _ (equiv.d_array_equiv_fin _).symm
instance array.fintype {n : ℕ} {α : Type*} [fintype α] : fintype (array n α) :=
d_array.fintype
instance vector.fintype {α : Type*} [fintype α] {n : ℕ} : fintype (vector α n) :=
fintype.of_equiv _ (equiv.vector_equiv_fin _ _).symm
instance quotient.fintype [fintype α] (s : setoid α)
[decidable_rel ((≈) : α → α → Prop)] : fintype (quotient s) :=
fintype.of_surjective quotient.mk (λ x, quotient.induction_on x (λ x, ⟨x, rfl⟩))
instance finset.fintype [fintype α] : fintype (finset α) :=
⟨univ.powerset, λ x, finset.mem_powerset.2 (finset.subset_univ _)⟩
-- irreducible due to this conversation on Zulip:
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/
-- topic/.60simp.60.20ignoring.20lemmas.3F/near/241824115
@[irreducible] instance function.embedding.fintype {α β} [fintype α] [fintype β]
[decidable_eq α] [decidable_eq β] : fintype (α ↪ β) :=
fintype.of_equiv _ (equiv.subtype_injective_equiv_embedding α β)
instance [decidable_eq α] [fintype α] {n : ℕ} : fintype (sym.sym' α n) :=
quotient.fintype _
instance [decidable_eq α] [fintype α] {n : ℕ} : fintype (sym α n) :=
fintype.of_equiv _ sym.sym_equiv_sym'.symm
@[simp] lemma fintype.card_finset [fintype α] :
fintype.card (finset α) = 2 ^ (fintype.card α) :=
finset.card_powerset finset.univ
@[simp] lemma finset.univ_filter_card_eq (α : Type*) [fintype α] (k : ℕ) :
(finset.univ : finset (finset α)).filter (λ s, s.card = k) = finset.univ.powerset_len k :=
by { ext, simp [finset.mem_powerset_len] }
@[simp] lemma fintype.card_finset_len [fintype α] (k : ℕ) :
fintype.card {s : finset α // s.card = k} = nat.choose (fintype.card α) k :=
by simp [fintype.subtype_card, finset.card_univ]
@[simp] lemma set.to_finset_univ [fintype α] :
(set.univ : set α).to_finset = finset.univ :=
by { ext, simp only [set.mem_univ, mem_univ, set.mem_to_finset] }
@[simp] lemma set.to_finset_eq_empty_iff {s : set α} [fintype s] :
s.to_finset = ∅ ↔ s = ∅ :=
by simp [ext_iff, set.ext_iff]
@[simp] lemma set.to_finset_empty :
(∅ : set α).to_finset = ∅ :=
set.to_finset_eq_empty_iff.mpr rfl
@[simp] lemma set.to_finset_range [decidable_eq α] [fintype β] (f : β → α) [fintype (set.range f)] :
(set.range f).to_finset = finset.univ.image f :=
by simp [ext_iff]
theorem fintype.card_subtype_le [fintype α] (p : α → Prop) [decidable_pred p] :
fintype.card {x // p x} ≤ fintype.card α :=
fintype.card_le_of_embedding (function.embedding.subtype _)
theorem fintype.card_subtype_lt [fintype α] {p : α → Prop} [decidable_pred p]
{x : α} (hx : ¬ p x) : fintype.card {x // p x} < fintype.card α :=
fintype.card_lt_of_injective_of_not_mem coe subtype.coe_injective $ by rwa subtype.range_coe_subtype
lemma fintype.card_subtype [fintype α] (p : α → Prop) [decidable_pred p] :
fintype.card {x // p x} = ((finset.univ : finset α).filter p).card :=
begin
refine fintype.card_of_subtype _ _,
simp
end
lemma fintype.card_subtype_or (p q : α → Prop)
[fintype {x // p x}] [fintype {x // q x}] [fintype {x // p x ∨ q x}] :
fintype.card {x // p x ∨ q x} ≤ fintype.card {x // p x} + fintype.card {x // q x} :=
begin
classical,
convert fintype.card_le_of_embedding (subtype_or_left_embedding p q),
rw fintype.card_sum
end
lemma fintype.card_subtype_or_disjoint (p q : α → Prop) (h : disjoint p q)
[fintype {x // p x}] [fintype {x // q x}] [fintype {x // p x ∨ q x}] :
fintype.card {x // p x ∨ q x} = fintype.card {x // p x} + fintype.card {x // q x} :=
begin
classical,
convert fintype.card_congr (subtype_or_equiv p q h),
simp
end
theorem fintype.card_quotient_le [fintype α] (s : setoid α) [decidable_rel ((≈) : α → α → Prop)] :
fintype.card (quotient s) ≤ fintype.card α :=
fintype.card_le_of_surjective _ (surjective_quotient_mk _)
theorem fintype.card_quotient_lt [fintype α] {s : setoid α} [decidable_rel ((≈) : α → α → Prop)]
{x y : α} (h1 : x ≠ y) (h2 : x ≈ y) : fintype.card (quotient s) < fintype.card α :=
fintype.card_lt_of_surjective_not_injective _ (surjective_quotient_mk _) $ λ w,
h1 (w $ quotient.eq.mpr h2)
instance psigma.fintype {α : Type*} {β : α → Type*} [fintype α] [∀ a, fintype (β a)] :
fintype (Σ' a, β a) :=
fintype.of_equiv _ (equiv.psigma_equiv_sigma _).symm
instance psigma.fintype_prop_left {α : Prop} {β : α → Type*} [decidable α] [∀ a, fintype (β a)] :
fintype (Σ' a, β a) :=
if h : α then fintype.of_equiv (β h) ⟨λ x, ⟨h, x⟩, psigma.snd, λ _, rfl, λ ⟨_, _⟩, rfl⟩
else ⟨∅, λ x, h x.1⟩
instance psigma.fintype_prop_right {α : Type*} {β : α → Prop} [∀ a, decidable (β a)] [fintype α] :
fintype (Σ' a, β a) :=
fintype.of_equiv {a // β a} ⟨λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, ⟨x, y⟩, λ ⟨x, y⟩, rfl, λ ⟨x, y⟩, rfl⟩
instance psigma.fintype_prop_prop {α : Prop} {β : α → Prop} [decidable α] [∀ a, decidable (β a)] :
fintype (Σ' a, β a) :=
if h : ∃ a, β a then ⟨{⟨h.fst, h.snd⟩}, λ ⟨_, _⟩, by simp⟩ else ⟨∅, λ ⟨x, y⟩, h ⟨x, y⟩⟩
instance set.fintype [fintype α] : fintype (set α) :=
⟨(@finset.univ α _).powerset.map ⟨coe, coe_injective⟩, λ s, begin
classical, refine mem_map.2 ⟨finset.univ.filter s, mem_powerset.2 (subset_univ _), _⟩,
apply (coe_filter _ _).trans, rw [coe_univ, set.sep_univ], refl
end⟩
@[simp] lemma fintype.card_set [fintype α] : fintype.card (set α) = 2 ^ fintype.card α :=
(finset.card_map _).trans (finset.card_powerset _)
instance pfun_fintype (p : Prop) [decidable p] (α : p → Type*)
[Π hp, fintype (α hp)] : fintype (Π hp : p, α hp) :=
if hp : p then fintype.of_equiv (α hp) ⟨λ a _, a, λ f, f hp, λ _, rfl, λ _, rfl⟩
else ⟨singleton (λ h, (hp h).elim), by simp [hp, function.funext_iff]⟩
@[simp] lemma finset.univ_pi_univ {α : Type*} {β : α → Type*}
[decidable_eq α] [fintype α] [∀ a, fintype (β a)] :
finset.univ.pi (λ a : α, (finset.univ : finset (β a))) = finset.univ :=
by { ext, simp }
lemma mem_image_univ_iff_mem_range
{α β : Type*} [fintype α] [decidable_eq β] {f : α → β} {b : β} :
b ∈ univ.image f ↔ b ∈ set.range f :=
by simp
/-- An auxiliary function for `quotient.fin_choice`. Given a
collection of setoids indexed by a type `ι`, a (finite) list `l` of
indices, and a function that for each `i ∈ l` gives a term of the
corresponding quotient type, then there is a corresponding term in the
quotient of the product of the setoids indexed by `l`. -/
def quotient.fin_choice_aux {ι : Type*} [decidable_eq ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
Π (l : list ι), (Π i ∈ l, quotient (S i)) → @quotient (Π i ∈ l, α i) (by apply_instance)
| [] f := ⟦λ i, false.elim⟧
| (i :: l) f := begin
refine quotient.lift_on₂ (f i (list.mem_cons_self _ _))
(quotient.fin_choice_aux l (λ j h, f j (list.mem_cons_of_mem _ h)))
_ _,
exact λ a l, ⟦λ j h,
if e : j = i then by rw e; exact a else
l _ (h.resolve_left e)⟧,
refine λ a₁ l₁ a₂ l₂ h₁ h₂, quotient.sound (λ j h, _),
by_cases e : j = i; simp [e],
{ subst j, exact h₁ },
{ exact h₂ _ _ }
end
theorem quotient.fin_choice_aux_eq {ι : Type*} [decidable_eq ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)] :
∀ (l : list ι) (f : Π i ∈ l, α i), quotient.fin_choice_aux l (λ i h, ⟦f i h⟧) = ⟦f⟧
| [] f := quotient.sound (λ i h, h.elim)
| (i :: l) f := begin
simp [quotient.fin_choice_aux, quotient.fin_choice_aux_eq l],
refine quotient.sound (λ j h, _),
by_cases e : j = i; simp [e],
subst j, refl
end
/-- Given a collection of setoids indexed by a fintype `ι` and a
function that for each `i : ι` gives a term of the corresponding
quotient type, then there is corresponding term in the quotient of the
product of the setoids. -/
def quotient.fin_choice {ι : Type*} [decidable_eq ι] [fintype ι]
{α : ι → Type*} [S : ∀ i, setoid (α i)]
(f : Π i, quotient (S i)) : @quotient (Π i, α i) (by apply_instance) :=
quotient.lift_on (@quotient.rec_on _ _ (λ l : multiset ι,
@quotient (Π i ∈ l, α i) (by apply_instance))
finset.univ.1
(λ l, quotient.fin_choice_aux l (λ i _, f i))
(λ a b h, begin
have := λ a, quotient.fin_choice_aux_eq a (λ i h, quotient.out (f i)),
simp [quotient.out_eq] at this,
simp [this],
let g := λ a:multiset ι, ⟦λ (i : ι) (h : i ∈ a), quotient.out (f i)⟧,
refine eq_of_heq ((eq_rec_heq _ _).trans (_ : g a == g b)),
congr' 1, exact quotient.sound h,
end))
(λ f, ⟦λ i, f i (finset.mem_univ _)⟧)
(λ a b h, quotient.sound $ λ i, h _ _)
theorem quotient.fin_choice_eq {ι : Type*} [decidable_eq ι] [fintype ι]
{α : ι → Type*} [∀ i, setoid (α i)]
(f : Π i, α i) : quotient.fin_choice (λ i, ⟦f i⟧) = ⟦f⟧ :=
begin
let q, swap, change quotient.lift_on q _ _ = _,
have : q = ⟦λ i h, f i⟧,
{ dsimp [q],
exact quotient.induction_on
(@finset.univ ι _).1 (λ l, quotient.fin_choice_aux_eq _ _) },
simp [this], exact setoid.refl _
end
section equiv
open list equiv equiv.perm
variables [decidable_eq α] [decidable_eq β]
/-- Given a list, produce a list of all permutations of its elements. -/
def perms_of_list : list α → list (perm α)
| [] := [1]
| (a :: l) := perms_of_list l ++ l.bind (λ b, (perms_of_list l).map (λ f, swap a b * f))
lemma length_perms_of_list : ∀ l : list α, length (perms_of_list l) = l.length!
| [] := rfl
| (a :: l) :=
begin
rw [length_cons, nat.factorial_succ],
simp [perms_of_list, length_bind, length_perms_of_list, function.comp, nat.succ_mul],
cc
end
lemma mem_perms_of_list_of_mem {l : list α} {f : perm α} (h : ∀ x, f x ≠ x → x ∈ l) :
f ∈ perms_of_list l :=
begin
induction l with a l IH generalizing f h,
{ exact list.mem_singleton.2 (equiv.ext $ λ x, decidable.by_contradiction $ h _) },
by_cases hfa : f a = a,
{ refine mem_append_left _ (IH (λ x hx, mem_of_ne_of_mem _ (h x hx))),
rintro rfl, exact hx hfa },
have hfa' : f (f a) ≠ f a := mt (λ h, f.injective h) hfa,
have : ∀ (x : α), (swap a (f a) * f) x ≠ x → x ∈ l,
{ intros x hx,
have hxa : x ≠ a,
{ rintro rfl, apply hx, simp only [mul_apply, swap_apply_right] },
refine list.mem_of_ne_of_mem hxa (h x (λ h, _)),
simp only [h, mul_apply, swap_apply_def, mul_apply, ne.def, apply_eq_iff_eq] at hx;
split_ifs at hx, exacts [hxa (h.symm.trans h_1), hx h] },
suffices : f ∈ perms_of_list l ∨ ∃ (b ∈ l) (g ∈ perms_of_list l), swap a b * g = f,
{ simpa only [perms_of_list, exists_prop, list.mem_map, mem_append, list.mem_bind] },
refine or_iff_not_imp_left.2 (λ hfl, ⟨f a, _, swap a (f a) * f, IH this, _⟩),
{ by_cases hffa : f (f a) = a,
{ exact mem_of_ne_of_mem hfa (h _ (mt (λ h, f.injective h) hfa)) },
{ apply this,
simp only [mul_apply, swap_apply_def, mul_apply, ne.def, apply_eq_iff_eq],
split_ifs; cc } },
{ rw [←mul_assoc, mul_def (swap a (f a)) (swap a (f a)),
swap_swap, ←perm.one_def, one_mul] }
end
lemma mem_of_mem_perms_of_list :
∀ {l : list α} {f : perm α}, f ∈ perms_of_list l → ∀ {x}, f x ≠ x → x ∈ l
| [] f h := have f = 1 := by simpa [perms_of_list] using h, by rw this; simp
| (a :: l) f h :=
(mem_append.1 h).elim
(λ h x hx, mem_cons_of_mem _ (mem_of_mem_perms_of_list h hx))
(λ h x hx,
let ⟨y, hy, hy'⟩ := list.mem_bind.1 h in
let ⟨g, hg₁, hg₂⟩ := list.mem_map.1 hy' in
if hxa : x = a then by simp [hxa]
else if hxy : x = y then mem_cons_of_mem _ $ by rwa hxy
else mem_cons_of_mem _ $
mem_of_mem_perms_of_list hg₁ $
by rw [eq_inv_mul_iff_mul_eq.2 hg₂, mul_apply, swap_inv, swap_apply_def];
split_ifs; cc)
lemma mem_perms_of_list_iff {l : list α} {f : perm α} :
f ∈ perms_of_list l ↔ ∀ {x}, f x ≠ x → x ∈ l :=
⟨mem_of_mem_perms_of_list, mem_perms_of_list_of_mem⟩
lemma nodup_perms_of_list : ∀ {l : list α} (hl : l.nodup), (perms_of_list l).nodup
| [] hl := by simp [perms_of_list]
| (a :: l) hl :=
have hl' : l.nodup, from nodup_of_nodup_cons hl,
have hln' : (perms_of_list l).nodup, from nodup_perms_of_list hl',
have hmeml : ∀ {f : perm α}, f ∈ perms_of_list l → f a = a,
from λ f hf, not_not.1 (mt (mem_of_mem_perms_of_list hf) (nodup_cons.1 hl).1),
by rw [perms_of_list, list.nodup_append, list.nodup_bind, pairwise_iff_nth_le]; exact
⟨hln', ⟨λ _ _, nodup_map (λ _ _, mul_left_cancel) hln',
λ i j hj hij x hx₁ hx₂,
let ⟨f, hf⟩ := list.mem_map.1 hx₁ in
let ⟨g, hg⟩ := list.mem_map.1 hx₂ in
have hix : x a = nth_le l i (lt_trans hij hj),
by rw [←hf.2, mul_apply, hmeml hf.1, swap_apply_left],
have hiy : x a = nth_le l j hj,
by rw [← hg.2, mul_apply, hmeml hg.1, swap_apply_left],
absurd (hf.2.trans (hg.2.symm)) $
λ h, ne_of_lt hij $ nodup_iff_nth_le_inj.1 hl' i j (lt_trans hij hj) hj $
by rw [← hix, hiy]⟩,
λ f hf₁ hf₂,
let ⟨x, hx, hx'⟩ := list.mem_bind.1 hf₂ in
let ⟨g, hg⟩ := list.mem_map.1 hx' in
have hgxa : g⁻¹ x = a, from f.injective $
by rw [hmeml hf₁, ← hg.2]; simp,
have hxa : x ≠ a, from λ h, (list.nodup_cons.1 hl).1 (h ▸ hx),
(list.nodup_cons.1 hl).1 $
hgxa ▸ mem_of_mem_perms_of_list hg.1 (by rwa [apply_inv_self, hgxa])⟩
/-- Given a finset, produce the finset of all permutations of its elements. -/
def perms_of_finset (s : finset α) : finset (perm α) :=
quotient.hrec_on s.1 (λ l hl, ⟨perms_of_list l, nodup_perms_of_list hl⟩)
(λ a b hab, hfunext (congr_arg _ (quotient.sound hab))
(λ ha hb _, heq_of_eq $ finset.ext $
by simp [mem_perms_of_list_iff, hab.mem_iff]))
s.2
lemma mem_perms_of_finset_iff : ∀ {s : finset α} {f : perm α},
f ∈ perms_of_finset s ↔ ∀ {x}, f x ≠ x → x ∈ s :=
by rintros ⟨⟨l⟩, hs⟩ f; exact mem_perms_of_list_iff
lemma card_perms_of_finset : ∀ (s : finset α),
(perms_of_finset s).card = s.card! :=
by rintros ⟨⟨l⟩, hs⟩; exact length_perms_of_list l
/-- The collection of permutations of a fintype is a fintype. -/
def fintype_perm [fintype α] : fintype (perm α) :=
⟨perms_of_finset (@finset.univ α _), by simp [mem_perms_of_finset_iff]⟩
instance [fintype α] [fintype β] : fintype (α ≃ β) :=
if h : fintype.card β = fintype.card α
then trunc.rec_on_subsingleton (fintype.trunc_equiv_fin α)
(λ eα, trunc.rec_on_subsingleton (fintype.trunc_equiv_fin β)
(λ eβ, @fintype.of_equiv _ (perm α) fintype_perm
(equiv_congr (equiv.refl α) (eα.trans (eq.rec_on h eβ.symm)) : (α ≃ α) ≃ (α ≃ β))))
else ⟨∅, λ x, false.elim (h (fintype.card_eq.2 ⟨x.symm⟩))⟩
lemma fintype.card_perm [fintype α] : fintype.card (perm α) = (fintype.card α)! :=
subsingleton.elim (@fintype_perm α _ _) (@equiv.fintype α α _ _ _ _) ▸
card_perms_of_finset _
lemma fintype.card_equiv [fintype α] [fintype β] (e : α ≃ β) :
fintype.card (α ≃ β) = (fintype.card α)! :=
fintype.card_congr (equiv_congr (equiv.refl α) e) ▸ fintype.card_perm
lemma univ_eq_singleton_of_card_one {α} [fintype α] (x : α) (h : fintype.card α = 1) :
(univ : finset α) = {x} :=
begin
symmetry,
apply eq_of_subset_of_card_le (subset_univ ({x})),
apply le_of_eq,
simp [h, finset.card_univ]
end
end equiv
namespace fintype
section choose
open fintype equiv
variables [fintype α] (p : α → Prop) [decidable_pred p]
/-- Given a fintype `α` and a predicate `p`, associate to a proof that there is a unique element of
`α` satisfying `p` this unique element, as an element of the corresponding subtype. -/
def choose_x (hp : ∃! a : α, p a) : {a // p a} :=
⟨finset.choose p univ (by simp; exact hp), finset.choose_property _ _ _⟩
/-- Given a fintype `α` and a predicate `p`, associate to a proof that there is a unique element of
`α` satisfying `p` this unique element, as an element of `α`. -/
def choose (hp : ∃! a, p a) : α := choose_x p hp
lemma choose_spec (hp : ∃! a, p a) : p (choose p hp) :=
(choose_x p hp).property
@[simp] lemma choose_subtype_eq {α : Type*} (p : α → Prop) [fintype {a : α // p a}]
[decidable_eq α] (x : {a : α // p a})
(h : ∃! (a : {a // p a}), (a : α) = x := ⟨x, rfl, λ y hy, by simpa [subtype.ext_iff] using hy⟩) :
fintype.choose (λ (y : {a : α // p a}), (y : α) = x) h = x :=
by rw [subtype.ext_iff, fintype.choose_spec (λ (y : {a : α // p a}), (y : α) = x) _]
end choose
section bijection_inverse
open function
variables [fintype α] [decidable_eq β] {f : α → β}
/--
`bij_inv f` is the unique inverse to a bijection `f`. This acts
as a computable alternative to `function.inv_fun`. -/
def bij_inv (f_bij : bijective f) (b : β) : α :=
fintype.choose (λ a, f a = b)
begin
rcases f_bij.right b with ⟨a', fa_eq_b⟩,
rw ← fa_eq_b,
exact ⟨a', ⟨rfl, (λ a h, f_bij.left h)⟩⟩
end
lemma left_inverse_bij_inv (f_bij : bijective f) : left_inverse (bij_inv f_bij) f :=
λ a, f_bij.left (choose_spec (λ a', f a' = f a) _)
lemma right_inverse_bij_inv (f_bij : bijective f) : right_inverse (bij_inv f_bij) f :=
λ b, choose_spec (λ a', f a' = b) _
lemma bijective_bij_inv (f_bij : bijective f) : bijective (bij_inv f_bij) :=
⟨(right_inverse_bij_inv _).injective, (left_inverse_bij_inv _).surjective⟩
end bijection_inverse
lemma well_founded_of_trans_of_irrefl [fintype α] (r : α → α → Prop)
[is_trans α r] [is_irrefl α r] : well_founded r :=
by classical; exact
have ∀ x y, r x y → (univ.filter (λ z, r z x)).card < (univ.filter (λ z, r z y)).card,
from λ x y hxy, finset.card_lt_card $
by simp only [finset.lt_iff_ssubset.symm, lt_iff_le_not_le,
finset.le_iff_subset, finset.subset_iff, mem_filter, true_and, mem_univ, hxy];
exact ⟨λ z hzx, trans hzx hxy, not_forall_of_exists_not ⟨x, not_imp.2 ⟨hxy, irrefl x⟩⟩⟩,
subrelation.wf this (measure_wf _)
lemma preorder.well_founded [fintype α] [preorder α] : well_founded ((<) : α → α → Prop) :=
well_founded_of_trans_of_irrefl _
@[instance, priority 10] lemma linear_order.is_well_order [fintype α] [linear_order α] :
is_well_order α (<) :=
{ wf := preorder.well_founded }
end fintype
/-- A type is said to be infinite if it has no fintype instance.
Note that `infinite α` is equivalent to `is_empty (fintype α)`. -/
class infinite (α : Type*) : Prop :=
(not_fintype : fintype α → false)
lemma not_fintype (α : Type*) [h1 : infinite α] [h2 : fintype α] : false :=
infinite.not_fintype h2
protected lemma fintype.false {α : Type*} [infinite α] (h : fintype α) : false :=
not_fintype α
protected lemma infinite.false {α : Type*} [fintype α] (h : infinite α) : false :=
not_fintype α
@[simp] lemma is_empty_fintype {α : Type*} : is_empty (fintype α) ↔ infinite α :=
⟨λ ⟨x⟩, ⟨x⟩, λ ⟨x⟩, ⟨x⟩⟩
/-- A non-infinite type is a fintype. -/
noncomputable def fintype_of_not_infinite {α : Type*} (h : ¬ infinite α) : fintype α :=
nonempty.some $ by rwa [← not_is_empty_iff, is_empty_fintype]
section
open_locale classical
/--
Any type is (classically) either a `fintype`, or `infinite`.
One can obtain the relevant typeclasses via `cases fintype_or_infinite α; resetI`.
-/
noncomputable def fintype_or_infinite (α : Type*) : psum (fintype α) (infinite α) :=
if h : infinite α then psum.inr h else psum.inl (fintype_of_not_infinite h)
end
lemma finset.exists_minimal {α : Type*} [preorder α] (s : finset α) (h : s.nonempty) :
∃ m ∈ s, ∀ x ∈ s, ¬ (x < m) :=
begin
obtain ⟨c, hcs : c ∈ s⟩ := h,
have : well_founded (@has_lt.lt {x // x ∈ s} _) := fintype.well_founded_of_trans_of_irrefl _,
obtain ⟨⟨m, hms : m ∈ s⟩, -, H⟩ := this.has_min set.univ ⟨⟨c, hcs⟩, trivial⟩,
exact ⟨m, hms, λ x hx hxm, H ⟨x, hx⟩ trivial hxm⟩,
end
lemma finset.exists_maximal {α : Type*} [preorder α] (s : finset α) (h : s.nonempty) :
∃ m ∈ s, ∀ x ∈ s, ¬ (m < x) :=
@finset.exists_minimal (order_dual α) _ s h
namespace infinite
lemma exists_not_mem_finset [infinite α] (s : finset α) : ∃ x, x ∉ s :=
not_forall.1 $ λ h, fintype.false ⟨s, h⟩
@[priority 100] -- see Note [lower instance priority]
instance (α : Type*) [H : infinite α] : nontrivial α :=
⟨let ⟨x, hx⟩ := exists_not_mem_finset (∅ : finset α) in
let ⟨y, hy⟩ := exists_not_mem_finset ({x} : finset α) in
⟨y, x, by simpa only [mem_singleton] using hy⟩⟩
protected lemma nonempty (α : Type*) [infinite α] : nonempty α :=
by apply_instance
lemma of_injective [infinite β] (f : β → α) (hf : injective f) : infinite α :=
⟨λ I, by exactI (fintype.of_injective f hf).false⟩
lemma of_surjective [infinite β] (f : α → β) (hf : surjective f) : infinite α :=
⟨λ I, by { classical, exactI (fintype.of_surjective f hf).false }⟩
instance : infinite ℕ :=
⟨λ ⟨s, hs⟩, finset.not_mem_range_self $ s.subset_range_sup_succ (hs _)⟩
instance : infinite ℤ :=
infinite.of_injective int.of_nat (λ _ _, int.of_nat.inj)
instance [infinite α] : infinite (set α) :=
of_injective singleton (λ a b, set.singleton_eq_singleton_iff.1)
instance [infinite α] : infinite (finset α) := of_injective singleton finset.singleton_injective
instance [nonempty α] : infinite (multiset α) :=
begin
inhabit α,
exact of_injective (multiset.repeat (default α)) (multiset.repeat_injective _),
end
instance [nonempty α] : infinite (list α) :=
of_surjective (coe : list α → multiset α) (surjective_quot_mk _)
instance sum_of_left [infinite α] : infinite (α ⊕ β) :=
of_injective sum.inl sum.inl_injective
instance sum_of_right [infinite β] : infinite (α ⊕ β) :=
of_injective sum.inr sum.inr_injective
instance prod_of_right [nonempty α] [infinite β] : infinite (α × β) :=
of_surjective prod.snd prod.snd_surjective
instance prod_of_left [infinite α] [nonempty β] : infinite (α × β) :=
of_surjective prod.fst prod.fst_surjective
private noncomputable def nat_embedding_aux (α : Type*) [infinite α] : ℕ → α
| n := by letI := classical.dec_eq α; exact classical.some (exists_not_mem_finset
((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux m)
(λ _, multiset.mem_range.1)).to_finset)
private lemma nat_embedding_aux_injective (α : Type*) [infinite α] :
function.injective (nat_embedding_aux α) :=
begin
rintro m n h,
letI := classical.dec_eq α,
wlog hmlen : m ≤ n using m n,
by_contradiction hmn,
have hmn : m < n, from lt_of_le_of_ne hmlen hmn,
refine (classical.some_spec (exists_not_mem_finset
((multiset.range n).pmap (λ m (hm : m < n), nat_embedding_aux α m)
(λ _, multiset.mem_range.1)).to_finset)) _,
refine multiset.mem_to_finset.2 (multiset.mem_pmap.2
⟨m, multiset.mem_range.2 hmn, _⟩),
rw [h, nat_embedding_aux]
end
/-- Embedding of `ℕ` into an infinite type. -/
noncomputable def nat_embedding (α : Type*) [infinite α] : ℕ ↪ α :=
⟨_, nat_embedding_aux_injective α⟩
lemma exists_subset_card_eq (α : Type*) [infinite α] (n : ℕ) :
∃ s : finset α, s.card = n :=
⟨(range n).map (nat_embedding α), by rw [card_map, card_range]⟩
end infinite
@[simp] lemma infinite_sum : infinite (α ⊕ β) ↔ infinite α ∨ infinite β :=
begin
refine ⟨λ H, _, λ H, H.elim (@infinite.sum_of_left α β) (@infinite.sum_of_right α β)⟩,
contrapose! H, haveI := fintype_of_not_infinite H.1, haveI := fintype_of_not_infinite H.2,
exact infinite.false
end
@[simp] lemma infinite_prod :
infinite (α × β) ↔ infinite α ∧ nonempty β ∨ nonempty α ∧ infinite β :=
begin
refine ⟨λ H, _, λ H, H.elim (and_imp.2 $ @infinite.prod_of_left α β)
(and_imp.2 $ @infinite.prod_of_right α β)⟩,
rw and.comm, contrapose! H, introI H',
rcases infinite.nonempty (α × β) with ⟨a, b⟩,
haveI := fintype_of_not_infinite (H.1 ⟨b⟩), haveI := fintype_of_not_infinite (H.2 ⟨a⟩),
exact H'.false
end
/-- If every finset in a type has bounded cardinality, that type is finite. -/
noncomputable def fintype_of_finset_card_le {ι : Type*} (n : ℕ)
(w : ∀ s : finset ι, s.card ≤ n) : fintype ι :=
begin
apply fintype_of_not_infinite,
introI i,
obtain ⟨s, c⟩ := infinite.exists_subset_card_eq ι (n+1),
specialize w s,
rw c at w,
exact nat.not_succ_le_self n w,
end
lemma not_injective_infinite_fintype [infinite α] [fintype β] (f : α → β) :
¬ injective f :=
λ hf, (fintype.of_injective f hf).false
/--
The pigeonhole principle for infinitely many pigeons in finitely many pigeonholes. If there are
infinitely many pigeons in finitely many pigeonholes, then there are at least two pigeons in the
same pigeonhole.
See also: `fintype.exists_ne_map_eq_of_card_lt`, `fintype.exists_infinite_fiber`.
-/
lemma fintype.exists_ne_map_eq_of_infinite [infinite α] [fintype β] (f : α → β) :
∃ x y : α, x ≠ y ∧ f x = f y :=
begin
classical, by_contra hf, push_neg at hf,
apply not_injective_infinite_fintype f,
intros x y, contrapose, apply hf,
end
-- irreducible due to this conversation on Zulip:
-- https://leanprover.zulipchat.com/#narrow/stream/113488-general/
-- topic/.60simp.60.20ignoring.20lemmas.3F/near/241824115
@[irreducible]
instance function.embedding.is_empty {α β} [infinite α] [fintype β] : is_empty (α ↪ β) :=
⟨λ f, let ⟨x, y, ne, feq⟩ := fintype.exists_ne_map_eq_of_infinite f in ne $ f.injective feq⟩
@[priority 100]
noncomputable instance function.embedding.fintype' {α β : Type*} [fintype β] : fintype (α ↪ β) :=
begin
by_cases h : infinite α,
{ resetI, apply_instance },
{ have := fintype_of_not_infinite h, classical, apply_instance }
-- the `classical` generates `decidable_eq α/β` instances, and resets instance cache
end
/--
The strong pigeonhole principle for infinitely many pigeons in
finitely many pigeonholes. If there are infinitely many pigeons in
finitely many pigeonholes, then there is a pigeonhole with infinitely
many pigeons.
See also: `fintype.exists_ne_map_eq_of_infinite`
-/
lemma fintype.exists_infinite_fiber [infinite α] [fintype β] (f : α → β) :
∃ y : β, infinite (f ⁻¹' {y}) :=
begin
classical,
by_contra hf,
push_neg at hf,
haveI := λ y, fintype_of_not_infinite $ hf y,
let key : fintype α :=
{ elems := univ.bUnion (λ (y : β), (f ⁻¹' {y}).to_finset),
complete := by simp },
exact key.false,
end
lemma not_surjective_fintype_infinite [fintype α] [infinite β] (f : α → β) :
¬ surjective f :=
assume (hf : surjective f),
have H : infinite α := infinite.of_surjective f hf,
by exactI not_fintype α
section trunc
/--
For `s : multiset α`, we can lift the existential statement that `∃ x, x ∈ s` to a `trunc α`.
-/
def trunc_of_multiset_exists_mem {α} (s : multiset α) : (∃ x, x ∈ s) → trunc α :=
quotient.rec_on_subsingleton s $ λ l h,
match l, h with
| [], _ := false.elim (by tauto)
| (a :: _), _ := trunc.mk a
end
/--
A `nonempty` `fintype` constructively contains an element.
-/
def trunc_of_nonempty_fintype (α) [nonempty α] [fintype α] : trunc α :=
trunc_of_multiset_exists_mem finset.univ.val (by simp)
/--
A `fintype` with positive cardinality constructively contains an element.
-/
def trunc_of_card_pos {α} [fintype α] (h : 0 < fintype.card α) : trunc α :=
by { letI := (fintype.card_pos_iff.mp h), exact trunc_of_nonempty_fintype α }
/--
By iterating over the elements of a fintype, we can lift an existential statement `∃ a, P a`
to `trunc (Σ' a, P a)`, containing data.
-/
def trunc_sigma_of_exists {α} [fintype α] {P : α → Prop} [decidable_pred P] (h : ∃ a, P a) :
trunc (Σ' a, P a) :=
@trunc_of_nonempty_fintype (Σ' a, P a) (exists.elim h $ λ a ha, ⟨⟨a, ha⟩⟩) _
end trunc
namespace multiset
variables [fintype α] [decidable_eq α]
@[simp] lemma count_univ (a : α) :
count a finset.univ.val = 1 :=
count_eq_one_of_mem finset.univ.nodup (finset.mem_univ _)
end multiset
namespace fintype
/-- A recursor principle for finite types, analogous to `nat.rec`. It effectively says
that every `fintype` is either `empty` or `option α`, up to an `equiv`. -/
def trunc_rec_empty_option {P : Type u → Sort v}
(of_equiv : ∀ {α β}, α ≃ β → P α → P β)
(h_empty : P pempty)
(h_option : ∀ {α} [fintype α] [decidable_eq α], P α → P (option α))
(α : Type u) [fintype α] [decidable_eq α] : trunc (P α) :=
begin
suffices : ∀ n : ℕ, trunc (P (ulift $ fin n)),
{ apply trunc.bind (this (fintype.card α)),
intro h,
apply trunc.map _ (fintype.trunc_equiv_fin α),
intro e,
exact of_equiv (equiv.ulift.trans e.symm) h },
intro n,
induction n with n ih,
{ have : card pempty = card (ulift (fin 0)),
{ simp only [card_fin, card_pempty, card_ulift] },
apply trunc.bind (trunc_equiv_of_card_eq this),
intro e,
apply trunc.mk,
refine of_equiv e h_empty, },
{ have : card (option (ulift (fin n))) = card (ulift (fin n.succ)),
{ simp only [card_fin, card_option, card_ulift] },
apply trunc.bind (trunc_equiv_of_card_eq this),
intro e,
apply trunc.map _ ih,
intro ih,
refine of_equiv e (h_option ih), },
end
/-- An induction principle for finite types, analogous to `nat.rec`. It effectively says
that every `fintype` is either `empty` or `option α`, up to an `equiv`. -/
@[elab_as_eliminator]
lemma induction_empty_option' {P : Π (α : Type u) [fintype α], Prop}
(of_equiv : ∀ α β [fintype β] (e : α ≃ β), @P α (@fintype.of_equiv α β ‹_› e.symm) → @P β ‹_›)
(h_empty : P pempty)
(h_option : ∀ α [fintype α], by exactI P α → P (option α))
(α : Type u) [fintype α] : P α :=
begin
obtain ⟨p⟩ := @trunc_rec_empty_option (λ α, ∀ h, @P α h)
(λ α β e hα hβ, @of_equiv α β hβ e (hα _)) (λ _i, by convert h_empty)
_ α _ (classical.dec_eq α),
{ exact p _ },
{ rintro α hα - Pα hα', resetI, convert h_option α (Pα _) }
end
/-- An induction principle for finite types, analogous to `nat.rec`. It effectively says
that every `fintype` is either `empty` or `option α`, up to an `equiv`. -/
lemma induction_empty_option {P : Type u → Prop}
(of_equiv : ∀ {α β}, α ≃ β → P α → P β)
(h_empty : P pempty)
(h_option : ∀ {α} [fintype α], P α → P (option α))
(α : Type u) [fintype α] : P α :=
begin
refine induction_empty_option' _ _ _ α,
exacts [λ α β _, of_equiv, h_empty, @h_option]
end
end fintype
/-- Auxiliary definition to show `exists_seq_of_forall_finset_exists`. -/
noncomputable def seq_of_forall_finset_exists_aux
{α : Type*} [decidable_eq α] (P : α → Prop) (r : α → α → Prop)
(h : ∀ (s : finset α), ∃ y, (∀ x ∈ s, P x) → (P y ∧ (∀ x ∈ s, r x y))) : ℕ → α
| n := classical.some (h (finset.image (λ (i : fin n), seq_of_forall_finset_exists_aux i)
(finset.univ : finset (fin n))))
using_well_founded {dec_tac := `[exact i.2]}
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m < n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
lemma exists_seq_of_forall_finset_exists {α : Type*} (P : α → Prop) (r : α → α → Prop)
(h : ∀ (s : finset α), (∀ x ∈ s, P x) → ∃ y, P y ∧ (∀ x ∈ s, r x y)) :
∃ (f : ℕ → α), (∀ n, P (f n)) ∧ (∀ m n, m < n → r (f m) (f n)) :=
begin
classical,
haveI : nonempty α,
{ rcases h ∅ (by simp) with ⟨y, hy⟩,
exact ⟨y⟩ },
choose! F hF using h,
have h' : ∀ (s : finset α), ∃ y, (∀ x ∈ s, P x) → (P y ∧ (∀ x ∈ s, r x y)) := λ s, ⟨F s, hF s⟩,
set f := seq_of_forall_finset_exists_aux P r h' with hf,
have A : ∀ (n : ℕ), P (f n),
{ assume n,
induction n using nat.strong_induction_on with n IH,
have IH' : ∀ (x : fin n), P (f x) := λ n, IH n.1 n.2,
rw [hf, seq_of_forall_finset_exists_aux],
exact (classical.some_spec (h' (finset.image (λ (i : fin n), f i)
(finset.univ : finset (fin n)))) (by simp [IH'])).1 },
refine ⟨f, A, λ m n hmn, _⟩,
nth_rewrite 1 hf,
rw seq_of_forall_finset_exists_aux,
apply (classical.some_spec (h' (finset.image (λ (i : fin n), f i)
(finset.univ : finset (fin n)))) (by simp [A])).2,
exact finset.mem_image.2 ⟨⟨m, hmn⟩, finset.mem_univ _, rfl⟩,
end
/-- Induction principle to build a sequence, by adding one point at a time satisfying a given
symmetric relation with respect to all the previously chosen points.
More precisely, Assume that, for any finite set `s`, one can find another point satisfying
some relation `r` with respect to all the points in `s`. Then one may construct a
function `f : ℕ → α` such that `r (f m) (f n)` holds whenever `m ≠ n`.
We also ensure that all constructed points satisfy a given predicate `P`. -/
lemma exists_seq_of_forall_finset_exists' {α : Type*} (P : α → Prop) (r : α → α → Prop)
[is_symm α r]
(h : ∀ (s : finset α), (∀ x ∈ s, P x) → ∃ y, P y ∧ (∀ x ∈ s, r x y)) :
∃ (f : ℕ → α), (∀ n, P (f n)) ∧ (∀ m n, m ≠ n → r (f m) (f n)) :=
begin
rcases exists_seq_of_forall_finset_exists P r h with ⟨f, hf, hf'⟩,
refine ⟨f, hf, λ m n hmn, _⟩,
rcases lt_trichotomy m n with h|rfl|h,
{ exact hf' m n h },
{ exact (hmn rfl).elim },
{ apply symm,
exact hf' n m h }
end
|
40de64b19b9d136612e78bf449679c4c271f8568 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/nat/order/lemmas.lean | 84cddcf68ccce439b121eaff6166e52c1022aff5 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 9,107 | lean | /-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import data.nat.order.basic
import data.nat.units
import data.set.basic
import algebra.ring.divisibility
import algebra.group_with_zero.divisibility
/-!
# Further lemmas about the natural numbers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
The distinction between this file and `data.nat.order.basic` is not particularly clear.
They are separated by now to minimize the porting requirements for tactics during the transition to
mathlib4. After `data.rat.order` has been ported, please feel free to reorganize these two files.
-/
universes u v
variables {a b m n k : ℕ}
namespace nat
/-! ### Sets -/
instance subtype.order_bot (s : set ℕ) [decidable_pred (∈ s)] [h : nonempty s] :
order_bot s :=
{ bot := ⟨nat.find (nonempty_subtype.1 h), nat.find_spec (nonempty_subtype.1 h)⟩,
bot_le := λ x, nat.find_min' _ x.2 }
instance subtype.semilattice_sup (s : set ℕ) :
semilattice_sup s :=
{ ..subtype.linear_order s,
..linear_order.to_lattice }
lemma subtype.coe_bot {s : set ℕ} [decidable_pred (∈ s)]
[h : nonempty s] : ((⊥ : s) : ℕ) = nat.find (nonempty_subtype.1 h) := rfl
lemma set_eq_univ {S : set ℕ} : S = set.univ ↔ 0 ∈ S ∧ ∀ k : ℕ, k ∈ S → k + 1 ∈ S :=
⟨by rintro rfl; simp, λ ⟨h0, hs⟩, set.eq_univ_of_forall (set_induction h0 hs)⟩
/-! ### `div` -/
protected lemma lt_div_iff_mul_lt {n d : ℕ} (hnd : d ∣ n) (a : ℕ) : a < n / d ↔ d * a < n :=
begin
rcases d.eq_zero_or_pos with rfl | hd0, { simp [zero_dvd_iff.mp hnd] },
rw [←mul_lt_mul_left hd0, ←nat.eq_mul_of_div_eq_right hnd rfl],
end
lemma div_eq_iff_eq_of_dvd_dvd {n x y : ℕ} (hn : n ≠ 0) (hx : x ∣ n) (hy : y ∣ n) :
n / x = n / y ↔ x = y :=
begin
split,
{ intros h,
rw ←mul_right_inj' hn,
apply nat.eq_mul_of_div_eq_left (dvd_mul_of_dvd_left hy x),
rw [eq_comm, mul_comm, nat.mul_div_assoc _ hy],
exact nat.eq_mul_of_div_eq_right hx h },
{ intros h, rw h },
end
protected lemma div_eq_zero_iff {a b : ℕ} (hb : 0 < b) : a / b = 0 ↔ a < b :=
⟨λ h, by rw [← mod_add_div a b, h, mul_zero, add_zero]; exact mod_lt _ hb,
λ h, by rw [← mul_right_inj' hb.ne', ← @add_left_cancel_iff _ _ _ (a % b), mod_add_div,
mod_eq_of_lt h, mul_zero, add_zero]⟩
protected lemma div_eq_zero {a b : ℕ} (hb : a < b) : a / b = 0 :=
(nat.div_eq_zero_iff $ (zero_le a).trans_lt hb).mpr hb
/-! ### `mod`, `dvd` -/
@[simp] protected theorem dvd_one {n : ℕ} : n ∣ 1 ↔ n = 1 :=
⟨eq_one_of_dvd_one, λ e, e.symm ▸ dvd_rfl⟩
@[simp] protected theorem not_two_dvd_bit1 (n : ℕ) : ¬ 2 ∣ bit1 n :=
by { rw [bit1, nat.dvd_add_right two_dvd_bit0, nat.dvd_one], cc }
/-- A natural number `m` divides the sum `m + n` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_left {m n : ℕ} :
m ∣ m + n ↔ m ∣ n :=
nat.dvd_add_right (dvd_refl m)
/-- A natural number `m` divides the sum `n + m` if and only if `m` divides `n`.-/
@[simp] protected lemma dvd_add_self_right {m n : ℕ} :
m ∣ n + m ↔ m ∣ n :=
nat.dvd_add_left (dvd_refl m)
-- TODO: update `nat.dvd_sub` in core
lemma dvd_sub' {k m n : ℕ} (h₁ : k ∣ m) (h₂ : k ∣ n) : k ∣ m - n :=
begin
cases le_total n m with H H,
{ exact dvd_sub H h₁ h₂ },
{ rw tsub_eq_zero_iff_le.mpr H,
exact dvd_zero k },
end
lemma succ_div : ∀ (a b : ℕ), (a + 1) / b =
a / b + if b ∣ a + 1 then 1 else 0
| a 0 := by simp
| 0 1 := by simp
| 0 (b+2) := have hb2 : b + 2 > 1, from dec_trivial,
by simp [ne_of_gt hb2, div_eq_of_lt hb2]
| (a+1) (b+1) := begin
rw [nat.div_def], conv_rhs { rw nat.div_def },
by_cases hb_eq_a : b = a + 1,
{ simp [hb_eq_a, le_refl] },
by_cases hb_le_a1 : b ≤ a + 1,
{ have hb_le_a : b ≤ a, from le_of_lt_succ (lt_of_le_of_ne hb_le_a1 hb_eq_a),
have h₁ : (0 < b + 1 ∧ b + 1 ≤ a + 1 + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a1⟩,
have h₂ : (0 < b + 1 ∧ b + 1 ≤ a + 1),
from ⟨succ_pos _, (add_le_add_iff_right _).2 hb_le_a⟩,
have dvd_iff : b + 1 ∣ a - b + 1 ↔ b + 1 ∣ a + 1 + 1,
{ rw [nat.dvd_add_iff_left (dvd_refl (b + 1)),
← add_tsub_add_eq_tsub_right a 1 b, add_comm (_ - _), add_assoc,
tsub_add_cancel_of_le (succ_le_succ hb_le_a), add_comm 1] },
have wf : a - b < a + 1, from lt_succ_of_le tsub_le_self,
rw [if_pos h₁, if_pos h₂, add_tsub_add_eq_tsub_right, ← tsub_add_eq_add_tsub hb_le_a,
by exact have _ := wf, succ_div (a - b),
add_tsub_add_eq_tsub_right],
simp [dvd_iff, succ_eq_add_one, add_comm 1, add_assoc] },
{ have hba : ¬ b ≤ a,
from not_le_of_gt (lt_trans (lt_succ_self a) (lt_of_not_ge hb_le_a1)),
have hb_dvd_a : ¬ b + 1 ∣ a + 2,
from λ h, hb_le_a1 (le_of_succ_le_succ (le_of_dvd (succ_pos _) h)),
simp [hba, hb_le_a1, hb_dvd_a], }
end
lemma succ_div_of_dvd {a b : ℕ} (hba : b ∣ a + 1) :
(a + 1) / b = a / b + 1 :=
by rw [succ_div, if_pos hba]
lemma succ_div_of_not_dvd {a b : ℕ} (hba : ¬ b ∣ a + 1) :
(a + 1) / b = a / b :=
by rw [succ_div, if_neg hba, add_zero]
lemma dvd_iff_div_mul_eq (n d : ℕ) : d ∣ n ↔ n / d * d = n :=
⟨λ h, nat.div_mul_cancel h, λ h, dvd.intro_left (n / d) h⟩
lemma dvd_iff_le_div_mul (n d : ℕ) : d ∣ n ↔ n ≤ n / d * d :=
((dvd_iff_div_mul_eq _ _).trans le_antisymm_iff).trans (and_iff_right (div_mul_le_self n d))
lemma dvd_iff_dvd_dvd (n d : ℕ) : d ∣ n ↔ ∀ k : ℕ, k ∣ d → k ∣ n :=
⟨λ h k hkd, dvd_trans hkd h, λ h, h _ dvd_rfl⟩
lemma dvd_div_of_mul_dvd {a b c : ℕ} (h : a * b ∣ c) : b ∣ c / a :=
if ha : a = 0 then
by simp [ha]
else
have ha : 0 < a, from nat.pos_of_ne_zero ha,
have h1 : ∃ d, c = a * b * d, from h,
let ⟨d, hd⟩ := h1 in
have h2 : c / a = b * d, from nat.div_eq_of_eq_mul_right ha (by simpa [mul_assoc] using hd),
show ∃ d, c / a = b * d, from ⟨d, h2⟩
@[simp] lemma dvd_div_iff {a b c : ℕ} (hbc : c ∣ b) : a ∣ b / c ↔ c * a ∣ b :=
⟨λ h, mul_dvd_of_dvd_div hbc h, λ h, dvd_div_of_mul_dvd h⟩
@[simp]
lemma div_div_div_eq_div : ∀ {a b c : ℕ} (dvd : b ∣ a) (dvd2 : a ∣ c), (c / (a / b)) / b = c / a
| 0 _ := by simp
| (a + 1) 0 := λ _ dvd _, by simpa using dvd
| (a + 1) (c + 1) :=
have a_split : a + 1 ≠ 0 := succ_ne_zero a,
have c_split : c + 1 ≠ 0 := succ_ne_zero c,
λ b dvd dvd2,
begin
rcases dvd2 with ⟨k, rfl⟩,
rcases dvd with ⟨k2, pr⟩,
have k2_nonzero : k2 ≠ 0 := λ k2_zero, by simpa [k2_zero] using pr,
rw [nat.mul_div_cancel_left k (nat.pos_of_ne_zero a_split), pr,
nat.mul_div_cancel_left k2 (nat.pos_of_ne_zero c_split), nat.mul_comm ((c + 1) * k2) k,
←nat.mul_assoc k (c + 1) k2, nat.mul_div_cancel _ (nat.pos_of_ne_zero k2_nonzero),
nat.mul_div_cancel _ (nat.pos_of_ne_zero c_split)],
end
/-- If a small natural number is divisible by a larger natural number,
the small number is zero. -/
lemma eq_zero_of_dvd_of_lt {a b : ℕ} (w : a ∣ b) (h : b < a) : b = 0 :=
nat.eq_zero_of_dvd_of_div_eq_zero w
((nat.div_eq_zero_iff (lt_of_le_of_lt (zero_le b) h)).elim_right h)
lemma le_of_lt_add_of_dvd (h : a < b + n) : n ∣ a → n ∣ b → a ≤ b :=
begin
rintro ⟨a, rfl⟩ ⟨b, rfl⟩,
rw ←mul_add_one at h,
exact mul_le_mul_left' (lt_succ_iff.1 $ lt_of_mul_lt_mul_left h bot_le) _,
end
@[simp] lemma mod_div_self (m n : ℕ) : m % n / n = 0 :=
begin
cases n,
{ exact (m % 0).div_zero },
{ exact nat.div_eq_zero (m.mod_lt n.succ_pos) }
end
/-- `n` is not divisible by `a` iff it is between `a * k` and `a * (k + 1)` for some `k`. -/
lemma not_dvd_iff_between_consec_multiples (n : ℕ) {a : ℕ} (ha : 0 < a) :
(∃ k : ℕ, a * k < n ∧ n < a * (k + 1)) ↔ ¬ a ∣ n :=
begin
refine ⟨λ ⟨k, hk1, hk2⟩, not_dvd_of_between_consec_multiples hk1 hk2,
λ han, ⟨n/a, ⟨lt_of_le_of_ne (mul_div_le n a) _, lt_mul_div_succ _ ha⟩⟩⟩,
exact mt (dvd.intro (n/a)) han,
end
/-- Two natural numbers are equal if and only if they have the same multiples. -/
lemma dvd_right_iff_eq {m n : ℕ} : (∀ a : ℕ, m ∣ a ↔ n ∣ a) ↔ m = n :=
⟨λ h, dvd_antisymm ((h _).mpr dvd_rfl) ((h _).mp dvd_rfl), λ h n, by rw h⟩
/-- Two natural numbers are equal if and only if they have the same divisors. -/
lemma dvd_left_iff_eq {m n : ℕ} : (∀ a : ℕ, a ∣ m ↔ a ∣ n) ↔ m = n :=
⟨λ h, dvd_antisymm ((h _).mp dvd_rfl) ((h _).mpr dvd_rfl), λ h n, by rw h⟩
/-- `dvd` is injective in the left argument -/
lemma dvd_left_injective : function.injective ((∣) : ℕ → ℕ → Prop) :=
λ m n h, dvd_right_iff_eq.mp $ λ a, iff_of_eq (congr_fun h a)
lemma div_lt_div_of_lt_of_dvd {a b d : ℕ} (hdb : d ∣ b) (h : a < b) : a / d < b / d :=
by { rw nat.lt_div_iff_mul_lt hdb, exact lt_of_le_of_lt (mul_div_le a d) h }
end nat
|
b967fe127dc2f989f984c3fe5845de08c9513e4f | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/real/nnreal.lean | 00a54cf758363d22ef1ece73fc0812e5a54046ed | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 32,325 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.linear_ordered_comm_group_with_zero
import algebra.big_operators.ring
import data.real.basic
import algebra.indicator_function
import algebra.algebra.basic
/-!
# Nonnegative real numbers
In this file we define `nnreal` (notation: `ℝ≥0`) to be the type of non-negative real numbers,
a.k.a. the interval `[0, ∞)`. We also define the following operations and structures on `ℝ≥0`:
* the order on `ℝ≥0` is the restriction of the order on `ℝ`; these relations define a conditionally
complete linear order with a bottom element, `conditionally_complete_linear_order_bot`;
* `a + b` and `a * b` are the restrictions of addition and multiplication of real numbers to `ℝ≥0`;
these operations together with `0 = ⟨0, _⟩` and `1 = ⟨1, _⟩` turn `ℝ≥0` into a linear ordered
archimedean commutative semifield; we have no typeclass for this in `mathlib` yet, so we define
the following instances instead:
- `linear_ordered_semiring ℝ≥0`;
- `comm_semiring ℝ≥0`;
- `canonically_ordered_comm_semiring ℝ≥0`;
- `linear_ordered_comm_group_with_zero ℝ≥0`;
- `archimedean ℝ≥0`.
* `real.to_nnreal x` is defined as `⟨max x 0, _⟩`, i.e. `↑(real.to_nnreal x) = x` when `0 ≤ x` and
`↑(real.to_nnreal x) = 0` otherwise.
We also define an instance `can_lift ℝ ℝ≥0`. This instance can be used by the `lift` tactic to
replace `x : ℝ` and `hx : 0 ≤ x` in the proof context with `x : ℝ≥0` while replacing all occurences
of `x` with `↑x`. This tactic also works for a function `f : α → ℝ` with a hypothesis
`hf : ∀ x, 0 ≤ f x`.
## Notations
This file defines `ℝ≥0` as a localized notation for `nnreal`.
-/
noncomputable theory
open_locale classical big_operators
/-- Nonnegative real numbers. -/
def nnreal := {r : ℝ // 0 ≤ r}
localized "notation ` ℝ≥0 ` := nnreal" in nnreal
namespace nnreal
instance : has_coe ℝ≥0 ℝ := ⟨subtype.val⟩
/- Simp lemma to put back `n.val` into the normal form given by the coercion. -/
@[simp] lemma val_eq_coe (n : ℝ≥0) : n.val = n := rfl
instance : can_lift ℝ ℝ≥0 :=
{ coe := coe,
cond := λ r, 0 ≤ r,
prf := λ x hx, ⟨⟨x, hx⟩, rfl⟩ }
protected lemma eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := subtype.eq
protected lemma eq_iff {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) ↔ n = m :=
iff.intro nnreal.eq (congr_arg coe)
lemma ne_iff {x y : ℝ≥0} : (x : ℝ) ≠ (y : ℝ) ↔ x ≠ y :=
not_iff_not_of_iff $ nnreal.eq_iff
/-- Reinterpret a real number `r` as a non-negative real number. Returns `0` if `r < 0`. -/
def _root_.real.to_nnreal (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩
lemma _root_.real.coe_to_nnreal (r : ℝ) (hr : 0 ≤ r) : (real.to_nnreal r : ℝ) = r :=
max_eq_left hr
lemma _root_.real.le_coe_to_nnreal (r : ℝ) : r ≤ real.to_nnreal r :=
le_max_left r 0
lemma coe_nonneg (r : ℝ≥0) : (0 : ℝ) ≤ r := r.2
@[norm_cast]
theorem coe_mk (a : ℝ) (ha) : ((⟨a, ha⟩ : ℝ≥0) : ℝ) = a := rfl
instance : has_zero ℝ≥0 := ⟨⟨0, le_refl 0⟩⟩
instance : has_one ℝ≥0 := ⟨⟨1, zero_le_one⟩⟩
instance : has_add ℝ≥0 := ⟨λa b, ⟨a + b, add_nonneg a.2 b.2⟩⟩
instance : has_sub ℝ≥0 := ⟨λa b, real.to_nnreal (a - b)⟩
instance : has_mul ℝ≥0 := ⟨λa b, ⟨a * b, mul_nonneg a.2 b.2⟩⟩
instance : has_inv ℝ≥0 := ⟨λa, ⟨(a.1)⁻¹, inv_nonneg.2 a.2⟩⟩
instance : has_div ℝ≥0 := ⟨λa b, ⟨a / b, div_nonneg a.2 b.2⟩⟩
instance : has_le ℝ≥0 := ⟨λ r s, (r:ℝ) ≤ s⟩
instance : has_bot ℝ≥0 := ⟨0⟩
instance : inhabited ℝ≥0 := ⟨0⟩
protected lemma coe_injective : function.injective (coe : ℝ≥0 → ℝ) := subtype.coe_injective
@[simp, norm_cast] protected lemma coe_eq {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) = r₂ ↔ r₁ = r₂ :=
nnreal.coe_injective.eq_iff
@[simp, norm_cast] protected lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl
@[simp, norm_cast] protected lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl
@[simp, norm_cast] protected lemma coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl
@[simp, norm_cast] protected lemma coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl
@[simp, norm_cast] protected lemma coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = r⁻¹ := rfl
@[simp, norm_cast] protected lemma coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = r₁ / r₂ := rfl
@[simp, norm_cast] protected lemma coe_bit0 (r : ℝ≥0) : ((bit0 r : ℝ≥0) : ℝ) = bit0 r := rfl
@[simp, norm_cast] protected lemma coe_bit1 (r : ℝ≥0) : ((bit1 r : ℝ≥0) : ℝ) = bit1 r := rfl
@[simp, norm_cast] protected lemma coe_sub {r₁ r₂ : ℝ≥0} (h : r₂ ≤ r₁) :
((r₁ - r₂ : ℝ≥0) : ℝ) = r₁ - r₂ :=
max_eq_left $ le_sub.2 $ by simp [show (r₂ : ℝ) ≤ r₁, from h]
-- TODO: setup semifield!
@[simp] protected lemma coe_eq_zero (r : ℝ≥0) : ↑r = (0 : ℝ) ↔ r = 0 := by norm_cast
lemma coe_ne_zero {r : ℝ≥0} : (r : ℝ) ≠ 0 ↔ r ≠ 0 := by norm_cast
instance : comm_semiring ℝ≥0 :=
{ zero := 0,
add := (+),
one := 1,
mul := (*),
.. nnreal.coe_injective.comm_semiring _ rfl rfl (λ _ _, rfl) (λ _ _, rfl) }
/-- Coercion `ℝ≥0 → ℝ` as a `ring_hom`. -/
def to_real_hom : ℝ≥0 →+* ℝ :=
⟨coe, nnreal.coe_one, nnreal.coe_mul, nnreal.coe_zero, nnreal.coe_add⟩
@[simp] lemma coe_to_real_hom : ⇑to_real_hom = coe := rfl
section actions
/-- A `mul_action` over `ℝ` restricts to a `mul_action` over `ℝ≥0`. -/
instance {M : Type*} [mul_action ℝ M] : mul_action ℝ≥0 M :=
mul_action.comp_hom M to_real_hom.to_monoid_hom
lemma smul_def {M : Type*} [mul_action ℝ M] (c : ℝ≥0) (x : M) :
c • x = (c : ℝ) • x := rfl
instance {M N : Type*} [mul_action ℝ M] [mul_action ℝ N] [has_scalar M N]
[is_scalar_tower ℝ M N] : is_scalar_tower ℝ≥0 M N :=
{ smul_assoc := λ r, (smul_assoc (r : ℝ) : _)}
instance smul_comm_class_left {M N : Type*} [mul_action ℝ N] [has_scalar M N]
[smul_comm_class ℝ M N] : smul_comm_class ℝ≥0 M N :=
{ smul_comm := λ r, (smul_comm (r : ℝ) : _)}
instance smul_comm_class_right {M N : Type*} [mul_action ℝ N] [has_scalar M N]
[smul_comm_class M ℝ N] : smul_comm_class M ℝ≥0 N :=
{ smul_comm := λ m r, (smul_comm m (r : ℝ) : _)}
/-- A `distrib_mul_action` over `ℝ` restricts to a `distrib_mul_action` over `ℝ≥0`. -/
instance {M : Type*} [add_monoid M] [distrib_mul_action ℝ M] : distrib_mul_action ℝ≥0 M :=
distrib_mul_action.comp_hom M to_real_hom.to_monoid_hom
/-- A `module` over `ℝ` restricts to a `module` over `ℝ≥0`. -/
instance {M : Type*} [add_comm_monoid M] [module ℝ M] : module ℝ≥0 M :=
module.comp_hom M to_real_hom
/-- An `algebra` over `ℝ` restricts to an `algebra` over `ℝ≥0`. -/
instance {A : Type*} [semiring A] [algebra ℝ A] : algebra ℝ≥0 A :=
{ smul := (•),
commutes' := λ r x, by simp [algebra.commutes],
smul_def' := λ r x, by simp [←algebra.smul_def (r : ℝ) x, smul_def],
to_ring_hom := ((algebra_map ℝ A).comp (to_real_hom : ℝ≥0 →+* ℝ)) }
-- verify that the above produces instances we might care about
example : algebra ℝ≥0 ℝ := by apply_instance
example : distrib_mul_action (units ℝ≥0) ℝ := by apply_instance
end actions
instance : comm_group_with_zero ℝ≥0 :=
{ zero := 0,
mul := (*),
one := 1,
inv := has_inv.inv,
div := (/),
.. nnreal.coe_injective.comm_group_with_zero _ rfl rfl (λ _ _, rfl) (λ _, rfl) (λ _ _, rfl) }
@[simp, norm_cast] lemma coe_indicator {α} (s : set α) (f : α → ℝ≥0) (a : α) :
((s.indicator f a : ℝ≥0) : ℝ) = s.indicator (λ x, f x) a :=
(to_real_hom : ℝ≥0 →+ ℝ).map_indicator _ _ _
@[simp, norm_cast] lemma coe_pow (r : ℝ≥0) (n : ℕ) : ((r^n : ℝ≥0) : ℝ) = r^n :=
to_real_hom.map_pow r n
@[norm_cast] lemma coe_list_sum (l : list ℝ≥0) :
((l.sum : ℝ≥0) : ℝ) = (l.map coe).sum :=
to_real_hom.map_list_sum l
@[norm_cast] lemma coe_list_prod (l : list ℝ≥0) :
((l.prod : ℝ≥0) : ℝ) = (l.map coe).prod :=
to_real_hom.map_list_prod l
@[norm_cast] lemma coe_multiset_sum (s : multiset ℝ≥0) :
((s.sum : ℝ≥0) : ℝ) = (s.map coe).sum :=
to_real_hom.map_multiset_sum s
@[norm_cast] lemma coe_multiset_prod (s : multiset ℝ≥0) :
((s.prod : ℝ≥0) : ℝ) = (s.map coe).prod :=
to_real_hom.map_multiset_prod s
@[norm_cast] lemma coe_sum {α} {s : finset α} {f : α → ℝ≥0} :
↑(∑ a in s, f a) = ∑ a in s, (f a : ℝ) :=
to_real_hom.map_sum _ _
lemma _root_.real.to_nnreal_sum_of_nonneg {α} {s : finset α} {f : α → ℝ}
(hf : ∀ a, a ∈ s → 0 ≤ f a) :
real.to_nnreal (∑ a in s, f a) = ∑ a in s, real.to_nnreal (f a) :=
begin
rw [←nnreal.coe_eq, nnreal.coe_sum, real.coe_to_nnreal _ (finset.sum_nonneg hf)],
exact finset.sum_congr rfl (λ x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),
end
@[norm_cast] lemma coe_prod {α} {s : finset α} {f : α → ℝ≥0} :
↑(∏ a in s, f a) = ∏ a in s, (f a : ℝ) :=
to_real_hom.map_prod _ _
lemma _root_.real.to_nnreal_prod_of_nonneg {α} {s : finset α} {f : α → ℝ}
(hf : ∀ a, a ∈ s → 0 ≤ f a) :
real.to_nnreal (∏ a in s, f a) = ∏ a in s, real.to_nnreal (f a) :=
begin
rw [←nnreal.coe_eq, nnreal.coe_prod, real.coe_to_nnreal _ (finset.prod_nonneg hf)],
exact finset.prod_congr rfl (λ x hxs, by rw real.coe_to_nnreal _ (hf x hxs)),
end
@[norm_cast] lemma nsmul_coe (r : ℝ≥0) (n : ℕ) : ↑(n • r) = n • (r:ℝ) :=
to_real_hom.to_add_monoid_hom.map_nsmul _ _
@[simp, norm_cast] protected lemma coe_nat_cast (n : ℕ) : (↑(↑n : ℝ≥0) : ℝ) = n :=
to_real_hom.map_nat_cast n
instance : linear_order ℝ≥0 :=
linear_order.lift (coe : ℝ≥0 → ℝ) nnreal.coe_injective
@[simp, norm_cast] protected lemma coe_le_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := iff.rfl
@[simp, norm_cast] protected lemma coe_lt_coe {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := iff.rfl
@[simp, norm_cast] protected lemma coe_pos {r : ℝ≥0} : (0 : ℝ) < r ↔ 0 < r := iff.rfl
protected lemma coe_mono : monotone (coe : ℝ≥0 → ℝ) := λ _ _, nnreal.coe_le_coe.2
protected lemma _root_.real.to_nnreal_mono : monotone real.to_nnreal :=
λ x y h, max_le_max h (le_refl 0)
@[simp] lemma _root_.real.to_nnreal_coe {r : ℝ≥0} : real.to_nnreal r = r :=
nnreal.eq $ max_eq_left r.2
@[simp] lemma mk_coe_nat (n : ℕ) : @eq ℝ≥0 (⟨(n : ℝ), n.cast_nonneg⟩ : ℝ≥0) n :=
nnreal.eq (nnreal.coe_nat_cast n).symm
@[simp] lemma to_nnreal_coe_nat (n : ℕ) : real.to_nnreal n = n :=
nnreal.eq $ by simp [real.coe_to_nnreal]
/-- `real.to_nnreal` and `coe : ℝ≥0 → ℝ` form a Galois insertion. -/
protected def gi : galois_insertion real.to_nnreal coe :=
galois_insertion.monotone_intro nnreal.coe_mono real.to_nnreal_mono
real.le_coe_to_nnreal (λ _, real.to_nnreal_coe)
instance : order_bot ℝ≥0 :=
{ bot := ⊥, bot_le := assume ⟨a, h⟩, h, .. nnreal.linear_order }
instance : canonically_linear_ordered_add_monoid ℝ≥0 :=
{ add_le_add_left := assume a b h c,
nnreal.coe_le_coe.mp $ (add_le_add_left (nnreal.coe_le_coe.mpr h) c),
lt_of_add_lt_add_left := assume a b c bc,
nnreal.coe_lt_coe.mp $ lt_of_add_lt_add_left (nnreal.coe_lt_coe.mpr bc),
le_iff_exists_add := assume ⟨a, ha⟩ ⟨b, hb⟩,
iff.intro
(assume h : a ≤ b,
⟨⟨b - a, le_sub_iff_add_le.2 $ (zero_add _).le.trans h⟩,
nnreal.eq $ show b = a + (b - a), from (add_sub_cancel'_right _ _).symm⟩)
(assume ⟨⟨c, hc⟩, eq⟩, eq.symm ▸ show a ≤ a + c, from (le_add_iff_nonneg_right a).2 hc),
..nnreal.comm_semiring,
..nnreal.order_bot,
..nnreal.linear_order }
instance : linear_ordered_add_comm_monoid ℝ≥0 :=
{ .. nnreal.comm_semiring,
.. nnreal.canonically_linear_ordered_add_monoid }
instance : distrib_lattice ℝ≥0 := by apply_instance
instance : semilattice_inf_bot ℝ≥0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : semilattice_sup_bot ℝ≥0 :=
{ .. nnreal.order_bot, .. nnreal.distrib_lattice }
instance : linear_ordered_semiring ℝ≥0 :=
{ add_left_cancel := assume a b c h, nnreal.eq $
@add_left_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
le_of_add_le_add_left := assume a b c, @le_of_add_le_add_left ℝ _ _ _ a b c,
mul_lt_mul_of_pos_left := assume a b c, @mul_lt_mul_of_pos_left ℝ _ a b c,
mul_lt_mul_of_pos_right := assume a b c, @mul_lt_mul_of_pos_right ℝ _ a b c,
zero_le_one := @zero_le_one ℝ _,
exists_pair_ne := ⟨0, 1, ne_of_lt (@zero_lt_one ℝ _ _)⟩,
.. nnreal.canonically_linear_ordered_add_monoid,
.. nnreal.comm_semiring, }
instance : linear_ordered_comm_group_with_zero ℝ≥0 :=
{ mul_le_mul_left := assume a b h c, mul_le_mul (le_refl c) h (zero_le a) (zero_le c),
zero_le_one := zero_le 1,
.. nnreal.linear_ordered_semiring,
.. nnreal.comm_group_with_zero }
instance : canonically_ordered_comm_semiring ℝ≥0 :=
{ .. nnreal.canonically_linear_ordered_add_monoid,
.. nnreal.comm_semiring,
.. (show no_zero_divisors ℝ≥0, by apply_instance),
.. nnreal.comm_group_with_zero }
instance : densely_ordered ℝ≥0 :=
⟨assume a b (h : (a : ℝ) < b), let ⟨c, hac, hcb⟩ := exists_between h in
⟨⟨c, le_trans a.property $ le_of_lt $ hac⟩, hac, hcb⟩⟩
instance : no_top_order ℝ≥0 :=
⟨assume a, let ⟨b, hb⟩ := no_top (a:ℝ) in ⟨⟨b, le_trans a.property $ le_of_lt $ hb⟩, hb⟩⟩
lemma bdd_above_coe {s : set ℝ≥0} : bdd_above ((coe : ℝ≥0 → ℝ) '' s) ↔ bdd_above s :=
iff.intro
(assume ⟨b, hb⟩, ⟨real.to_nnreal b, assume ⟨y, hy⟩ hys, show y ≤ max b 0, from
le_max_of_le_left $ hb $ set.mem_image_of_mem _ hys⟩)
(assume ⟨b, hb⟩, ⟨b, assume y ⟨x, hx, eq⟩, eq ▸ hb hx⟩)
lemma bdd_below_coe (s : set ℝ≥0) : bdd_below ((coe : ℝ≥0 → ℝ) '' s) :=
⟨0, assume r ⟨q, _, eq⟩, eq ▸ q.2⟩
instance : has_Sup ℝ≥0 :=
⟨λs, ⟨Sup ((coe : ℝ≥0 → ℝ) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Sup_empty] },
rcases h with ⟨⟨b, hb⟩, hbs⟩,
by_cases h' : bdd_above s,
{ exact le_cSup_of_le (bdd_above_coe.2 h') (set.mem_image_of_mem _ hbs) hb },
{ rw [real.Sup_of_not_bdd_above], rwa [bdd_above_coe] }
end⟩⟩
instance : has_Inf ℝ≥0 :=
⟨λs, ⟨Inf ((coe : ℝ≥0 → ℝ) '' s),
begin
cases s.eq_empty_or_nonempty with h h,
{ simp [h, set.image_empty, real.Inf_empty] },
exact le_cInf (h.image _) (assume r ⟨q, _, eq⟩, eq ▸ q.2)
end⟩⟩
lemma coe_Sup (s : set ℝ≥0) : (↑(Sup s) : ℝ) = Sup ((coe : ℝ≥0 → ℝ) '' s) := rfl
lemma coe_Inf (s : set ℝ≥0) : (↑(Inf s) : ℝ) = Inf ((coe : ℝ≥0 → ℝ) '' s) := rfl
instance : conditionally_complete_linear_order_bot ℝ≥0 :=
{ Sup := Sup,
Inf := Inf,
le_cSup := assume s a hs ha, le_cSup (bdd_above_coe.2 hs) (set.mem_image_of_mem _ ha),
cSup_le := assume s a hs h,show Sup ((coe : ℝ≥0 → ℝ) '' s) ≤ a, from
cSup_le (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h hb,
cInf_le := assume s a _ has, cInf_le (bdd_below_coe s) (set.mem_image_of_mem _ has),
le_cInf := assume s a hs h, show (↑a : ℝ) ≤ Inf ((coe : ℝ≥0 → ℝ) '' s), from
le_cInf (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h hb,
cSup_empty := nnreal.eq $ by simp [coe_Sup, real.Sup_empty]; refl,
decidable_le := begin assume x y, apply classical.dec end,
.. nnreal.linear_ordered_semiring, .. lattice_of_linear_order,
.. nnreal.order_bot }
instance : archimedean ℝ≥0 :=
⟨ assume x y pos_y,
let ⟨n, hr⟩ := archimedean.arch (x:ℝ) (pos_y : (0 : ℝ) < y) in
⟨n, show (x:ℝ) ≤ (n • y : ℝ≥0), by simp [*, -nsmul_eq_mul, nsmul_coe]⟩ ⟩
lemma le_of_forall_pos_le_add {a b : ℝ≥0} (h : ∀ε, 0 < ε → a ≤ b + ε) : a ≤ b :=
le_of_forall_le_of_dense $ assume x hxb,
begin
rcases le_iff_exists_add.1 (le_of_lt hxb) with ⟨ε, rfl⟩,
exact h _ ((lt_add_iff_pos_right b).1 hxb)
end
-- TODO: generalize to some ordered add_monoids, based on #6145
lemma le_of_add_le_left {a b c : ℝ≥0} (h : a + b ≤ c) : a ≤ c :=
by { refine le_trans _ h, simp }
lemma le_of_add_le_right {a b c : ℝ≥0} (h : a + b ≤ c) : b ≤ c :=
by { refine le_trans _ h, simp }
lemma lt_iff_exists_rat_btwn (a b : ℝ≥0) :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < real.to_nnreal q ∧ real.to_nnreal q < b) :=
iff.intro
(assume (h : (↑a:ℝ) < (↑b:ℝ)),
let ⟨q, haq, hqb⟩ := exists_rat_btwn h in
have 0 ≤ (q : ℝ), from le_trans a.2 $ le_of_lt haq,
⟨q, rat.cast_nonneg.1 this,
by simp [real.coe_to_nnreal _ this, nnreal.coe_lt_coe.symm, haq, hqb]⟩)
(assume ⟨q, _, haq, hqb⟩, lt_trans haq hqb)
lemma bot_eq_zero : (⊥ : ℝ≥0) = 0 := rfl
lemma mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = (a * b) ⊔ (a * c) :=
begin
cases le_total b c with h h,
{ simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },
{ simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },
end
lemma mul_finset_sup {α} {f : α → ℝ≥0} {s : finset α} (r : ℝ≥0) :
r * s.sup f = s.sup (λa, r * f a) :=
begin
refine s.induction_on _ _,
{ simp [bot_eq_zero] },
{ assume a s has ih, simp [has, ih, mul_sup], }
end
@[simp, norm_cast] lemma coe_max (x y : ℝ≥0) :
((max x y : ℝ≥0) : ℝ) = max (x : ℝ) (y : ℝ) :=
by { delta max, split_ifs; refl }
@[simp, norm_cast] lemma coe_min (x y : ℝ≥0) :
((min x y : ℝ≥0) : ℝ) = min (x : ℝ) (y : ℝ) :=
by { delta min, split_ifs; refl }
@[simp] lemma zero_le_coe {q : ℝ≥0} : 0 ≤ (q : ℝ) := q.2
end nnreal
namespace real
section to_nnreal
@[simp] lemma to_nnreal_zero : real.to_nnreal 0 = 0 :=
by simp [real.to_nnreal]; refl
@[simp] lemma to_nnreal_one : real.to_nnreal 1 = 1 :=
by simp [real.to_nnreal, max_eq_left (zero_le_one : (0 :ℝ) ≤ 1)]; refl
@[simp] lemma to_nnreal_pos {r : ℝ} : 0 < real.to_nnreal r ↔ 0 < r :=
by simp [real.to_nnreal, nnreal.coe_lt_coe.symm, lt_irrefl]
@[simp] lemma to_nnreal_eq_zero {r : ℝ} : real.to_nnreal r = 0 ↔ r ≤ 0 :=
by simpa [-to_nnreal_pos] using (not_iff_not.2 (@to_nnreal_pos r))
lemma to_nnreal_of_nonpos {r : ℝ} : r ≤ 0 → real.to_nnreal r = 0 :=
to_nnreal_eq_zero.2
@[simp] lemma coe_to_nnreal' (r : ℝ) : (real.to_nnreal r : ℝ) = max r 0 := rfl
@[simp] lemma to_nnreal_le_to_nnreal_iff {r p : ℝ} (hp : 0 ≤ p) :
real.to_nnreal r ≤ real.to_nnreal p ↔ r ≤ p :=
by simp [nnreal.coe_le_coe.symm, real.to_nnreal, hp]
@[simp] lemma to_nnreal_lt_to_nnreal_iff' {r p : ℝ} :
real.to_nnreal r < real.to_nnreal p ↔ r < p ∧ 0 < p :=
by simp [nnreal.coe_lt_coe.symm, real.to_nnreal, lt_irrefl]
lemma to_nnreal_lt_to_nnreal_iff {r p : ℝ} (h : 0 < p) :
real.to_nnreal r < real.to_nnreal p ↔ r < p :=
to_nnreal_lt_to_nnreal_iff'.trans (and_iff_left h)
lemma to_nnreal_lt_to_nnreal_iff_of_nonneg {r p : ℝ} (hr : 0 ≤ r) :
real.to_nnreal r < real.to_nnreal p ↔ r < p :=
to_nnreal_lt_to_nnreal_iff'.trans ⟨and.left, λ h, ⟨h, lt_of_le_of_lt hr h⟩⟩
@[simp] lemma to_nnreal_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
real.to_nnreal (r + p) = real.to_nnreal r + real.to_nnreal p :=
nnreal.eq $ by simp [real.to_nnreal, hr, hp, add_nonneg]
lemma to_nnreal_add_to_nnreal {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
real.to_nnreal r + real.to_nnreal p = real.to_nnreal (r + p) :=
(real.to_nnreal_add hr hp).symm
lemma to_nnreal_le_to_nnreal {r p : ℝ} (h : r ≤ p) :
real.to_nnreal r ≤ real.to_nnreal p :=
real.to_nnreal_mono h
lemma to_nnreal_add_le {r p : ℝ} :
real.to_nnreal (r + p) ≤ real.to_nnreal r + real.to_nnreal p :=
nnreal.coe_le_coe.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe
lemma to_nnreal_le_iff_le_coe {r : ℝ} {p : ℝ≥0} : real.to_nnreal r ≤ p ↔ r ≤ ↑p :=
nnreal.gi.gc r p
lemma le_to_nnreal_iff_coe_le {r : ℝ≥0} {p : ℝ} (hp : 0 ≤ p) : r ≤ real.to_nnreal p ↔ ↑r ≤ p :=
by rw [← nnreal.coe_le_coe, real.coe_to_nnreal p hp]
lemma le_to_nnreal_iff_coe_le' {r : ℝ≥0} {p : ℝ} (hr : 0 < r) : r ≤ real.to_nnreal p ↔ ↑r ≤ p :=
(le_or_lt 0 p).elim le_to_nnreal_iff_coe_le $ λ hp,
by simp only [(hp.trans_le r.coe_nonneg).not_le, to_nnreal_eq_zero.2 hp.le, hr.not_le]
lemma to_nnreal_lt_iff_lt_coe {r : ℝ} {p : ℝ≥0} (ha : 0 ≤ r) : real.to_nnreal r < p ↔ r < ↑p :=
by rw [← nnreal.coe_lt_coe, real.coe_to_nnreal r ha]
lemma lt_to_nnreal_iff_coe_lt {r : ℝ≥0} {p : ℝ} : r < real.to_nnreal p ↔ ↑r < p :=
begin
cases le_total 0 p,
{ rw [← nnreal.coe_lt_coe, real.coe_to_nnreal p h] },
{ rw [to_nnreal_eq_zero.2 h], split,
{ intro, have := not_lt_of_le (zero_le r), contradiction },
{ intro rp, have : ¬(p ≤ 0) := not_le_of_lt (lt_of_le_of_lt (nnreal.coe_nonneg _) rp),
contradiction } }
end
@[simp] lemma to_nnreal_bit0 {r : ℝ} (hr : 0 ≤ r) :
real.to_nnreal (bit0 r) = bit0 (real.to_nnreal r) :=
real.to_nnreal_add hr hr
@[simp] lemma to_nnreal_bit1 {r : ℝ} (hr : 0 ≤ r) :
real.to_nnreal (bit1 r) = bit1 (real.to_nnreal r) :=
(real.to_nnreal_add (by simp [hr]) zero_le_one).trans (by simp [to_nnreal_one, bit1, hr])
end to_nnreal
end real
open real
namespace nnreal
section mul
lemma mul_eq_mul_left {a b c : ℝ≥0} (h : a ≠ 0) : (a * b = a * c ↔ b = c) :=
begin
rw [← nnreal.eq_iff, ← nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,
{ exact mul_left_cancel' (mt (@nnreal.eq_iff a 0).1 h) },
{ assume h, rw [h] }
end
lemma _root_.real.to_nnreal_mul {p q : ℝ} (hp : 0 ≤ p) :
real.to_nnreal (p * q) = real.to_nnreal p * real.to_nnreal q :=
begin
cases le_total 0 q with hq hq,
{ apply nnreal.eq,
simp [real.to_nnreal, hp, hq, max_eq_left, mul_nonneg] },
{ have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,
rw [to_nnreal_eq_zero.2 hq, to_nnreal_eq_zero.2 hpq, mul_zero] }
end
end mul
section pow
lemma pow_mono_decr_exp {a : ℝ≥0} (m n : ℕ) (mn : m ≤ n) (a1 : a ≤ 1) :
a ^ n ≤ a ^ m :=
begin
rcases le_iff_exists_add.mp mn with ⟨k, rfl⟩,
rw [← mul_one (a ^ m), pow_add],
refine mul_le_mul rfl.le (pow_le_one _ (zero_le a) a1) _ _;
exact pow_nonneg (zero_le _) _,
end
end pow
section sub
lemma sub_def {r p : ℝ≥0} : r - p = real.to_nnreal (r - p) := rfl
lemma sub_eq_zero {r p : ℝ≥0} (h : r ≤ p) : r - p = 0 :=
nnreal.eq $ max_eq_right $ sub_le_iff_le_add.2 $ by simpa [nnreal.coe_le_coe] using h
@[simp] lemma sub_self {r : ℝ≥0} : r - r = 0 := sub_eq_zero $ le_refl r
@[simp] lemma sub_zero {r : ℝ≥0} : r - 0 = r :=
by rw [sub_def, nnreal.coe_zero, sub_zero, real.to_nnreal_coe]
lemma sub_pos {r p : ℝ≥0} : 0 < r - p ↔ p < r :=
to_nnreal_pos.trans $ sub_pos.trans $ nnreal.coe_lt_coe
protected lemma sub_lt_self {r p : ℝ≥0} : 0 < r → 0 < p → r - p < r :=
assume hr hp,
begin
cases le_total r p,
{ rwa [sub_eq_zero h] },
{ rw [← nnreal.coe_lt_coe, nnreal.coe_sub h], exact sub_lt_self _ hp }
end
@[simp] lemma sub_le_iff_le_add {r p q : ℝ≥0} : r - p ≤ q ↔ r ≤ q + p :=
match le_total p r with
| or.inl h := by rw [← nnreal.coe_le_coe, ← nnreal.coe_le_coe, nnreal.coe_sub h, nnreal.coe_add,
sub_le_iff_le_add]
| or.inr h :=
have r ≤ p + q, from le_add_right h,
by simpa [nnreal.coe_le_coe, nnreal.coe_le_coe, sub_eq_zero h, add_comm]
end
@[simp] lemma sub_le_self {r p : ℝ≥0} : r - p ≤ r :=
sub_le_iff_le_add.2 $ le_add_right $ le_refl r
lemma add_sub_cancel {r p : ℝ≥0} : (p + r) - r = p :=
nnreal.eq $ by rw [nnreal.coe_sub, nnreal.coe_add, add_sub_cancel]; exact le_add_self
lemma add_sub_cancel' {r p : ℝ≥0} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
lemma sub_add_eq_max {r p : ℝ≥0} : (r - p) + p = max r p :=
nnreal.eq $ by rw [sub_def, nnreal.coe_add, coe_max, real.to_nnreal, coe_mk,
← max_add_add_right, zero_add, sub_add_cancel]
lemma add_sub_eq_max {r p : ℝ≥0} : p + (r - p) = max p r :=
by rw [add_comm, sub_add_eq_max, max_comm]
@[simp] lemma sub_add_cancel_of_le {a b : ℝ≥0} (h : b ≤ a) : (a - b) + b = a :=
by rw [sub_add_eq_max, max_eq_left h]
lemma sub_sub_cancel_of_le {r p : ℝ≥0} (h : r ≤ p) : p - (p - r) = r :=
by rw [nnreal.sub_def, nnreal.sub_def, real.coe_to_nnreal _ $ sub_nonneg.2 h,
sub_sub_cancel, real.to_nnreal_coe]
lemma lt_sub_iff_add_lt {p q r : ℝ≥0} : p < q - r ↔ p + r < q :=
begin
split,
{ assume H,
have : (((q - r) : ℝ≥0) : ℝ) = (q : ℝ) - (r : ℝ) :=
nnreal.coe_sub (le_of_lt (sub_pos.1 (lt_of_le_of_lt (zero_le _) H))),
rwa [← nnreal.coe_lt_coe, this, lt_sub_iff_add_lt, ← nnreal.coe_add] at H },
{ assume H,
have : r ≤ q := le_trans (le_add_self) (le_of_lt H),
rwa [← nnreal.coe_lt_coe, nnreal.coe_sub this, lt_sub_iff_add_lt, ← nnreal.coe_add] }
end
lemma sub_lt_iff_lt_add {a b c : ℝ≥0} (h : b ≤ a) : a - b < c ↔ a < b + c :=
by simp only [←nnreal.coe_lt_coe, nnreal.coe_sub h, nnreal.coe_add, sub_lt_iff_lt_add']
lemma sub_eq_iff_eq_add {a b c : ℝ≥0} (h : b ≤ a) : a - b = c ↔ a = c + b :=
by rw [←nnreal.eq_iff, nnreal.coe_sub h, ←nnreal.eq_iff, nnreal.coe_add, sub_eq_iff_eq_add]
end sub
section inv
lemma sum_div {ι} (s : finset ι) (f : ι → ℝ≥0) (b : ℝ≥0) :
(∑ i in s, f i) / b = ∑ i in s, (f i / b) :=
by simp only [div_eq_mul_inv, finset.sum_mul]
@[simp] lemma inv_pos {r : ℝ≥0} : 0 < r⁻¹ ↔ 0 < r :=
by simp [pos_iff_ne_zero]
lemma div_pos {r p : ℝ≥0} (hr : 0 < r) (hp : 0 < p) : 0 < r / p :=
by simpa only [div_eq_mul_inv] using mul_pos hr (inv_pos.2 hp)
protected lemma mul_inv {r p : ℝ≥0} : (r * p)⁻¹ = p⁻¹ * r⁻¹ := nnreal.eq $ mul_inv_rev' _ _
lemma div_self_le (r : ℝ≥0) : r / r ≤ 1 :=
if h : r = 0 then by simp [h] else by rw [div_self h]
@[simp] lemma inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p :=
by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h]
lemma inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p :=
by by_cases r = 0; simp [*, inv_le]
@[simp] lemma le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : (r ≤ p⁻¹ ↔ r * p ≤ 1) :=
by rw [← mul_le_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
@[simp] lemma lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : (r < p⁻¹ ↔ r * p < 1) :=
by rw [← mul_lt_mul_left (pos_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
lemma mul_le_iff_le_inv {a b r : ℝ≥0} (hr : r ≠ 0) : r * a ≤ b ↔ a ≤ r⁻¹ * b :=
have 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,
by rw [← @mul_le_mul_left _ _ a _ r this, ← mul_assoc, mul_inv_cancel hr, one_mul]
lemma le_div_iff_mul_le {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ a * r ≤ b :=
by rw [div_eq_inv_mul, ← mul_le_iff_le_inv hr, mul_comm]
lemma div_le_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ b * r :=
@div_le_iff ℝ _ a r b $ pos_iff_ne_zero.2 hr
lemma div_le_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a / r ≤ b ↔ a ≤ r * b :=
@div_le_iff' ℝ _ a r b $ pos_iff_ne_zero.2 hr
lemma le_div_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ a * r ≤ b :=
@le_div_iff ℝ _ a b r $ pos_iff_ne_zero.2 hr
lemma le_div_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a ≤ b / r ↔ r * a ≤ b :=
@le_div_iff' ℝ _ a b r $ pos_iff_ne_zero.2 hr
lemma div_lt_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a / r < b ↔ a < b * r :=
lt_iff_lt_of_le_iff_le (le_div_iff hr)
lemma div_lt_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a / r < b ↔ a < r * b :=
lt_iff_lt_of_le_iff_le (le_div_iff' hr)
lemma lt_div_iff {a b r : ℝ≥0} (hr : r ≠ 0) : a < b / r ↔ a * r < b :=
lt_iff_lt_of_le_iff_le (div_le_iff hr)
lemma lt_div_iff' {a b r : ℝ≥0} (hr : r ≠ 0) : a < b / r ↔ r * a < b :=
lt_iff_lt_of_le_iff_le (div_le_iff' hr)
lemma mul_lt_of_lt_div {a b r : ℝ≥0} (h : a < b / r) : a * r < b :=
begin
refine (lt_div_iff $ λ hr, false.elim _).1 h,
subst r,
simpa using h
end
lemma div_le_div_left_of_le {a b c : ℝ≥0} (b0 : 0 < b) (c0 : 0 < c) (cb : c ≤ b) :
a / b ≤ a / c :=
begin
by_cases a0 : a = 0,
{ rw [a0, zero_div, zero_div] },
{ cases a with a ha,
replace a0 : 0 < a := lt_of_le_of_ne ha (ne_of_lt (zero_lt_iff.mpr a0)),
exact (div_le_div_left a0 b0 c0).mpr cb }
end
lemma div_le_div_left {a b c : ℝ≥0} (a0 : 0 < a) (b0 : 0 < b) (c0 : 0 < c) :
a / b ≤ a / c ↔ c ≤ b :=
by rw [nnreal.div_le_iff b0.ne.symm, div_mul_eq_mul_div, nnreal.le_div_iff_mul_le c0.ne.symm,
mul_le_mul_left a0]
lemma le_of_forall_lt_one_mul_le {x y : ℝ≥0} (h : ∀a<1, a * x ≤ y) : x ≤ y :=
le_of_forall_ge_of_dense $ assume a ha,
have hx : x ≠ 0 := pos_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),
have hx' : x⁻¹ ≠ 0, by rwa [(≠), inv_eq_zero],
have a * x⁻¹ < 1, by rwa [← lt_inv_iff_mul_lt hx', inv_inv'],
have (a * x⁻¹) * x ≤ y, from h _ this,
by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this
lemma div_add_div_same (a b c : ℝ≥0) : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma half_pos {a : ℝ≥0} (h : 0 < a) : 0 < a / 2 := div_pos h zero_lt_two
lemma add_halves (a : ℝ≥0) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)
lemma half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a :=
by rw [← nnreal.coe_lt_coe, nnreal.coe_div]; exact
half_lt_self (bot_lt_iff_ne_bot.2 h)
lemma two_inv_lt_one : (2⁻¹:ℝ≥0) < 1 :=
by simpa using half_lt_self zero_ne_one.symm
lemma div_lt_one_of_lt {a b : ℝ≥0} (h : a < b) : a / b < 1 :=
begin
rwa [div_lt_iff, one_mul],
exact ne_of_gt (lt_of_le_of_lt (zero_le _) h)
end
@[field_simps] lemma div_add_div (a : ℝ≥0) {b : ℝ≥0} (c : ℝ≥0) {d : ℝ≥0}
(hb : b ≠ 0) (hd : d ≠ 0) : a / b + c / d = (a * d + b * c) / (b * d) :=
begin
rw ← nnreal.eq_iff,
simp only [nnreal.coe_add, nnreal.coe_div, nnreal.coe_mul],
exact div_add_div _ _ (coe_ne_zero.2 hb) (coe_ne_zero.2 hd)
end
@[field_simps] lemma add_div' (a b c : ℝ≥0) (hc : c ≠ 0) :
b + a / c = (b * c + a) / c :=
by simpa using div_add_div b a one_ne_zero hc
@[field_simps] lemma div_add' (a b c : ℝ≥0) (hc : c ≠ 0) :
a / c + b = (a + b * c) / c :=
by rwa [add_comm, add_div', add_comm]
lemma _root_.real.to_nnreal_inv {x : ℝ} :
real.to_nnreal x⁻¹ = (real.to_nnreal x)⁻¹ :=
begin
by_cases hx : 0 ≤ x,
{ nth_rewrite 0 ← real.coe_to_nnreal x hx,
rw [←nnreal.coe_inv, real.to_nnreal_coe], },
{ have hx' := le_of_not_ge hx,
rw [to_nnreal_eq_zero.mpr hx', inv_zero, to_nnreal_eq_zero.mpr (inv_nonpos.mpr hx')], },
end
lemma _root_.real.to_nnreal_div {x y : ℝ} (hx : 0 ≤ x) :
real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=
by rw [div_eq_mul_inv, div_eq_mul_inv, ← real.to_nnreal_inv, ← real.to_nnreal_mul hx]
lemma _root_.real.to_nnreal_div' {x y : ℝ} (hy : 0 ≤ y) :
real.to_nnreal (x / y) = real.to_nnreal x / real.to_nnreal y :=
by rw [div_eq_inv_mul, div_eq_inv_mul, real.to_nnreal_mul (inv_nonneg.2 hy), real.to_nnreal_inv]
end inv
@[simp] lemma abs_eq (x : ℝ≥0) : abs (x : ℝ) = x :=
abs_of_nonneg x.property
end nnreal
/-- The absolute value on `ℝ` as a map to `ℝ≥0`. -/
@[pp_nodot] def real.nnabs (x : ℝ) : ℝ≥0 := ⟨abs x, abs_nonneg x⟩
@[norm_cast, simp] lemma nnreal.coe_nnabs (x : ℝ) : (real.nnabs x : ℝ) = abs x :=
by simp [real.nnabs]
@[simp]
lemma real.nnabs_of_nonneg {x : ℝ} (h : 0 ≤ x) : real.nnabs x = real.to_nnreal x :=
by { ext, simp [real.coe_to_nnreal x h, abs_of_nonneg h] }
lemma real.coe_to_nnreal_le (x : ℝ) : (real.to_nnreal x : ℝ) ≤ abs x :=
begin
by_cases h : 0 ≤ x,
{ simp [h, real.coe_to_nnreal x h, le_abs_self] },
{ simp [real.to_nnreal, h, le_abs_self, abs_nonneg] }
end
|
d6275f77a7d303d9dcf302f3d37d7fa519dd7683 | 453dcd7c0d1ef170b0843a81d7d8caedc9741dce | /group_theory/group_action.lean | e56691e60176893d914476400cc6335960f3bd61 | [
"Apache-2.0"
] | permissive | amswerdlow/mathlib | 9af77a1f08486d8fa059448ae2d97795bd12ec0c | 27f96e30b9c9bf518341705c99d641c38638dfd0 | refs/heads/master | 1,585,200,953,598 | 1,534,275,532,000 | 1,534,275,532,000 | 144,564,700 | 0 | 0 | null | 1,534,156,197,000 | 1,534,156,197,000 | null | UTF-8 | Lean | false | false | 4,156 | 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.set.finite group_theory.coset
universes u v
variables {α : Type u} {β : Type v}
class is_monoid_action [monoid α] (f : α → β → β) : Prop :=
(one : ∀ a : β, f (1 : α) a = a)
(mul : ∀ (x y : α) (a : β), f (x * y) a = f x (f y a))
namespace is_monoid_action
variables [monoid α] (f : α → β → β) [is_monoid_action f]
def orbit (a : β) := set.range (λ x : α, f x a)
@[simp] lemma mem_orbit_iff {f : α → β → β} [is_monoid_action f] {a b : β} :
b ∈ orbit f a ↔ ∃ x : α, f x a = b :=
iff.rfl
@[simp] lemma mem_orbit (a : β) (x : α) :
f x a ∈ orbit f a :=
⟨x, rfl⟩
@[simp] lemma mem_orbit_self (a : β) :
a ∈ orbit f a :=
⟨1, show f 1 a = a, by simp [is_monoid_action.one f]⟩
instance orbit_fintype (a : β) [fintype α] [decidable_eq β] :
fintype (orbit f a) := set.fintype_range _
def stabilizer (a : β) : set α :=
{x : α | f x a = a}
@[simp] lemma mem_stabilizer_iff {f : α → β → β} [is_monoid_action f] {a : β} {x : α} :
x ∈ stabilizer f a ↔ f x a = a :=
iff.rfl
def fixed_points : set β := {a : β | ∀ x, x ∈ stabilizer f a}
@[simp] lemma mem_fixed_points {f : α → β → β} [is_monoid_action f] {a : β} :
a ∈ fixed_points f ↔ ∀ x : α, f x a = a := iff.rfl
lemma mem_fixed_points' {f : α → β → β} [is_monoid_action f] {a : β} : a ∈ fixed_points f ↔
(∀ b, b ∈ orbit f a → b = a) :=
⟨λ h b h₁, let ⟨x, hx⟩ := mem_orbit_iff.1 h₁ in hx ▸ h x,
λ h b, mem_stabilizer_iff.2 (h _ (mem_orbit _ _ _))⟩
end is_monoid_action
class is_group_action [group α] (f : α → β → β) extends is_monoid_action f
namespace is_group_action
variables [group α] (f : α → β → β) [is_group_action f]
open is_monoid_action
def to_perm (g : α) : equiv.perm β :=
{ to_fun := f g,
inv_fun := f g⁻¹,
left_inv := λ a, by rw [← is_monoid_action.mul f, inv_mul_self, is_monoid_action.one f],
right_inv := λ a, by rw [← is_monoid_action.mul f, mul_inv_self, is_monoid_action.one f] }
instance : is_group_hom (to_perm f) :=
{ mul := λ x y, equiv.ext _ _ (λ a, is_monoid_action.mul f x y a) }
lemma bijective (g : α) : function.bijective (f g) :=
(to_perm f g).bijective
lemma orbit_eq_iff {f : α → β → β} [is_monoid_action f] {a b : β} :
orbit f a = orbit f b ↔ a ∈ orbit f b:=
⟨λ h, h ▸ mem_orbit_self _ _,
λ ⟨x, (hx : f x b = a)⟩, set.ext (λ c, ⟨λ ⟨y, (hy : f y a = c)⟩, ⟨y * x,
show f (y * x) b = c, by rwa [is_monoid_action.mul f, hx]⟩,
λ ⟨y, (hy : f y b = c)⟩, ⟨y * x⁻¹,
show f (y * x⁻¹) a = c, by
conv {to_rhs, rw [← hy, ← mul_one y, ← inv_mul_self x, ← mul_assoc,
is_monoid_action.mul f, hx]}⟩⟩)⟩
instance (a : β) : is_subgroup (stabilizer f a) :=
{ one_mem := is_monoid_action.one _ _,
mul_mem := λ x y (hx : f x a = a) (hy : f y a = a),
show f (x * y) a = a, by rw is_monoid_action.mul f; simp *,
inv_mem := λ x (hx : f x a = a), show f x⁻¹ a = a,
by rw [← hx, ← is_monoid_action.mul f, inv_mul_self, is_monoid_action.one f, hx] }
noncomputable lemma orbit_equiv_left_cosets (a : β) :
orbit f a ≃ left_cosets (stabilizer f a) :=
by letI := left_rel (stabilizer f a); exact
equiv.symm (@equiv.of_bijective _ _
(λ x : left_cosets (stabilizer f a), quotient.lift_on x
(λ x, (⟨f x a, mem_orbit _ _ _⟩ : orbit f a))
(λ g h (H : _ = _), subtype.eq $ (is_group_action.bijective f (g⁻¹)).1
$ show f g⁻¹ (f g a) = f g⁻¹ (f h a),
by rw [← is_monoid_action.mul f, ← is_monoid_action.mul f,
H, inv_mul_self, is_monoid_action.one f]))
⟨λ g h, quotient.induction_on₂ g h (λ g h H, quotient.sound $
have H : f g a = f h a := subtype.mk.inj H,
show f (g⁻¹ * h) a = a,
by rw [is_monoid_action.mul f, ← H, ← is_monoid_action.mul f, inv_mul_self,
is_monoid_action.one f]),
λ ⟨b, ⟨g, hgb⟩⟩, ⟨⟦g⟧, subtype.eq hgb⟩⟩)
end is_group_action |
5fbbdb869f0a05661de07ed545ea586a94bca273 | 737dc4b96c97368cb66b925eeea3ab633ec3d702 | /src/Lean/Meta/IndPredBelow.lean | 04d6b985bee03b20f4570f0e6e088cc905a69b86 | [
"Apache-2.0"
] | permissive | Bioye97/lean4 | 1ace34638efd9913dc5991443777b01a08983289 | bc3900cbb9adda83eed7e6affeaade7cfd07716d | refs/heads/master | 1,690,589,820,211 | 1,631,051,000,000 | 1,631,067,598,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,609 | lean | /-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dany Fabian
-/
import Lean.Meta.Constructions
import Lean.Meta.Transform
import Lean.Meta.Tactic
import Lean.Meta.Match.Match
import Lean.Meta.Reduce
namespace Lean.Meta.IndPredBelow
open Match
register_builtin_option maxBackwardChainingDepth : Nat := {
defValue := 10
descr := "The maximum search depth used in the backwards chaining part of the proof of `brecOn` for inductive predicates."
}
/--
The context used in the creation of the `below` scheme for inductive predicates.
-/
structure Context where
motives : Array (Name × Expr)
typeInfos : Array InductiveVal
belowNames : Array Name
headers : Array Expr
numParams : Nat
/--
Collection of variables used to keep track of the positions of binders in the construction
of `below` motives and constructors.
-/
structure Variables where
target : Array Expr
indVal : Array Expr
params : Array Expr
args : Array Expr
motives : Array Expr
innerType : Expr
deriving Inhabited
/--
Collection of variables used to keep track of the local context used in the `brecOn` proof.
-/
structure BrecOnVariables where
params : Array FVarId
motives : Array FVarId
indices : Array FVarId
witness : FVarId
indHyps : Array FVarId
def mkContext (declName : Name) : MetaM Context := do
let indVal ← getConstInfoInduct declName
let typeInfos ← indVal.all.toArray.mapM getConstInfoInduct
let motiveTypes ← typeInfos.mapM motiveType
let motives ←motiveTypes.mapIdxM fun j motive => do
(←motiveName motiveTypes j.val, motive)
let headers := typeInfos.mapM $ mkHeader motives indVal.numParams
return {
motives := motives
typeInfos := typeInfos
numParams := indVal.numParams
headers := ←headers
belowNames := ←indVal.all.toArray.map (· ++ `below) }
where
motiveName (motiveTypes : Array Expr) (i : Nat) : MetaM Name :=
if motiveTypes.size > 1
then mkFreshUserName s!"motive_{i.succ}"
else mkFreshUserName "motive"
mkHeader
(motives : Array (Name × Expr))
(numParams : Nat)
(indVal : InductiveVal) : MetaM Expr := do
let header ← forallTelescope indVal.type fun xs t => do
withNewBinderInfos (xs.map fun x => (x.fvarId!, BinderInfo.implicit)) $
mkForallFVars xs $ ←mkArrow (mkAppN (mkIndValConst indVal) xs) t
addMotives motives numParams header
addMotives (motives : Array (Name × Expr)) (numParams : Nat) : Expr → MetaM Expr :=
motives.foldrM (fun (motiveName, motive) t =>
forallTelescope t fun xs s => do
let motiveType ← instantiateForall motive xs[:numParams]
withLocalDecl motiveName BinderInfo.implicit motiveType fun motive => do
mkForallFVars (xs.insertAt numParams motive) s)
motiveType (indVal : InductiveVal) : MetaM Expr :=
forallTelescope indVal.type fun xs t => do
mkForallFVars xs $ ←mkArrow (mkAppN (mkIndValConst indVal) xs) (mkSort levelZero)
mkIndValConst (indVal : InductiveVal) : Expr :=
mkConst indVal.name $ indVal.levelParams.map mkLevelParam
partial def mkCtorType
(ctx : Context)
(belowIdx : Nat)
(originalCtor : ConstructorVal) : MetaM Expr :=
forallTelescope originalCtor.type fun xs t => addHeaderVars
{ innerType := t
indVal := #[]
motives := #[]
params := xs[:ctx.numParams]
args := xs[ctx.numParams:]
target := xs[:ctx.numParams] }
where
addHeaderVars (vars : Variables) := do
let headersWithNames ← ctx.headers.mapIdxM fun idx header =>
(ctx.belowNames[idx], fun _ => pure header)
withLocalDeclsD headersWithNames fun xs =>
addMotives { vars with indVal := xs }
addMotives (vars : Variables) := do
let motiveBuilders ← ctx.motives.mapM fun (motiveName, motiveType) =>
(motiveName, BinderInfo.implicit, fun _ =>
instantiateForall motiveType vars.params)
withLocalDecls motiveBuilders fun xs =>
modifyBinders { vars with target := vars.target ++ xs, motives := xs } 0
modifyBinders (vars : Variables) (i : Nat) := do
if i < vars.args.size then
let binder := vars.args[i]
let binderType ←inferType binder
if ←checkCount binderType then
mkBelowBinder vars binder binderType fun indValIdx x =>
mkMotiveBinder vars indValIdx binder binderType fun y =>
withNewBinderInfos #[(binder.fvarId!, BinderInfo.implicit)] do
modifyBinders { vars with target := vars.target ++ #[binder, x, y]} i.succ
else modifyBinders { vars with target := vars.target.push binder } i.succ
else rebuild vars
rebuild (vars : Variables) :=
vars.innerType.withApp fun f args => do
let hApp :=
mkAppN
(mkConst originalCtor.name $ ctx.typeInfos[0].levelParams.map mkLevelParam)
(vars.params ++ vars.args)
let innerType := mkAppN vars.indVal[belowIdx] $
vars.params ++ vars.motives ++ args[ctx.numParams:] ++ #[hApp]
let x ← mkForallFVars vars.target innerType
replaceTempVars vars x
replaceTempVars (vars : Variables) (ctor : Expr) :=
let levelParams :=
ctx.typeInfos[0].levelParams.map mkLevelParam
ctor.replaceFVars vars.indVal $ ctx.belowNames.map fun indVal =>
mkConst indVal levelParams
checkCount (domain : Expr) : MetaM Bool := do
let run (x : StateRefT Nat MetaM Expr) : MetaM (Expr × Nat) := StateRefT'.run x 0
let (_, cnt) ←run $ transform domain fun e => do
if let some name := e.constName? then
if let some idx := ctx.typeInfos.findIdx? fun indVal => indVal.name == name then
let cnt ←get
set $ cnt + 1
TransformStep.visit e
if cnt > 1 then
throwError "only arrows are allowed as premises. Multiple recursive occurrences detected:{indentExpr domain}"
return cnt == 1
mkBelowBinder
(vars : Variables)
(binder : Expr)
(domain : Expr)
{α : Type} (k : Nat → Expr → MetaM α) : MetaM α := do
forallTelescope domain fun xs t => do
let fail _ := do
throwError "only trivial inductive applications supported in premises:{indentExpr t}"
t.withApp fun f args => do
if let some name := f.constName? then
if let some idx := ctx.typeInfos.findIdx?
fun indVal => indVal.name == name then
let indVal := ctx.typeInfos[idx]
let hApp := mkAppN binder xs
let t :=
mkAppN vars.indVal[idx] $
vars.params ++ vars.motives ++ args[ctx.numParams:] ++ #[hApp]
let newDomain ← mkForallFVars xs t
withLocalDecl (←copyVarName binder.fvarId!) binder.binderInfo newDomain (k idx)
else fail ()
else fail ()
mkMotiveBinder
(vars : Variables)
(indValIdx : Nat)
(binder : Expr)
(domain : Expr)
{α : Type} (k : Expr → MetaM α) : MetaM α := do
forallTelescope domain fun xs t => do
t.withApp fun f args => do
let hApp := mkAppN binder xs
let t := mkAppN vars.motives[indValIdx] $ args[ctx.numParams:] ++ #[hApp]
let newDomain ← mkForallFVars xs t
withLocalDecl (←copyVarName binder.fvarId!) binder.binderInfo newDomain k
copyVarName (oldName : FVarId) : MetaM Name := do
let binderDecl ← getLocalDecl oldName
mkFreshUserName binderDecl.userName
def mkConstructor (ctx : Context) (i : Nat) (ctor : Name) : MetaM Constructor := do
let ctorInfo ← getConstInfoCtor ctor
let name := ctor.updatePrefix ctx.belowNames[i]
let type ← mkCtorType ctx i ctorInfo
return {
name := name
type := type }
def mkInductiveType
(ctx : Context)
(i : Fin ctx.typeInfos.size)
(indVal : InductiveVal) : MetaM InductiveType := do
return {
name := ctx.belowNames[i]
type := ctx.headers[i]
ctors := ←indVal.ctors.mapM (mkConstructor ctx i) }
def mkBelowDecl (ctx : Context) : MetaM Declaration := do
let lparams := ctx.typeInfos[0].levelParams
Declaration.inductDecl
lparams
(ctx.numParams + ctx.motives.size)
(←ctx.typeInfos.mapIdxM $ mkInductiveType ctx).toList
ctx.typeInfos[0].isUnsafe
partial def backwardsChaining (m : MVarId) (depth : Nat) : MetaM Bool := do
if depth = 0 then false
else
withMVarContext m do
let lctx ← getLCtx
let mTy ← getMVarType m
lctx.anyM fun localDecl =>
if localDecl.isAuxDecl then
false
else
commitWhen do
let (mvars, _, t) ← forallMetaTelescope localDecl.type
if ←isDefEq mTy t then
assignExprMVar m (mkAppN localDecl.toExpr mvars)
mvars.allM fun v =>
isExprMVarAssigned v.mvarId! <||> backwardsChaining v.mvarId! (depth - 1)
else false
partial def proveBrecOn (ctx : Context) (indVal : InductiveVal) (type : Expr) : MetaM Expr := do
let main ← mkFreshExprSyntheticOpaqueMVar type
let (m, vars) ← intros main.mvarId!
let [m] ← applyIH m vars |
throwError "applying the induction hypothesis should only return one goal"
let ms ← induction m vars
let ms ← applyCtors ms
let maxDepth := maxBackwardChainingDepth.get $ ←getOptions
ms.forM (closeGoal vars maxDepth)
instantiateMVars main
where
intros (m : MVarId) : MetaM (MVarId × BrecOnVariables) := do
let (params, m) ← introNP m indVal.numParams
let (motives, m) ← introNP m ctx.motives.size
let (indices, m) ← introNP m indVal.numIndices
let (witness, m) ← intro1P m
let (indHyps, m) ← introNP m ctx.motives.size
return (m, ⟨params, motives, indices, witness, indHyps⟩)
applyIH (m : MVarId) (vars : BrecOnVariables) : MetaM (List MVarId) := do
match ←vars.indHyps.findSomeM?
(fun ih => do try some $ (←apply m $ mkFVar ih) catch ex => none) with
| some goals => goals
| none => throwError "cannot apply induction hypothesis: {MessageData.ofGoal m}"
induction (m : MVarId) (vars : BrecOnVariables) : MetaM (List MVarId) := do
let params := vars.params.map mkFVar
let motives := vars.motives.map mkFVar
let levelParams := indVal.levelParams.map mkLevelParam
let motives ← ctx.motives.mapIdxM fun idx (_, motive) => do
let motive ← instantiateForall motive params
forallTelescope motive fun xs _ => do
mkLambdaFVars xs $ mkAppN (mkConst ctx.belowNames[idx] levelParams) $ (params ++ motives ++ xs)
let recursorInfo ← getConstInfo $ mkRecName indVal.name
let recLevels :=
if recursorInfo.numLevelParams > levelParams.length
then levelZero::levelParams
else levelParams
let recursor ← mkAppN (mkConst recursorInfo.name $ recLevels) $ params ++ motives
apply m recursor
applyCtors (ms : List MVarId) : MetaM $ List MVarId := do
let mss ← ms.toArray.mapIdxM fun idx m => do
let m ← introNPRec m
(←getMVarType m).withApp fun below args =>
withMVarContext m do
args.back.withApp fun ctor ctorArgs => do
let ctorName := ctor.constName!.updatePrefix below.constName!
let ctor := mkConst ctorName below.constLevels!
let ctorInfo ← getConstInfoCtor ctorName
let (mvars, _, t) ← forallMetaTelescope ctorInfo.type
let ctor := mkAppN ctor mvars
apply m ctor
return mss.foldr List.append []
introNPRec (m : MVarId) : MetaM MVarId := do
if (←getMVarType m).isForall then introNPRec (←intro1P m).2 else m
closeGoal (vars : BrecOnVariables) (maxDepth : Nat) (m : MVarId) : MetaM Unit := do
unless ←isExprMVarAssigned m do
let m ← introNPRec m
unless ←backwardsChaining m maxDepth do
withMVarContext m do
throwError "couldn't solve by backwards chaining ({``maxBackwardChainingDepth} = {maxDepth}): {MessageData.ofGoal m}"
def mkBrecOnDecl (ctx : Context) (idx : Nat) : MetaM Declaration := do
let type ← mkType
let indVal := ctx.typeInfos[idx]
let name := indVal.name ++ brecOnSuffix
Declaration.thmDecl {
name := name
levelParams := indVal.levelParams
type := type
value := ←proveBrecOn ctx indVal type }
where
mkType : MetaM Expr :=
forallTelescope ctx.headers[idx] fun xs t => do
let params := xs[:ctx.numParams]
let motives := xs[ctx.numParams:ctx.numParams + ctx.motives.size].toArray
let indices := xs[ctx.numParams + ctx.motives.size:]
let motiveBinders ← ctx.motives.mapIdxM $ mkIH params motives
withLocalDeclsD motiveBinders fun ys => do
mkForallFVars (xs ++ ys) (mkAppN motives[idx] indices)
mkIH
(params : Array Expr)
(motives : Array Expr)
(idx : Fin ctx.motives.size)
(motive : Name × Expr) : MetaM $ Name × (Array Expr → MetaM Expr) := do
let name :=
if ctx.motives.size > 1
then mkFreshUserName s!"ih_{idx.val.succ}"
else mkFreshUserName "ih"
let ih ← instantiateForall motive.2 params
let mkDomain _ :=
forallTelescope ih fun ys t => do
let levels := ctx.typeInfos[idx].levelParams.map mkLevelParam
let args := params ++ motives ++ ys
let premise :=
mkAppN
(mkConst ctx.belowNames[idx.val] levels) args
let conclusion :=
mkAppN motives[idx] ys
mkForallFVars ys (←mkArrow premise conclusion)
(←name, mkDomain)
/-- Given a constructor name, find the indices of the corresponding `below` version thereof. -/
partial def getBelowIndices (ctorName : Name) : MetaM $ Array Nat := do
let ctorInfo ← getConstInfoCtor ctorName
let belowCtorInfo ← getConstInfoCtor (ctorName.updatePrefix $ ctorInfo.induct ++ `below)
let belowInductInfo ← getConstInfoInduct belowCtorInfo.induct
forallTelescope ctorInfo.type fun xs t => do
loop xs belowCtorInfo.type #[] 0 0
where
loop
(xs : Array Expr)
(rest : Expr)
(belowIndices : Array Nat)
(xIdx yIdx : Nat) : MetaM $ Array Nat := do
if xIdx ≥ xs.size then belowIndices else
let x := xs[xIdx]
let xTy ← inferType x
let yTy := rest.bindingDomain!
if ←isDefEq xTy yTy then
let rest ← instantiateForall rest #[x]
loop xs rest (belowIndices.push yIdx) (xIdx + 1) (yIdx + 1)
else
forallBoundedTelescope rest (some 1) fun ys rest =>
loop xs rest belowIndices xIdx (yIdx + 1)
private def belowType (motive : Expr) (xs : Array Expr) (idx : Nat) : MetaM $ Name × Expr := do
(←inferType xs[idx]).withApp fun type args => do
let indName := type.constName!
let indInfo ← getConstInfoInduct indName
let belowArgs := args[:indInfo.numParams] ++ #[motive] ++ args[indInfo.numParams:] ++ #[xs[idx]]
let belowType := mkAppN (mkConst (indName ++ `below) type.constLevels!) belowArgs
(indName, belowType)
/-- This function adds an additional `below` discriminant to a matcher application.
It is used for modifying the patterns, such that the structural recursion can use the new
`below` predicate instead of the original one and thus be used prove structural recursion.
It takes as parameters:
- matcherApp: a matcher application
- belowMotive: the motive, that the `below` type should carry
- below: an expression from the local context that is the `below` version of a predicate
and can be used for structural recursion
- idx: the index of the original predicate discriminant.
It returns:
- A matcher application as an expression
- A side-effect for adding the matcher to the environment -/
partial def mkBelowMatcher
(matcherApp : MatcherApp)
(belowMotive : Expr)
(below : Expr)
(idx : Nat) : MetaM $ Expr × MetaM Unit := do
let mkMatcherInput ← getMkMatcherInputInContext matcherApp
let (indName, belowType, motive, matchType) ←
forallBoundedTelescope mkMatcherInput.matchType mkMatcherInput.numDiscrs fun xs t => do
let (indName, belowType) ← belowType belowMotive xs idx
let matchType ←
withLocalDeclD (←mkFreshUserName `h_below) belowType fun h_below => do
mkForallFVars (xs.push h_below) t
let motive ← newMotive belowType xs
(indName, belowType.replaceFVars xs matcherApp.discrs, motive, matchType)
let lhss ← mkMatcherInput.lhss.mapM $ addBelowPattern indName
let alts ← mkMatcherInput.lhss.zip lhss |>.toArray.zip matcherApp.alts |>.mapIdxM fun idx ((oldLhs, lhs), alt) => do
withExistingLocalDecls (oldLhs.fvarDecls ++ lhs.fvarDecls) do
lambdaTelescope alt fun xs t => do
let oldFVars := oldLhs.fvarDecls.toArray
let fvars := lhs.fvarDecls.toArray.map (·.toExpr)
let xs :=
-- special case: if we had no free vars, i.e. there was a unit added and no we do have free vars, we get rid of the unit.
match oldFVars.size, fvars.size with
| 0, n+1 => xs[1:]
| _, _ => xs
let t := t.replaceFVars xs[:oldFVars.size] fvars[:oldFVars.size]
trace[Meta.IndPredBelow.match] "xs = {xs}; oldFVars = {oldFVars.map (·.toExpr)}; fvars = {fvars}; new = {fvars[:oldFVars.size] ++ xs[oldFVars.size:] ++ fvars[oldFVars.size:]}"
let newAlt ← mkLambdaFVars (fvars[:oldFVars.size] ++ xs[oldFVars.size:] ++ fvars[oldFVars.size:]) t
trace[Meta.IndPredBelow.match] "alt {idx}:\n{alt} ↦ {newAlt}"
newAlt
let matcherName ← mkFreshUserName mkMatcherInput.matcherName
withExistingLocalDecls (lhss.foldl (init := []) fun s v => s ++ v.fvarDecls) do
for lhs in lhss do
trace[Meta.IndPredBelow.match] "{←lhs.patterns.mapM (·.toMessageData)}"
let res ← Match.mkMatcher { matcherName, matchType, numDiscrs := (mkMatcherInput.numDiscrs + 1), lhss }
res.addMatcher
-- if a wrong index is picked, the resulting matcher can be type-incorrect.
-- we check here, so that errors can propagate higher up the call stack.
check res.matcher
let args := #[motive] ++ matcherApp.discrs.push below ++ alts
let newApp := mkApp res.matcher motive
let newApp := mkAppN newApp $ matcherApp.discrs.push below
let newApp := mkAppN newApp alts
(newApp, res.addMatcher)
where
addBelowPattern (indName : Name) (lhs : AltLHS) : MetaM AltLHS := do
withExistingLocalDecls lhs.fvarDecls do
let patterns := lhs.patterns.toArray
let originalPattern := patterns[idx]
let (fVars, belowPattern) ← convertToBelow indName patterns[idx]
withExistingLocalDecls fVars.toList do
let patterns := patterns.push belowPattern
let patterns := patterns.set! idx (←toInaccessible originalPattern)
{ lhs with patterns := patterns.toList, fvarDecls := lhs.fvarDecls ++ fVars.toList }
/--
this function changes the type of the pattern from the original type to the `below` version thereof.
Most of the cases don't apply. In order to change the type and the pattern to be type correct, we don't
simply recursively change all occurrences, but rather, we recursively change occurences of the constructor.
As such there are only a few cases:
- the pattern is a constructor from the original type. Here we need to:
- replace the constructor
- copy original recursive patterns and convert them to below and reintroduce them in the correct position
- turn original recursive patterns inaccessible
- introduce free variables as needed.
- it is an `as` pattern. Here the contstructor could be hidden inside of it.
- it is a variable. Here you we need to introduce a fresh variable of a different type.
-/
convertToBelow (indName : Name)
(originalPattern : Pattern) : MetaM $ Array LocalDecl × Pattern := do
match originalPattern with
| Pattern.ctor ctorName us params fields =>
let ctorInfo ← getConstInfoCtor ctorName
let belowCtor ← getConstInfoCtor $ ctorName.updatePrefix $ ctorInfo.induct ++ `below
let belowIndices ← IndPredBelow.getBelowIndices ctorName
let belowIndices := belowIndices[ctorInfo.numParams:].toArray.map (· - belowCtor.numParams)
-- belowFieldOpts starts off with an array of empty fields.
-- We then go over pattern's fields and set the appropriate fields to values.
-- In general, there are fewer `fields` than `belowFieldOpts`, because the
-- `belowCtor` carries a `below`, a non-`below` and a `motive` version of each
-- field that occurs in a recursive application of the inductive predicate.
-- `belowIndices` is a mapping from non-`below` to the `below` version of each field.
let mut belowFieldOpts := mkArray belowCtor.numFields none
let fields := fields.toArray
for fieldIdx in [:fields.size] do
belowFieldOpts := belowFieldOpts.set! belowIndices[fieldIdx] (some fields[fieldIdx])
let belowParams := params.toArray.push belowMotive
let belowCtorExpr := mkAppN (mkConst belowCtor.name us) belowParams
let (additionalFVars, belowFields) ← transformFields belowCtorExpr indName belowFieldOpts
withExistingLocalDecls additionalFVars.toList do
let ctor := Pattern.ctor belowCtor.name us belowParams.toList belowFields.toList
trace[Meta.IndPredBelow.match] "{originalPattern.toMessageData} ↦ {ctor.toMessageData}"
(additionalFVars, ctor)
| Pattern.as varId p =>
let (additionalFVars, p) ← convertToBelow indName p
(additionalFVars, Pattern.as varId p)
| Pattern.var varId =>
let var := mkFVar varId
(←inferType var).withApp fun ind args => do
let (_, tgtType) ← belowType belowMotive #[var] 0
withLocalDeclD (←mkFreshUserName `h) tgtType fun h => do
let localDecl ← getFVarLocalDecl h
(#[localDecl], Pattern.var h.fvarId!)
| p => (#[], p)
transformFields belowCtor indName belowFieldOpts :=
let rec loop
(belowCtor : Expr)
(belowFieldOpts : Array $ Option Pattern)
(belowFields : Array Pattern)
(additionalFVars : Array LocalDecl) : MetaM (Array LocalDecl × Array Pattern) := do
if belowFields.size ≥ belowFieldOpts.size then (additionalFVars, belowFields) else
if let some belowField := belowFieldOpts[belowFields.size] then
let belowFieldExpr ← belowField.toExpr
let belowCtor := mkApp belowCtor belowFieldExpr
let patTy ← inferType belowFieldExpr
patTy.withApp fun f args => do
let constName := f.constName?
if constName == indName then
let (fvars, transformedField) ← convertToBelow indName belowField
withExistingLocalDecls fvars.toList do
let belowFieldOpts := belowFieldOpts.set! (belowFields.size + 1) transformedField
let belowField :=
match belowField with
| Pattern.ctor .. => Pattern.inaccessible belowFieldExpr
| _ => belowField
loop belowCtor belowFieldOpts (belowFields.push belowField) (additionalFVars ++ fvars)
else
loop belowCtor belowFieldOpts (belowFields.push belowField) additionalFVars
else
let ctorType ← inferType belowCtor
withLocalDeclD (←mkFreshUserName `a) ctorType.bindingDomain! fun a => do
let localDecl ← getFVarLocalDecl a
loop (mkApp belowCtor a) belowFieldOpts (belowFields.push $ Pattern.var a.fvarId!) (additionalFVars.push localDecl)
loop belowCtor belowFieldOpts #[] #[]
toInaccessible : Pattern → MetaM Pattern
| Pattern.inaccessible p => Pattern.inaccessible p
| Pattern.var v => Pattern.var v
| p => do Pattern.inaccessible $ ←p.toExpr
newMotive (belowType : Expr) (ys : Array Expr) : MetaM Expr :=
lambdaTelescope matcherApp.motive fun xs t => do
let numDiscrs := matcherApp.discrs.size
withLocalDeclD (←mkFreshUserName `h_below) (←belowType.replaceFVars ys xs) fun h_below => do
let motive ← mkLambdaFVars (xs[:numDiscrs] ++ #[h_below] ++ xs[numDiscrs:]) t
trace[Meta.IndPredBelow.match] "motive := {motive}"
motive
def findBelowIdx (xs : Array Expr) (motive : Expr) : MetaM $ Option (Expr × Nat) := do
xs.findSomeM? fun x => do
let xTy ← inferType x
xTy.withApp fun f args =>
match f.constName?, xs.indexOf? x with
| some name, some idx => do
if ←isInductivePredicate name then
let (_, belowTy) ← belowType motive xs idx
let below ← mkFreshExprSyntheticOpaqueMVar belowTy
try
trace[Meta.IndPredBelow.match] "{←Meta.ppGoal below.mvarId!}"
if ←backwardsChaining below.mvarId! 10 then
trace[Meta.IndPredBelow.match] "Found below term in the local context: {below}"
if ←xs.anyM (isDefEq below) then none else (below, idx.val)
else
trace[Meta.IndPredBelow.match] "could not find below term in the local context"
none
catch _ => none
else none
| _, _ => none
def mkBelow (declName : Name) : MetaM Unit := do
if (←isInductivePredicate declName) then
let x ← getConstInfoInduct declName
if x.isRec then
let ctx ← IndPredBelow.mkContext declName
let decl ← IndPredBelow.mkBelowDecl ctx
addDecl decl
trace[Meta.IndPredBelow] "added {ctx.belowNames}"
ctx.belowNames.forM Lean.mkCasesOn
for i in [:ctx.typeInfos.size] do
try
let decl ← IndPredBelow.mkBrecOnDecl ctx i
addDecl decl
catch e => trace[Meta.IndPredBelow] "failed to prove brecOn for {ctx.belowNames[i]}\n{e.toMessageData}"
else trace[Meta.IndPredBelow] "Not recursive"
else trace[Meta.IndPredBelow] "Not inductive predicate"
builtin_initialize
registerTraceClass `Meta.IndPredBelow
registerTraceClass `Meta.IndPredBelow.match
end Lean.Meta.IndPredBelow
|
a177328976b58dc89013110cd3fc8985a304bc83 | d6aa76a731f5d0a2c72a62729e52996fe8ac81b3 | /src/friendship.lean | 1baf3d44d07fcb444cc8d404555ca5798cc4b083 | [] | no_license | jalex-stark/friendship-theorem | 88d30d3f4b17cc275a1a4bbc747eeb41f9e1b7a1 | d0e823b0b298c3fcfffe885cd6d2064a5757ef27 | refs/heads/master | 1,668,993,481,235 | 1,595,108,750,000 | 1,595,108,777,000 | 270,936,124 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 17,836 | lean | import data.zmod.basic
import adjacency_matrix sym_matrix double_counting data.fintype.basic
import changing_scalars
import data.int.modeq
import tactic
import char_poly
import number_theory.quadratic_reciprocity
open_locale classical
noncomputable theory
lemma exists_unique_rewrite {X:Type*} {p: X → Prop} {q: X → Prop}:
(∀ x:X, p x ↔ q x) → (∃!x : X, p x) → ∃!x:X, q x:=
begin
intro h, rw exists_unique_congr h,
tidy,
end
variables {V:Type} [fintype V] [inhabited V]
def is_friend (G : simple_graph V) (v w : V) (u : V) : Prop :=
G.E v u ∧ G.E w u
def friendship (G : simple_graph V) : Prop :=
∀ v w : V, v ≠ w → ∃!(u : V), is_friend G v w u
@[simp] lemma friend_symm {G : simple_graph V} {v w x:V} :
G.E v x ∧ G.E x w ↔ G.E v x ∧ G.E w x:=
begin
split; try { intro a, cases a, split };
try {assumption};
{ apply G.undirected, assumption },
end
def find_friend (G:simple_graph V)(friendG: friendship G)(v w:V)(vneqw:v ≠ w):V:=
fintype.choose (is_friend G v w) (friendG v w vneqw)
lemma find_friend_spec (G:simple_graph V)(friendG: friendship G)(v w:V)(vneqw: v ≠ w):
is_friend G v w (find_friend G friendG v w vneqw):= by apply fintype.choose_spec
lemma find_friend_unique (G:simple_graph V)(friendG: friendship G)(v w:V)(vneqw: v ≠ w):
∀ y:V, is_friend G v w y → y=(find_friend G friendG v w vneqw):=
begin
intros y hy,
apply exists_unique.unique(friendG v w vneqw),
apply hy,
apply (find_friend_spec G friendG v w vneqw),
end
def exists_politician (G:simple_graph V) : Prop :=
∃ v:V, ∀ w:V, v=w ∨ G.E v w
def no_pol (G:simple_graph V) : Prop :=
∀ v:V, ∃ w:V, v ≠ w ∧ ¬ G.E v w
lemma exists_pol_of_not_no_pol {G:simple_graph V}:
(¬ no_pol G) ↔ exists_politician G:=
begin
unfold no_pol exists_politician, simp only [not_exists, not_and, classical.not_forall, ne.def, classical.not_not],
apply exists_congr, intro v, apply forall_congr, intro w, tauto,
end
def path_bigraph (G : simple_graph V) (A B:finset V) : bigraph V V:=
bigraph.mk A B G.E
lemma path_bigraph_swap {G : simple_graph V} {A B : finset V} :
(path_bigraph G A B).swap = path_bigraph G B A:=
begin
ext, {refl}, {refl},
split; apply G.undirected,
end
def friends (G : simple_graph V)(v w : V) : finset V :=
finset.filter (is_friend G v w) (finset.univ:finset V)
lemma friends_eq_inter_neighbors {G : simple_graph V} {v w : V} :
friends G v w = neighbors G v ∩ neighbors G w:=
begin
ext,
rw finset.mem_inter, erw finset.mem_filter,
unfold is_friend, simp,
end
lemma friendship' {G : simple_graph V} (friendG : friendship G) {v w : V} (hvw : v ≠ w):
exists_unique (is_friend G v w) :=
begin
use find_friend G friendG v w hvw,
split, exact find_friend_spec G friendG v w hvw,
intros x hx,
apply exists_unique.unique (friendG v w hvw) hx,
exact find_friend_spec G friendG v w hvw,
end
lemma card_friends {G : simple_graph V} (friendG : friendship G) {v w : V} (hvw : v ≠ w) :
(friends G v w).card = 1 :=
begin
rw finset.card_eq_one,
rw finset.singleton_iff_unique_mem,
unfold friends, simp [friendship' friendG hvw],
end
lemma left_fiber_eq_nbrs_inter_A {G : simple_graph V} {A B : finset V} {v : V} :
v ∈ B → left_fiber (path_bigraph G A B) v = A ∩ (neighbors G v):=
begin
intro vB, ext,
simp only [neighbor_iff_adjacent, mem_left_fiber, finset.mem_inter],
change a ∈ A ∧ G.E a v ↔ a ∈ A ∧ G.E v a,
have h : G.E a v ↔ G.E v a, {split; apply G.undirected},
rw h,
end
lemma right_fiber_eq_nbrs_inter_B {G : simple_graph V} {A B : finset V} {v : V} (hv : v ∈ A):
right_fiber (path_bigraph G A B) v = B ∩ (neighbors G v):=
begin
rw [← left_fiber_swap, path_bigraph_swap],
exact left_fiber_eq_nbrs_inter_A hv,
end
lemma lunique_paths {G : simple_graph V} {v : V} {B : finset V} (hG : friendship G) (hv : v ∉ B):
left_unique (path_bigraph G (neighbors G v) B) :=
begin
rw left_unique_one_reg,
unfold left_regular,
intros b hb,
have hsub : left_fiber (path_bigraph G (neighbors G v) B) b = (neighbors G v) ∩ (neighbors G b),
apply left_fiber_eq_nbrs_inter_A hb,
rw [hsub, ← friends_eq_inter_neighbors],
apply card_friends hG,
intro veqb, rw veqb at hv,
contradiction,
end
lemma runique_paths {G:simple_graph V} {v : V} {A : finset V} (hG : friendship G) (hv : v ∉ A):
right_unique (path_bigraph G A (neighbors G v)):=
begin
rw [← path_bigraph_swap, right_unique_swap],
exact lunique_paths hG hv,
end
lemma counter_non_adj_deg_eq
{G : simple_graph V} (hG : friendship G) (hG' : no_pol G)
{v w : V} (hvw : ¬ G.E v w ):
degree G v = degree G w:=
begin
by_cases v=w, { rw h },
let b:= bigraph.mk (neighbors G v) (neighbors G w) (λ (x:V), λ (y:V), G.E x y),
apply card_eq_of_lunique_runique b,
{ apply lunique_paths hG,
rw neighbor_iff_adjacent,
intro contra,
apply hvw,
apply G.undirected contra },
apply runique_paths hG,
rw neighbor_iff_adjacent,
apply hvw,
end
theorem counter_reg {G:simple_graph V} (hG : friendship G) (hG' : no_pol G) :
∃ d:ℕ, regular_graph G d :=
begin
have np:=hG',
have h2:=counter_non_adj_deg_eq hG,
have v := arbitrary V,
use degree G v,
intro x,
by_cases hvx : G.E v x,
swap, symmetry, apply counter_non_adj_deg_eq hG hG' hvx,
rcases hG' v with ⟨w, hvw', hvw⟩,
rcases hG' x with ⟨y, hxy', hxy⟩,
have degvw:=counter_non_adj_deg_eq hG hG' hvw,
have degxy:=counter_non_adj_deg_eq hG hG' hxy,
by_cases hxw : G.E x w,
swap, {rw degvw, apply counter_non_adj_deg_eq hG hG' hxw},
rw degxy,
by_cases hvy : G.E v y,
swap, {symmetry, apply counter_non_adj_deg_eq hG hG' hvy},
rw degvw,
apply counter_non_adj_deg_eq hG hG',
intro hcontra,
apply hxy',
apply exists_unique.unique (hG v w hvw'),
exact ⟨hvx, G.undirected hxw⟩,
exact ⟨hvy, G.undirected hcontra⟩,
end
variables {R : Type*} [ring R]
theorem friendship_adj_sq_off_diag_eq_one
(G:simple_graph V) (hG : friendship G) {v w : V} (hvw : v ≠ w) :
((adjacency_matrix R G)^2) v w = 1 :=
begin
rw [pow_two, adjacency_matrix_mul_apply, ← nat.cast_one, ← card_friends hG hvw, friends_eq_inter_neighbors],
unfold neighbors, simp [finset.inter_filter],
end
def two_path_from_v (G:simple_graph V) (v:V):(V × V → Prop):=
λ x:V × V, G.E v x.fst ∧ G.E x.fst x.snd
lemma friendship_reg_card_count_1
{G:simple_graph V} (hG : friendship G) (v:V) :
card_edges (path_bigraph G (neighbors G v) (finset.erase finset.univ v))=(finset.erase finset.univ v).card:=
begin
apply card_edges_of_lunique,
apply lunique_paths hG,
apply finset.not_mem_erase,
end
lemma friendship_reg_card_count_2
{G:simple_graph V} {d:ℕ} (hd : regular_graph G d) (v:V) :
card_edges (path_bigraph G (neighbors G v) {v}) = d :=
begin
unfold regular_graph at hd,
rw ← hd v,
apply card_edges_of_runique,
rw right_unique_one_reg,
unfold right_regular,
intros a ha,
change a ∈ neighbors G v at ha,
rw right_fiber_eq_nbrs_inter_B ha,
have h:neighbors G a∩ {v} = {v},
{ apply finset.inter_singleton_of_mem,
rw neighbor_iff_adjacent,
rw neighbor_iff_adjacent at ha,
exact G.undirected ha },
rw [finset.inter_comm, h], simp,
end
lemma reg_card_count_3
{G:simple_graph V} {d:ℕ} (hd : regular_graph G d) (v:V) :
card_edges (path_bigraph G (neighbors G v) finset.univ) = d * d :=
begin
unfold regular_graph at hd,
unfold degree at hd,
transitivity d * (neighbors G v).card,
swap, { rw hd v },
apply card_edges_of_rreg,
intros a ha,
rw right_fiber_eq_nbrs_inter_B,
{ rw [finset.univ_inter, hd a] },
{ exact ha },
end
lemma finset.erase_disj_sing {α:Type*}{s:finset α}{a:α}:
disjoint (s.erase a) {a}:=
begin
rw finset.disjoint_singleton,
apply finset.not_mem_erase,
end
lemma finset.erase_union_sing {α:Type*}{s:finset α}{a:α}:
a ∈ s → s.erase a ∪ {a}=s:=
begin
intro h,
rw finset.union_comm,
rw ← finset.insert_eq,
apply finset.insert_erase h,
end
theorem friendship_reg_card
{G:simple_graph V} {d:ℕ} (hG : friendship G) (hd : regular_graph G d) :
(fintype.card V) - 1 + d = d * d :=
begin
have v:=arbitrary V,
have hv : v ∈ finset.univ,
{apply finset.mem_univ}, swap, {apply_instance},
have un:(finset.erase finset.univ v)∪ {v}=finset.univ,
{ apply finset.erase_union_sing hv},
rw ← reg_card_count_3 hd v,
rw ← un,
rw ← finset.card_univ,
rw ← nat.pred_eq_sub_one,
rw ← finset.card_erase_of_mem hv,
rw ← friendship_reg_card_count_1 hG v,
rw ← friendship_reg_card_count_2 hd v,
symmetry,
apply card_edges_add_of_eq_disj_union_eq,
apply finset.erase_disj_sing,
end
theorem friendship_reg_card'
{G : simple_graph V} {d : ℕ} (hG : friendship G) (hd : regular_graph G d) :
(fintype.card V:ℤ) = d * (↑d -1) +1:=
begin
rw mul_sub, norm_cast, rw ← friendship_reg_card hG hd,
have : 0 ≠ fintype.card V,
{ have v := arbitrary V,
unfold fintype.card,
have : v ∈ @finset.univ V _, simp,
symmetry, exact finset.card_ne_zero_of_mem this },
push_cast, ring, norm_cast, omega,
end
lemma d_dvd_card_V
{G : simple_graph V} {d : ℕ} (hG : friendship G) (hd : regular_graph G d)
{p : ℕ} (hp : p ∣ d - 1) (d_pos : 0 < d) :
(p:ℤ) ∣ fintype.card V - 1 :=
begin
rw friendship_reg_card' hG hd, ring,
cases hp with k hk,
use d * k, norm_cast, rw hk, ring,
end
lemma le_one_of_pred_zero {n:ℕ}:
n-1=0 → n ≤ 1:= by omega
local attribute [simp]
lemma nat.smul_one (d : ℕ) (R : Type*) [ring R] : d • (1 : R) = (d : R) :=
begin
induction d with k hk, simp,
rw nat.succ_eq_add_one, push_cast,
rw ← hk, rw add_smul, simp,
end
local attribute [simp]
lemma int.smul_one (d : ℤ) (R : Type*) [ring R] : d • (1 : R) = (d : R) :=
begin
apply gsmul_one,
end
variable (R)
theorem friendship_reg_adj_sq
(G:simple_graph V) (d:ℕ) (pos : 0<d) (hG : friendship G) (hd : regular_graph G d) :
(adjacency_matrix R G)^2 = matrix_J R V + (d-1:ℤ) • 1 :=
begin
ext,
by_cases i=j,
{ rw [← h, pow_two],
rw adj_mat_sq_apply_eq,
rw hd i,
unfold matrix_J,
simp only [matrix.one_val_eq, nat.smul_one, matrix.add_val, pi.smul_apply],
cases d, {norm_num at pos}, {simp, rw add_comm,} },
rw friendship_adj_sq_off_diag_eq_one G hG h,
unfold matrix_J,
simp [matrix.one_val_ne h],
end
variable {R}
lemma subsingleton_graph_has_pol (G : simple_graph V) :
fintype.card V ≤ 1 → exists_politician G:=
begin
intro subsing,
rw fintype.card_le_one_iff at subsing,
use arbitrary V, intro w,
left, apply subsing,
end
lemma deg_le_one_friendship_has_pol
{G:simple_graph V} {d:ℕ} (hG : friendship G) (hd : regular_graph G d) :
d ≤ 1 → exists_politician G :=
begin
intro d_le_one,
have sq : d * d = d := by {interval_cases d; norm_num},
have hfr := friendship_reg_card hG hd,
rw sq at hfr,
apply subsingleton_graph_has_pol,
apply le_one_of_pred_zero,
linarith,
end
lemma ne_of_edge {G : simple_graph V} {a b : V} (hab : G.E a b) : a ≠ b :=
begin
intro h, rw h at hab, apply G.loopless b, exact hab,
end
lemma deg_two_friendship_has_pol
{G:simple_graph V} {d:ℕ} (hG : friendship G) (hd : regular_graph G d) :
d = 2 → exists_politician G :=
begin
intro deq2,
rw deq2 at hd,
have v := arbitrary V,
have hfr:=friendship_reg_card hG hd,
have h2 : fintype.card V - 1 = 2 := by linarith, clear hfr,
-- now we have a degree two graph with three vertices
-- the math thing to do would be to replace it with the triangle graph
have herase : (finset.univ.erase v).card = fintype.card V - 1,
{ apply finset.card_erase_of_mem,
apply finset.mem_univ },
rw h2 at herase, clear h2,
existsi v, intro w,
by_cases hvw : v = w, { left, exact hvw }, right,
have h':neighbors G v = finset.univ.erase v,
apply finset.eq_of_subset_of_card_le,
{ rw finset.subset_iff,
intro x,
rw neighbor_iff_adjacent,
rw finset.mem_erase,
intro h,
split, { symmetry, exact ne_of_edge h },
apply finset.mem_univ },
{ rw herase,
unfold regular_graph at hd, unfold degree at hd,
rw hd },
rw [← neighbor_iff_adjacent, h', finset.mem_erase],
split, { symmetry, exact hvw },
apply finset.mem_univ
end
lemma deg_le_two_friendship_has_pol
{G:simple_graph V} {d:ℕ} (hG : friendship G) (hd : regular_graph G d) :
d ≤ 2 → exists_politician G:=
begin
intro d_le_2,
interval_cases d,
iterate 2 { apply deg_le_one_friendship_has_pol hG hd, norm_num },
{ apply deg_two_friendship_has_pol hG hd, refl },
end
--def matrix_mod (V : Type* ) [fintype V] (p:ℕ) : matrix V V ℤ →+* matrix V V (zmod p) :=
--matrix.ring_hom_apply (int.cast_ring_hom (zmod p))
--def matrix_J_mod_p (V)[fintype V](p:ℕ): matrix V V (zmod p):=
-- (matrix_mod V p) (matrix_J ℤ V)
lemma matrix_J_sq :
(matrix_J R V)^2 = (fintype.card V : R) • (matrix_J R V) :=
begin
rw pow_two,
rw matrix.mul_eq_mul, ext, rw matrix.mul_val,
unfold matrix_J,
simp; refl,
end
lemma matrix_J_mod_p_idem
{p:ℕ} [char_p R p] (hp : ↑p ∣ (fintype.card V : ℤ ) - 1) :
(matrix_J (zmod p) V) ^ 2 = matrix_J (zmod p) V :=
begin
rw matrix_J_sq,
have : (fintype.card V : zmod p) = 1, swap, simp [this], symmetry,
rw [← nat.cast_one, zmod.eq_iff_modeq_nat, ← int.modeq.coe_nat_modeq_iff, int.modeq.modeq_iff_dvd], apply hp,
end
--lemma trace_mod (p:ℕ) (M: matrix V V ℤ):
--matrix.trace V (zmod p) (zmod p) (matrix_mod V p M) = (matrix.trace V ℤ ℤ M : zmod p):=
--begin
-- rw matrix_mod,
-- rw matrix.ring_hom_apply.trace (int.cast_ring_hom (zmod p)) M,
-- refl,
--end
lemma friendship_reg_adj_sq_mod_p
{G:simple_graph V} {d:ℕ} {dpos:0<d} (hG : friendship G) (hd : regular_graph G d)
{p:ℕ} (hp : ↑p ∣ (d: ℤ ) - 1) :
(adjacency_matrix (zmod p) G)^2 = matrix_J (zmod p) V:=
begin
rw friendship_reg_adj_sq (zmod p) G d dpos hG hd,
have h : (d - 1 : ℤ) • (1 : matrix V V (zmod p)) = 0, swap, rw [h, add_zero],
rw ← char_p.int_cast_eq_zero_iff (matrix V V (zmod p)) at hp, rw ← hp,
simp [algebra.smul_def'],
end
lemma friendship_reg_adj_mul_J
{G:simple_graph V} {d:ℕ} {dpos:0<d} (hG : friendship G) (hd : regular_graph G d)
:
(adjacency_matrix R G) * (matrix_J R V) = (d : ℤ) • matrix_J R V :=
by { ext, unfold matrix_J, rw ← hd i, unfold degree, simp, }
lemma friendship_reg_adj_mul_J_mod_p
{G:simple_graph V} {d:ℕ} {dpos:0<d} (hG : friendship G) (hd : regular_graph G d)
{p:ℕ} (hp : ↑p ∣ (d: ℤ ) - 1) :
(adjacency_matrix (zmod p) G) * (matrix_J (zmod p) V) = matrix_J (zmod p) V:=
begin
ext, symmetry, simp only [adjacency_matrix_mul_apply, finset.sum_apply, mul_one, matrix_J_apply, finset.sum_const, nsmul_eq_mul],
rw [← degree, hd, ← nat.cast_one, zmod.eq_iff_modeq_nat, ← int.modeq.coe_nat_modeq_iff, int.modeq.modeq_iff_dvd], apply hp,
end
lemma friendship_reg_adj_pow_mod_p
{G:simple_graph V} {d:ℕ} {dpos:0<d} (hG : friendship G) (hd : regular_graph G d)
{p:ℕ} (hp : ↑p ∣ (d: ℤ ) - 1) {k : ℕ} (hk : 2 ≤ k):
(adjacency_matrix (zmod p) G) ^ k = matrix_J (zmod p) V :=
begin
iterate 2 {cases k with k, { exfalso, linarith,},},
induction k with k hind,
{ apply friendship_reg_adj_sq_mod_p hG hd hp,
exact dpos},
{ rw pow_succ,
have h2 : 2 ≤ k.succ.succ := by omega,
have hind2 := hind h2,
rw hind2,
apply friendship_reg_adj_mul_J_mod_p hG hd hp,
exact dpos }
end
lemma tr_pow_p_mod_p {p:ℕ} [fact p.prime] (M : matrix V V (zmod p)) :
matrix.trace V (zmod p) (zmod p) (M ^ p) = (matrix.trace V (zmod p) (zmod p) M)^p :=
by rw [trace_from_char_poly, trace_from_char_poly, char_poly_pow_p_char_p, frobenius_fixed]
lemma three_le_deg_friendship_contra
{G:simple_graph V} {d:ℕ} (hG : friendship G) (hd : regular_graph G d) :
3 ≤ d → false :=
begin
intro h,
have dpos : 0<d := by linarith,
let p:ℕ:=(d-1).min_fac,
have hadj:=friendship_reg_adj_sq (zmod p) G d dpos hG,
have traceless:=adj_mat_traceless (zmod p) G,
have cardV:=friendship_reg_card' hG hd,
have p_dvd_d_pred:p ∣ d-1:=(d-1).min_fac_dvd,
have d_cast : coe (d - 1) = (d : ℤ) - 1 := by norm_cast,
have p_dvd_V_pred:↑p ∣ ((fintype.card V:ℤ)-1),
{ transitivity ↑(d-1), {rwa int.coe_nat_dvd},
use d, rw [d_cast, cardV], ring },
have neq1 : d-1 ≠ 1 := by linarith,
have pprime : p.prime := nat.min_fac_prime neq1,
haveI : fact p.prime := pprime,
have trace_0:= tr_pow_p_mod_p (adjacency_matrix (zmod p) G),
have eq_J : (adjacency_matrix (zmod p) G) ^ p = (matrix_J (zmod p) V),
{ apply friendship_reg_adj_pow_mod_p hG hd,
{ rw [← d_cast, int.coe_nat_dvd],
apply p_dvd_d_pred },
{ apply nat.prime.two_le pprime },
assumption },
contrapose! trace_0, clear trace_0,
rw eq_J,
rw trace_J (zmod p) V,
norm_num,
have p_pos : 0 < p,
linarith [nat.prime.two_le pprime],
rw zero_pow p_pos,
suffices key : ↑(fintype.card V) = (1 : zmod p),
{ rw key, simp },
cases p_dvd_V_pred with k hk,
lift k to ℕ,
{ rw sub_eq_iff_eq_add at hk, norm_cast at hk, rw hk, simp },
have p_pos' : (0 : ℤ) < p := by exact_mod_cast p_pos,
apply nonneg_of_mul_nonneg_left _ p_pos',
rw [← hk, cardV, add_sub_cancel], norm_cast,
simp,
end
theorem friendship_theorem {G:simple_graph V} (hG : friendship G):
exists_politician G:=
begin
rw ← exists_pol_of_not_no_pol,
intro npG,
have regG : ∃ (d:ℕ), regular_graph G d,
{ apply counter_reg; assumption },
cases regG with d dreg,
have : d ≤ 2 ∨ 3 ≤ d := by omega, cases this,
{ have ex_pol : exists_politician G,
apply deg_le_two_friendship_has_pol hG dreg,
linarith,
apply exists_pol_of_not_no_pol.2 ex_pol npG },
apply three_le_deg_friendship_contra hG dreg, assumption,
end |
001470b9c5876f739d55a627c6352690c804e5e4 | b82c5bb4c3b618c23ba67764bc3e93f4999a1a39 | /src/formal_ml/real.lean | 970d48ff10029e9523c0287d7ff7130ebe98e037 | [
"Apache-2.0"
] | permissive | nouretienne/formal-ml | 83c4261016955bf9bcb55bd32b4f2621b44163e0 | 40b6da3b6e875f47412d50c7cd97936cb5091a2b | refs/heads/master | 1,671,216,448,724 | 1,600,472,285,000 | 1,600,472,285,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,669 | lean | /-
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import order.filter.basic
import data.real.basic
import topology.basic
import topology.instances.real
import data.complex.exponential
import topology.algebra.infinite_sum
import data.nat.basic
import analysis.specific_limits
import analysis.calculus.deriv
import analysis.asymptotics
import formal_ml.nat
import formal_ml.core
lemma abs_eq_norm {a:ℝ}:abs a = ∥a∥ := rfl
---Results about the reals--------------------------------------------------------------------------
lemma nat_succ_pow {n:ℕ} {x:ℝ}:x^(nat.succ n)=x*(x^n) :=
begin
refl,
end
lemma pow_distrib (x y:ℝ) (n:ℕ):(x * y)^n = x^n * y^n :=
begin
induction n,
{
simp,
},
{
rw nat_succ_pow,
rw nat_succ_pow,
rw nat_succ_pow,
rw n_ih,
rw mul_assoc x (x ^ n_n),
rw ← mul_assoc (x ^ n_n),
rw mul_comm (x ^ n_n) y,
rw mul_assoc x y,
rw ← mul_assoc y (x ^ n_n),
}
end
lemma inv_pow_comm {x:ℝ} {n:ℕ}:(x⁻¹)^n = ((x)^n )⁻¹ :=
begin
simp,
end
lemma inv_pow_cancel (x:ℝ) (n:ℕ):(x≠ 0) → (x)^n * (x⁻¹)^n = 1 :=
begin
intro A1,
rw ← pow_distrib,
rw mul_inv_cancel,
simp,
apply A1,
end
lemma inv_pow_cancel2 (x:ℝ) (n:ℕ):(x≠ 0) → (x⁻¹)^n * (x)^n = 1 :=
begin
rw mul_comm,
apply inv_pow_cancel,
end
lemma pow_zero_eq_zero_if_pos {n:ℕ}:(0 < n) →
(0:ℝ)^n = 0 :=
begin
intro A1,
cases n,
{
exfalso,
apply lt_irrefl 0 A1,
},
{
rw nat_succ_pow,
simp
}
end
lemma abs_pow {x:ℝ} {n:ℕ}:(abs (x^n)) = (abs x)^n :=
begin
induction n,
{
simp,
},
{
rw nat_succ_pow,
rw nat_succ_pow,
rw abs_mul,
rw n_ih,
}
end
lemma real_nat_abs_coe {n:ℕ}:abs (n:ℝ)= (n:ℝ) :=
begin
have A1:abs (n:ℝ) =((abs n):ℝ) := rfl,
rw A1,
simp,
end
lemma abs_pos_of_nonzero {x:ℝ}:x ≠ 0 → 0 < abs x :=
begin
intro A1,
have A2:x < 0 ∨ x = 0 ∨ 0 < x := lt_trichotomy x 0,
cases A2,
{
apply abs_pos_of_neg A2,
},
cases A2,
{
exfalso,
apply A1,
apply A2,
},
{
apply abs_pos_of_pos A2,
}
end
lemma pow_two_pos (n:ℕ):0 < (2:ℝ)^n :=
begin
apply pow_pos,
apply zero_lt_two,
end
lemma pow_nonneg_of_nonneg {x:ℝ} {k:ℕ}:0 ≤ x → 0 ≤ x^k :=
begin
intro A1,
induction k,
{
simp,
apply le_of_lt,
apply zero_lt_one,
},
{
rw nat_succ_pow,
apply mul_nonneg,
apply A1,
apply k_ih,
}
end
lemma real_pow_mono {x y:real} {k:ℕ}:
0 ≤ x →
x ≤ y → x^k ≤ y^k :=
begin
intros A0 A1,
induction k,
{
simp,
},
{
rw nat_succ_pow,
rw nat_succ_pow,
apply mul_le_mul,
{
exact A1,
},
{
apply k_ih,
},
{
simp,
apply pow_nonneg_of_nonneg,
apply A0,
},
{
simp,
apply le_trans,
apply A0,
apply A1,
},
}
end
lemma div_inv (x:ℝ):1/x = x⁻¹ :=
begin
simp,
end
lemma inv_exp (n:ℕ):((2:ℝ)^n)⁻¹ = ((2:ℝ)⁻¹)^n :=
begin
induction n,
{
simp,
},
{
have A1:nat.succ n_n = 1 + n_n,
{
apply nat_succ_one_add,
},
rw A1,
rw pow_add,
rw pow_add,
simp,
rw mul_inv',
}
end
lemma abs_mul_eq_mul_abs (a b:ℝ):(0 ≤ a) → abs (a * b) = a * abs (b) :=
begin
intro A1,
rw abs_mul,
rw abs_of_nonneg,
apply A1,
end
lemma pos_of_pos_of_mul_pos {a b:ℝ}:(0 ≤ a) → (0 < a * b) → 0 < b :=
begin
intros A1 A2,
have A3:0 < b ∨ (b ≤ 0),
{
apply lt_or_ge,
},
cases A3,
{
apply A3,
},
{
exfalso,
have A3A:(a * b)≤ 0,
{
apply mul_nonpos_of_nonneg_of_nonpos,
apply A1,
apply A3,
},
apply not_lt_of_le A3A,
apply A2,
}
end
lemma inv_pos_of_pos {a:ℝ}:(0 < a) → 0 < (a⁻¹) :=
begin
intro A1,
apply pos_of_pos_of_mul_pos,
apply le_of_lt,
apply A1,
rw mul_inv_cancel,
apply zero_lt_one,
intro A2,
rw A2 at A1,
apply lt_irrefl _ A1,
end
lemma inv_lt_one_of_one_lt {a:ℝ}:(1 < a) → (a⁻¹)< 1 :=
begin
intro A1,
have A2:0 < a,
{
apply lt_trans,
apply zero_lt_one,
apply A1,
},
have A3:0 < a⁻¹,
{
apply inv_pos_of_pos A2,
},
have A4:a⁻¹ * 1 < a⁻¹ * a,
{
apply mul_lt_mul_of_pos_left,
apply A1,
apply A3,
},
rw inv_mul_cancel at A4,
rw mul_one at A4,
apply A4,
{
intro A5,
rw A5 at A2,
apply lt_irrefl _ A2,
}
end
lemma div_def {a b:ℝ}:a/b = a * b⁻¹ := rfl
lemma div_lt_div_of_lt_of_lt {a b c:ℝ}:(0<c) → (a < b) → (a/c < b/c) :=
begin
intros A1 A2,
rw div_def,
rw div_def,
apply mul_lt_mul_of_pos_right,
apply A2,
apply inv_pos_of_pos,
apply A1,
end
--Remove
lemma zero_lt_epsilon_half_of_zero_lt_epsilon {ε:ℝ}: 0 < ε → 0 < (ε / 2) :=
begin
apply half_pos,
end
lemma epsilon_half_lt_epsilon {ε:ℝ}: 0 < ε → (ε / 2) < ε :=
begin
intro A1,
have A2:0 < ε/2 := zero_lt_epsilon_half_of_zero_lt_epsilon A1,
have A3: ε/2 + 0 < ε/2 + ε/2,
{
apply add_lt_add_left,
apply A2,
},
simp at A3,
apply A3,
end
lemma inv_nonneg_of_nonneg {a:ℝ}:(0 ≤ a) → (0 ≤ a⁻¹) :=
begin
intro A1,
have A2:0 < a ∨ 0 = a := lt_or_eq_of_le A1,
cases A2,
{
apply le_of_lt,
apply inv_pos_of_pos,
apply A2,
},
cases A2,
{
rw ← A2,
simp,
},
end
lemma move_le {a b c:ℝ}:(0 < c) → (a ≤ b * c) → (a * c⁻¹) ≤ b :=
begin
intros A1 A2,
have A3:0 < c⁻¹ := inv_pos_of_pos A1,
have A4:(a * c⁻¹) ≤ (b * c) * (c⁻¹),
{
apply mul_le_mul_of_nonneg_right,
apply A2,
apply le_of_lt,
apply A3,
},
have A5:b * c * c⁻¹ = b,
{
rw mul_assoc,
rw mul_inv_cancel,
rw mul_one,
symmetry,
apply ne_of_lt,
apply A1,
},
rw A5 at A4,
apply A4,
end
lemma move_le2 {a b c:ℝ}:(0 < c) → (a * c⁻¹) ≤ b → (a ≤ b * c) :=
begin
intros A1 A2,
have A4:(a * c⁻¹) * c ≤ (b * c),
{
apply mul_le_mul_of_nonneg_right,
apply A2,
apply le_of_lt,
apply A1,
},
have A5:a * c⁻¹ * c = a,
{
rw mul_assoc,
rw inv_mul_cancel,
rw mul_one,
symmetry,
apply ne_of_lt,
apply A1,
},
rw A5 at A4,
apply A4,
end
--Probably a repeat.
lemma inv_decreasing {x y:ℝ}:(0 < x) → (x < y)→ (y⁻¹ < x⁻¹) :=
begin
intros A1 A2,
have A3:0< y,
{
apply lt_trans,
apply A1,
apply A2,
},
have A4:0 < x * y,
{
apply mul_pos;assumption,
},
have A5:x⁻¹ * x < x⁻¹ * y,
{
apply mul_lt_mul_of_pos_left,
apply A2,
apply inv_pos_of_pos,
apply A1,
},
rw inv_mul_cancel at A5,
have A6:1 * y⁻¹ < x⁻¹ * y * y⁻¹,
{
apply mul_lt_mul_of_pos_right,
apply A5,
apply inv_pos_of_pos,
apply A3,
},
rw one_mul at A6,
rw mul_assoc at A6,
rw mul_inv_cancel at A6,
rw mul_one at A6,
apply A6,
{
intro A7,
rw A7 at A3,
apply lt_irrefl 0 A3,
},
{
intro A7,
rw A7 at A1,
apply lt_irrefl 0 A1,
}
end
lemma abs_nonzero_pos {x:ℝ}:(x ≠ 0) → (0 < abs (x)) :=
begin
intro A1,
have A2:(x < 0 ∨ x = 0 ∨ 0 < x) := lt_trichotomy x 0,
cases A2,
{
apply abs_pos_of_neg,
apply A2,
},
cases A2,
{
exfalso,
apply A1,
apply A2,
},
{
apply abs_pos_of_pos,
apply A2,
},
end
lemma diff_ne_zero_of_ne {x x':ℝ}:(x ≠ x') → (x - x' ≠ 0) :=
begin
intro A1,
intro A2,
apply A1,
have A1:x - x' + x' = 0 + x',
{
rw A2,
},
simp at A1,
apply A1,
end
lemma abs_diff_pos {x x':ℝ}:(x ≠ x') → (0 < abs (x - x')) :=
begin
intro A1,
apply abs_nonzero_pos,
apply diff_ne_zero_of_ne A1,
end
lemma neg_inv_of_neg {x:ℝ}:x < 0 → (x⁻¹ < 0) :=
begin
intro A1,
have A2:x⁻¹ < 0 ∨ (0 ≤ x⁻¹) := lt_or_le x⁻¹ 0,
cases A2,
{
apply A2,
},
{
exfalso,
have A3:(x * x⁻¹ ≤ 0),
{
apply mul_nonpos_of_nonpos_of_nonneg,
apply le_of_lt,
apply A1,
apply A2,
},
rw mul_inv_cancel at A3,
apply not_lt_of_le A3,
apply zero_lt_one,
intro A4,
rw A4 at A1,
apply lt_irrefl (0:ℝ),
apply A1,
}
end
lemma zero_exp_zero {n:ℕ}:(0 < n) → (0:ℝ)^n = (0:ℝ) :=
begin
cases n,
{
simp,
},
{
intro A1,
rw nat_succ_pow,
simp,
}
end
lemma sub_inv {a b:ℝ}:a - (a - b) = b :=
begin
rw sub_eq_add_neg,
rw neg_sub,
rw sub_eq_add_neg,
rw add_comm b (-a),
rw ← add_assoc,
rw add_right_neg,
rw zero_add,
end
lemma x_in_Ioo {x r:ℝ}:(0 < r) → (x∈ set.Ioo (x- r) (x + r)) :=
begin
intro A1,
simp,
split,
{
apply lt_of_sub_pos,
rw sub_inv,
apply A1,
},
{
apply A1,
}
end
lemma abs_lt2 {x x' r:ℝ}:
(abs (x' - x) < r) ↔ ((x - r < x') ∧ (x' < x + r)) :=
begin
rw abs_lt,
split;intros A1;cases A1 with A2 A3;split,
{
apply add_lt_of_lt_sub_left A2,
},
{
apply lt_add_of_sub_left_lt A3,
},
{
apply lt_sub_left_of_add_lt A2,
},
{
apply sub_left_lt_of_lt_add A3,
}
end
lemma abs_lt_iff_in_Ioo {x x' r:ℝ}:
(abs (x' - x) < r) ↔ x' ∈ set.Ioo (x - r) (x + r) :=
begin
apply iff.trans,
apply abs_lt2,
simp,
end
lemma neg_lt_of_pos {x:ℝ}:(0 < x) → (-x < 0) :=
begin
apply neg_neg_of_pos,
end
lemma abs_lt_iff_in_Ioo2 {x x' r:ℝ}:
(abs (x - x') < r) ↔ x' ∈ set.Ioo (x - r) (x + r) :=
begin
have A1:abs (x - x')=abs (x' - x),
{
have A1A:x' - x = -(x - x'),
{
simp,
},
rw A1A,
rw abs_neg,
},
rw A1,
apply abs_lt_iff_in_Ioo,
end
lemma real_lt_coe {a b:ℕ}:a < b → (a:ℝ) < (b:ℝ) :=
begin
simp,
end
lemma add_of_sub {a b c:ℝ}:a - b = c ↔ a = b + c :=
begin
split;intros A1,
{
rw ← A1,
simp,
},
{
rw A1,
simp,
}
end
lemma sub_half_eq_half {a:ℝ}:(a - a * 2⁻¹)=a * 2⁻¹ :=
begin
rw add_of_sub,
rw ← div_def,
simp,
end
lemma half_pos2:0 < (2:ℝ)⁻¹ :=
begin
apply inv_pos_of_pos,
apply zero_lt_two,
end
/- The halfway point is in the middle. -/
lemma half_bound_lower {a b:ℝ}:a < b → a < (a + b)/2 :=
begin
intro A1,
rw div_def,
rw right_distrib,
apply lt_add_of_sub_left_lt,
have A2:(a - a * 2⁻¹)=a * 2⁻¹ := sub_half_eq_half,
rw A2,
apply mul_lt_mul_of_pos_right,
apply A1,
apply half_pos2,
end
lemma half_bound_upper {a b:ℝ}:a < b → (a + b)/2 < b :=
begin
intro A1,
rw div_def,
rw right_distrib,
apply add_lt_of_lt_sub_right,
have A2:(b - b * 2⁻¹)=b * 2⁻¹ := sub_half_eq_half,
rw A2,
apply mul_lt_mul_of_pos_right,
apply A1,
apply half_pos2,
end
lemma lt_of_sub_lt_sub {a b c:ℝ}:a - c < b - c → a < b :=
begin
intro A1,
have A2:(a - c) + c < (b - c) + c ,
{
apply add_lt_add_right,
apply A1,
},
simp at A2,
apply A2,
end
lemma abs_antisymm {a b:ℝ}:abs (a - b) = abs (b - a) :=
begin
have A1:-(a-b)=(b - a),
{
simp,
},
rw ← A1,
rw abs_neg,
end
lemma add_sub_triangle {a b c:ℝ}:(a - b) = (a - c) + (c - b) :=
begin
rw ← add_sub_assoc,
rw sub_add_cancel,
end
lemma abs_triangle {a b c:ℝ}:abs (a - b) ≤ abs (a - c) + abs (c - b) :=
begin
have A1:(a - b) = (a - c) + (c - b) := add_sub_triangle,
rw A1,
apply abs_add_le_abs_add_abs,
end
lemma pow_complex {x:ℝ} {n:ℕ}:((x:ℂ)^n).re=(x^n) :=
begin
induction n,
{
simp,
},
{
rw pow_succ,
rw pow_succ,
simp,
rw n_ih,
}
end
lemma div_complex {x y:ℝ}:((x:ℂ)/(y:ℂ)).re=x/y :=
begin
rw complex.div_re,
simp,
have A1:y=0 ∨ y≠ 0 := eq_or_ne,
cases A1,
{
rw A1,
simp,
},
{
rw mul_div_mul_right,
apply A1,
}
end
lemma complex_norm_sq_nat {y:ℕ}:complex.norm_sq (y:ℂ) = ((y:ℝ) * (y:ℝ)) :=
begin
unfold complex.norm_sq,
simp,
end
lemma num_denom_eq (a b c d:ℝ): (a = b) → (c = d) → (a/c)=(b/d) :=
begin
intros A1 A2,
rw A1,
rw A2,
end
lemma complex_pow_div_complex_re {x:ℝ} {n:ℕ} {y:ℕ}:(((x:ℂ)^n)/(y:ℂ)).re=x^n/(y:ℝ) :=
begin
rw complex.div_re,
simp,
have A1:(y:ℝ)=0 ∨ (y:ℝ) ≠ 0 := eq_or_ne,
cases A1,
{
rw A1,
simp,
},
{
rw complex_norm_sq_nat,
rw mul_div_mul_right,
apply num_denom_eq,
{
rw pow_complex,
},
{
refl,
},
apply A1,
}
end
lemma half_lt_one:(2:ℝ)⁻¹ < 1 :=
begin
have A1:1/(2:ℝ) < 1 := epsilon_half_lt_epsilon zero_lt_one,
rw div_def at A1,
rw one_mul at A1,
apply A1,
end
lemma half_pos_lit:0 < (2:ℝ)⁻¹ :=
begin
apply inv_pos_of_pos,
apply zero_lt_two,
end
/-
lemma div_re_eq_re_div_re (x y:ℂ):(x / y).re = (x.re)/(y.re) :=
begin
simp,
end
-/
--It is a common pattern that we calculate the distance to the middle,
--and then show that if you add or subtract it, you get to that middle.
lemma half_equal {x y ε:ℝ}:ε = (x - y)/2 → x - ε = y + ε :=
begin
intro A1,
have A2:(x - ε) + (ε - y) = (y + ε) + (ε - y),
{
rw ← add_sub_triangle,
rw ← add_sub_assoc,
rw add_comm (y+ε),
rw add_comm y ε,
rw ← add_assoc,
rw add_sub_assoc,
rw sub_self,
rw add_zero,
rw A1,
simp,
},
apply add_right_cancel A2,
end
|
356872bd0a219c60ae9db153981f466f6271bfde | 4b846d8dabdc64e7ea03552bad8f7fa74763fc67 | /tests/lean/def_inaccessible_issue.lean | 1671a7a870789404cff6eda7143f3eae0dd923e4 | [
"Apache-2.0"
] | permissive | pacchiano/lean | 9324b33f3ac3b5c5647285160f9f6ea8d0d767dc | fdadada3a970377a6df8afcd629a6f2eab6e84e8 | refs/heads/master | 1,611,357,380,399 | 1,489,870,101,000 | 1,489,870,101,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 384 | lean | open nat
set_option pp.binder_types true
inductive bv : nat → Type
| nil : bv 0
| cons : ∀ (n) (hd : bool) (tl : bv n), bv (n+1)
open bv
variable (f : bool → bool → bool)
definition map2 : ∀ {n}, bv n → bv n → bv n
| 0 nil nil := nil
| (n+1) (cons .n b1 v1) (cons .n b2 v2) := cons n (f b1 b2) (map2 v1 v2)
#check map2.equations._eqn_2
|
74a6dea2ff6348b55a037b78840dda6f6fec294d | b3fced0f3ff82d577384fe81653e47df68bb2fa1 | /src/measure_theory/integration.lean | af52b10fc5d973a60a15cad8c2f476bc8adebdfb | [
"Apache-2.0"
] | permissive | ratmice/mathlib | 93b251ef5df08b6fd55074650ff47fdcc41a4c75 | 3a948a6a4cd5968d60e15ed914b1ad2f4423af8d | refs/heads/master | 1,599,240,104,318 | 1,572,981,183,000 | 1,572,981,183,000 | 219,830,178 | 0 | 0 | Apache-2.0 | 1,572,980,897,000 | 1,572,980,896,000 | null | UTF-8 | Lean | false | false | 46,329 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
Lebesgue integral on `ennreal`.
We define simple functions and show that each Borel measurable function on `ennreal` can be
approximated by a sequence of simple functions.
-/
import
algebra.pi_instances
measure_theory.measure_space
measure_theory.borel_space
noncomputable theory
open lattice set filter
open_locale classical
section sequence_of_directed
variables {α : Type*} {β : Type*} [encodable α] [inhabited α]
open encodable
noncomputable def sequence_of_directed (r : β → β → Prop) (f : α → β) (hf : directed r f) : ℕ → α
| 0 := default α
| (n + 1) :=
let p := sequence_of_directed n in
match decode α n with
| none := p
| (some a) := classical.some (hf p a)
end
lemma monotone_sequence_of_directed [partial_order β] (f : α → β) (hf : directed (≤) f) :
monotone (f ∘ sequence_of_directed (≤) f hf) :=
monotone_of_monotone_nat $ assume n,
begin
dsimp [sequence_of_directed],
generalize eq : sequence_of_directed (≤) f hf n = p,
cases h : decode α n with a,
{ refl },
{ exact (classical.some_spec (hf p a)).1 }
end
lemma le_sequence_of_directed [partial_order β] (f : α → β) (hf : directed (≤) f) (a : α) :
f a ≤ f (sequence_of_directed (≤) f hf (encode a + 1)) :=
begin
simp [sequence_of_directed, -add_comm, encodek],
exact (classical.some_spec (hf _ a)).2
end
end sequence_of_directed
namespace measure_theory
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
structure {u v} simple_func (α : Type u) [measurable_space α] (β : Type v) :=
(to_fun : α → β)
(measurable_sn : ∀ x, is_measurable (to_fun ⁻¹' {x}))
(finite : (set.range to_fun).finite)
local infixr ` →ₛ `:25 := simple_func
namespace simple_func
section measurable
variables [measurable_space α]
instance has_coe_to_fun : has_coe_to_fun (α →ₛ β) := ⟨_, to_fun⟩
@[extensionality] theorem ext {f g : α →ₛ β} (H : ∀ a, f a = g a) : f = g :=
by cases f; cases g; congr; exact funext H
protected def range (f : α →ₛ β) := f.finite.to_finset
@[simp] theorem mem_range {f : α →ₛ β} {b} : b ∈ f.range ↔ ∃ a, f a = b :=
finite.mem_to_finset
def const (α) {β} [measurable_space α] (b : β) : α →ₛ β :=
⟨λ a, b, λ x, is_measurable.const _,
finite_subset (set.finite_singleton b) $ by rintro _ ⟨a, rfl⟩; simp⟩
@[simp] theorem const_apply (a : α) (b : β) : (const α b) a = b := rfl
lemma range_const (α) [measurable_space α] [ne : nonempty α] (b : β) :
(const α b).range = {b} :=
begin
ext b',
simp [mem_range],
exact ⟨assume ⟨_, h⟩, h.symm, assume h, ne.elim $ λa, ⟨a, h.symm⟩⟩
end
lemma is_measurable_cut (p : α → β → Prop) (f : α →ₛ β)
(h : ∀b, is_measurable {a | p a b}) : is_measurable {a | p a (f a)} :=
begin
rw (_ : {a | p a (f a)} = ⋃ b ∈ set.range f, {a | p a b} ∩ f ⁻¹' {b}),
{ exact is_measurable.bUnion (countable_finite f.finite)
(λ b _, is_measurable.inter (h b) (f.measurable_sn _)) },
ext a, simp,
exact ⟨λ h, ⟨_, ⟨a, rfl⟩, h, rfl⟩, λ ⟨_, ⟨a', rfl⟩, h', e⟩, e.symm ▸ h'⟩
end
theorem preimage_measurable (f : α →ₛ β) (s) : is_measurable (f ⁻¹' s) :=
is_measurable_cut (λ _ b, b ∈ s) f (λ b, by simp [is_measurable.const])
theorem measurable [measurable_space β] (f : α →ₛ β) : measurable f :=
λ s _, preimage_measurable f s
def ite {s : set α} (hs : is_measurable s) (f g : α →ₛ β) : α →ₛ β :=
⟨λ a, if a ∈ s then f a else g a,
λ x, by letI : measurable_space β := ⊤; exact
measurable.if hs f.measurable g.measurable _ trivial,
finite_subset (finite_union f.finite g.finite) begin
rintro _ ⟨a, rfl⟩,
by_cases a ∈ s; simp [h],
exacts [or.inl ⟨_, rfl⟩, or.inr ⟨_, rfl⟩]
end⟩
@[simp] theorem ite_apply {s : set α} (hs : is_measurable s)
(f g : α →ₛ β) (a) : ite hs f g a = if a ∈ s then f a else g a := rfl
def bind (f : α →ₛ β) (g : β → α →ₛ γ) : α →ₛ γ :=
⟨λa, g (f a) a,
λ c, is_measurable_cut (λa b, g b a ∈ ({c} : set γ)) f (λ b, (g b).measurable_sn c),
finite_subset (finite_bUnion f.finite (λ b, (g b).finite)) $
by rintro _ ⟨a, rfl⟩; simp; exact ⟨_, ⟨a, rfl⟩, _, rfl⟩⟩
@[simp] theorem bind_apply (f : α →ₛ β) (g : β → α →ₛ γ) (a) :
f.bind g a = g (f a) a := rfl
def restrict [has_zero β] (f : α →ₛ β) (s : set α) : α →ₛ β :=
if hs : is_measurable s then ite hs f (const α 0) else const α 0
@[simp] theorem restrict_apply [has_zero β]
(f : α →ₛ β) {s : set α} (hs : is_measurable s) (a) :
restrict f s a = if a ∈ s then f a else 0 :=
by unfold_coes; simp [restrict, hs]; apply ite_apply hs
theorem restrict_preimage [has_zero β]
(f : α →ₛ β) {s : set α} (hs : is_measurable s)
{t : set β} (ht : (0:β) ∉ t) : restrict f s ⁻¹' t = s ∩ f ⁻¹' t :=
by ext a; dsimp [preimage]; rw [restrict_apply]; by_cases a ∈ s; simp [h, hs, ht]
def map (g : β → γ) (f : α →ₛ β) : α →ₛ γ := bind f (const α ∘ g)
@[simp] theorem map_apply (g : β → γ) (f : α →ₛ β) (a) : f.map g a = g (f a) := rfl
theorem map_map (g : β → γ) (h: γ → δ) (f : α →ₛ β) : (f.map g).map h = f.map (h ∘ g) := rfl
theorem coe_map (g : β → γ) (f : α →ₛ β) : (f.map g : α → γ) = g ∘ f := rfl
@[simp] theorem range_map [decidable_eq γ] (g : β → γ) (f : α →ₛ β) :
(f.map g).range = f.range.image g :=
begin
ext c,
simp [mem_range],
split,
{ rintros ⟨a, rfl⟩, exact ⟨f a, ⟨_, rfl⟩, rfl⟩ },
{ rintros ⟨_, ⟨a, rfl⟩, rfl⟩, exact ⟨_, rfl⟩ }
end
def seq (f : α →ₛ (β → γ)) (g : α →ₛ β) : α →ₛ γ := f.bind (λf, g.map f)
def pair (f : α →ₛ β) (g : α →ₛ γ) : α →ₛ (β × γ) := (f.map prod.mk).seq g
@[simp] lemma pair_apply (f : α →ₛ β) (g : α →ₛ γ) (a) : pair f g a = (f a, g a) := rfl
theorem bind_const (f : α →ₛ β) : f.bind (const α) = f := by ext; simp
instance [has_zero β] : has_zero (α →ₛ β) := ⟨const α 0⟩
instance [has_add β] : has_add (α →ₛ β) := ⟨λf g, (f.map (+)).seq g⟩
instance [has_mul β] : has_mul (α →ₛ β) := ⟨λf g, (f.map (*)).seq g⟩
instance [has_sup β] : has_sup (α →ₛ β) := ⟨λf g, (f.map (⊔)).seq g⟩
instance [has_inf β] : has_inf (α →ₛ β) := ⟨λf g, (f.map (⊓)).seq g⟩
instance [has_le β] : has_le (α →ₛ β) := ⟨λf g, ∀a, f a ≤ g a⟩
@[simp] lemma sup_apply [has_sup β] (f g : α →ₛ β) (a : α) : (f ⊔ g) a = f a ⊔ g a := rfl
@[simp] lemma mul_apply [has_mul β] (f g : α →ₛ β) (a : α) : (f * g) a = f a * g a := rfl
lemma add_apply [has_add β] (f g : α →ₛ β) (a : α) : (f + g) a = f a + g a := rfl
lemma add_eq_map₂ [has_add β] (f g : α →ₛ β) : f + g = (pair f g).map (λp:β×β, p.1 + p.2) :=
rfl
lemma sup_eq_map₂ [has_sup β] (f g : α →ₛ β) : f ⊔ g = (pair f g).map (λp:β×β, p.1 ⊔ p.2) :=
rfl
lemma const_mul_eq_map [has_mul β] (f : α →ₛ β) (b : β) : const α b * f = f.map (λa, b * a) := rfl
instance [add_monoid β] : add_monoid (α →ₛ β) :=
{ add := (+), zero := 0,
add_assoc := assume f g h, ext (assume a, add_assoc _ _ _),
zero_add := assume f, ext (assume a, zero_add _),
add_zero := assume f, ext (assume a, add_zero _) }
instance [semiring β] [add_monoid β] : has_scalar β (α →ₛ β) := ⟨λb f, f.map (λa, b * a)⟩
instance [preorder β] : preorder (α →ₛ β) :=
{ le_refl := λf a, le_refl _,
le_trans := λf g h hfg hgh a, le_trans (hfg _) (hgh a),
.. simple_func.has_le }
instance [partial_order β] : partial_order (α →ₛ β) :=
{ le_antisymm := assume f g hfg hgf, ext $ assume a, le_antisymm (hfg a) (hgf a),
.. simple_func.preorder }
instance [order_bot β] : order_bot (α →ₛ β) :=
{ bot := const α ⊥, bot_le := λf a, bot_le, .. simple_func.partial_order }
instance [order_top β] : order_top (α →ₛ β) :=
{ top := const α⊤, le_top := λf a, le_top, .. simple_func.partial_order }
instance [semilattice_inf β] : semilattice_inf (α →ₛ β) :=
{ inf := (⊓),
inf_le_left := assume f g a, inf_le_left,
inf_le_right := assume f g a, inf_le_right,
le_inf := assume f g h hfh hgh a, le_inf (hfh a) (hgh a),
.. simple_func.partial_order }
instance [semilattice_sup β] : semilattice_sup (α →ₛ β) :=
{ sup := (⊔),
le_sup_left := assume f g a, le_sup_left,
le_sup_right := assume f g a, le_sup_right,
sup_le := assume f g h hfh hgh a, sup_le (hfh a) (hgh a),
.. simple_func.partial_order }
instance [semilattice_sup_bot β] : semilattice_sup_bot (α →ₛ β) :=
{ .. simple_func.lattice.semilattice_sup,.. simple_func.lattice.order_bot }
instance [lattice β] : lattice (α →ₛ β) :=
{ .. simple_func.lattice.semilattice_sup,.. simple_func.lattice.semilattice_inf }
instance [bounded_lattice β] : bounded_lattice (α →ₛ β) :=
{ .. simple_func.lattice.lattice, .. simple_func.lattice.order_bot, .. simple_func.lattice.order_top }
lemma finset_sup_apply [semilattice_sup_bot β] {f : γ → α →ₛ β} (s : finset γ) (a : α) :
s.sup f a = s.sup (λc, f c a) :=
begin
refine finset.induction_on s rfl _,
assume a s hs ih,
rw [finset.sup_insert, finset.sup_insert, sup_apply, ih]
end
section approx
section
variables [topological_space β] [semilattice_sup_bot β] [has_zero β]
def approx (i : ℕ → β) (f : α → β) (n : ℕ) : α →ₛ β :=
(finset.range n).sup (λk, restrict (const α (i k)) {a:α | i k ≤ f a})
lemma approx_apply [ordered_topology β] {i : ℕ → β} {f : α → β} {n : ℕ} (a : α)
(hf : _root_.measurable f) :
(approx i f n : α →ₛ β) a = (finset.range n).sup (λk, if i k ≤ f a then i k else 0) :=
begin
dsimp only [approx],
rw [finset_sup_apply],
congr,
funext k,
rw [restrict_apply],
refl,
exact (hf.preimage $ is_measurable_of_is_closed $ is_closed_ge' _)
end
lemma monotone_approx (i : ℕ → β) (f : α → β) : monotone (approx i f) :=
assume n m h, finset.sup_mono $ finset.range_subset.2 h
lemma approx_comp [ordered_topology β] [measurable_space γ]
{i : ℕ → β} {f : γ → β} {g : α → γ} {n : ℕ} (a : α)
(hf : _root_.measurable f) (hg : _root_.measurable g) :
(approx i (f ∘ g) n : α →ₛ β) a = (approx i f n : γ →ₛ β) (g a) :=
by rw [approx_apply _ hf, approx_apply _ (hf.comp hg)]
end
lemma supr_approx_apply [topological_space β] [complete_lattice β] [ordered_topology β] [has_zero β]
(i : ℕ → β) (f : α → β) (a : α) (hf : _root_.measurable f) (h_zero : (0 : β) = ⊥) :
(⨆n, (approx i f n : α →ₛ β) a) = (⨆k (h : i k ≤ f a), i k) :=
begin
refine le_antisymm (supr_le $ assume n, _) (supr_le $ assume k, supr_le $ assume hk, _),
{ rw [approx_apply a hf, h_zero],
refine finset.sup_le (assume k hk, _),
split_ifs,
exact le_supr_of_le k (le_supr _ h),
exact bot_le },
{ refine le_supr_of_le (k+1) _,
rw [approx_apply a hf],
have : k ∈ finset.range (k+1) := finset.mem_range.2 (nat.lt_succ_self _),
refine le_trans (le_of_eq _) (finset.le_sup this),
rw [if_pos hk] }
end
end approx
section eapprox
def ennreal_rat_embed (n : ℕ) : ennreal :=
nnreal.of_real ((encodable.decode ℚ n).get_or_else (0 : ℚ))
lemma ennreal_rat_embed_encode (q : ℚ) (hq : 0 ≤ q) :
ennreal_rat_embed (encodable.encode q) = nnreal.of_real q :=
by rw [ennreal_rat_embed, encodable.encodek]; refl
def eapprox : (α → ennreal) → ℕ → α →ₛ ennreal :=
approx ennreal_rat_embed
lemma monotone_eapprox (f : α → ennreal) : monotone (eapprox f) :=
monotone_approx _ f
lemma supr_eapprox_apply (f : α → ennreal) (hf : _root_.measurable f) (a : α) :
(⨆n, (eapprox f n : α →ₛ ennreal) a) = f a :=
begin
rw [eapprox, supr_approx_apply ennreal_rat_embed f a hf rfl],
refine le_antisymm (supr_le $ assume i, supr_le $ assume hi, hi) (le_of_not_gt _),
assume h,
rcases ennreal.lt_iff_exists_rat_btwn.1 h with ⟨q, hq, lt_q, q_lt⟩,
have : (nnreal.of_real q : ennreal) ≤
(⨆ (k : ℕ) (h : ennreal_rat_embed k ≤ f a), ennreal_rat_embed k),
{ refine le_supr_of_le (encodable.encode q) _,
rw [ennreal_rat_embed_encode q hq],
refine le_supr_of_le (le_of_lt q_lt) _,
exact le_refl _ },
exact lt_irrefl _ (lt_of_le_of_lt this lt_q)
end
lemma eapprox_comp [measurable_space γ] {f : γ → ennreal} {g : α → γ} {n : ℕ}
(hf : _root_.measurable f) (hg : _root_.measurable g) :
(eapprox (f ∘ g) n : α → ennreal) = (eapprox f n : γ →ₛ ennreal) ∘ g :=
funext $ assume a, approx_comp a hf hg
end eapprox
end measurable
section measure
variables [measure_space α]
def integral (f : α →ₛ ennreal) : ennreal :=
f.range.sum (λ x, x * volume (f ⁻¹' {x}))
-- TODO: slow simp proofs
lemma map_integral (g : β → ennreal) (f : α →ₛ β) :
(f.map g).integral = f.range.sum (λ x, g x * volume (f ⁻¹' {x})) :=
begin
simp only [integral, coe_map, range_map],
refine finset.sum_image' _ (assume b hb, _),
rcases mem_range.1 hb with ⟨a, rfl⟩,
let s' := f.range.filter (λb, g b = g (f a)),
have : g ∘ ⇑f ⁻¹' {g (f a)} = (⋃b∈s', ⇑f ⁻¹' {b}),
{ ext a',
simp,
split,
{ assume eq, exact ⟨⟨_, rfl⟩, eq⟩ },
{ rintros ⟨_, eq⟩, exact eq } },
calc g (f a) * volume (g ∘ ⇑f ⁻¹' {g (f a)}) = g (f a) * volume (⋃b∈s', ⇑f ⁻¹' {b}) : by rw [this]
... = g (f a) * s'.sum (λb, volume (f ⁻¹' {b})) :
begin
rw [volume_bUnion_finset],
{ simp [pairwise_on, (on)],
rintros b a₀ rfl eq₀ b a₁ rfl eq₁ ne a ⟨h₁, h₂⟩,
simp at h₁ h₂,
rw [← h₁, h₂] at ne,
exact ne rfl },
exact assume a ha, preimage_measurable _ _
end
... = s'.sum (λb, g (f a) * volume (f ⁻¹' {b})) : by rw [finset.mul_sum]
... = s'.sum (λb, g b * volume (f ⁻¹' {b})) : finset.sum_congr rfl $ by simp {contextual := tt}
end
lemma zero_integral : (0 : α →ₛ ennreal).integral = 0 :=
begin
refine (finset.sum_eq_zero_iff_of_nonneg $ assume _ _, zero_le _).2 _,
assume r hr, rcases mem_range.1 hr with ⟨a, rfl⟩,
exact zero_mul _
end
lemma add_integral (f g : α →ₛ ennreal) : (f + g).integral = f.integral + g.integral :=
calc (f + g).integral =
(pair f g).range.sum (λx, x.1 * volume (pair f g ⁻¹' {x}) + x.2 * volume (pair f g ⁻¹' {x})) :
by rw [add_eq_map₂, map_integral]; exact finset.sum_congr rfl (assume a ha, add_mul _ _ _)
... = (pair f g).range.sum (λx, x.1 * volume (pair f g ⁻¹' {x})) +
(pair f g).range.sum (λx, x.2 * volume (pair f g ⁻¹' {x})) : by rw [finset.sum_add_distrib]
... = ((pair f g).map prod.fst).integral + ((pair f g).map prod.snd).integral :
by rw [map_integral, map_integral]
... = integral f + integral g : rfl
lemma const_mul_integral (f : α →ₛ ennreal) (x : ennreal) :
(const α x * f).integral = x * f.integral :=
calc (f.map (λa, x * a)).integral = f.range.sum (λr, x * r * volume (f ⁻¹' {r})) :
by rw [map_integral]
... = f.range.sum (λr, x * (r * volume (f ⁻¹' {r}))) :
finset.sum_congr rfl (assume a ha, mul_assoc _ _ _)
... = x * f.integral :
finset.mul_sum.symm
lemma mem_restrict_range [has_zero β] {r : β} {s : set α} {f : α →ₛ β} (hs : is_measurable s) :
r ∈ (restrict f s).range ↔ (r = 0 ∧ s ≠ univ) ∨ (∃a∈s, f a = r) :=
begin
simp only [mem_range, restrict_apply, hs],
split,
{ rintros ⟨a, ha⟩,
split_ifs at ha,
{ exact or.inr ⟨a, h, ha⟩ },
{ exact or.inl ⟨ha.symm, assume eq, h $ eq.symm ▸ trivial⟩ } },
{ rintros (⟨rfl, h⟩ | ⟨a, ha, rfl⟩),
{ have : ¬ ∀a, a ∈ s := assume this, h $ eq_univ_of_forall this,
rcases not_forall.1 this with ⟨a, ha⟩,
refine ⟨a, _⟩,
rw [if_neg ha] },
{ refine ⟨a, _⟩,
rw [if_pos ha] } }
end
lemma restrict_preimage' {r : ennreal} {s : set α}
(f : α →ₛ ennreal) (hs : is_measurable s) (hr : r ≠ 0) :
(restrict f s) ⁻¹' {r} = (f ⁻¹' {r} ∩ s) :=
begin
ext a,
by_cases a ∈ s; simp [hs, h, hr.symm]
end
lemma restrict_integral (f : α →ₛ ennreal) (s : set α) (hs : is_measurable s) :
(restrict f s).integral = f.range.sum (λr, r * volume (f ⁻¹' {r} ∩ s)) :=
begin
refine finset.sum_bij_ne_zero (λr _ _, r) _ _ _ _,
{ assume r hr,
rcases (mem_restrict_range hs).1 hr with ⟨rfl, h⟩ | ⟨a, ha, rfl⟩,
{ simp },
{ assume _, exact mem_range.2 ⟨a, rfl⟩ } },
{ assume a b _ _ _ _ h, exact h },
{ assume r hr,
by_cases r0 : r = 0, { simp [r0] },
assume h0,
rcases mem_range.1 hr with ⟨a, rfl⟩,
have : f ⁻¹' {f a} ∩ s ≠ ∅,
{ assume h, simpa [h] using h0 },
rcases ne_empty_iff_exists_mem.1 this with ⟨a', eq', ha'⟩,
refine ⟨_, (mem_restrict_range hs).2 (or.inr ⟨a', ha', _⟩), _, rfl⟩,
{ simpa using eq' },
{ rwa [restrict_preimage' _ hs r0] } },
{ assume r hr ne,
by_cases r = 0, { simp [h] },
rw [restrict_preimage' _ hs h] }
end
lemma restrict_const_integral (c : ennreal) (s : set α) (hs : is_measurable s) :
(restrict (const α c) s).integral = c * volume s :=
have (@const α ennreal _ c) ⁻¹' {c} = univ,
begin
refine eq_univ_of_forall (assume a, _),
simp,
end,
calc (restrict (const α c) s).integral = c * volume ((const α c) ⁻¹' {c} ∩ s) :
begin
rw [restrict_integral (const α c) s hs],
refine finset.sum_eq_single c _ _,
{ assume r hr, rcases mem_range.1 hr with ⟨a, rfl⟩, contradiction },
{ by_cases nonempty α,
{ assume ne,
rcases h with ⟨a⟩,
exfalso,
exact ne (mem_range.2 ⟨a, rfl⟩) },
{ assume empty,
have : (@const α ennreal _ c) ⁻¹' {c} ∩ s = ∅,
{ ext a, exfalso, exact h ⟨a⟩ },
simp only [this, volume_empty, mul_zero] } }
end
... = c * volume s : by rw [this, univ_inter]
lemma integral_sup_le (f g : α →ₛ ennreal) : f.integral ⊔ g.integral ≤ (f ⊔ g).integral :=
calc f.integral ⊔ g.integral =
((pair f g).map prod.fst).integral ⊔ ((pair f g).map prod.snd).integral : rfl
... ≤ (pair f g).range.sum (λx, (x.1 ⊔ x.2) * volume (pair f g ⁻¹' {x})) :
begin
rw [map_integral, map_integral],
refine sup_le _ _;
refine finset.sum_le_sum (λ a _, canonically_ordered_semiring.mul_le_mul _ (le_refl _)),
exact le_sup_left,
exact le_sup_right
end
... = (f ⊔ g).integral : by rw [sup_eq_map₂, map_integral]
lemma integral_le_integral (f g : α →ₛ ennreal) (h : f ≤ g) : f.integral ≤ g.integral :=
calc f.integral ≤ f.integral ⊔ g.integral : le_sup_left
... ≤ (f ⊔ g).integral : integral_sup_le _ _
... = g.integral : by rw [sup_of_le_right h]
lemma integral_congr (f g : α →ₛ ennreal) (h : {a | f a = g a} ∈ (@measure_space.μ α _).a_e) :
f.integral = g.integral :=
show ((pair f g).map prod.fst).integral = ((pair f g).map prod.snd).integral, from
begin
rw [map_integral, map_integral],
refine finset.sum_congr rfl (assume p hp, _),
rcases mem_range.1 hp with ⟨a, rfl⟩,
by_cases eq : f a = g a,
{ dsimp only [pair_apply], rw eq },
{ have : volume ((pair f g) ⁻¹' {(f a, g a)}) = 0,
{ refine volume_mono_null (assume a' ha', _) h,
simp at ha',
show f a' ≠ g a',
rwa [ha'.1, ha'.2] },
simp [this] }
end
lemma integral_map {β} [measure_space β] (f : α →ₛ ennreal) (g : β →ₛ ennreal)
(m : α → β) (hm : _root_.measurable m) (eq : ∀a:α, f a = g (m a))
(h : ∀s:set β, is_measurable s → volume s = volume (m ⁻¹' s)) :
f.integral = g.integral :=
have f_eq : (f : α → ennreal) = g ∘ m := funext eq,
have vol_f : ∀r, volume (f ⁻¹' {r}) = volume (g ⁻¹' {r}),
by { assume r, rw [h, f_eq, preimage_comp], exact measurable_sn _ _ },
begin
simp [integral, vol_f],
refine finset.sum_subset _ _,
{ simp [finset.subset_iff, f_eq],
rintros r a rfl, exact ⟨_, rfl⟩ },
{ assume r hrg hrf,
rw [simple_func.mem_range, not_exists] at hrf,
have : f ⁻¹' {r} = ∅ := set.eq_empty_of_subset_empty (assume a, by simpa using hrf a),
simp [(vol_f _).symm, this] }
end
end measure
end simple_func
section lintegral
open simple_func
variable [measure_space α]
/-- The lower Lebesgue integral -/
def lintegral (f : α → ennreal) : ennreal :=
⨆ (s : α →ₛ ennreal) (hf : f ≥ s), s.integral
notation `∫⁻` binders `, ` r:(scoped f, lintegral f) := r
theorem simple_func.lintegral_eq_integral (f : α →ₛ ennreal) : (∫⁻ a, f a) = f.integral :=
le_antisymm
(supr_le $ assume s, supr_le $ assume hs, integral_le_integral _ _ hs)
(le_supr_of_le f $ le_supr_of_le (le_refl f) $ le_refl _)
lemma lintegral_le_lintegral (f g : α → ennreal) (h : f ≤ g) : (∫⁻ a, f a) ≤ (∫⁻ a, g a) :=
supr_le_supr $ assume s, supr_le $ assume hs, le_supr_of_le (le_trans hs h) (le_refl _)
lemma lintegral_eq_nnreal (f : α → ennreal) :
(∫⁻ a, f a) =
(⨆ (s : α →ₛ nnreal) (hf : f ≥ s.map (coe : nnreal → ennreal)), (s.map (coe : nnreal → ennreal)).integral) :=
begin
let c : nnreal → ennreal := coe,
refine le_antisymm
(supr_le $ assume s, supr_le $ assume hs, _)
(supr_le $ assume s, supr_le $ assume hs, le_supr_of_le (s.map c) $ le_supr _ hs),
by_cases {a | s a ≠ ⊤} ∈ (@measure_space.μ α _).a_e,
{ have : f ≥ (s.map ennreal.to_nnreal).map c :=
le_trans (assume a, ennreal.coe_to_nnreal_le_self) hs,
refine le_supr_of_le (s.map ennreal.to_nnreal) (le_supr_of_le this (le_of_eq $ integral_congr _ _ _)),
exact filter.mem_sets_of_superset h (assume a ha, (ennreal.coe_to_nnreal ha).symm) },
{ have h_vol_s : volume {a : α | s a = ⊤} ≠ 0,
{ simp [measure.a_e, set.compl_set_of] at h, assumption },
let n : ℕ → (α →ₛ nnreal) := λn, restrict (const α (n : nnreal)) (s ⁻¹' {⊤}),
have n_le_s : ∀i, (n i).map c ≤ s,
{ assume i a,
dsimp [n, c],
rw [restrict_apply _ (s.preimage_measurable _)],
split_ifs with ha,
{ simp at ha, exact ha.symm ▸ le_top },
{ exact zero_le _ } },
have approx_s : ∀ (i : ℕ), ↑i * volume {a : α | s a = ⊤} ≤ integral (map c (n i)),
{ assume i,
have : {a : α | s a = ⊤} = s ⁻¹' {⊤}, { ext a, simp },
rw [this, ← restrict_const_integral _ _ (s.preimage_measurable _)],
{ refine integral_le_integral _ _ (assume a, le_of_eq _),
simp [n, c, restrict_apply, s.preimage_measurable],
split_ifs; simp [ennreal.coe_nat] },
},
calc s.integral ≤ ⊤ : le_top
... = (⨆i:ℕ, (i : ennreal) * volume {a | s a = ⊤}) :
by rw [← ennreal.supr_mul, ennreal.supr_coe_nat, ennreal.top_mul, if_neg h_vol_s]
... ≤ (⨆i, ((n i).map c).integral) : supr_le_supr approx_s
... ≤ ⨆ (s : α →ₛ nnreal) (hf : f ≥ s.map c), (s.map c).integral :
have ∀i, ((n i).map c : α → ennreal) ≤ f := assume i, le_trans (n_le_s i) hs,
(supr_le $ assume i, le_supr_of_le (n i) (le_supr (λh, ((n i).map c).integral) (this i))) }
end
/-- Monotone convergence theorem -- somtimes called Beppo-Levi convergence.
See `lintegral_supr_directed` for a more general form. -/
theorem lintegral_supr
{f : ℕ → α → ennreal} (hf : ∀n, measurable (f n)) (h_mono : monotone f) :
(∫⁻ a, ⨆n, f n a) = (⨆n, ∫⁻ a, f n a) :=
let c : nnreal → ennreal := coe in
let F (a:α) := ⨆n, f n a in
have hF : measurable F := measurable.supr hf,
show (∫⁻ a, F a) = (⨆n, ∫⁻ a, f n a),
begin
refine le_antisymm _ _,
{ rw [lintegral_eq_nnreal],
refine supr_le (assume s, supr_le (assume hsf, _)),
refine ennreal.le_of_forall_lt_one_mul_lt (assume a ha, _),
rcases ennreal.lt_iff_exists_coe.1 ha with ⟨r, rfl, ha⟩,
have ha : r < 1 := ennreal.coe_lt_coe.1 ha,
let rs := s.map (λa, r * a),
have eq_rs : (const α r : α →ₛ ennreal) * map c s = rs.map c,
{ ext1 a, exact ennreal.coe_mul.symm },
have eq : ∀p, (rs.map c) ⁻¹' {p} = (⋃n, (rs.map c) ⁻¹' {p} ∩ {a | p ≤ f n a}),
{ assume p,
rw [← inter_Union, ← inter_univ ((map c rs) ⁻¹' {p})] {occs := occurrences.pos [1]},
refine set.ext (assume x, and_congr_right $ assume hx, (true_iff _).2 _),
by_cases p_eq : p = 0, { simp [p_eq] },
simp at hx, subst hx,
have : r * s x ≠ 0, { rwa [(≠), ← ennreal.coe_eq_zero] },
have : s x ≠ 0, { refine mt _ this, assume h, rw [h, mul_zero] },
have : (rs.map c) x < ⨆ (n : ℕ), f n x,
{ refine lt_of_lt_of_le (ennreal.coe_lt_coe.2 (_)) (hsf x),
suffices : r * s x < 1 * s x, simpa [rs],
exact mul_lt_mul_of_pos_right ha (zero_lt_iff_ne_zero.2 this) },
rcases lt_supr_iff.1 this with ⟨i, hi⟩,
exact mem_Union.2 ⟨i, le_of_lt hi⟩ },
have mono : ∀r:ennreal, monotone (λn, (rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a}),
{ assume r i j h,
refine inter_subset_inter (subset.refl _) _,
assume x hx, exact le_trans hx (h_mono h x) },
have h_meas : ∀n, is_measurable {a : α | ⇑(map c rs) a ≤ f n a} :=
assume n, measurable_le (simple_func.measurable _) (hf n),
calc (r:ennreal) * integral (s.map c) = (rs.map c).range.sum (λr, r * volume ((rs.map c) ⁻¹' {r})) :
by rw [← const_mul_integral, integral, eq_rs]
... ≤ (rs.map c).range.sum (λr, r * volume (⋃n, (rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a})) :
le_of_eq (finset.sum_congr rfl $ assume x hx, by rw ← eq)
... ≤ (rs.map c).range.sum (λr, (⨆n, r * volume ((rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a}))) :
le_of_eq (finset.sum_congr rfl $ assume x hx,
begin
rw [volume, measure_Union_eq_supr_nat _ (mono x), ennreal.mul_supr],
{ assume i,
refine is_measurable.inter ((rs.map c).preimage_measurable _) _,
refine (hf i).preimage _,
exact is_measurable_of_is_closed (is_closed_ge' _) }
end)
... ≤ ⨆n, (rs.map c).range.sum (λr, r * volume ((rs.map c) ⁻¹' {r} ∩ {a | r ≤ f n a})) :
begin
refine le_of_eq _,
rw [ennreal.finset_sum_supr_nat],
assume p i j h,
exact canonically_ordered_semiring.mul_le_mul (le_refl _) (volume_mono $ mono p h)
end
... ≤ (⨆n:ℕ, ((rs.map c).restrict {a | (rs.map c) a ≤ f n a}).integral) :
begin
refine supr_le_supr (assume n, _),
rw [restrict_integral _ _ (h_meas n)],
{ refine le_of_eq (finset.sum_congr rfl $ assume r hr, _),
congr' 2,
ext a,
refine and_congr_right _,
simp {contextual := tt} }
end
... ≤ (⨆n, ∫⁻ a, f n a) :
begin
refine supr_le_supr (assume n, _),
rw [← simple_func.lintegral_eq_integral],
refine lintegral_le_lintegral _ _ (assume a, _),
dsimp,
rw [restrict_apply],
split_ifs; simp, simpa using h,
exact h_meas n
end },
{ exact supr_le (assume n, lintegral_le_lintegral _ _ $ assume a, le_supr _ n) }
end
lemma lintegral_eq_supr_eapprox_integral {f : α → ennreal} (hf : measurable f) :
(∫⁻ a, f a) = (⨆n, (eapprox f n).integral) :=
calc (∫⁻ a, f a) = (∫⁻ a, ⨆n, (eapprox f n : α → ennreal) a) :
by congr; ext a; rw [supr_eapprox_apply f hf]
... = (⨆n, ∫⁻ a, (eapprox f n : α → ennreal) a) :
begin
rw [lintegral_supr],
{ assume n, exact (eapprox f n).measurable },
{ assume i j h, exact (monotone_eapprox f h) }
end
... = (⨆n, (eapprox f n).integral) : by congr; ext n; rw [(eapprox f n).lintegral_eq_integral]
lemma lintegral_add {f g : α → ennreal} (hf : measurable f) (hg : measurable g) :
(∫⁻ a, f a + g a) = (∫⁻ a, f a) + (∫⁻ a, g a) :=
calc (∫⁻ a, f a + g a) =
(∫⁻ a, (⨆n, (eapprox f n : α → ennreal) a) + (⨆n, (eapprox g n : α → ennreal) a)) :
by congr; funext a; rw [supr_eapprox_apply f hf, supr_eapprox_apply g hg]
... = (∫⁻ a, (⨆n, (eapprox f n + eapprox g n : α → ennreal) a)) :
begin
congr, funext a,
rw [ennreal.supr_add_supr_of_monotone], { refl },
{ assume i j h, exact monotone_eapprox _ h a },
{ assume i j h, exact monotone_eapprox _ h a },
end
... = (⨆n, (eapprox f n).integral + (eapprox g n).integral) :
begin
rw [lintegral_supr],
{ congr, funext n, rw [← simple_func.add_integral, ← simple_func.lintegral_eq_integral], refl },
{ assume n, exact measurable_add (eapprox f n).measurable (eapprox g n).measurable },
{ assume i j h a, exact add_le_add' (monotone_eapprox _ h _) (monotone_eapprox _ h _) }
end
... = (⨆n, (eapprox f n).integral) + (⨆n, (eapprox g n).integral) :
by refine (ennreal.supr_add_supr_of_monotone _ _).symm;
{ assume i j h, exact simple_func.integral_le_integral _ _ (monotone_eapprox _ h) }
... = (∫⁻ a, f a) + (∫⁻ a, g a) :
by rw [lintegral_eq_supr_eapprox_integral hf, lintegral_eq_supr_eapprox_integral hg]
@[simp] lemma lintegral_zero : (∫⁻ a:α, 0) = 0 :=
show (∫⁻ a:α, (0 : α →ₛ ennreal) a) = 0, by rw [simple_func.lintegral_eq_integral, zero_integral]
lemma lintegral_finset_sum (s : finset β) {f : β → α → ennreal} (hf : ∀b, measurable (f b)) :
(∫⁻ a, s.sum (λb, f b a)) = s.sum (λb, ∫⁻ a, f b a) :=
begin
refine finset.induction_on s _ _,
{ simp },
{ assume a s has ih,
simp [has],
rw [lintegral_add (hf _) (measurable_finset_sum s hf), ih] }
end
lemma lintegral_const_mul (r : ennreal) {f : α → ennreal} (hf : measurable f) :
(∫⁻ a, r * f a) = r * (∫⁻ a, f a) :=
calc (∫⁻ a, r * f a) = (∫⁻ a, (⨆n, (const α r * eapprox f n) a)) :
by congr; funext a; rw [← supr_eapprox_apply f hf, ennreal.mul_supr]; refl
... = (⨆n, r * (eapprox f n).integral) :
begin
rw [lintegral_supr],
{ congr, funext n, rw [← simple_func.const_mul_integral, ← simple_func.lintegral_eq_integral] },
{ assume n, exact simple_func.measurable _ },
{ assume i j h a, exact canonically_ordered_semiring.mul_le_mul (le_refl _)
(monotone_eapprox _ h _) }
end
... = r * (∫⁻ a, f a) : by rw [← ennreal.mul_supr, lintegral_eq_supr_eapprox_integral hf]
lemma lintegral_supr_const (r : ennreal) {s : set α} (hs : is_measurable s) :
(∫⁻ a, ⨆(h : a ∈ s), r) = r * volume s :=
begin
rw [← restrict_const_integral r s hs, ← (restrict (const α r) s).lintegral_eq_integral],
congr; ext a; by_cases a ∈ s; simp [h, hs]
end
lemma lintegral_le_lintegral_ae {f g : α → ennreal} (h : ∀ₘ a, f a ≤ g a) :
(∫⁻ a, f a) ≤ (∫⁻ a, g a) :=
begin
rcases exists_is_measurable_superset_of_measure_eq_zero h with ⟨t, hts, ht, ht0⟩,
have : - t ∈ (@measure_space.μ α _).a_e,
{ rw [measure.mem_a_e_iff, lattice.neg_neg, ht0] },
refine (supr_le $ assume s, supr_le $ assume hfs,
le_supr_of_le (s.restrict (- t)) $ le_supr_of_le _ _),
{ assume a,
by_cases a ∈ t;
simp [h, simple_func.restrict_apply, ht.compl],
exact le_trans (hfs a) (by_contradiction $ assume hnfg, h (hts hnfg)) },
{ refine le_of_eq (s.integral_congr _ _),
filter_upwards [this],
refine assume a hnt, _,
by_cases hat : a ∈ t; simp [hat, ht.compl],
exact (hnt hat).elim }
end
lemma lintegral_congr_ae {f g : α → ennreal} (h : ∀ₘ a, f a = g a) :
(∫⁻ a, f a) = (∫⁻ a, g a) :=
le_antisymm
(lintegral_le_lintegral_ae $ by filter_upwards [h] assume a h, le_of_eq h)
(lintegral_le_lintegral_ae $ by filter_upwards [h] assume a h, le_of_eq h.symm)
lemma lintegral_eq_zero_iff {f : α → ennreal} (hf : measurable f) :
lintegral f = 0 ↔ (∀ₘ a, f a = 0) :=
begin
refine iff.intro (assume h, _) (assume h, _),
{ have : ∀n:ℕ, ∀ₘ a, f a < n⁻¹,
{ assume n,
have : is_measurable {a : α | f a ≥ n⁻¹ },
{ exact hf _ (is_measurable_of_is_closed $ is_closed_ge' _) },
have : (n : ennreal)⁻¹ * volume {a | f a ≥ n⁻¹ } = 0,
{ rw [← simple_func.restrict_const_integral _ _ this, ← le_zero_iff_eq,
← simple_func.lintegral_eq_integral],
refine le_trans (lintegral_le_lintegral _ _ _) (le_of_eq h),
assume a, by_cases h : (n : ennreal)⁻¹ ≤ f a; simp [h, (≥), this] },
rw [ennreal.mul_eq_zero, ennreal.inv_eq_zero] at this,
simpa [ennreal.nat_ne_top, all_ae_iff] using this },
filter_upwards [all_ae_all_iff.2 this],
dsimp,
assume a ha,
by_contradiction h,
rcases ennreal.exists_inv_nat_lt h with ⟨n, hn⟩,
exact (lt_irrefl _ $ lt_trans hn $ ha n).elim },
{ calc lintegral f = lintegral (λa:α, 0) : lintegral_congr_ae h
... = 0 : lintegral_zero }
end
/-- Weaker version of the monotone convergence theorem-/
lemma lintegral_supr_ae {f : ℕ → α → ennreal} (hf : ∀n, measurable (f n))
(h_mono : ∀n, ∀ₘ a, f n a ≤ f n.succ a) :
(∫⁻ a, ⨆n, f n a) = (⨆n, ∫⁻ a, f n a) :=
let ⟨s, hs⟩ := exists_is_measurable_superset_of_measure_eq_zero
(all_ae_iff.1 (all_ae_all_iff.2 h_mono)) in
let g := λ n a, if a ∈ s then 0 else f n a in
have g_eq_f : ∀ₘ a, ∀n, g n a = f n a,
begin
have := hs.2.2, rw [← compl_compl s] at this,
filter_upwards [(measure.mem_a_e_iff (-s)).2 this] assume a ha n, if_neg ha
end,
calc
(∫⁻ a, ⨆n, f n a) = (∫⁻ a, ⨆n, g n a) :
lintegral_congr_ae
begin
filter_upwards [g_eq_f], assume a ha, congr, funext, exact (ha n).symm
end
... = ⨆n, (∫⁻ a, g n a) :
lintegral_supr
(assume n, measurable.if hs.2.1 measurable_const (hf n))
(monotone_of_monotone_nat $ assume n a, classical.by_cases
(assume h : a ∈ s, by simp [g, if_pos h])
(assume h : a ∉ s,
begin
simp only [g, if_neg h], have := hs.1, rw subset_def at this, have := mt (this a) h,
simp only [not_not, mem_set_of_eq] at this, exact this n
end))
... = ⨆n, (∫⁻ a, f n a) :
begin
congr, funext, apply lintegral_congr_ae, filter_upwards [g_eq_f] assume a ha, ha n
end
lemma lintegral_sub {f g : α → ennreal} (hf : measurable f) (hg : measurable g)
(hg_fin : lintegral g < ⊤) (h_le : ∀ₘ a, g a ≤ f a) :
(∫⁻ a, f a - g a) = (∫⁻ a, f a) - (∫⁻ a, g a) :=
begin
rw [← ennreal.add_right_inj hg_fin,
ennreal.sub_add_cancel_of_le (lintegral_le_lintegral_ae h_le),
← lintegral_add (ennreal.measurable_sub hf hg) hg],
show (∫⁻ (a : α), f a - g a + g a) = ∫⁻ (a : α), f a,
apply lintegral_congr_ae, filter_upwards [h_le], simp only [add_comm, mem_set_of_eq],
assume a ha, exact ennreal.add_sub_cancel_of_le ha
end
/-- Monotone convergence theorem for nonincreasing sequences of functions -/
lemma lintegral_infi_ae
{f : ℕ → α → ennreal} (h_meas : ∀n, measurable (f n))
(h_mono : ∀n:ℕ, ∀ₘ a, f n.succ a ≤ f n a) (h_fin : lintegral (f 0) < ⊤) :
(∫⁻ a, ⨅n, f n a) = (⨅n, ∫⁻ a, f n a) :=
have fn_le_f0 : (∫⁻ a, ⨅n, f n a) ≤ lintegral (f 0), from
lintegral_le_lintegral _ _ (assume a, infi_le_of_le 0 (le_refl _)),
have fn_le_f0' : (⨅n, ∫⁻ a, f n a) ≤ lintegral (f 0), from infi_le_of_le 0 (le_refl _),
(ennreal.sub_left_inj h_fin fn_le_f0 fn_le_f0').1 $
show lintegral (f 0) - (∫⁻ a, ⨅n, f n a) = lintegral (f 0) - (⨅n, ∫⁻ a, f n a), from
calc
lintegral (f 0) - (∫⁻ a, ⨅n, f n a) = ∫⁻ a, f 0 a - ⨅n, f n a :
(lintegral_sub (h_meas 0) (measurable.infi h_meas)
(calc
(∫⁻ a, ⨅n, f n a) ≤ lintegral (f 0) : lintegral_le_lintegral _ _
(assume a, infi_le _ _)
... < ⊤ : h_fin )
(all_ae_of_all $ assume a, infi_le _ _)).symm
... = ∫⁻ a, ⨆n, f 0 a - f n a : congr rfl (funext (assume a, ennreal.sub_infi))
... = ⨆n, ∫⁻ a, f 0 a - f n a :
lintegral_supr_ae
(assume n, ennreal.measurable_sub (h_meas 0) (h_meas n))
(assume n, by
filter_upwards [h_mono n] assume a ha, ennreal.sub_le_sub (le_refl _) ha)
... = ⨆n, lintegral (f 0) - ∫⁻ a, f n a :
have h_mono : ∀ₘ a, ∀n:ℕ, f n.succ a ≤ f n a := all_ae_all_iff.2 h_mono,
have h_mono : ∀n, ∀ₘa, f n a ≤ f 0 a := assume n,
begin
filter_upwards [h_mono], simp only [mem_set_of_eq], assume a, assume h, induction n with n ih,
{exact le_refl _}, {exact le_trans (h n) ih}
end,
congr rfl (funext $ assume n, lintegral_sub (h_meas _) (h_meas _)
(calc
(∫⁻ a, f n a) ≤ ∫⁻ a, f 0 a : lintegral_le_lintegral_ae $ h_mono n
... < ⊤ : h_fin)
(h_mono n))
... = lintegral (f 0) - (⨅n, ∫⁻ a, f n a) : ennreal.sub_infi.symm
section priority
-- for some reason the next proof fails without changing the priority of this instance
local attribute [instance, priority 1000] classical.prop_decidable
/-- Known as Fatou's lemma -/
lemma lintegral_liminf_le {f : ℕ → α → ennreal} (h_meas : ∀n, measurable (f n)) :
(∫⁻ a, liminf at_top (λ n, f n a)) ≤ liminf at_top (λ n, lintegral (f n)) :=
calc
(∫⁻ a, liminf at_top (λ n, f n a)) = ∫⁻ a, ⨆n:ℕ, ⨅i≥n, f i a :
congr rfl (funext (assume a, liminf_eq_supr_infi_of_nat))
... = ⨆n:ℕ, ∫⁻ a, ⨅i≥n, f i a :
lintegral_supr
begin
assume n, apply measurable.infi, assume i, by_cases h : i ≥ n,
{convert h_meas i, simp [h]},
{convert measurable_const, simp [h]}
end
begin
assume n m hnm a, simp only [le_infi_iff], assume i hi,
refine infi_le_of_le i (infi_le_of_le (le_trans hnm hi) (le_refl _))
end
... ≤ ⨆n:ℕ, ⨅i≥n, lintegral (f i) :
supr_le_supr $ assume n, le_infi $
assume i, le_infi $ assume hi, lintegral_le_lintegral _ _
$ assume a, infi_le_of_le i $ infi_le_of_le hi $ le_refl _
... = liminf at_top (λ n, lintegral (f n)) : liminf_eq_supr_infi_of_nat.symm
end priority
lemma limsup_lintegral_le {f : ℕ → α → ennreal} {g : α → ennreal}
(hf_meas : ∀ n, measurable (f n)) (hg_meas : measurable g)
(h_bound : ∀n, ∀ₘa, f n a ≤ g a) (h_fin : lintegral g < ⊤) :
limsup at_top (λn, lintegral (f n)) ≤ ∫⁻ a, limsup at_top (λn, f n a) :=
calc
limsup at_top (λn, lintegral (f n)) = ⨅n:ℕ, ⨆i≥n, lintegral (f i) :
limsup_eq_infi_supr_of_nat
... ≤ ⨅n:ℕ, ∫⁻ a, ⨆i≥n, f i a :
infi_le_infi $ assume n, supr_le $ assume i, supr_le $ assume hi,
lintegral_le_lintegral _ _ $ assume a, le_supr_of_le i $ le_supr_of_le hi (le_refl _)
... = ∫⁻ a, ⨅n:ℕ, ⨆i≥n, f i a :
(lintegral_infi_ae
(assume n,
@measurable.supr _ _ _ _ _ _ _ _ _ (λ i a, supr (λ (h : i ≥ n), f i a))
(assume i, measurable.supr_Prop (hf_meas i)))
(assume n, all_ae_of_all $ assume a,
begin
simp only [supr_le_iff], assume i hi, refine le_supr_of_le i _,
rw [supr_pos _], exact le_refl _, exact nat.le_of_succ_le hi
end )
(lt_of_le_of_lt
(lintegral_le_lintegral_ae
begin
filter_upwards [all_ae_all_iff.2 h_bound],
simp only [supr_le_iff, mem_set_of_eq],
assume a ha i hi, exact ha i
end )
h_fin)).symm
... = ∫⁻ a, limsup at_top (λn, f n a) :
lintegral_congr_ae $ all_ae_of_all $ assume a, limsup_eq_infi_supr_of_nat.symm
/-- Dominated convergence theorem for nonnegative functions -/
lemma dominated_convergence_nn
{F : ℕ → α → ennreal} {f : α → ennreal} {g : α → ennreal}
(hF_meas : ∀n, measurable (F n)) (hf_meas : measurable f) (hg_meas : measurable g)
(h_bound : ∀n, ∀ₘ a, F n a ≤ g a)
(h_fin : lintegral g < ⊤)
(h_lim : ∀ₘ a, tendsto (λ n, F n a) at_top (nhds (f a))) :
tendsto (λn, lintegral (F n)) at_top (nhds (lintegral f)) :=
begin
have limsup_le_lintegral :=
calc
limsup at_top (λ (n : ℕ), lintegral (F n)) ≤ ∫⁻ (a : α), limsup at_top (λn, F n a) :
limsup_lintegral_le hF_meas hg_meas h_bound h_fin
... = lintegral f :
lintegral_congr_ae $
by filter_upwards [h_lim] assume a h, limsup_eq_of_tendsto at_top_ne_bot h,
have lintegral_le_liminf :=
calc
lintegral f = ∫⁻ (a : α), liminf at_top (λ (n : ℕ), F n a) :
lintegral_congr_ae $
by filter_upwards [h_lim] assume a h, (liminf_eq_of_tendsto at_top_ne_bot h).symm
... ≤ liminf at_top (λ n, lintegral (F n)) :
lintegral_liminf_le hF_meas,
have liminf_eq_limsup :=
le_antisymm
(liminf_le_limsup (map_ne_bot at_top_ne_bot))
(le_trans limsup_le_lintegral lintegral_le_liminf),
have liminf_eq_lintegral : liminf at_top (λ n, lintegral (F n)) = lintegral f :=
le_antisymm (by convert limsup_le_lintegral) lintegral_le_liminf,
have limsup_eq_lintegral : limsup at_top (λ n, lintegral (F n)) = lintegral f :=
le_antisymm
limsup_le_lintegral
begin convert lintegral_le_liminf, exact liminf_eq_limsup.symm end,
exact tendsto_of_liminf_eq_limsup ⟨liminf_eq_lintegral, limsup_eq_lintegral⟩
end
section
open encodable
/-- Monotone convergence for a suprema over a directed family and indexed by an encodable type -/
theorem lintegral_supr_directed [encodable β] {f : β → α → ennreal}
(hf : ∀b, measurable (f b)) (h_directed : directed (≤) f) :
(∫⁻ a, ⨆b, f b a) = (⨆b, ∫⁻ a, f b a) :=
begin
by_cases hβ : ¬ nonempty β,
{ have : ∀f : β → ennreal, (⨆(b : β), f b) = 0 :=
assume f, supr_eq_bot.2 (assume b, (hβ ⟨b⟩).elim),
simp [this] },
cases of_not_not hβ with b,
haveI iβ : inhabited β := ⟨b⟩, clear hβ b,
have : ∀a, (⨆ b, f b a) = (⨆ n, f (sequence_of_directed (≤) f h_directed n) a),
{ assume a,
refine le_antisymm (supr_le $ assume b, _) (supr_le $ assume n, le_supr (λn, f n a) _),
exact le_supr_of_le (encode b + 1) (le_sequence_of_directed f h_directed b a) },
calc (∫⁻ a, ⨆ b, f b a) = (∫⁻ a, ⨆ n, f (sequence_of_directed (≤) f h_directed n) a) :
by simp only [this]
... = (⨆ n, ∫⁻ a, f (sequence_of_directed (≤) f h_directed n) a) :
lintegral_supr (assume n, hf _) (monotone_sequence_of_directed f h_directed)
... = (⨆ b, ∫⁻ a, f b a) :
begin
refine le_antisymm (supr_le $ assume n, _) (supr_le $ assume b, _),
{ exact le_supr (λb, lintegral (f b)) _ },
{ exact le_supr_of_le (encode b + 1)
(lintegral_le_lintegral _ _ $ le_sequence_of_directed f h_directed b) }
end
end
end
lemma lintegral_tsum [encodable β] {f : β → α → ennreal} (hf : ∀i, measurable (f i)) :
(∫⁻ a, ∑ i, f i a) = (∑ i, ∫⁻ a, f i a) :=
begin
simp only [ennreal.tsum_eq_supr_sum],
rw [lintegral_supr_directed],
{ simp [lintegral_finset_sum _ hf] },
{ assume b, exact measurable_finset_sum _ hf },
{ assume s t,
use [s ∪ t],
split,
exact assume a, finset.sum_le_sum_of_subset (finset.subset_union_left _ _),
exact assume a, finset.sum_le_sum_of_subset (finset.subset_union_right _ _) }
end
end lintegral
namespace measure
def integral [measurable_space α] (m : measure α) (f : α → ennreal) : ennreal :=
@lintegral α { μ := m } f
variables [measurable_space α] {m : measure α}
@[simp] lemma integral_zero : m.integral (λa, 0) = 0 := @lintegral_zero α { μ := m }
lemma integral_map [measurable_space β] {f : β → ennreal} {g : α → β}
(hf : measurable f) (hg : measurable g) : (map g m).integral f = m.integral (f ∘ g) :=
begin
rw [integral, integral, lintegral_eq_supr_eapprox_integral, lintegral_eq_supr_eapprox_integral],
{ congr, funext n, symmetry,
apply simple_func.integral_map,
{ exact hg },
{ assume a, exact congr_fun (simple_func.eapprox_comp hf hg) a },
{ assume s hs, exact map_apply hg hs } },
exact hf.comp hg,
assumption
end
lemma integral_dirac (a : α) {f : α → ennreal} (hf : measurable f) : (dirac a).integral f = f a :=
have ∀f:α →ₛ ennreal, @simple_func.integral α {μ := dirac a} f = f a,
begin
assume f,
have : ∀r, @volume α { μ := dirac a } (⇑f ⁻¹' {r}) = ⨆ h : f a = r, 1,
{ assume r,
transitivity,
apply dirac_apply,
apply simple_func.measurable_sn,
refine supr_congr_Prop _ _; simp },
transitivity,
apply finset.sum_eq_single (f a),
{ assume b hb h, simp [this, ne.symm h], },
{ assume h, simp at h, exact (h a rfl).elim },
{ rw [this], simp }
end,
begin
rw [integral, lintegral_eq_supr_eapprox_integral],
{ simp [this, simple_func.supr_eapprox_apply f hf] },
assumption
end
def with_density (m : measure α) (f : α → ennreal) : measure α :=
if hf : measurable f then
measure.of_measurable (λs hs, m.integral (λa, ⨆(h : a ∈ s), f a))
(by simp)
begin
assume s hs hd,
have : ∀a, (⨆ (h : a ∈ ⋃i, s i), f a) = (∑i, (⨆ (h : a ∈ s i), f a)),
{ assume a,
by_cases ha : ∃j, a ∈ s j,
{ rcases ha with ⟨j, haj⟩,
have : ∀i, a ∈ s i ↔ j = i := assume i,
iff.intro
(assume hai, by_contradiction $ assume hij, hd j i hij ⟨haj, hai⟩)
(by rintros rfl; assumption),
simp [this, ennreal.tsum_supr_eq] },
{ have : ∀i, ¬ a ∈ s i, { simpa using ha },
simp [this] } },
simp only [this],
apply lintegral_tsum,
{ assume i,
simp [supr_eq_if],
exact measurable.if (hs i) hf measurable_const }
end
else 0
lemma with_density_apply {m : measure α} {f : α → ennreal} {s : set α}
(hf : measurable f) (hs : is_measurable s) :
m.with_density f s = m.integral (λa, ⨆(h : a ∈ s), f a) :=
by rw [with_density, dif_pos hf]; exact measure.of_measurable_apply s hs
end measure
end measure_theory
|
4202b463bc395e62a75740bd9a2abe0ec6d7aa1f | f7315930643edc12e76c229a742d5446dad77097 | /library/init/quot.lean | bd16be1b674695b160995cb104645511563a826f | [
"Apache-2.0"
] | permissive | bmalehorn/lean | 8f77b762a76c59afff7b7403f9eb5fc2c3ce70c1 | 53653c352643751c4b62ff63ec5e555f11dae8eb | refs/heads/master | 1,610,945,684,489 | 1,429,681,220,000 | 1,429,681,449,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,988 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.quot
Author: Leonardo de Moura
Quotient types.
-/
prelude
import init.sigma init.setoid init.logic
open sigma.ops setoid
constant quot.{l} : Π {A : Type.{l}}, setoid A → Type.{l}
-- Remark: if we do not use propext here, then we would need a quot.lift for propositions.
constant propext {a b : Prop} : a ↔ b → a = b
namespace quot
constant mk : Π {A : Type} [s : setoid A], A → quot s
notation `⟦`:max a `⟧`:0 := mk a
constant sound : Π {A : Type} [s : setoid A] {a b : A}, a ≈ b → ⟦a⟧ = ⟦b⟧
constant exact : Π {A : Type} [s : setoid A] {a b : A}, ⟦a⟧ = ⟦b⟧ → a ≈ b
constant lift : Π {A B : Type} [s : setoid A] (f : A → B), (∀ a b, a ≈ b → f a = f b) → quot s → B
constant ind : ∀ {A : Type} [s : setoid A] {B : quot s → Prop}, (∀ a, B ⟦a⟧) → ∀ q, B q
init_quotient
protected theorem lift_beta {A B : Type} [s : setoid A] (f : A → B) (c : ∀ a b, a ≈ b → f a = f b) (a : A) : lift f c ⟦a⟧ = f a :=
rfl
protected theorem ind_beta {A : Type} [s : setoid A] {B : quot s → Prop} (p : ∀ a, B ⟦a⟧) (a : A) : ind p ⟦a⟧ = p a :=
rfl
protected definition lift_on [reducible] {A B : Type} [s : setoid A] (q : quot s) (f : A → B) (c : ∀ a b, a ≈ b → f a = f b) : B :=
lift f c q
protected theorem induction_on {A : Type} [s : setoid A] {B : quot s → Prop} (q : quot s) (H : ∀ a, B ⟦a⟧) : B q :=
ind H q
section
variable {A : Type}
variable [s : setoid A]
variable {B : quot s → Type}
include s
protected definition indep [reducible] (f : Π a, B ⟦a⟧) (a : A) : Σ q, B q :=
⟨⟦a⟧, f a⟩
protected lemma indep_coherent (f : Π a, B ⟦a⟧)
(H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b)
: ∀ a b, a ≈ b → indep f a = indep f b :=
λa b e, sigma.equal (sound e) (H a b e)
protected lemma lift_indep_pr1
(f : Π a, B ⟦a⟧) (H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b)
(q : quot s) : (lift (indep f) (indep_coherent f H) q).1 = q :=
ind (λ a, by esimp) q
protected definition rec [reducible]
(f : Π a, B ⟦a⟧) (H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b)
(q : quot s) : B q :=
let p := lift (indep f) (indep_coherent f H) q in
eq.rec_on (lift_indep_pr1 f H q) (p.2)
protected definition rec_on [reducible]
(q : quot s) (f : Π a, B ⟦a⟧) (H : ∀ (a b : A) (p : a ≈ b), eq.rec (f a) (sound p) = f b) : B q :=
rec f H q
protected definition rec_on_subsingleton [reducible]
[H : ∀ a, subsingleton (B ⟦a⟧)] (q : quot s) (f : Π a, B ⟦a⟧) : B q :=
rec f (λ a b h, !subsingleton.elim) q
end
section
variables {A B C : Type}
variables [s₁ : setoid A] [s₂ : setoid B]
include s₁ s₂
protected definition lift₂ [reducible]
(f : A → B → C)(c : ∀ a₁ a₂ b₁ b₂, a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂)
(q₁ : quot s₁) (q₂ : quot s₂) : C :=
lift
(λ a₁, lift (λ a₂, f a₁ a₂) (λ a b H, c a₁ a a₁ b (setoid.refl a₁) H) q₂)
(λ a b H, ind (λ a', proof c a a' b a' H (setoid.refl a') qed) q₂)
q₁
protected definition lift_on₂ [reducible]
(q₁ : quot s₁) (q₂ : quot s₂) (f : A → B → C) (c : ∀ a₁ a₂ b₁ b₂, a₁ ≈ b₁ → a₂ ≈ b₂ → f a₁ a₂ = f b₁ b₂) : C :=
lift₂ f c q₁ q₂
protected theorem ind₂ {C : quot s₁ → quot s₂ → Prop} (H : ∀ a b, C ⟦a⟧ ⟦b⟧) (q₁ : quot s₁) (q₂ : quot s₂) : C q₁ q₂ :=
quot.ind (λ a₁, quot.ind (λ a₂, H a₁ a₂) q₂) q₁
protected theorem induction_on₂
{C : quot s₁ → quot s₂ → Prop} (q₁ : quot s₁) (q₂ : quot s₂) (H : ∀ a b, C ⟦a⟧ ⟦b⟧) : C q₁ q₂ :=
quot.ind (λ a₁, quot.ind (λ a₂, H a₁ a₂) q₂) q₁
protected theorem induction_on₃
[s₃ : setoid C]
{D : quot s₁ → quot s₂ → quot s₃ → Prop} (q₁ : quot s₁) (q₂ : quot s₂) (q₃ : quot s₃) (H : ∀ a b c, D ⟦a⟧ ⟦b⟧ ⟦c⟧)
: D q₁ q₂ q₃ :=
quot.ind (λ a₁, quot.ind (λ a₂, quot.ind (λ a₃, H a₁ a₂ a₃) q₃) q₂) q₁
end
section
variables {A B : Type}
variables [s₁ : setoid A] [s₂ : setoid B]
include s₁ s₂
variable {C : quot s₁ → quot s₂ → Type}
protected definition rec_on_subsingleton₂ [reducible]
{C : quot s₁ → quot s₂ → Type₁} [H : ∀ a b, subsingleton (C ⟦a⟧ ⟦b⟧)]
(q₁ : quot s₁) (q₂ : quot s₂) (f : Π a b, C ⟦a⟧ ⟦b⟧) : C q₁ q₂:=
@quot.rec_on_subsingleton _ _ _
(λ a, quot.ind _ _)
q₁ (λ a, quot.rec_on_subsingleton q₂ (λ b, f a b))
end
end quot
|
be0b4c33c6dca3fbc59b0fedd0aac42b05a2cee5 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/order/liminf_limsup.lean | 38e2d9f206cb87764721635266a9bed4b78653c6 | [
"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 | 19,902 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl
-/
import order.filter order.conditionally_complete_lattice order.bounds
/-!
# liminfs and limsups of functions and filters
Defines the Liminf/Limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `f.Limsup` (`f.Liminf`) where `f` is a filter taking values in a conditionally complete
lattice. `f.Limsup` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`f.Liminf`). To work with the Limsup along a function `u` use `(f.map u).Limsup`.
Usually, one defines the Limsup as `Inf (Sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `Inf_n (Sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `Limsup (λx, 1/x)` on ℝ. Then
there is no guarantee that the quantity above really decreases (the value of the `Sup` beforehand is
not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not
use this `Inf Sup ...` definition in conditionally complete lattices, and one has to use a less
tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open filter set
variables {α : Type*} {β : Type*}
namespace filter
section relation
/-- `f.is_bounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def is_bounded (r : α → α → Prop) (f : filter α) := ∃ b, ∀ᶠ x in f, r x b
/-- `f.is_bounded_under (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def is_bounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_bounded r
variables {r : α → α → Prop} {f g : filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
lemma is_bounded_iff : f.is_bounded r ↔ (∃s∈f.sets, ∃b, s ⊆ {x | r x b}) :=
iff.intro
(assume ⟨b, hb⟩, ⟨{a | r a b}, hb, b, subset.refl _⟩)
(assume ⟨s, hs, b, hb⟩, ⟨b, mem_sets_of_superset hs hb⟩)
/-- A bounded function `u` is in particular eventually bounded. -/
lemma is_bounded_under_of {f : filter β} {u : β → α} :
(∃b, ∀x, r (u x) b) → f.is_bounded_under r u
| ⟨b, hb⟩ := ⟨b, show ∀ᶠ x in f, r (u x) b, from eventually_of_forall _ hb⟩
lemma is_bounded_bot : is_bounded r ⊥ ↔ nonempty α :=
by simp [is_bounded, exists_true_iff_nonempty]
lemma is_bounded_top : is_bounded r ⊤ ↔ (∃t, ∀x, r x t) :=
by simp [is_bounded, eq_univ_iff_forall]
lemma is_bounded_principal (s : set α) : is_bounded r (principal s) ↔ (∃t, ∀x∈s, r x t) :=
by simp [is_bounded, subset_def]
lemma is_bounded_sup [is_trans α r] (hr : ∀b₁ b₂, ∃b, r b₁ b ∧ r b₂ b) :
is_bounded r f → is_bounded r g → is_bounded r (f ⊔ g)
| ⟨b₁, h₁⟩ ⟨b₂, h₂⟩ := let ⟨b, rb₁b, rb₂b⟩ := hr b₁ b₂ in
⟨b, eventually_sup.mpr ⟨h₁.mono (λ x h, trans h rb₁b), h₂.mono (λ x h, trans h rb₂b)⟩⟩
lemma is_bounded_of_le (h : f ≤ g) : is_bounded r g → is_bounded r f
| ⟨b, hb⟩ := ⟨b, h hb⟩
lemma is_bounded_under_of_is_bounded {q : β → β → Prop} {u : α → β}
(hf : ∀a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.is_bounded r → f.is_bounded_under q u
| ⟨b, h⟩ := ⟨u b, show ∀ᶠ x in f, q (u x) (u b), from h.mono (λ x, hf x b)⟩
/-- `is_cobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.is_cobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def is_cobounded (r : α → α → Prop) (f : filter α) := ∃b, ∀a, (∀ᶠ x in f, r x a) → r b a
/-- `is_cobounded_under (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def is_cobounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (f.map u).is_cobounded r
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter.-/
lemma is_cobounded.mk [is_trans α r] (a : α) (h : ∀s∈f, ∃x∈s, r a x) : f.is_cobounded r :=
⟨a, assume y s, let ⟨x, h₁, h₂⟩ := h _ s in trans h₂ h₁⟩
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
lemma is_cobounded_of_is_bounded [is_trans α r] (hf : f ≠ ⊥) :
f.is_bounded r → f.is_cobounded (flip r)
| ⟨a, ha⟩ := ⟨a, assume b hb,
have ∀ᶠ x in f, r x a ∧ r b x, from ha.and hb,
let ⟨x, rxa, rbx⟩ := nonempty_of_mem_sets hf this in
show r b a, from trans rbx rxa⟩
lemma is_cobounded_bot : is_cobounded r ⊥ ↔ (∃b, ∀x, r b x) :=
by simp [is_cobounded]
lemma is_cobounded_top : is_cobounded r ⊤ ↔ nonempty α :=
by simp [is_cobounded, eq_univ_iff_forall, exists_true_iff_nonempty] {contextual := tt}
lemma is_cobounded_principal (s : set α) :
(principal s).is_cobounded r↔ (∃b, ∀a, (∀x∈s, r x a) → r b a) :=
by simp [is_cobounded, subset_def]
lemma is_cobounded_of_le (h : f ≤ g) : f.is_cobounded r → g.is_cobounded r
| ⟨b, hb⟩ := ⟨b, assume a ha, hb a (h ha)⟩
end relation
instance is_trans_le [preorder α] : is_trans α (≤) := ⟨assume a b c, le_trans⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
instance is_trans_ge [preorder α] : is_trans α (≥) := ⟨assume a b c h₁ h₂, le_trans h₂ h₁⟩
lemma is_cobounded_le_of_bot [order_bot α] {f : filter α} : f.is_cobounded (≤) :=
⟨⊥, assume a h, bot_le⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_cobounded_ge_of_top [order_top α] {f : filter α} : f.is_cobounded (≥) :=
⟨⊤, assume a h, le_top⟩
lemma is_bounded_le_of_top [order_top α] {f : filter α} : f.is_bounded (≤) :=
⟨⊤, eventually_of_forall _ $ λ _, le_top⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_bounded_ge_of_bot [order_bot α] {f : filter α} : f.is_bounded (≥) :=
⟨⊥, eventually_of_forall _ $ λ _, bot_le⟩
lemma is_bounded_under_sup [semilattice_sup α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≤) u → f.is_bounded_under (≤) v → f.is_bounded_under (≤) (λa, u a ⊔ v a)
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩ ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ :=
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv,
by filter_upwards [hu, hv] assume x, sup_le_sup⟩
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma is_bounded_under_inf [semilattice_inf α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≥) u → f.is_bounded_under (≥) v → f.is_bounded_under (≥) (λa, u a ⊓ v a)
| ⟨bu, (hu : ∀ᶠ x in f, u x ≥ bu)⟩ ⟨bv, (hv : ∀ᶠ x in f, v x ≥ bv)⟩ :=
⟨bu ⊓ bv, show ∀ᶠ x in f, u x ⊓ v x ≥ bu ⊓ bv,
by filter_upwards [hu, hv] assume x, inf_le_inf⟩
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `is_bounded_default` in the statements,
in the form `(hf : f.is_bounded (≥) . is_bounded_default)`. -/
meta def is_bounded_default : tactic unit :=
tactic.applyc ``is_cobounded_le_of_bot <|>
tactic.applyc ``is_cobounded_ge_of_top <|>
tactic.applyc ``is_bounded_le_of_top <|>
tactic.applyc ``is_bounded_ge_of_bot
section conditionally_complete_lattice
variables [conditionally_complete_lattice α]
/-- The `Limsup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def Limsup (f : filter α) : α := Inf { a | ∀ᶠ n in f, n ≤ a }
/-- The `Liminf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def Liminf (f : filter α) : α := Sup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (f : filter β) (u : β → α) : α := (f.map u).Limsup
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (f : filter β) (u : β → α) : α := (f.map u).Liminf
section
variables {f : filter β} {u : β → α}
theorem limsup_eq : f.limsup u = Inf { a | ∀ᶠ n in f, u n ≤ a } := rfl
theorem liminf_eq : f.liminf u = Sup { a | ∀ᶠ n in f, a ≤ u n } := rfl
end
theorem Limsup_le_of_le {f : filter α} {a}
(hf : f.is_cobounded (≤) . is_bounded_default) (h : ∀ᶠ n in f, n ≤ a) : f.Limsup ≤ a :=
cInf_le hf h
theorem le_Liminf_of_le {f : filter α} {a}
(hf : f.is_cobounded (≥) . is_bounded_default) (h : ∀ᶠ n in f, a ≤ n) : a ≤ f.Liminf :=
le_cSup hf h
theorem le_Limsup_of_le {f : filter α} {a}
(hf : f.is_bounded (≤) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) :
a ≤ f.Limsup :=
le_cInf hf h
theorem Liminf_le_of_le {f : filter α} {a}
(hf : f.is_bounded (≥) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) :
f.Liminf ≤ a :=
cSup_le hf h
theorem Liminf_le_Limsup {f : filter α} (hf : f ≠ ⊥)
(h₁ : f.is_bounded (≤) . is_bounded_default) (h₂ : f.is_bounded (≥) . is_bounded_default) :
f.Liminf ≤ f.Limsup :=
Liminf_le_of_le h₂ $ assume a₀ ha₀, le_Limsup_of_le h₁ $ assume a₁ ha₁, show a₀ ≤ a₁, from
have ∀ᶠ b in f, a₀ ≤ b ∧ b ≤ a₁, from ha₀.and ha₁,
let ⟨b, hb₀, hb₁⟩ := nonempty_of_mem_sets hf this in
le_trans hb₀ hb₁
lemma Liminf_le_Liminf {f g : filter α}
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : f.Liminf ≤ g.Liminf :=
cSup_le_cSup hg hf h
lemma Limsup_le_Limsup {f g : filter α}
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : f.Limsup ≤ g.Limsup :=
cInf_le_cInf hf hg h
lemma Limsup_le_Limsup_of_le {f g : filter α} (h : f ≤ g)
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default) :
f.Limsup ≤ g.Limsup :=
Limsup_le_Limsup hf hg (assume a ha, h ha)
lemma Liminf_le_Liminf_of_le {f g : filter α} (h : g ≤ f)
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default) :
f.Liminf ≤ g.Liminf :=
Liminf_le_Liminf hf hg (assume a ha, h ha)
lemma limsup_le_limsup {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.is_cobounded_under (≤) u . is_bounded_default)
(hv : f.is_bounded_under (≤) v . is_bounded_default) :
f.limsup u ≤ f.limsup v :=
Limsup_le_Limsup hu hv $ assume b (hb : ∀ᶠ a in f, v a ≤ b), show ∀ᶠ a in f, u a ≤ b,
by filter_upwards [h, hb] assume a, le_trans
lemma liminf_le_liminf {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hv : f.is_cobounded_under (≥) v . is_bounded_default) :
f.liminf u ≤ f.liminf v :=
Liminf_le_Liminf hu hv $ assume b (hb : ∀ᶠ a in f, b ≤ u a), show ∀ᶠ a in f, b ≤ v a,
by filter_upwards [hb, h] assume a, le_trans
theorem Limsup_principal {s : set α} (h : bdd_above s) (hs : s.nonempty) :
(principal s).Limsup = Sup s :=
by simp [Limsup]; exact cInf_upper_bounds_eq_cSup h hs
theorem Liminf_principal {s : set α} (h : bdd_below s) (hs : s.nonempty) :
(principal s).Liminf = Inf s :=
by simp [Liminf]; exact cSup_lower_bounds_eq_cInf h hs
lemma limsup_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup f u = limsup f v :=
begin
rw limsup_eq,
congr,
ext b,
exact eventually_congr (h.mono $ λ x hx, by simp [hx])
end
lemma liminf_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf f u = liminf f v :=
begin
rw liminf_eq,
congr,
ext b,
exact eventually_congr (h.mono $ λ x hx, by simp [hx])
end
lemma limsup_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} (hf : f ≠ ⊥)
(b : β) : limsup f (λ x, b) = b :=
begin
rw limsup_eq,
apply le_antisymm,
{ refine cInf_le ⟨b, λ a ha, _⟩ (by simp [le_refl]),
obtain ⟨n, hn⟩ : ∃ n, b ≤ a := eventually.exists ha hf,
exact hn },
{ refine le_cInf ⟨b, by simp [le_refl]⟩ (λ a ha, _),
obtain ⟨n, hn⟩ : ∃ n, b ≤ a := eventually.exists ha hf,
exact hn }
end
lemma liminf_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} (hf : f ≠ ⊥)
(b : β) : liminf f (λ x, b) = b :=
begin
rw liminf_eq,
apply le_antisymm,
{ refine cSup_le ⟨b, by simp [le_refl]⟩ (λ a ha, _),
obtain ⟨n, hn⟩ : ∃ n, a ≤ b := eventually.exists ha hf,
exact hn },
{ refine le_cSup ⟨b, λ a ha, _⟩ (by simp [le_refl]),
obtain ⟨n, hn⟩ : ∃ n, a ≤ b := eventually.exists ha hf,
exact hn }
end
end conditionally_complete_lattice
section complete_lattice
variables [complete_lattice α]
@[simp] theorem Limsup_bot : (⊥ : filter α).Limsup = ⊥ :=
bot_unique $ Inf_le $ by simp
@[simp] theorem Liminf_bot : (⊥ : filter α).Liminf = ⊤ :=
top_unique $ le_Sup $ by simp
@[simp] theorem Limsup_top : (⊤ : filter α).Limsup = ⊤ :=
top_unique $ le_Inf $
by simp [eq_univ_iff_forall]; exact assume b hb, (top_unique $ hb _)
@[simp] theorem Liminf_top : (⊤ : filter α).Liminf = ⊥ :=
bot_unique $ Sup_le $
by simp [eq_univ_iff_forall]; exact assume b hb, (bot_unique $ hb _)
lemma liminf_le_limsup {f : filter β} (hf : f ≠ ⊥) {u : β → α} : liminf f u ≤ limsup f u :=
Liminf_le_Limsup (map_ne_bot hf) is_bounded_le_of_top is_bounded_ge_of_bot
theorem Limsup_eq_infi_Sup {f : filter α} : f.Limsup = ⨅ s ∈ f, Sup s :=
le_antisymm
(le_infi $ assume s, le_infi $ assume hs, Inf_le $ show ∀ᶠ n in f, n ≤ Sup s,
by filter_upwards [hs] assume a, le_Sup)
(le_Inf $ assume a (ha : ∀ᶠ n in f, n ≤ a),
infi_le_of_le _ $ infi_le_of_le ha $ Sup_le $ assume b, id)
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_infi_supr {f : filter β} {u : β → α} : f.limsup u = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
calc f.limsup u = ⨅ s ∈ (f.map u), Sup s : Limsup_eq_infi_Sup
... = ⨅ s ∈ f, ⨆ a ∈ s, u a :
le_antisymm
(le_infi $ assume s, le_infi $ assume hs,
infi_le_of_le (u '' s) $ infi_le_of_le (image_mem_map hs) $ le_of_eq Sup_image)
(le_infi $ assume s, le_infi $ assume (hs : u ⁻¹' s ∈ f),
infi_le_of_le _ $ infi_le_of_le hs $ supr_le $ assume a, supr_le $ assume ha, le_Sup ha)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma limsup_eq_infi_supr_of_nat {u : ℕ → α} : limsup at_top u = ⨅n:ℕ, ⨆i≥n, u i :=
calc
limsup at_top u = ⨅ s ∈ at_top, ⨆n∈s, u n : limsup_eq_infi_supr
... = ⨅ n, ⨆i≥n, u i :
le_antisymm
(le_infi $ assume n, infi_le_of_le {i | i ≥ n} $ infi_le_of_le
(mem_at_top _)
(supr_le_supr $ assume i, supr_le_supr_const (by simp)))
(le_infi $ assume s, le_infi $ assume hs,
let ⟨n, hn⟩ := mem_at_top_sets.1 hs in
infi_le_of_le n $ supr_le_supr $ assume i, supr_le_supr_const (hn i))
theorem Liminf_eq_supr_Inf {f : filter α} : f.Liminf = ⨆ s ∈ f, Inf s :=
le_antisymm
(Sup_le $ assume a (ha : ∀ᶠ n in f, a ≤ n),
le_supr_of_le _ $ le_supr_of_le ha $ le_Inf $ assume b, id)
(supr_le $ assume s, supr_le $ assume hs, le_Sup $ show ∀ᶠ n in f, Inf s ≤ n,
by filter_upwards [hs] assume a, Inf_le)
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_supr_infi {f : filter β} {u : β → α} : f.liminf u = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
calc f.liminf u = ⨆ s ∈ f.map u, Inf s : Liminf_eq_supr_Inf
... = ⨆ s ∈ f, ⨅a∈s, u a :
le_antisymm
(supr_le $ assume s, supr_le $ assume (hs : u ⁻¹' s ∈ f),
le_supr_of_le _ $ le_supr_of_le hs $ le_infi $ assume a, le_infi $ assume ha, Inf_le ha)
(supr_le $ assume s, supr_le $ assume hs,
le_supr_of_le (u '' s) $ le_supr_of_le (image_mem_map hs) $ ge_of_eq Inf_image)
@[nolint ge_or_gt] -- see Note [nolint_ge]
lemma liminf_eq_supr_infi_of_nat {u : ℕ → α} : liminf at_top u = ⨆n:ℕ, ⨅i≥n, u i :=
calc
liminf at_top u = ⨆ s ∈ at_top, ⨅ n ∈ s, u n : liminf_eq_supr_infi
... = ⨆n:ℕ, ⨅i≥n, u i :
le_antisymm
(supr_le $ assume s, supr_le $ assume hs,
let ⟨n, hn⟩ := mem_at_top_sets.1 hs in
le_supr_of_le n $ infi_le_infi $ assume i, infi_le_infi_const (hn _) )
(supr_le $ assume n, le_supr_of_le {i | n ≤ i} $
le_supr_of_le
(mem_at_top _)
(infi_le_infi $ assume i, infi_le_infi_const (by simp)))
end complete_lattice
section conditionally_complete_linear_order
lemma eventually_lt_of_lt_liminf {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : b < liminf f u) (hu : f.is_bounded_under (≥) u . is_bounded_default) :
∀ᶠ a in f, b < u a :=
begin
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (hc : c ∈ {c : β | ∀ᶠ (n : α) in f, c ≤ u n}), b < c :=
exists_lt_of_lt_cSup hu h,
exact hc.mono (λ x hx, lt_of_lt_of_le hbc hx)
end
lemma eventually_lt_of_limsup_lt {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : limsup f u < b) (hu : f.is_bounded_under (≤) u . is_bounded_default) :
∀ᶠ a in f, u a < b :=
begin
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (hc : c ∈ {c : β | ∀ᶠ (n : α) in f, u n ≤ c}), c < b :=
exists_lt_of_cInf_lt hu h,
exact hc.mono (λ x hx, lt_of_le_of_lt hx hbc)
end
end conditionally_complete_linear_order
end filter
|
0a03e30aa74d180f8cf5d26e65259e0df5f84619 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/category_theory/bicategory/strict.lean | 7cd3b4d8c3f89e60f7cf4c42594969133aeab7fa | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 3,035 | lean | /-
Copyright (c) 2022 Yuma Mizuno. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yuma Mizuno
-/
import category_theory.eq_to_hom
import category_theory.bicategory.basic
/-!
# Strict bicategories
A bicategory is called `strict` if the left unitors, the right unitors, and the associators are
isomorphisms given by equalities.
## Implementation notes
In the literature of category theory, a strict bicategory (usually called a strict 2-category) is
often defined as a bicategory whose left unitors, right unitors, and associators are identities.
We cannot use this definition directly here since the types of 2-morphisms depend on 1-morphisms.
For this reason, we use `eq_to_iso`, which gives isomorphisms from equalities, instead of
identities.
-/
namespace category_theory
open_locale bicategory
universes w v u
variables (B : Type u) [bicategory.{w v} B]
/--
A bicategory is called `strict` if the left unitors, the right unitors, and the associators are
isomorphisms given by equalities.
-/
class bicategory.strict : Prop :=
(id_comp' : ∀ {a b : B} (f : a ⟶ b), 𝟙 a ≫ f = f . obviously)
(comp_id' : ∀ {a b : B} (f : a ⟶ b), f ≫ 𝟙 b = f . obviously)
(assoc' : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d),
(f ≫ g) ≫ h = f ≫ (g ≫ h) . obviously)
(left_unitor_eq_to_iso' : ∀ {a b : B} (f : a ⟶ b),
λ_ f = eq_to_iso (id_comp' f) . obviously)
(right_unitor_eq_to_iso' : ∀ {a b : B} (f : a ⟶ b),
ρ_ f = eq_to_iso (comp_id' f) . obviously)
(associator_eq_to_iso' : ∀ {a b c d : B} (f : a ⟶ b) (g : b ⟶ c) (h : c ⟶ d),
α_ f g h = eq_to_iso (assoc' f g h) . obviously)
restate_axiom bicategory.strict.id_comp'
restate_axiom bicategory.strict.comp_id'
restate_axiom bicategory.strict.assoc'
restate_axiom bicategory.strict.left_unitor_eq_to_iso'
restate_axiom bicategory.strict.right_unitor_eq_to_iso'
restate_axiom bicategory.strict.associator_eq_to_iso'
attribute [simp]
bicategory.strict.id_comp bicategory.strict.left_unitor_eq_to_iso
bicategory.strict.comp_id bicategory.strict.right_unitor_eq_to_iso
bicategory.strict.assoc bicategory.strict.associator_eq_to_iso
/-- Category structure on a strict bicategory -/
@[priority 100] -- see Note [lower instance priority]
instance strict_bicategory.category [bicategory.strict B] : category B :=
{ id_comp' := λ a b, bicategory.strict.id_comp,
comp_id' := λ a b, bicategory.strict.comp_id,
assoc' := λ a b c d, bicategory.strict.assoc }
namespace bicategory
variables {B}
@[simp]
lemma whisker_left_eq_to_hom {a b c : B} (f : a ⟶ b) {g h : b ⟶ c} (η : g = h) :
f ◁ eq_to_hom η = eq_to_hom (congr_arg2 (≫) rfl η) :=
by { cases η, simp only [whisker_left_id, eq_to_hom_refl] }
@[simp]
lemma eq_to_hom_whisker_right {a b c : B} {f g : a ⟶ b} (η : f = g) (h : b ⟶ c) :
eq_to_hom η ▷ h = eq_to_hom (congr_arg2 (≫) η rfl) :=
by { cases η, simp only [id_whisker_right, eq_to_hom_refl] }
end bicategory
end category_theory
|
68ebfa671f4ab73f1c92087642f94d2c2ca67caa | d450724ba99f5b50b57d244eb41fef9f6789db81 | /src/mywork/Homework/hw6.lean | 1173b81e6ace5556b1276011cdf51a09f330e773 | [] | no_license | jakekauff/CS2120F21 | 4f009adeb4ce4a148442b562196d66cc6c04530c | e69529ec6f5d47a554291c4241a3d8ec4fe8f5ad | refs/heads/main | 1,693,841,880,030 | 1,637,604,848,000 | 1,637,604,848,000 | 399,946,698 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,171 | lean | import data.set
/-
Exercise: Prove that for any set, L, L ∩ L = L.
-/
/-
Exercise: Give a formal statement and proof, then an
English language proof, that the union operator on
sets is commutative.
-/
/-
Exercise: Prove that ⊆ is reflexive and transitive.
Give a formal statement, a formal proof, and an English
language (informal) proof of this fact.
-/
/-
Exercise: Prove that ∪ and ∩ are associative.
Give a formal statement, a formal proof, and an
English language (informal) proof of this fact.
-/
/-
Assignment: read (at least skim) the Sections 1 and 2 of
the Wikipedia page on set identities:
https://en.wikipedia.org/wiki/List_of_set_identities_and_relations
There, , among *many* other facts, you will find definitions
of left and right distributivity. To complete the remainder
of this assignment, you need to understand what it means for
one operator to be left- (or right-) distributive over another.
-/
/-
Exercise: Formally state and prove both formally and
informally that ∩ is left-distributive over ∩.
-/
/-
Exercise: Formally state and prove both formally
and informally that ∪ is left-distributive over ∩.
-/
|
549ad318ac61b85c4ad59a60d08f29768e67714f | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/revert_fail.lean | 33b635f44038b8ea04af1af059ae47bb759ceb8b | [
"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 | 218 | lean | import data.examples.vector
example (A : Type) (n : nat) (v : vector A n) : v = v :=
begin
revert n
end
example (n : nat) : n = n :=
begin
esimp,
revert n
end
example (n : nat) : n = n :=
begin
revert m
end
|
54f6b4613426f226282c761ab08d57a3087185ce | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/homology/short_exact/abelian.lean | 47f08a30936c659c5954bdd0649bbf24f2950c8e | [
"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 | 4,027 | lean | /-
Copyright (c) 2021 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Andrew Yang, Pierre-Alexandre Bazin
-/
import algebra.homology.short_exact.preadditive
import category_theory.abelian.diagram_lemmas.four
/-!
# Short exact sequences in abelian categories
In an abelian category, a left-split or right-split short exact sequence admits a splitting.
-/
noncomputable theory
open category_theory category_theory.limits category_theory.preadditive
variables {𝒜 : Type*} [category 𝒜]
namespace category_theory
variables {A B C A' B' C' : 𝒜} {f : A ⟶ B} {g : B ⟶ C} {f' : A' ⟶ B'} {g' : B' ⟶ C'}
variables [abelian 𝒜]
open_locale zero_object
lemma is_iso_of_short_exact_of_is_iso_of_is_iso (h : short_exact f g) (h' : short_exact f' g')
(i₁ : A ⟶ A') (i₂ : B ⟶ B') (i₃ : C ⟶ C')
(comm₁ : i₁ ≫ f' = f ≫ i₂) (comm₂ : i₂ ≫ g' = g ≫ i₃) [is_iso i₁] [is_iso i₃] :
is_iso i₂ :=
begin
obtain ⟨_⟩ := h,
obtain ⟨_⟩ := h',
resetI,
refine @abelian.is_iso_of_is_iso_of_is_iso_of_is_iso_of_is_iso 𝒜 _ _ 0 _ _ _ 0 _ _ _
0 f g 0 f' g' 0 i₁ i₂ i₃ _ comm₁ comm₂ 0 0 0 0 0 _ _ _ _ _ _ _ _ _ _ _;
try { simp };
try { apply exact_zero_left_of_mono };
try { assumption };
rwa ← epi_iff_exact_zero_right,
end
/-- To construct a splitting of `A -f⟶ B -g⟶ C` it suffices to supply
a *morphism* `i : B ⟶ A ⊞ C` such that `f ≫ i` is the canonical map `biprod.inl : A ⟶ A ⊞ C` and
`i ≫ q = g`, where `q` is the canonical map `biprod.snd : A ⊞ C ⟶ C`,
together with proofs that `f` is mono and `g` is epi.
The morphism `i` is then automatically an isomorphism. -/
def splitting.mk' (h : short_exact f g) (i : B ⟶ A ⊞ C)
(h1 : f ≫ i = biprod.inl) (h2 : i ≫ biprod.snd = g) : splitting f g :=
{ iso :=
begin
refine @as_iso _ _ _ _ i (id _),
refine is_iso_of_short_exact_of_is_iso_of_is_iso h _ _ _ _
(h1.trans (category.id_comp _).symm).symm (h2.trans (category.comp_id _).symm),
split,
apply exact_inl_snd
end,
comp_iso_eq_inl := by { rwa as_iso_hom, },
iso_comp_snd_eq := h2 }
/-- To construct a splitting of `A -f⟶ B -g⟶ C` it suffices to supply
a *morphism* `i : A ⊞ C ⟶ B` such that `p ≫ i = f` where `p` is the canonical map
`biprod.inl : A ⟶ A ⊞ C`, and `i ≫ g` is the canonical map `biprod.snd : A ⊞ C ⟶ C`,
together with proofs that `f` is mono and `g` is epi.
The morphism `i` is then automatically an isomorphism. -/
def splitting.mk'' (h : short_exact f g) (i : A ⊞ C ⟶ B)
(h1 : biprod.inl ≫ i = f) (h2 : i ≫ g = biprod.snd) : splitting f g :=
{ iso :=
begin
refine (@as_iso _ _ _ _ i (id _)).symm,
refine is_iso_of_short_exact_of_is_iso_of_is_iso _ h _ _ _
(h1.trans (category.id_comp _).symm).symm (h2.trans (category.comp_id _).symm),
split,
apply exact_inl_snd
end,
comp_iso_eq_inl := by rw [iso.symm_hom, as_iso_inv, is_iso.comp_inv_eq, h1],
iso_comp_snd_eq := by rw [iso.symm_hom, as_iso_inv, is_iso.inv_comp_eq, h2] }
/-- A short exact sequence that is left split admits a splitting. -/
def left_split.splitting {f : A ⟶ B} {g : B ⟶ C} (h : left_split f g) : splitting f g :=
splitting.mk' h.short_exact (biprod.lift h.left_split.some g)
(by { ext,
{ simpa only [biprod.inl_fst, biprod.lift_fst, category.assoc] using h.left_split.some_spec },
{ simp only [biprod.inl_snd, biprod.lift_snd, category.assoc, h.exact.w], } })
(by { simp only [biprod.lift_snd], })
/-- A short exact sequence that is right split admits a splitting. -/
def right_split.splitting {f : A ⟶ B} {g : B ⟶ C} (h : right_split f g) : splitting f g :=
splitting.mk'' h.short_exact (biprod.desc f h.right_split.some)
(biprod.inl_desc _ _)
(by { ext,
{ rw [biprod.inl_snd, ← category.assoc, biprod.inl_desc, h.exact.w] },
{ rw [biprod.inr_snd, ← category.assoc, biprod.inr_desc, h.right_split.some_spec] } })
end category_theory
|
5119c76588eb7f7bf7c787cdcf2638cc159b7cf9 | 137c667471a40116a7afd7261f030b30180468c2 | /src/analysis/special_functions/pow.lean | 99b43511414eac9d168708af723ba8769ac9edbf | [
"Apache-2.0"
] | permissive | bragadeesh153/mathlib | 46bf814cfb1eecb34b5d1549b9117dc60f657792 | b577bb2cd1f96eb47031878256856020b76f73cd | refs/heads/master | 1,687,435,188,334 | 1,626,384,207,000 | 1,626,384,207,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 70,344 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Abhimanyu Pallavi Sudhir, Jean Lo, Calle Sönne, Sébastien Gouëzel,
Rémy Degenne
-/
import analysis.special_functions.trigonometric
import analysis.calculus.extend_deriv
/-!
# Power function on `ℂ`, `ℝ`, `ℝ≥0`, and `ℝ≥0∞`
We construct the power functions `x ^ y` where
* `x` and `y` are complex numbers,
* or `x` and `y` are real numbers,
* or `x` is a nonnegative real number and `y` is a real number;
* or `x` is a number from `[0, +∞]` (a.k.a. `ℝ≥0∞`) and `y` is a real number.
We also prove basic properties of these functions.
-/
noncomputable theory
open_locale classical real topological_space nnreal ennreal filter
open filter
namespace complex
/-- The complex power function `x^y`, given by `x^y = exp(y log x)` (where `log` is the principal
determination of the logarithm), unless `x = 0` where one sets `0^0 = 1` and `0^y = 0` for
`y ≠ 0`. -/
noncomputable def cpow (x y : ℂ) : ℂ :=
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y)
noncomputable instance : has_pow ℂ ℂ := ⟨cpow⟩
@[simp] lemma cpow_eq_pow (x y : ℂ) : cpow x y = x ^ y := rfl
lemma cpow_def (x y : ℂ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y) := rfl
lemma cpow_def_of_ne_zero {x : ℂ} (hx : x ≠ 0) (y : ℂ) : x ^ y = exp (log x * y) := if_neg hx
@[simp] lemma cpow_zero (x : ℂ) : x ^ (0 : ℂ) = 1 := by simp [cpow_def]
@[simp] lemma cpow_eq_zero_iff (x y : ℂ) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
by { simp only [cpow_def], split_ifs; simp [*, exp_ne_zero] }
@[simp] lemma zero_cpow {x : ℂ} (h : x ≠ 0) : (0 : ℂ) ^ x = 0 :=
by simp [cpow_def, *]
@[simp] lemma cpow_one (x : ℂ) : x ^ (1 : ℂ) = x :=
if hx : x = 0 then by simp [hx, cpow_def]
else by rw [cpow_def, if_neg (one_ne_zero : (1 : ℂ) ≠ 0), if_neg hx, mul_one, exp_log hx]
@[simp] lemma one_cpow (x : ℂ) : (1 : ℂ) ^ x = 1 :=
by rw cpow_def; split_ifs; simp [one_ne_zero, *] at *
lemma cpow_add {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y + z) = x ^ y * x ^ z :=
by simp [cpow_def]; split_ifs; simp [*, exp_add, mul_add] at *
lemma cpow_mul {x y : ℂ} (z : ℂ) (h₁ : -π < (log x * y).im) (h₂ : (log x * y).im ≤ π) :
x ^ (y * z) = (x ^ y) ^ z :=
begin
simp only [cpow_def],
split_ifs;
simp [*, exp_ne_zero, log_exp h₁ h₂, mul_assoc] at *
end
lemma cpow_neg (x y : ℂ) : x ^ -y = (x ^ y)⁻¹ :=
by simp [cpow_def]; split_ifs; simp [exp_neg]
lemma cpow_sub {x : ℂ} (y z : ℂ) (hx : x ≠ 0) : x ^ (y - z) = x ^ y / x ^ z :=
by rw [sub_eq_add_neg, cpow_add _ _ hx, cpow_neg, div_eq_mul_inv]
lemma cpow_neg_one (x : ℂ) : x ^ (-1 : ℂ) = x⁻¹ :=
by simpa using cpow_neg x 1
@[simp] lemma cpow_nat_cast (x : ℂ) : ∀ (n : ℕ), x ^ (n : ℂ) = x ^ n
| 0 := by simp
| (n + 1) := if hx : x = 0 then by simp only [hx, pow_succ,
complex.zero_cpow (nat.cast_ne_zero.2 (nat.succ_ne_zero _)), zero_mul]
else by simp [cpow_add, hx, pow_add, cpow_nat_cast n]
@[simp] lemma cpow_int_cast (x : ℂ) : ∀ (n : ℤ), x ^ (n : ℂ) = x ^ n
| (n : ℕ) := by simp; refl
| -[1+ n] := by rw gpow_neg_succ_of_nat;
simp only [int.neg_succ_of_nat_coe, int.cast_neg, complex.cpow_neg, inv_eq_one_div,
int.cast_coe_nat, cpow_nat_cast]
lemma cpow_nat_inv_pow (x : ℂ) {n : ℕ} (hn : 0 < n) : (x ^ (n⁻¹ : ℂ)) ^ n = x :=
begin
suffices : im (log x * n⁻¹) ∈ set.Ioc (-π) π,
{ rw [← cpow_nat_cast, ← cpow_mul _ this.1 this.2, inv_mul_cancel, cpow_one],
exact_mod_cast hn.ne' },
rw [mul_comm, ← of_real_nat_cast, ← of_real_inv, of_real_mul_im, ← div_eq_inv_mul],
have hn' : 0 < (n : ℝ), by assumption_mod_cast,
have hn1 : 1 ≤ (n : ℝ), by exact_mod_cast (nat.succ_le_iff.2 hn),
split,
{ rw lt_div_iff hn',
calc -π * n ≤ -π * 1 : mul_le_mul_of_nonpos_left hn1 (neg_nonpos.2 real.pi_pos.le)
... = -π : mul_one _
... < im (log x) : neg_pi_lt_log_im _ },
{ rw div_le_iff hn',
calc im (log x) ≤ π : log_im_le_pi _
... = π * 1 : (mul_one π).symm
... ≤ π * n : mul_le_mul_of_nonneg_left hn1 real.pi_pos.le }
end
lemma has_strict_fderiv_at_cpow {p : ℂ × ℂ} (hp : 0 < p.1.re ∨ p.1.im ≠ 0) :
has_strict_fderiv_at (λ x : ℂ × ℂ, x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • continuous_linear_map.fst ℂ ℂ ℂ +
(p.1 ^ p.2 * log p.1) • continuous_linear_map.snd ℂ ℂ ℂ) p :=
begin
have A : p.1 ≠ 0, by { intro h, simpa [h, lt_irrefl] using hp },
have : (λ x : ℂ × ℂ, x.1 ^ x.2) =ᶠ[𝓝 p] (λ x, exp (log x.1 * x.2)),
from ((is_open_ne.preimage continuous_fst).eventually_mem A).mono
(λ p hp, cpow_def_of_ne_zero hp _),
rw [cpow_sub _ _ A, cpow_one, mul_div_comm, mul_smul, mul_smul, ← smul_add],
refine has_strict_fderiv_at.congr_of_eventually_eq _ this.symm,
simpa only [cpow_def_of_ne_zero A, div_eq_mul_inv, smul_smul, add_comm]
using ((has_strict_fderiv_at_fst.clog hp).mul has_strict_fderiv_at_snd).cexp
end
lemma has_strict_deriv_at_const_cpow {x y : ℂ} (h : x ≠ 0 ∨ y ≠ 0) :
has_strict_deriv_at (λ y, x ^ y) (x ^ y * log x) y :=
begin
rcases em (x = 0) with rfl|hx,
{ replace h := h.neg_resolve_left rfl,
rw [log_zero, mul_zero],
refine (has_strict_deriv_at_const _ 0).congr_of_eventually_eq _,
exact (is_open_ne.eventually_mem h).mono (λ y hy, (zero_cpow hy).symm) },
{ simpa only [cpow_def_of_ne_zero hx, mul_one]
using ((has_strict_deriv_at_id y).const_mul (log x)).cexp }
end
lemma has_fderiv_at_cpow {p : ℂ × ℂ} (hp : 0 < p.1.re ∨ p.1.im ≠ 0) :
has_fderiv_at (λ x : ℂ × ℂ, x.1 ^ x.2)
((p.2 * p.1 ^ (p.2 - 1)) • continuous_linear_map.fst ℂ ℂ ℂ +
(p.1 ^ p.2 * log p.1) • continuous_linear_map.snd ℂ ℂ ℂ) p :=
(has_strict_fderiv_at_cpow hp).has_fderiv_at
end complex
section lim
open complex
variables {α : Type*}
lemma filter.tendsto.cpow {l : filter α} {f g : α → ℂ} {a b : ℂ} (hf : tendsto f l (𝓝 a))
(hg : tendsto g l (𝓝 b)) (ha : 0 < a.re ∨ a.im ≠ 0) :
tendsto (λ x, f x ^ g x) l (𝓝 (a ^ b)) :=
(@has_fderiv_at_cpow (a, b) ha).continuous_at.tendsto.comp (hf.prod_mk_nhds hg)
lemma filter.tendsto.const_cpow {l : filter α} {f : α → ℂ} {a b : ℂ} (hf : tendsto f l (𝓝 b))
(h : a ≠ 0 ∨ b ≠ 0) :
tendsto (λ x, a ^ f x) l (𝓝 (a ^ b)) :=
(has_strict_deriv_at_const_cpow h).continuous_at.tendsto.comp hf
variables [topological_space α] {f g : α → ℂ} {s : set α} {a : α}
lemma continuous_within_at.cpow (hf : continuous_within_at f s a) (hg : continuous_within_at g s a)
(h0 : 0 < (f a).re ∨ (f a).im ≠ 0) :
continuous_within_at (λ x, f x ^ g x) s a :=
hf.cpow hg h0
lemma continuous_within_at.const_cpow {b : ℂ} (hf : continuous_within_at f s a)
(h : b ≠ 0 ∨ f a ≠ 0) :
continuous_within_at (λ x, b ^ f x) s a :=
hf.const_cpow h
lemma continuous_at.cpow (hf : continuous_at f a) (hg : continuous_at g a)
(h0 : 0 < (f a).re ∨ (f a).im ≠ 0) :
continuous_at (λ x, f x ^ g x) a :=
hf.cpow hg h0
lemma continuous_at.const_cpow {b : ℂ} (hf : continuous_at f a) (h : b ≠ 0 ∨ f a ≠ 0) :
continuous_at (λ x, b ^ f x) a :=
hf.const_cpow h
lemma continuous_on.cpow (hf : continuous_on f s) (hg : continuous_on g s)
(h0 : ∀ a ∈ s, 0 < (f a).re ∨ (f a).im ≠ 0) :
continuous_on (λ x, f x ^ g x) s :=
λ a ha, (hf a ha).cpow (hg a ha) (h0 a ha)
lemma continuous_on.const_cpow {b : ℂ} (hf : continuous_on f s) (h : b ≠ 0 ∨ ∀ a ∈ s, f a ≠ 0) :
continuous_on (λ x, b ^ f x) s :=
λ a ha, (hf a ha).const_cpow (h.imp id $ λ h, h a ha)
lemma continuous.cpow (hf : continuous f) (hg : continuous g)
(h0 : ∀ a, 0 < (f a).re ∨ (f a).im ≠ 0) :
continuous (λ x, f x ^ g x) :=
continuous_iff_continuous_at.2 $ λ a, (hf.continuous_at.cpow hg.continuous_at (h0 a))
lemma continuous.const_cpow {b : ℂ} (hf : continuous f) (h : b ≠ 0 ∨ ∀ a, f a ≠ 0) :
continuous (λ x, b ^ f x) :=
continuous_iff_continuous_at.2 $ λ a, (hf.continuous_at.const_cpow $ h.imp id $ λ h, h a)
end lim
section fderiv
open complex
variables {E : Type*} [normed_group E] [normed_space ℂ E] {f g : E → ℂ} {f' g' : E →L[ℂ] ℂ}
{x : E} {s : set E} {c : ℂ}
lemma has_strict_fderiv_at.cpow (hf : has_strict_fderiv_at f f' x)
(hg : has_strict_fderiv_at g g' x) (h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_fderiv_at (λ x, f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * log (f x)) • g') x :=
by convert (@has_strict_fderiv_at_cpow ((λ x, (f x, g x)) x) h0).comp x (hf.prod hg)
lemma has_strict_fderiv_at.const_cpow (hf : has_strict_fderiv_at f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
has_strict_fderiv_at (λ x, c ^ f x) ((c ^ f x * log c) • f') x :=
(has_strict_deriv_at_const_cpow h0).comp_has_strict_fderiv_at x hf
lemma has_fderiv_at.cpow (hf : has_fderiv_at f f' x) (hg : has_fderiv_at g g' x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_at (λ x, f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * log (f x)) • g') x :=
by convert (@complex.has_fderiv_at_cpow ((λ x, (f x, g x)) x) h0).comp x (hf.prod hg)
lemma has_fderiv_at.const_cpow (hf : has_fderiv_at f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
has_fderiv_at (λ x, c ^ f x) ((c ^ f x * log c) • f') x :=
(has_strict_deriv_at_const_cpow h0).has_deriv_at.comp_has_fderiv_at x hf
lemma has_fderiv_within_at.cpow (hf : has_fderiv_within_at f f' s x)
(hg : has_fderiv_within_at g g' s x) (h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_within_at (λ x, f x ^ g x)
((g x * f x ^ (g x - 1)) • f' + (f x ^ g x * log (f x)) • g') s x :=
by convert (@complex.has_fderiv_at_cpow ((λ x, (f x, g x)) x) h0).comp_has_fderiv_within_at x
(hf.prod hg)
lemma has_fderiv_within_at.const_cpow (hf : has_fderiv_within_at f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
has_fderiv_within_at (λ x, c ^ f x) ((c ^ f x * log c) • f') s x :=
(has_strict_deriv_at_const_cpow h0).has_deriv_at.comp_has_fderiv_within_at x hf
lemma differentiable_at.cpow (hf : differentiable_at ℂ f x) (hg : differentiable_at ℂ g x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_at ℂ (λ x, f x ^ g x) x :=
(hf.has_fderiv_at.cpow hg.has_fderiv_at h0).differentiable_at
lemma differentiable_at.const_cpow (hf : differentiable_at ℂ f x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
differentiable_at ℂ (λ x, c ^ f x) x :=
(hf.has_fderiv_at.const_cpow h0).differentiable_at
lemma differentiable_within_at.cpow (hf : differentiable_within_at ℂ f s x)
(hg : differentiable_within_at ℂ g s x) (h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_within_at ℂ (λ x, f x ^ g x) s x :=
(hf.has_fderiv_within_at.cpow hg.has_fderiv_within_at h0).differentiable_within_at
lemma differentiable_within_at.const_cpow (hf : differentiable_within_at ℂ f s x)
(h0 : c ≠ 0 ∨ f x ≠ 0) :
differentiable_within_at ℂ (λ x, c ^ f x) s x :=
(hf.has_fderiv_within_at.const_cpow h0).differentiable_within_at
end fderiv
section deriv
open complex
variables {f g : ℂ → ℂ} {s : set ℂ} {f' g' x c : ℂ}
/-- A private lemma that rewrites the output of lemmas like `has_fderiv_at.cpow` to the form
expected by lemmas like `has_deriv_at.cpow`. -/
private lemma aux :
((g x * f x ^ (g x - 1)) • (1 : ℂ →L[ℂ] ℂ).smul_right f' +
(f x ^ g x * log (f x)) • (1 : ℂ →L[ℂ] ℂ).smul_right g') 1 =
g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g' :=
by simp only [algebra.id.smul_eq_mul, one_mul, continuous_linear_map.one_apply,
continuous_linear_map.smul_right_apply, continuous_linear_map.add_apply, pi.smul_apply,
continuous_linear_map.coe_smul']
lemma has_strict_deriv_at.cpow (hf : has_strict_deriv_at f f' x) (hg : has_strict_deriv_at g g' x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ x, f x ^ g x)
(g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g') x :=
by simpa only [aux] using (hf.cpow hg h0).has_strict_deriv_at
lemma has_strict_deriv_at.const_cpow (hf : has_strict_deriv_at f f' x) (h : c ≠ 0 ∨ f x ≠ 0) :
has_strict_deriv_at (λ x, c ^ f x) (c ^ f x * log c * f') x :=
(has_strict_deriv_at_const_cpow h).comp x hf
lemma complex.has_strict_deriv_at_cpow_const (h : 0 < x.re ∨ x.im ≠ 0) :
has_strict_deriv_at (λ z : ℂ, z ^ c) (c * x ^ (c - 1)) x :=
by simpa only [mul_zero, add_zero, mul_one]
using (has_strict_deriv_at_id x).cpow (has_strict_deriv_at_const x c) h
lemma has_strict_deriv_at.cpow_const (hf : has_strict_deriv_at f f' x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ x, f x ^ c) (c * f x ^ (c - 1) * f') x :=
(complex.has_strict_deriv_at_cpow_const h0).comp x hf
lemma has_deriv_at.cpow (hf : has_deriv_at f f' x) (hg : has_deriv_at g g' x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ x, f x ^ g x) (g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g') x :=
by simpa only [aux] using (hf.has_fderiv_at.cpow hg h0).has_deriv_at
lemma has_deriv_at.const_cpow (hf : has_deriv_at f f' x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
has_deriv_at (λ x, c ^ f x) (c ^ f x * log c * f') x :=
(has_strict_deriv_at_const_cpow h0).has_deriv_at.comp x hf
lemma has_deriv_at.cpow_const (hf : has_deriv_at f f' x) (h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ x, f x ^ c) (c * f x ^ (c - 1) * f') x :=
(complex.has_strict_deriv_at_cpow_const h0).has_deriv_at.comp x hf
lemma has_deriv_within_at.cpow (hf : has_deriv_within_at f f' s x)
(hg : has_deriv_within_at g g' s x) (h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ x, f x ^ g x)
(g x * f x ^ (g x - 1) * f' + f x ^ g x * log (f x) * g') s x :=
by simpa only [aux] using (hf.has_fderiv_within_at.cpow hg h0).has_deriv_within_at
lemma has_deriv_within_at.const_cpow (hf : has_deriv_within_at f f' s x) (h0 : c ≠ 0 ∨ f x ≠ 0) :
has_deriv_within_at (λ x, c ^ f x) (c ^ f x * log c * f') s x :=
(has_strict_deriv_at_const_cpow h0).has_deriv_at.comp_has_deriv_within_at x hf
lemma has_deriv_within_at.cpow_const (hf : has_deriv_within_at f f' s x)
(h0 : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ x, f x ^ c) (c * f x ^ (c - 1) * f') s x :=
(complex.has_strict_deriv_at_cpow_const h0).has_deriv_at.comp_has_deriv_within_at x hf
end deriv
namespace real
/-- The real power function `x^y`, defined as the real part of the complex power function.
For `x > 0`, it is equal to `exp(y log x)`. For `x = 0`, one sets `0^0=1` and `0^y=0` for `y ≠ 0`.
For `x < 0`, the definition is somewhat arbitary as it depends on the choice of a complex
determination of the logarithm. With our conventions, it is equal to `exp (y log x) cos (πy)`. -/
noncomputable def rpow (x y : ℝ) := ((x : ℂ) ^ (y : ℂ)).re
noncomputable instance : has_pow ℝ ℝ := ⟨rpow⟩
@[simp] lemma rpow_eq_pow (x y : ℝ) : rpow x y = x ^ y := rfl
lemma rpow_def (x y : ℝ) : x ^ y = ((x : ℂ) ^ (y : ℂ)).re := rfl
lemma rpow_def_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y) :=
by simp only [rpow_def, complex.cpow_def];
split_ifs;
simp [*, (complex.of_real_log hx).symm, -complex.of_real_mul, -is_R_or_C.of_real_mul,
(complex.of_real_mul _ _).symm, complex.exp_of_real_re] at *
lemma rpow_def_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : x ^ y = exp (log x * y) :=
by rw [rpow_def_of_nonneg (le_of_lt hx), if_neg (ne_of_gt hx)]
lemma exp_mul (x y : ℝ) : exp (x * y) = (exp x) ^ y :=
by rw [rpow_def_of_pos (exp_pos _), log_exp]
lemma rpow_eq_zero_iff_of_nonneg {x y : ℝ} (hx : 0 ≤ x) : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
by { simp only [rpow_def_of_nonneg hx], split_ifs; simp [*, exp_ne_zero] }
open_locale real
lemma rpow_def_of_neg {x : ℝ} (hx : x < 0) (y : ℝ) : x ^ y = exp (log x * y) * cos (y * π) :=
begin
rw [rpow_def, complex.cpow_def, if_neg],
have : complex.log x * y = ↑(log(-x) * y) + ↑(y * π) * complex.I,
{ simp only [complex.log, abs_of_neg hx, complex.arg_of_real_of_neg hx,
complex.abs_of_real, complex.of_real_mul], ring },
{ rw [this, complex.exp_add_mul_I, ← complex.of_real_exp, ← complex.of_real_cos,
← complex.of_real_sin, mul_add, ← complex.of_real_mul, ← mul_assoc, ← complex.of_real_mul,
complex.add_re, complex.of_real_re, complex.mul_re, complex.I_re, complex.of_real_im,
real.log_neg_eq_log],
ring },
{ rw complex.of_real_eq_zero, exact ne_of_lt hx }
end
lemma rpow_def_of_nonpos {x : ℝ} (hx : x ≤ 0) (y : ℝ) : x ^ y =
if x = 0
then if y = 0
then 1
else 0
else exp (log x * y) * cos (y * π) :=
by split_ifs; simp [rpow_def, *]; exact rpow_def_of_neg (lt_of_le_of_ne hx h) _
lemma rpow_pos_of_pos {x : ℝ} (hx : 0 < x) (y : ℝ) : 0 < x ^ y :=
by rw rpow_def_of_pos hx; apply exp_pos
@[simp] lemma rpow_zero (x : ℝ) : x ^ (0 : ℝ) = 1 := by simp [rpow_def]
@[simp] lemma zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ) ^ x = 0 :=
by simp [rpow_def, *]
@[simp] lemma rpow_one (x : ℝ) : x ^ (1 : ℝ) = x := by simp [rpow_def]
@[simp] lemma one_rpow (x : ℝ) : (1 : ℝ) ^ x = 1 := by simp [rpow_def]
lemma zero_rpow_le_one (x : ℝ) : (0 : ℝ) ^ x ≤ 1 :=
by { by_cases h : x = 0; simp [h, zero_le_one] }
lemma zero_rpow_nonneg (x : ℝ) : 0 ≤ (0 : ℝ) ^ x :=
by { by_cases h : x = 0; simp [h, zero_le_one] }
lemma rpow_nonneg_of_nonneg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : 0 ≤ x ^ y :=
by rw [rpow_def_of_nonneg hx];
split_ifs; simp only [zero_le_one, le_refl, le_of_lt (exp_pos _)]
lemma abs_rpow_le_abs_rpow (x y : ℝ) : abs (x ^ y) ≤ abs (x) ^ y :=
begin
rcases lt_trichotomy 0 x with (hx|rfl|hx),
{ rw [abs_of_pos hx, abs_of_pos (rpow_pos_of_pos hx _)] },
{ rw [abs_zero, abs_of_nonneg (rpow_nonneg_of_nonneg le_rfl _)] },
{ rw [abs_of_neg hx, rpow_def_of_neg hx, rpow_def_of_pos (neg_pos.2 hx), log_neg_eq_log,
abs_mul, abs_of_pos (exp_pos _)],
exact mul_le_of_le_one_right (exp_pos _).le (abs_cos_le_one _) }
end
lemma abs_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : abs (x ^ y) = (abs x) ^ y :=
begin
have h_rpow_nonneg : 0 ≤ x ^ y, from real.rpow_nonneg_of_nonneg hx_nonneg _,
rw [abs_eq_self.mpr hx_nonneg, abs_eq_self.mpr h_rpow_nonneg],
end
lemma norm_rpow_of_nonneg {x y : ℝ} (hx_nonneg : 0 ≤ x) : ∥x ^ y∥ = ∥x∥ ^ y :=
by { simp_rw real.norm_eq_abs, exact abs_rpow_of_nonneg hx_nonneg, }
end real
namespace complex
lemma of_real_cpow {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : ((x ^ y : ℝ) : ℂ) = (x : ℂ) ^ (y : ℂ) :=
by simp [real.rpow_def_of_nonneg hx, complex.cpow_def]; split_ifs; simp [complex.of_real_log hx]
@[simp] lemma abs_cpow_real (x : ℂ) (y : ℝ) : abs (x ^ (y : ℂ)) = x.abs ^ y :=
begin
rw [real.rpow_def_of_nonneg (abs_nonneg _), complex.cpow_def],
split_ifs;
simp [*, abs_of_nonneg (le_of_lt (real.exp_pos _)), complex.log, complex.exp_add,
add_mul, mul_right_comm _ I, exp_mul_I, abs_cos_add_sin_mul_I,
(complex.of_real_mul _ _).symm, -complex.of_real_mul, -is_R_or_C.of_real_mul] at *
end
@[simp] lemma abs_cpow_inv_nat (x : ℂ) (n : ℕ) : abs (x ^ (n⁻¹ : ℂ)) = x.abs ^ (n⁻¹ : ℝ) :=
by rw ← abs_cpow_real; simp [-abs_cpow_real]
end complex
namespace real
variables {x y z : ℝ}
lemma rpow_add {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
by simp only [rpow_def_of_pos hx, mul_add, exp_add]
lemma rpow_add' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z :=
begin
rcases le_iff_eq_or_lt.1 hx with H|pos,
{ simp only [← H, h, rpow_eq_zero_iff_of_nonneg, true_and, zero_rpow, eq_self_iff_true, ne.def,
not_false_iff, zero_eq_mul],
by_contradiction F,
push_neg at F,
apply h,
simp [F] },
{ exact rpow_add pos _ _ }
end
/-- For `0 ≤ x`, the only problematic case in the equality `x ^ y * x ^ z = x ^ (y + z)` is for
`x = 0` and `y + z = 0`, where the right hand side is `1` while the left hand side can vanish.
The inequality is always true, though, and given in this lemma. -/
lemma le_rpow_add {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ y * x ^ z ≤ x ^ (y + z) :=
begin
rcases le_iff_eq_or_lt.1 hx with H|pos,
{ by_cases h : y + z = 0,
{ simp only [H.symm, h, rpow_zero],
calc (0 : ℝ) ^ y * 0 ^ z ≤ 1 * 1 :
mul_le_mul (zero_rpow_le_one y) (zero_rpow_le_one z) (zero_rpow_nonneg z) zero_le_one
... = 1 : by simp },
{ simp [rpow_add', ← H, h] } },
{ simp [rpow_add pos] }
end
lemma rpow_mul {x : ℝ} (hx : 0 ≤ x) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
by rw [← complex.of_real_inj, complex.of_real_cpow (rpow_nonneg_of_nonneg hx _),
complex.of_real_cpow hx, complex.of_real_mul, complex.cpow_mul, complex.of_real_cpow hx];
simp only [(complex.of_real_mul _ _).symm, (complex.of_real_log hx).symm,
complex.of_real_im, neg_lt_zero, pi_pos, le_of_lt pi_pos]
lemma rpow_neg {x : ℝ} (hx : 0 ≤ x) (y : ℝ) : x ^ -y = (x ^ y)⁻¹ :=
by simp only [rpow_def_of_nonneg hx]; split_ifs; simp [*, exp_neg] at *
lemma rpow_sub {x : ℝ} (hx : 0 < x) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
by simp only [sub_eq_add_neg, rpow_add hx, rpow_neg (le_of_lt hx), div_eq_mul_inv]
lemma rpow_sub' {x : ℝ} (hx : 0 ≤ x) {y z : ℝ} (h : y - z ≠ 0) :
x ^ (y - z) = x ^ y / x ^ z :=
by { simp only [sub_eq_add_neg] at h ⊢, simp only [rpow_add' hx h, rpow_neg hx, div_eq_mul_inv] }
@[simp] lemma rpow_nat_cast (x : ℝ) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
by simp only [rpow_def, (complex.of_real_pow _ _).symm, complex.cpow_nat_cast,
complex.of_real_nat_cast, complex.of_real_re]
@[simp] lemma rpow_int_cast (x : ℝ) (n : ℤ) : x ^ (n : ℝ) = x ^ n :=
by simp only [rpow_def, (complex.of_real_fpow _ _).symm, complex.cpow_int_cast,
complex.of_real_int_cast, complex.of_real_re]
lemma rpow_neg_one (x : ℝ) : x ^ (-1 : ℝ) = x⁻¹ :=
begin
suffices H : x ^ ((-1 : ℤ) : ℝ) = x⁻¹, by exact_mod_cast H,
simp only [rpow_int_cast, gpow_one, fpow_neg],
end
lemma mul_rpow {x y z : ℝ} (h : 0 ≤ x) (h₁ : 0 ≤ y) : (x*y)^z = x^z * y^z :=
begin
iterate 3 { rw real.rpow_def_of_nonneg }, split_ifs; simp * at *,
{ have hx : 0 < x,
{ cases lt_or_eq_of_le h with h₂ h₂, { exact h₂ },
exfalso, apply h_2, exact eq.symm h₂ },
have hy : 0 < y,
{ cases lt_or_eq_of_le h₁ with h₂ h₂, { exact h₂ },
exfalso, apply h_3, exact eq.symm h₂ },
rw [log_mul (ne_of_gt hx) (ne_of_gt hy), add_mul, exp_add]},
{ exact h₁ },
{ exact h },
{ exact mul_nonneg h h₁ },
end
lemma inv_rpow (hx : 0 ≤ x) (y : ℝ) : (x⁻¹)^y = (x^y)⁻¹ :=
begin
by_cases hy0 : y = 0, { simp [*] },
by_cases hx0 : x = 0, { simp [*] },
simp only [real.rpow_def_of_nonneg hx, real.rpow_def_of_nonneg (inv_nonneg.2 hx), if_false,
hx0, mt inv_eq_zero.1 hx0, log_inv, ← neg_mul_eq_neg_mul, exp_neg]
end
lemma div_rpow (hx : 0 ≤ x) (hy : 0 ≤ y) (z : ℝ) : (x / y) ^ z = x^z / y^z :=
by simp only [div_eq_mul_inv, mul_rpow hx (inv_nonneg.2 hy), inv_rpow hy]
lemma log_rpow {x : ℝ} (hx : 0 < x) (y : ℝ) : log (x^y) = y * (log x) :=
begin
apply exp_injective,
rw [exp_log (rpow_pos_of_pos hx y), ← exp_log hx, mul_comm, rpow_def_of_pos (exp_pos (log x)) y],
end
lemma rpow_lt_rpow (hx : 0 ≤ x) (hxy : x < y) (hz : 0 < z) : x^z < y^z :=
begin
rw le_iff_eq_or_lt at hx, cases hx,
{ rw [← hx, zero_rpow (ne_of_gt hz)], exact rpow_pos_of_pos (by rwa ← hx at hxy) _ },
rw [rpow_def_of_pos hx, rpow_def_of_pos (lt_trans hx hxy), exp_lt_exp],
exact mul_lt_mul_of_pos_right (log_lt_log hx hxy) hz
end
lemma rpow_le_rpow {x y z: ℝ} (h : 0 ≤ x) (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
begin
rcases eq_or_lt_of_le h₁ with rfl|h₁', { refl },
rcases eq_or_lt_of_le h₂ with rfl|h₂', { simp },
exact le_of_lt (rpow_lt_rpow h h₁' h₂')
end
lemma rpow_lt_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
⟨lt_imp_lt_of_le_imp_le $ λ h, rpow_le_rpow hy h (le_of_lt hz), λ h, rpow_lt_rpow hx h hz⟩
lemma rpow_le_rpow_iff (hx : 0 ≤ x) (hy : 0 ≤ y) (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
le_iff_le_iff_lt_iff_lt.2 $ rpow_lt_rpow_iff hy hx hz
lemma rpow_lt_rpow_of_exponent_lt (hx : 1 < x) (hyz : y < z) : x^y < x^z :=
begin
repeat {rw [rpow_def_of_pos (lt_trans zero_lt_one hx)]},
rw exp_lt_exp, exact mul_lt_mul_of_pos_left hyz (log_pos hx),
end
lemma rpow_le_rpow_of_exponent_le (hx : 1 ≤ x) (hyz : y ≤ z) : x^y ≤ x^z :=
begin
repeat {rw [rpow_def_of_pos (lt_of_lt_of_le zero_lt_one hx)]},
rw exp_le_exp, exact mul_le_mul_of_nonneg_left hyz (log_nonneg hx),
end
lemma rpow_lt_rpow_of_exponent_gt (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x^y < x^z :=
begin
repeat {rw [rpow_def_of_pos hx0]},
rw exp_lt_exp, exact mul_lt_mul_of_neg_left hyz (log_neg hx0 hx1),
end
lemma rpow_le_rpow_of_exponent_ge (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x^y ≤ x^z :=
begin
repeat {rw [rpow_def_of_pos hx0]},
rw exp_le_exp, exact mul_le_mul_of_nonpos_left hyz (log_nonpos (le_of_lt hx0) hx1),
end
lemma rpow_lt_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x < 1) (hz : 0 < z) : x^z < 1 :=
by { rw ← one_rpow z, exact rpow_lt_rpow hx1 hx2 hz }
lemma rpow_le_one {x z : ℝ} (hx1 : 0 ≤ x) (hx2 : x ≤ 1) (hz : 0 ≤ z) : x^z ≤ 1 :=
by { rw ← one_rpow z, exact rpow_le_rpow hx1 hx2 hz }
lemma rpow_lt_one_of_one_lt_of_neg {x z : ℝ} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=
by { convert rpow_lt_rpow_of_exponent_lt hx hz, exact (rpow_zero x).symm }
lemma rpow_le_one_of_one_le_of_nonpos {x z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x^z ≤ 1 :=
by { convert rpow_le_rpow_of_exponent_le hx hz, exact (rpow_zero x).symm }
lemma one_lt_rpow {x z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=
by { rw ← one_rpow z, exact rpow_lt_rpow zero_le_one hx hz }
lemma one_le_rpow {x z : ℝ} (hx : 1 ≤ x) (hz : 0 ≤ z) : 1 ≤ x^z :=
by { rw ← one_rpow z, exact rpow_le_rpow zero_le_one hx hz }
lemma one_lt_rpow_of_pos_of_lt_one_of_neg (hx1 : 0 < x) (hx2 : x < 1) (hz : z < 0) :
1 < x^z :=
by { convert rpow_lt_rpow_of_exponent_gt hx1 hx2 hz, exact (rpow_zero x).symm }
lemma one_le_rpow_of_pos_of_le_one_of_nonpos (hx1 : 0 < x) (hx2 : x ≤ 1) (hz : z ≤ 0) :
1 ≤ x^z :=
by { convert rpow_le_rpow_of_exponent_ge hx1 hx2 hz, exact (rpow_zero x).symm }
lemma rpow_lt_one_iff_of_pos (hx : 0 < x) : x ^ y < 1 ↔ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y :=
by rw [rpow_def_of_pos hx, exp_lt_one_iff, mul_neg_iff, log_pos_iff hx, log_neg_iff hx]
lemma rpow_lt_one_iff (hx : 0 ≤ x) : x ^ y < 1 ↔ x = 0 ∧ y ≠ 0 ∨ 1 < x ∧ y < 0 ∨ x < 1 ∧ 0 < y :=
begin
rcases hx.eq_or_lt with (rfl|hx),
{ rcases em (y = 0) with (rfl|hy); simp [*, lt_irrefl, zero_lt_one] },
{ simp [rpow_lt_one_iff_of_pos hx, hx.ne.symm] }
end
lemma one_lt_rpow_iff_of_pos (hx : 0 < x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ x < 1 ∧ y < 0 :=
by rw [rpow_def_of_pos hx, one_lt_exp_iff, mul_pos_iff, log_pos_iff hx, log_neg_iff hx]
lemma one_lt_rpow_iff (hx : 0 ≤ x) : 1 < x ^ y ↔ 1 < x ∧ 0 < y ∨ 0 < x ∧ x < 1 ∧ y < 0 :=
begin
rcases hx.eq_or_lt with (rfl|hx),
{ rcases em (y = 0) with (rfl|hy); simp [*, lt_irrefl, (@zero_lt_one ℝ _ _).not_lt] },
{ simp [one_lt_rpow_iff_of_pos hx, hx] }
end
lemma le_rpow_iff_log_le (hx : 0 < x) (hy : 0 < y) :
x ≤ y^z ↔ real.log x ≤ z * real.log y :=
by rw [←real.log_le_log hx (real.rpow_pos_of_pos hy z), real.log_rpow hy]
lemma le_rpow_of_log_le (hx : 0 ≤ x) (hy : 0 < y) (h : real.log x ≤ z * real.log y) :
x ≤ y^z :=
begin
obtain hx | rfl := hx.lt_or_eq,
{ exact (le_rpow_iff_log_le hx hy).2 h },
exact (real.rpow_pos_of_pos hy z).le,
end
lemma lt_rpow_iff_log_lt (hx : 0 < x) (hy : 0 < y) :
x < y^z ↔ real.log x < z * real.log y :=
by rw [←real.log_lt_log_iff hx (real.rpow_pos_of_pos hy z), real.log_rpow hy]
lemma lt_rpow_of_log_lt (hx : 0 ≤ x) (hy : 0 < y) (h : real.log x < z * real.log y) :
x < y^z :=
begin
obtain hx | rfl := hx.lt_or_eq,
{ exact (lt_rpow_iff_log_lt hx hy).2 h },
exact real.rpow_pos_of_pos hy z,
end
lemma rpow_le_one_iff_of_pos (hx : 0 < x) : x ^ y ≤ 1 ↔ 1 ≤ x ∧ y ≤ 0 ∨ x ≤ 1 ∧ 0 ≤ y :=
by rw [rpow_def_of_pos hx, exp_le_one_iff, mul_nonpos_iff, log_nonneg_iff hx, log_nonpos_iff hx]
lemma pow_nat_rpow_nat_inv {x : ℝ} (hx : 0 ≤ x) {n : ℕ} (hn : 0 < n) :
(x ^ n) ^ (n⁻¹ : ℝ) = x :=
have hn0 : (n : ℝ) ≠ 0, by simpa [pos_iff_ne_zero] using hn,
by rw [← rpow_nat_cast, ← rpow_mul hx, mul_inv_cancel hn0, rpow_one]
lemma rpow_nat_inv_pow_nat {x : ℝ} (hx : 0 ≤ x) {n : ℕ} (hn : 0 < n) :
(x ^ (n⁻¹ : ℝ)) ^ n = x :=
have hn0 : (n : ℝ) ≠ 0, by simpa [pos_iff_ne_zero] using hn,
by rw [← rpow_nat_cast, ← rpow_mul hx, inv_mul_cancel hn0, rpow_one]
section prove_rpow_is_continuous
lemma continuous_rpow_aux1 : continuous (λp : {p:ℝ×ℝ // 0 < p.1}, p.val.1 ^ p.val.2) :=
suffices h : continuous (λ p : {p:ℝ×ℝ // 0 < p.1 }, exp (log p.val.1 * p.val.2)),
by { convert h, ext p, rw rpow_def_of_pos p.2 },
continuous_exp.comp $
(show continuous ((λp:{p:ℝ//0 < p}, log (p.val)) ∘ (λp:{p:ℝ×ℝ//0<p.fst}, ⟨p.val.1, p.2⟩)), from
continuous_log'.comp $ continuous_subtype_mk _ $ continuous_fst.comp continuous_subtype_val).mul
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id)
lemma continuous_rpow_aux2 : continuous (λ p : {p:ℝ×ℝ // p.1 < 0}, p.val.1 ^ p.val.2) :=
suffices h : continuous (λp:{p:ℝ×ℝ // p.1 < 0}, exp (log (-p.val.1) * p.val.2) * cos (p.val.2 * π)),
by { convert h, ext p, rw [rpow_def_of_neg p.2, log_neg_eq_log] },
(continuous_exp.comp $
(show continuous $ (λp:{p:ℝ//0<p},
log (p.val))∘(λp:{p:ℝ×ℝ//p.1<0}, ⟨-p.val.1, neg_pos_of_neg p.2⟩),
from continuous_log'.comp $ continuous_subtype_mk _ $ continuous_neg.comp $
continuous_fst.comp continuous_subtype_val).mul
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id)).mul
(continuous_cos.comp $
(continuous_snd.comp $ continuous_subtype_val.comp continuous_id).mul continuous_const)
lemma continuous_at_rpow_of_ne_zero (hx : x ≠ 0) (y : ℝ) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
begin
cases lt_trichotomy 0 x,
exact continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux1 _ h)
(is_open.mem_nhds (by { convert (is_open_lt' (0:ℝ)).prod is_open_univ, ext, finish }) h),
cases h,
{ exact absurd h.symm hx },
exact continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux2 _ h)
(is_open.mem_nhds (by { convert (is_open_gt' (0:ℝ)).prod is_open_univ, ext, finish }) h)
end
lemma continuous_rpow_aux3 : continuous (λ p : {p:ℝ×ℝ // 0 < p.2}, p.val.1 ^ p.val.2) :=
continuous_iff_continuous_at.2 $ λ ⟨(x₀, y₀), hy₀⟩,
begin
by_cases hx₀ : x₀ = 0,
{ simp only [continuous_at, hx₀, zero_rpow (ne_of_gt hy₀), metric.tendsto_nhds_nhds],
assume ε ε0,
rcases exists_pos_rat_lt (half_pos hy₀) with ⟨q, q_pos, q_lt⟩,
let q := (q:ℝ), replace q_pos : 0 < q := rat.cast_pos.2 q_pos,
let δ := min (min q (ε ^ (1 / q))) (1/2),
have δ0 : 0 < δ := lt_min (lt_min q_pos (rpow_pos_of_pos ε0 _)) (by norm_num),
have : δ ≤ q := le_trans (min_le_left _ _) (min_le_left _ _),
have : δ ≤ ε ^ (1 / q) := le_trans (min_le_left _ _) (min_le_right _ _),
have : δ < 1 := lt_of_le_of_lt (min_le_right _ _) (by norm_num),
use δ, use δ0, rintros ⟨⟨x, y⟩, hy⟩,
simp only [subtype.dist_eq, real.dist_eq, prod.dist_eq, sub_zero, subtype.coe_mk],
assume h, rw max_lt_iff at h, cases h with xδ yy₀,
have qy : q < y, calc q < y₀ / 2 : q_lt
... = y₀ - y₀ / 2 : (sub_half _).symm
... ≤ y₀ - δ : by linarith
... < y : sub_lt_of_abs_sub_lt_left yy₀,
calc abs(x^y) ≤ abs(x)^y : abs_rpow_le_abs_rpow _ _
... < δ ^ y : rpow_lt_rpow (abs_nonneg _) xδ hy
... < δ ^ q : by { refine rpow_lt_rpow_of_exponent_gt _ _ _, repeat {linarith} }
... ≤ (ε ^ (1 / q)) ^ q : by { refine rpow_le_rpow _ _ _, repeat {linarith} }
... = ε : by { rw [← rpow_mul, div_mul_cancel, rpow_one], exact ne_of_gt q_pos, linarith }},
{ exact (continuous_within_at_iff_continuous_at_restrict (λp:ℝ×ℝ, p.1^p.2) _).1
(continuous_at_rpow_of_ne_zero hx₀ _).continuous_within_at }
end
lemma continuous_at_rpow_of_pos (hy : 0 < y) (x : ℝ) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
continuous_within_at.continuous_at
(continuous_on_iff_continuous_restrict.2 continuous_rpow_aux3 _ hy)
(is_open.mem_nhds (by { convert is_open_univ.prod (is_open_lt' (0:ℝ)), ext, finish }) hy)
lemma continuous_at_rpow {x y : ℝ} (h : x ≠ 0 ∨ 0 < y) :
continuous_at (λp:ℝ×ℝ, p.1^p.2) (x, y) :=
by { cases h, exact continuous_at_rpow_of_ne_zero h _, exact continuous_at_rpow_of_pos h x }
variables {α : Type*} [topological_space α] {f g : α → ℝ}
/--
`real.rpow` is continuous at all points except for the lower half of the y-axis.
In other words, the function `λp:ℝ×ℝ, p.1^p.2` is continuous at `(x, y)` if `x ≠ 0` or `y > 0`.
Multiple forms of the claim is provided in the current section.
-/
lemma continuous_rpow (h : ∀a, f a ≠ 0 ∨ 0 < g a) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) :=
continuous_iff_continuous_at.2 $ λ a,
begin
show continuous_at ((λp:ℝ×ℝ, p.1^p.2) ∘ (λa, (f a, g a))) a,
refine continuous_at.comp _ (continuous_iff_continuous_at.1 (hf.prod_mk hg) _),
{ replace h := h a, cases h,
{ exact continuous_at_rpow_of_ne_zero h _ },
{ exact continuous_at_rpow_of_pos h _ }},
end
lemma continuous_rpow_of_ne_zero (h : ∀a, f a ≠ 0) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) := continuous_rpow (λa, or.inl $ h a) hf hg
lemma continuous_rpow_of_pos (h : ∀a, 0 < g a) (hf : continuous f) (hg : continuous g):
continuous (λa:α, (f a) ^ (g a)) := continuous_rpow (λa, or.inr $ h a) hf hg
end prove_rpow_is_continuous
section prove_rpow_is_differentiable
lemma has_deriv_at_rpow_of_pos {x : ℝ} (h : 0 < x) (p : ℝ) :
has_deriv_at (λ x, x^p) (p * x^(p-1)) x :=
begin
have : has_deriv_at (λ x, exp (log x * p)) (p * x^(p-1)) x,
{ convert (has_deriv_at_exp _).comp x ((has_deriv_at_log (ne_of_gt h)).mul_const p) using 1,
field_simp [rpow_def_of_pos h, mul_sub, exp_sub, exp_log h, ne_of_gt h],
ring },
apply this.congr_of_eventually_eq,
have : set.Ioi (0 : ℝ) ∈ 𝓝 x := is_open.mem_nhds is_open_Ioi h,
exact filter.eventually_of_mem this (λ y hy, rpow_def_of_pos hy _)
end
lemma has_deriv_at_rpow_of_neg {x : ℝ} (h : x < 0) (p : ℝ) :
has_deriv_at (λ x, x^p) (p * x^(p-1)) x :=
begin
have : has_deriv_at (λ x, exp (log x * p) * cos (p * π)) (p * x^(p-1)) x,
{ convert ((has_deriv_at_exp _).comp x ((has_deriv_at_log (ne_of_lt h)).mul_const p)).mul_const _
using 1,
field_simp [rpow_def_of_neg h, mul_sub, exp_sub, sub_mul, cos_sub, exp_log_of_neg h,
ne_of_lt h],
ring },
apply this.congr_of_eventually_eq,
have : set.Iio (0 : ℝ) ∈ 𝓝 x := is_open.mem_nhds is_open_Iio h,
exact filter.eventually_of_mem this (λ y hy, rpow_def_of_neg hy _)
end
lemma has_deriv_at_rpow {x : ℝ} (h : x ≠ 0) (p : ℝ) :
has_deriv_at (λ x, x^p) (p * x^(p-1)) x :=
begin
rcases lt_trichotomy x 0 with H|H|H,
{ exact has_deriv_at_rpow_of_neg H p },
{ exact (h H).elim },
{ exact has_deriv_at_rpow_of_pos H p },
end
lemma has_deriv_at_rpow_zero_of_one_le {p : ℝ} (h : 1 ≤ p) :
has_deriv_at (λ x, x^p) (p * (0 : ℝ)^(p-1)) 0 :=
begin
apply has_deriv_at_of_has_deriv_at_of_ne (λ x hx, has_deriv_at_rpow hx p),
{ exact (continuous_rpow_of_pos (λ _, (lt_of_lt_of_le zero_lt_one h))
continuous_id continuous_const).continuous_at },
{ rcases le_iff_eq_or_lt.1 h with rfl|h,
{ simp [continuous_const.continuous_at] },
{ exact (continuous_const.mul (continuous_rpow_of_pos (λ _, sub_pos_of_lt h)
continuous_id continuous_const)).continuous_at } }
end
lemma has_deriv_at_rpow_of_one_le (x : ℝ) {p : ℝ} (h : 1 ≤ p) :
has_deriv_at (λ x, x^p) (p * x^(p-1)) x :=
begin
by_cases hx : x = 0,
{ rw hx, exact has_deriv_at_rpow_zero_of_one_le h },
{ exact has_deriv_at_rpow hx p }
end
end prove_rpow_is_differentiable
section sqrt
lemma sqrt_eq_rpow : sqrt = λx:ℝ, x ^ (1/(2:ℝ)) :=
begin
funext, by_cases h : 0 ≤ x,
{ rw [← mul_self_inj_of_nonneg, mul_self_sqrt h, ← sq, ← rpow_nat_cast, ← rpow_mul h],
norm_num, exact sqrt_nonneg _, exact rpow_nonneg_of_nonneg h _ },
{ replace h : x < 0 := lt_of_not_ge h,
have : 1 / (2:ℝ) * π = π / (2:ℝ), ring,
rw [sqrt_eq_zero_of_nonpos (le_of_lt h), rpow_def_of_neg h, this, cos_pi_div_two, mul_zero] }
end
end sqrt
end real
section differentiability
open real
variables {f : ℝ → ℝ} {x f' : ℝ} {s : set ℝ} (p : ℝ)
/- Differentiability statements for the power of a function, when the function does not vanish
and the exponent is arbitrary-/
lemma has_deriv_within_at.rpow (hf : has_deriv_within_at f f' s x) (hx : f x ≠ 0) :
has_deriv_within_at (λ y, (f y)^p) (f' * p * (f x)^(p-1)) s x :=
begin
convert (has_deriv_at_rpow hx p).comp_has_deriv_within_at x hf using 1,
ring
end
lemma has_deriv_at.rpow (hf : has_deriv_at f f' x) (hx : f x ≠ 0) :
has_deriv_at (λ y, (f y)^p) (f' * p * (f x)^(p-1)) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hf.rpow p hx
end
lemma differentiable_within_at.rpow (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0) :
differentiable_within_at ℝ (λx, (f x)^p) s x :=
(hf.has_deriv_within_at.rpow p hx).differentiable_within_at
@[simp] lemma differentiable_at.rpow (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
differentiable_at ℝ (λx, (f x)^p) x :=
(hf.has_deriv_at.rpow p hx).differentiable_at
lemma differentiable_on.rpow (hf : differentiable_on ℝ f s) (hx : ∀ x ∈ s, f x ≠ 0) :
differentiable_on ℝ (λx, (f x)^p) s :=
λx h, (hf x h).rpow p (hx x h)
@[simp] lemma differentiable.rpow (hf : differentiable ℝ f) (hx : ∀ x, f x ≠ 0) :
differentiable ℝ (λx, (f x)^p) :=
λx, (hf x).rpow p (hx x)
lemma deriv_within_rpow (hf : differentiable_within_at ℝ f s x) (hx : f x ≠ 0)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, (f x)^p) s x = (deriv_within f s x) * p * (f x)^(p-1) :=
(hf.has_deriv_within_at.rpow p hx).deriv_within hxs
@[simp] lemma deriv_rpow (hf : differentiable_at ℝ f x) (hx : f x ≠ 0) :
deriv (λx, (f x)^p) x = (deriv f x) * p * (f x)^(p-1) :=
(hf.has_deriv_at.rpow p hx).deriv
/- Differentiability statements for the power of a function, when the function may vanish
but the exponent is at least one. -/
variable {p}
lemma has_deriv_within_at.rpow_of_one_le (hf : has_deriv_within_at f f' s x) (hp : 1 ≤ p) :
has_deriv_within_at (λ y, (f y)^p) (f' * p * (f x)^(p-1)) s x :=
begin
convert (has_deriv_at_rpow_of_one_le (f x) hp).comp_has_deriv_within_at x hf using 1,
ring
end
lemma has_deriv_at.rpow_of_one_le (hf : has_deriv_at f f' x) (hp : 1 ≤ p) :
has_deriv_at (λ y, (f y)^p) (f' * p * (f x)^(p-1)) x :=
begin
rw ← has_deriv_within_at_univ at *,
exact hf.rpow_of_one_le hp
end
lemma differentiable_within_at.rpow_of_one_le (hf : differentiable_within_at ℝ f s x) (hp : 1 ≤ p) :
differentiable_within_at ℝ (λx, (f x)^p) s x :=
(hf.has_deriv_within_at.rpow_of_one_le hp).differentiable_within_at
@[simp] lemma differentiable_at.rpow_of_one_le (hf : differentiable_at ℝ f x) (hp : 1 ≤ p) :
differentiable_at ℝ (λx, (f x)^p) x :=
(hf.has_deriv_at.rpow_of_one_le hp).differentiable_at
lemma differentiable_on.rpow_of_one_le (hf : differentiable_on ℝ f s) (hp : 1 ≤ p) :
differentiable_on ℝ (λx, (f x)^p) s :=
λx h, (hf x h).rpow_of_one_le hp
@[simp] lemma differentiable.rpow_of_one_le (hf : differentiable ℝ f) (hp : 1 ≤ p) :
differentiable ℝ (λx, (f x)^p) :=
λx, (hf x).rpow_of_one_le hp
lemma deriv_within_rpow_of_one_le (hf : differentiable_within_at ℝ f s x) (hp : 1 ≤ p)
(hxs : unique_diff_within_at ℝ s x) :
deriv_within (λx, (f x)^p) s x = (deriv_within f s x) * p * (f x)^(p-1) :=
(hf.has_deriv_within_at.rpow_of_one_le hp).deriv_within hxs
@[simp] lemma deriv_rpow_of_one_le (hf : differentiable_at ℝ f x) (hp : 1 ≤ p) :
deriv (λx, (f x)^p) x = (deriv f x) * p * (f x)^(p-1) :=
(hf.has_deriv_at.rpow_of_one_le hp).deriv
end differentiability
section limits
open real filter
/-- The function `x ^ y` tends to `+∞` at `+∞` for any positive real `y`. -/
lemma tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) : tendsto (λ x : ℝ, x ^ y) at_top at_top :=
begin
rw tendsto_at_top_at_top,
intro b,
use (max b 0) ^ (1/y),
intros x hx,
exact le_of_max_le_left
(by { convert rpow_le_rpow (rpow_nonneg_of_nonneg (le_max_right b 0) (1/y)) hx (le_of_lt hy),
rw [← rpow_mul (le_max_right b 0), (eq_div_iff (ne_of_gt hy)).mp rfl, rpow_one] }),
end
/-- The function `x ^ (-y)` tends to `0` at `+∞` for any positive real `y`. -/
lemma tendsto_rpow_neg_at_top {y : ℝ} (hy : 0 < y) : tendsto (λ x : ℝ, x ^ (-y)) at_top (𝓝 0) :=
tendsto.congr' (eventually_eq_of_mem (Ioi_mem_at_top 0) (λ x hx, (rpow_neg (le_of_lt hx) y).symm))
(tendsto_rpow_at_top hy).inv_tendsto_at_top
/-- The function `x ^ (a / (b * x + c))` tends to `1` at `+∞`, for any real numbers `a`, `b`, and
`c` such that `b` is nonzero. -/
lemma tendsto_rpow_div_mul_add (a b c : ℝ) (hb : 0 ≠ b) :
tendsto (λ x, x ^ (a / (b*x+c))) at_top (𝓝 1) :=
begin
refine tendsto.congr' _ ((tendsto_exp_nhds_0_nhds_1.comp
(by simpa only [mul_zero, pow_one] using ((@tendsto_const_nhds _ _ _ a _).mul
(tendsto_div_pow_mul_exp_add_at_top b c 1 hb (by norm_num))))).comp (tendsto_log_at_top)),
apply eventually_eq_of_mem (Ioi_mem_at_top (0:ℝ)),
intros x hx,
simp only [set.mem_Ioi, function.comp_app] at hx ⊢,
rw [exp_log hx, ← exp_log (rpow_pos_of_pos hx (a / (b * x + c))), log_rpow hx (a / (b * x + c))],
field_simp,
end
/-- The function `x ^ (1 / x)` tends to `1` at `+∞`. -/
lemma tendsto_rpow_div : tendsto (λ x, x ^ ((1:ℝ) / x)) at_top (𝓝 1) :=
by { convert tendsto_rpow_div_mul_add (1:ℝ) _ (0:ℝ) zero_ne_one, ring_nf }
/-- The function `x ^ (-1 / x)` tends to `1` at `+∞`. -/
lemma tendsto_rpow_neg_div : tendsto (λ x, x ^ (-(1:ℝ) / x)) at_top (𝓝 1) :=
by { convert tendsto_rpow_div_mul_add (-(1:ℝ)) _ (0:ℝ) zero_ne_one, ring_nf }
/-- The function `(1 + t/x) ^ x` tends to `exp t` at `+∞`. -/
lemma tendsto_one_plus_div_rpow_exp (t : ℝ) :
tendsto (λ (x : ℝ), (1 + t / x) ^ x) at_top (𝓝 (exp t)) :=
begin
apply ((real.continuous_exp.tendsto _).comp (tendsto_mul_log_one_plus_div_at_top t)).congr' _,
have h₁ : (1:ℝ)/2 < 1 := by linarith,
have h₂ : tendsto (λ x : ℝ, 1 + t / x) at_top (𝓝 1) :=
by simpa using (tendsto_inv_at_top_zero.const_mul t).const_add 1,
refine (eventually_ge_of_tendsto_gt h₁ h₂).mono (λ x hx, _),
have hx' : 0 < 1 + t / x := by linarith,
simp [mul_comm x, exp_mul, exp_log hx'],
end
/-- The function `(1 + t/x) ^ x` tends to `exp t` at `+∞` for naturals `x`. -/
lemma tendsto_one_plus_div_pow_exp (t : ℝ) :
tendsto (λ (x : ℕ), (1 + t / (x:ℝ)) ^ x) at_top (𝓝 (real.exp t)) :=
((tendsto_one_plus_div_rpow_exp t).comp tendsto_coe_nat_at_top_at_top).congr (by simp)
end limits
namespace nnreal
/-- The nonnegative real power function `x^y`, defined for `x : ℝ≥0` and `y : ℝ ` as the
restriction of the real power function. For `x > 0`, it is equal to `exp (y log x)`. For `x = 0`,
one sets `0 ^ 0 = 1` and `0 ^ y = 0` for `y ≠ 0`. -/
noncomputable def rpow (x : ℝ≥0) (y : ℝ) : ℝ≥0 :=
⟨(x : ℝ) ^ y, real.rpow_nonneg_of_nonneg x.2 y⟩
noncomputable instance : has_pow ℝ≥0 ℝ := ⟨rpow⟩
@[simp] lemma rpow_eq_pow (x : ℝ≥0) (y : ℝ) : rpow x y = x ^ y := rfl
@[simp, norm_cast] lemma coe_rpow (x : ℝ≥0) (y : ℝ) : ((x ^ y : ℝ≥0) : ℝ) = (x : ℝ) ^ y := rfl
@[simp] lemma rpow_zero (x : ℝ≥0) : x ^ (0 : ℝ) = 1 :=
nnreal.eq $ real.rpow_zero _
@[simp] lemma rpow_eq_zero_iff {x : ℝ≥0} {y : ℝ} : x ^ y = 0 ↔ x = 0 ∧ y ≠ 0 :=
begin
rw [← nnreal.coe_eq, coe_rpow, ← nnreal.coe_eq_zero],
exact real.rpow_eq_zero_iff_of_nonneg x.2
end
@[simp] lemma zero_rpow {x : ℝ} (h : x ≠ 0) : (0 : ℝ≥0) ^ x = 0 :=
nnreal.eq $ real.zero_rpow h
@[simp] lemma rpow_one (x : ℝ≥0) : x ^ (1 : ℝ) = x :=
nnreal.eq $ real.rpow_one _
@[simp] lemma one_rpow (x : ℝ) : (1 : ℝ≥0) ^ x = 1 :=
nnreal.eq $ real.one_rpow _
lemma rpow_add {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y + z) = x ^ y * x ^ z :=
nnreal.eq $ real.rpow_add (pos_iff_ne_zero.2 hx) _ _
lemma rpow_add' (x : ℝ≥0) {y z : ℝ} (h : y + z ≠ 0) : x ^ (y + z) = x ^ y * x ^ z :=
nnreal.eq $ real.rpow_add' x.2 h
lemma rpow_mul (x : ℝ≥0) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
nnreal.eq $ real.rpow_mul x.2 y z
lemma rpow_neg (x : ℝ≥0) (y : ℝ) : x ^ -y = (x ^ y)⁻¹ :=
nnreal.eq $ real.rpow_neg x.2 _
lemma rpow_neg_one (x : ℝ≥0) : x ^ (-1 : ℝ) = x ⁻¹ :=
by simp [rpow_neg]
lemma rpow_sub {x : ℝ≥0} (hx : x ≠ 0) (y z : ℝ) : x ^ (y - z) = x ^ y / x ^ z :=
nnreal.eq $ real.rpow_sub (pos_iff_ne_zero.2 hx) y z
lemma rpow_sub' (x : ℝ≥0) {y z : ℝ} (h : y - z ≠ 0) :
x ^ (y - z) = x ^ y / x ^ z :=
nnreal.eq $ real.rpow_sub' x.2 h
lemma inv_rpow (x : ℝ≥0) (y : ℝ) : (x⁻¹) ^ y = (x ^ y)⁻¹ :=
nnreal.eq $ real.inv_rpow x.2 y
lemma div_rpow (x y : ℝ≥0) (z : ℝ) : (x / y) ^ z = x ^ z / y ^ z :=
nnreal.eq $ real.div_rpow x.2 y.2 z
@[simp, norm_cast] lemma rpow_nat_cast (x : ℝ≥0) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
nnreal.eq $ by simpa only [coe_rpow, coe_pow] using real.rpow_nat_cast x n
lemma mul_rpow {x y : ℝ≥0} {z : ℝ} : (x*y)^z = x^z * y^z :=
nnreal.eq $ real.mul_rpow x.2 y.2
lemma rpow_le_rpow {x y : ℝ≥0} {z: ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
real.rpow_le_rpow x.2 h₁ h₂
lemma rpow_lt_rpow {x y : ℝ≥0} {z: ℝ} (h₁ : x < y) (h₂ : 0 < z) : x^z < y^z :=
real.rpow_lt_rpow x.2 h₁ h₂
lemma rpow_lt_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
real.rpow_lt_rpow_iff x.2 y.2 hz
lemma rpow_le_rpow_iff {x y : ℝ≥0} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
real.rpow_le_rpow_iff x.2 y.2 hz
lemma rpow_lt_rpow_of_exponent_lt {x : ℝ≥0} {y z : ℝ} (hx : 1 < x) (hyz : y < z) : x^y < x^z :=
real.rpow_lt_rpow_of_exponent_lt hx hyz
lemma rpow_le_rpow_of_exponent_le {x : ℝ≥0} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x^y ≤ x^z :=
real.rpow_le_rpow_of_exponent_le hx hyz
lemma rpow_lt_rpow_of_exponent_gt {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x^y < x^z :=
real.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz
lemma rpow_le_rpow_of_exponent_ge {x : ℝ≥0} {y z : ℝ} (hx0 : 0 < x) (hx1 : x ≤ 1) (hyz : z ≤ y) :
x^y ≤ x^z :=
real.rpow_le_rpow_of_exponent_ge hx0 hx1 hyz
lemma rpow_lt_one {x : ℝ≥0} {z : ℝ} (hx : 0 ≤ x) (hx1 : x < 1) (hz : 0 < z) : x^z < 1 :=
real.rpow_lt_one hx hx1 hz
lemma rpow_le_one {x : ℝ≥0} {z : ℝ} (hx2 : x ≤ 1) (hz : 0 ≤ z) : x^z ≤ 1 :=
real.rpow_le_one x.2 hx2 hz
lemma rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=
real.rpow_lt_one_of_one_lt_of_neg hx hz
lemma rpow_le_one_of_one_le_of_nonpos {x : ℝ≥0} {z : ℝ} (hx : 1 ≤ x) (hz : z ≤ 0) : x^z ≤ 1 :=
real.rpow_le_one_of_one_le_of_nonpos hx hz
lemma one_lt_rpow {x : ℝ≥0} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=
real.one_lt_rpow hx hz
lemma one_le_rpow {x : ℝ≥0} {z : ℝ} (h : 1 ≤ x) (h₁ : 0 ≤ z) : 1 ≤ x^z :=
real.one_le_rpow h h₁
lemma one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x^z :=
real.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz
lemma one_le_rpow_of_pos_of_le_one_of_nonpos {x : ℝ≥0} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z ≤ 0) : 1 ≤ x^z :=
real.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 hz
lemma pow_nat_rpow_nat_inv (x : ℝ≥0) {n : ℕ} (hn : 0 < n) :
(x ^ n) ^ (n⁻¹ : ℝ) = x :=
by { rw [← nnreal.coe_eq, coe_rpow, nnreal.coe_pow], exact real.pow_nat_rpow_nat_inv x.2 hn }
lemma rpow_nat_inv_pow_nat (x : ℝ≥0) {n : ℕ} (hn : 0 < n) :
(x ^ (n⁻¹ : ℝ)) ^ n = x :=
by { rw [← nnreal.coe_eq, nnreal.coe_pow, coe_rpow], exact real.rpow_nat_inv_pow_nat x.2 hn }
lemma continuous_at_rpow {x : ℝ≥0} {y : ℝ} (h : x ≠ 0 ∨ 0 < y) :
continuous_at (λp:ℝ≥0×ℝ, p.1^p.2) (x, y) :=
begin
have : (λp:ℝ≥0×ℝ, p.1^p.2) = real.to_nnreal ∘ (λp:ℝ×ℝ, p.1^p.2) ∘ (λp:ℝ≥0 × ℝ, (p.1.1, p.2)),
{ ext p,
rw [coe_rpow, real.coe_to_nnreal _ (real.rpow_nonneg_of_nonneg p.1.2 _)],
refl },
rw this,
refine nnreal.continuous_of_real.continuous_at.comp (continuous_at.comp _ _),
{ apply real.continuous_at_rpow,
simp at h,
rw ← (nnreal.coe_eq_zero x) at h,
exact h },
{ exact ((continuous_subtype_val.comp continuous_fst).prod_mk continuous_snd).continuous_at }
end
lemma _root_.real.to_nnreal_rpow_of_nonneg {x y : ℝ} (hx : 0 ≤ x) :
real.to_nnreal (x ^ y) = (real.to_nnreal x) ^ y :=
begin
nth_rewrite 0 ← real.coe_to_nnreal x hx,
rw [←nnreal.coe_rpow, real.to_nnreal_coe],
end
end nnreal
open filter
lemma filter.tendsto.nnrpow {α : Type*} {f : filter α} {u : α → ℝ≥0} {v : α → ℝ} {x : ℝ≥0} {y : ℝ}
(hx : tendsto u f (𝓝 x)) (hy : tendsto v f (𝓝 y)) (h : x ≠ 0 ∨ 0 < y) :
tendsto (λ a, (u a) ^ (v a)) f (𝓝 (x ^ y)) :=
tendsto.comp (nnreal.continuous_at_rpow h) (hx.prod_mk_nhds hy)
namespace nnreal
lemma continuous_at_rpow_const {x : ℝ≥0} {y : ℝ} (h : x ≠ 0 ∨ 0 ≤ y) :
continuous_at (λ z, z^y) x :=
h.elim (λ h, tendsto_id.nnrpow tendsto_const_nhds (or.inl h)) $
λ h, h.eq_or_lt.elim
(λ h, h ▸ by simp only [rpow_zero, continuous_at_const])
(λ h, tendsto_id.nnrpow tendsto_const_nhds (or.inr h))
lemma continuous_rpow_const {y : ℝ} (h : 0 ≤ y) :
continuous (λ x : ℝ≥0, x^y) :=
continuous_iff_continuous_at.2 $ λ x, continuous_at_rpow_const (or.inr h)
theorem tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) :
tendsto (λ (x : ℝ≥0), x ^ y) at_top at_top :=
begin
rw filter.tendsto_at_top_at_top,
intros b,
obtain ⟨c, hc⟩ := tendsto_at_top_at_top.mp (tendsto_rpow_at_top hy) b,
use c.to_nnreal,
intros a ha,
exact_mod_cast hc a (real.to_nnreal_le_iff_le_coe.mp ha),
end
end nnreal
namespace ennreal
/-- The real power function `x^y` on extended nonnegative reals, defined for `x : ℝ≥0∞` and
`y : ℝ` as the restriction of the real power function if `0 < x < ⊤`, and with the natural values
for `0` and `⊤` (i.e., `0 ^ x = 0` for `x > 0`, `1` for `x = 0` and `⊤` for `x < 0`, and
`⊤ ^ x = 1 / 0 ^ x`). -/
noncomputable def rpow : ℝ≥0∞ → ℝ → ℝ≥0∞
| (some x) y := if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0)
| none y := if 0 < y then ⊤ else if y = 0 then 1 else 0
noncomputable instance : has_pow ℝ≥0∞ ℝ := ⟨rpow⟩
@[simp] lemma rpow_eq_pow (x : ℝ≥0∞) (y : ℝ) : rpow x y = x ^ y := rfl
@[simp] lemma rpow_zero {x : ℝ≥0∞} : x ^ (0 : ℝ) = 1 :=
by cases x; { dsimp only [(^), rpow], simp [lt_irrefl] }
lemma top_rpow_def (y : ℝ) : (⊤ : ℝ≥0∞) ^ y = if 0 < y then ⊤ else if y = 0 then 1 else 0 :=
rfl
@[simp] lemma top_rpow_of_pos {y : ℝ} (h : 0 < y) : (⊤ : ℝ≥0∞) ^ y = ⊤ :=
by simp [top_rpow_def, h]
@[simp] lemma top_rpow_of_neg {y : ℝ} (h : y < 0) : (⊤ : ℝ≥0∞) ^ y = 0 :=
by simp [top_rpow_def, asymm h, ne_of_lt h]
@[simp] lemma zero_rpow_of_pos {y : ℝ} (h : 0 < y) : (0 : ℝ≥0∞) ^ y = 0 :=
begin
rw [← ennreal.coe_zero, ← ennreal.some_eq_coe],
dsimp only [(^), rpow],
simp [h, asymm h, ne_of_gt h],
end
@[simp] lemma zero_rpow_of_neg {y : ℝ} (h : y < 0) : (0 : ℝ≥0∞) ^ y = ⊤ :=
begin
rw [← ennreal.coe_zero, ← ennreal.some_eq_coe],
dsimp only [(^), rpow],
simp [h, ne_of_gt h],
end
lemma zero_rpow_def (y : ℝ) : (0 : ℝ≥0∞) ^ y = if 0 < y then 0 else if y = 0 then 1 else ⊤ :=
begin
rcases lt_trichotomy 0 y with H|rfl|H,
{ simp [H, ne_of_gt, zero_rpow_of_pos, lt_irrefl] },
{ simp [lt_irrefl] },
{ simp [H, asymm H, ne_of_lt, zero_rpow_of_neg] }
end
@[simp] lemma zero_rpow_mul_self (y : ℝ) : (0 : ℝ≥0∞) ^ y * 0 ^ y = 0 ^ y :=
by { rw zero_rpow_def, split_ifs, exacts [zero_mul _, one_mul _, top_mul_top] }
@[norm_cast] lemma coe_rpow_of_ne_zero {x : ℝ≥0} (h : x ≠ 0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) :=
begin
rw [← ennreal.some_eq_coe],
dsimp only [(^), rpow],
simp [h]
end
@[norm_cast] lemma coe_rpow_of_nonneg (x : ℝ≥0) {y : ℝ} (h : 0 ≤ y) :
(x : ℝ≥0∞) ^ y = (x ^ y : ℝ≥0) :=
begin
by_cases hx : x = 0,
{ rcases le_iff_eq_or_lt.1 h with H|H,
{ simp [hx, H.symm] },
{ simp [hx, zero_rpow_of_pos H, nnreal.zero_rpow (ne_of_gt H)] } },
{ exact coe_rpow_of_ne_zero hx _ }
end
lemma coe_rpow_def (x : ℝ≥0) (y : ℝ) :
(x : ℝ≥0∞) ^ y = if x = 0 ∧ y < 0 then ⊤ else (x ^ y : ℝ≥0) := rfl
@[simp] lemma rpow_one (x : ℝ≥0∞) : x ^ (1 : ℝ) = x :=
by cases x; dsimp only [(^), rpow]; simp [zero_lt_one, not_lt_of_le zero_le_one]
@[simp] lemma one_rpow (x : ℝ) : (1 : ℝ≥0∞) ^ x = 1 :=
by { rw [← coe_one, coe_rpow_of_ne_zero one_ne_zero], simp }
@[simp] lemma rpow_eq_zero_iff {x : ℝ≥0∞} {y : ℝ} :
x ^ y = 0 ↔ (x = 0 ∧ 0 < y) ∨ (x = ⊤ ∧ y < 0) :=
begin
cases x,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] },
{ by_cases h : x = 0,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] },
{ simp [coe_rpow_of_ne_zero h, h] } }
end
@[simp] lemma rpow_eq_top_iff {x : ℝ≥0∞} {y : ℝ} :
x ^ y = ⊤ ↔ (x = 0 ∧ y < 0) ∨ (x = ⊤ ∧ 0 < y) :=
begin
cases x,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [H, top_rpow_of_neg, top_rpow_of_pos, le_of_lt] },
{ by_cases h : x = 0,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [h, H, zero_rpow_of_neg, zero_rpow_of_pos, le_of_lt] },
{ simp [coe_rpow_of_ne_zero h, h] } }
end
lemma rpow_eq_top_iff_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : x ^ y = ⊤ ↔ x = ⊤ :=
by simp [rpow_eq_top_iff, hy, asymm hy]
lemma rpow_eq_top_of_nonneg (x : ℝ≥0∞) {y : ℝ} (hy0 : 0 ≤ y) : x ^ y = ⊤ → x = ⊤ :=
begin
rw ennreal.rpow_eq_top_iff,
intro h,
cases h,
{ exfalso, rw lt_iff_not_ge at h, exact h.right hy0, },
{ exact h.left, },
end
lemma rpow_ne_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y ≠ ⊤ :=
mt (ennreal.rpow_eq_top_of_nonneg x hy0) h
lemma rpow_lt_top_of_nonneg {x : ℝ≥0∞} {y : ℝ} (hy0 : 0 ≤ y) (h : x ≠ ⊤) : x ^ y < ⊤ :=
ennreal.lt_top_iff_ne_top.mpr (ennreal.rpow_ne_top_of_nonneg hy0 h)
lemma rpow_add {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y + z) = x ^ y * x ^ z :=
begin
cases x, { exact (h'x rfl).elim },
have : x ≠ 0 := λ h, by simpa [h] using hx,
simp [coe_rpow_of_ne_zero this, nnreal.rpow_add this]
end
lemma rpow_neg (x : ℝ≥0∞) (y : ℝ) : x ^ -y = (x ^ y)⁻¹ :=
begin
cases x,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [top_rpow_of_pos, top_rpow_of_neg, H, neg_pos.mpr] },
{ by_cases h : x = 0,
{ rcases lt_trichotomy y 0 with H|H|H;
simp [h, zero_rpow_of_pos, zero_rpow_of_neg, H, neg_pos.mpr] },
{ have A : x ^ y ≠ 0, by simp [h],
simp [coe_rpow_of_ne_zero h, ← coe_inv A, nnreal.rpow_neg] } }
end
lemma rpow_sub {x : ℝ≥0∞} (y z : ℝ) (hx : x ≠ 0) (h'x : x ≠ ⊤) : x ^ (y - z) = x ^ y / x ^ z :=
by rw [sub_eq_add_neg, rpow_add _ _ hx h'x, rpow_neg, div_eq_mul_inv]
lemma rpow_neg_one (x : ℝ≥0∞) : x ^ (-1 : ℝ) = x ⁻¹ :=
by simp [rpow_neg]
lemma rpow_mul (x : ℝ≥0∞) (y z : ℝ) : x ^ (y * z) = (x ^ y) ^ z :=
begin
cases x,
{ rcases lt_trichotomy y 0 with Hy|Hy|Hy;
rcases lt_trichotomy z 0 with Hz|Hz|Hz;
simp [Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] },
{ by_cases h : x = 0,
{ rcases lt_trichotomy y 0 with Hy|Hy|Hy;
rcases lt_trichotomy z 0 with Hz|Hz|Hz;
simp [h, Hy, Hz, zero_rpow_of_neg, zero_rpow_of_pos, top_rpow_of_neg, top_rpow_of_pos,
mul_pos_of_neg_of_neg, mul_neg_of_neg_of_pos, mul_neg_of_pos_of_neg] },
{ have : x ^ y ≠ 0, by simp [h],
simp [coe_rpow_of_ne_zero h, coe_rpow_of_ne_zero this, nnreal.rpow_mul] } }
end
@[simp, norm_cast] lemma rpow_nat_cast (x : ℝ≥0∞) (n : ℕ) : x ^ (n : ℝ) = x ^ n :=
begin
cases x,
{ cases n;
simp [top_rpow_of_pos (nat.cast_add_one_pos _), top_pow (nat.succ_pos _)] },
{ simp [coe_rpow_of_nonneg _ (nat.cast_nonneg n)] }
end
lemma mul_rpow_eq_ite (x y : ℝ≥0∞) (z : ℝ) :
(x * y) ^ z = if (x = 0 ∧ y = ⊤ ∨ x = ⊤ ∧ y = 0) ∧ z < 0 then ⊤ else x ^ z * y ^ z :=
begin
rcases eq_or_ne z 0 with rfl|hz, { simp },
replace hz := hz.lt_or_lt,
wlog hxy : x ≤ y := le_total x y using [x y, y x] tactic.skip,
{ rcases eq_or_ne x 0 with rfl|hx0,
{ induction y using with_top.rec_top_coe; cases hz with hz hz; simp [*, hz.not_lt] },
rcases eq_or_ne y 0 with rfl|hy0, { exact (hx0 (bot_unique hxy)).elim },
induction x using with_top.rec_top_coe, { cases hz with hz hz; simp [hz, top_unique hxy] },
induction y using with_top.rec_top_coe, { cases hz with hz hz; simp * },
simp only [*, false_and, and_false, false_or, if_false],
norm_cast at *,
rw [coe_rpow_of_ne_zero (mul_ne_zero hx0 hy0), nnreal.mul_rpow] },
{ convert this using 2; simp only [mul_comm, and_comm, or_comm] }
end
lemma mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) :
(x * y) ^ z = x^z * y^z :=
by simp [*, mul_rpow_eq_ite]
@[norm_cast] lemma coe_mul_rpow (x y : ℝ≥0) (z : ℝ) :
((x : ℝ≥0∞) * y) ^ z = x^z * y^z :=
mul_rpow_of_ne_top coe_ne_top coe_ne_top z
lemma mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z :=
by simp [*, mul_rpow_eq_ite]
lemma mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) :
(x * y) ^ z = x ^ z * y ^ z :=
by simp [hz.not_lt, mul_rpow_eq_ite]
lemma inv_rpow (x : ℝ≥0∞) (y : ℝ) : (x⁻¹) ^ y = (x ^ y)⁻¹ :=
begin
rcases eq_or_ne y 0 with rfl|hy, { simp only [rpow_zero, inv_one] },
replace hy := hy.lt_or_lt,
rcases eq_or_ne x 0 with rfl|h0, { cases hy; simp * },
rcases eq_or_ne x ⊤ with rfl|h_top, { cases hy; simp * },
apply eq_inv_of_mul_eq_one,
rw [← mul_rpow_of_ne_zero (inv_ne_zero.2 h_top) h0, inv_mul_cancel h0 h_top, one_rpow]
end
lemma div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) :
(x / y) ^ z = x ^ z / y ^ z :=
by rw [div_eq_mul_inv, mul_rpow_of_nonneg _ _ hz, inv_rpow, div_eq_mul_inv]
lemma strict_mono_rpow_of_pos {z : ℝ} (h : 0 < z) : strict_mono (λ x : ℝ≥0∞, x ^ z) :=
begin
intros x y hxy,
lift x to ℝ≥0 using ne_top_of_lt hxy,
rcases eq_or_ne y ∞ with rfl|hy,
{ simp only [top_rpow_of_pos h, coe_rpow_of_nonneg _ h.le, coe_lt_top] },
{ lift y to ℝ≥0 using hy,
simp only [coe_rpow_of_nonneg _ h.le, nnreal.rpow_lt_rpow (coe_lt_coe.1 hxy) h, coe_lt_coe] }
end
lemma monotone_rpow_of_nonneg {z : ℝ} (h : 0 ≤ z) : monotone (λ x : ℝ≥0∞, x ^ z) :=
h.eq_or_lt.elim (λ h0, h0 ▸ by simp only [rpow_zero, monotone_const])
(λ h0, (strict_mono_rpow_of_pos h0).monotone)
lemma rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
monotone_rpow_of_nonneg h₂ h₁
lemma rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x^z < y^z :=
strict_mono_rpow_of_pos h₂ h₁
lemma rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
(strict_mono_rpow_of_pos hz).le_iff_le
lemma rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
(strict_mono_rpow_of_pos hz).lt_iff_lt
lemma le_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ≤ y ^ (1 / z) ↔ x ^ z ≤ y :=
begin
nth_rewrite 0 ←rpow_one x,
nth_rewrite 0 ←@_root_.mul_inv_cancel _ _ z hz.ne',
rw [rpow_mul, ←one_div, @rpow_le_rpow_iff _ _ (1/z) (by simp [hz])],
end
lemma lt_rpow_one_div_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x < y ^ (1 / z) ↔ x ^ z < y :=
begin
nth_rewrite 0 ←rpow_one x,
nth_rewrite 0 ←@_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm,
rw [rpow_mul, ←one_div, @rpow_lt_rpow_iff _ _ (1/z) (by simp [hz])],
end
lemma rpow_lt_rpow_of_exponent_lt {x : ℝ≥0∞} {y z : ℝ} (hx : 1 < x) (hx' : x ≠ ⊤) (hyz : y < z) :
x^y < x^z :=
begin
lift x to ℝ≥0 using hx',
rw [one_lt_coe_iff] at hx,
simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
nnreal.rpow_lt_rpow_of_exponent_lt hx hyz]
end
lemma rpow_le_rpow_of_exponent_le {x : ℝ≥0∞} {y z : ℝ} (hx : 1 ≤ x) (hyz : y ≤ z) : x^y ≤ x^z :=
begin
cases x,
{ rcases lt_trichotomy y 0 with Hy|Hy|Hy;
rcases lt_trichotomy z 0 with Hz|Hz|Hz;
simp [Hy, Hz, top_rpow_of_neg, top_rpow_of_pos, le_refl];
linarith },
{ simp only [one_le_coe_iff, some_eq_coe] at hx,
simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
nnreal.rpow_le_rpow_of_exponent_le hx hyz] }
end
lemma rpow_lt_rpow_of_exponent_gt {x : ℝ≥0∞} {y z : ℝ} (hx0 : 0 < x) (hx1 : x < 1) (hyz : z < y) :
x^y < x^z :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx1 le_top),
simp at hx0 hx1,
simp [coe_rpow_of_ne_zero (ne_of_gt hx0), nnreal.rpow_lt_rpow_of_exponent_gt hx0 hx1 hyz]
end
lemma rpow_le_rpow_of_exponent_ge {x : ℝ≥0∞} {y z : ℝ} (hx1 : x ≤ 1) (hyz : z ≤ y) :
x^y ≤ x^z :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx1 coe_lt_top),
by_cases h : x = 0,
{ rcases lt_trichotomy y 0 with Hy|Hy|Hy;
rcases lt_trichotomy z 0 with Hz|Hz|Hz;
simp [Hy, Hz, h, zero_rpow_of_neg, zero_rpow_of_pos, le_refl];
linarith },
{ simp at hx1,
simp [coe_rpow_of_ne_zero h,
nnreal.rpow_le_rpow_of_exponent_ge (bot_lt_iff_ne_bot.mpr h) hx1 hyz] }
end
lemma rpow_le_self_of_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (h_one_le : 1 ≤ z) : x ^ z ≤ x :=
begin
nth_rewrite 1 ←ennreal.rpow_one x,
exact ennreal.rpow_le_rpow_of_exponent_ge hx h_one_le,
end
lemma le_rpow_self_of_one_le {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (h_one_le : 1 ≤ z) : x ≤ x ^ z :=
begin
nth_rewrite 0 ←ennreal.rpow_one x,
exact ennreal.rpow_le_rpow_of_exponent_le hx h_one_le,
end
lemma rpow_pos_of_nonneg {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hp_nonneg : 0 ≤ p) : 0 < x^p :=
begin
by_cases hp_zero : p = 0,
{ simp [hp_zero, ennreal.zero_lt_one], },
{ rw ←ne.def at hp_zero,
have hp_pos := lt_of_le_of_ne hp_nonneg hp_zero.symm,
rw ←zero_rpow_of_pos hp_pos, exact rpow_lt_rpow hx_pos hp_pos, },
end
lemma rpow_pos {p : ℝ} {x : ℝ≥0∞} (hx_pos : 0 < x) (hx_ne_top : x ≠ ⊤) : 0 < x^p :=
begin
cases lt_or_le 0 p with hp_pos hp_nonpos,
{ exact rpow_pos_of_nonneg hx_pos (le_of_lt hp_pos), },
{ rw [←neg_neg p, rpow_neg, inv_pos],
exact rpow_ne_top_of_nonneg (by simp [hp_nonpos]) hx_ne_top, },
end
lemma rpow_lt_one {x : ℝ≥0∞} {z : ℝ} (hx : x < 1) (hz : 0 < z) : x^z < 1 :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx le_top),
simp only [coe_lt_one_iff] at hx,
simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.rpow_lt_one (zero_le x) hx hz],
end
lemma rpow_le_one {x : ℝ≥0∞} {z : ℝ} (hx : x ≤ 1) (hz : 0 ≤ z) : x^z ≤ 1 :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx coe_lt_top),
simp only [coe_le_one_iff] at hx,
simp [coe_rpow_of_nonneg _ hz, nnreal.rpow_le_one hx hz],
end
lemma rpow_lt_one_of_one_lt_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : z < 0) : x^z < 1 :=
begin
cases x,
{ simp [top_rpow_of_neg hz, ennreal.zero_lt_one] },
{ simp only [some_eq_coe, one_lt_coe_iff] at hx,
simp [coe_rpow_of_ne_zero (ne_of_gt (lt_trans zero_lt_one hx)),
nnreal.rpow_lt_one_of_one_lt_of_neg hx hz] },
end
lemma rpow_le_one_of_one_le_of_neg {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : z < 0) : x^z ≤ 1 :=
begin
cases x,
{ simp [top_rpow_of_neg hz, ennreal.zero_lt_one] },
{ simp only [one_le_coe_iff, some_eq_coe] at hx,
simp [coe_rpow_of_ne_zero (ne_of_gt (lt_of_lt_of_le zero_lt_one hx)),
nnreal.rpow_le_one_of_one_le_of_nonpos hx (le_of_lt hz)] },
end
lemma one_lt_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 < x) (hz : 0 < z) : 1 < x^z :=
begin
cases x,
{ simp [top_rpow_of_pos hz] },
{ simp only [some_eq_coe, one_lt_coe_iff] at hx,
simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.one_lt_rpow hx hz] }
end
lemma one_le_rpow {x : ℝ≥0∞} {z : ℝ} (hx : 1 ≤ x) (hz : 0 < z) : 1 ≤ x^z :=
begin
cases x,
{ simp [top_rpow_of_pos hz] },
{ simp only [one_le_coe_iff, some_eq_coe] at hx,
simp [coe_rpow_of_nonneg _ (le_of_lt hz), nnreal.one_le_rpow hx (le_of_lt hz)] },
end
lemma one_lt_rpow_of_pos_of_lt_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x < 1)
(hz : z < 0) : 1 < x^z :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_lt_of_le hx2 le_top),
simp only [coe_lt_one_iff, coe_pos] at ⊢ hx1 hx2,
simp [coe_rpow_of_ne_zero (ne_of_gt hx1), nnreal.one_lt_rpow_of_pos_of_lt_one_of_neg hx1 hx2 hz],
end
lemma one_le_rpow_of_pos_of_le_one_of_neg {x : ℝ≥0∞} {z : ℝ} (hx1 : 0 < x) (hx2 : x ≤ 1)
(hz : z < 0) : 1 ≤ x^z :=
begin
lift x to ℝ≥0 using ne_of_lt (lt_of_le_of_lt hx2 coe_lt_top),
simp only [coe_le_one_iff, coe_pos] at ⊢ hx1 hx2,
simp [coe_rpow_of_ne_zero (ne_of_gt hx1),
nnreal.one_le_rpow_of_pos_of_le_one_of_nonpos hx1 hx2 (le_of_lt hz)],
end
lemma to_nnreal_rpow (x : ℝ≥0∞) (z : ℝ) : (x.to_nnreal) ^ z = (x ^ z).to_nnreal :=
begin
rcases lt_trichotomy z 0 with H|H|H,
{ cases x, { simp [H, ne_of_lt] },
by_cases hx : x = 0,
{ simp [hx, H, ne_of_lt] },
{ simp [coe_rpow_of_ne_zero hx] } },
{ simp [H] },
{ cases x, { simp [H, ne_of_gt] },
simp [coe_rpow_of_nonneg _ (le_of_lt H)] }
end
lemma to_real_rpow (x : ℝ≥0∞) (z : ℝ) : (x.to_real) ^ z = (x ^ z).to_real :=
by rw [ennreal.to_real, ennreal.to_real, ←nnreal.coe_rpow, ennreal.to_nnreal_rpow]
lemma of_real_rpow_of_pos {x p : ℝ} (hx_pos : 0 < x) :
ennreal.of_real x ^ p = ennreal.of_real (x ^ p) :=
begin
simp_rw ennreal.of_real,
rw [coe_rpow_of_ne_zero, coe_eq_coe, real.to_nnreal_rpow_of_nonneg hx_pos.le],
simp [hx_pos],
end
lemma of_real_rpow_of_nonneg {x p : ℝ} (hx_nonneg : 0 ≤ x) (hp_nonneg : 0 ≤ p) :
ennreal.of_real x ^ p = ennreal.of_real (x ^ p) :=
begin
by_cases hp0 : p = 0,
{ simp [hp0], },
by_cases hx0 : x = 0,
{ rw ← ne.def at hp0,
have hp_pos : 0 < p := lt_of_le_of_ne hp_nonneg hp0.symm,
simp [hx0, hp_pos, hp_pos.ne.symm], },
rw ← ne.def at hx0,
exact of_real_rpow_of_pos (hx_nonneg.lt_of_ne hx0.symm),
end
lemma rpow_left_injective {x : ℝ} (hx : x ≠ 0) :
function.injective (λ y : ℝ≥0∞, y^x) :=
begin
intros y z hyz,
dsimp only at hyz,
rw [←rpow_one y, ←rpow_one z, ←_root_.mul_inv_cancel hx, rpow_mul, rpow_mul, hyz],
end
lemma rpow_left_surjective {x : ℝ} (hx : x ≠ 0) :
function.surjective (λ y : ℝ≥0∞, y^x) :=
λ y, ⟨y ^ x⁻¹, by simp_rw [←rpow_mul, _root_.inv_mul_cancel hx, rpow_one]⟩
lemma rpow_left_bijective {x : ℝ} (hx : x ≠ 0) :
function.bijective (λ y : ℝ≥0∞, y^x) :=
⟨rpow_left_injective hx, rpow_left_surjective hx⟩
lemma rpow_left_monotone_of_nonneg {x : ℝ} (hx : 0 ≤ x) : monotone (λ y : ℝ≥0∞, y^x) :=
λ y z hyz, rpow_le_rpow hyz hx
lemma rpow_left_strict_mono_of_pos {x : ℝ} (hx : 0 < x) : strict_mono (λ y : ℝ≥0∞, y^x) :=
λ y z hyz, rpow_lt_rpow hyz hx
theorem tendsto_rpow_at_top {y : ℝ} (hy : 0 < y) :
tendsto (λ (x : ℝ≥0∞), x ^ y) (𝓝 ⊤) (𝓝 ⊤) :=
begin
rw tendsto_nhds_top_iff_nnreal,
intros x,
obtain ⟨c, _, hc⟩ :=
(at_top_basis_Ioi.tendsto_iff at_top_basis_Ioi).mp (nnreal.tendsto_rpow_at_top hy) x trivial,
have hc' : set.Ioi (↑c) ∈ 𝓝 (⊤ : ℝ≥0∞) := Ioi_mem_nhds coe_lt_top,
refine eventually_of_mem hc' _,
intros a ha,
by_cases ha' : a = ⊤,
{ simp [ha', hy] },
lift a to ℝ≥0 using ha',
change ↑c < ↑a at ha,
rw coe_rpow_of_nonneg _ hy.le,
exact_mod_cast hc a (by exact_mod_cast ha),
end
private lemma continuous_at_rpow_const_of_pos {x : ℝ≥0∞} {y : ℝ} (h : 0 < y) :
continuous_at (λ a : ennreal, a ^ y) x :=
begin
by_cases hx : x = ⊤,
{ rw [hx, continuous_at],
convert tendsto_rpow_at_top h,
simp [h] },
lift x to ℝ≥0 using hx,
rw continuous_at_coe_iff,
convert continuous_coe.continuous_at.comp
(nnreal.continuous_at_rpow_const (or.inr h.le)) using 1,
ext1 x,
simp [coe_rpow_of_nonneg _ h.le]
end
@[continuity]
lemma continuous_rpow_const {y : ℝ} : continuous (λ a : ennreal, a ^ y) :=
begin
apply continuous_iff_continuous_at.2 (λ x, _),
rcases lt_trichotomy 0 y with hy|rfl|hy,
{ exact continuous_at_rpow_const_of_pos hy },
{ simp, exact continuous_at_const },
{ obtain ⟨z, hz⟩ : ∃ z, y = -z := ⟨-y, (neg_neg _).symm⟩,
have z_pos : 0 < z, by simpa [hz] using hy,
simp_rw [hz, rpow_neg],
exact ennreal.continuous_inv.continuous_at.comp (continuous_at_rpow_const_of_pos z_pos) }
end
end ennreal
|
9886c8ba4e2a997775f4c508cc52bd788b55f8b5 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/finite/defs.lean | 8c66af8d3de5f744ab7f9443b4c0f792a4f4a4f8 | [
"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 | 4,491 | lean | /-
Copyright (c) 2022 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import logic.equiv.basic
/-!
# Definition of the `finite` typeclass
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/698
> Any changes to this file require a corresponding PR to mathlib4.
This file defines a typeclass `finite` saying that `α : Sort*` is finite. A type is `finite` if it
is equivalent to `fin n` for some `n`. We also define `infinite α` as a typeclass equivalent to
`¬finite α`.
The `finite` predicate has no computational relevance and, being `Prop`-valued, gets to enjoy proof
irrelevance -- it represents the mere fact that the type is finite. While the `fintype` class also
represents finiteness of a type, a key difference is that a `fintype` instance represents finiteness
in a computable way: it gives a concrete algorithm to produce a `finset` whose elements enumerate
the terms of the given type. As such, one generally relies on congruence lemmas when rewriting
expressions involving `fintype` instances.
Every `fintype` instance automatically gives a `finite` instance, see `fintype.finite`, but not vice
versa. Every `fintype` instance should be computable since they are meant for computation. If it's
not possible to write a computable `fintype` instance, one should prefer writing a `finite` instance
instead.
## Main definitions
* `finite α` denotes that `α` is a finite type.
* `infinite α` denotes that `α` is an infinite type.
## Implementation notes
The definition of `finite α` is not just `nonempty (fintype α)` since `fintype` requires
that `α : Type*`, and the definition in this module allows for `α : Sort*`. This means
we can write the instance `finite.prop`.
## Tags
finite, fintype
-/
universes u v
open function
variables {α β : Sort*}
/-- A type is `finite` if it is in bijective correspondence to some
`fin n`.
While this could be defined as `nonempty (fintype α)`, it is defined
in this way to allow there to be `finite` instances for propositions.
-/
class inductive finite (α : Sort*) : Prop
| intro {n : ℕ} : α ≃ fin n → finite
lemma finite_iff_exists_equiv_fin {α : Sort*} : finite α ↔ ∃ n, nonempty (α ≃ fin n) :=
⟨λ ⟨e⟩, ⟨_, ⟨e⟩⟩, λ ⟨n, ⟨e⟩⟩, ⟨e⟩⟩
lemma finite.exists_equiv_fin (α : Sort*) [h : finite α] : ∃ (n : ℕ), nonempty (α ≃ fin n) :=
finite_iff_exists_equiv_fin.mp h
lemma finite.of_equiv (α : Sort*) [h : finite α] (f : α ≃ β) : finite β :=
by { casesI h with n e, exact finite.intro (f.symm.trans e) }
lemma equiv.finite_iff (f : α ≃ β) : finite α ↔ finite β :=
⟨λ _, by exactI finite.of_equiv _ f, λ _, by exactI finite.of_equiv _ f.symm⟩
lemma function.bijective.finite_iff {f : α → β} (h : bijective f) : finite α ↔ finite β :=
(equiv.of_bijective f h).finite_iff
lemma finite.of_bijective [finite α] {f : α → β} (h : bijective f) : finite β := h.finite_iff.mp ‹_›
instance [finite α] : finite (plift α) := finite.of_equiv α equiv.plift.symm
instance {α : Type v} [finite α] : finite (ulift.{u} α) := finite.of_equiv α equiv.ulift.symm
/-- A type is said to be infinite if it is not finite. Note that `infinite α` is equivalent to
`is_empty (fintype α)` or `is_empty (finite α)`. -/
class infinite (α : Sort*) : Prop :=
(not_finite : ¬finite α)
@[simp] lemma not_finite_iff_infinite : ¬finite α ↔ infinite α := ⟨infinite.mk, λ h, h.1⟩
@[simp] lemma not_infinite_iff_finite : ¬infinite α ↔ finite α :=
not_finite_iff_infinite.not_right.symm
lemma equiv.infinite_iff (e : α ≃ β) : infinite α ↔ infinite β :=
not_finite_iff_infinite.symm.trans $ e.finite_iff.not.trans not_finite_iff_infinite
instance [infinite α] : infinite (plift α) := equiv.plift.infinite_iff.2 ‹_›
instance {α : Type v} [infinite α] : infinite (ulift.{u} α) := equiv.ulift.infinite_iff.2 ‹_›
lemma finite_or_infinite (α : Sort*) : finite α ∨ infinite α :=
or_iff_not_imp_left.2 $ not_finite_iff_infinite.1
lemma not_finite (α : Sort*) [infinite α] [finite α] : false := @infinite.not_finite α ‹_› ‹_›
protected lemma finite.false [infinite α] (h : finite α) : false := not_finite α
protected lemma infinite.false [finite α] (h : infinite α) : false := not_finite α
alias not_infinite_iff_finite ↔ finite.of_not_infinite finite.not_infinite
|
24ddda9d4559d02549932210d39c3b0d0d0068db | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/inner_product_space/conformal_linear_map.lean | a2ba89447a81e4f13f46006f6c97a3bbd5fa54df | [
"Apache-2.0"
] | permissive | robertylewis/mathlib | 3d16e3e6daf5ddde182473e03a1b601d2810952c | 1d13f5b932f5e40a8308e3840f96fc882fae01f0 | refs/heads/master | 1,651,379,945,369 | 1,644,276,960,000 | 1,644,276,960,000 | 98,875,504 | 0 | 0 | Apache-2.0 | 1,644,253,514,000 | 1,501,495,700,000 | Lean | UTF-8 | Lean | false | false | 1,778 | lean | /-
Copyright (c) 2021 Yourong Zang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yourong Zang
-/
import analysis.normed_space.conformal_linear_map
import analysis.inner_product_space.basic
/-!
# Conformal maps between inner product spaces
In an inner product space, a map is conformal iff it preserves inner products up to a scalar factor.
-/
variables {E F : Type*} [inner_product_space ℝ E] [inner_product_space ℝ F]
open linear_isometry continuous_linear_map
open_locale real_inner_product_space
lemma is_conformal_map_iff (f' : E →L[ℝ] F) :
is_conformal_map f' ↔ ∃ (c : ℝ), 0 < c ∧
∀ (u v : E), ⟪f' u, f' v⟫ = (c : ℝ) * ⟪u, v⟫ :=
begin
split,
{ rintros ⟨c₁, hc₁, li, h⟩,
refine ⟨c₁ * c₁, mul_self_pos.2 hc₁, λ u v, _⟩,
simp only [h, pi.smul_apply, inner_map_map,
real_inner_smul_left, real_inner_smul_right, mul_assoc], },
{ rintros ⟨c₁, hc₁, huv⟩,
let c := real.sqrt c₁⁻¹,
have hc : c ≠ 0 := λ w, by {simp only [c] at w;
exact (real.sqrt_ne_zero'.mpr $ inv_pos.mpr hc₁) w},
let f₁ := c • f',
have minor : (f₁ : E → F) = c • f' := rfl,
have minor' : (f' : E → F) = c⁻¹ • f₁ := by ext;
simp_rw [minor, pi.smul_apply]; rw [smul_smul, inv_mul_cancel hc, one_smul],
refine ⟨c⁻¹, inv_ne_zero hc, f₁.to_linear_map.isometry_of_inner (λ u v, _), minor'⟩,
simp_rw [to_linear_map_eq_coe, continuous_linear_map.coe_coe, minor, pi.smul_apply],
rw [real_inner_smul_left, real_inner_smul_right,
huv u v, ← mul_assoc, ← mul_assoc,
real.mul_self_sqrt $ le_of_lt $ inv_pos.mpr hc₁,
inv_mul_cancel $ ne_of_gt hc₁, one_mul], },
end
|
dcd1c814f31050053a18780eecc8a601bb3727c2 | 64874bd1010548c7f5a6e3e8902efa63baaff785 | /hott/init/priority.hlean | 8a23b069571a8dc8676749cc4a88cbf0c0e5e517 | [
"Apache-2.0"
] | permissive | tjiaqi/lean | 4634d729795c164664d10d093f3545287c76628f | d0ce4cf62f4246b0600c07e074d86e51f2195e30 | refs/heads/master | 1,622,323,796,480 | 1,422,643,069,000 | 1,422,643,069,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 293 | hlean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.datatypes
definition std.priority.default : num := 1000
definition std.priority.max : num := 4294967295
|
b1ba94f4c0b80058207655da8fa81e8cafab8507 | ccb7cdf8ebc2d015a000e8e7904952a36b910425 | /src/heap/tactic.lean | 56abaac0d7662f7de014acaeba8fa68ca3a399b3 | [] | no_license | cipher1024/lean-pl | f7258bda55606b75e3e39deaf7ce8928ed177d66 | 829680605ac17e91038d793c0188e9614353ca25 | refs/heads/master | 1,592,558,951,987 | 1,565,043,356,000 | 1,565,043,531,000 | 196,661,367 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,656 | lean |
import category.bitraversable.instances
import heap.basic
open memory
section disjoint
variables {val : Type}
inductive disj : list (list (heap val)) → Prop
| nil : disj []
| cons {xs : list (heap val)} {xss : list (list (heap val))} :
(∀ (x ∈ xs) (ys ∈ xss) (y ∈ ys), finmap.disjoint x y) →
disj xss → disj (xs :: xss)
def union' : list (heap val) → heap val
| [] := ∅
| [x] := x
| (x :: xs) := x ∪ union' xs
def {u} all_pairs' {α : Type u} : list α → list (list α) → list (α × α)
| xs [] := []
| xs (y::ys) := xs.product y ++ all_pairs' (y ++ xs) ys
def {u} all_pairs {α : Type u} : list (list α) → list (α × α) :=
all_pairs' []
variables (x x' : heap val)
variables (xs : list (heap val))
variables (xss : list (list (heap val)))
open finmap
def disj_all := (∀ (x ∈ xs) (ys ∈ xss) (y ∈ ys), disjoint x y)
variables {x' x xs xss}
def all_pairs_disjoint (xs : list (heap val × heap val)) :=
∀ x y, (x,y) ∈ xs → disjoint x y
lemma all_pairs_disjoint_of_all_pairs_disjoint_cons {x : heap val × heap val} {xs : list $ heap val × heap val} :
all_pairs_disjoint (x :: xs) → all_pairs_disjoint xs
| H x y Hxy := H _ _ (or.inr Hxy)
lemma disjoint_of_all_pairs_disjoint_cons {x y : heap val} {xs : list $ heap val × heap val} :
all_pairs_disjoint ((x,y) :: xs) → disjoint x y
| H := H _ _ (or.inl rfl)
lemma all_pairs_disjoint_of_disj' : Π {xss : list (list (heap val))} (ys : list (heap val)), disj_all ys xss → disj xss → ∀ x y, (x,y) ∈ all_pairs' ys xss → disjoint x y
| (xs :: xss) ys Hys (disj.cons h h') a b h'' :=
have a ∈ ys ∧ b ∈ xs ∨ (a, b) ∈ all_pairs' (xs ++ ys) xss, by simpa [all_pairs',list.mem_append] using h'',
or.cases_on this
(λ ⟨h,h'⟩, Hys _ h xs (or.inl rfl) _ h')
(λ h₂,
have h₃ : disj_all (xs ++ ys) xss,
from (λ a' Ha' zs Hzs y Hy,
by { simp at Ha', cases Ha';
[ apply h _ Ha' _ Hzs _ Hy,
apply Hys _ Ha' zs (or.inr Hzs) _ Hy] }),
all_pairs_disjoint_of_disj' (xs ++ ys) h₃ h' _ _ (h₂ ))
lemma all_pairs_disjoint_of_disj : Π {xss : list (list (heap val))}, disj xss → all_pairs_disjoint (all_pairs xss)
| xss h a b h'' :=
all_pairs_disjoint_of_disj' [] (λ x, false.elim) h _ _ h''
lemma disj_of_disj_cons_cons : disj ((x :: xs) :: xss) → disj (xs :: xss)
| (disj.cons h' h) := disj.cons (λ y hy ys hys z hz, h' _ (or.inr hy) ys hys _ hz) h
lemma disj_of_disj_nil_cons : disj ([] :: xss) → disj xss
| (disj.cons _ h) := h
@[simp]
lemma union_nil : @union' val [] = ∅ :=
rfl
@[simp]
lemma union_cons : union' (x :: xs) = x ∪ union' xs :=
by { cases xs with x' xs; simp [union'] }
def sum' : list (list (heap val)) → option (heap val)
| [] := some ∅
| [x] := some (union' x)
| (x :: xs) := some (union' x) ⊗ sum' xs
@[simp]
lemma sum_cons : sum' (xs :: xss) = some (union' xs) ⊗ sum' xss :=
by cases xss; simp [sum']
variables {x xs xss}
section finmap
variables {α : Type*} {β : α → Type*}
lemma sub_union_left [decidable_eq α] {x y z : finmap β} (h : x ⊆ y) : x ⊆ y ∪ z :=
λ a hx, finmap.mem_union.mpr $ or.inl (h _ hx)
lemma sub_union_right [decidable_eq α] {x y z : finmap β} (h : x ⊆ z) : x ⊆ y ∪ z :=
λ a hx, finmap.mem_union.mpr $ or.inr (h _ hx)
lemma sub_union_self_left [decidable_eq α] {x y : finmap β} : x ⊆ x ∪ y :=
λ a hx, finmap.mem_union.mpr $ or.inl hx
lemma sub_union_self_right [decidable_eq α] {x y : finmap β} : x ⊆ y ∪ x :=
λ a hx, finmap.mem_union.mpr $ or.inr hx
@[refl]
lemma sub_refl (x : finmap β) : x ⊆ x :=
λ a, id
@[trans]
lemma sub_trans {x y z : finmap β} (h₀ : x ⊆ y) (h₁ : y ⊆ z) : x ⊆ z :=
λ a hx, h₁ _ (h₀ _ hx)
end finmap
lemma sub_union'_of_mem {x : heap val} {xs : list (heap val)} (h : x ∈ xs) :
x ⊆ union' xs :=
begin
induction xs; cases h,
{ subst xs_hd, simp, apply sub_union_self_left },
{ transitivity', apply xs_ih h,
simp, apply sub_union_self_right }
end
lemma eq_union'_of_eq_sum {x : heap val} {xss : list $ list (heap val)}
(H : some x = sum' xss) :
x = union' (xss.map union') :=
begin
induction xss generalizing x,
{ simp [union',sum'] at *, exact H },
{ simp [sum'] at *,
rcases add_eq_some' _ _ _ H with ⟨ y, Hy ⟩,
rw ← Hy at H,
replace H := eq_union_of_eq_add H,
replace Hy := xss_ih Hy, cc },
end
lemma disj_of_some_eq_sum :
some x = sum' xss → disj xss :=
begin
introv Hxy,
induction xss with xs xss generalizing x, constructor,
simp at Hxy,
rcases add_eq_some' _ _ _ Hxy with ⟨y, Hy⟩,
constructor,
{ introv Hx Hys Hy', rw ← Hy at Hxy,
replace Hxy := disjoint_of_add _ Hxy,
apply memory.disjoint_mono' (sub_union'_of_mem Hx) _ Hxy,
rw eq_union'_of_eq_sum Hy,
transitivity' union' ys,
apply sub_union'_of_mem Hy',
apply sub_union'_of_mem, rw list.mem_map,
existsi [_,Hys], refl },
{ apply xss_ih Hy }
end
lemma all_pairs_disj_of_some_eq_sum (h : some x = sum' xss) :
all_pairs_disjoint (all_pairs xss) :=
all_pairs_disjoint_of_disj $ disj_of_some_eq_sum h
def all_subset (x : heap val) (xs : list (heap val)) :=
∀ y ∈ xs, y ⊆ x
lemma all_subset_of_some_eq_sum (h : some x = sum' xss) :
all_subset x xss.join :=
begin
induction xss generalizing x,
{ rintro _ ⟨ ⟩ },
{ simp at h,
rcases add_eq_some' _ _ _ h with ⟨w,hw⟩,
rw ← hw at h,
simp [all_subset],
rw eq_union_of_eq_add h,
rintro y (h'|⟨l,h₀,h₁⟩),
{ apply sub_union_left (sub_union'_of_mem h'), },
{ apply sub_union_right,
apply xss_ih hw y, rw list.mem_join,
exact ⟨_,h₀,h₁⟩ }, }
end
lemma all_subset_of_all_subset_cons (h : all_subset x (x' :: xs)) : all_subset x xs :=
λ a Ha, h _ (or.inr Ha)
lemma subset_of_all_subset_cons (h : all_subset x (x' :: xs)) : x' ⊆ x :=
h _ (or.inl rfl)
end disjoint
namespace tactic
@[reducible]
meta def graph := expr_map (list (expr × expr))
meta def parse_union : expr → tactic (list expr)
| `(%%x ∪ %%y) := (++) <$> parse_union x <*> parse_union y
| e := pure [e]
-- | _ := failed
meta def parse_sum : expr → tactic (list (list expr))
| `(some %%x) := list.ret <$> parse_union x
| `(%%x ⊗ %%y) := (++) <$> parse_sum x <*> parse_sum y
| _ := failed
lemma heap.rotate {α} (h : heap α) (h' h'' : option (heap α)) :
h' ⊗ h'' = some h ↔ some h = h' ⊗ h'' :=
⟨ eq.symm, eq.symm ⟩
meta def add_disj_edge (d : graph) (pr n n' : expr) : tactic graph :=
do pr' ← mk_mapp ``finmap.disjoint.symm [none,none,none,none,pr],
pure $ (d.insert_cons n (n', pr)).insert_cons n' (n,pr')
open function
meta def add_disjoint (xs : list (expr × expr × expr)) (d : graph) : tactic graph :=
xs.mfoldl (λ d ⟨x,y,h⟩,
do h' ← mk_mapp ``finmap.disjoint.symm [none,none,none,none,h],
pure $ (d.insert_cons x (y,h)).insert_cons y (x,h') ) d
meta def add_subset (xs : list (expr × expr × expr)) (d : graph) : graph :=
xs.foldl (λ d ⟨x,y,h⟩, d.insert_cons x (y,h) ) d
meta def reachable' (g : graph) (root : expr) : expr → expr_map expr → expr × expr → tactic (expr_map expr)
| pr s n :=
if s.contains n.1 then pure s
else do
pr' ← to_expr ``(sub_trans %%pr %%(n.2)),
(g.find_def [] n.1).mfoldl (reachable' pr') (s.insert n.1 pr')
meta def reachable (g : graph) (v : expr) : tactic (expr_map expr) :=
do pr ← mk_mapp ``sub_refl [none,none,v],
reachable' g v pr (mk_expr_map ) (v, pr)
setup_tactic_parser
meta def to_pair : expr × expr → tactic expr
| (x,y) := mk_app ``prod.mk [x,y]
meta def to_list (t : expr) : list expr → tactic expr
| [] := mk_app ``list.nil [t]
| (x :: xs) :=
do xs' ← to_list xs,
mk_app ``list.cons [x,xs']
meta def to_sum (t : expr) (xs : list (list expr)) : tactic expr :=
do ts ← mk_app ``list [t],
xs' ← xs.mmap (to_list t) >>= to_list ts,
mk_app ``sum' [xs']
meta def replace' (h : expr) (p : option expr) (e : expr) : tactic expr :=
note h.local_pp_name p e <* clear h
meta def mk_disj_hyps : list (expr × expr) → expr → tactic (list (expr × expr × expr))
| [] h := clear h *> pure []
| ((x,y) :: xss) h :=
do Hxy ← mk_mapp ``disjoint_of_all_pairs_disjoint_cons [none,none,none,none,h],
Hxy ← note (`h ++ x.local_pp_name ++ y.local_pp_name <.> "disj") none Hxy,
h ← mk_mapp ``all_pairs_disjoint_of_all_pairs_disjoint_cons [none,none,none,h] >>=
replace' h none,
list.cons (x,y,Hxy) <$> mk_disj_hyps xss h
meta def mk_sub_hyps (s : expr) : list expr → expr → tactic (list (expr × expr × expr))
| [] h := clear h *> pure []
| (x :: xss) h :=
do Hxy ← mk_mapp ``subset_of_all_subset_cons [none,none,none,none,h],
Hxy ← note (`h ++ x.local_pp_name ++ s.local_pp_name <.> "sub") none Hxy,
h ← mk_mapp ``all_subset_of_all_subset_cons [none,none,none,none,h] >>=
replace' h none,
-- trace!"sub: s: {s}; x: {x}; h: {infer_type h}",
list.cons (x,s,Hxy) <$> mk_sub_hyps xss h
meta def mk_sum_form (h : expr) : tactic (expr × expr × expr × list (list expr)) :=
do `(%%l = %%r) ← infer_type h,
`(some %%l') ← pure l,
`(option %%v) ← infer_type l,
r ← parse_sum r,
r' ← to_sum v r,
ht ← mk_app `eq [l,r'],
h ← assertv (h.local_pp_name ++ `sum) ht h,
pure (v,h,l',r)
meta def mk_disjointness_hyps (v h : expr) (r : list (list expr)) : tactic (list $ expr × expr × expr) :=
do p ← mk_mapp ``all_pairs_disj_of_some_eq_sum [none,none,none,h],
h ← note h.local_pp_name none p,
prod_t ← mk_app ``prod [v,v],
let r := all_pairs r,
x ← r.mmap to_pair >>= to_list prod_t,
x ← mk_app ``all_pairs_disjoint [x],
h ← replace' h (some x) h,
mk_disj_hyps r h
meta def mk_subset_hyps (v h l : expr) (r : list (list expr)) : tactic (list $ expr × expr × expr) :=
do p ← mk_mapp ``all_subset_of_some_eq_sum [none,none,none,h],
h ← note h.local_pp_name none p,
let r := r.join,
r' ← to_list v r,
ht ← mk_app ``all_subset [l,r'],
h ← replace' h (some ht) h,
mk_sub_hyps l r h
meta def parse_asm (s d : graph) : expr → expr → tactic (graph × graph)
| pr `(finmap.disjoint %%x %%y) :=
if x.is_local_constant ∧ y.is_local_constant
then do
d' ← add_disj_edge d pr x y,
pure (s,d')
else pure (s,d)
| pr `(%%x = %%y) :=
do [[x]] ← parse_sum x | pure (s,d),
(v,h,x,r) ← mk_sum_form pr,
ys ← mk_disjointness_hyps v h r,
d ← add_disjoint ys d,
zs ← mk_subset_hyps v h x r,
let s := add_subset zs s,
pure (s,d)
| _ _ := pure (s,d)
meta def mk_graph (t : expr) : tactic (graph × graph) :=
do let s : graph := expr_map.mk (list (expr × expr)),
let d : graph := expr_map.mk (list (expr × expr)),
ls ← local_context,
ht ← mk_app ``heap [t],
ls.mfoldl (λ ⟨s,d⟩ l,
do t ← infer_type l,
if t = ht then
pure (s.insert_if_absent l [],d.insert_if_absent l [])
else
parse_asm s d l t ) (s, d)
meta def split_asm : expr → expr → tactic unit
| h `(some %%h₀ = some %%h₁ ⊗ some %%h₂ ⊗ %%h₃) :=
do h' ← mk_app ``add_eq_some' [h],
h' ← note `h none h',
[(_, ([w,h'],_))] ← cases_core h',
ht ← infer_type h',
h ← mk_eq_symm h' >>= flip rewrite_hyp h,
split_asm h' ht
| _ _ := skip
meta def preprocess : tactic unit :=
do `[simp only [option.some_inj,tactic.heap.rotate,memory.add_assoc,finmap.union_assoc] at * { fail_if_unchanged := ff }],
subst_vars,
ls ← local_context,
ls.mmap' $ λ l,
infer_type l >>= split_asm l
meta def interactive.prove_disjoint : tactic unit :=
do preprocess,
`(finmap.disjoint %%x %%y) ← target,
`(heap %%v) ← infer_type x,
(s,d) ← mk_graph v,
mx ← reachable s x,
my ← reachable s y,
mx.to_list.any_of $ λ ⟨a,pa⟩,
(d.find_def [] a).any_of $ λ ⟨b,pb⟩,
do pc ← my.find b,
refine ``(disjoint_mono' %%pa %%pc %%pb)
end tactic
open memory tactic native
variables
h₀ h₁ h₂ h₃ h₄ h₅
h₆ h₇ h₈ h₉ : heap ℕ
example (H₂ : some h₂ = some h₁ ⊗ some h₀)
(H₅ : some h₅ = some h₄ ⊗ some h₃)
-- (H₈ : some h₈ = some h₇ ⊗ some h₆)
(H₈ : some h₈ = some (h₇ ∪ h₄) ⊗ some h₆ ⊗ some h₄ ⊗ some (h₃ ∪ h₀ ∪ h₂))
(H₈ : some h₈ = some (h₇ ∪ h₄) ⊗ some (h₃ ∪ h₀ ∪ h₂))
-- (H₉ : some h₉ = some h₂ ⊗ some h₅)
(H : finmap.disjoint h₅ h₂)
(H₁₀ : some h₀ = some h₁) :
finmap.disjoint h₀ h₄ :=
begin
prove_disjoint,
end
|
6e3bfef4594d91f696da14a1ca43c35346769fc7 | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/order/order_iso.lean | 34ef9891c861653d3e30176b365fa2ab19ee74ad | [
"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 | 13,463 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import order.basic logic.embedding data.nat.basic
open function
universes u v w
variables {α : Type*} {β : Type*} {γ : Type*}
{r : α → α → Prop} {s : β → β → Prop} {t : γ → γ → Prop}
/-- An increasing function is injective -/
lemma injective_of_increasing (r : α → α → Prop) (s : β → β → Prop) [is_trichotomous α r]
[is_irrefl β s] (f : α → β) (hf : ∀{x y}, r x y → s (f x) (f y)) : injective f :=
begin
intros x y hxy,
rcases trichotomous_of r x y with h | h | h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this,
exact h,
have := hf h, rw hxy at this, exfalso, exact irrefl_of s (f y) this
end
structure order_embedding {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ↪ β :=
(ord : ∀ {a b}, r a b ↔ s (to_embedding a) (to_embedding b))
infix ` ≼o `:50 := order_embedding
/-- the induced order on a subtype is an embedding under the natural inclusion. -/
definition subtype.order_embedding {X : Type*} (r : X → X → Prop) (p : X → Prop) :
((subtype.val : subtype p → X) ⁻¹'o r) ≼o r :=
⟨⟨subtype.val,subtype.val_injective⟩,by intros;refl⟩
theorem preimage_equivalence {α β} (f : α → β) {s : β → β → Prop}
(hs : equivalence s) : equivalence (f ⁻¹'o s) :=
⟨λ a, hs.1 _, λ a b h, hs.2.1 h, λ a b c h₁ h₂, hs.2.2 h₁ h₂⟩
namespace order_embedding
instance : has_coe_to_fun (r ≼o s) := ⟨λ _, α → β, λ o, o.to_embedding⟩
theorem ord' : ∀ (f : r ≼o s) {a b}, r a b ↔ s (f a) (f b)
| ⟨f, o⟩ := @o
@[simp] theorem coe_fn_mk (f : α ↪ β) (o) :
(@order_embedding.mk _ _ r s f o : α → β) = f := rfl
@[simp] theorem coe_fn_to_embedding (f : r ≼o s) : (f.to_embedding : α → β) = f := rfl
theorem eq_of_to_fun_eq : ∀ {e₁ e₂ : r ≼o s}, (e₁ : α → β) = e₂ → e₁ = e₂
| ⟨⟨f₁, h₁⟩, o₁⟩ ⟨⟨f₂, h₂⟩, o₂⟩ h := by congr; exact h
@[refl] protected def refl (r : α → α → Prop) : r ≼o r :=
⟨embedding.refl _, λ a b, iff.rfl⟩
@[trans] protected def trans (f : r ≼o s) (g : s ≼o t) : r ≼o t :=
⟨f.1.trans g.1, λ a b, by rw [f.2, g.2]; simp⟩
@[simp] theorem refl_apply (x : α) : order_embedding.refl r x = x := rfl
@[simp] theorem trans_apply (f : r ≼o s) (g : s ≼o t) (a : α) : (f.trans g) a = g (f a) := rfl
/-- An order embedding is also an order embedding between dual orders. -/
def rsymm (f : r ≼o s) : swap r ≼o swap s :=
⟨f.to_embedding, λ a b, f.ord'⟩
/-- If `f` is injective, then it is an order embedding from the
preimage order of `s` to `s`. -/
def preimage (f : α ↪ β) (s : β → β → Prop) : f ⁻¹'o s ≼o s := ⟨f, λ a b, iff.rfl⟩
theorem eq_preimage (f : r ≼o s) : r = f ⁻¹'o s :=
by funext a b; exact propext f.ord'
protected theorem is_irrefl : ∀ (f : r ≼o s) [is_irrefl β s], is_irrefl α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a h, H _ (o.1 h)⟩
protected theorem is_refl : ∀ (f : r ≼o s) [is_refl β s], is_refl α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a, o.2 (H _)⟩
protected theorem is_symm : ∀ (f : r ≼o s) [is_symm β s], is_symm α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h, o.2 (H _ _ (o.1 h))⟩
protected theorem is_asymm : ∀ (f : r ≼o s) [is_asymm β s], is_asymm α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h₁ h₂, H _ _ (o.1 h₁) (o.1 h₂)⟩
protected theorem is_antisymm : ∀ (f : r ≼o s) [is_antisymm β s], is_antisymm α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b h₁ h₂, f.inj' (H _ _ (o.1 h₁) (o.1 h₂))⟩
protected theorem is_trans : ∀ (f : r ≼o s) [is_trans β s], is_trans α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b c h₁ h₂, o.2 (H _ _ _ (o.1 h₁) (o.1 h₂))⟩
protected theorem is_total : ∀ (f : r ≼o s) [is_total β s], is_total α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b, (or_congr o o).2 (H _ _)⟩
protected theorem is_preorder : ∀ (f : r ≼o s) [is_preorder β s], is_preorder α r
| f H := by exactI {..f.is_refl, ..f.is_trans}
protected theorem is_partial_order : ∀ (f : r ≼o s) [is_partial_order β s], is_partial_order α r
| f H := by exactI {..f.is_preorder, ..f.is_antisymm}
protected theorem is_linear_order : ∀ (f : r ≼o s) [is_linear_order β s], is_linear_order α r
| f H := by exactI {..f.is_partial_order, ..f.is_total}
protected theorem is_strict_order : ∀ (f : r ≼o s) [is_strict_order β s], is_strict_order α r
| f H := by exactI {..f.is_irrefl, ..f.is_trans}
protected theorem is_trichotomous : ∀ (f : r ≼o s) [is_trichotomous β s], is_trichotomous α r
| ⟨f, o⟩ ⟨H⟩ := ⟨λ a b, (or_congr o (or_congr f.inj'.eq_iff.symm o)).2 (H _ _)⟩
protected theorem is_strict_total_order' : ∀ (f : r ≼o s) [is_strict_total_order' β s], is_strict_total_order' α r
| f H := by exactI {..f.is_trichotomous, ..f.is_strict_order}
protected theorem acc (f : r ≼o s) (a : α) : acc s (f a) → acc r a :=
begin
generalize h : f a = b, intro ac,
induction ac with _ H IH generalizing a, subst h,
exact ⟨_, λ a' h, IH (f a') (f.ord'.1 h) _ rfl⟩
end
protected theorem well_founded : ∀ (f : r ≼o s) (h : well_founded s), well_founded r
| f ⟨H⟩ := ⟨λ a, f.acc _ (H _)⟩
protected theorem is_well_order : ∀ (f : r ≼o s) [is_well_order β s], is_well_order α r
| f H := by exactI {wf := f.well_founded H.wf, ..f.is_strict_total_order'}
/-- It suffices to prove `f` is monotone between strict orders
to show it is an order embedding. -/
def of_monotone [is_trichotomous α r] [is_asymm β s] (f : α → β) (H : ∀ a b, r a b → s (f a) (f b)) : r ≼o s :=
begin
haveI := @is_irrefl_of_is_asymm β s _,
refine ⟨⟨f, λ a b e, _⟩, λ a b, ⟨H _ _, λ h, _⟩⟩,
{ refine ((@trichotomous _ r _ a b).resolve_left _).resolve_right _;
exact λ h, @irrefl _ s _ _ (by simpa [e] using H _ _ h) },
{ refine (@trichotomous _ r _ a b).resolve_right (or.rec (λ e, _) (λ h', _)),
{ subst e, exact irrefl _ h },
{ exact asymm (H _ _ h') h } }
end
@[simp] theorem of_monotone_coe [is_trichotomous α r] [is_asymm β s] (f : α → β) (H) :
(@of_monotone _ _ r s _ _ f H : α → β) = f := rfl
-- If le is preserved by an order embedding of preorders, then lt is too
def lt_embedding_of_le_embedding [preorder α] [preorder β]
(f : (has_le.le : α → α → Prop) ≼o (has_le.le : β → β → Prop)) :
(has_lt.lt : α → α → Prop) ≼o (has_lt.lt : β → β → Prop) :=
{ to_fun := f,
inj := f.inj,
ord := by intros; simp [lt_iff_le_not_le,f.ord] }
theorem nat_lt [is_strict_order α r] (f : ℕ → α) (H : ∀ n:ℕ, r (f n) (f (n+1))) :
((<) : ℕ → ℕ → Prop) ≼o r :=
of_monotone f $ λ a b h, begin
induction b with b IH, {exact (nat.not_lt_zero _ h).elim},
cases nat.lt_succ_iff_lt_or_eq.1 h with h e,
{ exact trans (IH h) (H _) },
{ subst b, apply H }
end
theorem nat_gt [is_strict_order α r] (f : ℕ → α) (H : ∀ n:ℕ, r (f (n+1)) (f n)) :
((>) : ℕ → ℕ → Prop) ≼o r :=
by haveI := is_strict_order.swap r; exact rsymm (nat_lt f H)
theorem well_founded_iff_no_descending_seq [is_strict_order α r] : well_founded r ↔ ¬ nonempty (((>) : ℕ → ℕ → Prop) ≼o r) :=
⟨λ ⟨h⟩ ⟨⟨f, o⟩⟩,
suffices ∀ a, acc r a → ∀ n, a ≠ f n, from this (f 0) (h _) 0 rfl,
λ a ac, begin
induction ac with a _ IH, intros n h, subst a,
exact IH (f (n+1)) (o.1 (nat.lt_succ_self _)) _ rfl
end,
λ N, ⟨λ a, classical.by_contradiction $ λ na,
let ⟨f, h⟩ := classical.axiom_of_choice $
show ∀ x : {a // ¬ acc r a}, ∃ y : {a // ¬ acc r a}, r y.1 x.1,
from λ ⟨x, h⟩, classical.by_contradiction $ λ hn, h $
⟨_, λ y h, classical.by_contradiction $ λ na, hn ⟨⟨y, na⟩, h⟩⟩ in
N ⟨nat_gt (λ n, (f^[n] ⟨a, na⟩).1) $ λ n,
by rw nat.iterate_succ'; apply h⟩⟩⟩
end order_embedding
/-- The inclusion map `fin n → ℕ` is an order embedding. -/
def fin.val.order_embedding (n) : @order_embedding (fin n) ℕ (<) (<) :=
⟨⟨fin.val, @fin.eq_of_veq _⟩, λ a b, iff.rfl⟩
/-- The inclusion map `fin m → fin n` is an order embedding. -/
def fin_fin.order_embedding {m n} (h : m ≤ n) : @order_embedding (fin m) (fin n) (<) (<) :=
⟨⟨λ ⟨x, h'⟩, ⟨x, lt_of_lt_of_le h' h⟩,
λ ⟨a, _⟩ ⟨b, _⟩ h, by congr; injection h⟩,
by intros; cases a; cases b; refl⟩
instance fin.lt.is_well_order (n) : is_well_order (fin n) (<) :=
(fin.val.order_embedding _).is_well_order
/-- An order isomorphism is an equivalence that is also an order embedding. -/
structure order_iso {α β : Type*} (r : α → α → Prop) (s : β → β → Prop) extends α ≃ β :=
(ord : ∀ {a b}, r a b ↔ s (to_equiv a) (to_equiv b))
infix ` ≃o `:50 := order_iso
namespace order_iso
def to_order_embedding (f : r ≃o s) : r ≼o s :=
⟨f.to_equiv.to_embedding, f.ord⟩
instance : has_coe (r ≃o s) (r ≼o s) := ⟨to_order_embedding⟩
theorem coe_coe_fn (f : r ≃o s) : ((f : r ≼o s) : α → β) = f := rfl
theorem ord' : ∀ (f : r ≃o s) {a b}, r a b ↔ s (f a) (f b)
| ⟨f, o⟩ := @o
@[simp] theorem coe_fn_mk (f : α ≃ β) (o) :
(@order_iso.mk _ _ r s f o : α → β) = f := rfl
@[simp] theorem coe_fn_to_equiv (f : r ≃o s) : (f.to_equiv : α → β) = f := rfl
theorem eq_of_to_fun_eq : ∀ {e₁ e₂ : r ≃o s}, (e₁ : α → β) = e₂ → e₁ = e₂
| ⟨e₁, o₁⟩ ⟨e₂, o₂⟩ h := by congr; exact equiv.eq_of_to_fun_eq h
@[refl] protected def refl (r : α → α → Prop) : r ≃o r :=
⟨equiv.refl _, λ a b, iff.rfl⟩
@[symm] protected def symm (f : r ≃o s) : s ≃o r :=
⟨f.to_equiv.symm, λ a b, by cases f with f o; rw o; simp⟩
@[trans] protected def trans (f₁ : r ≃o s) (f₂ : s ≃o t) : r ≃o t :=
⟨f₁.to_equiv.trans f₂.to_equiv, λ a b,
by cases f₁ with f₁ o₁; cases f₂ with f₂ o₂; rw [o₁, o₂]; simp⟩
@[simp] theorem coe_fn_symm_mk (f o) : ((@order_iso.mk _ _ r s f o).symm : β → α) = f.symm :=
rfl
@[simp] theorem refl_apply (x : α) : order_iso.refl r x = x := rfl
@[simp] theorem trans_apply : ∀ (f : r ≃o s) (g : s ≃o t) (a : α), (f.trans g) a = g (f a)
| ⟨f₁, o₁⟩ ⟨f₂, o₂⟩ a := equiv.trans_apply _ _ _
@[simp] theorem apply_symm_apply : ∀ (e : r ≃o s) (x : β), e (e.symm x) = x
| ⟨f₁, o₁⟩ x := by simp
@[simp] theorem symm_apply_apply : ∀ (e : r ≃o s) (x : α), e.symm (e x) = x
| ⟨f₁, o₁⟩ x := by simp
/-- Any equivalence lifts to an order isomorphism between `s` and its preimage. -/
def preimage (f : α ≃ β) (s : β → β → Prop) : f ⁻¹'o s ≃o s := ⟨f, λ a b, iff.rfl⟩
noncomputable def of_surjective (f : r ≼o s) (H : surjective f) : r ≃o s :=
⟨equiv.of_bijective ⟨f.inj, H⟩, by simp [f.ord']⟩
@[simp] theorem of_surjective_coe (f : r ≼o s) (H) : (of_surjective f H : α → β) = f :=
by delta of_surjective; simp
theorem sum_lex_congr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂}
(e₁ : @order_iso α₁ α₂ r₁ r₂) (e₂ : @order_iso β₁ β₂ s₁ s₂) :
sum.lex r₁ s₁ ≃o sum.lex r₂ s₂ :=
⟨equiv.sum_congr e₁.to_equiv e₂.to_equiv, λ a b,
by cases e₁ with f hf; cases e₂ with g hg;
cases a; cases b; simp [hf, hg]⟩
theorem prod_lex_congr {α₁ α₂ β₁ β₂ r₁ r₂ s₁ s₂}
(e₁ : @order_iso α₁ α₂ r₁ r₂) (e₂ : @order_iso β₁ β₂ s₁ s₂) :
prod.lex r₁ s₁ ≃o prod.lex r₂ s₂ :=
⟨equiv.prod_congr e₁.to_equiv e₂.to_equiv, λ a b, begin
cases e₁ with f hf; cases e₂ with g hg,
cases a with a₁ a₂; cases b with b₁ b₂,
suffices : prod.lex r₁ s₁ (a₁, a₂) (b₁, b₂) ↔
prod.lex r₂ s₂ (f a₁, g a₂) (f b₁, g b₂), {simpa [hf, hg]},
split,
{ intro h, cases h with _ _ _ _ h _ _ _ h,
{ left, exact hf.1 h },
{ right, exact hg.1 h } },
{ generalize e : f b₁ = fb₁,
intro h, cases h with _ _ _ _ h _ _ _ h,
{ subst e, left, exact hf.2 h },
{ have := f.injective e, subst b₁,
right, exact hg.2 h } }
end⟩
end order_iso
/-- A subset `p : set α` embeds into `α` -/
def set_coe_embedding {α : Type*} (p : set α) : p ↪ α := ⟨subtype.val, @subtype.eq _ _⟩
/-- `subrel r p` is the inherited relation on a subset. -/
def subrel (r : α → α → Prop) (p : set α) : p → p → Prop :=
@subtype.val _ p ⁻¹'o r
@[simp] theorem subrel_val (r : α → α → Prop) (p : set α)
{a b} : subrel r p a b ↔ r a.1 b.1 := iff.rfl
namespace subrel
protected def order_embedding (r : α → α → Prop) (p : set α) :
subrel r p ≼o r := ⟨set_coe_embedding _, λ a b, iff.rfl⟩
@[simp] theorem order_embedding_apply (r : α → α → Prop) (p a) :
subrel.order_embedding r p a = a.1 := rfl
instance (r : α → α → Prop) [is_well_order α r]
(p : set α) : is_well_order p (subrel r p) :=
order_embedding.is_well_order (subrel.order_embedding r p)
end subrel
/-- Restrict the codomain of an order embedding -/
def order_embedding.cod_restrict (p : set β) (f : r ≼o s) (H : ∀ a, f a ∈ p) : r ≼o subrel s p :=
⟨f.to_embedding.cod_restrict p H, f.ord⟩
@[simp] theorem order_embedding.cod_restrict_apply (p) (f : r ≼o s) (H a) :
order_embedding.cod_restrict p f H a = ⟨f a, H a⟩ := rfl
|
aa0062689adadac0670ef45c17831fa785dbd791 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/tactic/omega/clause.lean | 19d00c572d840e6a6565110d555ff408839256de | [
"Apache-2.0"
] | permissive | jjgarzella/mathlib | 96a345378c4e0bf26cf604aed84f90329e4896a2 | 395d8716c3ad03747059d482090e2bb97db612c8 | refs/heads/master | 1,686,480,124,379 | 1,625,163,323,000 | 1,625,163,323,000 | 281,190,421 | 2 | 0 | Apache-2.0 | 1,595,268,170,000 | 1,595,268,169,000 | null | UTF-8 | Lean | false | false | 2,005 | lean | /-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Seul Baek
-/
/-
Definition of linear constrain clauses.
-/
import tactic.omega.term
namespace omega
/-- (([t₁,...tₘ],[s₁,...,sₙ]) : clause) encodes the constraints
0 = ⟦t₁⟧ ∧ ... ∧ 0 = ⟦tₘ⟧ ∧ 0 ≤ ⟦s₁⟧ ∧ ... ∧ 0 ≤ ⟦sₙ⟧, where
⟦t⟧ is the value of (t : term). -/
@[reducible] def clause := (list term) × (list term)
namespace clause
/-- holds v c := clause c holds under valuation v -/
def holds (v : nat → int) : clause → Prop
| (eqs,les) :=
( (∀ t : term, t ∈ eqs → 0 = term.val v t)
∧ (∀ t : term, t ∈ les → 0 ≤ term.val v t) )
/-- sat c := there exists a valuation v under which c holds -/
def sat (c : clause) : Prop :=
∃ v : nat → int, holds v c
/-- unsat c := there is no valuation v under which c holds -/
def unsat (c : clause) : Prop := ¬ c.sat
/-- append two clauses by elementwise appending -/
def append (c1 c2 : clause) : clause :=
(c1.fst ++ c2.fst, c1.snd ++ c2.snd)
lemma holds_append {v : nat → int} {c1 c2 : clause} :
holds v c1 → holds v c2 → holds v (append c1 c2) :=
begin
intros h1 h2,
cases c1 with eqs1 les1,
cases c2 with eqs2 les2,
cases h1, cases h2,
constructor; rw list.forall_mem_append;
constructor; assumption,
end
end clause
/-- There exists a satisfiable clause c in argument -/
def clauses.sat (cs : list clause) : Prop :=
∃ c ∈ cs, clause.sat c
/-- There is no satisfiable clause c in argument -/
def clauses.unsat (cs : list clause) : Prop := ¬ clauses.sat cs
lemma clauses.unsat_nil : clauses.unsat [] :=
begin intro h1, rcases h1 with ⟨c,h1,h2⟩, cases h1 end
lemma clauses.unsat_cons (c : clause) (cs : list clause) :
clause.unsat c → clauses.unsat cs →
clauses.unsat (c::cs) | h1 h2 h3 :=
begin
unfold clauses.sat at h3,
rw list.exists_mem_cons_iff at h3,
cases h3; contradiction,
end
end omega
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.