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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ff5e5bce914422a1abca1348a82aa9184aa9bd49 | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/analysis/normed_space/riesz_lemma.lean | 714dbd9b0bccb0a8d7d37263eab94014056098b4 | [
"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 | 4,582 | lean | /-
Copyright (c) 2019 Jean Lo. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jean Lo
-/
import topology.metric_space.hausdorff_distance
/-!
# Riesz's lemma
Riesz's lemma, stated for a normed space over a normed field: for any
closed proper subspace `F` of `E`, there is a nonzero `x` such that `∥x - F∥`
is at least `r * ∥x∥` for any `r < 1`. This is `riesz_lemma`.
In a nondiscrete normed field (with an element `c` of norm `> 1`) and any `R > ∥c∥`, one can
guarantee `∥x∥ ≤ R` and `∥x - y∥ ≥ 1` for any `y` in `F`. This is `riesz_lemma_of_norm_lt`.
-/
variables {𝕜 : Type*} [normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
/-- Riesz's lemma, which usually states that it is possible to find a
vector with norm 1 whose distance to a closed proper subspace is
arbitrarily close to 1. The statement here is in terms of multiples of
norms, since in general the existence of an element of norm exactly 1
is not guaranteed. For a variant giving an element with norm in `[1, R]`, see
`riesz_lemma_of_norm_lt`. -/
lemma riesz_lemma {F : subspace 𝕜 E} (hFc : is_closed (F : set E))
(hF : ∃ x : E, x ∉ F) {r : ℝ} (hr : r < 1) :
∃ x₀ : E, x₀ ∉ F ∧ ∀ y ∈ F, r * ∥x₀∥ ≤ ∥x₀ - y∥ :=
begin
classical,
obtain ⟨x, hx⟩ : ∃ x : E, x ∉ F := hF,
let d := metric.inf_dist x F,
have hFn : (F : set E).nonempty, from ⟨_, F.zero_mem⟩,
have hdp : 0 < d,
from lt_of_le_of_ne metric.inf_dist_nonneg (λ heq, hx
((hFc.mem_iff_inf_dist_zero hFn).2 heq.symm)),
let r' := max r 2⁻¹,
have hr' : r' < 1, by { simp [r', hr], norm_num },
have hlt : 0 < r' := lt_of_lt_of_le (by norm_num) (le_max_right r 2⁻¹),
have hdlt : d < d / r', from (lt_div_iff hlt).mpr ((mul_lt_iff_lt_one_right hdp).2 hr'),
obtain ⟨y₀, hy₀F, hxy₀⟩ : ∃ y ∈ F, dist x y < d / r' := (metric.inf_dist_lt_iff hFn).mp hdlt,
have x_ne_y₀ : x - y₀ ∉ F,
{ by_contradiction h,
have : (x - y₀) + y₀ ∈ F, from F.add_mem h hy₀F,
simp only [neg_add_cancel_right, sub_eq_add_neg] at this,
exact hx this },
refine ⟨x - y₀, x_ne_y₀, λy hy, le_of_lt _⟩,
have hy₀y : y₀ + y ∈ F, from F.add_mem hy₀F hy,
calc
r * ∥x - y₀∥ ≤ r' * ∥x - y₀∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _)
... < d : by { rw ←dist_eq_norm, exact (lt_div_iff' hlt).1 hxy₀ }
... ≤ dist x (y₀ + y) : metric.inf_dist_le_dist_of_mem hy₀y
... = ∥x - y₀ - y∥ : by { rw [sub_sub, dist_eq_norm] }
end
/--
A version of Riesz lemma: given a strict closed subspace `F`, one may find an element of norm `≤ R`
which is at distance at least `1` of every element of `F`. Here, `R` is any given constant
strictly larger than the norm of an element of norm `> 1`. For a version without an `R`, see
`riesz_lemma`.
Since we are considering a general nondiscrete normed field, there may be a gap in possible norms
(for instance no element of norm in `(1,2)`). Hence, we can not allow `R` arbitrarily close to `1`,
and require `R > ∥c∥` for some `c : 𝕜` with norm `> 1`.
-/
lemma riesz_lemma_of_norm_lt
{c : 𝕜} (hc : 1 < ∥c∥) {R : ℝ} (hR : ∥c∥ < R)
{F : subspace 𝕜 E} (hFc : is_closed (F : set E)) (hF : ∃ x : E, x ∉ F) :
∃ x₀ : E, ∥x₀∥ ≤ R ∧ ∀ y ∈ F, 1 ≤ ∥x₀ - y∥ :=
begin
have Rpos : 0 < R := (norm_nonneg _).trans_lt hR,
have : ∥c∥ / R < 1, by { rw div_lt_iff Rpos, simpa using hR },
rcases riesz_lemma hFc hF this with ⟨x, xF, hx⟩,
have x0 : x ≠ 0 := λ H, by simpa [H] using xF,
obtain ⟨d, d0, dxlt, ledx, -⟩ :
∃ (d : 𝕜), d ≠ 0 ∧ ∥d • x∥ < R ∧ R / ∥c∥ ≤ ∥d • x∥ ∧ ∥d∥⁻¹ ≤ R⁻¹ * ∥c∥ * ∥x∥ :=
rescale_to_shell hc Rpos x0,
refine ⟨d • x, dxlt.le, λ y hy, _⟩,
set y' := d⁻¹ • y with hy',
have y'F : y' ∈ F, by simp [hy', submodule.smul_mem _ _ hy],
have yy' : y = d • y', by simp [hy', smul_smul, mul_inv_cancel d0],
calc 1 = (∥c∥/R) * (R/∥c∥) : by field_simp [Rpos.ne', (zero_lt_one.trans hc).ne']
... ≤ (∥c∥/R) * (∥d • x∥) :
mul_le_mul_of_nonneg_left ledx (div_nonneg (norm_nonneg _) Rpos.le)
... = ∥d∥ * (∥c∥/R * ∥x∥) : by { simp [norm_smul], ring }
... ≤ ∥d∥ * ∥x - y'∥ :
mul_le_mul_of_nonneg_left (hx y' (by simp [hy', submodule.smul_mem _ _ hy])) (norm_nonneg _)
... = ∥d • x - y∥ : by simp [yy', ← smul_sub, norm_smul],
end
|
986215543f05370dd3441f9f68ee3533e8edda70 | ca1ad81c8733787aba30f7a8d63f418508e12812 | /clfrags/src/core/connectives.lean | 062dd3d4bef0c27ac26673eaa6dcdc1f7dcae695 | [] | no_license | greati/hilbert-classical-fragments | 5cdbe07851e979c8a03c621a5efd4d24bbfa333a | 18a21ac6b2e890060eb4ae65752fc0245394d226 | refs/heads/master | 1,591,973,117,184 | 1,573,822,710,000 | 1,573,822,710,000 | 194,334,439 | 2 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 687 | lean | /- Declaration of the connectives for the fragments of Classical Logic
- as presented by Rautenberg (1981).
-
- @author Vitor Greati
-/
namespace clfrags
-- ∨
constant or : Prop → Prop → Prop
-- ∧
constant and : Prop → Prop → Prop
-- ka
constant ka : Prop → Prop → Prop → Prop
-- ki
constant ki : Prop → Prop → Prop → Prop
-- +₃
constant pt : Prop → Prop → Prop → Prop
-- d
constant dc : Prop → Prop → Prop → Prop
-- ad
constant ad : Prop → Prop → Prop → Prop
-- ¬
constant neg : Prop → Prop
-- 1
constant top : Prop
-- 0
constant bot : Prop
end clfrags
|
5fb123455871b3b8df8270b2992f1c030b36353e | 7541ac8517945d0f903ff5397e13e2ccd7c10573 | /src/category_theory/currying.lean | aad4901172b58f8a9097f6ea2ac5c04ed24743b1 | [] | no_license | ramonfmir/lean-category-theory | 29b6bad9f62c2cdf7517a3135e5a12b340b4ed90 | be516bcbc2dc21b99df2bcb8dde0d1e8de79c9ad | refs/heads/master | 1,586,110,684,637 | 1,541,927,184,000 | 1,541,927,184,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,988 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Scott Morrison
import category_theory.products.bifunctors
import category_theory.equivalence
-- FIXME why do we need this here?
@[obviously] meta def obviously_2 := tactic.tidy { tactics := extended_tidy_tactics }
namespace category_theory
universes u₁ v₁ u₂ v₂ u₃ v₃
variables {C : Type u₁} [𝒞 : category.{u₁ v₁} C] {D : Type u₂} [𝒟 : category.{u₂ v₂} D] {E : Type u₃} [ℰ : category.{u₃ v₃} E]
include 𝒞 𝒟 ℰ
-- FIXME this is taking too long again.
-- def uncurry : (C ⥤ (D ⥤ E)) ⥤ ((C × D) ⥤ E) :=
-- { obj := λ F, { obj := λ X, (F X.1) X.2,
-- map' := λ X Y f, ((F.map f.1) X.2) ≫ ((F Y.1).map f.2) },
-- map' := λ F G T, { app := λ X, (T X.1) X.2 } }.
-- def curry : ((C × D) ⥤ E) ⥤ (C ⥤ (D ⥤ E)) :=
-- { obj := λ F, { obj := λ X, { obj := λ Y, F (X, Y),
-- map' := λ Y Y' g, F.map (𝟙 X, g) },
-- map' := λ X X' f, { app := λ Y, F.map (f, 𝟙 Y) } },
-- map' := λ F G T, { app := λ X, { app := λ Y, T (X, Y) } } }.
-- -- We need the @s here in order for the coercions to work. :-(
-- @[simp] lemma uncurry.obj_map {F : C ⥤ (D ⥤ E)} {X Y : C × D} {f : X ⟶ Y} : (@uncurry C _ D _ E _ F).map f = ((F.map f.1) X.2) ≫ ((F Y.1).map f.2) := rfl
-- @[simp] lemma curry.obj_obj_map {F : (C × D) ⥤ E} {X : C} {Y Y' : D} {g : Y ⟶ Y'} : ((@curry C _ D _ E _ F) X).map g = F.map (𝟙 X, g) := rfl
-- @[simp] lemma curry.obj_map_app {F : (C × D) ⥤ E} {X X' : C} {f : X ⟶ X'} {Y} : ((@curry C _ D _ E _ F).map f) Y = F.map (f, 𝟙 Y) := rfl
-- local attribute [back] category.id -- this is usually a bad idea, but just what we needed here
-- def currying : equivalence (C ⥤ (D ⥤ E)) ((C × D) ⥤ E) :=
-- { functor := uncurry,
-- inverse := curry }
end category_theory |
2fbca7ba8536738880065c0e006a0bd4e6d58eaa | 952248371e69ccae722eb20bfe6815d8641554a8 | /src/normalizer.lean | 9a6a8fed8228bab595a69013849037f8dd7bd388 | [] | no_license | robertylewis/lean_polya | 5fd079031bf7114449d58d68ccd8c3bed9bcbc97 | 1da14d60a55ad6cd8af8017b1b64990fccb66ab7 | refs/heads/master | 1,647,212,226,179 | 1,558,108,354,000 | 1,558,108,354,000 | 89,933,264 | 1 | 2 | null | 1,560,964,118,000 | 1,493,650,551,000 | Lean | UTF-8 | Lean | false | false | 13,999 | lean | import datatypes -- blackboard
namespace polya
section aux
meta def mk_neg : expr → expr
| `((-%%lhs) * %%rhs) := `(%%lhs * %%rhs : ℚ)
| `(%%lhs * %%rhs) := `((-%%lhs) * %%rhs : ℚ)
| a := `((-1 : ℚ)*%%a)
meta def get_sum_components : expr → list expr
| `(%%lhs + %%rhs) := rhs::(get_sum_components lhs)
| `(%%lhs - %%rhs) := mk_neg rhs::(get_sum_components lhs)
| a := [a]
meta def get_prod_components : expr → list expr
| `(%%lhs * %%rhs) := rhs::(get_prod_components lhs)
| a := [a]
meta def is_sum (e : expr) : bool :=
e.is_app_of ``has_add.add || e.is_app_of ``has_sub.sub
meta def is_prod (e : expr) : bool :=
e.is_app_of ``has_mul.mul || e.is_app_of ``rat.pow
open tactic
meta def get_comps_of_mul (e : expr) : tactic (expr × ℚ) := match e with
| `(%%lhs * %%rhs) := (do c ← eval_expr ℚ lhs, return (rhs, c)) <|> return (e, 1)
| `(%%num / %%denom) := (do c ← eval_expr ℚ denom, return (num, 1/c)) <|> return (e, 1)
| f := return (f, 1)
end
meta def get_comps_of_exp (e : expr) : tactic (expr × ℤ) := match e with
| `(rat.pow %%base %%exp) := (do z ← eval_expr ℤ exp, return (base, z)) <|> return (e, 1)
| f := return (f, 1)
end
end aux
open native
/-meta mutual inductive sterm, term
with sterm : Type
| scaled : ℚ → term → sterm
with term : Type
| add_term : list sterm → term
| mul_term : list (term × ℤ) → term
| atom : expr → term-/
meta inductive term : Type
| add_term : rb_map term ℚ → term
| mul_term : rb_map term ℤ → term
| atom : expr → term
meta structure sterm :=
(coeff : ℚ) (body : term)
namespace term
meta mutual def cmp, list_cmp
with cmp : term → term → ordering
| (add_term m) (add_term n) := list_cmp m.keys n.keys
| (add_term _) _ := ordering.gt
| _ (add_term _) := ordering.lt
| (mul_term m) (mul_term n) := list_cmp m.keys n.keys
| (mul_term _) (atom _) := ordering.gt
| (atom _) (mul_term _) := ordering.lt
| (atom e1) (atom e2) := cmp_using has_lt.lt e1 e2
with list_cmp : list term → list term → ordering
| [] [] := ordering.eq
| [] _ := ordering.lt
| _ [] := ordering.gt
| (x::xs) (y::ys) := let c := cmp x y in if c = ordering.eq then list_cmp xs ys else c
meta def lt (x y : term) := cmp x y = ordering.lt
meta instance : has_lt term := ⟨lt⟩
meta instance : decidable_rel lt := λ x y, by delta lt; apply_instance
meta def add_term_empty : term :=
add_term mk_rb_map
meta def mul_term_empty : term :=
mul_term mk_rb_map
end term
private meta def add_term_coeff_pair (map : rb_map term ℚ) (st : term × ℚ) : rb_map term ℚ :=
match map.find st.1 with
| none := map.insert st.1 st.2
| some c := map.insert st.1 (st.2 + c)
end
private meta def add_term_coeff_pair_list (map : rb_map term ℚ) (l : list (term × ℚ)) : rb_map term ℚ :=
l.foldl add_term_coeff_pair map
private meta def add_sterm (map : rb_map term ℚ) (st : sterm) : rb_map term ℚ :=
add_term_coeff_pair map (st.body, st.coeff)
meta def add_term_of_sterm_list (l : list sterm) : term :=
term.add_term $ l.foldl add_sterm mk_rb_map
private meta def pow_term_exp (map : rb_map term ℤ) (pr : term × ℤ) : rb_map term ℤ :=
match map.find pr.1 with
| none := map.insert pr.1 pr.2
| some c := map.insert pr.1 (pr.2 + c)
end
private meta def pow_term_exp_list (map : rb_map term ℤ) (l : list (term × ℤ)) : rb_map term ℤ :=
l.foldl pow_term_exp map
meta def mul_term_of_term_exp_list (l : list (term × ℤ)) : term :=
term.mul_term $ l.foldl pow_term_exp mk_rb_map
meta def term.is_zero : term → bool
| (term.add_term m) := m.size = 0
| _ := ff
meta def sterm.is_zero (st : sterm) : bool :=
st.body.is_zero || (st.coeff = 0)
meta def term.scale (q : ℚ) (t : term) : sterm :=
⟨q, t⟩
meta def sterm.scale (q : ℚ) (st : sterm) : sterm :=
{ st with coeff := st.coeff * q }
meta def sterm.of_pair (pr : term × ℚ) : sterm :=
⟨pr.2, pr.1⟩
open tactic
private meta def expr.to_term_aux (tst : expr → tactic sterm) : expr → tactic term | e :=
if is_sum e then
let scs := get_sum_components e in
add_term_of_sterm_list <$> scs.mmap tst
else if is_prod e then
let scs := get_prod_components e in
do scs' ← scs.mmap get_comps_of_exp,
mul_term_of_term_exp_list <$> scs'.mmap (λ pr, do tm ← expr.to_term_aux pr.1, return (tm, pr.2))
else return $ term.atom e
private meta def split_num_nonnum_prod_comps : list expr → list expr × list expr
| [] := ([], [])
| (e::l) :=
let (t1, t2) := split_num_nonnum_prod_comps l in
if expr.is_numeral e then (e::t1, t2) else (t1, e::t2)
private meta def fold_op_app_aux (op : pexpr) : expr → list expr → tactic expr
| h [] := return h
| h (h'::t) := do h'' ← to_expr ``(%%op %%h %%h'), fold_op_app_aux h'' t
private meta def fold_op_app (op : pexpr) (dflt : expr) : list expr → tactic expr
| [] := return dflt
| (h::t) := fold_op_app_aux op h t
meta def expr.to_sterm : expr → tactic sterm | e :=
if expr.is_numeral e then
do q ← eval_expr ℚ e,
return ⟨q, (term.atom `(1 : ℚ))⟩
else if is_prod e then
let scs := get_prod_components e,
(numcs, nnumcs) := split_num_nonnum_prod_comps scs in
do numcs' ← numcs.mmap (eval_expr ℚ),
let q := numcs'.foldl (*) 1,
sterm.mk q <$> ((fold_op_app ``((*)) `(1 : ℚ) nnumcs) >>= expr.to_term_aux expr.to_sterm)
else sterm.mk 1 <$> expr.to_term_aux expr.to_sterm e
/-match e with
| `(%%c*%%t) :=
if expr.is_numeral c then
do q ← eval_expr ℚ c,
sterm.scale q <$> expr.to_sterm t
else sterm.mk 1 <$> expr.to_term_aux expr.to_sterm e
| t := sterm.mk 1 <$> expr.to_term_aux expr.to_sterm t
end -/
meta def expr.to_term : expr → tactic term := expr.to_term_aux expr.to_sterm
private meta def term.to_expr_aux (ste : sterm → tactic expr) : term → tactic expr
| (term.add_term l) :=
if l.size = 0 then return `(0 : ℚ) else
do l' ← l.to_list.mmap (λ pr, ste (sterm.of_pair pr)),
fold_op_app ``((+)) `(0 : ℚ) l'
| (term.mul_term l) :=
if l.size = 0 then return `(1 : ℚ) else
do l' ← l.to_list.mmap (λ pr, do e' ← term.to_expr_aux pr.1, return (e', pr.2)),
let l'' := l'.map (λ pr, `(rat.pow %%(pr.1) %%(pr.2.reflect))),
fold_op_app ``((*)) `(1 : ℚ) l''
| (term.atom e) := return e
meta def sterm.to_expr : sterm → tactic expr
| ⟨c, t⟩ :=
if t.is_zero || (c = 0) then return `(0 : ℚ) else
do t' ← term.to_expr_aux sterm.to_expr t,
return `(%%(c.reflect)*%%t' : ℚ)
meta def term.to_expr : term → tactic expr := term.to_expr_aux sterm.to_expr
meta def term.to_tactic_format (e : term) : tactic format :=
do ex ← e.to_expr,
tactic_format_expr ex
meta def sterm.to_tactic_format (e : sterm) : tactic format :=
do ex ← e.to_expr,
tactic_format_expr ex
meta instance term.has_to_tactic_format : has_to_tactic_format term :=
⟨term.to_tactic_format⟩
meta instance sterm.has_to_tactic_format : has_to_tactic_format sterm :=
⟨sterm.to_tactic_format⟩
section canonize
private meta def coeff_and_terms_of_sterm_z_list : list (sterm × ℤ) → ℚ × list (term × ℤ)
| [] := (1, [])
| ((⟨c, tm⟩, z)::t) :=
let (q, l) := coeff_and_terms_of_sterm_z_list t in
(q * rat.pow c z, (tm, z)::l)
/-private meta def coeff_and_terms_of_sterm_z_list : ℚ → list (term × ℤ) → list (sterm × ℤ) → ℚ × list (term × ℤ)
| acc l [] := (acc, l)
| acc l ((sterm.scaled c tm, z)::t) := (tm, z)::coeff_and_terms_of_sterm_z_list (acc*rat.pow c z) t-/
-- only applies to add_term
private meta def term.leading_coeff : term → ℚ
| (term.add_term l) :=
match l.to_list with
| [] := 1
| ((_, c)::t) := c
end
| _ := 1
-- only applies to add_term
private meta def term.scale_coeffs (c : ℚ) : term → term
| (term.add_term l) := term.add_term $ l.map (λ c', c*c')
| a := a
-- doesn't flatten
private meta def term.canonize_aux (stc : sterm → tactic sterm) : term → tactic sterm
| (term.add_term l) :=
do l' ← add_term_of_sterm_list <$> l.to_list.mmap (λ pr, stc (sterm.of_pair pr)),
let c := term.leading_coeff l',
return ⟨c, term.scale_coeffs (1/c) l'⟩
/- do l' : list (sterm × expr) ← l.to_list.mmap (λ st, do st' ← stc (sterm.of_pair st), e ← st'.to_expr, return (st', e)),
let l' := (l'.qsort (λ pr1 pr2 : sterm × expr, pr2.2.lt pr1.2)).map prod.fst,
match l' with
| [] := return $ sterm.mk 1 term.add_term_empty
| [st] := return st
| (⟨c, tm⟩)::t :=
if c = 1 then return $ sterm.mk 1 (add_term_of_sterm_list l')
else return $ sterm.mk c (add_term_of_sterm_list (l'.map (sterm.scale (1/c))))
end-/
| (term.mul_term l) :=
do l' ← l.to_list.mmap (λ pr, do t' ← term.canonize_aux pr.1, return (t', pr.2)),
let (q, l'') := coeff_and_terms_of_sterm_z_list l',
return ⟨q, mul_term_of_term_exp_list l''⟩
/- do l' ← l.to_list.mmap (λ pr, do t' ← term.canonize_aux pr.1, e ← t'.to_expr, return ((t', pr.2), e)),
let l' := (l'.qsort (λ pr1 pr2 : (sterm × ℤ) × expr, pr2.2.lt pr1.2)),
let l' := l'.map prod.fst,
let (q, l'') := coeff_and_terms_of_sterm_z_list l',
return $ sterm.mk q (mul_term_of_term_exp_list l'')-/
| (term.atom e) := return $ sterm.mk 1 (term.atom e)
-- doesn't flatten
private meta def sterm.canonize_aux : sterm → tactic sterm
| ⟨c, t⟩ :=
do sterm.mk c' t' ← term.canonize_aux sterm.canonize_aux t,
return $ sterm.mk (c*c') t'
/-private meta def flatten_sum_list : list (term × ℚ) → list (term × ℚ)
| [] := []
| ((term.add_term tm, c)::t) :=
(tm.to_list.map (λ pr : term × ℚ, (pr.1, pr.2*c))).append (flatten_sum_list t)
| (h::t) := h::flatten_sum_list t
private meta def flatten_prod_list : list (term × ℤ) → list (term × ℤ)
| [] := []
| ((term.mul_term l, z)::t) := (l.to_list.map (λ pr : term × ℤ, (pr.1, pr.2*z))).append (flatten_prod_list t)
| (h::t) := h::flatten_prod_list t-/
private meta def scale_list {α} [has_mul α] (l : list (term × α)) (q : α) : list (term × α) :=
l.map (λ pr, {pr with snd := pr.snd * q})
private meta def flatten_sum_term_aux (t : term) (coeff : ℚ) (map : rb_map term ℚ) : rb_map term ℚ :=
match t with
| term.add_term l := add_term_coeff_pair_list map (scale_list l.to_list coeff)
| _ := map.insert t coeff
end
private meta def flatten_sum_term (map : rb_map term ℚ) : rb_map term ℚ :=
map.fold mk_rb_map flatten_sum_term_aux
private meta def flatten_mul_term_aux (t : term) (exp : ℤ) (map : rb_map term ℤ) : rb_map term ℤ :=
match t with
| term.mul_term l := pow_term_exp_list map (scale_list l.to_list exp)
| _ := map.insert t exp
end
private meta def flatten_mul_term (map : rb_map term ℤ) : rb_map term ℤ :=
map.fold mk_rb_map flatten_mul_term_aux
private meta def term.flatten : term → term
| (term.add_term l) := term.add_term $ flatten_sum_term l --$ rb_map.of_list (flatten_sum_list l.to_list)
| (term.mul_term l) := term.mul_term $ flatten_mul_term l --$ rb_map.of_list (flatten_prod_list l.to_list)
| a := a
private meta def sterm.flatten : sterm → sterm
| (sterm.mk c t) := sterm.mk c (term.flatten t)
meta def sterm.canonize : sterm → tactic sterm :=
sterm.canonize_aux ∘ sterm.flatten
meta def term.canonize (t : term) : tactic sterm :=
term.canonize_aux sterm.canonize (term.flatten t)
meta def expr.canonize (e : expr) : tactic sterm :=
match e with
| `(0 : ℚ) := return $ sterm.mk 0 (term.add_term_empty)
| _ := expr.to_sterm e >>= sterm.canonize
end
meta def expr.canonize_to_expr (e : expr) : tactic expr :=
match e with
| `(0 : ℚ) := return e
| _ := expr.to_sterm e >>= sterm.canonize >>= sterm.to_expr
end
theorem canonized_inequality {P : Prop} (h : P) (canP : Prop) : canP := sorry
meta def prove_inequality (lhs rhs pf : expr) (op : gen_comp) : tactic expr :=
do sterm.mk clhs tlhs ← expr.canonize lhs,
--trace "tlhs", trace tlhs,
srhs ← expr.canonize rhs,
--trace "srhs", trace srhs,
elhs ← tlhs.to_expr,
if clhs = 0 then
do erhs ← srhs.to_expr,
tp ← op.reverse.to_function erhs elhs,
mk_app ``canonized_inequality [pf, tp]
else
do erhs ← (srhs.scale (1/clhs)).to_expr,
tp ← ((if clhs < 0 then gen_comp.reverse else id) op).to_function elhs erhs, --to_expr ``(%%op %%elhs %%erhs),
mk_app ``canonized_inequality [pf, tp]
meta def canonize_hyp (e : expr) : tactic expr :=
do tp ← infer_type e, match tp with
/-| `(0 > %%e) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(0 > %%ce)]
| `(0 ≥ %%e) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(0 ≥ %%ce)]
| `(0 < %%e) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(0 < %%ce)]
| `(0 ≤ %%e) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(0 ≤ %%ce)]
| `(%%e > 0) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(%%ce > 0)]
| `(%%e ≥ 0) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(%%ce ≥ 0)]
| `(%%e < 0) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(%%ce < 0)]
| `(%%e ≤ 0) := do ce ← expr.canonize e,
mk_app ``canonized_inequality [e, `(%%ce ≤ 0)]-/
| `(%%lhs ≤ %%rhs) := prove_inequality lhs rhs e gen_comp.le
| `(%%lhs < %%rhs) := prove_inequality lhs rhs e gen_comp.lt
| `(%%lhs ≥ %%rhs) := prove_inequality lhs rhs e gen_comp.ge
| `(%%lhs > %%rhs) := prove_inequality lhs rhs e gen_comp.gt
| `(%%lhs = %%rhs) := prove_inequality lhs rhs e gen_comp.eq
| `(%%lhs ≠ %%rhs) := prove_inequality lhs rhs e gen_comp.ne
| _ := /-trace e >>-/ do s ← to_string <$> pp e, fail $ "didn't recognize " ++ s
end
end canonize
end polya
|
b5752b179c2685a9822b6cffae6293b71eb11e22 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /stage0/src/Lean/Elab/Deriving/FromToJson.lean | a768d33eb4e7a5010d89ba0be34618cdb2622622 | [
"Apache-2.0"
] | permissive | WojciechKarpiel/lean4 | 7f89706b8e3c1f942b83a2c91a3a00b05da0e65b | f6e1314fa08293dea66a329e05b6c196a0189163 | refs/heads/master | 1,686,633,402,214 | 1,625,821,189,000 | 1,625,821,258,000 | 384,640,886 | 0 | 0 | Apache-2.0 | 1,625,903,617,000 | 1,625,903,026,000 | null | UTF-8 | Lean | false | false | 8,550 | lean | /-
Copyright (c) 2020 Sebastian Ullrich. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich, Dany Fabian
-/
import Lean.Meta.Transform
import Lean.Elab.Deriving.Basic
import Lean.Elab.Deriving.Util
import Lean.Data.Json.FromToJson
namespace Lean.Elab.Deriving.FromToJson
open Lean.Elab.Command
open Lean.Json
open Lean.Parser.Term
open Lean.Meta
def mkJsonField (n : Name) : Bool × Syntax :=
let s := n.toString
let s₁ := s.dropRightWhile (· == '?')
(s != s₁, Syntax.mkStrLit s₁)
private def parseTagged
(json : Json)
(tag : String)
(nFields : Nat)
(fieldNames? : Option (Array Name)) : Except String (Array Json) :=
if nFields == 0 then
match getStr? json with
| Except.ok s => if s == tag then Except.ok #[] else throw s!"incorrect tag: {s} ≟ {tag}"
| Except.error err => Except.error err
else
match getObjVal? json tag with
| Except.ok payload =>
match fieldNames? with
| some fieldNames =>
do
let mut fields := #[]
for fieldName in fieldNames do
fields := fields.push (←getObjVal? payload fieldName.getString!)
Except.ok fields
| none =>
if nFields == 1 then
Except.ok #[payload]
else
match getArr? payload with
| Except.ok fields =>
if fields.size == nFields then
Except.ok fields
else
Except.error "incorrect number of fields: {fields.size} ≟ {nFields}"
| Except.error err => Except.error err
| Except.error err => Except.error err
def mkToJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if declNames.size == 1 then
if (← isStructure (← getEnv) declNames[0]) then
let cmds ← liftTermElabM none <| do
let ctx ← mkContext "toJson" declNames[0]
let header ← mkHeader ctx ``ToJson 1 ctx.typeInfos[0]
let fields := getStructureFieldsFlattened (← getEnv) declNames[0] (includeSubobjectFields := false)
let fields : Array Syntax ← fields.mapM fun field => do
let (isOptField, nm) ← mkJsonField field
if isOptField then `(opt $nm $(mkIdent <| header.targetNames[0] ++ field))
else `([($nm, toJson $(mkIdent <| header.targetNames[0] ++ field))])
let cmd ← `(private def $(mkIdent ctx.auxFunNames[0]):ident $header.binders:explicitBinder* :=
mkObj <| List.join [$fields,*])
return #[cmd] ++ (← mkInstanceCmds ctx ``ToJson declNames)
cmds.forM elabCommand
return true
else
let indVal ← getConstInfoInduct declNames[0]
let cmds ← liftTermElabM none <| do
let ctx ← mkContext "toJson" declNames[0]
let header ← mkHeader ctx ``ToJson 1 ctx.typeInfos[0]
let discrs ← mkDiscrs header indVal
let alts ← mkAlts indVal fun ctor args userNames =>
match args, userNames with
| #[], _ => `(toJson $(quote ctor.name.getString!))
| #[x], _ => `(mkObj [($(quote ctor.name.getString!), toJson $x)])
| xs, none => do
let xs ← xs.mapM fun x => `(toJson $x)
`(mkObj [($(quote ctor.name.getString!), toJson #[$[$xs:term],*])])
| xs, some userNames => do
let xs ← xs.mapIdxM fun idx x => `(($(quote userNames[idx].getString!), toJson $x))
`(mkObj [($(quote ctor.name.getString!), mkObj [$[$xs:term],*])])
let auxCmd ← `(match $[$discrs],* with $alts:matchAlt*)
let auxCmd ← `(private def $(mkIdent ctx.auxFunNames[0]):ident $header.binders:explicitBinder* := $auxCmd)
return #[auxCmd] ++ (← mkInstanceCmds ctx ``ToJson declNames)
cmds.forM elabCommand
return true
else
return false
where
mkAlts
(indVal : InductiveVal)
(rhs : ConstructorVal → Array Syntax → (Option $ Array Name) → TermElabM Syntax) : TermElabM (Array Syntax) := do
indVal.ctors.toArray.mapM fun ctor => do
let ctorInfo ← getConstInfoCtor ctor
forallTelescopeReducing ctorInfo.type fun xs type => do
let mut patterns := #[]
-- add `_` pattern for indices
for i in [:indVal.numIndices] do
patterns := patterns.push (← `(_))
let mut ctorArgs := #[]
-- add `_` for inductive parameters, they are inaccessible
for i in [:indVal.numParams] do
ctorArgs := ctorArgs.push (← `(_))
let mut identNames := #[]
let mut userNames := #[]
for i in [:ctorInfo.numFields] do
let x := xs[indVal.numParams + i]
let localDecl ← getLocalDecl x.fvarId!
if !localDecl.userName.hasMacroScopes then
userNames := userNames.push localDecl.userName
let a := mkIdent (← mkFreshUserName `a)
identNames := identNames.push a
ctorArgs := ctorArgs.push a
patterns := patterns.push (← `(@$(mkIdent ctorInfo.name):ident $ctorArgs:term*))
let rhs ← rhs ctorInfo identNames (if userNames.size == identNames.size then some userNames else none)
`(matchAltExpr| | $[$patterns:term],* => $rhs:term)
def mkFromJsonInstanceHandler (declNames : Array Name) : CommandElabM Bool := do
if declNames.size == 1 then
if (← isStructure (← getEnv) declNames[0]) then
let cmds ← liftTermElabM none <| do
let ctx ← mkContext "fromJson" declNames[0]
let header ← mkHeader ctx ``FromJson 0 ctx.typeInfos[0]
let fields := getStructureFieldsFlattened (← getEnv) declNames[0] (includeSubobjectFields := false)
let jsonFields := fields.map (Prod.snd ∘ mkJsonField)
let fields := fields.map mkIdent
let cmd ← `(private def $(mkIdent ctx.auxFunNames[0]):ident $header.binders:explicitBinder* (j : Json)
: Except String $(← mkInductiveApp ctx.typeInfos[0] header.argNames) := do
$[let $fields:ident ← getObjValAs? j _ $jsonFields]*
return { $[$fields:ident := $(id fields)]* })
return #[cmd] ++ (← mkInstanceCmds ctx ``FromJson declNames)
cmds.forM elabCommand
return true
else
let indVal ← getConstInfoInduct declNames[0]
let cmds ← liftTermElabM none <| do
let ctx ← mkContext "fromJson" declNames[0]
let header ← mkHeader ctx ``FromJson 0 ctx.typeInfos[0]
let discrs ← mkDiscrs header indVal
let alts ← mkAlts indVal
let matchCmd ← alts.foldrM (fun xs x => `($xs <|> $x)) (←`(Except.error "none of the alternatives matched"))
let cmd ← `(private def $(mkIdent ctx.auxFunNames[0]):ident $header.binders:explicitBinder* (json : Json)
: Except String $(← mkInductiveApp ctx.typeInfos[0] header.argNames) :=
$matchCmd )
return #[cmd] ++ (← mkInstanceCmds ctx ``FromJson declNames)
cmds.forM elabCommand
return true
else
return false
where
mkAlts (indVal : InductiveVal) : TermElabM (Array Syntax) := do
let alts ←
indVal.ctors.toArray.mapM fun ctor => do
let ctorInfo ← getConstInfoCtor ctor
forallTelescopeReducing ctorInfo.type fun xs type => do
let mut identNames := #[]
let mut userNames := #[]
for i in [:ctorInfo.numFields] do
let x := xs[indVal.numParams + i]
let localDecl ← getLocalDecl x.fvarId!
if !localDecl.userName.hasMacroScopes then
userNames := userNames.push localDecl.userName
let xTy ← inferType x
let a := mkIdent (← mkFreshUserName `a)
identNames := identNames.push a
let jsonAccess ← identNames.mapIdxM (fun idx _ => `(jsons[$(quote idx.val)]))
let userNamesOpt ←
if identNames.size == userNames.size then
`(some #[$[$(userNames.map quote):ident],*])
else `(none)
let stx ←
`((parseTagged json $(quote ctor.getString!) $(quote ctorInfo.numFields) $(quote userNamesOpt)).bind
(fun jsons => do
$[let $identNames:ident ← fromJson? $jsonAccess]*
return $(mkIdent ctor):ident $identNames*))
(stx, ctorInfo.numFields)
-- the smaller cases, especially the ones without fields are likely faster
let alts := alts.qsort (fun (_, x) (_, y) => x < y)
alts.map Prod.fst
builtin_initialize
registerBuiltinDerivingHandler ``ToJson mkToJsonInstanceHandler
registerBuiltinDerivingHandler ``FromJson mkFromJsonInstanceHandler
end Lean.Elab.Deriving.FromToJson
|
7dfeb1bfd337a289c2b08ca39aa9b097accf016f | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/field_theory/splitting_field/is_splitting_field.lean | 1916a19ed67b94dcf288c445ed3e9065d463daa3 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 6,262 | 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 algebra.char_p.algebra
import field_theory.intermediate_field
import ring_theory.adjoin.field
/-!
# Splitting fields
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file introduces the notion of a splitting field of a polynomial and provides an embedding from
a splitting field to any field that splits the polynomial. A polynomial `f : K[X]` splits
over a field extension `L` of `K` if it is zero or all of its irreducible factors over `L` have
degree `1`. A field extension of `K` of a polynomial `f : K[X]` is called a splitting field
if it is the smallest field extension of `K` such that `f` splits.
## Main definitions
* `polynomial.is_splitting_field`: A predicate on a field to be a splitting field of a polynomial
`f`.
## Main statements
* `polynomial.is_splitting_field.lift`: An embedding of a splitting field of the polynomial `f` into
another field such that `f` splits.
-/
noncomputable theory
open_locale classical big_operators polynomial
universes u v w
variables {F : Type u} (K : Type v) (L : Type w)
namespace polynomial
variables [field K] [field L] [field F] [algebra K L]
/-- Typeclass characterising splitting fields. -/
class is_splitting_field (f : K[X]) : Prop :=
(splits [] : splits (algebra_map K L) f)
(adjoin_root_set [] : algebra.adjoin K (f.root_set L) = ⊤)
variables {K L F}
namespace is_splitting_field
section scalar_tower
variables [algebra F K] [algebra F L] [is_scalar_tower F K L]
instance map (f : F[X]) [is_splitting_field F L f] :
is_splitting_field K L (f.map $ algebra_map F K) :=
⟨by { rw [splits_map_iff, ← is_scalar_tower.algebra_map_eq], exact splits L f },
subalgebra.restrict_scalars_injective F $
by { rw [root_set, map_map, ← is_scalar_tower.algebra_map_eq, subalgebra.restrict_scalars_top,
eq_top_iff, ← adjoin_root_set L f, algebra.adjoin_le_iff],
exact λ x hx, @algebra.subset_adjoin K _ _ _ _ _ _ hx }⟩
variables (L)
theorem splits_iff (f : K[X]) [is_splitting_field K L f] :
polynomial.splits (ring_hom.id K) f ↔ (⊤ : subalgebra K L) = ⊥ :=
⟨λ h, eq_bot_iff.2 $ adjoin_root_set L f ▸
algebra.adjoin_le_iff.2 (λ y hy,
let ⟨x, hxs, hxy⟩ := finset.mem_image.1
(by rwa [root_set, roots_map _ h, multiset.to_finset_map] at hy) in
hxy ▸ set_like.mem_coe.2 $ subalgebra.algebra_map_mem _ _),
λ h, @ring_equiv.to_ring_hom_refl K _ ▸
ring_equiv.self_trans_symm (ring_equiv.of_bijective _ $ algebra.bijective_algebra_map_iff.2 h) ▸
by { rw ring_equiv.to_ring_hom_trans, exact splits_comp_of_splits _ _ (splits L f) }⟩
theorem mul (f g : F[X]) (hf : f ≠ 0) (hg : g ≠ 0) [is_splitting_field F K f]
[is_splitting_field K L (g.map $ algebra_map F K)] :
is_splitting_field F L (f * g) :=
⟨(is_scalar_tower.algebra_map_eq F K L).symm ▸ splits_mul _
(splits_comp_of_splits _ _ (splits K f))
((splits_map_iff _ _).1 (splits L $ g.map $ algebra_map F K)),
by rw [root_set, polynomial.map_mul,
roots_mul (mul_ne_zero (map_ne_zero hf : f.map (algebra_map F L) ≠ 0)
(map_ne_zero hg)), multiset.to_finset_add, finset.coe_union,
algebra.adjoin_union_eq_adjoin_adjoin,
is_scalar_tower.algebra_map_eq F K L, ← map_map,
roots_map (algebra_map K L) ((splits_id_iff_splits $ algebra_map F K).2 $ splits K f),
multiset.to_finset_map, finset.coe_image, algebra.adjoin_algebra_map, ←root_set,
adjoin_root_set, algebra.map_top, is_scalar_tower.adjoin_range_to_alg_hom, ← map_map,
←root_set, adjoin_root_set, subalgebra.restrict_scalars_top]⟩
end scalar_tower
variable (L)
/-- Splitting field of `f` embeds into any field that splits `f`. -/
def lift [algebra K F] (f : K[X]) [is_splitting_field K L f]
(hf : polynomial.splits (algebra_map K F) f) : L →ₐ[K] F :=
if hf0 : f = 0 then (algebra.of_id K F).comp $
(algebra.bot_equiv K L : (⊥ : subalgebra K L) →ₐ[K] K).comp $
by { rw ← (splits_iff L f).1 (show f.splits (ring_hom.id K), from hf0.symm ▸ splits_zero _),
exact algebra.to_top } else
alg_hom.comp (by { rw ← adjoin_root_set L f, exact classical.choice (lift_of_splits _ $ λ y hy,
have aeval y f = 0, from (eval₂_eq_eval_map _).trans $
(mem_roots $ by exact map_ne_zero hf0).1 (multiset.mem_to_finset.mp hy),
⟨is_algebraic_iff_is_integral.1 ⟨f, hf0, this⟩,
splits_of_splits_of_dvd _ hf0 hf $ minpoly.dvd _ _ this⟩) })
algebra.to_top
theorem finite_dimensional (f : K[X]) [is_splitting_field K L f] : finite_dimensional K L :=
⟨@algebra.top_to_submodule K L _ _ _ ▸ adjoin_root_set L f ▸
fg_adjoin_of_finite (finset.finite_to_set _) (λ y hy,
if hf : f = 0
then by { rw [hf, root_set_zero] at hy, cases hy }
else is_algebraic_iff_is_integral.1 ⟨f, hf, (eval₂_eq_eval_map _).trans $
(mem_roots $ by exact map_ne_zero hf).1 (multiset.mem_to_finset.mp hy)⟩)⟩
lemma of_alg_equiv [algebra K F] (p : K[X]) (f : F ≃ₐ[K] L) [is_splitting_field K F p] :
is_splitting_field K L p :=
begin
split,
{ rw ← f.to_alg_hom.comp_algebra_map,
exact splits_comp_of_splits _ _ (splits F p) },
{ rw [←(algebra.range_top_iff_surjective f.to_alg_hom).mpr f.surjective,
adjoin_root_set_eq_range (splits F p), adjoin_root_set F p] },
end
end is_splitting_field
end polynomial
namespace intermediate_field
open polynomial
variables {K L} [field K] [field L] [algebra K L] {p : K[X]}
lemma splits_of_splits {F : intermediate_field K L} (h : p.splits (algebra_map K L))
(hF : ∀ x ∈ p.root_set L, x ∈ F) : p.splits (algebra_map K F) :=
begin
simp_rw [root_set, finset.mem_coe, multiset.mem_to_finset] at hF,
rw splits_iff_exists_multiset,
refine ⟨multiset.pmap subtype.mk _ hF, map_injective _ (algebra_map F L).injective _⟩,
conv_lhs { rw [polynomial.map_map, ←is_scalar_tower.algebra_map_eq,
eq_prod_roots_of_splits h, ←multiset.pmap_eq_map _ _ _ hF] },
simp_rw [polynomial.map_mul, polynomial.map_multiset_prod,
multiset.map_pmap, polynomial.map_sub, map_C, map_X],
refl,
end
end intermediate_field
|
0ff5b4c42f6c7bcbbf22df747b5dc9b21fa166c3 | 695574baef97a204f68217f2dfede8512fd91ff8 | /src/assumptions.lean | a185ea662e73b29a6e3349891eb87b6e847623d4 | [] | no_license | JasonKYi/stone-weierstrass | ba463bedc758c4993e922afcc8cf8895a9257bd4 | 390affd1415cf393da55866b82fdf68747dee7a2 | refs/heads/master | 1,680,089,697,789 | 1,617,652,603,000 | 1,617,652,603,000 | 266,203,243 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,111 | lean | import definitions ralgebra
noncomputable theory
open set classical
local attribute [instance] prop_decidable
variables {X : Type*} [metric_space X] [compact_space X]
-- We adopt the notation of bounded countinuous function from mathlib
local infixr ` →ᵇ ` : 25 := bounded_continuous_function
/- This file contains all the non-proven propositions used by main.lean
Most of these lemmas are rather trivial. I aim to present a text proof alongside the
less trivial propositions. -/
-- compact.elim_finite_subcover require semilattices which we will assume
instance : semilattice_sup_bot (X →ᵇ ℝ) := sorry
instance : semilattice_inf_top (X →ᵇ ℝ) := sorry
variables {M₀ : set (X →ᵇ ℝ)}
-- The following 10 propositions are trivial
lemma le_finset_sup {I : finset X} (g : X → X →ᵇ ℝ) :
∀ i ∈ I, ∀ x : X, g i x ≤ (I.sup g) x := sorry
lemma finset_sup_lt {I : finset X} {g : X → X →ᵇ ℝ} {x} {r}
(hlt : ∀ i ∈ I, g i x < r) : (I.sup g) x < r := sorry
lemma finset_sup_mem_closure₀ {I : finset X} {g : X → X →ᵇ ℝ}
(hg : ∀ i, g i ∈ closure₀ M₀) : I.sup g ∈ closure₀ M₀ := sorry
lemma finset_inf_le {I : finset X} (g : X → X →ᵇ ℝ) :
∀ i ∈ I, ∀ x : X, (I.inf g) x ≤ g i x := sorry
lemma lt_finset_inf {I : finset X} {g : X → X →ᵇ ℝ} {x} {r}
(hlt : ∀ i ∈ I, r < g i x) : r < (I.inf g) x := sorry
lemma finset_inf_mem_closure₀ {I : finset X} {g : X → X →ᵇ ℝ}
(hg : ∀ i, g i ∈ closure₀ M₀) : I.inf g ∈ closure₀ M₀ := sorry
lemma is_open_aux_set₀ {f : X →ᵇ ℝ}
{g : X → X →ᵇ ℝ} {ε : ℝ} (hε : ε > 0) :
∀ y : X, is_open {z : X | f z - (g y) z < ε} := sorry
lemma is_open_aux_set₁ {f : X →ᵇ ℝ}
{g : X → X →ᵇ ℝ} {ε : ℝ} (hε : ε > 0) :
∀ x : X, is_open {z : X | g x z < f z + ε} := sorry
lemma neg_inf_eq_sup {f g h : X →ᵇ ℝ} : f = g ⊔ h ↔ -f = -g ⊓ -h := sorry
lemma neg_sup_eq_inf {f g h : X →ᵇ ℝ} : f = g ⊓ h ↔ -f = -g ⊔ -h := sorry
/- Follows by choosing the same δ from hF -/
lemma neg_unif_converges_to {f : X →ᵇ ℝ} {F : ℕ → (X →ᵇ ℝ)}
(hF : unif_converges_to (λ n, F n) f) : unif_converges_to (λ n, -F n) (-f) := sorry
/- The forward direction is true by mem_univ, the backwards is true by defining the function
such that ∀ z ∈ ℝ², f : X →ᵇ ℝ, (u : X) ↦ z.1 if u = x, else z.2 -/
lemma boundary_points_of_univ : ∀ x y : X, boundary_points univ x y = univ := sorry
/- This is true since M₀' is a subalgebra ⇒ 1 ∈ M₀'.carrier and
∀ μ ∈ ℝ, ∀ f ∈ M₀'.carrier, μf ∈ M₀'.carrier ⇒ r • 1 ∈ M₀'.carrier -/
lemma subalgebra_closed_under_smul' {M₀' : subalgebra ℝ (X →ᵇ ℝ)} :
∀ (α : ℝ) {x}, x ∈ M₀'.carrier → α • x ∈ M₀'.carrier := sorry
-- The following 4 propositions are trivial
lemma closure₂_of_closure₂ (M₀ : set (X →ᵇ ℝ)) :
closure₂ (closure₂ M₀) = closure₂ M₀ := sorry
lemma closure₀_closed_with_sup {M₀ : set (X →ᵇ ℝ)} {f g}
(hf : f ∈ closure₀ M₀) (hg : g ∈ closure₀ M₀) : f ⊔ g ∈ closure₀ M₀ := sorry
lemma closure₀_closed_with_inf {M₀ : set (X →ᵇ ℝ)} {f g}
(hf : f ∈ closure₀ M₀) (hg : g ∈ closure₀ M₀) : f ⊓ g ∈ closure₀ M₀ := sorry
lemma closure_le_seq₁ {M₀ : set (X →ᵇ ℝ)} :
closure₀ M₀ ⊆ closure₂ M₀ := sorry
/- To prove `closure₂_subalgebra` we need to first show that `closure₂ M₀'.carrier`
forms a subring. The is easily shown since M₀'.carrier ⊆ closure₂ M₀'.carrier and
closure₂ M₀'.carrier is closed.
We also need to show `range_le'` but this also follows directly from M₀'.carrier
⊆ closure₂ M₀'.carrier. -/
def closure₂_subalgebra (M₀' : subalgebra ℝ (X →ᵇ ℝ)) : subalgebra ℝ (X →ᵇ ℝ) :=
{ carrier := closure₂ M₀'.carrier,
subring := sorry,
range_le' := sorry}
/- This is the trivial subalgebra -/
def univ_subalgebra : subalgebra ℝ (X →ᵇ ℝ) :=
{ carrier := univ,
subring := sorry,
range_le' := sorry }
|
f86362f442a8a184ef0d934f083fd439725cefc2 | a537b538f2bea3181e24409d8a52590603d1ddd9 | /test/deeply_nested.lean | d1271a6f19a6ebdc43632fd3d9fe0f9eaa1fc418 | [] | no_license | rwbarton/lean-tidy | 6134813ded72b275d19d4d32514dba80c21708e3 | fe1125d32adb60decda7a77d0f679614ba9f6fbb | refs/heads/master | 1,585,549,718,705 | 1,538,120,619,000 | 1,538,120,624,000 | 150,864,330 | 0 | 0 | null | 1,538,225,790,000 | 1,538,225,790,000 | null | UTF-8 | Lean | false | false | 2,053 | lean | /-
old chain (did not automatically abstract intermediate results)
cumulative profiling times:
compilation 396ms
decl post-processing 6.77ms
elaboration 51.6s
elaboration: tactic compilation 140ms
elaboration: tactic execution 16.8s
parsing 234ms
type checking 20.5ms
new chain:
cumulative profiling times:
compilation 377ms
decl post-processing 7.26ms
elaboration 14.1s
elaboration: tactic compilation 135ms
elaboration: tactic execution 9.57s
parsing 231ms
type checking 19.9ms
-/
import tidy.tidy
namespace deeply_nested
structure A :=
(z : ℕ)
structure B :=
(a : A)
(aa : a.z = 0)
structure C :=
(a : A)
(b : B)
(ab : a.z = b.a.z)
structure D :=
(a : B)
(b : C)
(ab : a.a.z = b.a.z)
structure E :=
(a : C)
(b : D)
(ab : a.b.a.z = b.b.a.z)
structure F :=
(a : D)
(b : E)
(ab : a.b.b.a.z = b.b.b.a.z)
structure G :=
(a : E)
(b : F)
(ab : a.b.b.b.a.z = b.b.b.b.a.z)
structure H :=
(a : F)
(b : G)
(ab : a.b.b.b.b.a.z = b.b.b.b.b.a.z)
structure I :=
(a : G)
(b : H)
(ab : a.b.b.b.b.b.a.z = b.b.b.b.b.b.a.z)
structure J :=
(a : H)
(b : I)
(ab : a.b.b.b.b.b.b.a.z = b.b.b.b.b.b.b.a.z)
structure K :=
(a : I)
(b : J)
(ab : a.b.b.b.b.b.b.b.a.z = b.b.b.b.b.b.b.b.a.z)
structure L :=
(a : J)
(b : K)
(ab : a.b.b.b.b.b.b.b.b.a.z = b.b.b.b.b.b.b.b.b.a.z)
structure M :=
(a : K)
(b : L)
(ab : a.b.b.b.b.b.b.b.b.b.a.z = b.b.b.b.b.b.b.b.b.b.a.z)
structure N :=
(a : L)
(b : M)
(ab : a.b.b.b.b.b.b.b.b.b.b.a.z = b.b.b.b.b.b.b.b.b.b.b.a.z)
open tactic
def f : F :=
begin
tidy --{trace_result:=tt},
-- fsplit, fsplit, fsplit, fsplit, rotate_left 1,
-- refl, tactic.result >>= tactic.trace,
-- fsplit, fsplit, rotate_left 1,
-- fsplit, fsplit, rotate_left 1, refl,
-- refl, tactic.result >>= tactic.trace,
-- refl, fsplit,
-- fsplit, fsplit, rotate_left 1, fsplit, fsplit, rotate_left 1,
-- refl, refl, fsplit, fsplit, fsplit, rotate_left 1,
-- refl, fsplit, fsplit, rotate_left 1, fsplit,
-- fsplit, rotate_left 1, refl, refl, refl, refl, refl
end.
-- #print prefix deeply_nested.f
end deeply_nested
|
0ece978c445e0b14c79ae84dfe5f7d8c3ee76ea9 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/category_theory/limits/constructions/weakly_initial.lean | 0457a350e2dd332bcc10af238eec6bfb7a79fde9 | [
"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 | 2,423 | lean | /-
Copyright (c) 2021 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import category_theory.limits.shapes.wide_equalizers
import category_theory.limits.shapes.products
import category_theory.limits.shapes.terminal
/-!
# Constructions related to weakly initial objects
This file gives constructions related to weakly initial objects, namely:
* If a category has small products and a small weakly initial set of objects, then it has a weakly
initial object.
* If a category has wide equalizers and a weakly initial object, then it has an initial object.
These are primarily useful to show the General Adjoint Functor Theorem.
-/
universes v u
namespace category_theory
open limits
variables {C : Type u} [category.{v} C]
/--
If `C` has (small) products and a small weakly initial set of objects, then it has a weakly initial
object.
-/
lemma has_weakly_initial_of_weakly_initial_set_and_has_products [has_products C]
{ι : Type v} {B : ι → C} (hB : ∀ (A : C), ∃ i, nonempty (B i ⟶ A)) :
∃ (T : C), ∀ X, nonempty (T ⟶ X) :=
⟨∏ B, λ X, ⟨pi.π _ _ ≫ (hB X).some_spec.some⟩⟩
/--
If `C` has (small) wide equalizers and a weakly initial object, then it has an initial object.
The initial object is constructed as the wide equalizer of all endomorphisms on the given weakly
initial object.
-/
lemma has_initial_of_weakly_initial_and_has_wide_equalizers [has_wide_equalizers C]
{T : C} (hT : ∀ X, nonempty (T ⟶ X)) :
has_initial C :=
begin
let endos := T ⟶ T,
let i := wide_equalizer.ι (id : endos → endos),
haveI : nonempty endos := ⟨𝟙 _⟩,
have : ∀ (X : C), unique (wide_equalizer (id : endos → endos) ⟶ X),
{ intro X,
refine ⟨⟨i ≫ classical.choice (hT X)⟩, λ a, _⟩,
let E := equalizer a (i ≫ classical.choice (hT _)),
let e : E ⟶ wide_equalizer id := equalizer.ι _ _,
let h : T ⟶ E := classical.choice (hT E),
have : ((i ≫ h) ≫ e) ≫ i = i ≫ 𝟙 _,
{ rw [category.assoc, category.assoc],
apply wide_equalizer.condition (id : endos → endos) (h ≫ e ≫ i) },
rw [category.comp_id, cancel_mono_id i] at this,
haveI : split_epi e := ⟨i ≫ h, this⟩,
rw ←cancel_epi e,
apply equalizer.condition },
exactI has_initial_of_unique (wide_equalizer (id : endos → endos)),
end
end category_theory
|
126b282cc3cfd5f1115cdd78168df39e97fecf73 | d5ecf6c46a2f605470a4a7724909dc4b9e7350e0 | /data/nat/prime.lean | 4fa5a2e3ac3f572d8af88bd7e5896dce2a7f492c | [
"Apache-2.0"
] | permissive | MonoidMusician/mathlib | 41f79df478987a636b735c338396813d2e8e44c4 | 72234ef1a050eea3a2197c23aeb345fc13c08ff3 | refs/heads/master | 1,583,672,205,771 | 1,522,892,143,000 | 1,522,892,143,000 | 128,144,032 | 0 | 0 | Apache-2.0 | 1,522,892,144,000 | 1,522,890,892,000 | Lean | UTF-8 | Lean | false | false | 11,223 | lean | /-
Copyright (c) 2015 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Mario Carneiro
Prime numbers.
-/
import data.nat.sqrt data.nat.gcd
open bool subtype
namespace nat
open decidable
/-- `prime p` means that `p` is a prime number, that is, a natural number
at least 2 whose only divisors are `p` and `1`. -/
def prime (p : ℕ) := p ≥ 2 ∧ ∀ m ∣ p, m = 1 ∨ m = p
theorem prime.ge_two {p : ℕ} : prime p → p ≥ 2 := and.left
theorem prime.gt_one {p : ℕ} : prime p → p > 1 := prime.ge_two
theorem prime_def_lt {p : ℕ} : prime p ↔ p ≥ 2 ∧ ∀ m < p, m ∣ p → m = 1 :=
and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h l d, (h d).resolve_right (ne_of_lt l),
λ h d, (lt_or_eq_of_le $
le_of_dvd (le_of_succ_le p2) d).imp_left (λ l, h l d)⟩
theorem prime_def_lt' {p : ℕ} : prime p ↔ p ≥ 2 ∧ ∀ m, 2 ≤ m → m < p → ¬ m ∣ p :=
prime_def_lt.trans $ and_congr_right $ λ p2, forall_congr $ λ m,
⟨λ h m2 l d, not_lt_of_ge m2 ((h l d).symm ▸ dec_trivial),
λ h l d, begin
rcases m with _|_|m,
{ rw eq_zero_of_zero_dvd d at p2, revert p2, exact dec_trivial },
{ refl },
{ exact (h dec_trivial l).elim d }
end⟩
theorem prime_def_le_sqrt {p : ℕ} : prime p ↔ p ≥ 2 ∧
∀ m, 2 ≤ m → m ≤ sqrt p → ¬ m ∣ p :=
prime_def_lt'.trans $ and_congr_right $ λ p2,
⟨λ a m m2 l, a m m2 $ lt_of_le_of_lt l $ sqrt_lt_self p2,
λ a, have ∀ {m k}, m ≤ k → 1 < m → p ≠ m * k, from
λ m k mk m1 e, a m m1
(le_sqrt.2 (e.symm ▸ mul_le_mul_left m mk)) ⟨k, e⟩,
λ m m2 l ⟨k, e⟩, begin
cases (le_total m k) with mk km,
{ exact this mk m2 e },
{ rw [mul_comm] at e,
refine this km (lt_of_mul_lt_mul_right _ (zero_le m)) e,
rwa [one_mul, ← e] }
end⟩
def decidable_prime_1 (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_lt'
local attribute [instance] decidable_prime_1
theorem prime.pos {p : ℕ} (pp : prime p) : p > 0 :=
lt_of_succ_lt pp.gt_one
theorem not_prime_zero : ¬ prime 0 := dec_trivial
theorem not_prime_one : ¬ prime 1 := dec_trivial
theorem prime_two : prime 2 := dec_trivial
theorem prime_three : prime 3 := dec_trivial
theorem prime.pred_pos {p : ℕ} (pp : prime p) : pred p > 0 :=
lt_pred_of_succ_lt pp.gt_one
theorem succ_pred_prime {p : ℕ} (pp : prime p) : succ (pred p) = p :=
succ_pred_eq_of_pos pp.pos
theorem dvd_prime {p m : ℕ} (pp : prime p) : m ∣ p ↔ m = 1 ∨ m = p :=
⟨λ d, pp.2 m d, λ h, h.elim (λ e, e.symm ▸ one_dvd _) (λ e, e.symm ▸ dvd_refl _)⟩
theorem dvd_prime_ge_two {p m : ℕ} (pp : prime p) (H : m ≥ 2) : m ∣ p ↔ m = p :=
(dvd_prime pp).trans $ or_iff_right_of_imp $ not.elim $ ne_of_gt H
theorem prime.not_dvd_one {p : ℕ} (pp : prime p) : ¬ p ∣ 1
| d := (not_le_of_gt pp.gt_one) $ le_of_dvd dec_trivial d
section min_fac
private lemma min_fac_lemma (n k : ℕ) (h : ¬ k * k > n) :
sqrt n - k < sqrt n + 2 - k :=
(nat.sub_lt_sub_right_iff $ le_sqrt.2 $ le_of_not_gt h).2 $
nat.lt_add_of_pos_right dec_trivial
def min_fac_aux (n : ℕ) : ℕ → ℕ | k :=
if h : n < k * k then n else
if k ∣ n then k else
have _, from min_fac_lemma n k h,
min_fac_aux (k + 2)
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
/-- Returns the smallest prime factor of `n ≠ 1`. -/
def min_fac : ℕ → ℕ
| 0 := 2
| 1 := 1
| (n+2) := if 2 ∣ n then 2 else min_fac_aux (n + 2) 3
@[simp] theorem min_fac_zero : min_fac 0 = 2 := rfl
@[simp] theorem min_fac_one : min_fac 1 = 1 := rfl
theorem min_fac_eq : ∀ {n : ℕ} (n2 : n ≥ 2),
min_fac n = if 2 ∣ n then 2 else min_fac_aux n 3
| 1 h := (dec_trivial : ¬ _).elim h
| (n+2) h := by by_cases 2 ∣ n;
simp [min_fac, (nat.dvd_add_iff_left (dvd_refl 2)).symm, h]
private def min_fac_prop (n k : ℕ) :=
k ≥ 2 ∧ k ∣ n ∧ ∀ m ≥ 2, m ∣ n → k ≤ m
theorem min_fac_aux_has_prop {n : ℕ} (n2 : n ≥ 2) (nd2 : ¬ 2 ∣ n) :
∀ k i, k = 2*i+3 → (∀ m ≥ 2, m ∣ n → k ≤ m) → min_fac_prop n (min_fac_aux n k)
| k := λ i e a, begin
rw min_fac_aux,
by_cases h : n < k*k; simp [h],
{ have pp : prime n :=
prime_def_le_sqrt.2 ⟨n2, λ m m2 l d,
not_lt_of_ge l $ lt_of_lt_of_le (sqrt_lt.2 h) (a m m2 d)⟩,
from ⟨n2, dvd_refl _, λ m m2 d, le_of_eq
((dvd_prime_ge_two pp m2).1 d).symm⟩ },
have k2 : 2 ≤ k, { subst e, exact dec_trivial },
by_cases dk : k ∣ n; simp [dk],
{ exact ⟨k2, dk, a⟩ },
{ refine have _, from min_fac_lemma n k h,
min_fac_aux_has_prop (k+2) (i+1)
(by simp [e, left_distrib]) (λ m m2 d, _),
cases nat.eq_or_lt_of_le (a m m2 d) with me ml,
{ subst me, contradiction },
apply (nat.eq_or_lt_of_le ml).resolve_left, intro me,
rw [← me, e] at d, change 2 * (i + 2) ∣ n at d,
have := dvd_of_mul_right_dvd d, contradiction }
end
using_well_founded {rel_tac :=
λ _ _, `[exact ⟨_, measure_wf (λ k, sqrt n + 2 - k)⟩]}
theorem min_fac_has_prop {n : ℕ} (n1 : n ≠ 1) :
min_fac_prop n (min_fac n) :=
begin
by_cases n0 : n = 0, {simp [n0, min_fac_prop, ge]},
have n2 : 2 ≤ n, { revert n0 n1, rcases n with _|_|_; exact dec_trivial },
simp [min_fac_eq n2],
by_cases d2 : 2 ∣ n; simp [d2],
{ exact ⟨le_refl _, d2, λ k k2 d, k2⟩ },
{ refine min_fac_aux_has_prop n2 d2 3 0 rfl
(λ m m2 d, (nat.eq_or_lt_of_le m2).resolve_left (mt _ d2)),
exact λ e, e.symm ▸ d }
end
theorem min_fac_dvd (n : ℕ) : min_fac n ∣ n :=
by by_cases n1 : n = 1;
[exact n1.symm ▸ dec_trivial, exact (min_fac_has_prop n1).2.1]
theorem min_fac_prime {n : ℕ} (n1 : n ≠ 1) : prime (min_fac n) :=
let ⟨f2, fd, a⟩ := min_fac_has_prop n1 in
prime_def_lt'.2 ⟨f2, λ m m2 l d, not_le_of_gt l (a m m2 (dvd_trans d fd))⟩
theorem min_fac_le_of_dvd (n : ℕ) : ∀ (m : ℕ), m ≥ 2 → m ∣ n → min_fac n ≤ m :=
by by_cases n1 : n = 1;
[exact λ m m2 d, n1.symm ▸ le_trans dec_trivial m2,
exact (min_fac_has_prop n1).2.2]
theorem min_fac_pos (n : ℕ) : min_fac n > 0 :=
by by_cases n1 : n = 1;
[exact n1.symm ▸ dec_trivial, exact (min_fac_prime n1).pos]
theorem min_fac_le {n : ℕ} (H : n > 0) : min_fac n ≤ n :=
le_of_dvd H (min_fac_dvd n)
theorem prime_def_min_fac {p : ℕ} : prime p ↔ p ≥ 2 ∧ min_fac p = p :=
⟨λ pp, ⟨pp.ge_two,
let ⟨f2, fd, a⟩ := min_fac_has_prop $ ne_of_gt pp.gt_one in
((dvd_prime pp).1 fd).resolve_left (ne_of_gt f2)⟩,
λ ⟨p2, e⟩, e ▸ min_fac_prime (ne_of_gt p2)⟩
instance decidable_prime (p : ℕ) : decidable (prime p) :=
decidable_of_iff' _ prime_def_min_fac
theorem not_prime_iff_min_fac_lt {n : ℕ} (n2 : n ≥ 2) : ¬ prime n ↔ min_fac n < n :=
(not_congr $ prime_def_min_fac.trans $ and_iff_right n2).trans $
(lt_iff_le_and_ne.trans $ and_iff_right $ min_fac_le $ le_of_succ_le n2).symm
end min_fac
theorem exists_dvd_of_not_prime {n : ℕ} (n2 : n ≥ 2) (np : ¬ prime n) :
∃ m, m ∣ n ∧ m ≠ 1 ∧ m ≠ n :=
⟨min_fac n, min_fac_dvd _, ne_of_gt (min_fac_prime (ne_of_gt n2)).gt_one,
ne_of_lt $ (not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_dvd_of_not_prime2 {n : ℕ} (n2 : n ≥ 2) (np : ¬ prime n) :
∃ m, m ∣ n ∧ m ≥ 2 ∧ m < n :=
⟨min_fac n, min_fac_dvd _, (min_fac_prime (ne_of_gt n2)).ge_two,
(not_prime_iff_min_fac_lt n2).1 np⟩
theorem exists_prime_and_dvd {n : ℕ} (n2 : n ≥ 2) : ∃ p, prime p ∧ p ∣ n :=
⟨min_fac n, min_fac_prime (ne_of_gt n2), min_fac_dvd _⟩
theorem exists_infinite_primes : ∀ n : ℕ, ∃ p, p ≥ n ∧ prime p :=
suffices ∀ {n}, n ≥ 2 → ∃ p, p ≥ n ∧ prime p, from
λ n, let ⟨p, h, pp⟩ := this (nat.le_add_left 2 n) in
⟨p, le_trans (nat.le_add_right n 2) h, pp⟩,
λ n n2,
let p := min_fac (fact n + 1) in
have f1 : fact n + 1 ≠ 1, from ne_of_gt $ succ_lt_succ $ fact_pos _,
have pp : prime p, from min_fac_prime f1,
have n ≤ p, from le_of_not_ge $ λ h,
have p ∣ fact n, from dvd_fact (min_fac_pos _) h,
have p ∣ 1, from (nat.dvd_add_iff_right this).2 (min_fac_dvd _),
pp.not_dvd_one this,
⟨p, this, pp⟩
/-- `factors n` is the prime factorization of `n`, listed in increasing order. -/
def factors : ℕ → list ℕ
| 0 := []
| 1 := []
| n@(k+2) := let m := min_fac n in
have n / m < n, from
have n * 1 < n * min_fac n, from nat.mul_lt_mul_of_pos_left
(min_fac_prime dec_trivial).gt_one (succ_pos _),
(nat.div_lt_iff_lt_mul _ _ (min_fac_pos _)).2 $ by simpa,
m :: factors (n / m)
theorem prime.coprime_iff_not_dvd {p n : ℕ} (pp : prime p) : coprime p n ↔ ¬ p ∣ n :=
⟨λ co d, pp.not_dvd_one $ co.dvd_of_dvd_mul_left (by simp [d]),
λ nd, coprime_of_dvd $ λ m m2 mp, ((dvd_prime_ge_two pp m2).1 mp).symm ▸ nd⟩
theorem prime.dvd_iff_not_coprime {p n : ℕ} (pp : prime p) : p ∣ n ↔ ¬ coprime p n :=
iff_not_comm.2 pp.coprime_iff_not_dvd
theorem prime.dvd_mul {p m n : ℕ} (pp : prime p) : p ∣ m * n ↔ p ∣ m ∨ p ∣ n :=
⟨λ H, or_iff_not_imp_left.2 $ λ h,
(pp.coprime_iff_not_dvd.2 h).dvd_of_dvd_mul_left H,
or.rec (λ h, dvd_mul_of_dvd_left h _) (λ h, dvd_mul_of_dvd_right h _)⟩
theorem prime.not_dvd_mul {p m n : ℕ} (pp : prime p)
(Hm : ¬ p ∣ m) (Hn : ¬ p ∣ n) : ¬ p ∣ m * n :=
mt pp.dvd_mul.1 $ by simp [Hm, Hn]
theorem prime.dvd_of_dvd_pow {p m n : ℕ} (pp : prime p) (h : p ∣ m^n) : p ∣ m :=
by induction n with n IH;
[exact pp.not_dvd_one.elim h,
exact (pp.dvd_mul.1 h).elim IH id]
theorem prime.coprime_pow_of_not_dvd {p m a : ℕ} (pp : prime p) (h : ¬ p ∣ a) : coprime a (p^m) :=
(pp.coprime_iff_not_dvd.2 h).symm.pow_right _
theorem coprime_primes {p q : ℕ} (pp : prime p) (pq : prime q) : coprime p q ↔ p ≠ q :=
pp.coprime_iff_not_dvd.trans $ not_congr $ dvd_prime_ge_two pq pp.ge_two
theorem coprime_pow_primes {p q : ℕ} (n m : ℕ) (pp : prime p) (pq : prime q) (h : p ≠ q) :
coprime (p^n) (q^m) :=
((coprime_primes pp pq).2 h).pow _ _
theorem coprime_or_dvd_of_prime {p} (pp : prime p) (i : ℕ) : coprime p i ∨ p ∣ i :=
by rw [pp.dvd_iff_not_coprime]; apply em
theorem dvd_prime_pow {p : ℕ} (pp : prime p) {m i : ℕ} : i ∣ (p^m) ↔ ∃ k ≤ m, i = p^k :=
begin
induction m with m IH generalizing i, {simp [pow_succ, le_zero_iff] at *},
by_cases p ∣ i,
{ cases h with a e, subst e,
rw [pow_succ, mul_comm (p^m) p, nat.mul_dvd_mul_iff_left pp.pos, IH],
split; intro h; rcases h with ⟨k, h, e⟩,
{ exact ⟨succ k, succ_le_succ h, by rw [mul_comm, e]; refl⟩ },
cases k with k,
{ apply pp.not_dvd_one.elim,
simp at e, rw ← e, apply dvd_mul_right },
{ refine ⟨k, le_of_succ_le_succ h, _⟩,
rwa [mul_comm, pow_succ, nat.mul_right_inj pp.pos] at e } },
{ split; intro d,
{ rw (pp.coprime_pow_of_not_dvd h).eq_one_of_dvd d,
exact ⟨0, zero_le _, rfl⟩ },
{ rcases d with ⟨k, l, e⟩,
rw e, exact pow_dvd_pow _ l } }
end
end nat
|
14417ceb65ada3da8b57af6ae9fb8b39a73d609c | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/equiv/denumerable.lean | ab59b44e154d283254c6e18e5cb2ddb06b4141b9 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 9,072 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Denumerable (countably infinite) types, as a typeclass extending
encodable. This is used to provide explicit encode/decode functions
from nat, where the functions are known inverses of each other.
-/
import data.equiv.encodable.basic
import data.sigma
import data.fintype.basic
import data.list.min_max
open nat
/-- A denumerable type is one which is (constructively) bijective with ℕ.
Although we already have a name for this property, namely `α ≃ ℕ`,
we are here interested in using it as a typeclass. -/
class denumerable (α : Type*) extends encodable α :=
(decode_inv : ∀ n, ∃ a ∈ decode n, encode a = n)
namespace denumerable
section
variables {α : Type*} {β : Type*} [denumerable α] [denumerable β]
open encodable
theorem decode_is_some (α) [denumerable α] (n : ℕ) :
(decode α n).is_some :=
option.is_some_iff_exists.2 $
(decode_inv n).imp $ λ a, Exists.fst
def of_nat (α) [f : denumerable α] (n : ℕ) : α :=
option.get (decode_is_some α n)
@[simp, priority 900]
theorem decode_eq_of_nat (α) [denumerable α] (n : ℕ) :
decode α n = some (of_nat α n) :=
option.eq_some_of_is_some _
@[simp] theorem of_nat_of_decode {n b}
(h : decode α n = some b) : of_nat α n = b :=
option.some.inj $ (decode_eq_of_nat _ _).symm.trans h
@[simp] theorem encode_of_nat (n) : encode (of_nat α n) = n :=
let ⟨a, h, e⟩ := decode_inv n in
by rwa [of_nat_of_decode h]
@[simp] theorem of_nat_encode (a) : of_nat α (encode a) = a :=
of_nat_of_decode (encodek _)
def eqv (α) [denumerable α] : α ≃ ℕ :=
⟨encode, of_nat α, of_nat_encode, encode_of_nat⟩
def mk' {α} (e : α ≃ ℕ) : denumerable α :=
{ encode := e,
decode := some ∘ e.symm,
encodek := λ a, congr_arg some (e.symm_apply_apply _),
decode_inv := λ n, ⟨_, rfl, e.apply_symm_apply _⟩ }
def of_equiv (α) {β} [denumerable α] (e : β ≃ α) : denumerable β :=
{ decode_inv := λ n, by simp,
..encodable.of_equiv _ e }
@[simp] theorem of_equiv_of_nat (α) {β} [denumerable α] (e : β ≃ α)
(n) : @of_nat β (of_equiv _ e) n = e.symm (of_nat α n) :=
by apply of_nat_of_decode; show option.map _ _ = _; simp
def equiv₂ (α β) [denumerable α] [denumerable β] : α ≃ β := (eqv α).trans (eqv β).symm
instance nat : denumerable nat := ⟨λ n, ⟨_, rfl, rfl⟩⟩
@[simp] theorem of_nat_nat (n) : of_nat ℕ n = n := rfl
instance option : denumerable (option α) := ⟨λ n, by cases n; simp⟩
instance sum : denumerable (α ⊕ β) :=
⟨λ n, begin
suffices : ∃ a ∈ @decode_sum α β _ _ n,
encode_sum a = bit (bodd n) (div2 n), {simpa [bit_decomp]},
simp [decode_sum]; cases bodd n; simp [decode_sum, bit, encode_sum]
end⟩
section sigma
variables {γ : α → Type*} [∀ a, denumerable (γ a)]
instance sigma : denumerable (sigma γ) :=
⟨λ n, by simp [decode_sigma]; exact ⟨_, _, ⟨rfl, heq.rfl⟩, by simp⟩⟩
@[simp] theorem sigma_of_nat_val (n : ℕ) :
of_nat (sigma γ) n = ⟨of_nat α (unpair n).1, of_nat (γ _) (unpair n).2⟩ :=
option.some.inj $
by rw [← decode_eq_of_nat, decode_sigma_val]; simp; refl
end sigma
instance prod : denumerable (α × β) :=
of_equiv _ (equiv.sigma_equiv_prod α β).symm
@[simp] theorem prod_of_nat_val (n : ℕ) :
of_nat (α × β) n = (of_nat α (unpair n).1, of_nat β (unpair n).2) :=
by simp; refl
@[simp] theorem prod_nat_of_nat : of_nat (ℕ × ℕ) = unpair :=
by funext; simp
instance int : denumerable ℤ := denumerable.mk' equiv.int_equiv_nat
instance pnat : denumerable ℕ+ := denumerable.mk' equiv.pnat_equiv_nat
instance ulift : denumerable (ulift α) := of_equiv _ equiv.ulift
instance plift : denumerable (plift α) := of_equiv _ equiv.plift
def pair : α × α ≃ α := equiv₂ _ _
end
end denumerable
namespace nat.subtype
open function encodable
variables {s : set ℕ} [infinite s]
section classical
open_locale classical
lemma exists_succ (x : s) : ∃ n, x.1 + n + 1 ∈ s :=
classical.by_contradiction $ λ h,
have ∀ (a : ℕ) (ha : a ∈ s), a < x.val.succ,
from λ a ha, lt_of_not_ge (λ hax, h ⟨a - (x.1 + 1),
by rwa [add_right_comm, nat.add_sub_cancel' hax]⟩),
infinite.not_fintype
⟨(((multiset.range x.1.succ).filter (∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), subtype.mk y hy)
(by simp [-multiset.range_succ])).to_finset,
by simpa [subtype.ext_iff_val, multiset.mem_filter, -multiset.range_succ]⟩
end classical
variable [decidable_pred s]
def succ (x : s) : s :=
have h : ∃ m, x.1 + m + 1 ∈ s, from exists_succ x,
⟨x.1 + nat.find h + 1, nat.find_spec h⟩
lemma succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt h in
have nat.find hx ≤ k, from nat.find_min' _ (hk ▸ x.2),
show y.1 + nat.find hx + 1 ≤ x.1,
by rw hk; exact add_le_add_right (add_le_add_left this _) _
lemma le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
show x.1 ≤ y.1 + nat.find hx + 1,
from le_of_not_gt $ λ hxy,
have y.1 + nat.find hx + 1 ≤ y.1 := h ⟨_, nat.find_spec hx⟩ hxy,
not_lt_of_le this $
calc y.1 ≤ y.1 + nat.find hx : le_add_of_nonneg_right (nat.zero_le _)
... < y.1 + nat.find hx + 1 : nat.lt_succ_self _
lemma lt_succ_self (x : s) : x < succ x :=
calc x.1 ≤ x.1 + _ : le_add_right (le_refl _)
... < succ x : nat.lt_succ_self (x.1 + _)
lemma lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y :=
⟨λ h, le_of_not_gt (λ h', not_le_of_gt h (succ_le_of_lt h')),
λ h, lt_of_le_of_lt h (lt_succ_self _)⟩
def of_nat (s : set ℕ) [decidable_pred s] [infinite s] : ℕ → s
| 0 := ⊥
| (n+1) := succ (of_nat n)
lemma of_nat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, of_nat s n = ⟨x, hx⟩
| x := λ hx, let t : list s := ((list.range x).filter (λ y, y ∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩,
by simp [list.mem_filter, subtype.ext_iff_val, t]; intros; refl,
have wf : ∀ m : s, list.maximum t = m → m.1 < x,
from λ m hmax, by simpa [hmt] using list.maximum_mem hmax,
begin
cases hmax : list.maximum t with m,
{ exact ⟨0, le_antisymm (@bot_le s _ _)
(le_of_not_gt (λ h, list.not_mem_nil (⊥ : s) $
by rw [← list.maximum_eq_none.1 hmax, hmt]; exact h))⟩ },
{ cases of_nat_surjective_aux m.2 with a ha,
exact ⟨a + 1, le_antisymm
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf _ hmax)) $
by rw of_nat; exact le_succ_of_forall_lt_le
(λ z hz, by rw ha; cases m; exact list.le_maximum_of_mem (hmt.2 hz) hmax)⟩ }
end
using_well_founded {dec_tac := `[tauto]}
lemma of_nat_surjective : surjective (of_nat s) :=
λ ⟨x, hx⟩, of_nat_surjective_aux hx
private def to_fun_aux (x : s) : ℕ :=
(list.range x).countp s
private lemma to_fun_aux_eq (x : s) :
to_fun_aux x = ((finset.range x).filter s).card :=
by rw [to_fun_aux, list.countp_eq_length_filter]; refl
open finset
private lemma right_inverse_aux : ∀ n, to_fun_aux (of_nat s n) = n
| 0 := begin
rw [to_fun_aux_eq, card_eq_zero, eq_empty_iff_forall_not_mem],
assume n,
rw [mem_filter, of_nat, mem_range],
assume h,
exact not_lt_of_le bot_le (show (⟨n, h.2⟩ : s) < ⊥, from h.1)
end
| (n+1) := have ih : to_fun_aux (of_nat s n) = n, from right_inverse_aux n,
have h₁ : (of_nat s n : ℕ) ∉ (range (of_nat s n)).filter s, by simp,
have h₂ : (range (succ (of_nat s n))).filter s =
insert (of_nat s n) ((range (of_nat s n)).filter s),
begin
simp only [finset.ext_iff, mem_insert, mem_range, mem_filter],
assume m,
exact ⟨λ h, by simp only [h.2, and_true]; exact or.symm
(lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)),
λ h, h.elim (λ h, h.symm ▸ ⟨lt_succ_self _, subtype.property _⟩)
(λ h, ⟨lt_of_le_of_lt (le_of_lt h.1) (lt_succ_self _), h.2⟩)⟩
end,
begin
clear_aux_decl,
simp only [to_fun_aux_eq, of_nat, range_succ] at *,
conv {to_rhs, rw [← ih, ← card_insert_of_not_mem h₁, ← h₂] },
end
def denumerable (s : set ℕ) [decidable_pred s] [infinite s] : denumerable s :=
denumerable.of_equiv ℕ
{ to_fun := to_fun_aux,
inv_fun := of_nat s,
left_inv := left_inverse_of_surjective_of_right_inverse
of_nat_surjective right_inverse_aux,
right_inv := right_inverse_aux }
end nat.subtype
namespace denumerable
open encodable
def of_encodable_of_infinite (α : Type*) [encodable α] [infinite α] : denumerable α :=
begin
letI := @decidable_range_encode α _;
letI : infinite (set.range (@encode α _)) :=
infinite.of_injective _ (equiv.set.range _ encode_injective).injective,
letI := nat.subtype.denumerable (set.range (@encode α _)),
exact denumerable.of_equiv (set.range (@encode α _))
(equiv_range_encode α)
end
end denumerable
|
9e5f6ad047a061cd578380b038b581baf4914493 | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/algebra/group_with_zero/power.lean | 4a489e2e3a1e6a8265c465d6527cd230cdf17fc2 | [
"Apache-2.0"
] | permissive | AntoineChambert-Loir/mathlib | 64aabb896129885f12296a799818061bc90da1ff | 07be904260ab6e36a5769680b6012f03a4727134 | refs/heads/master | 1,693,187,631,771 | 1,636,719,886,000 | 1,636,719,886,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,458 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import algebra.group_power
/-!
# Powers of elements of groups with an adjoined zero element
In this file we define integer power functions for groups with an adjoined zero element.
This generalises the integer power function on a division ring.
-/
section zero
variables {M : Type*} [monoid_with_zero M]
@[simp] lemma zero_pow' : ∀ n : ℕ, n ≠ 0 → (0 : M) ^ n = 0
| 0 h := absurd rfl h
| (k+1) h := by { rw [pow_succ], exact zero_mul _ }
lemma ne_zero_pow {a : M} {n : ℕ} (hn : n ≠ 0) : a ^ n ≠ 0 → a ≠ 0 :=
by { contrapose!, rintro rfl, exact zero_pow' n hn }
@[simp] lemma zero_pow_eq_zero [nontrivial M] {n : ℕ} : (0 : M) ^ n = 0 ↔ 0 < n :=
begin
split; intro h,
{ rw [pos_iff_ne_zero], rintro rfl, simpa using h },
{ exact zero_pow' n h.ne.symm }
end
lemma ring.inverse_pow (r : M) : ∀ (n : ℕ), ring.inverse r ^ n = ring.inverse (r ^ n)
| 0 := by rw [pow_zero, pow_zero, ring.inverse_one]
| (n + 1) := by rw [pow_succ, pow_succ', ring.mul_inverse_rev' ((commute.refl r).pow_left n),
ring.inverse_pow]
end zero
section group_with_zero
variables {G₀ : Type*} [group_with_zero G₀]
section nat_pow
@[simp, field_simps] theorem inv_pow₀ (a : G₀) (n : ℕ) : (a⁻¹) ^ n = (a ^ n)⁻¹ :=
begin
induction n with n ih,
{ rw [pow_zero, pow_zero], exact inv_one.symm },
{ rw [pow_succ', pow_succ, ih, mul_inv_rev₀] }
end
theorem pow_sub₀ (a : G₀) {m n : ℕ} (ha : a ≠ 0) (h : n ≤ m) : a ^ (m - n) = a ^ m * (a ^ n)⁻¹ :=
have h1 : m - n + n = m, from tsub_add_cancel_of_le h,
have h2 : a ^ (m - n) * a ^ n = a ^ m, by rw [←pow_add, h1],
by simpa only [div_eq_mul_inv] using eq_div_of_mul_eq (pow_ne_zero _ ha) h2
theorem pow_inv_comm₀ (a : G₀) (m n : ℕ) : (a⁻¹) ^ m * a ^ n = a ^ n * (a⁻¹) ^ m :=
(commute.refl a).inv_left₀.pow_pow m n
end nat_pow
end group_with_zero
section zpow
open int
variables {G₀ : Type*} [group_with_zero G₀]
local attribute [ematch] le_of_lt
@[simp] theorem one_zpow₀ : ∀ (n : ℤ), (1 : G₀) ^ n = 1
| (n : ℕ) := by rw [zpow_coe_nat, one_pow]
| -[1+ n] := by rw [zpow_neg_succ_of_nat, one_pow, inv_one]
lemma zero_zpow : ∀ z : ℤ, z ≠ 0 → (0 : G₀) ^ z = 0
| (n : ℕ) h := by { rw [zpow_coe_nat, zero_pow'], simpa using h }
| -[1+n] h := by simp
lemma fzero_pow_eq (n : ℤ) : (0 : G₀) ^ n = if n = 0 then 1 else 0 :=
begin
split_ifs with h,
{ rw [h, zpow_zero] },
{ rw [zero_zpow _ h] }
end
@[simp] theorem zpow_neg₀ (a : G₀) : ∀ (n : ℤ), a ^ -n = (a ^ n)⁻¹
| (n+1:ℕ) := div_inv_monoid.zpow_neg' _ _
| 0 := by { change a ^ (0 : ℤ) = (a ^ (0 : ℤ))⁻¹, simp }
| -[1+ n] := by { rw [zpow_neg_succ_of_nat, inv_inv₀, ← zpow_coe_nat], refl }
theorem zpow_neg_one₀ (x : G₀) : x ^ (-1:ℤ) = x⁻¹ :=
by { rw [← congr_arg has_inv.inv (pow_one x), zpow_neg₀, ← zpow_coe_nat], refl }
theorem inv_zpow₀ (a : G₀) : ∀n:ℤ, a⁻¹ ^ n = (a ^ n)⁻¹
| (n : ℕ) := by rw [zpow_coe_nat, zpow_coe_nat, inv_pow₀]
| -[1+ n] := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, inv_pow₀]
lemma zpow_add_one₀ {a : G₀} (ha : a ≠ 0) : ∀ n : ℤ, a ^ (n + 1) = a ^ n * a
| (n : ℕ) := by simp [← int.coe_nat_succ, pow_succ']
| -[1+0] := by simp [int.neg_succ_of_nat_eq, ha]
| -[1+(n+1)] := by rw [int.neg_succ_of_nat_eq, zpow_neg₀, neg_add, neg_add_cancel_right, zpow_neg₀,
← int.coe_nat_succ, zpow_coe_nat, zpow_coe_nat, pow_succ _ (n + 1), mul_inv_rev₀, mul_assoc,
inv_mul_cancel ha, mul_one]
lemma zpow_sub_one₀ {a : G₀} (ha : a ≠ 0) (n : ℤ) : a ^ (n - 1) = a ^ n * a⁻¹ :=
calc a ^ (n - 1) = a ^ (n - 1) * a * a⁻¹ : by rw [mul_assoc, mul_inv_cancel ha, mul_one]
... = a^n * a⁻¹ : by rw [← zpow_add_one₀ ha, sub_add_cancel]
lemma zpow_add₀ {a : G₀} (ha : a ≠ 0) (m n : ℤ) : a ^ (m + n) = a ^ m * a ^ n :=
begin
induction n using int.induction_on with n ihn n ihn,
case hz : { simp },
{ simp only [← add_assoc, zpow_add_one₀ ha, ihn, mul_assoc] },
{ rw [zpow_sub_one₀ ha, ← mul_assoc, ← ihn, ← zpow_sub_one₀ ha, add_sub_assoc] }
end
lemma zpow_add' {a : G₀} {m n : ℤ} (h : a ≠ 0 ∨ m + n ≠ 0 ∨ m = 0 ∧ n = 0) :
a ^ (m + n) = a ^ m * a ^ n :=
begin
by_cases hm : m = 0, { simp [hm] },
by_cases hn : n = 0, { simp [hn] },
by_cases ha : a = 0,
{ subst a,
simp only [false_or, eq_self_iff_true, not_true, ne.def, hm, hn, false_and, or_false] at h,
rw [zero_zpow _ h, zero_zpow _ hm, zero_mul] },
{ exact zpow_add₀ ha m n }
end
theorem zpow_one_add₀ {a : G₀} (h : a ≠ 0) (i : ℤ) : a ^ (1 + i) = a * a ^ i :=
by rw [zpow_add₀ h, zpow_one]
theorem semiconj_by.zpow_right₀ {a x y : G₀} (h : semiconj_by a x y) :
∀ m : ℤ, semiconj_by a (x^m) (y^m)
| (n : ℕ) := by simp [h.pow_right n]
| -[1+n] := by simp [(h.pow_right (n + 1)).inv_right₀]
theorem commute.zpow_right₀ {a b : G₀} (h : commute a b) : ∀ m : ℤ, commute a (b^m) :=
h.zpow_right₀
theorem commute.zpow_left₀ {a b : G₀} (h : commute a b) (m : ℤ) : commute (a^m) b :=
(h.symm.zpow_right₀ m).symm
theorem commute.zpow_zpow₀ {a b : G₀} (h : commute a b) (m n : ℤ) : commute (a^m) (b^n) :=
(h.zpow_left₀ m).zpow_right₀ n
theorem commute.zpow_self₀ (a : G₀) (n : ℤ) : commute (a^n) a := (commute.refl a).zpow_left₀ n
theorem commute.self_zpow₀ (a : G₀) (n : ℤ) : commute a (a^n) := (commute.refl a).zpow_right₀ n
theorem commute.zpow_zpow_self₀ (a : G₀) (m n : ℤ) : commute (a^m) (a^n) :=
(commute.refl a).zpow_zpow₀ m n
theorem zpow_bit0₀ (a : G₀) (n : ℤ) : a ^ bit0 n = a ^ n * a ^ n :=
begin
apply zpow_add', right,
by_cases hn : n = 0,
{ simp [hn] },
{ simp [← two_mul, hn, two_ne_zero] }
end
theorem zpow_bit1₀ (a : G₀) (n : ℤ) : a ^ bit1 n = a ^ n * a ^ n * a :=
begin
rw [← zpow_bit0₀, bit1, zpow_add', zpow_one],
right, left,
apply bit1_ne_zero
end
theorem zpow_mul₀ (a : G₀) : ∀ m n : ℤ, a ^ (m * n) = (a ^ m) ^ n
| (m : ℕ) (n : ℕ) := by { rw [zpow_coe_nat, zpow_coe_nat, ← pow_mul, ← zpow_coe_nat], refl }
| (m : ℕ) -[1+ n] := by { rw [zpow_coe_nat, zpow_neg_succ_of_nat, ← pow_mul, coe_nat_mul_neg_succ,
zpow_neg₀, inv_inj₀, ← zpow_coe_nat], refl }
| -[1+ m] (n : ℕ) := by { rw [zpow_coe_nat, zpow_neg_succ_of_nat, ← inv_pow₀, ← pow_mul,
neg_succ_mul_coe_nat, zpow_neg₀, inv_pow₀, inv_inj₀, ← zpow_coe_nat], refl }
| -[1+ m] -[1+ n] := by { rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, neg_succ_mul_neg_succ,
inv_pow₀, inv_inv₀, ← pow_mul, ← zpow_coe_nat], refl }
theorem zpow_mul₀' (a : G₀) (m n : ℤ) : a ^ (m * n) = (a ^ n) ^ m :=
by rw [mul_comm, zpow_mul₀]
@[simp, norm_cast] lemma units.coe_zpow₀ (u : units G₀) :
∀ (n : ℤ), ((u ^ n : units G₀) : G₀) = u ^ n
| (n : ℕ) := by { rw [zpow_coe_nat, zpow_coe_nat], exact u.coe_pow n }
| -[1+k] := by rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat, units.coe_inv', u.coe_pow]
lemma zpow_ne_zero_of_ne_zero {a : G₀} (ha : a ≠ 0) : ∀ (z : ℤ), a ^ z ≠ 0
| (n : ℕ) := by { rw zpow_coe_nat, exact pow_ne_zero _ ha }
| -[1+n] := by { rw zpow_neg_succ_of_nat, exact inv_ne_zero (pow_ne_zero _ ha) }
lemma zpow_sub₀ {a : G₀} (ha : a ≠ 0) (z1 z2 : ℤ) : a ^ (z1 - z2) = a ^ z1 / a ^ z2 :=
by rw [sub_eq_add_neg, zpow_add₀ ha, zpow_neg₀, div_eq_mul_inv]
lemma commute.mul_zpow₀ {a b : G₀} (h : commute a b) :
∀ (i : ℤ), (a * b) ^ i = (a ^ i) * (b ^ i)
| (n : ℕ) := by simp [h.mul_pow n]
| -[1+n] := by simp [h.mul_pow, (h.pow_pow _ _).eq, mul_inv_rev₀]
lemma mul_zpow₀ {G₀ : Type*} [comm_group_with_zero G₀] (a b : G₀) (m : ℤ):
(a * b) ^ m = (a ^ m) * (b ^ m) :=
(commute.all a b).mul_zpow₀ m
theorem zpow_bit0' (a : G₀) (n : ℤ) : a ^ bit0 n = (a * a) ^ n :=
(zpow_bit0₀ a n).trans ((commute.refl a).mul_zpow₀ n).symm
theorem zpow_bit1' (a : G₀) (n : ℤ) : a ^ bit1 n = (a * a) ^ n * a :=
by rw [zpow_bit1₀, (commute.refl a).mul_zpow₀]
lemma zpow_eq_zero {x : G₀} {n : ℤ} (h : x ^ n = 0) : x = 0 :=
classical.by_contradiction $ λ hx, zpow_ne_zero_of_ne_zero hx n h
lemma zpow_ne_zero {x : G₀} (n : ℤ) : x ≠ 0 → x ^ n ≠ 0 :=
mt zpow_eq_zero
theorem zpow_neg_mul_zpow_self (n : ℤ) {x : G₀} (h : x ≠ 0) :
x ^ (-n) * x ^ n = 1 :=
begin
rw [zpow_neg₀],
exact inv_mul_cancel (zpow_ne_zero n h)
end
theorem one_div_pow {a : G₀} (n : ℕ) :
(1 / a) ^ n = 1 / a ^ n :=
by simp only [one_div, inv_pow₀]
theorem one_div_zpow {a : G₀} (n : ℤ) :
(1 / a) ^ n = 1 / a ^ n :=
by simp only [one_div, inv_zpow₀]
@[simp] lemma inv_zpow' {a : G₀} (n : ℤ) :
(a ⁻¹) ^ n = a ^ (-n) :=
by { rw [inv_zpow₀, ← zpow_neg_one₀, ← zpow_mul₀], simp }
end zpow
section
variables {G₀ : Type*} [comm_group_with_zero G₀]
@[simp] theorem div_pow (a b : G₀) (n : ℕ) :
(a / b) ^ n = a ^ n / b ^ n :=
by simp only [div_eq_mul_inv, mul_pow, inv_pow₀]
@[simp] theorem div_zpow₀ (a : G₀) {b : G₀} (n : ℤ) :
(a / b) ^ n = a ^ n / b ^ n :=
by simp only [div_eq_mul_inv, mul_zpow₀, inv_zpow₀]
lemma div_sq_cancel {a : G₀} (ha : a ≠ 0) (b : G₀) : a ^ 2 * b / a = a * b :=
by rw [sq, mul_assoc, mul_div_cancel_left _ ha]
end
/-- If a monoid homomorphism `f` between two `group_with_zero`s maps `0` to `0`, then it maps `x^n`,
`n : ℤ`, to `(f x)^n`. -/
lemma monoid_with_zero_hom.map_zpow {G₀ G₀' : Type*} [group_with_zero G₀] [group_with_zero G₀']
(f : monoid_with_zero_hom G₀ G₀') (x : G₀) :
∀ n : ℤ, f (x ^ n) = f x ^ n
| (n : ℕ) := by { rw [zpow_coe_nat, zpow_coe_nat], exact f.to_monoid_hom.map_pow x n }
| -[1+n] := begin
rw [zpow_neg_succ_of_nat, zpow_neg_succ_of_nat],
exact ((f.map_inv _).trans $ congr_arg _ $ f.to_monoid_hom.map_pow x _)
end
-- I haven't been able to find a better home for this:
-- it belongs with other lemmas on `linear_ordered_field`, but
-- we need to wait until `zpow` has been defined in this file.
section
variables {R : Type*} [linear_ordered_field R] {a : R}
lemma pow_minus_two_nonneg : 0 ≤ a^(-2 : ℤ) :=
begin
simp only [inv_nonneg, zpow_neg₀],
change 0 ≤ a ^ ((2 : ℕ) : ℤ),
rw zpow_coe_nat,
apply sq_nonneg,
end
end
|
f78e49780da9e4e1a640e00ec94861d343cf40a6 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/topology/algebra/nonarchimedean/adic_topology.lean | 946715c55fb3191f67912bef91dfe394c8dbd40b | [
"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 | 9,158 | lean | /-
Copyright (c) 2021 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot
-/
import ring_theory.ideal.operations
import topology.algebra.nonarchimedean.bases
import topology.algebra.uniform_ring
/-!
# Adic topology
Given a commutative ring `R` and an ideal `I` in `R`, this file constructs the unique
topology on `R` which is compatible with the ring structure and such that a set is a neighborhood
of zero if and only if it contains a power of `I`. This topology is non-archimedean: every
neighborhood of zero contains an open subgroup, namely a power of `I`.
It also studies the predicate `is_adic` which states that a given topological ring structure is
adic, proving a characterization and showing that raising an ideal to a positive power does not
change the associated topology.
Finally, it defines `with_ideal`, a class registering an ideal in a ring and providing the
corresponding adic topology to the type class inference system.
## Main definitions and results
* `ideal.adic_basis`: the basis of submodules given by powers of an ideal.
* `ideal.adic_topology`: the adic topology associated to an ideal. It has the above basis
for neighborhoods of zero.
* `ideal.nonarchimedean`: the adic topology is non-archimedean
* `is_ideal_adic_iff`: A topological ring is `J`-adic if and only if it admits the powers of `J` as
a basis of open neighborhoods of zero.
* `with_ideal`: a class registering an ideal in a ring.
## Implementation notes
The `I`-adic topology on a ring `R` has a contrived definition using `I^n • ⊤` instead of `I`
to make sure it is definitionally equal to the `I`-topology on `R` seen as a `R`-module.
-/
variables {R : Type*} [comm_ring R]
open set topological_add_group submodule filter
open_locale topological_space pointwise
namespace ideal
lemma adic_basis (I : ideal R) : submodules_ring_basis (λ n : ℕ, (I^n • ⊤ : ideal R)) :=
{ inter := begin
suffices : ∀ i j : ℕ, ∃ k, I ^ k ≤ I ^ i ∧ I ^ k ≤ I ^ j, by simpa,
intros i j,
exact ⟨max i j, pow_le_pow (le_max_left i j), pow_le_pow (le_max_right i j)⟩
end,
left_mul := begin
suffices : ∀ (a : R) (i : ℕ), ∃ j : ℕ, a • I ^ j ≤ I ^ i, by simpa,
intros r n,
use n,
rintro a ⟨x, hx, rfl⟩,
exact (I ^ n).smul_mem r hx
end,
mul := begin
suffices : ∀ (i : ℕ), ∃ (j : ℕ), ↑(I ^ j) * ↑(I ^ j) ⊆ ↑(I ^ i), by simpa,
intro n,
use n,
rintro a ⟨x, b, hx, hb, rfl⟩,
exact (I^n).smul_mem x hb
end }
/-- The adic ring filter basis associated to an ideal `I` is made of powers of `I`. -/
def ring_filter_basis (I : ideal R) := I.adic_basis.to_ring_subgroups_basis.to_ring_filter_basis
/-- The adic topology associated to an ideal `I`. This topology admits powers of `I` as a basis of
neighborhoods of zero. It is compatible with the ring structure and is non-archimedean. -/
def adic_topology (I : ideal R) : topological_space R :=
(adic_basis I).topology
lemma nonarchimedean (I : ideal R) : @nonarchimedean_ring R _ I.adic_topology :=
I.adic_basis.to_ring_subgroups_basis.nonarchimedean
/-- For the `I`-adic topology, the neighborhoods of zero has basis given by the powers of `I`. -/
lemma has_basis_nhds_zero_adic (I : ideal R) :
has_basis (@nhds R I.adic_topology (0 : R)) (λ n : ℕ, true) (λ n, ((I^n : ideal R) : set R)) :=
⟨begin
intros U,
rw I.ring_filter_basis.to_add_group_filter_basis.nhds_zero_has_basis.mem_iff,
split,
{ rintros ⟨-, ⟨i, rfl⟩, h⟩,
replace h : ↑(I ^ i) ⊆ U := by simpa using h,
use [i, trivial, h] },
{ rintros ⟨i, -, h⟩,
exact ⟨(I^i : ideal R), ⟨i, by simp⟩, h⟩ }
end⟩
lemma has_basis_nhds_adic (I : ideal R) (x : R) :
has_basis (@nhds R I.adic_topology x) (λ n : ℕ, true) (λ n, (λ y, x + y) '' (I^n : ideal R)) :=
begin
letI := I.adic_topology,
have := I.has_basis_nhds_zero_adic.map (λ y, x + y),
rwa map_add_left_nhds_zero x at this
end
variables (I : ideal R) (M : Type*) [add_comm_group M] [module R M]
lemma adic_module_basis :
I.ring_filter_basis.submodules_basis (λ n : ℕ, (I^n) • (⊤ : submodule R M)) :=
{ inter := λ i j, ⟨max i j, le_inf_iff.mpr ⟨smul_mono_left $ pow_le_pow (le_max_left i j),
smul_mono_left $ pow_le_pow (le_max_right i j)⟩⟩,
smul := λ m i, ⟨(I^i • ⊤ : ideal R), ⟨i, rfl⟩,
λ a a_in, by { replace a_in : a ∈ I^i := by simpa [(I^i).mul_top] using a_in,
exact smul_mem_smul a_in mem_top }⟩ }
/-- The topology on a `R`-module `M` associated to an ideal `M`. Submodules $I^n M$,
written `I^n • ⊤` form a basis of neighborhoods of zero. -/
def adic_module_topology : topological_space M :=
@module_filter_basis.topology R M _ I.adic_basis.topology _ _
(I.ring_filter_basis.module_filter_basis (I.adic_module_basis M))
/-- The elements of the basis of neighborhoods of zero for the `I`-adic topology
on a `R`-module `M`, seen as open additive subgroups of `M`. -/
def open_add_subgroup (n : ℕ) : @open_add_subgroup R _ I.adic_topology :=
{ is_open' := begin
letI := I.adic_topology,
convert (I.adic_basis.to_ring_subgroups_basis.open_add_subgroup n).is_open,
simp
end,
..(I^n).to_add_subgroup}
end ideal
section is_adic
/-- Given a topology on a ring `R` and an ideal `J`, `is_adic J` means the topology is the
`J`-adic one. -/
def is_adic [H : topological_space R] (J : ideal R) : Prop :=
H = J.adic_topology
/-- A topological ring is `J`-adic if and only if it admits the powers of `J` as a basis of
open neighborhoods of zero. -/
lemma is_adic_iff [top : topological_space R] [topological_ring R] {J : ideal R} :
is_adic J ↔ (∀ n : ℕ, is_open ((J^n : ideal R) : set R)) ∧
(∀ s ∈ 𝓝 (0 : R), ∃ n : ℕ, ((J^n : ideal R) : set R) ⊆ s) :=
begin
split,
{ intro H,
change _ = _ at H,
rw H,
letI := J.adic_topology,
split,
{ intro n,
exact (J.open_add_subgroup n).is_open' },
{ intros s hs,
simpa using J.has_basis_nhds_zero_adic.mem_iff.mp hs } },
{ rintro ⟨H₁, H₂⟩,
apply topological_add_group.ext,
{ apply @topological_ring.to_topological_add_group },
{ apply (ring_subgroups_basis.to_ring_filter_basis _).to_add_group_filter_basis
.is_topological_add_group },
{ ext s,
letI := ideal.adic_basis J,
rw J.has_basis_nhds_zero_adic.mem_iff,
split; intro H,
{ rcases H₂ s H with ⟨n, h⟩,
use [n, trivial, h] },
{ rcases H with ⟨n, -, hn⟩,
rw mem_nhds_iff,
refine ⟨_, hn, H₁ n, (J^n).zero_mem⟩ } } }
end
variables [topological_space R] [topological_ring R]
lemma is_ideal_adic_pow {J : ideal R} (h : is_adic J) {n : ℕ} (hn : 0 < n) :
is_adic (J^n) :=
begin
rw is_adic_iff at h ⊢,
split,
{ intro m, rw ← pow_mul, apply h.left },
{ intros V hV,
cases h.right V hV with m hm,
use m,
refine set.subset.trans _ hm,
cases n, { exfalso, exact nat.not_succ_le_zero 0 hn },
rw [← pow_mul, nat.succ_mul],
apply ideal.pow_le_pow,
apply nat.le_add_left }
end
lemma is_bot_adic_iff {A : Type*} [comm_ring A] [topological_space A] [topological_ring A] :
is_adic (⊥ : ideal A) ↔ discrete_topology A :=
begin
rw is_adic_iff,
split,
{ rintro ⟨h, h'⟩,
rw discrete_topology_iff_open_singleton_zero,
simpa using h 1 },
{ introsI,
split,
{ simp, },
{ intros U U_nhds,
use 1,
simp [mem_of_mem_nhds U_nhds] } },
end
end is_adic
/-- The ring `R` is equipped with a preferred ideal. -/
class with_ideal (R : Type*) [comm_ring R] :=
(I : ideal R)
namespace with_ideal
variables (R) [with_ideal R]
@[priority 100] instance : topological_space R := I.adic_topology
@[priority 100] instance : nonarchimedean_ring R := ring_subgroups_basis.nonarchimedean _
@[priority 100] instance : uniform_space R :=
topological_add_group.to_uniform_space R
@[priority 100] instance : uniform_add_group R :=
topological_add_group_is_uniform
/-- The adic topology on a `R` module coming from the ideal `with_ideal.I`.
This cannot be an instance because `R` cannot be inferred from `M`. -/
def topological_space_module (M : Type*) [add_comm_group M] [module R M] :
topological_space M := (I : ideal R).adic_module_topology M
/-
The next examples are kept to make sure potential future refactors won't break the instance
chaining.
-/
example : nonarchimedean_ring R :=
by apply_instance
example : topological_ring (uniform_space.completion R) :=
by apply_instance
example (M : Type*) [add_comm_group M] [module R M] :
@topological_add_group M (with_ideal.topological_space_module R M) _:=
by apply_instance
example (M : Type*) [add_comm_group M] [module R M] :
@has_continuous_smul R M _ _ (with_ideal.topological_space_module R M) :=
by apply_instance
example (M : Type*) [add_comm_group M] [module R M] :
@nonarchimedean_add_group M _ (with_ideal.topological_space_module R M) :=
submodules_basis.nonarchimedean _
end with_ideal
|
61ef9897b32d02f098179320ebc3c1494a6b60c0 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/complex/exponential_auto.lean | e25869909d52d0d919cc620690da4f02c1484b6d | [] | 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 | 12,312 | 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
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.algebra.geom_sum
import Mathlib.data.nat.choose.sum
import Mathlib.data.complex.basic
import Mathlib.PostPort
universes u_1 u_2 u_3
namespace Mathlib
/-!
# Exponential, trigonometric and hyperbolic trigonometric functions
This file contains the definitions of the real and complex exponential, sine, cosine, tangent,
hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
-/
theorem forall_ge_le_of_forall_le_succ {α : Type u_1} [preorder α] (f : ℕ → α) {m : ℕ}
(h : ∀ (n : ℕ), n ≥ m → f (Nat.succ n) ≤ f n) {l : ℕ} (k : ℕ) (H : k ≥ m) : k ≤ l → f l ≤ f k :=
sorry
theorem is_cau_of_decreasing_bounded {α : Type u_1} [linear_ordered_field α] [archimedean α]
(f : ℕ → α) {a : α} {m : ℕ} (ham : ∀ (n : ℕ), n ≥ m → abs (f n) ≤ a)
(hnm : ∀ (n : ℕ), n ≥ m → f (Nat.succ n) ≤ f n) : is_cau_seq abs f :=
sorry
theorem is_cau_of_mono_bounded {α : Type u_1} [linear_ordered_field α] [archimedean α] (f : ℕ → α)
{a : α} {m : ℕ} (ham : ∀ (n : ℕ), n ≥ m → abs (f n) ≤ a)
(hnm : ∀ (n : ℕ), n ≥ m → f n ≤ f (Nat.succ n)) : is_cau_seq abs f :=
sorry
theorem is_cau_series_of_abv_le_cau {α : Type u_1} {β : Type u_2} [ring β] [linear_ordered_field α]
{abv : β → α} [is_absolute_value abv] {f : ℕ → β} {g : ℕ → α} (n : ℕ) :
(∀ (m : ℕ), n ≤ m → abv (f m) ≤ g m) →
(is_cau_seq abs fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => g i) →
is_cau_seq abv fun (n : ℕ) => finset.sum (finset.range n) fun (i : ℕ) => f i :=
sorry
theorem is_cau_series_of_abv_cau {α : Type u_1} {β : Type u_2} [ring β] [linear_ordered_field α]
{abv : β → α} [is_absolute_value abv] {f : ℕ → β} :
(is_cau_seq abs fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => abv (f n)) →
is_cau_seq abv fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => f n :=
is_cau_series_of_abv_le_cau 0 fun (n : ℕ) (h : 0 ≤ n) => le_refl (abv (f n))
theorem is_cau_geo_series {α : Type u_1} [linear_ordered_field α] [archimedean α] {β : Type u_2}
[field β] {abv : β → α} [is_absolute_value abv] (x : β) (hx1 : abv x < 1) :
is_cau_seq abv fun (n : ℕ) => finset.sum (finset.range n) fun (m : ℕ) => x ^ m :=
sorry
theorem is_cau_geo_series_const {α : Type u_1} [linear_ordered_field α] [archimedean α] (a : α)
{x : α} (hx1 : abs x < 1) :
is_cau_seq abs fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => a * x ^ n :=
sorry
theorem series_ratio_test {α : Type u_1} {β : Type u_2} [ring β] [linear_ordered_field α]
[archimedean α] {abv : β → α} [is_absolute_value abv] {f : ℕ → β} (n : ℕ) (r : α) (hr0 : 0 ≤ r)
(hr1 : r < 1) (h : ∀ (m : ℕ), n ≤ m → abv (f (Nat.succ m)) ≤ r * abv (f m)) :
is_cau_seq abv fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => f n :=
sorry
theorem sum_range_diag_flip {α : Type u_1} [add_comm_monoid α] (n : ℕ) (f : ℕ → ℕ → α) :
(finset.sum (finset.range n)
fun (m : ℕ) => finset.sum (finset.range (m + 1)) fun (k : ℕ) => f k (m - k)) =
finset.sum (finset.range n)
fun (m : ℕ) => finset.sum (finset.range (n - m)) fun (k : ℕ) => f m k :=
sorry
theorem sum_range_sub_sum_range {α : Type u_1} [add_comm_group α] {f : ℕ → α} {n : ℕ} {m : ℕ}
(hnm : n ≤ m) :
((finset.sum (finset.range m) fun (k : ℕ) => f k) -
finset.sum (finset.range n) fun (k : ℕ) => f k) =
finset.sum (finset.filter (fun (k : ℕ) => n ≤ k) (finset.range m)) fun (k : ℕ) => f k :=
sorry
theorem abv_sum_le_sum_abv {α : Type u_1} {β : Type u_2} [ring β] [linear_ordered_field α]
{abv : β → α} [is_absolute_value abv] {γ : Type u_3} (f : γ → β) (s : finset γ) :
abv (finset.sum s fun (k : γ) => f k) ≤ finset.sum s fun (k : γ) => abv (f k) :=
sorry
theorem cauchy_product {α : Type u_1} {β : Type u_2} [ring β] [linear_ordered_field α] {abv : β → α}
[is_absolute_value abv] {a : ℕ → β} {b : ℕ → β}
(ha : is_cau_seq abs fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => abv (a n))
(hb : is_cau_seq abv fun (m : ℕ) => finset.sum (finset.range m) fun (n : ℕ) => b n) (ε : α)
(ε0 : 0 < ε) :
∃ (i : ℕ),
∀ (j : ℕ),
j ≥ i →
abv
(((finset.sum (finset.range j) fun (k : ℕ) => a k) *
finset.sum (finset.range j) fun (n : ℕ) => b n) -
finset.sum (finset.range j)
fun (n : ℕ) =>
finset.sum (finset.range (n + 1)) fun (m : ℕ) => a m * b (n - m)) <
ε :=
sorry
namespace complex
theorem is_cau_abs_exp (z : ℂ) :
is_cau_seq abs
fun (n : ℕ) =>
finset.sum (finset.range n) fun (m : ℕ) => abs (z ^ m / ↑(nat.factorial m)) :=
sorry
theorem is_cau_exp (z : ℂ) :
is_cau_seq abs
fun (n : ℕ) => finset.sum (finset.range n) fun (m : ℕ) => z ^ m / ↑(nat.factorial m) :=
is_cau_series_of_abv_cau (is_cau_abs_exp z)
/-- The Cauchy sequence consisting of partial sums of the Taylor series of
the complex exponential function -/
def exp' (z : ℂ) : cau_seq ℂ abs :=
{ val := fun (n : ℕ) => finset.sum (finset.range n) fun (m : ℕ) => z ^ m / ↑(nat.factorial m),
property := is_cau_exp z }
/-- The complex exponential function, defined via its Taylor series -/
def exp (z : ℂ) : ℂ := cau_seq.lim (exp' z)
/-- The complex sine function, defined via `exp` -/
def sin (z : ℂ) : ℂ := (exp (-z * I) - exp (z * I)) * I / bit0 1
/-- The complex cosine function, defined via `exp` -/
def cos (z : ℂ) : ℂ := (exp (z * I) + exp (-z * I)) / bit0 1
/-- The complex tangent function, defined as `sin z / cos z` -/
def tan (z : ℂ) : ℂ := sin z / cos z
/-- The complex hyperbolic sine function, defined via `exp` -/
def sinh (z : ℂ) : ℂ := (exp z - exp (-z)) / bit0 1
/-- The complex hyperbolic cosine function, defined via `exp` -/
def cosh (z : ℂ) : ℂ := (exp z + exp (-z)) / bit0 1
/-- The complex hyperbolic tangent function, defined as `sinh z / cosh z` -/
def tanh (z : ℂ) : ℂ := sinh z / cosh z
end complex
namespace real
/-- The real exponential function, defined as the real part of the complex exponential -/
def exp (x : ℝ) : ℝ := complex.re (complex.exp ↑x)
/-- The real sine function, defined as the real part of the complex sine -/
def sin (x : ℝ) : ℝ := complex.re (complex.sin ↑x)
/-- The real cosine function, defined as the real part of the complex cosine -/
def cos (x : ℝ) : ℝ := complex.re (complex.cos ↑x)
/-- The real tangent function, defined as the real part of the complex tangent -/
def tan (x : ℝ) : ℝ := complex.re (complex.tan ↑x)
/-- The real hypebolic sine function, defined as the real part of the complex hyperbolic sine -/
def sinh (x : ℝ) : ℝ := complex.re (complex.sinh ↑x)
/-- The real hypebolic cosine function, defined as the real part of the complex hyperbolic cosine -/
def cosh (x : ℝ) : ℝ := complex.re (complex.cosh ↑x)
/-- The real hypebolic tangent function, defined as the real part of
the complex hyperbolic tangent -/
def tanh (x : ℝ) : ℝ := complex.re (complex.tanh ↑x)
end real
namespace complex
@[simp] theorem exp_zero : exp 0 = 1 := sorry
theorem exp_add (x : ℂ) (y : ℂ) : exp (x + y) = exp x * exp y := sorry
theorem exp_list_sum (l : List ℂ) : exp (list.sum l) = list.prod (list.map exp l) :=
monoid_hom.map_list_prod (monoid_hom.mk exp exp_zero exp_add) l
theorem exp_multiset_sum (s : multiset ℂ) :
exp (multiset.sum s) = multiset.prod (multiset.map exp s) :=
monoid_hom.map_multiset_prod (monoid_hom.mk exp exp_zero exp_add) s
theorem exp_sum {α : Type u_1} (s : finset α) (f : α → ℂ) :
exp (finset.sum s fun (x : α) => f x) = finset.prod s fun (x : α) => exp (f x) :=
monoid_hom.map_prod (monoid_hom.mk exp exp_zero exp_add) f s
theorem exp_nat_mul (x : ℂ) (n : ℕ) : exp (↑n * x) = exp x ^ n := sorry
theorem exp_ne_zero (x : ℂ) : exp x ≠ 0 := sorry
theorem exp_neg (x : ℂ) : exp (-x) = (exp x⁻¹) := sorry
theorem exp_sub (x : ℂ) (y : ℂ) : exp (x - y) = exp x / exp y := sorry
@[simp] theorem exp_conj (x : ℂ) : exp (coe_fn conj x) = coe_fn conj (exp x) := sorry
@[simp] theorem of_real_exp_of_real_re (x : ℝ) : ↑(re (exp ↑x)) = exp ↑x :=
iff.mp eq_conj_iff_re
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn conj (exp ↑x) = exp ↑x)) (Eq.symm (exp_conj ↑x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (exp (coe_fn conj ↑x) = exp ↑x)) (conj_of_real x)))
(Eq.refl (exp ↑x))))
@[simp] theorem of_real_exp (x : ℝ) : ↑(real.exp x) = exp ↑x := of_real_exp_of_real_re x
@[simp] theorem exp_of_real_im (x : ℝ) : im (exp ↑x) = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (im (exp ↑x) = 0)) (Eq.symm (of_real_exp_of_real_re x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (im ↑(re (exp ↑x)) = 0)) (of_real_im (re (exp ↑x)))))
(Eq.refl 0))
theorem exp_of_real_re (x : ℝ) : re (exp ↑x) = real.exp x := rfl
theorem two_sinh (x : ℂ) : bit0 1 * sinh x = exp x - exp (-x) :=
mul_div_cancel' (exp x - exp (-x)) two_ne_zero'
theorem two_cosh (x : ℂ) : bit0 1 * cosh x = exp x + exp (-x) :=
mul_div_cancel' (exp x + exp (-x)) two_ne_zero'
@[simp] theorem sinh_zero : sinh 0 = 0 := sorry
@[simp] theorem sinh_neg (x : ℂ) : sinh (-x) = -sinh x := sorry
theorem sinh_add (x : ℂ) (y : ℂ) : sinh (x + y) = sinh x * cosh y + cosh x * sinh y := sorry
@[simp] theorem cosh_zero : cosh 0 = 1 := sorry
@[simp] theorem cosh_neg (x : ℂ) : cosh (-x) = cosh x := sorry
theorem cosh_add (x : ℂ) (y : ℂ) : cosh (x + y) = cosh x * cosh y + sinh x * sinh y := sorry
theorem sinh_sub (x : ℂ) (y : ℂ) : sinh (x - y) = sinh x * cosh y - cosh x * sinh y := sorry
theorem cosh_sub (x : ℂ) (y : ℂ) : cosh (x - y) = cosh x * cosh y - sinh x * sinh y := sorry
theorem sinh_conj (x : ℂ) : sinh (coe_fn conj x) = coe_fn conj (sinh x) := sorry
@[simp] theorem of_real_sinh_of_real_re (x : ℝ) : ↑(re (sinh ↑x)) = sinh ↑x :=
iff.mp eq_conj_iff_re
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn conj (sinh ↑x) = sinh ↑x)) (Eq.symm (sinh_conj ↑x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (sinh (coe_fn conj ↑x) = sinh ↑x)) (conj_of_real x)))
(Eq.refl (sinh ↑x))))
@[simp] theorem of_real_sinh (x : ℝ) : ↑(real.sinh x) = sinh ↑x := of_real_sinh_of_real_re x
@[simp] theorem sinh_of_real_im (x : ℝ) : im (sinh ↑x) = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (im (sinh ↑x) = 0)) (Eq.symm (of_real_sinh_of_real_re x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (im ↑(re (sinh ↑x)) = 0)) (of_real_im (re (sinh ↑x)))))
(Eq.refl 0))
theorem sinh_of_real_re (x : ℝ) : re (sinh ↑x) = real.sinh x := rfl
theorem cosh_conj (x : ℂ) : cosh (coe_fn conj x) = coe_fn conj (cosh x) := sorry
@[simp] theorem of_real_cosh_of_real_re (x : ℝ) : ↑(re (cosh ↑x)) = cosh ↑x :=
iff.mp eq_conj_iff_re
(eq.mpr (id (Eq._oldrec (Eq.refl (coe_fn conj (cosh ↑x) = cosh ↑x)) (Eq.symm (cosh_conj ↑x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (cosh (coe_fn conj ↑x) = cosh ↑x)) (conj_of_real x)))
(Eq.refl (cosh ↑x))))
@[simp] theorem of_real_cosh (x : ℝ) : ↑(real.cosh x) = cosh ↑x := of_real_cosh_of_real_re x
@[simp] theorem cosh_of_real_im (x : ℝ) : im (cosh ↑x) = 0 :=
eq.mpr (id (Eq._oldrec (Eq.refl (im (cosh ↑x) = 0)) (Eq.symm (of_real_cosh_of_real_re x))))
(eq.mpr (id (Eq._oldrec (Eq.refl (im ↑(re (cosh ↑x)) = 0)) (of_real_im (re (cosh ↑x)))))
(Eq.refl 0))
theorem cosh_of_real_re (x : ℝ) : re (cosh ↑x) = real.cosh x := rfl
theorem tanh_eq_sinh_div_cosh (x : ℂ) : tanh x = sinh x / cosh x := rfl
@[simp] theorem tanh_zero : tanh 0 = 0 := sorry
@[simp] theorem tanh_neg (x : ℂ) : tanh (-x) = -tanh x := |
a06d8aeae3ea05d04a81ffd232c77d66e6f21da9 | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/algebra/order/archimedean.lean | 5c6f61f764bfd79e7ea042e83a04ee74739946ef | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,727 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import algebra.field_power
import data.rat
import data.int.least_greatest
/-!
# Archimedean groups and fields.
This file defines the archimedean property for ordered groups and proves several results connected
to this notion. Being archimedean means that for all elements `x` and `y>0` there exists a natural
number `n` such that `x ≤ n • y`.
## Main definitions
* `archimedean` is a typeclass for an ordered additive commutative monoid to have the archimedean
property.
* `archimedean.floor_ring` defines a floor function on an archimedean linearly ordered ring making
it into a `floor_ring`.
* `round` defines a function rounding to the nearest integer for a linearly ordered field which is
also a floor ring.
## Main statements
* `ℕ`, `ℤ`, and `ℚ` are archimedean.
-/
open int
variables {α : Type*}
/-- An ordered additive commutative monoid is called `archimedean` if for any two elements `x`, `y`
such that `0 < y` there exists a natural number `n` such that `x ≤ n • y`. -/
class archimedean (α) [ordered_add_comm_monoid α] : Prop :=
(arch : ∀ (x : α) {y}, 0 < y → ∃ n : ℕ, x ≤ n • y)
instance order_dual.archimedean [ordered_add_comm_group α] [archimedean α] :
archimedean (order_dual α) :=
⟨λ x y hy, let ⟨n, hn⟩ := archimedean.arch (-x : α) (neg_pos.2 hy) in
⟨n, by rwa [neg_nsmul, neg_le_neg_iff] at hn⟩⟩
section linear_ordered_add_comm_group
variables [linear_ordered_add_comm_group α] [archimedean α]
/-- An archimedean decidable linearly ordered `add_comm_group` has a version of the floor: for
`a > 0`, any `g` in the group lies between some two consecutive multiples of `a`. -/
lemma exists_int_smul_near_of_pos {a : α} (ha : 0 < a) (g : α) :
∃ (k : ℤ), k • a ≤ g ∧ g < (k + 1) • a :=
begin
let s : set ℤ := {n : ℤ | n • a ≤ g},
obtain ⟨k, hk : -g ≤ k • a⟩ := archimedean.arch (-g) ha,
have h_ne : s.nonempty := ⟨-k, by simpa using neg_le_neg hk⟩,
obtain ⟨k, hk⟩ := archimedean.arch g ha,
have h_bdd : ∀ n ∈ s, n ≤ (k : ℤ),
{ assume n hn,
apply (zsmul_le_zsmul_iff ha).mp,
rw ← coe_nat_zsmul at hk,
exact le_trans hn hk },
obtain ⟨m, hm, hm'⟩ := int.exists_greatest_of_bdd ⟨k, h_bdd⟩ h_ne,
refine ⟨m, hm, _⟩,
by_contra H,
linarith [hm' _ $ not_lt.mp H]
end
lemma exists_int_smul_near_of_pos' {a : α} (ha : 0 < a) (g : α) :
∃ (k : ℤ), 0 ≤ g - k • a ∧ g - k • a < a :=
begin
obtain ⟨k, h1, h2⟩ := exists_int_smul_near_of_pos ha g,
refine ⟨k, sub_nonneg.mpr h1, _⟩,
simpa only [sub_lt_iff_lt_add', add_zsmul, one_zsmul] using h2
end
lemma exists_add_int_smul_mem_Ico {a : α} (ha : 0 < a) (b c : α) :
∃ m : ℤ, b + m • a ∈ set.Ico c (c + a) :=
begin
rcases exists_int_smul_near_of_pos' ha (b - c) with ⟨m, hle, hlt⟩,
refine ⟨-m, _, _⟩,
{ rwa [neg_zsmul, ← sub_eq_add_neg, le_sub, ← sub_nonneg] },
{ rwa [sub_right_comm, sub_lt_iff_lt_add', sub_eq_add_neg, ← neg_zsmul] at hlt }
end
lemma exists_add_int_smul_mem_Ioc {a : α} (ha : 0 < a) (b c : α) :
∃ m : ℤ, b + m • a ∈ set.Ioc c (c + a) :=
begin
rcases exists_int_smul_near_of_pos ha (c - b) with ⟨m, hle, hlt⟩,
refine ⟨m + 1, sub_lt_iff_lt_add'.1 hlt, _⟩,
rwa [add_zsmul, one_zsmul, ← add_assoc, add_le_add_iff_right, ← le_sub_iff_add_le']
end
end linear_ordered_add_comm_group
theorem exists_nat_gt [ordered_semiring α] [nontrivial α] [archimedean α]
(x : α) : ∃ n : ℕ, x < n :=
let ⟨n, h⟩ := archimedean.arch x zero_lt_one in
⟨n+1, lt_of_le_of_lt (by rwa ← nsmul_one)
(nat.cast_lt.2 (nat.lt_succ_self _))⟩
theorem exists_nat_ge [ordered_semiring α] [archimedean α] (x : α) :
∃ n : ℕ, x ≤ n :=
begin
nontriviality α,
exact (exists_nat_gt x).imp (λ n, le_of_lt)
end
lemma add_one_pow_unbounded_of_pos [ordered_semiring α] [nontrivial α] [archimedean α]
(x : α) {y : α} (hy : 0 < y) :
∃ n : ℕ, x < (y + 1) ^ n :=
have 0 ≤ 1 + y, from add_nonneg zero_le_one hy.le,
let ⟨n, h⟩ := archimedean.arch x hy in
⟨n, calc x ≤ n • y : h
... = n * y : nsmul_eq_mul _ _
... < 1 + n * y : lt_one_add _
... ≤ (1 + y) ^ n : one_add_mul_le_pow' (mul_nonneg hy.le hy.le) (mul_nonneg this this)
(add_nonneg zero_le_two hy.le) _
... = (y + 1) ^ n : by rw [add_comm]⟩
section linear_ordered_ring
variables [linear_ordered_ring α] [archimedean α]
lemma pow_unbounded_of_one_lt (x : α) {y : α} (hy1 : 1 < y) :
∃ n : ℕ, x < y ^ n :=
sub_add_cancel y 1 ▸ add_one_pow_unbounded_of_pos _ (sub_pos.2 hy1)
/-- Every x greater than or equal to 1 is between two successive
natural-number powers of every y greater than one. -/
lemma exists_nat_pow_near {x : α} {y : α} (hx : 1 ≤ x) (hy : 1 < y) :
∃ n : ℕ, y ^ n ≤ x ∧ x < y ^ (n + 1) :=
have h : ∃ n : ℕ, x < y ^ n, from pow_unbounded_of_one_lt _ hy,
by classical; exact let n := nat.find h in
have hn : x < y ^ n, from nat.find_spec h,
have hnp : 0 < n, from pos_iff_ne_zero.2 (λ hn0,
by rw [hn0, pow_zero] at hn; exact (not_le_of_gt hn hx)),
have hnsp : nat.pred n + 1 = n, from nat.succ_pred_eq_of_pos hnp,
have hltn : nat.pred n < n, from nat.pred_lt (ne_of_gt hnp),
⟨nat.pred n, le_of_not_lt (nat.find_min h hltn), by rwa hnsp⟩
theorem exists_int_gt (x : α) : ∃ n : ℤ, x < n :=
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa ← coe_coe⟩
theorem exists_int_lt (x : α) : ∃ n : ℤ, (n : α) < x :=
let ⟨n, h⟩ := exists_int_gt (-x) in ⟨-n, by rw int.cast_neg; exact neg_lt.1 h⟩
theorem exists_floor (x : α) :
∃ (fl : ℤ), ∀ (z : ℤ), z ≤ fl ↔ (z : α) ≤ x :=
begin
haveI := classical.prop_decidable,
have : ∃ (ub : ℤ), (ub:α) ≤ x ∧ ∀ (z : ℤ), (z:α) ≤ x → z ≤ ub :=
int.exists_greatest_of_bdd
(let ⟨n, hn⟩ := exists_int_gt x in ⟨n, λ z h',
int.cast_le.1 $ le_trans h' $ le_of_lt hn⟩)
(let ⟨n, hn⟩ := exists_int_lt x in ⟨n, le_of_lt hn⟩),
refine this.imp (λ fl h z, _),
cases h with h₁ h₂,
exact ⟨λ h, le_trans (int.cast_le.2 h) h₁, h₂ z⟩,
end
end linear_ordered_ring
section linear_ordered_field
variables [linear_ordered_field α]
/-- Every positive `x` is between two successive integer powers of
another `y` greater than one. This is the same as `exists_mem_Ioc_zpow`,
but with ≤ and < the other way around. -/
lemma exists_mem_Ico_zpow [archimedean α]
{x : α} {y : α} (hx : 0 < x) (hy : 1 < y) :
∃ n : ℤ, x ∈ set.Ico (y ^ n) (y ^ (n + 1)) :=
by classical; exact
let ⟨N, hN⟩ := pow_unbounded_of_one_lt x⁻¹ hy in
have he: ∃ m : ℤ, y ^ m ≤ x, from
⟨-N, le_of_lt (by { rw [zpow_neg₀ y (↑N), zpow_coe_nat],
exact (inv_lt hx (lt_trans (inv_pos.2 hx) hN)).1 hN })⟩,
let ⟨M, hM⟩ := pow_unbounded_of_one_lt x hy in
have hb: ∃ b : ℤ, ∀ m, y ^ m ≤ x → m ≤ b, from
⟨M, λ m hm, le_of_not_lt (λ hlt, not_lt_of_ge
(zpow_le_of_le hy.le hlt.le)
(lt_of_le_of_lt hm (by rwa ← zpow_coe_nat at hM)))⟩,
let ⟨n, hn₁, hn₂⟩ := int.exists_greatest_of_bdd hb he in
⟨n, hn₁, lt_of_not_ge (λ hge, not_le_of_gt (int.lt_succ _) (hn₂ _ hge))⟩
/-- Every positive `x` is between two successive integer powers of
another `y` greater than one. This is the same as `exists_mem_Ico_zpow`,
but with ≤ and < the other way around. -/
lemma exists_mem_Ioc_zpow [archimedean α]
{x : α} {y : α} (hx : 0 < x) (hy : 1 < y) :
∃ n : ℤ, x ∈ set.Ioc (y ^ n) (y ^ (n + 1)) :=
let ⟨m, hle, hlt⟩ := exists_mem_Ico_zpow (inv_pos.2 hx) hy in
have hyp : 0 < y, from lt_trans zero_lt_one hy,
⟨-(m+1),
by rwa [zpow_neg₀, inv_lt (zpow_pos_of_pos hyp _) hx],
by rwa [neg_add, neg_add_cancel_right, zpow_neg₀,
le_inv hx (zpow_pos_of_pos hyp _)]⟩
/-- For any `y < 1` and any positive `x`, there exists `n : ℕ` with `y ^ n < x`. -/
lemma exists_pow_lt_of_lt_one [archimedean α] {x y : α} (hx : 0 < x) (hy : y < 1) :
∃ n : ℕ, y ^ n < x :=
begin
by_cases y_pos : y ≤ 0,
{ use 1, simp only [pow_one], linarith, },
rw [not_le] at y_pos,
rcases pow_unbounded_of_one_lt (x⁻¹) (one_lt_inv y_pos hy) with ⟨q, hq⟩,
exact ⟨q, by rwa [inv_pow₀, inv_lt_inv hx (pow_pos y_pos _)] at hq⟩
end
/-- Given `x` and `y` between `0` and `1`, `x` is between two successive powers of `y`.
This is the same as `exists_nat_pow_near`, but for elements between `0` and `1` -/
lemma exists_nat_pow_near_of_lt_one [archimedean α]
{x : α} {y : α} (xpos : 0 < x) (hx : x ≤ 1) (ypos : 0 < y) (hy : y < 1) :
∃ n : ℕ, y ^ (n + 1) < x ∧ x ≤ y ^ n :=
begin
rcases exists_nat_pow_near (one_le_inv_iff.2 ⟨xpos, hx⟩) (one_lt_inv_iff.2 ⟨ypos, hy⟩)
with ⟨n, hn, h'n⟩,
refine ⟨n, _, _⟩,
{ rwa [inv_pow₀, inv_lt_inv xpos (pow_pos ypos _)] at h'n },
{ rwa [inv_pow₀, inv_le_inv (pow_pos ypos _) xpos] at hn }
end
variables [floor_ring α]
lemma sub_floor_div_mul_nonneg (x : α) {y : α} (hy : 0 < y) :
0 ≤ x - ⌊x / y⌋ * y :=
begin
conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm},
rw ← sub_mul,
exact mul_nonneg (sub_nonneg.2 (floor_le _)) (le_of_lt hy)
end
lemma sub_floor_div_mul_lt (x : α) {y : α} (hy : 0 < y) :
x - ⌊x / y⌋ * y < y :=
sub_lt_iff_lt_add.2 begin
conv in y {rw ← one_mul y},
conv in x {rw ← div_mul_cancel x (ne_of_lt hy).symm},
rw ← add_mul,
exact (mul_lt_mul_right hy).2 (by rw add_comm; exact lt_floor_add_one _),
end
end linear_ordered_field
instance : archimedean ℕ :=
⟨λ n m m0, ⟨n, by simpa only [mul_one, nat.nsmul_eq_mul] using nat.mul_le_mul_left n m0⟩⟩
instance : archimedean ℤ :=
⟨λ n m m0, ⟨n.to_nat, le_trans (int.le_to_nat _) $
by simpa only [nsmul_eq_mul, int.nat_cast_eq_coe_nat, zero_add, mul_one]
using mul_le_mul_of_nonneg_left (int.add_one_le_iff.2 m0) (int.coe_zero_le n.to_nat)⟩⟩
/-- A linear ordered archimedean ring is a floor ring. This is not an `instance` because in some
cases we have a computable `floor` function. -/
noncomputable def archimedean.floor_ring (α)
[linear_ordered_ring α] [archimedean α] : floor_ring α :=
floor_ring.of_floor α (λ a, classical.some (exists_floor a))
(λ z a, (classical.some_spec (exists_floor a) z).symm)
section linear_ordered_field
variables [linear_ordered_field α]
theorem archimedean_iff_nat_lt :
archimedean α ↔ ∀ x : α, ∃ n : ℕ, x < n :=
⟨@exists_nat_gt α _ _, λ H, ⟨λ x y y0,
(H (x / y)).imp $ λ n h, le_of_lt $
by rwa [div_lt_iff y0, ← nsmul_eq_mul] at h⟩⟩
theorem archimedean_iff_nat_le :
archimedean α ↔ ∀ x : α, ∃ n : ℕ, x ≤ n :=
archimedean_iff_nat_lt.trans
⟨λ H x, (H x).imp $ λ _, le_of_lt,
λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
lt_of_le_of_lt h (nat.cast_lt.2 (lt_add_one _))⟩⟩
theorem exists_rat_gt [archimedean α] (x : α) : ∃ q : ℚ, x < q :=
let ⟨n, h⟩ := exists_nat_gt x in ⟨n, by rwa rat.cast_coe_nat⟩
theorem archimedean_iff_rat_lt :
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x < q :=
⟨@exists_rat_gt α _,
λ H, archimedean_iff_nat_lt.2 $ λ x,
let ⟨q, h⟩ := H x in
⟨⌈q⌉₊, lt_of_lt_of_le h $
by simpa only [rat.cast_coe_nat] using (@rat.cast_le α _ _ _).2 (nat.le_ceil _)⟩⟩
theorem archimedean_iff_rat_le :
archimedean α ↔ ∀ x : α, ∃ q : ℚ, x ≤ q :=
archimedean_iff_rat_lt.trans
⟨λ H x, (H x).imp $ λ _, le_of_lt,
λ H x, let ⟨n, h⟩ := H x in ⟨n+1,
lt_of_le_of_lt h (rat.cast_lt.2 (lt_add_one _))⟩⟩
variable [archimedean α]
theorem exists_rat_lt (x : α) : ∃ q : ℚ, (q : α) < x :=
let ⟨n, h⟩ := exists_int_lt x in ⟨n, by rwa rat.cast_coe_int⟩
theorem exists_rat_btwn {x y : α} (h : x < y) : ∃ q : ℚ, x < q ∧ (q:α) < y :=
begin
cases exists_nat_gt (y - x)⁻¹ with n nh,
cases exists_floor (x * n) with z zh,
refine ⟨(z + 1 : ℤ) / n, _⟩,
have n0' := (inv_pos.2 (sub_pos.2 h)).trans nh,
have n0 := nat.cast_pos.1 n0',
rw [rat.cast_div_of_ne_zero, rat.cast_coe_nat, rat.cast_coe_int, div_lt_iff n0'],
refine ⟨(lt_div_iff n0').2 $
(lt_iff_lt_of_le_iff_le (zh _)).1 (lt_add_one _), _⟩,
rw [int.cast_add, int.cast_one],
refine lt_of_le_of_lt (add_le_add_right ((zh _).1 (le_refl _)) _) _,
rwa [← lt_sub_iff_add_lt', ← sub_mul,
← div_lt_iff' (sub_pos.2 h), one_div],
{ rw [rat.coe_int_denom, nat.cast_one], exact one_ne_zero },
{ intro H, rw [rat.coe_nat_num, ← coe_coe, nat.cast_eq_zero] at H, subst H, cases n0 },
{ rw [rat.coe_nat_denom, nat.cast_one], exact one_ne_zero }
end
theorem exists_nat_one_div_lt {ε : α} (hε : 0 < ε) : ∃ n : ℕ, 1 / (n + 1: α) < ε :=
begin
cases exists_nat_gt (1/ε) with n hn,
use n,
rw [div_lt_iff, ← div_lt_iff' hε],
{ apply hn.trans,
simp [zero_lt_one] },
{ exact n.cast_add_one_pos }
end
theorem exists_pos_rat_lt {x : α} (x0 : 0 < x) : ∃ q : ℚ, 0 < q ∧ (q : α) < x :=
by simpa only [rat.cast_pos] using exists_rat_btwn x0
end linear_ordered_field
section
variables [linear_ordered_field α] [floor_ring α]
/-- `round` rounds a number to the nearest integer. `round (1 / 2) = 1` -/
def round (x : α) : ℤ := ⌊x + 1 / 2⌋
@[simp] lemma round_zero : round (0 : α) = 0 := floor_eq_iff.2 (by norm_num)
@[simp] lemma round_one : round (1 : α) = 1 := floor_eq_iff.2 (by norm_num)
lemma abs_sub_round (x : α) : |x - round x| ≤ 1 / 2 :=
begin
rw [round, abs_sub_le_iff],
have := floor_le (x + 1 / 2),
have := lt_floor_add_one (x + 1 / 2),
split; linarith
end
@[simp, norm_cast] theorem rat.cast_floor (x : ℚ) : ⌊(x:α)⌋ = ⌊x⌋ :=
floor_eq_iff.2 (by exact_mod_cast floor_eq_iff.1 (eq.refl ⌊x⌋))
@[simp, norm_cast] theorem rat.cast_ceil (x : ℚ) : ⌈(x:α)⌉ = ⌈x⌉ :=
by rw [←neg_inj, ←floor_neg, ←floor_neg, ← rat.cast_neg, rat.cast_floor]
@[simp, norm_cast] theorem rat.cast_round (x : ℚ) : round (x:α) = round x :=
have ((x + 1 / 2 : ℚ) : α) = x + 1 / 2, by simp,
by rw [round, round, ← this, rat.cast_floor]
end
section
variables [linear_ordered_field α] [archimedean α]
theorem exists_rat_near (x : α) {ε : α} (ε0 : 0 < ε) :
∃ q : ℚ, |x - q| < ε :=
let ⟨q, h₁, h₂⟩ := exists_rat_btwn $
lt_trans ((sub_lt_self_iff x).2 ε0) ((lt_add_iff_pos_left x).2 ε0) in
⟨q, abs_sub_lt_iff.2 ⟨sub_lt.1 h₁, sub_lt_iff_lt_add.2 h₂⟩⟩
instance : archimedean ℚ :=
archimedean_iff_rat_le.2 $ λ q, ⟨q, by rw rat.cast_id⟩
end
|
01e9c2cb6de7c951f1800048c58970184aac7bc4 | 491068d2ad28831e7dade8d6dff871c3e49d9431 | /library/algebra/category/basic.lean | d2176572d346a650d8395de08212f0951086f1e6 | [
"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 | 2,042 | lean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
-/
open eq eq.ops
structure category [class] (ob : Type) : Type :=
(hom : ob → ob → Type)
(comp : Π⦃a b c : ob⦄, hom b c → hom a b → hom a c)
(ID : Π (a : ob), hom a a)
(assoc : Π ⦃a b c d : ob⦄ (h : hom c d) (g : hom b c) (f : hom a b),
comp h (comp g f) = comp (comp h g) f)
(id_left : Π ⦃a b : ob⦄ (f : hom a b), comp !ID f = f)
(id_right : Π ⦃a b : ob⦄ (f : hom a b), comp f !ID = f)
attribute category [multiple-instances]
namespace category
variables {ob : Type} [C : category ob]
variables {a b c d : ob}
include C
definition compose := @comp ob _
definition id [reducible] {a : ob} : hom a a := ID a
infixr `∘` := comp
infixl `⟶`:25 := hom -- input ⟶ using \--> (this is a different arrow than \-> (→))
variables {h : hom c d} {g : hom b c} {f : hom a b} {i : hom a a}
--the following is the only theorem for which "include C" is necessary if C is a variable (why?)
theorem id_compose (a : ob) : (ID a) ∘ id = id := !id_left
theorem left_id_unique (H : Π{b} {f : hom b a}, i ∘ f = f) : i = id :=
calc i = i ∘ id : id_right
... = id : H
theorem right_id_unique (H : Π{b} {f : hom a b}, f ∘ i = f) : i = id :=
calc i = id ∘ i : id_left
... = id : H
end category
inductive Category : Type := mk : Π (ob : Type), category ob → Category
namespace category
definition Mk {ob} (C) : Category := Category.mk ob C
definition MK (a b c d e f g) : Category := Category.mk a (category.mk b c d e f g)
definition objects [coercion] [reducible] (C : Category) : Type
:= Category.rec (fun c s, c) C
definition category_instance [instance] [coercion] [reducible] (C : Category) : category (objects C)
:= Category.rec (fun c s, s) C
end category
open category
theorem Category.equal (C : Category) : Category.mk C C = C :=
Category.rec (λ ob c, rfl) C
|
27eda0a14fc26d87faf72ccd3129f161237820a2 | 9cb9db9d79fad57d80ca53543dc07efb7c4f3838 | /src/pseudo_normed_group/Tinv.lean | 086f67092561d818e52cf806c5c4e97f8e59b44e | [] | no_license | mr-infty/lean-liquid | 3ff89d1f66244b434654c59bdbd6b77cb7de0109 | a8db559073d2101173775ccbd85729d3a4f1ed4d | refs/heads/master | 1,678,465,145,334 | 1,614,565,310,000 | 1,614,565,310,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 6,509 | lean | import for_mathlib.equalizers
import pseudo_normed_group.CLC
open_locale classical nnreal
noncomputable theory
local attribute [instance] type_pow
open NormedGroup opposite Profinite pseudo_normed_group category_theory breen_deligne
open profinitely_filtered_pseudo_normed_group category_theory.limits
universe variable u
variables (r : ℝ≥0) (V : NormedGroup) [normed_with_aut r V] [fact (0 < r)]
variables (r' : ℝ≥0) [fact (0 < r')] [fact (r' ≤ 1)] {M M₁ M₂ M₃ : Type u}
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r' M]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r' M₁]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r' M₂]
variables [profinitely_filtered_pseudo_normed_group_with_Tinv r' M₃]
variables (c c₁ c₂ c₃ c₄ : ℝ≥0) (l m n : ℕ)
variables (f : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r' M₁ M₂)
variables (g : profinitely_filtered_pseudo_normed_group_with_Tinv_hom r' M₂ M₃)
/-- The "functor" that sends `M` and `c` to `V-hat((filtration M c)^n)^{T⁻¹}`,
defined by taking `T⁻¹`-invariants
for two different actions by `T⁻¹`:
* The first comes from the action of `T⁻¹` on `M`.
* The second comes from the action of `T⁻¹` on `V`.
We take the equalizer of those two actions.
See the lines just above Definition 9.3 of [Analytic]. -/
def CLCFPTinv (r : ℝ≥0) (V : NormedGroup) (r' : ℝ≥0) (M : Type*) (c : ℝ≥0) (n : ℕ)
[normed_with_aut r V] [fact (0 < r)] [fact (0 < r')] [fact (r' ≤ 1)]
[profinitely_filtered_pseudo_normed_group_with_Tinv r' M] :
NormedGroup :=
equalizer (CLCFP.Tinv V r' c n) (CLCFP.T_inv r V r' c n ≫ (@CLCFP.res V r' M _ _ _ n _))
namespace CLCFPTinv
def map : CLCFPTinv r V r' M₂ c n ⟶ CLCFPTinv r V r' M₁ c n :=
equalizer.map (CLCFP.map _ _ _ _ f) (CLCFP.map _ _ _ _ f)
(CLCFP.map_comp_Tinv _ _ _ _ _).symm $
by rw [← category.assoc, CLCFP.map_comp_T_inv, category.assoc, category.assoc, CLCFP.map_comp_res]
variables (M)
@[simp] lemma map_id :
map r V r' c n (profinitely_filtered_pseudo_normed_group_with_Tinv_hom.id) =
𝟙 (CLCFPTinv r V r' M c n) :=
by { simp only [map, equalizer.map_id, CLCFP.map_id], refl }
variables {M}
lemma map_comp : map r V r' c n (g.comp f) = map r V r' c n g ≫ map r V r' c n f :=
by simp only [map, equalizer.map_comp_map, CLCFP.map_comp]
def res [fact (c₁ ≤ c₂)] : CLCFPTinv r V r' M c₂ n ⟶ CLCFPTinv r V r' M c₁ n :=
equalizer.map (CLCFP.res _ _ _ _ _) (CLCFP.res _ _ _ _ _)
(CLCFP.res_comp_Tinv _ _ _ _ _).symm $
begin
haveI : fact (r' * c₁ ≤ c₂) :=
le_trans (show fact (r' * c₁ ≤ c₁), by apply_instance) ‹c₁ ≤ c₂›,
rw [← category.assoc],
simp only [CLCFP.res_comp_T_inv, category.assoc],
rw [CLCFP.res_comp_res, CLCFP.res_comp_res],
end
@[simp] lemma res_refl : @res r V _ _ r' _ _ M _ c c n _ = 𝟙 _ :=
by { simp only [res, equalizer.map_id, CLCFP.res_refl], refl }
lemma res_comp_res [fact (c₁ ≤ c₂)] [fact (c₂ ≤ c₃)] [fact (c₁ ≤ c₃)] :
res r V r' c₂ c₃ n ≫ res r V r' c₁ c₂ n = @res r V _ _ r' _ _ M _ c₁ c₃ n _ :=
by simp only [res, equalizer.map_comp_map, CLCFP.res_comp_res]
lemma map_comp_res [fact (c₁ ≤ c₂)] :
map r V r' c₂ n f ≫ res r V r' c₁ c₂ n = res r V r' c₁ c₂ n ≫ map r V r' c₁ n f :=
by simp only [map, res, equalizer.map_comp_map, CLCFP.map_comp_res]
end CLCFPTinv
namespace breen_deligne
open CLCFPTinv
variables (M) {l m n}
namespace basic_universal_map
variables (ϕ : basic_universal_map m n)
def eval_CLCFPTinv [ϕ.suitable c₁ c₂] :
CLCFPTinv r V r' M c₂ n ⟶ CLCFPTinv r V r' M c₁ m :=
equalizer.map (ϕ.eval_CLCFP _ _ _ _ _) (ϕ.eval_CLCFP _ _ _ _ _)
(Tinv_comp_eval_CLCFP _ _ _ _ _ _) $
by rw [category.assoc, res_comp_eval_CLCFP V r' M (r' * c₁) c₁ (r' * c₂) c₂,
← category.assoc, T_inv_comp_eval_CLCFP, category.assoc]
lemma map_comp_eval_CLCFPTinv [ϕ.suitable c₁ c₂] :
map r V r' c₂ n f ≫ ϕ.eval_CLCFPTinv r V r' M₁ c₁ c₂ =
ϕ.eval_CLCFPTinv r V r' M₂ c₁ c₂ ≫ map r V r' c₁ m f :=
by simp only [map, eval_CLCFPTinv, equalizer.map_comp_map, map_comp_eval_CLCFP]
lemma res_comp_eval_CLCFPTinv
[fact (c₁ ≤ c₂)] [ϕ.suitable c₂ c₄] [ϕ.suitable c₁ c₃] [fact (c₃ ≤ c₄)] :
res r V r' c₃ c₄ n ≫ ϕ.eval_CLCFPTinv r V r' M c₁ c₃ =
ϕ.eval_CLCFPTinv r V r' M c₂ c₄ ≫ res r V r' c₁ c₂ m :=
by simp only [res, eval_CLCFPTinv, equalizer.map_comp_map,
res_comp_eval_CLCFP V r' _ c₁ c₂ c₃ c₄,
res_comp_eval_CLCFP V r' _ (r' * c₁) (r' * c₂) (r' * c₃) (r' * c₄)]
end basic_universal_map
namespace universal_map
variables (ϕ : universal_map m n)
def eval_CLCFPTinv [ϕ.suitable c₁ c₂] :
CLCFPTinv r V r' M c₂ n ⟶ CLCFPTinv r V r' M c₁ m :=
equalizer.map (ϕ.eval_CLCFP _ _ _ _ _) (ϕ.eval_CLCFP _ _ _ _ _)
(Tinv_comp_eval_CLCFP _ _ _ _ _ _) $
by rw [category.assoc, res_comp_eval_CLCFP V r' M (r' * c₁) c₁ (r' * c₂) c₂,
← category.assoc, T_inv_comp_eval_CLCFP, category.assoc]
@[simp] lemma eval_CLCFPTinv_zero :
(0 : universal_map m n).eval_CLCFPTinv r V r' M c₁ c₂ = 0 :=
begin
apply equalizer.hom_ext,
simp only [eval_CLCFPTinv, eval_CLCFP_zero, zero_comp, equalizer.map_ι, comp_zero]
end
open category_theory.limits
lemma eval_CLCFPTinv_comp (g : universal_map m n) (f : universal_map l m)
[hg : g.suitable c₂ c₃] [hf : f.suitable c₁ c₂] [(comp g f).suitable c₁ c₃] :
(comp g f).eval_CLCFPTinv r V r' M c₁ c₃ =
g.eval_CLCFPTinv r V r' M c₂ c₃ ≫ f.eval_CLCFPTinv r V r' M c₁ c₂ :=
by simp only [eval_CLCFPTinv, equalizer.map_comp_map, ← eval_CLCFP_comp]
lemma map_comp_eval_CLCFPTinv [ϕ.suitable c₁ c₂] :
map r V r' c₂ n f ≫ ϕ.eval_CLCFPTinv r V r' M₁ c₁ c₂ =
ϕ.eval_CLCFPTinv r V r' M₂ c₁ c₂ ≫ map r V r' c₁ m f :=
by simp only [map, eval_CLCFPTinv, equalizer.map_comp_map, map_comp_eval_CLCFP]
lemma res_comp_eval_CLCFPTinv
[fact (c₁ ≤ c₂)] [ϕ.suitable c₂ c₄] [ϕ.suitable c₁ c₃] [fact (c₃ ≤ c₄)] :
res r V r' c₃ c₄ n ≫ ϕ.eval_CLCFPTinv r V r' M c₁ c₃ =
ϕ.eval_CLCFPTinv r V r' M c₂ c₄ ≫ res r V r' c₁ c₂ m :=
by simp only [res, eval_CLCFPTinv, equalizer.map_comp_map,
res_comp_eval_CLCFP V r' _ c₁ c₂ c₃ c₄,
res_comp_eval_CLCFP V r' _ (r' * c₁) (r' * c₂) (r' * c₃) (r' * c₄)]
end universal_map
end breen_deligne
|
871bc2dacc01f05baab0c646b2c33d1555f25c6b | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/finset/pi.lean | 0978ffba703e90b77ef86fd49719a087aca46866 | [
"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,491 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import data.finset.image
import data.multiset.pi
/-!
# The cartesian product of finsets
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
namespace finset
open multiset
/-! ### pi -/
section pi
variables {α : Type*}
/-- The empty dependent product function, defined on the empty set. The assumption `a ∈ ∅` is never
satisfied. -/
def pi.empty (β : α → Sort*) (a : α) (h : a ∈ (∅ : finset α)) : β a :=
multiset.pi.empty β a h
variables {β : α → Type*} {δ : α → Sort*} [decidable_eq α]
/-- Given a finset `s` of `α` and for all `a : α` a finset `t a` of `δ a`, then one can define the
finset `s.pi t` of all functions defined on elements of `s` taking values in `t a` for `a ∈ s`.
Note that the elements of `s.pi t` are only partially defined, on `s`. -/
def pi (s : finset α) (t : Πa, finset (β a)) : finset (Πa∈s, β a) :=
⟨s.1.pi (λ a, (t a).1), s.nodup.pi $ λ a _, (t a).nodup⟩
@[simp] lemma pi_val (s : finset α) (t : Πa, finset (β a)) :
(s.pi t).1 = s.1.pi (λ a, (t a).1) := rfl
@[simp] lemma mem_pi {s : finset α} {t : Πa, finset (β a)} {f : Πa∈s, β a} :
f ∈ s.pi t ↔ (∀a (h : a ∈ s), f a h ∈ t a) :=
mem_pi _ _ _
/-- Given a function `f` defined on a finset `s`, define a new function on the finset `s ∪ {a}`,
equal to `f` on `s` and sending `a` to a given value `b`. This function is denoted
`s.pi.cons a b f`. If `a` already belongs to `s`, the new function takes the value `b` at `a`
anyway. -/
def pi.cons (s : finset α) (a : α) (b : δ a) (f : Πa, a ∈ s → δ a) (a' : α) (h : a' ∈ insert a s) :
δ a' :=
multiset.pi.cons s.1 a b f _ (multiset.mem_cons.2 $ mem_insert.symm.2 h)
@[simp]
lemma pi.cons_same (s : finset α) (a : α) (b : δ a) (f : Πa, a ∈ s → δ a) (h : a ∈ insert a s) :
pi.cons s a b f a h = b :=
multiset.pi.cons_same _
lemma pi.cons_ne {s : finset α} {a a' : α} {b : δ a} {f : Πa, a ∈ s → δ a} {h : a' ∈ insert a s}
(ha : a ≠ a') :
pi.cons s a b f a' h = f a' ((mem_insert.1 h).resolve_left ha.symm) :=
multiset.pi.cons_ne _ _
lemma pi.cons_injective {a : α} {b : δ a} {s : finset α} (hs : a ∉ s) :
function.injective (pi.cons s a b) :=
assume e₁ e₂ eq,
@multiset.pi.cons_injective α _ δ a b s.1 hs _ _ $
funext $ assume e, funext $ assume h,
have pi.cons s a b e₁ e (by simpa only [multiset.mem_cons, mem_insert] using h) =
pi.cons s a b e₂ e (by simpa only [multiset.mem_cons, mem_insert] using h),
{ rw [eq] },
this
@[simp] lemma pi_empty {t : Πa:α, finset (β a)} :
pi (∅ : finset α) t = singleton (pi.empty β) := rfl
@[simp] lemma pi_insert [∀a, decidable_eq (β a)]
{s : finset α} {t : Πa:α, finset (β a)} {a : α} (ha : a ∉ s) :
pi (insert a s) t = (t a).bUnion (λb, (pi s t).image (pi.cons s a b)) :=
begin
apply eq_of_veq,
rw ← (pi (insert a s) t).2.dedup,
refine (λ s' (h : s' = a ::ₘ s.1), (_ : dedup (multiset.pi s' (λ a, (t a).1)) =
dedup ((t a).1.bind $ λ b,
dedup $ (multiset.pi s.1 (λ (a : α), (t a).val)).map $
λ f a' h', multiset.pi.cons s.1 a b f a' (h ▸ h')))) _ (insert_val_of_not_mem ha),
subst s', rw pi_cons,
congr, funext b,
refine ((pi s t).nodup.map _).dedup.symm,
exact multiset.pi.cons_injective ha,
end
lemma pi_singletons {β : Type*} (s : finset α) (f : α → β) :
s.pi (λ a, ({f a} : finset β)) = {λ a _, f a} :=
begin
rw eq_singleton_iff_unique_mem,
split,
{ simp },
intros a ha,
ext i hi,
rw [mem_pi] at ha,
simpa using ha i hi,
end
lemma pi_const_singleton {β : Type*} (s : finset α) (i : β) :
s.pi (λ _, ({i} : finset β)) = {λ _ _, i} :=
pi_singletons s (λ _, i)
lemma pi_subset {s : finset α} (t₁ t₂ : Πa, finset (β a)) (h : ∀ a ∈ s, t₁ a ⊆ t₂ a) :
s.pi t₁ ⊆ s.pi t₂ :=
λ g hg, mem_pi.2 $ λ a ha, h a ha (mem_pi.mp hg a ha)
lemma pi_disjoint_of_disjoint {δ : α → Type*}
{s : finset α} (t₁ t₂ : Πa, finset (δ a)) {a : α} (ha : a ∈ s) (h : disjoint (t₁ a) (t₂ a)) :
disjoint (s.pi t₁) (s.pi t₂) :=
disjoint_iff_ne.2 $ λ f₁ hf₁ f₂ hf₂ eq₁₂,
disjoint_iff_ne.1 h (f₁ a ha) (mem_pi.mp hf₁ a ha) (f₂ a ha) (mem_pi.mp hf₂ a ha)
$ congr_fun (congr_fun eq₁₂ a) ha
end pi
end finset
|
94e77fa6c49674f9fbcb81a14414d504428c1a9d | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /src/data/rat/cast.lean | 94a97333ee2feb4b591636375c06de0c12149d1c | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 12,814 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import data.rat.order
import data.int.char_zero
/-!
# Casts for Rational Numbers
## Summary
We define the canonical injection from ℚ into an arbitrary division ring and prove various
casting lemmas showing the well-behavedness of this injection.
## Notations
- `/.` is infix notation for `rat.mk`.
## Tags
rat, rationals, field, ℚ, numerator, denominator, num, denom, cast, coercion, casting
-/
namespace rat
variable {α : Type*}
open_locale rat
section with_div_ring
variable [division_ring α]
/-- Construct the canonical injection from `ℚ` into an arbitrary
division ring. If the field has positive characteristic `p`,
we define `1 / p = 1 / 0 = 0` for consistency with our
division by zero convention. -/
-- see Note [coercion into rings]
@[priority 900] instance cast_coe : has_coe_t ℚ α := ⟨λ r, r.1 / r.2⟩
@[simp] theorem cast_of_int (n : ℤ) : (of_int n : α) = n :=
show (n / (1:ℕ) : α) = n, by rw [nat.cast_one, div_one]
@[simp, norm_cast] theorem cast_coe_int (n : ℤ) : ((n : ℚ) : α) = n :=
by rw [coe_int_eq_of_int, cast_of_int]
@[simp, norm_cast] theorem cast_coe_nat (n : ℕ) : ((n : ℚ) : α) = n := cast_coe_int n
@[simp, norm_cast] theorem cast_zero : ((0 : ℚ) : α) = 0 :=
(cast_of_int _).trans int.cast_zero
@[simp, norm_cast] theorem cast_one : ((1 : ℚ) : α) = 1 :=
(cast_of_int _).trans int.cast_one
theorem cast_commute (r : ℚ) (a : α) : commute ↑r a :=
(r.1.cast_commute a).div_left (r.2.cast_commute a)
theorem cast_comm (r : ℚ) (a : α) : (r : α) * a = a * r :=
(cast_commute r a).eq
theorem commute_cast (a : α) (r : ℚ) : commute a r :=
(r.cast_commute a).symm
@[norm_cast] theorem cast_mk_of_ne_zero (a b : ℤ)
(b0 : (b:α) ≠ 0) : (a /. b : α) = a / b :=
begin
have b0' : b ≠ 0, { refine mt _ b0, simp {contextual := tt} },
cases e : a /. b with n d h c,
have d0 : (d:α) ≠ 0,
{ intro d0,
have dd := denom_dvd a b,
cases (show (d:ℤ) ∣ b, by rwa e at dd) with k ke,
have : (b:α) = (d:α) * (k:α), {rw [ke, int.cast_mul], refl},
rw [d0, zero_mul] at this, contradiction },
rw [num_denom'] at e,
have := congr_arg (coe : ℤ → α) ((mk_eq b0' $ ne_of_gt $ int.coe_nat_pos.2 h).1 e),
rw [int.cast_mul, int.cast_mul, int.cast_coe_nat] at this,
symmetry, change (a / b : α) = n / d,
rw [div_eq_mul_inv, eq_div_iff_mul_eq d0, mul_assoc, (d.commute_cast _).eq,
← mul_assoc, this, mul_assoc, mul_inv_cancel b0, mul_one]
end
@[norm_cast] theorem cast_add_of_ne_zero : ∀ {m n : ℚ},
(m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m + n : ℚ) : α) = m + n
| ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin
have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl),
have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl),
rw [num_denom', num_denom', add_def d₁0' d₂0'],
suffices : (n₁ * (d₂ * (d₂⁻¹ * d₁⁻¹)) +
n₂ * (d₁ * d₂⁻¹) * d₁⁻¹ : α) = n₁ * d₁⁻¹ + n₂ * d₂⁻¹,
{ rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero],
{ simpa [division_def, left_distrib, right_distrib, mul_inv_rev', d₁0, d₂0, mul_assoc] },
all_goals {simp [d₁0, d₂0]} },
rw [← mul_assoc (d₂:α), mul_inv_cancel d₂0, one_mul,
(nat.cast_commute _ _).eq], simp [d₁0, mul_assoc]
end
@[simp, norm_cast] theorem cast_neg : ∀ n, ((-n : ℚ) : α) = -n
| ⟨n, d, h, c⟩ := show (↑-n / d : α) = -(n / d),
by rw [div_eq_mul_inv, div_eq_mul_inv, int.cast_neg, neg_mul_eq_neg_mul]
@[norm_cast] theorem cast_sub_of_ne_zero {m n : ℚ}
(m0 : (m.denom : α) ≠ 0) (n0 : (n.denom : α) ≠ 0) : ((m - n : ℚ) : α) = m - n :=
have ((-n).denom : α) ≠ 0, by cases n; exact n0,
by simp [sub_eq_add_neg, (cast_add_of_ne_zero m0 this)]
@[norm_cast] theorem cast_mul_of_ne_zero : ∀ {m n : ℚ},
(m.denom : α) ≠ 0 → (n.denom : α) ≠ 0 → ((m * n : ℚ) : α) = m * n
| ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := λ (d₁0 : (d₁:α) ≠ 0) (d₂0 : (d₂:α) ≠ 0), begin
have d₁0' : (d₁:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₁0; exact d₁0 rfl),
have d₂0' : (d₂:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d₂0; exact d₂0 rfl),
rw [num_denom', num_denom', mul_def d₁0' d₂0'],
suffices : (n₁ * ((n₂ * d₂⁻¹) * d₁⁻¹) : α) = n₁ * (d₁⁻¹ * (n₂ * d₂⁻¹)),
{ rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, cast_mk_of_ne_zero],
{ simpa [division_def, mul_inv_rev', d₁0, d₂0, mul_assoc] },
all_goals {simp [d₁0, d₂0]} },
rw [(d₁.commute_cast (_:α)).inv_right'.eq]
end
@[norm_cast] theorem cast_inv_of_ne_zero : ∀ {n : ℚ},
(n.num : α) ≠ 0 → (n.denom : α) ≠ 0 → ((n⁻¹ : ℚ) : α) = n⁻¹
| ⟨n, d, h, c⟩ := λ (n0 : (n:α) ≠ 0) (d0 : (d:α) ≠ 0), begin
have n0' : (n:ℤ) ≠ 0 := λ e, by rw e at n0; exact n0 rfl,
have d0' : (d:ℤ) ≠ 0 := int.coe_nat_ne_zero.2 (λ e, by rw e at d0; exact d0 rfl),
rw [num_denom', inv_def],
rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero, inv_div];
simp [n0, d0]
end
@[norm_cast] theorem cast_div_of_ne_zero {m n : ℚ} (md : (m.denom : α) ≠ 0)
(nn : (n.num : α) ≠ 0) (nd : (n.denom : α) ≠ 0) : ((m / n : ℚ) : α) = m / n :=
have (n⁻¹.denom : ℤ) ∣ n.num,
by conv in n⁻¹.denom { rw [←(@num_denom n), inv_def] };
apply denom_dvd,
have (n⁻¹.denom : α) = 0 → (n.num : α) = 0, from
λ h, let ⟨k, e⟩ := this in
by have := congr_arg (coe : ℤ → α) e;
rwa [int.cast_mul, int.cast_coe_nat, h, zero_mul] at this,
by rw [division_def, cast_mul_of_ne_zero md (mt this nn), cast_inv_of_ne_zero nn nd, division_def]
@[simp, norm_cast] theorem cast_inj [char_zero α] : ∀ {m n : ℚ}, (m : α) = n ↔ m = n
| ⟨n₁, d₁, h₁, c₁⟩ ⟨n₂, d₂, h₂, c₂⟩ := begin
refine ⟨λ h, _, congr_arg _⟩,
have d₁0 : d₁ ≠ 0 := ne_of_gt h₁,
have d₂0 : d₂ ≠ 0 := ne_of_gt h₂,
have d₁a : (d₁:α) ≠ 0 := nat.cast_ne_zero.2 d₁0,
have d₂a : (d₂:α) ≠ 0 := nat.cast_ne_zero.2 d₂0,
rw [num_denom', num_denom'] at h ⊢,
rw [cast_mk_of_ne_zero, cast_mk_of_ne_zero] at h; simp [d₁0, d₂0] at h ⊢,
rwa [eq_div_iff_mul_eq d₂a, division_def, mul_assoc, (d₁.cast_commute (d₂:α)).inv_left'.eq,
← mul_assoc, ← division_def, eq_comm, eq_div_iff_mul_eq d₁a, eq_comm,
← int.cast_coe_nat, ← int.cast_mul, ← int.cast_coe_nat, ← int.cast_mul,
int.cast_inj, ← mk_eq (int.coe_nat_ne_zero.2 d₁0) (int.coe_nat_ne_zero.2 d₂0)] at h
end
theorem cast_injective [char_zero α] : function.injective (coe : ℚ → α)
| m n := cast_inj.1
@[simp] theorem cast_eq_zero [char_zero α] {n : ℚ} : (n : α) = 0 ↔ n = 0 :=
by rw [← cast_zero, cast_inj]
theorem cast_ne_zero [char_zero α] {n : ℚ} : (n : α) ≠ 0 ↔ n ≠ 0 :=
not_congr cast_eq_zero
@[simp, norm_cast] theorem cast_add [char_zero α] (m n) :
((m + n : ℚ) : α) = m + n :=
cast_add_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos)
@[simp, norm_cast] theorem cast_sub [char_zero α] (m n) :
((m - n : ℚ) : α) = m - n :=
cast_sub_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos)
@[simp, norm_cast] theorem cast_mul [char_zero α] (m n) :
((m * n : ℚ) : α) = m * n :=
cast_mul_of_ne_zero (nat.cast_ne_zero.2 $ ne_of_gt m.pos) (nat.cast_ne_zero.2 $ ne_of_gt n.pos)
@[simp, norm_cast] theorem cast_bit0 [char_zero α] (n : ℚ) :
((bit0 n : ℚ) : α) = bit0 n :=
cast_add _ _
@[simp, norm_cast] theorem cast_bit1 [char_zero α] (n : ℚ) :
((bit1 n : ℚ) : α) = bit1 n :=
by rw [bit1, cast_add, cast_one, cast_bit0]; refl
variable (α)
/-- Coercion `ℚ → α` as a `ring_hom`. -/
def cast_hom [char_zero α] : ℚ →+* α := ⟨coe, cast_one, cast_mul, cast_zero, cast_add⟩
variable {α}
@[simp] lemma coe_cast_hom [char_zero α] : ⇑(cast_hom α) = coe := rfl
@[simp, norm_cast] theorem cast_inv [char_zero α] (n) : ((n⁻¹ : ℚ) : α) = n⁻¹ :=
(cast_hom α).map_inv _
@[simp, norm_cast] theorem cast_div [char_zero α] (m n) :
((m / n : ℚ) : α) = m / n :=
(cast_hom α).map_div _ _
@[norm_cast] theorem cast_mk [char_zero α] (a b : ℤ) : ((a /. b) : α) = a / b :=
by simp only [mk_eq_div, cast_div, cast_coe_int]
@[simp, norm_cast] theorem cast_pow [char_zero α] (q) (k : ℕ) :
((q ^ k : ℚ) : α) = q ^ k :=
(cast_hom α).map_pow q k
end with_div_ring
@[simp, norm_cast] theorem cast_nonneg [linear_ordered_field α] : ∀ {n : ℚ}, 0 ≤ (n : α) ↔ 0 ≤ n
| ⟨n, d, h, c⟩ :=
by { rw [num_denom', cast_mk, mk_eq_div, div_nonneg_iff, div_nonneg_iff], norm_cast }
@[simp, norm_cast] theorem cast_le [linear_ordered_field α] {m n : ℚ} : (m : α) ≤ n ↔ m ≤ n :=
by rw [← sub_nonneg, ← cast_sub, cast_nonneg, sub_nonneg]
@[simp, norm_cast] theorem cast_lt [linear_ordered_field α] {m n : ℚ} : (m : α) < n ↔ m < n :=
by simpa [-cast_le] using not_congr (@cast_le α _ n m)
@[simp] theorem cast_nonpos [linear_ordered_field α] {n : ℚ} : (n : α) ≤ 0 ↔ n ≤ 0 :=
by rw [← cast_zero, cast_le]
@[simp] theorem cast_pos [linear_ordered_field α] {n : ℚ} : (0 : α) < n ↔ 0 < n :=
by rw [← cast_zero, cast_lt]
@[simp] theorem cast_lt_zero [linear_ordered_field α] {n : ℚ} : (n : α) < 0 ↔ n < 0 :=
by rw [← cast_zero, cast_lt]
@[simp, norm_cast] theorem cast_id : ∀ n : ℚ, ↑n = n
| ⟨n, d, h, c⟩ := by rw [num_denom', cast_mk, mk_eq_div]
@[simp, norm_cast] theorem cast_min [linear_ordered_field α] {a b : ℚ} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [h, min]
@[simp, norm_cast] theorem cast_max [linear_ordered_field α] {a b : ℚ} :
(↑(max a b) : α) = max a b :=
by by_cases b ≤ a; simp [h, max]
@[simp, norm_cast] theorem cast_abs [linear_ordered_field α] {q : ℚ} :
((abs q : ℚ) : α) = abs q :=
by simp [abs_eq_max_neg]
end rat
open rat ring_hom
lemma ring_hom.eq_rat_cast {k} [division_ring k] (f : ℚ →+* k) (r : ℚ) : f r = r :=
calc f r = f (r.1 / r.2) : by rw [← int.cast_coe_nat, ← mk_eq_div, num_denom]
... = f r.1 / f r.2 : f.map_div _ _
... = r.1 / r.2 : by rw [map_nat_cast, map_int_cast]
-- This seems to be true for a `[char_p k]` too because `k'` must have the same characteristic
-- but the proof would be much longer
lemma ring_hom.map_rat_cast {k k'} [division_ring k] [char_zero k] [division_ring k']
(f : k →+* k') (r : ℚ) :
f r = r :=
(f.comp (cast_hom k)).eq_rat_cast r
lemma ring_hom.ext_rat {R : Type*} [semiring R] (f g : ℚ →+* R) : f = g :=
begin
ext r,
refine rat.num_denom_cases_on' r _,
intros a b b0,
let φ : ℤ →+* R := f.comp (int.cast_ring_hom ℚ),
let ψ : ℤ →+* R := g.comp (int.cast_ring_hom ℚ),
rw [rat.mk_eq_div, int.cast_coe_nat],
have b0' : (b:ℚ) ≠ 0 := nat.cast_ne_zero.2 b0,
have : ∀ n : ℤ, f n = g n := λ n, show φ n = ψ n, by rw [φ.ext_int ψ],
calc f (a * b⁻¹)
= f a * f b⁻¹ * (g (b:ℤ) * g b⁻¹) :
by rw [int.cast_coe_nat, ← g.map_mul, mul_inv_cancel b0', g.map_one, mul_one, f.map_mul]
... = g a * f b⁻¹ * (f (b:ℤ) * g b⁻¹) : by rw [this a, ← this b]
... = g (a * b⁻¹) :
by rw [int.cast_coe_nat, mul_assoc, ← mul_assoc (f b⁻¹),
← f.map_mul, inv_mul_cancel b0', f.map_one, one_mul, g.map_mul]
end
instance rat.subsingleton_ring_hom {R : Type*} [semiring R] : subsingleton (ℚ →+* R) :=
⟨ring_hom.ext_rat⟩
namespace monoid_with_zero_hom
variables {M : Type*} [group_with_zero M]
/-- If `f` and `g` agree on the integers then they are equal `φ`.
See note [partially-applied ext lemmas] for why `comp` is used here. -/
@[ext]
theorem ext_rat {f g : monoid_with_zero_hom ℚ M}
(same_on_int : f.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom =
g.comp (int.cast_ring_hom ℚ).to_monoid_with_zero_hom) : f = g :=
begin
have same_on_int' : ∀ k : ℤ, f k = g k := congr_fun same_on_int,
ext x,
rw [← @rat.num_denom x, rat.mk_eq_div, f.map_div, g.map_div,
same_on_int' x.num, same_on_int' x.denom],
end
/-- Positive integer values of a morphism `φ` and its value on `-1` completely determine `φ`. -/
theorem ext_rat_on_pnat {f g : monoid_with_zero_hom ℚ M}
(same_on_neg_one : f (-1) = g (-1)) (same_on_pnat : ∀ n : ℕ, 0 < n → f n = g n) : f = g :=
ext_rat $ ext_int' (by simpa) ‹_›
end monoid_with_zero_hom
|
06134937cb996928288a8436b96b214dda950ccb | 3dd1b66af77106badae6edb1c4dea91a146ead30 | /library/standard/diaconescu.lean | 93918f3cc68854998949cf597e687c67f072c651 | [
"Apache-2.0"
] | permissive | silky/lean | 79c20c15c93feef47bb659a2cc139b26f3614642 | df8b88dca2f8da1a422cb618cd476ef5be730546 | refs/heads/master | 1,610,737,587,697 | 1,406,574,534,000 | 1,406,574,534,000 | 22,362,176 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,770 | 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, Jeremy Avigad
import logic hilbert funext
using eq_proofs
-- Diaconescu’s theorem
-- Show that Excluded middle follows from
-- Hilbert's choice operator, function extensionality and Prop extensionality
section
hypothesis propext {a b : Prop} : (a → b) → (b → a) → a = b
parameter p : Prop
definition u [private] := epsilon (λ x, x = true ∨ p)
definition v [private] := epsilon (λ x, x = false ∨ p)
lemma u_def [private] : u = true ∨ p
:= epsilon_ax (exists_intro true (or_inl (refl true)))
lemma v_def [private] : v = false ∨ p
:= epsilon_ax (exists_intro false (or_inl (refl false)))
lemma uv_implies_p [private] : ¬(u = v) ∨ p
:= or_elim u_def
(assume Hut : u = true, or_elim v_def
(assume Hvf : v = false,
have Hne : ¬(u = v), from Hvf⁻¹ ▸ Hut⁻¹ ▸ true_ne_false,
or_inl Hne)
(assume Hp : p, or_inr Hp))
(assume Hp : p, or_inr Hp)
lemma p_implies_uv [private] : p → u = v
:= assume Hp : p,
have Hpred : (λ x, x = true ∨ p) = (λ x, x = false ∨ p), from
funext (take x : Prop,
have Hl : (x = true ∨ p) → (x = false ∨ p), from
assume A, or_inr Hp,
have Hr : (x = false ∨ p) → (x = true ∨ p), from
assume A, or_inr Hp,
show (x = true ∨ p) = (x = false ∨ p), from
propext Hl Hr),
show u = v, from
Hpred ▸ (refl (epsilon (λ x, x = true ∨ p)))
theorem em : p ∨ ¬p
:= have H : ¬(u = v) → ¬p, from contrapos p_implies_uv,
or_elim uv_implies_p
(assume Hne : ¬(u = v), or_inr (H Hne))
(assume Hp : p, or_inl Hp)
end
|
7f55a088827255f9e42d956408b5b5add7b001b6 | 7571914d3f4d9677288f35ab1a53a2ad70a62bd7 | /tests/lean/run/simp_match_reducibility_issue.lean | 136c8802c630417a7614dedda586bbdae96adc9e | [
"Apache-2.0"
] | permissive | picrin/lean-1 | a395fed5287995f09a15a190bb24609919a0727f | b50597228b42a7eaa01bf8cb7a4fb1a98e7a8aab | refs/heads/master | 1,610,757,735,162 | 1,502,008,413,000 | 1,502,008,413,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 273 | lean | namespace test
universes u v
section
open vector
variable α : Type u
variables m n k : ℕ
variable v : vector α m
variable w : vector α n
theorem append_nil : append v nil = v :=
by cases v; simp [vector.append, vector.nil]; reflexivity
end
end test
|
7a58ce8adac30d1f1f90c6ecb0c553464373be6d | 76ce87faa6bc3c2aa9af5962009e01e04f2a074a | /00_Foundations/03_truth_is_proof.lean | a96d3a631626694b4ac06b99e803a84469defcc6 | [] | no_license | Mnormansell/Discrete-Notes | db423dd9206bbe7080aecb84b4c2d275b758af97 | 61f13b98be590269fc4822be7b47924a6ddc1261 | refs/heads/master | 1,585,412,435,424 | 1,540,919,483,000 | 1,540,919,483,000 | 148,684,638 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,013 | lean | /-
Now here we're going to pull a little trick.
It's based on the idea that a "proof", whatever
that is (!), serves as "evidence" that justifies
a truth judgment about a proposition. So we are
now technically distinguishing between a proof
of a proposition and the truth judgment that it
justifies. Nevertheless, we will assume that a
truth judgment for some proposition, P, is in
fact justified if and only if we have a proof
of P.
To denote the fact that we have a proof, p,
of some proposition, P, we will write p : P.
Now, the key idea is that having a proof is
the evidence we need to judge that P is true.
Moreover, if we've judged P to be true, then
we must have a proof, p, of P.
In other words, P is true if and only if we
have evidence (a proof), p, for P. We can
write this statement in the language of logic
like this: "p : P → P : true". We'd read
this as saying "if p is a proof of P then P
is true."
The evidence, i.e., proof, p, for P, justifies
the judgement, P : true. Moreover, the only
way to justify such a judgement is with such
a piece of evidence, i.e., with a proof. In
the logic of Lean, proof is truth and truth
requires a proof.
-/
/-
Given that having a proof of P means that one
can conclude the truth of P, we can write an
equivalent inference rule like this (compare
with the previous):
p : P, q : Q
------------ (and.intro)
r : P ∧ Q
This then says, "If you give me a proof, p, of
some proposition, P, and if you also given me a
proof, q, of some proposition Q, then I promise
to give you back a proof, r, of the proposition,
P ∧ Q."
As a shorthand, mathematicians and logicians
would usually elide the ": true" and the "p :"
bits, so you'd usually see this rule written
informally like this:
P, Q
----- and.intro
P ∧ Q
However, if we want to be really precise, we'd
write the rule like this:
{ P Q : Prop } (p : P) (q : Q)
------------------------------ (and.intro)
pf : P ∧ Q
This is the final form, as we'll see in more
detail in material to come. It says that if
P and Q are propositions, and if p is a proof
of P and q is a proof of Q, then applying the
and.intro rule to p and q returns a proof of
P ∧ Q. We thus now have a rule to establish
the truth of a proposition of P ∧ Q by using
this inference rule to construct a proof of
the proposition P ∧ Q from given proofs of
its constituent propositions.
As we'll see in a bit, the expression,
(and.intro p q), which you can read as simply
applying the function, and.intro. to the proof
"values", p and q, returns (reduces to) a value
that is a proof of P ∧ Q. That's where we are
headed.
-/
/-
EXERCISE: What is returned when the and-introduction
inference rule, viewed as a program, is applied to two
proofs: one of the proposition, 0 = 0, and one of the
proposition, "Hello" = "Hello"?
EXERCISE: Why could this rule never be applied (in
any reasonable logic) to produce a proof (thus a
truth judgement) for the proposition, 0 = 0 ∧ 0 = 1?
-/ |
59a67b0f07742112df9f7357fe633c95a4d00168 | 592ee40978ac7604005a4e0d35bbc4b467389241 | /Library/generated/mathscheme-lean/RingoidWithMultAntiDistrib.lean | f25e524ea5e5370d14d2fce03d381240ccc8de8c | [] | 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 | 13,011 | 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 RingoidWithMultAntiDistrib
structure RingoidWithMultAntiDistrib (A : Type) : Type :=
(times : (A → (A → A)))
(prim : (A → A))
(antidis_prim_times : (∀ {x y : A} , (prim (times x y)) = (times (prim y) (prim x))))
(plus : (A → (A → A)))
(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 RingoidWithMultAntiDistrib
structure Sig (AS : Type) : Type :=
(timesS : (AS → (AS → AS)))
(primS : (AS → AS))
(plusS : (AS → (AS → AS)))
structure Product (A : Type) : Type :=
(timesP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(primP : ((Prod A A) → (Prod A A)))
(plusP : ((Prod A A) → ((Prod A A) → (Prod A A))))
(antidis_prim_timesP : (∀ {xP yP : (Prod A A)} , (primP (timesP xP yP)) = (timesP (primP yP) (primP xP))))
(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} (Ri1 : (RingoidWithMultAntiDistrib A1)) (Ri2 : (RingoidWithMultAntiDistrib A2)) : Type :=
(hom : (A1 → A2))
(pres_times : (∀ {x1 x2 : A1} , (hom ((times Ri1) x1 x2)) = ((times Ri2) (hom x1) (hom x2))))
(pres_prim : (∀ {x1 : A1} , (hom ((prim Ri1) x1)) = ((prim Ri2) (hom x1))))
(pres_plus : (∀ {x1 x2 : A1} , (hom ((plus Ri1) x1 x2)) = ((plus Ri2) (hom x1) (hom x2))))
structure RelInterp {A1 : Type} {A2 : Type} (Ri1 : (RingoidWithMultAntiDistrib A1)) (Ri2 : (RingoidWithMultAntiDistrib A2)) : Type 1 :=
(interp : (A1 → (A2 → Type)))
(interp_times : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((times Ri1) x1 x2) ((times Ri2) y1 y2))))))
(interp_prim : (∀ {x1 : A1} {y1 : A2} , ((interp x1 y1) → (interp ((prim Ri1) x1) ((prim Ri2) y1)))))
(interp_plus : (∀ {x1 x2 : A1} {y1 y2 : A2} , ((interp x1 y1) → ((interp x2 y2) → (interp ((plus Ri1) x1 x2) ((plus Ri2) y1 y2))))))
inductive RingoidWithMultAntiDistribTerm : Type
| timesL : (RingoidWithMultAntiDistribTerm → (RingoidWithMultAntiDistribTerm → RingoidWithMultAntiDistribTerm))
| primL : (RingoidWithMultAntiDistribTerm → RingoidWithMultAntiDistribTerm)
| plusL : (RingoidWithMultAntiDistribTerm → (RingoidWithMultAntiDistribTerm → RingoidWithMultAntiDistribTerm))
open RingoidWithMultAntiDistribTerm
inductive ClRingoidWithMultAntiDistribTerm (A : Type) : Type
| sing : (A → ClRingoidWithMultAntiDistribTerm)
| timesCl : (ClRingoidWithMultAntiDistribTerm → (ClRingoidWithMultAntiDistribTerm → ClRingoidWithMultAntiDistribTerm))
| primCl : (ClRingoidWithMultAntiDistribTerm → ClRingoidWithMultAntiDistribTerm)
| plusCl : (ClRingoidWithMultAntiDistribTerm → (ClRingoidWithMultAntiDistribTerm → ClRingoidWithMultAntiDistribTerm))
open ClRingoidWithMultAntiDistribTerm
inductive OpRingoidWithMultAntiDistribTerm (n : ℕ) : Type
| v : ((fin n) → OpRingoidWithMultAntiDistribTerm)
| timesOL : (OpRingoidWithMultAntiDistribTerm → (OpRingoidWithMultAntiDistribTerm → OpRingoidWithMultAntiDistribTerm))
| primOL : (OpRingoidWithMultAntiDistribTerm → OpRingoidWithMultAntiDistribTerm)
| plusOL : (OpRingoidWithMultAntiDistribTerm → (OpRingoidWithMultAntiDistribTerm → OpRingoidWithMultAntiDistribTerm))
open OpRingoidWithMultAntiDistribTerm
inductive OpRingoidWithMultAntiDistribTerm2 (n : ℕ) (A : Type) : Type
| v2 : ((fin n) → OpRingoidWithMultAntiDistribTerm2)
| sing2 : (A → OpRingoidWithMultAntiDistribTerm2)
| timesOL2 : (OpRingoidWithMultAntiDistribTerm2 → (OpRingoidWithMultAntiDistribTerm2 → OpRingoidWithMultAntiDistribTerm2))
| primOL2 : (OpRingoidWithMultAntiDistribTerm2 → OpRingoidWithMultAntiDistribTerm2)
| plusOL2 : (OpRingoidWithMultAntiDistribTerm2 → (OpRingoidWithMultAntiDistribTerm2 → OpRingoidWithMultAntiDistribTerm2))
open OpRingoidWithMultAntiDistribTerm2
def simplifyCl {A : Type} : ((ClRingoidWithMultAntiDistribTerm A) → (ClRingoidWithMultAntiDistribTerm A))
| (timesCl (primCl y) (primCl x)) := (primCl (timesCl x y))
| (timesCl x1 x2) := (timesCl (simplifyCl x1) (simplifyCl x2))
| (primCl x1) := (primCl (simplifyCl x1))
| (plusCl x1 x2) := (plusCl (simplifyCl x1) (simplifyCl x2))
| (sing x1) := (sing x1)
def simplifyOpB {n : ℕ} : ((OpRingoidWithMultAntiDistribTerm n) → (OpRingoidWithMultAntiDistribTerm n))
| (timesOL (primOL y) (primOL x)) := (primOL (timesOL x y))
| (timesOL x1 x2) := (timesOL (simplifyOpB x1) (simplifyOpB x2))
| (primOL x1) := (primOL (simplifyOpB x1))
| (plusOL x1 x2) := (plusOL (simplifyOpB x1) (simplifyOpB x2))
| (v x1) := (v x1)
def simplifyOp {n : ℕ} {A : Type} : ((OpRingoidWithMultAntiDistribTerm2 n A) → (OpRingoidWithMultAntiDistribTerm2 n A))
| (timesOL2 (primOL2 y) (primOL2 x)) := (primOL2 (timesOL2 x y))
| (timesOL2 x1 x2) := (timesOL2 (simplifyOp x1) (simplifyOp x2))
| (primOL2 x1) := (primOL2 (simplifyOp x1))
| (plusOL2 x1 x2) := (plusOL2 (simplifyOp x1) (simplifyOp x2))
| (v2 x1) := (v2 x1)
| (sing2 x1) := (sing2 x1)
def evalB {A : Type} : ((RingoidWithMultAntiDistrib A) → (RingoidWithMultAntiDistribTerm → A))
| Ri (timesL x1 x2) := ((times Ri) (evalB Ri x1) (evalB Ri x2))
| Ri (primL x1) := ((prim Ri) (evalB Ri x1))
| Ri (plusL x1 x2) := ((plus Ri) (evalB Ri x1) (evalB Ri x2))
def evalCl {A : Type} : ((RingoidWithMultAntiDistrib A) → ((ClRingoidWithMultAntiDistribTerm A) → A))
| Ri (sing x1) := x1
| Ri (timesCl x1 x2) := ((times Ri) (evalCl Ri x1) (evalCl Ri x2))
| Ri (primCl x1) := ((prim Ri) (evalCl Ri x1))
| Ri (plusCl x1 x2) := ((plus Ri) (evalCl Ri x1) (evalCl Ri x2))
def evalOpB {A : Type} {n : ℕ} : ((RingoidWithMultAntiDistrib A) → ((vector A n) → ((OpRingoidWithMultAntiDistribTerm n) → A)))
| Ri vars (v x1) := (nth vars x1)
| Ri vars (timesOL x1 x2) := ((times Ri) (evalOpB Ri vars x1) (evalOpB Ri vars x2))
| Ri vars (primOL x1) := ((prim Ri) (evalOpB Ri vars x1))
| Ri vars (plusOL x1 x2) := ((plus Ri) (evalOpB Ri vars x1) (evalOpB Ri vars x2))
def evalOp {A : Type} {n : ℕ} : ((RingoidWithMultAntiDistrib A) → ((vector A n) → ((OpRingoidWithMultAntiDistribTerm2 n A) → A)))
| Ri vars (v2 x1) := (nth vars x1)
| Ri vars (sing2 x1) := x1
| Ri vars (timesOL2 x1 x2) := ((times Ri) (evalOp Ri vars x1) (evalOp Ri vars x2))
| Ri vars (primOL2 x1) := ((prim Ri) (evalOp Ri vars x1))
| Ri vars (plusOL2 x1 x2) := ((plus Ri) (evalOp Ri vars x1) (evalOp Ri vars x2))
def inductionB {P : (RingoidWithMultAntiDistribTerm → Type)} : ((∀ (x1 x2 : RingoidWithMultAntiDistribTerm) , ((P x1) → ((P x2) → (P (timesL x1 x2))))) → ((∀ (x1 : RingoidWithMultAntiDistribTerm) , ((P x1) → (P (primL x1)))) → ((∀ (x1 x2 : RingoidWithMultAntiDistribTerm) , ((P x1) → ((P x2) → (P (plusL x1 x2))))) → (∀ (x : RingoidWithMultAntiDistribTerm) , (P x)))))
| ptimesl ppriml pplusl (timesL x1 x2) := (ptimesl _ _ (inductionB ptimesl ppriml pplusl x1) (inductionB ptimesl ppriml pplusl x2))
| ptimesl ppriml pplusl (primL x1) := (ppriml _ (inductionB ptimesl ppriml pplusl x1))
| ptimesl ppriml pplusl (plusL x1 x2) := (pplusl _ _ (inductionB ptimesl ppriml pplusl x1) (inductionB ptimesl ppriml pplusl x2))
def inductionCl {A : Type} {P : ((ClRingoidWithMultAntiDistribTerm A) → Type)} : ((∀ (x1 : A) , (P (sing x1))) → ((∀ (x1 x2 : (ClRingoidWithMultAntiDistribTerm A)) , ((P x1) → ((P x2) → (P (timesCl x1 x2))))) → ((∀ (x1 : (ClRingoidWithMultAntiDistribTerm A)) , ((P x1) → (P (primCl x1)))) → ((∀ (x1 x2 : (ClRingoidWithMultAntiDistribTerm A)) , ((P x1) → ((P x2) → (P (plusCl x1 x2))))) → (∀ (x : (ClRingoidWithMultAntiDistribTerm A)) , (P x))))))
| psing ptimescl pprimcl ppluscl (sing x1) := (psing x1)
| psing ptimescl pprimcl ppluscl (timesCl x1 x2) := (ptimescl _ _ (inductionCl psing ptimescl pprimcl ppluscl x1) (inductionCl psing ptimescl pprimcl ppluscl x2))
| psing ptimescl pprimcl ppluscl (primCl x1) := (pprimcl _ (inductionCl psing ptimescl pprimcl ppluscl x1))
| psing ptimescl pprimcl ppluscl (plusCl x1 x2) := (ppluscl _ _ (inductionCl psing ptimescl pprimcl ppluscl x1) (inductionCl psing ptimescl pprimcl ppluscl x2))
def inductionOpB {n : ℕ} {P : ((OpRingoidWithMultAntiDistribTerm n) → Type)} : ((∀ (fin : (fin n)) , (P (v fin))) → ((∀ (x1 x2 : (OpRingoidWithMultAntiDistribTerm n)) , ((P x1) → ((P x2) → (P (timesOL x1 x2))))) → ((∀ (x1 : (OpRingoidWithMultAntiDistribTerm n)) , ((P x1) → (P (primOL x1)))) → ((∀ (x1 x2 : (OpRingoidWithMultAntiDistribTerm n)) , ((P x1) → ((P x2) → (P (plusOL x1 x2))))) → (∀ (x : (OpRingoidWithMultAntiDistribTerm n)) , (P x))))))
| pv ptimesol pprimol pplusol (v x1) := (pv x1)
| pv ptimesol pprimol pplusol (timesOL x1 x2) := (ptimesol _ _ (inductionOpB pv ptimesol pprimol pplusol x1) (inductionOpB pv ptimesol pprimol pplusol x2))
| pv ptimesol pprimol pplusol (primOL x1) := (pprimol _ (inductionOpB pv ptimesol pprimol pplusol x1))
| pv ptimesol pprimol pplusol (plusOL x1 x2) := (pplusol _ _ (inductionOpB pv ptimesol pprimol pplusol x1) (inductionOpB pv ptimesol pprimol pplusol x2))
def inductionOp {n : ℕ} {A : Type} {P : ((OpRingoidWithMultAntiDistribTerm2 n A) → Type)} : ((∀ (fin : (fin n)) , (P (v2 fin))) → ((∀ (x1 : A) , (P (sing2 x1))) → ((∀ (x1 x2 : (OpRingoidWithMultAntiDistribTerm2 n A)) , ((P x1) → ((P x2) → (P (timesOL2 x1 x2))))) → ((∀ (x1 : (OpRingoidWithMultAntiDistribTerm2 n A)) , ((P x1) → (P (primOL2 x1)))) → ((∀ (x1 x2 : (OpRingoidWithMultAntiDistribTerm2 n A)) , ((P x1) → ((P x2) → (P (plusOL2 x1 x2))))) → (∀ (x : (OpRingoidWithMultAntiDistribTerm2 n A)) , (P x)))))))
| pv2 psing2 ptimesol2 pprimol2 pplusol2 (v2 x1) := (pv2 x1)
| pv2 psing2 ptimesol2 pprimol2 pplusol2 (sing2 x1) := (psing2 x1)
| pv2 psing2 ptimesol2 pprimol2 pplusol2 (timesOL2 x1 x2) := (ptimesol2 _ _ (inductionOp pv2 psing2 ptimesol2 pprimol2 pplusol2 x1) (inductionOp pv2 psing2 ptimesol2 pprimol2 pplusol2 x2))
| pv2 psing2 ptimesol2 pprimol2 pplusol2 (primOL2 x1) := (pprimol2 _ (inductionOp pv2 psing2 ptimesol2 pprimol2 pplusol2 x1))
| pv2 psing2 ptimesol2 pprimol2 pplusol2 (plusOL2 x1 x2) := (pplusol2 _ _ (inductionOp pv2 psing2 ptimesol2 pprimol2 pplusol2 x1) (inductionOp pv2 psing2 ptimesol2 pprimol2 pplusol2 x2))
def stageB : (RingoidWithMultAntiDistribTerm → (Staged RingoidWithMultAntiDistribTerm))
| (timesL x1 x2) := (stage2 timesL (codeLift2 timesL) (stageB x1) (stageB x2))
| (primL x1) := (stage1 primL (codeLift1 primL) (stageB x1))
| (plusL x1 x2) := (stage2 plusL (codeLift2 plusL) (stageB x1) (stageB x2))
def stageCl {A : Type} : ((ClRingoidWithMultAntiDistribTerm A) → (Staged (ClRingoidWithMultAntiDistribTerm A)))
| (sing x1) := (Now (sing x1))
| (timesCl x1 x2) := (stage2 timesCl (codeLift2 timesCl) (stageCl x1) (stageCl x2))
| (primCl x1) := (stage1 primCl (codeLift1 primCl) (stageCl x1))
| (plusCl x1 x2) := (stage2 plusCl (codeLift2 plusCl) (stageCl x1) (stageCl x2))
def stageOpB {n : ℕ} : ((OpRingoidWithMultAntiDistribTerm n) → (Staged (OpRingoidWithMultAntiDistribTerm n)))
| (v x1) := (const (code (v x1)))
| (timesOL x1 x2) := (stage2 timesOL (codeLift2 timesOL) (stageOpB x1) (stageOpB x2))
| (primOL x1) := (stage1 primOL (codeLift1 primOL) (stageOpB x1))
| (plusOL x1 x2) := (stage2 plusOL (codeLift2 plusOL) (stageOpB x1) (stageOpB x2))
def stageOp {n : ℕ} {A : Type} : ((OpRingoidWithMultAntiDistribTerm2 n A) → (Staged (OpRingoidWithMultAntiDistribTerm2 n A)))
| (sing2 x1) := (Now (sing2 x1))
| (v2 x1) := (const (code (v2 x1)))
| (timesOL2 x1 x2) := (stage2 timesOL2 (codeLift2 timesOL2) (stageOp x1) (stageOp x2))
| (primOL2 x1) := (stage1 primOL2 (codeLift1 primOL2) (stageOp x1))
| (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))))
(primT : ((Repr A) → (Repr A)))
(plusT : ((Repr A) → ((Repr A) → (Repr A))))
end RingoidWithMultAntiDistrib |
b3b783cf8d34a046f8ddcdc329df81b3f4f34752 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/data/list/defs.lean | e53bdb01c3ee8285ef6a3086fbbb4607068ccfb6 | [] | 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 | 31,503 | lean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.option.defs
import Mathlib.logic.basic
import Mathlib.tactic.cache
import Mathlib.PostPort
universes u_1 u v w u_2
namespace Mathlib
/-!
## Definitions on lists
This file contains various definitions on lists. It does not contain
proofs about these definitions, those are contained in other files in `data/list`
-/
namespace list
/-- Returns whether a list is []. Returns a boolean even if `l = []` is not decidable. -/
def is_nil {α : Type u_1} : List α → Bool :=
sorry
protected instance has_sdiff {α : Type u} [DecidableEq α] : has_sdiff (List α) :=
has_sdiff.mk list.diff
/-- Split a list at an index.
split_at 2 [a, b, c] = ([a, b], [c]) -/
def split_at {α : Type u} : ℕ → List α → List α × List α :=
sorry
/-- An auxiliary function for `split_on_p`. -/
def split_on_p_aux {α : Type u} (P : α → Prop) [decidable_pred P] : List α → (List α → List α) → List (List α) :=
sorry
/-- Split a list at every element satisfying a predicate. -/
def split_on_p {α : Type u} (P : α → Prop) [decidable_pred P] (l : List α) : List (List α) :=
split_on_p_aux P l id
/-- Split a list at every occurrence of an element.
[1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]] -/
def split_on {α : Type u} [DecidableEq α] (a : α) (as : List α) : List (List α) :=
split_on_p (fun (_x : α) => _x = a) as
/-- Concatenate an element at the end of a list.
concat [a, b] c = [a, b, c] -/
@[simp] def concat {α : Type u} : List α → α → List α :=
sorry
/-- `head' xs` returns the first element of `xs` if `xs` is non-empty;
it returns `none` otherwise -/
@[simp] def head' {α : Type u} : List α → Option α :=
sorry
/-- Convert a list into an array (whose length is the length of `l`). -/
def to_array {α : Type u} (l : List α) : array (length l) α :=
d_array.mk fun (v : fin (length l)) => nth_le l (subtype.val v) sorry
/-- "inhabited" `nth` function: returns `default` instead of `none` in the case
that the index is out of bounds. -/
@[simp] def inth {α : Type u} [h : Inhabited α] (l : List α) (n : ℕ) : α :=
option.iget (nth l n)
/-- Apply a function to the nth tail of `l`. Returns the input without
using `f` if the index is larger than the length of the list.
modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c] -/
@[simp] def modify_nth_tail {α : Type u} (f : List α → List α) : ℕ → List α → List α :=
sorry
/-- Apply `f` to the head of the list, if it exists. -/
@[simp] def modify_head {α : Type u} (f : α → α) : List α → List α :=
sorry
/-- Apply `f` to the nth element of the list, if it exists. -/
def modify_nth {α : Type u} (f : α → α) : ℕ → List α → List α :=
modify_nth_tail (modify_head f)
/-- Apply `f` to the last element of `l`, if it exists. -/
@[simp] def modify_last {α : Type u} (f : α → α) : List α → List α :=
sorry
/-- `insert_nth n a l` inserts `a` into the list `l` after the first `n` elements of `l`
`insert_nth 2 1 [1, 2, 3, 4] = [1, 2, 1, 3, 4]`-/
def insert_nth {α : Type u} (n : ℕ) (a : α) : List α → List α :=
modify_nth_tail (List.cons a) n
/-- Take `n` elements from a list `l`. If `l` has less than `n` elements, append `n - length l`
elements `default α`. -/
def take' {α : Type u} [Inhabited α] (n : ℕ) : List α → List α :=
sorry
/-- Get the longest initial segment of the list whose members all satisfy `p`.
take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2] -/
def take_while {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α :=
sorry
/-- Fold a function `f` over the list from the left, returning the list
of partial results.
scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6] -/
def scanl {α : Type u} {β : Type v} (f : α → β → α) : α → List β → List α :=
sorry
/-- Auxiliary definition used to define `scanr`. If `scanr_aux f b l = (b', l')`
then `scanr f b l = b' :: l'` -/
def scanr_aux {α : Type u} {β : Type v} (f : α → β → β) (b : β) : List α → β × List β :=
sorry
/-- Fold a function `f` over the list from the right, returning the list
of partial results.
scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0] -/
def scanr {α : Type u} {β : Type v} (f : α → β → β) (b : β) (l : List α) : List β :=
sorry
/-- Product of a list.
prod [a, b, c] = ((1 * a) * b) * c -/
def prod {α : Type u} [Mul α] [HasOne α] : List α → α :=
foldl Mul.mul 1
/-- Sum of a list.
sum [a, b, c] = ((0 + a) + b) + c -/
-- Later this will be tagged with `to_additive`, but this can't be done yet because of import
-- dependencies.
def sum {α : Type u} [Add α] [HasZero α] : List α → α :=
foldl Add.add 0
/-- The alternating sum of a list. -/
def alternating_sum {G : Type u_1} [HasZero G] [Add G] [Neg G] : List G → G :=
sorry
/-- The alternating product of a list. -/
def alternating_prod {G : Type u_1} [HasOne G] [Mul G] [has_inv G] : List G → G :=
sorry
/-- Given a function `f : α → β ⊕ γ`, `partition_map f l` maps the list by `f`
whilst partitioning the result it into a pair of lists, `list β × list γ`,
partitioning the `sum.inl _` into the left list, and the `sum.inr _` into the right list.
`partition_map (id : ℕ ⊕ ℕ → ℕ ⊕ ℕ) [inl 0, inr 1, inl 2] = ([0,2], [1])` -/
def partition_map {α : Type u} {β : Type v} {γ : Type w} (f : α → β ⊕ γ) : List α → List β × List γ :=
sorry
/-- `find p l` is the first element of `l` satisfying `p`, or `none` if no such
element exists. -/
def find {α : Type u} (p : α → Prop) [decidable_pred p] : List α → Option α :=
sorry
/-- `mfind tac l` returns the first element of `l` on which `tac` succeeds, and
fails otherwise. -/
def mfind {α : Type u} {m : Type u → Type v} [Monad m] [alternative m] (tac : α → m PUnit) : List α → m α :=
mfirst fun (a : α) => tac a $> a
/-- `mbfind' p l` returns the first element `a` of `l` for which `p a` returns
true. `mbfind'` short-circuits, so `p` is not necessarily run on every `a` in
`l`. This is a monadic version of `list.find`. -/
def mbfind' {m : Type u → Type v} [Monad m] {α : Type u} (p : α → m (ulift Bool)) : List α → m (Option α) :=
sorry
/-- A variant of `mbfind'` with more restrictive universe levels. -/
def mbfind {m : Type → Type v} [Monad m] {α : Type} (p : α → m Bool) (xs : List α) : m (Option α) :=
mbfind' (Functor.map ulift.up ∘ p) xs
/-- `many p as` returns true iff `p` returns true for any element of `l`.
`many` short-circuits, so if `p` returns true for any element of `l`, later
elements are not checked. This is a monadic version of `list.any`. -/
-- Implementing this via `mbfind` would give us less universe polymorphism.
def many {m : Type → Type v} [Monad m] {α : Type u} (p : α → m Bool) : List α → m Bool :=
sorry
/-- `mall p as` returns true iff `p` returns true for all elements of `l`.
`mall` short-circuits, so if `p` returns false for any element of `l`, later
elements are not checked. This is a monadic version of `list.all`. -/
def mall {m : Type → Type v} [Monad m] {α : Type u} (p : α → m Bool) (as : List α) : m Bool :=
bnot <$> many (fun (a : α) => bnot <$> p a) as
/-- `mbor xs` runs the actions in `xs`, returning true if any of them returns
true. `mbor` short-circuits, so if an action returns true, later actions are
not run. This is a monadic version of `list.bor`. -/
def mbor {m : Type → Type v} [Monad m] : List (m Bool) → m Bool :=
many id
/-- `mband xs` runs the actions in `xs`, returning true if all of them return
true. `mband` short-circuits, so if an action returns false, later actions are
not run. This is a monadic version of `list.band`. -/
def mband {m : Type → Type v} [Monad m] : List (m Bool) → m Bool :=
mall id
/-- Auxiliary definition for `foldl_with_index`. -/
def foldl_with_index_aux {α : Type u} {β : Type v} (f : ℕ → α → β → α) : ℕ → α → List β → α :=
sorry
/-- Fold a list from left to right as with `foldl`, but the combining function
also receives each element's index. -/
def foldl_with_index {α : Type u} {β : Type v} (f : ℕ → α → β → α) (a : α) (l : List β) : α :=
foldl_with_index_aux f 0 a l
/-- Auxiliary definition for `foldr_with_index`. -/
def foldr_with_index_aux {α : Type u} {β : Type v} (f : ℕ → α → β → β) : ℕ → β → List α → β :=
sorry
/-- Fold a list from right to left as with `foldr`, but the combining function
also receives each element's index. -/
def foldr_with_index {α : Type u} {β : Type v} (f : ℕ → α → β → β) (b : β) (l : List α) : β :=
foldr_with_index_aux f 0 b l
/-- `find_indexes p l` is the list of indexes of elements of `l` that satisfy `p`. -/
def find_indexes {α : Type u} (p : α → Prop) [decidable_pred p] (l : List α) : List ℕ :=
foldr_with_index (fun (i : ℕ) (a : α) (is : List ℕ) => ite (p a) (i :: is) is) [] l
/-- Returns the elements of `l` that satisfy `p` together with their indexes in
`l`. The returned list is ordered by index. -/
def indexes_values {α : Type u} (p : α → Prop) [decidable_pred p] (l : List α) : List (ℕ × α) :=
foldr_with_index (fun (i : ℕ) (a : α) (l : List (ℕ × α)) => ite (p a) ((i, a) :: l) l) [] l
/-- `indexes_of a l` is the list of all indexes of `a` in `l`. For example:
```
indexes_of a [a, b, a, a] = [0, 2, 3]
```
-/
def indexes_of {α : Type u} [DecidableEq α] (a : α) : List α → List ℕ :=
find_indexes (Eq a)
/-- Monadic variant of `foldl_with_index`. -/
def mfoldl_with_index {m : Type v → Type w} [Monad m] {α : Type u_1} {β : Type v} (f : ℕ → β → α → m β) (b : β) (as : List α) : m β :=
foldl_with_index
(fun (i : ℕ) (ma : m β) (b : α) =>
do
let a ← ma
f i a b)
(pure b) as
/-- Monadic variant of `foldr_with_index`. -/
def mfoldr_with_index {m : Type v → Type w} [Monad m] {α : Type u_1} {β : Type v} (f : ℕ → α → β → m β) (b : β) (as : List α) : m β :=
foldr_with_index
(fun (i : ℕ) (a : α) (mb : m β) =>
do
let b ← mb
f i a b)
(pure b) as
/-- Auxiliary definition for `mmap_with_index`. -/
def mmap_with_index_aux {m : Type v → Type w} [Applicative m] {α : Type u_1} {β : Type v} (f : ℕ → α → m β) : ℕ → List α → m (List β) :=
sorry
/-- Applicative variant of `map_with_index`. -/
def mmap_with_index {m : Type v → Type w} [Applicative m] {α : Type u_1} {β : Type v} (f : ℕ → α → m β) (as : List α) : m (List β) :=
mmap_with_index_aux f 0 as
/-- Auxiliary definition for `mmap_with_index'`. -/
def mmap_with_index'_aux {m : Type v → Type w} [Applicative m] {α : Type u_1} (f : ℕ → α → m PUnit) : ℕ → List α → m PUnit :=
sorry
/-- A variant of `mmap_with_index` specialised to applicative actions which
return `unit`. -/
def mmap_with_index' {m : Type v → Type w} [Applicative m] {α : Type u_1} (f : ℕ → α → m PUnit) (as : List α) : m PUnit :=
mmap_with_index'_aux f 0 as
/-- `lookmap` is a combination of `lookup` and `filter_map`.
`lookmap f l` will apply `f : α → option α` to each element of the list,
replacing `a → b` at the first value `a` in the list such that `f a = some b`. -/
def lookmap {α : Type u} (f : α → Option α) : List α → List α :=
sorry
/-- `countp p l` is the number of elements of `l` that satisfy `p`. -/
def countp {α : Type u} (p : α → Prop) [decidable_pred p] : List α → ℕ :=
sorry
/-- `count a l` is the number of occurrences of `a` in `l`. -/
def count {α : Type u} [DecidableEq α] (a : α) : List α → ℕ :=
countp (Eq a)
/-- `is_prefix l₁ l₂`, or `l₁ <+: l₂`, means that `l₁` is a prefix of `l₂`,
that is, `l₂` has the form `l₁ ++ t` for some `t`. -/
def is_prefix {α : Type u} (l₁ : List α) (l₂ : List α) :=
∃ (t : List α), l₁ ++ t = l₂
/-- `is_suffix l₁ l₂`, or `l₁ <:+ l₂`, means that `l₁` is a suffix of `l₂`,
that is, `l₂` has the form `t ++ l₁` for some `t`. -/
def is_suffix {α : Type u} (l₁ : List α) (l₂ : List α) :=
∃ (t : List α), t ++ l₁ = l₂
/-- `is_infix l₁ l₂`, or `l₁ <:+: l₂`, means that `l₁` is a contiguous
substring of `l₂`, that is, `l₂` has the form `s ++ l₁ ++ t` for some `s, t`. -/
def is_infix {α : Type u} (l₁ : List α) (l₂ : List α) :=
∃ (s : List α), ∃ (t : List α), s ++ l₁ ++ t = l₂
infixl:50 " <+: " => Mathlib.list.is_prefix
infixl:50 " <:+ " => Mathlib.list.is_suffix
infixl:50 " <:+: " => Mathlib.list.is_infix
/-- `inits l` is the list of initial segments of `l`.
inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]] -/
@[simp] def inits {α : Type u} : List α → List (List α) :=
sorry
/-- `tails l` is the list of terminal segments of `l`.
tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []] -/
@[simp] def tails {α : Type u} : List α → List (List α) :=
sorry
def sublists'_aux {α : Type u} {β : Type v} : List α → (List α → List β) → List (List β) → List (List β) :=
sorry
/-- `sublists' l` is the list of all (non-contiguous) sublists of `l`.
It differs from `sublists` only in the order of appearance of the sublists;
`sublists'` uses the first element of the list as the MSB,
`sublists` uses the first element of the list as the LSB.
sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] -/
def sublists' {α : Type u} (l : List α) : List (List α) :=
sublists'_aux l id []
def sublists_aux {α : Type u} {β : Type v} : List α → (List α → List β → List β) → List β :=
sorry
/-- `sublists l` is the list of all (non-contiguous) sublists of `l`; cf. `sublists'`
for a different ordering.
sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] -/
def sublists {α : Type u} (l : List α) : List (List α) :=
[] :: sublists_aux l List.cons
def sublists_aux₁ {α : Type u} {β : Type v} : List α → (List α → List β) → List β :=
sorry
/-- `forall₂ R l₁ l₂` means that `l₁` and `l₂` have the same length,
and whenever `a` is the nth element of `l₁`, and `b` is the nth element of `l₂`,
then `R a b` is satisfied. -/
inductive forall₂ {α : Type u} {β : Type v} (R : α → β → Prop) : List α → List β → Prop
where
| nil : forall₂ R [] []
| cons : ∀ {a : α} {b : β} {l₁ : List α} {l₂ : List β}, R a b → forall₂ R l₁ l₂ → forall₂ R (a :: l₁) (b :: l₂)
/-- Auxiliary definition used to define `transpose`.
`transpose_aux l L` takes each element of `l` and appends it to the start of
each element of `L`.
`transpose_aux [a, b, c] [l₁, l₂, l₃] = [a::l₁, b::l₂, c::l₃]` -/
def transpose_aux {α : Type u} : List α → List (List α) → List (List α) :=
sorry
/-- transpose of a list of lists, treated as a matrix.
transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]] -/
def transpose {α : Type u} : List (List α) → List (List α) :=
sorry
/-- List of all sections through a list of lists. A section
of `[L₁, L₂, ..., Lₙ]` is a list whose first element comes from
`L₁`, whose second element comes from `L₂`, and so on. -/
def sections {α : Type u} : List (List α) → List (List α) :=
sorry
def permutations_aux2 {α : Type u} {β : Type v} (t : α) (ts : List α) (r : List β) : List α → (List α → β) → List α × List β :=
sorry
def permutations_aux.rec {α : Type u} {C : List α → List α → Sort v} (H0 : (is : List α) → C [] is) (H1 : (t : α) → (ts is : List α) → C ts (t :: is) → C is [] → C (t :: ts) is) (l₁ : List α) (l₂ : List α) : C l₁ l₂ :=
sorry
def permutations_aux {α : Type u} : List α → List α → List (List α) :=
sorry
/-- List of all permutations of `l`.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [3, 2, 1],
[2, 3, 1], [3, 1, 2], [1, 3, 2]] -/
def permutations {α : Type u} (l : List α) : List (List α) :=
l :: permutations_aux l []
/-- `erasep p l` removes the first element of `l` satisfying the predicate `p`. -/
def erasep {α : Type u} (p : α → Prop) [decidable_pred p] : List α → List α :=
sorry
/-- `extractp p l` returns a pair of an element `a` of `l` satisfying the predicate
`p`, and `l`, with `a` removed. If there is no such element `a` it returns `(none, l)`. -/
def extractp {α : Type u} (p : α → Prop) [decidable_pred p] : List α → Option α × List α :=
sorry
/-- `revzip l` returns a list of pairs of the elements of `l` paired
with the elements of `l` in reverse order.
`revzip [1,2,3,4,5] = [(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)]`
-/
def revzip {α : Type u} (l : List α) : List (α × α) :=
zip l (reverse l)
/-- `product l₁ l₂` is the list of pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂`.
product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
def product {α : Type u} {β : Type v} (l₁ : List α) (l₂ : List β) : List (α × β) :=
list.bind l₁ fun (a : α) => map (Prod.mk a) l₂
/-- `sigma l₁ l₂` is the list of dependent pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂ a`.
sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
protected def sigma {α : Type u} {σ : α → Type u_1} (l₁ : List α) (l₂ : (a : α) → List (σ a)) : List (sigma fun (a : α) => σ a) :=
list.bind l₁ fun (a : α) => map (sigma.mk a) (l₂ a)
/-- Auxliary definition used to define `of_fn`.
`of_fn_aux f m h l` returns the first `m` elements of `of_fn f`
appended to `l` -/
def of_fn_aux {α : Type u} {n : ℕ} (f : fin n → α) (m : ℕ) : m ≤ n → List α → List α :=
sorry
/-- `of_fn f` with `f : fin n → α` returns the list whose ith element is `f i`
`of_fun f = [f 0, f 1, ... , f(n - 1)]` -/
def of_fn {α : Type u} {n : ℕ} (f : fin n → α) : List α :=
of_fn_aux f n sorry []
/-- `of_fn_nth_val f i` returns `some (f i)` if `i < n` and `none` otherwise. -/
def of_fn_nth_val {α : Type u} {n : ℕ} (f : fin n → α) (i : ℕ) : Option α :=
dite (i < n) (fun (h : i < n) => some (f { val := i, property := h })) fun (h : ¬i < n) => none
/-- `disjoint l₁ l₂` means that `l₁` and `l₂` have no elements in common. -/
def disjoint {α : Type u} (l₁ : List α) (l₂ : List α) :=
∀ {a : α}, a ∈ l₁ → a ∈ l₂ → False
/-- `pairwise R l` means that all the elements with earlier indexes are
`R`-related to all the elements with later indexes.
pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3
For example if `R = (≠)` then it asserts `l` has no duplicates,
and if `R = (<)` then it asserts that `l` is (strictly) sorted. -/
inductive pairwise {α : Type u} (R : α → α → Prop) : List α → Prop
where
| nil : pairwise R []
| cons : ∀ {a : α} {l : List α}, (∀ (a' : α), a' ∈ l → R a a') → pairwise R l → pairwise R (a :: l)
@[simp] theorem pairwise_cons {α : Type u} {R : α → α → Prop} {a : α} {l : List α} : pairwise R (a :: l) ↔ (∀ (a' : α), a' ∈ l → R a a') ∧ pairwise R l := sorry
protected instance decidable_pairwise {α : Type u} {R : α → α → Prop} [DecidableRel R] (l : List α) : Decidable (pairwise R l) :=
List.rec (is_true pairwise.nil)
(fun (hd : α) (tl : List α) (ih : Decidable (pairwise R tl)) =>
decidable_of_iff' ((∀ (a' : α), a' ∈ tl → R hd a') ∧ pairwise R tl) pairwise_cons)
l
/-- `pw_filter R l` is a maximal sublist of `l` which is `pairwise R`.
`pw_filter (≠)` is the erase duplicates function (cf. `erase_dup`), and `pw_filter (<)` finds
a maximal increasing subsequence in `l`. For example,
pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4] -/
def pw_filter {α : Type u} (R : α → α → Prop) [DecidableRel R] : List α → List α :=
sorry
/-- `chain R a l` means that `R` holds between adjacent elements of `a::l`.
chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
inductive chain {α : Type u} (R : α → α → Prop) : α → List α → Prop
where
| nil : ∀ {a : α}, chain R a []
| cons : ∀ {a b : α} {l : List α}, R a b → chain R b l → chain R a (b :: l)
/-- `chain' R l` means that `R` holds between adjacent elements of `l`.
chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
def chain' {α : Type u} (R : α → α → Prop) : List α → Prop :=
sorry
@[simp] theorem chain_cons {α : Type u} {R : α → α → Prop} {a : α} {b : α} {l : List α} : chain R a (b :: l) ↔ R a b ∧ chain R b l := sorry
protected instance decidable_chain {α : Type u} {R : α → α → Prop} [DecidableRel R] (a : α) (l : List α) : Decidable (chain R a l) :=
List.rec (fun (a : α) => eq.mpr sorry decidable.true)
(fun (l_hd : α) (l_tl : List α) (l_ih : (a : α) → Decidable (chain R a l_tl)) (a : α) => eq.mpr sorry and.decidable) l
a
protected instance decidable_chain' {α : Type u} {R : α → α → Prop} [DecidableRel R] (l : List α) : Decidable (chain' R l) :=
list.cases_on l (id decidable.true) fun (l_hd : α) (l_tl : List α) => id (list.decidable_chain l_hd l_tl)
/-- `nodup l` means that `l` has no duplicates, that is, any element appears at most
once in the list. It is defined as `pairwise (≠)`. -/
def nodup {α : Type u} : List α → Prop :=
pairwise ne
protected instance nodup_decidable {α : Type u} [DecidableEq α] (l : List α) : Decidable (nodup l) :=
list.decidable_pairwise
/-- `erase_dup l` removes duplicates from `l` (taking only the first occurrence).
Defined as `pw_filter (≠)`.
erase_dup [1, 0, 2, 2, 1] = [0, 2, 1] -/
def erase_dup {α : Type u} [DecidableEq α] : List α → List α :=
pw_filter ne
/-- `range' s n` is the list of numbers `[s, s+1, ..., s+n-1]`.
It is intended mainly for proving properties of `range` and `iota`. -/
@[simp] def range' : ℕ → ℕ → List ℕ :=
sorry
/-- Drop `none`s from a list, and replace each remaining `some a` with `a`. -/
def reduce_option {α : Type u_1} : List (Option α) → List α :=
filter_map id
/-- `ilast' x xs` returns the last element of `xs` if `xs` is non-empty;
it returns `x` otherwise -/
@[simp] def ilast' {α : Type u_1} : α → List α → α :=
sorry
/-- `last' xs` returns the last element of `xs` if `xs` is non-empty;
it returns `none` otherwise -/
@[simp] def last' {α : Type u_1} : List α → Option α :=
sorry
/-- `rotate l n` rotates the elements of `l` to the left by `n`
rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1] -/
def rotate {α : Type u} (l : List α) (n : ℕ) : List α :=
sorry
/-- rotate' is the same as `rotate`, but slower. Used for proofs about `rotate`-/
def rotate' {α : Type u} : List α → ℕ → List α :=
sorry
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns both `a` and proofs
of `a ∈ l` and `p a`. -/
def choose_x {α : Type u} (p : α → Prop) [decidable_pred p] (l : List α) (hp : ∃ (a : α), a ∈ l ∧ p a) : Subtype fun (a : α) => a ∈ l ∧ p a :=
sorry
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns `a : α`, and properties
are given by `choose_mem` and `choose_property`. -/
def choose {α : Type u} (p : α → Prop) [decidable_pred p] (l : List α) (hp : ∃ (a : α), a ∈ l ∧ p a) : α :=
↑(choose_x p l hp)
/-- Filters and maps elements of a list -/
def mmap_filter {m : Type → Type v} [Monad m] {α : Type u_1} {β : Type} (f : α → m (Option β)) : List α → m (List β) :=
sorry
/--
`mmap_upper_triangle f l` calls `f` on all elements in the upper triangular part of `l × l`.
That is, for each `e ∈ l`, it will run `f e e` and then `f e e'`
for each `e'` that appears after `e` in `l`.
Example: suppose `l = [1, 2, 3]`. `mmap_upper_triangle f l` will produce the list
`[f 1 1, f 1 2, f 1 3, f 2 2, f 2 3, f 3 3]`.
-/
def mmap_upper_triangle {m : Type u → Type u_1} [Monad m] {α : Type u} {β : Type u} (f : α → α → m β) : List α → m (List β) :=
sorry
/--
`mmap'_diag f l` calls `f` on all elements in the upper triangular part of `l × l`.
That is, for each `e ∈ l`, it will run `f e e` and then `f e e'`
for each `e'` that appears after `e` in `l`.
Example: suppose `l = [1, 2, 3]`. `mmap'_diag f l` will evaluate, in this order,
`f 1 1`, `f 1 2`, `f 1 3`, `f 2 2`, `f 2 3`, `f 3 3`.
-/
def mmap'_diag {m : Type → Type u_1} [Monad m] {α : Type u_2} (f : α → α → m Unit) : List α → m Unit :=
sorry
protected def traverse {F : Type u → Type v} [Applicative F] {α : Type u_1} {β : Type u} (f : α → F β) : List α → F (List β) :=
sorry
/-- `get_rest l l₁` returns `some l₂` if `l = l₁ ++ l₂`.
If `l₁` is not a prefix of `l`, returns `none` -/
def get_rest {α : Type u} [DecidableEq α] : List α → List α → Option (List α) :=
sorry
/--
`list.slice n m xs` removes a slice of length `m` at index `n` in list `xs`.
-/
def slice {α : Type u_1} : ℕ → ℕ → List α → List α :=
sorry
/--
Left-biased version of `list.map₂`. `map₂_left' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is
applied to `none` for the remaining `aᵢ`. Returns the results of the `f`
applications and the remaining `bs`.
```
map₂_left' prod.mk [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
map₂_left' prod.mk [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
```
-/
@[simp] def map₂_left' {α : Type u} {β : Type v} {γ : Type w} (f : α → Option β → γ) : List α → List β → List γ × List β :=
sorry
/--
Right-biased version of `list.map₂`. `map₂_right' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is
applied to `none` for the remaining `bᵢ`. Returns the results of the `f`
applications and the remaining `as`.
```
map₂_right' prod.mk [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
map₂_right' prod.mk [1, 2] ['a'] = ([(some 1, 'a')], [2])
```
-/
def map₂_right' {α : Type u} {β : Type v} {γ : Type w} (f : Option α → β → γ) (as : List α) (bs : List β) : List γ × List α :=
map₂_left' (flip f) bs as
/--
Left-biased version of `list.zip`. `zip_left' as bs` returns the list of
pairs `(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, the
remaining `aᵢ` are paired with `none`. Also returns the remaining `bs`.
```
zip_left' [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
zip_left' [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
zip_left' = map₂_left' prod.mk
```
-/
def zip_left' {α : Type u} {β : Type v} : List α → List β → List (α × Option β) × List β :=
map₂_left' Prod.mk
/--
Right-biased version of `list.zip`. `zip_right' as bs` returns the list of
pairs `(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, the
remaining `bᵢ` are paired with `none`. Also returns the remaining `as`.
```
zip_right' [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
zip_right' [1, 2] ['a'] = ([(some 1, 'a')], [2])
zip_right' = map₂_right' prod.mk
```
-/
def zip_right' {α : Type u} {β : Type v} : List α → List β → List (Option α × β) × List α :=
map₂_right' Prod.mk
/--
Left-biased version of `list.map₂`. `map₂_left f as bs` applies `f` to each pair
`aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is applied to `none`
for the remaining `aᵢ`.
```
map₂_left prod.mk [1, 2] ['a'] = [(1, some 'a'), (2, none)]
map₂_left prod.mk [1] ['a', 'b'] = [(1, some 'a')]
map₂_left f as bs = (map₂_left' f as bs).fst
```
-/
@[simp] def map₂_left {α : Type u} {β : Type v} {γ : Type w} (f : α → Option β → γ) : List α → List β → List γ :=
sorry
/--
Right-biased version of `list.map₂`. `map₂_right f as bs` applies `f` to each
pair `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is applied to
`none` for the remaining `bᵢ`.
```
map₂_right prod.mk [1, 2] ['a'] = [(some 1, 'a')]
map₂_right prod.mk [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
map₂_right f as bs = (map₂_right' f as bs).fst
```
-/
def map₂_right {α : Type u} {β : Type v} {γ : Type w} (f : Option α → β → γ) (as : List α) (bs : List β) : List γ :=
map₂_left (flip f) bs as
/--
Left-biased version of `list.zip`. `zip_left as bs` returns the list of pairs
`(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, the
remaining `aᵢ` are paired with `none`.
```
zip_left [1, 2] ['a'] = [(1, some 'a'), (2, none)]
zip_left [1] ['a', 'b'] = [(1, some 'a')]
zip_left = map₂_left prod.mk
```
-/
def zip_left {α : Type u} {β : Type v} : List α → List β → List (α × Option β) :=
map₂_left Prod.mk
/--
Right-biased version of `list.zip`. `zip_right as bs` returns the list of pairs
`(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, the
remaining `bᵢ` are paired with `none`.
```
zip_right [1, 2] ['a'] = [(some 1, 'a')]
zip_right [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
zip_right = map₂_right prod.mk
```
-/
def zip_right {α : Type u} {β : Type v} : List α → List β → List (Option α × β) :=
map₂_right Prod.mk
/--
If all elements of `xs` are `some xᵢ`, `all_some xs` returns the `xᵢ`. Otherwise
it returns `none`.
```
all_some [some 1, some 2] = some [1, 2]
all_some [some 1, none ] = none
```
-/
def all_some {α : Type u} : List (Option α) → Option (List α) :=
sorry
/--
`fill_nones xs ys` replaces the `none`s in `xs` with elements of `ys`. If there
are not enough `ys` to replace all the `none`s, the remaining `none`s are
dropped from `xs`.
```
fill_nones [none, some 1, none, none] [2, 3] = [2, 1, 3]
```
-/
def fill_nones {α : Type u_1} : List (Option α) → List α → List α :=
sorry
/--
`take_list as ns` extracts successive sublists from `as`. For `ns = n₁ ... nₘ`,
it first takes the `n₁` initial elements from `as`, then the next `n₂` ones,
etc. It returns the sublists of `as` -- one for each `nᵢ` -- and the remaining
elements of `as`. If `as` does not have at least as many elements as the sum of
the `nᵢ`, the corresponding sublists will have less than `nᵢ` elements.
```
take_list ['a', 'b', 'c', 'd', 'e'] [2, 1, 1] = ([['a', 'b'], ['c'], ['d']], ['e'])
take_list ['a', 'b'] [3, 1] = ([['a', 'b'], []], [])
```
-/
def take_list {α : Type u_1} : List α → List ℕ → List (List α) × List α :=
sorry
/--
`to_rbmap as` is the map that associates each index `i` of `as` with the
corresponding element of `as`.
```
to_rbmap ['a', 'b', 'c'] = rbmap_of [(0, 'a'), (1, 'b'), (2, 'c')]
```
-/
def to_rbmap {α : Type u} : List α → rbmap ℕ α :=
foldl_with_index (fun (i : ℕ) (mapp : rbmap ℕ α) (a : α) => rbmap.insert mapp i a) (mk_rbmap ℕ α)
|
e0c5643145e5d7e21dd5a69db8d5ef2c269d130c | 1437b3495ef9020d5413178aa33c0a625f15f15f | /tactic/explode.lean | 93c3abf3d2b32b2309577412d6e8cfe5fe8ef927 | [
"Apache-2.0"
] | permissive | jean002/mathlib | c66bbb2d9fdc9c03ae07f869acac7ddbfce67a30 | dc6c38a765799c99c4d9c8d5207d9e6c9e0e2cfd | refs/heads/master | 1,587,027,806,375 | 1,547,306,358,000 | 1,547,306,358,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,141 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Displays a proof term in a line by line format somewhat akin to a Fitch style
proof or the Metamath proof style.
-/
import tactic.basic
open expr tactic
namespace tactic
namespace explode
-- TODO(Mario): move back to list.basic
@[simp] def head' {α} : list α → option α
| [] := none
| (a :: l) := some a
inductive status | reg | intro | lam | sintro
meta structure entry :=
(expr : expr)
(line : nat)
(depth : nat)
(status : status)
(thm : string)
(deps : list nat)
meta def pad_right (l : list string) : list string :=
let n := l.foldl (λ r (s:string), max r s.length) 0 in
l.map $ λ s, nat.iterate (λ s, s.push ' ') (n - s.length) s
meta structure entries := mk' ::
(s : expr_map entry)
(l : list entry)
meta def entries.find (es : entries) (e : expr) := es.s.find e
meta def entries.size (es : entries) := es.s.size
meta def entries.add : entries → entry → entries
| es@⟨s, l⟩ e := if s.contains e.expr then es else ⟨s.insert e.expr e, e :: l⟩
meta def entries.head (es : entries) : option entry := head' es.l
meta instance : inhabited entries := ⟨⟨expr_map.mk _, []⟩⟩
meta def format_aux : list string → list string → list string → list entry → tactic format
| (line :: lines) (dep :: deps) (thm :: thms) (en :: es) := do
fmt ← do {
let margin := string.join (list.repeat " │" en.depth),
let margin := match en.status with
| status.sintro := " ├" ++ margin
| status.intro := " │" ++ margin ++ " ┌"
| status.reg := " │" ++ margin ++ ""
| status.lam := " │" ++ margin ++ ""
end,
p ← infer_type en.expr >>= pp,
let lhs := line ++ "│" ++ dep ++ "│ " ++ thm ++ margin ++ " ",
return $ format.of_string lhs ++ to_string p ++ format.line },
(++ fmt) <$> format_aux lines deps thms es
| _ _ _ _ := return format.nil
meta instance : has_to_tactic_format entries :=
⟨λ es : entries,
let lines := pad_right $ es.l.map (λ en, to_string en.line),
deps := pad_right $ es.l.map (λ en, string.intercalate "," (en.deps.map to_string)),
thms := pad_right $ es.l.map entry.thm in
format_aux lines deps thms es.l⟩
meta def append_dep (filter : expr → tactic unit)
(es : entries) (e : expr) (deps : list nat) : tactic (list nat) :=
do { ei ← es.find e,
filter ei.expr,
return (ei.line :: deps) }
<|> return deps
meta def may_be_proof (e : expr) : tactic bool :=
is_proof e >>= λ b, return $
b || is_app e || is_local_constant e || is_pi e || is_lambda e
end explode
open explode
meta mutual def explode.core, explode.args (filter : expr → tactic unit)
with explode.core : expr → bool → nat → entries → tactic entries
| e@(lam n bi d b) si depth es := do
m ← mk_fresh_name,
let l := local_const m n bi d,
let b' := instantiate_var b l,
if si then
let en : entry := ⟨l, es.size, depth, status.sintro, to_string n, []⟩ in
explode.core b' si depth (es.add en)
else do
let en : entry := ⟨l, es.size, depth, status.intro, to_string n, []⟩,
es' ← explode.core b' si (depth + 1) (es.add en),
deps' ← explode.append_dep filter es' b' [],
deps' ← explode.append_dep filter es' l deps',
return $ es'.add ⟨e, es'.size, depth, status.lam, "∀I", deps'⟩
| e@(macro _ l) si depth es := explode.core l.head si depth es
| e si depth es := filter e >>
match get_app_fn_args e with
| (const n _, args) :=
explode.args e args depth es (to_string n) []
| (fn, []) := do
p ← pp fn,
let en : entry := ⟨fn, es.size, depth, status.reg, to_string p, []⟩,
return (es.add en)
| (fn, args) := do
es' ← explode.core fn ff depth es,
deps ← explode.append_dep filter es' fn [],
explode.args e args depth es' "∀E" deps
end
with explode.args : expr → list expr → nat → entries → string → list nat → tactic entries
| e (arg :: args) depth es thm deps := do
es' ← explode.core arg ff depth es <|> return es,
deps' ← explode.append_dep filter es' arg deps,
explode.args e args depth es' thm deps'
| e [] depth es thm deps :=
return (es.add ⟨e, es.size, depth, status.reg, thm, deps.reverse⟩)
meta def explode_expr (e : expr) (hide_non_prop := tt) : tactic entries :=
let filter := if hide_non_prop then λ e, may_be_proof e >>= guardb else λ _, skip in
tactic.explode.core filter e tt 0 (default _)
meta def explode (n : name) : tactic unit :=
do const n _ ← resolve_name n | fail "cannot resolve name",
d ← get_decl n,
v ← match d with
| (declaration.defn _ _ _ v _ _) := return v
| (declaration.thm _ _ _ v) := return v.get
| _ := fail "not a definition"
end,
t ← pp d.type,
explode_expr v <* trace (to_fmt n ++ " : " ++ t) >>= trace
open interactive lean lean.parser interaction_monad.result
@[user_command]
meta def explode_cmd (_ : parse $ tk "#explode") : parser unit :=
do n ← ident,
explode n
.
-- #explode iff_true_intro
-- #explode nat.strong_rec_on
end tactic
|
9e5edf6f8e9171215a622a4706ac6497a3f6f218 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /src/Lean/Elab/SetOption.lean | 29b70ffc67033766af6bd507c20165e6d59d8644 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | leanprover/lean4 | 4bdf9790294964627eb9be79f5e8f6157780b4cc | f1f9dc0f2f531af3312398999d8b8303fa5f096b | refs/heads/master | 1,693,360,665,786 | 1,693,350,868,000 | 1,693,350,868,000 | 129,571,436 | 2,827 | 311 | Apache-2.0 | 1,694,716,156,000 | 1,523,760,560,000 | Lean | UTF-8 | Lean | false | false | 1,558 | 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.Log
import Lean.Elab.InfoTree
namespace Lean.Elab
variable [Monad m] [MonadOptions m] [MonadExceptOf Exception m] [MonadRef m]
variable [AddErrorMessageContext m] [MonadLiftT (EIO Exception) m] [MonadInfoTree m]
def elabSetOption (id : Syntax) (val : Syntax) : m Options := do
let ref ← getRef
-- For completion purposes, we discard `val` and any later arguments.
-- We include the first argument (the keyword) for position information in case `id` is `missing`.
addCompletionInfo <| CompletionInfo.option (ref.setArgs (ref.getArgs[0:2]))
let optionName := id.getId.eraseMacroScopes
let decl ← IO.toEIO (fun (ex : IO.Error) => Exception.error ref ex.toString) (getOptionDecl optionName)
pushInfoLeaf <| .ofOptionInfo { stx := id, optionName, declName := decl.declName }
let rec setOption (val : DataValue) : m Options := do
unless decl.defValue.sameCtor val do throwError "type mismatch at set_option"
return (← getOptions).insert optionName val
match val.isStrLit? with
| some str => setOption (DataValue.ofString str)
| none =>
match val.isNatLit? with
| some num => setOption (DataValue.ofNat num)
| none =>
match val with
| Syntax.atom _ "true" => setOption (DataValue.ofBool true)
| Syntax.atom _ "false" => setOption (DataValue.ofBool false)
| _ =>
throwError "unexpected set_option value {val}"
end Lean.Elab
|
00c29b844e0daa4f52d9a3e04c0071ee7b6224a0 | 54d7e71c3616d331b2ec3845d31deb08f3ff1dea | /tests/lean/curly_notation.lean | 6144d3d7c81da05a77b31fae1e4bc3262c157b9e | [
"Apache-2.0"
] | permissive | pachugupta/lean | 6f3305c4292288311cc4ab4550060b17d49ffb1d | 0d02136a09ac4cf27b5c88361750e38e1f485a1a | refs/heads/master | 1,611,110,653,606 | 1,493,130,117,000 | 1,493,167,649,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 480 | lean | #check ({1, 2, 3} : set nat)
#check ({1} : set nat)
#check ({} : set nat)
definition s1 : set nat := {1, 2+3, 3, 4}
#print s1
definition s2 : set char := {#"a", #"b", #"c"}
#print s2
definition s3 : set string := {"hello", "world"}
#print s3
#check { a ∈ s1 | a > 1 }
#check { a in s1 | a > 1 }
set_option pp.unicode false
#check { a ∈ s1 | a > 2 }
definition a := 10
#check ({a, a} : set nat)
#check ({a, 1, a} : set nat)
#check ({a} : set nat)
#check { a // a > 0 }
|
721e05aaa8d92091cda3182cfb1d1950225a56a1 | 88892181780ff536a81e794003fe058062f06758 | /src/xena_challenge/challenge08.lean | f0859203d294387db2585626207465fa6de1abe8 | [] | no_license | AtnNn/lean-sandbox | fe2c44280444e8bb8146ab8ac391c82b480c0a2e | 8c68afbdc09213173aef1be195da7a9a86060a97 | refs/heads/master | 1,623,004,395,876 | 1,579,969,507,000 | 1,579,969,507,000 | 146,666,368 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 119 | lean | example (G : Type) [group G] (g h k : G) : (g * h * k⁻¹)⁻¹ = k * h⁻¹ * g⁻¹ :=
begin
simp [mul_assoc]
end
|
2a8cb7c4d9033e540aef6f961eed9ede20bfecdc | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/polynomial/field_division.lean | 3d38ef90ca1f0b3d5afeb4a3f5a3451a8a6c7f96 | [
"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,459 | lean | /-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johannes Hölzl, Scott Morrison, Jens Wagemaker
-/
import algebra.gcd_monoid.basic
import data.polynomial.derivative
import data.polynomial.ring_division
import data.set.pairwise
import ring_theory.coprime.lemmas
import ring_theory.euclidean_domain
/-!
# Theory of univariate polynomials
This file starts looking like the ring theory of $ R[X] $
-/
noncomputable theory
open_locale classical big_operators polynomial
namespace polynomial
universes u v w y z
variables {R : Type u} {S : Type v} {k : Type y} {A : Type z} {a b : R} {n : ℕ}
section is_domain
variables [comm_ring R] [is_domain R]
lemma prod_multiset_root_eq_finset_root {p : R[X]} :
(multiset.map (λ (a : R), X - C a) p.roots).prod =
∏ a in p.roots.to_finset, (X - C a) ^ root_multiplicity a p :=
by simp only [count_roots, finset.prod_multiset_map_count]
lemma roots_C_mul (p : R[X]) {a : R} (hzero : a ≠ 0) : (C a * p).roots = p.roots :=
begin
by_cases hpzero : p = 0,
{ simp only [hpzero, mul_zero] },
rw multiset.ext,
intro b,
have prodzero : C a * p ≠ 0,
{ simp only [hpzero, or_false, ne.def, mul_eq_zero, C_eq_zero, hzero, not_false_iff] },
rw [count_roots, count_roots, root_multiplicity_mul prodzero],
have mulzero : root_multiplicity b (C a) = 0,
{ simp only [hzero, root_multiplicity_eq_zero, eval_C, is_root.def, not_false_iff] },
simp only [mulzero, zero_add]
end
lemma derivative_root_multiplicity_of_root [char_zero R] {p : R[X]} {t : R} (hpt : p.is_root t) :
p.derivative.root_multiplicity t = p.root_multiplicity t - 1 :=
begin
rcases eq_or_ne p 0 with rfl | hp,
{ simp },
nth_rewrite 0 [←p.div_by_monic_mul_pow_root_multiplicity_eq t],
simp only [derivative_pow, derivative_mul, derivative_sub, derivative_X,
derivative_C, sub_zero, mul_one],
set n := p.root_multiplicity t - 1,
have hn : n + 1 = _ := tsub_add_cancel_of_le ((root_multiplicity_pos hp).mpr hpt),
rw ←hn,
set q := p /ₘ (X - C t) ^ (n + 1) with hq,
convert_to root_multiplicity t ((X - C t) ^ n * (derivative q * (X - C t) + q * ↑(n + 1))) = n,
{ congr,
rw [mul_add, mul_left_comm $ (X - C t) ^ n, ←pow_succ'],
congr' 1,
rw [mul_left_comm $ (X - C t) ^ n, mul_comm $ (X - C t) ^ n] },
have h : (derivative q * (X - C t) + q * ↑(n + 1)).eval t ≠ 0,
{ suffices : eval t q * ↑(n + 1) ≠ 0,
{ simpa },
refine mul_ne_zero _ (nat.cast_ne_zero.mpr n.succ_ne_zero),
convert eval_div_by_monic_pow_root_multiplicity_ne_zero t hp,
exact hn ▸ hq },
rw [root_multiplicity_mul, root_multiplicity_X_sub_C_pow, root_multiplicity_eq_zero h, add_zero],
refine mul_ne_zero (pow_ne_zero n $ X_sub_C_ne_zero t) _,
contrapose! h,
rw [h, eval_zero]
end
lemma root_multiplicity_sub_one_le_derivative_root_multiplicity [char_zero R] (p : R[X]) (t : R) :
p.root_multiplicity t - 1 ≤ p.derivative.root_multiplicity t :=
begin
by_cases p.is_root t,
{ exact (derivative_root_multiplicity_of_root h).symm.le },
{ rw [root_multiplicity_eq_zero h, zero_tsub],
exact zero_le _ }
end
section normalization_monoid
variables [normalization_monoid R]
instance : normalization_monoid R[X] :=
{ norm_unit := λ p, ⟨C ↑(norm_unit (p.leading_coeff)), C ↑(norm_unit (p.leading_coeff))⁻¹,
by rw [← ring_hom.map_mul, units.mul_inv, C_1], by rw [← ring_hom.map_mul, units.inv_mul, C_1]⟩,
norm_unit_zero := units.ext (by simp),
norm_unit_mul := λ p q hp0 hq0, units.ext (begin
dsimp,
rw [ne.def, ← leading_coeff_eq_zero] at *,
rw [leading_coeff_mul, norm_unit_mul hp0 hq0, units.coe_mul, C_mul],
end),
norm_unit_coe_units := λ u,
units.ext begin
rw [← mul_one u⁻¹, units.coe_mul, units.eq_inv_mul_iff_mul_eq],
dsimp,
rcases polynomial.is_unit_iff.1 ⟨u, rfl⟩ with ⟨_, ⟨w, rfl⟩, h2⟩,
rw [← h2, leading_coeff_C, norm_unit_coe_units, ← C_mul, units.mul_inv, C_1],
end }
@[simp]
lemma coe_norm_unit {p : R[X]} :
(norm_unit p : R[X]) = C ↑(norm_unit p.leading_coeff) :=
by simp [norm_unit]
lemma leading_coeff_normalize (p : R[X]) :
leading_coeff (normalize p) = normalize (leading_coeff p) := by simp
lemma monic.normalize_eq_self {p : R[X]} (hp : p.monic) :
normalize p = p :=
by simp only [polynomial.coe_norm_unit, normalize_apply, hp.leading_coeff, norm_unit_one,
units.coe_one, polynomial.C.map_one, mul_one]
lemma roots_normalize {p : R[X]} : (normalize p).roots = p.roots :=
by rw [normalize_apply, mul_comm, coe_norm_unit,
roots_C_mul _ (norm_unit (leading_coeff p)).ne_zero]
end normalization_monoid
end is_domain
section division_ring
variables [division_ring R] {p q : R[X]}
lemma degree_pos_of_ne_zero_of_nonunit (hp0 : p ≠ 0) (hp : ¬is_unit p) :
0 < degree p :=
lt_of_not_ge (λ h, begin
rw [eq_C_of_degree_le_zero h] at hp0 hp,
exact hp (is_unit.map C
(is_unit.mk0 (coeff p 0) (mt C_inj.2 (by simpa using hp0)))),
end)
lemma monic_mul_leading_coeff_inv (h : p ≠ 0) :
monic (p * C (leading_coeff p)⁻¹) :=
by rw [monic, leading_coeff_mul, leading_coeff_C,
mul_inv_cancel (show leading_coeff p ≠ 0, from mt leading_coeff_eq_zero.1 h)]
lemma degree_mul_leading_coeff_inv (p : R[X]) (h : q ≠ 0) :
degree (p * C (leading_coeff q)⁻¹) = degree p :=
have h₁ : (leading_coeff q)⁻¹ ≠ 0 :=
inv_ne_zero (mt leading_coeff_eq_zero.1 h),
by rw [degree_mul, degree_C h₁, add_zero]
@[simp] lemma map_eq_zero [semiring S] [nontrivial S] (f : R →+* S) :
p.map f = 0 ↔ p = 0 :=
by simp only [polynomial.ext_iff, f.map_eq_zero, coeff_map, coeff_zero]
lemma map_ne_zero [semiring S] [nontrivial S] {f : R →+* S} (hp : p ≠ 0) : p.map f ≠ 0 :=
mt (map_eq_zero f).1 hp
end division_ring
section field
variables [field R] {p q : R[X]}
lemma is_unit_iff_degree_eq_zero : is_unit p ↔ degree p = 0 :=
⟨degree_eq_zero_of_is_unit,
λ h, have degree p ≤ 0, by simp [*, le_refl],
have hc : coeff p 0 ≠ 0, from λ hc,
by rw [eq_C_of_degree_le_zero this, hc] at h;
simpa using h,
is_unit_iff_dvd_one.2 ⟨C (coeff p 0)⁻¹, begin
conv in p { rw eq_C_of_degree_le_zero this },
rw [← C_mul, _root_.mul_inv_cancel hc, C_1]
end⟩⟩
theorem irreducible_of_monic {p : R[X]} (hp1 : p.monic) (hp2 : p ≠ 1) :
irreducible p ↔ (∀ f g : R[X], f.monic → g.monic → f * g = p → f = 1 ∨ g = 1) :=
⟨λ hp3 f g hf hg hfg, or.cases_on (hp3.is_unit_or_is_unit hfg.symm)
(assume huf : is_unit f, or.inl $ eq_one_of_is_unit_of_monic hf huf)
(assume hug : is_unit g, or.inr $ eq_one_of_is_unit_of_monic hg hug),
λ hp3, ⟨mt (eq_one_of_is_unit_of_monic hp1) hp2, λ f g hp,
have hf : f ≠ 0, from λ hf, by { rw [hp, hf, zero_mul] at hp1, exact not_monic_zero hp1 },
have hg : g ≠ 0, from λ hg, by { rw [hp, hg, mul_zero] at hp1, exact not_monic_zero hp1 },
or.imp (λ hf, is_unit_of_mul_eq_one _ _ hf) (λ hg, is_unit_of_mul_eq_one _ _ hg) $
hp3 (f * C f.leading_coeff⁻¹) (g * C g.leading_coeff⁻¹)
(monic_mul_leading_coeff_inv hf) (monic_mul_leading_coeff_inv hg) $
by rw [mul_assoc, mul_left_comm _ g, ← mul_assoc, ← C_mul, ← mul_inv, ← leading_coeff_mul,
← hp, monic.def.1 hp1, inv_one, C_1, mul_one]⟩⟩
/-- Division of polynomials. See `polynomial.div_by_monic` for more details.-/
def div (p q : R[X]) :=
C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹))
/-- Remainder of polynomial division. See `polynomial.mod_by_monic` for more details. -/
def mod (p q : R[X]) :=
p %ₘ (q * C (leading_coeff q)⁻¹)
private lemma quotient_mul_add_remainder_eq_aux (p q : R[X]) :
q * div p q + mod p q = p :=
if h : q = 0 then by simp only [h, zero_mul, mod, mod_by_monic_zero, zero_add]
else begin
conv {to_rhs, rw ← mod_by_monic_add_div p (monic_mul_leading_coeff_inv h)},
rw [div, mod, add_comm, mul_assoc]
end
private lemma remainder_lt_aux (p : R[X]) (hq : q ≠ 0) :
degree (mod p q) < degree q :=
by rw ← degree_mul_leading_coeff_inv q hq; exact
degree_mod_by_monic_lt p (monic_mul_leading_coeff_inv hq)
instance : has_div R[X] := ⟨div⟩
instance : has_mod R[X] := ⟨mod⟩
lemma div_def : p / q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)) := rfl
lemma mod_def : p % q = p %ₘ (q * C (leading_coeff q)⁻¹) := rfl
lemma mod_by_monic_eq_mod (p : R[X]) (hq : monic q) : p %ₘ q = p % q :=
show p %ₘ q = p %ₘ (q * C (leading_coeff q)⁻¹), by simp only [monic.def.1 hq, inv_one, mul_one, C_1]
lemma div_by_monic_eq_div (p : R[X]) (hq : monic q) : p /ₘ q = p / q :=
show p /ₘ q = C (leading_coeff q)⁻¹ * (p /ₘ (q * C (leading_coeff q)⁻¹)),
by simp only [monic.def.1 hq, inv_one, C_1, one_mul, mul_one]
lemma mod_X_sub_C_eq_C_eval (p : R[X]) (a : R) : p % (X - C a) = C (p.eval a) :=
mod_by_monic_eq_mod p (monic_X_sub_C a) ▸ mod_by_monic_X_sub_C_eq_C_eval _ _
lemma mul_div_eq_iff_is_root : (X - C a) * (p / (X - C a)) = p ↔ is_root p a :=
div_by_monic_eq_div p (monic_X_sub_C a) ▸ mul_div_by_monic_eq_iff_is_root
instance : euclidean_domain R[X] :=
{ quotient := (/),
quotient_zero := by simp [div_def],
remainder := (%),
r := _,
r_well_founded := degree_lt_wf,
quotient_mul_add_remainder_eq := quotient_mul_add_remainder_eq_aux,
remainder_lt := λ p q hq, remainder_lt_aux _ hq,
mul_left_not_lt := λ p q hq, not_lt_of_ge (degree_le_mul_left _ hq),
.. polynomial.comm_ring,
.. polynomial.nontrivial }
lemma mod_eq_self_iff (hq0 : q ≠ 0) : p % q = p ↔ degree p < degree q :=
⟨λ h, h ▸ euclidean_domain.mod_lt _ hq0,
λ h, have ¬degree (q * C (leading_coeff q)⁻¹) ≤ degree p :=
not_le_of_gt $ by rwa degree_mul_leading_coeff_inv q hq0,
begin
rw [mod_def, mod_by_monic, dif_pos (monic_mul_leading_coeff_inv hq0)],
unfold div_mod_by_monic_aux,
simp only [this, false_and, if_false]
end⟩
lemma div_eq_zero_iff (hq0 : q ≠ 0) : p / q = 0 ↔ degree p < degree q :=
⟨λ h, by have := euclidean_domain.div_add_mod p q;
rwa [h, mul_zero, zero_add, mod_eq_self_iff hq0] at this,
λ h, have hlt : degree p < degree (q * C (leading_coeff q)⁻¹),
by rwa degree_mul_leading_coeff_inv q hq0,
have hm : monic (q * C (leading_coeff q)⁻¹) := monic_mul_leading_coeff_inv hq0,
by rw [div_def, (div_by_monic_eq_zero_iff hm).2 hlt, mul_zero]⟩
lemma degree_add_div (hq0 : q ≠ 0) (hpq : degree q ≤ degree p) :
degree q + degree (p / q) = degree p :=
have degree (p % q) < degree (q * (p / q)) :=
calc degree (p % q) < degree q : euclidean_domain.mod_lt _ hq0
... ≤ _ : degree_le_mul_left _ (mt (div_eq_zero_iff hq0).1 (not_lt_of_ge hpq)),
by conv_rhs { rw [← euclidean_domain.div_add_mod p q,
degree_add_eq_left_of_degree_lt this, degree_mul] }
lemma degree_div_le (p q : R[X]) : degree (p / q) ≤ degree p :=
if hq : q = 0 then by simp [hq]
else by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq];
exact degree_div_by_monic_le _ _
lemma degree_div_lt (hp : p ≠ 0) (hq : 0 < degree q) : degree (p / q) < degree p :=
have hq0 : q ≠ 0, from λ hq0, by simpa [hq0] using hq,
by rw [div_def, mul_comm, degree_mul_leading_coeff_inv _ hq0];
exact degree_div_by_monic_lt _ (monic_mul_leading_coeff_inv hq0) hp
(by rw degree_mul_leading_coeff_inv _ hq0; exact hq)
@[simp] lemma degree_map [division_ring k] (p : R[X]) (f : R →+* k) :
degree (p.map f) = degree p :=
p.degree_map_eq_of_injective f.injective
@[simp] lemma nat_degree_map [division_ring k] (f : R →+* k) :
nat_degree (p.map f) = nat_degree p :=
nat_degree_eq_of_degree_eq (degree_map _ f)
@[simp] lemma leading_coeff_map [division_ring k] (f : R →+* k) :
leading_coeff (p.map f) = f (leading_coeff p) :=
by simp only [← coeff_nat_degree, coeff_map f, nat_degree_map]
theorem monic_map_iff [division_ring k] {f : R →+* k} {p : R[X]} :
(p.map f).monic ↔ p.monic :=
by rw [monic, leading_coeff_map, ← f.map_one, function.injective.eq_iff f.injective, monic]
theorem is_unit_map [field k] (f : R →+* k) :
is_unit (p.map f) ↔ is_unit p :=
by simp_rw [is_unit_iff_degree_eq_zero, degree_map]
lemma map_div [field k] (f : R →+* k) :
(p / q).map f = p.map f / q.map f :=
if hq0 : q = 0 then by simp [hq0]
else
by rw [div_def, div_def, polynomial.map_mul, map_div_by_monic f (monic_mul_leading_coeff_inv hq0)];
simp [f.map_inv, coeff_map f]
lemma map_mod [field k] (f : R →+* k) :
(p % q).map f = p.map f % q.map f :=
if hq0 : q = 0 then by simp [hq0]
else by rw [mod_def, mod_def, leading_coeff_map f, ← f.map_inv, ← map_C f,
← polynomial.map_mul f, map_mod_by_monic f (monic_mul_leading_coeff_inv hq0)]
section
open euclidean_domain
theorem gcd_map [field k] (f : R →+* k) :
gcd (p.map f) (q.map f) = (gcd p q).map f :=
gcd.induction p q (λ x, by simp_rw [polynomial.map_zero, euclidean_domain.gcd_zero_left]) $
λ x y hx ih,
by rw [gcd_val, ← map_mod, ih, ← gcd_val]
end
lemma eval₂_gcd_eq_zero [comm_semiring k] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hf : f.eval₂ ϕ α = 0) (hg : g.eval₂ ϕ α = 0) : (euclidean_domain.gcd f g).eval₂ ϕ α = 0 :=
by rw [euclidean_domain.gcd_eq_gcd_ab f g, polynomial.eval₂_add, polynomial.eval₂_mul,
polynomial.eval₂_mul, hf, hg, zero_mul, zero_mul, zero_add]
lemma eval_gcd_eq_zero {f g : R[X]} {α : R} (hf : f.eval α = 0) (hg : g.eval α = 0) :
(euclidean_domain.gcd f g).eval α = 0 := eval₂_gcd_eq_zero hf hg
lemma root_left_of_root_gcd [comm_semiring k] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (euclidean_domain.gcd f g).eval₂ ϕ α = 0) : f.eval₂ ϕ α = 0 :=
by { cases euclidean_domain.gcd_dvd_left f g with p hp,
rw [hp, polynomial.eval₂_mul, hα, zero_mul] }
lemma root_right_of_root_gcd [comm_semiring k] {ϕ : R →+* k} {f g : R[X]} {α : k}
(hα : (euclidean_domain.gcd f g).eval₂ ϕ α = 0) : g.eval₂ ϕ α = 0 :=
by { cases euclidean_domain.gcd_dvd_right f g with p hp,
rw [hp, polynomial.eval₂_mul, hα, zero_mul] }
lemma root_gcd_iff_root_left_right [comm_semiring k] {ϕ : R →+* k} {f g : R[X]} {α : k} :
(euclidean_domain.gcd f g).eval₂ ϕ α = 0 ↔ (f.eval₂ ϕ α = 0) ∧ (g.eval₂ ϕ α = 0) :=
⟨λ h, ⟨root_left_of_root_gcd h, root_right_of_root_gcd h⟩, λ h, eval₂_gcd_eq_zero h.1 h.2⟩
lemma is_root_gcd_iff_is_root_left_right {f g : R[X]} {α : R} :
(euclidean_domain.gcd f g).is_root α ↔ f.is_root α ∧ g.is_root α :=
root_gcd_iff_root_left_right
theorem is_coprime_map [field k] (f : R →+* k) :
is_coprime (p.map f) (q.map f) ↔ is_coprime p q :=
by rw [← euclidean_domain.gcd_is_unit_iff, ← euclidean_domain.gcd_is_unit_iff, gcd_map, is_unit_map]
lemma mem_roots_map [field k] {f : R →+* k} {x : k} (hp : p ≠ 0) :
x ∈ (p.map f).roots ↔ p.eval₂ f x = 0 :=
begin
rw mem_roots (show p.map f ≠ 0, by exact map_ne_zero hp),
dsimp only [is_root],
rw polynomial.eval_map,
end
lemma mem_root_set [field k] [algebra R k] {x : k} (hp : p ≠ 0) :
x ∈ p.root_set k ↔ aeval x p = 0 :=
iff.trans multiset.mem_to_finset (mem_roots_map hp)
lemma root_set_C_mul_X_pow {R S : Type*} [field R] [field S] [algebra R S]
{n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : (C a * X ^ n).root_set S = {0} :=
begin
ext x,
rw [set.mem_singleton_iff, mem_root_set, aeval_mul, aeval_C, aeval_X_pow, mul_eq_zero],
{ simp_rw [ring_hom.map_eq_zero, pow_eq_zero_iff (nat.pos_of_ne_zero hn), or_iff_right_iff_imp],
exact λ ha', (ha ha').elim },
{ exact mul_ne_zero (mt C_eq_zero.mp ha) (pow_ne_zero n X_ne_zero) },
end
lemma root_set_monomial {R S : Type*} [field R] [field S] [algebra R S]
{n : ℕ} (hn : n ≠ 0) {a : R} (ha : a ≠ 0) : (monomial n a).root_set S = {0} :=
by rw [←C_mul_X_pow_eq_monomial, root_set_C_mul_X_pow hn ha]
lemma root_set_X_pow {R S : Type*} [field R] [field S] [algebra R S]
{n : ℕ} (hn : n ≠ 0) : (X ^ n : R[X]).root_set S = {0} :=
by { rw [←one_mul (X ^ n : R[X]), ←C_1, root_set_C_mul_X_pow hn], exact one_ne_zero }
lemma exists_root_of_degree_eq_one (h : degree p = 1) : ∃ x, is_root p x :=
⟨-(p.coeff 0 / p.coeff 1),
have p.coeff 1 ≠ 0,
by rw ← nat_degree_eq_of_degree_eq_some h;
exact mt leading_coeff_eq_zero.1 (λ h0, by simpa [h0] using h),
by conv in p { rw [eq_X_add_C_of_degree_le_one (show degree p ≤ 1, by rw h; exact le_rfl)] };
simp [is_root, mul_div_cancel' _ this]⟩
lemma coeff_inv_units (u : R[X]ˣ) (n : ℕ) :
((↑u : R[X]).coeff n)⁻¹ = ((↑u⁻¹ : R[X]).coeff n) :=
begin
rw [eq_C_of_degree_eq_zero (degree_coe_units u), eq_C_of_degree_eq_zero (degree_coe_units u⁻¹),
coeff_C, coeff_C, inv_eq_one_div],
split_ifs,
{ rw [div_eq_iff_mul_eq (coeff_coe_units_zero_ne_zero u), coeff_zero_eq_eval_zero,
coeff_zero_eq_eval_zero, ← eval_mul, ← units.coe_mul, inv_mul_self];
simp },
{ simp }
end
lemma monic_normalize (hp0 : p ≠ 0) : monic (normalize p) :=
begin
rw [ne.def, ← leading_coeff_eq_zero, ← ne.def, ← is_unit_iff_ne_zero] at hp0,
rw [monic, leading_coeff_normalize, normalize_eq_one],
apply hp0,
end
lemma leading_coeff_div (hpq : q.degree ≤ p.degree) :
(p / q).leading_coeff = p.leading_coeff / q.leading_coeff :=
begin
by_cases hq : q = 0, { simp [hq] },
rw [div_def, leading_coeff_mul, leading_coeff_C,
leading_coeff_div_by_monic_of_monic (monic_mul_leading_coeff_inv hq) _,
mul_comm, div_eq_mul_inv],
rwa [degree_mul_leading_coeff_inv q hq]
end
lemma div_C_mul : p / (C a * q) = C a⁻¹ * (p / q) :=
begin
by_cases ha : a = 0,
{ simp [ha] },
simp only [div_def, leading_coeff_mul, mul_inv,
leading_coeff_C, C.map_mul, mul_assoc],
congr' 3,
rw [mul_left_comm q, ← mul_assoc, ← C.map_mul, mul_inv_cancel ha,
C.map_one, one_mul]
end
lemma C_mul_dvd (ha : a ≠ 0) : C a * p ∣ q ↔ p ∣ q :=
⟨λ h, dvd_trans (dvd_mul_left _ _) h, λ ⟨r, hr⟩, ⟨C a⁻¹ * r,
by rw [mul_assoc, mul_left_comm p, ← mul_assoc, ← C.map_mul, _root_.mul_inv_cancel ha,
C.map_one, one_mul, hr]⟩⟩
lemma dvd_C_mul (ha : a ≠ 0) : p ∣ polynomial.C a * q ↔ p ∣ q :=
⟨λ ⟨r, hr⟩, ⟨C a⁻¹ * r,
by rw [mul_left_comm p, ← hr, ← mul_assoc, ← C.map_mul, _root_.inv_mul_cancel ha,
C.map_one, one_mul]⟩,
λ h, dvd_trans h (dvd_mul_left _ _)⟩
lemma coe_norm_unit_of_ne_zero (hp : p ≠ 0) : (norm_unit p : R[X]) = C p.leading_coeff⁻¹ :=
have p.leading_coeff ≠ 0 := mt leading_coeff_eq_zero.mp hp,
by simp [comm_group_with_zero.coe_norm_unit _ this]
lemma normalize_monic (h : monic p) : normalize p = p := by simp [h]
theorem map_dvd_map' [field k] (f : R →+* k) {x y : R[X]} : x.map f ∣ y.map f ↔ x ∣ y :=
if H : x = 0 then by rw [H, polynomial.map_zero, zero_dvd_iff, zero_dvd_iff, map_eq_zero]
else by rw [← normalize_dvd_iff, ← @normalize_dvd_iff R[X],
normalize_apply, normalize_apply,
coe_norm_unit_of_ne_zero H, coe_norm_unit_of_ne_zero (mt (map_eq_zero f).1 H),
leading_coeff_map, ← f.map_inv, ← map_C, ← polynomial.map_mul,
map_dvd_map _ f.injective (monic_mul_leading_coeff_inv H)]
lemma degree_normalize : degree (normalize p) = degree p := by simp
lemma prime_of_degree_eq_one (hp1 : degree p = 1) : prime p :=
have prime (normalize p),
from monic.prime_of_degree_eq_one (hp1 ▸ degree_normalize)
(monic_normalize (λ hp0, absurd hp1 (hp0.symm ▸ by simp; exact dec_trivial))),
(normalize_associated _).prime this
lemma irreducible_of_degree_eq_one (hp1 : degree p = 1) : irreducible p :=
(prime_of_degree_eq_one hp1).irreducible
theorem not_irreducible_C (x : R) : ¬irreducible (C x) :=
if H : x = 0 then by { rw [H, C_0], exact not_irreducible_zero }
else λ hx, irreducible.not_unit hx $ is_unit_C.2 $ is_unit_iff_ne_zero.2 H
theorem degree_pos_of_irreducible (hp : irreducible p) : 0 < p.degree :=
lt_of_not_ge $ λ hp0, have _ := eq_C_of_degree_le_zero hp0,
not_irreducible_C (p.coeff 0) $ this ▸ hp
theorem pairwise_coprime_X_sub {α : Type u} [field α] {I : Type v}
{s : I → α} (H : function.injective s) :
pairwise (is_coprime on (λ i : I, polynomial.X - polynomial.C (s i))) :=
λ i j hij, have h : s j - s i ≠ 0, from sub_ne_zero_of_ne $ function.injective.ne H hij.symm,
⟨polynomial.C (s j - s i)⁻¹, -polynomial.C (s j - s i)⁻¹,
by rw [neg_mul, ← sub_eq_add_neg, ← mul_sub, sub_sub_sub_cancel_left,
← polynomial.C_sub, ← polynomial.C_mul, inv_mul_cancel h, polynomial.C_1]⟩
/-- If `f` is a polynomial over a field, and `a : K` satisfies `f' a ≠ 0`,
then `f / (X - a)` is coprime with `X - a`.
Note that we do not assume `f a = 0`, because `f / (X - a) = (f - f a) / (X - a)`. -/
lemma is_coprime_of_is_root_of_eval_derivative_ne_zero {K : Type*} [field K]
(f : K[X]) (a : K) (hf' : f.derivative.eval a ≠ 0) :
is_coprime (X - C a : K[X]) (f /ₘ (X - C a)) :=
begin
refine or.resolve_left (euclidean_domain.dvd_or_coprime (X - C a) (f /ₘ (X - C a))
(irreducible_of_degree_eq_one (polynomial.degree_X_sub_C a))) _,
contrapose! hf' with h,
have key : (X - C a) * (f /ₘ (X - C a)) = f - (f %ₘ (X - C a)),
{ rw [eq_sub_iff_add_eq, ← eq_sub_iff_add_eq', mod_by_monic_eq_sub_mul_div],
exact monic_X_sub_C a },
replace key := congr_arg derivative key,
simp only [derivative_X, derivative_mul, one_mul, sub_zero, derivative_sub,
mod_by_monic_X_sub_C_eq_C_eval, derivative_C] at key,
have : (X - C a) ∣ derivative f := key ▸ (dvd_add h (dvd_mul_right _ _)),
rw [← dvd_iff_mod_by_monic_eq_zero (monic_X_sub_C _), mod_by_monic_X_sub_C_eq_C_eval] at this,
rw [← C_inj, this, C_0],
end
/-- The product `∏ (X - a)` for `a` inside the multiset `p.roots` divides `p`. -/
lemma prod_multiset_X_sub_C_dvd (p : R[X]) :
(multiset.map (λ (a : R), X - C a) p.roots).prod ∣ p :=
begin
rw prod_multiset_root_eq_finset_root,
have hcoprime : pairwise (is_coprime on λ (a : R), polynomial.X - C (id a)) :=
pairwise_coprime_X_sub function.injective_id,
have H : pairwise (is_coprime on λ (a : R), (polynomial.X - C (id a)) ^ (root_multiplicity a p)),
{ intros a b hdiff, exact (hcoprime a b hdiff).pow },
apply finset.prod_dvd_of_coprime (H.set_pairwise (↑(multiset.to_finset p.roots) : set R)),
intros a h,
rw multiset.mem_to_finset at h,
exact pow_root_multiplicity_dvd p a
end
end field
end polynomial
|
06cac5e11edb309a91940ff0b990c56cd0a4068c | aa3f8992ef7806974bc1ffd468baa0c79f4d6643 | /tests/lean/run/nat_bug5.lean | a246fb62c0c11aaec25a3f8c224faea7c79b99b9 | [
"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,307 | lean | import standard
using num eq_proofs
inductive nat : Type :=
zero : nat,
succ : nat → nat
namespace nat
definition add (x y : nat) : nat := nat.rec x (λn r, succ r) y
infixl `+` := add
definition mul (n m : nat) := nat.rec zero (fun m x, x + n) m
infixl `*` := mul
axiom add_one (n:nat) : n + (succ zero) = succ n
axiom mul_zero_right (n : nat) : n * zero = zero
axiom add_zero_right (n : nat) : n + zero = n
axiom mul_succ_right (n m : nat) : n * succ m = n * m + n
axiom add_assoc (n m k : nat) : (n + m) + k = n + (m + k)
axiom add_right_comm (n m k : nat) : n + m + k = n + k + m
set_option unifier.max_steps 50000
theorem mul_add_distr_left (n m k : nat) : (n + m) * k = n * k + m * k
:= induction_on k
(calc
(n + m) * zero = zero : eq.refl _
... = n * zero + m * zero : eq.refl _)
(take l IH,
calc
(n + m) * succ l = (n + m) * l + (n + m) : mul_succ_right _ _
... = n * l + m * l + (n + m) : {IH}
... = n * l + m * l + n + m : symm (add_assoc _ _ _)
... = n * l + n + m * l + m : {add_right_comm _ _ _}
... = n * l + n + (m * l + m) : add_assoc _ _ _
... = n * succ l + (m * l + m) : {symm (mul_succ_right _ _)}
... = n * succ l + m * succ l : {symm (mul_succ_right _ _)})
end nat
end foo
|
138ccad6ad9c117b7459723d11a550291df7c162 | 717dd237d6a1fdd246152ec47f261c5244f9eba6 | /imo/src/testing.lean | 6c3fc7a5253c1c1749cd677afacb1e219aa2d852 | [] | no_license | lacker/kata | 32866813a6097218878f0ce327040d65a0aeb145 | 96b1d63e395c8cf02dc6abbbb5253f4cfe5fded6 | refs/heads/master | 1,692,275,692,563 | 1,691,955,719,000 | 1,691,955,719,000 | 87,217,280 | 19 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 15 | lean | import tactic
|
01d88de7b875c456b88370fbed93b60ce76b33cf | b70447c014d9e71cf619ebc9f539b262c19c2e0b | /hott/types/prod.hlean | 595e8288105852112304de29caaa894f2975a5a6 | [
"Apache-2.0"
] | permissive | ia0/lean2 | c20d8da69657f94b1d161f9590a4c635f8dc87f3 | d86284da630acb78fa5dc3b0b106153c50ffccd0 | refs/heads/master | 1,611,399,322,751 | 1,495,751,007,000 | 1,495,751,007,000 | 93,104,167 | 0 | 0 | null | 1,496,355,488,000 | 1,496,355,487,000 | null | UTF-8 | Lean | false | false | 10,694 | hlean | /-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Jakob von Raumer
Ported from Coq HoTT
Theorems about products
-/
open eq equiv is_equiv is_trunc prod prod.ops unit
variables {A A' B B' C D : Type} {P Q : A → Type}
{a a' a'' : A} {b b₁ b₂ b' b'' : B} {u v w : A × B}
namespace prod
/- Paths in a product space -/
protected definition eta [unfold 3] (u : A × B) : (pr₁ u, pr₂ u) = u :=
by cases u; reflexivity
definition pair_eq [unfold 7 8] (pa : a = a') (pb : b = b') : (a, b) = (a', b') :=
ap011 prod.mk pa pb
definition prod_eq [unfold 3 4 5 6] (H₁ : u.1 = v.1) (H₂ : u.2 = v.2) : u = v :=
by cases u; cases v; exact pair_eq H₁ H₂
definition eq_pr1 [unfold 5] (p : u = v) : u.1 = v.1 :=
ap pr1 p
definition eq_pr2 [unfold 5] (p : u = v) : u.2 = v.2 :=
ap pr2 p
namespace ops
postfix `..1`:(max+1) := eq_pr1
postfix `..2`:(max+1) := eq_pr2
end ops
open ops
protected definition ap_pr1 (p : u = v) : ap pr1 p = p..1 := idp
protected definition ap_pr2 (p : u = v) : ap pr2 p = p..2 := idp
definition pair_prod_eq (p : u.1 = v.1) (q : u.2 = v.2)
: ((prod_eq p q)..1, (prod_eq p q)..2) = (p, q) :=
by induction u; induction v; esimp at *; induction p; induction q; reflexivity
definition prod_eq_pr1 (p : u.1 = v.1) (q : u.2 = v.2) : (prod_eq p q)..1 = p :=
(pair_prod_eq p q)..1
definition prod_eq_pr2 (p : u.1 = v.1) (q : u.2 = v.2) : (prod_eq p q)..2 = q :=
(pair_prod_eq p q)..2
definition prod_eq_eta (p : u = v) : prod_eq (p..1) (p..2) = p :=
by induction p; induction u; reflexivity
-- the uncurried version of prod_eq. We will prove that this is an equivalence
definition prod_eq_unc [unfold 5] (H : u.1 = v.1 × u.2 = v.2) : u = v :=
by cases H with H₁ H₂; exact prod_eq H₁ H₂
definition pair_prod_eq_unc : Π(pq : u.1 = v.1 × u.2 = v.2),
((prod_eq_unc pq)..1, (prod_eq_unc pq)..2) = pq
| pair_prod_eq_unc (pq₁, pq₂) := pair_prod_eq pq₁ pq₂
definition prod_eq_unc_pr1 (pq : u.1 = v.1 × u.2 = v.2) : (prod_eq_unc pq)..1 = pq.1 :=
(pair_prod_eq_unc pq)..1
definition prod_eq_unc_pr2 (pq : u.1 = v.1 × u.2 = v.2) : (prod_eq_unc pq)..2 = pq.2 :=
(pair_prod_eq_unc pq)..2
definition prod_eq_unc_eta (p : u = v) : prod_eq_unc (p..1, p..2) = p :=
prod_eq_eta p
definition is_equiv_prod_eq [instance] [constructor] (u v : A × B)
: is_equiv (prod_eq_unc : u.1 = v.1 × u.2 = v.2 → u = v) :=
adjointify prod_eq_unc
(λp, (p..1, p..2))
prod_eq_unc_eta
pair_prod_eq_unc
definition prod_eq_equiv [constructor] (u v : A × B) : (u = v) ≃ (u.1 = v.1 × u.2 = v.2) :=
(equiv.mk prod_eq_unc _)⁻¹ᵉ
definition pair_eq_pair_equiv [constructor] (a a' : A) (b b' : B) :
((a, b) = (a', b')) ≃ (a = a' × b = b') :=
prod_eq_equiv (a, b) (a', b')
definition ap_prod_mk_left (p : a = a') : ap (λa, prod.mk a b) p = prod_eq p idp :=
ap_eq_ap011_left prod.mk p b
definition ap_prod_mk_right (p : b = b') : ap (λb, prod.mk a b) p = prod_eq idp p :=
ap_eq_ap011_right prod.mk a p
/- Groupoid structure -/
definition prod_eq_inv (p : a = a') (q : b = b') : (prod_eq p q)⁻¹ = prod_eq p⁻¹ q⁻¹ :=
by cases p; cases q; reflexivity
definition prod_eq_concat (p : a = a') (p' : a' = a'') (q : b = b') (q' : b' = b'')
: prod_eq p q ⬝ prod_eq p' q' = prod_eq (p ⬝ p') (q ⬝ q') :=
by cases p; cases q; cases p'; cases q'; reflexivity
definition prod_eq_concat_idp (p : a = a') (q : b = b')
: prod_eq p idp ⬝ prod_eq idp q = prod_eq p q :=
by cases p; cases q; reflexivity
/- Transport -/
definition prod_transport (p : a = a') (u : P a × Q a)
: p ▸ u = (p ▸ u.1, p ▸ u.2) :=
by induction p; induction u; reflexivity
definition prod_eq_transport (p : a = a') (q : b = b') {R : A × B → Type} (r : R (a, b))
: (prod_eq p q) ▸ r = p ▸ q ▸ r :=
by induction p; induction q; reflexivity
/- Pathovers -/
definition etao (p : a = a') (bc : P a × Q a) : bc =[p] (p ▸ bc.1, p ▸ bc.2) :=
by induction p; induction bc; apply idpo
definition prod_pathover (p : a = a') (u : P a × Q a) (v : P a' × Q a')
(r : u.1 =[p] v.1) (s : u.2 =[p] v.2) : u =[p] v :=
begin
induction u, induction v, esimp at *, induction r,
induction s using idp_rec_on,
apply idpo
end
/-
TODO:
* define the projections from the type u =[p] v
* show that the uncurried version of prod_pathover is an equivalence
-/
/- Functorial action -/
variables (f : A → A') (g : B → B')
definition prod_functor [unfold 7] (u : A × B) : A' × B' :=
(f u.1, g u.2)
definition ap_prod_functor (p : u.1 = v.1) (q : u.2 = v.2)
: ap (prod_functor f g) (prod_eq p q) = prod_eq (ap f p) (ap g q) :=
by induction u; induction v; esimp at *; induction p; induction q; reflexivity
/- Helpers for functions of two arguments -/
definition ap_diagonal {a a' : A} (p : a = a')
: ap (λx : A, (x,x)) p = prod_eq p p :=
by cases p; constructor
definition ap_binary (m : A → B → C) (p : a = a') (q : b = b')
: ap (λz : A × B, m z.1 z.2) (prod_eq p q)
= ap (m a) q ⬝ ap (λx : A, m x b') p :=
by cases p; cases q; constructor
definition ap_prod_elim {A B C : Type} {a a' : A} {b b' : B} (m : A → B → C)
(p : a = a') (q : b = b') : ap (prod.rec m) (prod_eq p q)
= ap (m a) q ⬝ ap (λx : A, m x b') p :=
by cases p; cases q; constructor
definition ap_prod_elim_idp {A B C : Type} {a a' : A} (m : A → B → C)
(p : a = a') (b : B) : ap (prod.rec m) (prod_eq p idp) = ap (λx : A, m x b) p :=
ap_prod_elim m p idp ⬝ !idp_con
/- Equivalences -/
definition is_equiv_prod_functor [instance] [constructor] [H : is_equiv f] [H : is_equiv g]
: is_equiv (prod_functor f g) :=
begin
apply adjointify _ (prod_functor f⁻¹ g⁻¹),
intro u, induction u, rewrite [▸*,right_inv f,right_inv g],
intro u, induction u, rewrite [▸*,left_inv f,left_inv g],
end
definition prod_equiv_prod_of_is_equiv [constructor] [H : is_equiv f] [H : is_equiv g]
: A × B ≃ A' × B' :=
equiv.mk (prod_functor f g) _
definition prod_equiv_prod [constructor] (f : A ≃ A') (g : B ≃ B') : A × B ≃ A' × B' :=
equiv.mk (prod_functor f g) _
-- rename
definition prod_equiv_prod_left [constructor] (g : B ≃ B') : A × B ≃ A × B' :=
prod_equiv_prod equiv.rfl g
-- rename
definition prod_equiv_prod_right [constructor] (f : A ≃ A') : A × B ≃ A' × B :=
prod_equiv_prod f equiv.rfl
/- Symmetry -/
definition is_equiv_flip [instance] [constructor] (A B : Type)
: is_equiv (flip : A × B → B × A) :=
adjointify flip
flip
(λu, destruct u (λb a, idp))
(λu, destruct u (λa b, idp))
definition prod_comm_equiv [constructor] (A B : Type) : A × B ≃ B × A :=
equiv.mk flip _
/- Associativity -/
definition prod_assoc_equiv [constructor] (A B C : Type) : A × (B × C) ≃ (A × B) × C :=
begin
fapply equiv.MK,
{ intro z, induction z with a z, induction z with b c, exact (a, b, c)},
{ intro z, induction z with z c, induction z with a b, exact (a, (b, c))},
{ intro z, induction z with z c, induction z with a b, reflexivity},
{ intro z, induction z with a z, induction z with b c, reflexivity},
end
definition prod_contr_equiv [constructor] (A B : Type) [H : is_contr B] : A × B ≃ A :=
equiv.MK pr1
(λx, (x, !center))
(λx, idp)
(λx, by cases x with a b; exact pair_eq idp !center_eq)
definition prod_unit_equiv [constructor] (A : Type) : A × unit ≃ A :=
!prod_contr_equiv
definition prod_empty_equiv (A : Type) : A × empty ≃ empty :=
begin
fapply equiv.MK,
{ intro x, cases x with a e, cases e },
{ intro e, cases e },
{ intro e, cases e },
{ intro x, cases x with a e, cases e }
end
/- Universal mapping properties -/
definition is_equiv_prod_rec [instance] [constructor] (P : A × B → Type)
: is_equiv (prod.rec : (Πa b, P (a, b)) → Πu, P u) :=
adjointify _
(λg a b, g (a, b))
(λg, eq_of_homotopy (λu, by induction u;reflexivity))
(λf, idp)
definition equiv_prod_rec [constructor] (P : A × B → Type) : (Πa b, P (a, b)) ≃ (Πu, P u) :=
equiv.mk prod.rec _
definition imp_imp_equiv_prod_imp [constructor] (A B C : Type) : (A → B → C) ≃ (A × B → C) :=
!equiv_prod_rec
definition prod_corec_unc [unfold 4] {P Q : A → Type} (u : (Πa, P a) × (Πa, Q a)) (a : A)
: P a × Q a :=
(u.1 a, u.2 a)
definition is_equiv_prod_corec [constructor] (P Q : A → Type)
: is_equiv (prod_corec_unc : (Πa, P a) × (Πa, Q a) → Πa, P a × Q a) :=
adjointify _
(λg, (λa, (g a).1, λa, (g a).2))
(by intro g; apply eq_of_homotopy; intro a; esimp; induction (g a); reflexivity)
(by intro h; induction h with f g; reflexivity)
definition equiv_prod_corec [constructor] (P Q : A → Type)
: ((Πa, P a) × (Πa, Q a)) ≃ (Πa, P a × Q a) :=
equiv.mk _ !is_equiv_prod_corec
definition imp_prod_imp_equiv_imp_prod [constructor] (A B C : Type)
: (A → B) × (A → C) ≃ (A → (B × C)) :=
!equiv_prod_corec
theorem is_trunc_prod (A B : Type) (n : trunc_index) [HA : is_trunc n A] [HB : is_trunc n B]
: is_trunc n (A × B) :=
begin
revert A B HA HB, induction n with n IH, all_goals intro A B HA HB,
{ fapply is_contr.mk,
exact (!center, !center),
intro u, apply prod_eq, all_goals apply center_eq},
{ apply is_trunc_succ_intro, intro u v,
apply is_trunc_equiv_closed_rev, apply prod_eq_equiv,
exact IH _ _ _ _}
end
end prod
attribute prod.is_trunc_prod [instance] [priority 1510]
namespace prod
/- pointed products -/
open pointed
definition pointed_prod [instance] [constructor] (A B : Type) [H1 : pointed A] [H2 : pointed B]
: pointed (A × B) :=
pointed.mk (pt,pt)
definition pprod [constructor] (A B : Type*) : Type* :=
pointed.mk' (A × B)
infixr ` ×* `:35 := pprod
definition ppr1 [constructor] {A B : Type*} : A ×* B →* A :=
pmap.mk pr1 idp
definition ppr2 [constructor] {A B : Type*} : A ×* B →* B :=
pmap.mk pr2 idp
definition tprod [constructor] {n : trunc_index} (A B : n-Type) : n-Type :=
trunctype.mk (A × B) _
infixr `×t`:30 := tprod
definition ptprod [constructor] {n : ℕ₋₂} (A B : n-Type*) : n-Type* :=
ptrunctype.mk' n (A × B)
end prod
|
1f3a47578b0365f52144319a78e841d4a53f9a24 | 957a80ea22c5abb4f4670b250d55534d9db99108 | /library/init/meta/rec_util.lean | 65e65813494a9c6b0bee7d84d668588bfa153fe4 | [
"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 | 4,666 | 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
Helper tactic for showing that a type has decidable equality.
-/
prelude
import init.meta.tactic init.data.option.instances
namespace tactic
open expr
/-- Return tt iff e's type is of the form `(I_name ...)` -/
meta def is_type_app_of (e : expr) (I_name : name) : tactic bool :=
do t ← infer_type e,
return $ is_constant_of (get_app_fn t) I_name
/- Auxiliary function for using brec_on "dictionary" -/
private meta def mk_rec_inst_aux : expr → nat → tactic expr
| F 0 := do
P ← mk_app `pprod.fst [F],
mk_app `pprod.fst [P]
| F (n+1) := do
F' ← mk_app `pprod.snd [F],
mk_rec_inst_aux F' n
/-- Construct brec_on "recursive value". F_name is the name of the brec_on "dictionary".
Type of the F_name hypothesis should be of the form (below (C ...)) where C is a constructor.
The result is the "recursive value" for the (i+1)-th recursive value of the constructor C. -/
meta def mk_brec_on_rec_value (F_name : name) (i : nat) : tactic expr :=
do F ← get_local F_name,
mk_rec_inst_aux F i
meta def constructor_num_fields (c : name) : tactic nat :=
do env ← get_env,
decl ← env.get c,
ctype ← return decl.type,
arity ← get_pi_arity ctype,
I ← env.inductive_type_of c,
nparams ← return (env.inductive_num_params I),
return $ arity - nparams
private meta def mk_name_list_aux : name → nat → nat → list name → list name × nat
| p i 0 l := (list.reverse l, i)
| p i (j+1) l := mk_name_list_aux p (i+1) j (mk_num_name p i :: l)
private meta def mk_name_list (p : name) (i : nat) (n : nat) : list name × nat :=
mk_name_list_aux p i n []
/-- Return a list of names of the form [p.i, ..., p.{i+n}] where n is
the number of fields of the constructor c -/
meta def mk_constructor_arg_names (c : name) (p : name) (i : nat) : tactic (list name × nat) :=
do nfields ← constructor_num_fields c,
return $ mk_name_list p i nfields
private meta def mk_constructors_arg_names_aux : list name → name → nat → list (list name) → tactic (list (list name))
| [] p i r := return (list.reverse r)
| (c::cs) p i r := do
v : list name × nat ← mk_constructor_arg_names c p i,
match v with (l, i') := mk_constructors_arg_names_aux cs p i' (l :: r) end
/-- Given an inductive datatype I with k constructors and where constructor i has n_i fields,
return the list [[p.1, ..., p.n_1], [p.{n_1 + 1}, ..., p.{n_1 + n_2}], ..., [..., p.{n_1 + ... + n_k}]] -/
meta def mk_constructors_arg_names (I : name) (p : name) : tactic (list (list name)) :=
do env ← get_env,
cs ← return $ env.constructors_of I,
mk_constructors_arg_names_aux cs p 1 []
private meta def mk_fresh_arg_name_aux : name → nat → name_set → tactic (name × name_set)
| n i s :=
do r ← get_unused_name n (some i),
if s.contains r then
mk_fresh_arg_name_aux n (i+1) s
else
return (r, s.insert r)
private meta def mk_fresh_arg_name (n : name) (s : name_set) : tactic (name × name_set) :=
do r ← get_unused_name n,
if s.contains r then
mk_fresh_arg_name_aux n 1 s
else
return (r, s.insert r)
private meta def mk_constructor_fresh_names_aux : nat → expr → name_set → tactic (list name × name_set)
| nparams ty s := do
ty ← whnf ty,
match ty with
| expr.pi n bi d b :=
if nparams = 0 then do {
(n', s') ← mk_fresh_arg_name n s,
x ← mk_local' n' bi d,
let ty' := b.instantiate_var x,
(ns, s'') ← mk_constructor_fresh_names_aux 0 ty' s',
return (n'::ns, s'')
} else do {
x ← mk_local' n bi d,
let ty' := b.instantiate_var x,
mk_constructor_fresh_names_aux (nparams - 1) ty' s
}
| _ := return ([], s)
end
meta def mk_constructor_fresh_names (nparams : nat) (c : name) (s : name_set) : tactic (list name × name_set) :=
do d ← get_decl c,
let t := d.type,
mk_constructor_fresh_names_aux nparams t s
private meta def mk_constructors_fresh_names_aux : nat → list name → name_set → list (list name) → tactic (list (list name))
| np [] s r := return (list.reverse r)
| np (c::cs) s r := do
(ns, s') ← mk_constructor_fresh_names np c s,
mk_constructors_fresh_names_aux np cs s' (ns::r)
meta def mk_constructors_fresh_names (I : name) : tactic (list (list name)) :=
do env ← get_env,
let cs := env.constructors_of I,
let nparams := env.inductive_num_params I,
mk_constructors_fresh_names_aux nparams cs mk_name_set []
end tactic
|
915bb5c3febf53f391f1f735e0e67c861af3d181 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/topology/subset_properties_auto.lean | e24e590b1a75c285d371bdae528b9768ff6910da | [] | 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 | 50,045 | 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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.bases
import Mathlib.data.finset.order
import Mathlib.PostPort
universes u v u_1 l u_2
namespace Mathlib
/-!
# Properties of subsets of topological spaces
In this file we define various properties of subsets of a topological space, and some classes on
topological spaces.
## Main definitions
We define the following properties for sets in a topological space:
* `is_compact`: each open cover has a finite subcover. This is defined in mathlib using filters.
The main property of a compact set is `is_compact.elim_finite_subcover`.
* `is_clopen`: a set that is both open and closed.
* `is_irreducible`: a nonempty set that has contains no non-trivial pair of disjoint opens.
See also the section below in the module doc.
* `is_connected`: a nonempty set that has no non-trivial open partition.
See also the section below in the module doc.
`connected_component` is the connected component of an element in the space.
* `is_totally_disconnected`: all of its connected components are singletons.
* `is_totally_separated`: any two points can be separated by two disjoint opens that cover the set.
For each of these definitions (except for `is_clopen`), we also have a class stating that the whole
space satisfies that property:
`compact_space`, `irreducible_space`, `connected_space`, `totally_disconnected_space`,
`totally_separated_space`.
Furthermore, we have two more classes:
* `locally_compact_space`: for every point `x`, every open neighborhood of `x` contains a compact
neighborhood of `x`. The definition is formulated in terms of the neighborhood filter.
* `sigma_compact_space`: a space that is the union of a countably many compact subspaces.
## On the definition of irreducible and connected sets/spaces
In informal mathematics, irreducible and connected spaces are assumed to be nonempty.
We formalise the predicate without that assumption
as `is_preirreducible` and `is_preconnected` respectively.
In other words, the only difference is whether the empty space
counts as irreducible and/or connected.
There are good reasons to consider the empty space to be “too simple to be simple”
See also https://ncatlab.org/nlab/show/too+simple+to+be+simple,
and in particular
https://ncatlab.org/nlab/show/too+simple+to+be+simple#relationship_to_biased_definitions.
-/
/- compact sets -/
/-- A set `s` is compact if for every filter `f` that contains `s`,
every set of `f` also meets every neighborhood of some `a ∈ s`. -/
def is_compact {α : Type u} [topological_space α] (s : set α) :=
∀ {f : filter α} [_inst_2 : filter.ne_bot f],
f ≤ filter.principal s → ∃ (a : α), ∃ (H : a ∈ s), cluster_pt a f
/-- The complement to a compact set belongs to a filter `f` if it belongs to each filter
`𝓝 a ⊓ f`, `a ∈ s`. -/
theorem is_compact.compl_mem_sets {α : Type u} [topological_space α] {s : set α} (hs : is_compact s)
{f : filter α} (hf : ∀ (a : α), a ∈ s → sᶜ ∈ nhds a ⊓ f) : sᶜ ∈ f :=
sorry
/-- The complement to a compact set belongs to a filter `f` if each `a ∈ s` has a neighborhood `t`
within `s` such that `tᶜ` belongs to `f`. -/
theorem is_compact.compl_mem_sets_of_nhds_within {α : Type u} [topological_space α] {s : set α}
(hs : is_compact s) {f : filter α}
(hf : ∀ (a : α) (H : a ∈ s), ∃ (t : set α), ∃ (H : t ∈ nhds_within a s), tᶜ ∈ f) : sᶜ ∈ f :=
sorry
/-- If `p : set α → Prop` is stable under restriction and union, and each point `x`
of a compact set `s` has a neighborhood `t` within `s` such that `p t`, then `p s` holds. -/
theorem is_compact.induction_on {α : Type u} [topological_space α] {s : set α} (hs : is_compact s)
{p : set α → Prop} (he : p ∅) (hmono : ∀ {s t : set α}, s ⊆ t → p t → p s)
(hunion : ∀ {s t : set α}, p s → p t → p (s ∪ t))
(hnhds : ∀ (x : α) (H : x ∈ s), ∃ (t : set α), ∃ (H : t ∈ nhds_within x s), p t) : p s :=
sorry
/-- The intersection of a compact set and a closed set is a compact set. -/
theorem is_compact.inter_right {α : Type u} [topological_space α] {s : set α} {t : set α}
(hs : is_compact s) (ht : is_closed t) : is_compact (s ∩ t) :=
sorry
/-- The intersection of a closed set and a compact set is a compact set. -/
theorem is_compact.inter_left {α : Type u} [topological_space α] {s : set α} {t : set α}
(ht : is_compact t) (hs : is_closed s) : is_compact (s ∩ t) :=
set.inter_comm t s ▸ is_compact.inter_right ht hs
/-- The set difference of a compact set and an open set is a compact set. -/
theorem compact_diff {α : Type u} [topological_space α] {s : set α} {t : set α} (hs : is_compact s)
(ht : is_open t) : is_compact (s \ t) :=
is_compact.inter_right hs (iff.mpr is_closed_compl_iff ht)
/-- A closed subset of a compact set is a compact set. -/
theorem compact_of_is_closed_subset {α : Type u} [topological_space α] {s : set α} {t : set α}
(hs : is_compact s) (ht : is_closed t) (h : t ⊆ s) : is_compact t :=
set.inter_eq_self_of_subset_right h ▸ is_compact.inter_right hs ht
theorem is_compact.adherence_nhdset {α : Type u} [topological_space α] {s : set α} {t : set α}
{f : filter α} (hs : is_compact s) (hf₂ : f ≤ filter.principal s) (ht₁ : is_open t)
(ht₂ : ∀ (a : α), a ∈ s → cluster_pt a f → a ∈ t) : t ∈ f :=
sorry
theorem compact_iff_ultrafilter_le_nhds {α : Type u} [topological_space α] {s : set α} :
is_compact s ↔
∀ (f : ultrafilter α), ↑f ≤ filter.principal s → ∃ (a : α), ∃ (H : a ∈ s), ↑f ≤ nhds a :=
sorry
theorem is_compact.ultrafilter_le_nhds {α : Type u} [topological_space α] {s : set α} :
is_compact s →
∀ (f : ultrafilter α), ↑f ≤ filter.principal s → ∃ (a : α), ∃ (H : a ∈ s), ↑f ≤ nhds a :=
iff.mp compact_iff_ultrafilter_le_nhds
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem is_compact.elim_finite_subcover {α : Type u} [topological_space α] {s : set α} {ι : Type v}
(hs : is_compact s) (U : ι → set α) (hUo : ∀ (i : ι), is_open (U i))
(hsU : s ⊆ set.Union fun (i : ι) => U i) :
∃ (t : finset ι), s ⊆ set.Union fun (i : ι) => set.Union fun (H : i ∈ t) => U i :=
sorry
/-- For every family of closed sets whose intersection avoids a compact set,
there exists a finite subfamily whose intersection avoids this compact set. -/
theorem is_compact.elim_finite_subfamily_closed {α : Type u} [topological_space α] {s : set α}
{ι : Type v} (hs : is_compact s) (Z : ι → set α) (hZc : ∀ (i : ι), is_closed (Z i))
(hsZ : (s ∩ set.Inter fun (i : ι) => Z i) = ∅) :
∃ (t : finset ι), (s ∩ set.Inter fun (i : ι) => set.Inter fun (H : i ∈ t) => Z i) = ∅ :=
sorry
/-- To show that a compact set intersects the intersection of a family of closed sets,
it is sufficient to show that it intersects every finite subfamily. -/
theorem is_compact.inter_Inter_nonempty {α : Type u} [topological_space α] {s : set α} {ι : Type v}
(hs : is_compact s) (Z : ι → set α) (hZc : ∀ (i : ι), is_closed (Z i))
(hsZ :
∀ (t : finset ι),
set.nonempty (s ∩ set.Inter fun (i : ι) => set.Inter fun (H : i ∈ t) => Z i)) :
set.nonempty (s ∩ set.Inter fun (i : ι) => Z i) :=
sorry
/-- Cantor's intersection theorem:
the intersection of a directed family of nonempty compact closed sets is nonempty. -/
theorem is_compact.nonempty_Inter_of_directed_nonempty_compact_closed {α : Type u}
[topological_space α] {ι : Type v} [hι : Nonempty ι] (Z : ι → set α) (hZd : directed superset Z)
(hZn : ∀ (i : ι), set.nonempty (Z i)) (hZc : ∀ (i : ι), is_compact (Z i))
(hZcl : ∀ (i : ι), is_closed (Z i)) : set.nonempty (set.Inter fun (i : ι) => Z i) :=
sorry
/-- Cantor's intersection theorem for sequences indexed by `ℕ`:
the intersection of a decreasing sequence of nonempty compact closed sets is nonempty. -/
theorem is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed {α : Type u}
[topological_space α] (Z : ℕ → set α) (hZd : ∀ (i : ℕ), Z (i + 1) ⊆ Z i)
(hZn : ∀ (i : ℕ), set.nonempty (Z i)) (hZ0 : is_compact (Z 0))
(hZcl : ∀ (i : ℕ), is_closed (Z i)) : set.nonempty (set.Inter fun (i : ℕ) => Z i) :=
sorry
/-- For every open cover of a compact set, there exists a finite subcover. -/
theorem is_compact.elim_finite_subcover_image {α : Type u} {β : Type v} [topological_space α]
{s : set α} {b : set β} {c : β → set α} (hs : is_compact s)
(hc₁ : ∀ (i : β), i ∈ b → is_open (c i))
(hc₂ : s ⊆ set.Union fun (i : β) => set.Union fun (H : i ∈ b) => c i) :
∃ (b' : set β),
∃ (H : b' ⊆ b),
set.finite b' ∧ s ⊆ set.Union fun (i : β) => set.Union fun (H : i ∈ b') => c i :=
sorry
/-- A set `s` is compact if for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_of_finite_subfamily_closed {α : Type u} [topological_space α] {s : set α}
(h :
∀ {ι : Type u} (Z : ι → set α),
(∀ (i : ι), is_closed (Z i)) →
(s ∩ set.Inter fun (i : ι) => Z i) = ∅ →
∃ (t : finset ι), (s ∩ set.Inter fun (i : ι) => set.Inter fun (H : i ∈ t) => Z i) = ∅) :
is_compact s :=
sorry
/-- A set `s` is compact if for every open cover of `s`, there exists a finite subcover. -/
theorem compact_of_finite_subcover {α : Type u} [topological_space α] {s : set α}
(h :
∀ {ι : Type u} (U : ι → set α),
(∀ (i : ι), is_open (U i)) →
(s ⊆ set.Union fun (i : ι) => U i) →
∃ (t : finset ι), s ⊆ set.Union fun (i : ι) => set.Union fun (H : i ∈ t) => U i) :
is_compact s :=
sorry
/-- A set `s` is compact if and only if
for every open cover of `s`, there exists a finite subcover. -/
theorem compact_iff_finite_subcover {α : Type u} [topological_space α] {s : set α} :
is_compact s ↔
∀ {ι : Type u} (U : ι → set α),
(∀ (i : ι), is_open (U i)) →
(s ⊆ set.Union fun (i : ι) => U i) →
∃ (t : finset ι), s ⊆ set.Union fun (i : ι) => set.Union fun (H : i ∈ t) => U i :=
{ mp := fun (hs : is_compact s) (ι : Type u) => is_compact.elim_finite_subcover hs,
mpr := compact_of_finite_subcover }
/-- A set `s` is compact if and only if
for every family of closed sets whose intersection avoids `s`,
there exists a finite subfamily whose intersection avoids `s`. -/
theorem compact_iff_finite_subfamily_closed {α : Type u} [topological_space α] {s : set α} :
is_compact s ↔
∀ {ι : Type u} (Z : ι → set α),
(∀ (i : ι), is_closed (Z i)) →
(s ∩ set.Inter fun (i : ι) => Z i) = ∅ →
∃ (t : finset ι),
(s ∩ set.Inter fun (i : ι) => set.Inter fun (H : i ∈ t) => Z i) = ∅ :=
{ mp := fun (hs : is_compact s) (ι : Type u) => is_compact.elim_finite_subfamily_closed hs,
mpr := compact_of_finite_subfamily_closed }
@[simp] theorem compact_empty {α : Type u} [topological_space α] : is_compact ∅ :=
fun (f : filter α) (hnf : filter.ne_bot f) (hsf : f ≤ filter.principal ∅) =>
not.elim hnf (iff.mp filter.empty_in_sets_eq_bot (iff.mp filter.le_principal_iff hsf))
@[simp] theorem compact_singleton {α : Type u} [topological_space α] {a : α} :
is_compact (singleton a) :=
sorry
theorem set.subsingleton.is_compact {α : Type u} [topological_space α] {s : set α}
(hs : set.subsingleton s) : is_compact s :=
set.subsingleton.induction_on hs compact_empty fun (x : α) => compact_singleton
theorem set.finite.compact_bUnion {α : Type u} {β : Type v} [topological_space α] {s : set β}
{f : β → set α} (hs : set.finite s) (hf : ∀ (i : β), i ∈ s → is_compact (f i)) :
is_compact (set.Union fun (i : β) => set.Union fun (H : i ∈ s) => f i) :=
sorry
theorem compact_Union {α : Type u} {β : Type v} [topological_space α] {f : β → set α} [fintype β]
(h : ∀ (i : β), is_compact (f i)) : is_compact (set.Union fun (i : β) => f i) :=
eq.mpr
(id
(Eq._oldrec (Eq.refl (is_compact (set.Union fun (i : β) => f i)))
(Eq.symm (set.bUnion_univ fun (i : β) => f i))))
(set.finite.compact_bUnion set.finite_univ fun (i : β) (_x : i ∈ set.univ) => h i)
theorem set.finite.is_compact {α : Type u} [topological_space α] {s : set α} (hs : set.finite s) :
is_compact s :=
set.bUnion_of_singleton s ▸
set.finite.compact_bUnion hs fun (_x : α) (_x_1 : _x ∈ s) => compact_singleton
theorem is_compact.union {α : Type u} [topological_space α] {s : set α} {t : set α}
(hs : is_compact s) (ht : is_compact t) : is_compact (s ∪ t) :=
eq.mpr (id (Eq._oldrec (Eq.refl (is_compact (s ∪ t))) set.union_eq_Union))
(compact_Union fun (b : Bool) => bool.cases_on b ht hs)
theorem is_compact.insert {α : Type u} [topological_space α] {s : set α} (hs : is_compact s)
(a : α) : is_compact (insert a s) :=
is_compact.union compact_singleton hs
/-- `filter.cocompact` is the filter generated by complements to compact sets. -/
def filter.cocompact (α : Type u_1) [topological_space α] : filter α :=
infi fun (s : set α) => infi fun (hs : is_compact s) => filter.principal (sᶜ)
theorem filter.has_basis_cocompact {α : Type u} [topological_space α] :
filter.has_basis (filter.cocompact α) is_compact compl :=
sorry
theorem filter.mem_cocompact {α : Type u} [topological_space α] {s : set α} :
s ∈ filter.cocompact α ↔ ∃ (t : set α), is_compact t ∧ tᶜ ⊆ s :=
iff.trans (filter.has_basis.mem_iff filter.has_basis_cocompact)
(exists_congr fun (t : set α) => exists_prop)
theorem filter.mem_cocompact' {α : Type u} [topological_space α] {s : set α} :
s ∈ filter.cocompact α ↔ ∃ (t : set α), is_compact t ∧ sᶜ ⊆ t :=
iff.trans filter.mem_cocompact
(exists_congr
fun (t : set α) => and_congr_right fun (ht : is_compact t) => set.compl_subset_comm)
theorem is_compact.compl_mem_cocompact {α : Type u} [topological_space α] {s : set α}
(hs : is_compact s) : sᶜ ∈ filter.cocompact α :=
filter.has_basis.mem_of_mem filter.has_basis_cocompact hs
/-- `nhds_contain_boxes s t` means that any open neighborhood of `s × t` in `α × β` includes
a product of an open neighborhood of `s` by an open neighborhood of `t`. -/
def nhds_contain_boxes {α : Type u} {β : Type v} [topological_space α] [topological_space β]
(s : set α) (t : set β) :=
∀ (n : set (α × β)),
is_open n →
set.prod s t ⊆ n →
∃ (u : set α), ∃ (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n
theorem nhds_contain_boxes.symm {α : Type u} {β : Type v} [topological_space α]
[topological_space β] {s : set α} {t : set β} :
nhds_contain_boxes s t → nhds_contain_boxes t s :=
sorry
theorem nhds_contain_boxes.comm {α : Type u} {β : Type v} [topological_space α]
[topological_space β] {s : set α} {t : set β} :
nhds_contain_boxes s t ↔ nhds_contain_boxes t s :=
{ mp := nhds_contain_boxes.symm, mpr := nhds_contain_boxes.symm }
theorem nhds_contain_boxes_of_singleton {α : Type u} {β : Type v} [topological_space α]
[topological_space β] {x : α} {y : β} : nhds_contain_boxes (singleton x) (singleton y) :=
sorry
theorem nhds_contain_boxes_of_compact {α : Type u} {β : Type v} [topological_space α]
[topological_space β] {s : set α} (hs : is_compact s) (t : set β)
(H : ∀ (x : α), x ∈ s → nhds_contain_boxes (singleton x) t) : nhds_contain_boxes s t :=
sorry
/-- If `s` and `t` are compact sets and `n` is an open neighborhood of `s × t`, then there exist
open neighborhoods `u ⊇ s` and `v ⊇ t` such that `u × v ⊆ n`. -/
theorem generalized_tube_lemma {α : Type u} {β : Type v} [topological_space α] [topological_space β]
{s : set α} (hs : is_compact s) {t : set β} (ht : is_compact t) {n : set (α × β)}
(hn : is_open n) (hp : set.prod s t ⊆ n) :
∃ (u : set α), ∃ (v : set β), is_open u ∧ is_open v ∧ s ⊆ u ∧ t ⊆ v ∧ set.prod u v ⊆ n :=
sorry
/-- Type class for compact spaces. Separation is sometimes included in the definition, especially
in the French literature, but we do not include it here. -/
class compact_space (α : Type u_1) [topological_space α] where
compact_univ : is_compact set.univ
protected instance subsingleton.compact_space {α : Type u} [topological_space α] [subsingleton α] :
compact_space α :=
compact_space.mk (set.subsingleton.is_compact set.subsingleton_univ)
theorem compact_univ {α : Type u} [topological_space α] [h : compact_space α] :
is_compact set.univ :=
compact_space.compact_univ
theorem cluster_point_of_compact {α : Type u} [topological_space α] [compact_space α] (f : filter α)
[filter.ne_bot f] : ∃ (x : α), cluster_pt x f :=
sorry
theorem compact_space_of_finite_subfamily_closed {α : Type u} [topological_space α]
(h :
∀ {ι : Type u} (Z : ι → set α),
(∀ (i : ι), is_closed (Z i)) →
(set.Inter fun (i : ι) => Z i) = ∅ →
∃ (t : finset ι), (set.Inter fun (i : ι) => set.Inter fun (H : i ∈ t) => Z i) = ∅) :
compact_space α :=
sorry
theorem is_closed.compact {α : Type u} [topological_space α] [compact_space α] {s : set α}
(h : is_closed s) : is_compact s :=
compact_of_is_closed_subset compact_univ h (set.subset_univ s)
theorem is_compact.image_of_continuous_on {α : Type u} {β : Type v} [topological_space α]
{s : set α} [topological_space β] {f : α → β} (hs : is_compact s) (hf : continuous_on f s) :
is_compact (f '' s) :=
sorry
theorem is_compact.image {α : Type u} {β : Type v} [topological_space α] {s : set α}
[topological_space β] {f : α → β} (hs : is_compact s) (hf : continuous f) :
is_compact (f '' s) :=
is_compact.image_of_continuous_on hs (continuous.continuous_on hf)
theorem compact_range {α : Type u} {β : Type v} [topological_space α] [topological_space β]
[compact_space α] {f : α → β} (hf : continuous f) : is_compact (set.range f) :=
eq.mpr (id (Eq._oldrec (Eq.refl (is_compact (set.range f))) (Eq.symm set.image_univ)))
(is_compact.image compact_univ hf)
/-- If X is is_compact then pr₂ : X × Y → Y is a closed map -/
theorem is_closed_proj_of_compact {X : Type u_1} [topological_space X] [compact_space X]
{Y : Type u_2} [topological_space Y] : is_closed_map prod.snd :=
sorry
theorem embedding.compact_iff_compact_image {α : Type u} {β : Type v} [topological_space α]
{s : set α} [topological_space β] {f : α → β} (hf : embedding f) :
is_compact s ↔ is_compact (f '' s) :=
sorry
theorem compact_iff_compact_in_subtype {α : Type u} [topological_space α] {p : α → Prop}
{s : set (Subtype fun (a : α) => p a)} : is_compact s ↔ is_compact (coe '' s) :=
embedding.compact_iff_compact_image embedding_subtype_coe
theorem compact_iff_compact_univ {α : Type u} [topological_space α] {s : set α} :
is_compact s ↔ is_compact set.univ :=
sorry
theorem compact_iff_compact_space {α : Type u} [topological_space α] {s : set α} :
is_compact s ↔ compact_space ↥s :=
iff.trans compact_iff_compact_univ
{ mp := fun (h : is_compact set.univ) => compact_space.mk h, mpr := compact_space.compact_univ }
theorem is_compact.prod {α : Type u} {β : Type v} [topological_space α] [topological_space β]
{s : set α} {t : set β} (hs : is_compact s) (ht : is_compact t) : is_compact (set.prod s t) :=
sorry
/-- Finite topological spaces are compact. -/
protected instance fintype.compact_space {α : Type u} [topological_space α] [fintype α] :
compact_space α :=
compact_space.mk (set.finite.is_compact set.finite_univ)
/-- The product of two compact spaces is compact. -/
protected instance prod.compact_space {α : Type u} {β : Type v} [topological_space α]
[topological_space β] [compact_space α] [compact_space β] : compact_space (α × β) :=
compact_space.mk
(eq.mpr (id (Eq._oldrec (Eq.refl (is_compact set.univ)) (Eq.symm set.univ_prod_univ)))
(is_compact.prod compact_univ compact_univ))
/-- The disjoint union of two compact spaces is compact. -/
protected instance sum.compact_space {α : Type u} {β : Type v} [topological_space α]
[topological_space β] [compact_space α] [compact_space β] : compact_space (α ⊕ β) :=
compact_space.mk
(eq.mpr
(id (Eq._oldrec (Eq.refl (is_compact set.univ)) (Eq.symm set.range_inl_union_range_inr)))
(is_compact.union (compact_range continuous_inl) (compact_range continuous_inr)))
/-- Tychonoff's theorem -/
theorem compact_pi_infinite {ι : Type u_1} {π : ι → Type u_2} [(i : ι) → topological_space (π i)]
{s : (i : ι) → set (π i)} :
(∀ (i : ι), is_compact (s i)) →
is_compact (set_of fun (x : (i : ι) → π i) => ∀ (i : ι), x i ∈ s i) :=
sorry
/-- A version of Tychonoff's theorem that uses `set.pi`. -/
theorem compact_univ_pi {ι : Type u_1} {π : ι → Type u_2} [(i : ι) → topological_space (π i)]
{s : (i : ι) → set (π i)} (h : ∀ (i : ι), is_compact (s i)) : is_compact (set.pi set.univ s) :=
sorry
protected instance pi.compact {ι : Type u_1} {π : ι → Type u_2} [(i : ι) → topological_space (π i)]
[∀ (i : ι), compact_space (π i)] : compact_space ((i : ι) → π i) :=
sorry
protected instance quot.compact_space {α : Type u} [topological_space α] {r : α → α → Prop}
[compact_space α] : compact_space (Quot r) :=
compact_space.mk
(eq.mpr (id (Eq._oldrec (Eq.refl (is_compact set.univ)) (Eq.symm (set.range_quot_mk r))))
(compact_range continuous_quot_mk))
protected instance quotient.compact_space {α : Type u} [topological_space α] {s : setoid α}
[compact_space α] : compact_space (quotient s) :=
quot.compact_space
/-- There are various definitions of "locally compact space" in the literature, which agree for
Hausdorff spaces but not in general. This one is the precise condition on X needed for the
evaluation `map C(X, Y) × X → Y` to be continuous for all `Y` when `C(X, Y)` is given the
compact-open topology. -/
class locally_compact_space (α : Type u_1) [topological_space α] where
local_compact_nhds :
∀ (x : α) (n : set α) (H : n ∈ nhds x), ∃ (s : set α), ∃ (H : s ∈ nhds x), s ⊆ n ∧ is_compact s
/-- A reformulation of the definition of locally compact space: In a locally compact space,
every open set containing `x` has a compact subset containing `x` in its interior. -/
theorem exists_compact_subset {α : Type u} [topological_space α] [locally_compact_space α] {x : α}
{U : set α} (hU : is_open U) (hx : x ∈ U) :
∃ (K : set α), is_compact K ∧ x ∈ interior K ∧ K ⊆ U :=
sorry
/-- In a locally compact space every point has a compact neighborhood. -/
theorem exists_compact_mem_nhds {α : Type u} [topological_space α] [locally_compact_space α]
(x : α) : ∃ (K : set α), is_compact K ∧ K ∈ nhds x :=
sorry
theorem ultrafilter.le_nhds_Lim {α : Type u} [topological_space α] [compact_space α]
(F : ultrafilter α) : ↑F ≤ nhds (Lim ↑F) :=
sorry
/-- A σ-compact space is a space that is the union of a countable collection of compact subspaces.
Note that a locally compact separable T₂ space need not be σ-compact.
The sequence can be extracted using `topological_space.compact_covering`. -/
class sigma_compact_space (α : Type u_1) [topological_space α] where
exists_compact_covering :
∃ (K : ℕ → set α), (∀ (n : ℕ), is_compact (K n)) ∧ (set.Union fun (n : ℕ) => K n) = set.univ
protected instance compact_space.sigma_compact {α : Type u} [topological_space α]
[compact_space α] : sigma_compact_space α :=
sigma_compact_space.mk
(Exists.intro (fun (_x : ℕ) => set.univ)
{ left := fun (_x : ℕ) => compact_univ, right := set.Union_const set.univ })
theorem sigma_compact_space.of_countable {α : Type u} [topological_space α] (S : set (set α))
(Hc : set.countable S) (Hcomp : ∀ (s : set α), s ∈ S → is_compact s) (HU : ⋃₀S = set.univ) :
sigma_compact_space α :=
sigma_compact_space.mk
(iff.mpr (set.exists_seq_cover_iff_countable (Exists.intro ∅ compact_empty))
(Exists.intro S { left := Hc, right := { left := Hcomp, right := HU } }))
theorem sigma_compact_space_of_locally_compact_second_countable {α : Type u} [topological_space α]
[locally_compact_space α] [topological_space.second_countable_topology α] :
sigma_compact_space α :=
sorry
/-- An arbitrary compact covering of a σ-compact space. -/
def compact_covering (α : Type u) [topological_space α] [sigma_compact_space α] : ℕ → set α :=
classical.some sigma_compact_space.exists_compact_covering
theorem is_compact_compact_covering (α : Type u) [topological_space α] [sigma_compact_space α]
(n : ℕ) : is_compact (compact_covering α n) :=
and.left (classical.some_spec sigma_compact_space.exists_compact_covering) n
theorem Union_compact_covering (α : Type u) [topological_space α] [sigma_compact_space α] :
(set.Union fun (n : ℕ) => compact_covering α n) = set.univ :=
and.right (classical.some_spec sigma_compact_space.exists_compact_covering)
/-- A set is clopen if it is both open and closed. -/
def is_clopen {α : Type u} [topological_space α] (s : set α) := is_open s ∧ is_closed s
theorem is_clopen_union {α : Type u} [topological_space α] {s : set α} {t : set α}
(hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∪ t) :=
{ left := is_open_union (and.left hs) (and.left ht),
right := is_closed_union (and.right hs) (and.right ht) }
theorem is_clopen_inter {α : Type u} [topological_space α] {s : set α} {t : set α}
(hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ t) :=
{ left := is_open_inter (and.left hs) (and.left ht),
right := is_closed_inter (and.right hs) (and.right ht) }
@[simp] theorem is_clopen_empty {α : Type u} [topological_space α] : is_clopen ∅ :=
{ left := is_open_empty, right := is_closed_empty }
@[simp] theorem is_clopen_univ {α : Type u} [topological_space α] : is_clopen set.univ :=
{ left := is_open_univ, right := is_closed_univ }
theorem is_clopen_compl {α : Type u} [topological_space α] {s : set α} (hs : is_clopen s) :
is_clopen (sᶜ) :=
{ left := and.right hs, right := iff.mpr is_closed_compl_iff (and.left hs) }
@[simp] theorem is_clopen_compl_iff {α : Type u} [topological_space α] {s : set α} :
is_clopen (sᶜ) ↔ is_clopen s :=
{ mp := fun (h : is_clopen (sᶜ)) => compl_compl s ▸ is_clopen_compl h, mpr := is_clopen_compl }
theorem is_clopen_diff {α : Type u} [topological_space α] {s : set α} {t : set α} (hs : is_clopen s)
(ht : is_clopen t) : is_clopen (s \ t) :=
is_clopen_inter hs (is_clopen_compl ht)
theorem is_clopen_Inter {α : Type u} [topological_space α] {β : Type u_1} [fintype β]
{s : β → set α} (h : ∀ (i : β), is_clopen (s i)) : is_clopen (set.Inter fun (i : β) => s i) :=
{ left := is_open_Inter (and.left (iff.mp forall_and_distrib h)),
right := is_closed_Inter (and.right (iff.mp forall_and_distrib h)) }
theorem is_clopen_bInter {α : Type u} [topological_space α] {β : Type u_1} {s : finset β}
{f : β → set α} (h : ∀ (i : β), i ∈ s → is_clopen (f i)) :
is_clopen (set.Inter fun (i : β) => set.Inter fun (H : i ∈ s) => f i) :=
sorry
theorem continuous_on.preimage_clopen_of_clopen {α : Type u} [topological_space α] {β : Type u_1}
[topological_space β] {f : α → β} {s : set α} {t : set β} (hf : continuous_on f s)
(hs : is_clopen s) (ht : is_clopen t) : is_clopen (s ∩ f ⁻¹' t) :=
{ left := continuous_on.preimage_open_of_open hf (and.left hs) (and.left ht),
right := continuous_on.preimage_closed_of_closed hf (and.right hs) (and.right ht) }
/-- The intersection of a disjoint covering by two open sets of a clopen set will be clopen. -/
theorem is_clopen_inter_of_disjoint_cover_clopen {α : Type u} [topological_space α] {Z : set α}
{a : set α} {b : set α} (h : is_clopen Z) (cover : Z ⊆ a ∪ b) (ha : is_open a) (hb : is_open b)
(hab : a ∩ b = ∅) : is_clopen (Z ∩ a) :=
sorry
/-- A preirreducible set `s` is one where there is no non-trivial pair of disjoint opens on `s`. -/
def is_preirreducible {α : Type u} [topological_space α] (s : set α) :=
∀ (u v : set α),
is_open u → is_open v → set.nonempty (s ∩ u) → set.nonempty (s ∩ v) → set.nonempty (s ∩ (u ∩ v))
/-- An irreducible set `s` is one that is nonempty and
where there is no non-trivial pair of disjoint opens on `s`. -/
def is_irreducible {α : Type u} [topological_space α] (s : set α) :=
set.nonempty s ∧ is_preirreducible s
theorem is_irreducible.nonempty {α : Type u} [topological_space α] {s : set α}
(h : is_irreducible s) : set.nonempty s :=
and.left h
theorem is_irreducible.is_preirreducible {α : Type u} [topological_space α] {s : set α}
(h : is_irreducible s) : is_preirreducible s :=
and.right h
theorem is_preirreducible_empty {α : Type u} [topological_space α] : is_preirreducible ∅ := sorry
theorem is_irreducible_singleton {α : Type u} [topological_space α] {x : α} :
is_irreducible (singleton x) :=
sorry
theorem is_preirreducible.closure {α : Type u} [topological_space α] {s : set α}
(H : is_preirreducible s) : is_preirreducible (closure s) :=
sorry
theorem is_irreducible.closure {α : Type u} [topological_space α] {s : set α}
(h : is_irreducible s) : is_irreducible (closure s) :=
{ left := set.nonempty.closure (is_irreducible.nonempty h),
right := is_preirreducible.closure (is_irreducible.is_preirreducible h) }
theorem exists_preirreducible {α : Type u} [topological_space α] (s : set α)
(H : is_preirreducible s) :
∃ (t : set α),
is_preirreducible t ∧ s ⊆ t ∧ ∀ (u : set α), is_preirreducible u → t ⊆ u → u = t :=
sorry
/-- A maximal irreducible set that contains a given point. -/
def irreducible_component {α : Type u} [topological_space α] (x : α) : set α := classical.some sorry
theorem irreducible_component_property {α : Type u} [topological_space α] (x : α) :
is_preirreducible (irreducible_component x) ∧
singleton x ⊆ irreducible_component x ∧
∀ (u : set α),
is_preirreducible u → irreducible_component x ⊆ u → u = irreducible_component x :=
classical.some_spec
(exists_preirreducible (singleton x)
(is_irreducible.is_preirreducible is_irreducible_singleton))
theorem mem_irreducible_component {α : Type u} [topological_space α] {x : α} :
x ∈ irreducible_component x :=
iff.mp set.singleton_subset_iff (and.left (and.right (irreducible_component_property x)))
theorem is_irreducible_irreducible_component {α : Type u} [topological_space α] {x : α} :
is_irreducible (irreducible_component x) :=
{ left := Exists.intro x mem_irreducible_component,
right := and.left (irreducible_component_property x) }
theorem eq_irreducible_component {α : Type u} [topological_space α] {x : α} {s : set α} :
is_preirreducible s → irreducible_component x ⊆ s → s = irreducible_component x :=
and.right (and.right (irreducible_component_property x))
theorem is_closed_irreducible_component {α : Type u} [topological_space α] {x : α} :
is_closed (irreducible_component x) :=
iff.mp closure_eq_iff_is_closed
(eq_irreducible_component
(is_preirreducible.closure
(is_irreducible.is_preirreducible is_irreducible_irreducible_component))
subset_closure)
/-- A preirreducible space is one where there is no non-trivial pair of disjoint opens. -/
class preirreducible_space (α : Type u) [topological_space α] where
is_preirreducible_univ : is_preirreducible set.univ
/-- An irreducible space is one that is nonempty
and where there is no non-trivial pair of disjoint opens. -/
class irreducible_space (α : Type u) [topological_space α]
extends Nonempty α, preirreducible_space α where
to_nonempty : Nonempty α
theorem nonempty_preirreducible_inter {α : Type u} [topological_space α] [preirreducible_space α]
{s : set α} {t : set α} :
is_open s → is_open t → set.nonempty s → set.nonempty t → set.nonempty (s ∩ t) :=
sorry
theorem is_preirreducible.image {α : Type u} {β : Type v} [topological_space α]
[topological_space β] {s : set α} (H : is_preirreducible s) (f : α → β)
(hf : continuous_on f s) : is_preirreducible (f '' s) :=
sorry
theorem is_irreducible.image {α : Type u} {β : Type v} [topological_space α] [topological_space β]
{s : set α} (H : is_irreducible s) (f : α → β) (hf : continuous_on f s) :
is_irreducible (f '' s) :=
{ left := iff.mpr set.nonempty_image_iff (is_irreducible.nonempty H),
right := is_preirreducible.image (is_irreducible.is_preirreducible H) f hf }
theorem subtype.preirreducible_space {α : Type u} [topological_space α] {s : set α}
(h : is_preirreducible s) : preirreducible_space ↥s :=
sorry
theorem subtype.irreducible_space {α : Type u} [topological_space α] {s : set α}
(h : is_irreducible s) : irreducible_space ↥s :=
irreducible_space.mk (set.nonempty.to_subtype (is_irreducible.nonempty h))
/-- A set `s` is irreducible if and only if
for every finite collection of open sets all of whose members intersect `s`,
`s` also intersects the intersection of the entire collection
(i.e., there is an element of `s` contained in every member of the collection). -/
theorem is_irreducible_iff_sInter {α : Type u} [topological_space α] {s : set α} :
is_irreducible s ↔
∀ (U : finset (set α)),
(∀ (u : set α), u ∈ U → is_open u) →
(∀ (u : set α), u ∈ U → set.nonempty (s ∩ u)) → set.nonempty (s ∩ ⋂₀↑U) :=
sorry
/-- A set is preirreducible if and only if
for every cover by two closed sets, it is contained in one of the two covering sets. -/
theorem is_preirreducible_iff_closed_union_closed {α : Type u} [topological_space α] {s : set α} :
is_preirreducible s ↔
∀ (z₁ z₂ : set α), is_closed z₁ → is_closed z₂ → s ⊆ z₁ ∪ z₂ → s ⊆ z₁ ∨ s ⊆ z₂ :=
sorry
/-- A set is irreducible if and only if
for every cover by a finite collection of closed sets,
it is contained in one of the members of the collection. -/
theorem is_irreducible_iff_sUnion_closed {α : Type u} [topological_space α] {s : set α} :
is_irreducible s ↔
∀ (Z : finset (set α)),
(∀ (z : set α), z ∈ Z → is_closed z) →
∀ (H : s ⊆ ⋃₀↑Z), ∃ (z : set α), ∃ (H : z ∈ Z), s ⊆ z :=
sorry
/-- A preconnected set is one where there is no non-trivial open partition. -/
def is_preconnected {α : Type u} [topological_space α] (s : set α) :=
∀ (u v : set α),
is_open u →
is_open v →
s ⊆ u ∪ v → set.nonempty (s ∩ u) → set.nonempty (s ∩ v) → set.nonempty (s ∩ (u ∩ v))
/-- A connected set is one that is nonempty and where there is no non-trivial open partition. -/
def is_connected {α : Type u} [topological_space α] (s : set α) :=
set.nonempty s ∧ is_preconnected s
theorem is_connected.nonempty {α : Type u} [topological_space α] {s : set α} (h : is_connected s) :
set.nonempty s :=
and.left h
theorem is_connected.is_preconnected {α : Type u} [topological_space α] {s : set α}
(h : is_connected s) : is_preconnected s :=
and.right h
theorem is_preirreducible.is_preconnected {α : Type u} [topological_space α] {s : set α}
(H : is_preirreducible s) : is_preconnected s :=
fun (_x _x_1 : set α) (hu : is_open _x) (hv : is_open _x_1) (_x_2 : s ⊆ _x ∪ _x_1) =>
H _x _x_1 hu hv
theorem is_irreducible.is_connected {α : Type u} [topological_space α] {s : set α}
(H : is_irreducible s) : is_connected s :=
{ left := is_irreducible.nonempty H,
right := is_preirreducible.is_preconnected (is_irreducible.is_preirreducible H) }
theorem is_preconnected_empty {α : Type u} [topological_space α] : is_preconnected ∅ :=
is_preirreducible.is_preconnected is_preirreducible_empty
theorem is_connected_singleton {α : Type u} [topological_space α] {x : α} :
is_connected (singleton x) :=
is_irreducible.is_connected is_irreducible_singleton
/-- If any point of a set is joined to a fixed point by a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall {α : Type u} [topological_space α] {s : set α} (x : α)
(H : ∀ (y : α) (H : y ∈ s), ∃ (t : set α), ∃ (H : t ⊆ s), x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
sorry
/-- If any two points of a set are contained in a preconnected subset,
then the original set is preconnected as well. -/
theorem is_preconnected_of_forall_pair {α : Type u} [topological_space α] {s : set α}
(H :
∀ (x y : α) (H : x ∈ s) (H : y ∈ s),
∃ (t : set α), ∃ (H : t ⊆ s), x ∈ t ∧ y ∈ t ∧ is_preconnected t) :
is_preconnected s :=
sorry
/-- A union of a family of preconnected sets with a common point is preconnected as well. -/
theorem is_preconnected_sUnion {α : Type u} [topological_space α] (x : α) (c : set (set α))
(H1 : ∀ (s : set α), s ∈ c → x ∈ s) (H2 : ∀ (s : set α), s ∈ c → is_preconnected s) :
is_preconnected (⋃₀c) :=
sorry
theorem is_preconnected.union {α : Type u} [topological_space α] (x : α) {s : set α} {t : set α}
(H1 : x ∈ s) (H2 : x ∈ t) (H3 : is_preconnected s) (H4 : is_preconnected t) :
is_preconnected (s ∪ t) :=
sorry
theorem is_connected.union {α : Type u} [topological_space α] {s : set α} {t : set α}
(H : set.nonempty (s ∩ t)) (Hs : is_connected s) (Ht : is_connected t) : is_connected (s ∪ t) :=
sorry
theorem is_preconnected.closure {α : Type u} [topological_space α] {s : set α}
(H : is_preconnected s) : is_preconnected (closure s) :=
sorry
theorem is_connected.closure {α : Type u} [topological_space α] {s : set α} (H : is_connected s) :
is_connected (closure s) :=
{ left := set.nonempty.closure (is_connected.nonempty H),
right := is_preconnected.closure (is_connected.is_preconnected H) }
theorem is_preconnected.image {α : Type u} {β : Type v} [topological_space α] [topological_space β]
{s : set α} (H : is_preconnected s) (f : α → β) (hf : continuous_on f s) :
is_preconnected (f '' s) :=
sorry
theorem is_connected.image {α : Type u} {β : Type v} [topological_space α] [topological_space β]
{s : set α} (H : is_connected s) (f : α → β) (hf : continuous_on f s) : is_connected (f '' s) :=
{ left := iff.mpr set.nonempty_image_iff (is_connected.nonempty H),
right := is_preconnected.image (is_connected.is_preconnected H) f hf }
theorem is_preconnected_closed_iff {α : Type u} [topological_space α] {s : set α} :
is_preconnected s ↔
∀ (t t' : set α),
is_closed t →
is_closed t' →
s ⊆ t ∪ t' →
set.nonempty (s ∩ t) → set.nonempty (s ∩ t') → set.nonempty (s ∩ (t ∩ t')) :=
sorry
/-- The connected component of a point is the maximal connected set
that contains this point. -/
def connected_component {α : Type u} [topological_space α] (x : α) : set α :=
⋃₀set_of fun (s : set α) => is_preconnected s ∧ x ∈ s
/-- The connected component of a point inside a set. -/
def connected_component_in {α : Type u} [topological_space α] (F : set α) (x : ↥F) : set α :=
coe '' connected_component x
theorem mem_connected_component {α : Type u} [topological_space α] {x : α} :
x ∈ connected_component x :=
set.mem_sUnion_of_mem (set.mem_singleton x)
{ left := is_connected.is_preconnected is_connected_singleton, right := set.mem_singleton x }
theorem is_connected_connected_component {α : Type u} [topological_space α] {x : α} :
is_connected (connected_component x) :=
sorry
theorem subset_connected_component {α : Type u} [topological_space α] {x : α} {s : set α}
(H1 : is_preconnected s) (H2 : x ∈ s) : s ⊆ connected_component x :=
fun (z : α) (hz : z ∈ s) => set.mem_sUnion_of_mem hz { left := H1, right := H2 }
theorem is_closed_connected_component {α : Type u} [topological_space α] {x : α} :
is_closed (connected_component x) :=
sorry
theorem irreducible_component_subset_connected_component {α : Type u} [topological_space α]
{x : α} : irreducible_component x ⊆ connected_component x :=
subset_connected_component
(is_connected.is_preconnected
(is_irreducible.is_connected is_irreducible_irreducible_component))
mem_irreducible_component
/-- A preconnected space is one where there is no non-trivial open partition. -/
class preconnected_space (α : Type u) [topological_space α] where
is_preconnected_univ : is_preconnected set.univ
/-- A connected space is a nonempty one where there is no non-trivial open partition. -/
class connected_space (α : Type u) [topological_space α] extends preconnected_space α, Nonempty α
where
to_nonempty : Nonempty α
theorem is_connected_range {α : Type u} {β : Type v} [topological_space α] [topological_space β]
[connected_space α] {f : α → β} (h : continuous f) : is_connected (set.range f) :=
sorry
theorem connected_space_iff_connected_component {α : Type u} [topological_space α] :
connected_space α ↔ ∃ (x : α), connected_component x = set.univ :=
sorry
protected instance preirreducible_space.preconnected_space (α : Type u) [topological_space α]
[preirreducible_space α] : preconnected_space α :=
preconnected_space.mk
(is_preirreducible.is_preconnected (preirreducible_space.is_preirreducible_univ α))
protected instance irreducible_space.connected_space (α : Type u) [topological_space α]
[irreducible_space α] : connected_space α :=
connected_space.mk (irreducible_space.to_nonempty α)
theorem nonempty_inter {α : Type u} [topological_space α] [preconnected_space α] {s : set α}
{t : set α} :
is_open s →
is_open t → s ∪ t = set.univ → set.nonempty s → set.nonempty t → set.nonempty (s ∩ t) :=
sorry
theorem is_clopen_iff {α : Type u} [topological_space α] [preconnected_space α] {s : set α} :
is_clopen s ↔ s = ∅ ∨ s = set.univ :=
sorry
theorem eq_univ_of_nonempty_clopen {α : Type u} [topological_space α] [preconnected_space α]
{s : set α} (h : set.nonempty s) (h' : is_clopen s) : s = set.univ :=
sorry
theorem subtype.preconnected_space {α : Type u} [topological_space α] {s : set α}
(h : is_preconnected s) : preconnected_space ↥s :=
sorry
theorem subtype.connected_space {α : Type u} [topological_space α] {s : set α}
(h : is_connected s) : connected_space ↥s :=
connected_space.mk (set.nonempty.to_subtype (is_connected.nonempty h))
theorem is_preconnected_iff_preconnected_space {α : Type u} [topological_space α] {s : set α} :
is_preconnected s ↔ preconnected_space ↥s :=
sorry
theorem is_connected_iff_connected_space {α : Type u} [topological_space α] {s : set α} :
is_connected s ↔ connected_space ↥s :=
sorry
/-- A set `s` is preconnected if and only if
for every cover by two open sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint {α : Type u} [topological_space α] {s : set α} :
is_preconnected s ↔
∀ (u v : set α), is_open u → is_open v → s ⊆ u ∪ v → s ∩ (u ∩ v) = ∅ → s ⊆ u ∨ s ⊆ v :=
sorry
/-- A set `s` is connected if and only if
for every cover by a finite collection of open sets that are pairwise disjoint on `s`,
it is contained in one of the members of the collection. -/
theorem is_connected_iff_sUnion_disjoint_open {α : Type u} [topological_space α] {s : set α} :
is_connected s ↔
∀ (U : finset (set α))
(H : ∀ (u v : set α), u ∈ U → v ∈ U → set.nonempty (s ∩ (u ∩ v)) → u = v),
(∀ (u : set α), u ∈ U → is_open u) → s ⊆ ⋃₀↑U → ∃ (u : set α), ∃ (H : u ∈ U), s ⊆ u :=
sorry
/-- Preconnected sets are either contained in or disjoint to any given clopen set. -/
theorem subset_or_disjoint_of_clopen {α : Type u_1} [topological_space α] {s : set α} {t : set α}
(h : is_preconnected t) (h1 : is_clopen s) : s ∩ t = ∅ ∨ t ⊆ s :=
sorry
/-- A set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint on `s`,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_disjoint_closed {α : Type u_1} {s : set α}
[topological_space α] :
is_preconnected s ↔
∀ (u v : set α), is_closed u → is_closed v → s ⊆ u ∪ v → s ∩ (u ∩ v) = ∅ → s ⊆ u ∨ s ⊆ v :=
sorry
/-- A closed set `s` is preconnected if and only if
for every cover by two closed sets that are disjoint,
it is contained in one of the two covering sets. -/
theorem is_preconnected_iff_subset_of_fully_disjoint_closed {α : Type u} [topological_space α]
{s : set α} (hs : is_closed s) :
is_preconnected s ↔
∀ (u v : set α), is_closed u → is_closed v → s ⊆ u ∪ v → u ∩ v = ∅ → s ⊆ u ∨ s ⊆ v :=
sorry
/-- The connected component of a point is always a subset of the intersection of all its clopen
neighbourhoods. -/
theorem connected_component_subset_Inter_clopen {α : Type u} [topological_space α] {x : α} :
connected_component x ⊆
set.Inter fun (Z : Subtype fun (Z : set α) => is_clopen Z ∧ x ∈ Z) => ↑Z :=
sorry
/-- A set is called totally disconnected if all of its connected components are singletons. -/
def is_totally_disconnected {α : Type u} [topological_space α] (s : set α) :=
∀ (t : set α), t ⊆ s → is_preconnected t → subsingleton ↥t
theorem is_totally_disconnected_empty {α : Type u} [topological_space α] :
is_totally_disconnected ∅ :=
sorry
theorem is_totally_disconnected_singleton {α : Type u} [topological_space α] {x : α} :
is_totally_disconnected (singleton x) :=
sorry
/-- A space is totally disconnected if all of its connected components are singletons. -/
class totally_disconnected_space (α : Type u) [topological_space α] where
is_totally_disconnected_univ : is_totally_disconnected set.univ
protected instance pi.totally_disconnected_space {α : Type u_1} {β : α → Type u_2}
[t₂ : (a : α) → topological_space (β a)] [∀ (a : α), totally_disconnected_space (β a)] :
totally_disconnected_space ((a : α) → β a) :=
sorry
protected instance subtype.totally_disconnected_space {α : Type u_1} {p : α → Prop}
[topological_space α] [totally_disconnected_space α] : totally_disconnected_space (Subtype p) :=
totally_disconnected_space.mk
fun (s : set (Subtype p)) (h1 : s ⊆ set.univ) (h2 : is_preconnected s) =>
set.subsingleton_of_image subtype.val_injective s
(totally_disconnected_space.is_totally_disconnected_univ (subtype.val '' s)
(set.subset_univ (subtype.val '' s))
(is_preconnected.image h2 subtype.val (continuous.continuous_on continuous_subtype_val)))
/-- A set `s` is called totally separated if any two points of this set can be separated
by two disjoint open sets covering `s`. -/
def is_totally_separated {α : Type u} [topological_space α] (s : set α) :=
∀ (x : α),
x ∈ s →
∀ (y : α),
y ∈ s →
x ≠ y →
∃ (u : set α),
∃ (v : set α), is_open u ∧ is_open v ∧ x ∈ u ∧ y ∈ v ∧ s ⊆ u ∪ v ∧ u ∩ v = ∅
theorem is_totally_separated_empty {α : Type u} [topological_space α] : is_totally_separated ∅ :=
fun (x : α) => false.elim
theorem is_totally_separated_singleton {α : Type u} [topological_space α] {x : α} :
is_totally_separated (singleton x) :=
fun (p : α) (hp : p ∈ singleton x) (q : α) (hq : q ∈ singleton x) (hpq : p ≠ q) =>
false.elim (hpq (Eq.symm (set.eq_of_mem_singleton hp) ▸ Eq.symm (set.eq_of_mem_singleton hq)))
theorem is_totally_disconnected_of_is_totally_separated {α : Type u} [topological_space α]
{s : set α} (H : is_totally_separated s) : is_totally_disconnected s :=
sorry
/-- A space is totally separated if any two points can be separated by two disjoint open sets
covering the whole space. -/
class totally_separated_space (α : Type u) [topological_space α] where
is_totally_separated_univ : is_totally_separated set.univ
protected instance totally_separated_space.totally_disconnected_space (α : Type u)
[topological_space α] [totally_separated_space α] : totally_disconnected_space α :=
totally_disconnected_space.mk
(is_totally_disconnected_of_is_totally_separated
(totally_separated_space.is_totally_separated_univ α))
protected instance totally_separated_space.of_discrete (α : Type u_1) [topological_space α]
[discrete_topology α] : totally_separated_space α :=
sorry
end Mathlib |
72fc4dfe6f5b580f9f80b150ddaee52165205a48 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/tactic/auto_cases.lean | 95adf9b9aa6b3f8d007f310eafb3de7f0ab7c8d2 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 2,363 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Keeley Hoek, Scott Morrison
-/
import tactic.hint
namespace tactic
namespace auto_cases
/-- Structure representing a tactic which can be used by `tactic.auto_cases`. -/
meta structure auto_cases_tac :=
(name : string)
{α : Type}
(tac : expr → tactic α)
/-- The `auto_cases_tac` for `tactic.cases`. -/
meta def tac_cases : auto_cases_tac := ⟨"cases", cases⟩
/-- The `auto_cases_tac` for `tactic.induction`. -/
meta def tac_induction : auto_cases_tac := ⟨"induction", induction⟩
/-- Find an `auto_cases_tac` which matches the given `type : expr`. -/
meta def find_tac : expr → option auto_cases_tac
| `(empty) := tac_cases
| `(pempty) := tac_cases
| `(false) := tac_cases
| `(unit) := tac_cases
| `(punit) := tac_cases
| `(ulift _) := tac_cases
| `(plift _) := tac_cases
| `(prod _ _) := tac_cases
| `(and _ _) := tac_cases
| `(sigma _) := tac_cases
| `(psigma _) := tac_cases
| `(subtype _) := tac_cases
| `(Exists _) := tac_cases
| `(fin 0) := tac_cases
| `(sum _ _) := tac_cases -- This is perhaps dangerous!
| `(or _ _) := tac_cases -- This is perhaps dangerous!
| `(iff _ _) := tac_cases -- This is perhaps dangerous!
/- `cases` can be dangerous on `eq` and `quot`, producing mysterious errors during type checking.
instead we attempt `induction`. -/
| `(eq _ _) := tac_induction
| `(quot _) := tac_induction
| _ := none
end auto_cases
/-- Applies `cases` or `induction` on the local_hypothesis `hyp : expr`. -/
meta def auto_cases_at (find : expr → option auto_cases.auto_cases_tac) (hyp : expr) :
tactic string :=
do t ← infer_type hyp >>= whnf,
match find t with
| some atac := do
atac.tac hyp,
pp ← pp hyp,
return sformat!"{atac.name} {pp}"
| none := fail "hypothesis type unsupported"
end
/-- Applies `cases` or `induction` on certain hypotheses. -/
@[hint_tactic]
meta def auto_cases (find := tactic.auto_cases.find_tac) : tactic string :=
do l ← local_context,
results ← successes $ l.reverse.map (auto_cases_at find),
when (results.empty) $
fail "`auto_cases` did not find any hypotheses to apply `cases` or `induction` to",
return (string.intercalate ", " results)
end tactic
|
68523f7d03691b29ad62fbab6f366fa5522cff0a | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /tests/lean/run/ind_ns.lean | b00a3168db3639ac4604c3ba384821876beb8c94 | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 125 | lean | inductive day
| monday | tuesday | wednesday | thursday | friday | saturday | sunday
check day.monday
open day
check monday
|
2ef926ed1b6d0092df5705982fbe3d8a5edb6a9a | f5f7e6fae601a5fe3cac7cc3ed353ed781d62419 | /src/measure_theory/measurable_space.lean | 9f22699076c15851fa9b30e42d37a9a990057c98 | [
"Apache-2.0"
] | permissive | EdAyers/mathlib | 9ecfb2f14bd6caad748b64c9c131befbff0fb4e0 | ca5d4c1f16f9c451cf7170b10105d0051db79e1b | refs/heads/master | 1,626,189,395,845 | 1,555,284,396,000 | 1,555,284,396,000 | 144,004,030 | 0 | 0 | Apache-2.0 | 1,533,727,664,000 | 1,533,727,663,000 | null | UTF-8 | Lean | false | false | 39,156 | 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
Measurable spaces -- σ-algberas
-/
import data.set.disjointed data.finset order.galois_connection data.set.countable
open set lattice encodable
local attribute [instance] classical.prop_decidable
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x} {ι : Sort x}
{s t u : set α}
structure measurable_space (α : Type u) :=
(is_measurable : set α → Prop)
(is_measurable_empty : is_measurable ∅)
(is_measurable_compl : ∀s, is_measurable s → is_measurable (- s))
(is_measurable_Union : ∀f:ℕ → set α, (∀i, is_measurable (f i)) → is_measurable (⋃i, f i))
attribute [class] measurable_space
section
variable [measurable_space α]
/-- `is_measurable s` means that `s` is measurable (in the ambient measure space on `α`) -/
def is_measurable : set α → Prop := ‹measurable_space α›.is_measurable
lemma is_measurable.empty : is_measurable (∅ : set α) :=
‹measurable_space α›.is_measurable_empty
lemma is_measurable.compl : is_measurable s → is_measurable (-s) :=
‹measurable_space α›.is_measurable_compl s
lemma is_measurable.compl_iff : is_measurable (-s) ↔ is_measurable s :=
⟨λ h, by simpa using h.compl, is_measurable.compl⟩
lemma is_measurable.univ : is_measurable (univ : set α) :=
by simpa using (@is_measurable.empty α _).compl
lemma encodable.Union_decode2 {α} [encodable β] (f : β → set α) :
(⋃ b, f b) = ⋃ (i : ℕ) (b ∈ decode2 β i), f b :=
ext $ by simp [mem_decode2, exists_swap]
@[elab_as_eliminator] lemma encodable.Union_decode2_cases
{α} [encodable β] {f : β → set α} {C : set α → Prop}
(H0 : C ∅) (H1 : ∀ b, C (f b)) {n} :
C (⋃ b ∈ decode2 β n, f b) :=
match decode2 β n with
| none := by simp; apply H0
| (some b) := by convert H1 b; simp [ext_iff]
end
lemma is_measurable.Union [encodable β] {f : β → set α} (h : ∀b, is_measurable (f b)) :
is_measurable (⋃b, f b) :=
by rw encodable.Union_decode2; exact
‹measurable_space α›.is_measurable_Union
(λ n, ⋃ b ∈ decode2 β n, f b)
(λ n, encodable.Union_decode2_cases is_measurable.empty h)
lemma is_measurable.bUnion {f : β → set α} {s : set β} (hs : countable s)
(h : ∀b∈s, is_measurable (f b)) : is_measurable (⋃b∈s, f b) :=
begin
rw bUnion_eq_Union,
haveI := hs.to_encodable,
exact is_measurable.Union (by simpa using h)
end
lemma is_measurable.sUnion {s : set (set α)} (hs : countable s) (h : ∀t∈s, is_measurable t) :
is_measurable (⋃₀ s) :=
by rw sUnion_eq_bUnion; exact is_measurable.bUnion hs h
lemma is_measurable.Union_Prop {p : Prop} {f : p → set α} (hf : ∀b, is_measurable (f b)) :
is_measurable (⋃b, f b) :=
by by_cases p; simp [h, hf, is_measurable.empty]
lemma is_measurable.Inter [encodable β] {f : β → set α} (h : ∀b, is_measurable (f b)) :
is_measurable (⋂b, f b) :=
is_measurable.compl_iff.1 $
by rw compl_Inter; exact is_measurable.Union (λ b, (h b).compl)
lemma is_measurable.bInter {f : β → set α} {s : set β} (hs : countable s)
(h : ∀b∈s, is_measurable (f b)) : is_measurable (⋂b∈s, f b) :=
is_measurable.compl_iff.1 $
by rw compl_bInter; exact is_measurable.bUnion hs (λ b hb, (h b hb).compl)
lemma is_measurable.sInter {s : set (set α)} (hs : countable s) (h : ∀t∈s, is_measurable t) :
is_measurable (⋂₀ s) :=
by rw sInter_eq_bInter; exact is_measurable.bInter hs h
lemma is_measurable.Inter_Prop {p : Prop} {f : p → set α} (hf : ∀b, is_measurable (f b)) :
is_measurable (⋂b, f b) :=
by by_cases p; simp [h, hf, is_measurable.univ]
lemma is_measurable.union {s₁ s₂ : set α}
(h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : is_measurable (s₁ ∪ s₂) :=
by rw union_eq_Union; exact
is_measurable.Union (bool.forall_bool.2 ⟨h₂, h₁⟩)
lemma is_measurable.inter {s₁ s₂ : set α}
(h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : is_measurable (s₁ ∩ s₂) :=
by rw inter_eq_compl_compl_union_compl; exact
(h₁.compl.union h₂.compl).compl
lemma is_measurable.diff {s₁ s₂ : set α}
(h₁ : is_measurable s₁) (h₂ : is_measurable s₂) : is_measurable (s₁ \ s₂) :=
h₁.inter h₂.compl
lemma is_measurable.sub {s₁ s₂ : set α} :
is_measurable s₁ → is_measurable s₂ → is_measurable (s₁ - s₂) :=
is_measurable.diff
lemma is_measurable.disjointed {f : ℕ → set α} (h : ∀i, is_measurable (f i)) (n) :
is_measurable (disjointed f n) :=
disjointed_induct (h n) (assume t i ht, is_measurable.diff ht $ h _)
lemma is_measurable.const (p : Prop) : is_measurable {a : α | p} :=
by by_cases p; simp [h, is_measurable.empty]; apply is_measurable.univ
end
@[extensionality] lemma measurable_space.ext :
∀{m₁ m₂ : measurable_space α}, (∀s:set α, m₁.is_measurable s ↔ m₂.is_measurable s) → m₁ = m₂
| ⟨s₁, _, _, _⟩ ⟨s₂, _, _, _⟩ h :=
have s₁ = s₂, from funext $ assume x, propext $ h x,
by subst this
namespace measurable_space
section complete_lattice
instance : partial_order (measurable_space α) :=
{ le := λm₁ m₂, m₁.is_measurable ≤ m₂.is_measurable,
le_refl := assume a b, le_refl _,
le_trans := assume a b c, le_trans,
le_antisymm := assume a b h₁ h₂, measurable_space.ext $ assume s, ⟨h₁ s, h₂ s⟩ }
/-- The smallest σ-algebra containing a collection `s` of basic sets -/
inductive generate_measurable (s : set (set α)) : set α → Prop
| basic : ∀u∈s, generate_measurable u
| empty : generate_measurable ∅
| compl : ∀s, generate_measurable s → generate_measurable (-s)
| union : ∀f:ℕ → set α, (∀n, generate_measurable (f n)) → generate_measurable (⋃i, f i)
/-- Construct the smallest measure space containing a collection of basic sets -/
def generate_from (s : set (set α)) : measurable_space α :=
{ is_measurable := generate_measurable s,
is_measurable_empty := generate_measurable.empty s,
is_measurable_compl := generate_measurable.compl,
is_measurable_Union := generate_measurable.union }
lemma is_measurable_generate_from {s : set (set α)} {t : set α} (ht : t ∈ s) :
(generate_from s).is_measurable t :=
generate_measurable.basic t ht
lemma generate_from_le {s : set (set α)} {m : measurable_space α} (h : ∀t∈s, m.is_measurable t) :
generate_from s ≤ m :=
assume t (ht : generate_measurable s t), ht.rec_on h
(is_measurable_empty m)
(assume s _ hs, is_measurable_compl m s hs)
(assume f _ hf, is_measurable_Union m f hf)
lemma generate_from_le_iff {s : set (set α)} {m : measurable_space α} :
generate_from s ≤ m ↔ s ⊆ {t | m.is_measurable t} :=
iff.intro
(assume h u hu, h _ $ is_measurable_generate_from hu)
(assume h, generate_from_le h)
protected def mk_of_closure (g : set (set α)) (hg : {t | (generate_from g).is_measurable t} = g) :
measurable_space α :=
{ is_measurable := λs, s ∈ g,
is_measurable_empty := hg ▸ is_measurable_empty _,
is_measurable_compl := hg ▸ is_measurable_compl _,
is_measurable_Union := hg ▸ is_measurable_Union _ }
lemma mk_of_closure_sets {s : set (set α)}
{hs : {t | (generate_from s).is_measurable t} = s} :
measurable_space.mk_of_closure s hs = generate_from s :=
measurable_space.ext $ assume t, show t ∈ s ↔ _, by rw [← hs] {occs := occurrences.pos [1] }; refl
def gi_generate_from : galois_insertion (@generate_from α) (λm, {t | @is_measurable α m t}) :=
{ gc := assume s m, generate_from_le_iff,
le_l_u := assume m s, is_measurable_generate_from,
choice :=
λg hg, measurable_space.mk_of_closure g $ le_antisymm hg $ generate_from_le_iff.1 $ le_refl _,
choice_eq := assume g hg, mk_of_closure_sets }
instance : complete_lattice (measurable_space α) :=
gi_generate_from.lift_complete_lattice
instance : inhabited (measurable_space α) := ⟨⊤⟩
lemma is_measurable_bot_iff {s : set α} : @is_measurable α ⊥ s ↔ (s = ∅ ∨ s = univ) :=
let b : measurable_space α :=
{ is_measurable := λs, s = ∅ ∨ s = univ,
is_measurable_empty := or.inl rfl,
is_measurable_compl := by simp [or_imp_distrib] {contextual := tt},
is_measurable_Union := assume f hf, classical.by_cases
(assume h : ∃i, f i = univ,
let ⟨i, hi⟩ := h in
or.inr $ eq_univ_of_univ_subset $ hi ▸ le_supr f i)
(assume h : ¬ ∃i, f i = univ,
or.inl $ eq_empty_of_subset_empty $ Union_subset $ assume i,
(hf i).elim (by simp {contextual := tt}) (assume hi, false.elim $ h ⟨i, hi⟩)) } in
have b = ⊥, from bot_unique $ assume s hs,
hs.elim (assume s, s.symm ▸ @is_measurable_empty _ ⊥) (assume s, s.symm ▸ @is_measurable.univ _ ⊥),
this ▸ iff.refl _
@[simp] theorem is_measurable_top {s : set α} : @is_measurable _ ⊤ s := trivial
@[simp] theorem is_measurable_inf {m₁ m₂ : measurable_space α} {s : set α} :
@is_measurable _ (m₁ ⊓ m₂) s ↔ @is_measurable _ m₁ s ∧ @is_measurable _ m₂ s :=
iff.rfl
@[simp] theorem is_measurable_Inf {ms : set (measurable_space α)} {s : set α} :
@is_measurable _ (Inf ms) s ↔ ∀ m ∈ ms, @is_measurable _ m s :=
show s ∈ (⋂m∈ms, {t | @is_measurable _ m t }) ↔ _, by simp
@[simp] theorem is_measurable_infi {ι} {m : ι → measurable_space α} {s : set α} :
@is_measurable _ (infi m) s ↔ ∀ i, @is_measurable _ (m i) s :=
show s ∈ (λm, {s | @is_measurable _ m s }) (infi m) ↔ _, by rw (@gi_generate_from α).gc.u_infi; simp; refl
end complete_lattice
section functors
variables {m m₁ m₂ : measurable_space α} {m' : measurable_space β} {f : α → β} {g : β → α}
/-- The forward image of a measure space under a function. `map f m` contains the sets `s : set β`
whose preimage under `f` is measurable. -/
protected def map (f : α → β) (m : measurable_space α) : measurable_space β :=
{ is_measurable := λs, m.is_measurable $ f ⁻¹' s,
is_measurable_empty := m.is_measurable_empty,
is_measurable_compl := assume s hs, m.is_measurable_compl _ hs,
is_measurable_Union := assume f hf, by rw [preimage_Union]; exact m.is_measurable_Union _ hf }
@[simp] lemma map_id : m.map id = m :=
measurable_space.ext $ assume s, iff.rfl
@[simp] lemma map_comp {f : α → β} {g : β → γ} : (m.map f).map g = m.map (g ∘ f) :=
measurable_space.ext $ assume s, iff.rfl
/-- The reverse image of a measure space under a function. `comap f m` contains the sets `s : set α`
such that `s` is the `f`-preimage of a measurable set in `β`. -/
protected def comap (f : α → β) (m : measurable_space β) : measurable_space α :=
{ is_measurable := λs, ∃s', m.is_measurable s' ∧ f ⁻¹' s' = s,
is_measurable_empty := ⟨∅, m.is_measurable_empty, rfl⟩,
is_measurable_compl := assume s ⟨s', h₁, h₂⟩, ⟨-s', m.is_measurable_compl _ h₁, h₂ ▸ rfl⟩,
is_measurable_Union := assume s hs,
let ⟨s', hs'⟩ := classical.axiom_of_choice hs in
⟨⋃i, s' i, m.is_measurable_Union _ (λi, (hs' i).left), by simp [hs'] ⟩ }
@[simp] lemma comap_id : m.comap id = m :=
measurable_space.ext $ assume s, ⟨assume ⟨s', hs', h⟩, h ▸ hs', assume h, ⟨s, h, rfl⟩⟩
@[simp] lemma comap_comp {f : β → α} {g : γ → β} : (m.comap f).comap g = m.comap (f ∘ g) :=
measurable_space.ext $ assume s,
⟨assume ⟨t, ⟨u, h, hu⟩, ht⟩, ⟨u, h, ht ▸ hu ▸ rfl⟩, assume ⟨t, h, ht⟩, ⟨f ⁻¹' t, ⟨_, h, rfl⟩, ht⟩⟩
lemma comap_le_iff_le_map {f : α → β} : m'.comap f ≤ m ↔ m' ≤ m.map f :=
⟨assume h s hs, h _ ⟨_, hs, rfl⟩, assume h s ⟨t, ht, heq⟩, heq ▸ h _ ht⟩
lemma gc_comap_map (f : α → β) :
galois_connection (measurable_space.comap f) (measurable_space.map f) :=
assume f g, comap_le_iff_le_map
lemma map_mono (h : m₁ ≤ m₂) : m₁.map f ≤ m₂.map f := (gc_comap_map f).monotone_u h
lemma monotone_map : monotone (measurable_space.map f) := assume a b h, map_mono h
lemma comap_mono (h : m₁ ≤ m₂) : m₁.comap g ≤ m₂.comap g := (gc_comap_map g).monotone_l h
lemma monotone_comap : monotone (measurable_space.comap g) := assume a b h, comap_mono h
@[simp] lemma comap_bot : (⊥:measurable_space α).comap g = ⊥ := (gc_comap_map g).l_bot
@[simp] lemma comap_sup : (m₁ ⊔ m₂).comap g = m₁.comap g ⊔ m₂.comap g := (gc_comap_map g).l_sup
@[simp] lemma comap_supr {m : ι → measurable_space α} :(⨆i, m i).comap g = (⨆i, (m i).comap g) :=
(gc_comap_map g).l_supr
@[simp] lemma map_top : (⊤:measurable_space α).map f = ⊤ := (gc_comap_map f).u_top
@[simp] lemma map_inf : (m₁ ⊓ m₂).map f = m₁.map f ⊓ m₂.map f := (gc_comap_map f).u_inf
@[simp] lemma map_infi {m : ι → measurable_space α} : (⨅i, m i).map f = (⨅i, (m i).map f) :=
(gc_comap_map f).u_infi
lemma comap_map_le : (m.map f).comap f ≤ m := (gc_comap_map f).l_u_le _
lemma le_map_comap : m ≤ (m.comap g).map g := (gc_comap_map g).le_u_l _
end functors
lemma generate_from_le_generate_from {s t : set (set α)} (h : s ⊆ t) :
generate_from s ≤ generate_from t :=
gi_generate_from.gc.monotone_l h
lemma generate_from_sup_generate_from {s t : set (set α)} :
generate_from s ⊔ generate_from t = generate_from (s ∪ t) :=
(@gi_generate_from α).gc.l_sup.symm
lemma comap_generate_from {f : α → β} {s : set (set β)} :
(generate_from s).comap f = generate_from (preimage f '' s) :=
le_antisymm
(comap_le_iff_le_map.2 $ generate_from_le $ assume t hts,
generate_measurable.basic _ $ mem_image_of_mem _ $ hts)
(generate_from_le $ assume t ⟨u, hu, eq⟩, eq ▸ ⟨u, generate_measurable.basic _ hu, rfl⟩)
end measurable_space
section measurable_functions
open measurable_space
/-- A function `f` between measurable spaces is measurable if the preimage of every
measurable set is measurable. -/
def measurable [m₁ : measurable_space α] [m₂ : measurable_space β] (f : α → β) : Prop :=
m₂ ≤ m₁.map f
lemma measurable_id [measurable_space α] : measurable (@id α) := le_refl _
lemma measurable.preimage [measurable_space α] [measurable_space β]
{f : α → β} (hf : measurable f) {s : set β} : is_measurable s → is_measurable (f ⁻¹' s) := hf _
lemma measurable.comp [measurable_space α] [measurable_space β] [measurable_space γ]
{f : α → β} {g : β → γ} (hf : measurable f) (hg : measurable g) : measurable (g ∘ f) :=
le_trans hg $ map_mono hf
lemma measurable_generate_from [measurable_space α] {s : set (set β)} {f : α → β}
(h : ∀t∈s, is_measurable (f ⁻¹' t)) : @measurable _ _ _ (generate_from s) f :=
generate_from_le h
lemma measurable.if [measurable_space α] [measurable_space β]
{p : α → Prop} {h : decidable_pred p} {f g : α → β}
(hp : is_measurable {a | p a}) (hf : measurable f) (hg : measurable g) :
measurable (λa, if p a then f a else g a) :=
λ s hs, show is_measurable {a | (if p a then f a else g a) ∈ s},
begin
convert (hp.inter $ hf s hs).union (hp.compl.inter $ hg s hs),
exact ext (λ a, by by_cases p a; simp [h, mem_def])
end
lemma measurable_const {α β} [measurable_space α] [measurable_space β] {a : α} : measurable (λb:β, a) :=
assume s hs, show is_measurable {b : β | a ∈ s}, from
classical.by_cases
(assume h : a ∈ s, by simp [h]; from is_measurable.univ)
(assume h : a ∉ s, by simp [h]; from is_measurable.empty)
end measurable_functions
section constructions
instance : measurable_space empty := ⊤
instance : measurable_space unit := ⊤
instance : measurable_space bool := ⊤
instance : measurable_space ℕ := ⊤
instance : measurable_space ℤ := ⊤
lemma measurable_unit [measurable_space α] (f : unit → α) : measurable f :=
have f = (λu, f ()) := funext $ assume ⟨⟩, rfl,
by rw this; exact measurable_const
section subtype
instance {p : α → Prop} [m : measurable_space α] : measurable_space (subtype p) :=
m.comap subtype.val
lemma measurable_subtype_val [measurable_space α] [measurable_space β] {p : β → Prop}
{f : α → subtype p} (hf : measurable f) : measurable (λa:α, (f a).val) :=
hf.comp $ measurable_space.comap_le_iff_le_map.mp $ le_refl _
lemma measurable_subtype_mk [measurable_space α] [measurable_space β] {p : β → Prop}
{f : α → subtype p} (hf : measurable (λa, (f a).val)) : measurable f :=
measurable_space.comap_le_iff_le_map.mpr $ by rw [measurable_space.map_comp]; exact hf
lemma is_measurable_subtype_image [measurable_space α] {s : set α} {t : set s}
(hs : is_measurable s) : is_measurable t → is_measurable ((coe : s → α) '' t)
| ⟨u, (hu : is_measurable u), (eq : coe ⁻¹' u = t)⟩ :=
begin
rw [← eq, image_preimage_eq_inter_range, range_coe_subtype],
exact is_measurable.inter hu hs
end
lemma measurable_of_measurable_union_cover
[measurable_space α] [measurable_space β]
{f : α → β} (s t : set α) (hs : is_measurable s) (ht : is_measurable t) (h : univ ⊆ s ∪ t)
(hc : measurable (λa:s, f a)) (hd : measurable (λa:t, f a)) :
measurable f :=
assume u (hu : is_measurable u), show is_measurable (f ⁻¹' u), from
begin
rw show f ⁻¹' u = coe '' (coe ⁻¹' (f ⁻¹' u) : set s) ∪ coe '' (coe ⁻¹' (f ⁻¹' u) : set t),
by rw [image_preimage_eq_inter_range, image_preimage_eq_inter_range, range_coe_subtype, range_coe_subtype, ← inter_distrib_left, univ_subset_iff.1 h, inter_univ],
exact is_measurable.union
(is_measurable_subtype_image hs (hc _ hu))
(is_measurable_subtype_image ht (hd _ hu))
end
end subtype
section prod
instance [m₁ : measurable_space α] [m₂ : measurable_space β] : measurable_space (α × β) :=
m₁.comap prod.fst ⊔ m₂.comap prod.snd
lemma measurable_fst [measurable_space α] [measurable_space β] [measurable_space γ]
{f : α → β × γ} (hf : measurable f) : measurable (λa:α, (f a).1) :=
hf.comp $ measurable_space.comap_le_iff_le_map.mp $ le_sup_left
lemma measurable_snd [measurable_space α] [measurable_space β] [measurable_space γ]
{f : α → β × γ} (hf : measurable f) : measurable (λa:α, (f a).2) :=
hf.comp $ measurable_space.comap_le_iff_le_map.mp $ le_sup_right
lemma measurable.prod [measurable_space α] [measurable_space β] [measurable_space γ]
{f : α → β × γ} (hf₁ : measurable (λa, (f a).1)) (hf₂ : measurable (λa, (f a).2)) :
measurable f :=
sup_le
(by rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp]; exact hf₁)
(by rw [measurable_space.comap_le_iff_le_map, measurable_space.map_comp]; exact hf₂)
lemma measurable_prod_mk [measurable_space α] [measurable_space β] [measurable_space γ]
{f : α → β} {g : α → γ} (hf : measurable f) (hg : measurable g) : measurable (λa:α, (f a, g a)) :=
measurable.prod hf hg
lemma is_measurable_set_prod [measurable_space α] [measurable_space β] {s : set α} {t : set β}
(hs : is_measurable s) (ht : is_measurable t) : is_measurable (set.prod s t) :=
is_measurable.inter (measurable_fst measurable_id _ hs) (measurable_snd measurable_id _ ht)
end prod
instance [m₁ : measurable_space α] [m₂ : measurable_space β] : measurable_space (α ⊕ β) :=
m₁.map sum.inl ⊓ m₂.map sum.inr
section sum
variables [measurable_space α] [measurable_space β] [measurable_space γ]
lemma measurable_inl : measurable (@sum.inl α β) := inf_le_left
lemma measurable_inr : measurable (@sum.inr α β) := inf_le_right
lemma measurable_sum {f : α ⊕ β → γ}
(hl : measurable (f ∘ sum.inl)) (hr : measurable (f ∘ sum.inr)) : measurable f :=
measurable_space.comap_le_iff_le_map.1 $ le_inf
(measurable_space.comap_le_iff_le_map.2 $ hl)
(measurable_space.comap_le_iff_le_map.2 $ hr)
lemma measurable_sum_rec {f : α → γ} {g : β → γ}
(hf : measurable f) (hg : measurable g) : @measurable (α ⊕ β) γ _ _ (@sum.rec α β (λ_, γ) f g) :=
measurable_sum hf hg
lemma is_measurable_inl_image [measurable_space α] [measurable_space β] {s : set α}
(hs : is_measurable s) : is_measurable (sum.inl '' s : set (α ⊕ β)) :=
⟨show is_measurable (sum.inl ⁻¹' _), by rwa [preimage_image_eq]; exact (assume a b, sum.inl.inj),
have sum.inr ⁻¹' (sum.inl '' s : set (α ⊕ β)) = ∅ :=
eq_empty_of_subset_empty $ assume x ⟨y, hy, eq⟩, by contradiction,
show is_measurable (sum.inr ⁻¹' _), by rw [this]; exact is_measurable.empty⟩
lemma is_measurable_range_inl [measurable_space α] [measurable_space β] :
is_measurable (range sum.inl : set (α ⊕ β)) :=
by rw [← image_univ]; exact is_measurable_inl_image is_measurable.univ
lemma is_measurable_inr_image [measurable_space α] [measurable_space β] {s : set β}
(hs : is_measurable s) : is_measurable (sum.inr '' s : set (α ⊕ β)) :=
⟨ have sum.inl ⁻¹' (sum.inr '' s : set (α ⊕ β)) = ∅ :=
eq_empty_of_subset_empty $ assume x ⟨y, hy, eq⟩, by contradiction,
show is_measurable (sum.inl ⁻¹' _), by rw [this]; exact is_measurable.empty,
show is_measurable (sum.inr ⁻¹' _), by rwa [preimage_image_eq]; exact (assume a b, sum.inr.inj)⟩
lemma is_measurable_range_inr [measurable_space α] [measurable_space β] :
is_measurable (range sum.inr : set (α ⊕ β)) :=
by rw [← image_univ]; exact is_measurable_inr_image is_measurable.univ
end sum
instance {β : α → Type v} [m : Πa, measurable_space (β a)] : measurable_space (sigma β) :=
⨅a, (m a).map (sigma.mk a)
end constructions
/-- Equivalences between measurable spaces. Main application is the simplification of measurability
statements along measurable equivalences. -/
structure measurable_equiv (α β : Type*) [measurable_space α] [measurable_space β] extends α ≃ β :=
(measurable_to_fun : measurable to_fun)
(measurable_inv_fun : measurable inv_fun)
namespace measurable_equiv
instance (α β) [measurable_space α] [measurable_space β] : has_coe_to_fun (measurable_equiv α β) :=
⟨λ_, α → β, λe, e.to_equiv⟩
lemma coe_eq {α β} [measurable_space α] [measurable_space β] (e : measurable_equiv α β) :
(e : α → β) = e.to_equiv := rfl
def refl (α : Type*) [measurable_space α] : measurable_equiv α α :=
{ to_equiv := equiv.refl α,
measurable_to_fun := measurable_id, measurable_inv_fun := measurable_id }
def trans [measurable_space α] [measurable_space β] [measurable_space γ]
(ab : measurable_equiv α β) (bc : measurable_equiv β γ) :
measurable_equiv α γ :=
{ to_equiv := ab.to_equiv.trans bc.to_equiv,
measurable_to_fun := ab.measurable_to_fun.comp bc.measurable_to_fun,
measurable_inv_fun := bc.measurable_inv_fun.comp ab.measurable_inv_fun }
lemma trans_to_equiv {α β} [measurable_space α] [measurable_space β] [measurable_space γ]
(e : measurable_equiv α β) (f : measurable_equiv β γ) :
(e.trans f).to_equiv = e.to_equiv.trans f.to_equiv := rfl
def symm [measurable_space α] [measurable_space β] (ab : measurable_equiv α β) :
measurable_equiv β α :=
{ to_equiv := ab.to_equiv.symm,
measurable_to_fun := ab.measurable_inv_fun,
measurable_inv_fun := ab.measurable_to_fun }
lemma symm_to_equiv {α β} [measurable_space α] [measurable_space β] (e : measurable_equiv α β) :
e.symm.to_equiv = e.to_equiv.symm := rfl
protected def cast {α β} [i₁ : measurable_space α] [i₂ : measurable_space β]
(h : α = β) (hi : i₁ == i₂) : measurable_equiv α β :=
{ to_equiv := equiv.cast h,
measurable_to_fun := by unfreezeI; subst h; subst hi; exact measurable_id,
measurable_inv_fun := by unfreezeI; subst h; subst hi; exact measurable_id }
protected lemma measurable {α β} [measurable_space α] [measurable_space β]
(e : measurable_equiv α β) : measurable (e : α → β) :=
e.measurable_to_fun
protected lemma measurable_coe_iff {α β γ} [measurable_space α] [measurable_space β] [measurable_space γ]
{f : β → γ} (e : measurable_equiv α β) : measurable (f ∘ e) ↔ measurable f :=
iff.intro
(assume hfe,
have measurable (f ∘ (e.symm.trans e).to_equiv) := e.symm.measurable.comp hfe,
by rwa [trans_to_equiv, symm_to_equiv, equiv.symm_trans] at this)
(e.measurable.comp)
def prod_congr [measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ]
(ab : measurable_equiv α β) (cd : measurable_equiv γ δ) :
measurable_equiv (α × γ) (β × δ) :=
{ to_equiv := equiv.prod_congr ab.to_equiv cd.to_equiv,
measurable_to_fun := measurable_prod_mk
((measurable_fst measurable_id).comp ab.measurable_to_fun)
((measurable_snd measurable_id).comp cd.measurable_to_fun),
measurable_inv_fun := measurable_prod_mk
((measurable_fst measurable_id).comp ab.measurable_inv_fun)
((measurable_snd measurable_id).comp cd.measurable_inv_fun) }
def prod_comm [measurable_space α] [measurable_space β] : measurable_equiv (α × β) (β × α) :=
{ to_equiv := equiv.prod_comm α β,
measurable_to_fun := measurable_prod_mk (measurable_snd measurable_id) (measurable_fst measurable_id),
measurable_inv_fun := measurable_prod_mk (measurable_snd measurable_id) (measurable_fst measurable_id) }
def sum_congr [measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ]
(ab : measurable_equiv α β) (cd : measurable_equiv γ δ) :
measurable_equiv (α ⊕ γ) (β ⊕ δ) :=
{ to_equiv := equiv.sum_congr ab.to_equiv cd.to_equiv,
measurable_to_fun :=
begin
cases ab with ab' abm, cases ab', cases cd with cd' cdm, cases cd',
refine measurable_sum (abm.comp measurable_inl) (cdm.comp measurable_inr)
end,
measurable_inv_fun :=
begin
cases ab with ab' _ abm, cases ab', cases cd with cd' _ cdm, cases cd',
refine measurable_sum (abm.comp measurable_inl) (cdm.comp measurable_inr)
end }
def set.prod [measurable_space α] [measurable_space β] (s : set α) (t : set β) :
measurable_equiv (set.prod s t) (s × t) :=
{ to_equiv := equiv.set.prod s t,
measurable_to_fun := measurable_prod_mk
(measurable_subtype_mk $ measurable_fst $ measurable_subtype_val $ measurable_id)
(measurable_subtype_mk $ measurable_snd $ measurable_subtype_val $ measurable_id),
measurable_inv_fun := measurable_subtype_mk $ measurable_prod_mk
(measurable_subtype_val $ measurable_fst $ measurable_id)
(measurable_subtype_val $ measurable_snd $ measurable_id) }
def set.univ (α : Type*) [measurable_space α] : measurable_equiv (univ : set α) α :=
{ to_equiv := equiv.set.univ α,
measurable_to_fun := measurable_subtype_val measurable_id,
measurable_inv_fun := measurable_subtype_mk measurable_id }
def set.singleton [measurable_space α] (a:α) : measurable_equiv ({a} : set α) unit :=
{ to_equiv := equiv.set.singleton a,
measurable_to_fun := measurable_const,
measurable_inv_fun := measurable_subtype_mk $ show measurable (λu:unit, a), from
measurable_const }
noncomputable def set.image [measurable_space α] [measurable_space β]
(f : α → β) (s : set α)
(hf : function.injective f)
(hfm : measurable f) (hfi : ∀s, is_measurable s → is_measurable (f '' s)) :
measurable_equiv s (f '' s) :=
{ to_equiv := equiv.set.image f s hf,
measurable_to_fun :=
begin
have : measurable (λa:s, f a) := (measurable_subtype_val measurable_id).comp hfm,
refine measurable_subtype_mk _,
convert this,
ext ⟨a, h⟩, refl
end,
measurable_inv_fun :=
assume t ⟨u, (hu : is_measurable u), eq⟩,
begin
clear_, subst eq,
show is_measurable {x : f '' s | ((equiv.set.image f s hf).inv_fun x).val ∈ u},
have : ∀(a ∈ s) (h : ∃a', a' ∈ s ∧ a' = a), classical.some h = a :=
λa ha h, (classical.some_spec h).2,
rw show {x:f '' s | ((equiv.set.image f s hf).inv_fun x).val ∈ u} = subtype.val ⁻¹' (f '' u),
by ext ⟨b, a, hbs, rfl⟩; simp [equiv.set.image, hf, this _ hbs],
exact (measurable_subtype_val measurable_id) (f '' u) (hfi u hu)
end }
noncomputable def set.range [measurable_space α] [measurable_space β]
(f : α → β) (hf : function.injective f) (hfm : measurable f)
(hfi : ∀s, is_measurable s → is_measurable (f '' s)) :
measurable_equiv α (range f) :=
(measurable_equiv.set.univ _).symm.trans $
(measurable_equiv.set.image f univ hf hfm hfi).trans $
measurable_equiv.cast (by rw image_univ) (by rw image_univ)
def set.range_inl [measurable_space α] [measurable_space β] :
measurable_equiv (range sum.inl : set (α ⊕ β)) α :=
{ to_fun := λab, match ab with
| ⟨sum.inl a, _⟩ := a
| ⟨sum.inr b, p⟩ := have false, by cases p; contradiction, this.elim
end,
inv_fun := λa, ⟨sum.inl a, a, rfl⟩,
left_inv := assume ⟨ab, a, eq⟩, by subst eq; refl,
right_inv := assume a, rfl,
measurable_to_fun := assume s (hs : is_measurable s),
begin
refine ⟨_, is_measurable_inl_image hs, set.ext _⟩,
rintros ⟨ab, a, rfl⟩,
simp [set.range_inl._match_1]
end,
measurable_inv_fun := measurable_subtype_mk measurable_inl }
def set.range_inr [measurable_space α] [measurable_space β] :
measurable_equiv (range sum.inr : set (α ⊕ β)) β :=
{ to_fun := λab, match ab with
| ⟨sum.inr b, _⟩ := b
| ⟨sum.inl a, p⟩ := have false, by cases p; contradiction, this.elim
end,
inv_fun := λb, ⟨sum.inr b, b, rfl⟩,
left_inv := assume ⟨ab, b, eq⟩, by subst eq; refl,
right_inv := assume b, rfl,
measurable_to_fun := assume s (hs : is_measurable s),
begin
refine ⟨_, is_measurable_inr_image hs, set.ext _⟩,
rintros ⟨ab, b, rfl⟩,
simp [set.range_inr._match_1]
end,
measurable_inv_fun := measurable_subtype_mk measurable_inr }
def sum_prod_distrib (α β γ) [measurable_space α] [measurable_space β] [measurable_space γ] :
measurable_equiv ((α ⊕ β) × γ) ((α × γ) ⊕ (β × γ)) :=
{ to_equiv := equiv.sum_prod_distrib α β γ,
measurable_to_fun :=
begin
refine measurable_of_measurable_union_cover
((range sum.inl).prod univ)
((range sum.inr).prod univ)
(is_measurable_set_prod is_measurable_range_inl is_measurable.univ)
(is_measurable_set_prod is_measurable_range_inr is_measurable.univ)
(assume ⟨ab, c⟩ s, by cases ab; simp [set.prod_eq])
_
_,
{ refine (set.prod (range sum.inl) univ).symm.measurable_coe_iff.1 _,
refine (prod_congr set.range_inl (set.univ _)).symm.measurable_coe_iff.1 _,
dsimp [(∘)],
convert measurable_inl,
ext ⟨a, c⟩, refl },
{ refine (set.prod (range sum.inr) univ).symm.measurable_coe_iff.1 _,
refine (prod_congr set.range_inr (set.univ _)).symm.measurable_coe_iff.1 _,
dsimp [(∘)],
convert measurable_inr,
ext ⟨b, c⟩, refl }
end,
measurable_inv_fun :=
begin
refine measurable_sum _ _,
{ convert measurable_prod_mk
((measurable_fst measurable_id).comp (measurable_inl)) (measurable_snd measurable_id),
ext ⟨a, c⟩; refl },
{ convert measurable_prod_mk
((measurable_fst measurable_id).comp (measurable_inr)) (measurable_snd measurable_id),
ext ⟨b, c⟩; refl }
end }
def prod_sum_distrib (α β γ) [measurable_space α] [measurable_space β] [measurable_space γ] :
measurable_equiv (α × (β ⊕ γ)) ((α × β) ⊕ (α × γ)) :=
prod_comm.trans $ (sum_prod_distrib _ _ _).trans $ sum_congr prod_comm prod_comm
def sum_prod_sum (α β γ δ)
[measurable_space α] [measurable_space β] [measurable_space γ] [measurable_space δ] :
measurable_equiv ((α ⊕ β) × (γ ⊕ δ)) (((α × γ) ⊕ (α × δ)) ⊕ ((β × γ) ⊕ (β × δ))) :=
(sum_prod_distrib _ _ _).trans $ sum_congr (prod_sum_distrib _ _ _) (prod_sum_distrib _ _ _)
end measurable_equiv
namespace measurable_equiv
end measurable_equiv
namespace measurable_space
/-- Dynkin systems
The main purpose of Dynkin systems is to provide a powerful induction rule for σ-algebras generated
by intersection stable set systems.
-/
structure dynkin_system (α : Type*) :=
(has : set α → Prop)
(has_empty : has ∅)
(has_compl : ∀{a}, has a → has (-a))
(has_Union_nat : ∀{f:ℕ → set α}, pairwise (disjoint on f) → (∀i, has (f i)) → has (⋃i, f i))
theorem Union_decode2_disjoint_on
{β} [encodable β] {f : β → set α} (hd : pairwise (disjoint on f)) :
pairwise (disjoint on λ i, ⋃ b ∈ decode2 β i, f b) :=
begin
rintro i j ij x ⟨h₁, h₂⟩,
revert h₁ h₂,
simp, intros b₁ e₁ h₁ b₂ e₂ h₂,
refine hd _ _ _ ⟨h₁, h₂⟩,
cases encodable.mem_decode2.1 e₁,
cases encodable.mem_decode2.1 e₂,
exact mt (congr_arg _) ij
end
namespace dynkin_system
@[extensionality] lemma ext :
∀{d₁ d₂ : dynkin_system α}, (∀s:set α, d₁.has s ↔ d₂.has s) → d₁ = d₂
| ⟨s₁, _, _, _⟩ ⟨s₂, _, _, _⟩ h :=
have s₁ = s₂, from funext $ assume x, propext $ h x,
by subst this
variable (d : dynkin_system α)
lemma has_compl_iff {a} : d.has (-a) ↔ d.has a :=
⟨λ h, by simpa using d.has_compl h, λ h, d.has_compl h⟩
lemma has_univ : d.has univ :=
by simpa using d.has_compl d.has_empty
theorem has_Union {β} [encodable β] {f : β → set α}
(hd : pairwise (disjoint on f)) (h : ∀i, d.has (f i)) : d.has (⋃i, f i) :=
by rw encodable.Union_decode2; exact
d.has_Union_nat (Union_decode2_disjoint_on hd)
(λ n, encodable.Union_decode2_cases d.has_empty h)
theorem has_union {s₁ s₂ : set α}
(h₁ : d.has s₁) (h₂ : d.has s₂) (h : s₁ ∩ s₂ ⊆ ∅) : d.has (s₁ ∪ s₂) :=
by rw union_eq_Union; exact
d.has_Union (pairwise_disjoint_on_bool.2 h)
(bool.forall_bool.2 ⟨h₂, h₁⟩)
lemma has_diff {s₁ s₂ : set α} (h₁ : d.has s₁) (h₂ : d.has s₂) (h : s₂ ⊆ s₁) : d.has (s₁ \ s₂) :=
d.has_compl_iff.1 begin
simp [diff_eq, compl_inter],
exact d.has_union (d.has_compl h₁) h₂ (λ x ⟨h₁, h₂⟩, h₁ (h h₂)),
end
instance : partial_order (dynkin_system α) :=
{ le := λm₁ m₂, m₁.has ≤ m₂.has,
le_refl := assume a b, le_refl _,
le_trans := assume a b c, le_trans,
le_antisymm := assume a b h₁ h₂, ext $ assume s, ⟨h₁ s, h₂ s⟩ }
def of_measurable_space (m : measurable_space α) : dynkin_system α :=
{ has := m.is_measurable,
has_empty := m.is_measurable_empty,
has_compl := m.is_measurable_compl,
has_Union_nat := assume f _ hf, m.is_measurable_Union f hf }
lemma of_measurable_space_le_of_measurable_space_iff {m₁ m₂ : measurable_space α} :
of_measurable_space m₁ ≤ of_measurable_space m₂ ↔ m₁ ≤ m₂ :=
iff.rfl
/-- The least Dynkin system containing a collection of basic sets. -/
inductive generate_has (s : set (set α)) : set α → Prop
| basic : ∀t∈s, generate_has t
| empty : generate_has ∅
| compl : ∀{a}, generate_has a → generate_has (-a)
| Union : ∀{f:ℕ → set α}, pairwise (disjoint on f) →
(∀i, generate_has (f i)) → generate_has (⋃i, f i)
def generate (s : set (set α)) : dynkin_system α :=
{ has := generate_has s,
has_empty := generate_has.empty s,
has_compl := assume a, generate_has.compl,
has_Union_nat := assume f, generate_has.Union }
def to_measurable_space (h_inter : ∀s₁ s₂, d.has s₁ → d.has s₂ → d.has (s₁ ∩ s₂)) :=
{ measurable_space .
is_measurable := d.has,
is_measurable_empty := d.has_empty,
is_measurable_compl := assume s h, d.has_compl h,
is_measurable_Union := assume f hf,
have ∀n, d.has (disjointed f n),
from assume n, disjointed_induct (hf n)
(assume t i h, h_inter _ _ h $ d.has_compl $ hf i),
have d.has (⋃n, disjointed f n), from d.has_Union disjoint_disjointed this,
by rwa [Union_disjointed] at this }
lemma of_measurable_space_to_measurable_space
(h_inter : ∀s₁ s₂, d.has s₁ → d.has s₂ → d.has (s₁ ∩ s₂)) :
of_measurable_space (d.to_measurable_space h_inter) = d :=
ext $ assume s, iff.rfl
def restrict_on {s : set α} (h : d.has s) : dynkin_system α :=
{ has := λt, d.has (t ∩ s),
has_empty := by simp [d.has_empty],
has_compl := assume t hts,
have -t ∩ s = (- (t ∩ s)) \ -s,
from set.ext $ assume x, by by_cases x ∈ s; simp [h],
by rw [this]; from d.has_diff (d.has_compl hts) (d.has_compl h)
(compl_subset_compl.mpr $ inter_subset_right _ _),
has_Union_nat := assume f hd hf,
begin
rw [inter_comm, inter_Union_left],
apply d.has_Union_nat,
{ exact λ i j h x ⟨⟨_, h₁⟩, _, h₂⟩, hd i j h ⟨h₁, h₂⟩ },
{ simpa [inter_comm] using hf },
end }
lemma generate_le {s : set (set α)} (h : ∀t∈s, d.has t) : generate s ≤ d :=
λ t ht, ht.rec_on h d.has_empty
(assume a _ h, d.has_compl h)
(assume f hd _ hf, d.has_Union hd hf)
lemma generate_inter {s : set (set α)}
(hs : ∀t₁ t₂, t₁ ∈ s → t₂ ∈ s → t₁ ∩ t₂ ≠ ∅ → t₁ ∩ t₂ ∈ s) {t₁ t₂ : set α}
(ht₁ : (generate s).has t₁) (ht₂ : (generate s).has t₂) : (generate s).has (t₁ ∩ t₂) :=
have generate s ≤ (generate s).restrict_on ht₂,
from generate_le _ $ assume s₁ hs₁,
have (generate s).has s₁, from generate_has.basic s₁ hs₁,
have generate s ≤ (generate s).restrict_on this,
from generate_le _ $ assume s₂ hs₂,
show (generate s).has (s₂ ∩ s₁), from
if h : s₂ ∩ s₁ = ∅ then by rw [h]; exact generate_has.empty _
else generate_has.basic _ (hs _ _ hs₂ hs₁ h),
have (generate s).has (t₂ ∩ s₁), from this _ ht₂,
show (generate s).has (s₁ ∩ t₂), by rwa [inter_comm],
this _ ht₁
lemma generate_from_eq {s : set (set α)}
(hs : ∀t₁ t₂, t₁ ∈ s → t₂ ∈ s → t₁ ∩ t₂ ≠ ∅ → t₁ ∩ t₂ ∈ s) :
generate_from s = (generate s).to_measurable_space (assume t₁ t₂, generate_inter hs) :=
le_antisymm
(generate_from_le $ assume t ht, generate_has.basic t ht)
(of_measurable_space_le_of_measurable_space_iff.mp $
by rw [of_measurable_space_to_measurable_space];
from (generate_le _ $ assume t ht, is_measurable_generate_from ht))
end dynkin_system
lemma induction_on_inter {C : set α → Prop} {s : set (set α)} {m : measurable_space α}
(h_eq : m = generate_from s)
(h_inter : ∀t₁ t₂, t₁ ∈ s → t₂ ∈ s → t₁ ∩ t₂ ≠ ∅ → t₁ ∩ t₂ ∈ s)
(h_empty : C ∅) (h_basic : ∀t∈s, C t) (h_compl : ∀t, m.is_measurable t → C t → C (- t))
(h_union : ∀f:ℕ → set α, (∀i j, i ≠ j → f i ∩ f j ⊆ ∅) →
(∀i, m.is_measurable (f i)) → (∀i, C (f i)) → C (⋃i, f i)) :
∀{t}, m.is_measurable t → C t :=
have eq : m.is_measurable = dynkin_system.generate_has s,
by rw [h_eq, dynkin_system.generate_from_eq h_inter]; refl,
assume t ht,
have dynkin_system.generate_has s t, by rwa [eq] at ht,
this.rec_on h_basic h_empty
(assume t ht, h_compl t $ by rw [eq]; exact ht)
(assume f hf ht, h_union f hf $ assume i, by rw [eq]; exact ht _)
end measurable_space
|
1b10f7e22e24bac3faaaea9b2c1ca464a9c5046c | 367134ba5a65885e863bdc4507601606690974c1 | /src/data/polynomial/degree/trailing_degree.lean | 8d13d8a5b3948ca32980a49ed8550cb2e6803770 | [
"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 | 13,102 | lean | /-
Copyright (c) 2020 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import data.polynomial.degree.definitions
/-!
# Trailing degree of univariate polynomials
## Main definitions
* `trailing_degree p`: the multiplicity of `X` in the polynomial `p`
* `nat_trailing_degree`: a variant of `trailing_degree` that takes values in the natural numbers
* `trailing_coeff`: the coefficient at index `nat_trailing_degree p`
Converts most results about `degree`, `nat_degree` and `leading_coeff` to results about the bottom
end of a polynomial
-/
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
open function polynomial finsupp finset
open_locale big_operators
namespace polynomial
universes u v
variables {R : Type u} {S : Type v} {a b : R} {n m : ℕ}
section semiring
variables [semiring R] {p q r : polynomial R}
/-- `trailing_degree p` is the multiplicity of `x` in the polynomial `p`, i.e. the smallest
`X`-exponent in `p`.
`trailing_degree p = some n` when `p ≠ 0` and `n` is the smallest power of `X` that appears
in `p`, otherwise
`trailing_degree 0 = ⊤`. -/
def trailing_degree (p : polynomial R) : with_top ℕ := p.support.inf some
lemma trailing_degree_lt_wf : well_founded
(λp q : polynomial R, trailing_degree p < trailing_degree q) :=
inv_image.wf trailing_degree (with_top.well_founded_lt nat.lt_wf)
/-- `nat_trailing_degree p` forces `trailing_degree p` to `ℕ`, by defining
`nat_trailing_degree ⊤ = 0`. -/
def nat_trailing_degree (p : polynomial R) : ℕ := (trailing_degree p).get_or_else 0
/-- `trailing_coeff p` gives the coefficient of the smallest power of `X` in `p`-/
def trailing_coeff (p : polynomial R) : R := coeff p (nat_trailing_degree p)
/-- a polynomial is `monic_at` if its trailing coefficient is 1 -/
def trailing_monic (p : polynomial R) := trailing_coeff p = (1 : R)
lemma trailing_monic.def : trailing_monic p ↔ trailing_coeff p = 1 := iff.rfl
instance trailing_monic.decidable [decidable_eq R] : decidable (trailing_monic p) :=
by unfold trailing_monic; apply_instance
@[simp] lemma trailing_monic.trailing_coeff {p : polynomial R} (hp : p.trailing_monic) :
trailing_coeff p = 1 := hp
@[simp] lemma trailing_degree_zero : trailing_degree (0 : polynomial R) = ⊤ := rfl
@[simp] lemma nat_trailing_degree_zero : nat_trailing_degree (0 : polynomial R) = 0 := rfl
lemma trailing_degree_eq_top : trailing_degree p = ⊤ ↔ p = 0 :=
⟨λ h, by rw [trailing_degree, ← min_eq_inf_with_top] at h;
exact support_eq_empty.1 (min_eq_none.1 h),
λ h, h.symm ▸ rfl⟩
lemma trailing_degree_eq_nat_trailing_degree (hp : p ≠ 0) :
trailing_degree p = (nat_trailing_degree p : with_top ℕ) :=
let ⟨n, hn⟩ :=
not_forall.1 (mt option.eq_none_iff_forall_not_mem.2 (mt trailing_degree_eq_top.1 hp)) in
have hn : trailing_degree p = some n := not_not.1 hn,
by rw [nat_trailing_degree, hn]; refl
lemma trailing_degree_eq_iff_nat_trailing_degree_eq {p : polynomial R} {n : ℕ} (hp : p ≠ 0) :
p.trailing_degree = n ↔ p.nat_trailing_degree = n :=
by rw [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_eq_coe]
lemma trailing_degree_eq_iff_nat_trailing_degree_eq_of_pos {p : polynomial R} {n : ℕ} (hn : 0 < n) :
p.trailing_degree = n ↔ p.nat_trailing_degree = n :=
begin
split,
{ intro H, rwa ← trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl,
rw trailing_degree_zero at H, exact option.no_confusion H },
{ intro H, rwa trailing_degree_eq_iff_nat_trailing_degree_eq, rintro rfl,
rw nat_trailing_degree_zero at H, rw H at hn, exact lt_irrefl _ hn }
end
lemma nat_trailing_degree_eq_of_trailing_degree_eq_some {p : polynomial R} {n : ℕ}
(h : trailing_degree p = n) : nat_trailing_degree p = n :=
have hp0 : p ≠ 0, from λ hp0, by rw hp0 at h; exact option.no_confusion h,
option.some_inj.1 $ show (nat_trailing_degree p : with_top ℕ) = n,
by rwa [← trailing_degree_eq_nat_trailing_degree hp0]
@[simp] lemma nat_trailing_degree_le_trailing_degree :
↑(nat_trailing_degree p) ≤ trailing_degree p :=
begin
by_cases hp : p = 0, { rw hp, exact le_top },
rw [trailing_degree_eq_nat_trailing_degree hp],
exact le_refl _
end
lemma nat_trailing_degree_eq_of_trailing_degree_eq [semiring S] {q : polynomial S}
(h : trailing_degree p = trailing_degree q) :
nat_trailing_degree p = nat_trailing_degree q :=
by unfold nat_trailing_degree; rw h
lemma le_trailing_degree_of_ne_zero (h : coeff p n ≠ 0) : trailing_degree p ≤ n :=
show @has_le.le (with_top ℕ) _ (p.support.inf some : with_top ℕ) (some n : with_top ℕ),
from finset.inf_le (finsupp.mem_support_iff.2 h)
lemma nat_trailing_degree_le_of_ne_zero (h : coeff p n ≠ 0) : nat_trailing_degree p ≤ n :=
begin
rw [← with_top.coe_le_coe, ← trailing_degree_eq_nat_trailing_degree],
{ exact le_trailing_degree_of_ne_zero h, },
{ assume h, subst h, exact h rfl }
end
lemma trailing_degree_le_trailing_degree (h : coeff q (nat_trailing_degree p) ≠ 0) :
trailing_degree q ≤ trailing_degree p :=
begin
by_cases hp : p = 0,
{ rw hp, exact le_top },
{ rw trailing_degree_eq_nat_trailing_degree hp, exact le_trailing_degree_of_ne_zero h }
end
lemma trailing_degree_ne_of_nat_trailing_degree_ne {n : ℕ} :
p.nat_trailing_degree ≠ n → trailing_degree p ≠ n :=
mt $ λ h, by rw [nat_trailing_degree, h, option.get_or_else_coe]
theorem nat_trailing_degree_le_of_trailing_degree_le {n : ℕ} {hp : p ≠ 0}
(H : (n : with_top ℕ) ≤ trailing_degree p) : n ≤ nat_trailing_degree p :=
begin
rw trailing_degree_eq_nat_trailing_degree hp at H,
exact with_top.coe_le_coe.mp H,
end
lemma nat_trailing_degree_le_nat_trailing_degree {hq : q ≠ 0}
(hpq : p.trailing_degree ≤ q.trailing_degree) :
p.nat_trailing_degree ≤ q.nat_trailing_degree :=
begin
by_cases hp : p = 0, { rw [hp, nat_trailing_degree_zero], exact zero_le _ },
rwa [trailing_degree_eq_nat_trailing_degree hp, trailing_degree_eq_nat_trailing_degree hq,
with_top.coe_le_coe] at hpq
end
@[simp] lemma trailing_degree_monomial (ha : a ≠ 0) : trailing_degree (monomial n a) = n :=
by rw [trailing_degree, support_monomial _ _ ha, inf_singleton, with_top.some_eq_coe]
lemma nat_trailing_degree_monomial (ha : a ≠ 0) : nat_trailing_degree (monomial n a) = n :=
by rw [nat_trailing_degree, trailing_degree_monomial ha]; refl
lemma nat_trailing_degree_monomial_le : nat_trailing_degree (monomial n a) ≤ n :=
if ha : a = 0 then by simp [ha] else (nat_trailing_degree_monomial ha).le
lemma le_trailing_degree_monomial : ↑n ≤ trailing_degree (monomial n a) :=
if ha : a = 0 then by simp [ha] else (trailing_degree_monomial ha).ge
@[simp] lemma trailing_degree_C (ha : a ≠ 0) : trailing_degree (C a) = (0 : with_top ℕ) :=
trailing_degree_monomial ha
lemma le_trailing_degree_C : (0 : with_top ℕ) ≤ trailing_degree (C a) :=
le_trailing_degree_monomial
lemma trailing_degree_one_le : (0 : with_top ℕ) ≤ trailing_degree (1 : polynomial R) :=
by rw [← C_1]; exact le_trailing_degree_C
@[simp] lemma nat_trailing_degree_C (a : R) : nat_trailing_degree (C a) = 0 :=
nonpos_iff_eq_zero.1 nat_trailing_degree_monomial_le
@[simp] lemma nat_trailing_degree_one : nat_trailing_degree (1 : polynomial R) = 0 :=
nat_trailing_degree_C 1
@[simp] lemma nat_trailing_degree_nat_cast (n : ℕ) : nat_trailing_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_nat_cast, nat_trailing_degree_C]
@[simp] lemma trailing_degree_C_mul_X_pow (n : ℕ) (ha : a ≠ 0) :
trailing_degree (C a * X ^ n) = n :=
by rw [C_mul_X_pow_eq_monomial, trailing_degree_monomial ha]
lemma le_trailing_degree_C_mul_X_pow (n : ℕ) (a : R) :
(n : with_top ℕ) ≤ trailing_degree (C a * X ^ n) :=
by { rw C_mul_X_pow_eq_monomial, exact le_trailing_degree_monomial }
lemma coeff_eq_zero_of_trailing_degree_lt (h : (n : with_top ℕ) < trailing_degree p) :
coeff p n = 0 :=
not_not.1 (mt le_trailing_degree_of_ne_zero (not_le_of_gt h))
lemma coeff_eq_zero_of_lt_nat_trailing_degree {p : polynomial R} {n : ℕ}
(h : n < p.nat_trailing_degree) :
p.coeff n = 0 :=
begin
apply coeff_eq_zero_of_trailing_degree_lt,
by_cases hp : p = 0,
{ subst hp, exact with_top.coe_lt_top n, },
{ rwa [trailing_degree_eq_nat_trailing_degree hp, with_top.coe_lt_coe] },
end
@[simp] lemma coeff_nat_trailing_degree_pred_eq_zero {p : polynomial R}
{hp : (0 : with_top ℕ) < nat_trailing_degree p} : p.coeff (p.nat_trailing_degree - 1) = 0 :=
coeff_eq_zero_of_lt_nat_trailing_degree $ nat.sub_lt
((with_top.zero_lt_coe (nat_trailing_degree p)).mp hp) nat.one_pos
theorem le_trailing_degree_X_pow (n : ℕ) :
(n : with_top ℕ) ≤ trailing_degree (X^n : polynomial R) :=
by simpa only [C_1, one_mul] using le_trailing_degree_C_mul_X_pow n (1:R)
theorem le_trailing_degree_X : (1 : with_top ℕ) ≤ trailing_degree (X : polynomial R) :=
le_trailing_degree_monomial
lemma nat_trailing_degree_X_le : (X : polynomial R).nat_trailing_degree ≤ 1 :=
nat_trailing_degree_monomial_le
@[simp] lemma trailing_coeff_eq_zero : trailing_coeff p = 0 ↔ p = 0 :=
⟨λ h, by_contradiction $ λ hp, mt mem_support_iff.1
(not_not.2 h) (mem_of_min (trailing_degree_eq_nat_trailing_degree hp)),
λ h, h.symm ▸ leading_coeff_zero⟩
lemma trailing_coeff_nonzero_iff_nonzero : trailing_coeff p ≠ 0 ↔ p ≠ 0 :=
not_congr trailing_coeff_eq_zero
lemma nat_trailing_degree_mem_support_of_nonzero : p ≠ 0 → nat_trailing_degree p ∈ p.support :=
(mem_support_iff.mpr ∘ trailing_coeff_nonzero_iff_nonzero.mpr)
lemma nat_trailing_degree_le_of_mem_supp (a : ℕ) :
a ∈ p.support → nat_trailing_degree p ≤ a:=
nat_trailing_degree_le_of_ne_zero ∘ mem_support_iff.mp
lemma nat_trailing_degree_eq_support_min' (h : p ≠ 0) :
nat_trailing_degree p = p.support.min' (nonempty_support_iff.mpr h) :=
begin
apply le_antisymm,
{ apply le_min',
intros y hy,
exact nat_trailing_degree_le_of_mem_supp y hy },
{ apply finset.min'_le,
exact mem_support_iff.mpr (trailing_coeff_nonzero_iff_nonzero.mpr h), },
end
lemma nat_trailing_degree_le_nat_degree (p : polynomial R) :
p.nat_trailing_degree ≤ p.nat_degree :=
begin
by_cases hp : p = 0,
{ rw [hp, nat_degree_zero, nat_trailing_degree_zero] },
{ exact le_nat_degree_of_ne_zero (mt trailing_coeff_eq_zero.mp hp) },
end
lemma nat_trailing_degree_mul_X_pow {p : polynomial R} (hp : p ≠ 0) (n : ℕ) :
(p * X ^ n).nat_trailing_degree = p.nat_trailing_degree + n :=
begin
apply le_antisymm,
{ refine nat_trailing_degree_le_of_ne_zero (λ h, mt trailing_coeff_eq_zero.mp hp _),
rwa [trailing_coeff, ←coeff_mul_X_pow] },
{ rw [nat_trailing_degree_eq_support_min' (λ h, hp (mul_X_pow_eq_zero h)), finset.le_min'_iff],
intros y hy,
have key : n ≤ y,
{ rw [mem_support_iff, coeff_mul_X_pow'] at hy,
exact by_contra (λ h, hy (if_neg h)) },
rw [mem_support_iff, coeff_mul_X_pow', if_pos key] at hy,
exact (nat.add_le_to_le_sub _ key).mpr (nat_trailing_degree_le_of_ne_zero hy) },
end
end semiring
section nonzero_semiring
variables [semiring R] [nontrivial R] {p q : polynomial R}
@[simp] lemma trailing_degree_one : trailing_degree (1 : polynomial R) = (0 : with_top ℕ) :=
trailing_degree_C one_ne_zero
@[simp] lemma trailing_degree_X : trailing_degree (X : polynomial R) = 1 :=
trailing_degree_monomial one_ne_zero
@[simp] lemma nat_trailing_degree_X : (X : polynomial R).nat_trailing_degree = 1 :=
nat_trailing_degree_monomial one_ne_zero
end nonzero_semiring
section ring
variables [ring R]
@[simp] lemma trailing_degree_neg (p : polynomial R) : trailing_degree (-p) = trailing_degree p :=
by unfold trailing_degree; rw support_neg
@[simp] lemma nat_trailing_degree_neg (p : polynomial R) :
nat_trailing_degree (-p) = nat_trailing_degree p :=
by simp [nat_trailing_degree]
@[simp] lemma nat_trailing_degree_int_cast (n : ℤ) : nat_trailing_degree (n : polynomial R) = 0 :=
by simp only [←C_eq_int_cast, nat_trailing_degree_C]
end ring
section semiring
variables [semiring R]
/-- The second-lowest coefficient, or 0 for constants -/
def next_coeff_up (p : polynomial R) : R :=
if p.nat_trailing_degree = 0 then 0 else p.coeff (p.nat_trailing_degree + 1)
@[simp]
lemma next_coeff_up_C_eq_zero (c : R) :
next_coeff_up (C c) = 0 := by { rw next_coeff_up, simp }
lemma next_coeff_up_of_pos_nat_trailing_degree (p : polynomial R) (hp : 0 < p.nat_trailing_degree) :
next_coeff_up p = p.coeff (p.nat_trailing_degree + 1) :=
by { rw [next_coeff_up, if_neg], contrapose! hp, simpa }
end semiring
section semiring
variables [semiring R] {p q : polynomial R} {ι : Type*}
lemma coeff_nat_trailing_degree_eq_zero_of_trailing_degree_lt
(h : trailing_degree p < trailing_degree q) :
coeff q (nat_trailing_degree p) = 0 :=
coeff_eq_zero_of_trailing_degree_lt $ nat_trailing_degree_le_trailing_degree.trans_lt h
lemma ne_zero_of_trailing_degree_lt {n : with_top ℕ} (h : trailing_degree p < n) : p ≠ 0 :=
λ h₀, h.not_le (by simp [h₀])
end semiring
end polynomial
|
9e41fc6de0c2c46a4889e6261f029612a4622d84 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/finite/set.lean | b46a4d80475da5852f3f00a3b8a6a79f973ddf9f | [
"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 | 772 | 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.fintype.card
/-!
# Lemmas about `finite` and `set`s
In this file we prove two lemmas about `finite` and `set`s.
## Tags
finiteness, finite sets
-/
open set
universes u v w x
variables {α : Type u} {β : Type v} {ι : Sort w}
lemma finite.set.finite_of_finite_image (s : set α)
{f : α → β} (h : s.inj_on f) [finite (f '' s)] : finite s :=
finite.of_equiv _ (equiv.of_bijective _ h.bij_on_image.bijective).symm
lemma finite.of_injective_finite_range {f : ι → α}
(hf : function.injective f) [finite (range f)] : finite ι :=
finite.of_injective (set.range_factorization f) (hf.cod_restrict _)
|
c5b02f0b5851f0ec50a82220fe253df5b495ac4b | de91c42b87530c3bdcc2b138ef1a3c3d9bee0d41 | /old/eval/time_eval.lean | 72c00aecfe405a177cd0a9254d9e9c74ff7787eb | [] | no_license | kevinsullivan/lang | d3e526ba363dc1ddf5ff1c2f36607d7f891806a7 | e9d869bff94fb13ad9262222a6f3c4aafba82d5e | refs/heads/master | 1,687,840,064,795 | 1,628,047,969,000 | 1,628,047,969,000 | 282,210,749 | 0 | 1 | null | 1,608,153,830,000 | 1,595,592,637,000 | Lean | UTF-8 | Lean | false | false | 417 | lean | import ..environment.environment
variables {K : Type*} [field K] [inhabited K]{f : fm K TIME} (sp : spc K f)
open lang.time
namespace lang.time_eval
def duration_eval : env sp → duration_expr sp → duration sp
| e (duration_expr.lit f) := f
| e (duration_expr.var v) := e.d v
def time_eval : env sp → time_expr sp → time sp
| e (time_expr.lit t) := t
| e (time_expr.var v) := e.t v
end lang.time_eval |
d703c9e984c30146b90783aadca80e59a7e74f4d | cf39355caa609c0f33405126beee2739aa3cb77e | /tests/lean/subpp.lean | 156f0fd92bcbe848ad040403e47fd71470bf49f9 | [
"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 | 30 | lean | --
#check {x : nat // x > 0 }
|
8566d1d10b0a01d31e6cfd9dad95521dc4a395d3 | 9bfad7663303efa7b1cd1bf8a0b91cbb8d9a31a6 | /src/semantics.lean | 5e8c7c5543f31bedefd4cfaac68b7f6ce2a3038d | [] | no_license | iehality/modallogic | 9c61bdeb4ef5798c9bc80d2b39d663c24dadaf2a | b759f418259b2e1b3b7dd8a784069f0eba49907a | refs/heads/main | 1,679,183,622,574 | 1,614,786,343,000 | 1,614,786,343,000 | 343,304,144 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,593 | lean | import data.int.parity
import syntax
import deduction
open classical
universe variables u
structure kripke_frame (W : Type u) :=
(relation : W → W → Prop)
inductive singleton : Type u
| s : singleton
def trivial_frame : kripke_frame singleton := ⟨λ x y, true⟩
namespace rel
variable {W : Type u}
variable F : kripke_frame W
def reflective := ∀ x, F.relation x x
def transitive := ∀ x y z, F.relation x y → F.relation y z → F.relation x z
def infinite_ascent := ∃ (z : ℕ → W), ∀ (n : ℕ), F.relation (z n) (z (n + 1))
end rel
def satisfy {W : Type u} (F : kripke_frame W) (V : ℕ → set W) : W → formula → Prop
| w (p : ℕ) := w ∈ V p
| w ⊥ₘ := false
| w (p →ₘ q) := satisfy w p → satisfy w q
| w □p := ∀ v, F.relation w v → satisfy v p
def frames {W : Type u} (F : kripke_frame W) (p : formula) := ∀ V w, satisfy F V w p
notation `[`F`, `V`, `w`]` ` ⊧ `p := satisfy F V w p
infix ` ⊧ `:50 := frames
namespace semantics
variable {W : Type u}
variable F : kripke_frame W
variables p q : ℕ
variables φ ψ χ : formula
local infix ` ≺ `:50 := F.relation
theorem distribution : F ⊧ □(φ →ₘ ψ) →ₘ □φ →ₘ □ψ :=
λ (V : ℕ → set W)
(w : W)
(h₀ : [F, V, w] ⊧ □(φ →ₘ ψ))
(h₁ : [F, V, w] ⊧ □φ)
(v : W)
(h₂ : w ≺ v),
h₀ v h₂ (h₁ v h₂)
theorem necessitation : F ⊧ φ → F ⊧ □φ :=
λ (h₀ : F ⊧ φ)
(V : ℕ → set W)
(w : W)
(v : W)
(h₁ : w ≺ v),
h₀ V v
/--
theorem trans_iff_4
: rel.transitive F ↔ F ⊧ □p →ₘ □□p :=
begin
split,
{ intros trans h₀ v h₁ u₀ r₀ u₁ r₁,
apply h₁,
exact (trans v u₀ u₁ r₀ r₁) },
{ intros h w v u rwv rvu,
by_contradiction nr,
have Vᵤ : ℕ → set W := λ e z, z ≠ u,
specialize h Vᵤ w,
have h₀ : [F, Vᵤ, w] ⊧ □p,
{ intros v' rwv',
simp [satisfy],
by_contradiction,
sorry },
sorry }
end
-/
lemma us_soundness : F ⊧ φ → F ⊧ (subst p ψ φ) :=
begin
intros h V w,
let V' : ℕ → set W := fun e u, [F, V, u] ⊧ subst p ψ e,
have i : ∀ v, ([F, V', v] ⊧ φ) ↔ ([F, V, v] ⊧ subst p ψ φ),
{ clear h,
induction φ,
{ exact λ v, ⟨λ h₀, h₀, λ h₀, h₀⟩ },
{ exact λ v, ⟨λ h₀, h₀, λ h₀, h₀⟩ },
{ exact λ v, ⟨λ h₀ s, (φ_ih_ᾰ_1 v).1 (h₀ ((φ_ih_ᾰ v).2 s)), λ h₀ s, (φ_ih_ᾰ_1 v).2 (h₀ ((φ_ih_ᾰ v).1 s))⟩ },
{ exact λ v, ⟨λ h u rvu, (φ_ih u).1 (h u rvu), λ h u rvu, (φ_ih u).2 (h u rvu)⟩ } },
have l : [F, V', w] ⊧ φ := h V' w,
exact (i w).1 l
end
lemma mp_soundness : F ⊧ φ →ₘ ψ → F ⊧ φ → F ⊧ ψ := λ h h₀ V w, (h V w) (h₀ V w)
lemma ak_soundness : F ⊧ φ →ₘ ψ →ₘ φ := λ V w h h₀, h
lemma as_soundness : F ⊧ (φ →ₘ ψ →ₘ χ) →ₘ (φ →ₘ ψ) →ₘ φ →ₘ χ := λ V w h h₀ h₁, h h₁ (h₀ h₁)
lemma an_soundness : F ⊧ (¬ₘφ →ₘ ¬ₘψ) →ₘ ψ →ₘ φ := by { intros V w h, simp [satisfy], contrapose, exact h }
theorem soundness : ⊢ₖ φ → F ⊧ φ :=
begin
assume h,
induction h,
{ exact us_soundness _ h_p _ _ h_ih },
{ exfalso, exact h_ᾰ },
{ exact mp_soundness _ _ _ h_ih_ᾰ h_ih_ᾰ_1 },
{ exact necessitation _ _ h_ih },
{ exact ak_soundness _ _ _ },
{ exact as_soundness _ _ _ _ },
{ exact an_soundness _ _ _ },
{ exact distribution _ _ _ }
end
theorem consis : consistent ∅ := λ h, soundness trivial_frame ⊥ₘ h (λ n, ∅) singleton.s
end semantics |
1bac3eb50eb202dc216d9f9e1e0ab285c7158171 | d9d511f37a523cd7659d6f573f990e2a0af93c6f | /archive/100-theorems-list/82_cubing_a_cube.lean | fe506049ea0f09185e7eccf99a89f28aa592eef4 | [
"Apache-2.0"
] | permissive | hikari0108/mathlib | b7ea2b7350497ab1a0b87a09d093ecc025a50dfa | a9e7d333b0cfd45f13a20f7b96b7d52e19fa2901 | refs/heads/master | 1,690,483,608,260 | 1,631,541,580,000 | 1,631,541,580,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,643 | lean | /-
Copyright (c) 2019 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import data.real.basic
import data.set.intervals
import data.set.pairwise
import set_theory.cardinal
/-!
Proof that a cube (in dimension n ≥ 3) cannot be cubed:
There does not exist a partition of a cube into finitely many smaller cubes (at least two)
of different sizes.
We follow the proof described here:
http://www.alaricstephen.com/main-featured/2017/9/28/cubing-a-cube-proof
-/
open real set function fin
noncomputable theory
variable {n : ℕ}
/-- Given three intervals `I, J, K` such that `J ⊂ I`,
neither endpoint of `J` coincides with an endpoint of `I`, `¬ (K ⊆ J)` and
`K` does not lie completely to the left nor completely to the right of `J`.
Then `I ∩ K \ J` is nonempty. -/
lemma Ico_lemma {α} [linear_order α] {x₁ x₂ y₁ y₂ z₁ z₂ w : α}
(h₁ : x₁ < y₁) (hy : y₁ < y₂) (h₂ : y₂ < x₂)
(hz₁ : z₁ ≤ y₂) (hz₂ : y₁ ≤ z₂) (hw : w ∉ Ico y₁ y₂ ∧ w ∈ Ico z₁ z₂) :
∃w, w ∈ Ico x₁ x₂ ∧ w ∉ Ico y₁ y₂ ∧ w ∈ Ico z₁ z₂ :=
begin
simp only [not_and, not_lt, mem_Ico] at hw,
refine ⟨max x₁ (min w y₂), _, _, _⟩,
{ simp [le_refl, lt_trans h₁ (lt_trans hy h₂), h₂] },
{ simp [hw, lt_irrefl, not_le_of_lt h₁] {contextual := tt} },
{ simp [hw.2.1, hw.2.2, hz₁, lt_of_lt_of_le h₁ hz₂] at ⊢ }
end
/-- A (hyper)-cube (in standard orientation) is a vector `b` consisting of the bottom-left point
of the cube, a width `w` and a proof that `w > 0`. We use functions from `fin n` to denote vectors.
-/
structure cube (n : ℕ) : Type :=
(b : fin n → ℝ) -- bottom-left coordinate
(w : ℝ) -- width
(hw : 0 < w)
namespace cube
lemma hw' (c : cube n) : 0 ≤ c.w := le_of_lt c.hw
/-- The j-th side of a cube is the half-open interval `[b j, b j + w)` -/
def side (c : cube n) (j : fin n) : set ℝ :=
Ico (c.b j) (c.b j + c.w)
@[simp] lemma b_mem_side (c : cube n) (j : fin n) : c.b j ∈ c.side j :=
by simp [side, cube.hw, le_refl]
def to_set (c : cube n) : set (fin n → ℝ) :=
{ x | ∀j, x j ∈ side c j }
def to_set_subset {c c' : cube n} : c.to_set ⊆ c'.to_set ↔ ∀j, c.side j ⊆ c'.side j :=
begin
split, intros h j x hx,
let f : fin n → ℝ := λ j', if j' = j then x else c.b j',
have : f ∈ c.to_set,
{ intro j', by_cases hj' : j' = j; simp [f, hj', if_pos, if_neg, hx] },
convert h this j, { simp [f, if_pos] },
intros h f hf j, exact h j (hf j)
end
def to_set_disjoint {c c' : cube n} : disjoint c.to_set c'.to_set ↔
∃j, disjoint (c.side j) (c'.side j) :=
begin
split, intros h, classical, by_contra h',
simp only [not_disjoint_iff, classical.skolem, not_exists] at h',
cases h' with f hf,
apply not_disjoint_iff.mpr ⟨f, _, _⟩ h; intro j, exact (hf j).1, exact (hf j).2,
rintro ⟨j, hj⟩, rw [set.disjoint_iff], rintros f ⟨h1f, h2f⟩,
apply not_disjoint_iff.mpr ⟨f j, h1f j, h2f j⟩ hj
end
lemma b_mem_to_set (c : cube n) : c.b ∈ c.to_set :=
by simp [to_set]
protected def tail (c : cube (n+1)) : cube n :=
⟨tail c.b, c.w, c.hw⟩
lemma side_tail (c : cube (n+1)) (j : fin n) : c.tail.side j = c.side j.succ := rfl
def bottom (c : cube (n+1)) : set (fin (n+1) → ℝ) :=
{ x | x 0 = c.b 0 ∧ tail x ∈ c.tail.to_set }
lemma b_mem_bottom (c : cube (n+1)) : c.b ∈ c.bottom :=
by simp [bottom, to_set, side, cube.hw, le_refl, cube.tail]
def xm (c : cube (n+1)) : ℝ :=
c.b 0 + c.w
lemma b_lt_xm (c : cube (n+1)) : c.b 0 < c.xm := by simp [xm, hw]
lemma b_ne_xm (c : cube (n+1)) : c.b 0 ≠ c.xm := ne_of_lt c.b_lt_xm
def shift_up (c : cube (n+1)) : cube (n+1) :=
⟨cons c.xm $ tail c.b, c.w, c.hw⟩
@[simp] lemma tail_shift_up (c : cube (n+1)) : c.shift_up.tail = c.tail :=
by simp [shift_up, cube.tail]
@[simp] lemma head_shift_up (c : cube (n+1)) : c.shift_up.b 0 = c.xm := rfl
def unit_cube : cube n :=
⟨λ _, 0, 1, by norm_num⟩
@[simp] lemma side_unit_cube {j : fin n} : unit_cube.side j = Ico 0 1 :=
by norm_num [unit_cube, side]
end cube
open cube
variables {ι : Type} [fintype ι] {cs : ι → cube (n+1)} {i i' : ι}
/-- A finite family of (at least 2) cubes partitioning the unit cube with different sizes -/
def correct (cs : ι → cube n) : Prop :=
pairwise (disjoint on (cube.to_set ∘ cs)) ∧
(⋃(i : ι), (cs i).to_set) = unit_cube.to_set ∧
injective (cube.w ∘ cs) ∧
2 ≤ cardinal.mk ι ∧
3 ≤ n
variable (h : correct cs)
include h
lemma to_set_subset_unit_cube {i} : (cs i).to_set ⊆ unit_cube.to_set :=
by { rw [←h.2.1], exact subset_Union _ i }
lemma side_subset {i j} : (cs i).side j ⊆ Ico 0 1 :=
by { have := to_set_subset_unit_cube h, rw [to_set_subset] at this,
convert this j, norm_num [unit_cube] }
lemma zero_le_of_mem_side {i j x} (hx : x ∈ (cs i).side j) : 0 ≤ x :=
(side_subset h hx).1
lemma zero_le_of_mem {i p} (hp : p ∈ (cs i).to_set) (j) : 0 ≤ p j :=
zero_le_of_mem_side h (hp j)
lemma zero_le_b {i j} : 0 ≤ (cs i).b j :=
zero_le_of_mem h (cs i).b_mem_to_set j
lemma b_add_w_le_one {j} : (cs i).b j + (cs i).w ≤ 1 :=
by { have := side_subset h, rw [side, Ico_subset_Ico_iff] at this, convert this.2, simp [hw] }
/-- The width of any cube in the partition cannot be 1. -/
lemma w_ne_one (i : ι) : (cs i).w ≠ 1 :=
begin
intro hi,
have := h.2.2.2.1, rw [cardinal.two_le_iff' i] at this, cases this with i' hi',
let p := (cs i').b,
have hp : p ∈ (cs i').to_set := (cs i').b_mem_to_set,
have h2p : p ∈ (cs i).to_set,
{ intro j, split,
transitivity (0 : ℝ),
{ rw [←add_le_add_iff_right (1 : ℝ)], convert b_add_w_le_one h, rw hi, rw zero_add },
apply zero_le_b h, apply lt_of_lt_of_le (side_subset h $ (cs i').b_mem_side j).2,
simp [hi, zero_le_b h] },
apply not_disjoint_iff.mpr ⟨p, hp, h2p⟩,
apply h.1, exact hi'.symm
end
/-- The top of a cube (which is the bottom of the cube shifted up by its width) must be covered by
bottoms of (other) cubes in the family. -/
lemma shift_up_bottom_subset_bottoms (hc : (cs i).xm ≠ 1) :
(cs i).shift_up.bottom ⊆ ⋃(i : ι), (cs i).bottom :=
begin
intros p hp, cases hp with hp0 hps, rw [tail_shift_up] at hps,
have : p ∈ (unit_cube : cube (n+1)).to_set,
{ simp only [to_set, forall_fin_succ, hp0, side_unit_cube, mem_set_of_eq, mem_Ico,
head_shift_up], refine ⟨⟨_, _⟩, _⟩,
{ rw [←zero_add (0 : ℝ)], apply add_le_add, apply zero_le_b h, apply (cs i).hw' },
{ exact lt_of_le_of_ne (b_add_w_le_one h) hc },
intro j, exact side_subset h (hps j) },
rw [←h.2.1] at this, rcases this with ⟨_, ⟨i', rfl⟩, hi'⟩,
rw [mem_Union], use i', refine ⟨_, λ j, hi' j.succ⟩,
have : i ≠ i', { rintro rfl, apply not_le_of_lt (hi' 0).2, rw [hp0], refl },
have := h.1 i i' this, rw [on_fun, to_set_disjoint, exists_fin_succ] at this,
rcases this with h0|⟨j, hj⟩,
rw [hp0], symmetry, apply eq_of_Ico_disjoint h0 (by simp [hw]) _,
convert hi' 0, rw [hp0], refl,
exfalso, apply not_disjoint_iff.mpr ⟨tail p j, hps j, hi' j.succ⟩ hj
end
omit h
/-- A valley is a square on which cubes in the family of cubes are placed, so that the cubes
completely cover the valley and none of those cubes is partially outside the square.
We also require that no cube on it has the same size as the valley (so that there are at least
two cubes on the valley).
This is the main concept in the formalization.
We prove that the smallest cube on a valley has another valley on the top of it, which
gives an infinite sequence of cubes in the partition, which contradicts the finiteness.
A valley is characterized by a cube `c` (which is not a cube in the family cs) by considering
the bottom face of `c`. -/
def valley (cs : ι → cube (n+1)) (c : cube (n+1)) : Prop :=
c.bottom ⊆ (⋃(i : ι), (cs i).bottom) ∧
(∀i, (cs i).b 0 = c.b 0 → (∃x, x ∈ (cs i).tail.to_set ∩ c.tail.to_set) →
(cs i).tail.to_set ⊆ c.tail.to_set) ∧
∀(i : ι), (cs i).b 0 = c.b 0 → (cs i).w ≠ c.w
variables {c : cube (n+1)} (v : valley cs c)
/-- The bottom of the unit cube is a valley -/
lemma valley_unit_cube (h : correct cs) : valley cs unit_cube :=
begin
refine ⟨_, _, _⟩,
{ intro v,
simp only [bottom, and_imp, mem_Union, mem_set_of_eq],
intros h0 hv,
have : v ∈ (unit_cube : cube (n+1)).to_set,
{ dsimp only [to_set, unit_cube, mem_set_of_eq],
rw [forall_fin_succ, h0], split, norm_num [side, unit_cube], exact hv },
rw [←h.2.1] at this, rcases this with ⟨_, ⟨i, rfl⟩, hi⟩,
use i,
split, { apply le_antisymm, rw h0, exact zero_le_b h, exact (hi 0).1 },
intro j, exact hi _ },
{ intros i hi h', rw to_set_subset, intro j, convert side_subset h using 1, simp [side_tail] },
{ intros i hi, exact w_ne_one h i }
end
/-- the cubes which lie in the valley `c` -/
def bcubes (cs : ι → cube (n+1)) (c : cube (n+1)) : set ι :=
{ i : ι | (cs i).b 0 = c.b 0 ∧ (cs i).tail.to_set ⊆ c.tail.to_set }
/-- A cube which lies on the boundary of a valley in dimension `j` -/
def on_boundary (hi : i ∈ bcubes cs c) (j : fin n) : Prop :=
c.b j.succ = (cs i).b j.succ ∨ (cs i).b j.succ + (cs i).w = c.b j.succ + c.w
lemma tail_sub (hi : i ∈ bcubes cs c) : ∀j, (cs i).tail.side j ⊆ c.tail.side j :=
by { rw [←to_set_subset], exact hi.2 }
lemma bottom_mem_side (hi : i ∈ bcubes cs c) : c.b 0 ∈ (cs i).side 0 :=
by { convert b_mem_side (cs i) _ using 1, rw hi.1 }
lemma b_le_b (hi : i ∈ bcubes cs c) (j : fin n) : c.b j.succ ≤ (cs i).b j.succ :=
(tail_sub hi j $ b_mem_side _ _).1
lemma t_le_t (hi : i ∈ bcubes cs c) (j : fin n) :
(cs i).b j.succ + (cs i).w ≤ c.b j.succ + c.w :=
begin
have h' := tail_sub hi j, dsimp only [side] at h', rw [Ico_subset_Ico_iff] at h',
exact h'.2, simp [hw]
end
include h v
/-- Every cube in the valley must be smaller than it -/
lemma w_lt_w (hi : i ∈ bcubes cs c) : (cs i).w < c.w :=
begin
apply lt_of_le_of_ne _ (v.2.2 i hi.1),
have j : fin n := ⟨1, nat.le_of_succ_le_succ h.2.2.2.2⟩,
rw [←add_le_add_iff_left ((cs i).b j.succ)],
apply le_trans (t_le_t hi j), rw [add_le_add_iff_right], apply b_le_b hi,
end
open cardinal
/-- There are at least two cubes in a valley -/
lemma two_le_mk_bcubes : 2 ≤ cardinal.mk (bcubes cs c) :=
begin
rw [two_le_iff],
rcases v.1 c.b_mem_bottom with ⟨_, ⟨i, rfl⟩, hi⟩,
have h2i : i ∈ bcubes cs c :=
⟨hi.1.symm, v.2.1 i hi.1.symm ⟨tail c.b, hi.2, λ j, c.b_mem_side j.succ⟩⟩,
let j : fin (n+1) := ⟨2, h.2.2.2.2⟩,
have hj : 0 ≠ j := by { simp only [fin.ext_iff, ne.def], contradiction },
let p : fin (n+1) → ℝ := λ j', if j' = j then c.b j + (cs i).w else c.b j',
have hp : p ∈ c.bottom,
{ split, { simp only [bottom, p, if_neg hj] },
intro j', simp only [tail, side_tail],
by_cases hj' : j'.succ = j,
{ simp [p, -add_comm, if_pos, side, hj', hw', w_lt_w h v h2i] },
{ simp [p, -add_comm, if_neg hj'] }},
rcases v.1 hp with ⟨_, ⟨i', rfl⟩, hi'⟩,
have h2i' : i' ∈ bcubes cs c := ⟨hi'.1.symm, v.2.1 i' hi'.1.symm ⟨tail p, hi'.2, hp.2⟩⟩,
refine ⟨⟨i, h2i⟩, ⟨i', h2i'⟩, _⟩,
intro hii', cases congr_arg subtype.val hii',
apply not_le_of_lt (hi'.2 ⟨1, nat.le_of_succ_le_succ h.2.2.2.2⟩).2,
simp only [-add_comm, tail, cube.tail, p],
rw [if_pos, add_le_add_iff_right],
{ exact (hi.2 _).1 },
refl
end
/-- There is a cube in the valley -/
lemma nonempty_bcubes : (bcubes cs c).nonempty :=
begin
rw [←set.ne_empty_iff_nonempty], intro h', have := two_le_mk_bcubes h v, rw h' at this,
apply not_lt_of_le this, rw mk_emptyc, norm_cast, norm_num
end
/-- There is a smallest cube in the valley -/
lemma exists_mi : ∃(i : ι), i ∈ bcubes cs c ∧ ∀(i' ∈ bcubes cs c),
(cs i).w ≤ (cs i').w :=
by simpa
using (bcubes cs c).exists_min_image (λ i, (cs i).w) (finite.of_fintype _) (nonempty_bcubes h v)
/-- We let `mi` be the (index for the) smallest cube in the valley `c` -/
def mi : ι := classical.some $ exists_mi h v
variables {h v}
lemma mi_mem_bcubes : mi h v ∈ bcubes cs c :=
(classical.some_spec $ exists_mi h v).1
lemma mi_minimal (hi : i ∈ bcubes cs c) : (cs $ mi h v).w ≤ (cs i).w :=
(classical.some_spec $ exists_mi h v).2 i hi
lemma mi_strict_minimal (hii' : mi h v ≠ i) (hi : i ∈ bcubes cs c) :
(cs $ mi h v).w < (cs i).w :=
by { apply lt_of_le_of_ne (mi_minimal hi), apply h.2.2.1.ne, apply hii' }
/-- The top of `mi` cannot be 1, since there is a larger cube in the valley -/
lemma mi_xm_ne_one : (cs $ mi h v).xm ≠ 1 :=
begin
apply ne_of_lt, rcases (two_le_iff' _).mp (two_le_mk_bcubes h v) with ⟨⟨i, hi⟩, h2i⟩,
swap, exact ⟨mi h v, mi_mem_bcubes⟩,
apply lt_of_lt_of_le _ (b_add_w_le_one h), exact i, exact 0,
rw [xm, mi_mem_bcubes.1, hi.1, _root_.add_lt_add_iff_left],
apply mi_strict_minimal _ hi, intro h', apply h2i, rw subtype.ext_iff_val, exact h'
end
/-- If `mi` lies on the boundary of the valley in dimension j, then this lemma expresses that all
other cubes on the same boundary extend further from the boundary.
More precisely, there is a j-th coordinate `x : ℝ` in the valley, but not in `mi`,
such that every cube that shares a (particular) j-th coordinate with `mi` also contains j-th
coordinate `x` -/
lemma smallest_on_boundary {j} (bi : on_boundary (mi_mem_bcubes : mi h v ∈ _) j) :
∃(x : ℝ), x ∈ c.side j.succ \ (cs $ mi h v).side j.succ ∧
∀{{i'}} (hi' : i' ∈ bcubes cs c), i' ≠ mi h v →
(cs $ mi h v).b j.succ ∈ (cs i').side j.succ → x ∈ (cs i').side j.succ :=
begin
let i := mi h v, have hi : i ∈ bcubes cs c := mi_mem_bcubes,
cases bi,
{ refine ⟨(cs i).b j.succ + (cs i).w, ⟨_, _⟩, _⟩,
{ simp [side, bi, hw', w_lt_w h v hi] },
{ intro h', simpa [i, lt_irrefl] using h'.2 },
intros i' hi' i'_i h2i', split,
apply le_trans h2i'.1, { simp [hw'] },
apply lt_of_lt_of_le (add_lt_add_left (mi_strict_minimal i'_i.symm hi') _),
simp [bi.symm, b_le_b hi'] },
let s := bcubes cs c \ { i },
have hs : s.nonempty,
{ rcases (two_le_iff' (⟨i, hi⟩ : bcubes cs c)).mp (two_le_mk_bcubes h v) with ⟨⟨i', hi'⟩, h2i'⟩,
refine ⟨i', hi', _⟩, simp only [mem_singleton_iff], intro h, apply h2i', simp [h] },
rcases set.exists_min_image s (w ∘ cs) (finite.of_fintype _) hs with ⟨i', ⟨hi', h2i'⟩, h3i'⟩,
rw [mem_singleton_iff] at h2i',
let x := c.b j.succ + c.w - (cs i').w,
have hx : x < (cs i).b j.succ,
{ dsimp only [x], rw [←bi, add_sub_assoc, add_lt_iff_neg_left, sub_lt_zero],
apply mi_strict_minimal (ne.symm h2i') hi' },
refine ⟨x, ⟨_, _⟩, _⟩,
{ simp only [side, x, -add_comm, -add_assoc, neg_lt_zero, hw, add_lt_iff_neg_left, and_true,
mem_Ico, sub_eq_add_neg],
rw [add_assoc, le_add_iff_nonneg_right, ←sub_eq_add_neg, sub_nonneg],
apply le_of_lt (w_lt_w h v hi') },
{ simp only [side, not_and_distrib, not_lt, add_comm, not_le, mem_Ico], left, exact hx },
intros i'' hi'' h2i'' h3i'', split, swap, apply lt_trans hx h3i''.2,
simp only [x], rw [le_sub_iff_add_le],
refine le_trans _ (t_le_t hi'' j), rw [add_le_add_iff_left], apply h3i' i'' ⟨hi'', _⟩,
simp [mem_singleton, h2i'']
end
variables (h v)
/-- `mi` cannot lie on the boundary of the valley. Otherwise, the cube adjacent to it in the `j`-th
direction will intersect one of the neighbouring cubes on the same boundary as `mi`. -/
lemma mi_not_on_boundary (j : fin n) : ¬on_boundary (mi_mem_bcubes : mi h v ∈ _) j :=
begin
let i := mi h v, have hi : i ∈ bcubes cs c := mi_mem_bcubes,
rcases (two_le_iff' j).mp _ with ⟨j', hj'⟩, swap,
{ rw [mk_fin, ←nat.cast_two, nat_cast_le], apply nat.le_of_succ_le_succ h.2.2.2.2 },
intro hj,
rcases smallest_on_boundary hj with ⟨x, ⟨hx, h2x⟩, h3x⟩,
let p : fin (n+1) → ℝ := cons (c.b 0) (λ j₂, if j₂ = j then x else (cs i).b j₂.succ),
have hp : p ∈ c.bottom,
{ suffices : ∀ (j' : fin n), ite (j' = j) x ((cs i).b j'.succ) ∈ c.side j'.succ,
{ simpa [bottom, p, to_set, tail, side_tail] },
intro j₂,
by_cases hj₂ : j₂ = j, { simp [hj₂, hx] },
simp only [hj₂, if_false], apply tail_sub hi, apply b_mem_side },
rcases v.1 hp with ⟨_, ⟨i', rfl⟩, hi'⟩,
have h2i' : i' ∈ bcubes cs c := ⟨hi'.1.symm, v.2.1 i' hi'.1.symm ⟨tail p, hi'.2, hp.2⟩⟩,
have i_i' : i ≠ i', { rintro rfl, simpa [p, side_tail, i, h2x] using hi'.2 j },
have : nonempty ↥((cs i').tail.side j' \ (cs i).tail.side j'),
{ apply nonempty_Ico_sdiff, apply mi_strict_minimal i_i' h2i', apply hw },
rcases this with ⟨⟨x', hx'⟩⟩,
let p' : fin (n+1) → ℝ :=
cons (c.b 0) (λ j₂, if j₂ = j' then x' else (cs i).b j₂.succ),
have hp' : p' ∈ c.bottom,
{ suffices : ∀ (j : fin n), ite (j = j') x' ((cs i).b j.succ) ∈ c.side j.succ,
{ simpa [bottom, p', to_set, tail, side_tail] },
intro j₂,
by_cases hj₂ : j₂ = j', simp [hj₂], apply tail_sub h2i', apply hx'.1,
simp only [if_congr, if_false, hj₂], apply tail_sub hi, apply b_mem_side },
rcases v.1 hp' with ⟨_, ⟨i'', rfl⟩, hi''⟩,
have h2i'' : i'' ∈ bcubes cs c := ⟨hi''.1.symm, v.2.1 i'' hi''.1.symm ⟨tail p', hi''.2, hp'.2⟩⟩,
have i'_i'' : i' ≠ i'',
{ rintro ⟨⟩,
have : (cs i).b ∈ (cs i').to_set,
{ simp only [to_set, forall_fin_succ, hi.1, bottom_mem_side h2i', true_and, mem_set_of_eq],
intro j₂, by_cases hj₂ : j₂ = j,
{ simpa [side_tail, p', hj', hj₂] using hi''.2 j },
{ simpa [hj₂] using hi'.2 j₂ } },
apply not_disjoint_iff.mpr ⟨(cs i).b, (cs i).b_mem_to_set, this⟩ (h.1 i i' i_i') },
have i_i'' : i ≠ i'', { intro h, induction h, simpa [hx'.2] using hi''.2 j' },
apply not.elim _ (h.1 i' i'' i'_i''),
simp only [on_fun, to_set_disjoint, not_disjoint_iff, forall_fin_succ, not_exists, comp_app],
refine ⟨⟨c.b 0, bottom_mem_side h2i', bottom_mem_side h2i''⟩, _⟩,
intro j₂,
by_cases hj₂ : j₂ = j,
{ cases hj₂, refine ⟨x, _, _⟩,
{ convert hi'.2 j, simp [p] },
apply h3x h2i'' i_i''.symm, convert hi''.2 j, simp [p', hj'] },
by_cases h2j₂ : j₂ = j',
{ cases h2j₂, refine ⟨x', hx'.1, _⟩, convert hi''.2 j', simp },
refine ⟨(cs i).b j₂.succ, _, _⟩,
{ convert hi'.2 j₂, simp [hj₂] },
{ convert hi''.2 j₂, simp [h2j₂] }
end
variables {h v}
/-- The same result that `mi` cannot lie on the boundary of the valley written as inequalities. -/
lemma mi_not_on_boundary' (j : fin n) : c.tail.b j < (cs (mi h v)).tail.b j ∧
(cs (mi h v)).tail.b j + (cs (mi h v)).w < c.tail.b j + c.w :=
begin
have := mi_not_on_boundary h v j,
simp only [on_boundary, not_or_distrib] at this, cases this with h1 h2,
split,
apply lt_of_le_of_ne (b_le_b mi_mem_bcubes _) h1,
apply lt_of_le_of_ne _ h2,
apply ((Ico_subset_Ico_iff _).mp (tail_sub mi_mem_bcubes j)).2,
simp [hw]
end
/-- The top of `mi` gives rise to a new valley, since the neighbouring cubes extend further upward
than `mi`. -/
def valley_mi : valley cs ((cs (mi h v)).shift_up) :=
begin
let i := mi h v, have hi : i ∈ bcubes cs c := mi_mem_bcubes,
refine ⟨_, _, _⟩,
{ intro p, apply shift_up_bottom_subset_bottoms h mi_xm_ne_one },
{ rintros i' hi' ⟨p2, hp2, h2p2⟩, simp only [head_shift_up] at hi', classical, by_contra h2i',
rw [tail_shift_up] at h2p2, simp only [not_subset, tail_shift_up] at h2i',
rcases h2i' with ⟨p1, hp1, h2p1⟩,
have : ∃p3, p3 ∈ (cs i').tail.to_set ∧ p3 ∉ (cs i).tail.to_set ∧ p3 ∈ c.tail.to_set,
{ simp only [to_set, not_forall, mem_set_of_eq] at h2p1, cases h2p1 with j hj,
rcases Ico_lemma (mi_not_on_boundary' j).1 (by simp [hw]) (mi_not_on_boundary' j).2
(le_trans (hp2 j).1 $ le_of_lt (h2p2 j).2)
(le_trans (h2p2 j).1 $ le_of_lt (hp2 j).2) ⟨hj, hp1 j⟩ with ⟨w, hw, h2w, h3w⟩,
refine ⟨λ j', if j' = j then w else p2 j', _, _, _⟩,
{ intro j', by_cases h : j' = j,
{ simp only [if_pos h], convert h3w },
{ simp only [if_neg h], exact hp2 j' } },
{ simp only [to_set, not_forall, mem_set_of_eq], use j, rw [if_pos rfl], convert h2w },
{ intro j', by_cases h : j' = j,
{ simp only [if_pos h, side_tail], convert hw },
{ simp only [if_neg h], apply hi.2, apply h2p2 } } },
rcases this with ⟨p3, h1p3, h2p3, h3p3⟩,
let p := @cons n (λ_, ℝ) (c.b 0) p3,
have hp : p ∈ c.bottom, { refine ⟨rfl, _⟩, rwa [tail_cons] },
rcases v.1 hp with ⟨_, ⟨i'', rfl⟩, hi''⟩,
have h2i'' : i'' ∈ bcubes cs c,
{ use hi''.1.symm, apply v.2.1 i'' hi''.1.symm,
use tail p, split, exact hi''.2, rw [tail_cons], exact h3p3 },
have h3i'' : (cs i).w < (cs i'').w,
{ apply mi_strict_minimal _ h2i'', rintro rfl, apply h2p3, convert hi''.2, rw [tail_cons] },
let p' := @cons n (λ_, ℝ) (cs i).xm p3,
have hp' : p' ∈ (cs i').to_set,
{ simpa [to_set, forall_fin_succ, p', hi'.symm] using h1p3 },
have h2p' : p' ∈ (cs i'').to_set,
{ simp only [to_set, forall_fin_succ, p', cons_succ, cons_zero, mem_set_of_eq],
refine ⟨_, by simpa [to_set, p] using hi''.2⟩,
have : (cs i).b 0 = (cs i'').b 0, { by rw [hi.1, h2i''.1] },
simp [side, hw', xm, this, h3i''] },
apply not_disjoint_iff.mpr ⟨p', hp', h2p'⟩,
apply h.1, rintro rfl, apply (cs i).b_ne_xm, rw [←hi', ←hi''.1, hi.1], refl },
{ intros i' hi' h2i',
dsimp only [shift_up] at h2i',
replace h2i' := h.2.2.1 h2i'.symm,
induction h2i',
exact b_ne_xm (cs i) hi' }
end
variables (h)
omit v
/-- We get a sequence of cubes whose size is decreasing -/
noncomputable def sequence_of_cubes : ℕ → { i : ι // valley cs ((cs i).shift_up) }
| 0 := let v := valley_unit_cube h in ⟨mi h v, valley_mi⟩
| (k+1) := let v := (sequence_of_cubes k).2 in ⟨mi h v, valley_mi⟩
def decreasing_sequence (k : ℕ) : order_dual ℝ :=
(cs (sequence_of_cubes h k).1).w
lemma strict_mono_sequence_of_cubes : strict_mono $ decreasing_sequence h :=
strict_mono_nat_of_lt_succ $
begin
intro k, let v := (sequence_of_cubes h k).2, dsimp only [decreasing_sequence, sequence_of_cubes],
apply w_lt_w h v (mi_mem_bcubes : mi h v ∈ _),
end
omit h
/-- The infinite sequence of cubes contradicts the finiteness of the family. -/
theorem not_correct : ¬correct cs :=
begin
intro h, apply not_le_of_lt (lt_omega_iff_fintype.mpr ⟨_inst_1⟩),
rw [omega, lift_id], fapply mk_le_of_injective, exact λ n, (sequence_of_cubes h n).1,
intros n m hnm, apply strict_mono.injective (strict_mono_sequence_of_cubes h),
dsimp only [decreasing_sequence], rw hnm
end
/-- **Dissection of Cubes**: A cube cannot be cubed. -/
theorem cannot_cube_a_cube :
∀{n : ℕ}, n ≥ 3 → -- In ℝ^n for n ≥ 3
∀{ι : Type} [fintype ι] {cs : ι → cube n}, -- given a finite collection of (hyper)cubes
2 ≤ cardinal.mk ι → -- containing at least two elements
pairwise (disjoint on (cube.to_set ∘ cs)) → -- which is pairwise disjoint
(⋃(i : ι), (cs i).to_set) = unit_cube.to_set → -- whose union is the unit cube
injective (cube.w ∘ cs) → -- such that the widths of all cubes are different
false := -- then we can derive a contradiction
begin
intros n hn ι hι cs h1 h2 h3 h4, resetI,
rcases n, cases hn,
exact not_correct ⟨h2, h3, h4, h1, hn⟩
end
|
2e3e86e0a3a014149c99bf83933a29e3b693a2a7 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/order/zorn.lean | 82591bf9c8b72ce7ca8f66b6764a11ef749c79d7 | [
"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 | 12,633 | 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
Zorn's lemmas.
Ported from Isabelle/HOL (written by Jacques D. Fleuriot, Tobias Nipkow, and Christian Sternagel).
-/
import data.set.lattice
noncomputable theory
universes u
open set classical
open_locale classical
namespace zorn
section chain
parameters {α : Type u} (r : α → α → Prop)
local infix ` ≺ `:50 := r
/-- A chain is a subset `c` satisfying
`x ≺ y ∨ x = y ∨ y ≺ x` for all `x y ∈ c`. -/
def chain (c : set α) := pairwise_on c (λx y, x ≺ y ∨ y ≺ x)
parameters {r}
theorem chain.total_of_refl [is_refl α r]
{c} (H : chain c) {x y} (hx : x ∈ c) (hy : y ∈ c) :
x ≺ y ∨ y ≺ x :=
if e : x = y then or.inl (e ▸ refl _) else H _ hx _ hy e
theorem chain.mono {c c'} : c' ⊆ c → chain c → chain c' :=
pairwise_on.mono
theorem chain.directed_on [is_refl α r] {c} (H : chain c) : directed_on (≺) c :=
assume x hx y hy,
match H.total_of_refl hx hy with
| or.inl h := ⟨y, hy, h, refl _⟩
| or.inr h := ⟨x, hx, refl _, h⟩
end
theorem chain_insert {c : set α} {a : α} (hc : chain c) (ha : ∀b∈c, b ≠ a → a ≺ b ∨ b ≺ a) :
chain (insert a c) :=
forall_insert_of_forall
(assume x hx, forall_insert_of_forall (hc x hx) (assume hneq, (ha x hx hneq).symm))
(forall_insert_of_forall (assume x hx hneq, ha x hx $ assume h', hneq h'.symm) (assume h, (h rfl).rec _))
/-- `super_chain c₁ c₂` means that `c₂ is a chain that strictly includes `c₁`. -/
def super_chain (c₁ c₂ : set α) : Prop := chain c₂ ∧ c₁ ⊂ c₂
/-- A chain `c` is a maximal chain if there does not exists a chain strictly including `c`. -/
def is_max_chain (c : set α) := chain c ∧ ¬ (∃c', super_chain c c')
/-- Given a set `c`, if there exists a chain `c'` strictly including `c`, then `succ_chain c`
is one of these chains. Otherwise it is `c`. -/
def succ_chain (c : set α) : set α :=
if h : ∃c', chain c ∧ super_chain c c' then some h else c
theorem succ_spec {c : set α} (h : ∃c', chain c ∧ super_chain c c') :
super_chain c (succ_chain c) :=
let ⟨c', hc'⟩ := h in
have chain c ∧ super_chain c (some h),
from @some_spec _ (λc', chain c ∧ super_chain c c') _,
by simp [succ_chain, dif_pos, h, this.right]
theorem chain_succ {c : set α} (hc : chain c) : chain (succ_chain c) :=
if h : ∃c', chain c ∧ super_chain c c' then
(succ_spec h).left
else
by simp [succ_chain, dif_neg, h]; exact hc
theorem super_of_not_max {c : set α} (hc₁ : chain c) (hc₂ : ¬ is_max_chain c) :
super_chain c (succ_chain c) :=
begin
simp [is_max_chain, not_and_distrib, not_forall_not] at hc₂,
cases hc₂.neg_resolve_left hc₁ with c' hc',
exact succ_spec ⟨c', hc₁, hc'⟩
end
theorem succ_increasing {c : set α} : c ⊆ succ_chain c :=
if h : ∃c', chain c ∧ super_chain c c' then
have super_chain c (succ_chain c), from succ_spec h,
this.right.left
else by simp [succ_chain, dif_neg, h, subset.refl]
/-- Set of sets reachable from `∅` using `succ_chain` and `⋃₀`. -/
inductive chain_closure : set α → Prop
| succ : ∀{s}, chain_closure s → chain_closure (succ_chain s)
| union : ∀{s}, (∀a∈s, chain_closure a) → chain_closure (⋃₀ s)
theorem chain_closure_empty : chain_closure ∅ :=
have chain_closure (⋃₀ ∅),
from chain_closure.union $ assume a h, h.rec _,
by simp at this; assumption
theorem chain_closure_closure : chain_closure (⋃₀ chain_closure) :=
chain_closure.union $ assume s hs, hs
variables {c c₁ c₂ c₃ : set α}
private lemma chain_closure_succ_total_aux (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h : ∀{c₃}, chain_closure c₃ → c₃ ⊆ c₂ → c₂ = c₃ ∨ succ_chain c₃ ⊆ c₂) :
c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁ :=
begin
induction hc₁,
case _root_.zorn.chain_closure.succ : c₃ hc₃ ih {
cases ih with ih ih,
{ have h := h hc₃ ih,
cases h with h h,
{ exact or.inr (h ▸ subset.refl _) },
{ exact or.inl h } },
{ exact or.inr (subset.trans ih succ_increasing) } },
case _root_.zorn.chain_closure.union : s hs ih {
refine (classical.or_iff_not_imp_right.2 $ λ hn, sUnion_subset $ λ a ha, _),
apply (ih a ha).resolve_right,
apply mt (λ h, _) hn,
exact subset.trans h (subset_sUnion_of_mem ha) }
end
private lemma chain_closure_succ_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) (h : c₁ ⊆ c₂) :
c₂ = c₁ ∨ succ_chain c₁ ⊆ c₂ :=
begin
induction hc₂ generalizing c₁ hc₁ h,
case _root_.zorn.chain_closure.succ : c₂ hc₂ ih {
have h₁ : c₁ ⊆ c₂ ∨ @succ_chain α r c₂ ⊆ c₁ :=
(chain_closure_succ_total_aux hc₁ hc₂ $ assume c₁, ih),
cases h₁ with h₁ h₁,
{ have h₂ := ih hc₁ h₁,
cases h₂ with h₂ h₂,
{ exact (or.inr $ h₂ ▸ subset.refl _) },
{ exact (or.inr $ subset.trans h₂ succ_increasing) } },
{ exact (or.inl $ subset.antisymm h₁ h) } },
case _root_.zorn.chain_closure.union : s hs ih {
apply or.imp_left (assume h', subset.antisymm h' h),
apply classical.by_contradiction,
simp [not_or_distrib, sUnion_subset_iff, classical.not_forall],
intros c₃ hc₃ h₁ h₂,
have h := chain_closure_succ_total_aux hc₁ (hs c₃ hc₃) (assume c₄, ih _ hc₃),
cases h with h h,
{ have h' := ih c₃ hc₃ hc₁ h,
cases h' with h' h',
{ exact (h₁ $ h' ▸ subset.refl _) },
{ exact (h₂ $ subset.trans h' $ subset_sUnion_of_mem hc₃) } },
{ exact (h₁ $ subset.trans succ_increasing h) } }
end
theorem chain_closure_total (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂) : c₁ ⊆ c₂ ∨ c₂ ⊆ c₁ :=
have c₁ ⊆ c₂ ∨ succ_chain c₂ ⊆ c₁,
from chain_closure_succ_total_aux hc₁ hc₂ $ assume c₃ hc₃, chain_closure_succ_total hc₃ hc₂,
or.imp_right (assume : succ_chain c₂ ⊆ c₁, subset.trans succ_increasing this) this
theorem chain_closure_succ_fixpoint (hc₁ : chain_closure c₁) (hc₂ : chain_closure c₂)
(h_eq : succ_chain c₂ = c₂) : c₁ ⊆ c₂ :=
begin
induction hc₁,
case _root_.zorn.chain_closure.succ : c₁ hc₁ h {
exact or.elim (chain_closure_succ_total hc₁ hc₂ h)
(assume h, h ▸ h_eq.symm ▸ subset.refl c₂) id },
case _root_.zorn.chain_closure.union : s hs ih {
exact (sUnion_subset $ assume c₁ hc₁, ih c₁ hc₁) }
end
theorem chain_closure_succ_fixpoint_iff (hc : chain_closure c) :
succ_chain c = c ↔ c = ⋃₀ chain_closure :=
⟨assume h, subset.antisymm
(subset_sUnion_of_mem hc)
(chain_closure_succ_fixpoint chain_closure_closure hc h),
assume : c = ⋃₀{c : set α | chain_closure c},
subset.antisymm
(calc succ_chain c ⊆ ⋃₀{c : set α | chain_closure c} :
subset_sUnion_of_mem $ chain_closure.succ hc
... = c : this.symm)
succ_increasing⟩
theorem chain_chain_closure (hc : chain_closure c) : chain c :=
begin
induction hc,
case _root_.zorn.chain_closure.succ : c hc h {
exact chain_succ h },
case _root_.zorn.chain_closure.union : s hs h {
have h : ∀c∈s, zorn.chain c := h,
exact assume c₁ ⟨t₁, ht₁, (hc₁ : c₁ ∈ t₁)⟩ c₂ ⟨t₂, ht₂, (hc₂ : c₂ ∈ t₂)⟩ hneq,
have t₁ ⊆ t₂ ∨ t₂ ⊆ t₁, from chain_closure_total (hs _ ht₁) (hs _ ht₂),
or.elim this
(assume : t₁ ⊆ t₂, h t₂ ht₂ c₁ (this hc₁) c₂ hc₂ hneq)
(assume : t₂ ⊆ t₁, h t₁ ht₁ c₁ hc₁ c₂ (this hc₂) hneq) }
end
/-- `max_chain` is the union of all sets in the chain closure. -/
def max_chain := ⋃₀ chain_closure
/-- Hausdorff's maximality principle
There exists a maximal totally ordered subset of `α`.
Note that we do not require `α` to be partially ordered by `r`. -/
theorem max_chain_spec : is_max_chain max_chain :=
classical.by_contradiction $
assume : ¬ is_max_chain (⋃₀ chain_closure),
have super_chain (⋃₀ chain_closure) (succ_chain (⋃₀ chain_closure)),
from super_of_not_max (chain_chain_closure chain_closure_closure) this,
let ⟨h₁, H⟩ := this,
⟨h₂, (h₃ : (⋃₀ chain_closure) ≠ succ_chain (⋃₀ chain_closure))⟩ := ssubset_iff_subset_ne.1 H in
have succ_chain (⋃₀ chain_closure) = (⋃₀ chain_closure),
from (chain_closure_succ_fixpoint_iff chain_closure_closure).mpr rfl,
h₃ this.symm
/-- Zorn's lemma
If every chain has an upper bound, then there is a maximal element -/
theorem exists_maximal_of_chains_bounded
(h : ∀c, chain c → ∃ub, ∀a∈c, a ≺ ub) (trans : ∀{a b c}, a ≺ b → b ≺ c → a ≺ c) :
∃m, ∀a, m ≺ a → a ≺ m :=
have ∃ub, ∀a∈max_chain, a ≺ ub,
from h _ $ max_chain_spec.left,
let ⟨ub, (hub : ∀a∈max_chain, a ≺ ub)⟩ := this in
⟨ub, assume a ha,
have chain (insert a max_chain),
from chain_insert max_chain_spec.left $ assume b hb _, or.inr $ trans (hub b hb) ha,
have a ∈ max_chain, from
classical.by_contradiction $ assume h : a ∉ max_chain,
max_chain_spec.right $ ⟨insert a max_chain, this, ssubset_insert h⟩,
hub a this⟩
end chain
theorem zorn_partial_order {α : Type u} [partial_order α]
(h : ∀c:set α, chain (≤) c → ∃ub, ∀a∈c, a ≤ ub) : ∃m:α, ∀a, m ≤ a → a = m :=
let ⟨m, hm⟩ := @exists_maximal_of_chains_bounded α (≤) h (assume a b c, le_trans) in
⟨m, assume a ha, le_antisymm (hm a ha) ha⟩
theorem zorn_partial_order₀ {α : Type u} [partial_order α] (s : set α)
(ih : ∀ c ⊆ s, chain (≤) c → ∀ y ∈ c, ∃ ub ∈ s, ∀ z ∈ c, z ≤ ub)
(x : α) (hxs : x ∈ s) : ∃ m ∈ s, x ≤ m ∧ ∀ z ∈ s, m ≤ z → z = m :=
let ⟨⟨m, hms, hxm⟩, h⟩ := @zorn_partial_order {m // m ∈ s ∧ x ≤ m} _ (λ c hc, c.eq_empty_or_nonempty.elim
(assume hce, hce.symm ▸ ⟨⟨x, hxs, le_refl _⟩, λ _, false.elim⟩)
(assume ⟨m, hmc⟩,
let ⟨ub, hubs, hub⟩ := ih (subtype.val '' c) (image_subset_iff.2 $ λ z hzc, z.2.1)
(by rintro _ ⟨p, hpc, rfl⟩ _ ⟨q, hqc, rfl⟩ hpq;
exact hc p hpc q hqc (mt (by rintro rfl; refl) hpq)) m.1 (mem_image_of_mem _ hmc) in
⟨⟨ub, hubs, le_trans m.2.2 $ hub m.1 $ mem_image_of_mem _ hmc⟩, λ a hac, hub a.1 ⟨a, hac, rfl⟩⟩)) in
⟨m, hms, hxm, λ z hzs hmz, congr_arg subtype.val $ h ⟨z, hzs, le_trans hxm hmz⟩ hmz⟩
theorem zorn_subset {α : Type u} (S : set (set α))
(h : ∀c ⊆ S, chain (⊆) c → ∃ub ∈ S, ∀ s ∈ c, s ⊆ ub) :
∃ m ∈ S, ∀a ∈ S, m ⊆ a → a = m :=
begin
letI : partial_order S := partial_order.lift subtype.val (λ _ _, subtype.eq') (by apply_instance),
have : ∀c:set S, @chain S (≤) c → ∃ub, ∀a∈c, a ≤ ub,
{ intros c hc,
rcases h (subtype.val '' c) (image_subset_iff.2 _) _ with ⟨s, sS, hs⟩,
{ exact ⟨⟨s, sS⟩, λ ⟨x, hx⟩ H, hs _ (mem_image_of_mem _ H)⟩ },
{ rintro ⟨x, hx⟩ _, exact hx },
{ rintro _ ⟨x, cx, rfl⟩ _ ⟨y, cy, rfl⟩ xy,
exact hc x cx y cy (mt (congr_arg _) xy) } },
rcases zorn_partial_order this with ⟨⟨m, mS⟩, hm⟩,
exact ⟨m, mS, λ a aS ha, congr_arg subtype.val (hm ⟨a, aS⟩ ha)⟩
end
theorem zorn_subset₀ {α : Type u} (S : set (set α))
(H : ∀c ⊆ S, chain (⊆) c → c.nonempty → ∃ub ∈ S, ∀ s ∈ c, s ⊆ ub) (x) (hx : x ∈ S) :
∃ m ∈ S, x ⊆ m ∧ ∀a ∈ S, m ⊆ a → a = m :=
begin
let T := {s ∈ S | x ⊆ s},
rcases zorn_subset T _ with ⟨m, ⟨mS, mx⟩, hm⟩,
{ exact ⟨m, mS, mx, λ a ha ha', hm a ⟨ha, subset.trans mx ha'⟩ ha'⟩ },
{ intros c cT hc,
cases c.eq_empty_or_nonempty with c0 c0,
{ rw c0, exact ⟨x, ⟨hx, subset.refl _⟩, λ _, false.elim⟩ },
{ rcases H _ (subset.trans cT (sep_subset _ _)) hc c0 with ⟨ub, us, h⟩,
refine ⟨ub, ⟨us, _⟩, h⟩,
rcases c0 with ⟨s, hs⟩,
exact subset.trans (cT hs).2 (h _ hs) } }
end
theorem chain.total {α : Type u} [preorder α]
{c : set α} (H : chain (≤) c) :
∀ {x y}, x ∈ c → y ∈ c → x ≤ y ∨ y ≤ x :=
λ x y, H.total_of_refl
theorem chain.image {α β : Type*} (r : α → α → Prop)
(s : β → β → Prop) (f : α → β)
(h : ∀ x y, r x y → s (f x) (f y))
{c : set α} (hrc : chain r c) : chain s (f '' c) :=
λ x ⟨a, ha₁, ha₂⟩ y ⟨b, hb₁, hb₂⟩, ha₂ ▸ hb₂ ▸ λ hxy,
(hrc a ha₁ b hb₁ (mt (congr_arg f) $ hxy)).elim
(or.inl ∘ h _ _) (or.inr ∘ h _ _)
end zorn
|
57489fb4f45b118202b26de633a22ea71c4dc8f9 | 367134ba5a65885e863bdc4507601606690974c1 | /src/order/category/Preorder.lean | be500a0ab7bc893c969aa824891ff2b828b3fa30 | [
"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 | 896 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import order.preorder_hom
import category_theory.concrete_category
import algebra.punit_instances
/-! # Category of preorders -/
open category_theory
/-- The category of preorders. -/
def Preorder := bundled preorder
namespace Preorder
instance : bundled_hom @preorder_hom :=
{ to_fun := @preorder_hom.to_fun,
id := @preorder_hom.id,
comp := @preorder_hom.comp,
hom_ext := @preorder_hom.coe_inj }
attribute [derive [has_coe_to_sort, large_category, concrete_category]] Preorder
/-- Construct a bundled Preorder from the underlying type and typeclass. -/
def of (α : Type*) [preorder α] : Preorder := bundled.of α
instance : inhabited Preorder := ⟨of punit⟩
instance (α : Preorder) : preorder α := α.str
end Preorder
|
f09071a12e860385a92217853cbbdfe244e072bf | 618003631150032a5676f229d13a079ac875ff77 | /src/tactic/ring_exp.lean | 4ca8182acc53a8eaeae74f1d0272372fecb44f36 | [
"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 | 55,399 | lean | /-
Copyright (c) 2019 Tim Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Tim Baanen.
Solve equations in commutative (semi)rings with exponents.
-/
import tactic.norm_num
/-!
# `ring_exp` tactic
A tactic for solving equations in commutative (semi)rings,
where the exponents can also contain variables.
More precisely, expressions of the following form are supported:
- constants (non-negative integers)
- variables
- coefficients (any rational number, embedded into the (semi)ring)
- addition of expressions
- multiplication of expressions
- exponentiation of expressions (the exponent must have type `ℕ`)
- subtraction and negation of expressions (if the base is a full ring)
The motivating example is proving `2 * 2^n * b = b * 2^(n+1)`,
something that the `ring` tactic cannot do, but `ring_exp` can.
## Implementation notes
The basic approach to prove equalities is to normalise both sides and check for equality.
The normalisation is guided by building a value in the type `ex` at the meta level,
together with a proof (at the base level) that the original value is equal to
the normalised version.
The normalised version and normalisation proofs are also stored in the `ex` type.
The outline of the file:
- Define an inductive family of types `ex`, parametrised over `ex_type`,
which can represent expressions with `+`, `*`, `^` and rational numerals.
The parametrisation over `ex_type` ensures that associativity and distributivity are applied,
by restricting which kinds of subexpressions appear as arguments to the various operators.
- Represent addition, multiplication and exponentiation in the `ex` type,
thus allowing us to map expressions to `ex` (the `eval` function drives this).
We apply associativity and distributivity of the operators here (helped by `ex_type`)
and commutativity as well (by sorting the subterms; unfortunately not helped by anything).
Any expression not of the above formats is treated as an atom (the same as a variable).
There are some details we glossed over which make the plan more complicated:
- The order on atoms is not initially obvious.
We construct a list containing them in order of initial appearance in the expression,
then use the index into the list as a key to order on.
- In the tactic, a normalized expression `ps : ex` lives in the meta-world,
but the normalization proofs live in the real world.
Thus, we cannot directly say `ps.orig = ps.pretty` anywhere,
but we have to carefully construct the proof when we compute `ps`.
This was a major source of bugs in development!
- For `pow`, the exponent must be a natural number, while the base can be any semiring `α`.
We swap out operations for the base ring `α` with those for the exponent ring `ℕ`
as soon as we deal with exponents.
This is accomplished by the `in_exponent` function and is relatively painless since
we work in a `reader` monad.
- The normalized form of an expression is the one that is useful for the tactic,
but not as nice to read. To remedy this, the user-facing normalization calls `ex.simp`.
## Caveats and future work
Subtraction cancels out identical terms, but division does not.
That is: `a - a = 0 := by ring_exp` solves the goal,
but `a / a := 1 by ring_exp` doesn't.
Note that `0 / 0` is generally defined to be `0`,
so division cancelling out is not true in general.
Multiplication of powers can be simplified a little bit further:
`2 ^ n * 2 ^ n = 4 ^ n := by ring_exp` could be implemented
in a similar way that `2 * a + 2 * a = 4 * a := by ring_exp` already works.
This feature wasn't needed yet, so it's not implemented yet.
## Tags
ring, semiring, exponent, power
-/
-- The base ring `α` will have a universe level `u`.
-- We do not introduce `α` as a variable yet,
-- in order to make it explicit or implicit as required.
universes u
namespace tactic.ring_exp
open nat
/--
The `atom` structure is used to represent atomic expressions:
those which `ring_exp` cannot parse any further.
For instance, `a + (a % b)` has `a` and `(a % b)` as atoms.
The `ring_exp_eq` tactic does not normalize the subexpressions in atoms,
but `ring_exp` does if `ring_exp_eq` was not sufficient.
Atoms in fact represent equivalence classes of expressions,
modulo definitional equality.
The field `index : ℕ` should be a unique number for each class,
while `value : expr` contains a representative of this class.
The function `resolve_atom` determines the appropriate atom
for a given expression.
-/
meta structure atom : Type := (value : expr) (index : ℕ)
namespace atom
/--
The `eq` operation on `atom`s works modulo definitional equality,
ignoring their `value`s.
The invariants on `atom` ensure indices are unique per value.
Thus, `eq` indicates equality as long as the `atom`s come from the same context.
-/
meta def eq (a b : atom) : bool := a.index = b.index
/--
We order `atom`s on the order of appearance in the main expression.
-/
meta def lt (a b : atom) : bool := a.index < b.index
meta instance : has_repr atom := ⟨λ x, "(atom " ++ repr x.2 ++ ")"⟩
end atom
section expression
/-!
### `expression` section
In this section, we define the `ex` type and its basic operations.
First, we introduce the supporting types `coeff`, `ex_type` and `ex_info`.
For understanding the code, it's easier to check out `ex` itself first,
then refer back to the supporting types.
The arithmetic operations on `ex` need additional definitions,
so they are defined in a later section.
-/
/--
Coefficients in the expression are stored in a wrapper structure,
allowing for easier modification of the data structures.
The modifications might be caching of the result of `expr.of_rat`,
or using a different meta representation of numerals.
-/
@[derive decidable_eq, derive inhabited]
structure coeff : Type := (value : ℚ)
/-- The values in `ex_type` are used as parameters to `ex` to control the expression's structure. -/
@[derive decidable_eq, derive inhabited]
inductive ex_type : Type
| base : ex_type
| sum : ex_type
| prod : ex_type
| exp : ex_type
open ex_type
/--
Each `ex` stores information for its normalization proof.
The `orig` expression is the expression that was passed to `eval`.
The `pretty` expression is the normalised form that the `ex` represents.
(I didn't call this something like `norm`, because there are already
too many things called `norm` in mathematics!)
The field `proof` contains an optional proof term of type `%%orig = %%pretty`.
The value `none` for the proof indicates that everything reduces to reflexivity.
(Which saves space in quite a lot of cases.)
-/
meta structure ex_info : Type :=
(orig : expr) (pretty : expr) (proof : option expr)
/--
The `ex` type is an abstract representation of an expression with `+`, `*` and `^`.
Those operators are mapped to the `sum`, `prod` and `exp` constructors respectively.
The `zero` constructor is the base case for `ex sum`, e.g. `1 + 2` is represented
by (something along the lines of) `sum 1 (sum 2 zero)`.
The `coeff` constructor is the base case for `ex prod`, and is used for numerals.
The code maintains the invariant that the coefficient is never `0`.
The `var` constructor is the base case for `ex exp`, and is used for atoms.
The `sum_b` constructor allows for addition in the base of an exponentiation;
it serves a similar purpose as the parentheses in `(a + b)^c`.
The code maintains the invariant that the argument to `sum_b` is not `zero`
or `sum _ zero`.
All of the constructors contain an `ex_info` field,
used to carry around (arguments to) proof terms.
While the `ex_type` parameter enforces some simplification invariants,
the following ones must be manually maintained at the risk of insufficient power:
- the argument to `coeff` must be nonzero (to ensure `0 = 0 * 1`)
- the argument to `sum_b` must be of the form `sum a (sum b bs)` (to ensure `(a + 0)^n = a^n`)
- normalisation proofs of subexpressions must be `refl ps.pretty`
- if we replace `sum` with `cons` and `zero` with `nil`, the resulting list is sorted
according to the `lt` relation defined further down; similarly for `prod` and `coeff`
(to ensure `a + b = b + a`).
The first two invariants could be encoded in a subtype of `ex`,
but aren't (yet) to spare some implementation burden.
The other invariants cannot be encoded because we need the `tactic` monad to check them.
(For example, the correct equality check of `expr` is `is_def_eq : expr → expr → tactic unit`.)
-/
meta inductive ex : ex_type → Type
| zero (info : ex_info) : ex sum
| sum (info : ex_info) : ex prod → ex sum → ex sum
| coeff (info : ex_info) : coeff → ex prod
| prod (info : ex_info) : ex exp → ex prod → ex prod
| var (info : ex_info) : atom → ex base
| sum_b (info : ex_info) : ex sum → ex base
| exp (info : ex_info) : ex base → ex prod → ex exp
/--
Return the proof information associated to the `ex`.
-/
meta def ex.info : Π {et : ex_type} (ps : ex et), ex_info
| sum (ex.zero i) := i
| sum (ex.sum i _ _) := i
| prod (ex.coeff i _) := i
| prod (ex.prod i _ _) := i
| base (ex.var i _) := i
| base (ex.sum_b i _) := i
| exp (ex.exp i _ _) := i
/--
Return the original, non-normalized version of this `ex`.
Note that arguments to another `ex` are always "pre-normalized":
their `orig` and `pretty` are equal, and their `proof` is reflexivity.
-/
meta def ex.orig {et : ex_type} (ps : ex et) : expr := ps.info.orig
/--
Return the normalized version of this `ex`.
-/
meta def ex.pretty {et : ex_type} (ps : ex et) : expr := ps.info.pretty
/--
Return the normalisation proof of the given expression.
If the proof is `refl`, we give `none` instead,
which helps to control the size of proof terms.
To get an actual term, use `ex.proof_term`,
or use `mk_proof` with the correct set of arguments.
-/
meta def ex.proof {et : ex_type} (ps : ex et) : option expr := ps.info.proof
/--
Update the `orig` and `proof` fields of the `ex_info`.
Intended for use in `ex.set_info`.
-/
meta def ex_info.set (i : ex_info) (o : option expr) (pf : option expr) : ex_info :=
{orig := o.get_or_else i.pretty, proof := pf, .. i}
/--
Update the `ex_info` of the given expression.
We use this to combine intermediate normalisation proofs.
Since `pretty` only depends on the subexpressions,
which do not change, we do not set `pretty`.
-/
meta def ex.set_info : Π {et : ex_type} (ps : ex et), option expr → option expr → ex et
| sum (ex.zero i) o pf := ex.zero (i.set o pf)
| sum (ex.sum i p ps) o pf := ex.sum (i.set o pf) p ps
| prod (ex.coeff i x) o pf := ex.coeff (i.set o pf) x
| prod (ex.prod i p ps) o pf := ex.prod (i.set o pf) p ps
| base (ex.var i x) o pf := ex.var (i.set o pf) x
| base (ex.sum_b i ps) o pf := ex.sum_b (i.set o pf) ps
| exp (ex.exp i p ps) o pf := ex.exp (i.set o pf) p ps
instance coeff_has_repr : has_repr coeff := ⟨λ x, repr x.1⟩
/-- Convert an `ex` to a `string`. -/
meta def ex.repr : Π {et : ex_type}, ex et → string
| sum (ex.zero _) := "0"
| sum (ex.sum _ p ps) := ex.repr p ++ " + " ++ ex.repr ps
| prod (ex.coeff _ x) := repr x
| prod (ex.prod _ p ps) := ex.repr p ++ " * " ++ ex.repr ps
| base (ex.var _ x) := repr x
| base (ex.sum_b _ ps) := "(" ++ ex.repr ps ++ ")"
| exp (ex.exp _ p ps) := ex.repr p ++ " ^ " ++ ex.repr ps
meta instance {et : ex_type} : has_repr (ex et) := ⟨ex.repr⟩
/--
Equality test for expressions.
Since equivalence of `atom`s is not the same as equality,
we cannot make a true `(=)` operator for `ex` either.
-/
meta def ex.eq : Π {et : ex_type}, ex et → ex et → bool
| sum (ex.zero _) (ex.zero _) := tt
| sum (ex.zero _) (ex.sum _ _ _) := ff
| sum (ex.sum _ _ _) (ex.zero _) := ff
| sum (ex.sum _ p ps) (ex.sum _ q qs) := p.eq q && ps.eq qs
| prod (ex.coeff _ x) (ex.coeff _ y) := x = y
| prod (ex.coeff _ _) (ex.prod _ _ _) := ff
| prod (ex.prod _ _ _) (ex.coeff _ _) := ff
| prod (ex.prod _ p ps) (ex.prod _ q qs) := p.eq q && ps.eq qs
| base (ex.var _ x) (ex.var _ y) := x.eq y
| base (ex.var _ _) (ex.sum_b _ _) := ff
| base (ex.sum_b _ _) (ex.var _ _) := ff
| base (ex.sum_b _ ps) (ex.sum_b _ qs) := ps.eq qs
| exp (ex.exp _ p ps) (ex.exp _ q qs) := p.eq q && ps.eq qs
/--
The ordering on expressions.
As for `ex.eq`, this is a linear order only in one context.
-/
meta def ex.lt : Π {et : ex_type}, ex et → ex et → bool
| sum _ (ex.zero _) := ff
| sum (ex.zero _) _ := tt
| sum (ex.sum _ p ps) (ex.sum _ q qs) := p.lt q || (p.eq q && ps.lt qs)
| prod (ex.coeff _ x) (ex.coeff _ y) := x.1 < y.1
| prod (ex.coeff _ _) _ := tt
| prod _ (ex.coeff _ _) := ff
| prod (ex.prod _ p ps) (ex.prod _ q qs) := p.lt q || (p.eq q && ps.lt qs)
| base (ex.var _ x) (ex.var _ y) := x.lt y
| base (ex.var _ _) (ex.sum_b _ _) := tt
| base (ex.sum_b _ _) (ex.var _ _) := ff
| base (ex.sum_b _ ps) (ex.sum_b _ qs) := ps.lt qs
| exp (ex.exp _ p ps) (ex.exp _ q qs) := p.lt q || (p.eq q && ps.lt qs)
end expression
section operations
/-!
### `operations` section
This section defines the operations (on `ex`) that use tactics.
They live in the `ring_exp_m` monad,
which adds a cache and a list of encountered atoms to the `tactic` monad.
Throughout this section, we will be constructing proof terms.
The lemmas used in the construction are all defined over a commutative semiring α.
-/
variables {α : Type u} [comm_semiring α]
open tactic
open ex_type
/--
Stores the information needed in the `eval` function and its dependencies,
so they can (re)construct expressions.
The `eval_info` structure stores this information for one type,
and the `context` combines the two types, one for bases and one for exponents.
-/
meta structure eval_info :=
(α : expr) (univ : level)
-- Cache the instances for optimization and consistency
(csr_instance : expr) (ha_instance : expr) (hm_instance : expr) (hp_instance : expr)
-- Optional instances (only required for (-) and (/) respectively)
(ring_instance : option expr) (dr_instance : option expr)
-- Cache common constants.
(zero : expr) (one : expr)
/--
The `context` contains the full set of information needed for the `eval` function.
This structure has two copies of `eval_info`:
one is for the base (typically some semiring `α`) and another for the exponent (always `ℕ`).
When evaluating an exponent, we put `info_e` in `info_b`.
-/
meta structure context :=
(info_b : eval_info) (info_e : eval_info) (transp : transparency)
/--
The `ring_exp_m` monad is used instead of `tactic` to store the context.
-/
@[derive [monad, alternative]]
meta def ring_exp_m (α : Type) : Type := reader_t context (state_t (list atom) tactic) α
/--
Access the instance cache.
-/
meta def get_context : ring_exp_m context := reader_t.read
/--
Lift an operation in the `tactic` monad to the `ring_exp_m` monad.
This operation will not access the cache.
-/
meta def lift {α} (m : tactic α) : ring_exp_m α := reader_t.lift (state_t.lift m)
/--
Change the context of the given computation,
so that expressions are evaluated in the exponent ring,
instead of the base ring.
-/
meta def in_exponent {α} (mx : ring_exp_m α) : ring_exp_m α := do
ctx ← get_context,
reader_t.lift $ mx.run ⟨ctx.info_e, ctx.info_e, ctx.transp⟩
/--
Specialized version of `mk_app` where the first two arguments are `{α}` `[some_class α]`.
Should be faster because it can use the cached instances.
-/
meta def mk_app_class (f : name) (inst : expr) (args : list expr) : ring_exp_m expr := do
ctx ← get_context,
pure $ (@expr.const tt f [ctx.info_b.univ] ctx.info_b.α inst).mk_app args
/--
Specialized version of `mk_app` where the first two arguments are `{α}` `[comm_semiring α]`.
Should be faster because it can use the cached instances.
-/
meta def mk_app_csr (f : name) (args : list expr) : ring_exp_m expr := do
ctx ← get_context,
mk_app_class f (ctx.info_b.csr_instance) args
/--
Specialized version of `mk_app ``has_add.add`.
Should be faster because it can use the cached instances.
-/
meta def mk_add (args : list expr) : ring_exp_m expr := do
ctx ← get_context,
mk_app_class ``has_add.add ctx.info_b.ha_instance args
/--
Specialized version of `mk_app ``has_mul.mul`.
Should be faster because it can use the cached instances.
-/
meta def mk_mul (args : list expr) : ring_exp_m expr := do
ctx ← get_context,
mk_app_class ``has_mul.mul ctx.info_b.hm_instance args
/--
Specialized version of `mk_app ``has_pow.pow`.
Should be faster because it can use the cached instances.
-/
meta def mk_pow (args : list expr) : ring_exp_m expr := do
ctx ← get_context,
pure $ (@expr.const tt ``has_pow.pow
[ctx.info_b.univ, ctx.info_e.univ]
ctx.info_b.α ctx.info_e.α
ctx.info_b.hp_instance).mk_app args
/-- Construct a normalization proof term or return the cached one. -/
meta def ex_info.proof_term (ps : ex_info) : ring_exp_m expr :=
match ps.proof with
| none := lift $ tactic.mk_eq_refl ps.pretty
| (some p) := pure p
end
/-- Construct a normalization proof term or return the cached one. -/
meta def ex.proof_term {et : ex_type} (ps : ex et) : ring_exp_m expr := ps.info.proof_term
/--
If all `ex_info` have trivial proofs, return a trivial proof.
Otherwise, construct all proof terms.
Useful in applications where trivial proofs combine to another trivial proof,
most importantly to pass to `mk_proof_or_refl`.
-/
meta def none_or_proof_term : list ex_info → ring_exp_m (option (list expr))
| [] := pure none
| (x :: xs) := do
xs_pfs ← none_or_proof_term xs,
match (x.proof, xs_pfs) with
| (none, none) := pure none
| (some x_pf, none) := do
xs_pfs ← traverse ex_info.proof_term xs,
pure (some (x_pf :: xs_pfs))
| (_, some xs_pfs) := do
x_pf ← x.proof_term,
pure (some (x_pf :: xs_pfs))
end
/--
Use the proof terms as arguments to the given lemma.
If the lemma could reduce to reflexivity, consider using `mk_proof_or_refl.`
-/
meta def mk_proof (lem : name) (args : list expr) (hs : list ex_info) : ring_exp_m expr := do
hs' ← traverse ex_info.proof_term hs,
mk_app_csr lem (args ++ hs')
/--
Use the proof terms as arguments to the given lemma.
Often, we construct a proof term using congruence where reflexivity suffices.
To solve this, the following function tries to get away with reflexivity.
-/
meta def mk_proof_or_refl (term : expr) (lem : name) (args : list expr) (hs : list ex_info) :
ring_exp_m expr := do
hs_full ← none_or_proof_term hs,
match hs_full with
| none := lift $ mk_eq_refl term
| (some hs') := mk_app_csr lem (args ++ hs')
end
/-- A shortcut for adding the original terms of two expressions. -/
meta def add_orig {et et'} (ps : ex et) (qs : ex et') : ring_exp_m expr :=
mk_add [ps.orig, qs.orig]
/-- A shortcut for multiplying the original terms of two expressions. -/
meta def mul_orig {et et'} (ps : ex et) (qs : ex et') : ring_exp_m expr :=
mk_mul [ps.orig, qs.orig]
/-- A shortcut for exponentiating the original terms of two expressions. -/
meta def pow_orig {et et'} (ps : ex et) (qs : ex et') : ring_exp_m expr :=
mk_pow [ps.orig, qs.orig]
/-- Congruence lemma for constructing `ex.sum`. -/
lemma sum_congr {p p' ps ps' : α} : p = p' → ps = ps' → p + ps = p' + ps' := by cc
/-- Congruence lemma for constructing `ex.prod`. -/
lemma prod_congr {p p' ps ps' : α} : p = p' → ps = ps' → p * ps = p' * ps' := by cc
/-- Congruence lemma for constructing `ex.exp`. -/
lemma exp_congr {p p' : α} {ps ps' : ℕ} : p = p' → ps = ps' → p ^ ps = p' ^ ps' := by cc
/-- Constructs `ex.zero` with the correct arguments. -/
meta def ex_zero : ring_exp_m (ex sum) := do
ctx ← get_context,
pure $ ex.zero ⟨ctx.info_b.zero, ctx.info_b.zero, none⟩
/-- Constructs `ex.sum` with the correct arguments. -/
meta def ex_sum (p : ex prod) (ps : ex sum) : ring_exp_m (ex sum) := do
pps_o ← add_orig p ps,
pps_p ← mk_add [p.pretty, ps.pretty],
pps_pf ← mk_proof_or_refl pps_p ``sum_congr
[p.orig, p.pretty, ps.orig, ps.pretty]
[p.info, ps.info],
pure (ex.sum ⟨pps_o, pps_p, pps_pf⟩ (p.set_info none none) (ps.set_info none none))
/--
Constructs `ex.coeff` with the correct arguments.
There are more efficient constructors for specific numerals:
if `x = 0`, you should use `ex_zero`; if `x = 1`, use `ex_one`.
-/
meta def ex_coeff (x : rat) : ring_exp_m (ex prod) := do
ctx ← get_context,
x_p ← lift $ expr.of_rat ctx.info_b.α x,
pure (ex.coeff ⟨x_p, x_p, none⟩ ⟨x⟩)
/--
Constructs `ex.coeff 1` with the correct arguments.
This is a special case for optimization purposes.
-/
meta def ex_one : ring_exp_m (ex prod) := do
ctx ← get_context,
pure $ ex.coeff ⟨ctx.info_b.one, ctx.info_b.one, none⟩ ⟨1⟩
/-- Constructs `ex.prod` with the correct arguments. -/
meta def ex_prod (p : ex exp) (ps : ex prod) : ring_exp_m (ex prod) := do
pps_o ← mul_orig p ps,
pps_p ← mk_mul [p.pretty, ps.pretty],
pps_pf ← mk_proof_or_refl pps_p ``prod_congr
[p.orig, p.pretty, ps.orig, ps.pretty]
[p.info, ps.info],
pure (ex.prod ⟨pps_o, pps_p, pps_pf⟩ (p.set_info none none) (ps.set_info none none))
/-- Constructs `ex.var` with the correct arguments. -/
meta def ex_var (p : atom) : ring_exp_m (ex base) := pure (ex.var ⟨p.1, p.1, none⟩ p)
/-- Constructs `ex.sum_b` with the correct arguments. -/
meta def ex_sum_b (ps : ex sum) : ring_exp_m (ex base) :=
pure (ex.sum_b ps.info (ps.set_info none none))
/-- Constructs `ex.exp` with the correct arguments. -/
meta def ex_exp (p : ex base) (ps : ex prod) : ring_exp_m (ex exp) := do
ctx ← get_context,
pps_o ← pow_orig p ps,
pps_p ← mk_pow [p.pretty, ps.pretty],
pps_pf ← mk_proof_or_refl pps_p ``exp_congr
[p.orig, p.pretty, ps.orig, ps.pretty]
[p.info, ps.info],
pure (ex.exp ⟨pps_o, pps_p, pps_pf⟩ (p.set_info none none) (ps.set_info none none))
lemma base_to_exp_pf {p p' : α} : p = p' → p = p' ^ 1 := by simp
/-- Conversion from `ex base` to `ex exp`. -/
meta def base_to_exp (p : ex base) : ring_exp_m (ex exp) := do
o ← in_exponent $ ex_one,
ps ← ex_exp p o,
pf ← mk_proof ``base_to_exp_pf [p.orig, p.pretty] [p.info],
pure $ ps.set_info p.orig pf
lemma exp_to_prod_pf {p p' : α} : p = p' → p = p' * 1 := by simp
/-- Conversion from `ex exp` to `ex prod`. -/
meta def exp_to_prod (p : ex exp) : ring_exp_m (ex prod) := do
o ← ex_one,
ps ← ex_prod p o,
pf ← mk_proof ``exp_to_prod_pf [p.orig, p.pretty] [p.info],
pure $ ps.set_info p.orig pf
lemma prod_to_sum_pf {p p' : α} : p = p' → p = p' + 0 := by simp
/-- Conversion from `ex prod` to `ex sum`. -/
meta def prod_to_sum (p : ex prod) : ring_exp_m (ex sum) := do
z ← ex_zero,
ps ← ex_sum p z,
pf ← mk_proof ``prod_to_sum_pf [p.orig, p.pretty] [p.info],
pure $ ps.set_info p.orig pf
lemma atom_to_sum_pf (p : α) : p = p ^ 1 * 1 + 0 := by simp
/--
A more efficient conversion from `atom` to `ex sum`.
The result should be the same as `ex_var p >>= base_to_exp >>= exp_to_prod >>= prod_to_sum`,
except we need to calculate less intermediate steps.
-/
meta def atom_to_sum (p : atom) : ring_exp_m (ex sum) := do
p' ← ex_var p,
o ← in_exponent $ ex_one,
p' ← ex_exp p' o,
o ← ex_one,
p' ← ex_prod p' o,
z ← ex_zero,
p' ← ex_sum p' z,
pf ← mk_proof ``atom_to_sum_pf [p.1] [],
pure $ p'.set_info p.1 pf
/--
Compute the sum of two coefficients.
Note that the result might not be a valid expression:
if `p = -q`, then the result should be `ex.zero : ex sum` instead.
The caller must detect when this happens!
The returned value is of the form `ex.coeff _ (p + q)`,
with the proof of `expr.of_rat p + expr.of_rat q = expr.of_rat (p + q)`.
-/
meta def add_coeff (p_p q_p : expr) (p q : coeff) : ring_exp_m (ex prod) := do
ctx ← get_context,
pq_o ← mk_add [p_p, q_p],
(pq_p, pq_pf) ← lift $ norm_num.derive' pq_o,
pure $ ex.coeff ⟨pq_o, pq_p, pq_pf⟩ ⟨p.1 + q.1⟩
lemma mul_coeff_pf_one_mul (q : α) : 1 * q = q := one_mul q
lemma mul_coeff_pf_mul_one (p : α) : p * 1 = p := mul_one p
/--
Compute the product of two coefficients.
The returned value is of the form `ex.coeff _ (p * q)`,
with the proof of `expr.of_rat p * expr.of_rat q = expr.of_rat (p * q)`.
-/
meta def mul_coeff (p_p q_p : expr) (p q : coeff) : ring_exp_m (ex prod) :=
match p.1, q.1 with -- Special case to speed up multiplication with 1.
| ⟨1, 1, _, _⟩, _ := do
ctx ← get_context,
pq_o ← mk_mul [p_p, q_p],
pf ← mk_app_csr ``mul_coeff_pf_one_mul [q_p],
pure $ ex.coeff ⟨pq_o, q_p, pf⟩ ⟨q.1⟩
| _, ⟨1, 1, _, _⟩ := do
ctx ← get_context,
pq_o ← mk_mul [p_p, q_p],
pf ← mk_app_csr ``mul_coeff_pf_mul_one [p_p],
pure $ ex.coeff ⟨pq_o, p_p, pf⟩ ⟨p.1⟩
| _, _ := do
ctx ← get_context,
pq' ← mk_mul [p_p, q_p],
(pq_p, pq_pf) ← lift $ norm_num.derive' pq',
pure $ ex.coeff ⟨pq_p, pq_p, pq_pf⟩ ⟨p.1 * q.1⟩
end
/--
Represents the way in which two products are equal except coefficient.
This type is used in the function `add_overlap`.
In order to deal with equations of the form `a * 2 + a = 3 * a`,
the `add` function will add up overlapping products,
turning `a * 2 + a` into `a * 3`.
We need to distinguish `a * 2 + a` from `a * 2 + b` in order to do this,
and the `overlap` type carries the information on how it overlaps.
The case `none` corresponds to non-overlapping products, e.g. `a * 2 + b`;
the case `nonzero` to overlapping products adding to non-zero, e.g. `a * 2 + a`
(the `ex prod` field will then look like `a * 3` with a proof that `a * 2 + a = a * 3`);
the case `zero` to overlapping products adding to zero, e.g. `a * 2 + a * -2`.
We distinguish those two cases because in the second, the whole product reduces to `0`.
A potential extension to the tactic would also do this for the base of exponents,
e.g. to show `2^n * 2^n = 4^n`.
-/
meta inductive overlap : Type
| none : overlap
| nonzero : ex prod → overlap
| zero : ex sum → overlap
lemma add_overlap_pf {ps qs pq} (p : α) : ps + qs = pq → p * ps + p * qs = p * pq := λ pq_pf, calc
p * ps + p * qs = p * (ps + qs) : symm (mul_add _ _ _)
... = p * pq : by rw pq_pf
lemma add_overlap_pf_zero {ps qs} (p : α) : ps + qs = 0 → p * ps + p * qs = 0 := λ pq_pf, calc
p * ps + p * qs = p * (ps + qs) : symm (mul_add _ _ _)
... = p * 0 : by rw pq_pf
... = 0 : mul_zero _
/--
Given arguments `ps`, `qs` of the form `ps' * x` and `ps' * y` respectively
return `ps + qs = ps' * (x + y)` (with `x` and `y` arbitrary coefficients).
For other arguments, return `overlap.none`.
-/
meta def add_overlap : ex prod → ex prod → ring_exp_m overlap
| (ex.coeff x_i x) (ex.coeff y_i y) := do
xy@(ex.coeff _ xy_c) ← add_coeff x_i.pretty y_i.pretty x y
| lift $ fail "internal error: add_coeff should return ex.coeff",
if xy_c.1 = 0
then do
z ← ex_zero,
pure $ overlap.zero (z.set_info xy.orig xy.proof)
else pure $ overlap.nonzero xy
| (ex.prod _ _ _) (ex.coeff _ _) := pure overlap.none
| (ex.coeff _ _) (ex.prod _ _ _) := pure overlap.none
| pps@(ex.prod _ p ps) qqs@(ex.prod _ q qs) := if p.eq q
then do
pq_ol ← add_overlap ps qs,
pqs_o ← add_orig pps qqs,
match pq_ol with
| overlap.none := pure overlap.none
| (overlap.nonzero pq) := do
pqs ← ex_prod p pq,
pf ← mk_proof ``add_overlap_pf
[ps.pretty, qs.pretty, pq.pretty, p.pretty]
[pq.info],
pure $ overlap.nonzero (pqs.set_info pqs_o pf)
| (overlap.zero pq) := do
z ← ex_zero,
pf ← mk_proof ``add_overlap_pf_zero
[ps.pretty, qs.pretty, p.pretty]
[pq.info],
pure $ overlap.zero (z.set_info pqs_o pf)
end
else pure overlap.none
section addition
lemma add_pf_z_sum {ps qs qs' : α} : ps = 0 → qs = qs' → ps + qs = qs' := λ ps_pf qs_pf, calc
ps + qs = 0 + qs' : by rw [ps_pf, qs_pf]
... = qs' : zero_add _
lemma add_pf_sum_z {ps ps' qs : α} : ps = ps' → qs = 0 → ps + qs = ps' := λ ps_pf qs_pf, calc
ps + qs = ps' + 0 : by rw [ps_pf, qs_pf]
... = ps' : add_zero _
lemma add_pf_sum_overlap {pps p ps qqs q qs pq pqs : α} :
pps = p + ps → qqs = q + qs → p + q = pq → ps + qs = pqs → pps + qqs = pq + pqs := by cc
lemma add_pf_sum_overlap_zero {pps p ps qqs q qs pqs : α} :
pps = p + ps → qqs = q + qs → p + q = 0 → ps + qs = pqs → pps + qqs = pqs :=
λ pps_pf qqs_pf pq_pf pqs_pf, calc
pps + qqs = (p + ps) + (q + qs) : by rw [pps_pf, qqs_pf]
... = (p + q) + (ps + qs) : by cc
... = 0 + pqs : by rw [pq_pf, pqs_pf]
... = pqs : zero_add _
lemma add_pf_sum_lt {pps p ps qqs pqs : α} :
pps = p + ps → ps + qqs = pqs → pps + qqs = p + pqs := by cc
lemma add_pf_sum_gt {pps qqs q qs pqs : α} :
qqs = q + qs → pps + qs = pqs → pps + qqs = q + pqs := by cc
/--
Add two expressions.
* `0 + qs = 0`
* `ps + 0 = 0`
* `ps * x + ps * y = ps * (x + y)` (for `x`, `y` coefficients; uses `add_overlap`)
* `(p + ps) + (q + qs) = p + (ps + (q + qs))` (if `p.lt q`)
* `(p + ps) + (q + qs) = q + ((p + ps) + qs)` (if not `p.lt q`)
-/
meta def add : ex sum → ex sum → ring_exp_m (ex sum)
| ps@(ex.zero ps_i) qs := do
pf ← mk_proof ``add_pf_z_sum [ps.orig, qs.orig, qs.pretty] [ps.info, qs.info],
pqs_o ← add_orig ps qs,
pure $ qs.set_info pqs_o pf
| ps qs@(ex.zero qs_i) := do
pf ← mk_proof ``add_pf_sum_z [ps.orig, ps.pretty, qs.orig] [ps.info, qs.info],
pqs_o ← add_orig ps qs,
pure $ ps.set_info pqs_o pf
| pps@(ex.sum pps_i p ps) qqs@(ex.sum qqs_i q qs) := do
ol ← add_overlap p q,
ppqqs_o ← add_orig pps qqs,
match ol with
| (overlap.nonzero pq) := do
pqs ← add ps qs,
pqqs ← ex_sum pq pqs,
qqs_pf ← qqs.proof_term,
pf ← mk_proof ``add_pf_sum_overlap
[pps.orig, p.pretty, ps.pretty, qqs.orig, q.pretty, qs.pretty, pq.pretty, pqs.pretty]
[pps.info, qqs.info, pq.info, pqs.info],
pure $ pqqs.set_info ppqqs_o pf
| (overlap.zero pq) := do
pqs ← add ps qs,
pf ← mk_proof ``add_pf_sum_overlap_zero
[pps.orig, p.pretty, ps.pretty, qqs.orig, q.pretty, qs.pretty, pqs.pretty]
[pps.info, qqs.info, pq.info, pqs.info],
pure $ pqs.set_info ppqqs_o pf
| overlap.none := if p.lt q
then do
pqs ← add ps qqs,
ppqs ← ex_sum p pqs,
pf ← mk_proof ``add_pf_sum_lt
[pps.orig, p.pretty, ps.pretty, qqs.orig, pqs.pretty]
[pps.info, pqs.info],
pure $ ppqs.set_info ppqqs_o pf
else do
pqs ← add pps qs,
pqqs ← ex_sum q pqs,
pf ← mk_proof ``add_pf_sum_gt
[pps.orig, qqs.orig, q.pretty, qs.pretty, pqs.pretty]
[qqs.info, pqs.info],
pure $ pqqs.set_info ppqqs_o pf
end
end addition
section multiplication
lemma mul_pf_c_c {ps ps' qs qs' pq : α} :
ps = ps' → qs = qs' → ps' * qs' = pq → ps * qs = pq := by cc
lemma mul_pf_c_prod {ps qqs q qs pqs : α} :
qqs = q * qs → ps * qs = pqs → ps * qqs = q * pqs := by cc
lemma mul_pf_prod_c {pps p ps qs pqs : α} :
pps = p * ps → ps * qs = pqs → pps * qs = p * pqs := by cc
lemma mul_pp_pf_overlap {pps p_b ps qqs qs psqs : α} {p_e q_e : ℕ} :
pps = p_b ^ p_e * ps → qqs = p_b ^ q_e * qs →
p_b ^ (p_e + q_e) * (ps * qs) = psqs → pps * qqs = psqs
:= λ ps_pf qs_pf psqs_pf, by simp [symm psqs_pf, _root_.pow_add, ps_pf, qs_pf]; ac_refl
lemma mul_pp_pf_prod_lt {pps p ps qqs pqs : α} :
pps = p * ps → ps * qqs = pqs → pps * qqs = p * pqs := by cc
lemma mul_pp_pf_prod_gt {pps qqs q qs pqs : α} :
qqs = q * qs → pps * qs = pqs → pps * qqs = q * pqs := by cc
/--
Multiply two expressions.
* `x * y = (x * y)` (for `x`, `y` coefficients)
* `x * (q * qs) = q * (qs * x)` (for `x` coefficient)
* `(p * ps) * y = p * (ps * y)` (for `y` coefficient)
* `(p_b^p_e * ps) * (p_b^q_e * qs) = p_b^(p_e + q_e) * (ps * qs)`
(if `p_e` and `q_e` are identical except coefficient)
* `(p * ps) * (q * qs) = p * (ps * (q * qs))` (if `p.lt q`)
* `(p * ps) * (q * qs) = q * ((p * ps) * qs)` (if not `p.lt q`)
-/
meta def mul_pp : ex prod → ex prod → ring_exp_m (ex prod)
| ps@(ex.coeff _ x) qs@(ex.coeff _ y) := do
pq ← mul_coeff ps.pretty qs.pretty x y,
pq_o ← mul_orig ps qs,
pf ← mk_proof_or_refl pq.pretty ``mul_pf_c_c
[ps.orig, ps.pretty, qs.orig, qs.pretty, pq.pretty]
[ps.info, qs.info, pq.info],
pure $ pq.set_info pq_o pf
| ps@(ex.coeff _ x) qqs@(ex.prod _ q qs) := do
pqs ← mul_pp ps qs,
pqqs ← ex_prod q pqs,
pqqs_o ← mul_orig ps qqs,
pf ← mk_proof ``mul_pf_c_prod
[ps.orig, qqs.orig, q.pretty, qs.pretty, pqs.pretty]
[qqs.info, pqs.info],
pure $ pqqs.set_info pqqs_o pf
| pps@(ex.prod _ p ps) qs@(ex.coeff _ y) := do
pqs ← mul_pp ps qs,
ppqs ← ex_prod p pqs,
ppqs_o ← mul_orig pps qs,
pf ← mk_proof ``mul_pf_prod_c
[pps.orig, p.pretty, ps.pretty, qs.orig, pqs.pretty]
[pps.info, pqs.info],
pure $ ppqs.set_info ppqs_o pf
| pps@(ex.prod _ p@(ex.exp _ p_b p_e) ps) qqs@(ex.prod _ q@(ex.exp _ q_b q_e) qs) := do
ppqqs_o ← mul_orig pps qqs,
pq_ol ← in_exponent $ add_overlap p_e q_e,
match pq_ol, p_b.eq q_b with
| (overlap.nonzero pq_e), tt := do
psqs ← mul_pp ps qs,
pq ← ex_exp p_b pq_e,
ppsqqs ← ex_prod pq psqs,
pf ← mk_proof ``mul_pp_pf_overlap
[pps.orig, p_b.pretty, ps.pretty, qqs.orig, qs.pretty, ppsqqs.pretty, p_e.pretty, q_e.pretty]
[pps.info, qqs.info, ppsqqs.info],
pure $ ppsqqs.set_info ppqqs_o pf
| _, _ := if p.lt q then do
pqs ← mul_pp ps qqs,
ppqs ← ex_prod p pqs,
pf ← mk_proof ``mul_pp_pf_prod_lt
[pps.orig, p.pretty, ps.pretty, qqs.orig, pqs.pretty]
[pps.info, pqs.info],
pure $ ppqs.set_info ppqqs_o pf
else do
pqs ← mul_pp pps qs,
pqqs ← ex_prod q pqs,
pf ← mk_proof ``mul_pp_pf_prod_gt
[pps.orig, qqs.orig, q.pretty, qs.pretty, pqs.pretty]
[qqs.info, pqs.info],
pure $ pqqs.set_info ppqqs_o pf
end
lemma mul_p_pf_zero {ps qs : α} : ps = 0 → ps * qs = 0 :=
λ ps_pf, by rw [ps_pf, zero_mul]
lemma mul_p_pf_sum {pps p ps qs ppsqs : α} : pps = p + ps →
p * qs + ps * qs = ppsqs → pps * qs = ppsqs := λ pps_pf ppsqs_pf, calc
pps * qs = (p + ps) * qs : by rw [pps_pf]
... = p * qs + ps * qs : add_mul _ _ _
... = ppsqs : ppsqs_pf
/--
Multiply two expressions.
* `0 * qs = 0`
* `(p + ps) * qs = (p * qs) + (ps * qs)`
-/
meta def mul_p : ex sum → ex prod → ring_exp_m (ex sum)
| ps@(ex.zero ps_i) qs := do
z ← ex_zero,
z_o ← mul_orig ps qs,
pf ← mk_proof ``mul_p_pf_zero [ps.orig, qs.orig] [ps.info],
pure $ z.set_info z_o pf
| pps@(ex.sum pps_i p ps) qs := do
pqs ← mul_pp p qs >>= prod_to_sum,
psqs ← mul_p ps qs,
ppsqs ← add pqs psqs,
pps_pf ← pps.proof_term,
ppsqs_o ← mul_orig pps qs,
ppsqs_pf ← ppsqs.proof_term,
pf ← mk_proof ``mul_p_pf_sum
[pps.orig, p.pretty, ps.pretty, qs.orig, ppsqs.pretty]
[pps.info, ppsqs.info],
pure $ ppsqs.set_info ppsqs_o pf
lemma mul_pf_zero {ps qs : α} : qs = 0 → ps * qs = 0 :=
λ qs_pf, by rw [qs_pf, mul_zero]
lemma mul_pf_sum {ps qqs q qs psqqs : α} : qqs = q + qs → ps * q + ps * qs = psqqs →
ps * qqs = psqqs := λ qs_pf psqqs_pf, calc
ps * qqs = ps * (q + qs) : by rw [qs_pf]
... = ps * q + ps * qs : mul_add _ _ _
... = psqqs : psqqs_pf
/--
Multiply two expressions.
* `ps * 0 = 0`
* `ps * (q + qs) = (ps * q) + (ps * qs)`
-/
meta def mul : ex sum → ex sum → ring_exp_m (ex sum)
| ps qs@(ex.zero qs_i) := do
z ← ex_zero,
z_o ← mul_orig ps qs,
pf ← mk_proof ``mul_pf_zero [ps.orig, qs.orig] [qs.info],
pure $ z.set_info z_o pf
| ps qqs@(ex.sum qqs_i q qs) := do
psq ← mul_p ps q,
psqs ← mul ps qs,
psqqs ← add psq psqs,
psqqs_o ← mul_orig ps qqs,
pf ← mk_proof ``mul_pf_sum
[ps.orig, qqs.orig, q.orig, qs.orig, psqqs.pretty]
[qqs.info, psqqs.info],
pure $ psqqs.set_info psqqs_o pf
end multiplication
section exponentiation
lemma pow_e_pf_exp {pps p : α} {ps qs psqs : ℕ} :
pps = p ^ ps → ps * qs = psqs → pps ^ qs = p ^ psqs :=
λ pps_pf psqs_pf, calc
pps ^ qs = (p ^ ps) ^ qs : by rw [pps_pf]
... = p ^ (ps * qs) : symm (pow_mul _ _ _)
... = p ^ psqs : by rw [psqs_pf]
/--
Exponentiate two expressions.
* `(p ^ ps) ^ qs = p ^ (ps * qs)`
-/
meta def pow_e : ex exp → ex prod → ring_exp_m (ex exp)
| pps@(ex.exp pps_i p ps) qs := do
psqs ← in_exponent $ mul_pp ps qs,
ppsqs ← ex_exp p psqs,
ppsqs_o ← pow_orig pps qs,
pf ← mk_proof ``pow_e_pf_exp
[pps.orig, p.pretty, ps.pretty, qs.orig, psqs.pretty]
[pps.info, psqs.info],
pure $ ppsqs.set_info ppsqs_o pf
lemma pow_pp_pf_one {ps : α} {qs : ℕ} : ps = 1 → ps ^ qs = 1 :=
λ ps_pf, by rw [ps_pf, _root_.one_pow]
lemma pow_pp_pf_c {ps ps' pqs : α} {qs qs' : ℕ} :
ps = ps' → qs = qs' → ps' ^ qs' = pqs → ps ^ qs = pqs * 1 :=
by simp; cc
lemma pow_pp_pf_prod {pps p ps pqs psqs : α} {qs : ℕ} : pps = p * ps →
p ^ qs = pqs → ps ^ qs = psqs → pps ^ qs = pqs * psqs :=
λ pps_pf pqs_pf psqs_pf, calc
pps ^ qs = (p * ps) ^ qs : by rw [pps_pf]
... = p ^ qs * ps ^ qs : mul_pow _ _ _
... = pqs * psqs : by rw [pqs_pf, psqs_pf]
/--
Exponentiate two expressions.
* `1 ^ qs = 1`
* `x ^ qs = x ^ qs` (for `x` coefficient)
* `(p * ps) ^ qs = p ^ qs + ps ^ qs`
-/
meta def pow_pp : ex prod → ex prod → ring_exp_m (ex prod)
| ps@(ex.coeff ps_i ⟨⟨1, 1, _, _⟩⟩) qs := do
o ← ex_one,
o_o ← pow_orig ps qs,
pf ← mk_proof ``pow_pp_pf_one [ps.orig, qs.orig] [ps.info],
pure $ o.set_info o_o pf
| ps@(ex.coeff ps_i x) qs := do
ps'' ← pure ps >>= prod_to_sum >>= ex_sum_b,
pqs ← ex_exp ps'' qs,
pqs_o ← pow_orig ps qs,
pf ← mk_proof_or_refl pqs.pretty ``pow_pp_pf_c
[ps.orig, ps.pretty, pqs.pretty, qs.orig, qs.pretty]
[ps.info, qs.info, pqs.info],
pqs' ← exp_to_prod pqs,
pure $ pqs'.set_info pqs_o pf
| pps@(ex.prod pps_i p ps) qs := do
pqs ← pow_e p qs,
psqs ← pow_pp ps qs,
ppsqs ← ex_prod pqs psqs,
ppsqs_o ← pow_orig pps qs,
pf ← mk_proof ``pow_pp_pf_prod
[pps.orig, p.pretty, ps.pretty, pqs.pretty, psqs.pretty, qs.orig]
[pps.info, pqs.info, psqs.info],
pure $ ppsqs.set_info ppsqs_o pf
lemma pow_p_pf_one {ps ps' : α} {qs : ℕ} : ps = ps' → qs = succ zero → ps ^ qs = ps' :=
λ ps_pf qs_pf, calc
ps ^ qs = ps' ^ 1 : by rw [ps_pf, qs_pf]
... = ps' : pow_one _
lemma pow_p_pf_zero {ps : α} {qs qs' : ℕ} : ps = 0 → qs = succ qs' → ps ^ qs = 0 :=
λ ps_pf qs_pf, calc
ps ^ qs = 0 ^ (succ qs') : by rw [ps_pf, qs_pf]
... = 0 : zero_pow (succ_pos qs')
lemma pow_p_pf_succ {ps pqqs : α} {qs qs' : ℕ} :
qs = succ qs' → ps * ps ^ qs' = pqqs → ps ^ qs = pqqs :=
λ qs_pf pqqs_pf, calc
ps ^ qs = ps ^ succ qs' : by rw [qs_pf]
... = ps * ps ^ qs' : pow_succ _ _
... = pqqs : by rw [pqqs_pf]
lemma pow_p_pf_singleton {pps p pqs : α} {qs : ℕ} :
pps = p + 0 → p ^ qs = pqs → pps ^ qs = pqs :=
λ pps_pf pqs_pf, by rw [pps_pf, add_zero, pqs_pf]
lemma pow_p_pf_cons {ps ps' : α} {qs qs' : ℕ} :
ps = ps' → qs = qs' → ps ^ qs = ps' ^ qs' := by cc
/--
Exponentiate two expressions.
* `ps ^ 1 = ps`
* `0 ^ qs = 0` (note that this is handled *after* `ps ^ 0 = 1`)
* `(p + 0) ^ qs = p ^ qs`
* `ps ^ (qs + 1) = ps * ps ^ qs` (note that this is handled *after* `p + 0 ^ qs = p ^ qs`)
* `ps ^ qs = ps ^ qs` (otherwise)
-/
meta def pow_p : ex sum → ex prod → ring_exp_m (ex sum)
| ps qs@(ex.coeff qs_i ⟨⟨1, 1, _, _⟩⟩) := do
ps_o ← pow_orig ps qs,
pf ← mk_proof ``pow_p_pf_one [ps.orig, ps.pretty, qs.orig] [ps.info, qs.info],
pure $ ps.set_info ps_o pf
| ps@(ex.zero ps_i) qs@(ex.coeff qs_i ⟨⟨succ y, 1, _, _⟩⟩) := do
ctx ← get_context,
z ← ex_zero,
qs_pred ← lift $ expr.of_nat ctx.info_e.α y,
pf ← mk_proof ``pow_p_pf_zero [ps.orig, qs.orig, qs_pred] [ps.info, qs.info],
z_o ← pow_orig ps qs,
pure $ z.set_info z_o pf
| pps@(ex.sum pps_i p (ex.zero _)) qqs := do
pqs ← pow_pp p qqs,
pqs_o ← pow_orig pps qqs,
pf ← mk_proof ``pow_p_pf_singleton
[pps.orig, p.pretty, pqs.pretty, qqs.orig]
[pps.info, pqs.info],
prod_to_sum $ pqs.set_info pqs_o pf
| ps qs@(ex.coeff qs_i ⟨⟨int.of_nat (succ n), 1, den_pos, _⟩⟩) := do
qs' ← in_exponent $ ex_coeff ⟨int.of_nat n, 1, den_pos, coprime_one_right _⟩,
pqs ← pow_p ps qs',
pqqs ← mul ps pqs,
pqqs_o ← pow_orig ps qs,
pf ← mk_proof ``pow_p_pf_succ
[ps.orig, pqqs.pretty, qs.orig, qs'.pretty]
[qs.info, pqqs.info],
pure $ pqqs.set_info pqqs_o pf
| pps qqs := do -- fallback: treat them as atoms
pps' ← ex_sum_b pps,
psqs ← ex_exp pps' qqs,
psqs_o ← pow_orig pps qqs,
pf ← mk_proof_or_refl psqs.pretty ``pow_p_pf_cons
[pps.orig, pps.pretty, qqs.orig, qqs.pretty]
[pps.info, qqs.info],
exp_to_prod (psqs.set_info psqs_o pf) >>= prod_to_sum
lemma pow_pf_zero {ps : α} {qs : ℕ} : qs = 0 → ps ^ qs = 1 := λ qs_pf, calc
ps ^ qs = ps ^ 0 : by rw [qs_pf]
... = 1 : pow_zero _
lemma pow_pf_sum {ps psqqs : α} {qqs q qs : ℕ} : qqs = q + qs →
ps ^ q * ps ^ qs = psqqs → ps ^ qqs = psqqs := λ qqs_pf psqqs_pf, calc
ps ^ qqs = ps ^ (q + qs) : by rw [qqs_pf]
... = ps ^ q * ps ^ qs : pow_add _ _ _
... = psqqs : psqqs_pf
/--
Exponentiate two expressions.
* `ps ^ 0 = 1`
* `ps ^ (q + qs) = ps ^ q * ps ^ qs`
-/
meta def pow : ex sum → ex sum → ring_exp_m (ex sum)
| ps qs@(ex.zero qs_i) := do
o ← ex_one,
o_o ← pow_orig ps qs,
pf ← mk_proof ``pow_pf_zero [ps.orig, qs.orig] [qs.info],
prod_to_sum $ o.set_info o_o pf
| ps qqs@(ex.sum qqs_i q qs) := do
psq ← pow_p ps q,
psqs ← pow ps qs,
psqqs ← mul psq psqs,
psqqs_o ← pow_orig ps qqs,
pf ← mk_proof ``pow_pf_sum
[ps.orig, psqqs.pretty, qqs.orig, q.pretty, qs.pretty]
[qqs.info, psqqs.info],
pure $ psqqs.set_info psqqs_o pf
end exponentiation
lemma simple_pf_sum_zero {p p' : α} : p = p' → p + 0 = p' := by simp
lemma simple_pf_prod_one {p p' : α} : p = p' → p * 1 = p' := by simp
lemma simple_pf_prod_neg_one {α} [ring α] {p p' : α} : p = p' → p * -1 = - p' := by simp
lemma simple_pf_var_one (p : α) : p ^ 1 = p := by simp
lemma simple_pf_exp_one {p p' : α} : p = p' → p ^ 1 = p' := by simp
/--
Give a simpler, more human-readable representation of the normalized expression.
Normalized expressions might have the form `a^1 * 1 + 0`,
since the dummy operations reduce special cases in pattern-matching.
Humans prefer to read `a` instead.
This tactic gets rid of the dummy additions, multiplications and exponentiations.
-/
meta def ex.simple : Π {et : ex_type}, ex et → ring_exp_m (expr × expr)
| sum pps@(ex.sum pps_i p (ex.zero _)) := do
(p_p, p_pf) ← p.simple,
prod.mk p_p <$> mk_app_csr ``simple_pf_sum_zero [p.pretty, p_p, p_pf]
| sum (ex.sum pps_i p ps) := do
(p_p, p_pf) ← p.simple,
(ps_p, ps_pf) ← ps.simple,
prod.mk
<$> mk_add [p_p, ps_p]
<*> mk_app_csr ``sum_congr [p.pretty, p_p, ps.pretty, ps_p, p_pf, ps_pf]
| prod (ex.prod pps_i p (ex.coeff _ ⟨⟨1, 1, _, _⟩⟩)) := do
(p_p, p_pf) ← p.simple,
prod.mk p_p <$> mk_app_csr ``simple_pf_prod_one [p.pretty, p_p, p_pf]
| prod pps@(ex.prod pps_i p (ex.coeff _ ⟨⟨-1, 1, _, _⟩⟩)) := do
ctx ← get_context,
match ctx.info_b.ring_instance with
| none := prod.mk pps.pretty <$> pps.proof_term
| (some ringi) := do
(p_p, p_pf) ← p.simple,
prod.mk
<$> lift (mk_app ``has_neg.neg [p_p])
<*> mk_app_class ``simple_pf_prod_neg_one ringi [p.pretty, p_p, p_pf]
end
| prod (ex.prod pps_i p ps) := do
(p_p, p_pf) ← p.simple,
(ps_p, ps_pf) ← ps.simple,
prod.mk
<$> mk_mul [p_p, ps_p]
<*> mk_app_csr ``prod_congr [p.pretty, p_p, ps.pretty, ps_p, p_pf, ps_pf]
| base (ex.sum_b pps_i ps) := ps.simple
| exp (ex.exp pps_i p (ex.coeff _ ⟨⟨1, 1, _, _⟩⟩)) := do
(p_p, p_pf) ← p.simple,
prod.mk p_p <$> mk_app_csr ``simple_pf_exp_one [p.pretty, p_p, p_pf]
| exp (ex.exp pps_i p ps) := do
(p_p, p_pf) ← p.simple,
(ps_p, ps_pf) ← in_exponent $ ps.simple,
prod.mk
<$> mk_pow [p_p, ps_p]
<*> mk_app_csr ``exp_congr [p.pretty, p_p, ps.pretty, ps_p, p_pf, ps_pf]
| et ps := prod.mk ps.pretty <$> ps.proof_term
/--
Performs a lookup of the atom `a` in the list of known atoms,
or allocates a new one.
If `a` is not definitionally equal to any of the list's entries,
a new atom is appended to the list and returned.
The index of this atom is kept track of in the second inductive argument.
This function is mostly useful in `resolve_atom`,
which updates the state with the new list of atoms.
-/
meta def resolve_atom_aux (a : expr) : list atom → ℕ → ring_exp_m (atom × list atom)
| [] n := let atm : atom := ⟨a, n⟩ in pure (atm, [atm])
| bas@(b :: as) n := do
ctx ← get_context,
(lift $ is_def_eq a b.value ctx.transp >> pure (b , bas)) <|> do
(atm, as') ← resolve_atom_aux as (succ n),
pure (atm, b :: as')
/--
Convert the expression to an atom:
either look up a definitionally equal atom,
or allocate it as a new atom.
You probably want to use `eval_base` if `eval` doesn't work
instead of directly calling `resolve_atom`,
since `eval_base` can also handle numerals.
-/
meta def resolve_atom (a : expr) : ring_exp_m atom := do
atoms ← reader_t.lift $ state_t.get,
(atm, atoms') ← resolve_atom_aux a atoms 0,
reader_t.lift $ state_t.put atoms',
pure atm
/--
Treat the expression atomically: as a coefficient or atom.
Handles cases where `eval` cannot treat the expression as a known operation
because it is just a number or single variable.
-/
meta def eval_base (ps : expr) : ring_exp_m (ex sum) :=
match ps.to_rat with
| some ⟨0, 1, _, _⟩ := ex_zero
| some x := ex_coeff x >>= prod_to_sum
| none := do
a ← resolve_atom ps,
atom_to_sum a
end
lemma negate_pf {α} [ring α] {ps ps' : α} : (-1) * ps = ps' → -ps = ps' := by simp
/--
Negate an expression by multiplying with `-1`.
Only works if there is a `ring` instance; otherwise it will `fail`.
-/
meta def negate (ps : ex sum) : ring_exp_m (ex sum) := do
ctx ← get_context,
match ctx.info_b.ring_instance with
| none := lift $ fail "internal error: negate called in semiring"
| (some ring_instance) := do
minus_one ← ex_coeff (-1) >>= prod_to_sum,
ps' ← mul minus_one ps,
ps_pf ← ps'.proof_term,
pf ← mk_app_class ``negate_pf ring_instance [ps.orig, ps'.pretty, ps_pf],
ps'_o ← lift $ mk_app ``has_neg.neg [ps.orig],
pure $ ps'.set_info ps'_o pf
end
lemma inverse_pf {α} [division_ring α] {ps ps_u ps_p e' e'' : α} :
ps = ps_u → ps_u = ps_p → ps_p ⁻¹ = e' → e' = e'' → ps ⁻¹ = e'' :=
by cc
/--
Invert an expression by simplifying, applying `has_inv.inv` and treating the result as an atom.
Only works if there is a `division_ring` instance; otherwise it will `fail`.
-/
meta def inverse (ps : ex sum) : ring_exp_m (ex sum) := do
ctx ← get_context,
dri ← match ctx.info_b.dr_instance with
| none := lift $ fail "division is only supported in a division ring"
| (some dri) := pure dri
end,
(ps_simple, ps_simple_pf) ← ps.simple,
e ← lift $ mk_app ``has_inv.inv [ps_simple],
(e', e_pf) ← lift (norm_num.derive e) <|> ((λ e_pf, (e, e_pf)) <$> lift (mk_eq_refl e)),
e'' ← eval_base e',
ps_pf ← ps.proof_term,
e''_pf ← e''.proof_term,
pf ← mk_app_class ``inverse_pf dri
[ ps.orig, ps.pretty, ps_simple, e', e''.pretty,
ps_pf, ps_simple_pf, e_pf, e''_pf],
e''_o ← lift $ mk_app ``has_inv.inv [ps.orig],
pure $ e''.set_info e''_o pf
lemma sub_pf {α} [ring α] {ps qs psqs : α} : ps + -qs = psqs → ps - qs = psqs := id
lemma div_pf {α} [division_ring α] {ps qs psqs : α} : ps * qs⁻¹ = psqs → ps / qs = psqs := id
end operations
section wiring
/-!
### `wiring` section
This section deals with going from `expr` to `ex` and back.
The main attraction is `eval`, which uses `add`, `mul`, etc.
to calculate an `ex` from a given `expr`.
Other functions use `ex`es to produce `expr`s together with a proof,
or produce the context to run `ring_exp_m` from an `expr`.
-/
open tactic
open ex_type
/--
Compute a normalized form (of type `ex`) from an expression (of type `expr`).
This is the main driver of the `ring_exp` tactic,
calling out to `add`, `mul`, `pow`, etc. to parse the `expr`.
-/
meta def eval : expr → ring_exp_m (ex sum)
| e@`(%%ps + %%qs) := do
ps' ← eval ps,
qs' ← eval qs,
add ps' qs'
| e@`(%%ps - %%qs) := (do
ctx ← get_context,
ri ← match ctx.info_b.ring_instance with
| none := lift $ fail "subtraction is not directly supported in a semiring"
| (some ri) := pure ri
end,
ps' ← eval ps,
qs' ← eval qs >>= negate,
psqs ← add ps' qs',
psqs_pf ← psqs.proof_term,
pf ← mk_app_class ``sub_pf ri [ps, qs, psqs.pretty, psqs_pf],
pure (psqs.set_info e pf)) <|> eval_base e
| e@`(- %%ps) := do
ps' ← eval ps,
negate ps' <|> eval_base e
| e@`(%%ps * %%qs) := do
ps' ← eval ps,
qs' ← eval qs,
mul ps' qs'
| e@`(has_inv.inv %%ps) := do
ps' ← eval ps,
inverse ps' <|> eval_base e
| e@`(%%ps / %%qs) := do
ctx ← get_context,
dri ← match ctx.info_b.dr_instance with
| none := lift $ fail "division is only directly supported in a division ring"
| (some dri) := pure dri
end,
ps' ← eval ps,
qs' ← eval qs,
(do qs'' ← inverse qs',
psqs ← mul ps' qs'',
psqs_pf ← psqs.proof_term,
pf ← mk_app_class ``div_pf dri [ps, qs, psqs.pretty, psqs_pf],
pure (psqs.set_info e pf)) <|> eval_base e
| e@`(@has_pow.pow _ _ %%hp_instance %%ps %%qs) := do
ps' ← eval ps,
qs' ← in_exponent $ eval qs,
psqs ← pow ps' qs',
psqs_pf ← psqs.proof_term,
(do has_pow_pf ← match hp_instance with
| `(monoid.has_pow) := lift $ mk_eq_refl e
| `(nat.has_pow) := lift $ mk_app ``nat.pow_eq_pow [ps, qs] >>= mk_eq_symm
| _ := lift $ fail "has_pow instance must be nat.has_pow or monoid.has_pow"
end,
pf ← lift $ mk_eq_trans has_pow_pf psqs_pf,
pure $ psqs.set_info e pf) <|> eval_base e
| ps := eval_base ps
/--
Run `eval` on the expression and return the result together with normalization proof.
See also `eval_simple` if you want something that behaves like `norm_num`.
-/
meta def eval_with_proof (e : expr) : ring_exp_m (ex sum × expr) := do
e' ← eval e,
prod.mk e' <$> e'.proof_term
/--
Run `eval` on the expression and simplify the result.
Returns a simplified normalized expression, together with an equality proof.
See also `eval_with_proof` if you just want to check the equality of two expressions.
-/
meta def eval_simple (e : expr) : ring_exp_m (expr × expr) := do
(complicated, complicated_pf) ← eval_with_proof e,
(simple, simple_pf) ← complicated.simple,
prod.mk simple <$> lift (mk_eq_trans complicated_pf simple_pf)
/-- Compute the `eval_info` for a given type `α`. -/
meta def make_eval_info (α : expr) : tactic eval_info := do
u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
csr_instance ← mk_app ``comm_semiring [α] >>= mk_instance,
ring_instance ← (some <$> (mk_app ``ring [α] >>= mk_instance) <|> pure none),
dr_instance ← (some <$> (mk_app ``division_ring [α] >>= mk_instance) <|> pure none),
ha_instance ← mk_app ``has_add [α] >>= mk_instance,
hm_instance ← mk_app ``has_mul [α] >>= mk_instance,
hp_instance ← mk_mapp ``monoid.has_pow [some α, none],
z ← mk_mapp ``has_zero.zero [α, none],
o ← mk_mapp ``has_one.one [α, none],
pure ⟨α, u, csr_instance, ha_instance, hm_instance, hp_instance, ring_instance, dr_instance, z, o⟩
/-- Use `e` to build the context for running `mx`. -/
meta def run_ring_exp {α} (transp : transparency) (e : expr) (mx : ring_exp_m α) : tactic α := do
info_b ← infer_type e >>= make_eval_info,
info_e ← mk_const ``nat >>= make_eval_info,
(λ x : (_ × _), x.1) <$> (state_t.run (reader_t.run mx ⟨info_b, info_e, transp⟩) [])
/-- Repeatedly apply `eval_simple` on (sub)expressions. -/
meta def normalize (transp : transparency) (e : expr) : tactic (expr × expr) := do
(_, e', pf') ← ext_simplify_core () {}
simp_lemmas.mk (λ _, failed) (λ _ _ _ _ e, do
(e'', pf) ← run_ring_exp transp e $ eval_simple e,
guard (¬ e'' =ₐ e),
return ((), e'', some pf, ff))
(λ _ _ _ _ _, failed) `eq e,
pure (e', pf')
end wiring
end tactic.ring_exp
namespace tactic.interactive
open interactive interactive.types lean.parser tactic tactic.ring_exp
local postfix `?`:9001 := optional
/--
Tactic for solving equations of *commutative* (semi)rings,
allowing variables in the exponent.
This version of `ring_exp` fails if the target is not an equality.
The variant `ring_exp_eq!` will use a more aggressive reducibility setting
to determine equality of atoms.
-/
meta def ring_exp_eq (red : parse (tk "!")?) : tactic unit := do
`(eq %%ps %%qs) ← target >>= whnf,
let transp := if red.is_some then semireducible else reducible,
((ps', ps_pf), (qs', qs_pf)) ← run_ring_exp transp ps $
prod.mk <$> eval_with_proof ps <*> eval_with_proof qs,
if ps'.eq qs'
then do
qs_pf_inv ← mk_eq_symm qs_pf,
pf ← mk_eq_trans ps_pf qs_pf_inv,
tactic.interactive.exact ``(%%pf)
else fail "ring_exp failed to prove equality"
/--
Tactic for evaluating expressions in *commutative* (semi)rings, allowing for variables in the
exponent.
This tactic extends `ring`: it should solve every goal that `ring` can solve.
Additionally, it knows how to evaluate expressions with complicated exponents
(where `ring` only understands constant exponents).
The variants `ring_exp!` and `ring_exp_eq!` use a more aggessive reducibility setting to determine
equality of atoms.
For example:
```lean
example (n : ℕ) (m : ℤ) : 2^(n+1) * m = 2 * 2^n * m := by ring_exp
example (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) = (a^2 + b^2 + a * b + b * a) * (a + b)^n := by ring_exp
example (x y : ℕ) : x + id y = y + id x := by ring_exp!
```
-/
meta def ring_exp (red : parse (tk "!")?) (loc : parse location) : tactic unit :=
match loc with
| interactive.loc.ns [none] := ring_exp_eq red
| _ := failed
end <|>
do ns ← loc.get_locals,
let transp := if red.is_some then semireducible else reducible,
tt ← tactic.replace_at (normalize transp) ns loc.include_goal
| fail "ring_exp failed to simplify",
when loc.include_goal $ try tactic.reflexivity
add_tactic_doc
{ name := "ring_exp",
category := doc_category.tactic,
decl_names := [`tactic.interactive.ring_exp],
tags := ["arithmetic", "simplification", "decision procedure"] }
end tactic.interactive
namespace conv.interactive
open conv interactive
open tactic tactic.interactive (ring_exp_eq)
open tactic.ring_exp (normalize)
local postfix `?`:9001 := optional
/--
Normalises expressions in commutative (semi-)rings inside of a `conv` block using the tactic `ring_exp`.
-/
meta def ring_exp (red : parse (lean.parser.tk "!")?) : conv unit :=
let transp := if red.is_some then semireducible else reducible in
discharge_eq_lhs (ring_exp_eq red)
<|> replace_lhs (normalize transp)
<|> fail "ring_exp failed to simplify"
end conv.interactive
|
e2ace79126f0c258cd65bec0cffc5bbca77e9883 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/order/hom/order.lean | dd5786296ba29c482906d985ae9f9833a3a0f1cd | [
"Apache-2.0"
] | permissive | Vierkantor/mathlib | 0ea59ac32a3a43c93c44d70f441c4ee810ccceca | 83bc3b9ce9b13910b57bda6b56222495ebd31c2f | refs/heads/master | 1,658,323,012,449 | 1,652,256,003,000 | 1,652,256,003,000 | 209,296,341 | 0 | 1 | Apache-2.0 | 1,568,807,655,000 | 1,568,807,655,000 | null | UTF-8 | Lean | false | false | 5,051 | lean | /-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Anne Baanen
-/
import logic.function.iterate
import order.galois_connection
import order.hom.basic
/-!
# Lattice structure on order homomorphisms
This file defines the lattice structure on order homomorphisms, which are bundled
monotone functions.
## Main definitions
* `order_hom.complete_lattice`: if `β` is a complete lattice, so is `α →o β`
## Tags
monotone map, bundled morphism
-/
namespace order_hom
variables {α β : Type*}
section preorder
variables [preorder α]
@[simps]
instance [semilattice_sup β] : has_sup (α →o β) :=
{ sup := λ f g, ⟨λ a, f a ⊔ g a, f.mono.sup g.mono⟩ }
instance [semilattice_sup β] : semilattice_sup (α →o β) :=
{ sup := has_sup.sup,
le_sup_left := λ a b x, le_sup_left,
le_sup_right := λ a b x, le_sup_right,
sup_le := λ a b c h₀ h₁ x, sup_le (h₀ x) (h₁ x),
.. (_ : partial_order (α →o β)) }
@[simps]
instance [semilattice_inf β] : has_inf (α →o β) :=
{ inf := λ f g, ⟨λ a, f a ⊓ g a, f.mono.inf g.mono⟩ }
instance [semilattice_inf β] : semilattice_inf (α →o β) :=
{ inf := (⊓),
.. (_ : partial_order (α →o β)),
.. (dual_iso α β).symm.to_galois_insertion.lift_semilattice_inf }
instance [lattice β] : lattice (α →o β) :=
{ .. (_ : semilattice_sup (α →o β)),
.. (_ : semilattice_inf (α →o β)) }
@[simps]
instance [preorder β] [order_bot β] : has_bot (α →o β) :=
{ bot := const α ⊥ }
instance [preorder β] [order_bot β] : order_bot (α →o β) :=
{ bot := ⊥,
bot_le := λ a x, bot_le }
@[simps]
instance [preorder β] [order_top β] : has_top (α →o β) :=
{ top := const α ⊤ }
instance [preorder β] [order_top β] : order_top (α →o β) :=
{ top := ⊤,
le_top := λ a x, le_top }
instance [complete_lattice β] : has_Inf (α →o β) :=
{ Inf := λ s, ⟨λ x, ⨅ f ∈ s, (f : _) x, λ x y h, infi₂_mono $ λ f _, f.mono h⟩ }
@[simp] lemma Inf_apply [complete_lattice β] (s : set (α →o β)) (x : α) :
Inf s x = ⨅ f ∈ s, (f : _) x := rfl
lemma infi_apply {ι : Sort*} [complete_lattice β] (f : ι → α →o β) (x : α) :
(⨅ i, f i) x = ⨅ i, f i x :=
(Inf_apply _ _).trans infi_range
@[simp, norm_cast] lemma coe_infi {ι : Sort*} [complete_lattice β] (f : ι → α →o β) :
((⨅ i, f i : α →o β) : α → β) = ⨅ i, f i :=
funext $ λ x, (infi_apply f x).trans (@_root_.infi_apply _ _ _ _ (λ i, f i) _).symm
instance [complete_lattice β] : has_Sup (α →o β) :=
{ Sup := λ s, ⟨λ x, ⨆ f ∈ s, (f : _) x, λ x y h, supr₂_mono (λ f _, f.mono h)⟩ }
@[simp] lemma Sup_apply [complete_lattice β] (s : set (α →o β)) (x : α) :
Sup s x = ⨆ f ∈ s, (f : _) x := rfl
lemma supr_apply {ι : Sort*} [complete_lattice β] (f : ι → α →o β) (x : α) :
(⨆ i, f i) x = ⨆ i, f i x :=
(Sup_apply _ _).trans supr_range
@[simp, norm_cast] lemma coe_supr {ι : Sort*} [complete_lattice β] (f : ι → α →o β) :
((⨆ i, f i : α →o β) : α → β) = ⨆ i, f i :=
funext $ λ x, (supr_apply f x).trans (@_root_.supr_apply _ _ _ _ (λ i, f i) _).symm
instance [complete_lattice β] : complete_lattice (α →o β) :=
{ Sup := Sup,
le_Sup := λ s f hf x, le_supr_of_le f (le_supr _ hf),
Sup_le := λ s f hf x, supr₂_le (λ g hg, hf g hg x),
Inf := Inf,
le_Inf := λ s f hf x, le_infi₂ (λ g hg, hf g hg x),
Inf_le := λ s f hf x, infi_le_of_le f (infi_le _ hf),
.. (_ : lattice (α →o β)),
.. order_hom.order_top,
.. order_hom.order_bot }
lemma iterate_sup_le_sup_iff {α : Type*} [semilattice_sup α] (f : α →o α) :
(∀ n₁ n₂ a₁ a₂, f^[n₁ + n₂] (a₁ ⊔ a₂) ≤ (f^[n₁] a₁) ⊔ (f^[n₂] a₂)) ↔
(∀ a₁ a₂, f (a₁ ⊔ a₂) ≤ (f a₁) ⊔ a₂) :=
begin
split; intros h,
{ exact h 1 0, },
{ intros n₁ n₂ a₁ a₂, have h' : ∀ n a₁ a₂, f^[n] (a₁ ⊔ a₂) ≤ (f^[n] a₁) ⊔ a₂,
{ intros n, induction n with n ih; intros a₁ a₂,
{ refl, },
{ calc f^[n + 1] (a₁ ⊔ a₂) = (f^[n] (f (a₁ ⊔ a₂))) : function.iterate_succ_apply f n _
... ≤ (f^[n] ((f a₁) ⊔ a₂)) : f.mono.iterate n (h a₁ a₂)
... ≤ (f^[n] (f a₁)) ⊔ a₂ : ih _ _
... = (f^[n + 1] a₁) ⊔ a₂ : by rw ← function.iterate_succ_apply, }, },
calc f^[n₁ + n₂] (a₁ ⊔ a₂) = (f^[n₁] (f^[n₂] (a₁ ⊔ a₂))) : function.iterate_add_apply f n₁ n₂ _
... = (f^[n₁] (f^[n₂] (a₂ ⊔ a₁))) : by rw sup_comm
... ≤ (f^[n₁] ((f^[n₂] a₂) ⊔ a₁)) : f.mono.iterate n₁ (h' n₂ _ _)
... = (f^[n₁] (a₁ ⊔ (f^[n₂] a₂))) : by rw sup_comm
... ≤ (f^[n₁] a₁) ⊔ (f^[n₂] a₂) : h' n₁ a₁ _, },
end
end preorder
end order_hom
|
3acf98dff38dc7739e2efd7f5adec87b61742fe8 | 4fa161becb8ce7378a709f5992a594764699e268 | /test/linarith.lean | 47c045a6912ecc08876d0aaa12a754e67b51705a | [
"Apache-2.0"
] | permissive | laughinggas/mathlib | e4aa4565ae34e46e834434284cb26bd9d67bc373 | 86dcd5cda7a5017c8b3c8876c89a510a19d49aad | refs/heads/master | 1,669,496,232,688 | 1,592,831,995,000 | 1,592,831,995,000 | 274,155,979 | 0 | 0 | Apache-2.0 | 1,592,835,190,000 | 1,592,835,189,000 | null | UTF-8 | Lean | false | false | 8,457 | lean | import tactic.linarith
example (e b c a v0 v1 : ℚ) (h1 : v0 = 5*a) (h2 : v1 = 3*b) (h3 : v0 + v1 + c = 10) :
v0 + 5 + (v1 - 3) + (c - 2) = 10 :=
by linarith
example (u v r s t : ℚ) (h : 0 < u*(t*v + t*r + s)) : 0 < (t*(r + v) + s)*3*u :=
by linarith
example (A B : ℚ) (h : 0 < A * B) : 0 < 8*A*B :=
begin
linarith
end
example (A B : ℚ) (h : 0 < A * B) : 0 < A*8*B :=
begin
linarith
end
example (A B : ℚ) (h : 0 < A * B) : 0 < A*B/8 :=
begin
linarith
end
example (A B : ℚ) (h : 0 < A * B) : 0 < A/8*B :=
begin
linarith
end
example (ε : ℚ) (h1 : ε > 0) : ε / 2 + ε / 3 + ε / 7 < ε :=
by linarith
example (x y z : ℚ) (h1 : 2*x < 3*y) (h2 : -4*x + z/2 < 0)
(h3 : 12*y - z < 0) : false :=
by linarith
example (ε : ℚ) (h1 : ε > 0) : ε / 2 < ε :=
by linarith
example (ε : ℚ) (h1 : ε > 0) : ε / 3 + ε / 3 + ε / 3 = ε :=
by linarith
example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false :=
by linarith {discharger := `[ring SOP]}
example (a b c : ℚ) (h2 : b + 2 > 3 + b) : false :=
by linarith
example (a b c : ℚ) (x y : ℤ) (h1 : x ≤ 3*y) (h2 : b + 2 > 3 + b) : false :=
by linarith {restrict_type := ℚ}
example (g v V c h : ℚ) (h1 : h = 0) (h2 : v = V) (h3 : V > 0) (h4 : g > 0)
(h5 : 0 ≤ c) (h6 : c < 1) :
v ≤ V :=
by linarith
example (x y z : ℚ) (h1 : 2*x + ((-3)*y) < 0) (h2 : (-4)*x + 2*z < 0)
(h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false :=
by linarith
example (x y z : ℚ) (h1 : 2*1*x + (3)*(y*(-1)) < 0) (h2 : (-2)*x*2 < -(z + z))
(h3 : 12*y + (-4)* z < 0) (h4 : nat.prime 7) : false :=
by linarith
example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5)
(h3 : 12*y - 4* z < 0) : false :=
by linarith
example (x y z : ℤ) (h1 : 2*x < 3*y) (h2 : -4*x + 2*z < 0) (h3 : x*y < 5) :
¬ 12*y - 4* z < 0 :=
by linarith
example (w x y z : ℤ) (h1 : 4*x + (-3)*y + 6*w ≤ 0) (h2 : (-1)*x < 0)
(h3 : y < 0) (h4 : w ≥ 0) (h5 : nat.prime x.nat_abs) : false :=
by linarith
example (a b c : ℚ) (h1 : a > 0) (h2 : b > 5) (h3 : c < -10)
(h4 : a + b - c < 3) : false :=
by linarith
example (a b c : ℚ) (h2 : b > 0) (h3 : ¬ b ≥ 0) : false :=
by linarith
example (a b c : ℚ) (h2 : (2 : ℚ) > 3) : a + b - c ≥ 3 :=
by linarith {exfalso := ff}
example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false :=
by linarith [rat.num_pos_iff_pos.mpr hx, h]
example (x : ℚ) (hx : x > 0) (h : x.num < 0) : false :=
by linarith only [rat.num_pos_iff_pos.mpr hx, h]
example (x y z : ℚ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y :=
by linarith
example (x y z : ℕ) (hx : x ≤ 3*y) (h2 : y ≤ 2*z) (h3 : x ≥ 6*z) : x = 3*y :=
by linarith
example (x y z : ℚ) (hx : ¬ x > 3*y) (h2 : ¬ y > 2*z) (h3 : x ≥ 6*z) : x = 3*y :=
by linarith
example (h1 : (1 : ℕ) < 1) : false :=
by linarith
example (a b c : ℚ) (h2 : b > 0) (h3 : b < 0) : nat.prime 10 :=
by linarith
example (a b c : ℕ) : a + b ≥ a :=
by linarith
example (a b c : ℕ) : ¬ a + b < a :=
by linarith
example (x y : ℚ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) (h' : (x + 4) * x ≥ 0)
(h'' : (6 + 3 * y) * y ≥ 0) : false :=
by linarith
example (x y : ℚ)
(h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3 ∧ (x + 4) * x ≥ 0 ∧ (6 + 3 * y) * y ≥ 0) : false :=
by linarith
example (x y : ℕ) (h : 6 + ((x + 4) * x + (6 + 3 * y) * y) = 3) : false :=
by linarith
example (a b i : ℕ) (h1 : ¬ a < i) (h2 : b < i) (h3 : a ≤ b) : false :=
by linarith
example (n : ℕ) (h1 : n ≤ 3) (h2 : n > 2) : n = 3 := by linarith
example (z : ℕ) (hz : ¬ z ≥ 2) (h2 : ¬ z + 1 ≤ 2) : false :=
by linarith
example (z : ℕ) (hz : ¬ z ≥ 2) : z + 1 ≤ 2 :=
by linarith
example (a b c : ℚ) (h1 : 1 / a < b) (h2 : b < c) : 1 / a < c :=
by linarith
example
(N : ℕ) (n : ℕ) (Hirrelevant : n > N)
(A : ℚ) (l : ℚ) (h : A - l ≤ -(A - l)) (h_1 : ¬A ≤ -A) (h_2 : ¬l ≤ -l)
(h_3 : -(A - l) < 1) : A < l + 1 := by linarith
example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) :
d ≤ ((q : ℚ) - 1)*n :=
by linarith
example (d : ℚ) (q n : ℕ) (h1 : ((q : ℚ) - 1)*n ≥ 0) (h2 : d = 2/3*(((q : ℚ) - 1)*n)) :
((q : ℚ) - 1)*n - d = 1/3 * (((q : ℚ) - 1)*n) :=
by linarith
example (a : ℚ) (ha : 0 ≤ a) : 0 * 0 ≤ 2 * a :=
by linarith
example (x : ℚ) : id x ≥ x :=
by success_if_fail {linarith}; linarith!
example (x y z : ℚ) (hx : x < 5) (hx2 : x > 5) (hy : y < 5000000000) (hz : z > 34*y) : false :=
by linarith only [hx, hx2]
example (x y z : ℚ) (hx : x < 5) (hy : y < 5000000000) (hz : z > 34*y) : x ≤ 5 :=
by linarith only [hx]
example (x y : ℚ) (h : x < y) : x ≠ y := by linarith
example (x y : ℚ) (h : x < y) : ¬ x = y := by linarith
example (u v x y A B : ℚ)
(a : 0 < A)
(a_1 : 0 <= 1 - A)
(a_2 : 0 <= B - 1)
(a_3 : 0 <= B - x)
(a_4 : 0 <= B - y)
(a_5 : 0 <= u)
(a_6 : 0 <= v)
(a_7 : 0 < A - u)
(a_8 : 0 < A - v) :
u * y + v * x + u * v < 3 * A * B :=
by nlinarith
example (u v x y A B : ℚ) : (0 < A) → (A ≤ 1) → (1 ≤ B)
→ (x ≤ B) → ( y ≤ B)
→ (0 ≤ u ) → (0 ≤ v )
→ (u < A) → ( v < A)
→ (u * y + v * x + u * v < 3 * A * B) :=
begin
intros,
nlinarith
end
example (u v x y A B : ℚ)
(a : 0 < A)
(a_1 : 0 <= 1 - A)
(a_2 : 0 <= B - 1)
(a_3 : 0 <= B - x)
(a_4 : 0 <= B - y)
(a_5 : 0 <= u)
(a_6 : 0 <= v)
(a_7 : 0 < A - u)
(a_8 : 0 < A - v) :
(0 < A * A)
-> (0 <= A * (1 - A))
-> (0 <= A * (B - 1))
-> (0 <= A * (B - x))
-> (0 <= A * (B - y))
-> (0 <= A * u)
-> (0 <= A * v)
-> (0 < A * (A - u))
-> (0 < A * (A - v))
-> (0 <= (1 - A) * A)
-> (0 <= (1 - A) * (1 - A))
-> (0 <= (1 - A) * (B - 1))
-> (0 <= (1 - A) * (B - x))
-> (0 <= (1 - A) * (B - y))
-> (0 <= (1 - A) * u)
-> (0 <= (1 - A) * v)
-> (0 <= (1 - A) * (A - u))
-> (0 <= (1 - A) * (A - v))
-> (0 <= (B - 1) * A)
-> (0 <= (B - 1) * (1 - A))
-> (0 <= (B - 1) * (B - 1))
-> (0 <= (B - 1) * (B - x))
-> (0 <= (B - 1) * (B - y))
-> (0 <= (B - 1) * u)
-> (0 <= (B - 1) * v)
-> (0 <= (B - 1) * (A - u))
-> (0 <= (B - 1) * (A - v))
-> (0 <= (B - x) * A)
-> (0 <= (B - x) * (1 - A))
-> (0 <= (B - x) * (B - 1))
-> (0 <= (B - x) * (B - x))
-> (0 <= (B - x) * (B - y))
-> (0 <= (B - x) * u)
-> (0 <= (B - x) * v)
-> (0 <= (B - x) * (A - u))
-> (0 <= (B - x) * (A - v))
-> (0 <= (B - y) * A)
-> (0 <= (B - y) * (1 - A))
-> (0 <= (B - y) * (B - 1))
-> (0 <= (B - y) * (B - x))
-> (0 <= (B - y) * (B - y))
-> (0 <= (B - y) * u)
-> (0 <= (B - y) * v)
-> (0 <= (B - y) * (A - u))
-> (0 <= (B - y) * (A - v))
-> (0 <= u * A)
-> (0 <= u * (1 - A))
-> (0 <= u * (B - 1))
-> (0 <= u * (B - x))
-> (0 <= u * (B - y))
-> (0 <= u * u)
-> (0 <= u * v)
-> (0 <= u * (A - u))
-> (0 <= u * (A - v))
-> (0 <= v * A)
-> (0 <= v * (1 - A))
-> (0 <= v * (B - 1))
-> (0 <= v * (B - x))
-> (0 <= v * (B - y))
-> (0 <= v * u)
-> (0 <= v * v)
-> (0 <= v * (A - u))
-> (0 <= v * (A - v))
-> (0 < (A - u) * A)
-> (0 <= (A - u) * (1 - A))
-> (0 <= (A - u) * (B - 1))
-> (0 <= (A - u) * (B - x))
-> (0 <= (A - u) * (B - y))
-> (0 <= (A - u) * u)
-> (0 <= (A - u) * v)
-> (0 < (A - u) * (A - u))
-> (0 < (A - u) * (A - v))
-> (0 < (A - v) * A)
-> (0 <= (A - v) * (1 - A))
-> (0 <= (A - v) * (B - 1))
-> (0 <= (A - v) * (B - x))
-> (0 <= (A - v) * (B - y))
-> (0 <= (A - v) * u)
-> (0 <= (A - v) * v)
-> (0 < (A - v) * (A - u))
-> (0 < (A - v) * (A - v))
->
u * y + v * x + u * v < 3 * A * B :=
begin
intros,
linarith
end
example (A B : ℚ) : (0 < A) → (1 ≤ B) → (0 < A / 8 * B) :=
begin
intros, nlinarith
end
example (x y : ℚ) : 0 ≤ x ^2 + y ^2 :=
by nlinarith
example (x y : ℚ) : 0 ≤ x*x + y*y :=
by nlinarith
example (x y : ℚ) : x = 0 → y = 0 → x*x + y*y = 0 :=
by intros; nlinarith
/- lemma norm_eq_zero_iff {x y : ℚ} : x * x + y * y = 0 ↔ x = 0 ∧ y = 0 :=
begin
split,
{ intro h, split; sorry }, -- should be solved after refactor
{ rintro ⟨⟩, nlinarith }
end -/
-- should be solved after refactor
/- lemma norm_nonpos_right {x y : ℚ} (h1 : x * x + y * y ≤ 0) : y = 0 :=
by nlinarith
lemma norm_nonpos_left (x y : ℚ) (h1 : x * x + y * y ≤ 0) : x = 0 :=
by nlinarith -/
variables {E : Type*} [add_group E]
example (f : ℤ → E) (h : 0 = f 0) : 1 ≤ 2 := by nlinarith
example (a : E) (h : a = a) : 1 ≤ 2 := by nlinarith
|
49aabee4ae2cd4e50195c4ef67eac3b9db6c8a51 | 41ebf3cb010344adfa84907b3304db00e02db0a6 | /uexp/src/uexp/rules/MergeFilter.lean | 016840fdeb8a75ae140dde969338fa1bef889622 | [
"BSD-2-Clause"
] | permissive | ReinierKoops/Cosette | e061b2ba58b26f4eddf4cd052dcf7abd16dfe8fb | eb8dadd06ee05fe7b6b99de431dd7c4faef5cb29 | refs/heads/master | 1,686,483,953,198 | 1,624,293,498,000 | 1,624,293,498,000 | 378,997,885 | 0 | 0 | BSD-2-Clause | 1,624,293,485,000 | 1,624,293,484,000 | null | UTF-8 | Lean | false | false | 900 | lean | import ..sql
import ..tactics
import ..u_semiring
import ..extra_constants
import ..meta.ucongr
import ..meta.TDP
set_option profiler true
open Expr
open Proj
open Pred
open SQL
open tree
notation `int` := datatypes.int
variable integer_10: const datatypes.int
theorem rule:
forall ( Γ scm_dept: Schema) (rel_dept: relation scm_dept) (dept_deptno : Column int scm_dept) (dept_name : Column int scm_dept),
denoteSQL ((SELECT1 (right⋅dept_name) FROM1 ((SELECT * FROM1 (table rel_dept) WHERE (equal (uvariable (right⋅dept_deptno)) (constantExpr integer_10)))) WHERE (equal (uvariable (right⋅dept_deptno)) (constantExpr integer_10))) :SQL Γ _)
=
denoteSQL ((SELECT1 (right⋅dept_name) FROM1 (table rel_dept) WHERE (equal (uvariable (right⋅dept_deptno)) (constantExpr integer_10))) :SQL Γ _) :=
begin
intros,
unfold_all_denotations,
funext,
simp,
print_size,
TDP' ucongr,
end |
9f548c215a4beb5cf61f73bc24873b5863afae29 | 1a61aba1b67cddccce19532a9596efe44be4285f | /hott/init/pathover.hlean | a4bdf597063a0424799c286a7f57b695d51ab960 | [
"Apache-2.0"
] | permissive | eigengrau/lean | 07986a0f2548688c13ba36231f6cdbee82abf4c6 | f8a773be1112015e2d232661ce616d23f12874d0 | refs/heads/master | 1,610,939,198,566 | 1,441,352,386,000 | 1,441,352,494,000 | 41,903,576 | 0 | 0 | null | 1,441,352,210,000 | 1,441,352,210,000 | null | UTF-8 | Lean | false | false | 10,113 | hlean | /-
Copyright (c) 2015 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Floris van Doorn
Basic theorems about pathovers
-/
prelude
import .path .equiv
open equiv is_equiv equiv.ops
variables {A A' : Type} {B B' : A → Type} {C : Π⦃a⦄, B a → Type}
{a a₂ a₃ a₄ : A} {p p' : a = a₂} {p₂ : a₂ = a₃} {p₃ : a₃ = a₄}
{b b' : B a} {b₂ b₂' : B a₂} {b₃ : B a₃} {b₄ : B a₄}
{c : C b} {c₂ : C b₂}
namespace eq
inductive pathover.{l} (B : A → Type.{l}) (b : B a) : Π{a₂ : A}, a = a₂ → B a₂ → Type.{l} :=
idpatho : pathover B b (refl a) b
notation b `=[`:50 p:0 `]`:0 b₂:50 := pathover _ b p b₂
definition idpo [reducible] [constructor] : b =[refl a] b :=
pathover.idpatho b
/- equivalences with equality using transport -/
definition pathover_of_tr_eq [unfold 5 8] (r : p ▸ b = b₂) : b =[p] b₂ :=
by cases p; cases r; exact idpo
definition pathover_of_eq_tr [unfold 5 8] (r : b = p⁻¹ ▸ b₂) : b =[p] b₂ :=
by cases p; cases r; exact idpo
definition tr_eq_of_pathover [unfold 8] (r : b =[p] b₂) : p ▸ b = b₂ :=
by cases r; exact idp
definition eq_tr_of_pathover [unfold 8] (r : b =[p] b₂) : b = p⁻¹ ▸ b₂ :=
by cases r; exact idp
definition pathover_equiv_tr_eq [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (p ▸ b = b₂) :=
begin
fapply equiv.MK,
{ exact tr_eq_of_pathover},
{ exact pathover_of_tr_eq},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_equiv_eq_tr [constructor] (p : a = a₂) (b : B a) (b₂ : B a₂)
: (b =[p] b₂) ≃ (b = p⁻¹ ▸ b₂) :=
begin
fapply equiv.MK,
{ exact eq_tr_of_pathover},
{ exact pathover_of_eq_tr},
{ intro r, cases p, cases r, apply idp},
{ intro r, cases r, apply idp},
end
definition pathover_tr [unfold 5] (p : a = a₂) (b : B a) : b =[p] p ▸ b :=
by cases p;exact idpo
definition tr_pathover [unfold 5] (p : a = a₂) (b : B a₂) : p⁻¹ ▸ b =[p] b :=
by cases p;exact idpo
definition concato [unfold 12] (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) : b =[p ⬝ p₂] b₃ :=
pathover.rec_on r₂ r
definition inverseo [unfold 8] (r : b =[p] b₂) : b₂ =[p⁻¹] b :=
pathover.rec_on r idpo
definition apdo [unfold 6] (f : Πa, B a) (p : a = a₂) : f a =[p] f a₂ :=
eq.rec_on p idpo
definition oap [unfold 6] {C : A → Type} (f : Πa, B a → C a) (p : a = a₂) : f a =[p] f a₂ :=
eq.rec_on p idpo
definition concato_eq [unfold 10] (r : b =[p] b₂) (q : b₂ = b₂') : b =[p] b₂' :=
eq.rec_on q r
definition eq_concato [unfold 9] (q : b = b') (r : b' =[p] b₂) : b =[p] b₂ :=
by induction q;exact r
-- infix `⬝` := concato
infix `⬝o`:75 := concato
infix `⬝op`:75 := concato_eq
infix `⬝po`:75 := eq_concato
-- postfix `⁻¹` := inverseo
postfix `⁻¹ᵒ`:(max+10) := inverseo
/- Some of the theorems analogous to theorems for = in init.path -/
definition cono_idpo (r : b =[p] b₂) : r ⬝o idpo =[con_idp p] r :=
pathover.rec_on r idpo
definition idpo_cono (r : b =[p] b₂) : idpo ⬝o r =[idp_con p] r :=
pathover.rec_on r idpo
definition cono.assoc' (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
r ⬝o (r₂ ⬝o r₃) =[!con.assoc'] (r ⬝o r₂) ⬝o r₃ :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.assoc (r : b =[p] b₂) (r₂ : b₂ =[p₂] b₃) (r₃ : b₃ =[p₃] b₄) :
(r ⬝o r₂) ⬝o r₃ =[!con.assoc] r ⬝o (r₂ ⬝o r₃) :=
pathover.rec_on r₃ (pathover.rec_on r₂ (pathover.rec_on r idpo))
definition cono.right_inv (r : b =[p] b₂) : r ⬝o r⁻¹ᵒ =[!con.right_inv] idpo :=
pathover.rec_on r idpo
definition cono.left_inv (r : b =[p] b₂) : r⁻¹ᵒ ⬝o r =[!con.left_inv] idpo :=
pathover.rec_on r idpo
definition eq_of_pathover {a' a₂' : A'} (q : a' =[p] a₂') : a' = a₂' :=
by cases q;reflexivity
definition pathover_of_eq {a' a₂' : A'} (q : a' = a₂') : a' =[p] a₂' :=
by cases p;cases q;exact idpo
definition pathover_constant [constructor] (p : a = a₂) (a' a₂' : A') : a' =[p] a₂' ≃ a' = a₂' :=
begin
fapply equiv.MK,
{ exact eq_of_pathover},
{ exact pathover_of_eq},
{ intro r, cases p, cases r, exact idp},
{ intro r, cases r, exact idp},
end
definition eq_of_pathover_idp [unfold 6] {b' : B a} (q : b =[idpath a] b') : b = b' :=
tr_eq_of_pathover q
--should B be explicit in the next two definitions?
definition pathover_idp_of_eq [unfold 6] {b' : B a} (q : b = b') : b =[idpath a] b' :=
pathover_of_tr_eq q
definition pathover_idp [constructor] (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
equiv.MK eq_of_pathover_idp
(pathover_idp_of_eq)
(to_right_inv !pathover_equiv_tr_eq)
(to_left_inv !pathover_equiv_tr_eq)
-- definition pathover_idp (b : B a) (b' : B a) : b =[idpath a] b' ≃ b = b' :=
-- pathover_equiv_tr_eq idp b b'
-- definition eq_of_pathover_idp [reducible] {b' : B a} (q : b =[idpath a] b') : b = b' :=
-- to_fun !pathover_idp q
-- definition pathover_idp_of_eq [reducible] {b' : B a} (q : b = b') : b =[idpath a] b' :=
-- to_inv !pathover_idp q
definition idp_rec_on [recursor] {P : Π⦃b₂ : B a⦄, b =[idpath a] b₂ → Type}
{b₂ : B a} (r : b =[idpath a] b₂) (H : P idpo) : P r :=
have H2 : P (pathover_idp_of_eq (eq_of_pathover_idp r)), from
eq.rec_on (eq_of_pathover_idp r) H,
proof left_inv !pathover_idp r ▸ H2 qed
definition rec_on_right [recursor] {P : Π⦃b₂ : B a₂⦄, b =[p] b₂ → Type}
{b₂ : B a₂} (r : b =[p] b₂) (H : P !pathover_tr) : P r :=
by cases r; exact H
definition rec_on_left [recursor] {P : Π⦃b : B a⦄, b =[p] b₂ → Type}
{b : B a} (r : b =[p] b₂) (H : P !tr_pathover) : P r :=
by cases r; exact H
--pathover with fibration B' ∘ f
definition pathover_ap [unfold 10] (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[p] b₂) : b =[ap f p] b₂ :=
by cases q; exact idpo
definition pathover_of_pathover_ap (B' : A' → Type) (f : A → A') {p : a = a₂}
{b : B' (f a)} {b₂ : B' (f a₂)} (q : b =[ap f p] b₂) : b =[p] b₂ :=
by cases p; apply (idp_rec_on q); apply idpo
definition pathover_compose (B' : A' → Type) (f : A → A') (p : a = a₂)
(b : B' (f a)) (b₂ : B' (f a₂)) : b =[p] b₂ ≃ b =[ap f p] b₂ :=
begin
fapply equiv.MK,
{ apply pathover_ap},
{ apply pathover_of_pathover_ap},
{ intro q, cases p, esimp, apply (idp_rec_on q), apply idp},
{ intro q, cases q, exact idp},
end
definition apdo_con (f : Πa, B a) (p : a = a₂) (q : a₂ = a₃)
: apdo f (p ⬝ q) = apdo f p ⬝o apdo f q :=
by cases p; cases q; exact idp
definition apdo_inv (f : Πa, B a) (p : a = a₂) : apdo f p⁻¹ = (apdo f p)⁻¹ᵒ :=
by cases p; exact idp
definition apdo_eq_pathover_of_eq_ap (f : A → A') (p : a = a₂) :
apdo f p = pathover_of_eq (ap f p) :=
eq.rec_on p idp
definition pathover_of_pathover_tr (q : b =[p ⬝ p₂] p₂ ▸ b₂) : b =[p] b₂ :=
by cases p₂;exact q
definition pathover_tr_of_pathover {p : a = a₃} (q : b =[p ⬝ p₂⁻¹] b₂) : b =[p] p₂ ▸ b₂ :=
by cases p₂;exact q
definition pathover_tr_of_eq (q : b = b') : b =[p] p ▸ b' :=
by cases q;apply pathover_tr
definition tr_pathover_of_eq (q : b₂ = b₂') : p⁻¹ ▸ b₂ =[p] b₂' :=
by cases q;apply tr_pathover
variable (C)
definition transporto (r : b =[p] b₂) (c : C b) : C b₂ :=
by induction r;exact c
infix `▸o`:75 := transporto _
definition fn_tro_eq_tro_fn (C' : Π ⦃a : A⦄, B a → Type) (q : b =[p] b₂)
(f : Π(b : B a), C b → C' b) (c : C b) : f b (q ▸o c) = (q ▸o (f b c)) :=
by induction q;reflexivity
variable {C}
definition apo (f : Πa, B a → B' a) {Ha : a = a₂} (Hb : b =[Ha] b₂)
: f a b =[Ha] f a₂ b₂ :=
by induction Hb; exact idpo
definition apo011 (f : Πa, B a → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
: f a b = f a₂ b₂ :=
by cases Hb; exact idp
definition apo0111 (f : Πa b, C b → A') (Ha : a = a₂) (Hb : b =[Ha] b₂)
(Hc : c =[apo011 C Ha Hb] c₂) : f a b c = f a₂ b₂ c₂ :=
by cases Hb; apply (idp_rec_on Hc); apply idp
definition apo11 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p] g)
{b : B a} {b₂ : B a₂} (q : b =[p] b₂) : f b =[apo011 C p q] g b₂ :=
by cases r; apply (idp_rec_on q); exact idpo
definition apdo10 {f : Πb, C b} {g : Πb₂, C b₂} (r : f =[p] g)
(b : B a) : f b =[apo011 C p !pathover_tr] g (p ▸ b) :=
by cases r; exact idpo
definition apo10 {f : B a → B' a} {g : B a₂ → B' a₂} (r : f =[p] g)
(b : B a) : f b =[p] g (p ▸ b) :=
by cases r; exact idpo
definition cono.right_inv_eq (q : b = b')
: concato_eq (pathover_idp_of_eq q) q⁻¹ = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.right_inv_eq' (q : b = b')
: eq_concato q (pathover_idp_of_eq q⁻¹) = (idpo : b =[refl a] b) :=
by induction q;constructor
definition cono.left_inv_eq (q : b = b')
: concato_eq (pathover_idp_of_eq q⁻¹) q = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition cono.left_inv_eq' (q : b = b')
: eq_concato q⁻¹ (pathover_idp_of_eq q) = (idpo : b' =[refl a] b') :=
by induction q;constructor
definition change_path [unfold 9] (q : p = p') (r : b =[p] b₂) : b =[p'] b₂ :=
by induction q;exact r
definition change_path_equiv (f : Π{a}, B a ≃ B' a) (r : b =[p] b₂) : f b =[p] f b₂ :=
by induction r;constructor
definition change_path_equiv' (f : Π{a}, B a ≃ B' a) (r : f b =[p] f b₂) : b =[p] b₂ :=
(left_inv f b)⁻¹ ⬝po change_path_equiv (λa, f⁻¹ᵉ) r ⬝op left_inv f b₂
end eq
|
8cd7cf169eabbbf028ce98c9482fefdb6f28b575 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/order/sub/canonical.lean | 0be3913982c1be90116b3f5b99393a01a22e0368 | [
"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 | 17,120 | 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 algebra.order.monoid.canonical.defs
import algebra.order.sub.defs
/-!
# Lemmas about subtraction in canonically ordered monoids
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/
variables {α : Type*}
section has_exists_add_of_le
variables [add_comm_semigroup α] [partial_order α] [has_exists_add_of_le α]
[covariant_class α α (+) (≤)] [has_sub α] [has_ordered_sub α] {a b c d : α}
@[simp] lemma add_tsub_cancel_of_le (h : a ≤ b) : a + (b - a) = b :=
begin
refine le_antisymm _ le_add_tsub,
obtain ⟨c, rfl⟩ := exists_add_of_le h,
exact add_le_add_left add_tsub_le_left a,
end
lemma tsub_add_cancel_of_le (h : a ≤ b) : b - a + a = b :=
by { rw [add_comm], exact add_tsub_cancel_of_le h }
lemma add_le_of_le_tsub_right_of_le (h : b ≤ c) (h2 : a ≤ c - b) : a + b ≤ c :=
(add_le_add_right h2 b).trans_eq $ tsub_add_cancel_of_le h
lemma add_le_of_le_tsub_left_of_le (h : a ≤ c) (h2 : b ≤ c - a) : a + b ≤ c :=
(add_le_add_left h2 a).trans_eq $ add_tsub_cancel_of_le h
lemma tsub_le_tsub_iff_right (h : c ≤ b) : a - c ≤ b - c ↔ a ≤ b :=
by rw [tsub_le_iff_right, tsub_add_cancel_of_le h]
lemma tsub_left_inj (h1 : c ≤ a) (h2 : c ≤ b) : a - c = b - c ↔ a = b :=
by simp_rw [le_antisymm_iff, tsub_le_tsub_iff_right h1, tsub_le_tsub_iff_right h2]
lemma tsub_inj_left (h₁ : a ≤ b) (h₂ : a ≤ c) : b - a = c - a → b = c := (tsub_left_inj h₁ h₂).1
/-- See `lt_of_tsub_lt_tsub_right` for a stronger statement in a linear order. -/
lemma lt_of_tsub_lt_tsub_right_of_le (h : c ≤ b) (h2 : a - c < b - c) : a < b :=
by { refine ((tsub_le_tsub_iff_right h).mp h2.le).lt_of_ne _, rintro rfl, exact h2.false }
lemma tsub_add_tsub_cancel (hab : b ≤ a) (hcb : c ≤ b) : (a - b) + (b - c) = a - c :=
begin
convert tsub_add_cancel_of_le (tsub_le_tsub_right hab c) using 2,
rw [tsub_tsub, add_tsub_cancel_of_le hcb],
end
lemma tsub_tsub_tsub_cancel_right (h : c ≤ b) : (a - c) - (b - c) = a - b :=
by rw [tsub_tsub, add_tsub_cancel_of_le h]
/-! #### Lemmas that assume that an element is `add_le_cancellable`. -/
namespace add_le_cancellable
protected lemma eq_tsub_iff_add_eq_of_le (hc : add_le_cancellable c) (h : c ≤ b) :
a = b - c ↔ a + c = b :=
⟨by { rintro rfl, exact tsub_add_cancel_of_le h }, hc.eq_tsub_of_add_eq⟩
protected lemma tsub_eq_iff_eq_add_of_le (hb : add_le_cancellable b) (h : b ≤ a) :
a - b = c ↔ a = c + b :=
by rw [eq_comm, hb.eq_tsub_iff_add_eq_of_le h, eq_comm]
protected lemma add_tsub_assoc_of_le (hc : add_le_cancellable c) (h : c ≤ b) (a : α) :
a + b - c = a + (b - c) :=
by conv_lhs { rw [← add_tsub_cancel_of_le h, add_comm c, ← add_assoc,
hc.add_tsub_cancel_right] }
protected lemma tsub_add_eq_add_tsub (hb : add_le_cancellable b) (h : b ≤ a) :
a - b + c = a + c - b :=
by rw [add_comm a, hb.add_tsub_assoc_of_le h, add_comm]
protected lemma tsub_tsub_assoc (hbc : add_le_cancellable (b - c)) (h₁ : b ≤ a) (h₂ : c ≤ b) :
a - (b - c) = a - b + c :=
hbc.tsub_eq_of_eq_add $ by rw [add_assoc, add_tsub_cancel_of_le h₂, tsub_add_cancel_of_le h₁]
protected lemma tsub_add_tsub_comm (hb : add_le_cancellable b) (hd : add_le_cancellable d)
(hba : b ≤ a) (hdc : d ≤ c) : a - b + (c - d) = a + c - (b + d) :=
by rw [hb.tsub_add_eq_add_tsub hba, ←hd.add_tsub_assoc_of_le hdc, tsub_tsub, add_comm d]
protected lemma le_tsub_iff_left (ha : add_le_cancellable a) (h : a ≤ c) : b ≤ c - a ↔ a + b ≤ c :=
⟨add_le_of_le_tsub_left_of_le h, ha.le_tsub_of_add_le_left⟩
protected lemma le_tsub_iff_right (ha : add_le_cancellable a) (h : a ≤ c) : b ≤ c - a ↔ b + a ≤ c :=
by { rw [add_comm], exact ha.le_tsub_iff_left h }
protected lemma tsub_lt_iff_left (hb : add_le_cancellable b) (hba : b ≤ a) :
a - b < c ↔ a < b + c :=
begin
refine ⟨hb.lt_add_of_tsub_lt_left, _⟩,
intro h, refine (tsub_le_iff_left.mpr h.le).lt_of_ne _,
rintro rfl, exact h.ne' (add_tsub_cancel_of_le hba)
end
protected lemma tsub_lt_iff_right (hb : add_le_cancellable b) (hba : b ≤ a) :
a - b < c ↔ a < c + b :=
by { rw [add_comm], exact hb.tsub_lt_iff_left hba }
protected lemma tsub_lt_iff_tsub_lt (hb : add_le_cancellable b) (hc : add_le_cancellable c)
(h₁ : b ≤ a) (h₂ : c ≤ a) : a - b < c ↔ a - c < b :=
by rw [hb.tsub_lt_iff_left h₁, hc.tsub_lt_iff_right h₂]
protected lemma le_tsub_iff_le_tsub (ha : add_le_cancellable a) (hc : add_le_cancellable c)
(h₁ : a ≤ b) (h₂ : c ≤ b) : a ≤ b - c ↔ c ≤ b - a :=
by rw [ha.le_tsub_iff_left h₁, hc.le_tsub_iff_right h₂]
protected lemma lt_tsub_iff_right_of_le (hc : add_le_cancellable c) (h : c ≤ b) :
a < b - c ↔ a + c < b :=
begin
refine ⟨λ h', (add_le_of_le_tsub_right_of_le h h'.le).lt_of_ne _, hc.lt_tsub_of_add_lt_right⟩,
rintro rfl,
exact h'.ne' hc.add_tsub_cancel_right,
end
protected lemma lt_tsub_iff_left_of_le (hc : add_le_cancellable c) (h : c ≤ b) :
a < b - c ↔ c + a < b :=
by { rw [add_comm], exact hc.lt_tsub_iff_right_of_le h }
protected lemma tsub_inj_right (hab : add_le_cancellable (a - b)) (h₁ : b ≤ a) (h₂ : c ≤ a)
(h₃ : a - b = a - c) : b = c :=
by { rw ← hab.inj, rw [tsub_add_cancel_of_le h₁, h₃, tsub_add_cancel_of_le h₂] }
protected lemma lt_of_tsub_lt_tsub_left_of_le [contravariant_class α α (+) (<)]
(hb : add_le_cancellable b) (hca : c ≤ a) (h : a - b < a - c) : c < b :=
begin
conv_lhs at h { rw [← tsub_add_cancel_of_le hca] },
exact lt_of_add_lt_add_left (hb.lt_add_of_tsub_lt_right h),
end
protected lemma tsub_lt_tsub_left_of_le (hab : add_le_cancellable (a - b)) (h₁ : b ≤ a)
(h : c < b) : a - b < a - c :=
(tsub_le_tsub_left h.le _).lt_of_ne $ λ h', h.ne' $ hab.tsub_inj_right h₁ (h.le.trans h₁) h'
protected lemma tsub_lt_tsub_right_of_le (hc : add_le_cancellable c) (h : c ≤ a) (h2 : a < b) :
a - c < b - c :=
by { apply hc.lt_tsub_of_add_lt_left, rwa [add_tsub_cancel_of_le h] }
protected lemma tsub_lt_tsub_iff_left_of_le_of_le [contravariant_class α α (+) (<)]
(hb : add_le_cancellable b) (hab : add_le_cancellable (a - b)) (h₁ : b ≤ a) (h₂ : c ≤ a) :
a - b < a - c ↔ c < b :=
⟨hb.lt_of_tsub_lt_tsub_left_of_le h₂, hab.tsub_lt_tsub_left_of_le h₁⟩
@[simp] protected lemma add_tsub_tsub_cancel (hac : add_le_cancellable (a - c)) (h : c ≤ a) :
(a + b) - (a - c) = b + c :=
hac.tsub_eq_of_eq_add $ by rw [add_assoc, add_tsub_cancel_of_le h, add_comm]
protected lemma tsub_tsub_cancel_of_le (hba : add_le_cancellable (b - a)) (h : a ≤ b) :
b - (b - a) = a :=
hba.tsub_eq_of_eq_add (add_tsub_cancel_of_le h).symm
protected lemma tsub_tsub_tsub_cancel_left (hab : add_le_cancellable (a - b)) (h : b ≤ a) :
a - c - (a - b) = b - c :=
by rw [tsub_right_comm, hab.tsub_tsub_cancel_of_le h]
end add_le_cancellable
section contra
/-! ### Lemmas where addition is order-reflecting. -/
variable [contravariant_class α α (+) (≤)]
lemma eq_tsub_iff_add_eq_of_le (h : c ≤ b) : a = b - c ↔ a + c = b :=
contravariant.add_le_cancellable.eq_tsub_iff_add_eq_of_le h
lemma tsub_eq_iff_eq_add_of_le (h : b ≤ a) : a - b = c ↔ a = c + b :=
contravariant.add_le_cancellable.tsub_eq_iff_eq_add_of_le h
/-- See `add_tsub_le_assoc` for an inequality. -/
lemma add_tsub_assoc_of_le (h : c ≤ b) (a : α) : a + b - c = a + (b - c) :=
contravariant.add_le_cancellable.add_tsub_assoc_of_le h a
lemma tsub_add_eq_add_tsub (h : b ≤ a) : a - b + c = a + c - b :=
contravariant.add_le_cancellable.tsub_add_eq_add_tsub h
lemma tsub_tsub_assoc (h₁ : b ≤ a) (h₂ : c ≤ b) : a - (b - c) = a - b + c :=
contravariant.add_le_cancellable.tsub_tsub_assoc h₁ h₂
lemma tsub_add_tsub_comm (hba : b ≤ a) (hdc : d ≤ c) : a - b + (c - d) = a + c - (b + d) :=
contravariant.add_le_cancellable.tsub_add_tsub_comm contravariant.add_le_cancellable hba hdc
lemma le_tsub_iff_left (h : a ≤ c) : b ≤ c - a ↔ a + b ≤ c :=
contravariant.add_le_cancellable.le_tsub_iff_left h
lemma le_tsub_iff_right (h : a ≤ c) : b ≤ c - a ↔ b + a ≤ c :=
contravariant.add_le_cancellable.le_tsub_iff_right h
lemma tsub_lt_iff_left (hbc : b ≤ a) : a - b < c ↔ a < b + c :=
contravariant.add_le_cancellable.tsub_lt_iff_left hbc
lemma tsub_lt_iff_right (hbc : b ≤ a) : a - b < c ↔ a < c + b :=
contravariant.add_le_cancellable.tsub_lt_iff_right hbc
lemma tsub_lt_iff_tsub_lt (h₁ : b ≤ a) (h₂ : c ≤ a) : a - b < c ↔ a - c < b :=
contravariant.add_le_cancellable.tsub_lt_iff_tsub_lt contravariant.add_le_cancellable h₁ h₂
lemma le_tsub_iff_le_tsub (h₁ : a ≤ b) (h₂ : c ≤ b) : a ≤ b - c ↔ c ≤ b - a :=
contravariant.add_le_cancellable.le_tsub_iff_le_tsub contravariant.add_le_cancellable h₁ h₂
/-- See `lt_tsub_iff_right` for a stronger statement in a linear order. -/
lemma lt_tsub_iff_right_of_le (h : c ≤ b) : a < b - c ↔ a + c < b :=
contravariant.add_le_cancellable.lt_tsub_iff_right_of_le h
/-- See `lt_tsub_iff_left` for a stronger statement in a linear order. -/
lemma lt_tsub_iff_left_of_le (h : c ≤ b) : a < b - c ↔ c + a < b :=
contravariant.add_le_cancellable.lt_tsub_iff_left_of_le h
/-- See `lt_of_tsub_lt_tsub_left` for a stronger statement in a linear order. -/
lemma lt_of_tsub_lt_tsub_left_of_le [contravariant_class α α (+) (<)]
(hca : c ≤ a) (h : a - b < a - c) : c < b :=
contravariant.add_le_cancellable.lt_of_tsub_lt_tsub_left_of_le hca h
lemma tsub_lt_tsub_left_of_le : b ≤ a → c < b → a - b < a - c :=
contravariant.add_le_cancellable.tsub_lt_tsub_left_of_le
lemma tsub_lt_tsub_right_of_le (h : c ≤ a) (h2 : a < b) : a - c < b - c :=
contravariant.add_le_cancellable.tsub_lt_tsub_right_of_le h h2
lemma tsub_inj_right (h₁ : b ≤ a) (h₂ : c ≤ a) (h₃ : a - b = a - c) : b = c :=
contravariant.add_le_cancellable.tsub_inj_right h₁ h₂ h₃
/-- See `tsub_lt_tsub_iff_left_of_le` for a stronger statement in a linear order. -/
lemma tsub_lt_tsub_iff_left_of_le_of_le [contravariant_class α α (+) (<)]
(h₁ : b ≤ a) (h₂ : c ≤ a) : a - b < a - c ↔ c < b :=
contravariant.add_le_cancellable.tsub_lt_tsub_iff_left_of_le_of_le
contravariant.add_le_cancellable h₁ h₂
@[simp] lemma add_tsub_tsub_cancel (h : c ≤ a) : (a + b) - (a - c) = b + c :=
contravariant.add_le_cancellable.add_tsub_tsub_cancel h
/-- See `tsub_tsub_le` for an inequality. -/
lemma tsub_tsub_cancel_of_le (h : a ≤ b) : b - (b - a) = a :=
contravariant.add_le_cancellable.tsub_tsub_cancel_of_le h
lemma tsub_tsub_tsub_cancel_left (h : b ≤ a) : a - c - (a - b) = b - c :=
contravariant.add_le_cancellable.tsub_tsub_tsub_cancel_left h
end contra
end has_exists_add_of_le
/-! ### Lemmas in a canonically ordered monoid. -/
section canonically_ordered_add_monoid
variables [canonically_ordered_add_monoid α] [has_sub α] [has_ordered_sub α] {a b c d : α}
lemma add_tsub_cancel_iff_le : a + (b - a) = b ↔ a ≤ b :=
⟨λ h, le_iff_exists_add.mpr ⟨b - a, h.symm⟩, add_tsub_cancel_of_le⟩
lemma tsub_add_cancel_iff_le : b - a + a = b ↔ a ≤ b :=
by { rw [add_comm], exact add_tsub_cancel_iff_le }
@[simp] lemma tsub_eq_zero_iff_le : a - b = 0 ↔ a ≤ b :=
by rw [← nonpos_iff_eq_zero, tsub_le_iff_left, add_zero]
alias tsub_eq_zero_iff_le ↔ _ tsub_eq_zero_of_le
attribute [simp] tsub_eq_zero_of_le
@[simp] lemma tsub_self (a : α) : a - a = 0 := tsub_eq_zero_of_le le_rfl
@[simp] lemma tsub_le_self : a - b ≤ a := tsub_le_iff_left.mpr $ le_add_left le_rfl
@[simp] lemma zero_tsub (a : α) : 0 - a = 0 := tsub_eq_zero_of_le $ zero_le a
lemma tsub_self_add (a b : α) : a - (a + b) = 0 := tsub_eq_zero_of_le $ self_le_add_right _ _
lemma tsub_pos_iff_not_le : 0 < a - b ↔ ¬ a ≤ b :=
by rw [pos_iff_ne_zero, ne.def, tsub_eq_zero_iff_le]
lemma tsub_pos_of_lt (h : a < b) : 0 < b - a := tsub_pos_iff_not_le.mpr h.not_le
lemma tsub_lt_of_lt (h : a < b) : a - c < b := lt_of_le_of_lt tsub_le_self h
namespace add_le_cancellable
protected lemma tsub_le_tsub_iff_left (ha : add_le_cancellable a) (hc : add_le_cancellable c)
(h : c ≤ a) : a - b ≤ a - c ↔ c ≤ b :=
begin
refine ⟨_, λ h, tsub_le_tsub_left h a⟩,
rw [tsub_le_iff_left, ← hc.add_tsub_assoc_of_le h, hc.le_tsub_iff_right (h.trans le_add_self),
add_comm b],
apply ha,
end
protected lemma tsub_right_inj (ha : add_le_cancellable a) (hb : add_le_cancellable b)
(hc : add_le_cancellable c) (hba : b ≤ a) (hca : c ≤ a) : a - b = a - c ↔ b = c :=
by simp_rw [le_antisymm_iff, ha.tsub_le_tsub_iff_left hb hba, ha.tsub_le_tsub_iff_left hc hca,
and_comm]
end add_le_cancellable
/-! #### Lemmas where addition is order-reflecting. -/
section contra
variable [contravariant_class α α (+) (≤)]
lemma tsub_le_tsub_iff_left (h : c ≤ a) : a - b ≤ a - c ↔ c ≤ b :=
contravariant.add_le_cancellable.tsub_le_tsub_iff_left contravariant.add_le_cancellable h
lemma tsub_right_inj (hba : b ≤ a) (hca : c ≤ a) : a - b = a - c ↔ b = c :=
contravariant.add_le_cancellable.tsub_right_inj contravariant.add_le_cancellable
contravariant.add_le_cancellable hba hca
variables (α)
/-- A `canonically_ordered_add_monoid` with ordered subtraction and order-reflecting addition is
cancellative. This is not an instance at it would form a typeclass loop.
See note [reducible non-instances]. -/
@[reducible]
def canonically_ordered_add_monoid.to_add_cancel_comm_monoid : add_cancel_comm_monoid α :=
{ add_left_cancel := λ a b c h, by simpa only [add_tsub_cancel_left] using congr_arg (λ x, x - a) h,
..(by apply_instance : add_comm_monoid α) }
end contra
end canonically_ordered_add_monoid
/-! ### Lemmas in a linearly canonically ordered monoid. -/
section canonically_linear_ordered_add_monoid
variables [canonically_linear_ordered_add_monoid α] [has_sub α] [has_ordered_sub α] {a b c d : α}
@[simp] lemma tsub_pos_iff_lt : 0 < a - b ↔ b < a :=
by rw [tsub_pos_iff_not_le, not_le]
lemma tsub_eq_tsub_min (a b : α) : a - b = a - min a b :=
begin
cases le_total a b with h h,
{ rw [min_eq_left h, tsub_self, tsub_eq_zero_of_le h] },
{ rw [min_eq_right h] },
end
namespace add_le_cancellable
protected lemma lt_tsub_iff_right (hc : add_le_cancellable c) : a < b - c ↔ a + c < b :=
⟨lt_imp_lt_of_le_imp_le tsub_le_iff_right.mpr, hc.lt_tsub_of_add_lt_right⟩
protected lemma lt_tsub_iff_left (hc : add_le_cancellable c) : a < b - c ↔ c + a < b :=
⟨lt_imp_lt_of_le_imp_le tsub_le_iff_left.mpr, hc.lt_tsub_of_add_lt_left⟩
protected lemma tsub_lt_tsub_iff_right (hc : add_le_cancellable c) (h : c ≤ a) :
a - c < b - c ↔ a < b :=
by rw [hc.lt_tsub_iff_left, add_tsub_cancel_of_le h]
protected lemma tsub_lt_self (ha : add_le_cancellable a) (h₁ : 0 < a) (h₂ : 0 < b) : a - b < a :=
begin
refine tsub_le_self.lt_of_ne (λ h, _),
rw [← h, tsub_pos_iff_lt] at h₁,
exact h₂.not_le (ha.add_le_iff_nonpos_left.1 $ add_le_of_le_tsub_left_of_le h₁.le h.ge),
end
protected lemma tsub_lt_self_iff (ha : add_le_cancellable a) : a - b < a ↔ 0 < a ∧ 0 < b :=
begin
refine ⟨λ h, ⟨(zero_le _).trans_lt h, (zero_le b).lt_of_ne _⟩, λ h, ha.tsub_lt_self h.1 h.2⟩,
rintro rfl,
rw [tsub_zero] at h,
exact h.false
end
/-- See `lt_tsub_iff_left_of_le_of_le` for a weaker statement in a partial order. -/
protected lemma tsub_lt_tsub_iff_left_of_le (ha : add_le_cancellable a) (hb : add_le_cancellable b)
(h : b ≤ a) : a - b < a - c ↔ c < b :=
lt_iff_lt_of_le_iff_le $ ha.tsub_le_tsub_iff_left hb h
end add_le_cancellable
section contra
variable [contravariant_class α α (+) (≤)]
/-- This lemma also holds for `ennreal`, but we need a different proof for that. -/
lemma tsub_lt_tsub_iff_right (h : c ≤ a) : a - c < b - c ↔ a < b :=
contravariant.add_le_cancellable.tsub_lt_tsub_iff_right h
lemma tsub_lt_self : 0 < a → 0 < b → a - b < a := contravariant.add_le_cancellable.tsub_lt_self
lemma tsub_lt_self_iff : a - b < a ↔ 0 < a ∧ 0 < b :=
contravariant.add_le_cancellable.tsub_lt_self_iff
/-- See `lt_tsub_iff_left_of_le_of_le` for a weaker statement in a partial order. -/
lemma tsub_lt_tsub_iff_left_of_le (h : b ≤ a) : a - b < a - c ↔ c < b :=
contravariant.add_le_cancellable.tsub_lt_tsub_iff_left_of_le contravariant.add_le_cancellable h
end contra
/-! ### Lemmas about `max` and `min`. -/
lemma tsub_add_eq_max : a - b + b = max a b :=
begin
cases le_total a b with h h,
{ rw [max_eq_right h, tsub_eq_zero_of_le h, zero_add] },
{ rw [max_eq_left h, tsub_add_cancel_of_le h] }
end
lemma add_tsub_eq_max : a + (b - a) = max a b :=
by rw [add_comm, max_comm, tsub_add_eq_max]
lemma tsub_min : a - min a b = a - b :=
begin
cases le_total a b with h h,
{ rw [min_eq_left h, tsub_self, tsub_eq_zero_of_le h] },
{ rw [min_eq_right h] }
end
lemma tsub_add_min : a - b + min a b = a :=
by { rw [← tsub_min, tsub_add_cancel_of_le], apply min_le_left }
end canonically_linear_ordered_add_monoid
|
3029cee058314b7003f24aa5a184aed044799faf | 022547453607c6244552158ff25ab3bf17361760 | /src/analysis/special_functions/pow.lean | 122cb0ae327c5675c04be391326ca5ca0bda63b2 | [
"Apache-2.0"
] | permissive | 1293045656/mathlib | 5f81741a7c1ff1873440ec680b3680bfb6b7b048 | 4709e61525a60189733e72a50e564c58d534bed8 | refs/heads/master | 1,687,010,200,553 | 1,626,245,646,000 | 1,626,245,646,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 72,229 | 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
@[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
@[norm_cast] lemma coe_mul_rpow (x y : ℝ≥0) (z : ℝ) :
((x : ℝ≥0∞) * y) ^ z = x^z * y^z :=
begin
rcases lt_trichotomy z 0 with H|H|H,
{ by_cases hx : x = 0; by_cases hy : y = 0,
{ simp [hx, hy, zero_rpow_of_neg, H] },
{ have : (y : ℝ≥0∞) ^ z ≠ 0, by simp [rpow_eq_zero_iff, hy],
simp [hx, hy, zero_rpow_of_neg, H, with_top.top_mul this] },
{ have : (x : ℝ≥0∞) ^ z ≠ 0, by simp [rpow_eq_zero_iff, hx],
simp [hx, hy, zero_rpow_of_neg H, with_top.mul_top this] },
{ rw [← coe_mul, coe_rpow_of_ne_zero, nnreal.mul_rpow, coe_mul,
coe_rpow_of_ne_zero hx, coe_rpow_of_ne_zero hy],
simp [hx, hy] } },
{ simp [H] },
{ by_cases hx : x = 0; by_cases hy : y = 0,
{ simp [hx, hy, zero_rpow_of_pos, H] },
{ have : (y : ℝ≥0∞) ^ z ≠ 0, by simp [rpow_eq_zero_iff, hy],
simp [hx, hy, zero_rpow_of_pos H, with_top.top_mul this] },
{ have : (x : ℝ≥0∞) ^ z ≠ 0, by simp [rpow_eq_zero_iff, hx],
simp [hx, hy, zero_rpow_of_pos H, with_top.mul_top this] },
{ rw [← coe_mul, coe_rpow_of_ne_zero, nnreal.mul_rpow, coe_mul,
coe_rpow_of_ne_zero hx, coe_rpow_of_ne_zero hy],
simp [hx, hy] } },
end
lemma mul_rpow_of_ne_top {x y : ℝ≥0∞} (hx : x ≠ ⊤) (hy : y ≠ ⊤) (z : ℝ) :
(x * y) ^ z = x^z * y^z :=
begin
lift x to ℝ≥0 using hx,
lift y to ℝ≥0 using hy,
exact coe_mul_rpow x y z
end
lemma mul_rpow_of_ne_zero {x y : ℝ≥0∞} (hx : x ≠ 0) (hy : y ≠ 0) (z : ℝ) :
(x * y) ^ z = x ^ z * y ^ z :=
begin
rcases lt_trichotomy z 0 with H|H|H,
{ cases x; cases y,
{ simp [hx, hy, top_rpow_of_neg, H] },
{ have : y ≠ 0, by simpa using hy,
simp [hx, hy, top_rpow_of_neg, H, rpow_eq_zero_iff, this] },
{ have : x ≠ 0, by simpa using hx,
simp [hx, hy, top_rpow_of_neg, H, rpow_eq_zero_iff, this] },
{ have hx' : x ≠ 0, by simpa using hx,
have hy' : y ≠ 0, by simpa using hy,
simp only [some_eq_coe],
rw [← coe_mul, coe_rpow_of_ne_zero, nnreal.mul_rpow, coe_mul,
coe_rpow_of_ne_zero hx', coe_rpow_of_ne_zero hy'],
simp [hx', hy'] } },
{ simp [H] },
{ cases x; cases y,
{ simp [hx, hy, top_rpow_of_pos, H] },
{ have : y ≠ 0, by simpa using hy,
simp [hx, hy, top_rpow_of_pos, H, rpow_eq_zero_iff, this] },
{ have : x ≠ 0, by simpa using hx,
simp [hx, hy, top_rpow_of_pos, H, rpow_eq_zero_iff, this] },
{ have hx' : x ≠ 0, by simpa using hx,
have hy' : y ≠ 0, by simpa using hy,
simp only [some_eq_coe],
rw [← coe_mul, coe_rpow_of_ne_zero, nnreal.mul_rpow, coe_mul,
coe_rpow_of_ne_zero hx', coe_rpow_of_ne_zero hy'],
simp [hx', hy'] } }
end
lemma mul_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) :
(x * y) ^ z = x ^ z * y ^ z :=
begin
rcases le_iff_eq_or_lt.1 hz with H|H, { simp [← H] },
by_cases h : x = 0 ∨ y = 0,
{ cases h; simp [h, zero_rpow_of_pos H] },
push_neg at h,
exact mul_rpow_of_ne_zero h.1 h.2 z
end
lemma inv_rpow_of_pos {x : ℝ≥0∞} {y : ℝ} (hy : 0 < y) : (x⁻¹) ^ y = (x ^ y)⁻¹ :=
begin
by_cases h0 : x = 0,
{ rw [h0, zero_rpow_of_pos hy, inv_zero, top_rpow_of_pos hy], },
by_cases h_top : x = ⊤,
{ rw [h_top, top_rpow_of_pos hy, inv_top, zero_rpow_of_pos hy], },
rw ←coe_to_nnreal h_top,
have h : x.to_nnreal ≠ 0,
{ rw [ne.def, to_nnreal_eq_zero_iff],
simp [h0, h_top], },
rw [←coe_inv h, coe_rpow_of_nonneg _ (le_of_lt hy), coe_rpow_of_nonneg _ (le_of_lt hy), ←coe_inv],
{ rw coe_eq_coe,
exact nnreal.inv_rpow x.to_nnreal y, },
{ simp [h], },
end
lemma div_rpow_of_nonneg (x y : ℝ≥0∞) {z : ℝ} (hz : 0 ≤ z) :
(x / y) ^ z = x ^ z / y ^ z :=
begin
by_cases h0 : z = 0,
{ simp [h0], },
rw ←ne.def at h0,
have hz_pos : 0 < z, from lt_of_le_of_ne hz h0.symm,
rw [div_eq_mul_inv, mul_rpow_of_nonneg x y⁻¹ hz, inv_rpow_of_pos hz_pos, ←div_eq_mul_inv],
end
lemma rpow_le_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x ≤ y) (h₂ : 0 ≤ z) : x^z ≤ y^z :=
begin
rcases le_iff_eq_or_lt.1 h₂ with H|H, { simp [← H, le_refl] },
cases y, { simp [top_rpow_of_pos H] },
cases x, { exact (not_top_le_coe h₁).elim },
simp at h₁,
simp [coe_rpow_of_nonneg _ h₂, nnreal.rpow_le_rpow h₁ h₂]
end
lemma rpow_lt_rpow {x y : ℝ≥0∞} {z : ℝ} (h₁ : x < y) (h₂ : 0 < z) : x^z < y^z :=
begin
cases x, { exact (not_top_lt h₁).elim },
cases y, { simp [top_rpow_of_pos h₂, coe_rpow_of_nonneg _ (le_of_lt h₂)] },
simp at h₁,
simp [coe_rpow_of_nonneg _ (le_of_lt h₂), nnreal.rpow_lt_rpow h₁ h₂]
end
lemma rpow_le_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z ≤ y ^ z ↔ x ≤ y :=
begin
refine ⟨λ h, _, λ h, rpow_le_rpow h (le_of_lt hz)⟩,
rw [←rpow_one x, ←rpow_one y, ←@_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm, rpow_mul,
rpow_mul, ←one_div],
exact rpow_le_rpow h (by simp [le_of_lt hz]),
end
lemma rpow_lt_rpow_iff {x y : ℝ≥0∞} {z : ℝ} (hz : 0 < z) : x ^ z < y ^ z ↔ x < y :=
begin
refine ⟨λ h_lt, _, λ h, rpow_lt_rpow h hz⟩,
rw [←rpow_one x, ←rpow_one y, ←@_root_.mul_inv_cancel _ _ z (ne_of_lt hz).symm, rpow_mul,
rpow_mul],
exact rpow_lt_rpow h_lt (by simp [hz]),
end
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 (ne_of_lt hz).symm,
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
|
ff37a1d28f4dfa2da0c3dcb0b20c6c2afcfe6511 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch4/ex0602.lean | 3f8ce022cb1fa8e5ca91dd8d783c1e04b6bd8185 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 571 | lean | open classical
variables (α : Type) (p q : α → Prop)
variable r : Prop
example : α → ((∀ x : α, r) ↔ r) :=
assume : α,
⟨λ h, h this, λ r x, r⟩
example : (∀ x, p x ∨ r) ↔ (∀ x, p x) ∨ r :=
⟨λ h,
by_cases
(λ hr, or.inr hr)
(assume hnr : ¬r,
or.inl
(assume x : α,
(h x).elim
id
(λ hr, absurd hr hnr))),
λ h x, h.elim (λ f, or.inl (f x)) or.inr⟩
example : (∀ x, r → p x) ↔ (r → ∀ x, p x) :=
⟨λ h r x, h x r, λ h x r, h r x⟩
|
e7b862c31e4569f5364b2df38a65ff8f5315819d | 28be2ab6091504b6ba250b367205fb94d50ab284 | /src/game/world7/level5.lean | f80e1f5efeb5450a3abfe17323baa60e7c464b41 | [
"Apache-2.0"
] | permissive | postmasters/natural_number_game | 87304ac22e5e1c5ac2382d6e523d6914dd67a92d | 38a7adcdfdb18c49c87b37831736c8f15300d821 | refs/heads/master | 1,649,856,819,031 | 1,586,444,676,000 | 1,586,444,676,000 | 255,006,061 | 0 | 0 | Apache-2.0 | 1,586,664,599,000 | 1,586,664,598,000 | null | UTF-8 | Lean | false | false | 1,140 | lean | /-
# Advanced proposition world.
## Level 5: `iff_trans` easter eggs.
Let's try ``iff_trans` again. Try proving it in other ways.
### A trick.
Instead of using `cases` on `h : P ↔ Q` you can just access the proofs of `P → Q` and `Q → P`
directly with `h.1` and `h.2`. So you can solve this level with
```
intros hpq hqr,
split,
intro p,
apply hqr.1,
...
```
### Another trick
Instead of using `cases` on `h : P ↔ Q`, you can just `rw h`, and this will change all `P`s to `Q`s
in the goal. You can use this to create a much shorter proof. Note that
this is an argument for *not* running the `cases` tactic on an iff statement;
you cannot rewrite one-way implications, but you can rewrite two-way implications.
### Another trick
`cc` works on this sort of goal too.
-/
/- Lemma : no-side-bar
If $P$, $Q$ and $R$ are true/false statements, then `P ↔ Q` and `Q ↔ R` together imply `P ↔ R`.
-/
lemma iff_trans (P Q R : Prop) : (P ↔ Q) → (Q ↔ R) → (P ↔ R) :=
begin
intros hpq hqr,
split,
intro p,
apply hqr.1,
apply hpq.1,
assumption,
intro r,
apply hpq.2,
apply hqr.2,
assumption,
end
|
f4d05b42425a1a5a81f02dcf4b8a560c39c089ed | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /archive/100-theorems-list/83_friendship_graphs.lean | 0a8259f6a61787780bf98261dbcac44bbbd7835b | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,802 | lean | /-
Copyright (c) 2020 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson, Jalex Stark, Kyle Miller
-/
import combinatorics.simple_graph.adj_matrix
import linear_algebra.char_poly.coeff
import data.int.modeq
import data.zmod.basic
import tactic.interval_cases
/-!
# The Friendship Theorem
## Definitions and Statement
- A `friendship` graph is one in which any two distinct vertices have exactly one neighbor in common
- A `politician`, at least in the context of this problem, is a vertex in a graph which is adjacent
to every other vertex.
- The friendship theorem (Erdős, Rényi, Sós 1966) states that every finite friendship graph has a
politician.
## Proof outline
The proof revolves around the theory of adjacency matrices, although some steps could equivalently
be phrased in terms of counting walks.
- Assume `G` is a finite friendship graph.
- First we show that any two nonadjacent vertices have the same degree
- Assume for contradiction that `G` does not have a politician.
- Conclude from the last two points that `G` is `d`-regular for some `d : ℕ`.
- Show that `G` has `d ^ 2 - d + 1` vertices.
- By casework, show that if `d = 0, 1, 2`, then `G` has a politician.
- If `3 ≤ d`, let `p` be a prime factor of `d - 1`.
- If `A` is the adjacency matrix of `G` with entries in `ℤ/pℤ`, we show that `A ^ p` has trace `1`.
- This gives a contradiction, as `A` has trace `0`, and thus `A ^ p` has trace `0`.
## References
- [P. Erdős, A. Rényi, V. Sós, *On A Problem of Graph Theory*][erdosrenyisos]
- [C. Huneke, *The Friendship Theorem*][huneke2002]
-/
open_locale classical big_operators
noncomputable theory
open finset simple_graph matrix
universes u v
variables {V : Type u} {R : Type v} [semiring R]
section friendship_def
variables (G : simple_graph V)
/--
This property of a graph is the hypothesis of the friendship theorem:
every pair of nonadjacent vertices has exactly one common friend,
a vertex to which both are adjacent.
-/
def friendship [fintype V] : Prop := ∀ ⦃v w : V⦄, v ≠ w → fintype.card (G.common_neighbors v w) = 1
/--
A politician is a vertex that is adjacent to all other vertices.
-/
def exists_politician : Prop := ∃ (v : V), ∀ (w : V), v ≠ w → G.adj v w
end friendship_def
variables [fintype V] {G : simple_graph V} {d : ℕ} (hG : friendship G)
include hG
namespace friendship
variables (R)
/-- One characterization of a friendship graph is that there is exactly one walk of length 2
between distinct vertices. These walks are counted in off-diagonal entries of the square of
the adjacency matrix, so for a friendship graph, those entries are all 1. -/
theorem adj_matrix_sq_of_ne {v w : V} (hvw : v ≠ w) :
((G.adj_matrix R) ^ 2) v w = 1 :=
begin
rw [pow_two, ← nat.cast_one, ← hG hvw],
simp [common_neighbors, neighbor_finset_eq_filter, finset.filter_filter, finset.filter_inter,
and_comm],
end
/-- This calculation amounts to counting the number of length 3 walks between nonadjacent vertices.
We use it to show that nonadjacent vertices have equal degrees. -/
lemma adj_matrix_pow_three_of_not_adj {v w : V} (non_adj : ¬ G.adj v w) :
((G.adj_matrix R) ^ 3) v w = degree G v :=
begin
rw [pow_succ, mul_eq_mul, adj_matrix_mul_apply, degree, card_eq_sum_ones, sum_nat_cast],
apply sum_congr rfl,
intros x hx,
rw [adj_matrix_sq_of_ne _ hG, nat.cast_one],
rintro ⟨rfl⟩,
rw mem_neighbor_finset at hx,
exact non_adj hx,
end
variable {R}
/-- As `v` and `w` not being adjacent implies
`degree G v = ((G.adj_matrix R) ^ 3) v w` and `degree G w = ((G.adj_matrix R) ^ 3) v w`,
the degrees are equal if `((G.adj_matrix R) ^ 3) v w = ((G.adj_matrix R) ^ 3) w v`
This is true as the adjacency matrix is symmetric. -/
lemma degree_eq_of_not_adj {v w : V} (hvw : ¬ G.adj v w) :
degree G v = degree G w :=
begin
rw [← nat.cast_id (G.degree v), ← nat.cast_id (G.degree w),
← adj_matrix_pow_three_of_not_adj ℕ hG hvw,
← adj_matrix_pow_three_of_not_adj ℕ hG (λ h, hvw (G.sym h))],
conv_lhs {rw ← transpose_adj_matrix},
simp only [pow_succ, pow_two, mul_eq_mul, ← transpose_mul, transpose_apply],
simp only [← mul_eq_mul, mul_assoc],
end
/-- Let `A` be the adjacency matrix of a graph `G`.
If `G` is a friendship graph, then all of the off-diagonal entries of `A^2` are 1.
If `G` is `d`-regular, then all of the diagonal entries of `A^2` are `d`.
Putting these together determines `A^2` exactly for a `d`-regular friendship graph. -/
theorem adj_matrix_sq_of_regular (hd : G.is_regular_of_degree d) :
((G.adj_matrix R) ^ 2) = λ v w, if v = w then d else 1 :=
begin
ext v w, by_cases h : v = w,
{ rw [h, pow_two, mul_eq_mul, adj_matrix_mul_self_apply_self, hd], simp, },
{ rw [adj_matrix_sq_of_ne R hG h, if_neg h], },
end
lemma adj_matrix_sq_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) ^ 2 = λ _ _, 1 :=
by simp [adj_matrix_sq_of_regular hG hd, dmod]
section nonempty
variable [nonempty V]
/-- If `G` is a friendship graph without a politician (a vertex adjacent to all others), then
it is regular. We have shown that nonadjacent vertices of a friendship graph have the same degree,
and if there isn't a politician, we can show this for adjacent vertices by finding a vertex
neither is adjacent to, and then using transitivity. -/
theorem is_regular_of_not_exists_politician (hG' : ¬exists_politician G) :
∃ (d : ℕ), G.is_regular_of_degree d :=
begin
have v := classical.arbitrary V,
use G.degree v,
intro x,
by_cases hvx : G.adj v x, swap, { exact (degree_eq_of_not_adj hG hvx).symm, },
dunfold exists_politician at hG',
push_neg at hG',
rcases hG' v with ⟨w, hvw', hvw⟩,
rcases hG' x with ⟨y, hxy', hxy⟩,
by_cases hxw : G.adj x w,
swap, { rw degree_eq_of_not_adj hG hvw, exact degree_eq_of_not_adj hG hxw },
rw degree_eq_of_not_adj hG hxy,
by_cases hvy : G.adj v y,
swap, { exact (degree_eq_of_not_adj hG hvy).symm },
rw degree_eq_of_not_adj hG hvw,
apply degree_eq_of_not_adj hG,
intro hcontra,
rcases finset.card_eq_one.mp (hG hvw') with ⟨⟨a, ha⟩, h⟩,
have key : ∀ {x}, x ∈ G.common_neighbors v w → x = a,
{ intros x hx,
have h' := mem_univ (subtype.mk x hx),
rw [h, mem_singleton] at h',
injection h', },
apply hxy',
rw [key ((mem_common_neighbors G).mpr ⟨hvx, G.sym hxw⟩),
key ((mem_common_neighbors G).mpr ⟨hvy, G.sym hcontra⟩)],
end
/-- Let `A` be the adjacency matrix of a `d`-regular friendship graph, and let `v` be a vector
all of whose components are `1`. Then `v` is an eigenvector of `A ^ 2`, and we can compute
the eigenvalue to be `d * d`, or as `d + (fintype.card V - 1)`, so those quantities must be equal.
This essentially means that the graph has `d ^ 2 - d + 1` vertices. -/
lemma card_of_regular (hd : G.is_regular_of_degree d) :
d + (fintype.card V - 1) = d * d :=
begin
have v := classical.arbitrary V,
transitivity ((G.adj_matrix ℕ) ^ 2).mul_vec (λ _, 1) v,
{ rw [adj_matrix_sq_of_regular hG hd, mul_vec, dot_product, ← insert_erase (mem_univ v)],
simp only [sum_insert, mul_one, if_true, nat.cast_id, eq_self_iff_true,
mem_erase, not_true, ne.def, not_false_iff, add_right_inj, false_and],
rw [finset.sum_const_nat, card_erase_of_mem (mem_univ v), mul_one], { refl },
intros x hx, simp [(ne_of_mem_erase hx).symm], },
{ rw [pow_two, mul_eq_mul, ← mul_vec_mul_vec],
simp [adj_matrix_mul_vec_const_apply_of_regular hd, neighbor_finset,
card_neighbor_set_eq_degree, hd v], }
end
/-- The size of a `d`-regular friendship graph is `1 mod (d-1)`, and thus `1 mod p` for a
factor `p ∣ d-1`. -/
lemma card_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1) (hd : G.is_regular_of_degree d) :
(fintype.card V : zmod p) = 1 :=
begin
have hpos : 0 < fintype.card V := fintype.card_pos_iff.mpr infer_instance,
rw [← nat.succ_pred_eq_of_pos hpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
have h := congr_arg (λ n, (↑n : zmod p)) (card_of_regular hG hd),
revert h, simp [dmod],
end
end nonempty
omit hG
lemma adj_matrix_sq_mul_const_one_of_regular (hd : G.is_regular_of_degree d) :
(G.adj_matrix R) * (λ _ _, 1) = λ _ _, d :=
by { ext x, simp [← hd x, degree] }
lemma adj_matrix_mul_const_one_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) :
(G.adj_matrix (zmod p)) * (λ _ _, 1) = λ _ _, 1 :=
by rw [adj_matrix_sq_mul_const_one_of_regular hd, dmod]
include hG
/-- Modulo a factor of `d-1`, the square and all higher powers of the adjacency matrix
of a `d`-regular friendship graph reduce to the matrix whose entries are all 1. -/
lemma adj_matrix_pow_mod_p_of_regular {p : ℕ} (dmod : (d : zmod p) = 1)
(hd : G.is_regular_of_degree d) {k : ℕ} (hk : 2 ≤ k) :
(G.adj_matrix (zmod p)) ^ k = λ _ _, 1 :=
begin
iterate 2 {cases k with k, { exfalso, linarith, }, },
induction k with k hind,
{ exact adj_matrix_sq_mod_p_of_regular hG dmod hd, },
have h2 : 2 ≤ k.succ.succ := by omega,
rw [pow_succ, hind h2],
exact adj_matrix_mul_const_one_mod_p_of_regular dmod hd,
end
variable [nonempty V]
/-- This is the main proof. Assuming that `3 ≤ d`, we take `p` to be a prime factor of `d-1`.
Then the `p`th power of the adjacency matrix of a `d`-regular friendship graph must have trace 1
mod `p`, but we can also show that the trace must be the `p`th power of the trace of the original
adjacency matrix, which is 0, a contradiction.
-/
lemma false_of_three_le_degree (hd : G.is_regular_of_degree d) (h : 3 ≤ d) : false :=
begin
-- get a prime factor of d - 1
let p : ℕ := (d - 1).min_fac,
have p_dvd_d_pred := (zmod.nat_coe_zmod_eq_zero_iff_dvd _ _).mpr (d - 1).min_fac_dvd,
have dpos : 0 < d := by linarith,
have d_cast : ↑(d - 1) = (d : ℤ) - 1 := by norm_cast,
haveI : fact p.prime := ⟨nat.min_fac_prime (by linarith)⟩,
have hp2 : 2 ≤ p := (fact.out p.prime).two_le,
have dmod : (d : zmod p) = 1,
{ rw [← nat.succ_pred_eq_of_pos dpos, nat.succ_eq_add_one, nat.pred_eq_sub_one],
simp only [add_left_eq_self, nat.cast_add, nat.cast_one],
exact p_dvd_d_pred, },
have Vmod := card_mod_p_of_regular hG dmod hd,
-- now we reduce to a trace calculation
have := zmod.trace_pow_card (G.adj_matrix (zmod p)),
contrapose! this, clear this,
-- the trace is 0 mod p when computed one way
rw [trace_adj_matrix, zero_pow (fact.out p.prime).pos],
-- but the trace is 1 mod p when computed the other way
rw adj_matrix_pow_mod_p_of_regular hG dmod hd hp2,
dunfold fintype.card at Vmod,
simp only [matrix.trace, diag_apply, mul_one, nsmul_eq_mul, linear_map.coe_mk, sum_const],
rw [Vmod, ← nat.cast_one, zmod.nat_coe_zmod_eq_zero_iff_dvd, nat.dvd_one,
nat.min_fac_eq_one_iff],
linarith,
end
/-- If `d ≤ 1`, a `d`-regular friendship graph has at most one vertex, which is
trivially a politician. -/
lemma exists_politician_of_degree_le_one (hd : G.is_regular_of_degree d) (hd1 : d ≤ 1) :
exists_politician G :=
begin
have sq : d * d = d := by { interval_cases d; norm_num },
have h := card_of_regular hG hd,
rw sq at h,
have : fintype.card V ≤ 1,
{ cases fintype.card V with n,
{ exact zero_le _, },
{ have : n = 0,
{ rw [nat.succ_sub_succ_eq_sub, nat.sub_zero] at h,
linarith },
subst n, } },
use classical.arbitrary V,
intros w h, exfalso,
apply h,
apply fintype.card_le_one_iff.mp this,
end
/-- If `d = 2`, a `d`-regular friendship graph has 3 vertices, so it must be complete graph,
and all the vertices are politicians. -/
lemma neighbor_finset_eq_of_degree_eq_two (hd : G.is_regular_of_degree 2) (v : V) :
G.neighbor_finset v = finset.univ.erase v :=
begin
apply finset.eq_of_subset_of_card_le,
{ rw finset.subset_iff,
intro x,
rw [mem_neighbor_finset, finset.mem_erase],
exact λ h, ⟨(G.ne_of_adj h).symm, finset.mem_univ _⟩ },
convert_to 2 ≤ _,
{ convert_to _ = fintype.card V - 1,
{ have hfr:= card_of_regular hG hd,
linarith },
{ exact finset.card_erase_of_mem (finset.mem_univ _), }, },
{ dsimp [is_regular_of_degree, degree] at hd,
rw hd, }
end
lemma exists_politician_of_degree_eq_two (hd : G.is_regular_of_degree 2) :
exists_politician G :=
begin
have v := classical.arbitrary V,
use v,
intros w hvw,
rw [← mem_neighbor_finset, neighbor_finset_eq_of_degree_eq_two hG hd v, finset.mem_erase],
exact ⟨hvw.symm, finset.mem_univ _⟩,
end
lemma exists_politician_of_degree_le_two (hd : G.is_regular_of_degree d) (h : d ≤ 2) :
exists_politician G :=
begin
interval_cases d,
iterate 2 { apply exists_politician_of_degree_le_one hG hd, norm_num },
{ exact exists_politician_of_degree_eq_two hG hd },
end
end friendship
/-- We wish to show that a friendship graph has a politician (a vertex adjacent to all others).
We proceed by contradiction, and assume the graph has no politician.
We have already proven that a friendship graph with no politician is `d`-regular for some `d`,
and now we do casework on `d`.
If the degree is at most 2, we observe by casework that it has a politician anyway.
If the degree is at least 3, the graph cannot exist. -/
theorem friendship_theorem [nonempty V] : exists_politician G :=
begin
by_contradiction npG,
rcases hG.is_regular_of_not_exists_politician npG with ⟨d, dreg⟩,
have h : d ≤ 2 ∨ 3 ≤ d := by omega,
cases h with dle2 dge3,
{ exact npG (hG.exists_politician_of_degree_le_two dreg dle2) },
{ exact hG.false_of_three_le_degree dreg dge3 },
end
|
27fd200ff12135ef33e19f1684e9e39832ba5d88 | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/measure_theory/integral/set_integral.lean | 2e86adca2624563c3836c4949cd19091bf0257c3 | [
"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 | 43,906 | lean | /-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Yury Kudryashov
-/
import measure_theory.integral.integrable_on
import measure_theory.integral.bochner
import order.filter.indicator_function
/-!
# Set integral
In this file we prove some properties of `∫ x in s, f x ∂μ`. Recall that this notation
is defined as `∫ x, f x ∂(μ.restrict s)`. In `integral_indicator` we prove that for a measurable
function `f` and a measurable set `s` this definition coincides with another natural definition:
`∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ`, where `indicator s f x` is equal to `f x` for `x ∈ s`
and is zero otherwise.
Since `∫ x in s, f x ∂μ` is a notation, one can rewrite or apply any theorem about `∫ x, f x ∂μ`
directly. In this file we prove some theorems about dependence of `∫ x in s, f x ∂μ` on `s`, e.g.
`integral_union`, `integral_empty`, `integral_univ`.
We use the property `integrable_on f s μ := integrable f (μ.restrict s)`, defined in
`measure_theory.integrable_on`. We also defined in that same file a predicate
`integrable_at_filter (f : α → E) (l : filter α) (μ : measure α)` saying that `f` is integrable at
some set `s ∈ l`.
Finally, we prove a version of the
[Fundamental theorem of calculus](https://en.wikipedia.org/wiki/Fundamental_theorem_of_calculus)
for set integral, see `filter.tendsto.integral_sub_linear_is_o_ae` and its corollaries.
Namely, consider a measurably generated filter `l`, a measure `μ` finite at this filter, and
a function `f` that has a finite limit `c` at `l ⊓ μ.ae`. Then `∫ x in s, f x ∂μ = μ s • c + o(μ s)`
as `s` tends to `l.lift' powerset`, i.e. for any `ε>0` there exists `t ∈ l` such that
`∥∫ x in s, f x ∂μ - μ s • c∥ ≤ ε * μ s` whenever `s ⊆ t`. We also formulate a version of this
theorem for a locally finite measure `μ` and a function `f` continuous at a point `a`.
## Notation
We provide the following notations for expressing the integral of a function on a set :
* `∫ a in s, f a ∂μ` is `measure_theory.integral (μ.restrict s) f`
* `∫ a in s, f a` is `∫ a in s, f a ∂volume`
Note that the set notations are defined in the file `measure_theory/integral/bochner`,
but we reference them here because all theorems about set integrals are in this file.
-/
noncomputable theory
open set filter topological_space measure_theory function
open_locale classical topological_space interval big_operators filter ennreal nnreal measure_theory
variables {α β E F : Type*} [measurable_space α]
namespace measure_theory
section normed_group
variables [normed_group E] [measurable_space E] {f g : α → E} {s t : set α} {μ ν : measure α}
{l l' : filter α} [borel_space E] [second_countable_topology E]
variables [complete_space E] [normed_space ℝ E]
lemma set_integral_congr_ae (hs : measurable_set s) (h : ∀ᵐ x ∂μ, x ∈ s → f x = g x) :
∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ :=
integral_congr_ae ((ae_restrict_iff' hs).2 h)
lemma set_integral_congr (hs : measurable_set s) (h : eq_on f g s) :
∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ :=
set_integral_congr_ae hs $ eventually_of_forall h
lemma set_integral_congr_set_ae (hst : s =ᵐ[μ] t) :
∫ x in s, f x ∂μ = ∫ x in t, f x ∂μ :=
by rw restrict_congr_set hst
lemma integral_union (hst : disjoint s t) (hs : measurable_set s) (ht : measurable_set t)
(hfs : integrable_on f s μ) (hft : integrable_on f t μ) :
∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ :=
by simp only [integrable_on, measure.restrict_union hst hs ht, integral_add_measure hfs hft]
lemma integral_union_ae (hst : (s ∩ t : set α) =ᵐ[μ] (∅ : set α)) (hs : measurable_set s)
(ht : measurable_set t) (hfs : integrable_on f s μ) (hft : integrable_on f t μ) :
∫ x in s ∪ t, f x ∂μ = ∫ x in s, f x ∂μ + ∫ x in t, f x ∂μ :=
begin
have : s =ᵐ[μ] s \ t,
{ refine (hst.mem_iff.mono _).set_eq, simp },
rw [← diff_union_self, integral_union disjoint_diff.symm, set_integral_congr_set_ae this],
exacts [hs.diff ht, ht, hfs.mono_set (diff_subset _ _), hft]
end
lemma integral_diff (hs : measurable_set s) (ht : measurable_set t) (hfs : integrable_on f s μ)
(hft : integrable_on f t μ) (hts : t ⊆ s) :
∫ x in s \ t, f x ∂μ = ∫ x in s, f x ∂μ - ∫ x in t, f x ∂μ :=
begin
rw [eq_sub_iff_add_eq, ← integral_union, diff_union_of_subset hts],
exacts [disjoint_diff.symm, hs.diff ht, ht, hfs.mono_set (diff_subset _ _), hft]
end
lemma integral_finset_bUnion {ι : Type*} (t : finset ι) {s : ι → set α}
(hs : ∀ i ∈ t, measurable_set (s i)) (h's : pairwise_on ↑t (disjoint on s))
(hf : ∀ i ∈ t, integrable_on f (s i) μ) :
∫ x in (⋃ i ∈ t, s i), f x ∂ μ = ∑ i in t, ∫ x in s i, f x ∂ μ :=
begin
induction t using finset.induction_on with a t hat IH hs h's,
{ simp },
{ simp only [finset.coe_insert, finset.forall_mem_insert, set.pairwise_on_insert,
finset.set_bUnion_insert] at hs hf h's ⊢,
rw [integral_union _ hs.1 _ hf.1 (integrable_on_finset_Union.2 hf.2)],
{ rw [finset.sum_insert hat, IH hs.2 h's.1 hf.2] },
{ simp only [disjoint_Union_right],
exact (λ i hi, (h's.2 i hi (ne_of_mem_of_not_mem hi hat).symm).1) },
{ exact finset.measurable_set_bUnion _ hs.2 } }
end
lemma integral_fintype_Union {ι : Type*} [fintype ι] {s : ι → set α}
(hs : ∀ i, measurable_set (s i)) (h's : pairwise (disjoint on s))
(hf : ∀ i, integrable_on f (s i) μ) :
∫ x in (⋃ i, s i), f x ∂ μ = ∑ i, ∫ x in s i, f x ∂ μ :=
begin
convert integral_finset_bUnion finset.univ (λ i hi, hs i) _ (λ i _, hf i),
{ simp },
{ simp [pairwise_on_univ, h's] }
end
lemma integral_empty : ∫ x in ∅, f x ∂μ = 0 := by rw [measure.restrict_empty, integral_zero_measure]
lemma integral_univ : ∫ x in univ, f x ∂μ = ∫ x, f x ∂μ := by rw [measure.restrict_univ]
lemma integral_add_compl (hs : measurable_set s) (hfi : integrable f μ) :
∫ x in s, f x ∂μ + ∫ x in sᶜ, f x ∂μ = ∫ x, f x ∂μ :=
by rw [← integral_union (@disjoint_compl_right (set α) _ _) hs hs.compl
hfi.integrable_on hfi.integrable_on, union_compl_self, integral_univ]
/-- For a function `f` and a measurable set `s`, the integral of `indicator s f`
over the whole space is equal to `∫ x in s, f x ∂μ` defined as `∫ x, f x ∂(μ.restrict s)`. -/
lemma integral_indicator (hs : measurable_set s) :
∫ x, indicator s f x ∂μ = ∫ x in s, f x ∂μ :=
begin
by_cases hf : ae_measurable f (μ.restrict s), swap,
{ rw integral_non_ae_measurable hf,
rw [← ae_measurable_indicator_iff hs] at hf,
exact integral_non_ae_measurable hf },
by_cases hfi : integrable_on f s μ, swap,
{ rwa [integral_undef, integral_undef],
rwa integrable_indicator_iff hs },
calc ∫ x, indicator s f x ∂μ = ∫ x in s, indicator s f x ∂μ + ∫ x in sᶜ, indicator s f x ∂μ :
(integral_add_compl hs (hfi.indicator hs)).symm
... = ∫ x in s, f x ∂μ + ∫ x in sᶜ, 0 ∂μ :
congr_arg2 (+) (integral_congr_ae (indicator_ae_eq_restrict hs))
(integral_congr_ae (indicator_ae_eq_restrict_compl hs))
... = ∫ x in s, f x ∂μ : by simp
end
lemma tendsto_set_integral_of_monotone {ι : Type*} [encodable ι] [semilattice_sup ι]
{s : ι → set α} {f : α → E} (hsm : ∀ i, measurable_set (s i))
(h_mono : monotone s) (hfi : integrable_on f (⋃ n, s n) μ) :
tendsto (λ i, ∫ a in s i, f a ∂μ) at_top (𝓝 (∫ a in (⋃ n, s n), f a ∂μ)) :=
begin
have hfi' : ∫⁻ x in ⋃ n, s n, ∥f x∥₊ ∂μ < ∞ := hfi.2,
set S := ⋃ i, s i,
have hSm : measurable_set S := measurable_set.Union hsm,
have hsub : ∀ {i}, s i ⊆ S, from subset_Union s,
rw [← with_density_apply _ hSm] at hfi',
set ν := μ.with_density (λ x, ∥f x∥₊) with hν,
refine metric.nhds_basis_closed_ball.tendsto_right_iff.2 (λ ε ε0, _),
lift ε to ℝ≥0 using ε0.le,
have : ∀ᶠ i in at_top, ν (s i) ∈ Icc (ν S - ε) (ν S + ε),
from tendsto_measure_Union hsm h_mono (ennreal.Icc_mem_nhds hfi'.ne (ennreal.coe_pos.2 ε0).ne'),
refine this.mono (λ i hi, _),
rw [mem_closed_ball_iff_norm', ← integral_diff hSm (hsm i) hfi (hfi.mono_set hsub) hsub,
← coe_nnnorm, nnreal.coe_le_coe, ← ennreal.coe_le_coe],
refine (ennnorm_integral_le_lintegral_ennnorm _).trans _,
rw [← with_density_apply _ (hSm.diff (hsm _)), ← hν, measure_diff hsub hSm (hsm _)],
exacts [ennreal.sub_le_of_sub_le hi.1,
(hi.2.trans_lt $ ennreal.add_lt_top.2 ⟨hfi', ennreal.coe_lt_top⟩).ne]
end
lemma has_sum_integral_Union {ι : Type*} [encodable ι] {s : ι → set α} {f : α → E}
(hm : ∀ i, measurable_set (s i)) (hd : pairwise (disjoint on s))
(hfi : integrable_on f (⋃ i, s i) μ) :
has_sum (λ n, ∫ a in s n, f a ∂ μ) (∫ a in ⋃ n, s n, f a ∂μ) :=
begin
have hfi' : ∀ i, integrable_on f (s i) μ, from λ i, hfi.mono_set (subset_Union _ _),
simp only [has_sum, ← integral_finset_bUnion _ (λ i _, hm i) (hd.pairwise_on _) (λ i _, hfi' i)],
rw Union_eq_Union_finset at hfi ⊢,
exact tendsto_set_integral_of_monotone (λ t, t.measurable_set_bUnion (λ i _, hm i))
(λ t₁ t₂ h, bUnion_subset_bUnion_left h) hfi
end
lemma integral_Union {ι : Type*} [encodable ι] {s : ι → set α} {f : α → E}
(hm : ∀ i, measurable_set (s i)) (hd : pairwise (disjoint on s))
(hfi : integrable_on f (⋃ i, s i) μ) :
(∫ a in (⋃ n, s n), f a ∂μ) = ∑' n, ∫ a in s n, f a ∂ μ :=
(has_sum.tsum_eq (has_sum_integral_Union hm hd hfi)).symm
lemma set_integral_eq_zero_of_forall_eq_zero {f : α → E} (hf : measurable f)
(ht_eq : ∀ x ∈ t, f x = 0) :
∫ x in t, f x ∂μ = 0 :=
begin
refine integral_eq_zero_of_ae _,
rw [eventually_eq, ae_restrict_iff (measurable_set_eq_fun hf measurable_zero)],
refine eventually_of_forall (λ x hx, _),
rw pi.zero_apply,
exact ht_eq x hx,
end
private lemma set_integral_union_eq_left_of_disjoint {f : α → E} (hf : measurable f)
(hfi : integrable f μ) (hs : measurable_set s) (ht : measurable_set t) (ht_eq : ∀ x ∈ t, f x = 0)
(hs_disj : disjoint s t) :
∫ x in (s ∪ t), f x ∂μ = ∫ x in s, f x ∂μ :=
by rw [integral_union hs_disj hs ht hfi.integrable_on hfi.integrable_on,
set_integral_eq_zero_of_forall_eq_zero hf ht_eq, add_zero]
lemma set_integral_union_eq_left {f : α → E} (hf : measurable f) (hfi : integrable f μ)
(hs : measurable_set s) (ht : measurable_set t) (ht_eq : ∀ x ∈ t, f x = 0) :
∫ x in (s ∪ t), f x ∂μ = ∫ x in s, f x ∂μ :=
begin
let s_ := s \ {x | f x = 0},
have hs_ : measurable_set s_, from hs.diff (measurable_set_eq_fun hf measurable_const),
let s0 := s ∩ {x | f x = 0},
have hs0 : measurable_set s0, from hs.inter (measurable_set_eq_fun hf measurable_const),
have hs0_eq : ∀ x ∈ s0, f x = 0,
by { intros x hx, simp_rw [s0, set.mem_inter_iff] at hx, exact hx.2, },
have h_s_union : s = s_ ∪ s0, from (set.diff_union_inter s _).symm,
have h_s_disj : disjoint s_ s0,
from (@disjoint_sdiff_self_left (set α) {x | f x = 0} s _).mono_right
(set.inter_subset_right _ _),
rw [h_s_union, set_integral_union_eq_left_of_disjoint hf hfi hs_ hs0 hs0_eq h_s_disj],
have hst0_eq : ∀ x ∈ s0 ∪ t, f x = 0,
{ intros x hx,
rw set.mem_union at hx,
cases hx,
{ exact hs0_eq x hx, },
{ exact ht_eq x hx, }, },
have hst_disj : disjoint s_ (s0 ∪ t),
{ rw [← set.sup_eq_union, disjoint_sup_right],
exact ⟨h_s_disj, (@disjoint_sdiff_self_left (set α) {x | f x = 0} s _).mono_right ht_eq⟩, },
rw set.union_assoc,
exact set_integral_union_eq_left_of_disjoint hf hfi hs_ (hs0.union ht) hst0_eq hst_disj,
end
lemma set_integral_neg_eq_set_integral_nonpos [linear_order E] [order_closed_topology E]
{f : α → E} (hf : measurable f) (hfi : integrable f μ) :
∫ x in {x | f x < 0}, f x ∂μ = ∫ x in {x | f x ≤ 0}, f x ∂μ :=
begin
have h_union : {x | f x ≤ 0} = {x | f x < 0} ∪ {x | f x = 0},
by { ext, simp_rw [set.mem_union_eq, set.mem_set_of_eq], exact le_iff_lt_or_eq, },
rw h_union,
exact (set_integral_union_eq_left hf hfi (measurable_set_lt hf measurable_const)
(measurable_set_eq_fun hf measurable_const) (λ x hx, hx)).symm,
end
lemma integral_norm_eq_pos_sub_neg {f : α → ℝ} (hf : measurable f) (hfi : integrable f μ) :
∫ x, ∥f x∥ ∂μ = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ :=
have h_meas : measurable_set {x | 0 ≤ f x}, from measurable_set_le measurable_const hf,
calc ∫ x, ∥f x∥ ∂μ = ∫ x in {x | 0 ≤ f x}, ∥f x∥ ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ∥f x∥ ∂μ :
by rw ← integral_add_compl h_meas hfi.norm
... = ∫ x in {x | 0 ≤ f x}, f x ∂μ + ∫ x in {x | 0 ≤ f x}ᶜ, ∥f x∥ ∂μ :
begin
congr' 1,
refine set_integral_congr h_meas (λ x hx, _),
dsimp only,
rw [real.norm_eq_abs, abs_eq_self.mpr _],
exact hx,
end
... = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | 0 ≤ f x}ᶜ, f x ∂μ :
begin
congr' 1,
rw ← integral_neg,
refine set_integral_congr h_meas.compl (λ x hx, _),
dsimp only,
rw [real.norm_eq_abs, abs_eq_neg_self.mpr _],
rw [set.mem_compl_iff, set.nmem_set_of_eq] at hx,
linarith,
end
... = ∫ x in {x | 0 ≤ f x}, f x ∂μ - ∫ x in {x | f x ≤ 0}, f x ∂μ :
by { rw ← set_integral_neg_eq_set_integral_nonpos hf hfi, congr, ext1 x, simp, }
lemma set_integral_const (c : E) : ∫ x in s, c ∂μ = (μ s).to_real • c :=
by rw [integral_const, measure.restrict_apply_univ]
@[simp]
lemma integral_indicator_const (e : E) ⦃s : set α⦄ (s_meas : measurable_set s) :
∫ (a : α), s.indicator (λ (x : α), e) a ∂μ = (μ s).to_real • e :=
by rw [integral_indicator s_meas, ← set_integral_const]
lemma set_integral_indicator_const_Lp {p : ℝ≥0∞} (hs : measurable_set s) (ht : measurable_set t)
(hμt : μ t ≠ ∞) (x : E) :
∫ a in s, indicator_const_Lp p ht hμt x a ∂μ = (μ (t ∩ s)).to_real • x :=
calc ∫ a in s, indicator_const_Lp p ht hμt x a ∂μ
= (∫ a in s, t.indicator (λ _, x) a ∂μ) :
by rw set_integral_congr_ae hs (indicator_const_Lp_coe_fn.mono (λ x hx hxs, hx))
... = (μ (t ∩ s)).to_real • x : by rw [integral_indicator_const _ ht, measure.restrict_apply ht]
lemma integral_indicator_const_Lp {p : ℝ≥0∞} (ht : measurable_set t) (hμt : μ t ≠ ∞) (x : E) :
∫ a, indicator_const_Lp p ht hμt x a ∂μ = (μ t).to_real • x :=
calc ∫ a, indicator_const_Lp p ht hμt x a ∂μ
= ∫ a in univ, indicator_const_Lp p ht hμt x a ∂μ : by rw integral_univ
... = (μ (t ∩ univ)).to_real • x : set_integral_indicator_const_Lp measurable_set.univ ht hμt x
... = (μ t).to_real • x : by rw inter_univ
lemma set_integral_map {β} [measurable_space β] {g : α → β} {f : β → E} {s : set β}
(hs : measurable_set s) (hf : ae_measurable f (measure.map g μ)) (hg : measurable g) :
∫ y in s, f y ∂(measure.map g μ) = ∫ x in g ⁻¹' s, f (g x) ∂μ :=
begin
rw [measure.restrict_map hg hs, integral_map hg (hf.mono_measure _)],
exact measure.map_mono g measure.restrict_le_self
end
lemma set_integral_map_of_closed_embedding [topological_space α] [borel_space α]
{β} [measurable_space β] [topological_space β] [borel_space β]
{g : α → β} {f : β → E} {s : set β} (hs : measurable_set s) (hg : closed_embedding g) :
∫ y in s, f y ∂(measure.map g μ) = ∫ x in g ⁻¹' s, f (g x) ∂μ :=
begin
rw [measure.restrict_map hg.measurable hs, integral_map_of_closed_embedding hg],
apply_instance,
end
lemma set_integral_map_equiv {β} [measurable_space β] (e : α ≃ᵐ β) (f : β → E) (s : set β) :
∫ y in s, f y ∂(measure.map e μ) = ∫ x in e ⁻¹' s, f (e x) ∂μ :=
by rw [e.restrict_map, integral_map_equiv]
lemma norm_set_integral_le_of_norm_le_const_ae {C : ℝ} (hs : μ s < ∞)
(hC : ∀ᵐ x ∂μ.restrict s, ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
begin
rw ← measure.restrict_apply_univ at *,
haveI : is_finite_measure (μ.restrict s) := ⟨‹_›⟩,
exact norm_integral_le_of_norm_le_const hC
end
lemma norm_set_integral_le_of_norm_le_const_ae' {C : ℝ} (hs : μ s < ∞)
(hC : ∀ᵐ x ∂μ, x ∈ s → ∥f x∥ ≤ C) (hfm : ae_measurable f (μ.restrict s)) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
begin
apply norm_set_integral_le_of_norm_le_const_ae hs,
have A : ∀ᵐ (x : α) ∂μ, x ∈ s → ∥ae_measurable.mk f hfm x∥ ≤ C,
{ filter_upwards [hC, hfm.ae_mem_imp_eq_mk],
assume a h1 h2 h3,
rw [← h2 h3],
exact h1 h3 },
have B : measurable_set {x | ∥(hfm.mk f) x∥ ≤ C} := hfm.measurable_mk.norm measurable_set_Iic,
filter_upwards [hfm.ae_eq_mk, (ae_restrict_iff B).2 A],
assume a h1 h2,
rwa h1
end
lemma norm_set_integral_le_of_norm_le_const_ae'' {C : ℝ} (hs : μ s < ∞) (hsm : measurable_set s)
(hC : ∀ᵐ x ∂μ, x ∈ s → ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae hs $ by rwa [ae_restrict_eq hsm, eventually_inf_principal]
lemma norm_set_integral_le_of_norm_le_const {C : ℝ} (hs : μ s < ∞)
(hC : ∀ x ∈ s, ∥f x∥ ≤ C) (hfm : ae_measurable f (μ.restrict s)) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae' hs (eventually_of_forall hC) hfm
lemma norm_set_integral_le_of_norm_le_const' {C : ℝ} (hs : μ s < ∞) (hsm : measurable_set s)
(hC : ∀ x ∈ s, ∥f x∥ ≤ C) :
∥∫ x in s, f x ∂μ∥ ≤ C * (μ s).to_real :=
norm_set_integral_le_of_norm_le_const_ae'' hs hsm $ eventually_of_forall hC
lemma set_integral_eq_zero_iff_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f)
(hfi : integrable_on f s μ) :
∫ x in s, f x ∂μ = 0 ↔ f =ᵐ[μ.restrict s] 0 :=
integral_eq_zero_iff_of_nonneg_ae hf hfi
lemma set_integral_pos_iff_support_of_nonneg_ae {f : α → ℝ} (hf : 0 ≤ᵐ[μ.restrict s] f)
(hfi : integrable_on f s μ) :
0 < ∫ x in s, f x ∂μ ↔ 0 < μ (support f ∩ s) :=
begin
rw [integral_pos_iff_support_of_nonneg_ae hf hfi, restrict_apply_of_null_measurable_set],
exact hfi.ae_measurable.null_measurable_set (measurable_set_singleton 0).compl
end
lemma set_integral_trim {α} {m m0 : measurable_space α} {μ : measure α} (hm : m ≤ m0) {f : α → E}
(hf_meas : @measurable _ _ m _ f) {s : set α} (hs : measurable_set[m] s) :
∫ x in s, f x ∂μ = ∫ x in s, f x ∂(μ.trim hm) :=
by rwa [integral_trim hm hf_meas, restrict_trim hm μ]
end normed_group
section mono
variables {μ : measure α} {f g : α → ℝ} {s t : set α}
(hf : integrable_on f s μ) (hg : integrable_on g s μ)
lemma set_integral_mono_ae_restrict (h : f ≤ᵐ[μ.restrict s] g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
integral_mono_ae hf hg h
lemma set_integral_mono_ae (h : f ≤ᵐ[μ] g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
set_integral_mono_ae_restrict hf hg (ae_restrict_of_ae h)
lemma set_integral_mono_on (hs : measurable_set s) (h : ∀ x ∈ s, f x ≤ g x) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
set_integral_mono_ae_restrict hf hg
(by simp [hs, eventually_le, eventually_inf_principal, ae_of_all _ h])
include hf hg -- why do I need this include, but we don't need it in other lemmas?
lemma set_integral_mono_on_ae (hs : measurable_set s) (h : ∀ᵐ x ∂μ, x ∈ s → f x ≤ g x) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
by { refine set_integral_mono_ae_restrict hf hg _, rwa [eventually_le, ae_restrict_iff' hs], }
omit hf hg
lemma set_integral_mono (h : f ≤ g) :
∫ a in s, f a ∂μ ≤ ∫ a in s, g a ∂μ :=
integral_mono hf hg h
lemma set_integral_mono_set (hfi : integrable f μ) (hf : 0 ≤ᵐ[μ] f) (hst : s ≤ᵐ[μ] t) :
∫ x in s, f x ∂μ ≤ ∫ x in t, f x ∂μ :=
begin
repeat { rw integral_eq_lintegral_of_nonneg_ae (ae_restrict_of_ae hf)
(hfi.1.mono_measure measure.restrict_le_self) },
rw ennreal.to_real_le_to_real
(ne_of_lt $ (has_finite_integral_iff_of_real (ae_restrict_of_ae hf)).mp hfi.integrable_on.2)
(ne_of_lt $ (has_finite_integral_iff_of_real (ae_restrict_of_ae hf)).mp hfi.integrable_on.2),
exact (lintegral_mono_set' hst),
end
end mono
section nonneg
variables {μ : measure α} {f : α → ℝ} {s : set α}
lemma set_integral_nonneg_of_ae_restrict (hf : 0 ≤ᵐ[μ.restrict s] f) :
0 ≤ ∫ a in s, f a ∂μ :=
integral_nonneg_of_ae hf
lemma set_integral_nonneg_of_ae (hf : 0 ≤ᵐ[μ] f) : 0 ≤ ∫ a in s, f a ∂μ :=
set_integral_nonneg_of_ae_restrict (ae_restrict_of_ae hf)
lemma set_integral_nonneg (hs : measurable_set s) (hf : ∀ a, a ∈ s → 0 ≤ f a) :
0 ≤ ∫ a in s, f a ∂μ :=
set_integral_nonneg_of_ae_restrict ((ae_restrict_iff' hs).mpr (ae_of_all μ hf))
lemma set_integral_nonneg_ae (hs : measurable_set s) (hf : ∀ᵐ a ∂μ, a ∈ s → 0 ≤ f a) :
0 ≤ ∫ a in s, f a ∂μ :=
set_integral_nonneg_of_ae_restrict $ by rwa [eventually_le, ae_restrict_iff' hs]
lemma set_integral_le_nonneg {s : set α} (hs : measurable_set s) (hf : measurable f)
(hfi : integrable f μ) :
∫ x in s, f x ∂μ ≤ ∫ x in {y | 0 ≤ f y}, f x ∂μ :=
begin
rw [← integral_indicator hs, ← integral_indicator (measurable_set_le measurable_const hf)],
exact integral_mono (hfi.indicator hs) (hfi.indicator (measurable_set_le measurable_const hf))
(indicator_le_indicator_nonneg s f),
end
lemma set_integral_nonpos_of_ae_restrict (hf : f ≤ᵐ[μ.restrict s] 0) :
∫ a in s, f a ∂μ ≤ 0 :=
integral_nonpos_of_ae hf
lemma set_integral_nonpos_of_ae (hf : f ≤ᵐ[μ] 0) : ∫ a in s, f a ∂μ ≤ 0 :=
set_integral_nonpos_of_ae_restrict (ae_restrict_of_ae hf)
lemma set_integral_nonpos (hs : measurable_set s) (hf : ∀ a, a ∈ s → f a ≤ 0) :
∫ a in s, f a ∂μ ≤ 0 :=
set_integral_nonpos_of_ae_restrict ((ae_restrict_iff' hs).mpr (ae_of_all μ hf))
lemma set_integral_nonpos_ae (hs : measurable_set s) (hf : ∀ᵐ a ∂μ, a ∈ s → f a ≤ 0) :
∫ a in s, f a ∂μ ≤ 0 :=
set_integral_nonpos_of_ae_restrict $ by rwa [eventually_le, ae_restrict_iff' hs]
lemma set_integral_nonpos_le {s : set α} (hs : measurable_set s) {f : α → ℝ} (hf : measurable f)
(hfi : integrable f μ) :
∫ x in {y | f y ≤ 0}, f x ∂μ ≤ ∫ x in s, f x ∂μ :=
begin
rw [← integral_indicator hs, ← integral_indicator (measurable_set_le hf measurable_const)],
exact integral_mono (hfi.indicator (measurable_set_le hf measurable_const)) (hfi.indicator hs)
(indicator_nonpos_le_indicator s f),
end
end nonneg
section tendsto_mono
variables {μ : measure α}
[measurable_space E] [normed_group E] [borel_space E] [complete_space E] [normed_space ℝ E]
[second_countable_topology E] {s : ℕ → set α} {f : α → E}
lemma _root_.antitone.tendsto_set_integral (hsm : ∀ i, measurable_set (s i))
(h_anti : antitone s) (hfi : integrable_on f (s 0) μ) :
tendsto (λi, ∫ a in s i, f a ∂μ) at_top (𝓝 (∫ a in (⋂ n, s n), f a ∂μ)) :=
begin
let bound : α → ℝ := indicator (s 0) (λ a, ∥f a∥),
have h_int_eq : (λ i, ∫ a in s i, f a ∂μ) = (λ i, ∫ a, (s i).indicator f a ∂μ),
from funext (λ i, (integral_indicator (hsm i)).symm),
rw h_int_eq,
rw ← integral_indicator (measurable_set.Inter hsm),
refine tendsto_integral_of_dominated_convergence bound _ _ _ _ _,
{ intro n,
rw ae_measurable_indicator_iff (hsm n),
exact (integrable_on.mono_set hfi (h_anti (zero_le n))).1 },
{ rw ae_measurable_indicator_iff (measurable_set.Inter hsm),
exact (integrable_on.mono_set hfi (set.Inter_subset s 0)).1, },
{ rw integrable_indicator_iff (hsm 0),
exact hfi.norm, },
{ simp_rw norm_indicator_eq_indicator_norm,
refine λ n, eventually_of_forall (λ x, _),
exact indicator_le_indicator_of_subset (h_anti (zero_le n)) (λ a, norm_nonneg _) _ },
{ filter_upwards [] λ a, le_trans (h_anti.tendsto_indicator _ _ _) (pure_le_nhds _) }
end
end tendsto_mono
/-! ### Continuity of the set integral
We prove that for any set `s`, the function `λ f : α →₁[μ] E, ∫ x in s, f x ∂μ` is continuous. -/
section continuous_set_integral
variables [normed_group E] [measurable_space E] [second_countable_topology E] [borel_space E]
{𝕜 : Type*} [is_R_or_C 𝕜] [measurable_space 𝕜]
[normed_group F] [measurable_space F] [second_countable_topology F] [borel_space F]
[normed_space 𝕜 F]
{p : ℝ≥0∞} {μ : measure α}
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map is additive. -/
lemma Lp_to_Lp_restrict_add (f g : Lp E p μ) (s : set α) :
((Lp.mem_ℒp (f + g)).restrict s).to_Lp ⇑(f + g)
= ((Lp.mem_ℒp f).restrict s).to_Lp f + ((Lp.mem_ℒp g).restrict s).to_Lp g :=
begin
ext1,
refine (ae_restrict_of_ae (Lp.coe_fn_add f g)).mp _,
refine (Lp.coe_fn_add (mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s))
(mem_ℒp.to_Lp g ((Lp.mem_ℒp g).restrict s))).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp g).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp (f+g)).restrict s)).mono (λ x hx1 hx2 hx3 hx4 hx5, _),
rw [hx4, hx1, pi.add_apply, hx2, hx3, hx5, pi.add_apply],
end
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map commutes with scalar multiplication. -/
lemma Lp_to_Lp_restrict_smul [opens_measurable_space 𝕜] (c : 𝕜) (f : Lp F p μ) (s : set α) :
((Lp.mem_ℒp (c • f)).restrict s).to_Lp ⇑(c • f) = c • (((Lp.mem_ℒp f).restrict s).to_Lp f) :=
begin
ext1,
refine (ae_restrict_of_ae (Lp.coe_fn_smul c f)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)).mp _,
refine (mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp (c • f)).restrict s)).mp _,
refine (Lp.coe_fn_smul c (mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s))).mono
(λ x hx1 hx2 hx3 hx4, _),
rw [hx2, hx1, pi.smul_apply, hx3, hx4, pi.smul_apply],
end
/-- For `f : Lp E p μ`, we can define an element of `Lp E p (μ.restrict s)` by
`(Lp.mem_ℒp f).restrict s).to_Lp f`. This map is non-expansive. -/
lemma norm_Lp_to_Lp_restrict_le (s : set α) (f : Lp E p μ) :
∥((Lp.mem_ℒp f).restrict s).to_Lp f∥ ≤ ∥f∥ :=
begin
rw [Lp.norm_def, Lp.norm_def, ennreal.to_real_le_to_real (Lp.snorm_ne_top _) (Lp.snorm_ne_top _)],
refine (le_of_eq _).trans (snorm_mono_measure _ measure.restrict_le_self),
{ exact s, },
exact snorm_congr_ae (mem_ℒp.coe_fn_to_Lp _),
end
variables (α F 𝕜)
/-- Continuous linear map sending a function of `Lp F p μ` to the same function in
`Lp F p (μ.restrict s)`. -/
def Lp_to_Lp_restrict_clm [borel_space 𝕜] (μ : measure α) (p : ℝ≥0∞) [hp : fact (1 ≤ p)]
(s : set α) :
Lp F p μ →L[𝕜] Lp F p (μ.restrict s) :=
@linear_map.mk_continuous 𝕜 (Lp F p μ) (Lp F p (μ.restrict s)) _ _ _ _ _
⟨λ f, mem_ℒp.to_Lp f ((Lp.mem_ℒp f).restrict s), λ f g, Lp_to_Lp_restrict_add f g s,
λ c f, Lp_to_Lp_restrict_smul c f s⟩
1 (by { intro f, rw one_mul, exact norm_Lp_to_Lp_restrict_le s f, })
variables {α F 𝕜}
variables (𝕜)
lemma Lp_to_Lp_restrict_clm_coe_fn [borel_space 𝕜] [hp : fact (1 ≤ p)] (s : set α) (f : Lp F p μ) :
Lp_to_Lp_restrict_clm α F 𝕜 μ p s f =ᵐ[μ.restrict s] f :=
mem_ℒp.coe_fn_to_Lp ((Lp.mem_ℒp f).restrict s)
variables {𝕜}
@[continuity]
lemma continuous_set_integral [normed_space ℝ E] [complete_space E] (s : set α) :
continuous (λ f : α →₁[μ] E, ∫ x in s, f x ∂μ) :=
begin
haveI : fact ((1 : ℝ≥0∞) ≤ 1) := ⟨le_rfl⟩,
have h_comp : (λ f : α →₁[μ] E, ∫ x in s, f x ∂μ)
= (integral (μ.restrict s)) ∘ (λ f, Lp_to_Lp_restrict_clm α E ℝ μ 1 s f),
{ ext1 f,
rw [function.comp_apply, integral_congr_ae (Lp_to_Lp_restrict_clm_coe_fn ℝ s f)], },
rw h_comp,
exact continuous_integral.comp (Lp_to_Lp_restrict_clm α E ℝ μ 1 s).continuous,
end
end continuous_set_integral
end measure_theory
open measure_theory asymptotics metric
variables {ι : Type*} [measurable_space E] [normed_group E]
/-- Fundamental theorem of calculus for set integrals: if `μ` is a measure that is finite at a
filter `l` and `f` is a measurable function that has a finite limit `b` at `l ⊓ μ.ae`, then `∫ x in
s i, f x ∂μ = μ (s i) • b + o(μ (s i))` at a filter `li` provided that `s i` tends to `l.lift'
powerset` along `li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the
actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma filter.tendsto.integral_sub_linear_is_o_ae
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} {l : filter α} [l.is_measurably_generated]
{f : α → E} {b : E} (h : tendsto f (l ⊓ μ.ae) (𝓝 b))
(hfm : measurable_at_filter f l μ) (hμ : μ.finite_at_filter l)
{s : ι → set α} {li : filter ι} (hs : tendsto s li (l.lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • b) m li :=
begin
suffices : is_o (λ s, ∫ x in s, f x ∂μ - (μ s).to_real • b) (λ s, (μ s).to_real)
(l.lift' powerset),
from (this.comp_tendsto hs).congr' (hsμ.mono $ λ a ha, ha ▸ rfl) hsμ,
refine is_o_iff.2 (λ ε ε₀, _),
have : ∀ᶠ s in l.lift' powerset, ∀ᶠ x in μ.ae, x ∈ s → f x ∈ closed_ball b ε :=
eventually_lift'_powerset_eventually.2 (h.eventually $ closed_ball_mem_nhds _ ε₀),
filter_upwards [hμ.eventually, (hμ.integrable_at_filter_of_tendsto_ae hfm h).eventually,
hfm.eventually, this],
simp only [mem_closed_ball, dist_eq_norm],
intros s hμs h_integrable hfm h_norm,
rw [← set_integral_const, ← integral_sub h_integrable (integrable_on_const.2 $ or.inr hμs),
real.norm_eq_abs, abs_of_nonneg ennreal.to_real_nonneg],
exact norm_set_integral_le_of_norm_le_const_ae' hμs h_norm (hfm.sub ae_measurable_const)
end
/-- Fundamental theorem of calculus for set integrals, `nhds_within` version: if `μ` is a locally
finite measure and `f` is an almost everywhere measurable function that is continuous at a point `a`
within a measurable set `t`, then `∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at a filter `li`
provided that `s i` tends to `(𝓝[t] a).lift' powerset` along `li`. Since `μ (s i)` is an `ℝ≥0∞`
number, we use `(μ (s i)).to_real` in the actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_within_at.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [is_locally_finite_measure μ] {a : α} {t : set α}
{f : α → E} (ha : continuous_within_at f t a) (ht : measurable_set t)
(hfm : measurable_at_filter f (𝓝[t] a) μ)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝[t] a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
by haveI : (𝓝[t] a).is_measurably_generated := ht.nhds_within_is_measurably_generated _;
exact (ha.mono_left inf_le_left).integral_sub_linear_is_o_ae
hfm (μ.finite_at_nhds_within a t) hs m hsμ
/-- Fundamental theorem of calculus for set integrals, `nhds` version: if `μ` is a locally finite
measure and `f` is an almost everywhere measurable function that is continuous at a point `a`, then
`∫ x in s i, f x ∂μ = μ (s i) • f a + o(μ (s i))` at `li` provided that `s` tends to `(𝓝 a).lift'
powerset` along `li. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the
actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_at.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [is_locally_finite_measure μ] {a : α}
{f : α → E} (ha : continuous_at f a) (hfm : measurable_at_filter f (𝓝 a) μ)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝 a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
(ha.mono_left inf_le_left).integral_sub_linear_is_o_ae hfm (μ.finite_at_nhds a) hs m hsμ
/-- If a function is continuous on an open set `s`, then it is measurable at the filter `𝓝 x` for
all `x ∈ s`. -/
lemma continuous_on.measurable_at_filter
[topological_space α] [opens_measurable_space α] [measurable_space β] [topological_space β]
[borel_space β]
{f : α → β} {s : set α} {μ : measure α} (hs : is_open s) (hf : continuous_on f s) :
∀ x ∈ s, measurable_at_filter f (𝓝 x) μ :=
λ x hx, ⟨s, is_open.mem_nhds hs hx, hf.ae_measurable hs.measurable_set⟩
lemma continuous_at.measurable_at_filter
[topological_space α] [opens_measurable_space α] [borel_space E]
{f : α → E} {s : set α} {μ : measure α} (hs : is_open s) (hf : ∀ x ∈ s, continuous_at f x) :
∀ x ∈ s, measurable_at_filter f (𝓝 x) μ :=
continuous_on.measurable_at_filter hs $ continuous_at.continuous_on hf
lemma continuous.measurable_at_filter [topological_space α] [opens_measurable_space α]
[measurable_space β] [topological_space β] [borel_space β] {f : α → β} (hf : continuous f)
(μ : measure α) (l : filter α) :
measurable_at_filter f l μ :=
hf.measurable.measurable_at_filter
/-- If a function is continuous on a measurable set `s`, then it is measurable at the filter
`𝓝[s] x` for all `x`. -/
lemma continuous_on.measurable_at_filter_nhds_within {α β : Type*} [measurable_space α]
[topological_space α] [opens_measurable_space α] [measurable_space β] [topological_space β]
[borel_space β] {f : α → β} {s : set α} {μ : measure α}
(hf : continuous_on f s) (hs : measurable_set s) (x : α) :
measurable_at_filter f (𝓝[s] x) μ :=
⟨s, self_mem_nhds_within, hf.ae_measurable hs⟩
/-- Fundamental theorem of calculus for set integrals, `nhds_within` version: if `μ` is a locally
finite measure, `f` is continuous on a measurable set `t`, and `a ∈ t`, then `∫ x in (s i), f x ∂μ =
μ (s i) • f a + o(μ (s i))` at `li` provided that `s i` tends to `(𝓝[t] a).lift' powerset` along
`li`. Since `μ (s i)` is an `ℝ≥0∞` number, we use `(μ (s i)).to_real` in the actual statement.
Often there is a good formula for `(μ (s i)).to_real`, so the formalization can take an optional
argument `m` with this formula and a proof `of `(λ i, (μ (s i)).to_real) =ᶠ[li] m`. Without these
arguments, `m i = (μ (s i)).to_real` is used in the output. -/
lemma continuous_on.integral_sub_linear_is_o_ae
[topological_space α] [opens_measurable_space α]
[normed_space ℝ E] [second_countable_topology E] [complete_space E] [borel_space E]
{μ : measure α} [is_locally_finite_measure μ] {a : α} {t : set α}
{f : α → E} (hft : continuous_on f t) (ha : a ∈ t) (ht : measurable_set t)
{s : ι → set α} {li : filter ι} (hs : tendsto s li ((𝓝[t] a).lift' powerset))
(m : ι → ℝ := λ i, (μ (s i)).to_real)
(hsμ : (λ i, (μ (s i)).to_real) =ᶠ[li] m . tactic.interactive.refl) :
is_o (λ i, ∫ x in s i, f x ∂μ - m i • f a) m li :=
(hft a ha).integral_sub_linear_is_o_ae ht ⟨t, self_mem_nhds_within, hft.ae_measurable ht⟩ hs m hsμ
section
/-! ### Continuous linear maps composed with integration
The goal of this section is to prove that integration commutes with continuous linear maps.
This holds for simple functions. The general result follows from the continuity of all involved
operations on the space `L¹`. Note that composition by a continuous linear map on `L¹` is not just
the composition, as we are dealing with classes of functions, but it has already been defined
as `continuous_linear_map.comp_Lp`. We take advantage of this construction here.
-/
variables {μ : measure α} {𝕜 : Type*} [is_R_or_C 𝕜] [normed_space 𝕜 E]
[normed_group F] [normed_space 𝕜 F]
{p : ennreal}
local attribute [instance] fact_one_le_one_ennreal
namespace continuous_linear_map
variables [measurable_space F] [borel_space F]
variables [second_countable_topology F] [complete_space F]
[borel_space E] [second_countable_topology E] [normed_space ℝ F]
lemma integral_comp_Lp (L : E →L[𝕜] F) (φ : Lp E p μ) :
∫ a, (L.comp_Lp φ) a ∂μ = ∫ a, L (φ a) ∂μ :=
integral_congr_ae $ coe_fn_comp_Lp _ _
lemma set_integral_comp_Lp (L : E →L[𝕜] F) (φ : Lp E p μ) {s : set α} (hs : measurable_set s) :
∫ a in s, (L.comp_Lp φ) a ∂μ = ∫ a in s, L (φ a) ∂μ :=
set_integral_congr_ae hs ((L.coe_fn_comp_Lp φ).mono (λ x hx hx2, hx))
lemma continuous_integral_comp_L1 [measurable_space 𝕜] [opens_measurable_space 𝕜] (L : E →L[𝕜] F) :
continuous (λ (φ : α →₁[μ] E), ∫ (a : α), L (φ a) ∂μ) :=
by { rw ← funext L.integral_comp_Lp, exact continuous_integral.comp (L.comp_LpL 1 μ).continuous, }
variables [complete_space E] [measurable_space 𝕜] [opens_measurable_space 𝕜]
[normed_space ℝ E] [is_scalar_tower ℝ 𝕜 E] [is_scalar_tower ℝ 𝕜 F]
lemma integral_comp_comm (L : E →L[𝕜] F) {φ : α → E} (φ_int : integrable φ μ) :
∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
begin
apply integrable.induction (λ φ, ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ)),
{ intros e s s_meas s_finite,
rw [integral_indicator_const e s_meas, ← @smul_one_smul E ℝ 𝕜 _ _ _ _ _ (μ s).to_real e,
continuous_linear_map.map_smul, @smul_one_smul F ℝ 𝕜 _ _ _ _ _ (μ s).to_real (L e),
← integral_indicator_const (L e) s_meas],
congr' 1 with a,
rw set.indicator_comp_of_zero L.map_zero },
{ intros f g H f_int g_int hf hg,
simp [L.map_add, integral_add f_int g_int,
integral_add (L.integrable_comp f_int) (L.integrable_comp g_int), hf, hg] },
{ exact is_closed_eq L.continuous_integral_comp_L1 (L.continuous.comp continuous_integral) },
{ intros f g hfg f_int hf,
convert hf using 1 ; clear hf,
{ exact integral_congr_ae (hfg.fun_comp L).symm },
{ rw integral_congr_ae hfg.symm } },
all_goals { assumption }
end
lemma integral_apply {H : Type*} [normed_group H] [normed_space ℝ H]
[second_countable_topology $ H →L[ℝ] E] {φ : α → H →L[ℝ] E} (φ_int : integrable φ μ) (v : H) :
(∫ a, φ a ∂μ) v = ∫ a, φ a v ∂μ :=
((continuous_linear_map.apply ℝ E v).integral_comp_comm φ_int).symm
lemma integral_comp_comm' (L : E →L[𝕜] F) {K} (hL : antilipschitz_with K L) (φ : α → E) :
∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
begin
by_cases h : integrable φ μ,
{ exact integral_comp_comm L h },
have : ¬ (integrable (L ∘ φ) μ),
by rwa lipschitz_with.integrable_comp_iff_of_antilipschitz L.lipschitz hL (L.map_zero),
simp [integral_undef, h, this]
end
lemma integral_comp_L1_comm (L : E →L[𝕜] F) (φ : α →₁[μ] E) : ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
L.integral_comp_comm (L1.integrable_coe_fn φ)
end continuous_linear_map
namespace linear_isometry
variables [measurable_space F] [borel_space F] [second_countable_topology F] [complete_space F]
[normed_space ℝ F] [is_scalar_tower ℝ 𝕜 F]
[borel_space E] [second_countable_topology E] [complete_space E] [normed_space ℝ E]
[is_scalar_tower ℝ 𝕜 E]
[measurable_space 𝕜] [opens_measurable_space 𝕜]
lemma integral_comp_comm (L : E →ₗᵢ[𝕜] F) (φ : α → E) : ∫ a, L (φ a) ∂μ = L (∫ a, φ a ∂μ) :=
L.to_continuous_linear_map.integral_comp_comm' L.antilipschitz _
end linear_isometry
variables [borel_space E] [second_countable_topology E] [complete_space E] [normed_space ℝ E]
[measurable_space F] [borel_space F] [second_countable_topology F] [complete_space F]
[normed_space ℝ F]
[measurable_space 𝕜] [borel_space 𝕜]
@[norm_cast] lemma integral_of_real {f : α → ℝ} : ∫ a, (f a : 𝕜) ∂μ = ↑∫ a, f a ∂μ :=
(@is_R_or_C.of_real_li 𝕜 _).integral_comp_comm f
lemma integral_re {f : α → 𝕜} (hf : integrable f μ) :
∫ a, is_R_or_C.re (f a) ∂μ = is_R_or_C.re ∫ a, f a ∂μ :=
(@is_R_or_C.re_clm 𝕜 _).integral_comp_comm hf
lemma integral_im {f : α → 𝕜} (hf : integrable f μ) :
∫ a, is_R_or_C.im (f a) ∂μ = is_R_or_C.im ∫ a, f a ∂μ :=
(@is_R_or_C.im_clm 𝕜 _).integral_comp_comm hf
lemma integral_conj {f : α → 𝕜} : ∫ a, is_R_or_C.conj (f a) ∂μ = is_R_or_C.conj ∫ a, f a ∂μ :=
(@is_R_or_C.conj_lie 𝕜 _).to_linear_isometry.integral_comp_comm f
lemma fst_integral {f : α → E × F} (hf : integrable f μ) :
(∫ x, f x ∂μ).1 = ∫ x, (f x).1 ∂μ :=
((continuous_linear_map.fst ℝ E F).integral_comp_comm hf).symm
lemma snd_integral {f : α → E × F} (hf : integrable f μ) :
(∫ x, f x ∂μ).2 = ∫ x, (f x).2 ∂μ :=
((continuous_linear_map.snd ℝ E F).integral_comp_comm hf).symm
lemma integral_pair {f : α → E} {g : α → F} (hf : integrable f μ) (hg : integrable g μ) :
∫ x, (f x, g x) ∂μ = (∫ x, f x ∂μ, ∫ x, g x ∂μ) :=
have _ := hf.prod_mk hg, prod.ext (fst_integral this) (snd_integral this)
lemma integral_smul_const (f : α → ℝ) (c : E) :
∫ x, f x • c ∂μ = (∫ x, f x ∂μ) • c :=
begin
by_cases hf : integrable f μ,
{ exact ((continuous_linear_map.id ℝ ℝ).smul_right c).integral_comp_comm hf },
{ by_cases hc : c = 0,
{ simp only [hc, integral_zero, smul_zero] },
rw [integral_undef hf, integral_undef, zero_smul],
simp_rw [integrable_smul_const hc, hf, not_false_iff] }
end
section inner
variables {E' : Type*} [inner_product_space 𝕜 E'] [measurable_space E'] [borel_space E']
[second_countable_topology E'] [complete_space E'] [normed_space ℝ E'] [is_scalar_tower ℝ 𝕜 E']
local notation `⟪`x`, `y`⟫` := @inner 𝕜 E' _ x y
lemma integral_inner {f : α → E'} (hf : integrable f μ) (c : E') :
∫ x, ⟪c, f x⟫ ∂μ = ⟪c, ∫ x, f x ∂μ⟫ :=
((@inner_right 𝕜 E' _ _ c).restrict_scalars ℝ).integral_comp_comm hf
lemma integral_eq_zero_of_forall_integral_inner_eq_zero (f : α → E') (hf : integrable f μ)
(hf_int : ∀ (c : E'), ∫ x, ⟪c, f x⟫ ∂μ = 0) :
∫ x, f x ∂μ = 0 :=
by { specialize hf_int (∫ x, f x ∂μ), rwa [integral_inner hf, inner_self_eq_zero] at hf_int }
end inner
end
|
54d37d7b5d65840fc7eb7f9599127367e89e501c | 57c233acf9386e610d99ed20ef139c5f97504ba3 | /src/category_theory/over.lean | 58b3fd21501440c814a4beb31436d4d5407343b5 | [
"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 | 11,760 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Bhavik Mehta
-/
import category_theory.structured_arrow
import category_theory.punit
import category_theory.reflects_isomorphisms
import category_theory.epi_mono
/-!
# Over and under categories
Over (and under) categories are special cases of comma categories.
* If `L` is the identity functor and `R` is a constant functor, then `comma L R` is the "slice" or
"over" category over the object `R` maps to.
* Conversely, if `L` is a constant functor and `R` is the identity functor, then `comma L R` is the
"coslice" or "under" category under the object `L` maps to.
## Tags
comma, slice, coslice, over, under
-/
namespace category_theory
universes v₁ v₂ u₁ u₂ -- morphism levels before object levels. See note [category_theory universes].
variables {T : Type u₁} [category.{v₁} T]
/--
The over category has as objects arrows in `T` with codomain `X` and as morphisms commutative
triangles.
See https://stacks.math.columbia.edu/tag/001G.
-/
@[derive category]
def over (X : T) := costructured_arrow (𝟭 T) X
-- Satisfying the inhabited linter
instance over.inhabited [inhabited T] : inhabited (over (default : T)) :=
{ default :=
{ left := default,
hom := 𝟙 _ } }
namespace over
variables {X : T}
@[ext] lemma over_morphism.ext {X : T} {U V : over X} {f g : U ⟶ V}
(h : f.left = g.left) : f = g :=
by tidy
@[simp] lemma over_right (U : over X) : U.right = punit.star := by tidy
@[simp] lemma id_left (U : over X) : comma_morphism.left (𝟙 U) = 𝟙 U.left := rfl
@[simp] lemma comp_left (a b c : over X) (f : a ⟶ b) (g : b ⟶ c) :
(f ≫ g).left = f.left ≫ g.left := rfl
@[simp, reassoc] lemma w {A B : over X} (f : A ⟶ B) : f.left ≫ B.hom = A.hom :=
by have := f.w; tidy
/-- To give an object in the over category, it suffices to give a morphism with codomain `X`. -/
@[simps]
def mk {X Y : T} (f : Y ⟶ X) : over X :=
costructured_arrow.mk f
/-- We can set up a coercion from arrows with codomain `X` to `over X`. This most likely should not
be a global instance, but it is sometimes useful. -/
def coe_from_hom {X Y : T} : has_coe (Y ⟶ X) (over X) :=
{ coe := mk }
section
local attribute [instance] coe_from_hom
@[simp] lemma coe_hom {X Y : T} (f : Y ⟶ X) : (f : over X).hom = f := rfl
end
/-- To give a morphism in the over category, it suffices to give an arrow fitting in a commutative
triangle. -/
@[simps]
def hom_mk {U V : over X} (f : U.left ⟶ V.left) (w : f ≫ V.hom = U.hom . obviously) :
U ⟶ V :=
costructured_arrow.hom_mk f w
/--
Construct an isomorphism in the over category given isomorphisms of the objects whose forward
direction gives a commutative triangle.
-/
@[simps]
def iso_mk {f g : over X} (hl : f.left ≅ g.left) (hw : hl.hom ≫ g.hom = f.hom . obviously) :
f ≅ g :=
costructured_arrow.iso_mk hl hw
section
variable (X)
/--
The forgetful functor mapping an arrow to its domain.
See https://stacks.math.columbia.edu/tag/001G.
-/
def forget : over X ⥤ T := comma.fst _ _
end
@[simp] lemma forget_obj {U : over X} : (forget X).obj U = U.left := rfl
@[simp] lemma forget_map {U V : over X} {f : U ⟶ V} : (forget X).map f = f.left := rfl
/-- The natural cocone over the forgetful functor `over X ⥤ T` with cocone point `X`. -/
@[simps] def forget_cocone (X : T) : limits.cocone (forget X) :=
{ X := X, ι := { app := comma.hom } }
/--
A morphism `f : X ⟶ Y` induces a functor `over X ⥤ over Y` in the obvious way.
See https://stacks.math.columbia.edu/tag/001G.
-/
def map {Y : T} (f : X ⟶ Y) : over X ⥤ over Y := comma.map_right _ $ discrete.nat_trans (λ _, f)
section
variables {Y : T} {f : X ⟶ Y} {U V : over X} {g : U ⟶ V}
@[simp] lemma map_obj_left : ((map f).obj U).left = U.left := rfl
@[simp] lemma map_obj_hom : ((map f).obj U).hom = U.hom ≫ f := rfl
@[simp] lemma map_map_left : ((map f).map g).left = g.left := rfl
/-- Mapping by the identity morphism is just the identity functor. -/
def map_id : map (𝟙 Y) ≅ 𝟭 _ :=
nat_iso.of_components (λ X, iso_mk (iso.refl _) (by tidy)) (by tidy)
/-- Mapping by the composite morphism `f ≫ g` is the same as mapping by `f` then by `g`. -/
def map_comp {Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) ≅ map f ⋙ map g :=
nat_iso.of_components (λ X, iso_mk (iso.refl _) (by tidy)) (by tidy)
end
instance forget_reflects_iso : reflects_isomorphisms (forget X) :=
{ reflects := λ Y Z f t, by exactI
⟨⟨over.hom_mk (inv ((forget X).map f))
((as_iso ((forget X).map f)).inv_comp_eq.2 (over.w f).symm),
by tidy⟩⟩ }
instance forget_faithful : faithful (forget X) := {}.
/--
If `k.left` is an epimorphism, then `k` is an epimorphism. In other words, `over.forget X` reflects
epimorphisms.
The converse does not hold without additional assumptions on the underlying category.
-/
-- TODO: Show the converse holds if `T` has binary products or pushouts.
lemma epi_of_epi_left {f g : over X} (k : f ⟶ g) [hk : epi k.left] : epi k :=
faithful_reflects_epi (forget X) hk
/--
If `k.left` is a monomorphism, then `k` is a monomorphism. In other words, `over.forget X` reflects
monomorphisms.
The converse of `category_theory.over.mono_left_of_mono`.
This lemma is not an instance, to avoid loops in type class inference.
-/
lemma mono_of_mono_left {f g : over X} (k : f ⟶ g) [hk : mono k.left] : mono k :=
faithful_reflects_mono (forget X) hk
/--
If `k` is a monomorphism, then `k.left` is a monomorphism. In other words, `over.forget X` preserves
monomorphisms.
The converse of `category_theory.over.mono_of_mono_left`.
-/
instance mono_left_of_mono {f g : over X} (k : f ⟶ g) [mono k] : mono k.left :=
begin
refine ⟨λ (Y : T) l m a, _⟩,
let l' : mk (m ≫ f.hom) ⟶ f := hom_mk l (by { dsimp, rw [←over.w k, reassoc_of a] }),
suffices : l' = hom_mk m,
{ apply congr_arg comma_morphism.left this },
rw ← cancel_mono k,
ext,
apply a,
end
section iterated_slice
variables (f : over X)
/-- Given f : Y ⟶ X, this is the obvious functor from (T/X)/f to T/Y -/
@[simps]
def iterated_slice_forward : over f ⥤ over f.left :=
{ obj := λ α, over.mk α.hom.left,
map := λ α β κ, over.hom_mk κ.left.left (by { rw auto_param_eq, rw ← over.w κ, refl }) }
/-- Given f : Y ⟶ X, this is the obvious functor from T/Y to (T/X)/f -/
@[simps]
def iterated_slice_backward : over f.left ⥤ over f :=
{ obj := λ g, mk (hom_mk g.hom : mk (g.hom ≫ f.hom) ⟶ f),
map := λ g h α, hom_mk (hom_mk α.left (w_assoc α f.hom)) (over_morphism.ext (w α)) }
/-- Given f : Y ⟶ X, we have an equivalence between (T/X)/f and T/Y -/
@[simps]
def iterated_slice_equiv : over f ≌ over f.left :=
{ functor := iterated_slice_forward f,
inverse := iterated_slice_backward f,
unit_iso :=
nat_iso.of_components
(λ g, over.iso_mk (over.iso_mk (iso.refl _) (by tidy)) (by tidy))
(λ X Y g, by { ext, dsimp, simp }),
counit_iso :=
nat_iso.of_components
(λ g, over.iso_mk (iso.refl _) (by tidy))
(λ X Y g, by { ext, dsimp, simp }) }
lemma iterated_slice_forward_forget :
iterated_slice_forward f ⋙ forget f.left = forget f ⋙ forget X :=
rfl
lemma iterated_slice_backward_forget_forget :
iterated_slice_backward f ⋙ forget f ⋙ forget X = forget f.left :=
rfl
end iterated_slice
section
variables {D : Type u₂} [category.{v₂} D]
/-- A functor `F : T ⥤ D` induces a functor `over X ⥤ over (F.obj X)` in the obvious way. -/
@[simps]
def post (F : T ⥤ D) : over X ⥤ over (F.obj X) :=
{ obj := λ Y, mk $ F.map Y.hom,
map := λ Y₁ Y₂ f,
{ left := F.map f.left,
w' := by tidy; erw [← F.map_comp, w] } }
end
end over
/-- The under category has as objects arrows with domain `X` and as morphisms commutative
triangles. -/
@[derive category]
def under (X : T) := structured_arrow X (𝟭 T)
-- Satisfying the inhabited linter
instance under.inhabited [inhabited T] : inhabited (under (default : T)) :=
{ default :=
{ right := default,
hom := 𝟙 _ } }
namespace under
variables {X : T}
@[ext] lemma under_morphism.ext {X : T} {U V : under X} {f g : U ⟶ V}
(h : f.right = g.right) : f = g :=
by tidy
@[simp] lemma under_left (U : under X) : U.left = punit.star := by tidy
@[simp] lemma id_right (U : under X) : comma_morphism.right (𝟙 U) = 𝟙 U.right := rfl
@[simp] lemma comp_right (a b c : under X) (f : a ⟶ b) (g : b ⟶ c) :
(f ≫ g).right = f.right ≫ g.right := rfl
@[simp, reassoc] lemma w {A B : under X} (f : A ⟶ B) : A.hom ≫ f.right = B.hom :=
by have := f.w; tidy
/-- To give an object in the under category, it suffices to give an arrow with domain `X`. -/
@[simps]
def mk {X Y : T} (f : X ⟶ Y) : under X :=
structured_arrow.mk f
/-- To give a morphism in the under category, it suffices to give a morphism fitting in a
commutative triangle. -/
@[simps]
def hom_mk {U V : under X} (f : U.right ⟶ V.right) (w : U.hom ≫ f = V.hom . obviously) :
U ⟶ V :=
structured_arrow.hom_mk f w
/--
Construct an isomorphism in the over category given isomorphisms of the objects whose forward
direction gives a commutative triangle.
-/
def iso_mk {f g : under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom) : f ≅ g :=
structured_arrow.iso_mk hr hw
@[simp]
lemma iso_mk_hom_right {f g : under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom) :
(iso_mk hr hw).hom.right = hr.hom := rfl
@[simp]
lemma iso_mk_inv_right {f g : under X} (hr : f.right ≅ g.right) (hw : f.hom ≫ hr.hom = g.hom) :
(iso_mk hr hw).inv.right = hr.inv := rfl
section
variables (X)
/-- The forgetful functor mapping an arrow to its domain. -/
def forget : under X ⥤ T := comma.snd _ _
end
@[simp] lemma forget_obj {U : under X} : (forget X).obj U = U.right := rfl
@[simp] lemma forget_map {U V : under X} {f : U ⟶ V} : (forget X).map f = f.right := rfl
/-- The natural cone over the forgetful functor `under X ⥤ T` with cone point `X`. -/
@[simps] def forget_cone (X : T) : limits.cone (forget X) :=
{ X := X, π := { app := comma.hom } }
/-- A morphism `X ⟶ Y` induces a functor `under Y ⥤ under X` in the obvious way. -/
def map {Y : T} (f : X ⟶ Y) : under Y ⥤ under X := comma.map_left _ $ discrete.nat_trans (λ _, f)
section
variables {Y : T} {f : X ⟶ Y} {U V : under Y} {g : U ⟶ V}
@[simp] lemma map_obj_right : ((map f).obj U).right = U.right := rfl
@[simp] lemma map_obj_hom : ((map f).obj U).hom = f ≫ U.hom := rfl
@[simp] lemma map_map_right : ((map f).map g).right = g.right := rfl
/-- Mapping by the identity morphism is just the identity functor. -/
def map_id : map (𝟙 Y) ≅ 𝟭 _ :=
nat_iso.of_components (λ X, iso_mk (iso.refl _) (by tidy)) (by tidy)
/-- Mapping by the composite morphism `f ≫ g` is the same as mapping by `f` then by `g`. -/
def map_comp {Y Z : T} (f : X ⟶ Y) (g : Y ⟶ Z) : map (f ≫ g) ≅ map g ⋙ map f :=
nat_iso.of_components (λ X, iso_mk (iso.refl _) (by tidy)) (by tidy)
end
instance forget_reflects_iso : reflects_isomorphisms (forget X) :=
{ reflects := λ Y Z f t, by exactI
⟨⟨under.hom_mk (inv ((under.forget X).map f)) ((is_iso.comp_inv_eq _).2 (under.w f).symm),
by tidy⟩⟩ }
instance forget_faithful : faithful (forget X) := {}.
section
variables {D : Type u₂} [category.{v₂} D]
/-- A functor `F : T ⥤ D` induces a functor `under X ⥤ under (F.obj X)` in the obvious way. -/
@[simps]
def post {X : T} (F : T ⥤ D) : under X ⥤ under (F.obj X) :=
{ obj := λ Y, mk $ F.map Y.hom,
map := λ Y₁ Y₂ f,
{ right := F.map f.right,
w' := by tidy; erw [← F.map_comp, w] } }
end
end under
end category_theory
|
2464438971118be10401ae514a1be7c89741e476 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/coe_auto.lean | a0e75481a15e38631d11753f92db0b7f035b7fd7 | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,758 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.data.list.basic
import Mathlib.Lean3Lib.init.data.subtype.basic
import Mathlib.Lean3Lib.init.data.prod
universes u v l u₁ u₂ u₃ ua₁ ua₂ ub₁ ub₂ ua ub
namespace Mathlib
/-
The elaborator tries to insert coercions automatically.
Only instances of has_coe type class are considered in the process.
Lean also provides a "lifting" operator: ↑a.
It uses all instances of has_lift type class.
Every has_coe instance is also a has_lift instance.
We recommend users only use has_coe for coercions that do not produce a lot
of ambiguity.
All coercions and lifts can be identified with the constant coe.
We use the has_coe_to_fun type class for encoding coercions from
a type to a function space.
We use the has_coe_to_sort type class for encoding coercions from
a type to a sort.
-/
/-- Can perform a lifting operation `↑a`. -/
class has_lift (a : Sort u) (b : Sort v) where
lift : a → b
/-- Auxiliary class that contains the transitive closure of has_lift. -/
class has_lift_t (a : Sort u) (b : Sort v) where
lift : a → b
class has_coe (a : Sort u) (b : Sort v) where
coe : a → b
/-- Auxiliary class that contains the transitive closure of has_coe. -/
class has_coe_t (a : Sort u) (b : Sort v) where
coe : a → b
class has_coe_to_fun (a : Sort u) where
F : a → Sort v
coe : (x : a) → F x
class has_coe_to_sort (a : Sort u) where
S : Sort v
coe : a → S
def lift {a : Sort u} {b : Sort v} [has_lift a b] : a → b := has_lift.lift
def lift_t {a : Sort u} {b : Sort v} [has_lift_t a b] : a → b := has_lift_t.lift
def coe_b {a : Sort u} {b : Sort v} [has_coe a b] : a → b := has_coe.coe
def coe_t {a : Sort u} {b : Sort v} [has_coe_t a b] : a → b := has_coe_t.coe
def coe_fn_b {a : Sort u} [has_coe_to_fun a] (x : a) : has_coe_to_fun.F x := has_coe_to_fun.coe
/- User level coercion operators -/
def coe {a : Sort u} {b : Sort v} [has_lift_t a b] : a → b := lift_t
def coe_fn {a : Sort u} [has_coe_to_fun a] (x : a) : has_coe_to_fun.F x := has_coe_to_fun.coe
def coe_sort {a : Sort u} [has_coe_to_sort a] : a → has_coe_to_sort.S a := has_coe_to_sort.coe
prefix:1024 "↑" => Mathlib.coe
prefix:1024 "⇑" => Mathlib.coe_fn
prefix:1024 "↥" => Mathlib.coe_sort
/- Notation -/
/- Transitive closure for has_lift, has_coe, has_coe_to_fun -/
protected instance lift_trans {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_lift_t b c]
[has_lift a b] : has_lift_t a c :=
has_lift_t.mk fun (x : a) => lift_t (lift x)
protected instance lift_base {a : Sort u} {b : Sort v} [has_lift a b] : has_lift_t a b :=
has_lift_t.mk lift
protected instance coe_trans {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_coe_t b c]
[has_coe a b] : has_coe_t a c :=
has_coe_t.mk fun (x : a) => coe_t (coe_b x)
protected instance coe_base {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t a b :=
has_coe_t.mk coe_b
/- We add this instance directly into has_coe_t to avoid non-termination.
Suppose coe_option had type (has_coe a (option a)).
Then, we can loop when searching a coercion from α to β (has_coe_t α β)
1- coe_trans at (has_coe_t α β)
(has_coe α ?b₁) and (has_coe_t ?b₁ c)
2- coe_option at (has_coe α ?b₁)
?b₁ := option α
3- coe_trans at (has_coe_t (option α) β)
(has_coe (option α) ?b₂) and (has_coe_t ?b₂ β)
4- coe_option at (has_coe (option α) ?b₂)
?b₂ := option (option α))
...
-/
protected instance coe_option {a : Type u} : has_coe_t a (Option a) :=
has_coe_t.mk fun (x : a) => some x
/- Auxiliary transitive closure for has_coe which does not contain
instances such as coe_option.
They would produce non-termination when combined with coe_fn_trans and coe_sort_trans.
-/
class has_coe_t_aux (a : Sort u) (b : Sort v) where
coe : a → b
protected instance coe_trans_aux {a : Sort u₁} {b : Sort u₂} {c : Sort u₃} [has_coe_t_aux b c]
[has_coe a b] : has_coe_t_aux a c :=
has_coe_t_aux.mk fun (x : a) => has_coe_t_aux.coe (coe_b x)
protected instance coe_base_aux {a : Sort u} {b : Sort v} [has_coe a b] : has_coe_t_aux a b :=
has_coe_t_aux.mk coe_b
protected instance coe_fn_trans {a : Sort u₁} {b : Sort u₂} [has_coe_to_fun b] [has_coe_t_aux a b] :
has_coe_to_fun a :=
has_coe_to_fun.mk (fun (x : a) => has_coe_to_fun.F (has_coe_t_aux.coe x))
fun (x : a) => ⇑(has_coe_t_aux.coe x)
protected instance coe_sort_trans {a : Sort u₁} {b : Sort u₂} [has_coe_to_sort b]
[has_coe_t_aux a b] : has_coe_to_sort a :=
has_coe_to_sort.mk (has_coe_to_sort.S b) fun (x : a) => ↥(has_coe_t_aux.coe x)
/- Every coercion is also a lift -/
protected instance coe_to_lift {a : Sort u} {b : Sort v} [has_coe_t a b] : has_lift_t a b :=
has_lift_t.mk coe_t
/- basic coercions -/
protected instance coe_bool_to_Prop : has_coe Bool Prop := has_coe.mk fun (y : Bool) => y = tt
/- Tactics such as the simplifier only unfold reducible constants when checking whether two terms are definitionally
equal or a term is a proposition. The motivation is performance.
In particular, when simplifying `p -> q`, the tactic `simp` only visits `p` if it can establish that it is a proposition.
Thus, we mark the following instance as @[reducible], otherwise `simp` will not visit `↑p` when simplifying `↑p -> q`.
-/
protected instance coe_sort_bool : has_coe_to_sort Bool :=
has_coe_to_sort.mk Prop fun (y : Bool) => y = tt
protected instance coe_decidable_eq (x : Bool) : Decidable ↑x :=
(fun (this : Decidable (x = tt)) => this) (bool.decidable_eq x tt)
protected instance coe_subtype {a : Sort u} {p : a → Prop} :
has_coe (Subtype fun (x : a) => p x) a :=
has_coe.mk subtype.val
/- basic lifts -/
/- Remark: we can't use [has_lift_t a₂ a₁] since it will produce non-termination whenever a type class resolution
problem does not have a solution. -/
protected instance lift_fn {a₁ : Sort ua₁} {a₂ : Sort ua₂} {b₁ : Sort ub₁} {b₂ : Sort ub₂}
[has_lift a₂ a₁] [has_lift_t b₁ b₂] : has_lift (a₁ → b₁) (a₂ → b₂) :=
has_lift.mk fun (f : a₁ → b₁) (x : a₂) => ↑(f ↑x)
protected instance lift_fn_range {a : Sort ua} {b₁ : Sort ub₁} {b₂ : Sort ub₂} [has_lift_t b₁ b₂] :
has_lift (a → b₁) (a → b₂) :=
has_lift.mk fun (f : a → b₁) (x : a) => ↑(f x)
protected instance lift_fn_dom {a₁ : Sort ua₁} {a₂ : Sort ua₂} {b : Sort ub} [has_lift a₂ a₁] :
has_lift (a₁ → b) (a₂ → b) :=
has_lift.mk fun (f : a₁ → b) (x : a₂) => f ↑x
protected instance lift_pair {a₁ : Type ua₁} {a₂ : Type ub₂} {b₁ : Type ub₁} {b₂ : Type ub₂}
[has_lift_t a₁ a₂] [has_lift_t b₁ b₂] : has_lift (a₁ × b₁) (a₂ × b₂) :=
has_lift.mk fun (p : a₁ × b₁) => prod.cases_on p fun (x : a₁) (y : b₁) => (↑x, ↑y)
protected instance lift_pair₁ {a₁ : Type ua₁} {a₂ : Type ua₂} {b : Type ub} [has_lift_t a₁ a₂] :
has_lift (a₁ × b) (a₂ × b) :=
has_lift.mk fun (p : a₁ × b) => prod.cases_on p fun (x : a₁) (y : b) => (↑x, y)
protected instance lift_pair₂ {a : Type ua} {b₁ : Type ub₁} {b₂ : Type ub₂} [has_lift_t b₁ b₂] :
has_lift (a × b₁) (a × b₂) :=
has_lift.mk fun (p : a × b₁) => prod.cases_on p fun (x : a) (y : b₁) => (x, ↑y)
protected instance lift_list {a : Type u} {b : Type v} [has_lift_t a b] :
has_lift (List a) (List b) :=
has_lift.mk fun (l : List a) => list.map coe l
end Mathlib |
548e355d8f40ad72068ea76e489ee0ad9db6a0aa | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/field_theory/minpoly/basic.lean | 4a19907b5e23118f937a530bf4a185978b0a9be6 | [
"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 | 8,502 | lean | /-
Copyright (c) 2019 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Johan Commelin
-/
import ring_theory.integral_closure
/-!
# Minimal polynomials
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines the minimal polynomial of an element `x` of an `A`-algebra `B`,
under the assumption that x is integral over `A`, and derives some basic properties
such as ireducibility under the assumption `B` is a domain.
-/
open_locale classical polynomial
open polynomial set function
variables {A B B' : Type*}
section min_poly_def
variables (A) [comm_ring A] [ring B] [algebra A B]
/--
Suppose `x : B`, where `B` is an `A`-algebra.
The minimal polynomial `minpoly A x` of `x`
is a monic polynomial with coefficients in `A` of smallest degree that has `x` as its root,
if such exists (`is_integral A x`) or zero otherwise.
For example, if `V` is a `𝕜`-vector space for some field `𝕜` and `f : V →ₗ[𝕜] V` then
the minimal polynomial of `f` is `minpoly 𝕜 f`.
-/
noncomputable def minpoly (x : B) : A[X] :=
if hx : is_integral A x then degree_lt_wf.min _ hx else 0
end min_poly_def
namespace minpoly
section ring
variables [comm_ring A] [ring B] [ring B'] [algebra A B] [algebra A B']
variables {x : B}
/-- A minimal polynomial is monic. -/
lemma monic (hx : is_integral A x) : monic (minpoly A x) :=
by { delta minpoly, rw dif_pos hx, exact (degree_lt_wf.min_mem _ hx).1 }
/-- A minimal polynomial is nonzero. -/
lemma ne_zero [nontrivial A] (hx : is_integral A x) : minpoly A x ≠ 0 :=
(monic hx).ne_zero
lemma eq_zero (hx : ¬ is_integral A x) : minpoly A x = 0 :=
dif_neg hx
lemma minpoly_alg_hom (f : B →ₐ[A] B') (hf : function.injective f) (x : B) :
minpoly A (f x) = minpoly A x :=
begin
refine dif_ctx_congr (is_integral_alg_hom_iff _ hf) (λ _, _) (λ _, rfl),
simp_rw [←polynomial.aeval_def, aeval_alg_hom, alg_hom.comp_apply, _root_.map_eq_zero_iff f hf],
end
@[simp] lemma minpoly_alg_equiv (f : B ≃ₐ[A] B') (x : B) : minpoly A (f x) = minpoly A x :=
minpoly_alg_hom (f : B →ₐ[A] B') f.injective x
variables (A x)
/-- An element is a root of its minimal polynomial. -/
@[simp] lemma aeval : aeval x (minpoly A x) = 0 :=
begin
delta minpoly, split_ifs with hx,
{ exact (degree_lt_wf.min_mem _ hx).2 },
{ exact aeval_zero _ }
end
/-- A minimal polynomial is not `1`. -/
lemma ne_one [nontrivial B] : minpoly A x ≠ 1 :=
begin
intro h,
refine (one_ne_zero : (1 : B) ≠ 0) _,
simpa using congr_arg (polynomial.aeval x) h
end
lemma map_ne_one [nontrivial B] {R : Type*} [semiring R] [nontrivial R] (f : A →+* R) :
(minpoly A x).map f ≠ 1 :=
begin
by_cases hx : is_integral A x,
{ exact mt ((monic hx).eq_one_of_map_eq_one f) (ne_one A x) },
{ rw [eq_zero hx, polynomial.map_zero], exact zero_ne_one },
end
/-- A minimal polynomial is not a unit. -/
lemma not_is_unit [nontrivial B] : ¬ is_unit (minpoly A x) :=
begin
haveI : nontrivial A := (algebra_map A B).domain_nontrivial,
by_cases hx : is_integral A x,
{ exact mt (monic hx).eq_one_of_is_unit (ne_one A x) },
{ rw [eq_zero hx], exact not_is_unit_zero }
end
lemma mem_range_of_degree_eq_one (hx : (minpoly A x).degree = 1) : x ∈ (algebra_map A B).range :=
begin
have h : is_integral A x,
{ by_contra h,
rw [eq_zero h, degree_zero, ←with_bot.coe_one] at hx,
exact (ne_of_lt (show ⊥ < ↑1, from with_bot.bot_lt_coe 1) hx) },
have key := minpoly.aeval A x,
rw [eq_X_add_C_of_degree_eq_one hx, (minpoly.monic h).leading_coeff, C_1, one_mul, aeval_add,
aeval_C, aeval_X, ←eq_neg_iff_add_eq_zero, ←ring_hom.map_neg] at key,
exact ⟨-(minpoly A x).coeff 0, key.symm⟩,
end
/-- The defining property of the minimal polynomial of an element `x`:
it is the monic polynomial with smallest degree that has `x` as its root. -/
lemma min {p : A[X]} (pmonic : p.monic) (hp : polynomial.aeval x p = 0) :
degree (minpoly A x) ≤ degree p :=
begin
delta minpoly, split_ifs with hx,
{ exact le_of_not_lt (degree_lt_wf.not_lt_min _ hx ⟨pmonic, hp⟩) },
{ simp only [degree_zero, bot_le] }
end
lemma unique' {p : A[X]} (hm : p.monic) (hp : polynomial.aeval x p = 0)
(hl : ∀ q : A[X], degree q < degree p → q = 0 ∨ polynomial.aeval x q ≠ 0) :
p = minpoly A x :=
begin
nontriviality A,
have hx : is_integral A x := ⟨p, hm, hp⟩,
obtain h | h := hl _ ((minpoly A x).degree_mod_by_monic_lt hm), swap,
{ exact (h $ (aeval_mod_by_monic_eq_self_of_root hm hp).trans $ aeval A x).elim },
obtain ⟨r, hr⟩ := (dvd_iff_mod_by_monic_eq_zero hm).1 h,
rw hr, have hlead := congr_arg leading_coeff hr,
rw [mul_comm, leading_coeff_mul_monic hm, (monic hx).leading_coeff] at hlead,
have : nat_degree r ≤ 0,
{ have hr0 : r ≠ 0 := by { rintro rfl, exact ne_zero hx (mul_zero p ▸ hr) },
apply_fun nat_degree at hr,
rw hm.nat_degree_mul' hr0 at hr,
apply nat.le_of_add_le_add_left,
rw add_zero,
exact hr.symm.trans_le (nat_degree_le_nat_degree $ min A x hm hp) },
rw [eq_C_of_nat_degree_le_zero this, ← nat.eq_zero_of_le_zero this,
← leading_coeff, ← hlead, C_1, mul_one],
end
@[nontriviality] lemma subsingleton [subsingleton B] : minpoly A x = 1 :=
begin
nontriviality A,
have := minpoly.min A x monic_one (subsingleton.elim _ _),
rw degree_one at this,
cases le_or_lt (minpoly A x).degree 0 with h h,
{ rwa (monic ⟨1, monic_one, by simp⟩ : (minpoly A x).monic).degree_le_zero_iff_eq_one at h },
{ exact (this.not_lt h).elim },
end
end ring
section comm_ring
variables [comm_ring A]
section ring
variables [ring B] [algebra A B]
variables {x : B}
/-- The degree of a minimal polynomial, as a natural number, is positive. -/
lemma nat_degree_pos [nontrivial B] (hx : is_integral A x) : 0 < nat_degree (minpoly A x) :=
begin
rw pos_iff_ne_zero,
intro ndeg_eq_zero,
have eq_one : minpoly A x = 1,
{ rw eq_C_of_nat_degree_eq_zero ndeg_eq_zero, convert C_1,
simpa only [ndeg_eq_zero.symm] using (monic hx).leading_coeff },
simpa only [eq_one, alg_hom.map_one, one_ne_zero] using aeval A x
end
/-- The degree of a minimal polynomial is positive. -/
lemma degree_pos [nontrivial B] (hx : is_integral A x) : 0 < degree (minpoly A x) :=
nat_degree_pos_iff_degree_pos.mp (nat_degree_pos hx)
/-- If `B/A` is an injective ring extension, and `a` is an element of `A`,
then the minimal polynomial of `algebra_map A B a` is `X - C a`. -/
lemma eq_X_sub_C_of_algebra_map_inj
(a : A) (hf : function.injective (algebra_map A B)) :
minpoly A (algebra_map A B a) = X - C a :=
begin
nontriviality A,
refine (unique' A _ (monic_X_sub_C a) _ _).symm,
{ rw [map_sub, aeval_C, aeval_X, sub_self] },
simp_rw or_iff_not_imp_left,
intros q hl h0,
rw [← nat_degree_lt_nat_degree_iff h0, nat_degree_X_sub_C, nat.lt_one_iff] at hl,
rw eq_C_of_nat_degree_eq_zero hl at h0 ⊢,
rwa [aeval_C, map_ne_zero_iff _ hf, ← C_ne_zero],
end
end ring
section is_domain
variables [ring B] [algebra A B]
variables {x : B}
/-- If `a` strictly divides the minimal polynomial of `x`, then `x` cannot be a root for `a`. -/
lemma aeval_ne_zero_of_dvd_not_unit_minpoly {a : A[X]} (hx : is_integral A x)
(hamonic : a.monic) (hdvd : dvd_not_unit a (minpoly A x)) :
polynomial.aeval x a ≠ 0 :=
begin
refine λ ha, (min A x hamonic ha).not_lt (degree_lt_degree _),
obtain ⟨b, c, hu, he⟩ := hdvd,
have hcm := hamonic.of_mul_monic_left (he.subst $ monic hx),
rw [he, hamonic.nat_degree_mul hcm],
apply nat.lt_add_of_zero_lt_left _ _ (lt_of_not_le $ λ h, hu _),
rw [eq_C_of_nat_degree_le_zero h, ← nat.eq_zero_of_le_zero h,
← leading_coeff, hcm.leading_coeff, C_1],
exact is_unit_one,
end
variables [is_domain A] [is_domain B]
/-- A minimal polynomial is irreducible. -/
lemma irreducible (hx : is_integral A x) : irreducible (minpoly A x) :=
begin
refine (irreducible_of_monic (monic hx) $ ne_one A x).2 (λ f g hf hg he, _),
rw [← hf.is_unit_iff, ← hg.is_unit_iff],
by_contra' h,
have heval := congr_arg (polynomial.aeval x) he,
rw [aeval A x, aeval_mul, mul_eq_zero] at heval,
cases heval,
{ exact aeval_ne_zero_of_dvd_not_unit_minpoly hx hf ⟨hf.ne_zero, g, h.2, he.symm⟩ heval },
{ refine aeval_ne_zero_of_dvd_not_unit_minpoly hx hg ⟨hg.ne_zero, f, h.1, _⟩ heval,
rw [mul_comm, he] },
end
end is_domain
end comm_ring
end minpoly
|
fb5da6f0191724e5fac01294facea31423176451 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /src/Lean/Meta/Tactic/Simp/SimpTheorems.lean | 8b523f8cf99e2d43727d061ce0d6cf0d2eed62f0 | [
"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 | 18,624 | 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
-/
import Lean.ScopedEnvExtension
import Lean.Util.Recognizers
import Lean.Meta.DiscrTree
import Lean.Meta.AppBuilder
import Lean.Meta.Eqns
import Lean.Meta.Tactic.AuxLemma
namespace Lean.Meta
/--
The fields `levelParams` and `proof` are used to encode the proof of the simp theorem.
If the `proof` is a global declaration `c`, we store `Expr.const c []` at `proof` without the universe levels, and `levelParams` is set to `#[]`
When using the lemma, we create fresh universe metavariables.
Motivation: most simp theorems are global declarations, and this approach is faster and saves memory.
The field `levelParams` is not empty only when we elaborate an expression provided by the user, and it contains universe metavariables.
Then, we use `abstractMVars` to abstract the universe metavariables and create new fresh universe parameters that are stored at the field `levelParams`.
-/
structure SimpTheorem where
keys : Array DiscrTree.Key := #[]
/--
It stores universe parameter names for universe polymorphic proofs.
Recall that it is non-empty only when we elaborate an expression provided by the user.
When `proof` is just a constant, we can use the universe parameter names stored in the declaration.
-/
levelParams : Array Name := #[]
proof : Expr
priority : Nat := eval_prio default
post : Bool := true
/-- `perm` is true if lhs and rhs are identical modulo permutation of variables. -/
perm : Bool := false
/--
`name?` is mainly relevant for producing trace messages.
It is also viewed an `id` used to "erase" `simp` theorems from `SimpTheorems`.
-/
name? : Option Name := none
/-- `rfl` is true if `proof` is by `Eq.refl` or `rfl`. -/
rfl : Bool
deriving Inhabited
def SimpTheorem.getName (s : SimpTheorem) : Name :=
match s.name? with
| some n => n
| none => "<unknown>"
mutual
partial def isRflProofCore (type : Expr) (proof : Expr) : CoreM Bool := do
match type with
| .forallE _ _ type _ =>
if let .lam _ _ proof _ := proof then
isRflProofCore type proof
else
return false
| _ =>
if type.isAppOfArity ``Eq 3 then
if proof.isAppOfArity ``Eq.refl 2 || proof.isAppOfArity ``rfl 2 then
return true
else if proof.isAppOfArity ``Eq.symm 4 then
-- `Eq.symm` of rfl theorem is a rfl theorem
isRflProofCore type proof.appArg! -- small hack: we don't need to set the exact type
else if proof.isApp && proof.getAppFn.isConst then
-- The application of a `rfl` theorem is a `rfl` theorem
isRflTheorem proof.getAppFn.constName!
else
return false
else
return false
partial def isRflTheorem (declName : Name) : CoreM Bool := do
let .thmInfo info ← getConstInfo declName | return false
isRflProofCore info.type info.value
end
def isRflProof (proof : Expr) : MetaM Bool := do
if let .const declName .. := proof then
isRflTheorem declName
else
isRflProofCore (← inferType proof) proof
instance : ToFormat SimpTheorem where
format s :=
let perm := if s.perm then ":perm" else ""
let name := format s.getName
let prio := f!":{s.priority}"
name ++ prio ++ perm
instance : ToMessageData SimpTheorem where
toMessageData s := format s
instance : BEq SimpTheorem where
beq e₁ e₂ := e₁.proof == e₂.proof
structure SimpTheorems where
pre : DiscrTree SimpTheorem := DiscrTree.empty
post : DiscrTree SimpTheorem := DiscrTree.empty
lemmaNames : Std.PHashSet Name := {}
toUnfold : Std.PHashSet Name := {}
erased : Std.PHashSet Name := {}
toUnfoldThms : Std.PHashMap Name (Array Name) := {}
deriving Inhabited
def addSimpTheoremEntry (d : SimpTheorems) (e : SimpTheorem) : SimpTheorems :=
if e.post then
{ d with post := d.post.insertCore e.keys e, lemmaNames := updateLemmaNames d.lemmaNames }
else
{ d with pre := d.pre.insertCore e.keys e, lemmaNames := updateLemmaNames d.lemmaNames }
where
updateLemmaNames (s : Std.PHashSet Name) : Std.PHashSet Name :=
match e.name? with
| none => s
| some name => s.insert name
def SimpTheorems.addDeclToUnfoldCore (d : SimpTheorems) (declName : Name) : SimpTheorems :=
{ d with toUnfold := d.toUnfold.insert declName }
/-- Return `true` if `declName` is tagged to be unfolded using `unfoldDefinition?` (i.e., without using equational theorems). -/
def SimpTheorems.isDeclToUnfold (d : SimpTheorems) (declName : Name) : Bool :=
d.toUnfold.contains declName
def SimpTheorems.isLemma (d : SimpTheorems) (declName : Name) : Bool :=
d.lemmaNames.contains declName
/-- Register the equational theorems for the given definition. -/
def SimpTheorems.registerDeclToUnfoldThms (d : SimpTheorems) (declName : Name) (eqThms : Array Name) : SimpTheorems :=
{ d with toUnfoldThms := d.toUnfoldThms.insert declName eqThms }
partial def SimpTheorems.eraseCore (d : SimpTheorems) (declName : Name) : SimpTheorems :=
let d := { d with erased := d.erased.insert declName, lemmaNames := d.lemmaNames.erase declName, toUnfold := d.toUnfold.erase declName }
if let some thms := d.toUnfoldThms.find? declName then
thms.foldl (init := d) eraseCore
else
d
def SimpTheorems.erase [Monad m] [MonadError m] (d : SimpTheorems) (declName : Name) : m SimpTheorems := do
unless d.isLemma declName || d.isDeclToUnfold declName || d.toUnfoldThms.contains declName do
throwError "'{declName}' does not have [simp] attribute"
return d.eraseCore declName
private partial def isPerm : Expr → Expr → MetaM Bool
| Expr.app f₁ a₁, Expr.app f₂ a₂ => isPerm f₁ f₂ <&&> isPerm a₁ a₂
| Expr.mdata _ s, t => isPerm s t
| s, Expr.mdata _ t => isPerm s t
| s@(Expr.mvar ..), t@(Expr.mvar ..) => isDefEq s t
| Expr.forallE n₁ d₁ b₁ _, Expr.forallE _ d₂ b₂ _ => isPerm d₁ d₂ <&&> withLocalDeclD n₁ d₁ fun x => isPerm (b₁.instantiate1 x) (b₂.instantiate1 x)
| Expr.lam n₁ d₁ b₁ _, Expr.lam _ d₂ b₂ _ => isPerm d₁ d₂ <&&> withLocalDeclD n₁ d₁ fun x => isPerm (b₁.instantiate1 x) (b₂.instantiate1 x)
| Expr.letE n₁ t₁ v₁ b₁ _, Expr.letE _ t₂ v₂ b₂ _ =>
isPerm t₁ t₂ <&&> isPerm v₁ v₂ <&&> withLetDecl n₁ t₁ v₁ fun x => isPerm (b₁.instantiate1 x) (b₂.instantiate1 x)
| Expr.proj _ i₁ b₁, Expr.proj _ i₂ b₂ => pure (i₁ == i₂) <&&> isPerm b₁ b₂
| s, t => return s == t
private def checkBadRewrite (lhs rhs : Expr) : MetaM Unit := do
let lhs ← DiscrTree.whnfDT lhs (root := true)
if lhs == rhs && lhs.isFVar then
throwError "invalid `simp` theorem, equation is equivalent to{indentExpr (← mkEq lhs rhs)}"
private partial def shouldPreprocess (type : Expr) : MetaM Bool :=
forallTelescopeReducing type fun _ result => do
if let some (_, lhs, rhs) := result.eq? then
checkBadRewrite lhs rhs
return false
else
return true
private partial def preprocess (e type : Expr) (inv : Bool) (isGlobal : Bool) : MetaM (List (Expr × Expr)) :=
go e type
where
go (e type : Expr) : MetaM (List (Expr × Expr)) := do
let type ← whnf type
if type.isForall then
forallTelescopeReducing type fun xs type => do
let e := mkAppN e xs
let ps ← go e type
ps.mapM fun (e, type) =>
return (← mkLambdaFVars xs e, ← mkForallFVars xs type)
else if let some (_, lhs, rhs) := type.eq? then
if isGlobal then
checkBadRewrite lhs rhs
if inv then
let type ← mkEq rhs lhs
let e ← mkEqSymm e
return [(e, type)]
else
return [(e, type)]
else if let some (lhs, rhs) := type.iff? then
if isGlobal then
checkBadRewrite lhs rhs
if inv then
let type ← mkEq rhs lhs
let e ← mkEqSymm (← mkPropExt e)
return [(e, type)]
else
let type ← mkEq lhs rhs
let e ← mkPropExt e
return [(e, type)]
else if let some (_, lhs, rhs) := type.ne? then
if inv then
throwError "invalid '←' modifier in rewrite rule to 'False'"
if rhs.isConstOf ``Bool.true then
return [(← mkAppM ``Bool.of_not_eq_true #[e], ← mkEq lhs (mkConst ``Bool.false))]
else if rhs.isConstOf ``Bool.false then
return [(← mkAppM ``Bool.of_not_eq_false #[e], ← mkEq lhs (mkConst ``Bool.true))]
let type ← mkEq (← mkEq lhs rhs) (mkConst ``False)
let e ← mkEqFalse e
return [(e, type)]
else if let some p := type.not? then
if inv then
throwError "invalid '←' modifier in rewrite rule to 'False'"
if let some (_, lhs, rhs) := p.eq? then
if rhs.isConstOf ``Bool.true then
return [(← mkAppM ``Bool.of_not_eq_true #[e], ← mkEq lhs (mkConst ``Bool.false))]
else if rhs.isConstOf ``Bool.false then
return [(← mkAppM ``Bool.of_not_eq_false #[e], ← mkEq lhs (mkConst ``Bool.true))]
let type ← mkEq p (mkConst ``False)
let e ← mkEqFalse e
return [(e, type)]
else if let some (type₁, type₂) := type.and? then
let e₁ := mkProj ``And 0 e
let e₂ := mkProj ``And 1 e
return (← go e₁ type₁) ++ (← go e₂ type₂)
else
if inv then
throwError "invalid '←' modifier in rewrite rule to 'True'"
let type ← mkEq type (mkConst ``True)
let e ← mkEqTrue e
return [(e, type)]
private def checkTypeIsProp (type : Expr) : MetaM Unit :=
unless (← isProp type) do
throwError "invalid 'simp', proposition expected{indentExpr type}"
private def mkSimpTheoremCore (e : Expr) (levelParams : Array Name) (proof : Expr) (post : Bool) (prio : Nat) (name? : Option Name) : MetaM SimpTheorem := do
let type ← instantiateMVars (← inferType e)
withNewMCtxDepth do
let (_, _, type) ← withReducible <| forallMetaTelescopeReducing type
let type ← whnfR type
let (keys, perm) ←
match type.eq? with
| some (_, lhs, rhs) => pure (← DiscrTree.mkPath lhs, ← isPerm lhs rhs)
| none => throwError "unexpected kind of 'simp' theorem{indentExpr type}"
return { keys, perm, post, levelParams, proof, name?, priority := prio, rfl := (← isRflProof proof) }
private def mkSimpTheoremsFromConst (declName : Name) (post : Bool) (inv : Bool) (prio : Nat) : MetaM (Array SimpTheorem) := do
let cinfo ← getConstInfo declName
let val := mkConst declName (cinfo.levelParams.map mkLevelParam)
withReducible do
let type ← inferType val
checkTypeIsProp type
if inv || (← shouldPreprocess type) then
let mut r := #[]
for (val, type) in (← preprocess val type inv (isGlobal := true)) do
let auxName ← mkAuxLemma cinfo.levelParams type val
r := r.push <| (← mkSimpTheoremCore (mkConst auxName (cinfo.levelParams.map mkLevelParam)) #[] (mkConst auxName) post prio declName)
return r
else
return #[← mkSimpTheoremCore (mkConst declName (cinfo.levelParams.map mkLevelParam)) #[] (mkConst declName) post prio declName]
inductive SimpEntry where
| thm : SimpTheorem → SimpEntry
| toUnfold : Name → SimpEntry
| toUnfoldThms : Name → Array Name → SimpEntry
deriving Inhabited
abbrev SimpExtension := SimpleScopedEnvExtension SimpEntry SimpTheorems
def SimpExtension.getTheorems (ext : SimpExtension) : CoreM SimpTheorems :=
return ext.getState (← getEnv)
def addSimpTheorem (ext : SimpExtension) (declName : Name) (post : Bool) (inv : Bool) (attrKind : AttributeKind) (prio : Nat) : MetaM Unit := do
let simpThms ← mkSimpTheoremsFromConst declName post inv prio
for simpThm in simpThms do
ext.add (SimpEntry.thm simpThm) attrKind
def mkSimpAttr (attrName : Name) (attrDescr : String) (ext : SimpExtension)
(ref : Name := by exact decl_name%) : IO Unit :=
registerBuiltinAttribute {
ref := ref
name := attrName
descr := attrDescr
applicationTime := AttributeApplicationTime.afterCompilation
add := fun declName stx attrKind =>
let go : MetaM Unit := do
let info ← getConstInfo declName
let post := if stx[1].isNone then true else stx[1][0].getKind == ``Lean.Parser.Tactic.simpPost
let prio ← getAttrParamOptPrio stx[2]
if (← isProp info.type) then
addSimpTheorem ext declName post (inv := false) attrKind prio
else if info.hasValue then
if let some eqns ← getEqnsFor? declName then
for eqn in eqns do
addSimpTheorem ext eqn post (inv := false) attrKind prio
ext.add (SimpEntry.toUnfoldThms declName eqns) attrKind
if hasSmartUnfoldingDecl (← getEnv) declName then
ext.add (SimpEntry.toUnfold declName) attrKind
else
ext.add (SimpEntry.toUnfold declName) attrKind
else
throwError "invalid 'simp', it is not a proposition nor a definition (to unfold)"
discard <| go.run {} {}
erase := fun declName => do
let s := ext.getState (← getEnv)
let s ← s.erase declName
modifyEnv fun env => ext.modifyState env fun _ => s
}
def mkSimpExt (extName : Name) : IO SimpExtension :=
registerSimpleScopedEnvExtension {
name := extName
initial := {}
addEntry := fun d e =>
match e with
| SimpEntry.thm e => addSimpTheoremEntry d e
| SimpEntry.toUnfold n => d.addDeclToUnfoldCore n
| SimpEntry.toUnfoldThms n thms => d.registerDeclToUnfoldThms n thms
}
abbrev SimpExtensionMap := Std.HashMap Name SimpExtension
builtin_initialize simpExtensionMapRef : IO.Ref SimpExtensionMap ← IO.mkRef {}
def registerSimpAttr (attrName : Name) (attrDescr : String)
(ref : Name := by exact decl_name%)
(extName : Name := attrName.appendAfter "Ext") : IO SimpExtension := do
let ext ← mkSimpExt extName
mkSimpAttr attrName attrDescr ext ref -- Remark: it will fail if it is not performed during initialization
simpExtensionMapRef.modify fun map => map.insert attrName ext
return ext
builtin_initialize simpExtension : SimpExtension ← registerSimpAttr `simp "simplification theorem"
def getSimpExtension? (attrName : Name) : IO (Option SimpExtension) :=
return (← simpExtensionMapRef.get).find? attrName
def getSimpTheorems : CoreM SimpTheorems :=
simpExtension.getTheorems
/-- Auxiliary method for adding a global declaration to a `SimpTheorems` datastructure. -/
def SimpTheorems.addConst (s : SimpTheorems) (declName : Name) (post : Bool := true) (inv : Bool := false) (prio : Nat := eval_prio default) : MetaM SimpTheorems := do
let s := { s with erased := s.erased.erase declName }
let simpThms ← mkSimpTheoremsFromConst declName post inv prio
return simpThms.foldl addSimpTheoremEntry s
def SimpTheorem.getValue (simpThm : SimpTheorem) : MetaM Expr := do
if simpThm.proof.isConst && simpThm.levelParams.isEmpty then
let info ← getConstInfo simpThm.proof.constName!
if info.levelParams.isEmpty then
return simpThm.proof
else
return simpThm.proof.updateConst! (← info.levelParams.mapM (fun _ => mkFreshLevelMVar))
else
let us ← simpThm.levelParams.mapM fun _ => mkFreshLevelMVar
return simpThm.proof.instantiateLevelParamsArray simpThm.levelParams us
private def preprocessProof (val : Expr) (inv : Bool) : MetaM (Array Expr) := do
let type ← inferType val
checkTypeIsProp type
let ps ← preprocess val type inv (isGlobal := false)
return ps.toArray.map fun (val, _) => val
/-- Auxiliary method for creating simp theorems from a proof term `val`. -/
def mkSimpTheorems (levelParams : Array Name) (proof : Expr) (post : Bool := true) (inv : Bool := false) (prio : Nat := eval_prio default) (name? : Option Name := none): MetaM (Array SimpTheorem) :=
withReducible do
(← preprocessProof proof inv).mapM fun val => mkSimpTheoremCore val levelParams val post prio name?
/-- Auxiliary method for adding a local simp theorem to a `SimpTheorems` datastructure. -/
def SimpTheorems.add (s : SimpTheorems) (levelParams : Array Name) (proof : Expr) (inv : Bool := false) (post : Bool := true) (prio : Nat := eval_prio default) (name? : Option Name := none): MetaM SimpTheorems := do
if proof.isConst then
s.addConst proof.constName! post inv prio
else
let simpThms ← mkSimpTheorems levelParams proof post inv prio (← getName? proof)
return simpThms.foldl addSimpTheoremEntry s
where
getName? (e : Expr) : MetaM (Option Name) := do
match name? with
| some _ => return name?
| none =>
let f := e.getAppFn
if f.isConst then
return f.constName!
else if f.isFVar then
let localDecl ← getFVarLocalDecl f
return localDecl.userName
else
return none
def SimpTheorems.addDeclToUnfold (d : SimpTheorems) (declName : Name) : MetaM SimpTheorems := do
if let some eqns ← getEqnsFor? declName then
let mut d := d
for eqn in eqns do
d ← SimpTheorems.addConst d eqn
if hasSmartUnfoldingDecl (← getEnv) declName then
d := d.addDeclToUnfoldCore declName
return d
else
return d.addDeclToUnfoldCore declName
abbrev SimpTheoremsArray := Array SimpTheorems
def SimpTheoremsArray.addTheorem (thmsArray : SimpTheoremsArray) (h : Expr) (name? : Option Name := none) : MetaM SimpTheoremsArray :=
if thmsArray.isEmpty then
let thms : SimpTheorems := {}
return #[ (← thms.add #[] h (name? := name?)) ]
else
thmsArray.modifyM 0 fun thms => thms.add #[] h (name? := name?)
def SimpTheoremsArray.eraseTheorem (thmsArray : SimpTheoremsArray) (thmId : Name) : SimpTheoremsArray :=
thmsArray.map fun thms => thms.eraseCore thmId
def SimpTheoremsArray.isErased (thmsArray : SimpTheoremsArray) (thmId : Name) : Bool :=
thmsArray.any fun thms => thms.erased.contains thmId
def SimpTheoremsArray.isDeclToUnfold (thmsArray : SimpTheoremsArray) (declName : Name) : Bool :=
thmsArray.any fun thms => thms.isDeclToUnfold declName
macro (name := _root_.Lean.Parser.Command.registerSimpAttr) doc?:(docComment)?
"register_simp_attr" id:ident descr:str : command => do
let str := id.getId.toString
let idParser := mkIdentFrom id (`Parser.Attr ++ id.getId)
`($[$doc?]? initialize ext : SimpExtension ← registerSimpAttr $(quote id.getId) $descr $(quote id.getId)
$[$doc?]? syntax (name := $idParser:ident) $(quote str):str (Parser.Tactic.simpPre <|> Parser.Tactic.simpPost)? (prio)? : attr)
end Meta
end Lean
|
429e1be59ca9bfc78cf001d1fd1f8f51c57ec075 | 827124860511172deb7ee955917c49b2bccd1b3c | /data/containers/utils/ordering.lean | a81480ed9cedc6d33668e95f789fd6761f64a815 | [] | no_license | joehendrix/lean-containers | afec24c7de19c935774738ff3a0415362894956c | ef6ff0533eada75f18922039f8312badf12e6124 | refs/heads/master | 1,624,853,911,199 | 1,505,890,599,000 | 1,505,890,599,000 | 103,489,962 | 1 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 716 | lean | namespace ordering
protected
def le : ordering → ordering → Prop
| lt _ := true
| _ lt := false
| eq _ := true
| gt eq := false
| gt gt := true
instance : linear_order ordering :=
{ le := ordering.le
, le_refl := λa, begin cases a; simp, end
, le_trans := λa b c, begin cases a; cases b; cases c; simp [ordering.le], end
, le_antisymm := λa b, begin cases a; cases b; simp [has_le.le, ordering.le], end
, le_total := λa b, begin cases a; cases b; simp [has_le.le, preorder.le, ordering.le], end
}
instance (x y : ordering) : decidable (x ≤ y) :=
begin
cases x; cases y;
simp [has_le.le, preorder.le, partial_order.le, linear_order.le, ordering.le];
apply_instance,
end
end ordering
|
93bbce45abc609dc7c3b1f1d8f599e554445c530 | 35677d2df3f081738fa6b08138e03ee36bc33cad | /src/algebra/ordered_group.lean | c1e7f9fa4e25dc147ac73319c000c482b7b70c2c | [
"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 | 28,057 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johannes Hölzl
Ordered monoids and groups.
-/
import algebra.group.units algebra.group.with_one algebra.group.type_tags
import order.bounded_lattice tactic.basic
universe u
variable {α : Type u}
section old_structure_cmd
set_option old_structure_cmd true
set_option default_priority 100 -- see Note [default priority]
/-- An ordered (additive) commutative monoid is a commutative monoid
with a partial order such that addition is an order embedding, i.e.
`a + b ≤ a + c ↔ b ≤ c`. These monoids are automatically cancellative. -/
class ordered_add_comm_monoid (α : Type*) extends add_comm_monoid α, partial_order α :=
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b)
(lt_of_add_lt_add_left : ∀ a b c : α, a + b < a + c → b < c)
/-- A canonically ordered monoid is an ordered commutative monoid
in which the ordering coincides with the divisibility relation,
which is to say, `a ≤ b` iff there exists `c` with `b = a + c`.
This is satisfied by the natural numbers, for example, but not
the integers or other ordered groups. -/
class canonically_ordered_add_monoid (α : Type*) extends ordered_add_comm_monoid α, order_bot α :=
(le_iff_exists_add : ∀a b:α, a ≤ b ↔ ∃c, b = a + c)
end old_structure_cmd
section ordered_add_comm_monoid
variables [ordered_add_comm_monoid α] {a b c d : α}
lemma add_le_add_left' (h : a ≤ b) : c + a ≤ c + b :=
ordered_add_comm_monoid.add_le_add_left a b h c
lemma add_le_add_right' (h : a ≤ b) : a + c ≤ b + c :=
add_comm c a ▸ add_comm c b ▸ add_le_add_left' h
lemma lt_of_add_lt_add_left' : a + b < a + c → b < c :=
ordered_add_comm_monoid.lt_of_add_lt_add_left a b c
lemma add_le_add' (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d :=
le_trans (add_le_add_right' h₁) (add_le_add_left' h₂)
lemma le_add_of_nonneg_right' (h : 0 ≤ b) : a ≤ a + b :=
have a + b ≥ a + 0, from add_le_add_left' h,
by rwa add_zero at this
lemma le_add_of_nonneg_left' (h : 0 ≤ b) : a ≤ b + a :=
have 0 + a ≤ b + a, from add_le_add_right' h,
by rwa zero_add at this
lemma lt_of_add_lt_add_right' (h : a + b < c + b) : a < c :=
lt_of_add_lt_add_left'
(show b + a < b + c, begin rw [add_comm b a, add_comm b c], assumption end)
-- here we start using properties of zero.
lemma le_add_of_nonneg_of_le' (ha : 0 ≤ a) (hbc : b ≤ c) : b ≤ a + c :=
zero_add b ▸ add_le_add' ha hbc
lemma le_add_of_le_of_nonneg' (hbc : b ≤ c) (ha : 0 ≤ a) : b ≤ c + a :=
add_zero b ▸ add_le_add' hbc ha
lemma add_nonneg' (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
le_add_of_nonneg_of_le' ha hb
lemma add_pos_of_pos_of_nonneg' (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b :=
lt_of_lt_of_le ha $ le_add_of_nonneg_right' hb
lemma add_pos' (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
add_pos_of_pos_of_nonneg' ha $ le_of_lt hb
lemma add_pos_of_nonneg_of_pos' (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b :=
lt_of_lt_of_le hb $ le_add_of_nonneg_left' ha
lemma add_nonpos' (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 :=
zero_add (0:α) ▸ (add_le_add' ha hb)
lemma add_le_of_nonpos_of_le' (ha : a ≤ 0) (hbc : b ≤ c) : a + b ≤ c :=
zero_add c ▸ add_le_add' ha hbc
lemma add_le_of_le_of_nonpos' (hbc : b ≤ c) (ha : a ≤ 0) : b + a ≤ c :=
add_zero c ▸ add_le_add' hbc ha
lemma add_neg_of_neg_of_nonpos' (ha : a < 0) (hb : b ≤ 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) hb) ha
lemma add_neg_of_nonpos_of_neg' (ha : a ≤ 0) (hb : b < 0) : a + b < 0 :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hb
lemma add_neg' (ha : a < 0) (hb : b < 0) : a + b < 0 :=
add_neg_of_nonpos_of_neg' (le_of_lt ha) hb
lemma lt_add_of_nonneg_of_lt' (ha : 0 ≤ a) (hbc : b < c) : b < a + c :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_left' ha
lemma lt_add_of_lt_of_nonneg' (hbc : b < c) (ha : 0 ≤ a) : b < c + a :=
lt_of_lt_of_le hbc $ le_add_of_nonneg_right' ha
lemma lt_add_of_pos_of_lt' (ha : 0 < a) (hbc : b < c) : b < a + c :=
lt_add_of_nonneg_of_lt' (le_of_lt ha) hbc
lemma lt_add_of_lt_of_pos' (hbc : b < c) (ha : 0 < a) : b < c + a :=
lt_add_of_lt_of_nonneg' hbc (le_of_lt ha)
lemma add_lt_of_nonpos_of_lt' (ha : a ≤ 0) (hbc : b < c) : a + b < c :=
lt_of_le_of_lt (add_le_of_nonpos_of_le' ha (le_refl _)) hbc
lemma add_lt_of_lt_of_nonpos' (hbc : b < c) (ha : a ≤ 0) : b + a < c :=
lt_of_le_of_lt (add_le_of_le_of_nonpos' (le_refl _) ha) hbc
lemma add_lt_of_neg_of_lt' (ha : a < 0) (hbc : b < c) : a + b < c :=
add_lt_of_nonpos_of_lt' (le_of_lt ha) hbc
lemma add_lt_of_lt_of_neg' (hbc : b < c) (ha : a < 0) : b + a < c :=
add_lt_of_lt_of_nonpos' hbc (le_of_lt ha)
lemma add_eq_zero_iff' (ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 :=
iff.intro
(assume hab : a + b = 0,
have a ≤ 0, from hab ▸ le_add_of_le_of_nonneg' (le_refl _) hb,
have a = 0, from le_antisymm this ha,
have b ≤ 0, from hab ▸ le_add_of_nonneg_of_le' ha (le_refl _),
have b = 0, from le_antisymm this hb,
and.intro ‹a = 0› ‹b = 0›)
(assume ⟨ha', hb'⟩, by rw [ha', hb', add_zero])
lemma bit0_pos {a : α} (h : 0 < a) : 0 < bit0 a :=
add_pos' h h
end ordered_add_comm_monoid
namespace units
instance [monoid α] [i : preorder α] : preorder (units α) :=
preorder.lift (coe : units α → α) i
@[simp] theorem coe_le_coe [monoid α] [preorder α] {a b : units α} :
(a : α) ≤ b ↔ a ≤ b := iff.rfl
@[simp] theorem coe_lt_coe [monoid α] [preorder α] {a b : units α} :
(a : α) < b ↔ a < b := iff.rfl
instance [monoid α] [i : partial_order α] : partial_order (units α) :=
partial_order.lift (coe : units α → α) (by ext) i
instance [monoid α] [i : linear_order α] : linear_order (units α) :=
linear_order.lift (coe : units α → α) (by ext) i
instance [monoid α] [i : decidable_linear_order α] : decidable_linear_order (units α) :=
decidable_linear_order.lift (coe : units α → α) (by ext) i
theorem max_coe [monoid α] [decidable_linear_order α] {a b : units α} :
(↑(max a b) : α) = max a b :=
by by_cases a ≤ b; simp [max, h]
theorem min_coe [monoid α] [decidable_linear_order α] {a b : units α} :
(↑(min a b) : α) = min a b :=
by by_cases a ≤ b; simp [min, h]
end units
namespace with_zero
instance [preorder α] : preorder (with_zero α) := with_bot.preorder
instance [partial_order α] : partial_order (with_zero α) := with_bot.partial_order
instance [partial_order α] : order_bot (with_zero α) := with_bot.order_bot
instance [lattice α] : lattice (with_zero α) := with_bot.lattice
instance [linear_order α] : linear_order (with_zero α) := with_bot.linear_order
instance [decidable_linear_order α] :
decidable_linear_order (with_zero α) := with_bot.decidable_linear_order
/--
If `0` is the least element in `α`, then `with_zero α` is an `ordered_add_comm_monoid`.
-/
def ordered_add_comm_monoid [ordered_add_comm_monoid α]
(zero_le : ∀ a : α, 0 ≤ a) : ordered_add_comm_monoid (with_zero α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_zero.partial_order,
..with_zero.add_comm_monoid, .. },
{ intros a b c h,
have h' := lt_iff_le_not_le.1 h,
rw lt_iff_le_not_le at ⊢,
refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩,
cases h₂, cases c with c,
{ cases h'.2 (this _ _ bot_le a) },
{ refine ⟨_, rfl, _⟩,
cases a with a,
{ exact with_bot.some_le_some.1 h'.1 },
{ exact le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h), } } },
{ intros a b h c ca h₂,
cases b with b,
{ rw le_antisymm h bot_le at h₂,
exact ⟨_, h₂, le_refl _⟩ },
cases a with a,
{ change c + 0 = some ca at h₂,
simp at h₂, simp [h₂],
exact ⟨_, rfl, by simpa using add_le_add_left' (zero_le b)⟩ },
{ simp at h,
cases c with c; change some _ = _ at h₂;
simp [-add_comm] at h₂; subst ca; refine ⟨_, rfl, _⟩,
{ exact h },
{ exact add_le_add_left' h } } }
end
end with_zero
namespace with_top
instance [add_semigroup α] : add_semigroup (with_top α) :=
{ add := λ o₁ o₂, o₁.bind (λ a, o₂.map (λ b, a + b)),
..@additive.add_semigroup _ $ @with_zero.semigroup (multiplicative α) _ }
lemma coe_add [add_semigroup α] {a b : α} : ((a + b : α) : with_top α) = a + b := rfl
instance [add_comm_semigroup α] : add_comm_semigroup (with_top α) :=
{ ..@additive.add_comm_semigroup _ $
@with_zero.comm_semigroup (multiplicative α) _ }
instance [add_monoid α] : add_monoid (with_top α) :=
{ zero := some 0,
add := (+),
..@additive.add_monoid _ $ @with_zero.monoid (multiplicative α) _ }
instance [add_comm_monoid α] : add_comm_monoid (with_top α) :=
{ zero := 0,
add := (+),
..@additive.add_comm_monoid _ $
@with_zero.comm_monoid (multiplicative α) _ }
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_top α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_top.partial_order,
..with_top.add_comm_monoid, ..},
{ intros a b c h,
have h' := h,
rw lt_iff_le_not_le at h' ⊢,
refine ⟨λ c h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩,
cases h₂, cases a with a,
{ exact (not_le_of_lt h).elim le_top },
cases b with b,
{ exact (not_le_of_lt h).elim le_top },
{ exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_top.some_lt_some.1 h)⟩ } },
{ intros a b h c ca h₂,
cases c with c, {cases h₂},
cases b with b; cases h₂,
cases a with a, {cases le_antisymm h le_top },
simp at h,
exact ⟨_, rfl, add_le_add_left' h⟩, }
end
@[simp] lemma zero_lt_top [ordered_add_comm_monoid α] : (0 : with_top α) < ⊤ :=
coe_lt_top 0
@[simp] lemma zero_lt_coe [ordered_add_comm_monoid α] (a : α) : (0 : with_top α) < a ↔ 0 < a :=
coe_lt_coe
@[simp] lemma add_top [ordered_add_comm_monoid α] : ∀{a : with_top α}, a + ⊤ = ⊤
| none := rfl
| (some a) := rfl
@[simp] lemma top_add [ordered_add_comm_monoid α] {a : with_top α} : ⊤ + a = ⊤ := rfl
lemma add_eq_top [ordered_add_comm_monoid α] (a b : with_top α) : a + b = ⊤ ↔ a = ⊤ ∨ b = ⊤ :=
by cases a; cases b; simp [none_eq_top, some_eq_coe, coe_add.symm]
lemma add_lt_top [ordered_add_comm_monoid α] (a b : with_top α) : a + b < ⊤ ↔ a < ⊤ ∧ b < ⊤ :=
begin
apply not_iff_not.1,
simp [lt_top_iff_ne_top, add_eq_top],
finish,
apply classical.dec _,
apply classical.dec _,
end
instance [canonically_ordered_add_monoid α] : canonically_ordered_add_monoid (with_top α) :=
{ le_iff_exists_add := assume a b,
match a, b with
| a, none := show a ≤ ⊤ ↔ ∃c, ⊤ = a + c, by simp; refine ⟨⊤, _⟩; cases a; refl
| (some a), (some b) := show (a:with_top α) ≤ ↑b ↔ ∃c:with_top α, ↑b = ↑a + c,
begin
simp [canonically_ordered_add_monoid.le_iff_exists_add, -add_comm],
split,
{ rintro ⟨c, rfl⟩, refine ⟨c, _⟩, simp [coe_add] },
{ exact assume h, match b, h with _, ⟨some c, rfl⟩ := ⟨_, rfl⟩ end }
end
| none, some b := show (⊤ : with_top α) ≤ b ↔ ∃c:with_top α, ↑b = ⊤ + c, by simp
end,
.. with_top.order_bot,
.. with_top.ordered_add_comm_monoid }
end with_top
namespace with_bot
instance [add_semigroup α] : add_semigroup (with_bot α) := with_top.add_semigroup
instance [add_comm_semigroup α] : add_comm_semigroup (with_bot α) := with_top.add_comm_semigroup
instance [add_monoid α] : add_monoid (with_bot α) := with_top.add_monoid
instance [add_comm_monoid α] : add_comm_monoid (with_bot α) := with_top.add_comm_monoid
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (with_bot α) :=
begin
suffices, refine {
add_le_add_left := this,
..with_bot.partial_order,
..with_bot.add_comm_monoid, ..},
{ intros a b c h,
have h' := h,
rw lt_iff_le_not_le at h' ⊢,
refine ⟨λ b h₂, _, λ h₂, h'.2 $ this _ _ h₂ _⟩,
cases h₂, cases a with a,
{ exact (not_le_of_lt h).elim bot_le },
cases c with c,
{ exact (not_le_of_lt h).elim bot_le },
{ exact ⟨_, rfl, le_of_lt (lt_of_add_lt_add_left' $
with_bot.some_lt_some.1 h)⟩ } },
{ intros a b h c ca h₂,
cases c with c, {cases h₂},
cases a with a; cases h₂,
cases b with b, {cases le_antisymm h bot_le},
simp at h,
exact ⟨_, rfl, add_le_add_left' h⟩, }
end
@[simp] lemma coe_zero [add_monoid α] : ((0 : α) : with_bot α) = 0 := rfl
@[simp] lemma coe_add [add_semigroup α] (a b : α) : ((a + b : α) : with_bot α) = a + b := rfl
@[simp] lemma bot_add [ordered_add_comm_monoid α] (a : with_bot α) : ⊥ + a = ⊥ := rfl
@[simp] lemma add_bot [ordered_add_comm_monoid α] (a : with_bot α) : a + ⊥ = ⊥ := by cases a; refl
instance has_one [has_one α] : has_one (with_bot α) := ⟨(1 : α)⟩
@[simp] lemma coe_one [has_one α] : ((1 : α) : with_bot α) = 1 := rfl
end with_bot
section canonically_ordered_add_monoid
variables [canonically_ordered_add_monoid α] {a b c d : α}
lemma le_iff_exists_add : a ≤ b ↔ ∃c, b = a + c :=
canonically_ordered_add_monoid.le_iff_exists_add a b
@[simp] lemma zero_le (a : α) : 0 ≤ a := le_iff_exists_add.mpr ⟨a, by simp⟩
@[simp] lemma bot_eq_zero : (⊥ : α) = 0 :=
le_antisymm bot_le (zero_le ⊥)
@[simp] lemma add_eq_zero_iff : a + b = 0 ↔ a = 0 ∧ b = 0 :=
add_eq_zero_iff' (zero_le _) (zero_le _)
@[simp] lemma le_zero_iff_eq : a ≤ 0 ↔ a = 0 :=
iff.intro
(assume h, le_antisymm h (zero_le a))
(assume h, h ▸ le_refl a)
protected lemma zero_lt_iff_ne_zero : 0 < a ↔ a ≠ 0 :=
iff.intro ne_of_gt $ assume hne, lt_of_le_of_ne (zero_le _) hne.symm
lemma le_add_left (h : a ≤ c) : a ≤ b + c :=
calc a = 0 + a : by simp
... ≤ b + c : add_le_add' (zero_le _) h
lemma le_add_right (h : a ≤ b) : a ≤ b + c :=
calc a = a + 0 : by simp
... ≤ b + c : add_le_add' h (zero_le _)
instance with_zero.canonically_ordered_add_monoid :
canonically_ordered_add_monoid (with_zero α) :=
{ le_iff_exists_add := λ a b, begin
cases a with a,
{ exact iff_of_true bot_le ⟨b, (zero_add b).symm⟩ },
cases b with b,
{ exact iff_of_false
(mt (le_antisymm bot_le) (by simp))
(λ ⟨c, h⟩, by cases c; cases h) },
{ simp [le_iff_exists_add, -add_comm],
split; intro h; rcases h with ⟨c, h⟩,
{ exact ⟨some c, congr_arg some h⟩ },
{ cases c; cases h,
{ exact ⟨_, (add_zero _).symm⟩ },
{ exact ⟨_, rfl⟩ } } }
end,
bot := 0,
bot_le := assume a a' h, option.no_confusion h,
.. with_zero.ordered_add_comm_monoid zero_le }
end canonically_ordered_add_monoid
@[priority 100] -- see Note [lower instance priority]
instance ordered_cancel_add_comm_monoid.to_ordered_add_comm_monoid
[H : ordered_cancel_add_comm_monoid α] : ordered_add_comm_monoid α :=
{ lt_of_add_lt_add_left := @lt_of_add_lt_add_left _ _, ..H }
section ordered_cancel_comm_monoid
variables [ordered_cancel_add_comm_monoid α] {a b c x y : α}
@[simp] lemma add_le_add_iff_left (a : α) {b c : α} : a + b ≤ a + c ↔ b ≤ c :=
⟨le_of_add_le_add_left, λ h, add_le_add_left h _⟩
@[simp] lemma add_le_add_iff_right (c : α) : a + c ≤ b + c ↔ a ≤ b :=
add_comm c a ▸ add_comm c b ▸ add_le_add_iff_left c
@[simp] lemma add_lt_add_iff_left (a : α) {b c : α} : a + b < a + c ↔ b < c :=
⟨lt_of_add_lt_add_left, λ h, add_lt_add_left h _⟩
@[simp] lemma add_lt_add_iff_right (c : α) : a + c < b + c ↔ a < b :=
add_comm c a ▸ add_comm c b ▸ add_lt_add_iff_left c
@[simp] lemma le_add_iff_nonneg_right (a : α) {b : α} : a ≤ a + b ↔ 0 ≤ b :=
have a + 0 ≤ a + b ↔ 0 ≤ b, from add_le_add_iff_left a,
by rwa add_zero at this
@[simp] lemma le_add_iff_nonneg_left (a : α) {b : α} : a ≤ b + a ↔ 0 ≤ b :=
by rw [add_comm, le_add_iff_nonneg_right]
@[simp] lemma lt_add_iff_pos_right (a : α) {b : α} : a < a + b ↔ 0 < b :=
have a + 0 < a + b ↔ 0 < b, from add_lt_add_iff_left a,
by rwa add_zero at this
@[simp] lemma lt_add_iff_pos_left (a : α) {b : α} : a < b + a ↔ 0 < b :=
by rw [add_comm, lt_add_iff_pos_right]
@[simp] lemma add_le_iff_nonpos_left : x + y ≤ y ↔ x ≤ 0 :=
by { convert add_le_add_iff_right y, rw [zero_add] }
@[simp] lemma add_le_iff_nonpos_right : x + y ≤ x ↔ y ≤ 0 :=
by { convert add_le_add_iff_left x, rw [add_zero] }
@[simp] lemma add_lt_iff_neg_right : x + y < y ↔ x < 0 :=
by { convert add_lt_add_iff_right y, rw [zero_add] }
@[simp] lemma add_lt_iff_neg_left : x + y < x ↔ y < 0 :=
by { convert add_lt_add_iff_left x, rw [add_zero] }
lemma add_eq_zero_iff_eq_zero_of_nonneg
(ha : 0 ≤ a) (hb : 0 ≤ b) : a + b = 0 ↔ a = 0 ∧ b = 0 :=
⟨λ hab : a + b = 0,
by split; apply le_antisymm; try {assumption};
rw ← hab; simp [ha, hb],
λ ⟨ha', hb'⟩, by rw [ha', hb', add_zero]⟩
lemma with_top.add_lt_add_iff_left :
∀{a b c : with_top α}, a < ⊤ → (a + c < a + b ↔ c < b)
| none := assume b c h, (lt_irrefl ⊤ h).elim
| (some a) :=
begin
assume b c h,
cases b; cases c;
simp [with_top.none_eq_top, with_top.some_eq_coe, with_top.coe_lt_top, with_top.coe_lt_coe],
{ rw [← with_top.coe_add], exact with_top.coe_lt_top _ },
{ rw [← with_top.coe_add, ← with_top.coe_add, with_top.coe_lt_coe],
exact add_lt_add_iff_left _ }
end
lemma with_top.add_lt_add_iff_right
{a b c : with_top α} : a < ⊤ → (c + a < b + a ↔ c < b) :=
by simpa [add_comm] using @with_top.add_lt_add_iff_left _ _ a b c
end ordered_cancel_comm_monoid
section ordered_add_comm_group
/--
The `add_lt_add_left` field of `ordered_add_comm_group` is redundant, but it is in core so
we can't remove it for now. This alternative constructor is the best we can do.
-/
def ordered_add_comm_group.mk' {α : Type u} [add_comm_group α] [partial_order α]
(add_le_add_left : ∀ a b : α, a ≤ b → ∀ c : α, c + a ≤ c + b) :
ordered_add_comm_group α :=
{ add_le_add_left := add_le_add_left,
..(by apply_instance : add_comm_group α),
..(by apply_instance : partial_order α) }
variables [ordered_add_comm_group α] {a b c : α}
@[simp] lemma neg_neg_iff_pos : -a < 0 ↔ 0 < a :=
⟨ pos_of_neg_neg, neg_neg_of_pos ⟩
@[simp] lemma neg_le_neg_iff : -a ≤ -b ↔ b ≤ a :=
have a + b + -a ≤ a + b + -b ↔ -a ≤ -b, from add_le_add_iff_left _,
by simp at this; simp [this]
lemma neg_le : -a ≤ b ↔ -b ≤ a :=
have -a ≤ -(-b) ↔ -b ≤ a, from neg_le_neg_iff,
by rwa neg_neg at this
lemma le_neg : a ≤ -b ↔ b ≤ -a :=
have -(-a) ≤ -b ↔ b ≤ -a, from neg_le_neg_iff,
by rwa neg_neg at this
lemma neg_le_iff_add_nonneg : -a ≤ b ↔ 0 ≤ a + b :=
(add_le_add_iff_left a).symm.trans $ by rw add_neg_self
lemma le_neg_iff_add_nonpos : a ≤ -b ↔ a + b ≤ 0 :=
(add_le_add_iff_right b).symm.trans $ by rw neg_add_self
@[simp] lemma neg_nonpos : -a ≤ 0 ↔ 0 ≤ a :=
have -a ≤ -0 ↔ 0 ≤ a, from neg_le_neg_iff,
by rwa neg_zero at this
@[simp] lemma neg_nonneg : 0 ≤ -a ↔ a ≤ 0 :=
have -0 ≤ -a ↔ a ≤ 0, from neg_le_neg_iff,
by rwa neg_zero at this
lemma neg_le_self (h : 0 ≤ a) : -a ≤ a :=
le_trans (neg_nonpos.2 h) h
lemma self_le_neg (h : a ≤ 0) : a ≤ -a :=
le_trans h (neg_nonneg.2 h)
@[simp] lemma neg_lt_neg_iff : -a < -b ↔ b < a :=
have a + b + -a < a + b + -b ↔ -a < -b, from add_lt_add_iff_left _,
by simp at this; simp [this]
lemma neg_lt_zero : -a < 0 ↔ 0 < a :=
have -a < -0 ↔ 0 < a, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_pos : 0 < -a ↔ a < 0 :=
have -0 < -a ↔ a < 0, from neg_lt_neg_iff,
by rwa neg_zero at this
lemma neg_lt : -a < b ↔ -b < a :=
have -a < -(-b) ↔ -b < a, from neg_lt_neg_iff,
by rwa neg_neg at this
lemma lt_neg : a < -b ↔ b < -a :=
have -(-a) < -b ↔ b < -a, from neg_lt_neg_iff,
by rwa neg_neg at this
@[simp]
lemma sub_le_sub_iff_left (a : α) {b c : α} : a - b ≤ a - c ↔ c ≤ b :=
(add_le_add_iff_left _).trans neg_le_neg_iff
@[simp]
lemma sub_le_sub_iff_right (c : α) : a - c ≤ b - c ↔ a ≤ b :=
add_le_add_iff_right _
@[simp]
lemma sub_lt_sub_iff_left (a : α) {b c : α} : a - b < a - c ↔ c < b :=
(add_lt_add_iff_left _).trans neg_lt_neg_iff
@[simp]
lemma sub_lt_sub_iff_right (c : α) : a - c < b - c ↔ a < b :=
add_lt_add_iff_right _
@[simp] lemma sub_nonneg : 0 ≤ a - b ↔ b ≤ a :=
have a - a ≤ a - b ↔ b ≤ a, from sub_le_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_nonpos : a - b ≤ 0 ↔ a ≤ b :=
have a - b ≤ b - b ↔ a ≤ b, from sub_le_sub_iff_right b,
by rwa sub_self at this
@[simp] lemma sub_pos : 0 < a - b ↔ b < a :=
have a - a < a - b ↔ b < a, from sub_lt_sub_iff_left a,
by rwa sub_self at this
@[simp] lemma sub_lt_zero : a - b < 0 ↔ a < b :=
have a - b < b - b ↔ a < b, from sub_lt_sub_iff_right b,
by rwa sub_self at this
lemma le_neg_add_iff_add_le : b ≤ -a + c ↔ a + b ≤ c :=
have -a + (a + b) ≤ -a + c ↔ a + b ≤ c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma le_sub_iff_add_le' : b ≤ c - a ↔ a + b ≤ c :=
by rw [sub_eq_add_neg, add_comm, le_neg_add_iff_add_le]
lemma le_sub_iff_add_le : a ≤ c - b ↔ a + b ≤ c :=
by rw [le_sub_iff_add_le', add_comm]
@[simp] lemma neg_add_le_iff_le_add : -b + a ≤ c ↔ a ≤ b + c :=
have -b + a ≤ -b + (b + c) ↔ a ≤ b + c, from add_le_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_le_iff_le_add' : a - b ≤ c ↔ a ≤ b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_le_iff_le_add]
lemma sub_le_iff_le_add : a - c ≤ b ↔ a ≤ b + c :=
by rw [sub_le_iff_le_add', add_comm]
lemma add_neg_le_iff_le_add : a + -c ≤ b ↔ a ≤ b + c :=
sub_le_iff_le_add
@[simp] lemma add_neg_le_iff_le_add' : a + -b ≤ c ↔ a ≤ b + c :=
sub_le_iff_le_add'
lemma neg_add_le_iff_le_add' : -c + a ≤ b ↔ a ≤ b + c :=
by rw [neg_add_le_iff_le_add, add_comm]
@[simp] lemma neg_le_sub_iff_le_add : -b ≤ a - c ↔ c ≤ a + b :=
le_sub_iff_add_le.trans neg_add_le_iff_le_add'
lemma neg_le_sub_iff_le_add' : -a ≤ b - c ↔ c ≤ a + b :=
by rw [neg_le_sub_iff_le_add, add_comm]
lemma sub_le : a - b ≤ c ↔ a - c ≤ b :=
sub_le_iff_le_add'.trans sub_le_iff_le_add.symm
theorem le_sub : a ≤ b - c ↔ c ≤ b - a :=
le_sub_iff_add_le'.trans le_sub_iff_add_le.symm
@[simp] lemma lt_neg_add_iff_add_lt : b < -a + c ↔ a + b < c :=
have -a + (a + b) < -a + c ↔ a + b < c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma lt_sub_iff_add_lt' : b < c - a ↔ a + b < c :=
by rw [sub_eq_add_neg, add_comm, lt_neg_add_iff_add_lt]
lemma lt_sub_iff_add_lt : a < c - b ↔ a + b < c :=
by rw [lt_sub_iff_add_lt', add_comm]
@[simp] lemma neg_add_lt_iff_lt_add : -b + a < c ↔ a < b + c :=
have -b + a < -b + (b + c) ↔ a < b + c, from add_lt_add_iff_left _,
by rwa neg_add_cancel_left at this
lemma sub_lt_iff_lt_add' : a - b < c ↔ a < b + c :=
by rw [sub_eq_add_neg, add_comm, neg_add_lt_iff_lt_add]
lemma sub_lt_iff_lt_add : a - c < b ↔ a < b + c :=
by rw [sub_lt_iff_lt_add', add_comm]
lemma neg_add_lt_iff_lt_add_right : -c + a < b ↔ a < b + c :=
by rw [neg_add_lt_iff_lt_add, add_comm]
@[simp] lemma neg_lt_sub_iff_lt_add : -b < a - c ↔ c < a + b :=
lt_sub_iff_add_lt.trans neg_add_lt_iff_lt_add_right
lemma neg_lt_sub_iff_lt_add' : -a < b - c ↔ c < a + b :=
by rw [neg_lt_sub_iff_lt_add, add_comm]
lemma sub_lt : a - b < c ↔ a - c < b :=
sub_lt_iff_lt_add'.trans sub_lt_iff_lt_add.symm
theorem lt_sub : a < b - c ↔ c < b - a :=
lt_sub_iff_add_lt'.trans lt_sub_iff_add_lt.symm
lemma sub_le_self_iff (a : α) {b : α} : a - b ≤ a ↔ 0 ≤ b :=
sub_le_iff_le_add'.trans (le_add_iff_nonneg_left _)
lemma sub_lt_self_iff (a : α) {b : α} : a - b < a ↔ 0 < b :=
sub_lt_iff_lt_add'.trans (lt_add_iff_pos_left _)
end ordered_add_comm_group
namespace decidable_linear_ordered_add_comm_group
variables [s : decidable_linear_ordered_add_comm_group α]
include s
@[priority 100] -- see Note [lower instance priority]
instance : decidable_linear_ordered_cancel_add_comm_monoid α :=
{ le_of_add_le_add_left := λ x y z, le_of_add_le_add_left,
add_left_cancel := λ x y z, add_left_cancel,
add_right_cancel := λ x y z, add_right_cancel,
..s }
lemma eq_of_abs_sub_nonpos {a b : α} (h : abs (a - b) ≤ 0) : a = b :=
eq_of_abs_sub_eq_zero (le_antisymm _ _ h (abs_nonneg (a - b)))
end decidable_linear_ordered_add_comm_group
set_option old_structure_cmd true
section prio
set_option default_priority 100 -- see Note [default priority]
/-- This is not so much a new structure as a construction mechanism
for ordered groups, by specifying only the "positive cone" of the group. -/
class nonneg_add_comm_group (α : Type*) extends add_comm_group α :=
(nonneg : α → Prop)
(pos : α → Prop := λ a, nonneg a ∧ ¬ nonneg (neg a))
(pos_iff : ∀ a, pos a ↔ nonneg a ∧ ¬ nonneg (-a) . order_laws_tac)
(zero_nonneg : nonneg 0)
(add_nonneg : ∀ {a b}, nonneg a → nonneg b → nonneg (a + b))
(nonneg_antisymm : ∀ {a}, nonneg a → nonneg (-a) → a = 0)
end prio
namespace nonneg_add_comm_group
variable [s : nonneg_add_comm_group α]
include s
@[reducible, priority 100] -- see Note [lower instance priority]
instance to_ordered_add_comm_group : ordered_add_comm_group α :=
{ le := λ a b, nonneg (b - a),
lt := λ a b, pos (b - a),
lt_iff_le_not_le := λ a b, by simp; rw [pos_iff]; simp,
le_refl := λ a, by simp [zero_nonneg],
le_trans := λ a b c nab nbc, by simp [-sub_eq_add_neg];
rw ← sub_add_sub_cancel; exact add_nonneg nbc nab,
le_antisymm := λ a b nab nba, eq_of_sub_eq_zero $
nonneg_antisymm nba (by rw neg_sub; exact nab),
add_le_add_left := λ a b nab c, by simpa [(≤), preorder.le] using nab,
..s }
theorem nonneg_def {a : α} : nonneg a ↔ 0 ≤ a :=
show _ ↔ nonneg _, by simp
theorem pos_def {a : α} : pos a ↔ 0 < a :=
show _ ↔ pos _, by simp
theorem not_zero_pos : ¬ pos (0 : α) :=
mt pos_def.1 (lt_irrefl _)
theorem zero_lt_iff_nonneg_nonneg {a : α} :
0 < a ↔ nonneg a ∧ ¬ nonneg (-a) :=
pos_def.symm.trans (pos_iff _)
theorem nonneg_total_iff :
(∀ a : α, nonneg a ∨ nonneg (-a)) ↔
(∀ a b : α, a ≤ b ∨ b ≤ a) :=
⟨λ h a b, by have := h (b - a); rwa [neg_sub] at this,
λ h a, by rw [nonneg_def, nonneg_def, neg_nonneg]; apply h⟩
/--
A `nonneg_add_comm_group` is a `decidable_linear_ordered_add_comm_group`
if `nonneg` is total and decidable.
-/
def to_decidable_linear_ordered_add_comm_group
[decidable_pred (@nonneg α _)]
(nonneg_total : ∀ a : α, nonneg a ∨ nonneg (-a))
: decidable_linear_ordered_add_comm_group α :=
{ le := (≤),
lt := (<),
lt_iff_le_not_le := @lt_iff_le_not_le _ _,
le_refl := @le_refl _ _,
le_trans := @le_trans _ _,
le_antisymm := @le_antisymm _ _,
le_total := nonneg_total_iff.1 nonneg_total,
decidable_le := by apply_instance,
decidable_lt := by apply_instance,
..@nonneg_add_comm_group.to_ordered_add_comm_group _ s }
end nonneg_add_comm_group
namespace order_dual
instance [ordered_add_comm_monoid α] : ordered_add_comm_monoid (order_dual α) :=
{ add_le_add_left := λ a b h c, @add_le_add_left' α _ b a c h,
lt_of_add_lt_add_left := λ a b c h, @lt_of_add_lt_add_left' α _ a c b h,
..order_dual.partial_order α,
..show add_comm_monoid α, by apply_instance }
instance [ordered_cancel_add_comm_monoid α] : ordered_cancel_add_comm_monoid (order_dual α) :=
{ le_of_add_le_add_left := λ a b c : α, le_of_add_le_add_left,
add_left_cancel := @add_left_cancel α _,
add_right_cancel := @add_right_cancel α _,
..order_dual.ordered_add_comm_monoid }
instance [ordered_add_comm_group α] : ordered_add_comm_group (order_dual α) :=
{ add_left_neg := λ a : α, add_left_neg a,
..order_dual.ordered_add_comm_monoid,
..show add_comm_group α, by apply_instance }
end order_dual
|
b4bd06f8f2c39e7359ac381ffb239ca7965dacae | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/W/constructions.lean | 654dfd030b995055510e441a3dd9b4cb4a957ae4 | [
"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 | 4,868 | lean | /-
Copyright (c) 2015 Joseph Hua. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Hua
-/
import data.W.basic
/-!
# Examples of W-types
We take the view of W types as inductive types.
Given `α : Type` and `β : α → Type`, the W type determined by this data, `W_type β`, is the
inductively with constructors from `α` and arities of each constructor `a : α` given by `β a`.
This file contains `nat` and `list` as examples of W types.
## Main results
* `W_type.equiv_nat`: the construction of the naturals as a W-type is equivalent
to `nat`
* `W_type.equiv_list`: the construction of lists on a type `γ` as a W-type is equivalent to
`list γ`
-/
universes u v
namespace W_type
section nat
/-- The constructors for the naturals -/
inductive nat_α : Type
| zero : nat_α
| succ : nat_α
instance : inhabited nat_α := ⟨ nat_α.zero ⟩
/-- The arity of the constructors for the naturals, `zero` takes no arguments, `succ` takes one -/
def nat_β : nat_α → Type
| nat_α.zero := empty
| nat_α.succ := unit
instance : inhabited (nat_β nat_α.succ) := ⟨ () ⟩
/-- The isomorphism from the naturals to its corresponding `W_type` -/
@[simp] def of_nat : ℕ → W_type nat_β
| nat.zero := ⟨ nat_α.zero , empty.elim ⟩
| (nat.succ n) := ⟨ nat_α.succ , λ _ , of_nat n ⟩
/-- The isomorphism from the `W_type` of the naturals to the naturals -/
@[simp] def to_nat : W_type nat_β → ℕ
| (W_type.mk nat_α.zero f) := 0
| (W_type.mk nat_α.succ f) := (to_nat (f ())).succ
lemma left_inv_nat : function.left_inverse of_nat to_nat
| (W_type.mk nat_α.zero f) := by { simp, tidy }
| (W_type.mk nat_α.succ f) := by { simp, tidy }
lemma right_inv_nat : function.right_inverse of_nat to_nat
| nat.zero := rfl
| (nat.succ n) := by rw [of_nat, to_nat, right_inv_nat n]
/-- The naturals are equivalent to their associated `W_type` -/
def equiv_nat : W_type nat_β ≃ ℕ :=
{ to_fun := to_nat,
inv_fun := of_nat,
left_inv := left_inv_nat,
right_inv := right_inv_nat }
open sum punit
/--
`W_type.nat_α` is equivalent to `punit ⊕ punit`.
This is useful when considering the associated polynomial endofunctor.
-/
@[simps] def nat_α_equiv_punit_sum_punit : nat_α ≃ punit.{u + 1} ⊕ punit :=
{ to_fun := λ c, match c with | nat_α.zero := inl star | nat_α.succ := inr star end,
inv_fun := λ b, match b with | inl x := nat_α.zero | inr x := nat_α.succ end,
left_inv := λ c, match c with | nat_α.zero := rfl | nat_α.succ := rfl end,
right_inv := λ b, match b with | inl star := rfl | inr star := rfl end }
end nat
section list
variable (γ : Type u)
/--
The constructors for lists.
There is "one constructor `cons x` for each `x : γ`",
since we view `list γ` as
```
| nil : list γ
| cons x₀ : list γ → list γ
| cons x₁ : list γ → list γ
| ⋮ γ many times
```
-/
inductive list_α : Type u
| nil : list_α
| cons : γ → list_α
instance : inhabited (list_α γ) := ⟨ list_α.nil ⟩
/-- The arities of each constructor for lists, `nil` takes no arguments, `cons hd` takes one -/
def list_β : list_α γ → Type u
| list_α.nil := pempty
| (list_α.cons hd) := punit
instance (hd : γ) : inhabited (list_β γ (list_α.cons hd)) := ⟨ punit.star ⟩
/-- The isomorphism from lists to the `W_type` construction of lists -/
@[simp] def of_list : list γ → W_type (list_β γ)
| list.nil := ⟨ list_α.nil, pempty.elim ⟩
| (list.cons hd tl) := ⟨ list_α.cons hd, λ _ , of_list tl ⟩
/-- The isomorphism from the `W_type` construction of lists to lists -/
@[simp] def to_list : W_type (list_β γ) → list γ
| (W_type.mk list_α.nil f) := []
| (W_type.mk (list_α.cons hd) f) := hd :: to_list (f punit.star)
lemma left_inv_list : function.left_inverse (of_list γ) (to_list _)
| (W_type.mk list_α.nil f) := by { simp, tidy }
| (W_type.mk (list_α.cons x) f) := by { simp, tidy }
lemma right_inv_list : function.right_inverse (of_list γ) (to_list _)
| list.nil := rfl
| (list.cons hd tl) := by simp [right_inv_list tl]
/-- Lists are equivalent to their associated `W_type` -/
def equiv_list : W_type (list_β γ) ≃ list γ :=
{ to_fun := to_list _,
inv_fun := of_list _,
left_inv := left_inv_list _,
right_inv := right_inv_list _ }
/--
`W_type.list_α` is equivalent to `γ` with an extra point.
This is useful when considering the associated polynomial endofunctor
-/
def list_α_equiv_punit_sum : list_α γ ≃ punit.{v + 1} ⊕ γ :=
{ to_fun := λ c, match c with | list_α.nil := sum.inl punit.star | list_α.cons x := sum.inr x end,
inv_fun := sum.elim (λ _, list_α.nil) (λ x, list_α.cons x),
left_inv := λ c, match c with | list_α.nil := rfl | list_α.cons x := rfl end,
right_inv := λ x, match x with | sum.inl punit.star := rfl | sum.inr x := rfl end, }
end list
end W_type
|
683488697d2a6c4d0a7360e8ca7882182a6b5ebc | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/algebra/algebra/basic.lean | 52344b44d7bb14bc9a36f03b94cd5d693e7156d2 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 54,212 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Yury Kudryashov
-/
import algebra.iterate_hom
import data.equiv.ring_aut
import linear_algebra.tensor_product
import tactic.nth_rewrite
/-!
# Algebra over Commutative Semiring
In this file we define `algebra`s over commutative (semi)rings, algebra homomorphisms `alg_hom`,
algebra equivalences `alg_equiv`. We also define usual operations on `alg_hom`s
(`id`, `comp`).
`subalgebra`s are defined in `algebra.algebra.subalgebra`.
If `S` is an `R`-algebra and `A` is an `S`-algebra then `algebra.comap.algebra R S A` can be used
to provide `A` with a structure of an `R`-algebra. Other than that, `algebra.comap` is now
deprecated and replaced with `is_scalar_tower`.
For the category of `R`-algebras, denoted `Algebra R`, see the file
`algebra/category/Algebra/basic.lean`.
## Notations
* `A →ₐ[R] B` : `R`-algebra homomorphism from `A` to `B`.
* `A ≃ₐ[R] B` : `R`-algebra equivalence from `A` to `B`.
-/
universes u v w u₁ v₁
open_locale tensor_product big_operators
section prio
-- We set this priority to 0 later in this file
set_option extends_priority 200 /- control priority of
`instance [algebra R A] : has_scalar R A` -/
/--
Given a commutative (semi)ring `R`, an `R`-algebra is a (possibly noncommutative)
(semi)ring `A` endowed with a morphism of rings `R →+* A` which lands in the
center of `A`.
For convenience, this typeclass extends `has_scalar R A` where the scalar action must
agree with left multiplication by the image of the structure morphism.
Given an `algebra R A` instance, the structure morphism `R →+* A` is denoted `algebra_map R A`.
-/
@[nolint has_inhabited_instance]
class algebra (R : Type u) (A : Type v) [comm_semiring R] [semiring A]
extends has_scalar R A, R →+* A :=
(commutes' : ∀ r x, to_fun r * x = x * to_fun r)
(smul_def' : ∀ r x, r • x = to_fun r * x)
end prio
/-- Embedding `R →+* A` given by `algebra` structure. -/
def algebra_map (R : Type u) (A : Type v) [comm_semiring R] [semiring A] [algebra R A] : R →+* A :=
algebra.to_ring_hom
/-- Creating an algebra from a morphism to the center of a semiring. -/
def ring_hom.to_algebra' {R S} [comm_semiring R] [semiring S] (i : R →+* S)
(h : ∀ c x, i c * x = x * i c) :
algebra R S :=
{ smul := λ c x, i c * x,
commutes' := h,
smul_def' := λ c x, rfl,
to_ring_hom := i}
/-- Creating an algebra from a morphism to a commutative semiring. -/
def ring_hom.to_algebra {R S} [comm_semiring R] [comm_semiring S] (i : R →+* S) :
algebra R S :=
i.to_algebra' $ λ _, mul_comm _
lemma ring_hom.algebra_map_to_algebra {R S} [comm_semiring R] [comm_semiring S]
(i : R →+* S) :
@algebra_map R S _ _ i.to_algebra = i :=
rfl
namespace algebra
variables {R : Type u} {S : Type v} {A : Type w} {B : Type*}
/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.
If `(r • 1) * x = x * (r • 1) = r • x` for all `r : R` and `x : A`, then `A` is an `algebra`
over `R`.
See note [reducible non-instances]. -/
@[reducible]
def of_module' [comm_semiring R] [semiring A] [module R A]
(h₁ : ∀ (r : R) (x : A), (r • 1) * x = r • x)
(h₂ : ∀ (r : R) (x : A), x * (r • 1) = r • x) : algebra R A :=
{ to_fun := λ r, r • 1,
map_one' := one_smul _ _,
map_mul' := λ r₁ r₂, by rw [h₁, mul_smul],
map_zero' := zero_smul _ _,
map_add' := λ r₁ r₂, add_smul r₁ r₂ 1,
commutes' := λ r x, by simp only [h₁, h₂],
smul_def' := λ r x, by simp only [h₁] }
/-- Let `R` be a commutative semiring, let `A` be a semiring with a `module R` structure.
If `(r • x) * y = x * (r • y) = r • (x * y)` for all `r : R` and `x y : A`, then `A`
is an `algebra` over `R`.
See note [reducible non-instances]. -/
@[reducible]
def of_module [comm_semiring R] [semiring A] [module R A]
(h₁ : ∀ (r : R) (x y : A), (r • x) * y = r • (x * y))
(h₂ : ∀ (r : R) (x y : A), x * (r • y) = r • (x * y)) : algebra R A :=
of_module' (λ r x, by rw [h₁, one_mul]) (λ r x, by rw [h₂, mul_one])
section semiring
variables [comm_semiring R] [comm_semiring S]
variables [semiring A] [algebra R A] [semiring B] [algebra R B]
lemma smul_def'' (r : R) (x : A) : r • x = algebra_map R A r * x :=
algebra.smul_def' r x
/--
To prove two algebra structures on a fixed `[comm_semiring R] [semiring A]` agree,
it suffices to check the `algebra_map`s agree.
-/
-- We'll later use this to show `algebra ℤ M` is a subsingleton.
@[ext]
lemma algebra_ext {R : Type*} [comm_semiring R] {A : Type*} [semiring A] (P Q : algebra R A)
(w : ∀ (r : R), by { haveI := P, exact algebra_map R A r } =
by { haveI := Q, exact algebra_map R A r }) :
P = Q :=
begin
unfreezingI { rcases P with ⟨⟨P⟩⟩, rcases Q with ⟨⟨Q⟩⟩ },
congr,
{ funext r a,
replace w := congr_arg (λ s, s * a) (w r),
simp only [←algebra.smul_def''] at w,
apply w, },
{ ext r,
exact w r, },
{ apply proof_irrel_heq, },
{ apply proof_irrel_heq, },
end
@[priority 200] -- see Note [lower instance priority]
instance to_module : module R A :=
{ one_smul := by simp [smul_def''],
mul_smul := by simp [smul_def'', mul_assoc],
smul_add := by simp [smul_def'', mul_add],
smul_zero := by simp [smul_def''],
add_smul := by simp [smul_def'', add_mul],
zero_smul := by simp [smul_def''] }
-- from now on, we don't want to use the following instance anymore
attribute [instance, priority 0] algebra.to_has_scalar
lemma smul_def (r : R) (x : A) : r • x = algebra_map R A r * x :=
algebra.smul_def' r x
lemma algebra_map_eq_smul_one (r : R) : algebra_map R A r = r • 1 :=
calc algebra_map R A r = algebra_map R A r * 1 : (mul_one _).symm
... = r • 1 : (algebra.smul_def r 1).symm
lemma algebra_map_eq_smul_one' : ⇑(algebra_map R A) = λ r, r • (1 : A) :=
funext algebra_map_eq_smul_one
/-- `mul_comm` for `algebra`s when one element is from the base ring. -/
theorem commutes (r : R) (x : A) : algebra_map R A r * x = x * algebra_map R A r :=
algebra.commutes' r x
/-- `mul_left_comm` for `algebra`s when one element is from the base ring. -/
theorem left_comm (x : A) (r : R) (y : A) :
x * (algebra_map R A r * y) = algebra_map R A r * (x * y) :=
by rw [← mul_assoc, ← commutes, mul_assoc]
/-- `mul_right_comm` for `algebra`s when one element is from the base ring. -/
theorem right_comm (x : A) (r : R) (y : A) :
(x * algebra_map R A r) * y = (x * y) * algebra_map R A r :=
by rw [mul_assoc, commutes, ←mul_assoc]
instance _root_.is_scalar_tower.right : is_scalar_tower R A A :=
⟨λ x y z, by rw [smul_eq_mul, smul_eq_mul, smul_def, smul_def, mul_assoc]⟩
/-- This is just a special case of the global `mul_smul_comm` lemma that requires less typeclass
search (and was here first). -/
@[simp] protected lemma mul_smul_comm (s : R) (x y : A) :
x * (s • y) = s • (x * y) :=
-- TODO: set up `is_scalar_tower.smul_comm_class` earlier so that we can actually prove this using
-- `mul_smul_comm s x y`.
by rw [smul_def, smul_def, left_comm]
/-- This is just a special case of the global `smul_mul_assoc` lemma that requires less typeclass
search (and was here first). -/
@[simp] protected lemma smul_mul_assoc (r : R) (x y : A) :
(r • x) * y = r • (x * y) :=
smul_mul_assoc r x y
instance _root_.is_scalar_tower.opposite_right : is_scalar_tower R Aᵒᵖ A :=
⟨λ x y z, algebra.mul_smul_comm _ _ _⟩
section
variables {r : R} {a : A}
@[simp] lemma bit0_smul_one : bit0 r • (1 : A) = bit0 (r • (1 : A)) :=
by simp [bit0, add_smul]
lemma bit0_smul_one' : bit0 r • (1 : A) = r • 2 :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit0_smul_bit0 : bit0 r • bit0 a = r • (bit0 (bit0 a)) :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit0_smul_bit1 : bit0 r • bit1 a = r • (bit0 (bit1 a)) :=
by simp [bit0, add_smul, smul_add]
@[simp] lemma bit1_smul_one : bit1 r • (1 : A) = bit1 (r • (1 : A)) :=
by simp [bit1, add_smul]
lemma bit1_smul_one' : bit1 r • (1 : A) = r • 2 + 1 :=
by simp [bit1, bit0, add_smul, smul_add]
@[simp] lemma bit1_smul_bit0 : bit1 r • bit0 a = r • (bit0 (bit0 a)) + bit0 a :=
by simp [bit1, add_smul, smul_add]
@[simp] lemma bit1_smul_bit1 : bit1 r • bit1 a = r • (bit0 (bit1 a)) + bit1 a :=
by { simp only [bit0, bit1, add_smul, smul_add, one_smul], abel }
end
variables (R A)
/--
The canonical ring homomorphism `algebra_map R A : R →* A` for any `R`-algebra `A`,
packaged as an `R`-linear map.
-/
protected def linear_map : R →ₗ[R] A :=
{ map_smul' := λ x y, by simp [algebra.smul_def],
..algebra_map R A }
@[simp]
lemma linear_map_apply (r : R) : algebra.linear_map R A r = algebra_map R A r := rfl
instance id : algebra R R := (ring_hom.id R).to_algebra
variables {R A}
namespace id
@[simp] lemma map_eq_self (x : R) : algebra_map R R x = x := rfl
@[simp] lemma smul_eq_mul (x y : R) : x • y = x * y := rfl
end id
section prod
variables (R A B)
instance : algebra R (A × B) :=
{ commutes' := by { rintro r ⟨a, b⟩, dsimp, rw [commutes r a, commutes r b] },
smul_def' := by { rintro r ⟨a, b⟩, dsimp, rw [smul_def r a, smul_def r b] },
.. prod.module,
.. ring_hom.prod (algebra_map R A) (algebra_map R B) }
variables {R A B}
@[simp] lemma algebra_map_prod_apply (r : R) :
algebra_map R (A × B) r = (algebra_map R A r, algebra_map R B r) := rfl
end prod
/-- Algebra over a subsemiring. This builds upon `subsemiring.module`. -/
instance of_subsemiring (S : subsemiring R) : algebra S A :=
{ smul := (•),
commutes' := λ r x, algebra.commutes r x,
smul_def' := λ r x, algebra.smul_def r x,
.. (algebra_map R A).comp S.subtype }
/-- Algebra over a subring. This builds upon `subring.module`. -/
instance of_subring {R A : Type*} [comm_ring R] [ring A] [algebra R A]
(S : subring R) : algebra S A :=
{ smul := (•),
.. algebra.of_subsemiring S.to_subsemiring,
.. (algebra_map R A).comp S.subtype }
lemma algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :
(algebra_map S R : S →+* R) = subring.subtype S := rfl
lemma coe_algebra_map_of_subring {R : Type*} [comm_ring R] (S : subring R) :
(algebra_map S R : S → R) = subtype.val := rfl
lemma algebra_map_of_subring_apply {R : Type*} [comm_ring R] (S : subring R) (x : S) :
algebra_map S R x = x := rfl
/-- Explicit characterization of the submonoid map in the case of an algebra.
`S` is made explicit to help with type inference -/
def algebra_map_submonoid (S : Type*) [semiring S] [algebra R S]
(M : submonoid R) : (submonoid S) :=
submonoid.map (algebra_map R S : R →* S) M
lemma mem_algebra_map_submonoid_of_mem [algebra R S] {M : submonoid R} (x : M) :
(algebra_map R S x) ∈ algebra_map_submonoid S M :=
set.mem_image_of_mem (algebra_map R S) x.2
end semiring
section ring
variables [comm_ring R]
variables (R)
/-- A `semiring` that is an `algebra` over a commutative ring carries a natural `ring` structure. -/
def semiring_to_ring [semiring A] [algebra R A] : ring A := {
..module.add_comm_monoid_to_add_comm_group R,
..(infer_instance : semiring A) }
variables {R}
lemma mul_sub_algebra_map_commutes [ring A] [algebra R A] (x : A) (r : R) :
x * (x - algebra_map R A r) = (x - algebra_map R A r) * x :=
by rw [mul_sub, ←commutes, sub_mul]
lemma mul_sub_algebra_map_pow_commutes [ring A] [algebra R A] (x : A) (r : R) (n : ℕ) :
x * (x - algebra_map R A r) ^ n = (x - algebra_map R A r) ^ n * x :=
begin
induction n with n ih,
{ simp },
{ rw [pow_succ, ←mul_assoc, mul_sub_algebra_map_commutes,
mul_assoc, ih, ←mul_assoc], }
end
/-- If `algebra_map R A` is injective and `A` has no zero divisors,
`R`-multiples in `A` are zero only if one of the factors is zero.
Cannot be an instance because there is no `injective (algebra_map R A)` typeclass.
-/
lemma no_zero_smul_divisors.of_algebra_map_injective
[semiring A] [algebra R A] [no_zero_divisors A]
(h : function.injective (algebra_map R A)) : no_zero_smul_divisors R A :=
⟨λ c x hcx, (mul_eq_zero.mp ((smul_def c x).symm.trans hcx)).imp_left
((algebra_map R A).injective_iff.mp h _)⟩
end ring
section field
variables [field R] [semiring A] [algebra R A]
@[priority 100] -- see note [lower instance priority]
instance [nontrivial A] [no_zero_divisors A] : no_zero_smul_divisors R A :=
no_zero_smul_divisors.of_algebra_map_injective (algebra_map R A).injective
end field
end algebra
namespace opposite
variables {R A : Type*} [comm_semiring R] [semiring A] [algebra R A]
instance : algebra R Aᵒᵖ :=
{ to_ring_hom := (algebra_map R A).to_opposite $ λ x y, algebra.commutes _ _,
smul_def' := λ c x, unop_injective $
by { dsimp, simp only [op_mul, algebra.smul_def, algebra.commutes, op_unop] },
commutes' := λ r, op_induction $ λ x, by dsimp; simp only [← op_mul, algebra.commutes],
..opposite.has_scalar A R }
@[simp] lemma algebra_map_apply (c : R) : algebra_map R Aᵒᵖ c = op (algebra_map R A c) := rfl
end opposite
namespace module
variables (R : Type u) (M : Type v) [comm_semiring R] [add_comm_monoid M] [module R M]
instance endomorphism_algebra : algebra R (M →ₗ[R] M) :=
{ to_fun := λ r, r • linear_map.id,
map_one' := one_smul _ _,
map_zero' := zero_smul _ _,
map_add' := λ r₁ r₂, add_smul _ _ _,
map_mul' := λ r₁ r₂, by { ext x, simp [mul_smul] },
commutes' := by { intros, ext, simp },
smul_def' := by { intros, ext, simp } }
lemma algebra_map_End_eq_smul_id (a : R) :
(algebra_map R (End R M)) a = a • linear_map.id := rfl
@[simp] lemma algebra_map_End_apply (a : R) (m : M) :
(algebra_map R (End R M)) a m = a • m := rfl
@[simp] lemma ker_algebra_map_End (K : Type u) (V : Type v)
[field K] [add_comm_group V] [module K V] (a : K) (ha : a ≠ 0) :
((algebra_map K (End K V)) a).ker = ⊥ :=
linear_map.ker_smul _ _ ha
end module
set_option old_structure_cmd true
/-- Defining the homomorphism in the category R-Alg. -/
@[nolint has_inhabited_instance]
structure alg_hom (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B] extends ring_hom A B :=
(commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
run_cmd tactic.add_doc_string `alg_hom.to_ring_hom "Reinterpret an `alg_hom` as a `ring_hom`"
infixr ` →ₐ `:25 := alg_hom _
notation A ` →ₐ[`:25 R `] ` B := alg_hom R A B
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {C : Type u₁} {D : Type v₁}
section semiring
variables [comm_semiring R] [semiring A] [semiring B] [semiring C] [semiring D]
variables [algebra R A] [algebra R B] [algebra R C] [algebra R D]
instance : has_coe_to_fun (A →ₐ[R] B) := ⟨_, λ f, f.to_fun⟩
initialize_simps_projections alg_hom (to_fun → apply)
@[simp] lemma to_fun_eq_coe (f : A →ₐ[R] B) : f.to_fun = f := rfl
instance coe_ring_hom : has_coe (A →ₐ[R] B) (A →+* B) := ⟨alg_hom.to_ring_hom⟩
instance coe_monoid_hom : has_coe (A →ₐ[R] B) (A →* B) := ⟨λ f, ↑(f : A →+* B)⟩
instance coe_add_monoid_hom : has_coe (A →ₐ[R] B) (A →+ B) := ⟨λ f, ↑(f : A →+* B)⟩
@[simp, norm_cast] lemma coe_mk {f : A → B} (h₁ h₂ h₃ h₄ h₅) :
⇑(⟨f, h₁, h₂, h₃, h₄, h₅⟩ : A →ₐ[R] B) = f := rfl
-- make the coercion the simp-normal form
@[simp] lemma to_ring_hom_eq_coe (f : A →ₐ[R] B) : f.to_ring_hom = f := rfl
@[simp, norm_cast] lemma coe_to_ring_hom (f : A →ₐ[R] B) : ⇑(f : A →+* B) = f := rfl
-- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute.
@[norm_cast] lemma coe_to_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A →* B) = f := rfl
-- as `simp` can already prove this lemma, it is not tagged with the `simp` attribute.
@[norm_cast] lemma coe_to_add_monoid_hom (f : A →ₐ[R] B) : ⇑(f : A →+ B) = f := rfl
variables (φ : A →ₐ[R] B)
theorem coe_fn_inj ⦃φ₁ φ₂ : A →ₐ[R] B⦄ (H : ⇑φ₁ = φ₂) : φ₁ = φ₂ :=
by { cases φ₁, cases φ₂, congr, exact H }
theorem coe_ring_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →+* B)) :=
λ φ₁ φ₂ H, coe_fn_inj $ show ((φ₁ : (A →+* B)) : A → B) = ((φ₂ : (A →+* B)) : A → B),
from congr_arg _ H
theorem coe_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →* B)) :=
ring_hom.coe_monoid_hom_injective.comp coe_ring_hom_injective
theorem coe_add_monoid_hom_injective : function.injective (coe : (A →ₐ[R] B) → (A →+ B)) :=
ring_hom.coe_add_monoid_hom_injective.comp coe_ring_hom_injective
protected lemma congr_fun {φ₁ φ₂ : A →ₐ[R] B} (H : φ₁ = φ₂) (x : A) : φ₁ x = φ₂ x := H ▸ rfl
protected lemma congr_arg (φ : A →ₐ[R] B) {x y : A} (h : x = y) : φ x = φ y := h ▸ rfl
@[ext]
theorem ext {φ₁ φ₂ : A →ₐ[R] B} (H : ∀ x, φ₁ x = φ₂ x) : φ₁ = φ₂ :=
coe_fn_inj $ funext H
theorem ext_iff {φ₁ φ₂ : A →ₐ[R] B} : φ₁ = φ₂ ↔ ∀ x, φ₁ x = φ₂ x :=
⟨alg_hom.congr_fun, ext⟩
@[simp] theorem mk_coe {f : A →ₐ[R] B} (h₁ h₂ h₃ h₄ h₅) :
(⟨f, h₁, h₂, h₃, h₄, h₅⟩ : A →ₐ[R] B) = f := ext $ λ _, rfl
@[simp]
theorem commutes (r : R) : φ (algebra_map R A r) = algebra_map R B r := φ.commutes' r
theorem comp_algebra_map : (φ : A →+* B).comp (algebra_map R A) = algebra_map R B :=
ring_hom.ext $ φ.commutes
@[simp] lemma map_add (r s : A) : φ (r + s) = φ r + φ s :=
φ.to_ring_hom.map_add r s
@[simp] lemma map_zero : φ 0 = 0 :=
φ.to_ring_hom.map_zero
@[simp] lemma map_mul (x y) : φ (x * y) = φ x * φ y :=
φ.to_ring_hom.map_mul x y
@[simp] lemma map_one : φ 1 = 1 :=
φ.to_ring_hom.map_one
@[simp] lemma map_smul (r : R) (x : A) : φ (r • x) = r • φ x :=
by simp only [algebra.smul_def, map_mul, commutes]
@[simp] lemma map_pow (x : A) (n : ℕ) : φ (x ^ n) = (φ x) ^ n :=
φ.to_ring_hom.map_pow x n
lemma map_sum {ι : Type*} (f : ι → A) (s : finset ι) :
φ (∑ x in s, f x) = ∑ x in s, φ (f x) :=
φ.to_ring_hom.map_sum f s
lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A) :
φ (f.sum g) = f.sum (λ i a, φ (g i a)) :=
φ.map_sum _ _
@[simp] lemma map_nat_cast (n : ℕ) : φ n = n :=
φ.to_ring_hom.map_nat_cast n
@[simp] lemma map_bit0 (x) : φ (bit0 x) = bit0 (φ x) :=
φ.to_ring_hom.map_bit0 x
@[simp] lemma map_bit1 (x) : φ (bit1 x) = bit1 (φ x) :=
φ.to_ring_hom.map_bit1 x
/-- If a `ring_hom` is `R`-linear, then it is an `alg_hom`. -/
def mk' (f : A →+* B) (h : ∀ (c : R) x, f (c • x) = c • f x) : A →ₐ[R] B :=
{ to_fun := f,
commutes' := λ c, by simp only [algebra.algebra_map_eq_smul_one, h, f.map_one],
.. f }
@[simp] lemma coe_mk' (f : A →+* B) (h : ∀ (c : R) x, f (c • x) = c • f x) : ⇑(mk' f h) = f := rfl
section
variables (R A)
/-- Identity map as an `alg_hom`. -/
protected def id : A →ₐ[R] A :=
{ commutes' := λ _, rfl,
..ring_hom.id A }
@[simp] lemma coe_id : ⇑(alg_hom.id R A) = id := rfl
@[simp] lemma id_to_ring_hom : (alg_hom.id R A : A →+* A) = ring_hom.id _ := rfl
end
lemma id_apply (p : A) : alg_hom.id R A p = p := rfl
/-- Composition of algebra homeomorphisms. -/
def comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : A →ₐ[R] C :=
{ commutes' := λ r : R, by rw [← φ₁.commutes, ← φ₂.commutes]; refl,
.. φ₁.to_ring_hom.comp ↑φ₂ }
@[simp] lemma coe_comp (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) : ⇑(φ₁.comp φ₂) = φ₁ ∘ φ₂ := rfl
lemma comp_apply (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) (p : A) : φ₁.comp φ₂ p = φ₁ (φ₂ p) := rfl
lemma comp_to_ring_hom (φ₁ : B →ₐ[R] C) (φ₂ : A →ₐ[R] B) :
⇑(φ₁.comp φ₂ : A →+* C) = (φ₁ : B →+* C).comp ↑φ₂ := rfl
@[simp] theorem comp_id : φ.comp (alg_hom.id R A) = φ :=
ext $ λ x, rfl
@[simp] theorem id_comp : (alg_hom.id R B).comp φ = φ :=
ext $ λ x, rfl
theorem comp_assoc (φ₁ : C →ₐ[R] D) (φ₂ : B →ₐ[R] C) (φ₃ : A →ₐ[R] B) :
(φ₁.comp φ₂).comp φ₃ = φ₁.comp (φ₂.comp φ₃) :=
ext $ λ x, rfl
/-- R-Alg ⥤ R-Mod -/
def to_linear_map : A →ₗ B :=
{ to_fun := φ,
map_add' := φ.map_add,
map_smul' := φ.map_smul }
@[simp] lemma to_linear_map_apply (p : A) : φ.to_linear_map p = φ p := rfl
theorem to_linear_map_injective : function.injective (to_linear_map : _ → (A →ₗ[R] B)) :=
λ φ₁ φ₂ h, ext $ linear_map.congr_fun h
@[simp] lemma comp_to_linear_map (f : A →ₐ[R] B) (g : B →ₐ[R] C) :
(g.comp f).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl
@[simp] lemma to_linear_map_id : to_linear_map (alg_hom.id R A) = linear_map.id :=
linear_map.ext $ λ _, rfl
/-- Promote a `linear_map` to an `alg_hom` by supplying proofs about the behavior on `1` and `*`. -/
@[simps]
def of_linear_map (f : A →ₗ[R] B) (map_one : f 1 = 1) (map_mul : ∀ x y, f (x * y) = f x * f y) :
A →ₐ[R] B :=
{ to_fun := f,
map_one' := map_one,
map_mul' := map_mul,
commutes' := λ c, by simp only [algebra.algebra_map_eq_smul_one, f.map_smul, map_one],
.. f.to_add_monoid_hom }
@[simp] lemma of_linear_map_to_linear_map (map_one) (map_mul) :
of_linear_map φ.to_linear_map map_one map_mul = φ :=
by { ext, refl }
@[simp] lemma to_linear_map_of_linear_map (f : A →ₗ[R] B) (map_one) (map_mul) :
to_linear_map (of_linear_map f map_one map_mul) = f :=
by { ext, refl }
@[simp] lemma of_linear_map_id (map_one) (map_mul) :
of_linear_map linear_map.id map_one map_mul = alg_hom.id R A :=
ext $ λ _, rfl
lemma map_list_prod (s : list A) :
φ s.prod = (s.map φ).prod :=
φ.to_ring_hom.map_list_prod s
section prod
/-- First projection as `alg_hom`. -/
def fst : A × B →ₐ[R] A :=
{ commutes' := λ r, rfl, .. ring_hom.fst A B}
/-- Second projection as `alg_hom`. -/
def snd : A × B →ₐ[R] B :=
{ commutes' := λ r, rfl, .. ring_hom.snd A B}
end prod
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A] [comm_semiring B]
variables [algebra R A] [algebra R B] (φ : A →ₐ[R] B)
lemma map_multiset_prod (s : multiset A) :
φ s.prod = (s.map φ).prod :=
φ.to_ring_hom.map_multiset_prod s
lemma map_prod {ι : Type*} (f : ι → A) (s : finset ι) :
φ (∏ x in s, f x) = ∏ x in s, φ (f x) :=
φ.to_ring_hom.map_prod f s
lemma map_finsupp_prod {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A) :
φ (f.prod g) = f.prod (λ i a, φ (g i a)) :=
φ.map_prod _ _
end comm_semiring
section ring
variables [comm_semiring R] [ring A] [ring B]
variables [algebra R A] [algebra R B] (φ : A →ₐ[R] B)
@[simp] lemma map_neg (x) : φ (-x) = -φ x :=
φ.to_ring_hom.map_neg x
@[simp] lemma map_sub (x y) : φ (x - y) = φ x - φ y :=
φ.to_ring_hom.map_sub x y
@[simp] lemma map_int_cast (n : ℤ) : φ n = n :=
φ.to_ring_hom.map_int_cast n
end ring
section division_ring
variables [comm_ring R] [division_ring A] [division_ring B]
variables [algebra R A] [algebra R B] (φ : A →ₐ[R] B)
@[simp] lemma map_inv (x) : φ (x⁻¹) = (φ x)⁻¹ :=
φ.to_ring_hom.map_inv x
@[simp] lemma map_div (x y) : φ (x / y) = φ x / φ y :=
φ.to_ring_hom.map_div x y
end division_ring
theorem injective_iff {R A B : Type*} [comm_semiring R] [ring A] [semiring B]
[algebra R A] [algebra R B] (f : A →ₐ[R] B) :
function.injective f ↔ (∀ x, f x = 0 → x = 0) :=
ring_hom.injective_iff (f : A →+* B)
end alg_hom
@[simp] lemma rat.smul_one_eq_coe {A : Type*} [division_ring A] [algebra ℚ A] (m : ℚ) :
m • (1 : A) = ↑m :=
by rw [algebra.smul_def, mul_one, ring_hom.eq_rat_cast]
set_option old_structure_cmd true
/-- An equivalence of algebras is an equivalence of rings commuting with the actions of scalars. -/
structure alg_equiv (R : Type u) (A : Type v) (B : Type w)
[comm_semiring R] [semiring A] [semiring B] [algebra R A] [algebra R B]
extends A ≃ B, A ≃* B, A ≃+ B, A ≃+* B :=
(commutes' : ∀ r : R, to_fun (algebra_map R A r) = algebra_map R B r)
attribute [nolint doc_blame] alg_equiv.to_ring_equiv
attribute [nolint doc_blame] alg_equiv.to_equiv
attribute [nolint doc_blame] alg_equiv.to_add_equiv
attribute [nolint doc_blame] alg_equiv.to_mul_equiv
notation A ` ≃ₐ[`:50 R `] ` A' := alg_equiv R A A'
namespace alg_equiv
variables {R : Type u} {A₁ : Type v} {A₂ : Type w} {A₃ : Type u₁}
section semiring
variables [comm_semiring R] [semiring A₁] [semiring A₂] [semiring A₃]
variables [algebra R A₁] [algebra R A₂] [algebra R A₃]
variables (e : A₁ ≃ₐ[R] A₂)
instance : has_coe_to_fun (A₁ ≃ₐ[R] A₂) := ⟨_, alg_equiv.to_fun⟩
@[ext]
lemma ext {f g : A₁ ≃ₐ[R] A₂} (h : ∀ a, f a = g a) : f = g :=
begin
have h₁ : f.to_equiv = g.to_equiv := equiv.ext h,
cases f, cases g, congr,
{ exact (funext h) },
{ exact congr_arg equiv.inv_fun h₁ }
end
protected lemma congr_arg {f : A₁ ≃ₐ[R] A₂} : Π {x x' : A₁}, x = x' → f x = f x'
| _ _ rfl := rfl
protected lemma congr_fun {f g : A₁ ≃ₐ[R] A₂} (h : f = g) (x : A₁) : f x = g x := h ▸ rfl
lemma ext_iff {f g : A₁ ≃ₐ[R] A₂} : f = g ↔ ∀ x, f x = g x :=
⟨λ h x, h ▸ rfl, ext⟩
lemma coe_fun_injective : @function.injective (A₁ ≃ₐ[R] A₂) (A₁ → A₂) (λ e, (e : A₁ → A₂)) :=
begin
intros f g w,
ext,
exact congr_fun w a,
end
instance has_coe_to_ring_equiv : has_coe (A₁ ≃ₐ[R] A₂) (A₁ ≃+* A₂) := ⟨alg_equiv.to_ring_equiv⟩
@[simp] lemma coe_mk {to_fun inv_fun left_inv right_inv map_mul map_add commutes} :
⇑(⟨to_fun, inv_fun, left_inv, right_inv, map_mul, map_add, commutes⟩ : A₁ ≃ₐ[R] A₂) = to_fun :=
rfl
@[simp] theorem mk_coe (e : A₁ ≃ₐ[R] A₂) (e' h₁ h₂ h₃ h₄ h₅) :
(⟨e, e', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂) = e := ext $ λ _, rfl
@[simp] lemma to_fun_eq_coe (e : A₁ ≃ₐ[R] A₂) : e.to_fun = e := rfl
-- TODO: decide on a simp-normal form so that only one of these two lemmas is needed
@[simp, norm_cast] lemma coe_ring_equiv : ((e : A₁ ≃+* A₂) : A₁ → A₂) = e := rfl
@[simp] lemma coe_ring_equiv' : (e.to_ring_equiv : A₁ → A₂) = e := rfl
lemma coe_ring_equiv_injective : function.injective (coe : (A₁ ≃ₐ[R] A₂) → (A₁ ≃+* A₂)) :=
λ e₁ e₂ h, ext $ ring_equiv.congr_fun h
@[simp] lemma map_add : ∀ x y, e (x + y) = e x + e y := e.to_add_equiv.map_add
@[simp] lemma map_zero : e 0 = 0 := e.to_add_equiv.map_zero
@[simp] lemma map_mul : ∀ x y, e (x * y) = (e x) * (e y) := e.to_mul_equiv.map_mul
@[simp] lemma map_one : e 1 = 1 := e.to_mul_equiv.map_one
@[simp] lemma commutes : ∀ (r : R), e (algebra_map R A₁ r) = algebra_map R A₂ r :=
e.commutes'
lemma map_sum {ι : Type*} (f : ι → A₁) (s : finset ι) :
e (∑ x in s, f x) = ∑ x in s, e (f x) :=
e.to_add_equiv.map_sum f s
lemma map_finsupp_sum {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A₁) :
e (f.sum g) = f.sum (λ i b, e (g i b)) :=
e.map_sum _ _
/-- Interpret an algebra equivalence as an algebra homomorphism.
This definition is included for symmetry with the other `to_*_hom` projections.
The `simp` normal form is to use the coercion of the `has_coe_to_alg_hom` instance. -/
def to_alg_hom : A₁ →ₐ[R] A₂ :=
{ map_one' := e.map_one, map_zero' := e.map_zero, ..e }
instance has_coe_to_alg_hom : has_coe (A₁ ≃ₐ[R] A₂) (A₁ →ₐ[R] A₂) :=
⟨to_alg_hom⟩
@[simp] lemma to_alg_hom_eq_coe : e.to_alg_hom = e := rfl
@[simp, norm_cast] lemma coe_alg_hom : ((e : A₁ →ₐ[R] A₂) : A₁ → A₂) = e :=
rfl
lemma coe_alg_hom_injective : function.injective (coe : (A₁ ≃ₐ[R] A₂) → (A₁ →ₐ[R] A₂)) :=
λ e₁ e₂ h, ext $ alg_hom.congr_fun h
/-- The two paths coercion can take to a `ring_hom` are equivalent -/
lemma coe_ring_hom_commutes : ((e : A₁ →ₐ[R] A₂) : A₁ →+* A₂) = ((e : A₁ ≃+* A₂) : A₁ →+* A₂) :=
rfl
@[simp] lemma map_pow : ∀ (x : A₁) (n : ℕ), e (x ^ n) = (e x) ^ n := e.to_alg_hom.map_pow
lemma injective : function.injective e := e.to_equiv.injective
lemma surjective : function.surjective e := e.to_equiv.surjective
lemma bijective : function.bijective e := e.to_equiv.bijective
instance : has_one (A₁ ≃ₐ[R] A₁) := ⟨{commutes' := λ r, rfl, ..(1 : A₁ ≃+* A₁)}⟩
instance : inhabited (A₁ ≃ₐ[R] A₁) := ⟨1⟩
/-- Algebra equivalences are reflexive. -/
@[refl]
def refl : A₁ ≃ₐ[R] A₁ := 1
@[simp] lemma refl_to_alg_hom : ↑(refl : A₁ ≃ₐ[R] A₁) = alg_hom.id R A₁ := rfl
@[simp] lemma coe_refl : ⇑(refl : A₁ ≃ₐ[R] A₁) = id := rfl
/-- Algebra equivalences are symmetric. -/
@[symm]
def symm (e : A₁ ≃ₐ[R] A₂) : A₂ ≃ₐ[R] A₁ :=
{ commutes' := λ r, by { rw ←e.to_ring_equiv.symm_apply_apply (algebra_map R A₁ r), congr,
change _ = e _, rw e.commutes, },
..e.to_ring_equiv.symm, }
/-- See Note [custom simps projection] -/
def simps.symm_apply (e : A₁ ≃ₐ[R] A₂) : A₂ → A₁ := e.symm
initialize_simps_projections alg_equiv (to_fun → apply, inv_fun → symm_apply)
@[simp] lemma inv_fun_eq_symm {e : A₁ ≃ₐ[R] A₂} : e.inv_fun = e.symm := rfl
@[simp] lemma symm_symm (e : A₁ ≃ₐ[R] A₂) : e.symm.symm = e :=
by { ext, refl, }
lemma symm_bijective : function.bijective (symm : (A₁ ≃ₐ[R] A₂) → (A₂ ≃ₐ[R] A₁)) :=
equiv.bijective ⟨symm, symm, symm_symm, symm_symm⟩
@[simp] lemma mk_coe' (e : A₁ ≃ₐ[R] A₂) (f h₁ h₂ h₃ h₄ h₅) :
(⟨f, e, h₁, h₂, h₃, h₄, h₅⟩ : A₂ ≃ₐ[R] A₁) = e.symm :=
symm_bijective.injective $ ext $ λ x, rfl
@[simp] theorem symm_mk (f f') (h₁ h₂ h₃ h₄ h₅) :
(⟨f, f', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm =
{ to_fun := f', inv_fun := f,
..(⟨f, f', h₁, h₂, h₃, h₄, h₅⟩ : A₁ ≃ₐ[R] A₂).symm } := rfl
/-- Algebra equivalences are transitive. -/
@[trans]
def trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) : A₁ ≃ₐ[R] A₃ :=
{ commutes' := λ r, show e₂.to_fun (e₁.to_fun _) = _, by rw [e₁.commutes', e₂.commutes'],
..(e₁.to_ring_equiv.trans e₂.to_ring_equiv), }
@[simp] lemma apply_symm_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e (e.symm x) = x :=
e.to_equiv.apply_symm_apply
@[simp] lemma symm_apply_apply (e : A₁ ≃ₐ[R] A₂) : ∀ x, e.symm (e x) = x :=
e.to_equiv.symm_apply_apply
@[simp] lemma coe_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) :
⇑(e₁.trans e₂) = e₂ ∘ e₁ := rfl
lemma trans_apply (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) (x : A₁) :
(e₁.trans e₂) x = e₂ (e₁ x) := rfl
@[simp] lemma comp_symm (e : A₁ ≃ₐ[R] A₂) :
alg_hom.comp (e : A₁ →ₐ[R] A₂) ↑e.symm = alg_hom.id R A₂ :=
by { ext, simp }
@[simp] lemma symm_comp (e : A₁ ≃ₐ[R] A₂) :
alg_hom.comp ↑e.symm (e : A₁ →ₐ[R] A₂) = alg_hom.id R A₁ :=
by { ext, simp }
theorem left_inverse_symm (e : A₁ ≃ₐ[R] A₂) : function.left_inverse e.symm e := e.left_inv
theorem right_inverse_symm (e : A₁ ≃ₐ[R] A₂) : function.right_inverse e.symm e := e.right_inv
/-- If `A₁` is equivalent to `A₁'` and `A₂` is equivalent to `A₂'`, then the type of maps
`A₁ →ₐ[R] A₂` is equivalent to the type of maps `A₁' →ₐ[R] A₂'`. -/
def arrow_congr {A₁' A₂' : Type*} [semiring A₁'] [semiring A₂'] [algebra R A₁'] [algebra R A₂']
(e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') : (A₁ →ₐ[R] A₂) ≃ (A₁' →ₐ[R] A₂') :=
{ to_fun := λ f, (e₂.to_alg_hom.comp f).comp e₁.symm.to_alg_hom,
inv_fun := λ f, (e₂.symm.to_alg_hom.comp f).comp e₁.to_alg_hom,
left_inv := λ f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, symm_comp],
simp only [←alg_hom.comp_assoc, symm_comp, alg_hom.id_comp, alg_hom.comp_id] },
right_inv := λ f, by { simp only [alg_hom.comp_assoc, to_alg_hom_eq_coe, comp_symm],
simp only [←alg_hom.comp_assoc, comp_symm, alg_hom.id_comp, alg_hom.comp_id] } }
lemma arrow_congr_comp {A₁' A₂' A₃' : Type*} [semiring A₁'] [semiring A₂'] [semiring A₃']
[algebra R A₁'] [algebra R A₂'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂')
(e₃ : A₃ ≃ₐ[R] A₃') (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₃) :
arrow_congr e₁ e₃ (g.comp f) = (arrow_congr e₂ e₃ g).comp (arrow_congr e₁ e₂ f) :=
by { ext, simp only [arrow_congr, equiv.coe_fn_mk, alg_hom.comp_apply],
congr, exact (e₂.symm_apply_apply _).symm }
@[simp] lemma arrow_congr_refl :
arrow_congr alg_equiv.refl alg_equiv.refl = equiv.refl (A₁ →ₐ[R] A₂) :=
by { ext, refl }
@[simp] lemma arrow_congr_trans {A₁' A₂' A₃' : Type*} [semiring A₁'] [semiring A₂'] [semiring A₃']
[algebra R A₁'] [algebra R A₂'] [algebra R A₃'] (e₁ : A₁ ≃ₐ[R] A₂) (e₁' : A₁' ≃ₐ[R] A₂')
(e₂ : A₂ ≃ₐ[R] A₃) (e₂' : A₂' ≃ₐ[R] A₃') :
arrow_congr (e₁.trans e₂) (e₁'.trans e₂') = (arrow_congr e₁ e₁').trans (arrow_congr e₂ e₂') :=
by { ext, refl }
@[simp] lemma arrow_congr_symm {A₁' A₂' : Type*} [semiring A₁'] [semiring A₂']
[algebra R A₁'] [algebra R A₂'] (e₁ : A₁ ≃ₐ[R] A₁') (e₂ : A₂ ≃ₐ[R] A₂') :
(arrow_congr e₁ e₂).symm = arrow_congr e₁.symm e₂.symm :=
by { ext, refl }
/-- If an algebra morphism has an inverse, it is a algebra isomorphism. -/
def of_alg_hom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ : f.comp g = alg_hom.id R A₂)
(h₂ : g.comp f = alg_hom.id R A₁) : A₁ ≃ₐ[R] A₂ :=
{ to_fun := f,
inv_fun := g,
left_inv := alg_hom.ext_iff.1 h₂,
right_inv := alg_hom.ext_iff.1 h₁,
..f }
lemma coe_alg_hom_of_alg_hom (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
↑(of_alg_hom f g h₁ h₂) = f := alg_hom.ext $ λ _, rfl
@[simp]
lemma of_alg_hom_coe_alg_hom (f : A₁ ≃ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
of_alg_hom ↑f g h₁ h₂ = f := ext $ λ _, rfl
lemma of_alg_hom_symm (f : A₁ →ₐ[R] A₂) (g : A₂ →ₐ[R] A₁) (h₁ h₂) :
(of_alg_hom f g h₁ h₂).symm = of_alg_hom g f h₂ h₁ := rfl
/-- Promotes a bijective algebra homomorphism to an algebra equivalence. -/
noncomputable def of_bijective (f : A₁ →ₐ[R] A₂) (hf : function.bijective f) : A₁ ≃ₐ[R] A₂ :=
{ .. ring_equiv.of_bijective (f : A₁ →+* A₂) hf, .. f }
/-- Forgetting the multiplicative structures, an equivalence of algebras is a linear equivalence. -/
@[simps apply] def to_linear_equiv (e : A₁ ≃ₐ[R] A₂) : A₁ ≃ₗ[R] A₂ :=
{ to_fun := e,
map_smul' := λ r x, by simp [algebra.smul_def''],
inv_fun := e.symm,
.. e }
@[simp] lemma to_linear_equiv_refl :
(alg_equiv.refl : A₁ ≃ₐ[R] A₁).to_linear_equiv = linear_equiv.refl R A₁ := rfl
@[simp] lemma to_linear_equiv_symm (e : A₁ ≃ₐ[R] A₂) :
e.to_linear_equiv.symm = e.symm.to_linear_equiv := rfl
@[simp] lemma to_linear_equiv_trans (e₁ : A₁ ≃ₐ[R] A₂) (e₂ : A₂ ≃ₐ[R] A₃) :
(e₁.trans e₂).to_linear_equiv = e₁.to_linear_equiv.trans e₂.to_linear_equiv := rfl
theorem to_linear_equiv_injective : function.injective (to_linear_equiv : _ → (A₁ ≃ₗ[R] A₂)) :=
λ e₁ e₂ h, ext $ linear_equiv.congr_fun h
/-- Interpret an algebra equivalence as a linear map. -/
def to_linear_map : A₁ →ₗ[R] A₂ :=
e.to_alg_hom.to_linear_map
@[simp] lemma to_alg_hom_to_linear_map :
(e : A₁ →ₐ[R] A₂).to_linear_map = e.to_linear_map := rfl
@[simp] lemma to_linear_equiv_to_linear_map :
e.to_linear_equiv.to_linear_map = e.to_linear_map := rfl
@[simp] lemma to_linear_map_apply (x : A₁) : e.to_linear_map x = e x := rfl
theorem to_linear_map_injective : function.injective (to_linear_map : _ → (A₁ →ₗ[R] A₂)) :=
λ e₁ e₂ h, ext $ linear_map.congr_fun h
@[simp] lemma trans_to_linear_map (f : A₁ ≃ₐ[R] A₂) (g : A₂ ≃ₐ[R] A₃) :
(f.trans g).to_linear_map = g.to_linear_map.comp f.to_linear_map := rfl
section of_linear_equiv
variables (l : A₁ ≃ₗ[R] A₂)
(map_mul : ∀ x y : A₁, l (x * y) = l x * l y)
(commutes : ∀ r : R, l (algebra_map R A₁ r) = algebra_map R A₂ r)
/--
Upgrade a linear equivalence to an algebra equivalence,
given that it distributes over multiplication and action of scalars.
-/
@[simps apply]
def of_linear_equiv : A₁ ≃ₐ[R] A₂ :=
{ to_fun := l,
inv_fun := l.symm,
map_mul' := map_mul,
commutes' := commutes,
..l }
@[simp]
lemma of_linear_equiv_symm :
(of_linear_equiv l map_mul commutes).symm = of_linear_equiv l.symm
((of_linear_equiv l map_mul commutes).symm.map_mul)
((of_linear_equiv l map_mul commutes).symm.commutes) :=
rfl
@[simp] lemma of_linear_equiv_to_linear_equiv (map_mul) (commutes) :
of_linear_equiv e.to_linear_equiv map_mul commutes = e :=
by { ext, refl }
@[simp] lemma to_linear_equiv_of_linear_equiv :
to_linear_equiv (of_linear_equiv l map_mul commutes) = l :=
by { ext, refl }
end of_linear_equiv
instance aut : group (A₁ ≃ₐ[R] A₁) :=
{ mul := λ ϕ ψ, ψ.trans ϕ,
mul_assoc := λ ϕ ψ χ, rfl,
one := 1,
one_mul := λ ϕ, by { ext, refl },
mul_one := λ ϕ, by { ext, refl },
inv := symm,
mul_left_inv := λ ϕ, by { ext, exact symm_apply_apply ϕ a } }
@[simp] lemma mul_apply (e₁ e₂ : A₁ ≃ₐ[R] A₁) (x : A₁) : (e₁ * e₂) x = e₁ (e₂ x) := rfl
/-- An algebra isomorphism induces a group isomorphism between automorphism groups -/
@[simps apply]
def aut_congr (ϕ : A₁ ≃ₐ[R] A₂) : (A₁ ≃ₐ[R] A₁) ≃* (A₂ ≃ₐ[R] A₂) :=
{ to_fun := λ ψ, ϕ.symm.trans (ψ.trans ϕ),
inv_fun := λ ψ, ϕ.trans (ψ.trans ϕ.symm),
left_inv := λ ψ, by { ext, simp_rw [trans_apply, symm_apply_apply] },
right_inv := λ ψ, by { ext, simp_rw [trans_apply, apply_symm_apply] },
map_mul' := λ ψ χ, by { ext, simp only [mul_apply, trans_apply, symm_apply_apply] } }
@[simp] lemma aut_congr_refl : aut_congr (alg_equiv.refl) = mul_equiv.refl (A₁ ≃ₐ[R] A₁) :=
by { ext, refl }
@[simp] lemma aut_congr_symm (ϕ : A₁ ≃ₐ[R] A₂) : (aut_congr ϕ).symm = aut_congr ϕ.symm := rfl
@[simp] lemma aut_congr_trans (ϕ : A₁ ≃ₐ[R] A₂) (ψ : A₂ ≃ₐ[R] A₃) :
(aut_congr ϕ).trans (aut_congr ψ) = aut_congr (ϕ.trans ψ) := rfl
end semiring
section comm_semiring
variables [comm_semiring R] [comm_semiring A₁] [comm_semiring A₂]
variables [algebra R A₁] [algebra R A₂] (e : A₁ ≃ₐ[R] A₂)
lemma map_prod {ι : Type*} (f : ι → A₁) (s : finset ι) :
e (∏ x in s, f x) = ∏ x in s, e (f x) :=
e.to_alg_hom.map_prod f s
lemma map_finsupp_prod {α : Type*} [has_zero α] {ι : Type*} (f : ι →₀ α) (g : ι → α → A₁) :
e (f.prod g) = f.prod (λ i a, e (g i a)) :=
e.to_alg_hom.map_finsupp_prod f g
end comm_semiring
section ring
variables [comm_ring R] [ring A₁] [ring A₂]
variables [algebra R A₁] [algebra R A₂] (e : A₁ ≃ₐ[R] A₂)
@[simp] lemma map_neg (x) : e (-x) = -e x :=
e.to_alg_hom.map_neg x
@[simp] lemma map_sub (x y) : e (x - y) = e x - e y :=
e.to_alg_hom.map_sub x y
end ring
section division_ring
variables [comm_ring R] [division_ring A₁] [division_ring A₂]
variables [algebra R A₁] [algebra R A₂] (e : A₁ ≃ₐ[R] A₂)
@[simp] lemma map_inv (x) : e (x⁻¹) = (e x)⁻¹ :=
e.to_alg_hom.map_inv x
@[simp] lemma map_div (x y) : e (x / y) = e x / e y :=
e.to_alg_hom.map_div x y
end division_ring
end alg_equiv
section nat
variables {R : Type*} [semiring R]
-- Lower the priority so that `algebra.id` is picked most of the time when working with
-- `ℕ`-algebras. This is only an issue since `algebra.id` and `algebra_nat` are not yet defeq.
-- TODO: fix this by adding an `of_nat` field to semirings.
/-- Semiring ⥤ ℕ-Alg -/
@[priority 99] instance algebra_nat : algebra ℕ R :=
{ commutes' := nat.cast_commute,
smul_def' := λ _ _, nsmul_eq_mul _ _,
to_ring_hom := nat.cast_ring_hom R }
instance nat_algebra_subsingleton : subsingleton (algebra ℕ R) :=
⟨λ P Q, by { ext, simp, }⟩
end nat
namespace ring_hom
variables {R S : Type*}
/-- Reinterpret a `ring_hom` as an `ℕ`-algebra homomorphism. -/
def to_nat_alg_hom [semiring R] [semiring S] (f : R →+* S) :
R →ₐ[ℕ] S :=
{ to_fun := f, commutes' := λ n, by simp, .. f }
/-- Reinterpret a `ring_hom` as a `ℤ`-algebra homomorphism. -/
def to_int_alg_hom [ring R] [ring S] [algebra ℤ R] [algebra ℤ S] (f : R →+* S) :
R →ₐ[ℤ] S :=
{ commutes' := λ n, by simp, .. f }
@[simp] lemma map_rat_algebra_map [ring R] [ring S] [algebra ℚ R] [algebra ℚ S] (f : R →+* S)
(r : ℚ) :
f (algebra_map ℚ R r) = algebra_map ℚ S r :=
ring_hom.ext_iff.1 (subsingleton.elim (f.comp (algebra_map ℚ R)) (algebra_map ℚ S)) r
/-- Reinterpret a `ring_hom` as a `ℚ`-algebra homomorphism. -/
def to_rat_alg_hom [ring R] [ring S] [algebra ℚ R] [algebra ℚ S] (f : R →+* S) :
R →ₐ[ℚ] S :=
{ commutes' := f.map_rat_algebra_map, .. f }
end ring_hom
namespace rat
instance algebra_rat {α} [division_ring α] [char_zero α] : algebra ℚ α :=
(rat.cast_hom α).to_algebra' $ λ r x, r.cast_commute x
@[simp] theorem algebra_map_rat_rat : algebra_map ℚ ℚ = ring_hom.id ℚ :=
subsingleton.elim _ _
-- TODO[gh-6025]: make this an instance once safe to do so
lemma algebra_rat_subsingleton {α} [semiring α] :
subsingleton (algebra ℚ α) :=
⟨λ x y, algebra.algebra_ext x y $ ring_hom.congr_fun $ subsingleton.elim _ _⟩
end rat
namespace algebra
open module
variables (R : Type u) (A : Type v)
variables [comm_semiring R] [semiring A] [algebra R A]
/-- `algebra_map` as an `alg_hom`. -/
def of_id : R →ₐ[R] A :=
{ commutes' := λ _, rfl, .. algebra_map R A }
variables {R}
theorem of_id_apply (r) : of_id R A r = algebra_map R A r := rfl
variables (R A)
/-- The multiplication in an algebra is a bilinear map.
A weaker version of this for semirings exists as `add_monoid_hom.mul`. -/
def lmul : A →ₐ[R] (End R A) :=
{ map_one' := by { ext a, exact one_mul a },
map_mul' := by { intros a b, ext c, exact mul_assoc a b c },
map_zero' := by { ext a, exact zero_mul a },
commutes' := by { intro r, ext a, dsimp, rw [smul_def] },
.. (show A →ₗ[R] A →ₗ[R] A, from linear_map.mk₂ R (*)
(λ x y z, add_mul x y z)
(λ c x y, by rw [smul_def, smul_def, mul_assoc _ x y])
(λ x y z, mul_add x y z)
(λ c x y, by rw [smul_def, smul_def, left_comm])) }
variables {A}
/-- The multiplication on the left in an algebra is a linear map. -/
def lmul_left (r : A) : A →ₗ A :=
lmul R A r
/-- The multiplication on the right in an algebra is a linear map. -/
def lmul_right (r : A) : A →ₗ A :=
(lmul R A).to_linear_map.flip r
/-- Simultaneous multiplication on the left and right is a linear map. -/
def lmul_left_right (vw: A × A) : A →ₗ[R] A :=
(lmul_right R vw.2).comp (lmul_left R vw.1)
/-- The multiplication map on an algebra, as an `R`-linear map from `A ⊗[R] A` to `A`. -/
def lmul' : A ⊗[R] A →ₗ[R] A :=
tensor_product.lift (lmul R A).to_linear_map
lemma commute_lmul_left_right (a b : A) :
commute (lmul_left R a) (lmul_right R b) :=
by { ext c, exact (mul_assoc a c b).symm, }
variables {R A}
@[simp] lemma lmul_apply (p q : A) : lmul R A p q = p * q := rfl
@[simp] lemma lmul_left_apply (p q : A) : lmul_left R p q = p * q := rfl
@[simp] lemma lmul_right_apply (p q : A) : lmul_right R p q = q * p := rfl
@[simp] lemma lmul_left_right_apply (vw : A × A) (p : A) :
lmul_left_right R vw p = vw.1 * p * vw.2 := rfl
@[simp] lemma lmul_left_one : lmul_left R (1:A) = linear_map.id :=
by { ext, simp only [linear_map.id_coe, one_mul, id.def, lmul_left_apply] }
@[simp] lemma lmul_left_mul (a b : A) :
lmul_left R (a * b) = (lmul_left R a).comp (lmul_left R b) :=
by { ext, simp only [lmul_left_apply, linear_map.comp_apply, mul_assoc] }
@[simp] lemma lmul_right_one : lmul_right R (1:A) = linear_map.id :=
by { ext, simp only [linear_map.id_coe, mul_one, id.def, lmul_right_apply] }
@[simp] lemma lmul_right_mul (a b : A) :
lmul_right R (a * b) = (lmul_right R b).comp (lmul_right R a) :=
by { ext, simp only [lmul_right_apply, linear_map.comp_apply, mul_assoc] }
@[simp] lemma lmul_left_zero_eq_zero :
lmul_left R (0 : A) = 0 :=
(lmul R A).map_zero
@[simp] lemma lmul_right_zero_eq_zero :
lmul_right R (0 : A) = 0 :=
(lmul R A).to_linear_map.flip.map_zero
@[simp] lemma lmul_left_eq_zero_iff (a : A) :
lmul_left R a = 0 ↔ a = 0 :=
begin
split; intros h,
{ rw [← mul_one a, ← lmul_left_apply a 1, h, linear_map.zero_apply], },
{ rw h, exact lmul_left_zero_eq_zero, },
end
@[simp] lemma lmul_right_eq_zero_iff (a : A) :
lmul_right R a = 0 ↔ a = 0 :=
begin
split; intros h,
{ rw [← one_mul a, ← lmul_right_apply a 1, h, linear_map.zero_apply], },
{ rw h, exact lmul_right_zero_eq_zero, },
end
@[simp] lemma pow_lmul_left (a : A) (n : ℕ) :
(lmul_left R a) ^ n = lmul_left R (a ^ n) :=
((lmul R A).map_pow a n).symm
@[simp] lemma pow_lmul_right (a : A) (n : ℕ) :
(lmul_right R a) ^ n = lmul_right R (a ^ n) :=
linear_map.coe_injective $ ((lmul_right R a).coe_pow n).symm ▸ (mul_right_iterate a n)
@[simp] lemma lmul'_apply {x y : A} : lmul' R (x ⊗ₜ y) = x * y :=
by simp only [algebra.lmul', tensor_product.lift.tmul, alg_hom.to_linear_map_apply, lmul_apply]
instance linear_map.module' (R : Type u) [comm_semiring R]
(M : Type v) [add_comm_monoid M] [module R M]
(S : Type w) [comm_semiring S] [algebra R S] : module S (M →ₗ[R] S) :=
{ smul := λ s f, linear_map.llcomp _ _ _ _ (algebra.lmul R S s) f,
one_smul := λ f, linear_map.ext $ λ x, one_mul _,
mul_smul := λ s₁ s₂ f, linear_map.ext $ λ x, mul_assoc _ _ _,
smul_add := λ s f g, linear_map.map_add _ _ _,
smul_zero := λ s, linear_map.map_zero _,
add_smul := λ s₁ s₂ f, linear_map.ext $ λ x, add_mul _ _ _,
zero_smul := λ f, linear_map.ext $ λ x, zero_mul _ }
end algebra
section ring
namespace algebra
variables {R A : Type*} [comm_semiring R] [ring A] [algebra R A]
lemma lmul_left_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
function.injective (lmul_left R x) :=
by { letI : domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
exact mul_right_injective' hx }
lemma lmul_right_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
function.injective (lmul_right R x) :=
by { letI : domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
exact mul_left_injective' hx }
lemma lmul_injective [no_zero_divisors A] {x : A} (hx : x ≠ 0) :
function.injective (lmul R A x) :=
by { letI : domain A := { exists_pair_ne := ⟨x, 0, hx⟩, ..‹ring A›, ..‹no_zero_divisors A› },
exact mul_right_injective' hx }
end algebra
end ring
section int
variables (R : Type*) [ring R]
-- Lower the priority so that `algebra.id` is picked most of the time when working with
-- `ℤ`-algebras. This is only an issue since `algebra.id ℤ` and `algebra_int ℤ` are not yet defeq.
-- TODO: fix this by adding an `of_int` field to rings.
/-- Ring ⥤ ℤ-Alg -/
@[priority 99] instance algebra_int : algebra ℤ R :=
{ commutes' := int.cast_commute,
smul_def' := λ _ _, gsmul_eq_mul _ _,
to_ring_hom := int.cast_ring_hom R }
variables {R}
instance int_algebra_subsingleton : subsingleton (algebra ℤ R) :=
⟨λ P Q, by { ext, simp, }⟩
end int
/-!
The R-algebra structure on `Π i : I, A i` when each `A i` is an R-algebra.
We couldn't set this up back in `algebra.pi_instances` because this file imports it.
-/
namespace pi
variable {I : Type u} -- The indexing type
variable {R : Type*} -- The scalar type
variable {f : I → Type v} -- The family of types already equipped with instances
variables (x y : Π i, f i) (i : I)
variables (I f)
instance algebra {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] :
algebra R (Π i : I, f i) :=
{ commutes' := λ a f, begin ext, simp [algebra.commutes], end,
smul_def' := λ a f, begin ext, simp [algebra.smul_def''], end,
..(pi.ring_hom (λ i, algebra_map R (f i)) : R →+* Π i : I, f i) }
@[simp] lemma algebra_map_apply {r : comm_semiring R}
[s : ∀ i, semiring (f i)] [∀ i, algebra R (f i)] (a : R) (i : I) :
algebra_map R (Π i, f i) a i = algebra_map R (f i) a := rfl
-- One could also build a `Π i, R i`-algebra structure on `Π i, A i`,
-- when each `A i` is an `R i`-algebra, although I'm not sure that it's useful.
variables {I} (R) (f)
/-- `function.eval` as an `alg_hom`. The name matches `pi.eval_ring_hom`, `pi.eval_monoid_hom`,
etc. -/
@[simps]
def eval_alg_hom {r : comm_semiring R} [Π i, semiring (f i)] [Π i, algebra R (f i)] (i : I) :
(Π i, f i) →ₐ[R] f i :=
{ to_fun := λ f, f i, commutes' := λ r, rfl, .. pi.eval_ring_hom f i}
variables (A B : Type*) [comm_semiring R] [semiring B] [algebra R B]
/-- `function.const` as an `alg_hom`. The name matches `pi.const_ring_hom`, `pi.const_monoid_hom`,
etc. -/
@[simps]
def const_alg_hom : B →ₐ[R] (A → B) :=
{ to_fun := function.const _,
commutes' := λ r, rfl,
.. pi.const_ring_hom A B}
/-- When `R` is commutative and permits an `algebra_map`, `pi.const_ring_hom` is equal to that
map. -/
@[simp] lemma const_ring_hom_eq_algebra_map : const_ring_hom A R = algebra_map R (A → R) :=
rfl
@[simp] lemma const_alg_hom_eq_algebra_of_id : const_alg_hom R A R = algebra.of_id R (A → R) :=
rfl
end pi
section is_scalar_tower
variables {R : Type*} [comm_semiring R]
variables (A : Type*) [semiring A] [algebra R A]
variables {M : Type*} [add_comm_monoid M] [module A M] [module R M] [is_scalar_tower R A M]
variables {N : Type*} [add_comm_monoid N] [module A N] [module R N] [is_scalar_tower R A N]
lemma algebra_compatible_smul (r : R) (m : M) : r • m = ((algebra_map R A) r) • m :=
by rw [←(one_smul A m), ←smul_assoc, algebra.smul_def, mul_one, one_smul]
@[simp] lemma algebra_map_smul (r : R) (m : M) : ((algebra_map R A) r) • m = r • m :=
(algebra_compatible_smul A r m).symm
variable {A}
@[priority 100] -- see Note [lower instance priority]
instance is_scalar_tower.to_smul_comm_class : smul_comm_class R A M :=
⟨λ r a m, by rw [algebra_compatible_smul A r (a • m), smul_smul, algebra.commutes, mul_smul,
←algebra_compatible_smul]⟩
@[priority 100] -- see Note [lower instance priority]
instance is_scalar_tower.to_smul_comm_class' : smul_comm_class A R M :=
smul_comm_class.symm _ _ _
lemma smul_algebra_smul_comm (r : R) (a : A) (m : M) : a • r • m = r • a • m :=
smul_comm _ _ _
namespace linear_map
instance coe_is_scalar_tower : has_coe (M →ₗ[A] N) (M →ₗ[R] N) :=
⟨restrict_scalars R⟩
variables (R) {A M N}
@[simp, norm_cast squash] lemma coe_restrict_scalars_eq_coe (f : M →ₗ[A] N) :
(f.restrict_scalars R : M → N) = f := rfl
@[simp, norm_cast squash] lemma coe_coe_is_scalar_tower (f : M →ₗ[A] N) :
((f : M →ₗ[R] N) : M → N) = f := rfl
/-- `A`-linearly coerce a `R`-linear map from `M` to `A` to a function, given an algebra `A` over
a commutative semiring `R` and `M` a module over `R`. -/
def lto_fun (R : Type u) (M : Type v) (A : Type w)
[comm_semiring R] [add_comm_monoid M] [module R M] [comm_ring A] [algebra R A] :
(M →ₗ[R] A) →ₗ[A] (M → A) :=
{ to_fun := linear_map.to_fun,
map_add' := λ f g, rfl,
map_smul' := λ c f, rfl }
end linear_map
end is_scalar_tower
/-! TODO: The following lemmas no longer involve `algebra` at all, and could be moved closer
to `algebra/module/submodule.lean`. Currently this is tricky because `ker`, `range`, `⊤`, and `⊥`
are all defined in `linear_algebra/basic.lean`. -/
section module
open module
variables (R S M N : Type*) [semiring R] [semiring S] [has_scalar R S]
variables [add_comm_monoid M] [module R M] [module S M] [is_scalar_tower R S M]
variables [add_comm_monoid N] [module R N] [module S N] [is_scalar_tower R S N]
variables {S M N}
namespace submodule
variables (R S M)
/-- If `S` is an `R`-algebra, then the `R`-module generated by a set `X` is included in the
`S`-module generated by `X`. -/
lemma span_le_restrict_scalars (X : set M) : span R (X : set M) ≤ restrict_scalars R (span S X) :=
submodule.span_le.mpr submodule.subset_span
end submodule
@[simp]
lemma linear_map.ker_restrict_scalars (f : M →ₗ[S] N) :
(f.restrict_scalars R).ker = f.ker.restrict_scalars R :=
rfl
end module
namespace submodule
variables (R A M : Type*)
variables [comm_semiring R] [semiring A] [algebra R A] [add_comm_monoid M]
variables [module R M] [module A M] [is_scalar_tower R A M]
/-- If `A` is an `R`-algebra such that the induced morhpsim `R →+* A` is surjective, then the
`R`-module generated by a set `X` equals the `A`-module generated by `X`. -/
lemma span_eq_restrict_scalars (X : set M) (hsur : function.surjective (algebra_map R A)) :
span R X = restrict_scalars R (span A X) :=
begin
apply (span_le_restrict_scalars R A M X).antisymm (λ m hm, _),
refine span_induction hm subset_span (zero_mem _) (λ _ _, add_mem _) (λ a m hm, _),
obtain ⟨r, rfl⟩ := hsur a,
simpa [algebra_map_smul] using smul_mem _ r hm
end
end submodule
namespace alg_hom
variables {R : Type u} {A : Type v} {B : Type w} {I : Type*}
variables [comm_semiring R] [semiring A] [semiring B]
variables [algebra R A] [algebra R B]
/-- `R`-algebra homomorphism between the function spaces `I → A` and `I → B`, induced by an
`R`-algebra homomorphism `f` between `A` and `B`. -/
@[simps] protected def comp_left (f : A →ₐ[R] B) (I : Type*) : (I → A) →ₐ[R] (I → B) :=
{ to_fun := λ h, f ∘ h,
commutes' := λ c, by { ext, exact f.commutes' c },
.. f.to_ring_hom.comp_left I }
end alg_hom
|
c611923f332c7a8d29e00cee7c73d53712810368 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/topology/compact_open.lean | 2c41791bd4e025779425c64515c51cb177013a6a | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 19,188 | lean | /-
Copyright (c) 2018 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton
-/
import tactic.tidy
import topology.continuous_function.basic
import topology.homeomorph
import topology.subset_properties
import topology.maps
/-!
# The compact-open topology
In this file, we define the compact-open topology on the set of continuous maps between two
topological spaces.
## Main definitions
* `compact_open` is the compact-open topology on `C(α, β)`. It is declared as an instance.
* `continuous_map.coev` is the coevaluation map `β → C(α, β × α)`. It is always continuous.
* `continuous_map.curry` is the currying map `C(α × β, γ) → C(α, C(β, γ))`. This map always exists
and it is continuous as long as `α × β` is locally compact.
* `continuous_map.uncurry` is the uncurrying map `C(α, C(β, γ)) → C(α × β, γ)`. For this map to
exist, we need `β` to be locally compact. If `α` is also locally compact, then this map is
continuous.
* `homeomorph.curry` combines the currying and uncurrying operations into a homeomorphism
`C(α × β, γ) ≃ₜ C(α, C(β, γ))`. This homeomorphism exists if `α` and `β` are locally compact.
## Tags
compact-open, curry, function space
-/
open set
open_locale topological_space
namespace continuous_map
section compact_open
variables {α : Type*} {β : Type*} {γ : Type*}
variables [topological_space α] [topological_space β] [topological_space γ]
/-- A generating set for the compact-open topology (when `s` is compact and `u` is open). -/
def compact_open.gen (s : set α) (u : set β) : set C(α,β) := {f | f '' s ⊆ u}
@[simp] lemma gen_empty (u : set β) : compact_open.gen (∅ : set α) u = set.univ :=
set.ext (λ f, iff_true_intro ((congr_arg (⊆ u) (image_empty f)).mpr u.empty_subset))
@[simp] lemma gen_univ (s : set α) : compact_open.gen s (set.univ : set β) = set.univ :=
set.ext (λ f, iff_true_intro (f '' s).subset_univ)
@[simp] lemma gen_inter (s : set α) (u v : set β) :
compact_open.gen s (u ∩ v) = compact_open.gen s u ∩ compact_open.gen s v :=
set.ext (λ f, subset_inter_iff)
@[simp] lemma gen_union (s t : set α) (u : set β) :
compact_open.gen (s ∪ t) u = compact_open.gen s u ∩ compact_open.gen t u :=
set.ext (λ f, (iff_of_eq (congr_arg (⊆ u) (image_union f s t))).trans union_subset_iff)
lemma gen_empty_right {s : set α} (h : s.nonempty) : compact_open.gen s (∅ : set β) = ∅ :=
eq_empty_of_forall_not_mem $ λ f, (h.image _).not_subset_empty
-- The compact-open topology on the space of continuous maps α → β.
instance compact_open : topological_space C(α, β) :=
topological_space.generate_from
{m | ∃ (s : set α) (hs : is_compact s) (u : set β) (hu : is_open u), m = compact_open.gen s u}
protected lemma is_open_gen {s : set α} (hs : is_compact s) {u : set β} (hu : is_open u) :
is_open (compact_open.gen s u) :=
topological_space.generate_open.basic _ (by dsimp [mem_set_of_eq]; tauto)
section functorial
variables (g : C(β, γ))
private lemma preimage_gen {s : set α} (hs : is_compact s) {u : set γ} (hu : is_open u) :
continuous_map.comp g ⁻¹' (compact_open.gen s u) = compact_open.gen s (g ⁻¹' u) :=
begin
ext ⟨f, _⟩,
change g ∘ f '' s ⊆ u ↔ f '' s ⊆ g ⁻¹' u,
rw [image_comp, image_subset_iff]
end
/-- C(α, -) is a functor. -/
lemma continuous_comp : continuous (continuous_map.comp g : C(α, β) → C(α, γ)) :=
continuous_generated_from $ assume m ⟨s, hs, u, hu, hm⟩,
by rw [hm, preimage_gen g hs hu]; exact continuous_map.is_open_gen hs (hu.preimage g.2)
variable (f : C(α, β))
private lemma image_gen {s : set α} (hs : is_compact s) {u : set γ} (hu : is_open u) :
(λ g : C(β, γ), g.comp f) ⁻¹' compact_open.gen s u = compact_open.gen (f '' s) u :=
begin
ext ⟨g, _⟩,
change g ∘ f '' s ⊆ u ↔ g '' (f '' s) ⊆ u,
rw set.image_comp,
end
/-- C(-, γ) is a functor. -/
lemma continuous_comp_left : continuous (λ g, g.comp f : C(β, γ) → C(α, γ)) :=
continuous_generated_from $ assume m ⟨s, hs, u, hu, hm⟩,
by { rw [hm, image_gen f hs hu], exact continuous_map.is_open_gen (hs.image f.2) hu }
/-- Composition is a continuous map from `C(α, β) × C(β, γ)` to `C(α, γ)`, provided that `β` is
locally compact. This is Prop. 9 of Chap. X, §3, №. 4 of Bourbaki's *Topologie Générale*. -/
lemma continuous_comp' [locally_compact_space β] :
continuous (λ x : C(α, β) × C(β, γ), x.2.comp x.1) :=
continuous_generated_from begin
rintros M ⟨K, hK, U, hU, rfl⟩,
conv { congr, rw [compact_open.gen, preimage_set_of_eq],
congr, funext, rw [coe_comp, image_comp, image_subset_iff] },
rw is_open_iff_forall_mem_open,
rintros ⟨φ₀, ψ₀⟩ H,
obtain ⟨L, hL, hKL, hLU⟩ := exists_compact_between (hK.image φ₀.2) (hU.preimage ψ₀.2) H,
use {φ : C(α, β) | φ '' K ⊆ interior L} ×ˢ {ψ : C(β, γ) | ψ '' L ⊆ U},
use λ ⟨φ, ψ⟩ ⟨hφ, hψ⟩, subset_trans hφ (interior_subset.trans $ image_subset_iff.mp hψ),
use (continuous_map.is_open_gen hK is_open_interior).prod (continuous_map.is_open_gen hL hU),
exact mem_prod.mpr ⟨hKL, image_subset_iff.mpr hLU⟩,
end
lemma continuous.comp' {X : Type*} [topological_space X] [locally_compact_space β]
{f : X → C(α, β)} {g : X → C(β, γ)} (hf : continuous f) (hg : continuous g) :
continuous (λ x, (g x).comp (f x)) :=
continuous_comp'.comp (hf.prod_mk hg : continuous $ λ x, (f x, g x))
end functorial
section ev
variables {α β}
/-- The evaluation map `C(α, β) × α → β` is continuous if `α` is locally compact.
See also `continuous_map.continuous_eval` -/
lemma continuous_eval' [locally_compact_space α] : continuous (λ p : C(α, β) × α, p.1 p.2) :=
continuous_iff_continuous_at.mpr $ assume ⟨f, x⟩ n hn,
let ⟨v, vn, vo, fxv⟩ := mem_nhds_iff.mp hn in
have v ∈ 𝓝 (f x), from is_open.mem_nhds vo fxv,
let ⟨s, hs, sv, sc⟩ :=
locally_compact_space.local_compact_nhds x (f ⁻¹' v)
(f.continuous.tendsto x this) in
let ⟨u, us, uo, xu⟩ := mem_nhds_iff.mp hs in
show (λ p : C(α, β) × α, p.1 p.2) ⁻¹' n ∈ 𝓝 (f, x), from
let w := compact_open.gen s v ×ˢ u in
have w ⊆ (λ p : C(α, β) × α, p.1 p.2) ⁻¹' n, from assume ⟨f', x'⟩ ⟨hf', hx'⟩, calc
f' x' ∈ f' '' s : mem_image_of_mem f' (us hx')
... ⊆ v : hf'
... ⊆ n : vn,
have is_open w, from (continuous_map.is_open_gen sc vo).prod uo,
have (f, x) ∈ w, from ⟨image_subset_iff.mpr sv, xu⟩,
mem_nhds_iff.mpr ⟨w, by assumption, by assumption, by assumption⟩
/-- See also `continuous_map.continuous_eval_const` -/
lemma continuous_eval_const' [locally_compact_space α] (a : α) : continuous (λ f : C(α, β), f a) :=
continuous_eval'.comp (continuous_id.prod_mk continuous_const)
/-- See also `continuous_map.continuous_coe` -/
lemma continuous_coe' [locally_compact_space α] : @continuous (C(α, β)) (α → β) _ _ coe_fn :=
continuous_pi continuous_eval_const'
instance [t2_space β] : t2_space C(α, β) :=
⟨ begin
intros f₁ f₂ h,
obtain ⟨x, hx⟩ := not_forall.mp (mt (fun_like.ext f₁ f₂) h),
obtain ⟨u, v, hu, hv, hxu, hxv, huv⟩ := t2_separation hx,
refine ⟨compact_open.gen {x} u, compact_open.gen {x} v, continuous_map.is_open_gen
is_compact_singleton hu, continuous_map.is_open_gen is_compact_singleton hv, _, _, _⟩,
{ rwa [compact_open.gen, mem_set_of_eq, image_singleton, singleton_subset_iff] },
{ rwa [compact_open.gen, mem_set_of_eq, image_singleton, singleton_subset_iff] },
{ rw [disjoint_iff_inter_eq_empty, ←gen_inter, huv.inter_eq,
gen_empty_right (singleton_nonempty _)] }
end ⟩
end ev
section Inf_induced
lemma compact_open_le_induced (s : set α) :
(continuous_map.compact_open : topological_space C(α, β))
≤ topological_space.induced (continuous_map.restrict s) continuous_map.compact_open :=
begin
simp only [induced_generate_from_eq, continuous_map.compact_open],
apply generate_from_mono,
rintros b ⟨a, ⟨c, hc, u, hu, rfl⟩, rfl⟩,
refine ⟨coe '' c, hc.image continuous_subtype_coe, u, hu, _⟩,
ext f,
simp only [compact_open.gen, mem_set_of_eq, mem_preimage, continuous_map.coe_restrict],
rw image_comp f (coe : s → α),
end
/-- The compact-open topology on `C(α, β)` is equal to the infimum of the compact-open topologies
on `C(s, β)` for `s` a compact subset of `α`. The key point of the proof is that the union of the
compact subsets of `α` is equal to the union of compact subsets of the compact subsets of `α`. -/
lemma compact_open_eq_Inf_induced :
(continuous_map.compact_open : topological_space C(α, β))
= ⨅ (s : set α) (hs : is_compact s),
topological_space.induced (continuous_map.restrict s) continuous_map.compact_open :=
begin
refine le_antisymm _ _,
{ refine le_infi₂ _,
exact λ s hs, compact_open_le_induced s },
simp only [← generate_from_Union, induced_generate_from_eq, continuous_map.compact_open],
apply generate_from_mono,
rintros _ ⟨s, hs, u, hu, rfl⟩,
rw mem_Union₂,
refine ⟨s, hs, _, ⟨univ, is_compact_iff_is_compact_univ.mp hs, u, hu, rfl⟩, _⟩,
ext f,
simp only [compact_open.gen, mem_set_of_eq, mem_preimage, continuous_map.coe_restrict],
rw image_comp f (coe : s → α),
simp
end
/-- For any subset `s` of `α`, the restriction of continuous functions to `s` is continuous as a
function from `C(α, β)` to `C(s, β)` with their respective compact-open topologies. -/
lemma continuous_restrict (s : set α) : continuous (λ F : C(α, β), F.restrict s) :=
by { rw continuous_iff_le_induced, exact compact_open_le_induced s }
lemma nhds_compact_open_eq_Inf_nhds_induced (f : C(α, β)) :
𝓝 f = ⨅ s (hs : is_compact s), (𝓝 (f.restrict s)).comap (continuous_map.restrict s) :=
by { rw [compact_open_eq_Inf_induced], simp [nhds_infi, nhds_induced] }
lemma tendsto_compact_open_restrict {ι : Type*} {l : filter ι} {F : ι → C(α, β)} {f : C(α, β)}
(hFf : filter.tendsto F l (𝓝 f)) (s : set α) :
filter.tendsto (λ i, (F i).restrict s) l (𝓝 (f.restrict s)) :=
(continuous_restrict s).continuous_at.tendsto.comp hFf
lemma tendsto_compact_open_iff_forall {ι : Type*} {l : filter ι} (F : ι → C(α, β)) (f : C(α, β)) :
filter.tendsto F l (𝓝 f)
↔ ∀ s (hs : is_compact s), filter.tendsto (λ i, (F i).restrict s) l (𝓝 (f.restrict s)) :=
by { rw [compact_open_eq_Inf_induced], simp [nhds_infi, nhds_induced, filter.tendsto_comap_iff] }
/-- A family `F` of functions in `C(α, β)` converges in the compact-open topology, if and only if
it converges in the compact-open topology on each compact subset of `α`. -/
lemma exists_tendsto_compact_open_iff_forall [locally_compact_space α] [t2_space α] [t2_space β]
{ι : Type*} {l : filter ι} [filter.ne_bot l] (F : ι → C(α, β)) :
(∃ f, filter.tendsto F l (𝓝 f))
↔ ∀ (s : set α) (hs : is_compact s), ∃ f, filter.tendsto (λ i, (F i).restrict s) l (𝓝 f) :=
begin
split,
{ rintros ⟨f, hf⟩ s hs,
exact ⟨f.restrict s, tendsto_compact_open_restrict hf s⟩ },
{ intros h,
choose f hf using h,
-- By uniqueness of limits in a `t2_space`, since `λ i, F i x` tends to both `f s₁ hs₁ x` and
-- `f s₂ hs₂ x`, we have `f s₁ hs₁ x = f s₂ hs₂ x`
have h : ∀ s₁ (hs₁ : is_compact s₁) s₂ (hs₂ : is_compact s₂) (x : α) (hxs₁ : x ∈ s₁)
(hxs₂ : x ∈ s₂), f s₁ hs₁ ⟨x, hxs₁⟩ = f s₂ hs₂ ⟨x, hxs₂⟩,
{ rintros s₁ hs₁ s₂ hs₂ x hxs₁ hxs₂,
haveI := is_compact_iff_compact_space.mp hs₁,
haveI := is_compact_iff_compact_space.mp hs₂,
have h₁ := (continuous_eval_const' (⟨x, hxs₁⟩ : s₁)).continuous_at.tendsto.comp (hf s₁ hs₁),
have h₂ := (continuous_eval_const' (⟨x, hxs₂⟩ : s₂)).continuous_at.tendsto.comp (hf s₂ hs₂),
exact tendsto_nhds_unique h₁ h₂ },
-- So glue the `f s hs` together and prove that this glued function `f₀` is a limit on each
-- compact set `s`
have hs : ∀ x : α, ∃ s (hs : is_compact s), s ∈ 𝓝 x,
{ intros x,
obtain ⟨s, hs, hs'⟩ := exists_compact_mem_nhds x,
exact ⟨s, hs, hs'⟩ },
refine ⟨lift_cover' _ _ h hs, _⟩,
rw tendsto_compact_open_iff_forall,
intros s hs,
rw lift_cover_restrict',
exact hf s hs }
end
end Inf_induced
section coev
variables (α β)
/-- The coevaluation map `β → C(α, β × α)` sending a point `x : β` to the continuous function
on `α` sending `y` to `(x, y)`. -/
def coev (b : β) : C(α, β × α) := ⟨prod.mk b, continuous_const.prod_mk continuous_id⟩
variables {α β}
lemma image_coev {y : β} (s : set α) : (coev α β y) '' s = ({y} : set β) ×ˢ s := by tidy
-- The coevaluation map β → C(α, β × α) is continuous (always).
lemma continuous_coev : continuous (coev α β) :=
continuous_generated_from $ begin
rintros _ ⟨s, sc, u, uo, rfl⟩,
rw is_open_iff_forall_mem_open,
intros y hy,
change (coev α β y) '' s ⊆ u at hy,
rw image_coev s at hy,
rcases generalized_tube_lemma is_compact_singleton sc uo hy
with ⟨v, w, vo, wo, yv, sw, vwu⟩,
refine ⟨v, _, vo, singleton_subset_iff.mp yv⟩,
intros y' hy',
change (coev α β y') '' s ⊆ u,
rw image_coev s,
exact subset.trans (prod_mono (singleton_subset_iff.mpr hy') sw) vwu
end
end coev
section curry
/-- Auxiliary definition, see `continuous_map.curry` and `homeomorph.curry`. -/
def curry' (f : C(α × β, γ)) (a : α) : C(β, γ) := ⟨function.curry f a⟩
/-- If a map `α × β → γ` is continuous, then its curried form `α → C(β, γ)` is continuous. -/
lemma continuous_curry' (f : C(α × β, γ)) : continuous (curry' f) :=
have hf : curry' f = continuous_map.comp f ∘ coev _ _, by { ext, refl },
hf ▸ continuous.comp (continuous_comp f) continuous_coev
/-- To show continuity of a map `α → C(β, γ)`, it suffices to show that its uncurried form
`α × β → γ` is continuous. -/
lemma continuous_of_continuous_uncurry (f : α → C(β, γ))
(h : continuous (function.uncurry (λ x y, f x y))) : continuous f :=
by { convert continuous_curry' ⟨_, h⟩, ext, refl }
/-- The curried form of a continuous map `α × β → γ` as a continuous map `α → C(β, γ)`.
If `a × β` is locally compact, this is continuous. If `α` and `β` are both locally
compact, then this is a homeomorphism, see `homeomorph.curry`. -/
def curry (f : C(α × β, γ)) : C(α, C(β, γ)) :=
⟨_, continuous_curry' f⟩
/-- The currying process is a continuous map between function spaces. -/
lemma continuous_curry [locally_compact_space (α × β)] :
continuous (curry : C(α × β, γ) → C(α, C(β, γ))) :=
begin
apply continuous_of_continuous_uncurry,
apply continuous_of_continuous_uncurry,
rw ←homeomorph.comp_continuous_iff' (homeomorph.prod_assoc _ _ _).symm,
convert continuous_eval';
tidy
end
@[simp]
lemma curry_apply (f : C(α × β, γ)) (a : α) (b : β) : f.curry a b = f (a, b) := rfl
/-- The uncurried form of a continuous map `α → C(β, γ)` is a continuous map `α × β → γ`. -/
lemma continuous_uncurry_of_continuous [locally_compact_space β] (f : C(α, C(β, γ))) :
continuous (function.uncurry (λ x y, f x y)) :=
continuous_eval'.comp $ f.continuous.prod_map continuous_id
/-- The uncurried form of a continuous map `α → C(β, γ)` as a continuous map `α × β → γ` (if `β` is
locally compact). If `α` is also locally compact, then this is a homeomorphism between the two
function spaces, see `homeomorph.curry`. -/
@[simps] def uncurry [locally_compact_space β] (f : C(α, C(β, γ))) : C(α × β, γ) :=
⟨_, continuous_uncurry_of_continuous f⟩
/-- The uncurrying process is a continuous map between function spaces. -/
lemma continuous_uncurry [locally_compact_space α] [locally_compact_space β] :
continuous (uncurry : C(α, C(β, γ)) → C(α × β, γ)) :=
begin
apply continuous_of_continuous_uncurry,
rw ←homeomorph.comp_continuous_iff' (homeomorph.prod_assoc _ _ _),
apply continuous.comp continuous_eval' (continuous.prod_map continuous_eval' continuous_id);
apply_instance
end
/-- The family of constant maps: `β → C(α, β)` as a continuous map. -/
def const' : C(β, C(α, β)) := curry ⟨prod.fst, continuous_fst⟩
@[simp] lemma coe_const' : (const' : β → C(α, β)) = const α := rfl
lemma continuous_const' : continuous (const α : β → C(α, β)) := const'.continuous
end curry
end compact_open
end continuous_map
open continuous_map
namespace homeomorph
variables {α : Type*} {β : Type*} {γ : Type*}
variables [topological_space α] [topological_space β] [topological_space γ]
/-- Currying as a homeomorphism between the function spaces `C(α × β, γ)` and `C(α, C(β, γ))`. -/
def curry [locally_compact_space α] [locally_compact_space β] : C(α × β, γ) ≃ₜ C(α, C(β, γ)) :=
⟨⟨curry, uncurry, by tidy, by tidy⟩, continuous_curry, continuous_uncurry⟩
/-- If `α` has a single element, then `β` is homeomorphic to `C(α, β)`. -/
def continuous_map_of_unique [unique α] : β ≃ₜ C(α, β) :=
{ to_fun := const α,
inv_fun := λ f, f default,
left_inv := λ a, rfl,
right_inv := λ f, by { ext, rw unique.eq_default a, refl },
continuous_to_fun := continuous_const',
continuous_inv_fun := continuous_eval'.comp (continuous_id.prod_mk continuous_const) }
@[simp] lemma continuous_map_of_unique_apply [unique α] (b : β) (a : α) :
continuous_map_of_unique b a = b :=
rfl
@[simp] lemma continuous_map_of_unique_symm_apply [unique α] (f : C(α, β)) :
continuous_map_of_unique.symm f = f default :=
rfl
end homeomorph
section quotient_map
variables {X₀ X Y Z : Type*} [topological_space X₀] [topological_space X]
[topological_space Y] [topological_space Z] [locally_compact_space Y] {f : X₀ → X}
lemma quotient_map.continuous_lift_prod_left (hf : quotient_map f) {g : X × Y → Z}
(hg : continuous (λ p : X₀ × Y, g (f p.1, p.2))) : continuous g :=
begin
let Gf : C(X₀, C(Y, Z)) := continuous_map.curry ⟨_, hg⟩,
have h : ∀ x : X, continuous (λ y, g (x, y)),
{ intros x,
obtain ⟨x₀, rfl⟩ := hf.surjective x,
exact (Gf x₀).continuous },
let G : X → C(Y, Z) := λ x, ⟨_, h x⟩,
have : continuous G,
{ rw hf.continuous_iff,
exact Gf.continuous },
convert continuous_map.continuous_uncurry_of_continuous ⟨G, this⟩,
ext x,
cases x,
refl,
end
lemma quotient_map.continuous_lift_prod_right (hf : quotient_map f) {g : Y × X → Z}
(hg : continuous (λ p : Y × X₀, g (p.1, f p.2))) : continuous g :=
begin
have : continuous (λ p : X₀ × Y, g ((prod.swap p).1, f (prod.swap p).2)),
{ exact hg.comp continuous_swap },
have : continuous (λ p : X₀ × Y, (g ∘ prod.swap) (f p.1, p.2)) := this,
convert (hf.continuous_lift_prod_left this).comp continuous_swap,
ext x,
simp,
end
end quotient_map
|
9d5a88866cc1b3941945cbabafb4a133720a4113 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/ir/lirc.lean | 34b39f4e512ea38d6cc9e82b7316946313928fa6 | [
"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 | 427 | lean | import init.IO
import init.Lean.Ir.lirc
open Lean.Ir IO
def main : IO Unit :=
do args ← IO.cmdlineArgs;
unless (args.length = 1) $
IO.fail "Error: incorrect number of arguments, expected `lirc file.Lean`";
let fname := args.head;
input ← Fs.readFile fname;
match lirc input {mainProc := some "main"} with
| Except.ok r := Fs.writeFile (fname ++ ".cpp") r
| Except.error e := IO.fail (toString e)
|
128fa3245e23a66e3754591a48e8171111f28426 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/algebra/group/units.lean | 94ccafd1c68473ae09650fe48a53a3fcff40b35f | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 14,973 | lean | /-
Copyright (c) 2017 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Mario Carneiro, Johannes Hölzl, Chris Hughes, Jens Wagemaker
-/
import algebra.group.basic
import logic.nontrivial
/-!
# Units (i.e., invertible elements) of a multiplicative monoid
-/
universe u
variable {α : Type u}
/-- Units of a monoid, bundled version. An element of a `monoid` is a unit if it has a two-sided
inverse. This version bundles the inverse element so that it can be computed. For a predicate
see `is_unit`. -/
structure units (α : Type u) [monoid α] :=
(val : α)
(inv : α)
(val_inv : val * inv = 1)
(inv_val : inv * val = 1)
/-- Units of an add_monoid, bundled version. An element of an add_monoid is a unit if it has a
two-sided additive inverse. This version bundles the inverse element so that it can be
computed. For a predicate see `is_add_unit`. -/
structure add_units (α : Type u) [add_monoid α] :=
(val : α)
(neg : α)
(val_neg : val + neg = 0)
(neg_val : neg + val = 0)
attribute [to_additive add_units] units
section has_elem
@[to_additive] lemma unique_has_one {α : Type*} [unique α] [has_one α] :
default α = 1 :=
unique.default_eq 1
end has_elem
namespace units
variables [monoid α]
@[to_additive] instance : has_coe (units α) α := ⟨val⟩
@[to_additive] instance : has_inv (units α) := ⟨λ u, ⟨u.2, u.1, u.4, u.3⟩⟩
/-- See Note [custom simps projection] -/
@[to_additive /-" See Note [custom simps projection] "-/]
def simps.coe (u : units α) : α := u
/-- See Note [custom simps projection] -/
@[to_additive /-" See Note [custom simps projection] "-/]
def simps.coe_inv (u : units α) : α := ↑(u⁻¹)
initialize_simps_projections units (val → coe as_prefix, inv → coe_inv as_prefix)
initialize_simps_projections add_units (val → coe as_prefix, neg → coe_neg as_prefix)
@[simp, to_additive] lemma coe_mk (a : α) (b h₁ h₂) : ↑(units.mk a b h₁ h₂) = a := rfl
@[ext, to_additive] theorem ext :
function.injective (coe : units α → α)
| ⟨v, i₁, vi₁, iv₁⟩ ⟨v', i₂, vi₂, iv₂⟩ e :=
by change v = v' at e; subst v'; congr;
simpa only [iv₂, vi₁, one_mul, mul_one] using mul_assoc i₂ v i₁
@[norm_cast, to_additive] theorem eq_iff {a b : units α} :
(a : α) = b ↔ a = b := ext.eq_iff
@[to_additive] theorem ext_iff {a b : units α} :
a = b ↔ (a : α) = b := eq_iff.symm
@[to_additive] instance [decidable_eq α] : decidable_eq (units α) :=
λ a b, decidable_of_iff' _ ext_iff
@[simp, to_additive] theorem mk_coe (u : units α) (y h₁ h₂) :
mk (u : α) y h₁ h₂ = u :=
ext rfl
/-- Copy a unit, adjusting definition equalities. -/
@[to_additive /-"Copy an `add_unit`, adjusting definitional equalities."-/, simps]
def copy (u : units α) (val : α) (hv : val = u) (inv : α) (hi : inv = ↑(u⁻¹)) : units α :=
{ val := val, inv := inv,
inv_val := hv.symm ▸ hi.symm ▸ u.inv_val, val_inv := hv.symm ▸ hi.symm ▸ u.val_inv }
@[to_additive]
lemma copy_eq (u : units α) (val hv inv hi) :
u.copy val hv inv hi = u :=
ext hv
/-- Units of a monoid form a group. -/
@[to_additive] instance : group (units α) :=
{ mul := λ u₁ u₂, ⟨u₁.val * u₂.val, u₂.inv * u₁.inv,
by rw [mul_assoc, ← mul_assoc u₂.val, val_inv, one_mul, val_inv],
by rw [mul_assoc, ← mul_assoc u₁.inv, inv_val, one_mul, inv_val]⟩,
one := ⟨1, 1, one_mul 1, one_mul 1⟩,
mul_one := λ u, ext $ mul_one u,
one_mul := λ u, ext $ one_mul u,
mul_assoc := λ u₁ u₂ u₃, ext $ mul_assoc u₁ u₂ u₃,
inv := has_inv.inv,
mul_left_inv := λ u, ext u.inv_val }
variables (a b : units α) {c : units α}
@[simp, norm_cast, to_additive] lemma coe_mul : (↑(a * b) : α) = a * b := rfl
attribute [norm_cast] add_units.coe_add
@[simp, norm_cast, to_additive] lemma coe_one : ((1 : units α) : α) = 1 := rfl
attribute [norm_cast] add_units.coe_zero
@[simp, norm_cast, to_additive] lemma coe_eq_one {a : units α} : (a : α) = 1 ↔ a = 1 :=
by rw [←units.coe_one, eq_iff]
@[simp, to_additive] lemma inv_mk (x y : α) (h₁ h₂) : (mk x y h₁ h₂)⁻¹ = mk y x h₂ h₁ := rfl
@[simp, to_additive] lemma val_eq_coe : a.val = (↑a : α) := rfl
@[simp, to_additive] lemma inv_eq_coe_inv : a.inv = ((a⁻¹ : units α) : α) := rfl
@[simp, to_additive] lemma inv_mul : (↑a⁻¹ * a : α) = 1 := inv_val _
@[simp, to_additive] lemma mul_inv : (a * ↑a⁻¹ : α) = 1 := val_inv _
@[to_additive] lemma inv_mul_of_eq {u : units α} {a : α} (h : ↑u = a) : ↑u⁻¹ * a = 1 :=
by { rw [←h, u.inv_mul], }
@[to_additive] lemma mul_inv_of_eq {u : units α} {a : α} (h : ↑u = a) : a * ↑u⁻¹ = 1 :=
by { rw [←h, u.mul_inv], }
@[simp, to_additive] lemma mul_inv_cancel_left (a : units α) (b : α) : (a:α) * (↑a⁻¹ * b) = b :=
by rw [← mul_assoc, mul_inv, one_mul]
@[simp, to_additive] lemma inv_mul_cancel_left (a : units α) (b : α) : (↑a⁻¹:α) * (a * b) = b :=
by rw [← mul_assoc, inv_mul, one_mul]
@[simp, to_additive] lemma mul_inv_cancel_right (a : α) (b : units α) : a * b * ↑b⁻¹ = a :=
by rw [mul_assoc, mul_inv, mul_one]
@[simp, to_additive] lemma inv_mul_cancel_right (a : α) (b : units α) : a * ↑b⁻¹ * b = a :=
by rw [mul_assoc, inv_mul, mul_one]
@[to_additive] instance : inhabited (units α) := ⟨1⟩
@[to_additive] instance {α} [comm_monoid α] : comm_group (units α) :=
{ mul_comm := λ u₁ u₂, ext $ mul_comm _ _, ..units.group }
@[to_additive] instance [has_repr α] : has_repr (units α) := ⟨repr ∘ val⟩
@[simp, to_additive] theorem mul_right_inj (a : units α) {b c : α} : (a:α) * b = a * c ↔ b = c :=
⟨λ h, by simpa only [inv_mul_cancel_left] using congr_arg ((*) ↑(a⁻¹ : units α)) h, congr_arg _⟩
@[simp, to_additive] theorem mul_left_inj (a : units α) {b c : α} : b * a = c * a ↔ b = c :=
⟨λ h, by simpa only [mul_inv_cancel_right] using congr_arg (* ↑(a⁻¹ : units α)) h, congr_arg _⟩
@[to_additive] theorem eq_mul_inv_iff_mul_eq {a b : α} : a = b * ↑c⁻¹ ↔ a * c = b :=
⟨λ h, by rw [h, inv_mul_cancel_right], λ h, by rw [← h, mul_inv_cancel_right]⟩
@[to_additive] theorem eq_inv_mul_iff_mul_eq {a c : α} : a = ↑b⁻¹ * c ↔ ↑b * a = c :=
⟨λ h, by rw [h, mul_inv_cancel_left], λ h, by rw [← h, inv_mul_cancel_left]⟩
@[to_additive] theorem inv_mul_eq_iff_eq_mul {b c : α} : ↑a⁻¹ * b = c ↔ b = a * c :=
⟨λ h, by rw [← h, mul_inv_cancel_left], λ h, by rw [h, inv_mul_cancel_left]⟩
@[to_additive] theorem mul_inv_eq_iff_eq_mul {a c : α} : a * ↑b⁻¹ = c ↔ a = c * b :=
⟨λ h, by rw [← h, inv_mul_cancel_right], λ h, by rw [h, mul_inv_cancel_right]⟩
lemma inv_eq_of_mul_eq_one {u : units α} {a : α} (h : ↑u * a = 1) : ↑u⁻¹ = a :=
calc ↑u⁻¹ = ↑u⁻¹ * 1 : by rw mul_one
... = ↑u⁻¹ * ↑u * a : by rw [←h, ←mul_assoc]
... = a : by rw [u.inv_mul, one_mul]
lemma inv_unique {u₁ u₂ : units α} (h : (↑u₁ : α) = ↑u₂) : (↑u₁⁻¹ : α) = ↑u₂⁻¹ :=
inv_eq_of_mul_eq_one $ by rw [h, u₂.mul_inv]
end units
/-- For `a, b` in a `comm_monoid` such that `a * b = 1`, makes a unit out of `a`. -/
@[to_additive "For `a, b` in an `add_comm_monoid` such that `a + b = 0`, makes an add_unit
out of `a`."]
def units.mk_of_mul_eq_one [comm_monoid α] (a b : α) (hab : a * b = 1) :
units α :=
⟨a, b, hab, (mul_comm b a).trans hab⟩
@[simp, to_additive] lemma units.coe_mk_of_mul_eq_one [comm_monoid α] {a b : α} (h : a * b = 1) :
(units.mk_of_mul_eq_one a b h : α) = a := rfl
section monoid
variables [monoid α] {a b c : α}
/-- Partial division. It is defined when the
second argument is invertible, and unlike the division operator
in `division_ring` it is not totalized at zero. -/
def divp (a : α) (u) : α := a * (u⁻¹ : units α)
infix ` /ₚ `:70 := divp
@[simp] theorem divp_self (u : units α) : (u : α) /ₚ u = 1 := units.mul_inv _
@[simp] theorem divp_one (a : α) : a /ₚ 1 = a := mul_one _
theorem divp_assoc (a b : α) (u : units α) : a * b /ₚ u = a * (b /ₚ u) :=
mul_assoc _ _ _
@[simp] theorem divp_inv (u : units α) : a /ₚ u⁻¹ = a * u := rfl
@[simp] theorem divp_mul_cancel (a : α) (u : units α) : a /ₚ u * u = a :=
(mul_assoc _ _ _).trans $ by rw [units.inv_mul, mul_one]
@[simp] theorem mul_divp_cancel (a : α) (u : units α) : (a * u) /ₚ u = a :=
(mul_assoc _ _ _).trans $ by rw [units.mul_inv, mul_one]
@[simp] theorem divp_left_inj (u : units α) {a b : α} : a /ₚ u = b /ₚ u ↔ a = b :=
units.mul_left_inj _
theorem divp_divp_eq_divp_mul (x : α) (u₁ u₂ : units α) : (x /ₚ u₁) /ₚ u₂ = x /ₚ (u₂ * u₁) :=
by simp only [divp, mul_inv_rev, units.coe_mul, mul_assoc]
theorem divp_eq_iff_mul_eq {x : α} {u : units α} {y : α} : x /ₚ u = y ↔ y * u = x :=
u.mul_left_inj.symm.trans $ by rw [divp_mul_cancel]; exact ⟨eq.symm, eq.symm⟩
theorem divp_eq_one_iff_eq {a : α} {u : units α} : a /ₚ u = 1 ↔ a = u :=
(units.mul_left_inj u).symm.trans $ by rw [divp_mul_cancel, one_mul]
@[simp] theorem one_divp (u : units α) : 1 /ₚ u = ↑u⁻¹ :=
one_mul _
end monoid
section comm_monoid
variables [comm_monoid α]
theorem divp_eq_divp_iff {x y : α} {ux uy : units α} :
x /ₚ ux = y /ₚ uy ↔ x * uy = y * ux :=
by rw [divp_eq_iff_mul_eq, mul_comm, ← divp_assoc, divp_eq_iff_mul_eq, mul_comm y ux]
theorem divp_mul_divp (x y : α) (ux uy : units α) :
(x /ₚ ux) * (y /ₚ uy) = (x * y) /ₚ (ux * uy) :=
by rw [← divp_divp_eq_divp_mul, divp_assoc, mul_comm x, divp_assoc, mul_comm]
end comm_monoid
/-!
# `is_unit` predicate
In this file we define the `is_unit` predicate on a `monoid`, and
prove a few basic properties. For the bundled version see `units`. See
also `prime`, `associated`, and `irreducible` in `algebra/associated`.
-/
section is_unit
variables {M : Type*} {N : Type*}
/-- An element `a : M` of a monoid is a unit if it has a two-sided inverse.
The actual definition says that `a` is equal to some `u : units M`, where
`units M` is a bundled version of `is_unit`. -/
@[to_additive is_add_unit "An element `a : M` of an add_monoid is an `add_unit` if it has
a two-sided additive inverse. The actual definition says that `a` is equal to some
`u : add_units M`, where `add_units M` is a bundled version of `is_add_unit`."]
def is_unit [monoid M] (a : M) : Prop := ∃ u : units M, (u : M) = a
@[nontriviality] lemma is_unit_of_subsingleton [monoid M] [subsingleton M] (a : M) : is_unit a :=
⟨⟨a, a, subsingleton.elim _ _, subsingleton.elim _ _⟩, rfl⟩
@[simp, to_additive is_add_unit_add_unit]
protected lemma units.is_unit [monoid M] (u : units M) : is_unit (u : M) := ⟨u, rfl⟩
@[simp, to_additive is_add_unit_zero]
theorem is_unit_one [monoid M] : is_unit (1:M) := ⟨1, rfl⟩
@[to_additive is_add_unit_of_add_eq_zero] theorem is_unit_of_mul_eq_one [comm_monoid M]
(a b : M) (h : a * b = 1) : is_unit a :=
⟨units.mk_of_mul_eq_one a b h, rfl⟩
@[to_additive is_add_unit.exists_neg] theorem is_unit.exists_right_inv [monoid M]
{a : M} (h : is_unit a) : ∃ b, a * b = 1 :=
by { rcases h with ⟨⟨a, b, hab, _⟩, rfl⟩, exact ⟨b, hab⟩ }
@[to_additive is_add_unit.exists_neg'] theorem is_unit.exists_left_inv [monoid M]
{a : M} (h : is_unit a) : ∃ b, b * a = 1 :=
by { rcases h with ⟨⟨a, b, _, hba⟩, rfl⟩, exact ⟨b, hba⟩ }
@[to_additive is_add_unit_iff_exists_neg] theorem is_unit_iff_exists_inv [comm_monoid M]
{a : M} : is_unit a ↔ ∃ b, a * b = 1 :=
⟨λ h, h.exists_right_inv,
λ ⟨b, hab⟩, is_unit_of_mul_eq_one _ b hab⟩
@[to_additive is_add_unit_iff_exists_neg'] theorem is_unit_iff_exists_inv' [comm_monoid M]
{a : M} : is_unit a ↔ ∃ b, b * a = 1 :=
by simp [is_unit_iff_exists_inv, mul_comm]
/-- Multiplication by a `u : units M` doesn't affect `is_unit`. -/
@[simp, to_additive is_add_unit_add_add_units "Addition of a `u : add_units M` doesn't affect
`is_add_unit`."]
theorem units.is_unit_mul_units [monoid M] (a : M) (u : units M) :
is_unit (a * u) ↔ is_unit a :=
iff.intro
(assume ⟨v, hv⟩,
have is_unit (a * ↑u * ↑u⁻¹), by existsi v * u⁻¹; rw [←hv, units.coe_mul],
by rwa [mul_assoc, units.mul_inv, mul_one] at this)
(assume ⟨v, hv⟩, hv ▸ ⟨v * u, (units.coe_mul v u).symm⟩)
@[to_additive]
lemma is_unit.mul [monoid M] {x y : M} : is_unit x → is_unit y → is_unit (x * y) :=
by { rintros ⟨x, rfl⟩ ⟨y, rfl⟩, exact ⟨x * y, units.coe_mul _ _⟩ }
@[to_additive is_add_unit_of_add_is_add_unit_left]
theorem is_unit_of_mul_is_unit_left [comm_monoid M] {x y : M}
(hu : is_unit (x * y)) : is_unit x :=
let ⟨z, hz⟩ := is_unit_iff_exists_inv.1 hu in
is_unit_iff_exists_inv.2 ⟨y * z, by rwa ← mul_assoc⟩
@[to_additive] theorem is_unit_of_mul_is_unit_right [comm_monoid M] {x y : M}
(hu : is_unit (x * y)) : is_unit y :=
@is_unit_of_mul_is_unit_left _ _ y x $ by rwa mul_comm
@[simp]
lemma is_unit.mul_iff [comm_monoid M] {x y : M} : is_unit (x * y) ↔ is_unit x ∧ is_unit y :=
⟨λ h, ⟨is_unit_of_mul_is_unit_left h, is_unit_of_mul_is_unit_right h⟩,
λ h, is_unit.mul h.1 h.2⟩
@[to_additive] theorem is_unit.mul_right_inj [monoid M] {a b c : M} (ha : is_unit a) :
a * b = a * c ↔ b = c :=
by cases ha with a ha; rw [←ha, units.mul_right_inj]
@[to_additive] theorem is_unit.mul_left_inj [monoid M] {a b c : M} (ha : is_unit a) :
b * a = c * a ↔ b = c :=
by cases ha with a ha; rw [←ha, units.mul_left_inj]
/-- The element of the group of units, corresponding to an element of a monoid which is a unit. -/
noncomputable def is_unit.unit [monoid M] {a : M} (h : is_unit a) : units M :=
(classical.some h).copy a (classical.some_spec h).symm _ rfl
lemma is_unit.unit_spec [monoid M] {a : M} (h : is_unit a) : ↑h.unit = a :=
rfl
lemma is_unit.coe_inv_mul [monoid M] {a : M} (h : is_unit a) :
↑(h.unit)⁻¹ * a = 1 :=
units.mul_inv _
lemma is_unit.mul_coe_inv [monoid M] {a : M} (h : is_unit a) :
a * ↑(h.unit)⁻¹ = 1 :=
begin
convert units.mul_inv _,
simp [h.unit_spec]
end
end is_unit
section noncomputable_defs
variables {M : Type*}
/-- Constructs a `group` structure on a `monoid` consisting only of units. -/
noncomputable def group_of_is_unit [hM : monoid M] (h : ∀ (a : M), is_unit a) : group M :=
{ inv := λ a, ↑((h a).unit)⁻¹,
mul_left_inv := λ a, by {
change ↑((h a).unit)⁻¹ * a = 1,
rw [units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] },
.. hM }
/-- Constructs a `comm_group` structure on a `comm_monoid` consisting only of units. -/
noncomputable def comm_group_of_is_unit [hM : comm_monoid M] (h : ∀ (a : M), is_unit a) :
comm_group M :=
{ inv := λ a, ↑((h a).unit)⁻¹,
mul_left_inv := λ a, by {
change ↑((h a).unit)⁻¹ * a = 1,
rw [units.inv_mul_eq_iff_eq_mul, (h a).unit_spec, mul_one] },
.. hM }
end noncomputable_defs
|
abcca129baa81a62702cd78446b64eafe6a04a01 | ec62863c729b7eedee77b86d974f2c529fa79d25 | /5/b.lean | 3408ab9c0e940ba5be427b8f02a925363ceeff72 | [] | no_license | rwbarton/advent-of-lean-4 | 2ac9b17ba708f66051e3d8cd694b0249bc433b65 | 417c7e2718253ba7148c0279fcb251b6fc291477 | refs/heads/main | 1,675,917,092,057 | 1,609,864,581,000 | 1,609,864,581,000 | 317,700,289 | 24 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 527 | lean | def value (s : String) : Nat :=
let cval (c : Char) : Nat := if c == 'B' || c == 'R' then 1 else 0
let rec v : List Char → Nat
| [] => 0
| (c :: cs) => 2 * v cs + cval c
v s.toList.reverse
def solve (input : List String) : Nat :=
let max := (input.map value).foldl Nat.max 0
let min := (input.map value).foldl Nat.min 10000
let sum := (input.map value).foldl Nat.add 0
(max - min + 1) * (min + max) / 2 - sum
def main : IO Unit := do
let input ← IO.FS.lines "a.in"
IO.print s!"{solve input.toList}\n"
|
229e03725f3afa845f6b2ed7be02bc5c1a11fd9c | e9078bde91465351e1b354b353c9f9d8b8a9c8c2 | /superseded/two_quotient_ext2.hlean | 3ff4b8451cc5d370337027b06a3e880286efc38b | [
"Apache-2.0"
] | permissive | EgbertRijke/leansnippets | 09fb7a9813477471532fbdd50c99be8d8fe3e6c4 | 1d9a7059784c92c0281fcc7ce66ac7b3619c8661 | refs/heads/master | 1,610,743,957,626 | 1,442,532,603,000 | 1,442,532,603,000 | 41,563,379 | 0 | 0 | null | 1,440,787,514,000 | 1,440,787,514,000 | null | UTF-8 | Lean | false | false | 19,730 | 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
-/
import hit.circle
open quotient eq circle sum sigma equiv function
section
variables {A B C : Type} {f : A → B} {a a' a₁ a₂ a₃ a₄ : A} {b b' : B}
-- move to square
definition top_deg_square (p : a₁ = a₂) (q : a₂ = a₃) (r : a₄ = a₃) : square (p ⬝ q ⬝ r⁻¹) q p r :=
by induction r;induction q;induction p;constructor
definition square_inv2 {p₁ p₂ p₃ p₄ : a = a'}
{t : p₁ = p₂} {b : p₃ = p₄} {l : p₁ = p₃} {r : p₂ = p₄} (s : square t b l r)
: square (inverse2 t) (inverse2 b) (inverse2 l) (inverse2 r) :=
by induction s;constructor
definition square_con2 {p₁ p₂ p₃ p₄ : a₁ = a₂} {q₁ q₂ q₃ q₄ : a₂ = a₃}
{t₁ : p₁ = p₂} {b₁ : p₃ = p₄} {l₁ : p₁ = p₃} {r₁ : p₂ = p₄}
{t₂ : q₁ = q₂} {b₂ : q₃ = q₄} {l₂ : q₁ = q₃} {r₂ : q₂ = q₄}
(s₁ : square t₁ b₁ l₁ r₁) (s₂ : square t₂ b₂ l₂ r₂)
: square (t₁ ◾ t₂) (b₁ ◾ b₂) (l₁ ◾ l₂) (r₁ ◾ r₂) :=
by induction s₂;induction s₁;constructor
-- move to types.eq
definition ap_weakly_constant [unfold 8] {A B : Type} {f : A → B} {b : B} (p : Πx, f x = b)
{x y : A} (q : x = y) : ap f q = p x ⬝ (p y)⁻¹ :=
by induction q;exact !con.right_inv⁻¹
theorem ap_weakly_constant_eq {A B : Type} {f : A → B} {b : B} (p : Πx, f x = b)
{x y : A} (q : x = y) :
ap_weakly_constant p q =
eq_con_inv_of_con_eq ((eq_of_square (square_of_pathover (apdo p q)))⁻¹ ⬝
whisker_left (p x) (ap_constant q b)) :=
begin
induction q, esimp, generalize (p x), intro p, cases p, apply idpath idp
end
definition inv2_inv {p q : a = a'} (r : p = q) : inverse2 r⁻¹ = (inverse2 r)⁻¹ :=
by induction r;reflexivity
definition inv2_con {p p' p'' : a = a'} (r : p = p') (r' : p' = p'')
: inverse2 (r ⬝ r') = inverse2 r ⬝ inverse2 r' :=
by induction r';induction r;reflexivity
definition con2_inv {p₁ q₁ : a₁ = a₂} {p₂ q₂ : a₂ = a₃} (r₁ : p₁ = q₁) (r₂ : p₂ = q₂)
: (r₁ ◾ r₂)⁻¹ = r₁⁻¹ ◾ r₂⁻¹ :=
by induction r₁;induction r₂;reflexivity
theorem eq_con_inv_of_con_eq_whisker_left {A : Type} {a a2 a3 : A}
{p : a = a2} {q q' : a2 = a3} {r : a = a3} (s' : q = q') (s : p ⬝ q' = r) :
eq_con_inv_of_con_eq (whisker_left p s' ⬝ s)
= eq_con_inv_of_con_eq s ⬝ whisker_left r (inverse2 s')⁻¹ :=
by induction s';induction q;induction s;reflexivity
theorem right_inv_eq_idp {A : Type} {a : A} {p : a = a} (r : p = idpath a) :
con.right_inv p = r ◾ inverse2 r :=
by cases r;reflexivity
-- move to a new file which both imports types.eq and types.cubical.square?
definition ap_inv2 {p q : a = a'} (r : p = q)
: square (ap (ap f) (inverse2 r))
(inverse2 (ap (ap f) r))
(ap_inv f p)
(ap_inv f q) :=
by induction r;exact hrfl
definition ap_con2 {p₁ q₁ : a₁ = a₂} {p₂ q₂ : a₂ = a₃} (r₁ : p₁ = q₁) (r₂ : p₂ = q₂)
: square (ap (ap f) (r₁ ◾ r₂))
(ap (ap f) r₁ ◾ ap (ap f) r₂)
(ap_con f p₁ p₂)
(ap_con f q₁ q₂) :=
by induction r₂;induction r₁;exact hrfl
theorem ap_con_right_inv_sq {A B : Type} {a1 a2 : A} (f : A → B) (p : a1 = a2) :
square (ap (ap f) (con.right_inv p))
(con.right_inv (ap f p))
(ap_con f p p⁻¹ ⬝ whisker_left _ (ap_inv f p))
idp :=
by cases p;apply hrefl
theorem ap_con_left_inv_sq {A B : Type} {a1 a2 : A} (f : A → B) (p : a1 = a2) :
square (ap (ap f) (con.left_inv p))
(con.left_inv (ap f p))
(ap_con f p⁻¹ p ⬝ whisker_right (ap_inv f p) _)
idp :=
by cases p;apply vrefl
theorem ap_ap_weakly_constant {A B C : Type} (g : B → C) {f : A → B} {b : B}
(p : Πx, f x = b) {x y : A} (q : x = y) :
square (ap (ap g) (ap_weakly_constant p q))
(ap_weakly_constant (λa, ap g (p a)) q)
(ap_compose g f q)⁻¹
(!ap_con ⬝ whisker_left _ !ap_inv) :=
begin
induction q, esimp, generalize (p x), intro p, cases p, apply ids
-- induction q, rewrite [↑ap_compose,ap_inv], apply hinverse, apply ap_con_right_inv_sq,
end
theorem ap_ap_compose {A B C D : Type} (h : C → D) (g : B → C) (f : A → B)
{x y : A} (p : x = y) :
square (ap_compose (h ∘ g) f p)
(ap (ap h) (ap_compose g f p))
(ap_compose h (g ∘ f) p)
(ap_compose h g (ap f p)) :=
by induction p;exact ids
theorem ap_compose_inv {A B C : Type} (g : B → C) (f : A → B)
{x y : A} (p : x = y) :
square (ap_compose g f p⁻¹)
(inverse2 (ap_compose g f p) ⬝ (ap_inv g (ap f p))⁻¹)
(ap_inv (g ∘ f) p)
(ap (ap g) (ap_inv f p)) :=
by induction p;exact ids
theorem ap_compose_con (g : B → C) (f : A → B) (p : a₁ = a₂) (q : a₂ = a₃) :
square (ap_compose g f (p ⬝ q))
(ap_compose g f p ◾ ap_compose g f q ⬝ (ap_con g (ap f p) (ap f q))⁻¹)
(ap_con (g ∘ f) p q)
(ap (ap g) (ap_con f p q)) :=
by induction q;induction p;exact ids
theorem ap_compose_natural {A B C : Type} (g : B → C) (f : A → B)
{x y : A} {p q : x = y} (r : p = q) :
square (ap (ap (g ∘ f)) r)
(ap (ap g ∘ ap f) r)
(ap_compose g f p)
(ap_compose g f q) :=
natural_square (ap_compose g f) r
-- definition naturality_apdo {A : Type} {B : A → Type} {a a₂ : A} {f g : Πa, B a}
-- (H : f ~ g) (p : a = a₂)
-- : squareover B vrfl (apdo f p) (apdo g p)
-- (pathover_idp_of_eq (H a)) (pathover_idp_of_eq (H a₂)) :=
-- by induction p;esimp;exact hrflo
definition naturality_apdo_eq {A : Type} {B : A → Type} {a a₂ : A} {f g : Πa, B a}
(H : f ~ g) (p : a = a₂)
: apdo f p = concato_eq (eq_concato (H a) (apdo g p)) (H a₂)⁻¹ :=
begin
induction p, esimp,
generalizes [H a, g a], intro ga Ha, induction Ha,
reflexivity
end
end
namespace two_quotient_ext
section
parameters {A : Type}
(R : A → A → Type)
-- symmetric transitive closure
inductive st_closure : A → A → Type :=
| of_rel : Π{a a'} (r : R a a'), st_closure a a'
| symm : Π{a a'} (r : st_closure a a'), st_closure a' a
| trans : Π{a a' a''} (r : st_closure a a') (r' : st_closure a' a''), st_closure a a''
open st_closure
local abbreviation T := st_closure
variables ⦃a a' : A⦄ {s : R a a'} {r : T a a}
protected definition st_closure.elim {B : Type} {f : A → B}
(e : Π⦃a a' : A⦄, R a a' → f a = f a') (t : T a a') : f a = f a' :=
begin
induction t,
exact e r,
exact v_0⁻¹,
exact v_0 ⬝ v_1
end
definition ap_st_closure_elim_h {B C : Type} {f : A → B} {g : B → C}
(e : Π⦃a a' : A⦄, R a a' → f a = f a')
{e' : Π⦃a a' : A⦄, R a a' → g (f a) = g (f a')}
(p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a')
: ap g (st_closure.elim e t) = st_closure.elim e' t :=
begin
induction t,
apply p,
exact ap_inv g (st_closure.elim e r) ⬝ inverse2 v_0,
exact ap_con g (st_closure.elim e r) (st_closure.elim e r') ⬝ (v_0 ◾ v_1)
end
definition ap_st_closure_elim {B C : Type} {f : A → B} (g : B → C)
(e : Π⦃a a' : A⦄, R a a' → f a = f a') (t : T a a')
: ap g (st_closure.elim e t) = st_closure.elim (λa a' r, ap g (e r)) t :=
ap_st_closure_elim_h e (λa a' s, idp) t
theorem ap_ap_st_closure_elim_h {B C D : Type} {f : A → B}
{g : B → C} (h : C → D)
(e : Π⦃a a' : A⦄, R a a' → f a = f a')
{e' : Π⦃a a' : A⦄, R a a' → g (f a) = g (f a')}
(p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a')
: square (ap (ap h) (ap_st_closure_elim_h e p t))
(ap_st_closure_elim_h e (λa a' s, ap_compose h g (e s)) t)
(ap_compose h g (st_closure.elim e t))⁻¹
(ap_st_closure_elim_h e' (λa a' s, (ap (ap h) (p s))⁻¹) t) :=
begin
induction t,
{ unfold [ap_st_closure_elim_h,st_closure.elim],
apply square_of_eq, exact !con.right_inv ⬝ !con.left_inv⁻¹},
{ rewrite [↑st_closure.elim,
↑ap_st_closure_elim_h,
ap_con (ap h)],
refine (transpose !ap_compose_inv)⁻¹ᵛ ⬝h _,
rewrite [con_inv,inv_inv,-inv2_inv],
exact !ap_inv2 ⬝v square_inv2 v_0},
{ rewrite [↑st_closure.elim,
↑ap_st_closure_elim_h,
ap_con (ap h)],
refine (transpose !ap_compose_con)⁻¹ᵛ ⬝h _,
rewrite [con_inv,inv_inv,con2_inv],
refine !ap_con2 ⬝v square_con2 v_0 v_1},
end
theorem ap_ap_st_closure_elim {B C D : Type} {f : A → B}
(g : B → C) (h : C → D)
(e : Π⦃a a' : A⦄, R a a' → f a = f a') (t : T a a')
: square (ap (ap h) (ap_st_closure_elim g e t))
(ap_st_closure_elim_h e (λa a' s, ap_compose h g (e s)) t)
(ap_compose h g (st_closure.elim e t))⁻¹
(ap_st_closure_elim h (λa a' r, ap g (e r)) t) :=
!ap_ap_st_closure_elim_h
-- definition ap_ap_st_closure_elim {B C D : Type} {f : A → B} {g : B → C} (h : C → D)
-- (e : Π⦃a a' : A⦄, R a a' → f a = f a') (t : T a a')
-- : square (ap (ap h) (ap_st_closure_elim g e t))
-- (ap_st_closure_elim (h ∘ g) e t)
-- (ap_compose h g (st_closure.elim e t))⁻¹
-- (ap_st_closure_elim_h (λa a' s, (ap_compose h g (e s))⁻¹) t) :=
-- begin
-- induction t,
-- end
parameter (Q : Π⦃a⦄, T a a → Type)
local abbreviation B := A ⊎ Σ(a : A) (r : T a a), Q r
inductive pre_two_quotient_ext_rel : B → B → Type :=
| pre_Rmk {} : Π⦃a a'⦄ (r : R a a'), pre_two_quotient_ext_rel (inl a) (inl a')
--BUG: if {} not provided, the alias for pre_Rmk is wrong
definition pre_two_quotient_ext := quotient pre_two_quotient_ext_rel
open pre_two_quotient_ext_rel
local abbreviation C := quotient pre_two_quotient_ext_rel
protected definition j [constructor] (a : A) : C := class_of pre_two_quotient_ext_rel (inl a)
protected definition pre_aux [constructor] (q : Q r) : C :=
class_of pre_two_quotient_ext_rel (inr ⟨a, r, q⟩)
protected definition e (s : R a a') : j a = j a' := eq_of_rel _ (pre_Rmk s)
protected definition et (t : T a a') : j a = j a' := st_closure.elim e t
protected definition f [unfold 7] (q : Q r) : S¹ → C :=
circle.elim (j a) (et r)
protected definition pre_rec [unfold 8] {P : C → Type}
(Pj : Πa, P (j a)) (Pa : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), P (pre_aux q))
(Pe : Π⦃a a' : A⦄ (s : R a a'), Pj a =[e s] Pj a') (x : C) : P x :=
begin
induction x with p,
{ induction p,
{ apply Pj},
{ induction a with a1 a2, induction a2, apply Pa}},
{ induction H, esimp, apply Pe},
end
protected definition pre_elim [unfold 8] {P : Type} (Pj : A → P)
(Pa : Π⦃a : A⦄ ⦃r : T a a⦄, Q r → P) (Pe : Π⦃a a' : A⦄ (s : R a a'), Pj a = Pj a') (x : C)
: P :=
pre_rec Pj Pa (λa a' s, pathover_of_eq (Pe s)) x
protected theorem rec_e {P : C → Type}
(Pj : Πa, P (j a)) (Pa : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), P (pre_aux q))
(Pe : Π⦃a a' : A⦄ (s : R a a'), Pj a =[e s] Pj a') ⦃a a' : A⦄ (s : R a a')
: apdo (pre_rec Pj Pa Pe) (e s) = Pe s :=
!rec_eq_of_rel
protected theorem elim_e {P : Type} (Pj : A → P) (Pa : Π⦃a : A⦄ ⦃r : T a a⦄, Q r → P)
(Pe : Π⦃a a' : A⦄ (s : R a a'), Pj a = Pj a') ⦃a a' : A⦄ (s : R a a')
: ap (pre_elim Pj Pa Pe) (e s) = Pe s :=
begin
apply eq_of_fn_eq_fn_inv !(pathover_constant (e s)),
rewrite [▸*,-apdo_eq_pathover_of_eq_ap,↑pre_elim,rec_e],
end
protected theorem elim_et {P : Type} (Pj : A → P) (Pa : Π⦃a : A⦄ ⦃r : T a a⦄, Q r → P)
(Pe : Π⦃a a' : A⦄ (s : R a a'), Pj a = Pj a') ⦃a a' : A⦄ (t : T a a')
: ap (pre_elim Pj Pa Pe) (et t) = st_closure.elim Pe t :=
ap_st_closure_elim_h e (elim_e Pj Pa Pe) t
inductive two_quotient_ext_rel : C → C → Type :=
| Rmk {} : Π{a : A} {r : T a a} (q : Q r) (x : circle), two_quotient_ext_rel (f q x) (pre_aux q)
open two_quotient_ext_rel
definition two_quotient_ext := quotient two_quotient_ext_rel
local abbreviation D := two_quotient_ext
local abbreviation i := class_of two_quotient_ext_rel
definition incl0 (a : A) : D := i (j a)
definition aux (q : Q r) : D := i (pre_aux q)
definition incl1 (s : R a a') : incl0 a = incl0 a' := ap i (e s)
-- definition inclt_wrong (t : T a a') : incl0 a = incl0 a' := ap i (et t)
definition inclt (t : T a a') : incl0 a = incl0 a' := st_closure.elim incl1 t
definition inclt_eq_ap (t : T a a') : inclt t = ap i (et t) :=
(ap_st_closure_elim i e t)⁻¹
definition incl2' (q : Q r) (x : S¹) : i (f q x) = aux q :=
eq_of_rel two_quotient_ext_rel (Rmk q x)
definition incl2 (q : Q r) : inclt r = idp :=
inclt_eq_ap r ⬝
(ap02 i (elim_loop (j a) (et r))⁻¹) ⬝
(ap_compose i (f q) loop)⁻¹ ⬝
ap_weakly_constant (incl2' q) loop ⬝
!con.right_inv
local attribute two_quotient_ext f i incl0 aux incl1 incl2' inclt [reducible]
local attribute i aux incl0 [constructor]
--TO CONSIDER: should all definitions about pre-structure be reducible?
protected definition elim {P : Type} (P0 : A → P)
(P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a')
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
(x : D) : P :=
begin
induction x,
{ refine (pre_elim _ _ _ a),
{ exact P0},
{ intro a r q, exact P0 a},
{ exact P1}},
{ exact abstract begin induction H, induction x,
{ exact idpath (P0 a)},
{ unfold f, apply eq_pathover, apply hdeg_square,
exact abstract ap_compose (pre_elim P0 _ P1) (f q) loop ⬝
ap _ !elim_loop ⬝
!elim_et ⬝
P2 q ⬝
!ap_constant⁻¹ end
} end end},
end
local attribute elim [unfold 8]
protected definition elim_on {P : Type} (x : D) (P0 : A → P)
(P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a')
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
: P :=
elim P0 P1 P2 x
definition elim_incl1 {P : Type} {P0 : A → P}
{P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a'}
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
⦃a a' : A⦄ (s : R a a') : ap (elim P0 P1 P2) (incl1 s) = P1 s :=
!ap_compose⁻¹ ⬝ !elim_e
definition elim_inclt {P : Type} {P0 : A → P}
{P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a'}
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
⦃a a' : A⦄ (t : T a a') : ap (elim P0 P1 P2) (inclt t) = st_closure.elim P1 t :=
ap_st_closure_elim_h incl1 (elim_incl1 P2) t
definition elim_incl2'_incl0 {P : Type} {P0 : A → P}
{P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a'}
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
⦃a : A⦄ ⦃r : T a a⦄ (q : Q r) : ap (elim P0 P1 P2) (incl2' q base) = idpath (P0 a) :=
!elim_eq_of_rel
-- theorem ap_ap_st_closure_elim_h {B C D : Type} {f : A → B}
-- {g : B → C} (h : C → D)
-- (e : Π⦃a a' : A⦄, R a a' → f a = f a')
-- {e' : Π⦃a a' : A⦄, R a a' → g (f a) = g (f a')}
-- (p : Π⦃a a' : A⦄ (s : R a a'), ap g (e s) = e' s) (t : T a a')
exit
-- set_option pp.implicit true
theorem elim_incl2 {P : Type} (P0 : A → P)
(P1 : Π⦃a a' : A⦄ (s : R a a'), P0 a = P0 a')
(P2 : Π⦃a : A⦄ ⦃r : T a a⦄ (q : Q r), st_closure.elim P1 r = idp)
⦃a : A⦄ ⦃r : T a a⦄ (q : Q r)
: square (ap02 (elim P0 P1 P2) (incl2 q)) (P2 q) (elim_inclt P2 r) idp :=
begin
/-
theorem ap_ap_st_closure_elim {B C D : Type} {f : A → B}
(g : B → C) (h : C → D)
(e : Π⦃a a' : A⦄, R a a' → f a = f a') (t : T a a')
: square (ap (ap h) (ap_st_closure_elim g e t))
(ap_st_closure_elim_h e (λa a' s, ap_compose h g (e s)) t)
(ap_compose h g (st_closure.elim e t))⁻¹
(ap_st_closure_elim h (λa a' r, ap g (e r)) t) :=
!ap_ap_st_closure_elim_h
-/
-- assert H : square (ap (ap (elim P0 P1 P2)) (inclt_eq_ap r)⁻¹)
-- (ap_st_closure_elim_h e (λa a' s, ap_compose (elim P0 P1 P2) i (e s)) r)
-- (ap_compose (elim P0 P1 P2) i (st_closure.elim e r))⁻¹
-- (ap_st_closure_elim (elim P0 P1 P2) (λa a' r, ap i (e r)) r)
-- ,
-- { },
esimp [incl2,ap02],
rewrite [+ap_con (ap _),▸*], --,-ap_compose (ap _) (ap i),+ap_inv],
xrewrite [-ap_compose (ap _) (ap i)],
rewrite [↑inclt_eq_ap,+ap_inv],
xrewrite [eq_top_of_square
((ap_ap_st_closure_elim i (elim P0 P1 P2) e r)⁻¹ʰ ⬝h
(ap_compose_natural (elim P0 P1 P2) i (elim_loop (j a) (et r)))⁻¹ʰ⁻¹ᵛ ⬝h
(ap_ap_compose (elim P0 P1 P2) i (f q) loop)⁻¹ʰ⁻¹ᵛ ⬝h
ap_ap_weakly_constant (elim P0 P1 P2) (incl2' q) loop ⬝h
ap_con_right_inv_sq (elim P0 P1 P2) (incl2' q base)),
↑[elim_inclt]],
apply whisker_tl,
rewrite [ap_weakly_constant_eq],
xrewrite [naturality_apdo_eq (λx, !elim_eq_of_rel) loop],
rewrite [↑elim_2,rec_loop,square_of_pathover_concato_eq,square_of_pathover_eq_concato,
eq_of_square_vconcat_eq,eq_of_square_eq_vconcat],
apply eq_vconcat,
{ apply ap (λx, _ ⬝ eq_con_inv_of_con_eq ((_ ⬝ x ⬝ _)⁻¹ ⬝ _) ⬝ _),
transitivity _, apply ap eq_of_square,
apply to_right_inv !pathover_eq_equiv_square (hdeg_square (elim_1 P A R Q P0 P1 a r q P2)),
transitivity _, apply eq_of_square_hdeg_square,
unfold elim_1, reflexivity},
end exit
rewrite [+con_inv,whisker_left_inv,+inv_inv,-whisker_right_inv,
con.assoc (whisker_left _ _),con.assoc _ (whisker_right _ _),▸*,
whisker_right_con_whisker_left _ !ap_constant],
xrewrite [-con.assoc _ _ (whisker_right _ _)],
rewrite [con.assoc _ _ (whisker_left _ _),idp_con_whisker_left,▸*,
con.assoc _ !ap_constant⁻¹,con.left_inv],
xrewrite [eq_con_inv_of_con_eq_whisker_left,▸*],
rewrite [+con.assoc _ _ !con.right_inv,
right_inv_eq_idp (
(λ(x : ap (elim P0 P1 P2) (incl2' q base) = idpath
(elim P0 P1 P2 (class_of two_quotient_ext_rel (f q base)))), x)
(elim_incl2'_incl0 P2 q)),
↑[whisker_left]],
xrewrite [con2_con_con2],
rewrite [idp_con,↑elim_incl2'_incl0,con.left_inv,whisker_right_inv,↑whisker_right],
xrewrite [con.assoc _ _ (_ ◾ _)],
rewrite [con.left_inv,▸*,-+con.assoc,con.assoc _⁻¹,↑[elim,function.compose],con.left_inv,
▸*,↑j,con.left_inv,idp_con],
apply square_of_eq, reflexivity
end
end
namespace st_closure
infix `⬝r`:75 := st_closure.trans
postfix `⁻¹ʳ`:(max+10) := st_closure.symm
end st_closure
end two_quotient_ext
--attribute two_quotient_ext.j [constructor] --TODO
attribute /-two_quotient_ext.rec-/ two_quotient_ext.elim [unfold 8] [recursor 8]
--attribute two_quotient_ext.elim_type [unfold 9]
attribute /-two_quotient_ext.rec_on-/ two_quotient_ext.elim_on [unfold 5]
--attribute two_quotient_ext.elim_type_on [unfold 6]
|
4b4b52661955a6d14434026d0e708c745b6318fc | aa5a655c05e5359a70646b7154e7cac59f0b4132 | /src/Lean/Meta.lean | c572041bd0e96d91945f5c97cf6ce9db6c3fd80b | [
"Apache-2.0"
] | permissive | lambdaxymox/lean4 | ae943c960a42247e06eff25c35338268d07454cb | 278d47c77270664ef29715faab467feac8a0f446 | refs/heads/master | 1,677,891,867,340 | 1,612,500,005,000 | 1,612,500,005,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 879 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Meta.Basic
import Lean.Meta.LevelDefEq
import Lean.Meta.WHNF
import Lean.Meta.InferType
import Lean.Meta.FunInfo
import Lean.Meta.ExprDefEq
import Lean.Meta.DiscrTree
import Lean.Meta.Reduce
import Lean.Meta.Instances
import Lean.Meta.AbstractMVars
import Lean.Meta.SynthInstance
import Lean.Meta.AppBuilder
import Lean.Meta.Tactic
import Lean.Meta.KAbstract
import Lean.Meta.RecursorInfo
import Lean.Meta.GeneralizeTelescope
import Lean.Meta.Match
import Lean.Meta.ReduceEval
import Lean.Meta.Closure
import Lean.Meta.AbstractNestedProofs
import Lean.Meta.ForEachExpr
import Lean.Meta.Transform
import Lean.Meta.PPGoal
import Lean.Meta.UnificationHint
import Lean.Meta.Inductive
import Lean.Meta.SizeOf |
55cddbbbd9ed9cf8a13a99c3e4e3209524495bb6 | 77c5b91fae1b966ddd1db969ba37b6f0e4901e88 | /src/measure_theory/decomposition/jordan.lean | 2f515bd388742365a617f78422950950596f3f01 | [
"Apache-2.0"
] | permissive | dexmagic/mathlib | ff48eefc56e2412429b31d4fddd41a976eb287ce | 7a5d15a955a92a90e1d398b2281916b9c41270b2 | refs/heads/master | 1,693,481,322,046 | 1,633,360,193,000 | 1,633,360,193,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,255 | lean | /-
Copyright (c) 2021 Kexing Ying. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kexing Ying
-/
import measure_theory.decomposition.signed_hahn
/-!
# Jordan decomposition
This file proves the existence and uniqueness of the Jordan decomposition for signed measures.
The Jordan decomposition theorem states that, given a signed measure `s`, there exists a
unique pair of mutually singular measures `μ` and `ν`, such that `s = μ - ν`.
The Jordan decomposition theorem for measures is a corollary of the Hahn decomposition theorem and
is useful for the Lebesgue decomposition theorem.
## Main definitions
* `measure_theory.jordan_decomposition`: a Jordan decomposition of a measurable space is a
pair of mutually singular finite measures. We say `j` is a Jordan decomposition of a signed
meausre `s` if `s = j.pos_part - j.neg_part`.
* `measure_theory.signed_measure.to_jordan_decomposition`: the Jordan decomposition of a
signed measure.
* `measure_theory.signed_measure.to_jordan_decomposition_equiv`: is the `equiv` between
`measure_theory.signed_measure` and `measure_theory.jordan_decomposition` formed by
`measure_theory.signed_measure.to_jordan_decomposition`.
## Main results
* `measure_theory.signed_measure.to_signed_measure_to_jordan_decomposition` : the Jordan
decomposition theorem.
* `measure_theory.jordan_decomposition.to_signed_measure_injective` : the Jordan decomposition of a
signed measure is unique.
## Tags
Jordan decomposition theorem
-/
noncomputable theory
open_locale classical measure_theory ennreal nnreal
variables {α β : Type*} [measurable_space α]
namespace measure_theory
/-- A Jordan decomposition of a measurable space is a pair of mutually singular,
finite measures. -/
@[ext] structure jordan_decomposition (α : Type*) [measurable_space α] :=
(pos_part neg_part : measure α)
[pos_part_finite : is_finite_measure pos_part]
[neg_part_finite : is_finite_measure neg_part]
(mutually_singular : pos_part ⊥ₘ neg_part)
attribute [instance] jordan_decomposition.pos_part_finite
attribute [instance] jordan_decomposition.neg_part_finite
namespace jordan_decomposition
open measure vector_measure
variable (j : jordan_decomposition α)
instance : has_zero (jordan_decomposition α) :=
{ zero := ⟨0, 0, mutually_singular.zero⟩ }
instance : inhabited (jordan_decomposition α) :=
{ default := 0 }
instance : has_neg (jordan_decomposition α) :=
{ neg := λ j, ⟨j.neg_part, j.pos_part, j.mutually_singular.symm⟩ }
instance : has_scalar ℝ≥0 (jordan_decomposition α) :=
{ smul := λ r j, ⟨r • j.pos_part, r • j.neg_part,
mutually_singular.smul _ (mutually_singular.smul _ j.mutually_singular.symm).symm⟩ }
instance has_scalar_real : has_scalar ℝ (jordan_decomposition α) :=
{ smul := λ r j, if hr : 0 ≤ r then r.to_nnreal • j else - ((-r).to_nnreal • j) }
@[simp] lemma zero_pos_part : (0 : jordan_decomposition α).pos_part = 0 := rfl
@[simp] lemma zero_neg_part : (0 : jordan_decomposition α).neg_part = 0 := rfl
@[simp] lemma neg_pos_part : (-j).pos_part = j.neg_part := rfl
@[simp] lemma neg_neg_part : (-j).neg_part = j.pos_part := rfl
@[simp] lemma smul_pos_part (r : ℝ≥0) : (r • j).pos_part = r • j.pos_part := rfl
@[simp] lemma smul_neg_part (r : ℝ≥0) : (r • j).neg_part = r • j.neg_part := rfl
lemma real_smul_def (r : ℝ) (j : jordan_decomposition α) :
r • j = if hr : 0 ≤ r then r.to_nnreal • j else - ((-r).to_nnreal • j) :=
rfl
@[simp] lemma coe_smul (r : ℝ≥0) : (r : ℝ) • j = r • j :=
show dite _ _ _ = _, by rw [dif_pos (nnreal.coe_nonneg r), real.to_nnreal_coe]
lemma real_smul_nonneg (r : ℝ) (hr : 0 ≤ r) : r • j = r.to_nnreal • j :=
dif_pos hr
lemma real_smul_neg (r : ℝ) (hr : r < 0) : r • j = - ((-r).to_nnreal • j) :=
dif_neg (not_le.2 hr)
lemma real_smul_pos_part_nonneg (r : ℝ) (hr : 0 ≤ r) :
(r • j).pos_part = r.to_nnreal • j.pos_part :=
by { rw [real_smul_def, ← smul_pos_part, dif_pos hr] }
lemma real_smul_neg_part_nonneg (r : ℝ) (hr : 0 ≤ r) :
(r • j).neg_part = r.to_nnreal • j.neg_part :=
by { rw [real_smul_def, ← smul_neg_part, dif_pos hr] }
lemma real_smul_pos_part_neg (r : ℝ) (hr : r < 0) :
(r • j).pos_part = (-r).to_nnreal • j.neg_part :=
by { rw [real_smul_def, ← smul_neg_part, dif_neg (not_le.2 hr), neg_pos_part] }
lemma real_smul_neg_part_neg (r : ℝ) (hr : r < 0) :
(r • j).neg_part = (-r).to_nnreal • j.pos_part :=
by { rw [real_smul_def, ← smul_pos_part, dif_neg (not_le.2 hr), neg_neg_part] }
/-- The signed measure associated with a Jordan decomposition. -/
def to_signed_measure : signed_measure α :=
j.pos_part.to_signed_measure - j.neg_part.to_signed_measure
lemma to_signed_measure_zero : (0 : jordan_decomposition α).to_signed_measure = 0 :=
begin
ext1 i hi,
erw [to_signed_measure, to_signed_measure_sub_apply hi, sub_self, zero_apply],
end
lemma to_signed_measure_neg : (-j).to_signed_measure = -j.to_signed_measure :=
begin
ext1 i hi,
rw [neg_apply, to_signed_measure, to_signed_measure,
to_signed_measure_sub_apply hi, to_signed_measure_sub_apply hi, neg_sub],
refl,
end
lemma to_signed_measure_smul (r : ℝ≥0) : (r • j).to_signed_measure = r • j.to_signed_measure :=
begin
ext1 i hi,
rw [vector_measure.smul_apply, to_signed_measure, to_signed_measure,
to_signed_measure_sub_apply hi, to_signed_measure_sub_apply hi, smul_sub,
smul_pos_part, smul_neg_part, ← ennreal.to_real_smul, ← ennreal.to_real_smul],
refl
end
/-- A Jordan decomposition provides a Hahn decomposition. -/
lemma exists_compl_positive_negative :
∃ S : set α, measurable_set S ∧
j.to_signed_measure ≤[S] 0 ∧ 0 ≤[Sᶜ] j.to_signed_measure ∧
j.pos_part S = 0 ∧ j.neg_part Sᶜ = 0 :=
begin
obtain ⟨S, hS₁, hS₂, hS₃⟩ := j.mutually_singular,
refine ⟨S, hS₁, _, _, hS₂, hS₃⟩,
{ refine restrict_le_restrict_of_subset_le _ _ (λ A hA hA₁, _),
rw [to_signed_measure, to_signed_measure_sub_apply hA,
show j.pos_part A = 0, by exact nonpos_iff_eq_zero.1 (hS₂ ▸ measure_mono hA₁),
ennreal.zero_to_real, zero_sub, neg_le, zero_apply, neg_zero],
exact ennreal.to_real_nonneg },
{ refine restrict_le_restrict_of_subset_le _ _ (λ A hA hA₁, _),
rw [to_signed_measure, to_signed_measure_sub_apply hA,
show j.neg_part A = 0, by exact nonpos_iff_eq_zero.1 (hS₃ ▸ measure_mono hA₁),
ennreal.zero_to_real, sub_zero],
exact ennreal.to_real_nonneg },
end
end jordan_decomposition
namespace signed_measure
open measure vector_measure jordan_decomposition classical
variables {s : signed_measure α} {μ ν : measure α} [is_finite_measure μ] [is_finite_measure ν]
/-- Given a signed measure `s`, `s.to_jordan_decomposition` is the Jordan decomposition `j`,
such that `s = j.to_signed_measure`. This property is known as the Jordan decomposition
theorem, and is shown by
`measure_theory.signed_measure.to_signed_measure_to_jordan_decomposition`. -/
def to_jordan_decomposition (s : signed_measure α) : jordan_decomposition α :=
let i := some s.exists_compl_positive_negative in
let hi := some_spec s.exists_compl_positive_negative in
{ pos_part := s.to_measure_of_zero_le i hi.1 hi.2.1,
neg_part := s.to_measure_of_le_zero iᶜ hi.1.compl hi.2.2,
pos_part_finite := infer_instance,
neg_part_finite := infer_instance,
mutually_singular :=
begin
refine ⟨iᶜ, hi.1.compl, _, _⟩,
{ rw [to_measure_of_zero_le_apply _ _ hi.1 hi.1.compl], simpa },
{ rw [to_measure_of_le_zero_apply _ _ hi.1.compl hi.1.compl.compl], simpa }
end }
lemma to_jordan_decomposition_spec (s : signed_measure α) :
∃ (i : set α) (hi₁ : measurable_set i) (hi₂ : 0 ≤[i] s) (hi₃ : s ≤[iᶜ] 0),
s.to_jordan_decomposition.pos_part = s.to_measure_of_zero_le i hi₁ hi₂ ∧
s.to_jordan_decomposition.neg_part = s.to_measure_of_le_zero iᶜ hi₁.compl hi₃ :=
begin
set i := some s.exists_compl_positive_negative,
obtain ⟨hi₁, hi₂, hi₃⟩ := some_spec s.exists_compl_positive_negative,
exact ⟨i, hi₁, hi₂, hi₃, rfl, rfl⟩,
end
/-- **The Jordan decomposition theorem**: Given a signed measure `s`, there exists a pair of
mutually singular measures `μ` and `ν` such that `s = μ - ν`. In this case, the measures `μ`
and `ν` are given by `s.to_jordan_decomposition.pos_part` and
`s.to_jordan_decomposition.neg_part` respectively.
Note that we use `measure_theory.jordan_decomposition.to_signed_measure` to represent the
signed measure corresponding to
`s.to_jordan_decomposition.pos_part - s.to_jordan_decomposition.neg_part`. -/
@[simp] lemma to_signed_measure_to_jordan_decomposition (s : signed_measure α) :
s.to_jordan_decomposition.to_signed_measure = s :=
begin
obtain ⟨i, hi₁, hi₂, hi₃, hμ, hν⟩ := s.to_jordan_decomposition_spec,
simp only [jordan_decomposition.to_signed_measure, hμ, hν],
ext k hk,
rw [to_signed_measure_sub_apply hk, to_measure_of_zero_le_apply _ hi₂ hi₁ hk,
to_measure_of_le_zero_apply _ hi₃ hi₁.compl hk],
simp only [ennreal.coe_to_real, subtype.coe_mk, ennreal.some_eq_coe, sub_neg_eq_add],
rw [← of_union _ (measurable_set.inter hi₁ hk) (measurable_set.inter hi₁.compl hk),
set.inter_comm i, set.inter_comm iᶜ, set.inter_union_compl _ _],
{ apply_instance },
{ rintro x ⟨⟨hx₁, _⟩, hx₂, _⟩,
exact false.elim (hx₂ hx₁) }
end
section
variables {u v w : set α}
/-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a positive set `u`. -/
lemma subset_positive_null_set
(hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)
(hsu : 0 ≤[u] s) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) : s v = 0 :=
begin
have : s v + s (w \ v) = 0,
{ rw [← hw₁, ← of_union set.disjoint_diff hv (hw.diff hv),
set.union_diff_self, set.union_eq_self_of_subset_left hwt],
apply_instance },
have h₁ := nonneg_of_zero_le_restrict _ (restrict_le_restrict_subset _ _ hu hsu (hwt.trans hw₂)),
have h₂ := nonneg_of_zero_le_restrict _
(restrict_le_restrict_subset _ _ hu hsu ((w.diff_subset v).trans hw₂)),
linarith,
end
/-- A subset `v` of a null-set `w` has zero measure if `w` is a subset of a negative set `u`. -/
lemma subset_negative_null_set
(hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)
(hsu : s ≤[u] 0) (hw₁ : s w = 0) (hw₂ : w ⊆ u) (hwt : v ⊆ w) : s v = 0 :=
begin
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu,
have := subset_positive_null_set hu hv hw hsu,
simp only [pi.neg_apply, neg_eq_zero, coe_neg] at this,
exact this hw₁ hw₂ hwt,
end
/-- If the symmetric difference of two positive sets is a null-set, then so are the differences
between the two sets. -/
lemma of_diff_eq_zero_of_symm_diff_eq_zero_positive
(hu : measurable_set u) (hv : measurable_set v)
(hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u Δ v) = 0) :
s (u \ v) = 0 ∧ s (v \ u) = 0 :=
begin
rw restrict_le_restrict_iff at hsu hsv,
have a := hsu (hu.diff hv) (u.diff_subset v),
have b := hsv (hv.diff hu) (v.diff_subset u),
erw [of_union (set.disjoint_of_subset_left (u.diff_subset v) set.disjoint_diff)
(hu.diff hv) (hv.diff hu)] at hs,
rw zero_apply at a b,
split,
all_goals { linarith <|> apply_instance <|> assumption },
end
/-- If the symmetric difference of two negative sets is a null-set, then so are the differences
between the two sets. -/
lemma of_diff_eq_zero_of_symm_diff_eq_zero_negative
(hu : measurable_set u) (hv : measurable_set v)
(hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u Δ v) = 0) :
s (u \ v) = 0 ∧ s (v \ u) = 0 :=
begin
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu,
rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv,
have := of_diff_eq_zero_of_symm_diff_eq_zero_positive hu hv hsu hsv,
simp only [pi.neg_apply, neg_eq_zero, coe_neg] at this,
exact this hs,
end
lemma of_inter_eq_of_symm_diff_eq_zero_positive
(hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)
(hsu : 0 ≤[u] s) (hsv : 0 ≤[v] s) (hs : s (u Δ v) = 0) :
s (w ∩ u) = s (w ∩ v) :=
begin
have hwuv : s ((w ∩ u) Δ (w ∩ v)) = 0,
{ refine subset_positive_null_set (hu.union hv) ((hw.inter hu).symm_diff (hw.inter hv))
(hu.symm_diff hv) (restrict_le_restrict_union _ _ hu hsu hv hsv) hs _ _,
{ exact symm_diff_le_sup u v },
{ rintro x (⟨⟨hxw, hxu⟩, hx⟩ | ⟨⟨hxw, hxv⟩, hx⟩);
rw [set.mem_inter_eq, not_and] at hx,
{ exact or.inl ⟨hxu, hx hxw⟩ },
{ exact or.inr ⟨hxv, hx hxw⟩ } } },
obtain ⟨huv, hvu⟩ := of_diff_eq_zero_of_symm_diff_eq_zero_positive
(hw.inter hu) (hw.inter hv)
(restrict_le_restrict_subset _ _ hu hsu (w.inter_subset_right u))
(restrict_le_restrict_subset _ _ hv hsv (w.inter_subset_right v)) hwuv,
rw [← of_diff_of_diff_eq_zero (hw.inter hu) (hw.inter hv) hvu, huv, zero_add]
end
lemma of_inter_eq_of_symm_diff_eq_zero_negative
(hu : measurable_set u) (hv : measurable_set v) (hw : measurable_set w)
(hsu : s ≤[u] 0) (hsv : s ≤[v] 0) (hs : s (u Δ v) = 0) :
s (w ∩ u) = s (w ∩ v) :=
begin
rw [← s.neg_le_neg_iff _ hu, neg_zero] at hsu,
rw [← s.neg_le_neg_iff _ hv, neg_zero] at hsv,
have := of_inter_eq_of_symm_diff_eq_zero_positive hu hv hw hsu hsv,
simp only [pi.neg_apply, neg_inj, neg_eq_zero, coe_neg] at this,
exact this hs,
end
end
end signed_measure
namespace jordan_decomposition
open measure vector_measure signed_measure function
private lemma eq_of_pos_part_eq_pos_part {j₁ j₂ : jordan_decomposition α}
(hj : j₁.pos_part = j₂.pos_part) (hj' : j₁.to_signed_measure = j₂.to_signed_measure) :
j₁ = j₂ :=
begin
ext1,
{ exact hj },
{ rw ← to_signed_measure_eq_to_signed_measure_iff,
suffices : j₁.pos_part.to_signed_measure - j₁.neg_part.to_signed_measure =
j₁.pos_part.to_signed_measure - j₂.neg_part.to_signed_measure,
{ exact sub_right_inj.mp this },
convert hj' }
end
/-- The Jordan decomposition of a signed measure is unique. -/
theorem to_signed_measure_injective :
injective $ @jordan_decomposition.to_signed_measure α _ :=
begin
/- The main idea is that two Jordan decompositions of a signed measure provide two
Hahn decompositions for that measure. Then, from `of_symm_diff_compl_positive_negative`,
the symmetric difference of the two Hahn decompositions has measure zero, thus, allowing us to
show the equality of the underlying measures of the Jordan decompositions. -/
intros j₁ j₂ hj,
-- obtain the two Hahn decompositions from the Jordan decompositions
obtain ⟨S, hS₁, hS₂, hS₃, hS₄, hS₅⟩ := j₁.exists_compl_positive_negative,
obtain ⟨T, hT₁, hT₂, hT₃, hT₄, hT₅⟩ := j₂.exists_compl_positive_negative,
rw ← hj at hT₂ hT₃,
-- the symmetric differences of the two Hahn decompositions have measure zero
obtain ⟨hST₁, -⟩ := of_symm_diff_compl_positive_negative hS₁.compl hT₁.compl
⟨hS₃, (compl_compl S).symm ▸ hS₂⟩ ⟨hT₃, (compl_compl T).symm ▸ hT₂⟩,
-- it suffices to show the Jordan decompositions have the same positive parts
refine eq_of_pos_part_eq_pos_part _ hj,
ext1 i hi,
-- we see that the positive parts of the two Jordan decompositions are equal to their
-- associated signed measures restricted on their associated Hahn decompositions
have hμ₁ : (j₁.pos_part i).to_real = j₁.to_signed_measure (i ∩ Sᶜ),
{ rw [to_signed_measure, to_signed_measure_sub_apply (hi.inter hS₁.compl),
show j₁.neg_part (i ∩ Sᶜ) = 0, by exact nonpos_iff_eq_zero.1
(hS₅ ▸ measure_mono (set.inter_subset_right _ _)),
ennreal.zero_to_real, sub_zero],
conv_lhs { rw ← set.inter_union_compl i S },
rw [measure_union, show j₁.pos_part (i ∩ S) = 0, by exact nonpos_iff_eq_zero.1
(hS₄ ▸ measure_mono (set.inter_subset_right _ _)), zero_add],
{ refine set.disjoint_of_subset_left (set.inter_subset_right _ _)
(set.disjoint_of_subset_right (set.inter_subset_right _ _) disjoint_compl_right) },
{ exact hi.inter hS₁ },
{ exact hi.inter hS₁.compl } },
have hμ₂ : (j₂.pos_part i).to_real = j₂.to_signed_measure (i ∩ Tᶜ),
{ rw [to_signed_measure, to_signed_measure_sub_apply (hi.inter hT₁.compl),
show j₂.neg_part (i ∩ Tᶜ) = 0, by exact nonpos_iff_eq_zero.1
(hT₅ ▸ measure_mono (set.inter_subset_right _ _)),
ennreal.zero_to_real, sub_zero],
conv_lhs { rw ← set.inter_union_compl i T },
rw [measure_union, show j₂.pos_part (i ∩ T) = 0, by exact nonpos_iff_eq_zero.1
(hT₄ ▸ measure_mono (set.inter_subset_right _ _)), zero_add],
{ exact set.disjoint_of_subset_left (set.inter_subset_right _ _)
(set.disjoint_of_subset_right (set.inter_subset_right _ _) disjoint_compl_right) },
{ exact hi.inter hT₁ },
{ exact hi.inter hT₁.compl } },
-- since the two signed measures associated with the Jordan decompositions are the same,
-- and the symmetric difference of the Hahn decompositions have measure zero, the result follows
rw [← ennreal.to_real_eq_to_real (measure_ne_top _ _) (measure_ne_top _ _), hμ₁, hμ₂, ← hj],
exact of_inter_eq_of_symm_diff_eq_zero_positive hS₁.compl hT₁.compl hi hS₃ hT₃ hST₁,
all_goals { apply_instance },
end
@[simp]
lemma to_jordan_decomposition_to_signed_measure (j : jordan_decomposition α) :
(j.to_signed_measure).to_jordan_decomposition = j :=
(@to_signed_measure_injective _ _ j (j.to_signed_measure).to_jordan_decomposition (by simp)).symm
end jordan_decomposition
namespace signed_measure
open jordan_decomposition
/-- `measure_theory.signed_measure.to_jordan_decomposition` and
`measure_theory.jordan_decomposition.to_signed_measure` form a `equiv`. -/
@[simps apply symm_apply]
def to_jordan_decomposition_equiv (α : Type*) [measurable_space α] :
signed_measure α ≃ jordan_decomposition α :=
{ to_fun := to_jordan_decomposition,
inv_fun := to_signed_measure,
left_inv := to_signed_measure_to_jordan_decomposition,
right_inv := to_jordan_decomposition_to_signed_measure }
lemma to_jordan_decomposition_zero : (0 : signed_measure α).to_jordan_decomposition = 0 :=
begin
apply to_signed_measure_injective,
simp [to_signed_measure_zero],
end
lemma to_jordan_decomposition_neg (s : signed_measure α) :
(-s).to_jordan_decomposition = -s.to_jordan_decomposition :=
begin
apply to_signed_measure_injective,
simp [to_signed_measure_neg],
end
lemma to_jordan_decomposition_smul (s : signed_measure α) (r : ℝ≥0) :
(r • s).to_jordan_decomposition = r • s.to_jordan_decomposition :=
begin
apply to_signed_measure_injective,
simp [to_signed_measure_smul],
end
private
lemma to_jordan_decomposition_smul_real_nonneg (s : signed_measure α) (r : ℝ) (hr : 0 ≤ r):
(r • s).to_jordan_decomposition = r • s.to_jordan_decomposition :=
begin
lift r to ℝ≥0 using hr,
rw [jordan_decomposition.coe_smul, ← to_jordan_decomposition_smul],
refl
end
lemma to_jordan_decomposition_smul_real (s : signed_measure α) (r : ℝ) :
(r • s).to_jordan_decomposition = r • s.to_jordan_decomposition :=
begin
by_cases hr : 0 ≤ r,
{ exact to_jordan_decomposition_smul_real_nonneg s r hr },
{ ext1,
{ rw [real_smul_pos_part_neg _ _ (not_le.1 hr),
show r • s = -(-r • s), by rw [neg_smul, neg_neg], to_jordan_decomposition_neg,
neg_pos_part, to_jordan_decomposition_smul_real_nonneg, ← smul_neg_part,
real_smul_nonneg],
all_goals { exact left.nonneg_neg_iff.2 (le_of_lt (not_le.1 hr)) } },
{ rw [real_smul_neg_part_neg _ _ (not_le.1 hr),
show r • s = -(-r • s), by rw [neg_smul, neg_neg], to_jordan_decomposition_neg,
neg_neg_part, to_jordan_decomposition_smul_real_nonneg, ← smul_pos_part,
real_smul_nonneg],
all_goals { exact left.nonneg_neg_iff.2 (le_of_lt (not_le.1 hr)) } } }
end
lemma to_jordan_decomposition_eq {s : signed_measure α} {j : jordan_decomposition α}
(h : s = j.to_signed_measure) : s.to_jordan_decomposition = j :=
by rw [h, to_jordan_decomposition_to_signed_measure]
/-- The total variation of a signed measure. -/
def total_variation (s : signed_measure α) : measure α :=
s.to_jordan_decomposition.pos_part + s.to_jordan_decomposition.neg_part
lemma total_variation_zero : (0 : signed_measure α).total_variation = 0 :=
by simp [total_variation, to_jordan_decomposition_zero]
lemma total_variation_neg (s : signed_measure α) : (-s).total_variation = s.total_variation :=
by simp [total_variation, to_jordan_decomposition_neg, add_comm]
lemma null_of_total_variation_zero (s : signed_measure α) {i : set α}
(hs : s.total_variation i = 0) : s i = 0 :=
begin
rw [total_variation, measure.coe_add, pi.add_apply, add_eq_zero_iff] at hs,
rw [← to_signed_measure_to_jordan_decomposition s, to_signed_measure, vector_measure.coe_sub,
pi.sub_apply, measure.to_signed_measure_apply, measure.to_signed_measure_apply],
by_cases hi : measurable_set i,
{ rw [if_pos hi, if_pos hi], simp [hs.1, hs.2] },
{ simp [if_neg hi] }
end
lemma absolutely_continuous_ennreal_iff (s : signed_measure α) (μ : vector_measure α ℝ≥0∞) :
s ≪ μ ↔ s.total_variation ≪ μ.ennreal_to_measure :=
begin
split; intro h,
{ refine measure.absolutely_continuous.mk (λ S hS₁ hS₂, _),
obtain ⟨i, hi₁, hi₂, hi₃, hpos, hneg⟩ := s.to_jordan_decomposition_spec,
rw [total_variation, measure.add_apply, hpos, hneg,
to_measure_of_zero_le_apply _ _ _ hS₁, to_measure_of_le_zero_apply _ _ _ hS₁],
rw ← vector_measure.absolutely_continuous.ennreal_to_measure at h,
simp [h (measure_mono_null (i.inter_subset_right S) hS₂),
h (measure_mono_null (iᶜ.inter_subset_right S) hS₂)],
refl },
{ refine vector_measure.absolutely_continuous.mk (λ S hS₁ hS₂, _),
rw ← vector_measure.ennreal_to_measure_apply hS₁ at hS₂,
exact null_of_total_variation_zero s (h hS₂) }
end
lemma total_variation_absolutely_continuous_iff (s : signed_measure α) (μ : measure α) :
s.total_variation ≪ μ ↔
s.to_jordan_decomposition.pos_part ≪ μ ∧ s.to_jordan_decomposition.neg_part ≪ μ :=
begin
split; intro h,
{ split, all_goals
{ refine measure.absolutely_continuous.mk (λ S hS₁ hS₂, _),
have := h hS₂,
rw [total_variation, measure.add_apply, add_eq_zero_iff] at this },
exacts [this.1, this.2] },
{ refine measure.absolutely_continuous.mk (λ S hS₁ hS₂, _),
rw [total_variation, measure.add_apply, h.1 hS₂, h.2 hS₂, add_zero] }
end
-- TODO: Generalize to vector measures once total variation on vector measures is defined
lemma mutually_singular_iff (s t : signed_measure α) :
s ⊥ᵥ t ↔ s.total_variation ⊥ₘ t.total_variation :=
begin
split,
{ rintro ⟨u, hmeas, hu₁, hu₂⟩,
obtain ⟨i, hi₁, hi₂, hi₃, hipos, hineg⟩ := s.to_jordan_decomposition_spec,
obtain ⟨j, hj₁, hj₂, hj₃, hjpos, hjneg⟩ := t.to_jordan_decomposition_spec,
refine ⟨u, hmeas, _, _⟩,
{ rw [total_variation, measure.add_apply, hipos, hineg,
to_measure_of_zero_le_apply _ _ _ hmeas, to_measure_of_le_zero_apply _ _ _ hmeas],
simpa [hu₁ _ (set.inter_subset_right _ _)] },
{ rw [total_variation, measure.add_apply, hjpos, hjneg,
to_measure_of_zero_le_apply _ _ _ hmeas.compl,
to_measure_of_le_zero_apply _ _ _ hmeas.compl],
simpa [hu₂ _ (set.inter_subset_right _ _)] } },
{ rintro ⟨u, hmeas, hu₁, hu₂⟩,
exact ⟨u, hmeas,
(λ t htu, null_of_total_variation_zero _ (measure_mono_null htu hu₁)),
(λ t htv, null_of_total_variation_zero _ (measure_mono_null htv hu₂))⟩ }
end
lemma mutually_singular_ennreal_iff (s : signed_measure α) (μ : vector_measure α ℝ≥0∞) :
s ⊥ᵥ μ ↔ s.total_variation ⊥ₘ μ.ennreal_to_measure :=
begin
split,
{ rintro ⟨u, hmeas, hu₁, hu₂⟩,
obtain ⟨i, hi₁, hi₂, hi₃, hpos, hneg⟩ := s.to_jordan_decomposition_spec,
refine ⟨u, hmeas, _, _⟩,
{ rw [total_variation, measure.add_apply, hpos, hneg,
to_measure_of_zero_le_apply _ _ _ hmeas, to_measure_of_le_zero_apply _ _ _ hmeas],
simpa [hu₁ _ (set.inter_subset_right _ _)] },
{ rw vector_measure.ennreal_to_measure_apply hmeas.compl,
exact hu₂ _ (set.subset.refl _) } },
{ rintro ⟨u, hmeas, hu₁, hu₂⟩,
refine vector_measure.mutually_singular.mk u hmeas
(λ t htu _, null_of_total_variation_zero _ (measure_mono_null htu hu₁)) (λ t htv hmt, _),
rw ← vector_measure.ennreal_to_measure_apply hmt,
exact measure_mono_null htv hu₂ }
end
lemma total_variation_mutually_singular_iff (s : signed_measure α) (μ : measure α) :
s.total_variation ⊥ₘ μ ↔
s.to_jordan_decomposition.pos_part ⊥ₘ μ ∧ s.to_jordan_decomposition.neg_part ⊥ₘ μ :=
measure.mutually_singular.add_iff
end signed_measure
end measure_theory
|
e75714938d2315dd0b81aedfa4913d916011c731 | 9dd3f3912f7321eb58ee9aa8f21778ad6221f87c | /tests/lean/coe1.lean | c512e576a1ef1b302a1af24438854bf4cc0a41cd | [
"Apache-2.0"
] | permissive | bre7k30/lean | de893411bcfa7b3c5572e61b9e1c52951b310aa4 | 5a924699d076dab1bd5af23a8f910b433e598d7a | refs/heads/master | 1,610,900,145,817 | 1,488,006,845,000 | 1,488,006,845,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 893 | lean | namespace hidden
check if tt then "a" else "b"
/- Remark: in the standard library nat_to_int and int_to_real are has_lift instances
instead of has_coe. -/
constant int : Type
constant real : Type
constant nat_to_int : has_coe nat int
constant int_to_real : has_coe int real
attribute [instance] nat_to_int int_to_real
constant sine : real → real
constants n m : nat
constants i j : int
constants x y : real
check sine x
check sine n
check sine i
constant int_has_add : has_add int
constant real_has_add : has_add real
attribute [instance] int_has_add real_has_add
check x + i
/- The following one does not work because the implicit argument ?A of add is bound to int
when x is processed. -/
check i + x -- FAIL
/- The workaround is to use the explicit lift -/
check ↑i + x
check x + n
check n + x -- FAIL
check ↑n + x
check (i:real) + x
check (n:real) + x
end hidden
|
1f8321a65caf9118601be7d92a1890c7a8850e0a | 80746c6dba6a866de5431094bf9f8f841b043d77 | /src/algebra/big_operators.lean | 418c54351fd56b5ae4d84ab232edbed3b38f7f31 | [
"Apache-2.0"
] | permissive | leanprover-fork/mathlib-backup | 8b5c95c535b148fca858f7e8db75a76252e32987 | 0eb9db6a1a8a605f0cf9e33873d0450f9f0ae9b0 | refs/heads/master | 1,585,156,056,139 | 1,548,864,430,000 | 1,548,864,438,000 | 143,964,213 | 0 | 0 | Apache-2.0 | 1,550,795,966,000 | 1,533,705,322,000 | Lean | UTF-8 | Lean | false | false | 27,714 | 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
Some big operators for lists and finite sets.
-/
import data.list.basic data.list.perm data.finset
import algebra.group algebra.ordered_group algebra.group_power
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
theorem directed.finset_le {r : α → α → Prop} [is_trans α r]
{ι} (hι : nonempty ι) {f : ι → α} (D : directed r f) (s : finset ι) :
∃ z, ∀ i ∈ s, r (f i) (f z) :=
show ∃ z, ∀ i ∈ s.1, r (f i) (f z), from
multiset.induction_on s.1 (let ⟨z⟩ := hι in ⟨z, λ _, false.elim⟩) $
λ i s ⟨j, H⟩, let ⟨k, h₁, h₂⟩ := D i j in
⟨k, λ a h, or.cases_on (multiset.mem_cons.1 h)
(λ h, h.symm ▸ h₁)
(λ h, trans (H _ h) h₂)⟩
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
/-- `prod s f` is the product of `f x` as `x` ranges over the elements of the finite set `s`. -/
@[to_additive finset.sum]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
attribute [to_additive finset.sum.equations._eqn_1] finset.prod.equations._eqn_1
@[to_additive finset.sum_eq_fold]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) : s.prod f = s.fold (*) 1 f := rfl
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive finset.sum_empty]
lemma prod_empty {α : Type u} {f : α → β} : (∅:finset α).prod f = 1 := rfl
@[simp, to_additive finset.sum_insert]
lemma prod_insert [decidable_eq α] : a ∉ s → (insert a s).prod f = f a * s.prod f := fold_insert
@[simp, to_additive finset.sum_singleton]
lemma prod_singleton : (singleton a).prod f = f a :=
eq.trans fold_singleton $ mul_one _
@[simp] lemma prod_const_one : s.prod (λx, (1 : β)) = 1 :=
by simp only [finset.prod, multiset.map_const, multiset.prod_repeat, one_pow]
@[simp] lemma sum_const_zero {β} {s : finset α} [add_comm_monoid β] : s.sum (λx, (0 : β)) = 0 :=
@prod_const_one _ (multiplicative β) _ _
attribute [to_additive finset.sum_const_zero] prod_const_one
@[simp, to_additive finset.sum_image]
lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
(∀x∈s, ∀y∈s, g x = g y → x = y) → (s.image g).prod f = s.prod (λx, f (g x)) :=
fold_image
@[congr, to_additive finset.sum_congr]
lemma prod_congr (h : s₁ = s₂) : (∀x∈s₂, f x = g x) → s₁.prod f = s₂.prod g :=
by rw [h]; exact fold_congr
attribute [congr] finset.sum_congr
@[to_additive finset.sum_union_inter]
lemma prod_union_inter [decidable_eq α] : (s₁ ∪ s₂).prod f * (s₁ ∩ s₂).prod f = s₁.prod f * s₂.prod f :=
fold_union_inter
@[to_additive finset.sum_union]
lemma prod_union [decidable_eq α] (h : s₁ ∩ s₂ = ∅) : (s₁ ∪ s₂).prod f = s₁.prod f * s₂.prod f :=
by rw [←prod_union_inter, h]; exact (mul_one _).symm
@[to_additive finset.sum_sdiff]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) : (s₂ \ s₁).prod f * s₁.prod f = s₂.prod f :=
by rw [←prod_union (sdiff_inter_self _ _), sdiff_union_of_subset h]
@[to_additive finset.sum_bind]
lemma prod_bind [decidable_eq α] {s : finset γ} {t : γ → finset α} :
(∀x∈s, ∀y∈s, x ≠ y → t x ∩ t y = ∅) → (s.bind t).prod f = s.prod (λx, (t x).prod f) :=
by haveI := classical.dec_eq γ; exact
finset.induction_on s (λ _, by simp only [bind_empty, prod_empty])
(assume x s hxs ih hd,
have hd' : ∀x∈s, ∀y∈s, x ≠ y → t x ∩ t y = ∅,
from assume _ hx _ hy, hd _ (mem_insert_of_mem hx) _ (mem_insert_of_mem hy),
have t x ∩ finset.bind s t = ∅,
from eq_empty_of_forall_not_mem $ assume a,
by rw [mem_inter, mem_bind];
rintro ⟨h₁, y, hys, hy₂⟩;
exact eq_empty_iff_forall_not_mem.1
(hd _ (mem_insert_self _ _) _ (mem_insert_of_mem hys) (assume h, hxs (h.symm ▸ hys)))
_ (mem_inter_of_mem h₁ hy₂),
by simp only [bind_insert, prod_insert hxs, prod_union this, ih hd'])
@[to_additive finset.sum_product]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(s.product t).prod f = s.prod (λx, t.prod $ λy, f (x, y)) :=
begin
haveI := classical.dec_eq α, haveI := classical.dec_eq γ,
rw [product_eq_bind, prod_bind (λ x hx y hy h, eq_empty_of_forall_not_mem _)],
{ congr, funext, exact prod_image (λ _ _ _ _ H, (prod.mk.inj H).2) },
simp only [mem_inter, mem_image], rintro ⟨_, _⟩ ⟨⟨_, _, _⟩, ⟨_, _, _⟩⟩, apply h, cc
end
@[to_additive finset.sum_sigma]
lemma prod_sigma {σ : α → Type*}
{s : finset α} {t : Πa, finset (σ a)} {f : sigma σ → β} :
(s.sigma t).prod f = s.prod (λa, (t a).prod $ λs, f ⟨a, s⟩) :=
by haveI := classical.dec_eq α; haveI := (λ a, classical.dec_eq (σ a)); exact
calc (s.sigma t).prod f =
(s.bind (λa, (t a).image (λs, sigma.mk a s))).prod f : by rw sigma_eq_bind
... = s.prod (λa, ((t a).image (λs, sigma.mk a s)).prod f) :
prod_bind $ assume a₁ ha a₂ ha₂ h, eq_empty_of_forall_not_mem $
by simp only [mem_inter, mem_image];
rintro ⟨_, _⟩ ⟨⟨_, _, _⟩, ⟨_, _, _⟩⟩; apply h; cc
... = (s.prod $ λa, (t a).prod $ λs, f ⟨a, s⟩) :
prod_congr rfl $ λ _ _, prod_image $ λ _ _ _ _ _, by cc
@[to_additive finset.sum_image']
lemma prod_image' [decidable_eq α] {s : finset γ} {g : γ → α} (h : γ → β)
(eq : ∀c∈s, f (g c) = (s.filter (λc', g c' = g c)).prod h) :
(s.image g).prod f = s.prod h :=
begin
letI := classical.dec_eq γ,
rw [← image_bind_filter_eq s g] {occs := occurrences.pos [2]},
rw [finset.prod_bind],
{ refine finset.prod_congr rfl (assume a ha, _),
rcases finset.mem_image.1 ha with ⟨b, hb, rfl⟩,
exact eq b hb },
assume a₀ _ a₁ _ ne,
refine disjoint_iff_inter_eq_empty.1 (disjoint_iff_ne.2 _),
assume c₀ h₀ c₁ h₁,
rcases mem_filter.1 h₀ with ⟨h₀, rfl⟩,
rcases mem_filter.1 h₁ with ⟨h₁, rfl⟩,
exact mt (congr_arg g) ne
end
@[to_additive finset.sum_add_distrib]
lemma prod_mul_distrib : s.prod (λx, f x * g x) = s.prod f * s.prod g :=
eq.trans (by rw one_mul; refl) fold_op_distrib
@[to_additive finset.sum_comm]
lemma prod_comm [decidable_eq γ] {s : finset γ} {t : finset α} {f : γ → α → β} :
s.prod (λx, t.prod $ f x) = t.prod (λy, s.prod $ λx, f x y) :=
finset.induction_on s (by simp only [prod_empty, prod_const_one]) $
λ _ _ H ih, by simp only [prod_insert H, prod_mul_distrib, ih]
lemma prod_hom [comm_monoid γ] (g : β → γ) [is_monoid_hom g] : s.prod (λx, g (f x)) = g (s.prod f) :=
eq.trans (by rw is_monoid_hom.map_one g; refl) (fold_hom (λ _ _, is_monoid_hom.map_mul g))
@[to_additive finset.sum_hom_rel]
lemma prod_hom_rel [comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : finset α}
(h₁ : r 1 1) (h₂ : ∀a b c, r b c → r (f a * b) (g a * c)) : r (s.prod f) (s.prod g) :=
begin
letI := classical.dec_eq α,
refine finset.induction_on s h₁ (assume a s has ih, _),
rw [prod_insert has, prod_insert has],
exact h₂ a (s.prod f) (s.prod g) ih,
end
@[to_additive finset.sum_subset]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → f x = 1) : s₁.prod f = s₂.prod f :=
by haveI := classical.dec_eq α; exact
have (s₂ \ s₁).prod f = (s₂ \ s₁).prod (λx, 1),
from prod_congr rfl $ by simpa only [mem_sdiff, and_imp],
by rw [←prod_sdiff h]; simp only [this, prod_const_one, one_mul]
@[to_additive finset.sum_eq_single]
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
(h₀ : ∀b∈s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : s.prod f = f a :=
by haveI := classical.dec_eq α;
from classical.by_cases
(assume : a ∈ s,
calc s.prod f = ({a} : finset α).prod f :
begin
refine (prod_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ simpa only [mem_singleton] }
end
... = f a : prod_singleton)
(assume : a ∉ s,
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
prod_const_one.trans (h₁ this).symm)
@[to_additive finset.sum_attach]
lemma prod_attach {f : α → β} : s.attach.prod (λx, f x.val) = s.prod f :=
by haveI := classical.dec_eq α; exact
calc s.attach.prod (λx, f x.val) = ((s.attach).image subtype.val).prod f :
by rw [prod_image]; exact assume x _ y _, subtype.eq
... = _ : by rw [attach_image_val]
@[to_additive finset.sum_bij]
lemma prod_bij {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, γ) (hi : ∀a ha, i a ha ∈ t) (h : ∀a ha, f a = g (i a ha))
(i_inj : ∀a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀b∈t, ∃a ha, b = i a ha) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = s.attach.prod (λx, f x.val) : prod_attach.symm
... = s.attach.prod (λx, g (i x.1 x.2)) : prod_congr rfl $ assume x hx, h _ _
... = (s.attach.image $ λx:{x // x ∈ s}, i x.1 x.2).prod g :
(prod_image $ assume (a₁:{x // x ∈ s}) _ a₂ _ eq, subtype.eq $ i_inj a₁.1 a₂.1 a₁.2 a₂.2 eq).symm
... = t.prod g :
prod_subset
(by simp only [subset_iff, mem_image, mem_attach]; rintro _ ⟨⟨_, _⟩, _, rfl⟩; solve_by_elim)
(assume b hb hb1, false.elim $ hb1 $ by rcases i_surj b hb with ⟨a, ha, rfl⟩;
exact mem_image.2 ⟨⟨_, _⟩, mem_attach _ _, rfl⟩)
@[to_additive finset.sum_bij_ne_zero]
lemma prod_bij_ne_one {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Πa∈s, f a ≠ 1 → γ) (hi₁ : ∀a h₁ h₂, i a h₁ h₂ ∈ t)
(hi₂ : ∀a₁ a₂ h₁₁ h₁₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(hi₃ : ∀b∈t, g b ≠ 1 → ∃a h₁ h₂, b = i a h₁ h₂)
(h : ∀a h₁ h₂, f a = g (i a h₁ h₂)) :
s.prod f = t.prod g :=
by haveI := classical.prop_decidable; exact
calc s.prod f = (s.filter $ λx, f x ≠ 1).prod f :
(prod_subset (filter_subset _) $ by simp only [not_imp_comm, mem_filter]; exact λ _, and.intro).symm
... = (t.filter $ λx, g x ≠ 1).prod g :
prod_bij (assume a ha, i a (mem_filter.mp ha).1 (mem_filter.mp ha).2)
(assume a ha, (mem_filter.mp ha).elim $ λh₁ h₂, mem_filter.mpr
⟨hi₁ a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
(assume a ha, (mem_filter.mp ha).elim $ h a)
(assume a₁ a₂ ha₁ ha₂,
(mem_filter.mp ha₁).elim $ λha₁₁ ha₁₂, (mem_filter.mp ha₂).elim $ λha₂₁ ha₂₂, hi₂ a₁ a₂ _ _ _ _)
(assume b hb, (mem_filter.mp hb).elim $ λh₁ h₂,
let ⟨a, ha₁, ha₂, eq⟩ := hi₃ b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
... = t.prod g :
(prod_subset (filter_subset _) $ by simp only [not_imp_comm, mem_filter]; exact λ _, and.intro)
@[to_additive finset.exists_ne_zero_of_sum_ne_zero]
lemma exists_ne_one_of_prod_ne_one : s.prod f ≠ 1 → ∃a∈s, f a ≠ 1 :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (λ H, (H rfl).elim) (assume a s has ih h,
classical.by_cases
(assume ha : f a = 1,
let ⟨a, ha, hfa⟩ := ih (by rwa [prod_insert has, ha, one_mul] at h) in
⟨a, mem_insert_of_mem ha, hfa⟩)
(assume hna : f a ≠ 1,
⟨a, mem_insert_self _ _, hna⟩))
@[to_additive finset.sum_range_succ]
lemma prod_range_succ (f : ℕ → β) (n : ℕ) :
(range (nat.succ n)).prod f = f n * (range n).prod f :=
by rw [range_succ, prod_insert not_mem_range_self]
lemma prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (range (nat.succ n)).prod f = (range n).prod (f ∘ nat.succ) * f 0
| 0 := (prod_range_succ _ _).trans $ mul_comm _ _
| (n + 1) := by rw [prod_range_succ (λ m, f (nat.succ m)), mul_assoc, ← prod_range_succ'];
exact prod_range_succ _ _
@[simp] lemma prod_const (b : β) : s.prod (λ a, b) = b ^ s.card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s rfl (λ a s has ih,
by rw [prod_insert has, card_insert_of_not_mem has, pow_succ, ih])
lemma prod_pow (s : finset α) (n : ℕ) (f : α → β) :
s.prod (λ x, f x ^ n) = s.prod f ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [_root_.mul_pow] {contextual := tt})
lemma prod_nat_pow (s : finset α) (n : ℕ) (f : α → ℕ) :
s.prod (λ x, f x ^ n) = s.prod f ^ n :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp) (by simp [nat.mul_pow] {contextual := tt})
@[to_additive finset.sum_involution]
lemma prod_involution {s : finset α} {f : α → β} :
∀ (g : Π a ∈ s, α)
(h₁ : ∀ a ha, f a * f (g a ha) = 1)
(h₂ : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(h₃ : ∀ a ha, g a ha ∈ s)
(h₄ : ∀ a ha, g (g a ha) (h₃ a ha) = a),
s.prod f = 1 :=
by haveI := classical.dec_eq α;
haveI := classical.dec_eq β; exact
finset.strong_induction_on s
(λ s ih g h₁ h₂ h₃ h₄,
if hs : s = ∅ then hs.symm ▸ rfl
else let ⟨x, hx⟩ := exists_mem_of_ne_empty hs in
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
from λ x hx y hy h, by rw [← h₄ x hx, ← h₄ y hy]; simp [h],
have ih': (erase (erase s x) (g x hx)).prod f = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨subset.trans (erase_subset _ _) (erase_subset _ _),
λ h, not_mem_erase (g x hx) (s.erase x) (h (h₃ x hx))⟩
(λ y hy, g y (hmem y hy))
(λ y hy, h₁ y (hmem y hy))
(λ y hy, h₂ y (hmem y hy))
(λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
mem_erase.2 ⟨λ (h : g y _ = x),
have y = g x hx, from h₄ y (hmem y hy) ▸ by simp [h],
by simpa [this] using hy, h₃ y (hmem y hy)⟩⟩)
(λ y hy, h₄ y (hmem y hy)),
if hx1 : f x = 1
then ih' ▸ eq.symm (prod_subset hmem
(λ y hy hy₁,
have y = x ∨ y = g x hx, by simp [hy] at hy₁; tauto,
this.elim (λ h, h.symm ▸ hx1)
(λ h, h₁ x hx ▸ h ▸ hx1.symm ▸ (one_mul _).symm)))
else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
← insert_erase (mem_erase.2 ⟨h₂ x hx hx1, h₃ x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h₁ x hx])
@[to_additive finset.sum_eq_zero]
lemma prod_eq_one [comm_monoid β] {f : α → β} {s : finset α} (h : ∀x∈s, f x = 1) : s.prod f = 1 :=
calc s.prod f = s.prod (λx, 1) : finset.prod_congr rfl h
... = 1 : finset.prod_const_one
end comm_monoid
lemma sum_hom [add_comm_monoid β] [add_comm_monoid γ] (g : β → γ) [is_add_monoid_hom g] :
s.sum (λx, g (f x)) = g (s.sum f) :=
eq.trans (by rw is_add_monoid_hom.map_zero g; refl) (fold_hom (λ _ _, is_add_monoid_hom.map_add g))
attribute [to_additive finset.sum_hom] prod_hom
lemma sum_smul [add_comm_monoid β] (s : finset α) (n : ℕ) (f : α → β) :
s.sum (λ x, add_monoid.smul n (f x)) = add_monoid.smul n (s.sum f) :=
@prod_pow _ (multiplicative β) _ _ _ _
attribute [to_additive finset.sum_smul] prod_pow
@[simp] lemma sum_const [add_comm_monoid β] (b : β) :
s.sum (λ a, b) = add_monoid.smul s.card b :=
@prod_const _ (multiplicative β) _ _ _
attribute [to_additive finset.sum_const] prod_const
lemma sum_range_succ' [add_comm_monoid β] (f : ℕ → β) :
∀ n : ℕ, (range (nat.succ n)).sum f = (range n).sum (f ∘ nat.succ) + f 0 :=
@prod_range_succ' (multiplicative β) _ _
attribute [to_additive finset.sum_range_succ'] prod_range_succ'
lemma sum_nat_cast [add_comm_monoid β] [has_one β] (s : finset α) (f : α → ℕ) :
↑(s.sum f) = s.sum (λa, f a : α → β) :=
(sum_hom _).symm
section comm_group
variables [comm_group β]
@[simp, to_additive finset.sum_neg_distrib]
lemma prod_inv_distrib : s.prod (λx, (f x)⁻¹) = (s.prod f)⁻¹ :=
prod_hom has_inv.inv
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = s.sum (λ a, card (t a)) :=
multiset.card_sigma _ _
lemma card_bind [decidable_eq β] {s : finset α} {t : α → finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → t x ∩ t y = ∅) :
(s.bind t).card = s.sum (λ u, card (t u)) :=
calc (s.bind t).card = (s.bind t).sum (λ _, 1) : by simp
... = s.sum (λ a, (t a).sum (λ _, 1)) : finset.sum_bind h
... = s.sum (λ u, card (t u)) : by simp
lemma card_bind_le [decidable_eq β] {s : finset α} {t : α → finset β} :
(s.bind t).card ≤ s.sum (λ a, (t a).card) :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp)
(λ a s has ih,
calc ((insert a s).bind t).card ≤ (t a).card + (s.bind t).card :
by rw bind_insert; exact finset.card_union_le _ _
... ≤ (insert a s).sum (λ a, card (t a)) :
by rw sum_insert has; exact add_le_add_left ih _)
lemma gsmul_sum [add_comm_group β] {f : α → β} {s : finset α} (z : ℤ) :
gsmul z (s.sum f) = s.sum (λa, gsmul z (f a)) :=
(finset.sum_hom (gsmul z)).symm
end finset
namespace finset
variables {s s₁ s₂ : finset α} {f g : α → β} {b : β} {a : α}
@[simp] lemma sum_sub_distrib [add_comm_group β] : s.sum (λx, f x - g x) = s.sum f - s.sum g :=
sum_add_distrib.trans $ congr_arg _ sum_neg_distrib
section ordered_cancel_comm_monoid
variables [decidable_eq α] [ordered_cancel_comm_monoid β]
lemma sum_le_sum : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (λ _, le_refl _) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
lemma zero_le_sum (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by rw [sum_const_zero]) (sum_le_sum h)
lemma sum_le_zero (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 0 := le_trans (sum_le_sum h) (by rw [sum_const_zero])
end ordered_cancel_comm_monoid
section semiring
variables [semiring β]
lemma sum_mul : s.sum f * b = s.sum (λx, f x * b) :=
(sum_hom (λx, x * b)).symm
lemma mul_sum : b * s.sum f = s.sum (λx, b * f x) :=
(sum_hom (λx, b * x)).symm
end semiring
section comm_semiring
variables [decidable_eq α] [comm_semiring β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : s.prod f = 0 :=
calc s.prod f = (insert a (erase s a)).prod f : by rw insert_erase ha
... = 0 : by rw [prod_insert (not_mem_erase _ _), h, zero_mul]
lemma prod_sum {δ : α → Type*} [∀a, decidable_eq (δ a)]
{s : finset α} {t : Πa, finset (δ a)} {f : Πa, δ a → β} :
s.prod (λa, (t a).sum (λb, f a b)) =
(s.pi t).sum (λp, s.attach.prod (λx, f x.1 (p x.1 x.2))) :=
begin
induction s using finset.induction with a s ha ih,
{ rw [pi_empty, sum_singleton], refl },
{ have h₁ : ∀x ∈ t a, ∀y ∈ t a, ∀h : x ≠ y,
image (pi.cons s a x) (pi s t) ∩ image (pi.cons s a y) (pi s t) = ∅,
{ assume x hx y hy h,
apply eq_empty_of_forall_not_mem,
simp only [mem_inter, mem_image],
rintro p₁ ⟨⟨p₂, hp, eq⟩, ⟨p₃, hp₃, rfl⟩⟩,
have : pi.cons s a x p₂ a (mem_insert_self _ _) = pi.cons s a y p₃ a (mem_insert_self _ _),
{ rw [eq] },
rw [pi.cons_same, pi.cons_same] at this,
exact h this },
rw [prod_insert ha, pi_insert ha, ih, sum_mul, sum_bind h₁],
refine sum_congr rfl (λ b _, _),
have h₂ : ∀p₁∈pi s t, ∀p₂∈pi s t, pi.cons s a b p₁ = pi.cons s a b p₂ → p₁ = p₂, from
assume p₁ h₁ p₂ h₂ eq, injective_pi_cons ha eq,
rw [sum_image h₂, mul_sum],
refine sum_congr rfl (λ g _, _),
rw [attach_insert, prod_insert, prod_image],
{ simp only [pi.cons_same],
congr', ext ⟨v, hv⟩, congr',
exact (pi.cons_ne (by rintro rfl; exact ha hv)).symm },
{ exact λ _ _ _ _, subtype.eq ∘ subtype.mk.inj },
{ simp only [mem_image], rintro ⟨⟨_, hm⟩, _, rfl⟩, exact ha hm } }
end
end comm_semiring
section integral_domain /- add integral_semi_domain to support nat and ennreal -/
variables [decidable_eq α] [integral_domain β]
lemma prod_eq_zero_iff : s.prod f = 0 ↔ (∃a∈s, f a = 0) :=
finset.induction_on s ⟨not.elim one_ne_zero, λ ⟨_, H, _⟩, H.elim⟩ $ λ a s ha ih,
by rw [prod_insert ha, mul_eq_zero_iff_eq_zero_or_eq_zero,
bex_def, exists_mem_insert, ih, ← bex_def]
end integral_domain
section ordered_comm_monoid
variables [decidable_eq α] [ordered_comm_monoid β]
lemma sum_le_sum' : (∀x∈s, f x ≤ g x) → s.sum f ≤ s.sum g :=
finset.induction_on s (λ _, le_refl _) $ assume a s ha ih h,
have f a + s.sum f ≤ g a + s.sum g,
from add_le_add' (h _ (mem_insert_self _ _)) (ih $ assume x hx, h _ $ mem_insert_of_mem hx),
by simpa only [sum_insert ha]
lemma zero_le_sum' (h : ∀x∈s, 0 ≤ f x) : 0 ≤ s.sum f := le_trans (by rw [sum_const_zero]) (sum_le_sum' h)
lemma sum_le_zero' (h : ∀x∈s, f x ≤ 0) : s.sum f ≤ 0 := le_trans (sum_le_sum' h) (by rw [sum_const_zero])
lemma sum_le_sum_of_subset_of_nonneg
(h : s₁ ⊆ s₂) (hf : ∀x∈s₂, x ∉ s₁ → 0 ≤ f x) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f ≤ (s₂ \ s₁).sum f + s₁.sum f :
le_add_of_nonneg_left' $ zero_le_sum' $ by simpa only [mem_sdiff, and_imp]
... = (s₂ \ s₁ ∪ s₁).sum f : (sum_union (sdiff_inter_self _ _)).symm
... = s₂.sum f : by rw [sdiff_union_of_subset h]
lemma sum_eq_zero_iff_of_nonneg : (∀x∈s, 0 ≤ f x) → (s.sum f = 0 ↔ ∀x∈s, f x = 0) :=
finset.induction_on s (λ _, ⟨λ _ _, false.elim, λ _, rfl⟩) $ λ a s ha ih H,
have ∀ x ∈ s, 0 ≤ f x, from λ _, H _ ∘ mem_insert_of_mem,
by rw [sum_insert ha,
add_eq_zero_iff' (H _ $ mem_insert_self _ _) (zero_le_sum' this),
forall_mem_insert, ih this]
lemma single_le_sum (hf : ∀x∈s, 0 ≤ f x) {a} (h : a ∈ s) : f a ≤ s.sum f :=
have (singleton a).sum f ≤ s.sum f,
from sum_le_sum_of_subset_of_nonneg
(λ x e, (mem_singleton.1 e).symm ▸ h) (λ x h _, hf x h),
by rwa sum_singleton at this
end ordered_comm_monoid
section canonically_ordered_monoid
variables [decidable_eq α] [canonically_ordered_monoid β] [@decidable_rel β (≤)]
lemma sum_le_sum_of_subset (h : s₁ ⊆ s₂) : s₁.sum f ≤ s₂.sum f :=
sum_le_sum_of_subset_of_nonneg h $ assume x h₁ h₂, zero_le _
lemma sum_le_sum_of_ne_zero (h : ∀x∈s₁, f x ≠ 0 → x ∈ s₂) : s₁.sum f ≤ s₂.sum f :=
calc s₁.sum f = (s₁.filter (λx, f x = 0)).sum f + (s₁.filter (λx, f x ≠ 0)).sum f :
by rw [←sum_union, filter_union_filter_neg_eq]; apply filter_inter_filter_neg_eq
... ≤ s₂.sum f : add_le_of_nonpos_of_le'
(sum_le_zero' $ by simp only [mem_filter, and_imp]; exact λ _ _, le_of_eq)
(sum_le_sum_of_subset $ by simpa only [subset_iff, mem_filter, and_imp])
end canonically_ordered_monoid
section discrete_linear_ordered_field
variables [discrete_linear_ordered_field α] [decidable_eq β]
lemma abs_sum_le_sum_abs {f : β → α} {s : finset β} : abs (s.sum f) ≤ s.sum (λa, abs (f a)) :=
finset.induction_on s (le_of_eq abs_zero) $
assume a s has ih,
calc abs (sum (insert a s) f) ≤ abs (f a) + abs (sum s f) :
by rw sum_insert has; exact abs_add_le_abs_add_abs _ _
... ≤ abs (f a) + s.sum (λa, abs (f a)) : add_le_add (le_refl _) ih
... ≤ sum (insert a s) (λ (a : β), abs (f a)) : by rw sum_insert has
end discrete_linear_ordered_field
@[simp] lemma card_pi [decidable_eq α] {δ : α → Type*}
(s : finset α) (t : Π a, finset (δ a)) :
(s.pi t).card = s.prod (λ a, card (t a)) :=
multiset.card_pi _ _
@[simp] lemma prod_range_id_eq_fact (n : ℕ) : ((range n.succ).erase 0).prod (λ x, x) = nat.fact n :=
calc ((range n.succ).erase 0).prod (λ x, x) = (range n).prod nat.succ :
eq.symm (prod_bij (λ x _, nat.succ x)
(λ a h₁, mem_erase.2 ⟨nat.succ_ne_zero _, mem_range.2 $ nat.succ_lt_succ $ by simpa using h₁⟩)
(by simp) (λ _ _ _ _, nat.succ_inj)
(λ b h,
have b.pred.succ = b, from nat.succ_pred_eq_of_pos $
by simp [nat.pos_iff_ne_zero] at *; tauto,
⟨nat.pred b, mem_range.2 $ nat.lt_of_succ_lt_succ (by simp [*] at *), this.symm⟩))
... = nat.fact n : by induction n; simp [*, range_succ]
end finset
section group
open list
variables [group α] [group β]
@[to_additive is_add_group_hom.sum]
theorem is_group_hom.prod (f : α → β) [is_group_hom f] (l : list α) :
f (prod l) = prod (map f l) :=
by induction l; simp only [*, is_group_hom.mul f, is_group_hom.one f, prod_nil, prod_cons, map]
theorem is_group_anti_hom.prod (f : α → β) [is_group_anti_hom f] (l : list α) :
f (prod l) = prod (map f (reverse l)) :=
by induction l with hd tl ih; [exact is_group_anti_hom.one f,
simp only [prod_cons, is_group_anti_hom.mul f, ih, reverse_cons, map_append, prod_append, map_singleton, prod_cons, prod_nil, mul_one]]
theorem inv_prod : ∀ l : list α, (prod l)⁻¹ = prod (map (λ x, x⁻¹) (reverse l)) :=
λ l, @is_group_anti_hom.prod _ _ _ _ _ inv_is_group_anti_hom l -- TODO there is probably a cleaner proof of this
end group
section comm_group
variables [comm_group α] [comm_group β] (f : α → β) [is_group_hom f]
@[to_additive is_add_group_hom.multiset_sum]
lemma is_group_hom.multiset_prod (m : multiset α) : f m.prod = (m.map f).prod :=
quotient.induction_on m $ assume l, by simp [is_group_hom.prod f l]
@[to_additive is_add_group_hom.finset_sum]
lemma is_group_hom.finset_prod (g : γ → α) (s : finset γ) : f (s.prod g) = s.prod (f ∘ g) :=
show f (s.val.map g).prod = (s.val.map (f ∘ g)).prod, by rw [is_group_hom.multiset_prod f]; simp
end comm_group
@[to_additive is_add_group_hom_finset_sum]
lemma is_group_hom_finset_prod {α β γ} [group α] [comm_group β] (s : finset γ)
(f : γ → α → β) [∀c, is_group_hom (f c)] : is_group_hom (λa, s.prod (λc, f c a)) :=
⟨assume a b, by simp only [λc, is_group_hom.mul (f c), finset.prod_mul_distrib]⟩
attribute [instance] is_group_hom_finset_prod is_add_group_hom_finset_sum
namespace multiset
variables [decidable_eq α]
@[simp] lemma to_finset_sum_count_eq (s : multiset α) :
s.to_finset.sum (λa, s.count a) = s.card :=
multiset.induction_on s rfl
(assume a s ih,
calc (to_finset (a :: s)).sum (λx, count x (a :: s)) =
(to_finset (a :: s)).sum (λx, (if x = a then 1 else 0) + count x s) :
finset.sum_congr rfl $ λ _ _, by split_ifs;
[simp only [h, count_cons_self, nat.one_add], simp only [count_cons_of_ne h, zero_add]]
... = card (a :: s) :
begin
by_cases a ∈ s.to_finset,
{ have : (to_finset s).sum (λx, ite (x = a) 1 0) = (finset.singleton a).sum (λx, ite (x = a) 1 0),
{ apply (finset.sum_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ exact λ _ _ H, if_neg (mt finset.mem_singleton.2 H) } },
rw [to_finset_cons, finset.insert_eq_of_mem h, finset.sum_add_distrib, ih, this, finset.sum_singleton, if_pos rfl, add_comm, card_cons] },
{ have ha : a ∉ s, by rwa mem_to_finset at h,
have : (to_finset s).sum (λx, ite (x = a) 1 0) = (to_finset s).sum (λx, 0), from
finset.sum_congr rfl (λ x hx, if_neg $ by rintro rfl; cc),
rw [to_finset_cons, finset.sum_insert h, if_pos rfl, finset.sum_add_distrib, this, finset.sum_const_zero, ih, count_eq_zero_of_not_mem ha, zero_add, add_comm, card_cons] }
end)
end multiset
|
2835c5ccb6050dea8c0b1b5bb7221aa724beb229 | 5ae26df177f810c5006841e9c73dc56e01b978d7 | /src/topology/algebra/ring.lean | bea1706bcd2d54a675a3ee42d358e06dd9f25088 | [
"Apache-2.0"
] | permissive | ChrisHughes24/mathlib | 98322577c460bc6b1fe5c21f42ce33ad1c3e5558 | a2a867e827c2a6702beb9efc2b9282bd801d5f9a | refs/heads/master | 1,583,848,251,477 | 1,565,164,247,000 | 1,565,164,247,000 | 129,409,993 | 0 | 1 | Apache-2.0 | 1,565,164,817,000 | 1,523,628,059,000 | Lean | UTF-8 | Lean | false | false | 3,754 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
Theory of topological rings.
-/
import topology.algebra.group ring_theory.ideals
open classical set lattice filter topological_space
local attribute [instance] classical.prop_decidable
section topological_ring
universes u v w
variables (α : Type u) [topological_space α]
/-- A topological semiring is a semiring where addition and multiplication are continuous. -/
class topological_semiring [semiring α]
extends topological_add_monoid α, topological_monoid α : Prop
variables [ring α]
/-- A topological ring is a ring where the ring operations are continuous. -/
class topological_ring extends topological_add_monoid α, topological_monoid α : Prop :=
(continuous_neg : continuous (λa:α, -a))
variables [t : topological_ring α]
instance topological_ring.to_topological_semiring : topological_semiring α := {..t}
instance topological_ring.to_topological_add_group : topological_add_group α := {..t}
end topological_ring
section topological_comm_ring
variables {α : Type*} [topological_space α] [comm_ring α] [topological_ring α]
def ideal.closure (S : ideal α) : ideal α :=
{ carrier := closure S,
zero := subset_closure S.zero_mem,
add := assume x y hx hy,
mem_closure2 continuous_add' hx hy $ assume a b, S.add_mem,
smul := assume c x hx,
have continuous (λx:α, c * x) := continuous_mul continuous_const continuous_id,
mem_closure this hx $ assume a, S.mul_mem_left }
@[simp] lemma ideal.coe_closure (S : ideal α) :
(S.closure : set α) = closure S := rfl
end topological_comm_ring
section topological_ring
variables {α : Type*} [topological_space α] [comm_ring α] [topological_ring α] (N : ideal α)
open ideal.quotient
instance topological_ring_quotient_topology : topological_space N.quotient :=
by dunfold ideal.quotient submodule.quotient; apply_instance
lemma quotient_ring_saturate (s : set α) :
mk N ⁻¹' (mk N '' s) = (⋃ x : N, (λ y, x.1 + y) '' s) :=
begin
ext x,
simp only [mem_preimage, mem_image, mem_Union, ideal.quotient.eq],
split,
{ exact assume ⟨a, a_in, h⟩, ⟨⟨_, N.neg_mem h⟩, a, a_in, by simp⟩ },
{ exact assume ⟨⟨i, hi⟩, a, ha, eq⟩, ⟨a, ha,
by rw [← eq, sub_add_eq_sub_sub_swap, sub_self, zero_sub];
exact N.neg_mem hi⟩ }
end
lemma quotient_ring.is_open_map_coe : is_open_map (mk N) :=
begin
assume s s_op,
show is_open (mk N ⁻¹' (mk N '' s)),
rw quotient_ring_saturate N s,
exact is_open_Union (assume ⟨n, _⟩, is_open_map_add_left n s s_op)
end
lemma quotient_ring.quotient_map_coe_coe : quotient_map (λ p : α × α, (mk N p.1, mk N p.2)) :=
begin
apply is_open_map.to_quotient_map,
{ exact is_open_map.prod (quotient_ring.is_open_map_coe N) (quotient_ring.is_open_map_coe N) },
{ apply continuous.prod_mk,
{ exact continuous_quot_mk.comp continuous_fst },
{ exact continuous_quot_mk.comp continuous_snd } },
{ rintro ⟨⟨x⟩, ⟨y⟩⟩,
exact ⟨(x, y), rfl⟩ }
end
instance topological_ring_quotient : topological_ring N.quotient :=
{ continuous_add :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst + p.snd)) :=
continuous_quot_mk.comp continuous_add',
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont,
continuous_neg := continuous_quotient_lift _ (continuous_quot_mk.comp continuous_neg'),
continuous_mul :=
have cont : continuous (mk N ∘ (λ (p : α × α), p.fst * p.snd)) :=
continuous_quot_mk.comp continuous_mul',
(quotient_map.continuous_iff (quotient_ring.quotient_map_coe_coe N)).2 cont }
end topological_ring
|
f57365b0e49c94c39c095849a85dbd2e62d48e13 | ebf7140a9ea507409ff4c994124fa36e79b4ae35 | /src/hints/category_theory/exercise4/hint1.lean | 8ffec18dd101d95344c47770e8c6abb1a9a5010f | [] | no_license | fundou/lftcm2020 | 3e88d58a92755ea5dd49f19c36239c35286ecf5e | 99d11bf3bcd71ffeaef0250caa08ecc46e69b55b | refs/heads/master | 1,685,610,799,304 | 1,624,070,416,000 | 1,624,070,416,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 472 | lean | import algebra.category.CommRing
import category_theory.yoneda
import data.polynomial.algebra_map
noncomputable theory
open category_theory
open opposite
/-!
We need to provide a commutative ring, and then an isomorphism between two functors.
-/
def CommRing_forget_representable : Σ (R : CommRing), (forget CommRing) ≅ coyoneda.obj (op R) :=
⟨CommRing.of (polynomial ℤ),
{ hom := sorry,
inv := sorry,
hom_inv_id' := sorry,
inv_hom_id' := sorry, }⟩
|
b2ffaca17da50305e81eacc21c0f98f678d6dc0e | ae1e94c332e17c7dc7051ce976d5a9eebe7ab8a5 | /tests/lean/run/new_compiler.lean | 0fa118a081d3d1b1c344450999ae2c8367307256 | [
"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 | 1,742 | lean |
universes u v w r s
set_option trace.compiler.stage1 true
-- setOption pp.implicit True
set_option pp.binder_types false
set_option pp.proofs true
def foo (n : Nat) : Nat :=
let x := Nat.zero;
let x1 := Nat.succ x;
let x2 := Nat.succ x1;
let x3 := Nat.succ x2;
let x4 := Nat.succ x3;
let x5 := Nat.succ x4;
let x6 := Nat.succ x5;
let x7 := Nat.succ x ;
let x8 := Nat.succ x7;
let y1 := x;
let y2 := y1;
y2 + n
def cseTst (n : Nat) : Nat :=
let y := Nat.succ ((fun x => x) n);
let z := Nat.succ n;
y + z
def tst1 (n : Nat) : Nat :=
let p := (Nat.succ n, n);
let q := (p, p);
match q with
| ((z, w), y) => z
def tst2 (n : Nat) : Nat :=
let p := (fun x => Nat.succ x, Nat.zero) ;
let f := fun (p : (Nat → Nat) × Nat) => p.1;
f p n
partial def add' : Nat → Nat → Nat
| 0, b => Nat.succ b
| a+1, b => Nat.succ (Nat.succ (add' a b))
def aux (i : Nat) (h : i > 0) :=
i
axiom bad (α : Sort u) : α
unsafe def foo2 : Nat :=
@False.rec (fun _ => Nat) (bad _)
set_option pp.notation false
def foo3 (n : Nat) : Nat :=
(fun (a : Nat) => a + a + a) (n*n)
def boo (a : Nat) (l : List Nat) : List Nat :=
let f := @List.cons Nat;
f a (f a l)
def bla (i : Nat) (h : i > 0 ∧ i ≠ 10) : Nat :=
@And.rec _ _ (fun _ => Nat) (fun h₁ h₂ => aux i h₁ + aux i h₁) h
def bla' (i : Nat) (h : i > 0 ∧ i ≠ 10) : Nat :=
@And.casesOn _ _ (fun _ => Nat) h (fun h₁ h₂ => aux i h₁ + aux i h₁)
inductive vec (α : Type u) : Nat → Type u
| nil : vec α 0
| cons : ∀ {n}, α → vec α n → vec α (Nat.succ n)
/-
def vec.map {α β σ : Type u} (f : α → β → σ) : ∀ {n : Nat}, vec α n → vec β n → vec σ n
| _, nil, nil => nil
| _, cons a as, cons b bs => cons (f a b) (map f as bs)
-/
|
abedd6983cfa7e23e01f35c4c496bb8af01a2d30 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/model_theory/elementary_maps.lean | 4d014c5ae8aa85f03608b6827d9a8804ee933f23 | [
"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 | 15,016 | lean | /-
Copyright (c) 2022 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import data.fintype.basic
import model_theory.substructures
/-!
# Elementary Maps Between First-Order Structures
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
## Main Definitions
* A `first_order.language.elementary_embedding` is an embedding that commutes with the
realizations of formulas.
* A `first_order.language.elementary_substructure` is a substructure where the realization of each
formula agrees with the realization in the larger model.
* The `first_order.language.elementary_diagram` of a structure is the set of all sentences with
parameters that the structure satisfies.
* `first_order.language.elementary_embedding.of_models_elementary_diagram` is the canonical
elementary embedding of any structure into a model of its elementary diagram.
## Main Results
* The Tarski-Vaught Test for embeddings: `first_order.language.embedding.is_elementary_of_exists`
gives a simple criterion for an embedding to be elementary.
* The Tarski-Vaught Test for substructures: `first_order.language.embedding.is_elementary_of_exists`
gives a simple criterion for a substructure to be elementary.
-/
open_locale first_order
namespace first_order
namespace language
open Structure
variables (L : language) (M : Type*) (N : Type*) {P : Type*} {Q : Type*}
variables [L.Structure M] [L.Structure N] [L.Structure P] [L.Structure Q]
/-- An elementary embedding of first-order structures is an embedding that commutes with the
realizations of formulas. -/
structure elementary_embedding :=
(to_fun : M → N)
(map_formula' : ∀ {{n}} (φ : L.formula (fin n)) (x : fin n → M),
φ.realize (to_fun ∘ x) ↔ φ.realize x . obviously)
localized "notation (name := elementary_embedding)
A ` ↪ₑ[`:25 L `] ` B := first_order.language.elementary_embedding L A B" in first_order
variables {L} {M} {N}
namespace elementary_embedding
instance fun_like : fun_like (M ↪ₑ[L] N) M (λ _, N) :=
{ coe := λ f, f.to_fun,
coe_injective' := λ f g h, begin
cases f,
cases g,
simp only,
ext x,
exact function.funext_iff.1 h x end }
instance : has_coe_to_fun (M ↪ₑ[L] N) (λ _, M → N) := fun_like.has_coe_to_fun
@[simp] lemma map_bounded_formula (f : M ↪ₑ[L] N) {α : Type*} {n : ℕ}
(φ : L.bounded_formula α n) (v : α → M) (xs : fin n → M) :
φ.realize (f ∘ v) (f ∘ xs) ↔ φ.realize v xs :=
begin
classical,
rw [← bounded_formula.realize_restrict_free_var set.subset.rfl, set.inclusion_eq_id, iff_eq_eq],
swap, { apply_instance },
have h := f.map_formula' ((φ.restrict_free_var id).to_formula.relabel (fintype.equiv_fin _))
((sum.elim (v ∘ coe) xs) ∘ (fintype.equiv_fin _).symm),
simp only [formula.realize_relabel, bounded_formula.realize_to_formula, iff_eq_eq] at h,
rw [← function.comp.assoc _ _ ((fintype.equiv_fin _).symm),
function.comp.assoc _ ((fintype.equiv_fin _).symm) (fintype.equiv_fin _),
equiv.symm_comp_self, function.comp.right_id, function.comp.assoc, sum.elim_comp_inl,
function.comp.assoc _ _ sum.inr, sum.elim_comp_inr,
← function.comp.assoc] at h,
refine h.trans _,
rw [function.comp.assoc _ _ (fintype.equiv_fin _), equiv.symm_comp_self,
function.comp.right_id, sum.elim_comp_inl, sum.elim_comp_inr, ← set.inclusion_eq_id,
bounded_formula.realize_restrict_free_var set.subset.rfl],
end
@[simp] lemma map_formula (f : M ↪ₑ[L] N) {α : Type*} (φ : L.formula α) (x : α → M) :
φ.realize (f ∘ x) ↔ φ.realize x :=
by rw [formula.realize, formula.realize, ← f.map_bounded_formula, unique.eq_default (f ∘ default)]
lemma map_sentence (f : M ↪ₑ[L] N) (φ : L.sentence) :
M ⊨ φ ↔ N ⊨ φ :=
by rw [sentence.realize, sentence.realize, ← f.map_formula, unique.eq_default (f ∘ default)]
lemma Theory_model_iff (f : M ↪ₑ[L] N) (T : L.Theory) :
M ⊨ T ↔ N ⊨ T :=
by simp only [Theory.model_iff, f.map_sentence]
lemma elementarily_equivalent (f : M ↪ₑ[L] N) : M ≅[L] N :=
elementarily_equivalent_iff.2 f.map_sentence
@[simp] lemma injective (φ : M ↪ₑ[L] N) :
function.injective φ :=
begin
intros x y,
have h := φ.map_formula ((var 0).equal (var 1) : L.formula (fin 2)) (λ i, if i = 0 then x else y),
rw [formula.realize_equal, formula.realize_equal] at h,
simp only [nat.one_ne_zero, term.realize, fin.one_eq_zero_iff, if_true, eq_self_iff_true,
function.comp_app, if_false] at h,
exact h.1,
end
instance embedding_like : embedding_like (M ↪ₑ[L] N) M N :=
{ injective' := injective,
.. show fun_like (M ↪ₑ[L] N) M (λ _, N), from infer_instance }
@[simp] lemma map_fun (φ : M ↪ₑ[L] N) {n : ℕ} (f : L.functions n) (x : fin n → M) :
φ (fun_map f x) = fun_map f (φ ∘ x) :=
begin
have h := φ.map_formula (formula.graph f) (fin.cons (fun_map f x) x),
rw [formula.realize_graph, fin.comp_cons, formula.realize_graph] at h,
rw [eq_comm, h]
end
@[simp] lemma map_rel (φ : M ↪ₑ[L] N) {n : ℕ} (r : L.relations n) (x : fin n → M) :
rel_map r (φ ∘ x) ↔ rel_map r x :=
begin
have h := φ.map_formula (r.formula var) x,
exact h
end
instance strong_hom_class : strong_hom_class L (M ↪ₑ[L] N) M N :=
{ map_fun := map_fun,
map_rel := map_rel }
@[simp] lemma map_constants (φ : M ↪ₑ[L] N) (c : L.constants) : φ c = c :=
hom_class.map_constants φ c
/-- An elementary embedding is also a first-order embedding. -/
def to_embedding (f : M ↪ₑ[L] N) : M ↪[L] N :=
{ to_fun := f,
inj' := f.injective, }
/-- An elementary embedding is also a first-order homomorphism. -/
def to_hom (f : M ↪ₑ[L] N) : M →[L] N :=
{ to_fun := f }
@[simp] lemma to_embedding_to_hom (f : M ↪ₑ[L] N) : f.to_embedding.to_hom = f.to_hom := rfl
@[simp]
lemma coe_to_hom {f : M ↪ₑ[L] N} : (f.to_hom : M → N) = (f : M → N) := rfl
@[simp] lemma coe_to_embedding (f : M ↪ₑ[L] N) : (f.to_embedding : M → N) = (f : M → N) := rfl
lemma coe_injective : @function.injective (M ↪ₑ[L] N) (M → N) coe_fn :=
fun_like.coe_injective
@[ext]
lemma ext ⦃f g : M ↪ₑ[L] N⦄ (h : ∀ x, f x = g x) : f = g :=
fun_like.ext f g h
lemma ext_iff {f g : M ↪ₑ[L] N} : f = g ↔ ∀ x, f x = g x :=
fun_like.ext_iff
variables (L) (M)
/-- The identity elementary embedding from a structure to itself -/
@[refl] def refl : M ↪ₑ[L] M :=
{ to_fun := id }
variables {L} {M}
instance : inhabited (M ↪ₑ[L] M) := ⟨refl L M⟩
@[simp] lemma refl_apply (x : M) :
refl L M x = x := rfl
/-- Composition of elementary embeddings -/
@[trans] def comp (hnp : N ↪ₑ[L] P) (hmn : M ↪ₑ[L] N) : M ↪ₑ[L] P :=
{ to_fun := hnp ∘ hmn }
@[simp] lemma comp_apply (g : N ↪ₑ[L] P) (f : M ↪ₑ[L] N) (x : M) :
g.comp f x = g (f x) := rfl
/-- Composition of elementary embeddings is associative. -/
lemma comp_assoc (f : M ↪ₑ[L] N) (g : N ↪ₑ[L] P) (h : P ↪ₑ[L] Q) :
(h.comp g).comp f = h.comp (g.comp f) := rfl
end elementary_embedding
variables (L) (M)
/-- The elementary diagram of an `L`-structure is the set of all sentences with parameters it
satisfies. -/
abbreviation elementary_diagram : L[[M]].Theory := L[[M]].complete_theory M
/-- The canonical elementary embedding of an `L`-structure into any model of its elementary diagram
-/
@[simps] def elementary_embedding.of_models_elementary_diagram
(N : Type*) [L.Structure N] [L[[M]].Structure N]
[(Lhom_with_constants L M).is_expansion_on N] [N ⊨ L.elementary_diagram M] :
M ↪ₑ[L] N :=
⟨(coe : L[[M]].constants → N) ∘ sum.inr, λ n φ x, begin
refine trans _ ((realize_iff_of_model_complete_theory M N (((L.Lhom_with_constants
M).on_bounded_formula φ).subst (constants.term ∘ sum.inr ∘ x)).alls).trans _),
{ simp_rw [sentence.realize, bounded_formula.realize_alls, bounded_formula.realize_subst,
Lhom.realize_on_bounded_formula, formula.realize, unique.forall_iff, realize_constants] },
{ simp_rw [sentence.realize, bounded_formula.realize_alls, bounded_formula.realize_subst,
Lhom.realize_on_bounded_formula, formula.realize, unique.forall_iff],
refl }
end⟩
variables {L M}
namespace embedding
/-- The Tarski-Vaught test for elementarity of an embedding. -/
theorem is_elementary_of_exists (f : M ↪[L] N)
(htv : ∀ (n : ℕ) (φ : L.bounded_formula empty (n + 1)) (x : fin n → M) (a : N),
φ.realize default (fin.snoc (f ∘ x) a : _ → N) →
∃ b : M, φ.realize default (fin.snoc (f ∘ x) (f b) : _ → N)) :
∀{n} (φ : L.formula (fin n)) (x : fin n → M), φ.realize (f ∘ x) ↔ φ.realize x :=
begin
suffices h : ∀ (n : ℕ) (φ : L.bounded_formula empty n) (xs : fin n → M),
φ.realize (f ∘ default) (f ∘ xs) ↔ φ.realize default xs,
{ intros n φ x,
refine φ.realize_relabel_sum_inr.symm.trans (trans (h n _ _) φ.realize_relabel_sum_inr), },
refine λ n φ, φ.rec_on _ _ _ _ _,
{ exact λ _ _, iff.rfl },
{ intros,
simp [bounded_formula.realize, ← sum.comp_elim, embedding.realize_term] },
{ intros,
simp [bounded_formula.realize, ← sum.comp_elim, embedding.realize_term] },
{ intros _ _ _ ih1 ih2 _,
simp [ih1, ih2] },
{ intros n φ ih xs,
simp only [bounded_formula.realize_all],
refine ⟨λ h a, _, _⟩,
{ rw [← ih, fin.comp_snoc],
exact h (f a) },
{ contrapose!,
rintro ⟨a, ha⟩,
obtain ⟨b, hb⟩ := htv n φ.not xs a _,
{ refine ⟨b, λ h, hb (eq.mp _ ((ih _).2 h))⟩,
rw [unique.eq_default (f ∘ default), fin.comp_snoc], },
{ rw [bounded_formula.realize_not, ← unique.eq_default (f ∘ default)],
exact ha } } },
end
/-- Bundles an embedding satisfying the Tarski-Vaught test as an elementary embedding. -/
@[simps] def to_elementary_embedding (f : M ↪[L] N)
(htv : ∀ (n : ℕ) (φ : L.bounded_formula empty (n + 1)) (x : fin n → M) (a : N),
φ.realize default (fin.snoc (f ∘ x) a : _ → N) →
∃ b : M, φ.realize default (fin.snoc (f ∘ x) (f b) : _ → N)) :
M ↪ₑ[L] N :=
⟨f, λ _, f.is_elementary_of_exists htv⟩
end embedding
namespace equiv
/-- A first-order equivalence is also an elementary embedding. -/
def to_elementary_embedding (f : M ≃[L] N) : M ↪ₑ[L] N :=
{ to_fun := f }
@[simp] lemma to_elementary_embedding_to_embedding (f : M ≃[L] N) :
f.to_elementary_embedding.to_embedding = f.to_embedding := rfl
@[simp] lemma coe_to_elementary_embedding (f : M ≃[L] N) :
(f.to_elementary_embedding : M → N) = (f : M → N) := rfl
end equiv
@[simp] lemma realize_term_substructure {α : Type*} {S : L.substructure M} (v : α → S)
(t : L.term α) :
t.realize (coe ∘ v) = (↑(t.realize v) : M) :=
S.subtype.realize_term t
namespace substructure
@[simp] lemma realize_bounded_formula_top {α : Type*} {n : ℕ} {φ : L.bounded_formula α n}
{v : α → (⊤ : L.substructure M)} {xs : fin n → (⊤ : L.substructure M)} :
φ.realize v xs ↔ φ.realize ((coe : _ → M) ∘ v) (coe ∘ xs) :=
begin
rw ← substructure.top_equiv.realize_bounded_formula φ,
simp,
end
@[simp] lemma realize_formula_top {α : Type*} {φ : L.formula α} {v : α → (⊤ : L.substructure M)} :
φ.realize v ↔ φ.realize ((coe : (⊤ : L.substructure M) → M) ∘ v) :=
begin
rw ← substructure.top_equiv.realize_formula φ,
simp,
end
/-- A substructure is elementary when every formula applied to a tuple in the subtructure
agrees with its value in the overall structure. -/
def is_elementary (S : L.substructure M) : Prop :=
∀ {{n}} (φ : L.formula (fin n)) (x : fin n → S), φ.realize ((coe : _ → M) ∘ x) ↔ φ.realize x
end substructure
variables (L M)
/-- An elementary substructure is one in which every formula applied to a tuple in the subtructure
agrees with its value in the overall structure. -/
structure elementary_substructure :=
(to_substructure : L.substructure M)
(is_elementary' : to_substructure.is_elementary)
variables {L M}
namespace elementary_substructure
instance : has_coe (L.elementary_substructure M) (L.substructure M) :=
⟨elementary_substructure.to_substructure⟩
instance : set_like (L.elementary_substructure M) M :=
⟨λ x, x.to_substructure.carrier, λ ⟨⟨s, hs1⟩, hs2⟩ ⟨⟨t, ht1⟩, ht2⟩ h, begin
congr,
exact h,
end⟩
instance induced_Structure (S : L.elementary_substructure M) : L.Structure S :=
substructure.induced_Structure
@[simp] lemma is_elementary (S : L.elementary_substructure M) :
(S : L.substructure M).is_elementary := S.is_elementary'
/-- The natural embedding of an `L.substructure` of `M` into `M`. -/
def subtype (S : L.elementary_substructure M) : S ↪ₑ[L] M :=
{ to_fun := coe,
map_formula' := S.is_elementary }
@[simp] theorem coe_subtype {S : L.elementary_substructure M} : ⇑S.subtype = coe := rfl
/-- The substructure `M` of the structure `M` is elementary. -/
instance : has_top (L.elementary_substructure M) :=
⟨⟨⊤, λ n φ x, substructure.realize_formula_top.symm⟩⟩
instance : inhabited (L.elementary_substructure M) := ⟨⊤⟩
@[simp] lemma mem_top (x : M) : x ∈ (⊤ : L.elementary_substructure M) := set.mem_univ x
@[simp] lemma coe_top : ((⊤ : L.elementary_substructure M) : set M) = set.univ := rfl
@[simp] lemma realize_sentence (S : L.elementary_substructure M) (φ : L.sentence) :
S ⊨ φ ↔ M ⊨ φ :=
S.subtype.map_sentence φ
@[simp] lemma Theory_model_iff (S : L.elementary_substructure M) (T : L.Theory) :
S ⊨ T ↔ M ⊨ T :=
by simp only [Theory.model_iff, realize_sentence]
instance Theory_model {T : L.Theory} [h : M ⊨ T] {S : L.elementary_substructure M} : S ⊨ T :=
(Theory_model_iff S T).2 h
instance [h : nonempty M] {S : L.elementary_substructure M} : nonempty S :=
(model_nonempty_theory_iff L).1 infer_instance
lemma elementarily_equivalent (S : L.elementary_substructure M) : S ≅[L] M :=
S.subtype.elementarily_equivalent
end elementary_substructure
namespace substructure
/-- The Tarski-Vaught test for elementarity of a substructure. -/
theorem is_elementary_of_exists (S : L.substructure M)
(htv : ∀ (n : ℕ) (φ : L.bounded_formula empty (n + 1)) (x : fin n → S) (a : M),
φ.realize default (fin.snoc (coe ∘ x) a : _ → M) →
∃ b : S, φ.realize default (fin.snoc (coe ∘ x) b : _ → M)) :
S.is_elementary :=
λ n, S.subtype.is_elementary_of_exists htv
/-- Bundles a substructure satisfying the Tarski-Vaught test as an elementary substructure. -/
@[simps] def to_elementary_substructure (S : L.substructure M)
(htv : ∀ (n : ℕ) (φ : L.bounded_formula empty (n + 1)) (x : fin n → S) (a : M),
φ.realize default (fin.snoc (coe ∘ x) a : _ → M) →
∃ b : S, φ.realize default (fin.snoc (coe ∘ x) b : _ → M)) :
L.elementary_substructure M :=
⟨S, S.is_elementary_of_exists htv⟩
end substructure
end language
end first_order
|
04b13460fb780cb55a9786148383183ed3ed7386 | 618003631150032a5676f229d13a079ac875ff77 | /src/category_theory/functor.lean | 426b1981a5b06cca3a796a36d5571fee26751ec2 | [
"Apache-2.0"
] | permissive | awainverse/mathlib | 939b68c8486df66cfda64d327ad3d9165248c777 | ea76bd8f3ca0a8bf0a166a06a475b10663dec44a | refs/heads/master | 1,659,592,962,036 | 1,590,987,592,000 | 1,590,987,592,000 | 268,436,019 | 1 | 0 | Apache-2.0 | 1,590,990,500,000 | 1,590,990,500,000 | null | UTF-8 | Lean | false | false | 3,392 | lean | /-
Copyright (c) 2017 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Tim Baumann, Stephen Morgan, Scott Morrison
Defines a functor between categories.
(As it is a 'bundled' object rather than the `is_functorial` typeclass parametrised
by the underlying function on objects, the name is capitalised.)
Introduces notations
`C ⥤ D` for the type of all functors from `C` to `D`.
(I would like a better arrow here, unfortunately ⇒ (`\functor`) is taken by core.)
-/
import category_theory.category
import tactic.reassoc_axiom
namespace category_theory
universes v v₁ v₂ v₃ u u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
/--
`functor C D` represents a functor between categories `C` and `D`.
To apply a functor `F` to an object use `F.obj X`, and to a morphism use `F.map f`.
The axiom `map_id` expresses preservation of identities, and
`map_comp` expresses functoriality.
-/
structure functor (C : Type u₁) [category.{v₁} C] (D : Type u₂) [category.{v₂} D] :
Type (max v₁ v₂ u₁ u₂) :=
(obj [] : C → D)
(map : Π {X Y : C}, (X ⟶ Y) → ((obj X) ⟶ (obj Y)))
(map_id' : ∀ (X : C), map (𝟙 X) = 𝟙 (obj X) . obviously)
(map_comp' : ∀ {X Y Z : C} (f : X ⟶ Y) (g : Y ⟶ Z), map (f ≫ g) = (map f) ≫ (map g) . obviously)
-- A functor is basically a function, so give ⥤ a similar precedence to → (25).
-- For example, `C × D ⥤ E` should parse as `(C × D) ⥤ E` not `C × (D ⥤ E)`.
infixr ` ⥤ `:26 := functor -- type as \func --
restate_axiom functor.map_id'
attribute [simp] functor.map_id
restate_axiom functor.map_comp'
attribute [reassoc, simp] functor.map_comp
namespace functor
section
variables (C : Type u₁) [category.{v₁} C]
/-- `𝟭 C` is the identity functor on a category `C`. -/
protected def id : C ⥤ C :=
{ obj := λ X, X,
map := λ _ _ f, f }
notation `𝟭` := functor.id
variable {C}
@[simp] lemma id_obj (X : C) : (𝟭 C).obj X = X := rfl
@[simp] lemma id_map {X Y : C} (f : X ⟶ Y) : (𝟭 C).map f = f := rfl
end
section
variables {C : Type u₁} [category.{v₁} C]
{D : Type u₂} [category.{v₂} D]
{E : Type u₃} [category.{v₃} E]
/--
`F ⋙ G` is the composition of a functor `F` and a functor `G` (`F` first, then `G`).
-/
def comp (F : C ⥤ D) (G : D ⥤ E) : C ⥤ E :=
{ obj := λ X, G.obj (F.obj X),
map := λ _ _ f, G.map (F.map f) }
infixr ` ⋙ `:80 := comp
@[simp] lemma comp_obj (F : C ⥤ D) (G : D ⥤ E) (X : C) : (F ⋙ G).obj X = G.obj (F.obj X) := rfl
@[simp] lemma comp_map (F : C ⥤ D) (G : D ⥤ E) {X Y : C} (f : X ⟶ Y) :
(F ⋙ G).map f = G.map (F.map f) := rfl
-- These are not simp lemmas because rewriting along equalities between functors
-- is not necessarily a good idea.
-- Natural isomorphisms are also provided in `whiskering.lean`.
protected lemma comp_id (F : C ⥤ D) : F ⋙ (𝟭 D) = F := by cases F; refl
protected lemma id_comp (F : C ⥤ D) : (𝟭 C) ⋙ F = F := by cases F; refl
end
section
variables (C : Type u₁) [category.{v₁} C]
@[simp] def ulift_down : (ulift.{u₂} C) ⥤ C :=
{ obj := λ X, X.down,
map := λ X Y f, f }
@[simp] def ulift_up : C ⥤ (ulift.{u₂} C) :=
{ obj := λ X, ⟨ X ⟩,
map := λ X Y f, f }
end
end functor
end category_theory
|
32f143fdfbc0ebbc95a694e24e2d6296c43d81a4 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/analysis/asymptotics.lean | 9c292914aa80d98dede508e82a9d56b9b7ee3b55 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 46,755 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Yury Kudryashov
-/
import analysis.normed_space.basic
import topology.local_homeomorph
/-!
# Asymptotics
We introduce these relations:
* `is_O_with c f g l` : "f is big O of g along l with constant c";
* `is_O f g l` : "f is big O of g along l";
* `is_o f g l` : "f is little o of g along l".
Here `l` is any filter on the domain of `f` and `g`, which are assumed to be the same. The codomains
of `f` and `g` do not need to be the same; all that is needed that there is a norm associated with
these types, and it is the norm that is compared asymptotically.
The relation `is_O_with c` is introduced to factor out common algebraic arguments in the proofs of
similar properties of `is_O` and `is_o`. Usually proofs outside of this file should use `is_O`
instead.
Often the ranges of `f` and `g` will be the real numbers, in which case the norm is the absolute
value. In general, we have
`is_O f g l ↔ is_O (λ x, ∥f x∥) (λ x, ∥g x∥) l`,
and similarly for `is_o`. But our setup allows us to use the notions e.g. with functions
to the integers, rationals, complex numbers, or any normed vector space without mentioning the
norm explicitly.
If `f` and `g` are functions to a normed field like the reals or complex numbers and `g` is always
nonzero, we have
`is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0)`.
In fact, the right-to-left direction holds without the hypothesis on `g`, and in the other direction
it suffices to assume that `f` is zero wherever `g` is. (This generalization is useful in defining
the Fréchet derivative.)
-/
open filter set
open_locale topological_space big_operators classical
namespace asymptotics
variables {α : Type*} {β : Type*} {E : Type*} {F : Type*} {G : Type*}
{E' : Type*} {F' : Type*} {G' : Type*} {R : Type*} {R' : Type*} {𝕜 : Type*} {𝕜' : Type*}
variables [has_norm E] [has_norm F] [has_norm G] [normed_group E'] [normed_group F']
[normed_group G'] [normed_ring R] [normed_ring R'] [normed_field 𝕜] [normed_field 𝕜']
{c c' : ℝ} {f : α → E} {g : α → F} {k : α → G} {f' : α → E'} {g' : α → F'} {k' : α → G'}
{l l' : filter α}
section defs
/-! ### Definitions -/
/-- This version of the Landau notation `is_O_with C f g l` where `f` and `g` are two functions on
a type `α` and `l` is a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by `C * ∥g∥`.
In other words, `∥f∥ / ∥g∥` is eventually bounded by `C`, modulo division by zero issues that are
avoided by this definition. Probably you want to use `is_O` instead of this relation. -/
def is_O_with (c : ℝ) (f : α → E) (g : α → F) (l : filter α) : Prop :=
∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥
/-- Definition of `is_O_with`. We record it in a lemma as we will set `is_O_with` to be irreducible
at the end of this file. -/
lemma is_O_with_iff {c : ℝ} {f : α → E} {g : α → F} {l : filter α} :
is_O_with c f g l ↔ ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := iff.rfl
lemma is_O_with.of_bound {c : ℝ} {f : α → E} {g : α → F} {l : filter α}
(h : ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥) : is_O_with c f g l := h
/-- The Landau notation `is_O f g l` where `f` and `g` are two functions on a type `α` and `l` is
a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by a constant multiple of `∥g∥`.
In other words, `∥f∥ / ∥g∥` is eventually bounded, modulo division by zero issues that are avoided
by this definition. -/
def is_O (f : α → E) (g : α → F) (l : filter α) : Prop := ∃ c : ℝ, is_O_with c f g l
/-- Definition of `is_O` in terms of `is_O_with`. We record it in a lemma as we will set
`is_O` to be irreducible at the end of this file. -/
lemma is_O_iff_is_O_with {f : α → E} {g : α → F} {l : filter α} :
is_O f g l ↔ ∃ c : ℝ, is_O_with c f g l := iff.rfl
/-- Definition of `is_O` in terms of filters. We record it in a lemma as we will set
`is_O` to be irreducible at the end of this file. -/
lemma is_O_iff {f : α → E} {g : α → F} {l : filter α} :
is_O f g l ↔ ∃ c : ℝ, ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := iff.rfl
lemma is_O.of_bound (c : ℝ) {f : α → E} {g : α → F} {l : filter α}
(h : ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥) : is_O f g l := ⟨c, h⟩
/-- The Landau notation `is_o f g l` where `f` and `g` are two functions on a type `α` and `l` is
a filter on `α`, means that eventually for `l`, `∥f∥` is bounded by an arbitrarily small constant
multiple of `∥g∥`. In other words, `∥f∥ / ∥g∥` tends to `0` along `l`, modulo division by zero
issues that are avoided by this definition. -/
def is_o (f : α → E) (g : α → F) (l : filter α) : Prop := ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l
/-- Definition of `is_o` in terms of `is_O_with`. We record it in a lemma as we will set
`is_o` to be irreducible at the end of this file. -/
lemma is_o_iff_forall_is_O_with {f : α → E} {g : α → F} {l : filter α} :
is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → is_O_with c f g l := iff.rfl
/-- Definition of `is_o` in terms of filters. We record it in a lemma as we will set
`is_o` to be irreducible at the end of this file. -/
lemma is_o_iff {f : α → E} {g : α → F} {l : filter α} :
is_o f g l ↔ ∀ ⦃c : ℝ⦄, 0 < c → ∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ := iff.rfl
lemma is_o.def {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) :
∀ᶠ x in l, ∥ f x ∥ ≤ c * ∥ g x ∥ :=
h hc
lemma is_o.def' {f : α → E} {g : α → F} {l : filter α} (h : is_o f g l) {c : ℝ} (hc : 0 < c) :
is_O_with c f g l :=
h hc
end defs
/-! ### Conversions -/
theorem is_O_with.is_O (h : is_O_with c f g l) : is_O f g l := ⟨c, h⟩
theorem is_o.is_O_with (hgf : is_o f g l) : is_O_with 1 f g l := hgf zero_lt_one
theorem is_o.is_O (hgf : is_o f g l) : is_O f g l := hgf.is_O_with.is_O
theorem is_O_with.weaken (h : is_O_with c f g' l) (hc : c ≤ c') : is_O_with c' f g' l :=
mem_sets_of_superset h $ λ x hx,
calc ∥f x∥ ≤ c * ∥g' x∥ : hx
... ≤ _ : mul_le_mul_of_nonneg_right hc (norm_nonneg _)
theorem is_O_with.exists_pos (h : is_O_with c f g' l) :
∃ c' (H : 0 < c'), is_O_with c' f g' l :=
⟨max c 1, lt_of_lt_of_le zero_lt_one (le_max_right c 1), h.weaken $ le_max_left c 1⟩
theorem is_O.exists_pos (h : is_O f g' l) : ∃ c (H : 0 < c), is_O_with c f g' l :=
let ⟨c, hc⟩ := h in hc.exists_pos
theorem is_O_with.exists_nonneg (h : is_O_with c f g' l) :
∃ c' (H : 0 ≤ c'), is_O_with c' f g' l :=
let ⟨c, cpos, hc⟩ := h.exists_pos in ⟨c, le_of_lt cpos, hc⟩
theorem is_O.exists_nonneg (h : is_O f g' l) :
∃ c (H : 0 ≤ c), is_O_with c f g' l :=
let ⟨c, hc⟩ := h in hc.exists_nonneg
/-! ### Congruence -/
theorem is_O_with_congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_O_with c₁ f₁ g₁ l ↔ is_O_with c₂ f₂ g₂ l :=
begin
subst c₂,
apply filter.congr_sets,
filter_upwards [hf, hg],
assume x e₁ e₂,
dsimp at e₁ e₂ ⊢,
rw [e₁, e₂]
end
theorem is_O_with.congr' {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
(is_O_with_congr hc hf hg).mp
theorem is_O_with.congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
λ h, h.congr' hc (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O_with.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O_with c f₁ g l → is_O_with c f₂ g l :=
is_O_with.congr rfl hf (λ _, rfl)
theorem is_O_with.congr_right {g₁ g₂ : α → F} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c f g₁ l → is_O_with c f g₂ l :=
is_O_with.congr rfl (λ _, rfl) hg
theorem is_O_with.congr_const {c₁ c₂} {l : filter α} (hc : c₁ = c₂) :
is_O_with c₁ f g l → is_O_with c₂ f g l :=
is_O_with.congr hc (λ _, rfl) (λ _, rfl)
theorem is_O_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_O f₁ g₁ l ↔ is_O f₂ g₂ l :=
exists_congr $ λ c, is_O_with_congr rfl hf hg
theorem is_O.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
(is_O_congr hf hg).mp
theorem is_O.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O f₁ g l → is_O f₂ g l :=
is_O.congr hf (λ _, rfl)
theorem is_O.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O f g₁ l → is_O f g₂ l :=
is_O.congr (λ _, rfl) hg
theorem is_o_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_o f₁ g₁ l ↔ is_o f₂ g₂ l :=
ball_congr (λ c hc, is_O_with_congr (eq.refl c) hf hg)
theorem is_o.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : f₁ =ᶠ[l] f₂) (hg : g₁ =ᶠ[l] g₂) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
(is_o_congr hf hg).mp
theorem is_o.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_o.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_o f₁ g l → is_o f₂ g l :=
is_o.congr hf (λ _, rfl)
theorem is_o.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_o f g₁ l → is_o f g₂ l :=
is_o.congr (λ _, rfl) hg
/-! ### Filter operations and transitivity -/
theorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l)
{k : β → α} {l' : filter β} (hk : tendsto k l' l):
is_O_with c (f ∘ k) (g ∘ k) l' :=
hk hcfg
theorem is_O.comp_tendsto (hfg : is_O f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_O (f ∘ k) (g ∘ k) l' :=
hfg.imp (λ c h, h.comp_tendsto hk)
theorem is_o.comp_tendsto (hfg : is_o f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_o (f ∘ k) (g ∘ k) l' :=
λ c cpos, (hfg cpos).comp_tendsto hk
theorem is_O_with.mono (h : is_O_with c f g l') (hl : l ≤ l') : is_O_with c f g l :=
hl h
theorem is_O.mono (h : is_O f g l') (hl : l ≤ l') : is_O f g l :=
h.imp (λ c h, h.mono hl)
theorem is_o.mono (h : is_o f g l') (hl : l ≤ l') : is_o f g l :=
λ c cpos, (h cpos).mono hl
theorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 ≤ c) :
is_O_with (c * c') f k l :=
begin
filter_upwards [hfg, hgk],
assume x hx hx',
calc ∥f x∥ ≤ c * ∥g x∥ : hx
... ≤ c * (c' * ∥k x∥) : mul_le_mul_of_nonneg_left hx' hc
... = c * c' * ∥k x∥ : (mul_assoc _ _ _).symm
end
theorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l :=
let ⟨c, cnonneg, hc⟩ := hfg.exists_nonneg, ⟨c', hc'⟩ := hgk in (hc.trans hc' cnonneg).is_O
theorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc))
end
theorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l :=
let ⟨c, cpos, hc⟩ := hgk.exists_pos in hfg.trans_is_O_with hc cpos
theorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc))
end
theorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l :=
let ⟨c, cpos, hc⟩ := hfg.exists_pos in hc.trans_is_o hgk cpos
theorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l :=
hfg.trans_is_O hgk.is_O
theorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l :=
hfg.is_O.trans_is_o hgk
section
variable (l)
theorem is_O_with_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O_with c f g l :=
univ_mem_sets' hfg
theorem is_O_with_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O_with 1 f g l :=
is_O_with_of_le' l $ λ x, by { rw one_mul, exact hfg x }
theorem is_O_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O f g l :=
(is_O_with_of_le' l hfg).is_O
theorem is_O_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O f g l :=
(is_O_with_of_le l hfg).is_O
end
theorem is_O_with_refl (f : α → E) (l : filter α) : is_O_with 1 f f l :=
is_O_with_of_le l $ λ _, le_refl _
theorem is_O_refl (f : α → E) (l : filter α) : is_O f f l := (is_O_with_refl f l).is_O
theorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) (hc : 0 ≤ c) :
is_O_with c f k l :=
(hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c
theorem is_O.trans_le (hfg : is_O f g' l) (hgk : ∀ x, ∥g' x∥ ≤ ∥k x∥) :
is_O f k l :=
hfg.trans (is_O_of_le l hgk)
theorem is_o.trans_le (hfg : is_o f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) :
is_o f k l :=
hfg.trans_is_O_with (is_O_with_of_le _ hgk) zero_lt_one
section bot
variables (c f g)
theorem is_O_with_bot : is_O_with c f g ⊥ := trivial
theorem is_O_bot : is_O f g ⊥ := (is_O_with_bot c f g).is_O
theorem is_o_bot : is_o f g ⊥ := λ c _, is_O_with_bot c f g
end bot
theorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') :
is_O_with c f g (l ⊔ l') :=
mem_sup_sets.2 ⟨h, h'⟩
theorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') :
is_O_with (max c c') f g' (l ⊔ l') :=
mem_sup_sets.2 ⟨(h.weaken $ le_max_left c c'), (h'.weaken $ le_max_right c c')⟩
theorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l ⊔ l') :=
let ⟨c, hc⟩ := h, ⟨c', hc'⟩ := h' in (hc.join' hc').is_O
theorem is_o.join (h : is_o f g l) (h' : is_o f g l') :
is_o f g (l ⊔ l') :=
λ c cpos, (h cpos).join (h' cpos)
/-! ### Simplification : norm -/
@[simp] theorem is_O_with_norm_right : is_O_with c f (λ x, ∥g' x∥) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_right ↔ asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right
@[simp] theorem is_O_norm_right : is_O f (λ x, ∥g' x∥) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_norm_right
alias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right
@[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_right
alias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right
@[simp] theorem is_O_with_norm_left : is_O_with c (λ x, ∥f' x∥) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_left ↔ asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left
@[simp] theorem is_O_norm_left : is_O (λ x, ∥f' x∥) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_norm_left
alias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left
@[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_left
alias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left
theorem is_O_with_norm_norm :
is_O_with c (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O_with c f' g' l :=
is_O_with_norm_left.trans is_O_with_norm_right
alias is_O_with_norm_norm ↔ asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm
theorem is_O_norm_norm :
is_O (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O f' g' l :=
is_O_norm_left.trans is_O_norm_right
alias is_O_norm_norm ↔ asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm
theorem is_o_norm_norm :
is_o (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_o f' g' l :=
is_o_norm_left.trans is_o_norm_right
alias is_o_norm_norm ↔ asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm
/-! ### Simplification: negate -/
@[simp] theorem is_O_with_neg_right : is_O_with c f (λ x, -(g' x)) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_right ↔ asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right
@[simp] theorem is_O_neg_right : is_O f (λ x, -(g' x)) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_neg_right
alias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right
@[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_right
alias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right
@[simp] theorem is_O_with_neg_left : is_O_with c (λ x, -(f' x)) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_left ↔ asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left
@[simp] theorem is_O_neg_left : is_O (λ x, -(f' x)) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_neg_left
alias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left
@[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_left
alias is_o_neg_left ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left
/-! ### Product of functions (right) -/
lemma is_O_with_fst_prod : is_O_with 1 f' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_left _ _
lemma is_O_with_snd_prod : is_O_with 1 g' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_right _ _
lemma is_O_fst_prod : is_O f' (λ x, (f' x, g' x)) l := is_O_with_fst_prod.is_O
lemma is_O_snd_prod : is_O g' (λ x, (f' x, g' x)) l := is_O_with_snd_prod.is_O
lemma is_O_fst_prod' {f' : α → E' × F'} : is_O (λ x, (f' x).1) f' l :=
is_O_fst_prod
lemma is_O_snd_prod' {f' : α → E' × F'} : is_O (λ x, (f' x).2) f' l :=
is_O_snd_prod
section
variables (f' k')
lemma is_O_with.prod_rightl (h : is_O_with c f g' l) (hc : 0 ≤ c) :
is_O_with c f (λ x, (g' x, k' x)) l :=
(h.trans is_O_with_fst_prod hc).congr_const (mul_one c)
lemma is_O.prod_rightl (h : is_O f g' l) : is_O f (λx, (g' x, k' x)) l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightl k' cnonneg).is_O
lemma is_o.prod_rightl (h : is_o f g' l) : is_o f (λ x, (g' x, k' x)) l :=
λ c cpos, (h cpos).prod_rightl k' (le_of_lt cpos)
lemma is_O_with.prod_rightr (h : is_O_with c f g' l) (hc : 0 ≤ c) :
is_O_with c f (λ x, (f' x, g' x)) l :=
(h.trans is_O_with_snd_prod hc).congr_const (mul_one c)
lemma is_O.prod_rightr (h : is_O f g' l) : is_O f (λx, (f' x, g' x)) l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.prod_rightr f' cnonneg).is_O
lemma is_o.prod_rightr (h : is_o f g' l) : is_o f (λx, (f' x, g' x)) l :=
λ c cpos, (h cpos).prod_rightr f' (le_of_lt cpos)
end
lemma is_O_with.prod_left_same (hf : is_O_with c f' k' l) (hg : is_O_with c g' k' l) :
is_O_with c (λ x, (f' x, g' x)) k' l :=
begin
filter_upwards [hf, hg],
simp only [mem_set_of_eq],
exact λ x, max_le
end
lemma is_O_with.prod_left (hf : is_O_with c f' k' l) (hg : is_O_with c' g' k' l) :
is_O_with (max c c') (λ x, (f' x, g' x)) k' l :=
(hf.weaken $ le_max_left c c').prod_left_same (hg.weaken $ le_max_right c c')
lemma is_O_with.prod_left_fst (h : is_O_with c (λ x, (f' x, g' x)) k' l) :
is_O_with c f' k' l :=
(is_O_with_fst_prod.trans h zero_le_one).congr_const $ one_mul c
lemma is_O_with.prod_left_snd (h : is_O_with c (λ x, (f' x, g' x)) k' l) :
is_O_with c g' k' l :=
(is_O_with_snd_prod.trans h zero_le_one).congr_const $ one_mul c
lemma is_O_with_prod_left :
is_O_with c (λ x, (f' x, g' x)) k' l ↔ is_O_with c f' k' l ∧ is_O_with c g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left_same h.2⟩
lemma is_O.prod_left (hf : is_O f' k' l) (hg : is_O g' k' l) : is_O (λ x, (f' x, g' x)) k' l :=
let ⟨c, hf⟩ := hf, ⟨c', hg⟩ := hg in (hf.prod_left hg).is_O
lemma is_O.prod_left_fst (h : is_O (λ x, (f' x, g' x)) k' l) : is_O f' k' l :=
is_O_fst_prod.trans h
lemma is_O.prod_left_snd (h : is_O (λ x, (f' x, g' x)) k' l) : is_O g' k' l :=
is_O_snd_prod.trans h
@[simp] lemma is_O_prod_left :
is_O (λ x, (f' x, g' x)) k' l ↔ is_O f' k' l ∧ is_O g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩
lemma is_o.prod_left (hf : is_o f' k' l) (hg : is_o g' k' l) : is_o (λ x, (f' x, g' x)) k' l :=
λ c hc, (hf hc).prod_left_same (hg hc)
lemma is_o.prod_left_fst (h : is_o (λ x, (f' x, g' x)) k' l) : is_o f' k' l :=
is_O_fst_prod.trans_is_o h
lemma is_o.prod_left_snd (h : is_o (λ x, (f' x, g' x)) k' l) : is_o g' k' l :=
is_O_snd_prod.trans_is_o h
@[simp] lemma is_o_prod_left :
is_o (λ x, (f' x, g' x)) k' l ↔ is_o f' k' l ∧ is_o g' k' l :=
⟨λ h, ⟨h.prod_left_fst, h.prod_left_snd⟩, λ h, h.1.prod_left h.2⟩
/-! ### Addition and subtraction -/
section add_sub
variables {c₁ c₂ : ℝ} {f₁ f₂ : α → E'}
theorem is_O_with.add (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :
is_O_with (c₁ + c₂) (λ x, f₁ x + f₂ x) g l :=
by filter_upwards [h₁, h₂] λ x hx₁ hx₂,
calc ∥f₁ x + f₂ x∥ ≤ c₁ * ∥g x∥ + c₂ * ∥g x∥ : norm_add_le_of_le hx₁ hx₂
... = (c₁ + c₂) * ∥g x∥ : (add_mul _ _ _).symm
theorem is_O.add : is_O f₁ g l → is_O f₂ g l → is_O (λ x, f₁ x + f₂ x) g l
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := (hc₁.add hc₂).is_O
theorem is_o.add (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x + f₂ x) g l :=
λ c cpos, ((h₁ $ half_pos cpos).add (h₂ $ half_pos cpos)).congr_const (add_halves c)
theorem is_o.add_add {g₁ g₂ : α → F'} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :
is_o (λ x, f₁ x + f₂ x) (λ x, ∥g₁ x∥ + ∥g₂ x∥) l :=
by refine (h₁.trans_le $ λ x, _).add (h₂.trans_le _);
simp [real.norm_eq_abs, abs_of_nonneg, add_nonneg]
theorem is_O.add_is_o (h₁ : is_O f₁ g l) (h₂ : is_o f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=
h₁.add h₂.is_O
theorem is_o.add_is_O (h₁ : is_o f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x + f₂ x) g l :=
h₁.is_O.add h₂
theorem is_O_with.add_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λx, f₁ x + f₂ x) g l :=
(h₁.add (h₂ (sub_pos.2 hc))).congr_const (add_sub_cancel'_right _ _)
theorem is_o.add_is_O_with (h₁ : is_o f₁ g l) (h₂ : is_O_with c₁ f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λx, f₁ x + f₂ x) g l :=
(h₂.add_is_o h₁ hc).congr_left $ λ _, add_comm _ _
theorem is_O_with.sub (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_O_with c₂ f₂ g l) :
is_O_with (c₁ + c₂) (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
theorem is_O_with.sub_is_o (h₁ : is_O_with c₁ f₁ g l) (h₂ : is_o f₂ g l) (hc : c₁ < c₂) :
is_O_with c₂ (λ x, f₁ x - f₂ x) g l :=
h₁.add_is_o h₂.neg_left hc
theorem is_O.sub (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) : is_O (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
theorem is_o.sub (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) : is_o (λ x, f₁ x - f₂ x) g l :=
h₁.add h₂.neg_left
end add_sub
/-! ### Lemmas about `is_O (f₁ - f₂) g l` / `is_o (f₁ - f₂) g l` treated as a binary relation -/
section is_oO_as_rel
variables {f₁ f₂ f₃ : α → E'}
theorem is_O_with.symm (h : is_O_with c (λ x, f₁ x - f₂ x) g l) :
is_O_with c (λ x, f₂ x - f₁ x) g l :=
h.neg_left.congr_left $ λ x, neg_sub _ _
theorem is_O_with_comm :
is_O_with c (λ x, f₁ x - f₂ x) g l ↔ is_O_with c (λ x, f₂ x - f₁ x) g l :=
⟨is_O_with.symm, is_O_with.symm⟩
theorem is_O.symm (h : is_O (λ x, f₁ x - f₂ x) g l) : is_O (λ x, f₂ x - f₁ x) g l :=
h.neg_left.congr_left $ λ x, neg_sub _ _
theorem is_O_comm : is_O (λ x, f₁ x - f₂ x) g l ↔ is_O (λ x, f₂ x - f₁ x) g l :=
⟨is_O.symm, is_O.symm⟩
theorem is_o.symm (h : is_o (λ x, f₁ x - f₂ x) g l) : is_o (λ x, f₂ x - f₁ x) g l :=
by simpa only [neg_sub] using h.neg_left
theorem is_o_comm : is_o (λ x, f₁ x - f₂ x) g l ↔ is_o (λ x, f₂ x - f₁ x) g l :=
⟨is_o.symm, is_o.symm⟩
theorem is_O_with.triangle (h₁ : is_O_with c (λ x, f₁ x - f₂ x) g l)
(h₂ : is_O_with c' (λ x, f₂ x - f₃ x) g l) :
is_O_with (c + c') (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_O.triangle (h₁ : is_O (λ x, f₁ x - f₂ x) g l) (h₂ : is_O (λ x, f₂ x - f₃ x) g l) :
is_O (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_o.triangle (h₁ : is_o (λ x, f₁ x - f₂ x) g l) (h₂ : is_o (λ x, f₂ x - f₃ x) g l) :
is_o (λ x, f₁ x - f₃ x) g l :=
(h₁.add h₂).congr_left $ λ x, sub_add_sub_cancel _ _ _
theorem is_O.congr_of_sub (h : is_O (λ x, f₁ x - f₂ x) g l) :
is_O f₁ g l ↔ is_O f₂ g l :=
⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),
λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩
theorem is_o.congr_of_sub (h : is_o (λ x, f₁ x - f₂ x) g l) :
is_o f₁ g l ↔ is_o f₂ g l :=
⟨λ h', (h'.sub h).congr_left (λ x, sub_sub_cancel _ _),
λ h', (h.add h').congr_left (λ x, sub_add_cancel _ _)⟩
end is_oO_as_rel
/-! ### Zero, one, and other constants -/
section zero_const
variables (g g' l)
theorem is_o_zero : is_o (λ x, (0 : E')) g' l :=
λ c hc, univ_mem_sets' $ λ x, by simpa using mul_nonneg (le_of_lt hc) (norm_nonneg $ g' x)
theorem is_O_with_zero (hc : 0 ≤ c) : is_O_with c (λ x, (0 : E')) g' l :=
univ_mem_sets' $ λ x, by simpa using mul_nonneg hc (norm_nonneg $ g' x)
theorem is_O_with_zero' : is_O_with 0 (λ x, (0 : E')) g l :=
univ_mem_sets' $ λ x, by simp
theorem is_O_zero : is_O (λ x, (0 : E')) g l := ⟨0, is_O_with_zero' _ _⟩
theorem is_O_refl_left : is_O (λ x, f' x - f' x) g' l :=
(is_O_zero g' l).congr_left $ λ x, (sub_self _).symm
theorem is_o_refl_left : is_o (λ x, f' x - f' x) g' l :=
(is_o_zero g' l).congr_left $ λ x, (sub_self _).symm
variables {g g' l}
theorem is_O_with_zero_right_iff :
is_O_with c f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
by simp only [is_O_with, exists_prop, true_and, norm_zero, mul_zero, norm_le_zero_iff]
theorem is_O_zero_right_iff : is_O f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
⟨λ h, let ⟨c, hc⟩ := h in (is_O_with_zero_right_iff).1 hc,
λ h, (is_O_with_zero_right_iff.2 h : is_O_with 1 _ _ _).is_O⟩
theorem is_o_zero_right_iff :
is_o f' (λ x, (0 : F')) l ↔ ∀ᶠ x in l, f' x = 0 :=
⟨λ h, is_O_zero_right_iff.1 h.is_O,
λ h c hc, is_O_with_zero_right_iff.2 h⟩
theorem is_O_with_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) :
is_O_with (∥c∥ / ∥c'∥) (λ x : α, c) (λ x, c') l :=
begin
apply univ_mem_sets',
intro x,
rw [mem_set_of_eq, div_mul_cancel],
rwa [ne.def, norm_eq_zero]
end
theorem is_O_const_const (c : E) {c' : F'} (hc' : c' ≠ 0) (l : filter α) :
is_O (λ x : α, c) (λ x, c') l :=
(is_O_with_const_const c hc' l).is_O
end zero_const
theorem is_O_with_const_one (c : E) (l : filter α) : is_O_with ∥c∥ (λ x : α, c) (λ x, (1 : 𝕜)) l :=
begin
refine (is_O_with_const_const c _ l).congr_const _,
{ rw [normed_field.norm_one, div_one] },
{ exact one_ne_zero }
end
theorem is_O_const_one (c : E) (l : filter α) : is_O (λ x : α, c) (λ x, (1 : 𝕜)) l :=
(is_O_with_const_one c l).is_O
section
variable (𝕜)
theorem is_o_const_iff_is_o_one {c : F'} (hc : c ≠ 0) :
is_o f (λ x, c) l ↔ is_o f (λ x, (1:𝕜)) l :=
⟨λ h, h.trans_is_O $ is_O_const_one c l, λ h, h.trans_is_O $ is_O_const_const _ hc _⟩
end
theorem is_o_const_iff {c : F'} (hc : c ≠ 0) :
is_o f' (λ x, c) l ↔ tendsto f' l (𝓝 0) :=
(is_o_const_iff_is_o_one ℝ hc).trans
begin
clear hc c,
simp only [is_o, is_O_with, normed_field.norm_one, mul_one,
metric.nhds_basis_closed_ball.tendsto_right_iff, metric.mem_closed_ball, dist_zero_right]
end
lemma is_o_id_const {c : F'} (hc : c ≠ 0) :
is_o (λ (x : E'), x) (λ x, c) (𝓝 0) :=
(is_o_const_iff hc).mpr (continuous_id.tendsto 0)
theorem is_O_const_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) {c : F'} (hc : c ≠ 0) :
is_O f' (λ x, c) l :=
begin
refine is_O.trans _ (is_O_const_const (∥y∥ + 1) hc l),
use 1,
simp only [is_O_with, one_mul],
have : tendsto (λx, ∥f' x∥) l (𝓝 ∥y∥), from (continuous_norm.tendsto _).comp h,
have Iy : ∥y∥ < ∥∥y∥ + 1∥, from lt_of_lt_of_le (lt_add_one _) (le_abs_self _),
exact this (ge_mem_nhds Iy)
end
section
variable (𝕜)
theorem is_o_one_iff : is_o f' (λ x, (1 : 𝕜)) l ↔ tendsto f' l (𝓝 0) :=
is_o_const_iff one_ne_zero
theorem is_O_one_of_tendsto {y : E'} (h : tendsto f' l (𝓝 y)) :
is_O f' (λ x, (1:𝕜)) l :=
is_O_const_of_tendsto h one_ne_zero
theorem is_O.trans_tendsto_nhds (hfg : is_O f g' l) {y : F'} (hg : tendsto g' l (𝓝 y)) :
is_O f (λ x, (1:𝕜)) l :=
hfg.trans $ is_O_one_of_tendsto 𝕜 hg
end
theorem is_O.trans_tendsto (hfg : is_O f' g' l) (hg : tendsto g' l (𝓝 0)) :
tendsto f' l (𝓝 0) :=
(is_o_one_iff ℝ).1 $ hfg.trans_is_o $ (is_o_one_iff ℝ).2 hg
theorem is_o.trans_tendsto (hfg : is_o f' g' l) (hg : tendsto g' l (𝓝 0)) :
tendsto f' l (𝓝 0) :=
hfg.is_O.trans_tendsto hg
/-! ### Multiplication by a constant -/
theorem is_O_with_const_mul_self (c : R) (f : α → R) (l : filter α) :
is_O_with ∥c∥ (λ x, c * f x) f l :=
is_O_with_of_le' _ $ λ x, norm_mul_le _ _
theorem is_O_const_mul_self (c : R) (f : α → R) (l : filter α) :
is_O (λ x, c * f x) f l :=
(is_O_with_const_mul_self c f l).is_O
theorem is_O_with.const_mul_left {f : α → R} (h : is_O_with c f g l) (c' : R) :
is_O_with (∥c'∥ * c) (λ x, c' * f x) g l :=
(is_O_with_const_mul_self c' f l).trans h (norm_nonneg c')
theorem is_O.const_mul_left {f : α → R} (h : is_O f g l) (c' : R) :
is_O (λ x, c' * f x) g l :=
let ⟨c, hc⟩ := h in (hc.const_mul_left c').is_O
theorem is_O_with_self_const_mul' (u : units R) (f : α → R) (l : filter α) :
is_O_with ∥(↑u⁻¹:R)∥ f (λ x, ↑u * f x) l :=
(is_O_with_const_mul_self ↑u⁻¹ _ l).congr_left $ λ x, u.inv_mul_cancel_left (f x)
theorem is_O_with_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :
is_O_with ∥c∥⁻¹ f (λ x, c * f x) l :=
(is_O_with_self_const_mul' (units.mk0 c hc) f l).congr_const $
normed_field.norm_inv c
theorem is_O_self_const_mul' {c : R} (hc : is_unit c) (f : α → R) (l : filter α) :
is_O f (λ x, c * f x) l :=
let ⟨u, hu⟩ := hc in hu ▸ (is_O_with_self_const_mul' u f l).is_O
theorem is_O_self_const_mul (c : 𝕜) (hc : c ≠ 0) (f : α → 𝕜) (l : filter α) :
is_O f (λ x, c * f x) l :=
is_O_self_const_mul' (is_unit.mk0 c hc) f l
theorem is_O_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) :
is_O (λ x, c * f x) g l ↔ is_O f g l :=
⟨(is_O_self_const_mul' hc f l).trans, λ h, h.const_mul_left c⟩
theorem is_O_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_O (λ x, c * f x) g l ↔ is_O f g l :=
is_O_const_mul_left_iff' $ is_unit.mk0 c hc
theorem is_o.const_mul_left {f : α → R} (h : is_o f g l) (c : R) :
is_o (λ x, c * f x) g l :=
(is_O_const_mul_self c f l).trans_is_o h
theorem is_o_const_mul_left_iff' {f : α → R} {c : R} (hc : is_unit c) :
is_o (λ x, c * f x) g l ↔ is_o f g l :=
⟨(is_O_self_const_mul' hc f l).trans_is_o, λ h, h.const_mul_left c⟩
theorem is_o_const_mul_left_iff {f : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_o (λ x, c * f x) g l ↔ is_o f g l :=
is_o_const_mul_left_iff' $ is_unit.mk0 c hc
theorem is_O_with.of_const_mul_right {g : α → R} {c : R} (hc' : 0 ≤ c')
(h : is_O_with c' f (λ x, c * g x) l) :
is_O_with (c' * ∥c∥) f g l :=
h.trans (is_O_with_const_mul_self c g l) hc'
theorem is_O.of_const_mul_right {g : α → R} {c : R}
(h : is_O f (λ x, c * g x) l) :
is_O f g l :=
let ⟨c, cnonneg, hc⟩ := h.exists_nonneg in (hc.of_const_mul_right cnonneg).is_O
theorem is_O_with.const_mul_right' {g : α → R} {u : units R} {c' : ℝ} (hc' : 0 ≤ c')
(h : is_O_with c' f g l) :
is_O_with (c' * ∥(↑u⁻¹:R)∥) f (λ x, ↑u * g x) l :=
h.trans (is_O_with_self_const_mul' _ _ _) hc'
theorem is_O_with.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0)
{c' : ℝ} (hc' : 0 ≤ c') (h : is_O_with c' f g l) :
is_O_with (c' * ∥c∥⁻¹) f (λ x, c * g x) l :=
h.trans (is_O_with_self_const_mul c hc g l) hc'
theorem is_O.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_O f g l) :
is_O f (λ x, c * g x) l :=
h.trans (is_O_self_const_mul' hc g l)
theorem is_O.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_O f g l) :
is_O f (λ x, c * g x) l :=
h.const_mul_right' $ is_unit.mk0 c hc
theorem is_O_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :
is_O f (λ x, c * g x) l ↔ is_O f g l :=
⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩
theorem is_O_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_O f (λ x, c * g x) l ↔ is_O f g l :=
is_O_const_mul_right_iff' $ is_unit.mk0 c hc
theorem is_o.of_const_mul_right {g : α → R} {c : R} (h : is_o f (λ x, c * g x) l) :
is_o f g l :=
h.trans_is_O (is_O_const_mul_self c g l)
theorem is_o.const_mul_right' {g : α → R} {c : R} (hc : is_unit c) (h : is_o f g l) :
is_o f (λ x, c * g x) l :=
h.trans_is_O (is_O_self_const_mul' hc g l)
theorem is_o.const_mul_right {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) (h : is_o f g l) :
is_o f (λ x, c * g x) l :=
h.const_mul_right' $ is_unit.mk0 c hc
theorem is_o_const_mul_right_iff' {g : α → R} {c : R} (hc : is_unit c) :
is_o f (λ x, c * g x) l ↔ is_o f g l :=
⟨λ h, h.of_const_mul_right, λ h, h.const_mul_right' hc⟩
theorem is_o_const_mul_right_iff {g : α → 𝕜} {c : 𝕜} (hc : c ≠ 0) :
is_o f (λ x, c * g x) l ↔ is_o f g l :=
is_o_const_mul_right_iff' $ is_unit.mk0 c hc
/-! ### Multiplication -/
theorem is_O_with.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} {c₁ c₂ : ℝ}
(h₁ : is_O_with c₁ f₁ g₁ l) (h₂ : is_O_with c₂ f₂ g₂ l) :
is_O_with (c₁ * c₂) (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
filter_upwards [h₁, h₂], simp only [mem_set_of_eq],
intros x hx₁ hx₂,
apply le_trans (norm_mul_le _ _),
convert mul_le_mul hx₁ hx₂ (norm_nonneg _) (le_trans (norm_nonneg _) hx₁) using 1,
rw normed_field.norm_mul,
ac_refl
end
theorem is_O.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_O f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :
is_O (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
let ⟨c, hc⟩ := h₁, ⟨c', hc'⟩ := h₂ in (hc.mul hc').is_O
theorem is_O.mul_is_o {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_O f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
intros c cpos,
rcases h₁.exists_pos with ⟨c', c'pos, hc'⟩,
exact (hc'.mul (h₂ (div_pos cpos c'pos))).congr_const (mul_div_cancel' _ (ne_of_gt c'pos))
end
theorem is_o.mul_is_O {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜}
(h₁ : is_o f₁ g₁ l) (h₂ : is_O f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
begin
intros c cpos,
rcases h₂.exists_pos with ⟨c', c'pos, hc'⟩,
exact ((h₁ (div_pos cpos c'pos)).mul hc').congr_const (div_mul_cancel _ (ne_of_gt c'pos))
end
theorem is_o.mul {f₁ f₂ : α → R} {g₁ g₂ : α → 𝕜} (h₁ : is_o f₁ g₁ l) (h₂ : is_o f₂ g₂ l) :
is_o (λ x, f₁ x * f₂ x) (λ x, g₁ x * g₂ x) l :=
h₁.mul_is_O h₂.is_O
/-! ### Scalar multiplication -/
section smul_const
variables [normed_space 𝕜 E']
theorem is_O_with.const_smul_left (h : is_O_with c f' g l) (c' : 𝕜) :
is_O_with (∥c'∥ * c) (λ x, c' • f' x) g l :=
by refine ((h.norm_left.const_mul_left (∥c'∥)).congr _ _ (λ _, rfl)).of_norm_left;
intros; simp only [norm_norm, norm_smul]
theorem is_O_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :
is_O (λ x, c • f' x) g l ↔ is_O f' g l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,
rw [←is_O_norm_left], simp only [norm_smul],
rw [is_O_const_mul_left_iff cne0, is_O_norm_left],
end
theorem is_o_const_smul_left (h : is_o f' g l) (c : 𝕜) :
is_o (λ x, c • f' x) g l :=
begin
refine ((h.norm_left.const_mul_left (∥c∥)).congr_left _).of_norm_left,
exact λ x, (norm_smul _ _).symm
end
theorem is_o_const_smul_left_iff {c : 𝕜} (hc : c ≠ 0) :
is_o (λ x, c • f' x) g l ↔ is_o f' g l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,
rw [←is_o_norm_left], simp only [norm_smul],
rw [is_o_const_mul_left_iff cne0, is_o_norm_left]
end
theorem is_O_const_smul_right {c : 𝕜} (hc : c ≠ 0) :
is_O f (λ x, c • f' x) l ↔ is_O f f' l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,
rw [←is_O_norm_right], simp only [norm_smul],
rw [is_O_const_mul_right_iff cne0, is_O_norm_right]
end
theorem is_o_const_smul_right {c : 𝕜} (hc : c ≠ 0) :
is_o f (λ x, c • f' x) l ↔ is_o f f' l :=
begin
have cne0 : ∥c∥ ≠ 0, from mt norm_eq_zero.mp hc,
rw [←is_o_norm_right], simp only [norm_smul],
rw [is_o_const_mul_right_iff cne0, is_o_norm_right]
end
end smul_const
section smul
variables [normed_space 𝕜 E'] [normed_space 𝕜 F']
theorem is_O_with.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O_with c k₁ k₂ l) (h₂ : is_O_with c' f' g' l) :
is_O_with (c * c') (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr rfl _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_O.smul {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_O f' g' l) :
is_O (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_O.smul_is_o {k₁ k₂ : α → 𝕜} (h₁ : is_O k₁ k₂ l) (h₂ : is_o f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul_is_o h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_o.smul_is_O {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_O f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul_is_O h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
theorem is_o.smul {k₁ k₂ : α → 𝕜} (h₁ : is_o k₁ k₂ l) (h₂ : is_o f' g' l) :
is_o (λ x, k₁ x • f' x) (λ x, k₂ x • g' x) l :=
by refine ((h₁.norm_norm.mul h₂.norm_norm).congr _ _).of_norm_norm;
by intros; simp only [norm_smul]
end smul
/-! ### Sum -/
section sum
variables {ι : Type*} {A : ι → α → E'} {C : ι → ℝ} {s : finset ι}
theorem is_O_with.sum (h : ∀ i ∈ s, is_O_with (C i) (A i) g l) :
is_O_with (∑ i in s, C i) (λ x, ∑ i in s, A i x) g l :=
begin
induction s using finset.induction_on with i s is IH,
{ simp only [is_O_with_zero', finset.sum_empty, forall_true_iff] },
{ simp only [is, finset.sum_insert, not_false_iff],
exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) }
end
theorem is_O.sum (h : ∀ i ∈ s, is_O (A i) g l) :
is_O (λ x, ∑ i in s, A i x) g l :=
begin
induction s using finset.induction_on with i s is IH,
{ simp only [is_O_zero, finset.sum_empty, forall_true_iff] },
{ simp only [is, finset.sum_insert, not_false_iff],
exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) }
end
theorem is_o.sum (h : ∀ i ∈ s, is_o (A i) g' l) :
is_o (λ x, ∑ i in s, A i x) g' l :=
begin
induction s using finset.induction_on with i s is IH,
{ simp only [is_o_zero, finset.sum_empty, forall_true_iff] },
{ simp only [is, finset.sum_insert, not_false_iff],
exact (h _ (finset.mem_insert_self i s)).add (IH (λ j hj, h _ (finset.mem_insert_of_mem hj))) }
end
end sum
/-! ### Relation between `f = o(g)` and `f / g → 0` -/
theorem is_o.tendsto_0 {f g : α → 𝕜} {l : filter α} (h : is_o f g l) :
tendsto (λ x, f x / (g x)) l (𝓝 0) :=
have eq₁ : is_o (λ x, f x / g x) (λ x, g x / g x) l,
from h.mul_is_O (is_O_refl _ _),
have eq₂ : is_O (λ x, g x / g x) (λ x, (1 : 𝕜)) l,
from is_O_of_le _ (λ x, by by_cases h : ∥g x∥ = 0; simp [h, zero_le_one]),
(is_o_one_iff 𝕜).mp (eq₁.trans_is_O eq₂)
private theorem is_o_of_tendsto {f g : α → 𝕜} {l : filter α}
(hgf : ∀ x, g x = 0 → f x = 0) (h : tendsto (λ x, f x / (g x)) l (𝓝 0)) :
is_o f g l :=
have eq₁ : is_o (λ x, f x / (g x)) (λ x, (1 : 𝕜)) l,
from (is_o_one_iff _).mpr h,
have eq₂ : is_o (λ x, f x / g x * g x) g l,
by convert eq₁.mul_is_O (is_O_refl _ _); simp,
have eq₃ : is_O f (λ x, f x / g x * g x) l,
begin
refine is_O_of_le _ (λ x, _),
by_cases H : g x = 0,
{ simp only [H, hgf _ H, mul_zero] },
{ simp only [div_mul_cancel _ H] }
end,
eq₃.trans_is_o eq₂
theorem is_o_iff_tendsto {f g : α → 𝕜} {l : filter α}
(hgf : ∀ x, g x = 0 → f x = 0) :
is_o f g l ↔ tendsto (λ x, f x / (g x)) l (𝓝 0) :=
iff.intro is_o.tendsto_0 (is_o_of_tendsto hgf)
/-! ### Miscellanous lemmas -/
theorem is_o_pow_pow {m n : ℕ} (h : m < n) :
is_o (λ(x : 𝕜), x^n) (λx, x^m) (𝓝 0) :=
begin
let p := n - m,
have nmp : n = m + p := (nat.add_sub_cancel' (le_of_lt h)).symm,
have : (λ(x : 𝕜), x^m) = (λx, x^m * 1), by simp only [mul_one],
simp only [this, pow_add, nmp],
refine is_O.mul_is_o (is_O_refl _ _) ((is_o_one_iff _).2 _),
convert (continuous_pow p).tendsto (0 : 𝕜),
exact (zero_pow (nat.sub_pos_of_lt h)).symm
end
theorem is_o_pow_id {n : ℕ} (h : 1 < n) :
is_o (λ(x : 𝕜), x^n) (λx, x) (𝓝 0) :=
by { convert is_o_pow_pow h, simp only [pow_one] }
theorem is_O_with.right_le_sub_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :
is_O_with (1 / (1 - c)) f₂ (λx, f₂ x - f₁ x) l :=
mem_sets_of_superset h $ λ x hx,
begin
simp only [mem_set_of_eq] at hx ⊢,
rw [mul_comm, one_div, ← div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm],
{ exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) },
{ exact sub_pos.2 hc }
end
theorem is_O_with.right_le_add_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :
is_O_with (1 / (1 - c)) f₂ (λx, f₁ x + f₂ x) l :=
(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.of_neg_left.congr rfl (λ x, rfl)
(λ x, by rw [neg_sub, sub_neg_eq_add])
theorem is_o.right_is_O_sub {f₁ f₂ : α → E'} (h : is_o f₁ f₂ l) :
is_O f₂ (λx, f₂ x - f₁ x) l :=
((h.def' one_half_pos).right_le_sub_of_lt_1 one_half_lt_one).is_O
theorem is_o.right_is_O_add {f₁ f₂ : α → E'} (h : is_o f₁ f₂ l) :
is_O f₂ (λx, f₁ x + f₂ x) l :=
((h.def' one_half_pos).right_le_add_of_lt_1 one_half_lt_one).is_O
end asymptotics
namespace local_homeomorph
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
variables {E : Type*} [has_norm E] {F : Type*} [has_norm F]
open asymptotics
/-- Transfer `is_O_with` over a `local_homeomorph`. -/
lemma is_O_with_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target)
{f : β → E} {g : β → F} {C : ℝ} :
is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
⟨λ h, h.comp_tendsto $
by { convert e.continuous_at (e.map_target hb), exact (e.right_inv hb).symm },
λ h, (h.comp_tendsto (e.continuous_at_symm hb)).congr' rfl
((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg f hx)
((e.eventually_right_inverse hb).mono $ λ x hx, congr_arg g hx)⟩
/-- Transfer `is_O` over a `local_homeomorph`. -/
lemma is_O_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} :
is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
exists_congr $ λ C, e.is_O_with_congr hb
/-- Transfer `is_o` over a `local_homeomorph`. -/
lemma is_o_congr (e : local_homeomorph α β) {b : β} (hb : b ∈ e.target) {f : β → E} {g : β → F} :
is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
forall_congr $ λ c, forall_congr $ λ hc, e.is_O_with_congr hb
end local_homeomorph
namespace homeomorph
variables {α : Type*} {β : Type*} [topological_space α] [topological_space β]
variables {E : Type*} [has_norm E] {F : Type*} [has_norm F]
open asymptotics
/-- Transfer `is_O_with` over a `homeomorph`. -/
lemma is_O_with_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} {C : ℝ} :
is_O_with C f g (𝓝 b) ↔ is_O_with C (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
e.to_local_homeomorph.is_O_with_congr trivial
/-- Transfer `is_O` over a `homeomorph`. -/
lemma is_O_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} :
is_O f g (𝓝 b) ↔ is_O (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
exists_congr $ λ C, e.is_O_with_congr
/-- Transfer `is_o` over a `homeomorph`. -/
lemma is_o_congr (e : α ≃ₜ β) {b : β} {f : β → E} {g : β → F} :
is_o f g (𝓝 b) ↔ is_o (f ∘ e) (g ∘ e) (𝓝 (e.symm b)) :=
forall_congr $ λ c, forall_congr $ λ hc, e.is_O_with_congr
end homeomorph
attribute [irreducible] asymptotics.is_o asymptotics.is_O asymptotics.is_O_with
|
3e45fe81cec918abb66ec5ba57bafc0b785531d4 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/category/Mon/default.lean | dabba273e243d1dfb3d19ed72c561258e30216fc | [
"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 | 37 | lean | import algebra.category.Mon.colimits
|
8e32a102c77dacd4c3d879852467f3aaa1d13aa1 | 12dabd587ce2621d9a4eff9f16e354d02e206c8e | /world08/level04.lean | 399ac3a92efc11ce74094ce517bf2677bbb6e3e2 | [] | no_license | abdelq/natural-number-game | a1b5b8f1d52625a7addcefc97c966d3f06a48263 | bbddadc6d2e78ece2e9acd40fa7702ecc2db75c2 | refs/heads/master | 1,668,606,478,691 | 1,594,175,058,000 | 1,594,175,058,000 | 278,673,209 | 0 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 129 | lean | theorem succ_eq_succ_iff (a b : mynat) : succ a = succ b ↔ a = b :=
begin
split,
exact succ_inj,
exact succ_eq_succ_of_eq,
end
|
318edd2697717fd2bfa1cb144b030a70bd90429c | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/set/pointwise/finite.lean | eb42fa54ee92c722d2d58c3a1506ed59d6329683 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,750 | lean | /-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Floris van Doorn
-/
import data.set.finite
import data.set.pointwise.smul
/-! # Finiteness lemmas for pointwise operations on sets -/
open_locale pointwise
variables {F α β γ : Type*}
namespace set
section has_involutive_inv
variables [has_involutive_inv α] {s : set α}
@[to_additive] lemma finite.inv (hs : s.finite) : s⁻¹.finite :=
hs.preimage $ inv_injective.inj_on _
end has_involutive_inv
section has_mul
variables [has_mul α] {s t : set α}
@[to_additive] lemma finite.mul : s.finite → t.finite → (s * t).finite := finite.image2 _
/-- Multiplication preserves finiteness. -/
@[to_additive "Addition preserves finiteness."]
def fintype_mul [decidable_eq α] (s t : set α) [fintype s] [fintype t] : fintype (s * t : set α) :=
set.fintype_image2 _ _ _
end has_mul
section monoid
variables [monoid α] {s t : set α}
@[to_additive]
instance decidable_mem_mul [fintype α] [decidable_eq α] [decidable_pred (∈ s)]
[decidable_pred (∈ t)] :
decidable_pred (∈ s * t) :=
λ _, decidable_of_iff _ mem_mul.symm
@[to_additive]
instance decidable_mem_pow [fintype α] [decidable_eq α] [decidable_pred (∈ s)] (n : ℕ) :
decidable_pred (∈ (s ^ n)) :=
begin
induction n with n ih,
{ simp_rw [pow_zero, mem_one], apply_instance },
{ letI := ih, rw pow_succ, apply_instance }
end
end monoid
section has_smul
variables [has_smul α β] {s : set α} {t : set β}
@[to_additive] lemma finite.smul : s.finite → t.finite → (s • t).finite := finite.image2 _
end has_smul
section has_smul_set
variables [has_smul α β] {s : set β} {a : α}
@[to_additive] lemma finite.smul_set : s.finite → (a • s).finite := finite.image _
end has_smul_set
section vsub
variables [has_vsub α β] {s t : set β}
include α
lemma finite.vsub (hs : s.finite) (ht : t.finite) : set.finite (s -ᵥ t) := hs.image2 _ ht
end vsub
end set
open set
namespace group
variables {G : Type*} [group G] [fintype G] (S : set G)
@[to_additive]
lemma card_pow_eq_card_pow_card_univ [∀ (k : ℕ), decidable_pred (∈ (S ^ k))] :
∀ k, fintype.card G ≤ k → fintype.card ↥(S ^ k) = fintype.card ↥(S ^ (fintype.card G)) :=
begin
have hG : 0 < fintype.card G := fintype.card_pos_iff.mpr ⟨1⟩,
by_cases hS : S = ∅,
{ refine λ k hk, fintype.card_congr _,
rw [hS, empty_pow (ne_of_gt (lt_of_lt_of_le hG hk)), empty_pow (ne_of_gt hG)] },
obtain ⟨a, ha⟩ := set.ne_empty_iff_nonempty.mp hS,
classical!,
have key : ∀ a (s t : set G), (∀ b : G, b ∈ s → a * b ∈ t) → fintype.card s ≤ fintype.card t,
{ refine λ a s t h, fintype.card_le_of_injective (λ ⟨b, hb⟩, ⟨a * b, h b hb⟩) _,
rintro ⟨b, hb⟩ ⟨c, hc⟩ hbc,
exact subtype.ext (mul_left_cancel (subtype.ext_iff.mp hbc)) },
have mono : monotone (λ n, fintype.card ↥(S ^ n) : ℕ → ℕ) :=
monotone_nat_of_le_succ (λ n, key a _ _ (λ b hb, set.mul_mem_mul ha hb)),
convert card_pow_eq_card_pow_card_univ_aux mono (λ n, set_fintype_card_le_univ (S ^ n))
(λ n h, le_antisymm (mono (n + 1).le_succ) (key a⁻¹ _ _ _)),
{ simp only [finset.filter_congr_decidable, fintype.card_of_finset] },
replace h : {a} * S ^ n = S ^ (n + 1),
{ refine set.eq_of_subset_of_card_le _ (le_trans (ge_of_eq h) _),
{ exact mul_subset_mul (set.singleton_subset_iff.mpr ha) set.subset.rfl },
{ convert key a (S ^ n) ({a} * S ^ n) (λ b hb, set.mul_mem_mul (set.mem_singleton a) hb) } },
rw [pow_succ', ←h, mul_assoc, ←pow_succ', h],
rintro _ ⟨b, c, hb, hc, rfl⟩,
rwa [set.mem_singleton_iff.mp hb, inv_mul_cancel_left],
end
end group
|
30f610ad67eb0b2810febdfdcecbd0185d220b34 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /library/data/old_fin.lean | 52361b4d1b9e1141bde44ec11b4f38d6352bd3bc | [
"Apache-2.0"
] | permissive | soonhokong/lean-osx | 4a954262c780e404c1369d6c06516161d07fcb40 | 3670278342d2f4faa49d95b46d86642d7875b47c | refs/heads/master | 1,611,410,334,552 | 1,474,425,686,000 | 1,474,425,686,000 | 12,043,103 | 5 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 18,063 | lean | /-
Copyright (c) 2015 Haitao Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Haitao Zhang, Leonardo de Moura
Finite ordinal types.
-/
import data.list.basic data.finset.basic data.fintype.card algebra.group data.equiv
open eq.ops nat function list finset fintype
structure fin (n : nat) := (val : nat) (is_lt : val < n)
attribute [reducible]
definition less_than := fin
namespace fin
-- attribute fin.val [coercion]
section def_equal
variable {n : nat}
lemma eq_of_veq : ∀ {i j : fin n}, (val i) = j → i = j
| (mk iv ilt) (mk jv jlt) := assume (veq : iv = jv), begin congruence, assumption end
lemma veq_of_eq : ∀ {i j : fin n}, i = j → (val i) = j
| (mk iv ilt) (mk jv jlt) := assume Peq,
show iv = jv, from fin.no_confusion Peq (λ Pe Pqe, Pe)
lemma eq_iff_veq {i j : fin n} : (val i) = j ↔ i = j :=
iff.intro eq_of_veq veq_of_eq
definition val_inj := @eq_of_veq n
end def_equal
section
open decidable
attribute [instance]
protected definition has_decidable_eq (n : nat) : ∀ (i j : fin n), decidable (i = j)
| (mk ival ilt) (mk jval jlt) :=
decidable_of_decidable_of_iff (nat.has_decidable_eq ival jval) eq_iff_veq
end
lemma dinj_lt (n : nat) : dinj (λ i, i < n) fin.mk :=
take a1 a2 Pa1 Pa2 Pmkeq, fin.no_confusion Pmkeq (λ Pe Pqe, Pe)
lemma val_mk (n i : nat) (Plt : i < n) : fin.val (fin.mk i Plt) = i := rfl
attribute [reducible]
definition upto (n : nat) : list (fin n) :=
dmap (λ i, i < n) fin.mk (list.upto n)
lemma nodup_upto (n : nat) : nodup (upto n) :=
dmap_nodup_of_dinj (dinj_lt n) (list.nodup_upto n)
lemma mem_upto (n : nat) : ∀ (i : fin n), i ∈ upto n :=
take i, fin.destruct i
(take ival Piltn,
have ival ∈ list.upto n, from mem_upto_of_lt Piltn,
mem_dmap Piltn this)
lemma upto_zero : upto 0 = [] :=
by rewrite [↑upto, list.upto_nil, dmap_nil]
lemma map_val_upto (n : nat) : map fin.val (upto n) = list.upto n :=
map_dmap_of_inv_of_pos (val_mk n) (@lt_of_mem_upto n)
lemma length_upto (n : nat) : length (upto n) = n :=
calc
length (upto n) = length (list.upto n) : (map_val_upto n ▸ length_map fin.val (upto n))⁻¹
... = n : list.length_upto n
attribute [instance]
definition is_fintype (n : nat) : fintype (fin n) :=
fintype.mk (upto n) (nodup_upto n) (mem_upto n)
section pigeonhole
open fintype
lemma card_fin (n : nat) : card (fin n) = n := length_upto n
theorem pigeonhole {n m : nat} (Pmltn : m < n) : ¬∃ f : fin n → fin m, injective f :=
assume Pex, absurd Pmltn (not_lt_of_ge
(calc
n = card (fin n) : card_fin
... ≤ card (fin m) : card_le_of_inj (fin n) (fin m) Pex
... = m : card_fin))
end pigeonhole
protected definition zero (n : nat) : fin (succ n) :=
mk 0 !zero_lt_succ
attribute [instance]
definition fin_has_zero (n : nat) : has_zero (fin (succ n)) :=
has_zero.mk (fin.zero n)
theorem val_zero (n : nat) : val (0 : fin (succ n)) = 0 := rfl
attribute [reducible]
definition mk_mod (n i : nat) : fin (succ n) :=
mk (i % (succ n)) (mod_lt _ !zero_lt_succ)
theorem mk_mod_zero_eq (n : nat) : mk_mod n 0 = 0 :=
rfl
variable {n : nat}
theorem val_lt : ∀ i : fin n, val i < n
| (mk v h) := h
lemma max_lt (i j : fin n) : max i j < n :=
max_lt (is_lt i) (is_lt j)
definition lift : fin n → Π m : nat, fin (n + m)
| (mk v h) m := mk v (lt_add_of_lt_right h m)
definition lift_succ (i : fin n) : fin (nat.succ n) :=
have r : fin (n+1), from lift i 1,
r
attribute [reducible]
definition maxi : fin (succ n) :=
mk n !lt_succ_self
theorem val_lift : ∀ (i : fin n) (m : nat), val i = val (lift i m)
| (mk v h) m := rfl
lemma mk_succ_ne_zero {i : nat} : ∀ {P}, mk (succ i) P ≠ (0 : fin (succ n)) :=
assume P Pe, absurd (veq_of_eq Pe) !succ_ne_zero
lemma mk_mod_eq {i : fin (succ n)} : i = mk_mod n i :=
eq_of_veq begin rewrite [↑mk_mod, mod_eq_of_lt !is_lt] end
lemma mk_mod_of_lt {i : nat} (Plt : i < succ n) : mk_mod n i = mk i Plt :=
begin esimp [mk_mod], congruence, exact mod_eq_of_lt Plt end
section lift_lower
lemma lift_zero : lift_succ (0 : fin (succ n)) = (0 : fin (succ (succ n))) := rfl
lemma ne_max_of_lt_max {i : fin (succ n)} : i < n → i ≠ maxi :=
by intro hlt he; substvars; exact absurd hlt (lt.irrefl n)
lemma lt_max_of_ne_max {i : fin (succ n)} : i ≠ maxi → i < n :=
assume hne : i ≠ maxi,
have vne : val i ≠ n, from
assume he,
have val (@maxi n) = n, from rfl,
have val i = val (@maxi n), from he ⬝ this⁻¹,
absurd (eq_of_veq this) hne,
have val i < nat.succ n, from val_lt i,
lt_of_le_of_ne (le_of_lt_succ this) vne
lemma lift_succ_ne_max {i : fin n} : lift_succ i ≠ maxi :=
begin
cases i with v hlt, esimp [lift_succ, lift, max], intro he,
injection he, substvars,
exact absurd hlt (lt.irrefl v)
end
lemma lift_succ_inj : injective (@lift_succ n) :=
take i j, destruct i (destruct j (take iv ilt jv jlt Pmkeq,
begin congruence, apply fin.no_confusion Pmkeq, intros, assumption end))
lemma lt_of_inj_of_max (f : fin (succ n) → fin (succ n)) :
injective f → (f maxi = maxi) → ∀ i : fin (succ n), i < n → f i < n :=
assume Pinj Peq, take i, assume Pilt,
have P1 : f i = f maxi → i = maxi, from assume Peq, Pinj i maxi Peq,
have f i ≠ maxi, from
begin rewrite -Peq, intro P2, apply absurd (P1 P2) (ne_max_of_lt_max Pilt) end,
lt_max_of_ne_max this
definition lift_fun : (fin n → fin n) → (fin (succ n) → fin (succ n)) :=
λ f i, dite (i = maxi) (λ Pe, maxi) (λ Pne, lift_succ (f (mk i (lt_max_of_ne_max Pne))))
definition lower_inj (f : fin (succ n) → fin (succ n)) (inj : injective f) :
f maxi = maxi → fin n → fin n :=
assume Peq, take i, mk (f (lift_succ i)) (lt_of_inj_of_max f inj Peq (lift_succ i) (lt_max_of_ne_max lift_succ_ne_max))
lemma lift_fun_max {f : fin n → fin n} : lift_fun f maxi = maxi :=
begin rewrite [↑lift_fun, dif_pos rfl] end
lemma lift_fun_of_ne_max {f : fin n → fin n} {i} (Pne : i ≠ maxi) :
lift_fun f i = lift_succ (f (mk i (lt_max_of_ne_max Pne))) :=
begin rewrite [↑lift_fun, dif_neg Pne] end
lemma lift_fun_eq {f : fin n → fin n} {i : fin n} :
lift_fun f (lift_succ i) = lift_succ (f i) :=
begin
rewrite [lift_fun_of_ne_max lift_succ_ne_max], congruence, congruence,
rewrite [-eq_iff_veq], esimp, rewrite [↑lift_succ, -val_lift]
end
lemma lift_fun_of_inj {f : fin n → fin n} : injective f → injective (lift_fun f) :=
assume Pinj, take i j,
have Pdi : decidable (i = maxi), from _, have Pdj : decidable (j = maxi), from _,
begin
cases Pdi with Pimax Pinmax,
cases Pdj with Pjmax Pjnmax,
substvars, intros, exact rfl,
substvars, rewrite [lift_fun_max, lift_fun_of_ne_max Pjnmax],
intro Plmax, apply absurd Plmax⁻¹ lift_succ_ne_max,
cases Pdj with Pjmax Pjnmax,
substvars, rewrite [lift_fun_max, lift_fun_of_ne_max Pinmax],
intro Plmax, apply absurd Plmax lift_succ_ne_max,
rewrite [lift_fun_of_ne_max Pinmax, lift_fun_of_ne_max Pjnmax],
intro Peq, rewrite [-eq_iff_veq],
exact veq_of_eq (Pinj (lift_succ_inj Peq))
end
lemma lift_fun_inj : injective (@lift_fun n) :=
take f₁ f₂ Peq, funext (λ i,
have lift_fun f₁ (lift_succ i) = lift_fun f₂ (lift_succ i), from congr_fun Peq _,
begin revert this, rewrite [*lift_fun_eq], apply lift_succ_inj end)
lemma lower_inj_apply {f Pinj Pmax} (i : fin n) :
val (lower_inj f Pinj Pmax i) = val (f (lift_succ i)) :=
by rewrite [↑lower_inj]
end lift_lower
section madd
definition madd (i j : fin (succ n)) : fin (succ n) :=
mk ((i + j) % (succ n)) (mod_lt _ !zero_lt_succ)
definition minv : ∀ i : fin (succ n), fin (succ n)
| (mk iv ilt) := mk ((succ n - iv) % succ n) (mod_lt _ !zero_lt_succ)
lemma val_madd : ∀ i j : fin (succ n), val (madd i j) = (i + j) % (succ n)
| (mk iv ilt) (mk jv jlt) := by esimp
lemma madd_inj : ∀ {i : fin (succ n)}, injective (madd i)
| (mk iv ilt) :=
take j₁ j₂, fin.destruct j₁ (fin.destruct j₂ (λ jv₁ jlt₁ jv₂ jlt₂, begin
rewrite [↑madd, -eq_iff_veq],
intro Peq, congruence,
rewrite [-(mod_eq_of_lt jlt₁), -(mod_eq_of_lt jlt₂)],
apply mod_eq_mod_of_add_mod_eq_add_mod_left Peq
end))
lemma madd_mk_mod {i j : nat} : madd (mk_mod n i) (mk_mod n j) = mk_mod n (i+j) :=
eq_of_veq begin esimp [madd, mk_mod], rewrite [ mod_add_mod, add_mod_mod ] end
lemma val_mod : ∀ i : fin (succ n), (val i) % (succ n) = val i
| (mk iv ilt) := by esimp; rewrite [(mod_eq_of_lt ilt)]
lemma madd_comm (i j : fin (succ n)) : madd i j = madd j i :=
by apply eq_of_veq; rewrite [*val_madd, add.comm (val i)]
lemma zero_madd (i : fin (succ n)) : madd 0 i = i :=
have H : madd (fin.zero n) i = i,
by apply eq_of_veq; rewrite [val_madd, ↑fin.zero, nat.zero_add, mod_eq_of_lt (is_lt i)],
H
lemma madd_zero (i : fin (succ n)) : madd i (fin.zero n) = i :=
!madd_comm ▸ zero_madd i
lemma madd_assoc (i j k : fin (succ n)) : madd (madd i j) k = madd i (madd j k) :=
by apply eq_of_veq; rewrite [*val_madd, mod_add_mod, add_mod_mod, add.assoc (val i)]
lemma madd_left_inv : ∀ i : fin (succ n), madd (minv i) i = fin.zero n
| (mk iv ilt) := eq_of_veq (by
rewrite [val_madd, ↑minv, ↑fin.zero, mod_add_mod, nat.sub_add_cancel (le_of_lt ilt), mod_self])
attribute [instance]
definition madd_is_comm_group : add_comm_group (fin (succ n)) :=
add_comm_group.mk madd madd_assoc (fin.zero n) zero_madd madd_zero minv madd_left_inv madd_comm
end madd
definition pred : fin n → fin n
| (mk v h) := mk (nat.pred v) (pre_lt_of_lt h)
lemma val_pred : ∀ (i : fin n), val (pred i) = nat.pred (val i)
| (mk v h) := rfl
lemma pred_zero : pred (fin.zero n) = fin.zero n :=
rfl
definition mk_pred (i : nat) (h : succ i < succ n) : fin n :=
mk i (lt_of_succ_lt_succ h)
definition succ : fin n → fin (succ n)
| (mk v h) := mk (nat.succ v) (succ_lt_succ h)
lemma val_succ : ∀ (i : fin n), val (succ i) = nat.succ (val i)
| (mk v h) := rfl
lemma succ_max : fin.succ maxi = (@maxi (nat.succ n)) := rfl
lemma lift_succ.comm : lift_succ ∘ (@succ n) = succ ∘ lift_succ :=
funext take i, eq_of_veq (begin rewrite [↑lift_succ, -val_lift, *val_succ, -val_lift] end)
definition elim0 {C : fin 0 → Type} : Π i : fin 0, C i
| (mk v h) := absurd h !not_lt_zero
definition zero_succ_cases {C : fin (nat.succ n) → Type} :
C (fin.zero n) → (Π j : fin n, C (succ j)) → (Π k : fin (nat.succ n), C k) :=
begin
intros CO CS k,
induction k with [vk, pk],
induction (nat.decidable_lt 0 vk) with [HT, HF],
{ show C (mk vk pk), from
let vj := nat.pred vk in
have vk = vj+1, from
eq.symm (succ_pred_of_pos HT),
have vj < n, from
lt_of_succ_lt_succ (eq.subst `vk = vj+1` pk),
have succ (mk vj `vj < n`) = mk vk pk, from
val_inj (eq.symm `vk = vj+1`),
eq.rec_on this (CS (mk vj `vj < n`)) },
{ show C (mk vk pk), from
have vk = 0, from
eq_zero_of_le_zero (le_of_not_gt HF),
have fin.zero n = mk vk pk, from
val_inj (eq.symm this),
eq.rec_on this CO }
end
definition succ_maxi_cases {C : fin (nat.succ n) → Type} :
(Π j : fin n, C (lift_succ j)) → C maxi → (Π k : fin (nat.succ n), C k) :=
begin
intros CL CM k,
induction k with [vk, pk],
induction (nat.decidable_lt vk n) with [HT, HF],
{ show C (mk vk pk), from
have HL : lift_succ (mk vk HT) = mk vk pk, from
val_inj rfl,
eq.rec_on HL (CL (mk vk HT)) },
{ show C (mk vk pk), from
have HMv : vk = n, from
le.antisymm (le_of_lt_succ pk) (le_of_not_gt HF),
have HM : maxi = mk vk pk, from
val_inj (eq.symm HMv),
eq.rec_on HM CM }
end
definition foldr {A B : Type} (m : A → B → B) (b : B) : ∀ {n : nat}, (fin n → A) → B :=
nat.rec (λ f, b) (λ n IH f, m (f (fin.zero n)) (IH (λ i : fin n, f (succ i))))
definition foldl {A B : Type} (m : B → A → B) (b : B) : ∀ {n : nat}, (fin n → A) → B :=
nat.rec (λ f, b) (λ n IH f, m (IH (λ i : fin n, f (lift_succ i))) (f maxi))
theorem choice {C : fin n → Type} :
(∀ i : fin n, nonempty (C i)) → nonempty (Π i : fin n, C i) :=
begin
revert C,
induction n with [n, IH],
{ intros C H,
apply nonempty.intro,
exact elim0 },
{ intros C H,
fapply nonempty.elim (H (fin.zero n)),
intro CO,
fapply nonempty.elim (IH (λ i, C (succ i)) (λ i, H (succ i))),
intro CS,
apply nonempty.intro,
exact zero_succ_cases CO CS }
end
section
open list
local postfix `+1`:100 := nat.succ
lemma dmap_map_lift {n : nat} : ∀ l : list nat, (∀ i, i ∈ l → i < n) → dmap (λ i, i < n +1) mk l = map lift_succ (dmap (λ i, i < n) mk l)
| [] := assume Plt, rfl
| (i::l) := assume Plt, begin
rewrite [@dmap_cons_of_pos _ _ (λ i, i < n +1) _ _ _ (lt_succ_of_lt (Plt i !mem_cons)), @dmap_cons_of_pos _ _ (λ i, i < n) _ _ _ (Plt i !mem_cons), map_cons],
congruence,
apply dmap_map_lift,
intro j Pjinl, apply Plt, apply mem_cons_of_mem, assumption end
lemma upto_succ (n : nat) : upto (n +1) = maxi :: map lift_succ (upto n) :=
begin
rewrite [↑fin.upto, list.upto_succ, @dmap_cons_of_pos _ _ (λ i, i < n +1) _ _ _ (nat.self_lt_succ n)],
congruence,
apply dmap_map_lift, apply @list.lt_of_mem_upto
end
definition upto_step : ∀ {n : nat}, fin.upto (n +1) = (map succ (upto n))++[0]
| 0 := rfl
| (i +1) := begin rewrite [upto_succ i, map_cons, append_cons, succ_max, upto_succ, -lift_zero],
congruence, rewrite [map_map, -lift_succ.comm, -map_map, -(map_singleton _ 0), -map_append, -upto_step] end
end
open sum equiv decidable
definition fin_zero_equiv_empty : fin 0 ≃ empty :=
⦃ equiv,
to_fun := λ f : (fin 0), elim0 f,
inv_fun := λ e : empty, empty.rec _ e,
left_inv := λ f : (fin 0), elim0 f,
right_inv := λ e : empty, empty.rec _ e
⦄
definition fin_one_equiv_unit : fin 1 ≃ unit :=
⦃ equiv,
to_fun := λ f : (fin 1), unit.star,
inv_fun := λ u : unit, fin.zero 0,
left_inv := begin
intro f, change mk 0 !zero_lt_succ = f, cases f with v h, congruence,
have v +1 ≤ 1, from succ_le_of_lt h,
have v ≤ 0, from le_of_succ_le_succ this,
have v = 0, from eq_zero_of_le_zero this,
subst v
end,
right_inv := begin
intro u, cases u, reflexivity
end
⦄
definition fin_sum_equiv (n m : nat) : (fin n + fin m) ≃ fin (n+m) :=
have aux₁ : ∀ {v}, v < m → (v + n) < (n + m), from
take v, suppose v < m, calc
v + n < m + n : add_lt_add_of_lt_of_le this !le.refl
... = n + m : add.comm,
⦃ equiv,
to_fun := λ s : sum (fin n) (fin m),
match s with
| sum.inl (mk v hlt) := mk v (lt_add_of_lt_right hlt m)
| sum.inr (mk v hlt) := mk (v+n) (aux₁ hlt)
end,
inv_fun := λ f : fin (n + m),
match f with
| mk v hlt := if h : v < n then sum.inl (mk v h) else sum.inr (mk (v-n) (nat.sub_lt_of_lt_add hlt (le_of_not_gt h)))
end,
left_inv := begin
intro s, cases s with f₁ f₂,
{ cases f₁ with v hlt, esimp, rewrite [dif_pos hlt] },
{ cases f₂ with v hlt, esimp,
have ¬ v + n < n, from
suppose v + n < n,
have v < n - n, from nat.lt_sub_of_add_lt this !le.refl,
have v < 0, by rewrite [nat.sub_self at this]; exact this,
absurd this !not_lt_zero,
rewrite [dif_neg this], congruence, congruence, rewrite [nat.add_sub_cancel] }
end,
right_inv := begin
intro f, cases f with v hlt, esimp, apply @by_cases (v < n),
{ intro h₁, rewrite [dif_pos h₁] },
{ intro h₁, rewrite [dif_neg h₁], esimp, congruence, rewrite [nat.sub_add_cancel (le_of_not_gt h₁)] }
end
⦄
definition fin_prod_equiv_of_pos (n m : nat) : n > 0 → (fin n × fin m) ≃ fin (n*m) :=
suppose n > 0,
have aux₁ : ∀ {v₁ v₂}, v₁ < n → v₂ < m → v₁ + v₂ * n < n*m, from
take v₁ v₂, assume h₁ h₂,
have nat.succ v₂ ≤ m, from succ_le_of_lt h₂,
have nat.succ v₂ * n ≤ m * n, from mul_le_mul_right _ this,
have v₂ * n + n ≤ n * m, by rewrite [-add_one at this, right_distrib at this, one_mul at this, mul.comm m n at this]; exact this,
have v₁ + (v₂ * n + n) < n + n * m, from add_lt_add_of_lt_of_le h₁ this,
have v₁ + v₂ * n + n < n * m + n, by rewrite [add.assoc, add.comm (n*m) n]; exact this,
lt_of_add_lt_add_right this,
have aux₂ : ∀ v, v % n < n, from
take v, mod_lt _ `n > 0`,
have aux₃ : ∀ {v}, v < n * m → v / n < m, from
take v, assume h, by rewrite mul.comm at h; exact nat.div_lt_of_lt_mul h,
⦃ equiv,
to_fun := λ p : (fin n × fin m), match p with (mk v₁ hlt₁, mk v₂ hlt₂) := mk (v₁ + v₂ * n) (aux₁ hlt₁ hlt₂) end,
inv_fun := λ f : fin (n*m), match f with (mk v hlt) := (mk (v % n) (aux₂ v), mk (v / n) (aux₃ hlt)) end,
left_inv := begin
intro p, cases p with f₁ f₂, cases f₁ with v₁ hlt₁, cases f₂ with v₂ hlt₂, esimp,
congruence,
{congruence, rewrite [add_mul_mod_self, mod_eq_of_lt hlt₁] },
{congruence, rewrite [add_mul_div_self `n > 0`, div_eq_zero_of_lt hlt₁, zero_add]}
end,
right_inv := begin
intro f, cases f with v hlt, esimp, congruence,
rewrite [add.comm, -eq_div_mul_add_mod]
end
⦄
definition fin_prod_equiv : Π (n m : nat), (fin n × fin m) ≃ fin (n*m)
| 0 b := calc
(fin 0 × fin b) ≃ (empty × fin b) : prod_congr fin_zero_equiv_empty !equiv.refl
... ≃ empty : prod_empty_left
... ≃ fin 0 : fin_zero_equiv_empty
... ≃ fin (0 * b) : by rewrite zero_mul
| (a+1) b := fin_prod_equiv_of_pos (a+1) b dec_trivial
definition fin_two_equiv_bool : fin 2 ≃ bool :=
calc
fin 2 ≃ fin (1 + 1) : equiv.refl
... ≃ fin 1 + fin 1 : fin_sum_equiv
... ≃ unit + unit : sum_congr fin_one_equiv_unit fin_one_equiv_unit
... ≃ bool : bool_equiv_unit_sum_unit
definition fin_sum_unit_equiv (n : nat) : fin n + unit ≃ fin (n+1) :=
calc
fin n + unit ≃ fin n + fin 1 : sum_congr !equiv.refl (equiv.symm fin_one_equiv_unit)
... ≃ fin (n+1) : fin_sum_equiv
end fin
|
52146b6e4881a1d58e0a68407aa6a0e6e8da5261 | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/const.lean | a88f7444b595e8b03f32ff3dc7b8d5b6cc6eedc1 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 3,048 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.opposites
-- declare the `v`'s first; see `category_theory.category` for an explanation
universes v₁ v₂ v₃ u₁ u₂ u₃
open category_theory
namespace category_theory.functor
variables (J : Type u₁) [category.{v₁} J]
variables {C : Type u₂} [category.{v₂} C]
/--
The functor sending `X : C` to the constant functor `J ⥤ C` sending everything to `X`.
-/
def const : C ⥤ (J ⥤ C) :=
{ obj := λ X,
{ obj := λ j, X,
map := λ j j' f, 𝟙 X },
map := λ X Y f, { app := λ j, f } }
namespace const
open opposite
variables {J}
@[simp] lemma obj_obj (X : C) (j : J) : ((const J).obj X).obj j = X := rfl
@[simp] lemma obj_map (X : C) {j j' : J} (f : j ⟶ j') : ((const J).obj X).map f = 𝟙 X := rfl
@[simp] lemma map_app {X Y : C} (f : X ⟶ Y) (j : J) : ((const J).map f).app j = f := rfl
/--
The contant functor `Jᵒᵖ ⥤ Cᵒᵖ` sending everything to `op X`
is (naturally isomorphic to) the opposite of the constant functor `J ⥤ C` sending everything to `X`.
-/
def op_obj_op (X : C) :
(const Jᵒᵖ).obj (op X) ≅ ((const J).obj X).op :=
{ hom := { app := λ j, 𝟙 _ },
inv := { app := λ j, 𝟙 _ } }
@[simp] lemma op_obj_op_hom_app (X : C) (j : Jᵒᵖ) : (op_obj_op X).hom.app j = 𝟙 _ := rfl
@[simp] lemma op_obj_op_inv_app (X : C) (j : Jᵒᵖ) : (op_obj_op X).inv.app j = 𝟙 _ := rfl
/--
The contant functor `Jᵒᵖ ⥤ C` sending everything to `unop X`
is (naturally isomorphic to) the opposite of
the constant functor `J ⥤ Cᵒᵖ` sending everything to `X`.
-/
def op_obj_unop (X : Cᵒᵖ) :
(const Jᵒᵖ).obj (unop X) ≅ ((const J).obj X).left_op :=
{ hom := { app := λ j, 𝟙 _ },
inv := { app := λ j, 𝟙 _ } }
-- Lean needs some help with universes here.
@[simp] lemma op_obj_unop_hom_app (X : Cᵒᵖ) (j : Jᵒᵖ) : (op_obj_unop.{v₁ v₂} X).hom.app j = 𝟙 _ :=
rfl
@[simp] lemma op_obj_unop_inv_app (X : Cᵒᵖ) (j : Jᵒᵖ) : (op_obj_unop.{v₁ v₂} X).inv.app j = 𝟙 _ :=
rfl
@[simp] lemma unop_functor_op_obj_map (X : Cᵒᵖ) {j₁ j₂ : J} (f : j₁ ⟶ j₂) :
(unop ((functor.op (const J)).obj X)).map f = 𝟙 (unop X) := rfl
end const
section
variables {D : Type u₃} [category.{v₃} D]
/-- These are actually equal, of course, but not definitionally equal
(the equality requires F.map (𝟙 _) = 𝟙 _). A natural isomorphism is
more convenient than an equality between functors (compare id_to_iso). -/
@[simps] def const_comp (X : C) (F : C ⥤ D) :
(const J).obj X ⋙ F ≅ (const J).obj (F.obj X) :=
{ hom := { app := λ _, 𝟙 _ },
inv := { app := λ _, 𝟙 _ } }
/-- If `J` is nonempty, then the constant functor over `J` is faithful. -/
instance [nonempty J] : faithful (const J : C ⥤ J ⥤ C) :=
{ map_injective' := λ X Y f g e, nat_trans.congr_app e (classical.arbitrary J) }
end
end category_theory.functor
|
58599c2da06670a9957224cc105454c5cac00046 | d1a52c3f208fa42c41df8278c3d280f075eb020c | /tests/lean/run/500_lean3.lean | 893baa58d62ed20c30903dc25a18f8096229fe22 | [
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"... | permissive | cipher1024/lean4 | 6e1f98bb58e7a92b28f5364eb38a14c8d0aae393 | 69114d3b50806264ef35b57394391c3e738a9822 | refs/heads/master | 1,642,227,983,603 | 1,642,011,696,000 | 1,642,011,696,000 | 228,607,691 | 0 | 0 | Apache-2.0 | 1,576,584,269,000 | 1,576,584,268,000 | null | UTF-8 | Lean | false | false | 126 | lean | example (foo bar : OptionM Nat) : False := by
have : do { let x ← bar; foo } = bar >>= fun x => foo := rfl
admit
done
|
5543b23671cf2039ea77e5f7d841aaa2e60a9636 | 367134ba5a65885e863bdc4507601606690974c1 | /src/algebra/group/conj.lean | ed85131234c5e1670754386e558bf1f77efc26e0 | [
"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,120 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Chris Hughes, Michael Howes
-/
import algebra.group.hom
import data.equiv.mul_add_aut
/-!
# Conjugacy of group elements
See also `mul_aut.conj` and `quandle.conj`.
-/
universes u v
variables {α : Type u} {β : Type v}
variables [group α] [group β]
/-- We say that `a` is conjugate to `b` if for some `c` we have `c * a * c⁻¹ = b`. -/
def is_conj (a b : α) := ∃ c : α, c * a * c⁻¹ = b
@[refl] lemma is_conj_refl (a : α) : is_conj a a :=
⟨1, by rw [one_mul, one_inv, mul_one]⟩
@[symm] lemma is_conj_symm {a b : α} : is_conj a b → is_conj b a
| ⟨c, hc⟩ := ⟨c⁻¹, by rw [← hc, mul_assoc, mul_inv_cancel_right, inv_mul_cancel_left]⟩
@[trans] lemma is_conj_trans {a b c : α} : is_conj a b → is_conj b c → is_conj a c
| ⟨c₁, hc₁⟩ ⟨c₂, hc₂⟩ := ⟨c₂ * c₁, by rw [← hc₂, ← hc₁, mul_inv_rev]; simp only [mul_assoc]⟩
@[simp] lemma is_conj_one_right {a : α} : is_conj 1 a ↔ a = 1 :=
⟨by simp [is_conj, is_conj_refl] {contextual := tt}, by simp [is_conj_refl] {contextual := tt}⟩
@[simp] lemma is_conj_one_left {a : α} : is_conj a 1 ↔ a = 1 :=
calc is_conj a 1 ↔ is_conj 1 a : ⟨is_conj_symm, is_conj_symm⟩
... ↔ a = 1 : is_conj_one_right
@[simp] lemma conj_inv {a b : α} : (b * a * b⁻¹)⁻¹ = b * a⁻¹ * b⁻¹ :=
((mul_aut.conj b).map_inv a).symm
@[simp] lemma conj_mul {a b c : α} : (b * a * b⁻¹) * (b * c * b⁻¹) = b * (a * c) * b⁻¹ :=
((mul_aut.conj b).map_mul a c).symm
lemma conj_injective {x : α} : function.injective (λ (g : α), x * g * x⁻¹) :=
(mul_aut.conj x).injective
@[simp] lemma is_conj_iff_eq {α : Type*} [comm_group α] {a b : α} : is_conj a b ↔ a = b :=
⟨λ ⟨c, hc⟩, by rw [← hc, mul_right_comm, mul_inv_self, one_mul], λ h, by rw h⟩
protected lemma monoid_hom.map_is_conj (f : α →* β) {a b : α} : is_conj a b → is_conj (f a) (f b)
| ⟨c, hc⟩ := ⟨f c, by rw [← f.map_mul, ← f.map_inv, ← f.map_mul, hc]⟩
|
668f804e7352a7c4f66e7e43f175e3c05472fd66 | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/category_theory/monad/algebra.lean | 86622f056b39e17d3574af9cbdc62fb2db9f1127 | [
"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 | 6,901 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.monad.basic
import category_theory.adjunction.basic
import category_theory.reflects_isomorphisms
/-!
# Eilenberg-Moore (co)algebras for a (co)monad
This file defines Eilenberg-Moore (co)algebras for a (co)monad, and provides the category instance for them.
Further it defines the adjoint pair of free and forgetful functors, respectively
from and to the original category, as well as the adjoint pair of forgetful and
cofree functors, respectively from and to the original category.
## References
* [Riehl, *Category theory in context*, Section 5.2.4][riehl2017]
-/
namespace category_theory
open category
universes v₁ u₁ -- declare the `v`'s first; see `category_theory.category` for an explanation
variables {C : Type u₁} [category.{v₁} C]
namespace monad
/-- An Eilenberg-Moore algebra for a monad `T`.
cf Definition 5.2.3 in [Riehl][riehl2017]. -/
structure algebra (T : C ⥤ C) [monad T] : Type (max u₁ v₁) :=
(A : C)
(a : T.obj A ⟶ A)
(unit' : (η_ T).app A ≫ a = 𝟙 A . obviously)
(assoc' : ((μ_ T).app A ≫ a) = (T.map a ≫ a) . obviously)
restate_axiom algebra.unit'
restate_axiom algebra.assoc'
namespace algebra
variables {T : C ⥤ C} [monad T]
/-- A morphism of Eilenberg–Moore algebras for the monad `T`. -/
@[ext] structure hom (A B : algebra T) :=
(f : A.A ⟶ B.A)
(h' : T.map f ≫ B.a = A.a ≫ f . obviously)
restate_axiom hom.h'
attribute [simp] hom.h
namespace hom
/-- The identity homomorphism for an Eilenberg–Moore algebra. -/
@[simps] def id (A : algebra T) : hom A A :=
{ f := 𝟙 A.A }
/-- Composition of Eilenberg–Moore algebra homomorphisms. -/
@[simps] def comp {P Q R : algebra T} (f : hom P Q) (g : hom Q R) : hom P R :=
{ f := f.f ≫ g.f,
h' := by rw [functor.map_comp, category.assoc, g.h, ←category.assoc, f.h, category.assoc] }
end hom
/-- The category of Eilenberg-Moore algebras for a monad.
cf Definition 5.2.4 in [Riehl][riehl2017]. -/
@[simps] instance EilenbergMoore : category (algebra T) :=
{ hom := hom,
id := hom.id,
comp := @hom.comp _ _ _ _ }
end algebra
variables (T : C ⥤ C) [monad T]
/-- The forgetful functor from the Eilenberg-Moore category, forgetting the algebraic structure. -/
@[simps] def forget : algebra T ⥤ C :=
{ obj := λ A, A.A,
map := λ A B f, f.f }
/-- The free functor from the Eilenberg-Moore category, constructing an algebra for any object. -/
@[simps] def free : C ⥤ algebra T :=
{ obj := λ X,
{ A := T.obj X,
a := (μ_ T).app X,
assoc' := (monad.assoc _).symm },
map := λ X Y f,
{ f := T.map f,
h' := by erw (μ_ T).naturality } }
/-- The adjunction between the free and forgetful constructions for Eilenberg-Moore algebras for a monad.
cf Lemma 5.2.8 of [Riehl][riehl2017]. -/
def adj : free T ⊣ forget T :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X Y,
{ to_fun := λ f, (η_ T).app X ≫ f.f,
inv_fun := λ f,
{ f := T.map f ≫ Y.a,
h' :=
begin
simp,
conv { to_rhs, rw [←category.assoc, ←(μ_ T).naturality, category.assoc], erw algebra.assoc },
refl,
end },
left_inv := λ f,
begin
ext1,
simp only [free_obj_a, functor.map_comp, algebra.hom.h, category.assoc],
erw [←category.assoc, monad.right_unit, id_comp],
end,
right_inv := λ f,
begin
dsimp,
erw [←category.assoc, ←(η_ T).naturality, functor.id_map,
category.assoc, Y.unit, comp_id],
end }}
/-- Given an algebra morphism whose carrier part is an isomorphism, we get an algebra isomorphism. -/
def algebra_iso_of_iso {A B : algebra T} (f : A ⟶ B) [i : is_iso f.f] : is_iso f :=
{ inv :=
{ f := i.inv,
h' :=
begin
erw (as_iso f.f).eq_comp_inv,
slice_lhs 2 3 {erw ← f.h},
slice_lhs 1 2 {rw ← T.map_comp},
rw [is_iso.inv_hom_id, T.map_id, category.id_comp]
end } }
instance forget_reflects_iso : reflects_isomorphisms (forget T) :=
{ reflects := λ A B, algebra_iso_of_iso T }
end monad
namespace comonad
/-- An Eilenberg-Moore coalgebra for a comonad `T`. -/
@[nolint has_inhabited_instance]
structure coalgebra (G : C ⥤ C) [comonad G] : Type (max u₁ v₁) :=
(A : C)
(a : A ⟶ G.obj A)
(counit' : a ≫ (ε_ G).app A = 𝟙 A . obviously)
(coassoc' : (a ≫ (δ_ G).app A) = (a ≫ G.map a) . obviously)
restate_axiom coalgebra.counit'
restate_axiom coalgebra.coassoc'
namespace coalgebra
variables {G : C ⥤ C} [comonad G]
/-- A morphism of Eilenberg-Moore coalgebras for the comonad `G`. -/
@[ext, nolint has_inhabited_instance] structure hom (A B : coalgebra G) :=
(f : A.A ⟶ B.A)
(h' : A.a ≫ G.map f = f ≫ B.a . obviously)
restate_axiom hom.h'
attribute [simp] hom.h
namespace hom
/-- The identity homomorphism for an Eilenberg–Moore coalgebra. -/
@[simps] def id (A : coalgebra G) : hom A A :=
{ f := 𝟙 A.A }
/-- Composition of Eilenberg–Moore coalgebra homomorphisms. -/
@[simps] def comp {P Q R : coalgebra G} (f : hom P Q) (g : hom Q R) : hom P R :=
{ f := f.f ≫ g.f,
h' := by rw [functor.map_comp, ← category.assoc, f.h, category.assoc, g.h, category.assoc] }
end hom
/-- The category of Eilenberg-Moore coalgebras for a comonad. -/
@[simps] instance EilenbergMoore : category (coalgebra G) :=
{ hom := hom,
id := hom.id,
comp := @hom.comp _ _ _ _ }
end coalgebra
variables (G : C ⥤ C) [comonad G]
/-- The forgetful functor from the Eilenberg-Moore category, forgetting the coalgebraic structure. -/
@[simps] def forget : coalgebra G ⥤ C :=
{ obj := λ A, A.A,
map := λ A B f, f.f }
/-- The cofree functor from the Eilenberg-Moore category, constructing a coalgebra for any object. -/
@[simps] def cofree : C ⥤ coalgebra G :=
{ obj := λ X,
{ A := G.obj X,
a := (δ_ G).app X,
coassoc' := (comonad.coassoc _).symm },
map := λ X Y f,
{ f := G.map f,
h' := by erw (δ_ G).naturality; refl} }
/--
The adjunction between the cofree and forgetful constructions for Eilenberg-Moore coalgebras
for a comonad.
-/
def adj : forget G ⊣ cofree G :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X Y,
{ to_fun := λ f,
{ f := X.a ≫ G.map f,
h' := by { rw [functor.map_comp, ← category.assoc, ← coalgebra.coassoc], simp } },
inv_fun := λ g, g.f ≫ (ε_ G).app Y,
left_inv := λ f,
begin
dsimp,
rw [category.assoc, (ε_ G).naturality,
functor.id_map, ← category.assoc, X.counit, id_comp],
end,
right_inv := λ g,
begin
ext1, dsimp,
rw [functor.map_comp, ← category.assoc, coalgebra.hom.h, assoc,
cofree_obj_a, comonad.right_counit],
-- See note [dsimp, simp].
dsimp, simp
end
}}
end comonad
end category_theory
|
8513278053659499737951284a34e3c163e3ec15 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/data/nat/factorial.lean | ae722f6d68c5908c415bb2339a34272b4b046b42 | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,164 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Chris Hughes, Floris van Doorn
-/
import data.nat.basic
/-!
# The factorial function
-/
namespace nat
variables {m n : ℕ}
/-- `nat.factorial n` is the factorial of `n`. -/
@[simp] def factorial : nat → nat
| 0 := 1
| (succ n) := succ n * factorial n
localized "notation n `!`:10000 := nat.factorial n" in nat
@[simp] theorem factorial_zero : 0! = 1! := rfl
@[simp] theorem factorial_succ (n : ℕ) : n.succ! = succ n * n! := rfl
@[simp] theorem factorial_one : 1! = 1 := rfl
theorem mul_factorial_pred (hn : 0 < n) : n * (n - 1)! = n! :=
nat.sub_add_cancel hn ▸ rfl
theorem factorial_pos : ∀ n, 0 < n!
| 0 := zero_lt_one
| (succ n) := mul_pos (succ_pos _) (factorial_pos n)
theorem factorial_ne_zero (n : ℕ) : n! ≠ 0 := ne_of_gt (factorial_pos _)
theorem factorial_dvd_factorial {m n} (h : m ≤ n) : m! ∣ n! :=
begin
induction n with n IH; simp,
{ have := eq_zero_of_le_zero h, subst m, simp },
{ cases eq_or_lt_of_le h with he hl,
{ subst m, simp },
{ apply dvd_mul_of_dvd_right (IH (le_of_lt_succ hl)) } }
end
theorem dvd_factorial : ∀ {m n}, 0 < m → m ≤ n → m ∣ n!
| (succ m) n _ h := dvd_of_mul_right_dvd (factorial_dvd_factorial h)
@[mono] theorem factorial_le {m n} (h : m ≤ n) : m! ≤ n! :=
le_of_dvd (factorial_pos _) (factorial_dvd_factorial h)
lemma factorial_mul_pow_le_factorial : ∀ {m n : ℕ}, m! * m.succ ^ n ≤ (m + n)!
| m 0 := by simp
| m (n+1) :=
by rw [← add_assoc, nat.factorial_succ, mul_comm (nat.succ _), pow_succ', ← mul_assoc];
exact mul_le_mul factorial_mul_pow_le_factorial
(nat.succ_le_succ (nat.le_add_right _ _)) (nat.zero_le _) (nat.zero_le _)
lemma monotone_factorial : monotone factorial := λ n m, factorial_le
lemma factorial_lt (h0 : 0 < n) : n! < m! ↔ n < m :=
begin
split; intro h,
{ rw [← not_le], intro hmn, apply not_le_of_lt h (factorial_le hmn) },
{ have : ∀(n : ℕ), 0 < n → n! < n.succ!,
{ intros k hk, rw [factorial_succ, succ_mul, lt_add_iff_pos_left],
apply mul_pos hk (factorial_pos k) },
induction h with k hnk generalizing h0,
{ exact this _ h0, },
{ refine lt_trans (h_ih h0) (this _ _), exact lt_trans h0 (lt_of_succ_le hnk) }}
end
lemma one_lt_factorial : 1 < n! ↔ 1 < n :=
by { convert factorial_lt _, refl, exact one_pos }
lemma factorial_eq_one : n! = 1 ↔ n ≤ 1 :=
begin
split; intro h,
{ rw [← not_lt, ← one_lt_factorial, h], apply lt_irrefl },
{ cases h with h h, refl, cases h, refl }
end
lemma factorial_inj (h0 : 1 < n!) : n! = m! ↔ n = m :=
begin
split; intro h,
{ rcases lt_trichotomy n m with hnm|hnm|hnm,
{ exfalso, rw [← factorial_lt, h] at hnm, exact lt_irrefl _ hnm,
rw [one_lt_factorial] at h0, exact lt_trans one_pos h0 },
{ exact hnm },
{ exfalso, rw [← factorial_lt, h] at hnm, exact lt_irrefl _ hnm,
rw [h, one_lt_factorial] at h0, exact lt_trans one_pos h0 }},
{ rw h }
end
lemma self_le_factorial : ∀ n : ℕ, n ≤ n!
| 0 := zero_le_one
| (k+1) := le_mul_of_one_le_right k.zero_lt_succ.le (nat.one_le_of_lt $ nat.factorial_pos _)
lemma lt_factorial_self {n : ℕ} (hi : 3 ≤ n) : n < n! :=
begin
rw [← succ_pred_eq_of_pos ((zero_lt_two.trans (lt.base 2)).trans_le hi), factorial_succ],
exact lt_mul_of_one_lt_right ((pred n).succ_pos) ((one_lt_two.trans_le
(le_pred_of_lt (succ_le_iff.mp hi))).trans_le (self_le_factorial _)),
end
lemma add_factorial_succ_lt_factorial_add_succ {i : ℕ} (n : ℕ) (hi : 2 ≤ i) :
i + (n + 1)! < (i + n + 1)! :=
begin
rw [factorial_succ (i + _), succ_eq_add_one, add_mul, one_mul],
have : i ≤ i + n := le.intro rfl,
exact add_lt_add_of_lt_of_le (this.trans_lt ((lt_mul_iff_one_lt_right (zero_lt_two.trans_le
(hi.trans this))).mpr (lt_iff_le_and_ne.mpr ⟨(i + n).factorial_pos, λ g,
nat.not_succ_le_self 1 ((hi.trans this).trans (factorial_eq_one.mp g.symm))⟩))) (factorial_le
((le_of_eq (add_comm n 1)).trans ((add_le_add_iff_right n).mpr (one_le_two.trans hi)))),
end
lemma add_factorial_lt_factorial_add {i n : ℕ} (hi : 2 ≤ i) (hn : 1 ≤ n) :
i + n! < (i + n)! :=
begin
cases hn,
{ rw factorial_one,
exact lt_factorial_self (succ_le_succ hi) },
{ exact add_factorial_succ_lt_factorial_add_succ _ hi }
end
lemma add_factorial_succ_le_factorial_add_succ (i : ℕ) (n : ℕ) :
i + (n + 1)! ≤ (i + (n + 1))! :=
begin
by_cases i2 : 2 ≤ i,
{ exact (n.add_factorial_succ_lt_factorial_add_succ i2).le },
{ cases (not_le.mp i2) with _ i0,
{ change 1 + (n + 1)! ≤ (1 + n + 1) * (1 + n)!,
rw [add_mul, one_mul, add_comm 1 n],
exact (add_le_add_iff_right _).mpr (one_le_mul (nat.le_add_left 1 n) (n + 1).factorial_pos) },
{ rw [nat.le_zero_iff.mp (nat.succ_le_succ_iff.mp i0), zero_add, zero_add] } }
end
lemma add_factorial_le_factorial_add (i : ℕ) {n : ℕ} (n1 : 1 ≤ n) :
i + n! ≤ (i + n)! :=
begin
cases n1 with h,
{ exact self_le_factorial _ },
{ exact add_factorial_succ_le_factorial_add_succ i h }
end
end nat
|
08b9cd392a36133845358ec871809ca05ee4b30c | f02b05b665ad2d2cd970e93758a98d57f310a822 | /src/tactic/tcache/common.lean | c3e89cde333038d2ca288463e43b595302df5833 | [] | no_license | khoek/leancache | b0ed5d2a9a2e87f58d4ad27343d957a9cd49ce5f | 5c8329f7b647b8d82966ab180c4473b20d1f249c | refs/heads/master | 1,585,344,140,717 | 1,549,094,327,000 | 1,549,094,327,000 | 147,138,187 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 113 | lean | universe u
declare_trace tcache
meta def error {α : Sort u} (message : string) : α := undefined_core message
|
93dd1fa40e0fb77e72e72c3c3a4d3ab29c78679b | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/order/countable_dense_linear_order.lean | 7f1ad7989d7da0899ac0c12331ff967fea5c53cd | [] | no_license | AurelienSaue/Mathlib4_auto | f538cfd0980f65a6361eadea39e6fc639e9dae14 | 590df64109b08190abe22358fabc3eae000943f2 | refs/heads/master | 1,683,906,849,776 | 1,622,564,669,000 | 1,622,564,669,000 | 371,723,747 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 7,750 | lean | /-
Copyright (c) 2020 David Wärn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Wärn
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.ideal
import Mathlib.data.finset.default
import Mathlib.PostPort
universes u_1 u_2
namespace Mathlib
/-!
# The back and forth method and countable dense linear orders
## Results
Suppose `α β` are linear orders, with `α` countable and `β` dense, nonempty, without endpoints.
Then there is an order embedding `α ↪ β`. If in addition `α` is dense, nonempty, without
endpoints and `β` is countable, then we can upgrade this to an order isomorhpism `α ≃ β`.
The idea for both results is to consider "partial isomorphisms", which
identify a finite subset of `α` with a finite subset of `β`, and prove that
for any such partial isomorphism `f` and `a : α`, we can extend `f` to
include `a` in its domain.
## References
https://en.wikipedia.org/wiki/Back-and-forth_method
## Tags
back and forth, dense, countable, order
-/
namespace order
/-- Suppose `α` is a nonempty dense linear order without endpoints, and
suppose `lo`, `hi`, are finite subssets with all of `lo` strictly
before `hi`. Then there is an element of `α` strictly between `lo`
and `hi`. -/
theorem exists_between_finsets {α : Type u_1} [linear_order α] [densely_ordered α] [no_bot_order α] [no_top_order α] [nonem : Nonempty α] (lo : finset α) (hi : finset α) (lo_lt_hi : ∀ (x : α), x ∈ lo → ∀ (y : α), y ∈ hi → x < y) : ∃ (m : α), (∀ (x : α), x ∈ lo → x < m) ∧ ∀ (y : α), y ∈ hi → m < y := sorry
/-- The type of partial order isomorphisms between `α` and `β` defined on finite subsets.
A partial order isomorphism is encoded as a finite subset of `α × β`, consisting
of pairs which should be identified. -/
def partial_iso (α : Type u_1) (β : Type u_2) [linear_order α] [linear_order β] :=
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)
namespace partial_iso
protected instance inhabited (α : Type u_1) (β : Type u_2) [linear_order α] [linear_order β] : Inhabited (partial_iso α β) :=
{ default := { val := ∅, property := sorry } }
protected instance preorder (α : Type u_1) (β : Type u_2) [linear_order α] [linear_order β] : preorder (partial_iso α β) :=
subtype.preorder
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)
/-- For each `a`, we can find a `b` in the codomain, such that `a`'s relation to
the domain of `f` is `b`'s relation to the image of `f`.
Thus, if `a` is not already in `f`, then we can extend `f` by sending `a` to `b`.
-/
theorem exists_across {α : Type u_1} {β : Type u_2} [linear_order α] [linear_order β] [densely_ordered β] [no_bot_order β] [no_top_order β] [Nonempty β] (f : partial_iso α β) (a : α) : ∃ (b : β), ∀ (p : α × β), p ∈ subtype.val f → cmp (prod.fst p) a = cmp (prod.snd p) b := sorry
/-- A partial isomorphism between `α` and `β` is also a partial isomorphism between `β` and `α`. -/
protected def comm {α : Type u_1} {β : Type u_2} [linear_order α] [linear_order β] : partial_iso α β → partial_iso β α :=
subtype.map (finset.image ⇑(equiv.prod_comm α β)) sorry
/-- The set of partial isomorphisms defined at `a : α`, together with a proof that any
partial isomorphism can be extended to one defined at `a`. -/
def defined_at_left {α : Type u_1} (β : Type u_2) [linear_order α] [linear_order β] [densely_ordered β] [no_bot_order β] [no_top_order β] [Nonempty β] (a : α) : cofinal (partial_iso α β) :=
cofinal.mk (fun (f : partial_iso α β) => ∃ (b : β), (a, b) ∈ subtype.val f) sorry
/-- The set of partial isomorphisms defined at `b : β`, together with a proof that any
partial isomorphism can be extended to include `b`. We prove this by symmetry. -/
def defined_at_right (α : Type u_1) {β : Type u_2} [linear_order α] [linear_order β] [densely_ordered α] [no_bot_order α] [no_top_order α] [Nonempty α] (b : β) : cofinal (partial_iso α β) :=
cofinal.mk (fun (f : partial_iso α β) => ∃ (a : α), (a, b) ∈ subtype.val f) sorry
/-- Given an ideal which intersects `defined_at_left β a`, pick `b : β` such that
some partial function in the ideal maps `a` to `b`. -/
def fun_of_ideal {α : Type u_1} {β : Type u_2} [linear_order α] [linear_order β] [densely_ordered β] [no_bot_order β] [no_top_order β] [Nonempty β] (a : α) (I : ideal (partial_iso α β)) : (∃ (f : partial_iso α β), f ∈ defined_at_left β a ∧ f ∈ I) →
Subtype
fun (b : β) =>
∃ (f :
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)),
∃ (H : f ∈ I), (a, b) ∈ subtype.val f :=
(classical.indefinite_description
fun (x : β) =>
∃ (f :
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)),
∃ (H : f ∈ I), (a, x) ∈ subtype.val f) ∘
sorry
/-- Given an ideal which intersects `defined_at_right α b`, pick `a : α` such that
some partial function in the ideal maps `a` to `b`. -/
def inv_of_ideal {α : Type u_1} {β : Type u_2} [linear_order α] [linear_order β] [densely_ordered α] [no_bot_order α] [no_top_order α] [Nonempty α] (b : β) (I : ideal (partial_iso α β)) : (∃ (f : partial_iso α β), f ∈ defined_at_right α b ∧ f ∈ I) →
Subtype
fun (a : α) =>
∃ (f :
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)),
∃ (H : f ∈ I), (a, b) ∈ subtype.val f :=
(classical.indefinite_description
fun (x : α) =>
∃ (f :
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)),
∃ (H : f ∈ I), (x, b) ∈ subtype.val f) ∘
sorry
end partial_iso
/-- Any countable linear order embeds in any nonempty dense linear order without endpoints. -/
def embedding_from_countable_to_dense (α : Type u_1) (β : Type u_2) [linear_order α] [linear_order β] [encodable α] [densely_ordered β] [no_bot_order β] [no_top_order β] [Nonempty β] : α ↪o β :=
let our_ideal : ideal (partial_iso α β) := ideal_of_cofinals Inhabited.default (partial_iso.defined_at_left β);
let F :
(a : α) →
Subtype
fun (b : β) =>
∃ (f :
Subtype
fun (f : finset (α × β)) =>
∀ (p q : α × β), p ∈ f → q ∈ f → cmp (prod.fst p) (prod.fst q) = cmp (prod.snd p) (prod.snd q)),
∃ (H : f ∈ our_ideal), (a, b) ∈ subtype.val f :=
fun (a : α) => partial_iso.fun_of_ideal a our_ideal sorry;
order_embedding.of_strict_mono (fun (a : α) => subtype.val (F a)) sorry
/-- Any two countable dense, nonempty linear orders without endpoints are order isomorphic. -/
def iso_of_countable_dense (α : Type u_1) (β : Type u_2) [linear_order α] [linear_order β] [encodable α] [densely_ordered α] [no_bot_order α] [no_top_order α] [Nonempty α] [encodable β] [densely_ordered β] [no_bot_order β] [no_top_order β] [Nonempty β] : α ≃o β := sorry
|
339f2c7ce69ff100e92360e066896b5270de4b78 | 94e33a31faa76775069b071adea97e86e218a8ee | /src/category_theory/limits/shapes/products.lean | 4bf49c165731f7bea3b6eab323205f7e06808d05 | [
"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 | 13,761 | lean | /-
Copyright (c) 2018 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import category_theory.limits.has_limits
import category_theory.discrete_category
/-!
# Categorical (co)products
This file defines (co)products as special cases of (co)limits.
A product is the categorical generalization of the object `Π i, f i` where `f : ι → C`. It is a
limit cone over the diagram formed by `f`, implemented by converting `f` into a functor
`discrete ι ⥤ C`.
A coproduct is the dual concept.
## Main definitions
* a `fan` is a cone over a discrete category
* `fan.mk` constructs a fan from an indexed collection of maps
* a `pi` is a `limit (discrete.functor f)`
Each of these has a dual.
## Implementation notes
As with the other special shapes in the limits library, all the definitions here are given as
`abbreviation`s of the general statements for limits, so all the `simp` lemmas and theorems about
general limits can be used.
-/
noncomputable theory
universes w v v₂ u u₂
open category_theory
namespace category_theory.limits
variables {β : Type w}
variables {C : Type u} [category.{v} C]
-- We don't need an analogue of `pair` (for binary products), `parallel_pair` (for equalizers),
-- or `(co)span`, since we already have `discrete.functor`.
local attribute [tidy] tactic.discrete_cases
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
abbreviation fan (f : β → C) := cone (discrete.functor f)
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
abbreviation cofan (f : β → C) := cocone (discrete.functor f)
/-- A fan over `f : β → C` consists of a collection of maps from an object `P` to every `f b`. -/
@[simps]
def fan.mk {f : β → C} (P : C) (p : Π b, P ⟶ f b) : fan f :=
{ X := P,
π := { app := λ X, p X.as } }
/-- A cofan over `f : β → C` consists of a collection of maps from every `f b` to an object `P`. -/
@[simps]
def cofan.mk {f : β → C} (P : C) (p : Π b, f b ⟶ P) : cofan f :=
{ X := P,
ι := { app := λ X, p X.as } }
-- FIXME dualize as needed below (and rename?)
/-- Get the `j`th map in the fan -/
def fan.proj {f : β → C} (p : fan f) (j : β) : p.X ⟶ f j := p.π.app (discrete.mk j)
@[simp] lemma fan_mk_proj {f : β → C} (P : C) (p : Π b, P ⟶ f b) (j : β) :
(fan.mk P p).proj j = p j := rfl
/-- An abbreviation for `has_limit (discrete.functor f)`. -/
abbreviation has_product (f : β → C) := has_limit (discrete.functor f)
/-- An abbreviation for `has_colimit (discrete.functor f)`. -/
abbreviation has_coproduct (f : β → C) := has_colimit (discrete.functor f)
/-- Make a fan `f` into a limit fan by providing `lift`, `fac`, and `uniq` --
just a convenience lemma to avoid having to go through `discrete` -/
@[simps] def mk_fan_limit {f : β → C} (t : fan f)
(lift : Π s : fan f, s.X ⟶ t.X)
(fac : ∀ (s : fan f) (j : β), lift s ≫ (t.proj j) = s.proj j)
(uniq : ∀ (s : fan f) (m : s.X ⟶ t.X) (w : ∀ j : β, m ≫ t.proj j = s.proj j), m = lift s) :
is_limit t :=
{ lift := lift,
fac' := λ s j, by convert fac s j.as; simp,
uniq' := λ s m w, uniq s m (λ j, w (discrete.mk j)), }
section
variables (C)
/-- An abbreviation for `has_limits_of_shape (discrete f)`. -/
abbreviation has_products_of_shape (β : Type v) := has_limits_of_shape.{v} (discrete β)
/-- An abbreviation for `has_colimits_of_shape (discrete f)`. -/
abbreviation has_coproducts_of_shape (β : Type v) := has_colimits_of_shape.{v} (discrete β)
end
/-- `pi_obj f` computes the product of a family of elements `f`.
(It is defined as an abbreviation for `limit (discrete.functor f)`,
so for most facts about `pi_obj f`, you will just use general facts about limits.) -/
abbreviation pi_obj (f : β → C) [has_product f] := limit (discrete.functor f)
/-- `sigma_obj f` computes the coproduct of a family of elements `f`.
(It is defined as an abbreviation for `colimit (discrete.functor f)`,
so for most facts about `sigma_obj f`, you will just use general facts about colimits.) -/
abbreviation sigma_obj (f : β → C) [has_coproduct f] := colimit (discrete.functor f)
notation `∏ ` f:20 := pi_obj f
notation `∐ ` f:20 := sigma_obj f
/-- The `b`-th projection from the pi object over `f` has the form `∏ f ⟶ f b`. -/
abbreviation pi.π (f : β → C) [has_product f] (b : β) : ∏ f ⟶ f b :=
limit.π (discrete.functor f) (discrete.mk b)
/-- The `b`-th inclusion into the sigma object over `f` has the form `f b ⟶ ∐ f`. -/
abbreviation sigma.ι (f : β → C) [has_coproduct f] (b : β) : f b ⟶ ∐ f :=
colimit.ι (discrete.functor f) (discrete.mk b)
/-- The fan constructed of the projections from the product is limiting. -/
def product_is_product (f : β → C) [has_product f] :
is_limit (fan.mk _ (pi.π f)) :=
is_limit.of_iso_limit (limit.is_limit (discrete.functor f)) (cones.ext (iso.refl _) (by tidy))
/-- The cofan constructed of the inclusions from the coproduct is colimiting. -/
def coproduct_is_coproduct (f : β → C) [has_coproduct f] :
is_colimit (cofan.mk _ (sigma.ι f)) :=
is_colimit.of_iso_colimit (colimit.is_colimit (discrete.functor f)) (cocones.ext (iso.refl _)
(by tidy))
/-- A collection of morphisms `P ⟶ f b` induces a morphism `P ⟶ ∏ f`. -/
abbreviation pi.lift {f : β → C} [has_product f] {P : C} (p : Π b, P ⟶ f b) : P ⟶ ∏ f :=
limit.lift _ (fan.mk P p)
/-- A collection of morphisms `f b ⟶ P` induces a morphism `∐ f ⟶ P`. -/
abbreviation sigma.desc {f : β → C} [has_coproduct f] {P : C} (p : Π b, f b ⟶ P) : ∐ f ⟶ P :=
colimit.desc _ (cofan.mk P p)
/--
Construct a morphism between categorical products (indexed by the same type)
from a family of morphisms between the factors.
-/
abbreviation pi.map {f g : β → C} [has_product f] [has_product g]
(p : Π b, f b ⟶ g b) : ∏ f ⟶ ∏ g :=
lim_map (discrete.nat_trans (λ X, p X.as))
/--
Construct an isomorphism between categorical products (indexed by the same type)
from a family of isomorphisms between the factors.
-/
abbreviation pi.map_iso {f g : β → C} [has_products_of_shape β C]
(p : Π b, f b ≅ g b) : ∏ f ≅ ∏ g :=
lim.map_iso (discrete.nat_iso (λ X, p X.as))
/--
Construct a morphism between categorical coproducts (indexed by the same type)
from a family of morphisms between the factors.
-/
abbreviation sigma.map {f g : β → C} [has_coproduct f] [has_coproduct g]
(p : Π b, f b ⟶ g b) : ∐ f ⟶ ∐ g :=
colim_map (discrete.nat_trans (λ X, p X.as))
/--
Construct an isomorphism between categorical coproducts (indexed by the same type)
from a family of isomorphisms between the factors.
-/
abbreviation sigma.map_iso {f g : β → C} [has_coproducts_of_shape β C]
(p : Π b, f b ≅ g b) : ∐ f ≅ ∐ g :=
colim.map_iso (discrete.nat_iso (λ X, p X.as))
section comparison
variables {D : Type u₂} [category.{v₂} D] (G : C ⥤ D)
variables (f : β → C)
/-- The comparison morphism for the product of `f`. This is an iso iff `G` preserves the product
of `f`, see `preserves_product.of_iso_comparison`. -/
def pi_comparison [has_product f] [has_product (λ b, G.obj (f b))] :
G.obj (∏ f) ⟶ ∏ (λ b, G.obj (f b)) :=
pi.lift (λ b, G.map (pi.π f b))
@[simp, reassoc]
lemma pi_comparison_comp_π [has_product f] [has_product (λ b, G.obj (f b))] (b : β) :
pi_comparison G f ≫ pi.π _ b = G.map (pi.π f b) :=
limit.lift_π _ (discrete.mk b)
@[simp, reassoc]
lemma map_lift_pi_comparison [has_product f] [has_product (λ b, G.obj (f b))]
(P : C) (g : Π j, P ⟶ f j) :
G.map (pi.lift g) ≫ pi_comparison G f = pi.lift (λ j, G.map (g j)) :=
by { ext, discrete_cases, simp [← G.map_comp] }
/-- The comparison morphism for the coproduct of `f`. This is an iso iff `G` preserves the coproduct
of `f`, see `preserves_coproduct.of_iso_comparison`. -/
def sigma_comparison [has_coproduct f] [has_coproduct (λ b, G.obj (f b))] :
∐ (λ b, G.obj (f b)) ⟶ G.obj (∐ f) :=
sigma.desc (λ b, G.map (sigma.ι f b))
@[simp, reassoc]
lemma ι_comp_sigma_comparison [has_coproduct f] [has_coproduct (λ b, G.obj (f b))] (b : β) :
sigma.ι _ b ≫ sigma_comparison G f = G.map (sigma.ι f b) :=
colimit.ι_desc _ (discrete.mk b)
@[simp, reassoc]
lemma sigma_comparison_map_desc [has_coproduct f] [has_coproduct (λ b, G.obj (f b))]
(P : C) (g : Π j, f j ⟶ P) :
sigma_comparison G f ≫ G.map (sigma.desc g) = sigma.desc (λ j, G.map (g j)) :=
by { ext, discrete_cases, simp [← G.map_comp] }
end comparison
variables (C)
/-- An abbreviation for `Π J, has_limits_of_shape (discrete J) C` -/
abbreviation has_products := Π (J : Type w), has_limits_of_shape (discrete J) C
/-- An abbreviation for `Π J, has_colimits_of_shape (discrete J) C` -/
abbreviation has_coproducts := Π (J : Type w), has_colimits_of_shape (discrete J) C
variable {C}
lemma has_smallest_products_of_has_products [has_products.{w} C] : has_products.{0} C :=
λ J, has_limits_of_shape_of_equivalence
(discrete.equivalence equiv.ulift : discrete (ulift.{w} J) ≌ _)
lemma has_smallest_coproducts_of_has_coproducts [has_coproducts.{w} C] : has_coproducts.{0} C :=
λ J, has_colimits_of_shape_of_equivalence
(discrete.equivalence equiv.ulift : discrete (ulift.{w} J) ≌ _)
lemma has_products_of_limit_fans (lf : ∀ {J : Type w} (f : J → C), fan f)
(lf_is_limit : ∀ {J : Type w} (f : J → C), is_limit (lf f)) : has_products.{w} C :=
λ (J : Type w), { has_limit := λ F, has_limit.mk
⟨(cones.postcompose discrete.nat_iso_functor.inv).obj (lf (λ j, F.obj ⟨j⟩)),
(is_limit.postcompose_inv_equiv _ _).symm (lf_is_limit _)⟩ }
/-!
(Co)products over a type with a unique term.
-/
section unique
variables {C} [unique β] (f : β → C)
/-- The limit cone for the product over an index type with exactly one term. -/
@[simps]
def limit_cone_of_unique : limit_cone (discrete.functor f) :=
{ cone :=
{ X := f default,
π := { app := λ j, eq_to_hom (by { dsimp, congr, }), }, },
is_limit :=
{ lift := λ s, s.π.app default,
fac' := λ s j, begin
have w := (s.π.naturality (eq_to_hom (unique.default_eq _))).symm,
dsimp at w,
simpa [eq_to_hom_map] using w,
end,
uniq' := λ s m w, begin
specialize w default,
dsimp at w,
simpa using w,
end, }, }
@[priority 100] instance has_product_unique : has_product f :=
has_limit.mk (limit_cone_of_unique f)
/-- A product over a index type with exactly one term is just the object over that term. -/
@[simps]
def product_unique_iso : ∏ f ≅ f default :=
is_limit.cone_point_unique_up_to_iso (limit.is_limit _) (limit_cone_of_unique f).is_limit
/-- The colimit cocone for the coproduct over an index type with exactly one term. -/
@[simps]
def colimit_cocone_of_unique : colimit_cocone (discrete.functor f) :=
{ cocone :=
{ X := f default,
ι := { app := λ j, eq_to_hom (by { discrete_cases, dsimp, congr, }), }, },
is_colimit :=
{ desc := λ s, s.ι.app default,
fac' := λ s j, begin
have w := (s.ι.naturality (eq_to_hom (unique.eq_default _))),
dsimp at w,
simpa [eq_to_hom_map] using w,
end,
uniq' := λ s m w, begin
specialize w default,
dsimp at w,
simpa using w,
end, }, }
@[priority 100] instance has_coproduct_unique : has_coproduct f :=
has_colimit.mk (colimit_cocone_of_unique f)
/-- A coproduct over a index type with exactly one term is just the object over that term. -/
@[simps]
def coproduct_unique_iso : ∐ f ≅ f default :=
is_colimit.cocone_point_unique_up_to_iso (colimit.is_colimit _)
(colimit_cocone_of_unique f).is_colimit
end unique
section reindex
variables {C} {γ : Type v} (ε : β ≃ γ) (f : γ → C)
section
variables [has_product f] [has_product (f ∘ ε)]
/-- Reindex a categorical product via an equivalence of the index types. -/
def pi.reindex : pi_obj (f ∘ ε) ≅ pi_obj f :=
has_limit.iso_of_equivalence (discrete.equivalence ε) (discrete.nat_iso (λ i, iso.refl _))
@[simp, reassoc]
lemma pi.reindex_hom_π (b : β) : (pi.reindex ε f).hom ≫ pi.π f (ε b) = pi.π (f ∘ ε) b :=
begin
dsimp [pi.reindex],
simp only [has_limit.iso_of_equivalence_hom_π, discrete.nat_iso_inv_app,
equivalence.equivalence_mk'_counit, discrete.equivalence_counit_iso, discrete.nat_iso_hom_app,
eq_to_iso.hom, eq_to_hom_map],
dsimp,
simpa [eq_to_hom_map] using
limit.w (discrete.functor (f ∘ ε)) (discrete.eq_to_hom' (ε.symm_apply_apply b)),
end
@[simp, reassoc]
lemma pi.reindex_inv_π (b : β) : (pi.reindex ε f).inv ≫ pi.π (f ∘ ε) b = pi.π f (ε b) :=
by simp [iso.inv_comp_eq]
end
section
variables [has_coproduct f] [has_coproduct (f ∘ ε)]
/-- Reindex a categorical coproduct via an equivalence of the index types. -/
def sigma.reindex : sigma_obj (f ∘ ε) ≅ sigma_obj f :=
has_colimit.iso_of_equivalence (discrete.equivalence ε) (discrete.nat_iso (λ i, iso.refl _))
@[simp, reassoc]
lemma sigma.ι_reindex_hom (b : β) : sigma.ι (f ∘ ε) b ≫ (sigma.reindex ε f).hom = sigma.ι f (ε b) :=
begin
dsimp [sigma.reindex],
simp only [has_colimit.iso_of_equivalence_hom_π, equivalence.equivalence_mk'_unit,
discrete.equivalence_unit_iso, discrete.nat_iso_hom_app, eq_to_iso.hom, eq_to_hom_map,
discrete.nat_iso_inv_app],
dsimp,
simp [eq_to_hom_map,
←colimit.w (discrete.functor f) (discrete.eq_to_hom' (ε.apply_symm_apply (ε b)))],
end
@[simp, reassoc]
lemma sigma.ι_reindex_inv (b : β) : sigma.ι f (ε b) ≫ (sigma.reindex ε f).inv = sigma.ι (f ∘ ε) b :=
by simp [iso.comp_inv_eq]
end
end reindex
end category_theory.limits
|
e3e86a541b120219cb1086154cb2dda7c36904b7 | 9be442d9ec2fcf442516ed6e9e1660aa9071b7bd | /tests/lean/derivingRpcEncoding.lean | 7008783919f765527893984840a803aaff0c4715 | [
"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 | 2,490 | lean | import Lean.Server.Rpc.Basic
open Lean Server
abbrev M := StateM RpcObjectStore
def M.run (x : ExceptT String M α) : Except String α :=
x.run' {}
def test (α : Type) [RpcEncodable α] (a : α) := M.run do
let json ← rpcEncode a
let _a : α ← ofExcept (rpcDecode json (← get))
return json
structure FooRef where
a : Array Nat
deriving Inhabited, Std.TypeName
#check instTypeNameFooRef
#eval test (WithRpcRef FooRef) default
structure FooJson where
s : String
deriving FromJson, ToJson, Inhabited
structure Bar where
fooRef : WithRpcRef FooRef
fooJson : FooJson
deriving RpcEncodable, Inhabited
#check instRpcEncodableBar
#eval test Bar default
structure BarTrans where
bar : Bar
deriving RpcEncodable, Inhabited
#check instRpcEncodableBarTrans
#eval test BarTrans default
structure Baz where
arr : Array String -- non-constant field
deriving RpcEncodable, Inhabited
#check instRpcEncodableBaz
#eval test Baz default
structure FooGeneric (α : Type) where
a : α
b? : Option α
deriving RpcEncodable, Inhabited
#check @instRpcEncodableFooGeneric
#eval test (FooGeneric Nat) default
#eval test (FooGeneric Nat) { a := 3, b? := some 42 }
inductive BazInductive
| baz (arr : Array Bar)
deriving RpcEncodable, Inhabited
#check @instRpcEncodableBazInductive
#eval test BazInductive ⟨#[default, default]⟩
inductive FooInductive (α : Type) where
| a : α → WithRpcRef FooRef → FooInductive α
| b : (n : Nat) → (a : α) → (m : Nat) → FooInductive α
deriving RpcEncodable, Inhabited
#check @instRpcEncodableFooInductive
#eval test (FooInductive BazInductive) (.a default default)
#eval test (FooInductive BazInductive) (.b 42 default default)
inductive FooNested (α : Type) where
| a : α → Array (FooNested α) → FooNested α
deriving RpcEncodable, Inhabited
#eval test (FooNested BazInductive) (.a default #[default])
inductive FooParam (n : Nat) where
| a : Nat → FooParam n
deriving RpcEncodable, Inhabited
#check @instRpcEncodableFooParam
#eval test (FooParam 10) (.a 42)
inductive Unused (α : Type) | a
deriving RpcEncodable, Inhabited
#check @instRpcEncodableUnused
structure NoRpcEncodable
#eval test (Unused NoRpcEncodable) default
structure UnusedStruct (α : Type)
deriving RpcEncodable, Inhabited
#check @instRpcEncodableUnusedStruct
#eval test (UnusedStruct NoRpcEncodable) default
deriving instance Repr, RpcEncodable for Empty
#eval rpcDecode (α := Empty) .null {}
|
47807ee8cf68ef30180b8047877f0a525d64647d | 8d65764a9e5f0923a67fc435eb1a5a1d02fd80e3 | /src/data/fin.lean | d2751817d7a58b9700a7b0bbcec1c062ab5778d8 | [
"Apache-2.0"
] | permissive | troyjlee/mathlib | e18d4b8026e32062ab9e89bc3b003a5d1cfec3f5 | 45e7eb8447555247246e3fe91c87066506c14875 | refs/heads/master | 1,689,248,035,046 | 1,629,470,528,000 | 1,629,470,528,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 68,696 | lean | /-
Copyright (c) 2017 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis, Keeley Hoek
-/
import data.nat.cast
import data.int.basic
import tactic.localized
import tactic.apply_fun
import order.rel_iso
/-!
# The finite type with `n` elements
`fin n` is the type whose elements are natural numbers smaller than `n`.
This file expands on the development in the core library.
## Main definitions
### Induction principles
* `fin_zero_elim` : Elimination principle for the empty set `fin 0`, generalizes `fin.elim0`.
* `fin.succ_rec` : Define `C n i` by induction on `i : fin n` interpreted
as `(0 : fin (n - i)).succ.succ…`. This function has two arguments: `H0 n` defines
`0`-th element `C (n+1) 0` of an `(n+1)`-tuple, and `Hs n i` defines `(i+1)`-st element
of `(n+1)`-tuple based on `n`, `i`, and `i`-th element of `n`-tuple.
* `fin.succ_rec_on` : same as `fin.succ_rec` but `i : fin n` is the first argument;
* `fin.induction` : Define `C i` by induction on `i : fin (n + 1)`, separating into the
`nat`-like base cases of `C 0` and `C (i.succ)`.
* `fin.induction_on` : same as `fin.induction` but with `i : fin (n + 1)` as the first argument.
### Casts
* `cast_lt i h` : embed `i` into a `fin` where `h` proves it belongs into;
* `cast_le h` : embed `fin n` into `fin m`, `h : n ≤ m`;
* `cast eq` : embed `fin n` into `fin m`, `eq : n = m`;
* `cast_add m` : embed `fin n` into `fin (n+m)`;
* `cast_succ` : embed `fin n` into `fin (n+1)`;
* `succ_above p` : embed `fin n` into `fin (n + 1)` with a hole around `p`;
* `pred_above (p : fin n) i` : embed `i : fin (n+1)` into `fin n` by subtracting one if `p < i`;
* `cast_pred` : embed `fin (n + 2)` into `fin (n + 1)` by mapping `last (n + 1)` to `last n`;
* `sub_nat i h` : subtract `m` from `i ≥ m`, generalizes `fin.pred`;
* `add_nat m i` : add `m` on `i` on the right, generalizes `fin.succ`;
* `nat_add n i` adds `n` on `i` on the left;
* `clamp n m` : `min n m` as an element of `fin (m + 1)`;
### Operation on tuples
We interpret maps `Π i : fin n, α i` as tuples `(α 0, …, α (n-1))`.
If `α i` is a constant map, then tuples are isomorphic (but not definitionally equal)
to `vector`s.
We define the following operations:
* `tail` : the tail of an `n+1` tuple, i.e., its last `n` entries;
* `cons` : adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple;
* `init` : the beginning of an `n+1` tuple, i.e., its first `n` entries;
* `snoc` : adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc`
comes from `cons` (i.e., adding an element to the left of a tuple) read in reverse order.
* `insert_nth` : insert an element to a tuple at a given position.
* `find p` : returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied.
### Misc definitions
* `fin.last n` : The greatest value of `fin (n+1)`.
-/
universes u v
open fin nat function
/-- Elimination principle for the empty set `fin 0`, dependent version. -/
def fin_zero_elim {α : fin 0 → Sort u} (x : fin 0) : α x := x.elim0
lemma fact.succ.pos {n} : fact (0 < succ n) := ⟨zero_lt_succ _⟩
lemma fact.bit0.pos {n} [h : fact (0 < n)] : fact (0 < bit0 n) :=
⟨nat.zero_lt_bit0 $ ne_of_gt h.1⟩
lemma fact.bit1.pos {n} : fact (0 < bit1 n) :=
⟨nat.zero_lt_bit1 _⟩
lemma fact.pow.pos {p n : ℕ} [h : fact $ 0 < p] : fact (0 < p ^ n) :=
⟨pow_pos h.1 _⟩
localized "attribute [instance] fact.succ.pos" in fin_fact
localized "attribute [instance] fact.bit0.pos" in fin_fact
localized "attribute [instance] fact.bit1.pos" in fin_fact
localized "attribute [instance] fact.pow.pos" in fin_fact
namespace fin
variables {n m : ℕ} {a b : fin n}
instance fin_to_nat (n : ℕ) : has_coe (fin n) nat := ⟨subtype.val⟩
section coe
/-!
### coercions and constructions
-/
@[simp] protected lemma eta (a : fin n) (h : (a : ℕ) < n) : (⟨(a : ℕ), h⟩ : fin n) = a :=
by cases a; refl
@[ext]
lemma ext {a b : fin n} (h : (a : ℕ) = b) : a = b := eq_of_veq h
lemma ext_iff (a b : fin n) : a = b ↔ (a : ℕ) = b :=
iff.intro (congr_arg _) fin.eq_of_veq
lemma coe_injective {n : ℕ} : injective (coe : fin n → ℕ) := subtype.coe_injective
lemma eq_iff_veq (a b : fin n) : a = b ↔ a.1 = b.1 :=
⟨veq_of_eq, eq_of_veq⟩
lemma ne_iff_vne (a b : fin n) : a ≠ b ↔ a.1 ≠ b.1 :=
⟨vne_of_ne, ne_of_vne⟩
@[simp] lemma mk_eq_subtype_mk (a : ℕ) (h : a < n) : mk a h = ⟨a, h⟩ := rfl
protected lemma mk.inj_iff {n a b : ℕ} {ha : a < n} {hb : b < n} :
(⟨a, ha⟩ : fin n) = ⟨b, hb⟩ ↔ a = b :=
subtype.mk_eq_mk
lemma mk_val {m n : ℕ} (h : m < n) : (⟨m, h⟩ : fin n).val = m := rfl
lemma eq_mk_iff_coe_eq {k : ℕ} {hk : k < n} : a = ⟨k, hk⟩ ↔ (a : ℕ) = k :=
fin.eq_iff_veq a ⟨k, hk⟩
@[simp, norm_cast] lemma coe_mk {m n : ℕ} (h : m < n) : ((⟨m, h⟩ : fin n) : ℕ) = m := rfl
lemma mk_coe (i : fin n) : (⟨i, i.property⟩ : fin n) = i :=
fin.eta _ _
lemma coe_eq_val (a : fin n) : (a : ℕ) = a.val := rfl
@[simp] lemma val_eq_coe (a : fin n) : a.val = a := rfl
/-- Assume `k = l`. If two functions defined on `fin k` and `fin l` are equal on each element,
then they coincide (in the heq sense). -/
protected lemma heq_fun_iff {α : Sort*} {k l : ℕ} (h : k = l) {f : fin k → α} {g : fin l → α} :
f == g ↔ (∀ (i : fin k), f i = g ⟨(i : ℕ), h ▸ i.2⟩) :=
by { induction h, simp [heq_iff_eq, function.funext_iff] }
protected lemma heq_ext_iff {k l : ℕ} (h : k = l) {i : fin k} {j : fin l} :
i == j ↔ (i : ℕ) = (j : ℕ) :=
by { induction h, simp [ext_iff] }
lemma exists_iff {p : fin n → Prop} : (∃ i, p i) ↔ ∃ i h, p ⟨i, h⟩ :=
⟨λ h, exists.elim h (λ ⟨i, hi⟩ hpi, ⟨i, hi, hpi⟩),
λ h, exists.elim h (λ i hi, ⟨⟨i, hi.fst⟩, hi.snd⟩)⟩
lemma forall_iff {p : fin n → Prop} : (∀ i, p i) ↔ ∀ i h, p ⟨i, h⟩ :=
⟨λ h i hi, h ⟨i, hi⟩, λ h ⟨i, hi⟩, h i hi⟩
end coe
section order
/-!
### order
-/
lemma is_lt (i : fin n) : (i : ℕ) < n := i.2
lemma is_le (i : fin (n + 1)) : (i : ℕ) ≤ n := le_of_lt_succ i.is_lt
lemma lt_iff_coe_lt_coe : a < b ↔ (a : ℕ) < b := iff.rfl
lemma le_iff_coe_le_coe : a ≤ b ↔ (a : ℕ) ≤ b := iff.rfl
lemma mk_lt_of_lt_coe {a : ℕ} (h : a < b) : (⟨a, h.trans b.is_lt⟩ : fin n) < b := h
lemma mk_le_of_le_coe {a : ℕ} (h : a ≤ b) : (⟨a, h.trans_lt b.is_lt⟩ : fin n) ≤ b := h
/-- `a < b` as natural numbers if and only if `a < b` in `fin n`. -/
@[norm_cast, simp] lemma coe_fin_lt {n : ℕ} {a b : fin n} : (a : ℕ) < (b : ℕ) ↔ a < b :=
iff.rfl
/-- `a ≤ b` as natural numbers if and only if `a ≤ b` in `fin n`. -/
@[norm_cast, simp] lemma coe_fin_le {n : ℕ} {a b : fin n} : (a : ℕ) ≤ (b : ℕ) ↔ a ≤ b :=
iff.rfl
instance {n : ℕ} : linear_order (fin n) :=
{ le := (≤), lt := (<),
decidable_le := fin.decidable_le,
decidable_lt := fin.decidable_lt,
decidable_eq := fin.decidable_eq _,
..linear_order.lift (coe : fin n → ℕ) (@fin.eq_of_veq _) }
/-- The inclusion map `fin n → ℕ` is a relation embedding. -/
def coe_embedding (n) : (fin n) ↪o ℕ :=
⟨⟨coe, @fin.eq_of_veq _⟩, λ a b, iff.rfl⟩
/-- The ordering on `fin n` is a well order. -/
instance fin.lt.is_well_order (n) : is_well_order (fin n) (<) :=
(coe_embedding n).is_well_order
/-- Use the ordering on `fin n` for checking recursive definitions.
For example, the following definition is not accepted by the termination checker,
unless we declare the `has_well_founded` instance:
```lean
def factorial {n : ℕ} : fin n → ℕ
| ⟨0, _⟩ := 1
| ⟨i + 1, hi⟩ := (i + 1) * factorial ⟨i, i.lt_succ_self.trans hi⟩
```
-/
instance {n : ℕ} : has_well_founded (fin n) :=
⟨_, measure_wf coe⟩
@[simp] lemma coe_zero {n : ℕ} : ((0 : fin (n+1)) : ℕ) = 0 := rfl
attribute [simp] val_zero
@[simp] lemma val_zero' (n) : (0 : fin (n+1)).val = 0 := rfl
@[simp] lemma mk_zero : (⟨0, nat.succ_pos'⟩ : fin (n + 1)) = (0 : fin _) := rfl
lemma zero_le (a : fin (n + 1)) : 0 ≤ a := zero_le a.1
lemma pos_iff_ne_zero (a : fin (n+1)) : 0 < a ↔ a ≠ 0 :=
begin
split,
{ rintros h rfl, exact lt_irrefl _ h, },
{ rintros h,
apply (@pos_iff_ne_zero _ _ (a : ℕ)).mpr,
cases a,
rintro w,
apply h,
simp at w,
subst w,
refl, },
end
/-- The greatest value of `fin (n+1)` -/
def last (n : ℕ) : fin (n+1) := ⟨_, n.lt_succ_self⟩
@[simp, norm_cast] lemma coe_last (n : ℕ) : (last n : ℕ) = n := rfl
lemma last_val (n : ℕ) : (last n).val = n := rfl
theorem le_last (i : fin (n+1)) : i ≤ last n :=
le_of_lt_succ i.is_lt
instance : bounded_lattice (fin (n + 1)) :=
{ top := last n,
le_top := le_last,
bot := 0,
bot_le := zero_le,
.. fin.linear_order, .. lattice_of_linear_order }
lemma last_pos : (0 : fin (n + 2)) < last (n + 1) :=
by simp [lt_iff_coe_lt_coe]
lemma eq_last_of_not_lt {i : fin (n+1)} (h : ¬ (i : ℕ) < n) : i = last n :=
le_antisymm (le_last i) (not_lt.1 h)
section
variables {α : Type*} [preorder α]
open set
/-- If `e` is an `order_iso` between `fin n` and `fin m`, then `n = m` and `e` is the identity
map. In this lemma we state that for each `i : fin n` we have `(e i : ℕ) = (i : ℕ)`. -/
@[simp] lemma coe_order_iso_apply (e : fin n ≃o fin m) (i : fin n) : (e i : ℕ) = i :=
begin
rcases i with ⟨i, hi⟩,
rw [subtype.coe_mk],
induction i using nat.strong_induction_on with i h,
refine le_antisymm (forall_lt_iff_le.1 $ λ j hj, _) (forall_lt_iff_le.1 $ λ j hj, _),
{ have := e.symm.lt_iff_lt.2 (mk_lt_of_lt_coe hj),
rw e.symm_apply_apply at this,
convert this,
simpa using h _ this (e.symm _).is_lt },
{ rwa [← h j hj (hj.trans hi), ← lt_iff_coe_lt_coe, e.lt_iff_lt] }
end
instance order_iso_subsingleton : subsingleton (fin n ≃o α) :=
⟨λ e e', by { ext i,
rw [← e.symm.apply_eq_iff_eq, e.symm_apply_apply, ← e'.trans_apply, ext_iff,
coe_order_iso_apply] }⟩
instance order_iso_subsingleton' : subsingleton (α ≃o fin n) :=
order_iso.symm_injective.subsingleton
instance order_iso_unique : unique (fin n ≃o fin n) := unique.mk' _
/-- Two strictly monotone functions from `fin n` are equal provided that their ranges
are equal. -/
lemma strict_mono_unique {f g : fin n → α} (hf : strict_mono f) (hg : strict_mono g)
(h : range f = range g) : f = g :=
have (hf.order_iso f).trans (order_iso.set_congr _ _ h) = hg.order_iso g,
from subsingleton.elim _ _,
congr_arg (function.comp (coe : range g → α)) (funext $ rel_iso.ext_iff.1 this)
/-- Two order embeddings of `fin n` are equal provided that their ranges are equal. -/
lemma order_embedding_eq {f g : fin n ↪o α} (h : range f = range g) : f = g :=
rel_embedding.ext $ funext_iff.1 $ strict_mono_unique f.strict_mono g.strict_mono h
end
/-- A function `f` on `fin n` is strictly monotone if and only if `f i < f (i+1)` for all `i`. -/
lemma strict_mono_iff_lt_succ {α : Type*} [preorder α] {f : fin n → α} :
strict_mono f ↔ ∀ i (h : i + 1 < n), f ⟨i, lt_of_le_of_lt (nat.le_succ i) h⟩ < f ⟨i+1, h⟩ :=
begin
split,
{ assume H i hi,
apply H,
exact nat.lt_succ_self _ },
{ assume H,
have A : ∀ i j (h : i < j) (h' : j < n), f ⟨i, lt_trans h h'⟩ < f ⟨j, h'⟩,
{ assume i j h h',
induction h with k h IH,
{ exact H _ _ },
{ exact lt_trans (IH (nat.lt_of_succ_lt h')) (H _ _) } },
assume i j hij,
convert A (i : ℕ) (j : ℕ) hij j.2; ext; simp only [subtype.coe_eta] }
end
end order
section add
/-!
### addition, numerals, and coercion from nat
-/
/-- convert a `ℕ` to `fin n`, provided `n` is positive -/
def of_nat' [h : fact (0 < n)] (i : ℕ) : fin n := ⟨i%n, mod_lt _ h.1⟩
lemma one_val {n : ℕ} : (1 : fin (n+1)).val = 1 % (n+1) := rfl
lemma coe_one' {n : ℕ} : ((1 : fin (n+1)) : ℕ) = 1 % (n+1) := rfl
@[simp] lemma val_one {n : ℕ} : (1 : fin (n+2)).val = 1 := rfl
@[simp] lemma coe_one {n : ℕ} : ((1 : fin (n+2)) : ℕ) = 1 := rfl
@[simp] lemma mk_one : (⟨1, nat.succ_lt_succ (nat.succ_pos n)⟩ : fin (n + 2)) = (1 : fin _) := rfl
instance {n : ℕ} : nontrivial (fin (n + 2)) := ⟨⟨0, 1, dec_trivial⟩⟩
section monoid
@[simp] protected lemma add_zero (k : fin (n + 1)) : k + 0 = k :=
by simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]
@[simp] protected lemma zero_add (k : fin (n + 1)) : (0 : fin (n + 1)) + k = k :=
by simp [eq_iff_veq, add_def, mod_eq_of_lt (is_lt k)]
instance add_comm_monoid (n : ℕ) : add_comm_monoid (fin (n + 1)) :=
{ add := (+),
add_assoc := by simp [eq_iff_veq, add_def, add_assoc],
zero := 0,
zero_add := fin.zero_add,
add_zero := fin.add_zero,
add_comm := by simp [eq_iff_veq, add_def, add_comm] }
end monoid
lemma val_add {n : ℕ} : ∀ a b : fin n, (a + b).val = (a.val + b.val) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma coe_add {n : ℕ} : ∀ a b : fin n, ((a + b : fin n) : ℕ) = (a + b) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma coe_add_eq_ite {n : ℕ} (a b : fin n) :
(↑(a + b) : ℕ) = if n ≤ a + b then a + b - n else a + b :=
by rw [fin.coe_add, nat.add_mod_eq_ite,
nat.mod_eq_of_lt (show ↑a < n, from a.2), nat.mod_eq_of_lt (show ↑b < n, from b.2)]
lemma coe_bit0 {n : ℕ} (k : fin n) : ((bit0 k : fin n) : ℕ) = bit0 (k : ℕ) % n :=
by { cases k, refl }
lemma coe_bit1 {n : ℕ} (k : fin (n + 1)) :
((bit1 k : fin (n + 1)) : ℕ) = bit1 (k : ℕ) % (n + 1) :=
begin
cases n, { cases k with k h, cases k, {show _ % _ = _, simp}, cases h with _ h, cases h },
simp [bit1, fin.coe_bit0, fin.coe_add, fin.coe_one],
end
lemma coe_add_one_of_lt {n : ℕ} {i : fin n.succ} (h : i < last _) :
(↑(i + 1) : ℕ) = i + 1 :=
begin
-- First show that `((1 : fin n.succ) : ℕ) = 1`, because `n.succ` is at least 2.
cases n,
{ cases h },
-- Then just unfold the definitions.
rw [fin.coe_add, fin.coe_one, nat.mod_eq_of_lt (nat.succ_lt_succ _)],
exact h
end
@[simp] lemma last_add_one : ∀ n, last n + 1 = 0
| 0 := subsingleton.elim _ _
| (n + 1) := by { ext, rw [coe_add, coe_zero, coe_last, coe_one, nat.mod_self] }
lemma coe_add_one {n : ℕ} (i : fin (n + 1)) :
((i + 1 : fin (n + 1)) : ℕ) = if i = last _ then 0 else i + 1 :=
begin
rcases (le_last i).eq_or_lt with rfl|h,
{ simp },
{ simpa [h.ne] using coe_add_one_of_lt h }
end
section bit
@[simp] lemma mk_bit0 {m n : ℕ} (h : bit0 m < n) :
(⟨bit0 m, h⟩ : fin n) = (bit0 ⟨m, (nat.le_add_right m m).trans_lt h⟩ : fin _) :=
eq_of_veq (nat.mod_eq_of_lt h).symm
@[simp] lemma mk_bit1 {m n : ℕ} (h : bit1 m < n + 1) :
(⟨bit1 m, h⟩ : fin (n + 1)) = (bit1 ⟨m, (nat.le_add_right m m).trans_lt
((m + m).lt_succ_self.trans h)⟩ : fin _) :=
begin
ext,
simp only [bit1, bit0] at h,
simp only [bit1, bit0, coe_add, coe_one', coe_mk, ←nat.add_mod, nat.mod_eq_of_lt h],
end
end bit
@[simp] lemma val_two {n : ℕ} : (2 : fin (n+3)).val = 2 := rfl
@[simp] lemma coe_two {n : ℕ} : ((2 : fin (n+3)) : ℕ) = 2 := rfl
section of_nat_coe
@[simp]
lemma of_nat_eq_coe (n : ℕ) (a : ℕ) : (of_nat a : fin (n+1)) = a :=
begin
induction a with a ih, { refl },
ext, show (a+1) % (n+1) = subtype.val (a+1 : fin (n+1)),
{ rw [val_add, ← ih, of_nat],
exact add_mod _ _ _ }
end
/-- Converting an in-range number to `fin (n + 1)` produces a result
whose value is the original number. -/
lemma coe_val_of_lt {n : ℕ} {a : ℕ} (h : a < n + 1) :
((a : fin (n + 1)).val) = a :=
begin
rw ←of_nat_eq_coe,
exact nat.mod_eq_of_lt h
end
/-- Converting the value of a `fin (n + 1)` to `fin (n + 1)` results
in the same value. -/
lemma coe_val_eq_self {n : ℕ} (a : fin (n + 1)) : (a.val : fin (n + 1)) = a :=
begin
rw fin.eq_iff_veq,
exact coe_val_of_lt a.property
end
/-- Coercing an in-range number to `fin (n + 1)`, and converting back
to `ℕ`, results in that number. -/
lemma coe_coe_of_lt {n : ℕ} {a : ℕ} (h : a < n + 1) :
((a : fin (n + 1)) : ℕ) = a :=
coe_val_of_lt h
/-- Converting a `fin (n + 1)` to `ℕ` and back results in the same
value. -/
@[simp] lemma coe_coe_eq_self {n : ℕ} (a : fin (n + 1)) : ((a : ℕ) : fin (n + 1)) = a :=
coe_val_eq_self a
lemma coe_nat_eq_last (n) : (n : fin (n + 1)) = fin.last n :=
by { rw [←fin.of_nat_eq_coe, fin.of_nat, fin.last], simp only [nat.mod_eq_of_lt n.lt_succ_self] }
lemma le_coe_last (i : fin (n + 1)) : i ≤ n :=
by { rw fin.coe_nat_eq_last, exact fin.le_last i }
end of_nat_coe
lemma add_one_pos (i : fin (n + 1)) (h : i < fin.last n) : (0 : fin (n + 1)) < i + 1 :=
begin
cases n,
{ exact absurd h (nat.not_lt_zero _) },
{ rw [lt_iff_coe_lt_coe, coe_last, ←add_lt_add_iff_right 1] at h,
rw [lt_iff_coe_lt_coe, coe_add, coe_zero, coe_one, nat.mod_eq_of_lt h],
exact nat.zero_lt_succ _ }
end
lemma one_pos : (0 : fin (n + 2)) < 1 := succ_pos 0
lemma zero_ne_one : (0 : fin (n + 2)) ≠ 1 := ne_of_lt one_pos
@[simp] lemma zero_eq_one_iff : (0 : fin (n + 1)) = 1 ↔ n = 0 :=
begin
split,
{ cases n; intro h,
{ refl },
{ have := zero_ne_one, contradiction } },
{ rintro rfl, refl }
end
@[simp] lemma one_eq_zero_iff : (1 : fin (n + 1)) = 0 ↔ n = 0 :=
by rw [eq_comm, zero_eq_one_iff]
end add
section succ
/-!
### succ and casts into larger fin types
-/
@[simp] lemma coe_succ (j : fin n) : (j.succ : ℕ) = j + 1 :=
by cases j; simp [fin.succ]
lemma succ_pos (a : fin n) : (0 : fin (n + 1)) < a.succ := by simp [lt_iff_coe_lt_coe]
/-- `fin.succ` as an `order_embedding` -/
def succ_embedding (n : ℕ) : fin n ↪o fin (n + 1) :=
order_embedding.of_strict_mono fin.succ $ λ ⟨i, hi⟩ ⟨j, hj⟩ h, succ_lt_succ h
@[simp] lemma coe_succ_embedding : ⇑(succ_embedding n) = fin.succ := rfl
@[simp] lemma succ_le_succ_iff : a.succ ≤ b.succ ↔ a ≤ b :=
(succ_embedding n).le_iff_le
@[simp] lemma succ_lt_succ_iff : a.succ < b.succ ↔ a < b :=
(succ_embedding n).lt_iff_lt
lemma succ_injective (n : ℕ) : injective (@fin.succ n) :=
(succ_embedding n).injective
@[simp] lemma succ_inj {a b : fin n} : a.succ = b.succ ↔ a = b :=
(succ_injective n).eq_iff
lemma succ_ne_zero {n} : ∀ k : fin n, fin.succ k ≠ 0
| ⟨k, hk⟩ heq := nat.succ_ne_zero k $ (ext_iff _ _).1 heq
@[simp] lemma succ_zero_eq_one : fin.succ (0 : fin (n + 1)) = 1 := rfl
@[simp] lemma succ_one_eq_two : fin.succ (1 : fin (n + 2)) = 2 := rfl
@[simp] lemma succ_mk (n i : ℕ) (h : i < n) : fin.succ ⟨i, h⟩ = ⟨i + 1, nat.succ_lt_succ h⟩ :=
rfl
lemma mk_succ_pos (i : ℕ) (h : i < n) : (0 : fin (n + 1)) < ⟨i.succ, add_lt_add_right h 1⟩ :=
by { rw [lt_iff_coe_lt_coe, coe_zero], exact nat.succ_pos i }
lemma one_lt_succ_succ (a : fin n) : (1 : fin (n + 2)) < a.succ.succ :=
begin
cases n,
{ exact fin_zero_elim a },
{ rw [←succ_zero_eq_one, succ_lt_succ_iff], exact succ_pos a }
end
lemma succ_succ_ne_one (a : fin n) : fin.succ (fin.succ a) ≠ 1 := ne_of_gt (one_lt_succ_succ a)
/-- `cast_lt i h` embeds `i` into a `fin` where `h` proves it belongs into. -/
def cast_lt (i : fin m) (h : i.1 < n) : fin n := ⟨i.1, h⟩
@[simp] lemma coe_cast_lt (i : fin m) (h : i.1 < n) : (cast_lt i h : ℕ) = i := rfl
@[simp] lemma cast_lt_mk (i n m : ℕ) (hn : i < n) (hm : i < m) : cast_lt ⟨i, hn⟩ hm = ⟨i, hm⟩ := rfl
/-- `cast_le h i` embeds `i` into a larger `fin` type. -/
def cast_le (h : n ≤ m) : fin n ↪o fin m :=
order_embedding.of_strict_mono (λ a, cast_lt a (lt_of_lt_of_le a.2 h)) $ λ a b h, h
@[simp] lemma coe_cast_le (h : n ≤ m) (i : fin n) : (cast_le h i : ℕ) = i := rfl
@[simp] lemma cast_le_mk (i n m : ℕ) (hn : i < n) (h : n ≤ m) :
cast_le h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h⟩ := rfl
@[simp] lemma cast_le_zero {n m : ℕ} (h : n.succ ≤ m.succ) :
cast_le h 0 = 0 :=
by simp [eq_iff_veq]
@[simp] lemma range_cast_le {n k : ℕ} (h : n ≤ k) :
set.range (cast_le h) = {i | (i : ℕ) < n} :=
set.ext (λ x, ⟨λ ⟨y, hy⟩, hy ▸ y.2, λ hx, ⟨⟨x, hx⟩, fin.ext rfl⟩⟩)
@[simp] lemma coe_of_injective_cast_le_symm {n k : ℕ} (h : n ≤ k) (i : fin k) (hi) :
((equiv.of_injective _ (cast_le h).injective).symm ⟨i, hi⟩ : ℕ) = i :=
begin
rw ← coe_cast_le,
exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)
end
@[simp] lemma cast_le_succ {m n : ℕ} (h : (m + 1) ≤ (n + 1)) (i : fin m) :
cast_le h i.succ = (cast_le (nat.succ_le_succ_iff.mp h) i).succ :=
by simp [fin.eq_iff_veq]
/-- `cast eq i` embeds `i` into a equal `fin` type. -/
def cast (eq : n = m) : fin n ≃o fin m :=
{ to_equiv := ⟨cast_le eq.le, cast_le eq.symm.le, λ a, eq_of_veq rfl, λ a, eq_of_veq rfl⟩,
map_rel_iff' := λ a b, iff.rfl }
@[simp] lemma symm_cast (h : n = m) : (cast h).symm = cast h.symm := rfl
lemma coe_cast (h : n = m) (i : fin n) : (cast h i : ℕ) = i := rfl
@[simp] lemma cast_mk (h : n = m) (i : ℕ) (hn : i < n) :
cast h ⟨i, hn⟩ = ⟨i, lt_of_lt_of_le hn h.le⟩ := rfl
@[simp] lemma cast_trans {k : ℕ} (h : n = m) (h' : m = k) {i : fin n} :
cast h' (cast h i) = cast (eq.trans h h') i := rfl
@[simp] lemma cast_refl (h : n = n := rfl) : cast h = order_iso.refl (fin n) :=
by { ext, refl }
/-- While in many cases `fin.cast` is better than `equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma cast_to_equiv (h : n = m) : (cast h).to_equiv = equiv.cast (h ▸ rfl) :=
by { subst h, simp }
/-- While in many cases `fin.cast` is better than `equiv.cast`/`cast`, sometimes we want to apply
a generic theorem about `cast`. -/
lemma cast_eq_cast (h : n = m) : (cast h : fin n → fin m) = _root_.cast (h ▸ rfl) :=
by { subst h, ext, simp }
/-- `cast_add m i` embeds `i : fin n` in `fin (n+m)`. -/
def cast_add (m) : fin n ↪o fin (n + m) := cast_le $ nat.le_add_right n m
@[simp] lemma coe_cast_add (m : ℕ) (i : fin n) : (cast_add m i : ℕ) = i := rfl
@[simp] lemma cast_add_mk (m : ℕ) (i : ℕ) (h : i < n) :
cast_add m ⟨i, h⟩ = ⟨i, lt_add_right i n m h⟩ := rfl
/-- `cast_succ i` embeds `i : fin n` in `fin (n+1)`. -/
def cast_succ : fin n ↪o fin (n + 1) := cast_add 1
@[simp] lemma coe_cast_succ (i : fin n) : (i.cast_succ : ℕ) = i := rfl
@[simp] lemma cast_succ_mk (n i : ℕ) (h : i < n) : cast_succ ⟨i, h⟩ = ⟨i, nat.lt.step h⟩ := rfl
lemma cast_succ_lt_succ (i : fin n) : i.cast_succ < i.succ :=
lt_iff_coe_lt_coe.2 $ by simp only [coe_cast_succ, coe_succ, nat.lt_succ_self]
lemma le_cast_succ_iff {i : fin (n + 1)} {j : fin n} : i ≤ j.cast_succ ↔ i < j.succ :=
by simpa [lt_iff_coe_lt_coe, le_iff_coe_le_coe] using nat.succ_le_succ_iff.symm
@[simp] lemma succ_last (n : ℕ) : (last n).succ = last (n.succ) := rfl
@[simp] lemma succ_eq_last_succ {n : ℕ} (i : fin n.succ) :
i.succ = last (n + 1) ↔ i = last n :=
by rw [← succ_last, (succ_injective _).eq_iff]
@[simp] lemma cast_succ_cast_lt (i : fin (n + 1)) (h : (i : ℕ) < n) : cast_succ (cast_lt i h) = i :=
fin.eq_of_veq rfl
@[simp] lemma cast_lt_cast_succ {n : ℕ} (a : fin n) (h : (a : ℕ) < n) :
cast_lt (cast_succ a) h = a :=
by cases a; refl
@[simp] lemma cast_succ_lt_cast_succ_iff : a.cast_succ < b.cast_succ ↔ a < b :=
(@cast_succ n).lt_iff_lt
lemma cast_succ_injective (n : ℕ) : injective (@fin.cast_succ n) :=
(cast_succ : fin n ↪o _).injective
lemma cast_succ_inj {a b : fin n} : a.cast_succ = b.cast_succ ↔ a = b :=
(cast_succ_injective n).eq_iff
lemma cast_succ_lt_last (a : fin n) : cast_succ a < last n := lt_iff_coe_lt_coe.mpr a.is_lt
@[simp] lemma cast_succ_zero : cast_succ (0 : fin (n + 1)) = 0 := rfl
@[simp] lemma cast_succ_one {n : ℕ} : fin.cast_succ (1 : fin (n + 2)) = 1 := rfl
/-- `cast_succ i` is positive when `i` is positive -/
lemma cast_succ_pos {i : fin (n + 1)} (h : 0 < i) : 0 < cast_succ i :=
by simpa [lt_iff_coe_lt_coe] using h
@[simp] lemma cast_succ_eq_zero_iff (a : fin (n + 1)) : a.cast_succ = 0 ↔ a = 0 :=
subtype.ext_iff.trans $ (subtype.ext_iff.trans $ by exact iff.rfl).symm
lemma cast_succ_ne_zero_iff (a : fin (n + 1)) : a.cast_succ ≠ 0 ↔ a ≠ 0 :=
not_iff_not.mpr $ cast_succ_eq_zero_iff a
lemma cast_succ_fin_succ (n : ℕ) (j : fin n) :
cast_succ (fin.succ j) = fin.succ (cast_succ j) :=
by simp [fin.ext_iff]
@[norm_cast, simp] lemma coe_eq_cast_succ : (a : fin (n + 1)) = a.cast_succ :=
begin
ext,
exact coe_val_of_lt (nat.lt.step a.is_lt),
end
@[simp] lemma coe_succ_eq_succ : a.cast_succ + 1 = a.succ :=
begin
cases n,
{ exact fin_zero_elim a },
{ simp [a.is_lt, eq_iff_veq, add_def, nat.mod_eq_of_lt] }
end
lemma lt_succ : a.cast_succ < a.succ :=
by { rw [cast_succ, lt_iff_coe_lt_coe, coe_cast_add, coe_succ], exact lt_add_one a.val }
@[simp] lemma range_cast_succ {n : ℕ} :
set.range (cast_succ : fin n → fin n.succ) = {i | (i : ℕ) < n} :=
range_cast_le _
@[simp] lemma coe_of_injective_cast_succ_symm {n : ℕ} (i : fin n.succ) (hi) :
((equiv.of_injective cast_succ (cast_succ_injective _)).symm ⟨i, hi⟩ : ℕ) = i :=
begin
rw ← coe_cast_succ,
exact congr_arg coe (equiv.apply_of_injective_symm _ _ _)
end
/-- `add_nat m i` adds `m` to `i`, generalizes `fin.succ`. -/
def add_nat (m) : fin n ↪o fin (n + m) :=
order_embedding.of_strict_mono (λ i, ⟨(i : ℕ) + m, add_lt_add_right i.2 _⟩) $
λ i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_right h _
@[simp] lemma coe_add_nat (m : ℕ) (i : fin n) : (add_nat m i : ℕ) = i + m := rfl
/-- `nat_add n i` adds `n` to `i` "on the left". -/
def nat_add (n) {m} : fin m ↪o fin (n + m) :=
order_embedding.of_strict_mono (λ i, ⟨n + (i : ℕ), add_lt_add_left i.2 _⟩) $
λ i j h, lt_iff_coe_lt_coe.2 $ add_lt_add_left h _
@[simp] lemma coe_nat_add (n : ℕ) {m : ℕ} (i : fin m) : (nat_add n i : ℕ) = n + i := rfl
lemma nat_add_zero {n : ℕ} : fin.nat_add 0 = (fin.cast (zero_add n).symm).to_rel_embedding :=
by { ext, apply zero_add }
end succ
section rec
/-!
### recursion and induction principles
-/
/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`.
This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,
and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element
of `n`-tuple. -/
@[elab_as_eliminator] def succ_rec
{C : Π n, fin n → Sort*}
(H0 : Π n, C (succ n) 0)
(Hs : Π n i, C n i → C (succ n) i.succ) : Π {n : ℕ} (i : fin n), C n i
| 0 i := i.elim0
| (succ n) ⟨0, _⟩ := H0 _
| (succ n) ⟨succ i, h⟩ := Hs _ _ (succ_rec ⟨i, lt_of_succ_lt_succ h⟩)
/-- Define `C n i` by induction on `i : fin n` interpreted as `(0 : fin (n - i)).succ.succ…`.
This function has two arguments: `H0 n` defines `0`-th element `C (n+1) 0` of an `(n+1)`-tuple,
and `Hs n i` defines `(i+1)`-st element of `(n+1)`-tuple based on `n`, `i`, and `i`-th element
of `n`-tuple.
A version of `fin.succ_rec` taking `i : fin n` as the first argument. -/
@[elab_as_eliminator] def succ_rec_on {n : ℕ} (i : fin n)
{C : Π n, fin n → Sort*}
(H0 : Π n, C (succ n) 0)
(Hs : Π n i, C n i → C (succ n) i.succ) : C n i :=
i.succ_rec H0 Hs
@[simp] theorem succ_rec_on_zero {C : ∀ n, fin n → Sort*} {H0 Hs} (n) :
@fin.succ_rec_on (succ n) 0 C H0 Hs = H0 n :=
rfl
@[simp] theorem succ_rec_on_succ {C : ∀ n, fin n → Sort*} {H0 Hs} {n} (i : fin n) :
@fin.succ_rec_on (succ n) i.succ C H0 Hs = Hs n i (fin.succ_rec_on i H0 Hs) :=
by cases i; refl
/--
Define `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value.
This function has two arguments: `h0` handles the base case on `C 0`,
and `hs` defines the inductive step using `C i.cast_succ`.
-/
@[elab_as_eliminator] def induction
{C : fin (n + 1) → Sort*}
(h0 : C 0)
(hs : ∀ i : fin n, C i.cast_succ → C i.succ) :
Π (i : fin (n + 1)), C i :=
begin
rintro ⟨i, hi⟩,
induction i with i IH,
{ rwa [fin.mk_zero] },
{ refine hs ⟨i, lt_of_succ_lt_succ hi⟩ _,
exact IH (lt_of_succ_lt hi) }
end
/--
Define `C i` by induction on `i : fin (n + 1)` via induction on the underlying `nat` value.
This function has two arguments: `h0` handles the base case on `C 0`,
and `hs` defines the inductive step using `C i.cast_succ`.
A version of `fin.induction` taking `i : fin (n + 1)` as the first argument.
-/
@[elab_as_eliminator] def induction_on (i : fin (n + 1))
{C : fin (n + 1) → Sort*}
(h0 : C 0)
(hs : ∀ i : fin n, C i.cast_succ → C i.succ) : C i :=
induction h0 hs i
/-- Define `f : Π i : fin n.succ, C i` by separately handling the cases `i = 0` and
`i = j.succ`, `j : fin n`. -/
@[elab_as_eliminator] def cases
{C : fin (succ n) → Sort*} (H0 : C 0) (Hs : Π i : fin n, C (i.succ)) :
Π (i : fin (succ n)), C i :=
induction H0 (λ i _, Hs i)
@[simp] theorem cases_zero {n} {C : fin (succ n) → Sort*} {H0 Hs} : @fin.cases n C H0 Hs 0 = H0 :=
rfl
@[simp] theorem cases_succ {n} {C : fin (succ n) → Sort*} {H0 Hs} (i : fin n) :
@fin.cases n C H0 Hs i.succ = Hs i :=
by cases i; refl
@[simp] theorem cases_succ' {n} {C : fin (succ n) → Sort*} {H0 Hs} {i : ℕ} (h : i + 1 < n + 1) :
@fin.cases n C H0 Hs ⟨i.succ, h⟩ = Hs ⟨i, lt_of_succ_lt_succ h⟩ :=
by cases i; refl
lemma forall_fin_succ {P : fin (n+1) → Prop} :
(∀ i, P i) ↔ P 0 ∧ (∀ i:fin n, P i.succ) :=
⟨λ H, ⟨H 0, λ i, H _⟩, λ ⟨H0, H1⟩ i, fin.cases H0 H1 i⟩
lemma exists_fin_succ {P : fin (n+1) → Prop} :
(∃ i, P i) ↔ P 0 ∨ (∃i:fin n, P i.succ) :=
⟨λ ⟨i, h⟩, fin.cases or.inl (λ i hi, or.inr ⟨i, hi⟩) i h,
λ h, or.elim h (λ h, ⟨0, h⟩) $ λ⟨i, hi⟩, ⟨i.succ, hi⟩⟩
end rec
section pred
/-!
### pred
-/
@[simp] lemma coe_pred (j : fin (n+1)) (h : j ≠ 0) : (j.pred h : ℕ) = j - 1 :=
by { cases j, refl }
@[simp] lemma succ_pred : ∀(i : fin (n+1)) (h : i ≠ 0), (i.pred h).succ = i
| ⟨0, h⟩ hi := by contradiction
| ⟨n + 1, h⟩ hi := rfl
@[simp] lemma pred_succ (i : fin n) {h : i.succ ≠ 0} : i.succ.pred h = i :=
by { cases i, refl }
@[simp] lemma pred_mk_succ (i : ℕ) (h : i < n + 1) :
fin.pred ⟨i + 1, add_lt_add_right h 1⟩ (ne_of_vne (ne_of_gt (mk_succ_pos i h))) = ⟨i, h⟩ :=
by simp only [ext_iff, coe_pred, coe_mk, nat.add_sub_cancel]
-- This is not a simp lemma by default, because `pred_mk_succ` is nicer when it applies.
lemma pred_mk {n : ℕ} (i : ℕ) (h : i < n + 1) (w) :
fin.pred ⟨i, h⟩ w =
⟨i - 1, by rwa nat.sub_lt_right_iff_lt_add (nat.pos_of_ne_zero (fin.vne_of_ne w))⟩ :=
rfl
@[simp] lemma pred_le_pred_iff {n : ℕ} {a b : fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :
a.pred ha ≤ b.pred hb ↔ a ≤ b :=
by rw [←succ_le_succ_iff, succ_pred, succ_pred]
@[simp] lemma pred_lt_pred_iff {n : ℕ} {a b : fin n.succ} {ha : a ≠ 0} {hb : b ≠ 0} :
a.pred ha < b.pred hb ↔ a < b :=
by rw [←succ_lt_succ_iff, succ_pred, succ_pred]
@[simp] lemma pred_inj :
∀ {a b : fin (n + 1)} {ha : a ≠ 0} {hb : b ≠ 0}, a.pred ha = b.pred hb ↔ a = b
| ⟨0, _⟩ b ha hb := by contradiction
| ⟨i+1, _⟩ ⟨0, _⟩ ha hb := by contradiction
| ⟨i+1, hi⟩ ⟨j+1, hj⟩ ha hb := by simp [fin.eq_iff_veq]
@[simp] lemma pred_one {n : ℕ} : fin.pred (1 : fin (n + 2)) (ne.symm (ne_of_lt one_pos)) = 0 := rfl
lemma pred_add_one (i : fin (n + 2)) (h : (i : ℕ) < n + 1) :
pred (i + 1) (ne_of_gt (add_one_pos _ (lt_iff_coe_lt_coe.mpr h))) = cast_lt i h :=
begin
rw [ext_iff, coe_pred, coe_cast_lt, coe_add, coe_one, mod_eq_of_lt, nat.add_sub_cancel],
exact add_lt_add_right h 1,
end
/-- `sub_nat i h` subtracts `m` from `i`, generalizes `fin.pred`. -/
def sub_nat (m) (i : fin (n + m)) (h : m ≤ (i : ℕ)) : fin n :=
⟨(i : ℕ) - m, by { rw [nat.sub_lt_right_iff_lt_add h], exact i.is_lt }⟩
@[simp] lemma coe_sub_nat (i : fin (n + m)) (h : m ≤ i) : (i.sub_nat m h : ℕ) = i - m :=
rfl
@[simp] lemma pred_cast_succ_succ (i : fin n) :
pred (cast_succ i.succ) (ne_of_gt (cast_succ_pos i.succ_pos)) = i.cast_succ :=
by simp [eq_iff_veq]
end pred
section add_group
open nat int
/-- Negation on `fin n` -/
instance (n : ℕ) : has_neg (fin n) :=
⟨λ a, ⟨(n - a) % n, nat.mod_lt _ (lt_of_le_of_lt (nat.zero_le _) a.2)⟩⟩
/-- Abelian group structure on `fin (n+1)`. -/
instance (n : ℕ) : add_comm_group (fin (n+1)) :=
{ add_left_neg := λ ⟨a, ha⟩, fin.ext $ trans (nat.mod_add_mod _ _ _) $
by { rw [fin.coe_mk, fin.coe_zero, nat.sub_add_cancel, nat.mod_self], exact le_of_lt ha },
sub_eq_add_neg := λ ⟨a, ha⟩ ⟨b, hb⟩, fin.ext $
show (a + (n + 1 - b)) % (n + 1) = (a + (n + 1 - b) % (n + 1)) % (n + 1), by simp,
sub := fin.sub,
..fin.add_comm_monoid n,
..fin.has_neg n.succ }
protected lemma coe_neg (a : fin n) : ((-a : fin n) : ℕ) = (n - a) % n := rfl
protected lemma coe_sub (a b : fin n) : ((a - b : fin n) : ℕ) = (a + (n - b)) % n :=
by cases a; cases b; refl
end add_group
section succ_above
lemma succ_above_aux (p : fin (n + 1)) :
strict_mono (λ i : fin n, if i.cast_succ < p then i.cast_succ else i.succ) :=
(cast_succ : fin n ↪o _).strict_mono.ite (succ_embedding n).strict_mono
(λ i j hij hj, lt_trans ((cast_succ : fin n ↪o _).lt_iff_lt.2 hij) hj)
(λ i, (cast_succ_lt_succ i).le)
/-- `succ_above p i` embeds `fin n` into `fin (n + 1)` with a hole around `p`. -/
def succ_above (p : fin (n + 1)) : fin n ↪o fin (n + 1) :=
order_embedding.of_strict_mono _ p.succ_above_aux
/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`
embeds `i` by `cast_succ` when the resulting `i.cast_succ < p`. -/
lemma succ_above_below (p : fin (n + 1)) (i : fin n) (h : i.cast_succ < p) :
p.succ_above i = i.cast_succ :=
by { rw [succ_above], exact if_pos h }
@[simp] lemma succ_above_ne_zero_zero {a : fin (n + 2)} (ha : a ≠ 0) : a.succ_above 0 = 0 :=
begin
rw fin.succ_above_below,
{ refl },
{ exact bot_lt_iff_ne_bot.mpr ha }
end
lemma succ_above_eq_zero_iff {a : fin (n + 2)} {b : fin (n + 1)} (ha : a ≠ 0) :
a.succ_above b = 0 ↔ b = 0 :=
by simp only [←succ_above_ne_zero_zero ha, order_embedding.eq_iff_eq]
lemma succ_above_ne_zero {a : fin (n + 2)} {b : fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0) :
a.succ_above b ≠ 0 :=
mt (succ_above_eq_zero_iff ha).mp hb
/-- Embedding `fin n` into `fin (n + 1)` with a hole around zero embeds by `succ`. -/
@[simp] lemma succ_above_zero : ⇑(succ_above (0 : fin (n + 1))) = fin.succ := rfl
/-- Embedding `fin n` into `fin (n + 1)` with a hole around `last n` embeds by `cast_succ`. -/
@[simp] lemma succ_above_last : succ_above (fin.last n) = cast_succ :=
by { ext, simp only [succ_above_below, cast_succ_lt_last] }
lemma succ_above_last_apply (i : fin n) : succ_above (fin.last n) i = i.cast_succ :=
by rw succ_above_last
/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`
embeds `i` by `succ` when the resulting `p < i.succ`. -/
lemma succ_above_above (p : fin (n + 1)) (i : fin n) (h : p ≤ i.cast_succ) :
p.succ_above i = i.succ :=
by simp [succ_above, h.not_lt]
/-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p`. -/
lemma succ_above_lt_ge (p : fin (n + 1)) (i : fin n) : i.cast_succ < p ∨ p ≤ i.cast_succ :=
lt_or_ge (cast_succ i) p
/-- Embedding `i : fin n` into `fin (n + 1)` is always about some hole `p`. -/
lemma succ_above_lt_gt (p : fin (n + 1)) (i : fin n) : i.cast_succ < p ∨ p < i.succ :=
or.cases_on (succ_above_lt_ge p i)
(λ h, or.inl h) (λ h, or.inr (lt_of_le_of_lt h (cast_succ_lt_succ i)))
/-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is greater
results in a value that is less than `p`. -/
@[simp] lemma succ_above_lt_iff (p : fin (n + 1)) (i : fin n) :
p.succ_above i < p ↔ i.cast_succ < p :=
begin
refine iff.intro _ _,
{ intro h,
cases succ_above_lt_ge p i with H H,
{ exact H },
{ rw succ_above_above _ _ H at h,
exact lt_trans (cast_succ_lt_succ i) h } },
{ intro h,
rw succ_above_below _ _ h,
exact h }
end
/-- Embedding `i : fin n` into `fin (n + 1)` using a pivot `p` that is lesser
results in a value that is greater than `p`. -/
lemma lt_succ_above_iff (p : fin (n + 1)) (i : fin n) : p < p.succ_above i ↔ p ≤ i.cast_succ :=
begin
refine iff.intro _ _,
{ intro h,
cases succ_above_lt_ge p i with H H,
{ rw succ_above_below _ _ H at h,
exact le_of_lt h },
{ exact H } },
{ intro h,
rw succ_above_above _ _ h,
exact lt_of_le_of_lt h (cast_succ_lt_succ i) },
end
/-- Embedding `i : fin n` into `fin (n + 1)` with a hole around `p : fin (n + 1)`
never results in `p` itself -/
theorem succ_above_ne (p : fin (n + 1)) (i : fin n) : p.succ_above i ≠ p :=
begin
intro eq,
by_cases H : i.cast_succ < p,
{ simpa [lt_irrefl, ←succ_above_below _ _ H, eq] using H },
{ simpa [←succ_above_above _ _ (le_of_not_lt H), eq] using cast_succ_lt_succ i }
end
/-- Embedding a positive `fin n` results in a positive fin (n + 1)` -/
lemma succ_above_pos (p : fin (n + 2)) (i : fin (n + 1)) (h : 0 < i) : 0 < p.succ_above i :=
begin
by_cases H : i.cast_succ < p,
{ simpa [succ_above_below _ _ H] using cast_succ_pos h },
{ simpa [succ_above_above _ _ (le_of_not_lt H)] using succ_pos _ },
end
/-- The range of `p.succ_above` is everything except `p`. -/
lemma range_succ_above (p : fin (n + 1)) : set.range (p.succ_above) = { i | i ≠ p } :=
begin
ext,
simp only [set.mem_range, ne.def, set.mem_set_of_eq],
split,
{ rintro ⟨y, rfl⟩,
exact succ_above_ne _ _ },
{ intro h,
cases lt_or_gt_of_ne h with H H,
{ refine ⟨x.cast_lt _, _⟩,
{ exact lt_of_lt_of_le H p.le_last },
{ rw succ_above_below,
{ simp },
{ exact H } } },
{ refine ⟨x.pred _, _⟩,
{ exact (ne_of_lt (lt_of_le_of_lt p.zero_le H)).symm },
{ rw succ_above_above,
{ simp },
{ simpa [le_iff_coe_le_coe] using nat.le_pred_of_lt H } } } }
end
/-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/
lemma succ_above_right_injective {x : fin (n + 1)} : injective (succ_above x) :=
(succ_above x).injective
/-- Given a fixed pivot `x : fin (n + 1)`, `x.succ_above` is injective -/
lemma succ_above_right_inj {x : fin (n + 1)} :
x.succ_above a = x.succ_above b ↔ a = b :=
succ_above_right_injective.eq_iff
/-- `succ_above` is injective at the pivot -/
lemma succ_above_left_injective : injective (@succ_above n) :=
λ _ _ h, by simpa [range_succ_above] using congr_arg (λ f : fin n ↪o fin (n + 1), (set.range f)ᶜ) h
/-- `succ_above` is injective at the pivot -/
lemma succ_above_left_inj {x y : fin (n + 1)} :
x.succ_above = y.succ_above ↔ x = y :=
succ_above_left_injective.eq_iff
@[simp] lemma zero_succ_above {n : ℕ} (i : fin n) :
(0 : fin (n + 1)).succ_above i = i.succ :=
rfl
@[simp] lemma succ_succ_above_zero {n : ℕ} (i : fin (n + 1)) :
(i.succ).succ_above 0 = 0 :=
succ_above_below _ _ (succ_pos _)
@[simp] lemma succ_succ_above_succ {n : ℕ} (i : fin (n + 1)) (j : fin n) :
(i.succ).succ_above j.succ = (i.succ_above j).succ :=
(lt_or_ge j.cast_succ i).elim
(λ h, have h' : j.succ.cast_succ < i.succ, by simpa [lt_iff_coe_lt_coe] using h,
by { ext, simp [succ_above_below _ _ h, succ_above_below _ _ h'] })
(λ h, have h' : i.succ ≤ j.succ.cast_succ, by simpa [le_iff_coe_le_coe] using h,
by { ext, simp [succ_above_above _ _ h, succ_above_above _ _ h'] })
@[simp] lemma one_succ_above_zero {n : ℕ} :
(1 : fin (n + 2)).succ_above 0 = 0 :=
succ_succ_above_zero 0
/-- By moving `succ` to the outside of this expression, we create opportunities for further
simplification using `succ_above_zero` or `succ_succ_above_zero`. -/
@[simp] lemma succ_succ_above_one {n : ℕ} (i : fin (n + 2)) :
(i.succ).succ_above 1 = (i.succ_above 0).succ :=
succ_succ_above_succ i 0
@[simp] lemma one_succ_above_succ {n : ℕ} (j : fin n) :
(1 : fin (n + 2)).succ_above j.succ = j.succ.succ :=
succ_succ_above_succ 0 j
@[simp] lemma one_succ_above_one {n : ℕ} :
(1 : fin (n + 3)).succ_above 1 = 2 :=
succ_succ_above_succ 0 0
end succ_above
section pred_above
/-- `pred_above p i` embeds `i : fin (n+1)` into `fin n` by subtracting one if `p < i`. -/
def pred_above (p : fin n) (i : fin (n+1)) : fin n :=
if h : p.cast_succ < i then
i.pred (ne_of_lt (lt_of_le_of_lt (zero_le p.cast_succ) h)).symm
else
i.cast_lt (lt_of_le_of_lt (le_of_not_lt h) p.2)
lemma pred_above_right_monotone (p : fin n) : monotone p.pred_above :=
λ a b H,
begin
dsimp [pred_above],
split_ifs with ha hb hb,
all_goals { simp only [le_iff_coe_le_coe, coe_pred], },
{ exact pred_le_pred H, },
{ calc _ ≤ _ : nat.pred_le _
... ≤ _ : H, },
{ simp at ha, exact le_pred_of_lt (lt_of_le_of_lt ha hb), },
{ exact H, },
end
lemma pred_above_left_monotone (i : fin (n + 1)) : monotone (λ p, pred_above p i) :=
λ a b H,
begin
dsimp [pred_above],
split_ifs with ha hb hb,
all_goals { simp only [le_iff_coe_le_coe, coe_pred] },
{ exact pred_le _, },
{ have : b < a := cast_succ_lt_cast_succ_iff.mpr (hb.trans_le (le_of_not_gt ha)),
exact absurd H this.not_le }
end
/-- `cast_pred` embeds `i : fin (n + 2)` into `fin (n + 1)`
by lowering just `last (n + 1)` to `last n`. -/
def cast_pred (i : fin (n + 2)) : fin (n + 1) :=
pred_above (last n) i
@[simp] lemma cast_pred_zero : cast_pred (0 : fin (n + 2)) = 0 := rfl
@[simp] lemma cast_pred_one : cast_pred (1 : fin (n + 2)) = 1 :=
by { cases n, apply subsingleton.elim, refl }
@[simp] theorem pred_above_zero {i : fin (n + 2)} (hi : i ≠ 0) :
pred_above 0 i = i.pred hi :=
begin
dsimp [pred_above],
rw dif_pos,
exact (pos_iff_ne_zero _).mpr hi,
end
@[simp] lemma cast_pred_last : cast_pred (last (n + 1)) = last n :=
by simp [eq_iff_veq, cast_pred, pred_above, cast_succ_lt_last]
@[simp] lemma cast_pred_mk (n i : ℕ) (h : i < n + 1) :
cast_pred ⟨i, lt_succ_of_lt h⟩ = ⟨i, h⟩ :=
begin
have : ¬cast_succ (last n) < ⟨i, lt_succ_of_lt h⟩,
{ simpa [lt_iff_coe_lt_coe] using le_of_lt_succ h },
simp [cast_pred, pred_above, this]
end
lemma pred_above_below (p : fin (n + 1)) (i : fin (n + 2)) (h : i ≤ p.cast_succ) :
p.pred_above i = i.cast_pred :=
begin
have : i ≤ (last n).cast_succ := h.trans p.le_last,
simp [pred_above, cast_pred, h.not_lt, this.not_lt]
end
@[simp] lemma pred_above_last : pred_above (fin.last n) = cast_pred := rfl
lemma pred_above_last_apply (i : fin n) : pred_above (fin.last n) i = i.cast_pred :=
by rw pred_above_last
lemma pred_above_above (p : fin n) (i : fin (n + 1)) (h : p.cast_succ < i) :
p.pred_above i = i.pred (p.cast_succ.zero_le.trans_lt h).ne.symm :=
by simp [pred_above, h]
lemma cast_pred_monotone : monotone (@cast_pred n) :=
pred_above_right_monotone (last _)
/-- Sending `fin (n+1)` to `fin n` by subtracting one from anything above `p`
then back to `fin (n+1)` with a gap around `p` is the identity away from `p`. -/
@[simp] lemma succ_above_pred_above {p : fin n} {i : fin (n + 1)} (h : i ≠ p.cast_succ) :
p.cast_succ.succ_above (p.pred_above i) = i :=
begin
dsimp [pred_above, succ_above],
rcases p with ⟨p, _⟩,
rcases i with ⟨i, _⟩,
cases lt_or_le i p with H H,
{ rw dif_neg, rw if_pos, refl, exact H, simp, apply le_of_lt H, },
{ rw dif_pos, rw if_neg,
swap 3, -- For some reason `simp` doesn't fire fully unless we discharge the third goal.
{ exact lt_of_le_of_ne H (ne.symm h), },
{ simp, },
{ simp only [subtype.mk_eq_mk, ne.def, fin.cast_succ_mk] at h,
simp only [pred, subtype.mk_lt_mk, not_lt],
exact nat.le_pred_of_lt (nat.lt_of_le_and_ne H (ne.symm h)), }, },
end
/-- Sending `fin n` into `fin (n + 1)` with a gap at `p`
then back to `fin n` by subtracting one from anything above `p` is the identity. -/
@[simp] lemma pred_above_succ_above (p : fin n) (i : fin n) :
p.pred_above (p.cast_succ.succ_above i) = i :=
begin
dsimp [pred_above, succ_above],
rcases p with ⟨p, _⟩,
rcases i with ⟨i, _⟩,
split_ifs,
{ rw dif_neg,
{ refl },
{ simp_rw [if_pos h],
simp only [subtype.mk_lt_mk, not_lt],
exact le_of_lt h, }, },
{ rw dif_pos,
{ refl, },
{ simp_rw [if_neg h],
exact lt_succ_iff.mpr (not_lt.mp h), }, },
end
lemma cast_succ_pred_eq_pred_cast_succ {a : fin (n + 1)} (ha : a ≠ 0)
(ha' := a.cast_succ_ne_zero_iff.mpr ha) : (a.pred ha).cast_succ = a.cast_succ.pred ha' :=
by { cases a, refl }
/-- `pred` commutes with `succ_above`. -/
lemma pred_succ_above_pred {a : fin (n + 2)} {b : fin (n + 1)} (ha : a ≠ 0) (hb : b ≠ 0)
(hk := succ_above_ne_zero ha hb) :
(a.pred ha).succ_above (b.pred hb) = (a.succ_above b).pred hk :=
begin
obtain hbelow | habove := lt_or_le b.cast_succ a, -- `rwa` uses them
{ rw fin.succ_above_below,
{ rwa [cast_succ_pred_eq_pred_cast_succ , fin.pred_inj, fin.succ_above_below] },
{ rwa [cast_succ_pred_eq_pred_cast_succ , pred_lt_pred_iff] } },
{ rw fin.succ_above_above,
have : (b.pred hb).succ = b.succ.pred (fin.succ_ne_zero _), by rw [succ_pred, pred_succ],
{ rwa [this, fin.pred_inj, fin.succ_above_above] },
{ rwa [cast_succ_pred_eq_pred_cast_succ , fin.pred_le_pred_iff] } }
end
@[simp] theorem cast_pred_cast_succ (i : fin (n + 1)) :
cast_pred i.cast_succ = i :=
by simp [cast_pred, pred_above, le_last]
lemma cast_succ_cast_pred {i : fin (n + 2)} (h : i < last _) : cast_succ i.cast_pred = i :=
begin
rw [cast_pred, pred_above, dif_neg],
{ simp [fin.eq_iff_veq] },
{ exact h.not_le }
end
lemma coe_cast_pred_le_self (i : fin (n + 2)) : (i.cast_pred : ℕ) ≤ i :=
begin
rcases i.le_last.eq_or_lt with rfl|h,
{ simp },
{ rw [cast_pred, pred_above, dif_neg],
{ simp },
{ simpa [lt_iff_coe_lt_coe, le_iff_coe_le_coe, lt_succ_iff] using h } }
end
lemma coe_cast_pred_lt_iff {i : fin (n + 2)} : (i.cast_pred : ℕ) < i ↔ i = fin.last _ :=
begin
rcases i.le_last.eq_or_lt with rfl|H,
{ simp },
{ simp only [ne_of_lt H],
rw ←cast_succ_cast_pred H,
simp }
end
lemma lt_last_iff_coe_cast_pred {i : fin (n + 2)} : i < fin.last _ ↔ (i.cast_pred : ℕ) = i :=
begin
rcases i.le_last.eq_or_lt with rfl|H,
{ simp },
{ simp only [H],
rw ←cast_succ_cast_pred H,
simp }
end
lemma forall_iff_succ_above {p : fin (n + 1) → Prop} (i : fin (n + 1)) :
(∀ j, p j) ↔ p i ∧ ∀ j, p (i.succ_above j) :=
⟨λ h, ⟨h _, λ j, h _⟩,
λ h j, if hj : j = i then (hj.symm ▸ h.1) else
begin
cases n,
{ convert h.1 },
{ cases lt_or_gt_of_ne hj with lt gt,
{ rcases j.zero_le.eq_or_lt with rfl|H,
{ convert h.2 0, rw succ_above_below; simp [lt] },
{ have ltl : j < last _ := lt.trans_le i.le_last,
convert h.2 j.cast_pred,
simp [succ_above_below, cast_succ_cast_pred ltl, lt] } },
{ convert h.2 (j.pred (i.zero_le.trans_lt gt).ne.symm),
rw succ_above_above;
simp [le_cast_succ_iff, gt.lt] } }
end⟩
end pred_above
/-- `min n m` as an element of `fin (m + 1)` -/
def clamp (n m : ℕ) : fin (m + 1) := of_nat $ min n m
@[simp] lemma coe_clamp (n m : ℕ) : (clamp n m : ℕ) = min n m :=
nat.mod_eq_of_lt $ nat.lt_succ_iff.mpr $ min_le_right _ _
section tuple
/-!
### Tuples
We can think of the type `Π(i : fin n), α i` as `n`-tuples of elements of possibly varying type
`α i`. A particular case is `fin n → α` of elements with all the same type. Here are some relevant
operations, first about adding or removing elements at the beginning of a tuple.
-/
/-- There is exactly one tuple of size zero. -/
example (α : fin 0 → Sort u) : unique (Π i : fin 0, α i) :=
by apply_instance
@[simp] lemma tuple0_le {α : Π i : fin 0, Type*} [Π i, preorder (α i)] (f g : Π i, α i) : f ≤ g :=
fin_zero_elim
variables {α : fin (n+1) → Type u} (x : α 0) (q : Πi, α i) (p : Π(i : fin n), α (i.succ))
(i : fin n) (y : α i.succ) (z : α 0)
/-- The tail of an `n+1` tuple, i.e., its last `n` entries. -/
def tail (q : Πi, α i) : (Π(i : fin n), α (i.succ)) := λ i, q i.succ
lemma tail_def {n : ℕ} {α : fin (n+1) → Type*} {q : Π i, α i} :
tail (λ k : fin (n+1), q k) = (λ k : fin n, q k.succ) := rfl
/-- Adding an element at the beginning of an `n`-tuple, to get an `n+1`-tuple. -/
def cons (x : α 0) (p : Π(i : fin n), α (i.succ)) : Πi, α i :=
λ j, fin.cases x p j
@[simp] lemma tail_cons : tail (cons x p) = p :=
by simp [tail, cons]
@[simp] lemma cons_succ : cons x p i.succ = p i :=
by simp [cons]
@[simp] lemma cons_zero : cons x p 0 = x :=
by simp [cons]
/-- Updating a tuple and adding an element at the beginning commute. -/
@[simp] lemma cons_update : cons x (update p i y) = update (cons x p) i.succ y :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp [ne.symm (succ_ne_zero i)] },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ],
by_cases h' : j' = i,
{ rw h', simp },
{ have : j'.succ ≠ i.succ, by rwa [ne.def, succ_inj],
rw [update_noteq h', update_noteq this, cons_succ] } }
end
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it
directly. -/
lemma update_cons_zero : update (cons x p) 0 z = cons z p :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp },
{ simp only [h, update_noteq, ne.def, not_false_iff],
let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ, cons_succ] }
end
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp] lemma cons_self_tail : cons (q 0) (tail q) = q :=
begin
ext j,
by_cases h : j = 0,
{ rw h, simp },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, tail, cons_succ] }
end
/-- Updating the first element of a tuple does not change the tail. -/
@[simp] lemma tail_update_zero : tail (update q 0 z) = tail q :=
by { ext j, simp [tail, fin.succ_ne_zero] }
/-- Updating a nonzero element and taking the tail commute. -/
@[simp] lemma tail_update_succ :
tail (update q i.succ y) = update (tail q) i y :=
begin
ext j,
by_cases h : j = i,
{ rw h, simp [tail] },
{ simp [tail, (fin.succ_injective n).ne h, h] }
end
lemma comp_cons {α : Type*} {β : Type*} (g : α → β) (y : α) (q : fin n → α) :
g ∘ (cons y q) = cons (g y) (g ∘ q) :=
begin
ext j,
by_cases h : j = 0,
{ rw h, refl },
{ let j' := pred j h,
have : j'.succ = j := succ_pred j h,
rw [← this, cons_succ, comp_app, cons_succ] }
end
lemma comp_tail {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :
g ∘ (tail q) = tail (g ∘ q) :=
by { ext j, simp [tail] }
lemma le_cons [Π i, preorder (α i)] {x : α 0} {q : Π i, α i} {p : Π i : fin n, α i.succ} :
q ≤ cons x p ↔ q 0 ≤ x ∧ tail q ≤ p :=
forall_fin_succ.trans $ and_congr iff.rfl $ forall_congr $ λ j, by simp [tail]
lemma cons_le [Π i, preorder (α i)] {x : α 0} {q : Π i, α i} {p : Π i : fin n, α i.succ} :
cons x p ≤ q ↔ x ≤ q 0 ∧ p ≤ tail q :=
@le_cons _ (λ i, order_dual (α i)) _ x q p
@[simp]
lemma range_cons {α : Type*} {n : ℕ} (x : α) (b : fin n → α) :
set.range (fin.cons x b : fin n.succ → α) = insert x (set.range b) :=
begin
ext y,
simp only [set.mem_range, set.mem_insert_iff],
split,
{ rintros ⟨i, rfl⟩,
refine cases (or.inl (cons_zero _ _)) (λ i, or.inr ⟨i, _⟩) i,
rw cons_succ },
{ rintros (rfl | ⟨i, hi⟩),
{ exact ⟨0, fin.cons_zero _ _⟩ },
{ refine ⟨i.succ, _⟩,
rw [cons_succ, hi] } }
end
/-- `fin.append ho u v` appends two vectors of lengths `m` and `n` to produce
one of length `o = m + n`. `ho` provides control of definitional equality
for the vector length. -/
def append {α : Type*} {o : ℕ} (ho : o = m + n) (u : fin m → α) (v : fin n → α) : fin o → α :=
λ i, if h : (i : ℕ) < m
then u ⟨i, h⟩
else v ⟨(i : ℕ) - m, (nat.sub_lt_left_iff_lt_add (le_of_not_lt h)).2 (ho ▸ i.property)⟩
@[simp] lemma fin_append_apply_zero {α : Type*} {o : ℕ} (ho : (o + 1) = (m + 1) + n)
(u : fin (m + 1) → α) (v : fin n → α) :
fin.append ho u v 0 = u 0 := rfl
end tuple
section tuple_right
/-! In the previous section, we have discussed inserting or removing elements on the left of a
tuple. In this section, we do the same on the right. A difference is that `fin (n+1)` is constructed
inductively from `fin n` starting from the left, not from the right. This implies that Lean needs
more help to realize that elements belong to the right types, i.e., we need to insert casts at
several places. -/
variables {α : fin (n+1) → Type u} (x : α (last n)) (q : Πi, α i) (p : Π(i : fin n), α i.cast_succ)
(i : fin n) (y : α i.cast_succ) (z : α (last n))
/-- The beginning of an `n+1` tuple, i.e., its first `n` entries -/
def init (q : Πi, α i) (i : fin n) : α i.cast_succ :=
q i.cast_succ
lemma init_def {n : ℕ} {α : fin (n+1) → Type*} {q : Π i, α i} :
init (λ k : fin (n+1), q k) = (λ k : fin n, q k.cast_succ) := rfl
/-- Adding an element at the end of an `n`-tuple, to get an `n+1`-tuple. The name `snoc` comes from
`cons` (i.e., adding an element to the left of a tuple) read in reverse order. -/
def snoc (p : Π(i : fin n), α i.cast_succ) (x : α (last n)) (i : fin (n+1)) : α i :=
if h : i.val < n
then _root_.cast (by rw fin.cast_succ_cast_lt i h) (p (cast_lt i h))
else _root_.cast (by rw eq_last_of_not_lt h) x
@[simp] lemma init_snoc : init (snoc p x) = p :=
begin
ext i,
have h' := fin.cast_lt_cast_succ i i.is_lt,
simp [init, snoc, i.is_lt, h'],
convert cast_eq rfl (p i)
end
@[simp] lemma snoc_cast_succ : snoc p x i.cast_succ = p i :=
begin
have : i.cast_succ.val < n := i.is_lt,
have h' := fin.cast_lt_cast_succ i i.is_lt,
simp [snoc, this, h'],
convert cast_eq rfl (p i)
end
@[simp] lemma snoc_last : snoc p x (last n) = x :=
by { simp [snoc] }
/-- Updating a tuple and adding an element at the end commute. -/
@[simp] lemma snoc_update : snoc (update p i y) x = update (snoc p x) i.cast_succ y :=
begin
ext j,
by_cases h : j.val < n,
{ simp only [snoc, h, dif_pos],
by_cases h' : j = cast_succ i,
{ have C1 : α i.cast_succ = α j, by rw h',
have E1 : update (snoc p x) i.cast_succ y j = _root_.cast C1 y,
{ have : update (snoc p x) j (_root_.cast C1 y) j = _root_.cast C1 y, by simp,
convert this,
{ exact h'.symm },
{ exact heq_of_cast_eq (congr_arg α (eq.symm h')) rfl } },
have C2 : α i.cast_succ = α (cast_succ (cast_lt j h)),
by rw [cast_succ_cast_lt, h'],
have E2 : update p i y (cast_lt j h) = _root_.cast C2 y,
{ have : update p (cast_lt j h) (_root_.cast C2 y) (cast_lt j h) = _root_.cast C2 y,
by simp,
convert this,
{ simp [h, h'] },
{ exact heq_of_cast_eq C2 rfl } },
rw [E1, E2],
exact eq_rec_compose _ _ _ },
{ have : ¬(cast_lt j h = i),
by { assume E, apply h', rw [← E, cast_succ_cast_lt] },
simp [h', this, snoc, h] } },
{ rw eq_last_of_not_lt h,
simp [ne.symm (ne_of_lt (cast_succ_lt_last i))] }
end
/-- Adding an element at the beginning of a tuple and then updating it amounts to adding it
directly. -/
lemma update_snoc_last : update (snoc p x) (last n) z = snoc p z :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, update_noteq, this, snoc] },
{ rw eq_last_of_not_lt h,
simp }
end
/-- Concatenating the first element of a tuple with its tail gives back the original tuple -/
@[simp] lemma snoc_init_self : snoc (init q) (q (last n)) = q :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, update_noteq, this, snoc, init, cast_succ_cast_lt],
have A : cast_succ (cast_lt j h) = j := cast_succ_cast_lt _ _,
rw ← cast_eq rfl (q j),
congr' 1; rw A },
{ rw eq_last_of_not_lt h,
simp }
end
/-- Updating the last element of a tuple does not change the beginning. -/
@[simp] lemma init_update_last : init (update q (last n) z) = init q :=
by { ext j, simp [init, ne_of_lt, cast_succ_lt_last] }
/-- Updating an element and taking the beginning commute. -/
@[simp] lemma init_update_cast_succ :
init (update q i.cast_succ y) = update (init q) i y :=
begin
ext j,
by_cases h : j = i,
{ rw h, simp [init] },
{ simp [init, h] }
end
/-- `tail` and `init` commute. We state this lemma in a non-dependent setting, as otherwise it
would involve a cast to convince Lean that the two types are equal, making it harder to use. -/
lemma tail_init_eq_init_tail {β : Type*} (q : fin (n+2) → β) :
tail (init q) = init (tail q) :=
by { ext i, simp [tail, init, cast_succ_fin_succ] }
/-- `cons` and `snoc` commute. We state this lemma in a non-dependent setting, as otherwise it
would involve a cast to convince Lean that the two types are equal, making it harder to use. -/
lemma cons_snoc_eq_snoc_cons {β : Type*} (a : β) (q : fin n → β) (b : β) :
@cons n.succ (λ i, β) a (snoc q b) = snoc (cons a q) b :=
begin
ext i,
by_cases h : i = 0,
{ rw h, refl },
set j := pred i h with ji,
have : i = j.succ, by rw [ji, succ_pred],
rw [this, cons_succ],
by_cases h' : j.val < n,
{ set k := cast_lt j h' with jk,
have : j = k.cast_succ, by rw [jk, cast_succ_cast_lt],
rw [this, ← cast_succ_fin_succ],
simp },
rw [eq_last_of_not_lt h', succ_last],
simp
end
lemma comp_snoc {α : Type*} {β : Type*} (g : α → β) (q : fin n → α) (y : α) :
g ∘ (snoc q y) = snoc (g ∘ q) (g y) :=
begin
ext j,
by_cases h : j.val < n,
{ have : j ≠ last n := ne_of_lt h,
simp [h, this, snoc, cast_succ_cast_lt] },
{ rw eq_last_of_not_lt h,
simp }
end
lemma comp_init {α : Type*} {β : Type*} (g : α → β) (q : fin n.succ → α) :
g ∘ (init q) = init (g ∘ q) :=
by { ext j, simp [init] }
end tuple_right
section insert_nth
variables {α : fin (n+1) → Type u} {β : Type v}
/-- Insert an element into a tuple at a given position, auxiliary definition.
For the general definition, see `insert_nth`. -/
def insert_nth' {α : fin (n + 2) → Type u} (i : fin (n + 2)) (x : α i)
(p : Π j : fin (n + 1), α (i.succ_above j)) (j : fin (n + 2)) : α j :=
if h : i = j
then _root_.cast (congr_arg α h) x
else if h' : j < i then _root_.cast (congr_arg α $ begin
obtain ⟨k, hk⟩ : ∃ (k : fin (n + 1)), k.cast_succ = j,
{ refine ⟨⟨(j : ℕ), _⟩, _⟩,
{ exact lt_of_lt_of_le h' i.is_le, },
{ simp },
},
subst hk,
simp [succ_above_below, h'],
end)
(p j.cast_pred) else _root_.cast (congr_arg α $ begin
have lt : i < j := lt_of_le_of_ne (le_of_not_lt h') h,
have : j ≠ 0 := (ne_of_gt (lt_of_le_of_lt i.zero_le lt)),
rw [←succ_pred j this, ←le_cast_succ_iff] at lt,
simp [pred_above_zero this, succ_above_above _ _ lt]
end) (p (fin.pred_above 0 j))
/-- Insert an element into a tuple at a given position. For `i = 0` see `fin.cons`,
for `i = fin.last n` see `fin.snoc`. -/
def insert_nth : Π {n : ℕ} {α : fin (n + 1) → Type u} (i : fin (n + 1)) (x : α i)
(p : Π j : fin n, α (i.succ_above j)) (j : fin (n + 1)), α j
| 0 _ _ x _ _ := _root_.cast (by congr) x
| (n + 1) _ i x p j := insert_nth' i x p j
@[simp] lemma insert_nth_apply_same (i : fin (n + 1)) (x : α i) (p : Π j, α (i.succ_above j)) :
insert_nth i x p i = x :=
by { cases n; simp [insert_nth, insert_nth'] }
@[simp] lemma insert_nth_apply_succ_above (i : fin (n + 1)) (x : α i) (p : Π j, α (i.succ_above j))
(j : fin n) :
insert_nth i x p (i.succ_above j) = p j :=
begin
cases n,
{ exact j.elim0 },
simp only [insert_nth, insert_nth', dif_neg (succ_above_ne _ _).symm],
cases succ_above_lt_ge i j with h h,
{ rw dif_pos,
refine eq_of_heq ((cast_heq _ _).trans _),
{ simp [h] },
{ congr,
simp [succ_above_below, h] } },
{ rw dif_neg,
refine eq_of_heq ((cast_heq _ _).trans _),
{ simp [h] },
{ congr,
simp [succ_above_above, h, succ_ne_zero] } }
end
@[simp] lemma insert_nth_comp_succ_above (i : fin (n + 1)) (x : β) (p : fin n → β) :
insert_nth i x p ∘ i.succ_above = p :=
funext $ insert_nth_apply_succ_above i x p
lemma insert_nth_eq_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :
i.insert_nth x p = q ↔ q i = x ∧ p = (λ j, q (i.succ_above j)) :=
by simp [funext_iff, forall_iff_succ_above i, eq_comm]
lemma eq_insert_nth_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :
q = i.insert_nth x p ↔ q i = x ∧ p = (λ j, q (i.succ_above j)) :=
eq_comm.trans insert_nth_eq_iff
lemma insert_nth_zero (x : α 0) (p : Π j : fin n, α (succ_above 0 j)) :
insert_nth 0 x p = cons x (λ j, _root_.cast (congr_arg α (congr_fun succ_above_zero j)) (p j)) :=
begin
refine insert_nth_eq_iff.2 ⟨by simp, _⟩,
ext j,
convert (cons_succ _ _ _).symm
end
@[simp] lemma insert_nth_zero' (x : β) (p : fin n → β) :
@insert_nth _ (λ _, β) 0 x p = cons x p :=
by simp [insert_nth_zero]
lemma insert_nth_last (x : α (last n)) (p : Π j : fin n, α ((last n).succ_above j)) :
insert_nth (last n) x p =
snoc (λ j, _root_.cast (congr_arg α (succ_above_last_apply j)) (p j)) x :=
begin
refine insert_nth_eq_iff.2 ⟨by simp, _⟩,
ext j,
apply eq_of_heq,
transitivity snoc (λ j, _root_.cast (congr_arg α (succ_above_last_apply j)) (p j)) x j.cast_succ,
{ rw [snoc_cast_succ], exact (cast_heq _ _).symm },
{ apply congr_arg_heq,
rw [succ_above_last] }
end
@[simp] lemma insert_nth_last' (x : β) (p : fin n → β) :
@insert_nth _ (λ _, β) (last n) x p = snoc p x :=
by simp [insert_nth_last]
variables [Π i, preorder (α i)]
lemma insert_nth_le_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :
i.insert_nth x p ≤ q ↔ x ≤ q i ∧ p ≤ (λ j, q (i.succ_above j)) :=
by simp [pi.le_def, forall_iff_succ_above i]
lemma le_insert_nth_iff {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)} {q : Π j, α j} :
q ≤ i.insert_nth x p ↔ q i ≤ x ∧ (λ j, q (i.succ_above j)) ≤ p :=
by simp [pi.le_def, forall_iff_succ_above i]
open set
lemma insert_nth_mem_Icc {i : fin (n + 1)} {x : α i} {p : Π j, α (i.succ_above j)}
{q₁ q₂ : Π j, α j} :
i.insert_nth x p ∈ Icc q₁ q₂ ↔
x ∈ Icc (q₁ i) (q₂ i) ∧ p ∈ Icc (λ j, q₁ (i.succ_above j)) (λ j, q₂ (i.succ_above j)) :=
by simp only [mem_Icc, insert_nth_le_iff, le_insert_nth_iff, and.assoc, and.left_comm]
lemma preimage_insert_nth_Icc_of_mem {i : fin (n + 1)} {x : α i} {q₁ q₂ : Π j, α j}
(hx : x ∈ Icc (q₁ i) (q₂ i)) :
i.insert_nth x ⁻¹' (Icc q₁ q₂) = Icc (λ j, q₁ (i.succ_above j)) (λ j, q₂ (i.succ_above j)) :=
set.ext $ λ p, by simp only [mem_preimage, insert_nth_mem_Icc, hx, true_and]
lemma preimage_insert_nth_Icc_of_not_mem {i : fin (n + 1)} {x : α i} {q₁ q₂ : Π j, α j}
(hx : x ∉ Icc (q₁ i) (q₂ i)) :
i.insert_nth x ⁻¹' (Icc q₁ q₂) = ∅ :=
set.ext $ λ p, by simp only [mem_preimage, insert_nth_mem_Icc, hx, false_and, mem_empty_eq]
end insert_nth
section find
/-- `find p` returns the first index `n` where `p n` is satisfied, and `none` if it is never
satisfied. -/
def find : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p], option (fin n)
| 0 p _ := none
| (n+1) p _ := by resetI; exact option.cases_on
(@find n (λ i, p (i.cast_lt (nat.lt_succ_of_lt i.2))) _)
(if h : p (fin.last n) then some (fin.last n) else none)
(λ i, some (i.cast_lt (nat.lt_succ_of_lt i.2)))
/-- If `find p = some i`, then `p i` holds -/
lemma find_spec : Π {n : ℕ} (p : fin n → Prop) [decidable_pred p] {i : fin n}
(hi : i ∈ by exactI fin.find p), p i
| 0 p I i hi := option.no_confusion hi
| (n+1) p I i hi := begin
dsimp [find] at hi,
resetI,
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ rw h at hi,
dsimp at hi,
split_ifs at hi with hl hl,
{ exact option.some_inj.1 hi ▸ hl },
{ exact option.no_confusion hi } },
{ rw h at hi,
rw [← option.some_inj.1 hi],
exact find_spec _ h }
end
/-- `find p` does not return `none` if and only if `p i` holds at some index `i`. -/
lemma is_some_find_iff : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p],
by exactI (find p).is_some ↔ ∃ i, p i
| 0 p _ := iff_of_false (λ h, bool.no_confusion h) (λ ⟨i, _⟩, fin_zero_elim i)
| (n+1) p _ := ⟨λ h, begin
rw [option.is_some_iff_exists] at h,
cases h with i hi,
exactI ⟨i, find_spec _ hi⟩
end, λ ⟨⟨i, hin⟩, hi⟩,
begin
resetI,
dsimp [find],
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with j,
{ split_ifs with hl hl,
{ exact option.is_some_some },
{ have := (@is_some_find_iff n (λ x, p (x.cast_lt (nat.lt_succ_of_lt x.2))) _).2
⟨⟨i, lt_of_le_of_ne (nat.le_of_lt_succ hin)
(λ h, by clear_aux_decl; cases h; exact hl hi)⟩, hi⟩,
rw h at this,
exact this } },
{ simp }
end⟩
/-- `find p` returns `none` if and only if `p i` never holds. -/
lemma find_eq_none_iff {n : ℕ} {p : fin n → Prop} [decidable_pred p] :
find p = none ↔ ∀ i, ¬ p i :=
by rw [← not_exists, ← is_some_find_iff]; cases (find p); simp
/-- If `find p` returns `some i`, then `p j` does not hold for `j < i`, i.e., `i` is minimal among
the indices where `p` holds. -/
lemma find_min : Π {n : ℕ} {p : fin n → Prop} [decidable_pred p] {i : fin n}
(hi : i ∈ by exactI fin.find p) {j : fin n} (hj : j < i), ¬ p j
| 0 p _ i hi j hj hpj := option.no_confusion hi
| (n+1) p _ i hi ⟨j, hjn⟩ hj hpj := begin
resetI,
dsimp [find] at hi,
cases h : find (λ i : fin n, (p (i.cast_lt (nat.lt_succ_of_lt i.2)))) with k,
{ rw [h] at hi,
split_ifs at hi with hl hl,
{ have := option.some_inj.1 hi,
subst this,
rw [find_eq_none_iff] at h,
exact h ⟨j, hj⟩ hpj },
{ exact option.no_confusion hi } },
{ rw h at hi,
dsimp at hi,
have := option.some_inj.1 hi,
subst this,
exact find_min h (show (⟨j, lt_trans hj k.2⟩ : fin n) < k, from hj) hpj }
end
lemma find_min' {p : fin n → Prop} [decidable_pred p] {i : fin n}
(h : i ∈ fin.find p) {j : fin n} (hj : p j) : i ≤ j :=
le_of_not_gt (λ hij, find_min h hij hj)
lemma nat_find_mem_find {p : fin n → Prop} [decidable_pred p]
(h : ∃ i, ∃ hin : i < n, p ⟨i, hin⟩) :
(⟨nat.find h, (nat.find_spec h).fst⟩ : fin n) ∈ find p :=
let ⟨i, hin, hi⟩ := h in
begin
cases hf : find p with f,
{ rw [find_eq_none_iff] at hf,
exact (hf ⟨i, hin⟩ hi).elim },
{ refine option.some_inj.2 (le_antisymm _ _),
{ exact find_min' hf (nat.find_spec h).snd },
{ exact nat.find_min' _ ⟨f.2, by convert find_spec p hf;
exact fin.eta _ _⟩ } }
end
lemma mem_find_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :
i ∈ fin.find p ↔ p i ∧ ∀ j, p j → i ≤ j :=
⟨λ hi, ⟨find_spec _ hi, λ _, find_min' hi⟩,
begin
rintros ⟨hpi, hj⟩,
cases hfp : fin.find p,
{ rw [find_eq_none_iff] at hfp,
exact (hfp _ hpi).elim },
{ exact option.some_inj.2 (le_antisymm (find_min' hfp hpi) (hj _ (find_spec _ hfp))) }
end⟩
lemma find_eq_some_iff {p : fin n → Prop} [decidable_pred p] {i : fin n} :
fin.find p = some i ↔ p i ∧ ∀ j, p j → i ≤ j :=
mem_find_iff
lemma mem_find_of_unique {p : fin n → Prop} [decidable_pred p]
(h : ∀ i j, p i → p j → i = j) {i : fin n} (hi : p i) : i ∈ fin.find p :=
mem_find_iff.2 ⟨hi, λ j hj, le_of_eq $ h i j hi hj⟩
end find
@[simp]
lemma coe_of_nat_eq_mod (m n : ℕ) :
((n : fin (succ m)) : ℕ) = n % succ m :=
by rw [← of_nat_eq_coe]; refl
@[simp] lemma coe_of_nat_eq_mod' (m n : ℕ) [I : fact (0 < m)] :
(@fin.of_nat' _ I n : ℕ) = n % m :=
rfl
section mul
/-!
### mul
-/
lemma val_mul {n : ℕ} : ∀ a b : fin n, (a * b).val = (a.val * b.val) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
lemma coe_mul {n : ℕ} : ∀ a b : fin n, ((a * b : fin n) : ℕ) = (a * b) % n
| ⟨_, _⟩ ⟨_, _⟩ := rfl
@[simp] protected lemma mul_one (k : fin (n + 1)) : k * 1 = k :=
by { cases n, simp, simp [eq_iff_veq, mul_def, mod_eq_of_lt (is_lt k)] }
@[simp] protected lemma one_mul (k : fin (n + 1)) : (1 : fin (n + 1)) * k = k :=
by { cases n, simp, simp [eq_iff_veq, mul_def, mod_eq_of_lt (is_lt k)] }
@[simp] protected lemma mul_zero (k : fin (n + 1)) : k * 0 = 0 :=
by simp [eq_iff_veq, mul_def]
@[simp] protected lemma zero_mul (k : fin (n + 1)) : (0 : fin (n + 1)) * k = 0 :=
by simp [eq_iff_veq, mul_def]
end mul
end fin
|
91f7264afad769e53f27b494590b401100763aff | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/category_theory/monoidal/opposite.lean | 455ffba7b7a8a45b70c8c23204f9d44c8feef56a | [
"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,625 | lean | /-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import category_theory.monoidal.category
/-!
# Monoidal opposites
We write `Cᵐᵒᵖ` for the monoidal opposite of a monoidal category `C`.
-/
universes v₁ v₂ u₁ u₂
variables {C : Type u₁}
namespace category_theory
open category_theory.monoidal_category
/-- A type synonym for the monoidal opposite. Use the notation `Cᵐᵒᵖ`. -/
@[nolint has_inhabited_instance]
def monoidal_opposite (C : Type u₁) := C
namespace monoidal_opposite
notation C `ᵐᵒᵖ`:std.prec.max_plus := monoidal_opposite C
/-- Think of an object of `C` as an object of `Cᵐᵒᵖ`. -/
@[pp_nodot]
def mop (X : C) : Cᵐᵒᵖ := X
/-- Think of an object of `Cᵐᵒᵖ` as an object of `C`. -/
@[pp_nodot]
def unmop (X : Cᵐᵒᵖ) : C := X
lemma op_injective : function.injective (mop : C → Cᵐᵒᵖ) := λ _ _, id
lemma unop_injective : function.injective (unmop : Cᵐᵒᵖ → C) := λ _ _, id
@[simp] lemma op_inj_iff (x y : C) : mop x = mop y ↔ x = y := iff.rfl
@[simp] lemma unop_inj_iff (x y : Cᵐᵒᵖ) : unmop x = unmop y ↔ x = y := iff.rfl
attribute [irreducible] monoidal_opposite
@[simp] lemma mop_unmop (X : Cᵐᵒᵖ) : mop (unmop X) = X := rfl
@[simp] lemma unmop_mop (X : C) : unmop (mop X) = X := rfl
instance monoidal_opposite_category [I : category.{v₁} C] : category Cᵐᵒᵖ :=
{ hom := λ X Y, unmop X ⟶ unmop Y,
id := λ X, 𝟙 (unmop X),
comp := λ X Y Z f g, f ≫ g, }
end monoidal_opposite
end category_theory
open category_theory
open category_theory.monoidal_opposite
variables [category.{v₁} C]
/-- The monoidal opposite of a morphism `f : X ⟶ Y` is just `f`, thought of as `mop X ⟶ mop Y`. -/
def quiver.hom.mop {X Y : C} (f : X ⟶ Y) : @quiver.hom Cᵐᵒᵖ _ (mop X) (mop Y) := f
/-- We can think of a morphism `f : mop X ⟶ mop Y` as a morphism `X ⟶ Y`. -/
def quiver.hom.unmop {X Y : Cᵐᵒᵖ} (f : X ⟶ Y) : unmop X ⟶ unmop Y := f
namespace category_theory
lemma mop_inj {X Y : C} :
function.injective (quiver.hom.mop : (X ⟶ Y) → (mop X ⟶ mop Y)) :=
λ _ _ H, congr_arg quiver.hom.unmop H
lemma unmop_inj {X Y : Cᵐᵒᵖ} :
function.injective (quiver.hom.unmop : (X ⟶ Y) → (unmop X ⟶ unmop Y)) :=
λ _ _ H, congr_arg quiver.hom.mop H
@[simp] lemma unmop_mop {X Y : C} {f : X ⟶ Y} : f.mop.unmop = f := rfl
@[simp] lemma mop_unmop {X Y : Cᵐᵒᵖ} {f : X ⟶ Y} : f.unmop.mop = f := rfl
@[simp] lemma mop_comp {X Y Z : C} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).mop = f.mop ≫ g.mop := rfl
@[simp] lemma mop_id {X : C} : (𝟙 X).mop = 𝟙 (mop X) := rfl
@[simp] lemma unmop_comp {X Y Z : Cᵐᵒᵖ} {f : X ⟶ Y} {g : Y ⟶ Z} :
(f ≫ g).unmop = f.unmop ≫ g.unmop := rfl
@[simp] lemma unmop_id {X : Cᵐᵒᵖ} : (𝟙 X).unmop = 𝟙 (unmop X) := rfl
@[simp] lemma unmop_id_mop {X : C} : (𝟙 (mop X)).unmop = 𝟙 X := rfl
@[simp] lemma mop_id_unmop {X : Cᵐᵒᵖ} : (𝟙 (unmop X)).mop = 𝟙 X := rfl
namespace iso
variables {X Y : C}
/-- An isomorphism in `C` gives an isomorphism in `Cᵐᵒᵖ`. -/
@[simps]
def mop (f : X ≅ Y) : mop X ≅ mop Y :=
{ hom := f.hom.mop,
inv := f.inv.mop,
hom_inv_id' := unmop_inj f.hom_inv_id,
inv_hom_id' := unmop_inj f.inv_hom_id }
end iso
variables [monoidal_category.{v₁} C]
open opposite monoidal_category
instance monoidal_category_op : monoidal_category Cᵒᵖ :=
{ tensor_obj := λ X Y, op (unop X ⊗ unop Y),
tensor_hom := λ X₁ Y₁ X₂ Y₂ f g, (f.unop ⊗ g.unop).op,
tensor_unit := op (𝟙_ C),
associator := λ X Y Z, (α_ (unop X) (unop Y) (unop Z)).symm.op,
left_unitor := λ X, (λ_ (unop X)).symm.op,
right_unitor := λ X, (ρ_ (unop X)).symm.op,
associator_naturality' :=
begin
intros,
apply quiver.hom.unop_inj,
simp [associator_inv_naturality],
end,
left_unitor_naturality' :=
begin
intros,
apply quiver.hom.unop_inj,
simp [left_unitor_inv_naturality],
end,
right_unitor_naturality' :=
begin
intros,
apply quiver.hom.unop_inj,
simp [right_unitor_inv_naturality],
end,
triangle' :=
begin
intros,
apply quiver.hom.unop_inj,
dsimp,
simp,
end,
pentagon' :=
begin
intros,
apply quiver.hom.unop_inj,
dsimp,
simp [pentagon_inv],
end }
lemma op_tensor_obj (X Y : Cᵒᵖ) : X ⊗ Y = op (unop X ⊗ unop Y) := rfl
lemma op_tensor_unit : (𝟙_ Cᵒᵖ) = op (𝟙_ C) := rfl
instance monoidal_category_mop : monoidal_category Cᵐᵒᵖ :=
{ tensor_obj := λ X Y, mop (unmop Y ⊗ unmop X),
tensor_hom := λ X₁ Y₁ X₂ Y₂ f g, (g.unmop ⊗ f.unmop).mop,
tensor_unit := mop (𝟙_ C),
associator := λ X Y Z, (α_ (unmop Z) (unmop Y) (unmop X)).symm.mop,
left_unitor := λ X, (ρ_ (unmop X)).mop,
right_unitor := λ X, (λ_ (unmop X)).mop,
associator_naturality' :=
begin
intros,
apply unmop_inj,
simp [associator_inv_naturality],
end,
left_unitor_naturality' :=
begin
intros,
apply unmop_inj,
simp [right_unitor_naturality],
end,
right_unitor_naturality' :=
begin
intros,
apply unmop_inj,
simp [left_unitor_naturality],
end,
triangle' :=
begin
intros,
apply unmop_inj,
dsimp,
simp,
end,
pentagon' :=
begin
intros,
apply unmop_inj,
dsimp,
simp [pentagon_inv],
end }
lemma mop_tensor_obj (X Y : Cᵐᵒᵖ) : X ⊗ Y = mop (unmop Y ⊗ unmop X) := rfl
lemma mop_tensor_unit : (𝟙_ Cᵐᵒᵖ) = mop (𝟙_ C) := rfl
end category_theory
|
3c7e392327dbdcc8901e51a45ef26f5732c9017e | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/group_theory/order_of_element.lean | f800d06d2bf9ceaa286dc06491732ccdfeb4ae85 | [
"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 | 22,702 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import data.set.finite group_theory.coset data.nat.totient
open function
variables {α : Type*} {s : set α} {a a₁ a₂ b c: α}
-- TODO this lemma isn't used anywhere in this file, and should be moved elsewhere.
namespace finset
open finset
lemma mem_range_iff_mem_finset_range_of_mod_eq [decidable_eq α] {f : ℤ → α} {a : α} {n : ℕ}
(hn : 0 < n) (h : ∀i, f (i % n) = f i) :
a ∈ set.range f ↔ a ∈ (finset.range n).image (λi, f i) :=
suffices (∃i, f (i % n) = a) ↔ ∃i, i < n ∧ f ↑i = a, by simpa [h],
have hn' : 0 < (n : ℤ), from int.coe_nat_lt.mpr hn,
iff.intro
(assume ⟨i, hi⟩,
have 0 ≤ i % ↑n, from int.mod_nonneg _ (ne_of_gt hn'),
⟨int.to_nat (i % n),
by rw [←int.coe_nat_lt, int.to_nat_of_nonneg this]; exact ⟨int.mod_lt_of_pos i hn', hi⟩⟩)
(assume ⟨i, hi, ha⟩,
⟨i, by rw [int.mod_eq_of_lt (int.coe_zero_le _) (int.coe_nat_lt_coe_nat_of_lt hi), ha]⟩)
end finset
lemma conj_inj [group α] {x : α} : function.injective (λ (g : α), x * g * x⁻¹) :=
λ a b h, by simpa [mul_left_inj, mul_right_inj] using h
lemma mem_normalizer_fintype [group α] {s : set α} [fintype s] {x : α}
(h : ∀ n, n ∈ s → x * n * x⁻¹ ∈ s) : x ∈ is_subgroup.normalizer s :=
by haveI := classical.prop_decidable;
haveI := set.fintype_image s (λ n, x * n * x⁻¹); exact
λ n, ⟨h n, λ h₁,
have heq : (λ n, x * n * x⁻¹) '' s = s := set.eq_of_subset_of_card_le
(λ n ⟨y, hy⟩, hy.2 ▸ h y hy.1) (by rw set.card_image_of_injective s conj_inj),
have x * n * x⁻¹ ∈ (λ n, x * n * x⁻¹) '' s := heq.symm ▸ h₁,
let ⟨y, hy⟩ := this in conj_inj hy.2 ▸ hy.1⟩
section order_of
variables [group α] [fintype α] [decidable_eq α]
open quotient_group set
instance quotient_group.fintype (s : set α) [is_subgroup s] [d : decidable_pred s] :
fintype (quotient s) :=
@quotient.fintype _ _ (left_rel s) (λ _ _, d _)
lemma card_eq_card_quotient_mul_card_subgroup (s : set α) [hs : is_subgroup s] [fintype s]
[decidable_pred s] : fintype.card α = fintype.card (quotient s) * fintype.card s :=
by rw ← fintype.card_prod;
exact fintype.card_congr (is_subgroup.group_equiv_quotient_times_subgroup hs)
lemma card_subgroup_dvd_card (s : set α) [is_subgroup s] [fintype s] :
fintype.card s ∣ fintype.card α :=
by haveI := classical.prop_decidable; simp [card_eq_card_quotient_mul_card_subgroup s]
lemma card_quotient_dvd_card (s : set α) [is_subgroup s] [decidable_pred s] [fintype s] :
fintype.card (quotient s) ∣ fintype.card α :=
by simp [card_eq_card_quotient_mul_card_subgroup s]
@[simp] lemma card_trivial [fintype (is_subgroup.trivial α)] :
fintype.card (is_subgroup.trivial α) = 1 :=
fintype.card_eq_one_iff.2
⟨⟨(1 : α), by simp⟩, λ ⟨y, hy⟩, subtype.eq $ is_subgroup.mem_trivial.1 hy⟩
lemma exists_gpow_eq_one (a : α) : ∃i≠0, a ^ (i:ℤ) = 1 :=
have ¬ injective (λi, a ^ i),
from not_injective_int_fintype,
let ⟨i, j, a_eq, ne⟩ := show ∃(i j : ℤ), a ^ i = a ^ j ∧ i ≠ j,
by rw [injective] at this; simpa [classical.not_forall] in
have a ^ (i - j) = 1,
by simp [gpow_add, gpow_neg, a_eq],
⟨i - j, sub_ne_zero.mpr ne, this⟩
lemma exists_pow_eq_one (a : α) : ∃i > 0, a ^ i = 1 :=
let ⟨i, hi, eq⟩ := exists_gpow_eq_one a in
begin
cases i,
{ exact ⟨i, nat.pos_of_ne_zero (by simp [int.of_nat_eq_coe, *] at *), eq⟩ },
{ exact ⟨i + 1, dec_trivial, inv_eq_one.1 eq⟩ }
end
/-- `order_of a` is the order of the element `a`, i.e. the `n ≥ 1`, s.t. `a ^ n = 1` -/
def order_of (a : α) : ℕ := nat.find (exists_pow_eq_one a)
lemma pow_order_of_eq_one (a : α) : a ^ order_of a = 1 :=
let ⟨h₁, h₂⟩ := nat.find_spec (exists_pow_eq_one a) in h₂
lemma order_of_pos (a : α) : order_of a > 0 :=
let ⟨h₁, h₂⟩ := nat.find_spec (exists_pow_eq_one a) in h₁
private lemma pow_injective_aux {n m : ℕ} (a : α) (h : n ≤ m)
(hn : n < order_of a) (hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m :=
decidable.by_contradiction $ assume ne : n ≠ m,
have h₁ : m - n > 0, from nat.pos_of_ne_zero (by simp [nat.sub_eq_iff_eq_add h, ne.symm]),
have h₂ : a ^ (m - n) = 1, by simp [pow_sub _ h, eq],
have le : order_of a ≤ m - n, from nat.find_min' (exists_pow_eq_one a) ⟨h₁, h₂⟩,
have lt : m - n < order_of a,
from (nat.sub_lt_left_iff_lt_add h).mpr $ nat.lt_add_left _ _ _ hm,
lt_irrefl _ (lt_of_le_of_lt le lt)
lemma pow_injective_of_lt_order_of {n m : ℕ} (a : α)
(hn : n < order_of a) (hm : m < order_of a) (eq : a ^ n = a ^ m) : n = m :=
(le_total n m).elim
(assume h, pow_injective_aux a h hn hm eq)
(assume h, (pow_injective_aux a h hm hn eq.symm).symm)
lemma order_of_le_card_univ : order_of a ≤ fintype.card α :=
finset.card_le_of_inj_on ((^) a)
(assume n _, fintype.complete _)
(assume i j, pow_injective_of_lt_order_of a)
lemma pow_eq_mod_order_of {n : ℕ} : a ^ n = a ^ (n % order_of a) :=
calc a ^ n = a ^ (n % order_of a + order_of a * (n / order_of a)) :
by rw [nat.mod_add_div]
... = a ^ (n % order_of a) :
by simp [pow_add, pow_mul, pow_order_of_eq_one]
lemma gpow_eq_mod_order_of {i : ℤ} : a ^ i = a ^ (i % order_of a) :=
calc a ^ i = a ^ (i % order_of a + order_of a * (i / order_of a)) :
by rw [int.mod_add_div]
... = a ^ (i % order_of a) :
by simp [gpow_add, gpow_mul, pow_order_of_eq_one]
lemma mem_gpowers_iff_mem_range_order_of {a a' : α} :
a' ∈ gpowers a ↔ a' ∈ (finset.range (order_of a)).image ((^) a : ℕ → α) :=
finset.mem_range_iff_mem_finset_range_of_mod_eq
(order_of_pos a)
(assume i, gpow_eq_mod_order_of.symm)
instance decidable_gpowers : decidable_pred (gpowers a) :=
assume a', decidable_of_iff'
(a' ∈ (finset.range (order_of a)).image ((^) a))
mem_gpowers_iff_mem_range_order_of
lemma order_of_dvd_of_pow_eq_one {n : ℕ} (h : a ^ n = 1) : order_of a ∣ n :=
by_contradiction
(λ h₁, nat.find_min _ (show n % order_of a < order_of a,
from nat.mod_lt _ (order_of_pos _))
⟨nat.pos_of_ne_zero (mt nat.dvd_of_mod_eq_zero h₁), by rwa ← pow_eq_mod_order_of⟩)
lemma order_of_le_of_pow_eq_one {n : ℕ} (hn : 0 < n) (h : a ^ n = 1) : order_of a ≤ n :=
nat.find_min' (exists_pow_eq_one a) ⟨hn, h⟩
lemma sum_card_order_of_eq_card_pow_eq_one {n : ℕ} (hn : 0 < n) :
((finset.range n.succ).filter (∣ n)).sum (λ m, (finset.univ.filter (λ a : α, order_of a = m)).card)
= (finset.univ.filter (λ a : α, a ^ n = 1)).card :=
calc ((finset.range n.succ).filter (∣ n)).sum (λ m, (finset.univ.filter (λ a : α, order_of a = m)).card)
= _ : (finset.card_bind (by simp [finset.ext]; cc)).symm
... = _ : congr_arg finset.card (finset.ext.2 (begin
assume a,
suffices : order_of a ≤ n ∧ order_of a ∣ n ↔ a ^ n = 1,
{ simpa [nat.lt_succ_iff], },
exact ⟨λ h, let ⟨m, hm⟩ := h.2 in by rw [hm, pow_mul, pow_order_of_eq_one, _root_.one_pow],
λ h, ⟨order_of_le_of_pow_eq_one hn h, order_of_dvd_of_pow_eq_one h⟩⟩
end))
section
local attribute [instance] set_fintype
lemma order_eq_card_gpowers : order_of a = fintype.card (gpowers a) :=
begin
refine (finset.card_eq_of_bijective _ _ _ _).symm,
{ exact λn hn, ⟨gpow a n, ⟨n, rfl⟩⟩ },
{ exact assume ⟨_, i, rfl⟩ _,
have pos: (0:int) < order_of a,
from int.coe_nat_lt.mpr $ order_of_pos a,
have 0 ≤ i % (order_of a),
from int.mod_nonneg _ $ ne_of_gt pos,
⟨int.to_nat (i % order_of a),
by rw [← int.coe_nat_lt, int.to_nat_of_nonneg this];
exact ⟨int.mod_lt_of_pos _ pos, subtype.eq gpow_eq_mod_order_of.symm⟩⟩ },
{ intros, exact finset.mem_univ _ },
{ exact assume i j hi hj eq, pow_injective_of_lt_order_of a hi hj $ by simpa using eq }
end
@[simp] lemma order_of_one : order_of (1 : α) = 1 :=
by rw [order_eq_card_gpowers, fintype.card_eq_one_iff];
exact ⟨⟨1, 0, rfl⟩, λ ⟨a, i, ha⟩, by simp [ha.symm]⟩
@[simp] lemma order_of_eq_one_iff : order_of a = 1 ↔ a = 1 :=
⟨λ h, by conv { to_lhs, rw [← pow_one a, ← h, pow_order_of_eq_one] }, λ h, by simp [h]⟩
section classical
local attribute [instance] classical.prop_decidable
open quotient_group
/- TODO: use cardinal theory, introduce `card : set α → ℕ`, or setup decidability for cosets -/
lemma order_of_dvd_card_univ : order_of a ∣ fintype.card α :=
have ft_prod : fintype (quotient (gpowers a) × (gpowers a)),
from fintype.of_equiv α (gpowers.is_subgroup a).group_equiv_quotient_times_subgroup,
have ft_s : fintype (gpowers a),
from @fintype.fintype_prod_right _ _ _ ft_prod _,
have ft_cosets : fintype (quotient (gpowers a)),
from @fintype.fintype_prod_left _ _ _ ft_prod ⟨⟨1, is_submonoid.one_mem (gpowers a)⟩⟩,
have ft : fintype (quotient (gpowers a) × (gpowers a)),
from @prod.fintype _ _ ft_cosets ft_s,
have eq₁ : fintype.card α = @fintype.card _ ft_cosets * @fintype.card _ ft_s,
from calc fintype.card α = @fintype.card _ ft_prod :
@fintype.card_congr _ _ _ ft_prod (gpowers.is_subgroup a).group_equiv_quotient_times_subgroup
... = @fintype.card _ (@prod.fintype _ _ ft_cosets ft_s) :
congr_arg (@fintype.card _) $ subsingleton.elim _ _
... = @fintype.card _ ft_cosets * @fintype.card _ ft_s :
@fintype.card_prod _ _ ft_cosets ft_s,
have eq₂ : order_of a = @fintype.card _ ft_s,
from calc order_of a = _ : order_eq_card_gpowers
... = _ : congr_arg (@fintype.card _) $ subsingleton.elim _ _,
dvd.intro (@fintype.card (quotient (gpowers a)) ft_cosets) $
by rw [eq₁, eq₂, mul_comm]
end classical
@[simp] lemma pow_card_eq_one (a : α) : a ^ fintype.card α = 1 :=
let ⟨m, hm⟩ := @order_of_dvd_card_univ _ a _ _ _ in
by simp [hm, pow_mul, pow_order_of_eq_one]
lemma powers_eq_gpowers (a : α) : powers a = gpowers a :=
set.ext (λ x, ⟨λ ⟨n, hn⟩, ⟨n, by simp * at *⟩,
λ ⟨i, hi⟩, ⟨(i % order_of a).nat_abs,
by rwa [← gpow_coe_nat, int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (order_of_pos _))), ← gpow_eq_mod_order_of]⟩⟩)
open nat
lemma order_of_pow (a : α) (n : ℕ) : order_of (a ^ n) = order_of a / gcd (order_of a) n :=
dvd_antisymm
(order_of_dvd_of_pow_eq_one
(by rw [← pow_mul, ← nat.mul_div_assoc _ (gcd_dvd_left _ _), mul_comm,
nat.mul_div_assoc _ (gcd_dvd_right _ _), pow_mul, pow_order_of_eq_one, _root_.one_pow]))
(have gcd_pos : 0 < gcd (order_of a) n, from gcd_pos_of_pos_left n (order_of_pos a),
have hdvd : order_of a ∣ n * order_of (a ^ n),
from order_of_dvd_of_pow_eq_one (by rw [pow_mul, pow_order_of_eq_one]),
coprime.dvd_of_dvd_mul_right (coprime_div_gcd_div_gcd gcd_pos)
(dvd_of_mul_dvd_mul_right gcd_pos
(by rwa [nat.div_mul_cancel (gcd_dvd_left _ _), mul_assoc,
nat.div_mul_cancel (gcd_dvd_right _ _), mul_comm])))
lemma pow_gcd_card_eq_one_iff {n : ℕ} {a : α} :
a ^ n = 1 ↔ a ^ (gcd n (fintype.card α)) = 1 :=
⟨λ h, have hn : order_of a ∣ n, from dvd_of_mod_eq_zero $
by_contradiction (λ ha, by rw pow_eq_mod_order_of at h;
exact (not_le_of_gt (nat.mod_lt n (order_of_pos a)))
(order_of_le_of_pow_eq_one (nat.pos_of_ne_zero ha) h)),
let ⟨m, hm⟩ := dvd_gcd hn order_of_dvd_card_univ in
by rw [hm, pow_mul, pow_order_of_eq_one, _root_.one_pow],
λ h, let ⟨m, hm⟩ := gcd_dvd_left n (fintype.card α) in
by rw [hm, pow_mul, h, _root_.one_pow]⟩
end
end order_of
section cyclic
local attribute [instance] set_fintype
class is_cyclic (α : Type*) [group α] : Prop :=
(exists_generator : ∃ g : α, ∀ x, x ∈ gpowers g)
def is_cyclic.comm_group [hg : group α] [is_cyclic α] : comm_group α :=
{ mul_comm := λ x y, show x * y = y * x,
from let ⟨g, hg⟩ := is_cyclic.exists_generator α in
let ⟨n, hn⟩ := hg x in let ⟨m, hm⟩ := hg y in
hm ▸ hn ▸ gpow_mul_comm _ _ _,
..hg }
lemma is_cyclic_of_order_of_eq_card [group α] [fintype α] [decidable_eq α]
(x : α) (hx : order_of x = fintype.card α) : is_cyclic α :=
⟨⟨x, set.eq_univ_iff_forall.1 $ set.eq_of_subset_of_card_le
(set.subset_univ _)
(by rw [fintype.card_congr (equiv.set.univ α), ← hx, order_eq_card_gpowers])⟩⟩
lemma order_of_eq_card_of_forall_mem_gpowers [group α] [fintype α] [decidable_eq α]
{g : α} (hx : ∀ x, x ∈ gpowers g) : order_of g = fintype.card α :=
by rw [← fintype.card_congr (equiv.set.univ α), order_eq_card_gpowers];
simp [hx]; congr
instance [group α] : is_cyclic (is_subgroup.trivial α) :=
⟨⟨(1 : is_subgroup.trivial α), λ x, ⟨0, subtype.eq $ eq.symm (is_subgroup.mem_trivial.1 x.2)⟩⟩⟩
instance is_subgroup.is_cyclic [group α] [is_cyclic α] (H : set α) [is_subgroup H] : is_cyclic H :=
by haveI := classical.prop_decidable; exact
let ⟨g, hg⟩ := is_cyclic.exists_generator α in
if hx : ∃ (x : α), x ∈ H ∧ x ≠ (1 : α) then
let ⟨x, hx₁, hx₂⟩ := hx in
let ⟨k, hk⟩ := hg x in
have hex : ∃ n : ℕ, 0 < n ∧ g ^ n ∈ H,
from ⟨k.nat_abs, nat.pos_of_ne_zero
(λ h, hx₂ $ by rw [← hk, int.eq_zero_of_nat_abs_eq_zero h, gpow_zero]),
match k, hk with
| (k : ℕ), hk := by rw [int.nat_abs_of_nat, ← gpow_coe_nat, hk]; exact hx₁
| -[1+ k], hk := by rw [int.nat_abs_of_neg_succ_of_nat,
← is_subgroup.inv_mem_iff H]; simp * at *
end⟩,
⟨⟨⟨g ^ nat.find hex, (nat.find_spec hex).2⟩,
λ ⟨x, hx⟩, let ⟨k, hk⟩ := hg x in
have hk₁ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ gpowers (g ^ nat.find hex),
from ⟨k / nat.find hex, eq.symm $ gpow_mul _ _ _⟩,
have hk₂ : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) ∈ H,
by rw gpow_mul; exact is_subgroup.gpow_mem (nat.find_spec hex).2,
have hk₃ : g ^ (k % nat.find hex) ∈ H,
from (is_subgroup.mul_mem_cancel_left H hk₂).1 $
by rw [← gpow_add, int.mod_add_div, hk]; exact hx,
have hk₄ : k % nat.find hex = (k % nat.find hex).nat_abs,
by rw int.nat_abs_of_nonneg (int.mod_nonneg _
(int.coe_nat_ne_zero_iff_pos.2 (nat.find_spec hex).1)),
have hk₅ : g ^ (k % nat.find hex ).nat_abs ∈ H,
by rwa [← gpow_coe_nat, ← hk₄],
have hk₆ : (k % (nat.find hex : ℤ)).nat_abs = 0,
from by_contradiction (λ h,
nat.find_min hex (int.coe_nat_lt.1 $ by rw [← hk₄];
exact int.mod_lt_of_pos _ (int.coe_nat_pos.2 (nat.find_spec hex).1))
⟨nat.pos_of_ne_zero h, hk₅⟩),
⟨k / (nat.find hex : ℤ), subtype.coe_ext.2 begin
suffices : g ^ ((nat.find hex : ℤ) * (k / nat.find hex)) = x,
{ simpa [gpow_mul] },
rw [int.mul_div_cancel' (int.dvd_of_mod_eq_zero (int.eq_zero_of_nat_abs_eq_zero hk₆)), hk]
end⟩⟩⟩
else
have H = is_subgroup.trivial α,
from set.ext $ λ x, ⟨λ h, by simp at *; tauto,
λ h, by rw [is_subgroup.mem_trivial.1 h]; exact is_submonoid.one_mem _⟩,
by clear _let_match; subst this; apply_instance
open finset nat
lemma is_cyclic.card_pow_eq_one_le [group α] [fintype α] [decidable_eq α] [is_cyclic α] {n : ℕ}
(hn0 : 0 < n) : (univ.filter (λ a : α, a ^ n = 1)).card ≤ n :=
let ⟨g, hg⟩ := is_cyclic.exists_generator α in
calc (univ.filter (λ a : α, a ^ n = 1)).card ≤ (gpowers (g ^ (fintype.card α / (gcd n (fintype.card α))))).to_finset.card :
card_le_of_subset (λ x hx, let ⟨m, hm⟩ := show x ∈ powers g, from (powers_eq_gpowers g).symm ▸ hg x in
set.mem_to_finset.2 ⟨(m / (fintype.card α / (gcd n (fintype.card α))) : ℕ),
have hgmn : g ^ (m * gcd n (fintype.card α)) = 1,
by rw [pow_mul, hm, ← pow_gcd_card_eq_one_iff]; exact (mem_filter.1 hx).2,
begin
rw [gpow_coe_nat, ← pow_mul, nat.mul_div_cancel_left', hm],
refine dvd_of_mul_dvd_mul_right (gcd_pos_of_pos_left (fintype.card α) hn0) _,
conv {to_lhs, rw [nat.div_mul_cancel (gcd_dvd_right _ _), ← order_of_eq_card_of_forall_mem_gpowers hg]},
exact order_of_dvd_of_pow_eq_one hgmn
end⟩)
... ≤ n :
let ⟨m, hm⟩ := gcd_dvd_right n (fintype.card α) in
have hm0 : 0 < m, from nat.pos_of_ne_zero
(λ hm0, (by rw [hm0, mul_zero, fintype.card_eq_zero_iff] at hm; exact hm 1)),
begin
rw [← set.card_fintype_of_finset' _ (λ _, set.mem_to_finset), ← order_eq_card_gpowers,
order_of_pow, order_of_eq_card_of_forall_mem_gpowers hg],
rw [hm] {occs := occurrences.pos [2,3]},
rw [nat.mul_div_cancel_left _ (gcd_pos_of_pos_left _ hn0), gcd_mul_left_left,
hm, nat.mul_div_cancel _ hm0],
exact le_of_dvd hn0 (gcd_dvd_left _ _)
end
section totient
variables [group α] [fintype α] [decidable_eq α] (hn : ∀ n : ℕ, 0 < n → (univ.filter (λ a : α, a ^ n = 1)).card ≤ n)
include hn
lemma card_pow_eq_one_eq_order_of_aux (a : α) :
(finset.univ.filter (λ b : α, b ^ order_of a = 1)).card = order_of a :=
le_antisymm
(hn _ (order_of_pos _))
(calc order_of a = @fintype.card (gpowers a) (id _) : order_eq_card_gpowers
... ≤ @fintype.card (↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α)
(set.fintype_of_finset _ (λ _, iff.rfl)) :
@fintype.card_le_of_injective (gpowers a) (↑(univ.filter (λ b : α, b ^ order_of a = 1)) : set α)
(id _) (id _) (λ b, ⟨b.1, mem_filter.2 ⟨mem_univ _,
let ⟨i, hi⟩ := b.2 in
by rw [← hi, ← gpow_coe_nat, ← gpow_mul, mul_comm, gpow_mul, gpow_coe_nat,
pow_order_of_eq_one, one_gpow]⟩⟩) (λ _ _ h, subtype.eq (subtype.mk.inj h))
... = (univ.filter (λ b : α, b ^ order_of a = 1)).card : set.card_fintype_of_finset _ _)
local notation `φ` := nat.totient
private lemma card_order_of_eq_totient_aux₁ :
∀ {d : ℕ}, d ∣ fintype.card α → 0 < (univ.filter (λ a : α, order_of a = d)).card →
(univ.filter (λ a : α, order_of a = d)).card = φ d
| 0 := λ hd hd0, absurd hd0 (mt card_pos.1
(by simp [finset.ext, nat.pos_iff_ne_zero.1 (order_of_pos _)]))
| (d+1) := λ hd hd0,
let ⟨a, ha⟩ := exists_mem_of_ne_empty (card_pos.1 hd0) in
have ha : order_of a = d.succ, from (mem_filter.1 ha).2,
have h : ((range d.succ).filter (∣ d.succ)).sum
(λ m, (univ.filter (λ a : α, order_of a = m)).card) =
((range d.succ).filter (∣ d.succ)).sum φ, from
finset.sum_congr rfl
(λ m hm, have hmd : m < d.succ, from mem_range.1 (mem_filter.1 hm).1,
have hm : m ∣ d.succ, from (mem_filter.1 hm).2,
card_order_of_eq_totient_aux₁ (dvd.trans hm hd) (finset.card_pos.2
(ne_empty_of_mem (show a ^ (d.succ / m) ∈ _,
from mem_filter.2 ⟨mem_univ _,
by rw [order_of_pow, ha, gcd_eq_right (div_dvd_of_dvd hm),
nat.div_div_self hm (succ_pos _)]⟩)))),
have hinsert : insert d.succ ((range d.succ).filter (∣ d.succ))
= (range d.succ.succ).filter (∣ d.succ),
from (finset.ext.2 $ λ x, ⟨λ h, (mem_insert.1 h).elim (λ h, by simp [h, range_succ])
(by clear _let_match; simp [range_succ]; tauto), by clear _let_match; simp [range_succ] {contextual := tt}; tauto⟩),
have hinsert₁ : d.succ ∉ (range d.succ).filter (∣ d.succ),
by simp [mem_range, zero_le_one, le_succ],
(add_right_inj (((range d.succ).filter (∣ d.succ)).sum
(λ m, (univ.filter (λ a : α, order_of a = m)).card))).1
(calc _ = (insert d.succ (filter (∣ d.succ) (range d.succ))).sum
(λ m, (univ.filter (λ a : α, order_of a = m)).card) :
eq.symm (finset.sum_insert (by simp [mem_range, zero_le_one, le_succ]))
... = ((range d.succ.succ).filter (∣ d.succ)).sum (λ m,
(univ.filter (λ a : α, order_of a = m)).card) :
sum_congr hinsert (λ _ _, rfl)
... = (univ.filter (λ a : α, a ^ d.succ = 1)).card :
sum_card_order_of_eq_card_pow_eq_one (succ_pos d)
... = ((range d.succ.succ).filter (∣ d.succ)).sum φ :
ha ▸ (card_pow_eq_one_eq_order_of_aux hn a).symm ▸ (sum_totient _).symm
... = _ : by rw [h, ← sum_insert hinsert₁];
exact finset.sum_congr hinsert.symm (λ _ _, rfl))
lemma card_order_of_eq_totient_aux₂ {d : ℕ} (hd : d ∣ fintype.card α) :
(univ.filter (λ a : α, order_of a = d)).card = φ d :=
by_contradiction $ λ h,
have h0 : (univ.filter (λ a : α , order_of a = d)).card = 0 :=
not_not.1 (mt nat.pos_iff_ne_zero.2 (mt (card_order_of_eq_totient_aux₁ hn hd) h)),
let c := fintype.card α in
have hc0 : 0 < c, from fintype.card_pos_iff.2 ⟨1⟩,
lt_irrefl c $
calc c = (univ.filter (λ a : α, a ^ c = 1)).card :
congr_arg card $ by simp [finset.ext, c]
... = ((range c.succ).filter (∣ c)).sum
(λ m, (univ.filter (λ a : α, order_of a = m)).card) :
(sum_card_order_of_eq_card_pow_eq_one hc0).symm
... = (((range c.succ).filter (∣ c)).erase d).sum
(λ m, (univ.filter (λ a : α, order_of a = m)).card) :
eq.symm (sum_subset (erase_subset _ _) (λ m hm₁ hm₂,
have m = d, by simp at *; cc,
by simp [*, finset.ext] at *; exact h0))
... ≤ (((range c.succ).filter (∣ c)).erase d).sum φ :
sum_le_sum (λ m hm,
have hmc : m ∣ c, by simp at hm; tauto,
(imp_iff_not_or.1 (card_order_of_eq_totient_aux₁ hn hmc)).elim
(λ h, by simp [nat.le_zero_iff.1 (le_of_not_gt h), nat.zero_le])
(by simp [le_refl] {contextual := tt}))
... < φ d + (((range c.succ).filter (∣ c)).erase d).sum φ :
lt_add_of_pos_left _ (totient_pos (nat.pos_of_ne_zero
(λ h, nat.pos_iff_ne_zero.1 hc0 (eq_zero_of_zero_dvd $ h ▸ hd))))
... = (insert d (((range c.succ).filter (∣ c)).erase d)).sum φ : eq.symm (sum_insert (by simp))
... = ((range c.succ).filter (∣ c)).sum φ : finset.sum_congr
(finset.insert_erase (mem_filter.2 ⟨mem_range.2 (lt_succ_of_le (le_of_dvd hc0 hd)), hd⟩)) (λ _ _, rfl)
... = c : sum_totient _
lemma is_cyclic_of_card_pow_eq_one_le : is_cyclic α :=
have ∃ x, x ∈ univ.filter (λ a : α, order_of a = fintype.card α),
from exists_mem_of_ne_empty (card_pos.1 $
by rw [card_order_of_eq_totient_aux₂ hn (dvd_refl _)];
exact totient_pos (fintype.card_pos_iff.2 ⟨1⟩)),
let ⟨x, hx⟩ := this in
is_cyclic_of_order_of_eq_card x (finset.mem_filter.1 hx).2
end totient
lemma is_cyclic.card_order_of_eq_totient [group α] [is_cyclic α] [fintype α] [decidable_eq α]
{d : ℕ} (hd : d ∣ fintype.card α) : (univ.filter (λ a : α, order_of a = d)).card = totient d :=
card_order_of_eq_totient_aux₂ (λ n, is_cyclic.card_pow_eq_one_le) hd
end cyclic
|
543c326e1bce04ae4027d907a59c0b009e40aa55 | 07c76fbd96ea1786cc6392fa834be62643cea420 | /hott/algebra/group_power.hlean | f1b5a3c7a198d743e2e21986e0ebfe1240329d16 | [
"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 | 11,518 | hlean | /-
Copyright (c) 2015 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
The power operation on monoids prod groups. We separate this from group, because it depends on
nat, which in turn depends on other parts of algebra.
We have "pow a n" for natural number powers, prod "gpow a i" for integer powers. The notation
a^n is used for the first, but users can locally redefine it to gpow when needed.
Note: power adopts the convention that 0^0=1.
-/
import types.nat.basic types.int.basic .homomorphism .group_theory
open algebra eq
namespace algebra
variables {A B : Type}
structure has_pow_nat [class] (A : Type) :=
(pow_nat : A → nat → A)
definition pow_nat {A : Type} [s : has_pow_nat A] : A → nat → A :=
has_pow_nat.pow_nat
infix ` ^ ` := pow_nat
structure has_pow_int [class] (A : Type) :=
(pow_int : A → int → A)
definition pow_int {A : Type} [s : has_pow_int A] : A → int → A :=
has_pow_int.pow_int
/- monoid -/
section monoid
open nat
variable [s : monoid A]
include s
definition monoid.pow (a : A) : ℕ → A
| 0 := 1
| (n+1) := a * monoid.pow n
definition monoid_has_pow_nat [instance] : has_pow_nat A :=
has_pow_nat.mk monoid.pow
theorem pow_zero (a : A) : a^0 = 1 := rfl
theorem pow_succ (a : A) (n : ℕ) : a^(succ n) = a * a^n := rfl
theorem pow_one (a : A) : a^1 = a := !mul_one
theorem pow_two (a : A) : a^2 = a * a :=
calc
a^2 = a * (a * 1) : rfl
... = a * a : mul_one
theorem pow_three (a : A) : a^3 = a * (a * a) :=
calc
a^3 = a * (a * (a * 1)) : rfl
... = a * (a * a) : mul_one
theorem pow_four (a : A) : a^4 = a * (a * (a * a)) :=
calc
a^4 = a * a^3 : rfl
... = a * (a * (a * a)) : pow_three
theorem pow_succ' (a : A) : Πn, a^(succ n) = a^n * a
| 0 := by rewrite [pow_succ, *pow_zero, one_mul, mul_one]
| (succ n) := by rewrite [pow_succ, pow_succ' at {1}, pow_succ, mul.assoc]
theorem one_pow : Π n : ℕ, 1^n = (1:A)
| 0 := rfl
| (succ n) := by rewrite [pow_succ, one_mul, one_pow]
theorem pow_add (a : A) (m n : ℕ) : a^(m + n) = a^m * a^n :=
begin
induction n with n ih,
{krewrite [nat.add_zero, pow_zero, mul_one]},
rewrite [add_succ, *pow_succ', ih, mul.assoc]
end
theorem pow_mul (a : A) (m : ℕ) : Π n, a^(m * n) = (a^m)^n
| 0 := by rewrite [nat.mul_zero, pow_zero]
| (succ n) := by rewrite [nat.mul_succ, pow_add, pow_succ', pow_mul]
theorem pow_comm (a : A) (m n : ℕ) : a^m * a^n = a^n * a^m :=
by rewrite [-*pow_add, add.comm]
end monoid
/- commutative monoid -/
section comm_monoid
open nat
variable [s : comm_monoid A]
include s
theorem mul_pow (a b : A) : Π n, (a * b)^n = a^n * b^n
| 0 := by rewrite [*pow_zero, mul_one]
| (succ n) := by rewrite [*pow_succ', mul_pow, *mul.assoc, mul.left_comm a]
end comm_monoid
section group
variable [s : group A]
include s
section nat
open nat
theorem inv_pow (a : A) : Πn, (a⁻¹)^n = (a^n)⁻¹
| 0 := by rewrite [*pow_zero, one_inv]
| (succ n) := by rewrite [pow_succ, pow_succ', inv_pow, mul_inv]
theorem pow_sub (a : A) {m n : ℕ} (H : m ≥ n) : a^(m - n) = a^m * (a^n)⁻¹ :=
have H1 : m - n + n = m, from nat.sub_add_cancel H,
have H2 : a^(m - n) * a^n = a^m, by rewrite [-pow_add, H1],
eq_mul_inv_of_mul_eq H2
theorem pow_inv_comm (a : A) : Πm n, (a⁻¹)^m * a^n = a^n * (a⁻¹)^m
| 0 n := by rewrite [*pow_zero, one_mul, mul_one]
| m 0 := by rewrite [*pow_zero, one_mul, mul_one]
| (succ m) (succ n) := by rewrite [pow_succ' at {1}, pow_succ at {1}, pow_succ', pow_succ,
*mul.assoc, inv_mul_cancel_left, mul_inv_cancel_left, pow_inv_comm]
lemma respect_pow [group B] (f : A → B) [is_mul_hom f] (a : A) : Πn, f (a ^ n) = (f a) ^ n
| 0 := respect_one f
| (succ n) := by rewrite [pow_succ, respect_mul, respect_pow]
end nat
open int
definition gpow (a : A) : ℤ → A
| (of_nat n) := a^n
| -[1+n] := (a^(nat.succ n))⁻¹
open nat
lemma gpow_zero (a : A) : gpow a 0 = 1 := rfl
lemma gpow_one (a : A) : gpow a 1 = a := pow_one a
lemma gpow_eq_pow (a : A) (n : ℕ) : gpow a n = a^n := by reflexivity
private lemma gpow_add_aux (a : A) (m n : ℕ) :
gpow a ((of_nat m) + -[1+n]) = gpow a (of_nat m) * gpow a (-[1+n]) :=
sum.elim (nat.lt_sum_ge m (nat.succ n))
(assume H : (m < nat.succ n),
have H1 : (#nat nat.succ n - m > nat.zero), from nat.sub_pos_of_lt H,
calc
gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n)) : rfl
... = gpow a (-[1+ nat.pred (nat.sub (nat.succ n) m)]) : {sub_nat_nat_of_lt H}
... = (a ^ (nat.succ (nat.pred (nat.sub (nat.succ n) m))))⁻¹ : rfl
... = (a ^ (nat.succ n) * (a ^ m)⁻¹)⁻¹ :
by krewrite [succ_pred_of_pos H1, pow_sub a (nat.le_of_lt H)]
... = a ^ m * (a ^ (nat.succ n))⁻¹ :
by rewrite [mul_inv, inv_inv]
... = gpow a (of_nat m) * gpow a (-[1+n]) : rfl)
(assume H : (m ≥ nat.succ n),
calc
gpow a ((of_nat m) + -[1+n]) = gpow a (sub_nat_nat m (nat.succ n)) : rfl
... = gpow a (#nat m - nat.succ n) : {sub_nat_nat_of_ge H}
... = a ^ m * (a ^ (nat.succ n))⁻¹ : pow_sub a H
... = gpow a (of_nat m) * gpow a (-[1+n]) : rfl)
theorem gpow_add (a : A) : Πi j : int, gpow a (i + j) = gpow a i * gpow a j
| (of_nat m) (of_nat n) := !pow_add
| (of_nat m) -[1+n] := !gpow_add_aux
| -[1+m] (of_nat n) := by rewrite [add.comm, gpow_add_aux, ↑gpow, -*inv_pow, pow_inv_comm]
| -[1+m] -[1+n] :=
calc
gpow a (-[1+m] + -[1+n]) = (a^(#nat nat.succ m + nat.succ n))⁻¹ : rfl
... = (a^(nat.succ m))⁻¹ * (a^(nat.succ n))⁻¹ : by rewrite [pow_add, pow_comm, mul_inv]
... = gpow a (-[1+m]) * gpow a (-[1+n]) : rfl
theorem gpow_comm (a : A) (i j : ℤ) : gpow a i * gpow a j = gpow a j * gpow a i :=
by rewrite [-*gpow_add, add.comm]
lemma gpow_neg (a : A) : Π(n : ℤ), gpow a (-n) = (gpow a n)⁻¹
| (of_nat n) := begin cases n with n, exact !one_inv⁻¹, reflexivity end
| -[1+n] := by rewrite [↑gpow at {2}, inv_inv]
lemma inv_gpow (a : A) : Π(n : ℤ), gpow a⁻¹ n = (gpow a n)⁻¹
| (of_nat n) := !inv_pow
| -[1+n] := by rewrite [↑gpow, inv_pow]
private lemma gpow_mul_aux (a : A) (m n : ℕ) :
gpow a ((of_nat m) * -[1+n]) = gpow (gpow a (of_nat m)) (-[1+n]) :=
by rewrite [↑gpow at {2,3}, -pow_mul, -gpow_eq_pow, -gpow_neg]
theorem gpow_mul (a : A) : Π n m, gpow a (n * m) = gpow (gpow a n) m
| (of_nat m) (of_nat n) := !pow_mul
| (of_nat m) -[1+n] := by rewrite [↑gpow at {2,3}, -pow_mul, -gpow_eq_pow, -gpow_neg]
| -[1+m] (of_nat n) := by rewrite [↑gpow at {2,3}, inv_pow, -pow_mul, -gpow_eq_pow, -gpow_neg]
| -[1+m] -[1+n] := by rewrite [↑gpow at {2,3}, inv_pow, inv_inv, -pow_mul]
lemma respect_gpow [group B] (f : A → B) [is_mul_hom f] (a : A) : Πn, f (gpow a n) = gpow (f a) n
| (of_nat n) := !respect_pow
| -[1+n] := by rewrite [↑gpow, respect_inv, respect_pow]
end group
section comm_monoid
open int
variable [ab_group A]
theorem mul_gpow (a b : A) : Πi, gpow (a * b) i = gpow a i * gpow b i
| (of_nat n) := !mul_pow
| -[1+n] := by rewrite [↑gpow,-mul_inv,mul.comm,mul_pow]
end comm_monoid
section ordered_ring
open nat
variable [s : linear_ordered_ring A]
include s
theorem pow_pos {a : A} (H : a > 0) (n : ℕ) : a ^ n > 0 :=
begin
induction n,
krewrite pow_zero,
apply zero_lt_one,
rewrite pow_succ',
apply mul_pos,
apply v_0, apply H
end
theorem pow_ge_one_of_ge_one {a : A} (H : a ≥ 1) (n : ℕ) : a ^ n ≥ 1 :=
begin
induction n,
krewrite pow_zero,
apply le.refl,
rewrite [pow_succ', -mul_one 1],
apply mul_le_mul v_0 H zero_le_one,
apply le_of_lt,
apply pow_pos,
apply gt_of_ge_of_gt H zero_lt_one
end
theorem pow_two_add (n : ℕ) : (2:A)^n + 2^n = 2^(succ n) :=
by rewrite [pow_succ', -one_add_one_eq_two, left_distrib, *mul_one]
end ordered_ring
section bundled
open group
lemma to_respect_pow {A B : Group} (f : A →g B) (a : A) (n : ℕ) : f (a ^ n) = (f a) ^ n :=
respect_pow f a n
lemma to_respect_gpow {A B : Group} (f : A →g B) (a : A) (n : ℤ) : f (gpow a n) = gpow (f a) n :=
respect_gpow f a n
end bundled
/- additive monoid -/
section add_monoid
variable [s : add_monoid A]
include s
local attribute add_monoid.to_monoid [trans_instance]
open nat
definition nmul : ℕ → A → A := λ n a, a^n
local infix [priority algebra.prio] `⬝` := nmul
theorem zero_nmul (a : A) : (0:ℕ) ⬝ a = 0 := pow_zero a
theorem succ_nmul (n : ℕ) (a : A) : nmul (succ n) a = a + (nmul n a) := pow_succ a n
theorem succ_nmul' (n : ℕ) (a : A) : succ n ⬝ a = nmul n a + a := pow_succ' a n
theorem nmul_zero (n : ℕ) : n ⬝ 0 = (0:A) := one_pow n
theorem one_nmul (a : A) : 1 ⬝ a = a := pow_one a
theorem add_nmul (m n : ℕ) (a : A) : (m + n) ⬝ a = (m ⬝ a) + (n ⬝ a) := pow_add a m n
theorem mul_nmul (m n : ℕ) (a : A) : (m * n) ⬝ a = m ⬝ (n ⬝ a) :=
eq.subst (mul.comm n m) (pow_mul a n m)
theorem nmul_comm (m n : ℕ) (a : A) : (m ⬝ a) + (n ⬝ a) = (n ⬝ a) + (m ⬝ a) := pow_comm a m n
end add_monoid
namespace ops
infix [priority algebra.prio] `⬝` := nmul
end ops
open algebra.ops
/- additive commutative monoid -/
section add_comm_monoid
open nat
variable [s : add_comm_monoid A]
include s
local attribute add_comm_monoid.to_comm_monoid [trans_instance]
theorem nmul_add (n : ℕ) (a b : A) : n ⬝ (a + b) = (n ⬝ a) + (n ⬝ b) := mul_pow a b n
end add_comm_monoid
section add_group
variable [s : add_group A]
include s
local attribute add_group.to_group [trans_instance]
section nat
open nat
theorem nmul_neg (n : ℕ) (a : A) : n ⬝ (-a) = -(n ⬝ a) := inv_pow a n
theorem sub_nmul {m n : ℕ} (a : A) (H : m ≥ n) : (m - n) ⬝ a = (m ⬝ a) + -(n ⬝ a) := pow_sub a H
theorem nmul_neg_comm (m n : ℕ) (a : A) : (m ⬝ (-a)) + (n ⬝ a) = (n ⬝ a) + (m ⬝ (-a)) :=
pow_inv_comm a m n
lemma respect_nmul [add_group B] (f : A → B) [H : is_add_hom f] (n : ℕ) (a : A) :
f (nmul n a) = nmul n (f a) :=
to_respect_pow (group.homomorphism.mk f H) a n
end nat
open int
definition imul : ℤ → A → A := λ i a, gpow a i
theorem add_imul (i j : ℤ) (a : A) : imul (i + j) a = imul i a + imul j a :=
gpow_add a i j
theorem imul_comm (i j : ℤ) (a : A) : imul i a + imul j a = imul j a + imul i a := gpow_comm a i j
end add_group
section add_ab_group
open int
variable [add_ab_group A]
local attribute add_ab_group.to_ab_group [trans_instance]
theorem imul_add (i : ℤ) (a b : A) : imul i (a + b) = imul i a + imul i b :=
mul_gpow a b i
theorem mul_imul (i j : ℤ) (a : A) : imul (i * j) a = imul i (imul j a) :=
by rewrite [mul.comm]; apply gpow_mul
lemma one_imul (a : A) : imul 1 a = a :=
gpow_one a
lemma respect_imul [add_group B] (f : A → B) [H : is_add_hom f] (n : ℤ) (a : A) :
f (imul n a) = imul n (f a) :=
to_respect_gpow (group.homomorphism.mk f H) a n
end add_ab_group
section bundled
open group
lemma to_respect_nmul {A B : AddGroup} (f : A →g B) (n : ℕ) (a : A) : f (nmul n a) = nmul n (f a) :=
to_respect_pow f a n
lemma to_respect_imul {A B : AddGroup} (f : A →g B) (n : ℤ) (a : A) : f (imul n a) = imul n (f a) :=
to_respect_gpow f a n
end bundled
end algebra
|
1799df3622f451a56b9b0275941c4e4772bf9e43 | efa51dd2edbbbbd6c34bd0ce436415eb405832e7 | /20170116_POPL/profile/leanfmt.lean | d2c27e8594b97e1c7e275d403cf86f9f854dc443 | [
"Apache-2.0"
] | permissive | leanprover/presentations | dd031a05bcb12c8855676c77e52ed84246bd889a | 3ce2d132d299409f1de269fa8e95afa1333d644e | refs/heads/master | 1,688,703,388,796 | 1,686,838,383,000 | 1,687,465,742,000 | 29,750,158 | 12 | 9 | Apache-2.0 | 1,540,211,670,000 | 1,422,042,683,000 | Lean | UTF-8 | Lean | false | false | 3,014 | lean | open tactic
-- set_option trace.compiler true
namespace fmt
meta def format.concat : list format -> format
| [] := format.nil
| (f :: fs) := f ++ format.concat fs
meta definition mk_local (n : name) (ty : expr) : expr :=
expr.local_const n n binder_info.default ty
meta def binder (n : format) (ty : format) : format :=
"(" ++ n ++ format.space ++ ":" ++ format.space ++ ty ++ ")"
meta def let_binding (n : format) (ty : format) (val : format) : format :=
"x" ++ format.space ++ ":" ++ format.space ++ ":=" ++ val
def intersperse {A : Type} (elem : A) : list A → list A
| [] := []
| (x :: []) := [x]
| (x :: xs) := x :: elem :: intersperse xs
meta def exp_app (fmt_exp : expr -> format) (fn : expr) (args : list expr) : format :=
fmt_exp fn ++ format.space ++
(format.concat $
intersperse format.space $ list.map (fun e, "(" ++ fmt_exp e ++ ")") args)
/- We define a simple pretty printing function, reusing the `format` type exposed
from the Lean core. -/
meta def exp : expr → format
| (expr.elet n ty val body) :=
"let" ++ let_binding (to_string n) (exp ty) (exp $ expr.instantiate_var body (mk_local n ty)) ++
format.line ++ "in" ++ format.space ++ exp body
| (expr.app f arg) :=
let fn := expr.get_app_fn (expr.app f arg),
args := expr.get_app_args (expr.app f arg)
in exp_app exp fn args
| (expr.const c _) := to_string c
| (expr.local_const n n' bi ty) := to_string n
| (expr.macro _ _ _) := "macro"
| (expr.pi n bi sort ty) :=
"forall" ++ format.space ++ binder (to_string n) (exp sort) ++ "," ++
format.group (format.line ++ format.space ++ exp (expr.instantiate_var ty (mk_local n sort)))
| (expr.lam n bi ty body) :=
"fun" ++ format.space ++ binder (to_string n) (exp ty) ++ "," ++
format.group (format.line ++ exp (expr.instantiate_var body (mk_local n ty)))
| (expr.mvar n ty) := "?" ++ to_string n
| (expr.sort _) := "Type"
| (expr.var i) := "i"
meta def decl : declaration → format
| (declaration.defn n us ty value _ _) :=
"def" ++ format.space ++ to_string n ++ format.space ++ ":" ++ format.space ++ exp ty ++ format.space ++ ":=" ++
format.indent (exp value) 2
| (declaration.ax n us ty) := "axiom" ++ format.space ++ to_string n
| (declaration.cnst n us body _) := "constant" ++ format.space ++ to_string n
| (declaration.thm n us ty body) := "theorem" ++ format.space ++ to_string n
end fmt
/- Turn on the profiler. -/
set_option profiler true
meta def main : tactic unit := do
/- Get the global environment. -/
env ← get_env,
/- Get the global options. -/
opts ← get_options,
/- Do a fold over all the declarations in the environment. -/
let fs := environment.fold env [] (fun decl decls, fmt.decl decl :: decls) in
/- Print all the formatted declarations. -/
monad.mapm (fun f, tactic.trace (format.to_string f opts ++ "\n")) fs,
return ()
/- We can then just run the main function to format all declarations in the environment. -/
-- run_command main
|
da94159cd7f64ca09d17c8cf2542dff66dc0af65 | 88fb7558b0636ec6b181f2a548ac11ad3919f8a5 | /tests/lean/run/dunfold1.lean | 4c5a6aecdef2dc9ec4932c0eb61fe2b2ca7f5d64 | [
"Apache-2.0"
] | permissive | moritayasuaki/lean | 9f666c323cb6fa1f31ac597d777914aed41e3b7a | ae96ebf6ee953088c235ff7ae0e8c95066ba8001 | refs/heads/master | 1,611,135,440,814 | 1,493,852,869,000 | 1,493,852,869,000 | 90,269,903 | 0 | 0 | null | 1,493,906,291,000 | 1,493,906,291,000 | null | UTF-8 | Lean | false | false | 657 | lean | open tactic
set_option pp.all true
def g : nat → nat := λ x, x + 5
example (a b : nat) (p : nat → Prop) (h : p (g (nat.succ (nat.succ a)))) : p (g (a + 2)) :=
by do
t ← target,
new_t ← dsimplify (λ e, failed)
(λ e,
do { new_e ← unfold_projection e, return (new_e, tt) }
<|>
do {
guard ([`add, `nat.add, `one, `zero, `bit0, `bit1]^.any e^.is_app_of),
new_e ← dunfold_expr e, trace e,
trace "===>", trace new_e, trace "-------",
return (new_e, tt) })
t,
expected ← to_expr `(p (g (nat.succ (nat.succ a)))),
guard (new_t = expected),
trace new_t,
assumption
|
e024438e6ecb8cec92ddad059344706d034a9603 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/ring_theory/polynomial/basic.lean | fd1d2109cec9cc1e03953f9aa2a157c0be9a4997 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 26,295 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Ring-theoretic supplement of data.polynomial.
Main result: Hilbert basis theorem, that if a ring is noetherian then so is its polynomial ring.
-/
import algebra.char_p
import data.mv_polynomial.comm_ring
import data.mv_polynomial.equiv
import data.polynomial.field_division
import ring_theory.principal_ideal_domain
noncomputable theory
local attribute [instance, priority 100] classical.prop_decidable
universes u v w
namespace polynomial
instance {R : Type u} [semiring R] (p : ℕ) [h : char_p R p] : char_p (polynomial R) p :=
let ⟨h⟩ := h in ⟨λ n, by rw [← C.map_nat_cast, ← C_0, C_inj, h]⟩
variables (R : Type u) [comm_ring R]
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
⨅ k : ℕ, ⨅ h : ↑k > n, (lcoeff R k).ker
/-- The `R`-submodule of `R[X]` consisting of polynomials of degree < `n`. -/
def degree_lt (n : ℕ) : submodule R (polynomial R) :=
⨅ k : ℕ, ⨅ h : k ≥ n, (lcoeff R k).ker
variable {R}
theorem mem_degree_le {n : with_bot ℕ} {f : polynomial R} :
f ∈ degree_le R n ↔ degree f ≤ n :=
by simp only [degree_le, submodule.mem_infi, degree_le_iff_coeff_zero, linear_map.mem_ker]; refl
@[mono] theorem degree_le_mono {m n : with_bot ℕ} (H : m ≤ n) :
degree_le R m ≤ degree_le R n :=
λ f hf, mem_degree_le.2 (le_trans (mem_degree_le.1 hf) H)
theorem degree_le_eq_span_X_pow {n : ℕ} :
degree_le R n = submodule.span R ↑((finset.range (n+1)).image (λ n, X^n) : finset (polynomial R)) :=
begin
apply le_antisymm,
{ intros p hp, replace hp := mem_degree_le.1 hp,
rw [← finsupp.sum_single p, finsupp.sum],
refine submodule.sum_mem _ (λ k hk, _),
show monomial _ _ ∈ _,
have := with_bot.coe_le_coe.1 (finset.sup_le_iff.1 hp k hk),
rw [single_eq_C_mul_X, C_mul'],
refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $
finset.mem_image.2 ⟨_, finset.mem_range.2 (nat.lt_succ_of_le this), rfl⟩) },
rw [submodule.span_le, finset.coe_image, set.image_subset_iff],
intros k hk, apply mem_degree_le.2,
apply le_trans (degree_X_pow_le _) (with_bot.coe_le_coe.2 $ nat.le_of_lt_succ $ finset.mem_range.1 hk)
end
theorem mem_degree_lt {n : ℕ} {f : polynomial R} :
f ∈ degree_lt R n ↔ degree f < n :=
by { simp_rw [degree_lt, submodule.mem_infi, linear_map.mem_ker, degree,
finset.sup_lt_iff (with_bot.bot_lt_coe n), finsupp.mem_support_iff, with_bot.some_eq_coe,
with_bot.coe_lt_coe, lt_iff_not_ge', ne, not_imp_not], refl }
@[mono] theorem degree_lt_mono {m n : ℕ} (H : m ≤ n) :
degree_lt R m ≤ degree_lt R n :=
λ f hf, mem_degree_lt.2 (lt_of_lt_of_le (mem_degree_lt.1 hf) $ with_bot.coe_le_coe.2 H)
theorem degree_lt_eq_span_X_pow {n : ℕ} :
degree_lt R n = submodule.span R ↑((finset.range n).image (λ n, X^n) : finset (polynomial R)) :=
begin
apply le_antisymm,
{ intros p hp, replace hp := mem_degree_lt.1 hp,
rw [← finsupp.sum_single p, finsupp.sum],
refine submodule.sum_mem _ (λ k hk, _),
show monomial _ _ ∈ _,
have := with_bot.coe_lt_coe.1 ((finset.sup_lt_iff $ with_bot.bot_lt_coe n).1 hp k hk),
rw [single_eq_C_mul_X, C_mul'],
refine submodule.smul_mem _ _ (submodule.subset_span $ finset.mem_coe.2 $
finset.mem_image.2 ⟨_, finset.mem_range.2 this, rfl⟩) },
rw [submodule.span_le, finset.coe_image, set.image_subset_iff],
intros k hk, apply mem_degree_lt.2,
exact lt_of_le_of_lt (degree_X_pow_le _) (with_bot.coe_lt_coe.2 $ finset.mem_range.1 hk)
end
/-- Given a polynomial, return the polynomial whose coefficients are in
the ring closure of the original coefficients. -/
def restriction (p : polynomial R) : polynomial (ring.closure (↑p.frange : set R)) :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem
else ring.subset_closure $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
@[simp] theorem coeff_restriction {p : polynomial R} {n : ℕ} : ↑(coeff (restriction p) n) = coeff p n := rfl
@[simp] theorem coeff_restriction' {p : polynomial R} {n : ℕ} : (coeff (restriction p) n).1 = coeff p n := rfl
@[simp] theorem map_restriction (p : polynomial R) : p.restriction.map (algebra_map _ _) = p :=
ext $ λ n, by rw [coeff_map, algebra.is_subring_algebra_map_apply, coeff_restriction]
@[simp] theorem degree_restriction {p : polynomial R} : (restriction p).degree = p.degree := rfl
@[simp] theorem nat_degree_restriction {p : polynomial R} : (restriction p).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_restriction {p : polynomial R} : monic (restriction p) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
@[simp] theorem restriction_zero : restriction (0 : polynomial R) = 0 := rfl
@[simp] theorem restriction_one : restriction (1 : polynomial R) = 1 :=
ext $ λ i, subtype.eq $ by rw [coeff_restriction', coeff_one, coeff_one]; split_ifs; refl
variables {S : Type v} [ring S] {f : R →+* S} {x : S}
theorem eval₂_restriction {p : polynomial R} :
eval₂ f x p = eval₂ (f.comp (is_subring.subtype _)) x p.restriction :=
by { dsimp only [eval₂_eq_sum], refl, }
section to_subring
variables (p : polynomial R) (T : set R) [is_subring T]
/-- Given a polynomial `p` and a subring `T` that contains the coefficients of `p`,
return the corresponding polynomial whose coefficients are in `T. -/
def to_subring (hp : ↑p.frange ⊆ T) : polynomial T :=
⟨p.support, λ i, ⟨p.to_fun i,
if H : p.to_fun i = 0 then H.symm ▸ is_add_submonoid.zero_mem
else hp $ finsupp.mem_frange.2 ⟨H, i, rfl⟩⟩,
λ i, finsupp.mem_support_iff.trans (not_iff_not_of_iff ⟨λ H, subtype.eq H, subtype.mk.inj⟩)⟩
variables (hp : ↑p.frange ⊆ T)
include hp
@[simp] theorem coeff_to_subring {n : ℕ} : ↑(coeff (to_subring p T hp) n) = coeff p n := rfl
@[simp] theorem coeff_to_subring' {n : ℕ} : (coeff (to_subring p T hp) n).1 = coeff p n := rfl
@[simp] theorem degree_to_subring : (to_subring p T hp).degree = p.degree := rfl
@[simp] theorem nat_degree_to_subring : (to_subring p T hp).nat_degree = p.nat_degree := rfl
@[simp] theorem monic_to_subring : monic (to_subring p T hp) ↔ monic p :=
⟨λ H, congr_arg subtype.val H, λ H, subtype.eq H⟩
omit hp
@[simp] theorem to_subring_zero : to_subring (0 : polynomial R) T (set.empty_subset _) = 0 := rfl
@[simp] theorem to_subring_one : to_subring (1 : polynomial R) T
(set.subset.trans (finset.coe_subset.2 finsupp.frange_single)
(finset.singleton_subset_set_iff.2 is_submonoid.one_mem)) = 1 :=
ext $ λ i, subtype.eq $ by rw [coeff_to_subring', coeff_one, coeff_one]; split_ifs; refl
@[simp] theorem map_to_subring : (p.to_subring T hp).map (is_subring.subtype T) = p :=
ext $ λ n, coeff_map _ _
end to_subring
variables (T : set R) [is_subring T]
/-- Given a polynomial whose coefficients are in some subring, return
the corresponding polynomial whose coefificents are in the ambient ring. -/
def of_subring (p : polynomial T) : polynomial R :=
⟨p.support, subtype.val ∘ p.to_fun,
λ n, finsupp.mem_support_iff.trans (not_iff_not_of_iff
⟨λ h, congr_arg subtype.val h, λ h, subtype.eq h⟩)⟩
@[simp] theorem frange_of_subring {p : polynomial T} :
↑(p.of_subring T).frange ⊆ T :=
λ y H, let ⟨hy, x, hx⟩ := finsupp.mem_frange.1 H in hx ▸ (p.to_fun x).2
end polynomial
variables {R : Type u} {σ : Type v} {M : Type w} [comm_ring R] [add_comm_group M] [module R M]
namespace ideal
open polynomial
/-- The push-forward of an ideal `I` of `R` to `polynomial R` via inclusion
is exactly the set of polynomials whose coefficients are in `I` -/
theorem mem_map_C_iff {I : ideal R} {f : polynomial R} :
f ∈ (ideal.map C I : ideal (polynomial R)) ↔ ∀ n : ℕ, f.coeff n ∈ I :=
begin
split,
{ intros hf,
apply submodule.span_induction hf,
{ intros f hf n,
cases (set.mem_image _ _ _).mp hf with x hx,
rw [← hx.right, coeff_C],
by_cases (n = 0),
{ simpa [h] using hx.left },
{ simp [h] } },
{ simp },
{ exact λ f g hf hg n, by simp [I.add_mem (hf n) (hg n)] },
{ refine λ f g hg n, _,
rw [smul_eq_mul, coeff_mul],
exact I.sum_mem (λ c hc, I.smul_mem (f.coeff c.fst) (hg c.snd)) } },
{ intros hf,
rw ← sum_monomial_eq f,
refine (map C I : ideal (polynomial R)).sum_mem (λ n hn, _),
simp [single_eq_C_mul_X],
rw mul_comm,
exact (map C I : ideal (polynomial R)).smul_mem _ (mem_map_of_mem (hf n)) }
end
lemma quotient_map_C_eq_zero {I : ideal R} :
∀ a ∈ I, ((quotient.mk (map C I : ideal (polynomial R))).comp C) a = 0 :=
begin
intros a ha,
rw [ring_hom.comp_apply, quotient.eq_zero_iff_mem],
exact mem_map_of_mem ha,
end
lemma eval₂_C_mk_eq_zero {I : ideal R} :
∀ f ∈ (map C I : ideal (polynomial R)), eval₂_ring_hom (C.comp (quotient.mk I)) X f = 0 :=
begin
intros a ha,
rw ← sum_monomial_eq a,
dsimp,
rw eval₂_sum (C.comp (quotient.mk I)) a monomial X,
refine finset.sum_eq_zero (λ n hn, _),
dsimp,
rw eval₂_monomial (C.comp (quotient.mk I)) X,
refine mul_eq_zero_of_left (polynomial.ext (λ m, _)) (X ^ n),
erw coeff_C,
by_cases h : m = 0,
{ simpa [h] using quotient.eq_zero_iff_mem.2 ((mem_map_C_iff.1 ha) n) },
{ simp [h] }
end
/-- If `I` is an ideal of `R`, then the ring polynomials over the quotient ring `I.quotient` is
isomorphic to the quotient of `polynomial R` by the ideal `map C I`,
where `map C I` contains exactly the polynomials whose coefficients all lie in `I` -/
def polynomial_quotient_equiv_quotient_polynomial {I : ideal R} :
polynomial (I.quotient) ≃+* (map C I : ideal (polynomial R)).quotient :=
{ to_fun := eval₂_ring_hom
(quotient.lift I ((quotient.mk (map C I : ideal (polynomial R))).comp C) quotient_map_C_eq_zero)
((quotient.mk (map C I : ideal (polynomial R)) X)),
inv_fun := quotient.lift (map C I : ideal (polynomial R))
(eval₂_ring_hom (C.comp (quotient.mk I)) X) eval₂_C_mk_eq_zero,
map_mul' := λ f g, by simp,
map_add' := λ f g, by simp,
left_inv := begin
intro f,
apply polynomial.induction_on' f,
{ simp_intros p q hp hq,
rw [hp, hq] },
{ rintros n ⟨x⟩,
simp [monomial_eq_smul_X, C_mul'] }
end,
right_inv := begin
rintro ⟨f⟩,
apply polynomial.induction_on' f,
{ simp_intros p q hp hq,
rw [hp, hq] },
{ intros n a,
simp [monomial_eq_smul_X, ← C_mul' a (X ^ n)] },
end,
}
/-- Transport an ideal of `R[X]` to an `R`-submodule of `R[X]`. -/
def of_polynomial (I : ideal (polynomial R)) : submodule R (polynomial R) :=
{ carrier := I.carrier,
zero_mem' := I.zero_mem,
add_mem' := λ _ _, I.add_mem,
smul_mem' := λ c x H, by rw [← C_mul']; exact submodule.smul_mem _ _ H }
variables {I : ideal (polynomial R)}
theorem mem_of_polynomial (x) : x ∈ I.of_polynomial ↔ x ∈ I := iff.rfl
variables (I)
/-- Given an ideal `I` of `R[X]`, make the `R`-submodule of `I`
consisting of polynomials of degree ≤ `n`. -/
def degree_le (n : with_bot ℕ) : submodule R (polynomial R) :=
degree_le R n ⊓ I.of_polynomial
/-- Given an ideal `I` of `R[X]`, make the ideal in `R` of
leading coefficients of polynomials in `I` with degree ≤ `n`. -/
def leading_coeff_nth (n : ℕ) : ideal R :=
(I.degree_le n).map $ lcoeff R n
theorem mem_leading_coeff_nth (n : ℕ) (x) :
x ∈ I.leading_coeff_nth n ↔ ∃ p ∈ I, degree p ≤ n ∧ leading_coeff p = x :=
begin
simp only [leading_coeff_nth, degree_le, submodule.mem_map, lcoeff_apply, submodule.mem_inf, mem_degree_le],
split,
{ rintro ⟨p, ⟨hpdeg, hpI⟩, rfl⟩,
cases lt_or_eq_of_le hpdeg with hpdeg hpdeg,
{ refine ⟨0, I.zero_mem, bot_le, _⟩,
rw [leading_coeff_zero, eq_comm],
exact coeff_eq_zero_of_degree_lt hpdeg },
{ refine ⟨p, hpI, le_of_eq hpdeg, _⟩,
rw [leading_coeff, nat_degree, hpdeg], refl } },
{ rintro ⟨p, hpI, hpdeg, rfl⟩,
have : nat_degree p + (n - nat_degree p) = n,
{ exact nat.add_sub_cancel' (nat_degree_le_of_degree_le hpdeg) },
refine ⟨p * X ^ (n - nat_degree p), ⟨_, I.mul_mem_right hpI⟩, _⟩,
{ apply le_trans (degree_mul_le _ _) _,
apply le_trans (add_le_add (degree_le_nat_degree) (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, this],
exact le_refl _ },
{ rw [leading_coeff, ← coeff_mul_X_pow p (n - nat_degree p), this] } }
end
theorem mem_leading_coeff_nth_zero (x) :
x ∈ I.leading_coeff_nth 0 ↔ C x ∈ I :=
(mem_leading_coeff_nth _ _ _).trans
⟨λ ⟨p, hpI, hpdeg, hpx⟩, by rwa [← hpx, leading_coeff,
nat.eq_zero_of_le_zero (nat_degree_le_of_degree_le hpdeg),
← eq_C_of_degree_le_zero hpdeg],
λ hx, ⟨C x, hx, degree_C_le, leading_coeff_C x⟩⟩
theorem leading_coeff_nth_mono {m n : ℕ} (H : m ≤ n) :
I.leading_coeff_nth m ≤ I.leading_coeff_nth n :=
begin
intros r hr,
simp only [submodule.mem_coe, mem_leading_coeff_nth] at hr ⊢,
rcases hr with ⟨p, hpI, hpdeg, rfl⟩,
refine ⟨p * X ^ (n - m), I.mul_mem_right hpI, _, leading_coeff_mul_X_pow⟩,
refine le_trans (degree_mul_le _ _) _,
refine le_trans (add_le_add hpdeg (degree_X_pow_le _)) _,
rw [← with_bot.coe_add, nat.add_sub_cancel' H],
exact le_refl _
end
/-- Given an ideal `I` in `R[X]`, make the ideal in `R` of the
leading coefficients in `I`. -/
def leading_coeff : ideal R :=
⨆ n : ℕ, I.leading_coeff_nth n
theorem mem_leading_coeff (x) :
x ∈ I.leading_coeff ↔ ∃ p ∈ I, polynomial.leading_coeff p = x :=
begin
rw [leading_coeff, submodule.mem_supr_of_directed],
simp only [mem_leading_coeff_nth],
{ split, { rintro ⟨i, p, hpI, hpdeg, rfl⟩, exact ⟨p, hpI, rfl⟩ },
rintro ⟨p, hpI, rfl⟩, exact ⟨nat_degree p, p, hpI, degree_le_nat_degree, rfl⟩ },
intros i j, exact ⟨i + j, I.leading_coeff_nth_mono (nat.le_add_right _ _),
I.leading_coeff_nth_mono (nat.le_add_left _ _)⟩
end
theorem is_fg_degree_le [is_noetherian_ring R] (n : ℕ) :
submodule.fg (I.degree_le n) :=
is_noetherian_submodule_left.1 (is_noetherian_of_fg_of_noetherian _
⟨_, degree_le_eq_span_X_pow.symm⟩) _
end ideal
/-- Hilbert basis theorem: a polynomial ring over a noetherian ring is a noetherian ring. -/
protected theorem polynomial.is_noetherian_ring [is_noetherian_ring R] :
is_noetherian_ring (polynomial R) :=
⟨assume I : ideal (polynomial R),
let L := I.leading_coeff in
let M := well_founded.min (is_noetherian_iff_well_founded.1 (by apply_instance))
(set.range I.leading_coeff_nth) ⟨_, ⟨0, rfl⟩⟩ in
have hm : M ∈ set.range I.leading_coeff_nth := well_founded.min_mem _ _ _,
let ⟨N, HN⟩ := hm, ⟨s, hs⟩ := I.is_fg_degree_le N in
have hm2 : ∀ k, I.leading_coeff_nth k ≤ M := λ k, or.cases_on (le_or_lt k N)
(λ h, HN ▸ I.leading_coeff_nth_mono h)
(λ h x hx, classical.by_contradiction $ λ hxm,
have ¬M < I.leading_coeff_nth k, by refine well_founded.not_lt_min
(well_founded_submodule_gt _ _) _ _ _; exact ⟨k, rfl⟩,
this ⟨HN ▸ I.leading_coeff_nth_mono (le_of_lt h), λ H, hxm (H hx)⟩),
have hs2 : ∀ {x}, x ∈ I.degree_le N → x ∈ ideal.span (↑s : set (polynomial R)),
from hs ▸ λ x hx, submodule.span_induction hx (λ _ hx, ideal.subset_span hx) (ideal.zero_mem _)
(λ _ _, ideal.add_mem _) (λ c f hf, f.C_mul' c ▸ ideal.mul_mem_left _ hf),
⟨s, le_antisymm (ideal.span_le.2 $ λ x hx, have x ∈ I.degree_le N, from hs ▸ submodule.subset_span hx, this.2) $ begin
change I ≤ ideal.span ↑s,
intros p hp, generalize hn : p.nat_degree = k,
induction k using nat.strong_induction_on with k ih generalizing p,
cases le_or_lt k N,
{ subst k, refine hs2 ⟨polynomial.mem_degree_le.2
(le_trans polynomial.degree_le_nat_degree $ with_bot.coe_le_coe.2 h), hp⟩ },
{ have hp0 : p ≠ 0,
{ rintro rfl, cases hn, exact nat.not_lt_zero _ h },
have : (0 : R) ≠ 1,
{ intro h, apply hp0, ext i, refine (mul_one _).symm.trans _,
rw [← h, mul_zero], refl },
haveI : nontrivial R := ⟨⟨0, 1, this⟩⟩,
have : p.leading_coeff ∈ I.leading_coeff_nth N,
{ rw HN, exact hm2 k ((I.mem_leading_coeff_nth _ _).2
⟨_, hp, hn ▸ polynomial.degree_le_nat_degree, rfl⟩) },
rw I.mem_leading_coeff_nth at this,
rcases this with ⟨q, hq, hdq, hlqp⟩,
have hq0 : q ≠ 0,
{ intro H, rw [← polynomial.leading_coeff_eq_zero] at H,
rw [hlqp, polynomial.leading_coeff_eq_zero] at H, exact hp0 H },
have h1 : p.degree = (q * polynomial.X ^ (k - q.nat_degree)).degree,
{ rw [polynomial.degree_mul', polynomial.degree_X_pow],
rw [polynomial.degree_eq_nat_degree hp0, polynomial.degree_eq_nat_degree hq0],
rw [← with_bot.coe_add, nat.add_sub_cancel', hn],
{ refine le_trans (polynomial.nat_degree_le_of_degree_le hdq) (le_of_lt h) },
rw [polynomial.leading_coeff_X_pow, mul_one],
exact mt polynomial.leading_coeff_eq_zero.1 hq0 },
have h2 : p.leading_coeff = (q * polynomial.X ^ (k - q.nat_degree)).leading_coeff,
{ rw [← hlqp, polynomial.leading_coeff_mul_X_pow] },
have := polynomial.degree_sub_lt h1 hp0 h2,
rw [polynomial.degree_eq_nat_degree hp0] at this,
rw ← sub_add_cancel p (q * polynomial.X ^ (k - q.nat_degree)),
refine (ideal.span ↑s).add_mem _ ((ideal.span ↑s).mul_mem_right _),
{ by_cases hpq : p - q * polynomial.X ^ (k - q.nat_degree) = 0,
{ rw hpq, exact ideal.zero_mem _ },
refine ih _ _ (I.sub_mem hp (I.mul_mem_right hq)) rfl,
rwa [polynomial.degree_eq_nat_degree hpq, with_bot.coe_lt_coe, hn] at this },
exact hs2 ⟨polynomial.mem_degree_le.2 hdq, hq⟩ }
end⟩⟩
attribute [instance] polynomial.is_noetherian_ring
namespace polynomial
theorem exists_irreducible_of_degree_pos {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : 0 < f.degree) : ∃ g, irreducible g ∧ g ∣ f :=
wf_dvd_monoid.exists_irreducible_factor
(λ huf, ne_of_gt hf $ degree_eq_zero_of_is_unit huf)
(λ hf0, not_lt_of_lt hf $ hf0.symm ▸ (@degree_zero R _).symm ▸ with_bot.bot_lt_coe _)
theorem exists_irreducible_of_nat_degree_pos {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : 0 < f.nat_degree) : ∃ g, irreducible g ∧ g ∣ f :=
exists_irreducible_of_degree_pos $ by { contrapose! hf, exact nat_degree_le_of_degree_le hf }
theorem exists_irreducible_of_nat_degree_ne_zero {R : Type u} [integral_domain R] [is_noetherian_ring R]
{f : polynomial R} (hf : f.nat_degree ≠ 0) : ∃ g, irreducible g ∧ g ∣ f :=
exists_irreducible_of_nat_degree_pos $ nat.pos_of_ne_zero hf
lemma linear_independent_powers_iff_eval₂
(f : M →ₗ[R] M) (v : M) :
linear_independent R (λ n : ℕ, (f ^ n) v)
↔ ∀ (p : polynomial R), aeval f p v = 0 → p = 0 :=
begin
rw linear_independent_iff,
simp only [finsupp.total_apply, aeval_endomorphism],
refl
end
lemma disjoint_ker_aeval_of_coprime
(f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) :
disjoint (aeval f p).ker (aeval f q).ker :=
begin
intros v hv,
rcases hpq with ⟨p', q', hpq'⟩,
simpa [linear_map.mem_ker.1 (submodule.mem_inf.1 hv).1,
linear_map.mem_ker.1 (submodule.mem_inf.1 hv).2]
using congr_arg (λ p : polynomial R, aeval f p v) hpq'.symm,
end
lemma sup_aeval_range_eq_top_of_coprime
(f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) :
(aeval f p).range ⊔ (aeval f q).range = ⊤ :=
begin
rw eq_top_iff,
intros v hv,
rw submodule.mem_sup,
rcases hpq with ⟨p', q', hpq'⟩,
use aeval f (p * p') v,
use linear_map.mem_range.2 ⟨aeval f p' v, by simp only [linear_map.mul_app, aeval_mul]⟩,
use aeval f (q * q') v,
use linear_map.mem_range.2 ⟨aeval f q' v, by simp only [linear_map.mul_app, aeval_mul]⟩,
simpa only [mul_comm p p', mul_comm q q', aeval_one, aeval_add]
using congr_arg (λ p : polynomial R, aeval f p v) hpq'
end
lemma sup_ker_aeval_le_ker_aeval_mul {f : M →ₗ[R] M} {p q : polynomial R} :
(aeval f p).ker ⊔ (aeval f q).ker ≤ (aeval f (p * q)).ker :=
begin
intros v hv,
rcases submodule.mem_sup.1 hv with ⟨x, hx, y, hy, hxy⟩,
have h_eval_x : aeval f (p * q) x = 0,
{ rw [mul_comm, aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hx, linear_map.map_zero] },
have h_eval_y : aeval f (p * q) y = 0,
{ rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hy, linear_map.map_zero] },
rw [linear_map.mem_ker, ←hxy, linear_map.map_add, h_eval_x, h_eval_y, add_zero],
end
lemma sup_ker_aeval_eq_ker_aeval_mul_of_coprime
(f : M →ₗ[R] M) {p q : polynomial R} (hpq : is_coprime p q) :
(aeval f p).ker ⊔ (aeval f q).ker = (aeval f (p * q)).ker :=
begin
apply le_antisymm sup_ker_aeval_le_ker_aeval_mul,
intros v hv,
rw submodule.mem_sup,
rcases hpq with ⟨p', q', hpq'⟩,
have h_eval₂_qpp' := calc
aeval f (q * (p * p')) v = aeval f (p' * (p * q)) v :
by rw [mul_comm, mul_assoc, mul_comm, mul_assoc, mul_comm q p]
... = 0 :
by rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hv, linear_map.map_zero],
have h_eval₂_pqq' := calc
aeval f (p * (q * q')) v = aeval f (q' * (p * q)) v :
by rw [←mul_assoc, mul_comm]
... = 0 :
by rw [aeval_mul, linear_map.mul_apply, linear_map.mem_ker.1 hv, linear_map.map_zero],
rw aeval_mul at h_eval₂_qpp' h_eval₂_pqq',
refine ⟨aeval f (q * q') v, linear_map.mem_ker.1 h_eval₂_pqq',
aeval f (p * p') v, linear_map.mem_ker.1 h_eval₂_qpp', _⟩,
rw [add_comm, mul_comm p p', mul_comm q q'],
simpa using congr_arg (λ p : polynomial R, aeval f p v) hpq'
end
end polynomial
namespace mv_polynomial
lemma is_noetherian_ring_fin_0 [is_noetherian_ring R] :
is_noetherian_ring (mv_polynomial (fin 0) R) :=
is_noetherian_ring_of_ring_equiv R
((mv_polynomial.pempty_ring_equiv R).symm.trans
(mv_polynomial.ring_equiv_of_equiv _ fin_zero_equiv'.symm))
theorem is_noetherian_ring_fin [is_noetherian_ring R] :
∀ {n : ℕ}, is_noetherian_ring (mv_polynomial (fin n) R)
| 0 := is_noetherian_ring_fin_0
| (n+1) :=
@is_noetherian_ring_of_ring_equiv (polynomial (mv_polynomial (fin n) R)) _ _ _
(mv_polynomial.fin_succ_equiv _ n).symm
(@polynomial.is_noetherian_ring (mv_polynomial (fin n) R) _ (is_noetherian_ring_fin))
/-- The multivariate polynomial ring in finitely many variables over a noetherian ring
is itself a noetherian ring. -/
instance is_noetherian_ring [fintype σ] [is_noetherian_ring R] :
is_noetherian_ring (mv_polynomial σ R) :=
trunc.induction_on (fintype.equiv_fin σ) $ λ e,
@is_noetherian_ring_of_ring_equiv (mv_polynomial (fin (fintype.card σ)) R) _ _ _
(mv_polynomial.ring_equiv_of_equiv _ e.symm) is_noetherian_ring_fin
lemma is_integral_domain_fin_zero (R : Type u) [comm_ring R] (hR : is_integral_domain R) :
is_integral_domain (mv_polynomial (fin 0) R) :=
ring_equiv.is_integral_domain R hR
((ring_equiv_of_equiv R fin_zero_equiv').trans (mv_polynomial.pempty_ring_equiv R))
/-- Auxilliary lemma:
Multivariate polynomials over an integral domain
with variables indexed by `fin n` form an integral domain.
This fact is proven inductively,
and then used to prove the general case without any finiteness hypotheses.
See `mv_polynomial.integral_domain` for the general case. -/
lemma is_integral_domain_fin (R : Type u) [comm_ring R] (hR : is_integral_domain R) :
∀ (n : ℕ), is_integral_domain (mv_polynomial (fin n) R)
| 0 := is_integral_domain_fin_zero R hR
| (n+1) :=
ring_equiv.is_integral_domain
(polynomial (mv_polynomial (fin n) R))
(is_integral_domain_fin n).polynomial
(mv_polynomial.fin_succ_equiv _ n)
lemma is_integral_domain_fintype (R : Type u) (σ : Type v) [comm_ring R] [fintype σ]
(hR : is_integral_domain R) : is_integral_domain (mv_polynomial σ R) :=
trunc.induction_on (fintype.equiv_fin σ) $ λ e,
@ring_equiv.is_integral_domain _ (mv_polynomial (fin $ fintype.card σ) R) _ _
(mv_polynomial.is_integral_domain_fin _ hR _)
(ring_equiv_of_equiv R e)
/-- Auxilliary definition:
Multivariate polynomials in finitely many variables over an integral domain form an integral domain.
This fact is proven by transport of structure from the `mv_polynomial.integral_domain_fin`,
and then used to prove the general case without finiteness hypotheses.
See `mv_polynomial.integral_domain` for the general case. -/
def integral_domain_fintype (R : Type u) (σ : Type v) [integral_domain R] [fintype σ] :
integral_domain (mv_polynomial σ R) :=
@is_integral_domain.to_integral_domain _ _ $ mv_polynomial.is_integral_domain_fintype R σ $
integral_domain.to_is_integral_domain R
protected theorem eq_zero_or_eq_zero_of_mul_eq_zero {R : Type u} [integral_domain R] {σ : Type v}
(p q : mv_polynomial σ R) (h : p * q = 0) : p = 0 ∨ q = 0 :=
begin
obtain ⟨s, p, rfl⟩ := exists_finset_rename p,
obtain ⟨t, q, rfl⟩ := exists_finset_rename q,
have : rename (subtype.map id (finset.subset_union_left s t) : {x // x ∈ s} → {x // x ∈ s ∪ t}) p *
rename (subtype.map id (finset.subset_union_right s t) : {x // x ∈ t} → {x // x ∈ s ∪ t}) q = 0,
{ apply rename_injective _ subtype.val_injective, simpa using h },
letI := mv_polynomial.integral_domain_fintype R {x // x ∈ (s ∪ t)},
rw mul_eq_zero at this,
cases this; [left, right],
all_goals { simpa using congr_arg (rename subtype.val) this }
end
/-- The multivariate polynomial ring over an integral domain is an integral domain. -/
instance {R : Type u} {σ : Type v} [integral_domain R] :
integral_domain (mv_polynomial σ R) :=
{ eq_zero_or_eq_zero_of_mul_eq_zero := mv_polynomial.eq_zero_or_eq_zero_of_mul_eq_zero,
exists_pair_ne := ⟨0, 1, λ H,
begin
have : eval₂ (ring_hom.id _) (λ s, (0:R)) (0 : mv_polynomial σ R) =
eval₂ (ring_hom.id _) (λ s, (0:R)) (1 : mv_polynomial σ R),
{ congr, exact H },
simpa,
end⟩,
.. (by apply_instance : comm_ring (mv_polynomial σ R)) }
end mv_polynomial
|
367424fa4d218e50e1e5d8179bae9278f7862ef7 | 432d948a4d3d242fdfb44b81c9e1b1baacd58617 | /src/order/well_founded_set.lean | b27a1dfe9562e2da6c4a07df2795bf78de4a272a | [
"Apache-2.0"
] | permissive | JLimperg/aesop3 | 306cc6570c556568897ed2e508c8869667252e8a | a4a116f650cc7403428e72bd2e2c4cda300fe03f | refs/heads/master | 1,682,884,916,368 | 1,620,320,033,000 | 1,620,320,033,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 23,993 | lean | /-
Copyright (c) 2021 Aaron Anderson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Aaron Anderson
-/
import data.set.finite
import data.fintype.basic
import order.well_founded
import order.order_iso_nat
import algebra.pointwise
/-!
# Well-founded sets
A well-founded subset of an ordered type is one on which the relation `<` is well-founded.
## Main Definitions
* `set.well_founded_on s r` indicates that the relation `r` is
well-founded when restricted to the set `s`.
* `set.is_wf s` indicates that `<` is well-founded when restricted to `s`.
* `set.is_pwo s` indicates that any infinite sequence of elements in `s`
contains an infinite monotone subsequence.
### Definitions for Hahn Series
* `set.add_antidiagonal s t a` and `set.mul_antidiagonal s t a` are the sets of pairs of elements
from `s` and `t` that add/multiply to `a`.
* `finset.add_antidiagonal` and `finset.mul_antidiagonal` are finite versions of
`set.add_antidiagonal` and `set.mul_antidiagonal` defined when `s` and `t` are well-founded.
## Main Results
* `set.well_founded_on_iff` relates `well_founded_on` to the well-foundedness of a relation on the
original type, to avoid dealing with subtypes.
* `set.is_wf.mono` shows that a subset of a well-founded subset is well-founded.
* `set.is_wf.union` shows that the union of two well-founded subsets is well-founded.
* `finset.is_wf` shows that all `finset`s are well-founded.
-/
variables {α : Type*}
namespace set
/-- `s.well_founded_on r` indicates that the relation `r` is well-founded when restricted to `s`. -/
def well_founded_on (s : set α) (r : α → α → Prop) : Prop :=
well_founded (λ (a : s) (b : s), r a b)
lemma well_founded_on_iff {s : set α} {r : α → α → Prop} :
s.well_founded_on r ↔ well_founded (λ (a b : α), r a b ∧ a ∈ s ∧ b ∈ s) :=
begin
have f : rel_embedding (λ (a : s) (b : s), r a b) (λ (a b : α), r a b ∧ a ∈ s ∧ b ∈ s) :=
⟨⟨coe, subtype.coe_injective⟩, λ a b, by simp⟩,
refine ⟨λ h, _, f.well_founded⟩,
rw well_founded.well_founded_iff_has_min,
intros t ht,
by_cases hst : (s ∩ t).nonempty,
{ rw ← subtype.preimage_coe_nonempty at hst,
rcases well_founded.well_founded_iff_has_min.1 h (coe ⁻¹' t) hst with ⟨⟨m, ms⟩, mt, hm⟩,
exact ⟨m, mt, λ x xt ⟨xm, xs, ms⟩, hm ⟨x, xs⟩ xt xm⟩ },
{ rcases ht with ⟨m, mt⟩,
exact ⟨m, mt, λ x xt ⟨xm, xs, ms⟩, hst ⟨m, ⟨ms, mt⟩⟩⟩ }
end
instance is_strict_order.subset {s : set α} {r : α → α → Prop} [is_strict_order α r] :
is_strict_order α (λ (a b : α), r a b ∧ a ∈ s ∧ b ∈ s) :=
{ to_is_irrefl := ⟨λ a con, irrefl_of r a con.1 ⟩,
to_is_trans := ⟨λ a b c ab bc, ⟨trans_of r ab.1 bc.1, ab.2.1, bc.2.2⟩ ⟩ }
theorem well_founded_on_iff_no_descending_seq {s : set α} {r : α → α → Prop} [is_strict_order α r] :
s.well_founded_on r ↔ ∀ (f : ((>) : ℕ → ℕ → Prop) ↪r r), ¬ (range f) ⊆ s :=
begin
rw [well_founded_on_iff, rel_embedding.well_founded_iff_no_descending_seq],
refine ⟨λ h f con, h begin
use f,
{ exact f.injective },
{ intros a b,
simp only [con (mem_range_self a), con (mem_range_self b), and_true, gt_iff_lt,
function.embedding.coe_fn_mk, f.map_rel_iff] }
end, λ h con, _⟩,
rcases con with ⟨f, hf⟩,
have hfs' : ∀ n : ℕ, f n ∈ s := λ n, (hf.2 n.lt_succ_self).2.2,
refine h ⟨f, λ a b, _⟩ (λ n hn, _),
{ rw ← hf,
exact ⟨λ h, ⟨h, hfs' _, hfs' _⟩, λ h, h.1⟩ },
{ rcases set.mem_range.1 hn with ⟨m, hm⟩,
rw ← hm,
apply hfs' }
end
section has_lt
variables [has_lt α]
/-- `s.is_wf` indicates that `<` is well-founded when restricted to `s`. -/
def is_wf (s : set α) : Prop := well_founded_on s (<)
lemma is_wf_univ_iff : is_wf (univ : set α) ↔ well_founded ((<) : α → α → Prop) :=
by simp [is_wf, well_founded_on_iff]
variables {s t : set α}
theorem is_wf.mono (h : is_wf t) (st : s ⊆ t) : is_wf s :=
begin
rw [is_wf, well_founded_on_iff] at *,
refine subrelation.wf (λ x y xy, _) h,
exact ⟨xy.1, st xy.2.1, st xy.2.2⟩,
end
end has_lt
section partial_order
variables [partial_order α] {s t : set α} {a : α}
theorem is_wf_iff_no_descending_seq :
is_wf s ↔ ∀ (f : (order_dual ℕ) ↪o α), ¬ (range f) ⊆ s :=
begin
haveI : is_strict_order α (λ (a b : α), a < b ∧ a ∈ s ∧ b ∈ s) := {
to_is_irrefl := ⟨λ x con, lt_irrefl x con.1⟩,
to_is_trans := ⟨λ a b c ab bc, ⟨lt_trans ab.1 bc.1, ab.2.1, bc.2.2⟩⟩,
},
rw [is_wf, well_founded_on_iff_no_descending_seq],
exact ⟨λ h f, h f.lt_embedding, λ h f, h (order_embedding.of_strict_mono
f (λ _ _, f.map_rel_iff.2))⟩,
end
theorem is_wf.union (hs : is_wf s) (ht : is_wf t) : is_wf (s ∪ t) :=
begin
classical,
rw [is_wf_iff_no_descending_seq] at *,
rintros f fst,
have h : infinite (f ⁻¹' s) ∨ infinite (f ⁻¹' t),
{ have h : infinite (univ : set ℕ) := infinite_univ,
have hpre : f ⁻¹' (s ∪ t) = set.univ,
{ rw [← image_univ, image_subset_iff, univ_subset_iff] at fst,
exact fst },
rw preimage_union at hpre,
rw ← hpre at h,
rw [infinite, infinite],
rw infinite at h,
contrapose! h,
exact finite.union h.1 h.2, },
rw [← infinite_coe_iff, ← infinite_coe_iff] at h,
cases h with inf inf; haveI := inf,
{ apply hs ((nat.order_embedding_of_set (f ⁻¹' s)).dual.trans f),
change range (function.comp f (nat.order_embedding_of_set (f ⁻¹' s))) ⊆ s,
rw [range_comp, image_subset_iff],
simp },
{ apply ht ((nat.order_embedding_of_set (f ⁻¹' t)).dual.trans f),
change range (function.comp f (nat.order_embedding_of_set (f ⁻¹' t))) ⊆ t,
rw [range_comp, image_subset_iff],
simp }
end
end partial_order
end set
namespace set
/-- A subset is partially well-ordered by a relation `r` when any infinite sequence contains
two elements where the first is related to the second by `r`. -/
def partially_well_ordered_on (s) (r : α → α → Prop) : Prop :=
∀ (f : ℕ → α), range f ⊆ s → ∃ (m n : ℕ), m < n ∧ r (f m) (f n)
/-- A subset of a preorder is partially well-ordered when any infinite sequence contains
a monotone subsequence of length 2 (or equivalently, an infinite monotone subsequence). -/
def is_pwo [preorder α] (s) : Prop :=
partially_well_ordered_on s ((≤) : α → α → Prop)
theorem partially_well_ordered_on.mono {s t : set α} {r : α → α → Prop}
(ht : t.partially_well_ordered_on r) (hsub : s ⊆ t) :
s.partially_well_ordered_on r :=
λ f hf, ht f (set.subset.trans hf hsub)
theorem partially_well_ordered_on.image_of_monotone {s : set α}
{r : α → α → Prop} {β : Type*} {r' : β → β → Prop}
(hs : s.partially_well_ordered_on r) {f : α → β} (hf : ∀ a1 a2 : α, r a1 a2 → r' (f a1) (f a2)) :
(f '' s).partially_well_ordered_on r' :=
λ g hg, begin
have h := λ (n : ℕ), ((mem_image _ _ _).1 (hg (mem_range_self n))),
obtain ⟨m, n, hlt, hmn⟩ := hs (λ n, classical.some (h n)) _,
{ refine ⟨m, n, hlt, _⟩,
rw [← (classical.some_spec (h m)).2,
← (classical.some_spec (h n)).2],
apply hf _ _ hmn },
{ rintros _ ⟨n, rfl⟩,
exact (classical.some_spec (h n)).1 }
end
section partial_order
variables {s : set α} {t : set α} {r : α → α → Prop}
theorem partially_well_ordered_on.exists_monotone_subseq [is_refl α r] [is_trans α r]
(h : s.partially_well_ordered_on r) (f : ℕ → α) (hf : range f ⊆ s) :
∃ (g : ℕ ↪o ℕ), ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) :=
begin
obtain ⟨g, h1 | h2⟩ := exists_increasing_or_nonincreasing_subseq r f,
{ refine ⟨g, λ m n hle, _⟩,
obtain hlt | heq := lt_or_eq_of_le hle,
{ exact h1 m n hlt, },
{ rw [heq],
apply refl_of r } },
{ exfalso,
obtain ⟨m, n, hlt, hle⟩ := h (f ∘ g) (subset.trans (range_comp_subset_range _ _) hf),
exact h2 m n hlt hle }
end
theorem partially_well_ordered_on_iff_exists_monotone_subseq [is_refl α r] [is_trans α r] :
s.partially_well_ordered_on r ↔
∀ f : ℕ → α, range f ⊆ s → ∃ (g : ℕ ↪o ℕ), ∀ m n : ℕ, m ≤ n → r (f (g m)) (f (g n)) :=
begin
classical,
split; intros h f hf,
{ exact h.exists_monotone_subseq f hf },
{ obtain ⟨g, gmon⟩ := h f hf,
refine ⟨g 0, g 1, g.lt_iff_lt.2 zero_lt_one, gmon _ _ zero_le_one⟩, }
end
lemma partially_well_ordered_on.well_founded_on [is_partial_order α r]
(h : s.partially_well_ordered_on r) :
s.well_founded_on (λ a b, r a b ∧ a ≠ b) :=
begin
haveI : is_strict_order α (λ a b, r a b ∧ a ≠ b) :=
{ to_is_irrefl := ⟨λ a con, con.2 rfl⟩,
to_is_trans := ⟨λ a b c ab bc, ⟨trans ab.1 bc.1,
λ ac, ab.2 (antisymm ab.1 (ac.symm ▸ bc.1))⟩⟩ },
rw well_founded_on_iff_no_descending_seq,
intros f con,
obtain ⟨m, n, hlt, hle⟩ := h f con,
exact (f.map_rel_iff.2 hlt).2 (antisymm hle (f.map_rel_iff.2 hlt).1).symm,
end
variables [partial_order α]
lemma is_pwo.is_wf (h : s.is_pwo) :
s.is_wf :=
begin
rw [is_wf],
convert h.well_founded_on,
ext x y,
rw lt_iff_le_and_ne,
end
theorem is_pwo.exists_monotone_subseq
(h : s.is_pwo) (f : ℕ → α) (hf : range f ⊆ s) :
∃ (g : ℕ ↪o ℕ), monotone (f ∘ g) :=
h.exists_monotone_subseq f hf
theorem is_pwo_iff_exists_monotone_subseq :
s.is_pwo ↔
∀ f : ℕ → α, range f ⊆ s → ∃ (g : ℕ ↪o ℕ), monotone (f ∘ g) :=
partially_well_ordered_on_iff_exists_monotone_subseq
lemma is_pwo.prod (hs : s.is_pwo)
(ht : t.is_pwo) :
(s.prod t).is_pwo :=
begin
classical,
rw is_pwo_iff_exists_monotone_subseq at *,
intros f hf,
obtain ⟨g1, h1⟩ := hs (prod.fst ∘ f) _,
swap,
{ rw [range_comp, image_subset_iff],
refine subset.trans hf _,
rintros ⟨x1, x2⟩ hx,
simp only [mem_preimage, hx.1] },
obtain ⟨g2, h2⟩ := ht (prod.snd ∘ f ∘ g1) _,
refine ⟨g2.trans g1, λ m n mn, _⟩,
swap,
{ rw [range_comp, image_subset_iff],
refine subset.trans (range_comp_subset_range _ _) (subset.trans hf _),
rintros ⟨x1, x2⟩ hx,
simp only [mem_preimage, hx.2] },
simp only [rel_embedding.coe_trans, function.comp_app],
exact ⟨h1 (g2.le_iff_le.2 mn), h2 mn⟩,
end
theorem is_pwo.image_of_monotone {β : Type*} [partial_order β]
(hs : s.is_pwo) {f : α → β} (hf : monotone f) :
is_pwo (f '' s) :=
hs.image_of_monotone hf
theorem is_pwo.union (hs : is_pwo s) (ht : is_pwo t) : is_pwo (s ∪ t) :=
begin
classical,
rw [is_pwo_iff_exists_monotone_subseq] at *,
rintros f fst,
have h : infinite (f ⁻¹' s) ∨ infinite (f ⁻¹' t),
{ have h : infinite (univ : set ℕ) := infinite_univ,
have hpre : f ⁻¹' (s ∪ t) = set.univ,
{ rw [← image_univ, image_subset_iff, univ_subset_iff] at fst,
exact fst },
rw preimage_union at hpre,
rw ← hpre at h,
rw [infinite, infinite],
rw infinite at h,
contrapose! h,
exact finite.union h.1 h.2, },
rw [← infinite_coe_iff, ← infinite_coe_iff] at h,
cases h with inf inf; haveI := inf,
{ obtain ⟨g, hg⟩ := hs (f ∘ (nat.order_embedding_of_set (f ⁻¹' s))) _,
{ rw [function.comp.assoc, ← rel_embedding.coe_trans] at hg,
exact ⟨_, hg⟩ },
rw [range_comp, image_subset_iff],
simp },
{ obtain ⟨g, hg⟩ := ht (f ∘ (nat.order_embedding_of_set (f ⁻¹' t))) _,
{ rw [function.comp.assoc, ← rel_embedding.coe_trans] at hg,
exact ⟨_, hg⟩ },
rw [range_comp, image_subset_iff],
simp }
end
end partial_order
theorem is_wf.is_pwo [linear_order α] {s : set α}
(hs : s.is_wf) : s.is_pwo :=
λ f hf, begin
rw [is_wf, well_founded_on_iff] at hs,
have hrange : (range f).nonempty := ⟨f 0, mem_range_self 0⟩,
let a := hs.min (range f) hrange,
obtain ⟨m, hm⟩ := hs.min_mem (range f) hrange,
refine ⟨m, m.succ, m.lt_succ_self, le_of_not_lt (λ con, _)⟩,
rw hm at con,
apply hs.not_lt_min (range f) hrange (mem_range_self m.succ)
⟨con, hf (mem_range_self m.succ), hf _⟩,
rw ← hm,
apply mem_range_self,
end
theorem is_wf_iff_is_pwo [linear_order α] {s : set α} :
s.is_wf ↔ s.is_pwo :=
⟨is_wf.is_pwo, is_pwo.is_wf⟩
end set
namespace finset
@[simp]
theorem partially_well_ordered_on {r : α → α → Prop} [is_refl α r] {f : finset α} :
set.partially_well_ordered_on (↑f : set α) r :=
begin
intros g hg,
by_cases hinj : function.injective g,
{ exact (set.infinite_of_injective_forall_mem hinj (set.range_subset_iff.1 hg)
f.finite_to_set).elim },
{ rw [function.injective] at hinj,
push_neg at hinj,
obtain ⟨m, n, gmgn, hne⟩ := hinj,
cases lt_or_gt_of_ne hne with hlt hlt;
{ refine ⟨_, _, hlt, _⟩,
rw gmgn,
exact refl_of r _, } }
end
@[simp]
theorem is_pwo [partial_order α] {f : finset α} :
set.is_pwo (↑f : set α) :=
finset.partially_well_ordered_on
@[simp]
theorem well_founded_on {r : α → α → Prop} [is_strict_order α r] {f : finset α} :
set.well_founded_on (↑f : set α) r :=
begin
rw [set.well_founded_on_iff_no_descending_seq],
intros g con,
apply set.infinite_of_injective_forall_mem g.injective (set.range_subset_iff.1 con),
exact f.finite_to_set,
end
@[simp]
theorem is_wf [partial_order α] {f : finset α} : set.is_wf (↑f : set α) :=
finset.is_pwo.is_wf
end finset
namespace set
variables [partial_order α] {s : set α} {a : α}
theorem finite.is_pwo (h : s.finite) : s.is_pwo :=
begin
rw ← h.coe_to_finset,
exact finset.is_pwo,
end
@[simp]
theorem fintype.is_pwo [fintype α] : s.is_pwo := (finite.of_fintype s).is_pwo
@[simp]
theorem is_pwo_empty : is_pwo (∅ : set α) :=
finite_empty.is_pwo
@[simp]
theorem is_pwo_singleton (a) : is_pwo ({a} : set α) :=
(finite_singleton a).is_pwo
theorem is_pwo.insert (a) (hs : is_pwo s) : is_pwo (insert a s) :=
by { rw ← union_singleton, exact hs.union (is_pwo_singleton a) }
/-- `is_wf.min` returns a minimal element of a nonempty well-founded set. -/
noncomputable def is_wf.min (hs : is_wf s) (hn : s.nonempty) : α :=
hs.min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)
lemma is_wf.min_mem (hs : is_wf s) (hn : s.nonempty) : hs.min hn ∈ s :=
(well_founded.min hs univ (nonempty_iff_univ_nonempty.1 hn.to_subtype)).2
lemma is_wf.not_lt_min (hs : is_wf s) (hn : s.nonempty) (ha : a ∈ s) : ¬ a < hs.min hn :=
hs.not_lt_min univ (nonempty_iff_univ_nonempty.1 hn.to_subtype) (mem_univ (⟨a, ha⟩ : s))
@[simp]
lemma is_wf_min_singleton (a) {hs : is_wf ({a} : set α)} {hn : ({a} : set α).nonempty} :
hs.min hn = a :=
eq_of_mem_singleton (is_wf.min_mem hs hn)
end set
@[simp]
theorem finset.is_wf_sup {ι : Type*} [partial_order α] (f : finset ι) (g : ι → set α)
(hf : ∀ i : ι, i ∈ f → (g i).is_wf) : (f.sup g).is_wf :=
begin
classical,
revert hf,
apply f.induction_on,
{ intro h,
simp [set.is_pwo_empty.is_wf], },
{ intros s f sf hf hsf,
rw finset.sup_insert,
exact (hsf s (finset.mem_insert_self _ _)).union (hf (λ s' s'f, hsf _
(finset.mem_insert_of_mem s'f))) }
end
@[simp]
theorem finset.is_pwo_sup {ι : Type*} [partial_order α] (f : finset ι) (g : ι → set α)
(hf : ∀ i : ι, i ∈ f → (g i).is_pwo) : (f.sup g).is_pwo :=
begin
classical,
revert hf,
apply f.induction_on,
{ intro h,
simp [set.is_pwo_empty.is_wf], },
{ intros s f sf hf hsf,
rw finset.sup_insert,
exact (hsf s (finset.mem_insert_self _ _)).union (hf (λ s' s'f, hsf _
(finset.mem_insert_of_mem s'f))) }
end
namespace set
variables [linear_order α] {s t : set α} {a : α}
lemma is_wf.min_le
(hs : s.is_wf) (hn : s.nonempty) (ha : a ∈ s) : hs.min hn ≤ a :=
le_of_not_lt (hs.not_lt_min hn ha)
lemma is_wf.le_min_iff
(hs : s.is_wf) (hn : s.nonempty) :
a ≤ hs.min hn ↔ ∀ b, b ∈ s → a ≤ b :=
⟨λ ha b hb, le_trans ha (hs.min_le hn hb), λ h, h _ (hs.min_mem _)⟩
lemma is_wf.min_le_min_of_subset
{hs : s.is_wf} {hsn : s.nonempty} {ht : t.is_wf} {htn : t.nonempty} (hst : s ⊆ t) :
ht.min htn ≤ hs.min hsn :=
(is_wf.le_min_iff _ _).2 (λ b hb, ht.min_le htn (hst hb))
lemma is_wf.min_union (hs : s.is_wf) (hsn : s.nonempty) (ht : t.is_wf) (htn : t.nonempty) :
(hs.union ht).min (union_nonempty.2 (or.intro_left _ hsn)) = min (hs.min hsn) (ht.min htn) :=
begin
refine le_antisymm (le_min (is_wf.min_le_min_of_subset (subset_union_left _ _))
(is_wf.min_le_min_of_subset (subset_union_right _ _))) _,
rw min_le_iff,
exact ((mem_union _ _ _).1 ((hs.union ht).min_mem
(union_nonempty.2 (or.intro_left _ hsn)))).imp (hs.min_le _) (ht.min_le _),
end
end set
namespace set
variables {s : set α} {t : set α}
@[to_additive]
theorem is_pwo.mul [ordered_cancel_comm_monoid α] (hs : s.is_pwo) (ht : t.is_pwo) :
is_pwo (s * t) :=
begin
rw ← image_mul_prod,
exact (is_pwo.prod hs ht).image_of_monotone (λ _ _ h, mul_le_mul' h.1 h.2),
end
variable [linear_ordered_cancel_comm_monoid α]
@[to_additive]
theorem is_wf.mul (hs : s.is_wf) (ht : t.is_wf) : is_wf (s * t) :=
(hs.is_pwo.mul ht.is_pwo).is_wf
@[to_additive]
theorem is_wf.min_mul (hs : s.is_wf) (ht : t.is_wf) (hsn : s.nonempty) (htn : t.nonempty) :
(hs.mul ht).min (hsn.mul htn) = hs.min hsn * ht.min htn :=
begin
refine le_antisymm (is_wf.min_le _ _ (mem_mul.2 ⟨_, _, hs.min_mem _, ht.min_mem _, rfl⟩)) _,
rw is_wf.le_min_iff,
rintros _ ⟨x, y, hx, hy, rfl⟩,
exact mul_le_mul' (hs.min_le _ hx) (ht.min_le _ hy),
end
end set
namespace set
/-- `set.mul_antidiagonal s t a` is the set of all pairs of an element in `s` and an element in `t`
that multiply to `a`. -/
@[to_additive "`set.add_antidiagonal s t a` is the set of all pairs of an element in `s`
and an element in `t` that add to `a`."]
def mul_antidiagonal [monoid α] (s t : set α) (a : α) : set (α × α) :=
{ x | x.1 * x.2 = a ∧ x.1 ∈ s ∧ x.2 ∈ t }
namespace mul_antidiagonal
@[simp, to_additive]
lemma mem_mul_antidiagonal [monoid α] {s t : set α} {a : α} {x : α × α} :
x ∈ mul_antidiagonal s t a ↔ x.1 * x.2 = a ∧ x.1 ∈ s ∧ x.2 ∈ t := iff.refl _
section cancel_comm_monoid
variables [cancel_comm_monoid α] {s t : set α} {a : α}
@[to_additive]
lemma fst_eq_fst_iff_snd_eq_snd {x y : (mul_antidiagonal s t a)} :
(x : α × α).fst = (y : α × α).fst ↔ (x : α × α).snd = (y : α × α).snd :=
⟨λ h, begin
have hx := x.2.1,
rw [subtype.val_eq_coe, h] at hx,
apply mul_left_cancel (hx.trans y.2.1.symm),
end, λ h, begin
have hx := x.2.1,
rw [subtype.val_eq_coe, h] at hx,
apply mul_right_cancel (hx.trans y.2.1.symm),
end⟩
@[to_additive]
lemma eq_of_fst_eq_fst {x y : (mul_antidiagonal s t a)}
(h : (x : α × α).fst = (y : α × α).fst) : x = y :=
subtype.ext (prod.ext h (mul_antidiagonal.fst_eq_fst_iff_snd_eq_snd.1 h))
@[to_additive]
lemma eq_of_snd_eq_snd {x y : (mul_antidiagonal s t a)}
(h : (x : α × α).snd = (y : α × α).snd) : x = y :=
subtype.ext (prod.ext (mul_antidiagonal.fst_eq_fst_iff_snd_eq_snd.2 h) h)
end cancel_comm_monoid
section ordered_cancel_comm_monoid
variables [ordered_cancel_comm_monoid α] (s t : set α) (a : α)
@[to_additive]
lemma eq_of_fst_le_fst_of_snd_le_snd {x y : (mul_antidiagonal s t a)}
(h1 : (x : α × α).fst ≤ (y : α × α).fst) (h2 : (x : α × α).snd ≤ (y : α × α).snd ) :
x = y :=
begin
apply eq_of_fst_eq_fst,
cases eq_or_lt_of_le h1 with heq hlt,
{ exact heq },
exfalso,
exact ne_of_lt (mul_lt_mul_of_lt_of_le hlt h2)
((mem_mul_antidiagonal.1 x.2).1.trans (mem_mul_antidiagonal.1 y.2).1.symm)
end
variables {s} {t}
@[to_additive]
theorem finite_of_is_pwo (hs : s.is_pwo) (ht : t.is_pwo) (a) :
(mul_antidiagonal s t a).finite :=
begin
by_contra h,
rw [← set.infinite] at h,
have h1 : (mul_antidiagonal s t a).partially_well_ordered_on (prod.fst ⁻¹'o (≤)),
{ intros f hf,
refine hs (prod.fst ∘ f) _,
rw range_comp,
rintros _ ⟨⟨x, y⟩, hxy, rfl⟩,
exact (mem_mul_antidiagonal.1 (hf hxy)).2.1 },
have h2 : (mul_antidiagonal s t a).partially_well_ordered_on (prod.snd ⁻¹'o (≤)),
{ intros f hf,
refine ht (prod.snd ∘ f) _,
rw range_comp,
rintros _ ⟨⟨x, y⟩, hxy, rfl⟩,
exact (mem_mul_antidiagonal.1 (hf hxy)).2.2 },
obtain ⟨g, hg⟩ := h1.exists_monotone_subseq (λ x, h.nat_embedding _ x) _,
swap, { rintro _ ⟨k, rfl⟩,
exact ((infinite.nat_embedding (s.mul_antidiagonal t a) h) _).2 },
obtain ⟨m, n, mn, h2'⟩ := h2 (λ x, (h.nat_embedding _) (g x)) _,
swap, { rintro _ ⟨k, rfl⟩,
exact ((infinite.nat_embedding (s.mul_antidiagonal t a) h) _).2, },
apply ne_of_lt mn (g.injective ((h.nat_embedding _).injective _)),
exact eq_of_fst_le_fst_of_snd_le_snd _ _ _ (hg _ _ (le_of_lt mn)) h2',
end
end ordered_cancel_comm_monoid
@[to_additive]
theorem finite_of_is_wf [linear_ordered_cancel_comm_monoid α] {s t : set α}
(hs : s.is_wf) (ht : t.is_wf) (a) :
(mul_antidiagonal s t a).finite :=
finite_of_is_pwo hs.is_pwo ht.is_pwo a
end mul_antidiagonal
end set
namespace finset
variables [ordered_cancel_comm_monoid α]
variables {s t : set α} (hs : s.is_pwo) (ht : t.is_pwo) (a : α)
/-- `finset.mul_antidiagonal_of_is_wf hs ht a` is the set of all pairs of an element in
`s` and an element in `t` that multiply to `a`, but its construction requires proofs
`hs` and `ht` that `s` and `t` are well-ordered. -/
@[to_additive "`finset.add_antidiagonal_of_is_wf hs ht a` is the set of all pairs of an element in
`s` and an element in `t` that add to `a`, but its construction requires proofs
`hs` and `ht` that `s` and `t` are well-ordered."]
noncomputable def mul_antidiagonal : finset (α × α) :=
(set.mul_antidiagonal.finite_of_is_pwo hs ht a).to_finset
variables {hs} {ht} {u : set α} {hu : u.is_pwo} {a} {x : α × α}
@[simp, to_additive]
lemma mem_mul_antidiagonal :
x ∈ mul_antidiagonal hs ht a ↔ x.1 * x.2 = a ∧ x.1 ∈ s ∧ x.2 ∈ t :=
by simp [mul_antidiagonal]
@[to_additive]
lemma mul_antidiagonal_mono_left (hus : u ⊆ s) :
(finset.mul_antidiagonal hu ht a) ⊆ (finset.mul_antidiagonal hs ht a) :=
λ x hx, begin
rw mem_mul_antidiagonal at *,
exact ⟨hx.1, hus hx.2.1, hx.2.2⟩,
end
@[to_additive]
lemma mul_antidiagonal_mono_right (hut : u ⊆ t) :
(finset.mul_antidiagonal hs hu a) ⊆ (finset.mul_antidiagonal hs ht a) :=
λ x hx, begin
rw mem_mul_antidiagonal at *,
exact ⟨hx.1, hx.2.1, hut hx.2.2⟩,
end
@[to_additive]
lemma support_mul_antidiagonal_subset_mul :
{ a : α | (mul_antidiagonal hs ht a).nonempty } ⊆ s * t :=
(λ x ⟨⟨a1, a2⟩, ha⟩, begin
obtain ⟨hmul, h1, h2⟩ := mem_mul_antidiagonal.1 ha,
exact ⟨a1, a2, h1, h2, hmul⟩,
end)
@[to_additive]
theorem is_pwo_support_mul_antidiagonal :
{ a : α | (mul_antidiagonal hs ht a).nonempty }.is_pwo :=
(hs.mul ht).mono support_mul_antidiagonal_subset_mul
@[to_additive]
theorem mul_antidiagonal_min_mul_min {α} [linear_ordered_cancel_comm_monoid α] {s t : set α}
(hs : s.is_wf) (ht : t.is_wf)
(hns : s.nonempty) (hnt : t.nonempty) :
mul_antidiagonal hs.is_pwo ht.is_pwo ((hs.min hns) * (ht.min hnt)) =
{(hs.min hns, ht.min hnt)} :=
begin
ext ⟨a1, a2⟩,
rw [mem_mul_antidiagonal, finset.mem_singleton, prod.ext_iff],
split,
{ rintro ⟨hast, has, hat⟩,
cases eq_or_lt_of_le (hs.min_le hns has) with heq hlt,
{ refine ⟨heq.symm, _⟩,
rw heq at hast,
exact mul_left_cancel hast },
{ contrapose hast,
exact ne_of_gt (mul_lt_mul_of_lt_of_le hlt (ht.min_le hnt hat)) } },
{ rintro ⟨ha1, ha2⟩,
rw [ha1, ha2],
exact ⟨rfl, hs.min_mem _, ht.min_mem _⟩ }
end
end finset
lemma well_founded.is_wf [has_lt α] (h : well_founded ((<) : α → α → Prop)) (s : set α) :
s.is_wf :=
(set.is_wf_univ_iff.2 h).mono (set.subset_univ s)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.