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
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
224ad6c975d563cccc19a61f1909e60f5a769fd4
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/number_theory/cyclotomic/gal.lean
|
42b0de42698bf1c2c7668f7f16f59d2a447f83ad
|
[
"Apache-2.0"
] |
permissive
|
ramonfmir/mathlib
|
c5dc8b33155473fab97c38bd3aa6723dc289beaa
|
14c52e990c17f5a00c0cc9e09847af16fabbed25
|
refs/heads/master
| 1,661,979,343,526
| 1,660,830,384,000
| 1,660,830,384,000
| 182,072,989
| 0
| 0
| null | 1,555,585,876,000
| 1,555,585,876,000
| null |
UTF-8
|
Lean
| false
| false
| 7,269
|
lean
|
/-
Copyright (c) 2022 Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Rodriguez
-/
import number_theory.cyclotomic.primitive_roots
import field_theory.polynomial_galois_group
/-!
# Galois group of cyclotomic extensions
In this file, we show the relationship between the Galois group of `K(ζₙ)` and `(zmod n)ˣ`;
it is always a subgroup, and if the `n`th cyclotomic polynomial is irreducible, they are isomorphic.
## Main results
* `is_primitive_root.aut_to_pow_injective`: `is_primitive_root.aut_to_pow` is injective
in the case that it's considered over a cyclotomic field extension.
* `is_cyclotomic_extension.aut_equiv_pow`: If the `n`th cyclotomic polynomial is irreducible
in `K`, then `aut_to_pow` is a `mul_equiv` (for example, in `ℚ` and certain `𝔽ₚ`).
* `gal_X_pow_equiv_units_zmod`, `gal_cyclotomic_equiv_units_zmod`: Repackage `aut_equiv_pow` in
terms of `polynomial.gal`.
* `is_cyclotomic_extension.aut.comm_group`: Cyclotomic extensions are abelian.
## References
* https://kconrad.math.uconn.edu/blurbs/galoistheory/cyclotomic.pdf
## TODO
* We currently can get away with the fact that the power of a primitive root is a primitive root,
but the correct long-term solution for computing other explicit Galois groups is creating
`power_basis.map_conjugate`; but figuring out the exact correct assumptions + proof for this is
mathematically nontrivial. (Current thoughts: the correct condition is that the annihilating
ideal of both elements is equal. This may not hold in an ID, and definitely holds in an ICD.)
-/
local attribute [instance] pnat.fact_pos
variables {n : ℕ+} (K : Type*) [field K] {L : Type*} {μ : L}
open polynomial is_cyclotomic_extension
open_locale cyclotomic
namespace is_primitive_root
variables [comm_ring L] [is_domain L] (hμ : is_primitive_root μ n) [algebra K L]
[is_cyclotomic_extension {n} K L]
/-- `is_primitive_root.aut_to_pow` is injective in the case that it's considered over a cyclotomic
field extension. -/
lemma aut_to_pow_injective : function.injective $ hμ.aut_to_pow K :=
begin
intros f g hfg,
apply_fun units.val at hfg,
simp only [is_primitive_root.coe_aut_to_pow_apply, units.val_eq_coe] at hfg,
generalize_proofs hf' hg' at hfg,
have hf := hf'.some_spec,
have hg := hg'.some_spec,
generalize_proofs hζ at hf hg,
suffices : f hμ.to_roots_of_unity = g hμ.to_roots_of_unity,
{ apply alg_equiv.coe_alg_hom_injective,
apply (hμ.power_basis K).alg_hom_ext,
exact this },
rw zmod.eq_iff_modeq_nat at hfg,
refine (hf.trans _).trans hg.symm,
rw [←roots_of_unity.coe_pow _ hf'.some, ←roots_of_unity.coe_pow _ hg'.some],
congr' 1,
rw [pow_eq_pow_iff_modeq],
convert hfg,
rw [hμ.eq_order_of],
rw [←hμ.coe_to_roots_of_unity_coe] {occs := occurrences.pos [2]},
rw [order_of_units, order_of_subgroup]
end
end is_primitive_root
namespace is_cyclotomic_extension
variables [comm_ring L] [is_domain L] (hμ : is_primitive_root μ n) [algebra K L]
[is_cyclotomic_extension {n} K L]
/-- Cyclotomic extensions are abelian. -/
noncomputable def aut.comm_group : comm_group (L ≃ₐ[K] L) :=
((zeta_spec n K L).aut_to_pow_injective K).comm_group _
(map_one _) (map_mul _) (map_inv _) (map_div _) (map_pow _) (map_zpow _)
variables (h : irreducible (cyclotomic n K)) {K} (L)
include h
/-- The `mul_equiv` that takes an automorphism `f` to the element `k : (zmod n)ˣ` such that
`f μ = μ ^ k`. A stronger version of `is_primitive_root.aut_to_pow`. -/
@[simps] noncomputable def aut_equiv_pow : (L ≃ₐ[K] L) ≃* (zmod n)ˣ :=
let hζ := zeta_spec n K L,
hμ := λ t, hζ.pow_of_coprime _ (zmod.val_coe_unit_coprime t) in
{ inv_fun := λ t, (hζ.power_basis K).equiv_of_minpoly ((hμ t).power_basis K)
begin
haveI := is_cyclotomic_extension.ne_zero' n K L,
simp only [is_primitive_root.power_basis_gen],
have hr := is_primitive_root.minpoly_eq_cyclotomic_of_irreducible
((zeta_spec n K L).pow_of_coprime _ (zmod.val_coe_unit_coprime t)) h,
exact ((zeta_spec n K L).minpoly_eq_cyclotomic_of_irreducible h).symm.trans hr
end,
left_inv := λ f, begin
simp only [monoid_hom.to_fun_eq_coe],
apply alg_equiv.coe_alg_hom_injective,
apply (hζ.power_basis K).alg_hom_ext,
simp only [alg_equiv.coe_alg_hom, alg_equiv.map_pow],
rw power_basis.equiv_of_minpoly_gen,
simp only [is_primitive_root.power_basis_gen, is_primitive_root.aut_to_pow_spec],
end,
right_inv := λ x, begin
simp only [monoid_hom.to_fun_eq_coe],
generalize_proofs _ _ h,
have key := hζ.aut_to_pow_spec K ((hζ.power_basis K).equiv_of_minpoly
((hμ x).power_basis K) h),
have := (hζ.power_basis K).equiv_of_minpoly_gen ((hμ x).power_basis K) h,
rw hζ.power_basis_gen K at this,
rw [this, is_primitive_root.power_basis_gen] at key,
rw ← hζ.coe_to_roots_of_unity_coe at key {occs := occurrences.pos [1, 5]},
simp only [←coe_coe, ←roots_of_unity.coe_pow] at key,
replace key := roots_of_unity.coe_injective key,
rw [pow_eq_pow_iff_modeq, ←order_of_subgroup, ←order_of_units, hζ.coe_to_roots_of_unity_coe,
←(zeta_spec n K L).eq_order_of, ←zmod.eq_iff_modeq_nat] at key,
simp only [zmod.nat_cast_val, zmod.cast_id', id.def] at key,
exact units.ext key
end,
.. (zeta_spec n K L).aut_to_pow K }
include hμ
variables {L}
/-- Maps `μ` to the `alg_equiv` that sends `is_cyclotomic_extension.zeta` to `μ`. -/
noncomputable def from_zeta_aut : L ≃ₐ[K] L :=
let hζ := (zeta_spec n K L).eq_pow_of_pow_eq_one hμ.pow_eq_one n.pos in
(aut_equiv_pow L h).symm $ zmod.unit_of_coprime hζ.some $
((zeta_spec n K L).pow_iff_coprime n.pos hζ.some).mp $ hζ.some_spec.some_spec.symm ▸ hμ
lemma from_zeta_aut_spec : from_zeta_aut hμ h (zeta n K L) = μ :=
begin
simp_rw [from_zeta_aut, aut_equiv_pow_symm_apply],
generalize_proofs _ hζ h _ hμ _,
rw [←hζ.power_basis_gen K] {occs := occurrences.pos [4]},
rw [power_basis.equiv_of_minpoly_gen, hμ.power_basis_gen K],
convert h.some_spec.some_spec,
exact zmod.val_cast_of_lt h.some_spec.some
end
end is_cyclotomic_extension
section gal
variables [field L] (hμ : is_primitive_root μ n) [algebra K L]
[is_cyclotomic_extension {n} K L] (h : irreducible (cyclotomic n K)) {K}
/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`. Asserts that the
Galois group of `cyclotomic n K` is equivalent to `(zmod n)ˣ` if `cyclotomic n K` is irreducible in
the base field. -/
noncomputable def gal_cyclotomic_equiv_units_zmod :
(cyclotomic n K).gal ≃* (zmod n)ˣ :=
(alg_equiv.aut_congr (is_splitting_field.alg_equiv _ _)).symm.trans
(is_cyclotomic_extension.aut_equiv_pow L h)
/-- `is_cyclotomic_extension.aut_equiv_pow` repackaged in terms of `gal`. Asserts that the
Galois group of `X ^ n - 1` is equivalent to `(zmod n)ˣ` if `cyclotomic n K` is irreducible in the
base field. -/
noncomputable def gal_X_pow_equiv_units_zmod :
(X ^ (n : ℕ) - 1).gal ≃* (zmod n)ˣ :=
(alg_equiv.aut_congr (is_splitting_field.alg_equiv _ _)).symm.trans
(is_cyclotomic_extension.aut_equiv_pow L h)
end gal
|
9e5b98368d5727284f09e661d11ff875bcf4a3be
|
36c7a18fd72e5b57229bd8ba36493daf536a19ce
|
/hott/types/bool.hlean
|
1532cf2d9ec6da50d040b1f6d7aa3872e151bf84
|
[
"Apache-2.0"
] |
permissive
|
YHVHvx/lean
|
732bf0fb7a298cd7fe0f15d82f8e248c11db49e9
|
038369533e0136dd395dc252084d3c1853accbf2
|
refs/heads/master
| 1,610,701,080,210
| 1,449,128,595,000
| 1,449,128,595,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,592
|
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
Theorems about the booleans
-/
open is_equiv eq equiv function is_trunc option unit decidable
namespace bool
definition ff_ne_tt : ff = tt → empty
| [none]
definition is_equiv_bnot [constructor] [instance] [priority 500] : is_equiv bnot :=
begin
fapply is_equiv.mk,
exact bnot,
all_goals (intro b;cases b), do 6 reflexivity
-- all_goals (focus (intro b;cases b;all_goals reflexivity)),
end
definition bnot_ne : Π(b : bool), bnot b ≠ b
| bnot_ne tt := ff_ne_tt
| bnot_ne ff := ne.symm ff_ne_tt
definition equiv_bnot [constructor] : bool ≃ bool := equiv.mk bnot _
definition eq_bnot : bool = bool := ua equiv_bnot
definition eq_bnot_ne_idp : eq_bnot ≠ idp :=
assume H : eq_bnot = idp,
assert H2 : bnot = id, from !cast_ua_fn⁻¹ ⬝ ap cast H,
absurd (ap10 H2 tt) ff_ne_tt
definition bool_equiv_option_unit : bool ≃ option unit :=
begin
fapply equiv.MK,
{ intro b, cases b, exact none, exact some star},
{ intro u, cases u, exact ff, exact tt},
{ intro u, cases u with u, reflexivity, cases u, reflexivity},
{ intro b, cases b, reflexivity, reflexivity},
end
protected definition has_decidable_eq [instance] : ∀ x y : bool, decidable (x = y)
| has_decidable_eq ff ff := inl rfl
| has_decidable_eq ff tt := inr (by contradiction)
| has_decidable_eq tt ff := inr (by contradiction)
| has_decidable_eq tt tt := inl rfl
end bool
|
58cad90c17dbe82818d0c08631656aeb80dd3a6c
|
d642a6b1261b2cbe691e53561ac777b924751b63
|
/src/algebra/module.lean
|
c26e055f480e7f09c55ad3ce1ad3101246eee74c
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/mathlib
|
fee56b9954e969721715e45fea8bcb95f9dc03fe
|
d077887141000fefa5a264e30fa57520e9f03522
|
refs/heads/master
| 1,651,806,490,504
| 1,573,508,694,000
| 1,573,508,694,000
| 107,216,176
| 0
| 0
|
Apache-2.0
| 1,647,363,136,000
| 1,508,213,014,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 16,048
|
lean
|
/-
Copyright (c) 2015 Nathaniel Thomas. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
Modules over a ring.
## Implemetation notes
Throughout the `linear_map` section implicit `{}` brackets are often used instead of type class `[]` brackets.
This is done when the instances can be inferred because they are implicit arguments to the type `linear_map`.
When they can be inferred from the type it is faster to use this method than to use type class inference
-/
import algebra.ring algebra.big_operators group_theory.subgroup group_theory.group_action
open function
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
-- /-- Typeclass for types with a scalar multiplication operation, denoted `•` (`\bu`) -/
-- class has_scalar (α : Type u) (γ : Type v) := (smul : α → γ → γ)
-- infixr ` • `:73 := has_scalar.smul
/-- A semimodule is a generalization of vector spaces to a scalar semiring.
It consists of a scalar semiring `α` and an additive monoid of "vectors" `β`,
connected by a "scalar multiplication" operation `r • x : β`
(where `r : α` and `x : β`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
class semimodule (α : Type u) (β : Type v) [semiring α]
[add_comm_monoid β] extends distrib_mul_action α β :=
(add_smul : ∀(r s : α) (x : β), (r + s) • x = r • x + s • x)
(zero_smul : ∀x : β, (0 : α) • x = 0)
section semimodule
variables [R:semiring α] [add_comm_monoid β] [semimodule α β] (r s : α) (x y : β)
include R
theorem add_smul : (r + s) • x = r • x + s • x := semimodule.add_smul r s x
variables (α)
@[simp] theorem zero_smul : (0 : α) • x = 0 := semimodule.zero_smul α x
lemma smul_smul : r • s • x = (r * s) • x := (mul_smul _ _ _).symm
instance smul.is_add_monoid_hom {r : α} : is_add_monoid_hom (λ x : β, r • x) :=
{ map_add := smul_add _, map_zero := smul_zero _ }
lemma semimodule.eq_zero_of_zero_eq_one (zero_eq_one : (0 : α) = 1) : x = 0 :=
by rw [←one_smul α x, ←zero_eq_one, zero_smul]
end semimodule
/-- A module is a generalization of vector spaces to a scalar ring.
It consists of a scalar ring `α` and an additive group of "vectors" `β`,
connected by a "scalar multiplication" operation `r • x : β`
(where `r : α` and `x : β`) with some natural associativity and
distributivity axioms similar to those on a ring. -/
class module (α : Type u) (β : Type v) [ring α] [add_comm_group β] extends semimodule α β
structure module.core (α β) [ring α] [add_comm_group β] extends has_scalar α β :=
(smul_add : ∀(r : α) (x y : β), r • (x + y) = r • x + r • y)
(add_smul : ∀(r s : α) (x : β), (r + s) • x = r • x + s • x)
(mul_smul : ∀(r s : α) (x : β), (r * s) • x = r • s • x)
(one_smul : ∀x : β, (1 : α) • x = x)
def module.of_core {α β} [ring α] [add_comm_group β] (M : module.core α β) : module α β :=
by letI := M.to_has_scalar; exact
{ zero_smul := λ x,
have (0 : α) • x + (0 : α) • x = (0 : α) • x + 0, by rw ← M.add_smul; simp,
add_left_cancel this,
smul_zero := λ r,
have r • (0:β) + r • 0 = r • 0 + 0, by rw ← M.smul_add; simp,
add_left_cancel this,
..M }
section module
variables [ring α] [add_comm_group β] [module α β] (r s : α) (x y : β)
@[simp] theorem neg_smul : -r • x = - (r • x) :=
eq_neg_of_add_eq_zero (by rw [← add_smul, add_left_neg, zero_smul])
variables (α)
theorem neg_one_smul (x : β) : (-1 : α) • x = -x := by simp
variables {α}
@[simp] theorem smul_neg : r • (-x) = -(r • x) :=
by rw [← neg_one_smul α, ← mul_smul, mul_neg_one, neg_smul]
theorem smul_sub (r : α) (x y : β) : r • (x - y) = r • x - r • y :=
by simp [smul_add]; rw smul_neg
theorem sub_smul (r s : α) (y : β) : (r - s) • y = r • y - s • y :=
by simp [add_smul]
end module
instance semiring.to_semimodule [r : semiring α] : semimodule α α :=
{ smul := (*),
smul_add := mul_add,
add_smul := add_mul,
mul_smul := mul_assoc,
one_smul := one_mul,
zero_smul := zero_mul,
smul_zero := mul_zero, ..r }
@[simp] lemma smul_eq_mul [semiring α] {a a' : α} : a • a' = a * a' := rfl
instance ring.to_module [r : ring α] : module α α :=
{ ..semiring.to_semimodule }
def is_ring_hom.to_module [ring α] [ring β] (f : α → β) [h : is_ring_hom f] : module α β :=
module.of_core
{ smul := λ r x, f r * x,
smul_add := λ r x y, by unfold has_scalar.smul; rw [mul_add],
add_smul := λ r s x, by unfold has_scalar.smul; rw [h.map_add, add_mul],
mul_smul := λ r s x, by unfold has_scalar.smul; rw [h.map_mul, mul_assoc],
one_smul := λ x, show f 1 * x = _, by rw [h.map_one, one_mul] }
class is_linear_map (α : Type u) {β : Type v} {γ : Type w}
[ring α] [add_comm_group β] [add_comm_group γ] [module α β] [module α γ]
(f : β → γ) : Prop :=
(add : ∀x y, f (x + y) = f x + f y)
(smul : ∀(c : α) x, f (c • x) = c • f x)
structure linear_map (α : Type u) (β : Type v) (γ : Type w)
[ring α] [add_comm_group β] [add_comm_group γ] [module α β] [module α γ] :=
(to_fun : β → γ)
(add : ∀x y, to_fun (x + y) = to_fun x + to_fun y)
(smul : ∀(c : α) x, to_fun (c • x) = c • to_fun x)
infixr ` →ₗ `:25 := linear_map _
notation β ` →ₗ[`:25 α:25 `] `:0 γ:0 := linear_map α β γ
namespace linear_map
variables {rα : ring α} {gβ : add_comm_group β} {gγ : add_comm_group γ} {gδ : add_comm_group δ}
variables {mβ : module α β} {mγ : module α γ} {mδ : module α δ}
variables (f g : β →ₗ[α] γ)
include α mβ mγ
instance : has_coe_to_fun (β →ₗ[α] γ) := ⟨_, to_fun⟩
@[simp] lemma coe_mk (f : β → γ) (h₁ h₂) :
((linear_map.mk f h₁ h₂ : β →ₗ[α] γ) : β → γ) = f := rfl
theorem is_linear : is_linear_map α f := {..f}
@[ext] theorem ext {f g : β →ₗ[α] γ} (H : ∀ x, f x = g x) : f = g :=
by cases f; cases g; congr'; exact funext H
theorem ext_iff {f g : β →ₗ[α] γ} : f = g ↔ ∀ x, f x = g x :=
⟨by rintro rfl; simp, ext⟩
@[simp] lemma map_add (x y : β) : f (x + y) = f x + f y := f.add x y
@[simp] lemma map_smul (c : α) (x : β) : f (c • x) = c • f x := f.smul c x
@[simp] lemma map_zero : f 0 = 0 :=
by rw [← zero_smul α, map_smul f 0 0, zero_smul]
instance : is_add_group_hom f := { map_add := map_add f }
@[simp] lemma map_neg (x : β) : f (- x) = - f x :=
by rw [← neg_one_smul α, map_smul, neg_one_smul]
@[simp] lemma map_sub (x y : β) : f (x - y) = f x - f y :=
by simp [map_neg, map_add]
@[simp] lemma map_sum {ι} {t : finset ι} {g : ι → β} :
f (t.sum g) = t.sum (λi, f (g i)) :=
(finset.sum_hom f).symm
include mδ
def comp (f : γ →ₗ[α] δ) (g : β →ₗ[α] γ) : β →ₗ[α] δ := ⟨f ∘ g, by simp, by simp⟩
@[simp] lemma comp_apply (f : γ →ₗ[α] δ) (g : β →ₗ[α] γ) (x : β) : f.comp g x = f (g x) := rfl
omit mγ mδ
variables [rα] [gβ] [mβ]
def id : β →ₗ[α] β := ⟨id, by simp, by simp⟩
@[simp] lemma id_apply (x : β) : @id α β _ _ _ x = x := rfl
end linear_map
namespace is_linear_map
variables [ring α] [add_comm_group β] [add_comm_group γ]
variables [module α β] [module α γ]
include α
def mk' (f : β → γ) (H : is_linear_map α f) : β →ₗ γ := {to_fun := f, ..H}
@[simp] theorem mk'_apply {f : β → γ} (H : is_linear_map α f) (x : β) :
mk' f H x = f x := rfl
lemma is_linear_map_neg :
is_linear_map α (λ (z : β), -z) :=
is_linear_map.mk neg_add (λ x y, (smul_neg x y).symm)
lemma is_linear_map_smul {α R : Type*} [add_comm_group α] [comm_ring R] [module R α] (c : R) :
is_linear_map R (λ (z : α), c • z) :=
begin
refine is_linear_map.mk (smul_add c) _,
intros _ _,
simp [smul_smul],
ac_refl
end
--TODO: move
lemma is_linear_map_smul' {α R : Type*} [add_comm_group α] [comm_ring R] [module R α] (a : α) :
is_linear_map R (λ (c : R), c • a) :=
begin
refine is_linear_map.mk (λ x y, add_smul x y a) _,
intros _ _,
simp [smul_smul]
end
variables {f : β → γ} (lin : is_linear_map α f)
include β γ lin
@[simp] lemma map_zero : f (0 : β) = (0 : γ) :=
by rw [← zero_smul α (0 : β), lin.smul, zero_smul]
@[simp] lemma map_add (x y : β) : f (x + y) = f x + f y :=
by rw [lin.add]
@[simp] lemma map_neg (x : β) : f (- x) = - f x :=
by rw [← neg_one_smul α, lin.smul, neg_one_smul]
@[simp] lemma map_sub (x y : β) : f (x - y) = f x - f y :=
by simp [lin.map_neg, lin.map_add]
end is_linear_map
/-- A submodule of a module is one which is closed under vector operations.
This is a sufficient condition for the subset of vectors in the submodule
to themselves form a module. -/
structure submodule (α : Type u) (β : Type v) [ring α]
[add_comm_group β] [module α β] : Type v :=
(carrier : set β)
(zero : (0:β) ∈ carrier)
(add : ∀ {x y}, x ∈ carrier → y ∈ carrier → x + y ∈ carrier)
(smul : ∀ (c:α) {x}, x ∈ carrier → c • x ∈ carrier)
namespace submodule
variables [ring α] [add_comm_group β] [add_comm_group γ]
variables [module α β] [module α γ]
variables (p p' : submodule α β)
variables {r : α} {x y : β}
instance : has_coe (submodule α β) (set β) := ⟨submodule.carrier⟩
instance : has_mem β (submodule α β) := ⟨λ x p, x ∈ (p : set β)⟩
@[simp] theorem mem_coe : x ∈ (p : set β) ↔ x ∈ p := iff.rfl
theorem ext' {s t : submodule α β} (h : (s : set β) = t) : s = t :=
by cases s; cases t; congr'
protected theorem ext'_iff {s t : submodule α β} : (s : set β) = t ↔ s = t :=
⟨ext', λ h, h ▸ rfl⟩
@[ext] theorem ext {s t : submodule α β}
(h : ∀ x, x ∈ s ↔ x ∈ t) : s = t := ext' $ set.ext h
@[simp] lemma zero_mem : (0 : β) ∈ p := p.zero
lemma add_mem (h₁ : x ∈ p) (h₂ : y ∈ p) : x + y ∈ p := p.add h₁ h₂
lemma smul_mem (r : α) (h : x ∈ p) : r • x ∈ p := p.smul r h
lemma neg_mem (hx : x ∈ p) : -x ∈ p := by rw ← neg_one_smul α; exact p.smul_mem _ hx
lemma sub_mem (hx : x ∈ p) (hy : y ∈ p) : x - y ∈ p := p.add_mem hx (p.neg_mem hy)
lemma neg_mem_iff : -x ∈ p ↔ x ∈ p :=
⟨λ h, by simpa using neg_mem p h, neg_mem p⟩
lemma add_mem_iff_left (h₁ : y ∈ p) : x + y ∈ p ↔ x ∈ p :=
⟨λ h₂, by simpa using sub_mem _ h₂ h₁, λ h₂, add_mem _ h₂ h₁⟩
lemma add_mem_iff_right (h₁ : x ∈ p) : x + y ∈ p ↔ y ∈ p :=
⟨λ h₂, by simpa using sub_mem _ h₂ h₁, add_mem _ h₁⟩
lemma sum_mem {ι : Type w} [decidable_eq ι] {t : finset ι} {f : ι → β} :
(∀c∈t, f c ∈ p) → t.sum f ∈ p :=
finset.induction_on t (by simp [p.zero_mem]) (by simp [p.add_mem] {contextual := tt})
instance : has_add p := ⟨λx y, ⟨x.1 + y.1, add_mem _ x.2 y.2⟩⟩
instance : has_zero p := ⟨⟨0, zero_mem _⟩⟩
instance : has_neg p := ⟨λx, ⟨-x.1, neg_mem _ x.2⟩⟩
instance : has_scalar α p := ⟨λ c x, ⟨c • x.1, smul_mem _ c x.2⟩⟩
@[simp] lemma coe_add (x y : p) : (↑(x + y) : β) = ↑x + ↑y := rfl
@[simp] lemma coe_zero : ((0 : p) : β) = 0 := rfl
@[simp] lemma coe_neg (x : p) : ((-x : p) : β) = -x := rfl
@[simp] lemma coe_smul (r : α) (x : p) : ((r • x : p) : β) = r • ↑x := rfl
instance : add_comm_group p :=
by refine {add := (+), zero := 0, neg := has_neg.neg, ..};
{ intros, apply set_coe.ext, simp }
instance submodule_is_add_subgroup : is_add_subgroup (p : set β) :=
{ zero_mem := p.zero,
add_mem := p.add,
neg_mem := λ _, p.neg_mem }
lemma coe_sub (x y : p) : (↑(x - y) : β) = ↑x - ↑y := by simp
instance : module α p :=
by refine {smul := (•), ..};
{ intros, apply set_coe.ext, simp [smul_add, add_smul, mul_smul] }
protected def subtype : p →ₗ[α] β :=
by refine {to_fun := coe, ..}; simp [coe_smul]
@[simp] theorem subtype_apply (x : p) : p.subtype x = x := rfl
lemma subtype_eq_val (p : submodule α β) :
((submodule.subtype p) : p → β) = subtype.val := rfl
end submodule
@[reducible] def ideal (α : Type u) [comm_ring α] := submodule α α
namespace ideal
variables [comm_ring α] (I : ideal α) {a b : α}
protected lemma zero_mem : (0 : α) ∈ I := I.zero_mem
protected lemma add_mem : a ∈ I → b ∈ I → a + b ∈ I := I.add_mem
lemma neg_mem_iff : -a ∈ I ↔ a ∈ I := I.neg_mem_iff
lemma add_mem_iff_left : b ∈ I → (a + b ∈ I ↔ a ∈ I) := I.add_mem_iff_left
lemma add_mem_iff_right : a ∈ I → (a + b ∈ I ↔ b ∈ I) := I.add_mem_iff_right
protected lemma sub_mem : a ∈ I → b ∈ I → a - b ∈ I := I.sub_mem
lemma mul_mem_left : b ∈ I → a * b ∈ I := I.smul_mem _
lemma mul_mem_right (h : a ∈ I) : a * b ∈ I := mul_comm b a ▸ I.mul_mem_left h
end ideal
/-- A vector space is the same as a module, except the scalar ring is actually
a field. (This adds commutativity of the multiplication and existence of inverses.)
This is the traditional generalization of spaces like `ℝ^n`, which have a natural
addition operation and a way to multiply them by real numbers, but no multiplication
operation between vectors. -/
class vector_space (α : Type u) (β : Type v) [discrete_field α] [add_comm_group β] extends module α β
instance discrete_field.to_vector_space {α : Type*} [discrete_field α] : vector_space α α :=
{ .. ring.to_module }
/-- Subspace of a vector space. Defined to equal `submodule`. -/
@[reducible] def subspace (α : Type u) (β : Type v)
[discrete_field α] [add_comm_group β] [vector_space α β] : Type v :=
submodule α β
instance subspace.vector_space {α β}
{f : discrete_field α} [add_comm_group β] [vector_space α β]
(p : subspace α β) : vector_space α p := {..submodule.module p}
namespace submodule
variables {R:discrete_field α} [add_comm_group β] [add_comm_group γ]
variables [vector_space α β] [vector_space α γ]
variables (p p' : submodule α β)
variables {r : α} {x y : β}
include R
set_option class.instance_max_depth 36
theorem smul_mem_iff (r0 : r ≠ 0) : r • x ∈ p ↔ x ∈ p :=
⟨λ h, by simpa [smul_smul, inv_mul_cancel r0] using p.smul_mem (r⁻¹) h,
p.smul_mem r⟩
end submodule
namespace add_comm_monoid
open add_monoid
variables {M : Type*} [add_comm_monoid M]
instance : semimodule ℕ M :=
{ smul := smul,
smul_add := λ _ _ _, smul_add _ _ _,
add_smul := λ _ _ _, add_smul _ _ _,
mul_smul := λ _ _ _, mul_smul _ _ _,
one_smul := one_smul,
zero_smul := zero_smul,
smul_zero := smul_zero }
end add_comm_monoid
namespace add_comm_group
variables {M : Type*} [add_comm_group M]
instance : module ℤ M :=
{ smul := gsmul,
smul_add := λ _ _ _, gsmul_add _ _ _,
add_smul := λ _ _ _, add_gsmul _ _ _,
mul_smul := λ _ _ _, gsmul_mul _ _ _,
one_smul := one_gsmul,
zero_smul := zero_gsmul,
smul_zero := gsmul_zero }
end add_comm_group
def is_add_group_hom.to_linear_map [add_comm_group α] [add_comm_group β]
(f : α → β) [is_add_group_hom f] : α →ₗ[ℤ] β :=
{ to_fun := f,
add := is_add_hom.map_add f,
smul := λ i x, int.induction_on i (by rw [zero_smul, zero_smul, is_add_group_hom.map_zero f])
(λ i ih, by rw [add_smul, add_smul, is_add_hom.map_add f, ih, one_smul, one_smul])
(λ i ih, by rw [sub_smul, sub_smul, is_add_group_hom.map_sub f, ih, one_smul, one_smul]) }
lemma module.smul_eq_smul {R : Type*} [ring R] {β : Type*} [add_comm_group β] [module R β]
(n : ℕ) (b : β) : n • b = (n : R) • b :=
begin
induction n with n ih,
{ rw [nat.cast_zero, zero_smul, zero_smul] },
{ change (n + 1) • b = (n + 1 : R) • b,
rw [add_smul, add_smul, one_smul, ih, one_smul] }
end
lemma finset.sum_const' {α : Type*} (R : Type*) [ring R] {β : Type*}
[add_comm_group β] [module R β] {s : finset α} (b : β) :
finset.sum s (λ (a : α), b) = (finset.card s : R) • b :=
by rw [finset.sum_const, ← module.smul_eq_smul]; refl
|
d3914c98ff3effce774a6d172594bf36058ef6d6
|
d642a6b1261b2cbe691e53561ac777b924751b63
|
/src/analysis/asymptotics.lean
|
0ddb78585090695311b5a7323fdc4f56d1ca90a2
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/mathlib
|
fee56b9954e969721715e45fea8bcb95f9dc03fe
|
d077887141000fefa5a264e30fa57520e9f03522
|
refs/heads/master
| 1,651,806,490,504
| 1,573,508,694,000
| 1,573,508,694,000
| 107,216,176
| 0
| 0
|
Apache-2.0
| 1,647,363,136,000
| 1,508,213,014,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 29,358
|
lean
|
/-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
We introduce these relations:
`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.
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)) (nhds 0) l`.
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.)
-/
import analysis.normed_space.basic
open filter
namespace asymptotics
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section
variables [has_norm β] [has_norm γ] [has_norm δ]
def is_O (f : α → β) (g : α → γ) (l : filter α) : Prop :=
∃ c > 0, { x | ∥ f x ∥ ≤ c * ∥ g x ∥ } ∈ l
def is_o (f : α → β) (g : α → γ) (l : filter α) : Prop :=
∀ c > 0, { x | ∥ f x ∥ ≤ c * ∥ g x ∥ } ∈ l
theorem is_O_refl (f : α → β) (l : filter α) : is_O f f l :=
⟨1, zero_lt_one, by { filter_upwards [univ_mem_sets], intros x _, simp }⟩
theorem is_O.comp {f : α → β} {g : α → γ} {l : filter α} (hfg : is_O f g l)
{δ : Type*} (k : δ → α) :
is_O (f ∘ k) (g ∘ k) (l.comap k) :=
let ⟨c, cpos, hfgc⟩ := hfg in
⟨c, cpos, mem_comap_sets.mpr ⟨_, hfgc, set.subset.refl _⟩⟩
theorem is_o.comp {f : α → β} {g : α → γ} {l : filter α} (hfg : is_o f g l)
{δ : Type*} (k : δ → α) :
is_o (f ∘ k) (g ∘ k) (l.comap k) :=
λ c cpos, mem_comap_sets.mpr ⟨_, hfg c cpos, set.subset.refl _⟩
theorem is_O.mono {f : α → β} {g : α → γ} {l₁ l₂ : filter α} (h : l₁ ≤ l₂)
(h' : is_O f g l₂) : is_O f g l₁ :=
let ⟨c, cpos, h'c⟩ := h' in ⟨c, cpos, h (h'c)⟩
theorem is_o.mono {f : α → β} {g : α → γ} {l₁ l₂ : filter α} (h : l₁ ≤ l₂)
(h' : is_o f g l₂) : is_o f g l₁ :=
λ c cpos, h (h' c cpos)
theorem is_o.to_is_O {f : α → β} {g : α → γ} {l : filter α} (hgf : is_o f g l) : is_O f g l :=
⟨1, zero_lt_one, hgf 1 zero_lt_one⟩
theorem is_O.trans {f : α → β} {g : α → γ} {k : α → δ} {l : filter α}
(h₁ : is_O f g l) (h₂ : is_O g k l) :
is_O f k l :=
let ⟨c, cpos, hc⟩ := h₁,
⟨c', c'pos, hc'⟩ := h₂ in
begin
use [c * c', mul_pos cpos c'pos],
filter_upwards [hc, hc'], dsimp,
intros x h₁x h₂x, rw mul_assoc,
exact le_trans h₁x (mul_le_mul_of_nonneg_left h₂x (le_of_lt cpos))
end
theorem is_o.trans_is_O {f : α → β} {g : α → γ} {k : α → δ} {l : filter α}
(h₁ : is_o f g l) (h₂ : is_O g k l) :
is_o f k l :=
begin
intros c cpos,
rcases h₂ with ⟨c', c'pos, hc'⟩,
have cc'pos := div_pos cpos c'pos,
filter_upwards [h₁ (c / c') cc'pos, hc'], dsimp,
intros x h₁x h₂x,
refine le_trans h₁x (le_trans (mul_le_mul_of_nonneg_left h₂x (le_of_lt cc'pos)) _),
rw [←mul_assoc, div_mul_cancel _ (ne_of_gt c'pos)]
end
theorem is_O.trans_is_o {f : α → β} {g : α → γ} {k : α → δ} {l : filter α}
(h₁ : is_O f g l) (h₂ : is_o g k l) :
is_o f k l :=
begin
intros c cpos,
rcases h₁ with ⟨c', c'pos, hc'⟩,
have cc'pos := div_pos cpos c'pos,
filter_upwards [hc', h₂ (c / c') cc'pos], dsimp,
intros x h₁x h₂x,
refine le_trans h₁x (le_trans (mul_le_mul_of_nonneg_left h₂x (le_of_lt c'pos)) _),
rw [←mul_assoc, mul_div_cancel' _ (ne_of_gt c'pos)]
end
theorem is_o.trans {f : α → β} {g : α → γ} {k : α → δ} {l : filter α}
(h₁ : is_o f g l) (h₂ : is_o g k l) :
is_o f k l :=
h₁.to_is_O.trans_is_o h₂
theorem is_o_join {f : α → β} {g : α → γ} {l₁ l₂ : filter α}
(h₁ : is_o f g l₁) (h₂ : is_o f g l₂) :
is_o f g (l₁ ⊔ l₂) :=
begin
intros c cpos,
rw mem_sup_sets,
exact ⟨h₁ c cpos, h₂ c cpos⟩
end
theorem is_O_congr {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(hf : {x | f₁ x = f₂ x} ∈ l) (hg : {x | g₁ x = g₂ x} ∈ l) :
is_O f₁ g₁ l ↔ is_O f₂ g₂ l :=
bex_congr $ λ c _, filter.congr_sets $
by filter_upwards [hf, hg] λ x e₁ e₂,
by dsimp at e₁ e₂ ⊢; rw [e₁, e₂]
theorem is_o_congr {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(hf : {x | f₁ x = f₂ x} ∈ l) (hg : {x | g₁ x = g₂ x} ∈ l) :
is_o f₁ g₁ l ↔ is_o f₂ g₂ l :=
ball_congr $ λ c _, filter.congr_sets $
by filter_upwards [hf, hg] λ x e₁ e₂,
by dsimp at e₁ e₂ ⊢; rw [e₁, e₂]
theorem is_O.congr {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
(is_O_congr (univ_mem_sets' hf) (univ_mem_sets' hg)).1
theorem is_o.congr {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
(is_o_congr (univ_mem_sets' hf) (univ_mem_sets' hg)).1
theorem is_O_congr_left {f₁ f₂ : α → β} {g : α → γ} {l : filter α}
(h : {x | f₁ x = f₂ x} ∈ l) :
is_O f₁ g l ↔ is_O f₂ g l :=
is_O_congr h (univ_mem_sets' $ λ _, rfl)
theorem is_o_congr_left {f₁ f₂ : α → β} {g : α → γ} {l : filter α}
(h : {x | f₁ x = f₂ x} ∈ l) :
is_o f₁ g l ↔ is_o f₂ g l :=
is_o_congr h (univ_mem_sets' $ λ _, rfl)
theorem is_O.congr_left {f₁ f₂ : α → β} {g : α → γ} {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_left {f₁ f₂ : α → β} {g : α → γ} {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 {f : α → β} {g₁ g₂ : α → γ} {l : filter α}
(h : {x | g₁ x = g₂ x} ∈ l) :
is_O f g₁ l ↔ is_O f g₂ l :=
is_O_congr (univ_mem_sets' $ λ _, rfl) h
theorem is_o_congr_right {f : α → β} {g₁ g₂ : α → γ} {l : filter α}
(h : {x | g₁ x = g₂ x} ∈ l) :
is_o f g₁ l ↔ is_o f g₂ l :=
is_o_congr (univ_mem_sets' $ λ _, rfl) h
theorem is_O.congr_right {f : α → β} {g₁ g₂ : α → γ} {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_right {f : α → β} {g₁ g₂ : α → γ} {l : filter α}
(hg : ∀ x, g₁ x = g₂ x) : is_o f g₁ l → is_o f g₂ l :=
is_o.congr (λ _, rfl) hg
end
section
variables [has_norm β] [normed_group γ] [normed_group δ]
@[simp]
theorem is_O_norm_right {f : α → β} {g : α → γ} {l : filter α} :
is_O f (λ x, ∥g x∥) l ↔ is_O f g l :=
by simp only [is_O, norm_norm]
@[simp]
theorem is_o_norm_right {f : α → β} {g : α → γ} {l : filter α} :
is_o f (λ x, ∥g x∥) l ↔ is_o f g l :=
by simp only [is_o, norm_norm]
@[simp]
theorem is_O_neg_right {f : α → β} {g : α → γ} {l : filter α} :
is_O f (λ x, -(g x)) l ↔ is_O f g l :=
by { rw ←is_O_norm_right, simp only [norm_neg], rw is_O_norm_right }
@[simp]
theorem is_o_neg_right {f : α → β} {g : α → γ} {l : filter α} :
is_o f (λ x, -(g x)) l ↔ is_o f g l :=
by { rw ←is_o_norm_right, simp only [norm_neg], rw is_o_norm_right }
theorem is_O_iff {f : α → β} {g : α → γ} {l : filter α} :
is_O f g l ↔ ∃ c, { x | ∥f x∥ ≤ c * ∥g x∥ } ∈ l :=
suffices (∃ c, { x | ∥f x∥ ≤ c * ∥g x∥ } ∈ l) → is_O f g l,
from ⟨λ ⟨c, cpos, hc⟩, ⟨c, hc⟩, this⟩,
assume ⟨c, hc⟩,
or.elim (lt_or_ge 0 c)
(assume : c > 0, ⟨c, this, hc⟩)
(assume h'c : c ≤ 0,
have {x : α | ∥f x∥ ≤ 1 * ∥g x∥} ∈ l,
begin
filter_upwards [hc], intros x,
show ∥f x∥ ≤ c * ∥g x∥ → ∥f x∥ ≤ 1 * ∥g x∥,
{ intro hx, apply le_trans hx,
apply mul_le_mul_of_nonneg_right _ (norm_nonneg _),
show c ≤ 1, from le_trans h'c zero_le_one }
end,
⟨1, zero_lt_one, this⟩)
theorem is_O_join {f : α → β} {g : α → γ} {l₁ l₂ : filter α}
(h₁ : is_O f g l₁) (h₂ : is_O f g l₂) :
is_O f g (l₁ ⊔ l₂) :=
begin
rcases h₁ with ⟨c₁, c₁pos, hc₁⟩,
rcases h₂ with ⟨c₂, c₂pos, hc₂⟩,
have : 0 < max c₁ c₂, by { rw lt_max_iff, left, exact c₁pos },
use [max c₁ c₂, this],
rw mem_sup_sets, split,
{ filter_upwards [hc₁], dsimp, intros x hx,
exact le_trans hx (mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _)) },
filter_upwards [hc₂], dsimp, intros x hx,
exact le_trans hx (mul_le_mul_of_nonneg_right (le_max_right _ _) (norm_nonneg _))
end
lemma is_O.prod_rightl {f : α → β} {g₁ : α → γ} {g₂ : α → δ} {l : filter α}
(h : is_O f g₁ l) : is_O f (λx, (g₁ x, g₂ x)) l :=
begin
have : is_O g₁ (λx, (g₁ x, g₂ x)) l :=
⟨1, zero_lt_one, filter.univ_mem_sets' (λx, by simp [norm, le_refl])⟩,
exact is_O.trans h this
end
lemma is_O.prod_rightr {f : α → β} {g₁ : α → γ} {g₂ : α → δ} {l : filter α}
(h : is_O f g₂ l) : is_O f (λx, (g₁ x, g₂ x)) l :=
begin
have : is_O g₂ (λx, (g₁ x, g₂ x)) l :=
⟨1, zero_lt_one, filter.univ_mem_sets' (λx, by simp [norm, le_refl])⟩,
exact is_O.trans h this
end
lemma is_o.prod_rightl {f : α → β} {g₁ : α → γ} {g₂ : α → δ} {l : filter α}
(h : is_o f g₁ l) : is_o f (λx, (g₁ x, g₂ x)) l :=
is_o.trans_is_O h (is_O.prod_rightl (is_O_refl g₁ l))
lemma is_o.prod_rightr {f : α → β} {g₁ : α → γ} {g₂ : α → δ} {l : filter α}
(h : is_o f g₂ l) : is_o f (λx, (g₁ x, g₂ x)) l :=
is_o.trans_is_O h (is_O.prod_rightr (is_O_refl g₂ l))
end
section
variables [normed_group β] [normed_group δ] [has_norm γ]
@[simp] theorem is_O_norm_left {f : α → β} {g : α → γ} {l : filter α} :
is_O (λ x, ∥f x∥) g l ↔ is_O f g l :=
by simp only [is_O, norm_norm]
@[simp] theorem is_o_norm_left {f : α → β} {g : α → γ} {l : filter α} :
is_o (λ x, ∥f x∥) g l ↔ is_o f g l :=
by simp only [is_o, norm_norm]
@[simp] theorem is_O_neg_left {f : α → β} {g : α → γ} {l : filter α} :
is_O (λ x, -f x) g l ↔ is_O f g l :=
by { rw ←is_O_norm_left, simp only [norm_neg], rw is_O_norm_left }
@[simp] theorem is_o_neg_left {f : α → β} {g : α → γ} {l : filter α} :
is_o (λ x, -f x) g l ↔ is_o f g l :=
by { rw ←is_o_norm_left, simp only [norm_neg], rw is_o_norm_left }
theorem is_O.add {f₁ f₂ : α → β} {g : α → γ} {l : filter α} (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) :
is_O (λ x, f₁ x + f₂ x) g l :=
let ⟨c₁, c₁pos, hc₁⟩ := h₁,
⟨c₂, c₂pos, hc₂⟩ := h₂ in
begin
use [c₁ + c₂, add_pos c₁pos c₂pos],
filter_upwards [hc₁, hc₂],
intros x hx₁ hx₂,
show ∥f₁ x + f₂ x∥ ≤ (c₁ + c₂) * ∥g x∥,
apply le_trans (norm_triangle _ _),
rw add_mul,
exact add_le_add hx₁ hx₂
end
theorem is_o.add {f₁ f₂ : α → β} {g : α → γ} {l : filter α} (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) :
is_o (λ x, f₁ x + f₂ x) g l :=
begin
intros c cpos,
filter_upwards [h₁ (c / 2) (half_pos cpos), h₂ (c / 2) (half_pos cpos)],
intros x hx₁ hx₂, dsimp at hx₁ hx₂,
apply le_trans (norm_triangle _ _),
apply le_trans (add_le_add hx₁ hx₂),
rw [←mul_add, ←two_mul, ←mul_assoc, div_mul_cancel _ two_ne_zero]
end
theorem is_O.sub {f₁ f₂ : α → β} {g : α → γ} {l : filter α} (h₁ : is_O f₁ g l) (h₂ : is_O f₂ g l) :
is_O (λ x, f₁ x - f₂ x) g l :=
h₁.add (is_O_neg_left.mpr h₂)
theorem is_o.sub {f₁ f₂ : α → β} {g : α → γ} {l : filter α} (h₁ : is_o f₁ g l) (h₂ : is_o f₂ g l) :
is_o (λ x, f₁ x - f₂ x) g l :=
h₁.add (is_o_neg_left.mpr h₂)
theorem is_O_comm {f₁ f₂ : α → β} {g : α → γ} {l : filter α} :
is_O (λ x, f₁ x - f₂ x) g l ↔ is_O (λ x, f₂ x - f₁ x) g l :=
by simpa using @is_O_neg_left _ _ _ _ _ (λ x, f₂ x - f₁ x) g l
theorem is_O.symm {f₁ f₂ : α → β} {g : α → γ} {l : filter α} :
is_O (λ x, f₁ x - f₂ x) g l → is_O (λ x, f₂ x - f₁ x) g l :=
is_O_comm.1
theorem is_O.tri {f₁ f₂ f₃ : α → β} {g : α → γ} {l : filter α}
(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 (by simp)
theorem is_O.congr_of_sub {f₁ f₂ : α → β} {g : α → γ} {l : filter α}
(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_comm {f₁ f₂ : α → β} {g : α → γ} {l : filter α} :
is_o (λ x, f₁ x - f₂ x) g l ↔ is_o (λ x, f₂ x - f₁ x) g l :=
by simpa using @is_o_neg_left _ _ _ _ _ (λ x, f₂ x - f₁ x) g l
theorem is_o.symm {f₁ f₂ : α → β} {g : α → γ} {l : filter α} :
is_o (λ x, f₁ x - f₂ x) g l → is_o (λ x, f₂ x - f₁ x) g l :=
is_o_comm.1
theorem is_o.tri {f₁ f₂ f₃ : α → β} {g : α → γ} {l : filter α}
(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 (by simp)
theorem is_o.congr_of_sub {f₁ f₂ : α → β} {g : α → γ} {l : filter α}
(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 _ _)⟩
@[simp] theorem is_O_prod_left {f₁ : α → β} {f₂ : α → δ} {g : α → γ} {l : filter α} :
is_O (λx, (f₁ x, f₂ x)) g l ↔ is_O f₁ g l ∧ is_O f₂ g l :=
begin
split,
{ assume h,
split,
{ exact is_O.trans (is_O.prod_rightl (is_O_refl f₁ l)) h },
{ exact is_O.trans (is_O.prod_rightr (is_O_refl f₂ l)) h } },
{ rintros ⟨h₁, h₂⟩,
have : is_O (λx, ∥f₁ x∥ + ∥f₂ x∥) g l :=
is_O.add (is_O_norm_left.2 h₁) (is_O_norm_left.2 h₂),
apply is_O.trans _ this,
refine ⟨1, zero_lt_one, filter.univ_mem_sets' (λx, _)⟩,
simp only [norm, max_le_iff, one_mul, set.mem_set_of_eq],
split; exact le_trans (by simp) (le_abs_self _) }
end
@[simp] theorem is_o_prod_left {f₁ : α → β} {f₂ : α → δ} {g : α → γ} {l : filter α} :
is_o (λx, (f₁ x, f₂ x)) g l ↔ is_o f₁ g l ∧ is_o f₂ g l :=
begin
split,
{ assume h,
split,
{ exact is_O.trans_is_o (is_O.prod_rightl (is_O_refl f₁ l)) h },
{ exact is_O.trans_is_o (is_O.prod_rightr (is_O_refl f₂ l)) h } },
{ rintros ⟨h₁, h₂⟩,
have : is_o (λx, ∥f₁ x∥ + ∥f₂ x∥) g l :=
is_o.add (is_o_norm_left.2 h₁) (is_o_norm_left.2 h₂),
apply is_O.trans_is_o _ this,
refine ⟨1, zero_lt_one, filter.univ_mem_sets' (λx, _)⟩,
simp only [norm, max_le_iff, one_mul, set.mem_set_of_eq],
split; exact le_trans (by simp) (le_abs_self _) }
end
end
section
variables [normed_group β] [normed_group γ]
theorem is_O_zero (g : α → γ) (l : filter α) :
is_O (λ x, (0 : β)) g l :=
⟨1, zero_lt_one, by { filter_upwards [univ_mem_sets], intros x _, simp }⟩
theorem is_O_refl_left {f : α → β} {g : α → γ} {l : filter α} :
is_O (λ x, f x - f x) g l :=
by simpa using is_O_zero g l
theorem is_O_zero_right_iff {f : α → β} {l : filter α} :
is_O f (λ x, (0 : γ)) l ↔ {x | f x = 0} ∈ l :=
begin
rw [is_O_iff], split,
{ rintros ⟨c, hc⟩,
filter_upwards [hc], dsimp,
intro x, rw [norm_zero, mul_zero], intro hx,
rw ←norm_eq_zero,
exact le_antisymm hx (norm_nonneg _) },
intro h, use 0,
filter_upwards [h], dsimp,
intros x hx,
rw [hx, norm_zero, zero_mul]
end
theorem is_o_zero (g : α → γ) (l : filter α) :
is_o (λ x, (0 : β)) g l :=
λ c cpos,
by { filter_upwards [univ_mem_sets], intros x _, simp,
exact mul_nonneg (le_of_lt cpos) (norm_nonneg _)}
theorem is_o_refl_left {f : α → β} {g : α → γ} {l : filter α} :
is_o (λ x, f x - f x) g l :=
by simpa using is_o_zero g l
theorem is_o_zero_right_iff {f : α → β} (l : filter α) :
is_o f (λ x, (0 : γ)) l ↔ {x | f x = 0} ∈ l :=
begin
split,
{ intro h, exact is_O_zero_right_iff.mp h.to_is_O },
intros h c cpos,
filter_upwards [h], dsimp,
intros x hx,
rw [hx, norm_zero, norm_zero, mul_zero]
end
end
section
variables [has_norm β] [normed_field γ]
open normed_field
theorem is_O_const_one (c : β) (l : filter α) :
is_O (λ x : α, c) (λ x, (1 : γ)) l :=
begin
rw is_O_iff,
refine ⟨∥c∥, _⟩,
simp only [norm_one, mul_one],
apply univ_mem_sets',
simp [le_refl],
end
end
section
variables [normed_field β] [normed_group γ]
theorem is_O_const_mul_left {f : α → β} {g : α → γ} {l : filter α} (h : is_O f g l) (c : β) :
is_O (λ x, c * f x) g l :=
begin
cases classical.em (c = 0) with h'' h'',
{ simp [h''], apply is_O_zero },
rcases h with ⟨c', c'pos, h'⟩,
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp h'',
have cpos : ∥c∥ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
refine ⟨∥c∥ * c', mul_pos cpos c'pos, _⟩,
filter_upwards [h'], dsimp,
intros x h₀,
rw [normed_field.norm_mul, mul_assoc],
exact mul_le_mul_of_nonneg_left h₀ (norm_nonneg _)
end
theorem is_O_const_mul_left_iff {f : α → β} {g : α → γ} {l : filter α} {c : β} (hc : c ≠ 0) :
is_O (λ x, c * f x) g l ↔ is_O f g l :=
begin
split,
{ intro h,
convert is_O_const_mul_left h c⁻¹, ext,
rw [←mul_assoc, inv_mul_cancel hc, one_mul] },
intro h, apply is_O_const_mul_left h
end
theorem is_o_const_mul_left {f : α → β} {g : α → γ} {l : filter α}
(h : is_o f g l) (c : β) :
is_o (λ x, c * f x) g l :=
begin
cases classical.em (c = 0) with h'' h'',
{ simp [h''], apply is_o_zero },
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp h'',
have cpos : ∥c∥ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
intros c' c'pos, dsimp,
filter_upwards [h (c' / ∥c∥) (div_pos c'pos cpos)], dsimp,
intros x hx, rw [normed_field.norm_mul],
apply le_trans (mul_le_mul_of_nonneg_left hx (le_of_lt cpos)),
rw [←mul_assoc, mul_div_cancel' _ cne0]
end
theorem is_o_const_mul_left_iff {f : α → β} {g : α → γ} {l : filter α} {c : β} (hc : c ≠ 0) :
is_o (λ x, c * f x) g l ↔ is_o f g l :=
begin
split,
{ intro h,
convert is_o_const_mul_left h c⁻¹, ext,
rw [←mul_assoc, inv_mul_cancel hc, one_mul] },
intro h',
apply is_o_const_mul_left h'
end
end
section
variables [normed_group β] [normed_field γ]
theorem is_O_of_is_O_const_mul_right {f : α → β} {g : α → γ} {l : filter α} {c : γ}
(h : is_O f (λ x, c * g x) l) :
is_O f g l :=
begin
cases classical.em (c = 0) with h' h',
{ simp [h', is_O_zero_right_iff] at h, rw is_O_congr_left h, apply is_O_zero },
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp h',
have cpos : ∥c∥ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
rcases h with ⟨c', c'pos, h''⟩,
refine ⟨c' * ∥c∥, mul_pos c'pos cpos, _⟩,
convert h'', ext x, dsimp,
rw [normed_field.norm_mul, mul_assoc]
end
theorem is_O_const_mul_right_iff {f : α → β} {g : α → γ} {l : filter α} {c : γ} (hc : c ≠ 0) :
is_O f (λ x, c * g x) l ↔ is_O f g l :=
begin
split,
{ intro h, exact is_O_of_is_O_const_mul_right h },
intro h,
apply is_O_of_is_O_const_mul_right,
show is_O f (λ (x : α), c⁻¹ * (c * g x)) l,
convert h, ext, rw [←mul_assoc, inv_mul_cancel hc, one_mul]
end
theorem is_o_of_is_o_const_mul_right {f : α → β} {g : α → γ} {l : filter α} {c : γ}
(h : is_o f (λ x, c * g x) l) :
is_o f g l :=
begin
cases classical.em (c = 0) with h' h',
{ simp [h', is_o_zero_right_iff] at h, rw is_o_congr_left h, apply is_o_zero },
have cne0 : ∥c∥ ≠ 0, from mt (norm_eq_zero _).mp h',
have cpos : ∥c∥ > 0, from lt_of_le_of_ne (norm_nonneg _) (ne.symm cne0),
intros c' c'pos,
convert h (c' / ∥c∥) (div_pos c'pos cpos), dsimp,
ext x, rw [normed_field.norm_mul, ←mul_assoc, div_mul_cancel _ cne0]
end
theorem is_o_const_mul_right {f : α → β} {g : α → γ} {l : filter α} {c : γ} (hc : c ≠ 0) :
is_o f (λ x, c * g x) l ↔ is_o f g l :=
begin
split,
{ intro h, exact is_o_of_is_o_const_mul_right h },
intro h,
apply is_o_of_is_o_const_mul_right,
show is_o f (λ (x : α), c⁻¹ * (c * g x)) l,
convert h, ext, rw [←mul_assoc, inv_mul_cancel hc, one_mul]
end
theorem is_o_one_iff {f : α → β} {l : filter α} :
is_o f (λ x, (1 : γ)) l ↔ tendsto f l (nhds 0) :=
begin
rw [normed_group.tendsto_nhds_zero, is_o], split,
{ intros h e epos,
filter_upwards [h (e / 2) (half_pos epos)], simp,
intros x hx,
exact lt_of_le_of_lt hx (half_lt_self epos) },
intros h e epos,
filter_upwards [h e epos], simp,
intros x hx,
exact le_of_lt hx
end
theorem is_O_one_of_tendsto {f : α → β} {l : filter α} {y : β}
(h : tendsto f l (nhds y)) : is_O f (λ x, (1 : γ)) l :=
begin
have Iy : ∥y∥ < ∥y∥ + 1 := lt_add_one _,
refine ⟨∥y∥ + 1, lt_of_le_of_lt (norm_nonneg _) Iy, _⟩,
simp only [mul_one, normed_field.norm_one],
have : tendsto (λx, ∥f x∥) l (nhds ∥y∥) :=
(continuous_norm.tendsto _).comp h,
exact this (ge_mem_nhds Iy)
end
end
section
variables [normed_group β] [normed_group γ]
theorem is_O.trans_tendsto {f : α → β} {g : α → γ} {l : filter α}
(h₁ : is_O f g l) (h₂ : tendsto g l (nhds 0)) :
tendsto f l (nhds 0) :=
(@is_o_one_iff _ _ ℝ _ _ _ _).1 $ h₁.trans_is_o $ is_o_one_iff.2 h₂
theorem is_o.trans_tendsto {f : α → β} {g : α → γ} {l : filter α}
(h₁ : is_o f g l) : tendsto g l (nhds 0) → tendsto f l (nhds 0) :=
h₁.to_is_O.trans_tendsto
end
section
variables [normed_field β] [normed_field γ]
theorem is_O_mul {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(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
rcases h₁ with ⟨c₁, c₁pos, hc₁⟩,
rcases h₂ with ⟨c₂, c₂pos, hc₂⟩,
refine ⟨c₁ * c₂, mul_pos c₁pos c₂pos, _⟩,
filter_upwards [hc₁, hc₂], dsimp,
intros x hx₁ hx₂,
rw [normed_field.norm_mul, normed_field.norm_mul, mul_assoc, mul_left_comm c₂, ←mul_assoc],
exact mul_le_mul hx₁ hx₂ (norm_nonneg _) (mul_nonneg (le_of_lt c₁pos) (norm_nonneg _))
end
theorem is_o_mul_left {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(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₁ with ⟨c₁, c₁pos, hc₁⟩,
filter_upwards [hc₁, h₂ (c / c₁) (div_pos cpos c₁pos)], dsimp,
intros x hx₁ hx₂,
rw [normed_field.norm_mul, normed_field.norm_mul],
apply le_trans (mul_le_mul hx₁ hx₂ (norm_nonneg _) (mul_nonneg (le_of_lt c₁pos) (norm_nonneg _))),
rw [mul_comm c₁, mul_assoc, mul_left_comm c₁, ←mul_assoc _ c₁, div_mul_cancel _ (ne_of_gt c₁pos)],
rw [mul_left_comm]
end
theorem is_o_mul_right {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(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 convert is_o_mul_left h₂ h₁; simp only [mul_comm]
theorem is_o_mul {f₁ f₂ : α → β} {g₁ g₂ : α → γ} {l : filter α}
(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 :=
is_o_mul_left h₁.to_is_O h₂
end
/-
Note: the theorems in the next two sections can also be used for the integers, since
scalar multiplication is multiplication.
-/
section
variables {K : Type*} [normed_field K] [normed_group β] [normed_space K β] [normed_group γ]
set_option class.instance_max_depth 43
theorem is_O_const_smul_left {f : α → β} {g : α → γ} {l : filter α} (h : is_O f g l) (c : K) :
is_O (λ x, c • f x) g l :=
begin
rw [←is_O_norm_left], simp only [norm_smul],
apply is_O_const_mul_left,
rw [is_O_norm_left],
apply h
end
theorem is_O_const_smul_left_iff {f : α → β} {g : α → γ} {l : filter α} {c : K} (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 {f : α → β} {g : α → γ} {l : filter α} (h : is_o f g l) (c : K) :
is_o (λ x, c • f x) g l :=
begin
rw [←is_o_norm_left], simp only [norm_smul],
apply is_o_const_mul_left,
rw [is_o_norm_left],
apply h
end
theorem is_o_const_smul_left_iff {f : α → β} {g : α → γ} {l : filter α} {c : K} (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
end
section
variables {K : Type*} [normed_group β] [normed_field K] [normed_group γ] [normed_space K γ]
set_option class.instance_max_depth 43
theorem is_O_const_smul_right {f : α → β} {g : α → γ} {l : filter α} {c : K} (hc : c ≠ 0) :
is_O f (λ x, c • g x) l ↔ is_O f g 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 {f : α → β} {g : α → γ} {l : filter α} {c : K} (hc : c ≠ 0) :
is_o f (λ x, c • g x) l ↔ is_o f g 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 cne0, is_o_norm_right]
end
end
section
variables {K : Type*} [normed_field K] [normed_group β] [normed_space K β]
[normed_group γ] [normed_space K γ]
set_option class.instance_max_depth 43
theorem is_O_smul {k : α → K} {f : α → β} {g : α → γ} {l : filter α} (h : is_O f g l) :
is_O (λ x, k x • f x) (λ x, k x • g x) l :=
begin
rw [←is_O_norm_left, ←is_O_norm_right], simp only [norm_smul],
apply is_O_mul (is_O_refl _ _),
rw [is_O_norm_left, is_O_norm_right],
exact h
end
theorem is_o_smul {k : α → K} {f : α → β} {g : α → γ} {l : filter α} (h : is_o f g l) :
is_o (λ x, k x • f x) (λ x, k x • g x) l :=
begin
rw [←is_o_norm_left, ←is_o_norm_right], simp only [norm_smul],
apply is_o_mul_left (is_O_refl _ _),
rw [is_o_norm_left, is_o_norm_right],
exact h
end
end
section
variables [normed_field β]
theorem tendsto_nhds_zero_of_is_o {f g : α → β} {l : filter α} (h : is_o f g l) :
tendsto (λ x, f x / (g x)) l (nhds 0) :=
have eq₁ : is_o (λ x, f x / g x) (λ x, g x / g x) l,
from is_o_mul_right h (is_O_refl _ _),
have eq₂ : is_O (λ x, g x / g x) (λ x, (1 : β)) l,
begin
use [1, zero_lt_one],
filter_upwards [univ_mem_sets], simp,
intro x,
cases classical.em (∥g x∥ = 0) with h' h'; simp [h'],
exact zero_le_one
end,
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 (nhds 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 is_o_mul_right eq₁ (is_O_refl _ _); simp,
have eq₃ : is_O f (λ x, f x / g x * g x) l,
begin
use [1, zero_lt_one],
refine filter.univ_mem_sets' (assume x, _),
suffices : ∥f x∥ ≤ ∥f x∥ / ∥g x∥ * ∥g x∥, { simpa },
by_cases g x = 0,
{ simp only [h, hgf x h, norm_zero, mul_zero] },
{ rw [div_mul_cancel], exact mt (norm_eq_zero _).1 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 (nhds 0) :=
iff.intro tendsto_nhds_zero_of_is_o (is_o_of_tendsto hgf)
end
end asymptotics
|
b386f6a3ca46aff3f2fbd4a073ce02c98b1205f7
|
206422fb9edabf63def0ed2aa3f489150fb09ccb
|
/src/data/buffer/parser/numeral.lean
|
ab7b0a4ea1ecc3b7ca3e05a95578f6f63967f092
|
[
"Apache-2.0"
] |
permissive
|
hamdysalah1/mathlib
|
b915f86b2503feeae268de369f1b16932321f097
|
95454452f6b3569bf967d35aab8d852b1ddf8017
|
refs/heads/master
| 1,677,154,116,545
| 1,611,797,994,000
| 1,611,797,994,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,238
|
lean
|
/-
Copyright (c) 2020 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import data.fintype.card
/-!
# Numeral parsers
This file expands on the existing `nat : parser ℕ` to provide parsers into any type `α` that
can be represented by a numeral, which relies on `α` having a 0, 1, and addition operation.
There are also convenience parsers that ensure that the numeral parsed in is not larger than
the cardinality of the type `α` , if it is known that `fintype α`. Additionally, there are
convenience parsers that parse in starting from "1", which can be useful for positive ordinals;
or parser from a given character or character range.
## Main definitions
* 'numeral` : The parser which uses `nat.cast` to map the result of `parser.nat` to the desired `α`
* `numeral.of_fintype` : The parser which `guard`s to make sure the parsed numeral is within the
cardinality of the target `fintype` type `α`.
## Implementation details
When the `numeral` or related parsers are invoked, the desired type is provided explicitly. In many
cases, it can be inferred, so one can write, for example
```lean
def get_fin : string → fin 5 :=
sum.elim (λ _, 0) id ∘ parser.run_string (parser.numeral.of_fintype _)
```
In the definitions of the parsers (except for `numeral`), there is an explicit `nat.bin_cast`
instead an explicit or implicit `nat.cast`
-/
open parser parse_result
namespace parser
variables (α : Type) [has_zero α] [has_one α] [has_add α]
/--
Parse a string of digits as a numeral while casting it to target type `α`.
-/
def numeral : parser α :=
nat.bin_cast <$> nat
/--
Parse a string of digits as a numeral while casting it to target type `α`,
which has a `[fintype α]` constraint. The parser ensures that the numeral parsed in
is within the cardinality of the type `α`.
-/
def numeral.of_fintype [fintype α] : parser α :=
do
c ← nat,
decorate_error (sformat!"<numeral less than {to_string (fintype.card α)}>")
(guard (c < fintype.card α)),
pure $ nat.bin_cast c
/--
Parse a string of digits as a numeral while casting it to target type `α`. The parsing starts
at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure.
-/
def numeral.from_one : parser α :=
do
c ← nat,
decorate_error ("<positive numeral>")
(guard (0 < c)),
pure $ nat.bin_cast (c - 1)
/--
Parse a string of digits as a numeral while casting it to target type `α`,
which has a `[fintype α]` constraint. The parser ensures that the numeral parsed in
is within the cardinality of the type `α`. The parsing starts
at "1", so `"1"` is parsed in as `nat.cast 0`. Providing `"0"` to the parser causes a failure.
-/
def numeral.from_one.of_fintype [fintype α] : parser α :=
do
c ← nat,
decorate_error (sformat!"<positive numeral less than or equal to {to_string (fintype.card α)}>")
(guard (0 < c ∧ c ≤ fintype.card α)),
pure $ nat.bin_cast (c - 1)
/--
Parse a character as a numeral while casting it to target type `α`,
The parser ensures that the character parsed in is within the bounds set by `fromc` and `toc`,
and subtracts the value of `fromc` from the parsed in character.
-/
def numeral.char (fromc toc : char) : parser α :=
do
c ← decorate_error
(sformat!"<char between '{fromc.to_string}' to '{toc.to_string}' inclusively>")
(sat (λ c, fromc ≤ c ∧ c ≤ toc)),
pure $ nat.bin_cast (c.to_nat - fromc.to_nat)
/--
Parse a character as a numeral while casting it to target type `α`,
which has a `[fintype α]` constraint.
The parser ensures that the character parsed in is greater or equal to `fromc` and
and subtracts the value of `fromc` from the parsed in character. There is also a check
that the resulting value is within the cardinality of the type `α`.
-/
def numeral.char.of_fintype [fintype α] (fromc : char) : parser α :=
do
c ← decorate_error
(sformat!"<char from '{fromc.to_string}' to '{
(char.of_nat (fromc.to_nat + fintype.card α - 1)).to_string}' inclusively>")
(sat (λ c, fromc ≤ c ∧ c.to_nat - fintype.card α < fromc.to_nat)),
pure $ nat.bin_cast (c.to_nat - fromc.to_nat)
end parser
|
b8b7a6f0addd99152015215386d2675659daa387
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/topology/sheaves/local_predicate.lean
|
2b8747ce3a40ac0eeb9206adefafe917aaca901b
|
[] |
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
| 15,248
|
lean
|
/-
Copyright (c) 2020 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Scott Morrison, Adam Topaz
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.sheaves.sheaf_of_functions
import Mathlib.topology.sheaves.stalks
import Mathlib.PostPort
universes v l
namespace Mathlib
/-!
# Functions satisfying a local predicate form a sheaf.
At this stage, in `topology/sheaves/sheaf_of_functions.lean`
we've proved that not-necessarily-continuous functions from a topological space
into some type (or type family) form a sheaf.
Why do the continuous functions form a sheaf?
The point is just that continuity is a local condition,
so one can use the lifting condition for functions to provide a candidate lift,
then verify that the lift is actually continuous by using the factorisation condition for the lift
(which guarantees that on each open set it agrees with the functions being lifted,
which were assumed to be continuous).
This file abstracts this argument to work for
any collection of dependent functions on a topological space
satisfying a "local predicate".
As an application, we check that continuity is a local predicate in this sense, and provide
* `Top.sheaf_condition.to_Top`: continuous functions into a topological space form a sheaf
A sheaf constructed in this way has a natural map `stalk_to_fiber` from the stalks
to the types in the ambient type family.
We give conditions sufficient to show that this map is injective and/or surjective.
-/
namespace Top
/--
Given a topological space `X : Top` and a type family `T : X → Type`,
a `P : prelocal_predicate T` consists of:
* a family of predicates `P.pred`, one for each `U : opens X`, of the form `(Π x : U, T x) → Prop`
* a proof that if `f : Π x : V, T x` satisfies the predicate on `V : opens X`, then
the restriction of `f` to any open subset `U` also satisfies the predicate.
-/
structure prelocal_predicate {X : Top} (T : ↥X → Type v)
where
pred : {U : topological_space.opens ↥X} → ((x : ↥U) → T ↑x) → Prop
res : ∀ {U V : topological_space.opens ↥X} (i : U ⟶ V) (f : (x : ↥V) → T ↑x), pred f → pred fun (x : ↥U) => f (coe_fn i x)
/--
Continuity is a "prelocal" predicate on functions to a fixed topological space `T`.
-/
@[simp] theorem continuous_prelocal_pred (X : Top) (T : Top) (U : topological_space.opens ↥X) (f : ↥U → ↥T) : prelocal_predicate.pred (continuous_prelocal X T) f = continuous f :=
Eq.refl (prelocal_predicate.pred (continuous_prelocal X T) f)
/-- Satisfying the inhabited linter. -/
protected instance inhabited_prelocal_predicate (X : Top) (T : Top) : Inhabited (prelocal_predicate fun (x : ↥X) => ↥T) :=
{ default := continuous_prelocal X T }
/--
Given a topological space `X : Top` and a type family `T : X → Type`,
a `P : local_predicate T` consists of:
* a family of predicates `P.pred`, one for each `U : opens X`, of the form `(Π x : U, T x) → Prop`
* a proof that if `f : Π x : V, T x` satisfies the predicate on `V : opens X`, then
the restriction of `f` to any open subset `U` also satisfies the predicate, and
* a proof that given some `f : Π x : U, T x`,
if for every `x : U` we can find an open set `x ∈ V ≤ U`
so that the restriction of `f` to `V` satisfies the predicate,
then `f` itself satisfies the predicate.
-/
structure local_predicate {X : Top} (T : ↥X → Type v)
extends prelocal_predicate T
where
locality : ∀ {U : topological_space.opens ↥X} (f : (x : ↥U) → T ↑x),
(∀ (x : ↥U),
∃ (V : topological_space.opens ↥X),
∃ (m : subtype.val x ∈ V),
∃ (i : V ⟶ U), prelocal_predicate.pred _to_prelocal_predicate fun (x : ↥V) => f (coe_fn i x)) →
prelocal_predicate.pred _to_prelocal_predicate f
/--
Continuity is a "local" predicate on functions to a fixed topological space `T`.
-/
def continuous_local (X : Top) (T : Top) : local_predicate fun (x : ↥X) => ↥T :=
local_predicate.mk (prelocal_predicate.mk (prelocal_predicate.pred (continuous_prelocal X T)) sorry) sorry
/-- Satisfying the inhabited linter. -/
protected instance inhabited_local_predicate (X : Top) (T : Top) : Inhabited (local_predicate fun (x : ↥X) => ↥T) :=
{ default := continuous_local X T }
/--
Given a `P : prelocal_predicate`, we can always construct a `local_predicate`
by asking that the condition from `P` holds locally near every point.
-/
def prelocal_predicate.sheafify {X : Top} {T : ↥X → Type v} (P : prelocal_predicate T) : local_predicate T :=
local_predicate.mk
(prelocal_predicate.mk
(fun (U : topological_space.opens ↥X) (f : (x : ↥U) → T ↑x) =>
∀ (x : ↥U),
∃ (V : topological_space.opens ↥X),
∃ (m : subtype.val x ∈ V), ∃ (i : V ⟶ U), prelocal_predicate.pred P fun (x : ↥V) => f (coe_fn i x))
sorry)
sorry
theorem prelocal_predicate.sheafify_of {X : Top} {T : ↥X → Type v} {P : prelocal_predicate T} {U : topological_space.opens ↥X} {f : (x : ↥U) → T ↑x} (h : prelocal_predicate.pred P f) : prelocal_predicate.pred (local_predicate.to_prelocal_predicate (prelocal_predicate.sheafify P)) f := sorry
/--
The subpresheaf of dependent functions on `X` satisfying the "pre-local" predicate `P`.
-/
def subpresheaf_to_Types {X : Top} {T : ↥X → Type v} (P : prelocal_predicate T) : presheaf (Type v) X :=
category_theory.functor.mk
(fun (U : topological_space.opens ↥Xᵒᵖ) =>
Subtype fun (f : (x : ↥(opposite.unop U)) → T ↑x) => prelocal_predicate.pred P f)
fun (U V : topological_space.opens ↥Xᵒᵖ) (i : U ⟶ V)
(f : Subtype fun (f : (x : ↥(opposite.unop U)) → T ↑x) => prelocal_predicate.pred P f) =>
{ val := fun (x : ↥(opposite.unop V)) => subtype.val f (coe_fn (category_theory.has_hom.hom.unop i) x),
property := sorry }
namespace subpresheaf_to_Types
/--
The natural transformation including the subpresheaf of functions satisfying a local predicate
into the presheaf of all functions.
-/
def subtype {X : Top} {T : ↥X → Type v} (P : prelocal_predicate T) : subpresheaf_to_Types P ⟶ presheaf_to_Types X T :=
category_theory.nat_trans.mk
fun (U : topological_space.opens ↥Xᵒᵖ) (f : category_theory.functor.obj (subpresheaf_to_Types P) U) => subtype.val f
/--
The natural transformation
from the sheaf condition diagram for functions satisfying a local predicate
to the sheaf condition diagram for arbitrary functions,
given by forgetting that the local predicate holds.
-/
def diagram_subtype {X : Top} {T : ↥X → Type v} (P : prelocal_predicate T) {ι : Type v} (U : ι → topological_space.opens ↥X) : presheaf.sheaf_condition_equalizer_products.diagram (subpresheaf_to_Types P) U ⟶
presheaf.sheaf_condition_equalizer_products.diagram (presheaf_to_Types X T) U :=
category_theory.nat_trans.mk
fun (j : category_theory.limits.walking_parallel_pair) =>
category_theory.limits.walking_parallel_pair.rec_on j
(category_theory.limits.pi.map
fun (i : ι) (f : category_theory.functor.obj (subpresheaf_to_Types P) (opposite.op (U i))) => subtype.val f)
(category_theory.limits.pi.map
fun (p : ι × ι)
(f : category_theory.functor.obj (subpresheaf_to_Types P) (opposite.op (U (prod.fst p) ⊓ U (prod.snd p)))) =>
subtype.val f)
-- auxilliary lemma for `sheaf_condition` below
theorem sheaf_condition_fac {X : Top} {T : ↥X → Type v} {P : local_predicate T} {ι : Type v} {U : ι → topological_space.opens ↥X} {s : category_theory.limits.fork
(presheaf.sheaf_condition_equalizer_products.left_res (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P))
U)
(presheaf.sheaf_condition_equalizer_products.right_res
(subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) U)} (i : ι) (f : category_theory.limits.cone.X s) (h : prelocal_predicate.pred (local_predicate.to_prelocal_predicate P)
(category_theory.limits.is_limit.lift (presheaf.to_Types X T U)
(category_theory.functor.obj
(category_theory.limits.cones.postcompose (diagram_subtype (local_predicate.to_prelocal_predicate P) U)) s)
f)) : category_theory.limits.limit.π
(category_theory.discrete.functor
fun (i : ι) =>
Subtype
fun (f : (x : ↥(opposite.unop (opposite.op (U i)))) → T ↑x) =>
prelocal_predicate.pred (local_predicate.to_prelocal_predicate P) f)
i
(presheaf.sheaf_condition_equalizer_products.res (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) U
{ val :=
category_theory.limits.is_limit.lift (presheaf.to_Types X T U)
(category_theory.functor.obj
(category_theory.limits.cones.postcompose (diagram_subtype (local_predicate.to_prelocal_predicate P) U))
s)
f,
property := h }) =
category_theory.limits.limit.π
(category_theory.discrete.functor
fun (i : ι) =>
Subtype
fun (f : (x : ↥(opposite.unop (opposite.op (U i)))) → T ↑x) =>
prelocal_predicate.pred (local_predicate.to_prelocal_predicate P) f)
i (category_theory.limits.fork.ι s f) := sorry
-- auxilliary lemma for `sheaf_condition` below
theorem sheaf_condition_uniq {X : Top} {T : ↥X → Type v} {P : local_predicate T} {ι : Type v} {U : ι → topological_space.opens ↥X} {s : category_theory.limits.fork
(presheaf.sheaf_condition_equalizer_products.left_res (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P))
U)
(presheaf.sheaf_condition_equalizer_products.right_res
(subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) U)} (m : category_theory.limits.cone.X s ⟶
category_theory.limits.cone.X
(presheaf.sheaf_condition_equalizer_products.fork (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P))
U)) (w : ∀ (j : category_theory.limits.walking_parallel_pair),
m ≫
category_theory.nat_trans.app
(category_theory.limits.cone.π
(presheaf.sheaf_condition_equalizer_products.fork
(subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) U))
j =
category_theory.nat_trans.app (category_theory.limits.cone.π s) j) (f : category_theory.limits.cone.X s) (h : prelocal_predicate.pred (local_predicate.to_prelocal_predicate P)
(category_theory.limits.is_limit.lift (presheaf.to_Types X T U)
(category_theory.functor.obj
(category_theory.limits.cones.postcompose (diagram_subtype (local_predicate.to_prelocal_predicate P) U)) s)
f)) : m f =
{ val :=
category_theory.limits.is_limit.lift (presheaf.to_Types X T U)
(category_theory.functor.obj
(category_theory.limits.cones.postcompose (diagram_subtype (local_predicate.to_prelocal_predicate P) U)) s)
f,
property := h } := sorry
/--
The functions satisfying a local predicate satisfy the sheaf condition.
-/
def sheaf_condition {X : Top} {T : ↥X → Type v} (P : local_predicate T) : presheaf.sheaf_condition (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) := sorry
end subpresheaf_to_Types
/--
The subsheaf of the sheaf of all dependently typed functions satisfying the local predicate `P`.
-/
def subsheaf_to_Types {X : Top} {T : ↥X → Type v} (P : local_predicate T) : sheaf (Type v) X :=
sheaf.mk (subpresheaf_to_Types (local_predicate.to_prelocal_predicate P)) (subpresheaf_to_Types.sheaf_condition P)
/--
There is a canonical map from the stalk to the original fiber, given by evaluating sections.
-/
def stalk_to_fiber {X : Top} {T : ↥X → Type v} (P : local_predicate T) (x : ↥X) : presheaf.stalk (sheaf.presheaf (subsheaf_to_Types P)) x ⟶ T x :=
category_theory.limits.colimit.desc
(category_theory.functor.obj
(category_theory.functor.obj
(category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ) (topological_space.opens ↥Xᵒᵖ) (Type v))
(category_theory.functor.op (topological_space.open_nhds.inclusion x)))
(sheaf.presheaf (subsheaf_to_Types P)))
(category_theory.limits.cocone.mk (T x)
(category_theory.nat_trans.mk
fun (U : topological_space.open_nhds xᵒᵖ)
(f :
category_theory.functor.obj
(category_theory.functor.obj
(category_theory.functor.obj
(category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ) (topological_space.opens ↥Xᵒᵖ)
(Type v))
(category_theory.functor.op (topological_space.open_nhds.inclusion x)))
(sheaf.presheaf (subsheaf_to_Types P)))
U) =>
subtype.val f { val := x, property := sorry }))
@[simp] theorem stalk_to_fiber_germ {X : Top} {T : ↥X → Type v} (P : local_predicate T) (U : topological_space.opens ↥X) (x : ↥U) (f : category_theory.functor.obj (sheaf.presheaf (subsheaf_to_Types P)) (opposite.op U)) : stalk_to_fiber P (↑x) (presheaf.germ (sheaf.presheaf (subsheaf_to_Types P)) x f) = subtype.val f x := sorry
/--
The `stalk_to_fiber` map is surjective at `x` if
every point in the fiber `T x` has an allowed section passing through it.
-/
theorem stalk_to_fiber_surjective {X : Top} {T : ↥X → Type v} (P : local_predicate T) (x : ↥X) (w : ∀ (t : T x),
∃ (U : topological_space.open_nhds x),
∃ (f : (y : ↥(subtype.val U)) → T ↑y),
∃ (h : prelocal_predicate.pred (local_predicate.to_prelocal_predicate P) f),
f { val := x, property := subtype.property U } = t) : function.surjective (stalk_to_fiber P x) := sorry
/--
The `stalk_to_fiber` map is injective at `x` if any two allowed sections which agree at `x`
agree on some neighborhood of `x`.
-/
theorem stalk_to_fiber_injective {X : Top} {T : ↥X → Type v} (P : local_predicate T) (x : ↥X) (w : ∀ (U V : topological_space.open_nhds x) (fU : (y : ↥(subtype.val U)) → T ↑y),
prelocal_predicate.pred (local_predicate.to_prelocal_predicate P) fU →
∀ (fV : (y : ↥(subtype.val V)) → T ↑y),
prelocal_predicate.pred (local_predicate.to_prelocal_predicate P) fV →
fU { val := x, property := subtype.property U } = fV { val := x, property := subtype.property V } →
∃ (W : topological_space.open_nhds x),
∃ (iU : W ⟶ U), ∃ (iV : W ⟶ V), ∀ (w : ↥(subtype.val W)), fU (coe_fn iU w) = fV (coe_fn iV w)) : function.injective (stalk_to_fiber P x) := sorry
/--
Some repackaging:
the presheaf of functions satisfying `continuous_prelocal` is just the same thing as
the presheaf of continuous functions.
-/
def subpresheaf_continuous_prelocal_iso_presheaf_to_Top {X : Top} (T : Top) : subpresheaf_to_Types (continuous_prelocal X T) ≅ presheaf_to_Top X T := sorry
/--
The sheaf of continuous functions on `X` with values in a space `T`.
-/
def sheaf_to_Top {X : Top} (T : Top) : sheaf (Type v) X :=
sheaf.mk (presheaf_to_Top X T)
(coe_fn (presheaf.sheaf_condition_equiv_of_iso (subpresheaf_continuous_prelocal_iso_presheaf_to_Top T))
(subpresheaf_to_Types.sheaf_condition (continuous_local X T)))
|
6df3c52e688882daf159fc6615c2f44a8e36e74f
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/data/real/cau_seq.lean
|
f988d639e7caade8fd36a1d5cbb27fb0f9a0e19b
|
[
"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
| 33,426
|
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.group_power.lemmas
import algebra.order.absolute_value
import algebra.order.group.min_max
import algebra.order.field.basic
/-!
# Cauchy sequences
A basic theory of Cauchy sequences, used in the construction of the reals and p-adic numbers. Where
applicable, lemmas that will be reused in other contexts have been stated in extra generality.
There are other "versions" of Cauchyness in the library, in particular Cauchy filters in topology.
This is a concrete implementation that is useful for simplicity and computability reasons.
## Important definitions
* `is_cau_seq`: a predicate that says `f : ℕ → β` is Cauchy.
* `cau_seq`: the type of Cauchy sequences valued in type `β` with respect to an absolute value
function `abv`.
## Tags
sequence, cauchy, abs val, absolute value
-/
open is_absolute_value
variables {G α β : Type*}
theorem exists_forall_ge_and {α} [linear_order α] {P Q : α → Prop} :
(∃ i, ∀ j ≥ i, P j) → (∃ i, ∀ j ≥ i, Q j) →
∃ i, ∀ j ≥ i, P j ∧ Q j
| ⟨a, h₁⟩ ⟨b, h₂⟩ := let ⟨c, ac, bc⟩ := exists_ge_of_linear a b in
⟨c, λ j hj, ⟨h₁ _ (le_trans ac hj), h₂ _ (le_trans bc hj)⟩⟩
section
variables [linear_ordered_field α] [ring β] (abv : β → α) [is_absolute_value abv]
theorem rat_add_continuous_lemma
{ε : α} (ε0 : 0 < ε) : ∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β},
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ + a₂ - (b₁ + b₂)) < ε :=
⟨ε / 2, half_pos ε0, λ a₁ a₂ b₁ b₂ h₁ h₂,
by simpa [add_halves, sub_eq_add_neg, add_comm, add_left_comm, add_assoc]
using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add h₁ h₂)⟩
theorem rat_mul_continuous_lemma
{ε K₁ K₂ : α} (ε0 : 0 < ε) :
∃ δ > 0, ∀ {a₁ a₂ b₁ b₂ : β}, abv a₁ < K₁ → abv b₂ < K₂ →
abv (a₁ - b₁) < δ → abv (a₂ - b₂) < δ → abv (a₁ * a₂ - b₁ * b₂) < ε :=
begin
have K0 : (0 : α) < max 1 (max K₁ K₂) := lt_of_lt_of_le zero_lt_one (le_max_left _ _),
have εK := div_pos (half_pos ε0) K0,
refine ⟨_, εK, λ a₁ a₂ b₁ b₂ ha₁ hb₂ h₁ h₂, _⟩,
replace ha₁ := lt_of_lt_of_le ha₁ (le_trans (le_max_left _ K₂) (le_max_right 1 _)),
replace hb₂ := lt_of_lt_of_le hb₂ (le_trans (le_max_right K₁ _) (le_max_right 1 _)),
have := add_lt_add
(mul_lt_mul' (le_of_lt h₁) hb₂ (abv_nonneg abv _) εK)
(mul_lt_mul' (le_of_lt h₂) ha₁ (abv_nonneg abv _) εK),
rw [← abv_mul abv, mul_comm, div_mul_cancel _ (ne_of_gt K0), ← abv_mul abv, add_halves] at this,
simpa [mul_add, add_mul, sub_eq_add_neg, add_comm, add_left_comm]
using lt_of_le_of_lt (abv_add abv _ _) this
end
theorem rat_inv_continuous_lemma
{β : Type*} [division_ring β] (abv : β → α) [is_absolute_value abv]
{ε K : α} (ε0 : 0 < ε) (K0 : 0 < K) :
∃ δ > 0, ∀ {a b : β}, K ≤ abv a → K ≤ abv b →
abv (a - b) < δ → abv (a⁻¹ - b⁻¹) < ε :=
begin
refine ⟨K * ε * K, mul_pos (mul_pos K0 ε0) K0, λ a b ha hb h, _⟩,
have a0 := K0.trans_le ha,
have b0 := K0.trans_le hb,
rw [inv_sub_inv' ((abv_pos abv).1 a0) ((abv_pos abv).1 b0), abv_mul abv, abv_mul abv,
abv_inv abv, abv_inv abv, abv_sub abv],
refine lt_of_mul_lt_mul_left (lt_of_mul_lt_mul_right _ b0.le) a0.le,
rw [mul_assoc, inv_mul_cancel_right₀ b0.ne', ←mul_assoc, mul_inv_cancel a0.ne', one_mul],
refine h.trans_le _,
exact mul_le_mul (mul_le_mul ha le_rfl ε0.le a0.le) hb K0.le (mul_nonneg a0.le ε0.le),
end
end
/-- A sequence is Cauchy if the distance between its entries tends to zero. -/
def is_cau_seq {α : Type*} [linear_ordered_field α]
{β : Type*} [ring β] (abv : β → α) (f : ℕ → β) : Prop :=
∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - f i) < ε
namespace is_cau_seq
variables [linear_ordered_field α] [ring β] {abv : β → α} [is_absolute_value abv] {f g : ℕ → β}
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy₂ (hf : is_cau_seq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε :=
begin
refine (hf _ (half_pos ε0)).imp (λ i hi j ij k ik, _),
rw ← add_halves ε,
refine lt_of_le_of_lt (abv_sub_le abv _ _ _) (add_lt_add (hi _ ij) _),
rw abv_sub abv, exact hi _ ik
end
theorem cauchy₃ (hf : is_cau_seq abv f) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε :=
let ⟨i, H⟩ := hf.cauchy₂ ε0 in ⟨i, λ j ij k jk, H _ (le_trans ij jk) _ ij⟩
lemma add (hf : is_cau_seq abv f) (hg : is_cau_seq abv g) : is_cau_seq abv (f + g) :=
λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abv ε0,
⟨i, H⟩ := exists_forall_ge_and (hf.cauchy₃ δ0) (hg.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ le_rfl in Hδ (H₁ _ ij) (H₂ _ ij)⟩
end is_cau_seq
/-- `cau_seq β abv` is the type of `β`-valued Cauchy sequences, with respect to the absolute value
function `abv`. -/
def cau_seq {α : Type*} [linear_ordered_field α]
(β : Type*) [ring β] (abv : β → α) : Type* :=
{f : ℕ → β // is_cau_seq abv f}
namespace cau_seq
variables [linear_ordered_field α]
section ring
variables [ring β] {abv : β → α}
instance : has_coe_to_fun (cau_seq β abv) (λ _, ℕ → β) := ⟨subtype.val⟩
@[simp] theorem mk_to_fun (f) (hf : is_cau_seq abv f) :
@coe_fn (cau_seq β abv) _ _ ⟨f, hf⟩ = f := rfl
theorem ext {f g : cau_seq β abv} (h : ∀ i, f i = g i) : f = g :=
subtype.eq (funext h)
theorem is_cau (f : cau_seq β abv) : is_cau_seq abv f := f.2
theorem cauchy (f : cau_seq β abv) :
∀ {ε}, 0 < ε → ∃ i, ∀ j ≥ i, abv (f j - f i) < ε := f.2
/-- Given a Cauchy sequence `f`, create a Cauchy sequence from a sequence `g` with
the same values as `f`. -/
def of_eq (f : cau_seq β abv) (g : ℕ → β) (e : ∀ i, f i = g i) : cau_seq β abv :=
⟨g, λ ε, by rw [show g = f, from (funext e).symm]; exact f.cauchy⟩
variable [is_absolute_value abv]
@[nolint ge_or_gt] -- see Note [nolint_ge]
theorem cauchy₂ (f : cau_seq β abv) {ε} : 0 < ε →
∃ i, ∀ j k ≥ i, abv (f j - f k) < ε := f.2.cauchy₂
theorem cauchy₃ (f : cau_seq β abv) {ε} : 0 < ε →
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - f j) < ε := f.2.cauchy₃
theorem bounded (f : cau_seq β abv) : ∃ r, ∀ i, abv (f i) < r :=
begin
cases f.cauchy zero_lt_one with i h,
set R : ℕ → α := @nat.rec (λ n, α) (abv (f 0)) (λ i c, max c (abv (f i.succ))) with hR,
have : ∀ i, ∀ j ≤ i, abv (f j) ≤ R i,
{ refine nat.rec (by simp [hR]) _,
rintros i hi j (rfl | hj),
{ simp },
exact (hi j hj).trans (le_max_left _ _) },
refine ⟨R i + 1, λ j, _⟩,
cases lt_or_le j i with ij ij,
{ exact lt_of_le_of_lt (this i _ (le_of_lt ij)) (lt_add_one _) },
{ have := lt_of_le_of_lt (abv_add abv _ _)
(add_lt_add_of_le_of_lt (this i _ le_rfl) (h _ ij)),
rw [add_sub, add_comm] at this, simpa }
end
theorem bounded' (f : cau_seq β abv) (x : α) : ∃ r > x, ∀ i, abv (f i) < r :=
let ⟨r, h⟩ := f.bounded in
⟨max r (x+1), lt_of_lt_of_le (lt_add_one _) (le_max_right _ _),
λ i, lt_of_lt_of_le (h i) (le_max_left _ _)⟩
instance : has_add (cau_seq β abv) := ⟨λ f g, ⟨f + g, f.2.add g.2⟩⟩
@[simp, norm_cast] lemma coe_add (f g : cau_seq β abv) : ⇑(f + g) = f + g := rfl
@[simp, norm_cast] theorem add_apply (f g : cau_seq β abv) (i : ℕ) : (f + g) i = f i + g i := rfl
variable (abv)
/-- The constant Cauchy sequence. -/
def const (x : β) : cau_seq β abv :=
⟨λ i, x, λ ε ε0, ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩⟩
variable {abv}
local notation `const` := const abv
@[simp, norm_cast] lemma coe_const (x : β) : ⇑(const x) = function.const _ x := rfl
@[simp, norm_cast] theorem const_apply (x : β) (i : ℕ) : (const x : ℕ → β) i = x := rfl
theorem const_inj {x y : β} : (const x : cau_seq β abv) = const y ↔ x = y :=
⟨λ h, congr_arg (λ f:cau_seq β abv, (f:ℕ→β) 0) h, congr_arg _⟩
instance : has_zero (cau_seq β abv) := ⟨const 0⟩
instance : has_one (cau_seq β abv) := ⟨const 1⟩
instance : inhabited (cau_seq β abv) := ⟨0⟩
@[simp, norm_cast] lemma coe_zero : ⇑(0 : cau_seq β abv) = 0 := rfl
@[simp, norm_cast] lemma coe_one : ⇑(1 : cau_seq β abv) = 1 := rfl
@[simp, norm_cast] lemma zero_apply (i) : (0 : cau_seq β abv) i = 0 := rfl
@[simp, norm_cast] lemma one_apply (i) : (1 : cau_seq β abv) i = 1 := rfl
@[simp] lemma const_zero : const 0 = 0 := rfl
@[simp] lemma const_one : const 1 = 1 := rfl
theorem const_add (x y : β) : const (x + y) = const x + const y :=
rfl
instance : has_mul (cau_seq β abv) :=
⟨λ f g, ⟨f * g, λ ε ε0,
let ⟨F, F0, hF⟩ := f.bounded' 0, ⟨G, G0, hG⟩ := g.bounded' 0,
⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abv ε0,
⟨i, H⟩ := exists_forall_ge_and (f.cauchy₃ δ0) (g.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨H₁, H₂⟩ := H _ le_rfl in
Hδ (hF j) (hG i) (H₁ _ ij) (H₂ _ ij)⟩⟩⟩
@[simp, norm_cast] lemma coe_mul (f g : cau_seq β abv) : ⇑(f * g) = f * g := rfl
@[simp, norm_cast] theorem mul_apply (f g : cau_seq β abv) (i : ℕ) : (f * g) i = f i * g i := rfl
theorem const_mul (x y : β) : const (x * y) = const x * const y := rfl
instance : has_neg (cau_seq β abv) :=
⟨λ f, of_eq (const (-1) * f) (λ x, -f x) (λ i, by simp)⟩
@[simp, norm_cast] lemma coe_neg (f : cau_seq β abv) : ⇑(-f) = -f := rfl
@[simp, norm_cast] theorem neg_apply (f : cau_seq β abv) (i) : (-f) i = -f i := rfl
theorem const_neg (x : β) : const (-x) = -const x := rfl
instance : has_sub (cau_seq β abv) :=
⟨λ f g, of_eq (f + -g) (λ x, f x - g x) (λ i, by simp [sub_eq_add_neg])⟩
@[simp, norm_cast] lemma coe_sub (f g : cau_seq β abv) : ⇑(f - g) = f - g := rfl
@[simp, norm_cast] theorem sub_apply (f g : cau_seq β abv) (i : ℕ) : (f - g) i = f i - g i := rfl
theorem const_sub (x y : β) : const (x - y) = const x - const y := rfl
section has_smul
variables [has_smul G β] [is_scalar_tower G β β]
instance : has_smul G (cau_seq β abv) :=
⟨λ a f, of_eq (const (a • 1) * f) (a • f) $ λ i, smul_one_mul _ _⟩
@[simp, norm_cast] lemma coe_smul (a : G) (f : cau_seq β abv) : ⇑(a • f) = a • f := rfl
@[simp, norm_cast] lemma smul_apply (a : G) (f : cau_seq β abv) (i : ℕ) : (a • f) i = a • f i := rfl
lemma const_smul (a : G) (x : β) : const (a • x) = a • const x := rfl
end has_smul
instance : add_group (cau_seq β abv) :=
by refine_struct
{ add := (+),
neg := has_neg.neg,
zero := (0 : cau_seq β abv),
sub := has_sub.sub,
zsmul := (•),
nsmul := (•) };
intros; try { refl }; apply ext; simp [add_comm, add_left_comm, sub_eq_add_neg, add_mul]
instance : add_group_with_one (cau_seq β abv) :=
{ one := 1,
nat_cast := λ n, const n,
nat_cast_zero := congr_arg const nat.cast_zero,
nat_cast_succ := λ n, congr_arg const (nat.cast_succ n),
int_cast := λ n, const n,
int_cast_of_nat := λ n, congr_arg const (int.cast_of_nat n),
int_cast_neg_succ_of_nat := λ n, congr_arg const (int.cast_neg_succ_of_nat n),
.. cau_seq.add_group }
instance : has_pow (cau_seq β abv) ℕ :=
⟨λ f n, of_eq (npow_rec n f) (λ i, f i ^ n) $ by induction n; simp [*, npow_rec, pow_succ]⟩
@[simp, norm_cast] lemma coe_pow (f : cau_seq β abv) (n : ℕ) : ⇑(f ^ n) = f ^ n := rfl
@[simp, norm_cast] lemma pow_apply (f : cau_seq β abv) (n i : ℕ) : (f ^ n) i = f i ^ n := rfl
lemma const_pow (x : β) (n : ℕ) : const (x ^ n) = const x ^ n := rfl
instance : ring (cau_seq β abv) :=
by refine_struct
{ add := (+),
zero := (0 : cau_seq β abv),
mul := (*),
one := 1,
npow := λ n f, f ^ n,
.. cau_seq.add_group_with_one };
intros; try { refl }; apply ext;
simp [mul_add, mul_assoc, add_mul, add_comm, add_left_comm, sub_eq_add_neg, pow_succ]
instance {β : Type*} [comm_ring β] {abv : β → α} [is_absolute_value abv] :
comm_ring (cau_seq β abv) :=
{ mul_comm := by intros; apply ext; simp [mul_left_comm, mul_comm],
..cau_seq.ring }
/-- `lim_zero f` holds when `f` approaches 0. -/
def lim_zero {abv : β → α} (f : cau_seq β abv) : Prop := ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j) < ε
theorem add_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f + g)
| ε ε0 := (exists_forall_ge_and
(hf _ $ half_pos ε0) (hg _ $ half_pos ε0)).imp $
λ i H j ij, let ⟨H₁, H₂⟩ := H _ ij in
by simpa [add_halves ε] using lt_of_le_of_lt (abv_add abv _ _) (add_lt_add H₁ H₂)
theorem mul_lim_zero_right (f : cau_seq β abv) {g}
(hg : lim_zero g) : lim_zero (f * g)
| ε ε0 := let ⟨F, F0, hF⟩ := f.bounded' 0 in
(hg _ $ div_pos ε0 F0).imp $ λ i H j ij,
by have := mul_lt_mul' (le_of_lt $ hF j) (H _ ij) (abv_nonneg abv _) F0;
rwa [mul_comm F, div_mul_cancel _ (ne_of_gt F0), ← abv_mul abv] at this
theorem mul_lim_zero_left {f} (g : cau_seq β abv)
(hg : lim_zero f) : lim_zero (f * g)
| ε ε0 := let ⟨G, G0, hG⟩ := g.bounded' 0 in
(hg _ $ div_pos ε0 G0).imp $ λ i H j ij,
by have := mul_lt_mul'' (H _ ij) (hG j) (abv_nonneg abv _) (abv_nonneg abv _);
rwa [div_mul_cancel _ (ne_of_gt G0), ← abv_mul abv] at this
theorem neg_lim_zero {f : cau_seq β abv} (hf : lim_zero f) : lim_zero (-f) :=
by rw ← neg_one_mul; exact mul_lim_zero_right _ hf
theorem sub_lim_zero {f g : cau_seq β abv}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f - g) :=
by simpa only [sub_eq_add_neg] using add_lim_zero hf (neg_lim_zero hg)
theorem lim_zero_sub_rev {f g : cau_seq β abv} (hfg : lim_zero (f - g)) : lim_zero (g - f) :=
by simpa using neg_lim_zero hfg
theorem zero_lim_zero : lim_zero (0 : cau_seq β abv)
| ε ε0 := ⟨0, λ j ij, by simpa [abv_zero abv] using ε0⟩
theorem const_lim_zero {x : β} : lim_zero (const x) ↔ x = 0 :=
⟨λ H, (abv_eq_zero abv).1 $
eq_of_le_of_forall_le_of_dense (abv_nonneg abv _) $
λ ε ε0, let ⟨i, hi⟩ := H _ ε0 in le_of_lt $ hi _ le_rfl,
λ e, e.symm ▸ zero_lim_zero⟩
instance equiv : setoid (cau_seq β abv) :=
⟨λ f g, lim_zero (f - g),
⟨λ f, by simp [zero_lim_zero],
λ f g h, by simpa using neg_lim_zero h,
λ f g h fg gh, by simpa [sub_eq_add_neg, add_assoc] using add_lim_zero fg gh⟩⟩
lemma add_equiv_add {f1 f2 g1 g2 : cau_seq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 + g1 ≈ f2 + g2 :=
by simpa only [←add_sub_add_comm] using add_lim_zero hf hg
lemma neg_equiv_neg {f g : cau_seq β abv} (hf : f ≈ g) : -f ≈ -g :=
by simpa only [neg_sub'] using neg_lim_zero hf
lemma sub_equiv_sub {f1 f2 g1 g2 : cau_seq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 - g1 ≈ f2 - g2 :=
by simpa only [sub_eq_add_neg] using add_equiv_add hf (neg_equiv_neg hg)
theorem equiv_def₃ {f g : cau_seq β abv} (h : f ≈ g) {ε : α} (ε0 : 0 < ε) :
∃ i, ∀ j ≥ i, ∀ k ≥ j, abv (f k - g j) < ε :=
(exists_forall_ge_and (h _ $ half_pos ε0) (f.cauchy₃ $ half_pos ε0)).imp $
λ i H j ij k jk, let ⟨h₁, h₂⟩ := H _ ij in
by have := lt_of_le_of_lt (abv_add abv (f j - g j) _) (add_lt_add h₁ (h₂ _ jk));
rwa [sub_add_sub_cancel', add_halves] at this
theorem lim_zero_congr {f g : cau_seq β abv} (h : f ≈ g) : lim_zero f ↔ lim_zero g :=
⟨λ l, by simpa using add_lim_zero (setoid.symm h) l,
λ l, by simpa using add_lim_zero h l⟩
theorem abv_pos_of_not_lim_zero {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ abv (f j) :=
begin
haveI := classical.prop_decidable,
by_contra nk,
refine hf (λ ε ε0, _),
simp [not_forall] at nk,
cases f.cauchy₃ (half_pos ε0) with i hi,
rcases nk _ (half_pos ε0) i with ⟨j, ij, hj⟩,
refine ⟨j, λ k jk, _⟩,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi j ij k jk) hj),
rwa [sub_add_cancel, add_halves] at this
end
theorem of_near (f : ℕ → β) (g : cau_seq β abv)
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abv (f j - g j) < ε) : is_cau_seq abv f
| ε ε0 :=
let ⟨i, hi⟩ := exists_forall_ge_and
(h _ (half_pos $ half_pos ε0)) (g.cauchy₃ $ half_pos ε0) in
⟨i, λ j ij, begin
cases hi _ le_rfl with h₁ h₂, rw abv_sub abv at h₁,
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add (hi _ ij).1 h₁),
have := lt_of_le_of_lt (abv_add abv _ _) (add_lt_add this (h₂ _ ij)),
rwa [add_halves, add_halves, add_right_comm,
sub_add_sub_cancel, sub_add_sub_cancel] at this
end⟩
lemma not_lim_zero_of_not_congr_zero {f : cau_seq _ abv} (hf : ¬ f ≈ 0) : ¬ lim_zero f :=
assume : lim_zero f,
have lim_zero (f - 0), by simpa,
hf this
lemma mul_equiv_zero (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : g * f ≈ 0 :=
have lim_zero (f - 0), from hf,
have lim_zero (g*f), from mul_lim_zero_right _ $ by simpa,
show lim_zero (g*f - 0), by simpa
lemma mul_equiv_zero' (g : cau_seq _ abv) {f : cau_seq _ abv} (hf : f ≈ 0) : f * g ≈ 0 :=
have lim_zero (f - 0), from hf,
have lim_zero (f*g), from mul_lim_zero_left _ $ by simpa,
show lim_zero (f*g - 0), by simpa
lemma mul_not_equiv_zero {f g : cau_seq _ abv} (hf : ¬ f ≈ 0) (hg : ¬ g ≈ 0) : ¬ (f * g) ≈ 0 :=
assume : lim_zero (f*g - 0),
have hlz : lim_zero (f*g), by simpa,
have hf' : ¬ lim_zero f, by simpa using (show ¬ lim_zero (f - 0), from hf),
have hg' : ¬ lim_zero g, by simpa using (show ¬ lim_zero (g - 0), from hg),
begin
rcases abv_pos_of_not_lim_zero hf' with ⟨a1, ha1, N1, hN1⟩,
rcases abv_pos_of_not_lim_zero hg' with ⟨a2, ha2, N2, hN2⟩,
have : 0 < a1 * a2, from mul_pos ha1 ha2,
cases hlz _ this with N hN,
let i := max N (max N1 N2),
have hN' := hN i (le_max_left _ _),
have hN1' := hN1 i (le_trans (le_max_left _ _) (le_max_right _ _)),
have hN1' := hN2 i (le_trans (le_max_right _ _) (le_max_right _ _)),
apply not_le_of_lt hN',
change _ ≤ abv (_ * _),
rw is_absolute_value.abv_mul abv,
apply mul_le_mul; try { assumption },
{ apply le_of_lt ha2 },
{ apply is_absolute_value.abv_nonneg abv }
end
theorem const_equiv {x y : β} : const x ≈ const y ↔ x = y :=
show lim_zero _ ↔ _, by rw [← const_sub, const_lim_zero, sub_eq_zero]
lemma mul_equiv_mul {f1 f2 g1 g2 : cau_seq β abv} (hf : f1 ≈ f2) (hg : g1 ≈ g2) :
f1 * g1 ≈ f2 * g2 :=
by simpa only [mul_sub, sub_mul, sub_add_sub_cancel]
using add_lim_zero (mul_lim_zero_left g1 hf) (mul_lim_zero_right f2 hg)
end ring
section is_domain
variables [ring β] [is_domain β] (abv : β → α) [is_absolute_value abv]
lemma one_not_equiv_zero : ¬ (const abv 1) ≈ (const abv 0) :=
assume h,
have ∀ ε > 0, ∃ i, ∀ k, i ≤ k → abv (1 - 0) < ε, from h,
have h1 : abv 1 ≤ 0, from le_of_not_gt $
assume h2 : 0 < abv 1,
exists.elim (this _ h2) $ λ i hi,
lt_irrefl (abv 1) $ by simpa using hi _ le_rfl,
have h2 : 0 ≤ abv 1, from is_absolute_value.abv_nonneg _ _,
have abv 1 = 0, from le_antisymm h1 h2,
have (1 : β) = 0, from (is_absolute_value.abv_eq_zero abv).1 this,
absurd this one_ne_zero
end is_domain
section division_ring
variables [division_ring β] {abv : β → α} [is_absolute_value abv]
theorem inv_aux {f : cau_seq β abv} (hf : ¬ lim_zero f) :
∀ ε > 0, ∃ i, ∀ j ≥ i, abv ((f j)⁻¹ - (f i)⁻¹) < ε | ε ε0 :=
let ⟨K, K0, HK⟩ := abv_pos_of_not_lim_zero hf,
⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abv ε0 K0,
⟨i, H⟩ := exists_forall_ge_and HK (f.cauchy₃ δ0) in
⟨i, λ j ij, let ⟨iK, H'⟩ := H _ le_rfl in Hδ (H _ ij).1 iK (H' _ ij)⟩
/-- Given a Cauchy sequence `f` with nonzero limit, create a Cauchy sequence with values equal to
the inverses of the values of `f`. -/
def inv (f : cau_seq β abv) (hf : ¬ lim_zero f) : cau_seq β abv := ⟨_, inv_aux hf⟩
@[simp, norm_cast] lemma coe_inv {f : cau_seq β abv} (hf) : ⇑(inv f hf) = f⁻¹ := rfl
@[simp, norm_cast] theorem inv_apply {f : cau_seq β abv} (hf i) : inv f hf i = (f i)⁻¹ := rfl
theorem inv_mul_cancel {f : cau_seq β abv} (hf) : inv f hf * f ≈ 1 :=
λ ε ε0, let ⟨K, K0, i, H⟩ := abv_pos_of_not_lim_zero hf in
⟨i, λ j ij,
by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)),
abv_zero abv] using ε0⟩
theorem mul_inv_cancel {f : cau_seq β abv} (hf) : f * inv f hf ≈ 1 :=
λ ε ε0, let ⟨K, K0, i, H⟩ := abv_pos_of_not_lim_zero hf in
⟨i, λ j ij,
by simpa [(abv_pos abv).1 (lt_of_lt_of_le K0 (H _ ij)),
abv_zero abv] using ε0⟩
theorem const_inv {x : β} (hx : x ≠ 0) :
const abv (x⁻¹) = inv (const abv x) (by rwa const_lim_zero) := rfl
end division_ring
section abs
local notation `const` := const abs
/-- The entries of a positive Cauchy sequence eventually have a positive lower bound. -/
def pos (f : cau_seq α abs) : Prop := ∃ K > 0, ∃ i, ∀ j ≥ i, K ≤ f j
theorem not_lim_zero_of_pos {f : cau_seq α abs} : pos f → ¬ lim_zero f
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ F0),
⟨h₁, h₂⟩ := h _ le_rfl in
not_lt_of_le h₁ (abs_lt.1 h₂).2
theorem const_pos {x : α} : pos (const x) ↔ 0 < x :=
⟨λ ⟨K, K0, i, h⟩, lt_of_lt_of_le K0 (h _ le_rfl),
λ h, ⟨x, h, 0, λ j _, le_rfl⟩⟩
theorem add_pos {f g : cau_seq α abs} : pos f → pos g → pos (f + g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.add_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in add_le_add h₁ h₂⟩
theorem pos_add_lim_zero {f g : cau_seq α abs} : pos f → lim_zero g → pos (f + g)
| ⟨F, F0, hF⟩ H :=
let ⟨i, h⟩ := exists_forall_ge_and hF (H _ (half_pos F0)) in
⟨_, half_pos F0, i, λ j ij, begin
cases h j ij with h₁ h₂,
have := add_le_add h₁ (le_of_lt (abs_lt.1 h₂).1),
rwa [← sub_eq_add_neg, sub_self_div_two] at this
end⟩
protected theorem mul_pos {f g : cau_seq α abs} : pos f → pos g → pos (f * g)
| ⟨F, F0, hF⟩ ⟨G, G0, hG⟩ :=
let ⟨i, h⟩ := exists_forall_ge_and hF hG in
⟨_, _root_.mul_pos F0 G0, i,
λ j ij, let ⟨h₁, h₂⟩ := h _ ij in
mul_le_mul h₁ h₂ (le_of_lt G0) (le_trans (le_of_lt F0) h₁)⟩
theorem trichotomy (f : cau_seq α abs) : pos f ∨ lim_zero f ∨ pos (-f) :=
begin
cases classical.em (lim_zero f); simp *,
rcases abv_pos_of_not_lim_zero h with ⟨K, K0, hK⟩,
rcases exists_forall_ge_and hK (f.cauchy₃ K0) with ⟨i, hi⟩,
refine (le_total 0 (f i)).imp _ _;
refine (λ h, ⟨K, K0, i, λ j ij, _⟩);
have := (hi _ ij).1;
cases hi _ le_rfl with h₁ h₂,
{ rwa abs_of_nonneg at this,
rw abs_of_nonneg h at h₁,
exact (le_add_iff_nonneg_right _).1
(le_trans h₁ $ neg_le_sub_iff_le_add'.1 $
le_of_lt (abs_lt.1 $ h₂ _ ij).1) },
{ rwa abs_of_nonpos at this,
rw abs_of_nonpos h at h₁,
rw [← sub_le_sub_iff_right, zero_sub],
exact le_trans (le_of_lt (abs_lt.1 $ h₂ _ ij).2) h₁ }
end
instance : has_lt (cau_seq α abs) := ⟨λ f g, pos (g - f)⟩
instance : has_le (cau_seq α abs) := ⟨λ f g, f < g ∨ f ≈ g⟩
theorem lt_of_lt_of_eq {f g h : cau_seq α abs}
(fg : f < g) (gh : g ≈ h) : f < h :=
show pos (h - f),
by simpa [sub_eq_add_neg, add_comm, add_left_comm] using pos_add_lim_zero fg (neg_lim_zero gh)
theorem lt_of_eq_of_lt {f g h : cau_seq α abs}
(fg : f ≈ g) (gh : g < h) : f < h :=
by have := pos_add_lim_zero gh (neg_lim_zero fg);
rwa [← sub_eq_add_neg, sub_sub_sub_cancel_right] at this
theorem lt_trans {f g h : cau_seq α abs} (fg : f < g) (gh : g < h) : f < h :=
show pos (h - f),
by simpa [sub_eq_add_neg, add_comm, add_left_comm] using add_pos fg gh
theorem lt_irrefl {f : cau_seq α abs} : ¬ f < f
| h := not_lim_zero_of_pos h (by simp [zero_lim_zero])
lemma le_of_eq_of_le {f g h : cau_seq α abs}
(hfg : f ≈ g) (hgh : g ≤ h) : f ≤ h :=
hgh.elim (or.inl ∘ cau_seq.lt_of_eq_of_lt hfg)
(or.inr ∘ setoid.trans hfg)
lemma le_of_le_of_eq {f g h : cau_seq α abs}
(hfg : f ≤ g) (hgh : g ≈ h) : f ≤ h :=
hfg.elim (λ h, or.inl (cau_seq.lt_of_lt_of_eq h hgh))
(λ h, or.inr (setoid.trans h hgh))
instance : preorder (cau_seq α abs) :=
{ lt := (<),
le := λ f g, f < g ∨ f ≈ g,
le_refl := λ f, or.inr (setoid.refl _),
le_trans := λ f g h fg, match fg with
| or.inl fg, or.inl gh := or.inl $ lt_trans fg gh
| or.inl fg, or.inr gh := or.inl $ lt_of_lt_of_eq fg gh
| or.inr fg, or.inl gh := or.inl $ lt_of_eq_of_lt fg gh
| or.inr fg, or.inr gh := or.inr $ setoid.trans fg gh
end,
lt_iff_le_not_le := λ f g,
⟨λ h, ⟨or.inl h,
not_or (mt (lt_trans h) lt_irrefl) (not_lim_zero_of_pos h)⟩,
λ ⟨h₁, h₂⟩, h₁.resolve_right
(mt (λ h, or.inr (setoid.symm h)) h₂)⟩ }
theorem le_antisymm {f g : cau_seq α abs} (fg : f ≤ g) (gf : g ≤ f) : f ≈ g :=
fg.resolve_left (not_lt_of_le gf)
theorem lt_total (f g : cau_seq α abs) : f < g ∨ f ≈ g ∨ g < f :=
(trichotomy (g - f)).imp_right
(λ h, h.imp (λ h, setoid.symm h) (λ h, by rwa neg_sub at h))
theorem le_total (f g : cau_seq α abs) : f ≤ g ∨ g ≤ f :=
(or.assoc.2 (lt_total f g)).imp_right or.inl
theorem const_lt {x y : α} : const x < const y ↔ x < y :=
show pos _ ↔ _, by rw [← const_sub, const_pos, sub_pos]
theorem const_le {x y : α} : const x ≤ const y ↔ x ≤ y :=
by rw le_iff_lt_or_eq; exact or_congr const_lt const_equiv
lemma le_of_exists {f g : cau_seq α abs}
(h : ∃ i, ∀ j ≥ i, f j ≤ g j) : f ≤ g :=
let ⟨i, hi⟩ := h in
(or.assoc.2 (cau_seq.lt_total f g)).elim
id
(λ hgf, false.elim (let ⟨K, hK0, j, hKj⟩ := hgf in
not_lt_of_ge (hi (max i j) (le_max_left _ _))
(sub_pos.1 (lt_of_lt_of_le hK0 (hKj _ (le_max_right _ _))))))
theorem exists_gt (f : cau_seq α abs) : ∃ a : α, f < const a :=
let ⟨K, H⟩ := f.bounded in
⟨K + 1, 1, zero_lt_one, 0, λ i _, begin
rw [sub_apply, const_apply, le_sub_iff_add_le', add_le_add_iff_right],
exact le_of_lt (abs_lt.1 (H _)).2
end⟩
theorem exists_lt (f : cau_seq α abs) : ∃ a : α, const a < f :=
let ⟨a, h⟩ := (-f).exists_gt in ⟨-a, show pos _,
by rwa [const_neg, sub_neg_eq_add, add_comm, ← sub_neg_eq_add]⟩
-- so named to match `rat_add_continuous_lemma`
theorem _root_.rat_sup_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊔ a₂ - (b₁ ⊔ b₂)) < ε :=
λ h₁ h₂, (abs_max_sub_max_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
-- so named to match `rat_add_continuous_lemma`
theorem _root_.rat_inf_continuous_lemma {ε : α} {a₁ a₂ b₁ b₂ : α} :
abs (a₁ - b₁) < ε → abs (a₂ - b₂) < ε → abs (a₁ ⊓ a₂ - (b₁ ⊓ b₂)) < ε :=
λ h₁ h₂, (abs_min_sub_min_le_max _ _ _ _).trans_lt (max_lt h₁ h₂)
instance : has_sup (cau_seq α abs) :=
⟨λ f g, ⟨f ⊔ g, λ ε ε0,
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp $ λ i H j ij,
let ⟨H₁, H₂⟩ := H _ le_rfl in rat_sup_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
instance : has_inf (cau_seq α abs) :=
⟨λ f g, ⟨f ⊓ g, λ ε ε0,
(exists_forall_ge_and (f.cauchy₃ ε0) (g.cauchy₃ ε0)).imp $ λ i H j ij,
let ⟨H₁, H₂⟩ := H _ le_rfl in rat_inf_continuous_lemma (H₁ _ ij) (H₂ _ ij)⟩⟩
@[simp, norm_cast] lemma coe_sup (f g : cau_seq α abs) : ⇑(f ⊔ g) = f ⊔ g := rfl
@[simp, norm_cast] lemma coe_inf (f g : cau_seq α abs) : ⇑(f ⊓ g) = f ⊓ g := rfl
theorem sup_lim_zero {f g : cau_seq α abs}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f ⊔ g)
| ε ε0 := (exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp $
λ i H j ij, let ⟨H₁, H₂⟩ := H _ ij in begin
rw abs_lt at H₁ H₂ ⊢,
exact ⟨lt_sup_iff.mpr (or.inl H₁.1), sup_lt_iff.mpr ⟨H₁.2, H₂.2⟩⟩
end
theorem inf_lim_zero {f g : cau_seq α abs}
(hf : lim_zero f) (hg : lim_zero g) : lim_zero (f ⊓ g)
| ε ε0 := (exists_forall_ge_and (hf _ ε0) (hg _ ε0)).imp $
λ i H j ij, let ⟨H₁, H₂⟩ := H _ ij in begin
rw abs_lt at H₁ H₂ ⊢,
exact ⟨lt_inf_iff.mpr ⟨H₁.1, H₂.1⟩, inf_lt_iff.mpr (or.inl H₁.2), ⟩
end
lemma sup_equiv_sup {a₁ b₁ a₂ b₂ : cau_seq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊔ b₁ ≈ a₂ ⊔ b₂ :=
begin
intros ε ε0,
obtain ⟨ai, hai⟩ := ha ε ε0,
obtain ⟨bi, hbi⟩ := hb ε ε0,
exact ⟨ai ⊔ bi, λ i hi,
(abs_max_sub_max_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩,
end
lemma inf_equiv_inf {a₁ b₁ a₂ b₂ : cau_seq α abs} (ha : a₁ ≈ a₂) (hb : b₁ ≈ b₂) :
a₁ ⊓ b₁ ≈ a₂ ⊓ b₂ :=
begin
intros ε ε0,
obtain ⟨ai, hai⟩ := ha ε ε0,
obtain ⟨bi, hbi⟩ := hb ε ε0,
exact ⟨ai ⊔ bi, λ i hi,
(abs_min_sub_min_le_max (a₁ i) (b₁ i) (a₂ i) (b₂ i)).trans_lt
(max_lt (hai i (sup_le_iff.mp hi).1) (hbi i (sup_le_iff.mp hi).2))⟩,
end
protected lemma sup_lt {a b c : cau_seq α abs} (ha : a < c) (hb : b < c) : a ⊔ b < c :=
begin
obtain ⟨⟨εa, εa0, ia, ha⟩, ⟨εb, εb0, ib, hb⟩⟩ := ⟨ha, hb⟩,
refine ⟨εa ⊓ εb, lt_inf_iff.mpr ⟨εa0, εb0⟩, ia ⊔ ib, λ i hi, _⟩,
have := min_le_min (ha _ (sup_le_iff.mp hi).1) (hb _ (sup_le_iff.mp hi).2),
exact this.trans_eq (min_sub_sub_left _ _ _)
end
protected lemma lt_inf {a b c : cau_seq α abs} (hb : a < b) (hc : a < c) : a < b ⊓ c :=
begin
obtain ⟨⟨εb, εb0, ib, hb⟩, ⟨εc, εc0, ic, hc⟩⟩ := ⟨hb, hc⟩,
refine ⟨εb ⊓ εc, lt_inf_iff.mpr ⟨εb0, εc0⟩, ib ⊔ ic, λ i hi, _⟩,
have := min_le_min (hb _ (sup_le_iff.mp hi).1) (hc _ (sup_le_iff.mp hi).2),
exact this.trans_eq (min_sub_sub_right _ _ _),
end
@[simp] protected lemma sup_idem (a : cau_seq α abs) : a ⊔ a = a := subtype.ext sup_idem
@[simp] protected lemma inf_idem (a : cau_seq α abs) : a ⊓ a = a := subtype.ext inf_idem
protected lemma sup_comm (a b : cau_seq α abs) : a ⊔ b = b ⊔ a := subtype.ext sup_comm
protected lemma inf_comm (a b : cau_seq α abs) : a ⊓ b = b ⊓ a := subtype.ext inf_comm
protected lemma sup_eq_right {a b : cau_seq α abs} (h : a ≤ b) :
a ⊔ b ≈ b :=
begin
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h,
{ intros _ _,
refine ⟨i, λ j hj, _⟩,
dsimp,
erw ←max_sub_sub_right,
rwa [sub_self, max_eq_right, abs_zero],
rw [sub_nonpos, ←sub_nonneg],
exact ε0.le.trans (h _ hj) },
{ refine setoid.trans (sup_equiv_sup h (setoid.refl _)) _,
rw cau_seq.sup_idem,
exact setoid.refl _ },
end
protected lemma inf_eq_right {a b : cau_seq α abs} (h : b ≤ a) :
a ⊓ b ≈ b :=
begin
obtain ⟨ε, ε0 : _ < _, i, h⟩ | h := h,
{ intros _ _,
refine ⟨i, λ j hj, _⟩,
dsimp,
erw ←min_sub_sub_right,
rwa [sub_self, min_eq_right, abs_zero],
exact ε0.le.trans (h _ hj) },
{ refine setoid.trans (inf_equiv_inf (setoid.symm h) (setoid.refl _)) _,
rw cau_seq.inf_idem,
exact setoid.refl _ },
end
protected lemma sup_eq_left {a b : cau_seq α abs} (h : b ≤ a) :
a ⊔ b ≈ a :=
by simpa only [cau_seq.sup_comm] using cau_seq.sup_eq_right h
protected lemma inf_eq_left {a b : cau_seq α abs} (h : a ≤ b) :
a ⊓ b ≈ a :=
by simpa only [cau_seq.inf_comm] using cau_seq.inf_eq_right h
protected lemma le_sup_left {a b : cau_seq α abs} : a ≤ a ⊔ b :=
le_of_exists ⟨0, λ j hj, le_sup_left⟩
protected lemma inf_le_left {a b : cau_seq α abs} : a ⊓ b ≤ a :=
le_of_exists ⟨0, λ j hj, inf_le_left⟩
protected lemma le_sup_right {a b : cau_seq α abs} : b ≤ a ⊔ b :=
le_of_exists ⟨0, λ j hj, le_sup_right⟩
protected lemma inf_le_right {a b : cau_seq α abs} : a ⊓ b ≤ b :=
le_of_exists ⟨0, λ j hj, inf_le_right⟩
protected lemma sup_le {a b c : cau_seq α abs} (ha : a ≤ c) (hb : b ≤ c) : a ⊔ b ≤ c :=
begin
cases ha with ha ha,
{ cases hb with hb hb,
{ exact or.inl (cau_seq.sup_lt ha hb) },
{ replace ha := le_of_le_of_eq ha.le (setoid.symm hb),
refine le_of_le_of_eq (or.inr _) hb,
exact cau_seq.sup_eq_right ha }, },
{ replace hb := le_of_le_of_eq hb (setoid.symm ha),
refine le_of_le_of_eq (or.inr _) ha,
exact cau_seq.sup_eq_left hb }
end
protected lemma le_inf {a b c : cau_seq α abs} (hb : a ≤ b) (hc : a ≤ c) : a ≤ b ⊓ c :=
begin
cases hb with hb hb,
{ cases hc with hc hc,
{ exact or.inl (cau_seq.lt_inf hb hc) },
{ replace hb := le_of_eq_of_le (setoid.symm hc) hb.le,
refine le_of_eq_of_le hc (or.inr _),
exact setoid.symm (cau_seq.inf_eq_right hb) }, },
{ replace hc := le_of_eq_of_le (setoid.symm hb) hc,
refine le_of_eq_of_le hb (or.inr _),
exact setoid.symm (cau_seq.inf_eq_left hc) }
end
/-! Note that `distrib_lattice (cau_seq α abs)` is not true because there is no `partial_order`. -/
protected lemma sup_inf_distrib_left (a b c : cau_seq α abs) : a ⊔ (b ⊓ c) = (a ⊔ b) ⊓ (a ⊔ c) :=
subtype.ext $ funext $ λ i, max_min_distrib_left
protected lemma sup_inf_distrib_right (a b c : cau_seq α abs) : (a ⊓ b) ⊔ c = (a ⊔ c) ⊓ (b ⊔ c) :=
subtype.ext $ funext $ λ i, max_min_distrib_right
end abs
end cau_seq
|
a7a7c69b06e95ac16ff7c7a07b948ab977423794
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/Lean3Lib/init/data/nat/div.lean
|
63d1f1f7061ab2548a8bef4db85e9ee671e51683
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,005
|
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.wf
import Mathlib.Lean3Lib.init.data.nat.basic
namespace Mathlib
namespace nat
protected def div (x : ℕ) : ℕ → ℕ :=
well_founded.fix lt_wf div.F
protected instance has_div : Div ℕ :=
{ div := nat.div }
theorem div_def_aux (x : ℕ) (y : ℕ) : x / y = dite (0 < y ∧ y ≤ x) (fun (h : 0 < y ∧ y ≤ x) => (x - y) / y + 1) fun (h : ¬(0 < y ∧ y ≤ x)) => 0 :=
congr_fun (well_founded.fix_eq lt_wf div.F x) y
protected def mod (x : ℕ) : ℕ → ℕ :=
well_founded.fix lt_wf mod.F
protected instance has_mod : Mod ℕ :=
{ mod := nat.mod }
theorem mod_def_aux (x : ℕ) (y : ℕ) : x % y = dite (0 < y ∧ y ≤ x) (fun (h : 0 < y ∧ y ≤ x) => (x - y) % y) fun (h : ¬(0 < y ∧ y ≤ x)) => x :=
congr_fun (well_founded.fix_eq lt_wf mod.F x) y
|
105d49eefdeca86483ea87eb6c3480d175c35a17
|
8cb37a089cdb4af3af9d8bf1002b417e407a8e9e
|
/tests/lean/run/tc_cache2.lean
|
9f6e266da43f6469dd043970a590a5ecd7d6f03c
|
[
"Apache-2.0"
] |
permissive
|
kbuzzard/lean
|
ae3c3db4bb462d750dbf7419b28bafb3ec983ef7
|
ed1788fd674bb8991acffc8fca585ec746711928
|
refs/heads/master
| 1,620,983,366,617
| 1,618,937,600,000
| 1,618,937,600,000
| 359,886,396
| 1
| 0
|
Apache-2.0
| 1,618,936,987,000
| 1,618,936,987,000
| null |
UTF-8
|
Lean
| false
| false
| 841
|
lean
|
class succeeds_w_cache (α : Type) := (a : α)
class fails_quickly_w_cache (α : Type) extends succeeds_w_cache α
class loops_wo_cache (α : Type) := (a : α)
class has_no_inst (α : Type)
instance loops_wo_cache.loop {α} [loops_wo_cache α] [inhabited α] :
loops_wo_cache α :=
‹loops_wo_cache α›
instance inhabited.to_loops_wo_cache {α} [inhabited α] : loops_wo_cache α :=
{a := default _}
instance loops_wo_cache.to_fails_quickly_w_cache {α} [has_no_inst α] [loops_wo_cache α] :
fails_quickly_w_cache α :=
{a := loops_wo_cache.a}
@[priority 1] instance inhabited.to_succeeds_w_cache {α} [inhabited α] :
succeeds_w_cache α :=
{a := default _}
#check (by apply_instance : succeeds_w_cache ℕ)
open tactic
#eval do
x ← to_expr ``(succeeds_w_cache.a),
infer_type x >>= unify `(nat),
unify `(nat.zero) x
|
8b5277c2b4389321806b3eb3761c8710ceb536c7
|
5ae26df177f810c5006841e9c73dc56e01b978d7
|
/src/topology/metric_space/lipschitz.lean
|
5b62a0720bfda1ef7ec5d6679d99ba98e927a59d
|
[
"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
| 5,507
|
lean
|
/-
Copyright (c) 2018 Rohan Mitta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rohan Mitta, Kevin Buzzard, Alistair Tucker, Johannes Hölzl
Lipschitz functions and the Banach fixed-point theorem
-/
import topology.metric_space.basic analysis.specific_limits
open filter
variables {α : Type*} {β : Type*} {γ : Type*}
lemma fixed_point_of_tendsto_iterate [topological_space α] [t2_space α] {f : α → α} {x : α}
(hf : tendsto f (nhds x) (nhds (f x))) (hx : ∃ x₀ : α, tendsto (λ n, f^[n] x₀) at_top (nhds x)) :
f x = x :=
begin
rcases hx with ⟨x₀, hx⟩,
refine tendsto_nhds_unique at_top_ne_bot _ hx,
rw [← tendsto_add_at_top_iff_nat 1, funext (assume n, nat.iterate_succ' f n x₀)],
exact hf.comp hx
end
/-- A Lipschitz function is uniformly continuous -/
lemma uniform_continuous_of_lipschitz [metric_space α] [metric_space β] {K : ℝ}
{f : α → β} (H : ∀x y, dist (f x) (f y) ≤ K * dist x y) : uniform_continuous f :=
begin
have : 0 < max K 1 := lt_of_lt_of_le zero_lt_one (le_max_right K 1),
refine metric.uniform_continuous_iff.2 (λε εpos, _),
exact ⟨ε/max K 1, div_pos εpos this, assume y x Dyx, calc
dist (f y) (f x) ≤ K * dist y x : H y x
... ≤ max K 1 * dist y x : mul_le_mul_of_nonneg_right (le_max_left K 1) (dist_nonneg)
... < max K 1 * (ε/max K 1) : mul_lt_mul_of_pos_left Dyx this
... = ε : mul_div_cancel' _ (ne_of_gt this)⟩
end
/-- A Lipschitz function is continuous -/
lemma continuous_of_lipschitz [metric_space α] [metric_space β] {K : ℝ}
{f : α → β} (H : ∀x y, dist (f x) (f y) ≤ K * dist x y) : continuous f :=
uniform_continuous.continuous (uniform_continuous_of_lipschitz H)
lemma uniform_continuous_of_le_add [metric_space α] {f : α → ℝ} (K : ℝ)
(h : ∀x y, f x ≤ f y + K * dist x y) : uniform_continuous f :=
begin
have I : ∀ (x y : α), f x - f y ≤ K * dist x y := λx y, calc
f x - f y ≤ (f y + K * dist x y) - f y : add_le_add (h x y) (le_refl _)
... = K * dist x y : by ring,
refine @uniform_continuous_of_lipschitz _ _ _ _ K _ (λx y, _),
rw real.dist_eq,
refine abs_sub_le_iff.2 ⟨_, _⟩,
{ exact I x y },
{ rw dist_comm, exact I y x }
end
/-- `lipschitz_with K f`: the function `f` is Lipschitz continuous w.r.t. the Lipschitz
constant `K`. -/
def lipschitz_with [metric_space α] [metric_space β] (K : ℝ) (f : α → β) :=
0 ≤ K ∧ ∀x y, dist (f x) (f y) ≤ K * dist x y
namespace lipschitz_with
variables [metric_space α] [metric_space β] [metric_space γ] {K : ℝ}
protected lemma weaken (K' : ℝ) {f : α → β} (hf : lipschitz_with K f) (h : K ≤ K') :
lipschitz_with K' f :=
⟨le_trans hf.1 h, assume x y, le_trans (hf.2 x y) $ mul_le_mul_of_nonneg_right h dist_nonneg⟩
protected lemma to_uniform_continuous {f : α → β} (hf : lipschitz_with K f) : uniform_continuous f :=
uniform_continuous_of_lipschitz hf.2
protected lemma to_continuous {f : α → β} (hf : lipschitz_with K f) : continuous f :=
continuous_of_lipschitz hf.2
protected lemma const (b : β) : lipschitz_with 0 (λa:α, b) :=
⟨le_refl 0, assume x y, by simp⟩
protected lemma id : lipschitz_with 1 (@id α) :=
⟨zero_le_one, by simp [le_refl]⟩
protected lemma comp {Kf Kg : ℝ} {f : β → γ} {g : α → β}
(hf : lipschitz_with Kf f) (hg : lipschitz_with Kg g) : lipschitz_with (Kf * Kg) (f ∘ g) :=
⟨mul_nonneg hf.1 hg.1, assume x y,
calc dist (f (g x)) (f (g y)) ≤ Kf * dist (g x) (g y) : hf.2 _ _
... ≤ Kf * (Kg * dist x y) : mul_le_mul_of_nonneg_left (hg.2 _ _) hf.1
... = (Kf * Kg) * dist x y : by rw mul_assoc⟩
protected lemma iterate {f : α → α} (hf : lipschitz_with K f) : ∀n, lipschitz_with (K ^ n) (f^[n])
| 0 := lipschitz_with.id
| (n + 1) := by rw [← nat.succ_eq_add_one, pow_succ, mul_comm]; exact (iterate n).comp hf
section contraction
variables {f : α → α} {x y : α}
lemma dist_inequality_of_contraction (hK₁ : K < 1) (hf : lipschitz_with K f) :
dist x y ≤ (dist x (f x) + dist y (f y)) / (1 - K) :=
suffices dist x y ≤ dist x (f x) + (dist y (f y) + K * dist x y),
by rwa [le_div_iff (sub_pos_of_lt hK₁), mul_comm, sub_mul, one_mul, sub_le_iff_le_add, add_assoc],
calc dist x y ≤ dist x (f x) + dist y (f x) :
dist_triangle_right x y (f x)
... ≤ dist x (f x) + (dist y (f y) + dist (f x) (f y)) :
add_le_add_left (dist_triangle_right y (f x) (f y)) _
... ≤ dist x (f x) + (dist y (f y) + K * dist x y) :
add_le_add_left (add_le_add_left (hf.2 _ _) _) _
theorem fixed_point_unique_of_contraction (hK : K < 1) (hf : lipschitz_with K f)
(hx : f x = x) (hy : f y = y) : x = y :=
dist_le_zero.1 $ le_trans (dist_inequality_of_contraction hK hf) $
by rewrite [iff.mpr dist_eq_zero hx.symm, iff.mpr dist_eq_zero hy.symm]; simp
/-- Banach fixed-point theorem, contraction mapping theorem -/
theorem exists_fixed_point_of_contraction [hα : nonempty α] [complete_space α]
(hK : K < 1) (hf : lipschitz_with K f) : ∃x, f x = x :=
let ⟨x₀⟩ := hα in
have cauchy_seq (λ n, f^[n] x₀) := begin
refine cauchy_seq_of_le_geometric K (dist x₀ (f x₀)) hK (λn, _),
rw [nat.iterate_succ f n x₀, mul_comm],
exact and.right (hf.iterate n) x₀ (f x₀)
end,
let ⟨x, hx⟩ := cauchy_seq_tendsto_of_complete this in
⟨x, fixed_point_of_tendsto_iterate (hf.to_uniform_continuous.continuous.tendsto x) ⟨x₀, hx⟩⟩
end contraction
end lipschitz_with
|
c8f1a319ad89ba6975f59fe50e72eb606d905a06
|
cc060cf567f81c404a13ee79bf21f2e720fa6db0
|
/lean/mwe2.lean
|
f08cb486b381c2be45283983fdedc8b6953ff0d2
|
[
"Apache-2.0"
] |
permissive
|
semorrison/proof
|
cf0a8c6957153bdb206fd5d5a762a75958a82bca
|
5ee398aa239a379a431190edbb6022b1a0aa2c70
|
refs/heads/master
| 1,610,414,502,842
| 1,518,696,851,000
| 1,518,696,851,000
| 78,375,937
| 2
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,563
|
lean
|
import standard
meta def blast : tactic unit :=
using_smt $ return ()
structure Category (Obj : Type) (Hom : Obj -> Obj -> Type) :=
(identity : Π A : Obj, Hom A A)
(compose : Π ⦃A B C : Obj⦄, Hom A B → Hom B C → Hom A C)
attribute [class] Category
open Category
structure MonoidalCategory (Obj : Type) (Hom : Obj → Obj → Type)
extends carrier : Category Obj Hom :=
(unit : Obj)
variables { Obj₁ Obj₂ : Type }
variables { Hom₁ : Obj₁ → Obj₁ → Type } { Hom₂ : Obj₂ → Obj₂ → Type }
structure Functor (C₁ : Category Obj₁ Hom₁) (C₂ : Category Obj₂ Hom₂) :=
(onObjects : Obj₁ → Obj₂)
(onMorphisms : Π ⦃A B : Obj₁⦄,
Hom₁ A B → Hom₂ (onObjects A) (onObjects B))
(identities : Π (A : Obj₁),
onMorphisms (identity C₁ A) = identity C₂ (onObjects A))
definition ℕCategory : Category unit (λ a b, ℕ) :=
{ identity := λ a, 0,
compose := λ a b c, add
}
definition DoublingAsFunctor : Functor ℕCategory ℕCategory :=
{ onObjects := id,
onMorphisms := (λ A B n, n + n),
identities := by blast
}
attribute [instance] MonoidalCategory.to_Category
definition ℕMonoidalCategory : MonoidalCategory unit (λ A B, ℕ) :=
{ ℕCategory with
unit := ()
}
-- casting is not working: we really want to be able to write the following:
definition DoublingAsFunctor' : Functor ℕMonoidalCategory ℕMonoidalCategory :=
{ onObjects := id,
onMorphisms := (λ A B n, n + n),
identities := by blast
}
|
38b56defa0e10e777f54ddd65f95e1c50c9a61c8
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/hott/id_tac5.hlean
|
e23ad67e14dc2fa926a16a186011fabac80c2026
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean
|
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
|
38607e3eb57f57f77c0ac114ad169e9e4262e24f
|
refs/heads/master
| 1,611,187,284,081
| 1,450,766,737,000
| 1,476,122,547,000
| 11,513,992
| 2
| 0
| null | 1,401,763,102,000
| 1,374,182,235,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 293
|
hlean
|
open equiv
constant rec_on_ua {A B : Type} {P : A ≃ B → Type}
(f : A ≃ B) (H : Π(q : A = B), P (equiv_of_eq q)) : P f
set_option pp.universes true
set_option pp.implicit true
set_option pp.notation false
check @rec_on_ua
attribute rec_on_ua [recursor]
print [recursor] rec_on_ua
|
88af60115ec6a060bf46d74d51905daf56ea84ee
|
64874bd1010548c7f5a6e3e8902efa63baaff785
|
/tests/lean/notation2.lean
|
25372a35627ffe851d6b5a9609bc567dcb924b05
|
[
"Apache-2.0"
] |
permissive
|
tjiaqi/lean
|
4634d729795c164664d10d093f3545287c76628f
|
d0ce4cf62f4246b0600c07e074d86e51f2195e30
|
refs/heads/master
| 1,622,323,796,480
| 1,422,643,069,000
| 1,422,643,069,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 272
|
lean
|
import data.num
inductive list (T : Type) : Type := nil {} : list T, cons : T → list T → list T open list notation h :: t := cons h t notation `[` l:(foldr `,` (h t, cons h t) nil) `]` := l
infixr `::` := cons
check 1 :: 2 :: nil
check 1 :: 2 :: 3 :: 4 :: 5 :: nil
|
7938936fcb1b0022978e99a37ebeb5916741e797
|
abd85493667895c57a7507870867b28124b3998f
|
/src/number_theory/quadratic_reciprocity.lean
|
cb1f337851154fd9d9f8873f1a44b1aa5bbfcda1
|
[
"Apache-2.0"
] |
permissive
|
pechersky/mathlib
|
d56eef16bddb0bfc8bc552b05b7270aff5944393
|
f1df14c2214ee114c9738e733efd5de174deb95d
|
refs/heads/master
| 1,666,714,392,571
| 1,591,747,567,000
| 1,591,747,567,000
| 270,557,274
| 0
| 0
|
Apache-2.0
| 1,591,597,975,000
| 1,591,597,974,000
| null |
UTF-8
|
Lean
| false
| false
| 25,076
|
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 field_theory.finite
import data.zmod.basic
import data.nat.parity
/-!
# Quadratic reciprocity.
This file contains results about quadratic residues modulo a prime number.
The main results are the law of quadratic reciprocity, `quadratic_reciprocity`, as well as the
interpretations in terms of existence of square roots depending on the congruence mod 4,
`exists_pow_two_eq_prime_iff_of_mod_four_eq_one`, and
`exists_pow_two_eq_prime_iff_of_mod_four_eq_three`.
Also proven are conditions for `-1` and `2` to be a square modulo a prime,
`exists_pow_two_eq_neg_one_iff_mod_four_ne_three` and
`exists_pow_two_eq_two_iff`
## Implementation notes
The proof of quadratic reciprocity implemented uses Gauss' lemma and Eisenstein's lemma
-/
open function finset nat finite_field zmod
open_locale big_operators
namespace zmod
variables (p q : ℕ) [fact p.prime] [fact q.prime]
@[simp] lemma card_units : fintype.card (units (zmod p)) = p - 1 :=
by rw [card_units, card]
/-- Fermat's Little Theorem: for every unit `a` of `zmod p`, we have `a ^ (p - 1) = 1`. -/
theorem fermat_little_units {p : ℕ} [fact p.prime] (a : units (zmod p)) :
a ^ (p - 1) = 1 :=
by rw [← card_units p, pow_card_eq_one]
/-- Fermat's Little Theorem: for all nonzero `a : zmod p`, we have `a ^ (p - 1) = 1`. -/
theorem fermat_little {a : zmod p} (ha : a ≠ 0) : a ^ (p - 1) = 1 :=
begin
have := fermat_little_units (units.mk0 a ha),
apply_fun (coe : units (zmod p) → zmod p) at this,
simpa,
end
/-- Euler's Criterion: A unit `x` of `zmod p` is a square if and only if `x ^ (p / 2) = 1`. -/
lemma euler_criterion_units (x : units (zmod p)) :
(∃ y : units (zmod p), y ^ 2 = x) ↔ x ^ (p / 2) = 1 :=
begin
cases nat.prime.eq_two_or_odd ‹p.prime› with hp2 hp_odd,
{ resetI, subst p, refine iff_of_true ⟨1, _⟩ _; apply subsingleton.elim },
obtain ⟨g, hg⟩ := is_cyclic.exists_generator (units (zmod p)),
obtain ⟨n, hn⟩ : x ∈ powers g, { rw powers_eq_gpowers, apply hg },
split,
{ rintro ⟨y, rfl⟩, rw [← pow_mul, two_mul_odd_div_two hp_odd, fermat_little_units], },
{ subst x, assume h,
have key : 2 * (p / 2) ∣ n * (p / 2),
{ rw [← pow_mul] at h,
rw [two_mul_odd_div_two hp_odd, ← card_units, ← order_of_eq_card_of_forall_mem_gpowers hg],
apply order_of_dvd_of_pow_eq_one h },
have : 0 < p / 2 := nat.div_pos (show fact (1 < p), by apply_instance) dec_trivial,
obtain ⟨m, rfl⟩ := dvd_of_mul_dvd_mul_right this key,
refine ⟨g ^ m, _⟩,
rw [mul_comm, pow_mul], },
end
/-- Euler's Criterion: a nonzero `a : zmod p` is a square if and only if `x ^ (p / 2) = 1`. -/
lemma euler_criterion {a : zmod p} (ha : a ≠ 0) :
(∃ y : zmod p, y ^ 2 = a) ↔ a ^ (p / 2) = 1 :=
begin
apply (iff_congr _ (by simp [units.ext_iff])).mp (euler_criterion_units p (units.mk0 a ha)),
simp only [units.ext_iff, _root_.pow_two, units.coe_mk0, units.coe_mul],
split, { rintro ⟨y, hy⟩, exact ⟨y, hy⟩ },
{ rintro ⟨y, rfl⟩,
have hy : y ≠ 0, { rintro rfl, simpa [_root_.zero_pow] using ha, },
refine ⟨units.mk0 y hy, _⟩, simp, }
end
lemma exists_pow_two_eq_neg_one_iff_mod_four_ne_three :
(∃ y : zmod p, y ^ 2 = -1) ↔ p % 4 ≠ 3 :=
begin
cases nat.prime.eq_two_or_odd ‹p.prime› with hp2 hp_odd,
{ resetI, subst p, exact dec_trivial },
change fact (p % 2 = 1) at hp_odd, resetI,
have neg_one_ne_zero : (-1 : zmod p) ≠ 0, from mt neg_eq_zero.1 one_ne_zero,
rw [euler_criterion p neg_one_ne_zero, neg_one_pow_eq_pow_mod_two],
cases mod_two_eq_zero_or_one (p / 2) with p_half_even p_half_odd,
{ rw [p_half_even, _root_.pow_zero, eq_self_iff_true, true_iff],
contrapose! p_half_even with hp,
rw [← nat.mod_mul_right_div_self, show 2 * 2 = 4, from rfl, hp],
exact dec_trivial },
{ rw [p_half_odd, _root_.pow_one,
iff_false_intro (ne_neg_self p one_ne_zero).symm, false_iff, not_not],
rw [← nat.mod_mul_right_div_self, show 2 * 2 = 4, from rfl] at p_half_odd,
rw [_root_.fact, ← nat.mod_mul_left_mod _ 2, show 2 * 2 = 4, from rfl] at hp_odd,
have hp : p % 4 < 4, from nat.mod_lt _ dec_trivial,
revert hp hp_odd p_half_odd,
generalize : p % 4 = k, revert k, exact dec_trivial }
end
lemma pow_div_two_eq_neg_one_or_one {a : zmod p} (ha : a ≠ 0) :
a ^ (p / 2) = 1 ∨ a ^ (p / 2) = -1 :=
begin
cases nat.prime.eq_two_or_odd ‹p.prime› with hp2 hp_odd,
{ resetI, subst p, revert a ha, exact dec_trivial },
rw [← mul_self_eq_one_iff, ← _root_.pow_add, ← two_mul, two_mul_odd_div_two hp_odd],
exact fermat_little p ha
end
/-- Wilson's Lemma: the product of `1`, ..., `p-1` is `-1` modulo `p`. -/
@[simp] lemma wilsons_lemma : (nat.fact (p - 1) : zmod p) = -1 :=
begin
refine
calc (nat.fact (p - 1) : zmod p) = (∏ x in Ico 1 (succ (p - 1)), x) :
by rw [← finset.prod_Ico_id_eq_fact, prod_nat_cast]
... = (∏ x : units (zmod p), x) : _
... = -1 :
by rw [prod_hom _ (coe : units (zmod p) → zmod p),
prod_univ_units_id_eq_neg_one, units.coe_neg, units.coe_one],
have hp : 0 < p := nat.prime.pos ‹p.prime›,
symmetry,
refine prod_bij (λ a _, (a : zmod p).val) _ _ _ _,
{ intros a ha,
rw [Ico.mem, ← nat.succ_sub hp, nat.succ_sub_one],
split,
{ apply nat.pos_of_ne_zero, rw ← @val_zero p,
assume h, apply units.coe_ne_zero a (val_injective p h) },
{ exact val_lt _ } },
{ intros a ha, simp only [cast_id, nat_cast_val], },
{ intros _ _ _ _ h, rw units.ext_iff, exact val_injective p h },
{ intros b hb,
rw [Ico.mem, nat.succ_le_iff, ← succ_sub hp, succ_sub_one, nat.pos_iff_ne_zero] at hb,
refine ⟨units.mk0 b _, finset.mem_univ _, _⟩,
{ assume h, apply hb.1, apply_fun val at h,
simpa only [val_cast_of_lt hb.right, val_zero] using h },
{ simp only [val_cast_of_lt hb.right, units.coe_mk0], } }
end
@[simp] lemma prod_Ico_one_prime : (∏ x in Ico 1 p, (x : zmod p)) = -1 :=
begin
conv in (Ico 1 p) { rw [← succ_sub_one p, succ_sub (nat.prime.pos ‹p.prime›)] },
rw [← prod_nat_cast, finset.prod_Ico_id_eq_fact, wilsons_lemma]
end
end zmod
/-- The image of the map sending a non zero natural number `x ≤ p / 2` to the absolute value
of the element of interger in the interval `(-p/2, p/2]` congruent to `a * x` mod p is the set
of non zero natural numbers `x` such that `x ≤ p / 2` -/
lemma Ico_map_val_min_abs_nat_abs_eq_Ico_map_id
(p : ℕ) [hp : fact p.prime] (a : zmod p) (hap : a ≠ 0) :
(Ico 1 (p / 2).succ).1.map (λ x, (a * x).val_min_abs.nat_abs) =
(Ico 1 (p / 2).succ).1.map (λ a, a) :=
begin
have he : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x ≠ 0 ∧ x ≤ p / 2,
by simp [nat.lt_succ_iff, nat.succ_le_iff, nat.pos_iff_ne_zero] {contextual := tt},
have hep : ∀ {x}, x ∈ Ico 1 (p / 2).succ → x < p,
from λ x hx, lt_of_le_of_lt (he hx).2 (nat.div_lt_self hp.pos dec_trivial),
have hpe : ∀ {x}, x ∈ Ico 1 (p / 2).succ → ¬ p ∣ x,
from λ x hx hpx, not_lt_of_ge (le_of_dvd (nat.pos_of_ne_zero (he hx).1) hpx) (hep hx),
have hmem : ∀ (x : ℕ) (hx : x ∈ Ico 1 (p / 2).succ),
(a * x : zmod p).val_min_abs.nat_abs ∈ Ico 1 (p / 2).succ,
{ assume x hx,
simp [hap, char_p.cast_eq_zero_iff (zmod p) p, hpe hx, lt_succ_iff, succ_le_iff,
nat.pos_iff_ne_zero, nat_abs_val_min_abs_le _], },
have hsurj : ∀ (b : ℕ) (hb : b ∈ Ico 1 (p / 2).succ),
∃ x ∈ Ico 1 (p / 2).succ, b = (a * x : zmod p).val_min_abs.nat_abs,
{ assume b hb,
refine ⟨(b / a : zmod p).val_min_abs.nat_abs, Ico.mem.mpr ⟨_, _⟩, _⟩,
{ apply nat.pos_of_ne_zero,
simp only [div_eq_mul_inv, hap, char_p.cast_eq_zero_iff (zmod p) p, hpe hb, not_false_iff,
val_min_abs_eq_zero, inv_eq_zero, int.nat_abs_eq_zero, ne.def, mul_eq_zero_iff', or_self] },
{ apply lt_succ_of_le, apply nat_abs_val_min_abs_le },
{ rw cast_nat_abs_val_min_abs,
split_ifs,
{ erw [mul_div_cancel' _ hap, val_min_abs_def_pos, val_cast_of_lt (hep hb),
if_pos (le_of_lt_succ (Ico.mem.1 hb).2), int.nat_abs_of_nat], },
{ erw [mul_neg_eq_neg_mul_symm, mul_div_cancel' _ hap, nat_abs_val_min_abs_neg,
val_min_abs_def_pos, val_cast_of_lt (hep hb), if_pos (le_of_lt_succ (Ico.mem.1 hb).2),
int.nat_abs_of_nat] } } },
exact multiset.map_eq_map_of_bij_of_nodup _ _ (finset.nodup _) (finset.nodup _)
(λ x _, (a * x : zmod p).val_min_abs.nat_abs) hmem (λ _ _, rfl)
(inj_on_of_surj_on_of_card_le _ hmem hsurj (le_refl _)) hsurj
end
private lemma gauss_lemma_aux₁ (p : ℕ) [hp : fact p.prime] [hp2 : fact (p % 2 = 1)]
{a : ℕ} (hap : (a : zmod p) ≠ 0) :
(a^(p / 2) * (p / 2).fact : zmod p) =
(-1)^((Ico 1 (p / 2).succ).filter
(λ x : ℕ, ¬(a * x : zmod p).val ≤ p / 2)).card * (p / 2).fact :=
calc (a ^ (p / 2) * (p / 2).fact : zmod p) =
(∏ x in Ico 1 (p / 2).succ, a * x) :
by rw [prod_mul_distrib, ← prod_nat_cast, ← prod_nat_cast, prod_Ico_id_eq_fact,
prod_const, Ico.card, succ_sub_one]; simp
... = (∏ x in Ico 1 (p / 2).succ, (a * x : zmod p).val) : by simp
... = (∏ x in Ico 1 (p / 2).succ,
(if (a * x : zmod p).val ≤ p / 2 then 1 else -1) *
(a * x : zmod p).val_min_abs.nat_abs) :
prod_congr rfl $ λ _ _, begin
simp only [cast_nat_abs_val_min_abs],
split_ifs; simp
end
... = (-1)^((Ico 1 (p / 2).succ).filter
(λ x : ℕ, ¬(a * x : zmod p).val ≤ p / 2)).card *
(∏ x in Ico 1 (p / 2).succ, (a * x : zmod p).val_min_abs.nat_abs) :
have (∏ x in Ico 1 (p / 2).succ,
if (a * x : zmod p).val ≤ p / 2 then (1 : zmod p) else -1) =
(∏ x in (Ico 1 (p / 2).succ).filter
(λ x : ℕ, ¬(a * x : zmod p).val ≤ p / 2), -1),
from prod_bij_ne_one (λ x _ _, x)
(λ x, by split_ifs; simp * at * {contextual := tt})
(λ _ _ _ _ _ _, id)
(λ b h _, ⟨b, by simp [-not_le, *] at *⟩)
(by intros; split_ifs at *; simp * at *),
by rw [prod_mul_distrib, this]; simp
... = (-1)^((Ico 1 (p / 2).succ).filter
(λ x : ℕ, ¬(a * x : zmod p).val ≤ p / 2)).card * (p / 2).fact :
by rw [← prod_nat_cast, finset.prod_eq_multiset_prod,
Ico_map_val_min_abs_nat_abs_eq_Ico_map_id p a hap,
← finset.prod_eq_multiset_prod, prod_Ico_id_eq_fact]
private lemma gauss_lemma_aux₂ (p : ℕ) [hp : fact p.prime] [hp2 : fact (p % 2 = 1)]
{a : ℕ} (hap : (a : zmod p) ≠ 0) :
(a^(p / 2) : zmod p) = (-1)^((Ico 1 (p / 2).succ).filter
(λ x : ℕ, p / 2 < (a * x : zmod p).val)).card :=
(domain.mul_left_inj
(show ((p / 2).fact : zmod p) ≠ 0,
by rw [ne.def, char_p.cast_eq_zero_iff (zmod p) p, hp.dvd_fact, not_le];
exact nat.div_lt_self hp.pos dec_trivial)).1 $
by simpa using gauss_lemma_aux₁ p hap
private lemma eisenstein_lemma_aux₁ (p : ℕ) [hp : fact p.prime] [hp2 : fact (p % 2 = 1)]
{a : ℕ} (hap : (a : zmod p) ≠ 0) :
(((Ico 1 (p / 2).succ).sum (λ x, a * x) : ℕ) : zmod 2) =
((Ico 1 (p / 2).succ).filter
((λ x : ℕ, p / 2 < (a * x : zmod p).val))).card +
(Ico 1 (p / 2).succ).sum (λ x, x)
+ ((Ico 1 (p / 2).succ).sum (λ x, (a * x) / p) : ℕ) :=
have hp2 : (p : zmod 2) = (1 : ℕ), from (eq_iff_modeq_nat _).2 hp2,
calc (((Ico 1 (p / 2).succ).sum (λ x, a * x) : ℕ) : zmod 2)
= (((Ico 1 (p / 2).succ).sum (λ x, (a * x) % p + p * ((a * x) / p)) : ℕ) : zmod 2) :
by simp only [mod_add_div]
... = ((Ico 1 (p / 2).succ).sum (λ x, ((a * x : ℕ) : zmod p).val) : ℕ) +
((Ico 1 (p / 2).succ).sum (λ x, (a * x) / p) : ℕ) :
by simp only [val_cast_nat];
simp [sum_add_distrib, mul_sum.symm, nat.cast_add, nat.cast_mul, sum_nat_cast, hp2]
... = _ : congr_arg2 (+)
(calc (((Ico 1 (p / 2).succ).sum (λ x, ((a * x : ℕ) : zmod p).val) : ℕ) : zmod 2)
= (Ico 1 (p / 2).succ).sum
(λ x, ((((a * x : zmod p).val_min_abs +
(if (a * x : zmod p).val ≤ p / 2 then 0 else p)) : ℤ) : zmod 2)) :
by simp only [(val_eq_ite_val_min_abs _).symm]; simp [sum_nat_cast]
... = ((Ico 1 (p / 2).succ).filter
(λ x : ℕ, p / 2 < (a * x : zmod p).val)).card +
(((Ico 1 (p / 2).succ).sum (λ x, (a * x : zmod p).val_min_abs.nat_abs)) : ℕ) :
by { simp [ite_cast, add_comm, sum_add_distrib, finset.sum_ite, hp2, sum_nat_cast], }
... = _ : by rw [finset.sum_eq_multiset_sum,
Ico_map_val_min_abs_nat_abs_eq_Ico_map_id p a hap,
← finset.sum_eq_multiset_sum];
simp [sum_nat_cast]) rfl
private lemma eisenstein_lemma_aux₂ (p : ℕ) [hp : fact p.prime] [hp2 : fact (p % 2 = 1)]
{a : ℕ} (ha2 : a % 2 = 1) (hap : (a : zmod p) ≠ 0) :
((Ico 1 (p / 2).succ).filter
((λ x : ℕ, p / 2 < (a * x : zmod p).val))).card
≡ (Ico 1 (p / 2).succ).sum (λ x, (x * a) / p) [MOD 2] :=
have ha2 : (a : zmod 2) = (1 : ℕ), from (eq_iff_modeq_nat _).2 ha2,
(eq_iff_modeq_nat 2).1 $ sub_eq_zero.1 $
by simpa [add_left_comm, sub_eq_add_neg, finset.mul_sum.symm, mul_comm, ha2, sum_nat_cast,
add_neg_eq_iff_eq_add.symm, neg_eq_self_mod_two, add_assoc]
using eq.symm (eisenstein_lemma_aux₁ p hap)
lemma div_eq_filter_card {a b c : ℕ} (hb0 : 0 < b) (hc : a / b ≤ c) : a / b =
((Ico 1 c.succ).filter (λ x, x * b ≤ a)).card :=
calc a / b = (Ico 1 (a / b).succ).card : by simp
... = ((Ico 1 c.succ).filter (λ x, x * b ≤ a)).card :
congr_arg _$ finset.ext.2 $ λ x,
have x * b ≤ a → x ≤ c,
from λ h, le_trans (by rwa [le_div_iff_mul_le _ _ hb0]) hc,
by simp [lt_succ_iff, le_div_iff_mul_le _ _ hb0]; tauto
/-- The given sum is the number of integer points in the triangle formed by the diagonal of the
rectangle `(0, p/2) × (0, q/2)` -/
private lemma sum_Ico_eq_card_lt {p q : ℕ} :
(Ico 1 (p / 2).succ).sum (λ a, (a * q) / p) =
(((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.2 * p ≤ x.1 * q)).card :=
if hp0 : p = 0 then by simp [hp0, finset.ext]
else
calc (Ico 1 (p / 2).succ).sum (λ a, (a * q) / p) =
(Ico 1 (p / 2).succ).sum (λ a,
((Ico 1 (q / 2).succ).filter (λ x, x * p ≤ a * q)).card) :
finset.sum_congr rfl $ λ x hx,
div_eq_filter_card (nat.pos_of_ne_zero hp0)
(calc x * q / p ≤ (p / 2) * q / p :
nat.div_le_div_right (mul_le_mul_of_nonneg_right
(le_of_lt_succ $ by finish)
(nat.zero_le _))
... ≤ _ : nat.div_mul_div_le_div _ _ _)
... = _ : by rw [← card_sigma];
exact card_congr (λ a _, ⟨a.1, a.2⟩)
(by simp {contextual := tt})
(λ ⟨_, _⟩ ⟨_, _⟩, by simp {contextual := tt})
(λ ⟨b₁, b₂⟩ h, ⟨⟨b₁, b₂⟩,
by revert h; simp {contextual := tt}⟩)
/-- Each of the sums in this lemma is the cardinality of the set integer points in each of the
two triangles formed by the diagonal of the rectangle `(0, p/2) × (0, q/2)`. Adding them
gives the number of points in the rectangle. -/
private lemma sum_mul_div_add_sum_mul_div_eq_mul (p q : ℕ) [hp : fact p.prime]
(hq0 : (q : zmod p) ≠ 0) :
(Ico 1 (p / 2).succ).sum (λ a, (a * q) / p) +
(Ico 1 (q / 2).succ).sum (λ a, (a * p) / q) =
(p / 2) * (q / 2) :=
have hswap : (((Ico 1 (q / 2).succ).product (Ico 1 (p / 2).succ)).filter
(λ x : ℕ × ℕ, x.2 * q ≤ x.1 * p)).card =
(((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.1 * q ≤ x.2 * p)).card :=
card_congr (λ x _, prod.swap x)
(λ ⟨_, _⟩, by simp {contextual := tt})
(λ ⟨_, _⟩ ⟨_, _⟩, by simp {contextual := tt})
(λ ⟨x₁, x₂⟩ h, ⟨⟨x₂, x₁⟩, by revert h; simp {contextual := tt}⟩),
have hdisj : disjoint
(((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.2 * p ≤ x.1 * q))
(((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.1 * q ≤ x.2 * p)),
from disjoint_filter.2 $ λ x hx hpq hqp,
have hxp : x.1 < p, from lt_of_le_of_lt
(show x.1 ≤ p / 2, by simp [*, nat.lt_succ_iff] at *; tauto)
(nat.div_lt_self hp.pos dec_trivial),
begin
have : (x.1 : zmod p) = 0,
{ simpa [hq0] using congr_arg (coe : ℕ → zmod p) (le_antisymm hpq hqp) },
apply_fun zmod.val at this,
rw [val_cast_of_lt hxp, val_zero] at this,
simp * at *
end,
have hunion : ((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.2 * p ≤ x.1 * q) ∪
((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)).filter
(λ x : ℕ × ℕ, x.1 * q ≤ x.2 * p) =
((Ico 1 (p / 2).succ).product (Ico 1 (q / 2).succ)),
from finset.ext.2 $ λ x, by have := le_total (x.2 * p) (x.1 * q); simp; tauto,
by rw [sum_Ico_eq_card_lt, sum_Ico_eq_card_lt, hswap, ← card_disjoint_union hdisj, hunion,
card_product];
simp
variables (p q : ℕ) [fact p.prime] [fact q.prime]
namespace zmod
/-- The Legendre symbol of `a` and `p` is an integer defined as
* `0` if `a` is `0` modulo `p`;
* `1` if `a ^ (p / 2)` is `1` modulo `p`
(by `euler_criterion` this is equivalent to “`a` is a square modulo `p`”);
* `-1` otherwise.
-/
def legendre_sym (a p : ℕ) : ℤ :=
if (a : zmod p) = 0 then 0
else if (a : zmod p) ^ (p / 2) = 1 then 1
else -1
lemma legendre_sym_eq_pow (a p : ℕ) [hp : fact p.prime] :
(legendre_sym a p : zmod p) = (a ^ (p / 2)) :=
begin
rw legendre_sym,
by_cases ha : (a : zmod p) = 0,
{ simp only [if_pos, ha, _root_.zero_pow (nat.div_pos (hp.two_le) (succ_pos 1)), int.cast_zero] },
cases hp.eq_two_or_odd with hp2 hp_odd,
{ resetI, subst p,
have : ∀ (a : zmod 2),
((if a = 0 then 0 else if a ^ (2 / 2) = 1 then 1 else -1 : ℤ) : zmod 2) = a ^ (2 / 2),
by exact dec_trivial,
exact this a },
{ change fact (p % 2 = 1) at hp_odd, resetI,
rw if_neg ha,
have : (-1 : zmod p) ≠ 1, from (ne_neg_self p one_ne_zero).symm,
cases pow_div_two_eq_neg_one_or_one p ha with h h,
{ rw [if_pos h, h, int.cast_one], },
{ rw [h, if_neg this, int.cast_neg, int.cast_one], } }
end
lemma legendre_sym_eq_one_or_neg_one (a p : ℕ) (ha : (a : zmod p) ≠ 0) :
legendre_sym a p = -1 ∨ legendre_sym a p = 1 :=
by unfold legendre_sym; split_ifs; simp only [*, eq_self_iff_true, or_true, true_or] at *
lemma legendre_sym_eq_zero_iff (a p : ℕ) :
legendre_sym a p = 0 ↔ (a : zmod p) = 0 :=
begin
split,
{ classical, contrapose,
assume ha, cases legendre_sym_eq_one_or_neg_one a p ha with h h,
all_goals { rw h, norm_num } },
{ assume ha, rw [legendre_sym, if_pos ha] }
end
/-- Gauss' lemma. The legendre symbol can be computed by considering the number of naturals less
than `p/2` such that `(a * x) % p > p / 2` -/
lemma gauss_lemma {a : ℕ} [hp1 : fact (p % 2 = 1)] (ha0 : (a : zmod p) ≠ 0) :
legendre_sym a p = (-1) ^ ((Ico 1 (p / 2).succ).filter
(λ x : ℕ, p / 2 < (a * x : zmod p).val)).card :=
have (legendre_sym a p : zmod p) = (((-1)^((Ico 1 (p / 2).succ).filter
(λ x : ℕ, p / 2 < (a * x : zmod p).val)).card : ℤ) : zmod p),
by rw [legendre_sym_eq_pow, gauss_lemma_aux₂ p ha0]; simp,
begin
cases legendre_sym_eq_one_or_neg_one a p ha0;
cases @neg_one_pow_eq_or ℤ _ ((Ico 1 (p / 2).succ).filter
(λ x : ℕ, p / 2 < (a * x : zmod p).val)).card;
simp [*, ne_neg_self p one_ne_zero, (ne_neg_self p one_ne_zero).symm] at *
end
lemma legendre_sym_eq_one_iff {a : ℕ} (ha0 : (a : zmod p) ≠ 0) :
legendre_sym a p = 1 ↔ (∃ b : zmod p, b ^ 2 = a) :=
begin
rw [euler_criterion p ha0, legendre_sym, if_neg ha0],
split_ifs,
{ simp only [h, eq_self_iff_true] },
finish -- this is quite slow. I'm actually surprised that it can close the goal at all!
end
lemma eisenstein_lemma [hp1 : fact (p % 2 = 1)] {a : ℕ} (ha1 : a % 2 = 1) (ha0 : (a : zmod p) ≠ 0) :
legendre_sym a p = (-1)^(Ico 1 (p / 2).succ).sum (λ x, (x * a) / p) :=
by rw [neg_one_pow_eq_pow_mod_two, gauss_lemma p ha0, neg_one_pow_eq_pow_mod_two,
show _ = _, from eisenstein_lemma_aux₂ p ha1 ha0]
theorem quadratic_reciprocity [hp1 : fact (p % 2 = 1)] [hq1 : fact (q % 2 = 1)] (hpq : p ≠ q) :
legendre_sym p q * legendre_sym q p = (-1) ^ ((p / 2) * (q / 2)) :=
have hpq0 : (p : zmod q) ≠ 0, from prime_ne_zero q p hpq.symm,
have hqp0 : (q : zmod p) ≠ 0, from prime_ne_zero p q hpq,
by rw [eisenstein_lemma q hp1 hpq0, eisenstein_lemma p hq1 hqp0,
← _root_.pow_add, sum_mul_div_add_sum_mul_div_eq_mul q p hpq0, mul_comm]
-- move this
instance fact_prime_two : fact (nat.prime 2) := nat.prime_two
lemma legendre_sym_two [hp1 : fact (p % 2 = 1)] : legendre_sym 2 p = (-1) ^ (p / 4 + p / 2) :=
have hp2 : p ≠ 2, from mt (congr_arg (% 2)) (by simpa using hp1),
have hp22 : p / 2 / 2 = _ := div_eq_filter_card (show 0 < 2, from dec_trivial)
(nat.div_le_self (p / 2) 2),
have hcard : (Ico 1 (p / 2).succ).card = p / 2, by simp,
have hx2 : ∀ x ∈ Ico 1 (p / 2).succ, (2 * x : zmod p).val = 2 * x,
from λ x hx, have h2xp : 2 * x < p,
from calc 2 * x ≤ 2 * (p / 2) : mul_le_mul_of_nonneg_left
(le_of_lt_succ $ by finish) dec_trivial
... < _ : by conv_rhs {rw [← mod_add_div p 2, add_comm, show p % 2 = 1, from hp1]}; exact lt_succ_self _,
by rw [← nat.cast_two, ← nat.cast_mul, val_cast_of_lt h2xp],
have hdisj : disjoint
((Ico 1 (p / 2).succ).filter (λ x, p / 2 < ((2 : ℕ) * x : zmod p).val))
((Ico 1 (p / 2).succ).filter (λ x, x * 2 ≤ p / 2)),
from disjoint_filter.2 (λ x hx, by simp [hx2 _ hx, mul_comm]),
have hunion :
((Ico 1 (p / 2).succ).filter (λ x, p / 2 < ((2 : ℕ) * x : zmod p).val)) ∪
((Ico 1 (p / 2).succ).filter (λ x, x * 2 ≤ p / 2)) =
Ico 1 (p / 2).succ,
begin
rw [filter_union_right],
conv_rhs {rw [← @filter_true _ (Ico 1 (p / 2).succ)]},
exact filter_congr (λ x hx, by simp [hx2 _ hx, lt_or_le, mul_comm])
end,
begin
rw [gauss_lemma p (prime_ne_zero p 2 hp2),
neg_one_pow_eq_pow_mod_two, @neg_one_pow_eq_pow_mod_two _ _ (p / 4 + p / 2)],
refine congr_arg2 _ rfl ((eq_iff_modeq_nat 2).1 _),
rw [show 4 = 2 * 2, from rfl, ← nat.div_div_eq_div_mul, hp22, nat.cast_add,
← sub_eq_iff_eq_add', sub_eq_add_neg, neg_eq_self_mod_two,
← nat.cast_add, ← card_disjoint_union hdisj, hunion, hcard]
end
lemma exists_pow_two_eq_two_iff [hp1 : fact (p % 2 = 1)] :
(∃ a : zmod p, a ^ 2 = 2) ↔ p % 8 = 1 ∨ p % 8 = 7 :=
have hp2 : ((2 : ℕ) : zmod p) ≠ 0,
from prime_ne_zero p 2 (λ h, by simpa [h] using hp1),
have hpm4 : p % 4 = p % 8 % 4, from (nat.mod_mul_left_mod p 2 4).symm,
have hpm2 : p % 2 = p % 8 % 2, from (nat.mod_mul_left_mod p 4 2).symm,
begin
rw [show (2 : zmod p) = (2 : ℕ), by simp, ← legendre_sym_eq_one_iff p hp2,
legendre_sym_two p, neg_one_pow_eq_one_iff_even (show (-1 : ℤ) ≠ 1, from dec_trivial),
even_add, even_div, even_div],
have := nat.mod_lt p (show 0 < 8, from dec_trivial),
resetI, rw _root_.fact at hp1,
revert this hp1,
erw [hpm4, hpm2],
generalize hm : p % 8 = m,
clear hm,
revert m,
exact dec_trivial
end
lemma exists_pow_two_eq_prime_iff_of_mod_four_eq_one (hp1 : p % 4 = 1) [hq1 : fact (q % 2 = 1)] :
(∃ a : zmod p, a ^ 2 = q) ↔ ∃ b : zmod q, b ^ 2 = p :=
if hpq : p = q then by resetI; subst hpq else
have h1 : ((p / 2) * (q / 2)) % 2 = 0,
from (dvd_iff_mod_eq_zero _ _).1
(dvd_mul_of_dvd_left ((dvd_iff_mod_eq_zero _ _).2 $
by rw [← mod_mul_right_div_self, show 2 * 2 = 4, from rfl, hp1]; refl) _),
begin
haveI hp_odd : fact (p % 2 = 1) := odd_of_mod_four_eq_one hp1,
have hpq0 : (p : zmod q) ≠ 0 := prime_ne_zero q p (ne.symm hpq),
have hqp0 : (q : zmod p) ≠ 0 := prime_ne_zero p q hpq,
have := quadratic_reciprocity p q hpq,
rw [neg_one_pow_eq_pow_mod_two, h1, legendre_sym, legendre_sym,
if_neg hqp0, if_neg hpq0] at this,
rw [euler_criterion q hpq0, euler_criterion p hqp0],
split_ifs at this; simp *; contradiction,
end
lemma exists_pow_two_eq_prime_iff_of_mod_four_eq_three (hp3 : p % 4 = 3)
(hq3 : q % 4 = 3) (hpq : p ≠ q) : (∃ a : zmod p, a ^ 2 = q) ↔ ¬∃ b : zmod q, b ^ 2 = p :=
have h1 : ((p / 2) * (q / 2)) % 2 = 1,
from nat.odd_mul_odd
(by rw [← mod_mul_right_div_self, show 2 * 2 = 4, from rfl, hp3]; refl)
(by rw [← mod_mul_right_div_self, show 2 * 2 = 4, from rfl, hq3]; refl),
begin
haveI hp_odd : fact (p % 2 = 1) := odd_of_mod_four_eq_three hp3,
haveI hq_odd : fact (q % 2 = 1) := odd_of_mod_four_eq_three hq3,
have hpq0 : (p : zmod q) ≠ 0 := prime_ne_zero q p (ne.symm hpq),
have hqp0 : (q : zmod p) ≠ 0 := prime_ne_zero p q hpq,
have := quadratic_reciprocity p q hpq,
rw [neg_one_pow_eq_pow_mod_two, h1, legendre_sym, legendre_sym,
if_neg hpq0, if_neg hqp0] at this,
rw [euler_criterion q hpq0, euler_criterion p hqp0],
split_ifs at this; simp *; contradiction
end
end zmod
|
13246e793b763b64a7768cbe0c277951edaec53e
|
b7f22e51856f4989b970961f794f1c435f9b8f78
|
/tests/lean/cases_tac.lean
|
cb7456f2c5fce026990ebd6177c8830bfb4e3726
|
[
"Apache-2.0"
] |
permissive
|
soonhokong/lean
|
cb8aa01055ffe2af0fb99a16b4cda8463b882cd1
|
38607e3eb57f57f77c0ac114ad169e9e4262e24f
|
refs/heads/master
| 1,611,187,284,081
| 1,450,766,737,000
| 1,476,122,547,000
| 11,513,992
| 2
| 0
| null | 1,401,763,102,000
| 1,374,182,235,000
|
C++
|
UTF-8
|
Lean
| false
| false
| 412
|
lean
|
inductive foo {A : Type} : A → Type :=
mk : Π a : A, foo a
example (A : Type) (B : A → Type) (a : A) (H : foo a) (Hb : B a) : A :=
begin
cases H,
state,
assumption
end
inductive foo₂ {A : Type} : A → A → Type :=
mk : Π a b : A, foo₂ a b
example (A : Type) (B : A → Type) (f : A → A) (a : A) (H : foo₂ (f a) a) (Hb : H = H) (Hc : a = a) : A :=
begin
cases H,
state,
exact a
end
|
79d8dd99e325ef0d20b4c7315cc293b822d5174e
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/analysis/special_functions/complex/log_deriv.lean
|
6c9fa17a0181ed3d11a6c415e00f475a3de86630
|
[
"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
| 6,381
|
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, Benjamin Davidson
-/
import analysis.special_functions.complex.log
import analysis.special_functions.exp_deriv
/-!
# Differentiability of the complex `log` function
-/
noncomputable theory
namespace complex
open set filter
open_locale real topological_space
/-- `complex.exp` as a `local_homeomorph` with `source = {z | -π < im z < π}` and
`target = {z | 0 < re z} ∪ {z | im z ≠ 0}`. This definition is used to prove that `complex.log`
is complex differentiable at all points but the negative real semi-axis. -/
def exp_local_homeomorph : local_homeomorph ℂ ℂ :=
local_homeomorph.of_continuous_open
{ to_fun := exp,
inv_fun := log,
source := {z : ℂ | z.im ∈ Ioo (- π) π},
target := {z : ℂ | 0 < z.re} ∪ {z : ℂ | z.im ≠ 0},
map_source' :=
begin
rintro ⟨x, y⟩ ⟨h₁ : -π < y, h₂ : y < π⟩,
refine (not_or_of_imp $ λ hz, _).symm,
obtain rfl : y = 0,
{ rw exp_im at hz,
simpa [(real.exp_pos _).ne', real.sin_eq_zero_iff_of_lt_of_lt h₁ h₂] using hz },
rw [mem_set_of_eq, ← of_real_def, exp_of_real_re],
exact real.exp_pos x
end,
map_target' := λ z h,
suffices 0 ≤ z.re ∨ z.im ≠ 0,
by simpa [log_im, neg_pi_lt_arg, (arg_le_pi _).lt_iff_ne, arg_eq_pi_iff, not_and_distrib],
h.imp (λ h, le_of_lt h) id,
left_inv' := λ x hx, log_exp hx.1 (le_of_lt hx.2),
right_inv' := λ x hx, exp_log $ by { rintro rfl, simpa [lt_irrefl] using hx } }
continuous_exp.continuous_on is_open_map_exp (is_open_Ioo.preimage continuous_im)
lemma has_strict_deriv_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) :
has_strict_deriv_at log x⁻¹ x :=
have h0 : x ≠ 0, by { rintro rfl, simpa [lt_irrefl] using h },
exp_local_homeomorph.has_strict_deriv_at_symm h h0 $
by simpa [exp_log h0] using has_strict_deriv_at_exp (log x)
lemma has_strict_fderiv_at_log_real {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) :
has_strict_fderiv_at log (x⁻¹ • (1 : ℂ →L[ℝ] ℂ)) x :=
(has_strict_deriv_at_log h).complex_to_real_fderiv
lemma times_cont_diff_at_log {x : ℂ} (h : 0 < x.re ∨ x.im ≠ 0) {n : with_top ℕ} :
times_cont_diff_at ℂ n log x :=
exp_local_homeomorph.times_cont_diff_at_symm_deriv (exp_ne_zero $ log x) h
(has_deriv_at_exp _) times_cont_diff_exp.times_cont_diff_at
end complex
section log_deriv
open complex filter
open_locale topological_space
variables {α : Type*} [topological_space α] {E : Type*} [normed_group E] [normed_space ℂ E]
lemma has_strict_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_strict_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).comp_has_strict_fderiv_at x h₁
lemma has_strict_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_strict_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).comp x h₁ }
lemma has_strict_deriv_at.clog_real {f : ℝ → ℂ} {x : ℝ} {f' : ℂ} (h₁ : has_strict_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_strict_deriv_at (λ t, log (f t)) (f' / f x) x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real h₂).comp_has_strict_deriv_at x h₁
lemma has_fderiv_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {x : E}
(h₁ : has_fderiv_at f f' x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_at (λ t, log (f t)) ((f x)⁻¹ • f') x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_at x h₁
lemma has_deriv_at.clog {f : ℂ → ℂ} {f' x : ℂ} (h₁ : has_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ t, log (f t)) (f' / f x) x :=
by { rw div_eq_inv_mul, exact (has_strict_deriv_at_log h₂).has_deriv_at.comp x h₁ }
lemma has_deriv_at.clog_real {f : ℝ → ℂ} {x : ℝ} {f' : ℂ} (h₁ : has_deriv_at f f' x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_at (λ t, log (f t)) (f' / f x) x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real h₂).has_fderiv_at.comp_has_deriv_at x h₁
lemma differentiable_at.clog {f : E → ℂ} {x : E} (h₁ : differentiable_at ℂ f x)
(h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_at ℂ (λ t, log (f t)) x :=
(h₁.has_fderiv_at.clog h₂).differentiable_at
lemma has_fderiv_within_at.clog {f : E → ℂ} {f' : E →L[ℂ] ℂ} {s : set E} {x : E}
(h₁ : has_fderiv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_fderiv_within_at (λ t, log (f t)) ((f x)⁻¹ • f') s x :=
(has_strict_deriv_at_log h₂).has_deriv_at.comp_has_fderiv_within_at x h₁
lemma has_deriv_within_at.clog {f : ℂ → ℂ} {f' x : ℂ} {s : set ℂ}
(h₁ : has_deriv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ t, log (f t)) (f' / f x) s x :=
by { rw div_eq_inv_mul,
exact (has_strict_deriv_at_log h₂).has_deriv_at.comp_has_deriv_within_at x h₁ }
lemma has_deriv_within_at.clog_real {f : ℝ → ℂ} {s : set ℝ} {x : ℝ} {f' : ℂ}
(h₁ : has_deriv_within_at f f' s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
has_deriv_within_at (λ t, log (f t)) (f' / f x) s x :=
by simpa only [div_eq_inv_mul]
using (has_strict_fderiv_at_log_real h₂).has_fderiv_at.comp_has_deriv_within_at x h₁
lemma differentiable_within_at.clog {f : E → ℂ} {s : set E} {x : E}
(h₁ : differentiable_within_at ℂ f s x) (h₂ : 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_within_at ℂ (λ t, log (f t)) s x :=
(h₁.has_fderiv_within_at.clog h₂).differentiable_within_at
lemma differentiable_on.clog {f : E → ℂ} {s : set E}
(h₁ : differentiable_on ℂ f s) (h₂ : ∀ x ∈ s, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable_on ℂ (λ t, log (f t)) s :=
λ x hx, (h₁ x hx).clog (h₂ x hx)
lemma differentiable.clog {f : E → ℂ} (h₁ : differentiable ℂ f)
(h₂ : ∀ x, 0 < (f x).re ∨ (f x).im ≠ 0) :
differentiable ℂ (λ t, log (f t)) :=
λ x, (h₁ x).clog (h₂ x)
end log_deriv
|
a78101e1d5c05579daa8b56192877e87eebad445
|
82b86ba2ae0d5aed0f01f49c46db5afec0eb2bd7
|
/tests/lean/run/termParserAttr.lean
|
0a6ea1d13b6eb816a345b90777145d3b37176e7a
|
[
"Apache-2.0"
] |
permissive
|
banksonian/lean4
|
3a2e6b0f1eb63aa56ff95b8d07b2f851072d54dc
|
78da6b3aa2840693eea354a41e89fc5b212a5011
|
refs/heads/master
| 1,673,703,624,165
| 1,605,123,551,000
| 1,605,123,551,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 2,133
|
lean
|
import Lean
open Lean
open Lean.Elab
def runCore (input : String) (failIff : Bool := true) : CoreM Unit := do
let env ← getEnv;
let opts ← getOptions;
let (env, messages) ← liftIO $ process input env opts;
messages.toList.forM $ fun msg => liftIO (msg.toString >>= IO.println);
when (failIff && messages.hasErrors) $ throwError "errors have been found";
when (!failIff && !messages.hasErrors) $ throwError "there are no errors";
pure ()
open Lean.Parser
@[termParser] def tst := parser! "(|" >> termParser >> Parser.optional (symbol ", " >> termParser) >> "|)"
def tst2 : Parser := symbol "(||" >> termParser >> symbol "||)"
@[termParser] def boo : ParserDescr :=
ParserDescr.node `boo 10
(ParserDescr.andthen
(ParserDescr.symbol "[|")
(ParserDescr.andthen
(ParserDescr.cat `term 0)
(ParserDescr.symbol "|]")))
@[termParser] def boo2 : ParserDescr :=
ParserDescr.node `boo2 10 (ParserDescr.parser `tst2)
open Lean.Elab.Term
@[termElab tst] def elabTst : TermElab :=
adaptExpander $ fun stx => match_syntax stx with
| `((| $e |)) => pure e
| _ => throwUnsupportedSyntax
@[termElab boo] def elabBoo : TermElab :=
fun stx expected? =>
elabTerm (stx.getArg 1) expected?
@[termElab boo2] def elabBool2 : TermElab :=
adaptExpander $ fun stx => match_syntax stx with
| `((|| $e ||)) => `($e + 1)
| _ => throwUnsupportedSyntax
#eval runCore "#check [| @id.{1} Nat |]"
#eval runCore "#check (| id 1 |)"
#eval runCore "#check (|| id 1 ||)"
-- #eval run "#check (| id 1, id 1 |)" -- it will fail
@[termElab tst] def elabTst2 : TermElab :=
adaptExpander $ fun stx => match_syntax stx with
| `((| $e1, $e2 |)) => `(($e1, $e2))
| _ => throwUnsupportedSyntax
-- Now both work
#eval runCore "#check (| id 1 |)"
#eval runCore "#check (| id 1, id 2 |)"
declare_syntax_cat foo
syntax "⟨|" term "|⟩" : foo
syntax term : foo
syntax term ">>>" term : foo
syntax [tst3] "FOO " foo : term
macro_rules
| `(FOO ⟨| $t |⟩) => `($t+1)
| `(FOO $t:term) => `($t)
| `(FOO $t:term >>> $r) => `($t * $r)
#check FOO ⟨| id 1 |⟩
#check FOO 1
#check FOO 1 >>> 2
|
888a6aeb46a08211ba036d154bb756b9ead41646
|
097294e9b80f0d9893ac160b9c7219aa135b51b9
|
/assignments/hw4/hw4.lean
|
ccbc686ec788984aaec3dc53705cb5d357314021
|
[] |
no_license
|
AbigailCastro17/CS2102-Discrete-Math
|
cf296251be9418ce90206f5e66bde9163e21abf9
|
d741e4d2d6a9b2e0c8380e51706218b8f608cee4
|
refs/heads/main
| 1,682,891,087,358
| 1,621,401,341,000
| 1,621,401,341,000
| 368,749,959
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 6,371
|
lean
|
/-
Here we import the dm_option type defined in class
from the instructor directory. This line shows how
to include a file from the parent of the parent of
the current directory (one dot = current, two dots
= parent, three = parent of parent), descending into
several subdirectories before finding the file that
we want to import. Leave off the ".lean" extension.
-/
import ...instructor.types.option.dm_option
/- #1
Representing Partial Functions as Total Functions
[20 points]
Consider the strictly partial function, pid, from
natural numbers to natural numbers, defined by cases
as follows. If n is zero, the function is undefined,
otherwise pid n = n. We can't represent this function
directly in Lean, because Lean requires all functions
to be total. The usual approach is to represent such
a partial function as a total function that returns
not a nat (for then it would have to return a nat,
even when the argument is zero) but a value of type
option nat. Use this approach to implement pid in
Lean. Use "by cases" syntax. (Fill in the blanks.)
-/
def pid : _ → _
| _ := _
| _ := _
/- #2
Defining functions by cases (by pattern matching)
[15 points]
Given a value of type option ℕ, the value might be
none or it might be some n, where n is a value of
type ℕ. Write a funtion option_to_nat that takes
any value of type option ℕ as an argument and that
returns a natural number: namely 0 if the option
value is none, and n if the option value is some n.
Write your definition using C-style syntax, with
an explicit return type specified. You will want
to use a "match ... with ... end" expression to do
the required pattern matching.
(Note that it will be impossible to tell from the
return value alone whether a given option was none
or some 0.)
-/
-- ANSWER HERE
/- #3
Inductive definitions.
[15 points]
You have probably yelled into a canyon (or maybe
between two buildings) and heard a reverberating
echo. An echo is a sound followed by another echo,
or, eventually an echo is no sound at all (at which
point the reverberation ends).
Define a data type, echo, values of which represent
echoes. For our purposes, an echo comes in one of
two forms: it is either "silence" (at which point
there is no more reverberation) OR it is a "sound"
followed another echo.
You can think of "silence" as a "base case" and
"sound" as an inductive case, in the sense that
an echo of this form is a sound followed by a
smaller echo. Give each of these cases its own
constructor.
Once you've defined your data type, define e0,
e1, and e3 to be identifiers bound to three values
of this type, where e0 is bound to "silence", e1
is bound to an echo with one sound followed by
silence, and e3 is bound to an echo with three
sounds followed by silence.
-/
-- ANSWERS HERE
/- #4
Lists. A word list type.
[10 points]
Define a data type, list_words_ values of which
represent lists of words, where words are represented
as values of type string. For our purposes, such a
list comes in one of two forms: it is either "nil"
(the word we tend to use for empty lists), or it is
*constructed* from a word followed by a smaller list
of words. Give each form of list its own constructor.
Call the constructors nil and cons.
Once you've defined your data type, define l0,
l1, and l3 to be identifiers bound to three values
of this type, where l0 is bound to an empty list
of words, l1 is bound to a list with one word
(followed by the empty list), and l3 is bound to
a list with three words. We don't care what words
you put in your lists (but be nice :-).
-/
-- ANSWERS HERE
/- #5
Recursive definitions. Length of word list.
[10 points]
Define a function, num_words, that takes a word
list (as just defined) as an argument and that
returns the length of the list as a value of type
ℕ.
-/
/- #6
Recursion. Number of permutations of a set.
[10 points]
Suppose you have a set containing n objects,
where n is a natural number. How many ways are
there to make an ordered list of n objects from
this (unordered) set? Such an ordered list is
called a permutation.
As an example, consider the set, { x, y, z}.
Here are the lists:
- x, y, z
- x, z, y
- y, x, z
- y, z, x
- z, x, y
- z, y, x
It's not too hard to see the answer to the
question. First, if the set is empty, there
is only *one* way to make a list: it is the
empty list. If the list is not empty, there
are n ways to pick the first element of the
list (so in our example, there are three ways
to pick the first element: it has to be x or
y or z); and then what's left is to make the
rest of each list from remaining n-1 (in our
example, 2) elements. So the number of lists
has to be n *times* the number of lists that
can be produced from a set of size n-1.
We can express this idea as a function. Let's
call it the permutations function, or perms,
for short. As we've seen, perms 0 must be one.
This is the base case. Implement the function,
perms: ℕ → ℕ, to compute the number of perms
for a set of any given size, n. Note that in
Lean you'll need to use "by cases" syntax to
define a recursive function.
-/
/- #7
Recursion. Number of subsets of a given set.
[20 points]
How many subsets are there of a set of size
n?
A subset of a set, s, is a set all of whose
elements are in s. So every set is a subset
of itself, and the empty set is a subset of
every set, s (since all of its elements, of
which there are none(!), are in s).
So how many subsets are there of a set of
size n? We can answer this question nicely
using recursion. First, how many subsets are
there of the empty set? It's one, right? If
you don't see this immediately, reread the
preceding explanation.
Now, consider a set, s, of size n, where n
is one more than some number, n'. How many
subsets does s have?
To see the answer, ask the question, how
many subsets does a subset of s of size n'
= (n-1) have? If you have the answer to
that question, then you can easily compute
the number of subsets of s. A set, s', of
size n' must have left out one element of
s, let's call it e. For each subset of s',
you can form *two* subsets of s: one with,
and one without e.
Write a function, power_set_cardinality,
that takes a natural number representing
the size of a set, s, and that then returns
a natural number expressing the number of
subsets there are of a set of that size.
-/
|
d1a5b20df4bf9354477d309337c1cfd331e41f24
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/tactic/omega/term.lean
|
8b48371ce4446c2660f90fb99b6c07da4cc3699e
|
[
"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,734
|
lean
|
/-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Seul Baek
-/
/-
Normalized linear integer arithmetic terms.
-/
import tactic.omega.coeffs
namespace omega
/-- Shadow syntax of normalized terms. The first element
represents the constant term and the list represents
the coefficients. -/
@[derive inhabited]
def term : Type := int × list int
meta instance : has_reflect term := prod.has_reflect _ _
namespace term
/-- Evaluate a term using the valuation v. -/
@[simp] def val (v : nat → int) : term → int
| (b,as) := b + coeffs.val v as
@[simp] def neg : term → term
| (b,as) := (-b, list.func.neg as)
@[simp] def add : term → term → term
| (c1,cfs1) (c2,cfs2) := (c1+c2, list.func.add cfs1 cfs2)
@[simp] def sub : term → term → term
| (c1,cfs1) (c2,cfs2) := (c1 - c2, list.func.sub cfs1 cfs2)
@[simp] def mul (i : int) : term → term
| (b,as) := (i * b, as.map ((*) i))
@[simp] def div (i : int) : term → term
| (b,as) := (b/i, as.map (λ x, x / i))
lemma val_neg {v : nat → int} {t : term} :
(neg t).val v = -(t.val v) :=
begin
cases t with b as,
simp only [val, neg_add, neg, val, coeffs.val_neg]
end
@[simp] lemma val_sub {v : nat → int} {t1 t2 : term} :
(sub t1 t2).val v = t1.val v - t2.val v :=
begin
cases t1, cases t2,
simp only [add_assoc, coeffs.val_sub, neg_add_rev,
val, sub, add_comm, add_left_comm, sub_eq_add_neg]
end
@[simp] lemma val_add {v : nat → int} {t1 t2 : term} :
(add t1 t2).val v = t1.val v + t2.val v :=
begin
cases t1, cases t2,
simp only [coeffs.val_add, add,
val, add_comm, add_left_comm]
end
@[simp] lemma val_mul {v : nat → int} {i : int} {t : term} :
val v (mul i t) = i * (val v t) :=
begin
cases t,
simp only [mul, mul_add, add_mul, list.length_map,
coeffs.val, coeffs.val_between_map_mul, val, list.map]
end
lemma val_div {v : nat → int} {i b : int} {as : list int} :
i ∣ b → (∀ x ∈ as, i ∣ x) → (div i (b,as)).val v = (val v (b,as)) / i :=
begin
intros h1 h2, simp only [val, div, list.map],
rw [int.add_div_of_dvd_left h1],
apply fun_mono_2 rfl,
rw ← coeffs.val_map_div h2
end
/-- Fresh de Brujin index not used by any variable ocurring in the term -/
def fresh_index (t : term) : nat := t.snd.length
def to_string (t : term) : string :=
t.2.enum.foldr (λ ⟨i, n⟩ r,
to_string n ++ " * x" ++ to_string i ++ " + " ++ r) (to_string t.1)
instance : has_to_string term := ⟨to_string⟩
end term
/-- Fresh de Brujin index not used by any variable ocurring in the list of terms -/
def terms.fresh_index : list term → nat
| [] := 0
| (t::ts) := max t.fresh_index (terms.fresh_index ts)
end omega
|
3e38b44f6ff24a555c751a15e35d742cb54dce50
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/755.lean
|
e39bcf6ffe2a14b6b6a8e170aebcc8b76d0ab51c
|
[
"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,204
|
lean
|
def Additive (α : Type) := α
instance [OfNat α 1] : OfNat (Additive α) (nat_lit 0) := ⟨(1 : α)⟩
example : (0 : Nat) = (0 : Additive Nat) := rfl -- Error
def toA (a : Nat) : Additive Nat := a
def Foo (α : Type) := α
instance [OfNat α n] : OfNat (Foo α) n :=
inferInstanceAs (OfNat α n)
instance [HAdd α α α] : HMul (Foo α) (Foo α) (Foo α) where
hMul a b := let a : α := a; let b : α := b; let x : α := a + b; x
instance [HAdd α α α] : HSub (Foo α) (Foo α) (Foo α) where
hSub a b := let a : α := a; let b : α := b; let x : α := a + b; x
instance [HAdd α α α] : HAdd (Foo α) (Foo α) (Foo α) where
hAdd a b := let a : α := a; let b : α := b; let x : α := a + b + a; x
example : (2 : Nat) * (3 : Nat) = (2 : Foo Nat) * (3 : Foo Nat) :=
rfl -- Error
example : (2 : Nat) + (3 : Nat) = (2 : Foo Nat) + (3 : Foo Nat) :=
rfl -- Error
example : (2 : Nat) - (3 : Nat) = (2 : Foo Nat) - (3 : Foo Nat) :=
rfl -- Error
example : (2 : Nat) + (3 : Nat) = (2 : Foo Nat) * (3 : Foo Nat) :=
rfl
example : (2 : Nat) + (3 : Nat) + (2 : Nat) = (2 : Foo Nat) + (3 : Foo Nat) :=
rfl
example : (2 : Nat) + (3 : Nat) = (2 : Foo Nat) - (3 : Foo Nat) :=
rfl
|
fa05502ce317fe4de3a16e23b5f644f1dfdf4445
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/set_theory/ordinal/principal.lean
|
a79c5847169721f3f8ec192de431eed89b00a347
|
[
"Apache-2.0"
] |
permissive
|
alreadydone/mathlib
|
dc0be621c6c8208c581f5170a8216c5ba6721927
|
c982179ec21091d3e102d8a5d9f5fe06c8fafb73
|
refs/heads/master
| 1,685,523,275,196
| 1,670,184,141,000
| 1,670,184,141,000
| 287,574,545
| 0
| 0
|
Apache-2.0
| 1,670,290,714,000
| 1,597,421,623,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 16,464
|
lean
|
/-
Copyright (c) 2022 Violeta Hernández Palacios. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Violeta Hernández Palacios
-/
import set_theory.ordinal.fixed_point
/-!
### Principal ordinals
We define principal or indecomposable ordinals, and we prove the standard properties about them.
### Main definitions and results
* `principal`: A principal or indecomposable ordinal under some binary operation. We include 0 and
any other typically excluded edge cases for simplicity.
* `unbounded_principal`: Principal ordinals are unbounded.
* `principal_add_iff_zero_or_omega_opow`: The main characterization theorem for additive principal
ordinals.
* `principal_mul_iff_le_two_or_omega_opow_opow`: The main characterization theorem for
multiplicative principal ordinals.
### Todo
* Prove that exponential principal ordinals are 0, 1, 2, ω, or epsilon numbers, i.e. fixed points
of `λ x, ω ^ x`.
-/
universe u
noncomputable theory
open order
namespace ordinal
local infixr (name := ordinal.pow) ^ := @pow ordinal ordinal ordinal.has_pow
/-! ### Principal ordinals -/
/-- An ordinal `o` is said to be principal or indecomposable under an operation when the set of
ordinals less than it is closed under that operation. In standard mathematical usage, this term is
almost exclusively used for additive and multiplicative principal ordinals.
For simplicity, we break usual convention and regard 0 as principal. -/
def principal (op : ordinal → ordinal → ordinal) (o : ordinal) : Prop :=
∀ ⦃a b⦄, a < o → b < o → op a b < o
theorem principal_iff_principal_swap {op : ordinal → ordinal → ordinal} {o : ordinal} :
principal op o ↔ principal (function.swap op) o :=
by split; exact λ h a b ha hb, h hb ha
theorem principal_zero {op : ordinal → ordinal → ordinal} : principal op 0 :=
λ a _ h, (ordinal.not_lt_zero a h).elim
@[simp] theorem principal_one_iff {op : ordinal → ordinal → ordinal} :
principal op 1 ↔ op 0 0 = 0 :=
begin
refine ⟨λ h, _, λ h a b ha hb, _⟩,
{ rwa ←lt_one_iff_zero,
exact h zero_lt_one zero_lt_one },
{ rwa [lt_one_iff_zero, ha, hb] at * }
end
theorem principal.iterate_lt {op : ordinal → ordinal → ordinal} {a o : ordinal} (hao : a < o)
(ho : principal op o) (n : ℕ) : (op a)^[n] a < o :=
begin
induction n with n hn,
{ rwa function.iterate_zero },
{ rw function.iterate_succ', exact ho hao hn }
end
theorem op_eq_self_of_principal {op : ordinal → ordinal → ordinal} {a o : ordinal.{u}}
(hao : a < o) (H : is_normal (op a)) (ho : principal op o) (ho' : is_limit o) : op a o = o :=
begin
refine le_antisymm _ (H.self_le _),
rw [←is_normal.bsup_eq.{u u} H ho', bsup_le_iff],
exact λ b hbo, (ho hao hbo).le
end
theorem nfp_le_of_principal {op : ordinal → ordinal → ordinal}
{a o : ordinal} (hao : a < o) (ho : principal op o) : nfp (op a) a ≤ o :=
nfp_le $ λ n, (ho.iterate_lt hao n).le
/-! ### Principal ordinals are unbounded -/
/-- The least strict upper bound of `op` applied to all pairs of ordinals less than `o`. This is
essentially a two-argument version of `ordinal.blsub`. -/
def blsub₂ (op : ordinal → ordinal → ordinal) (o : ordinal) : ordinal :=
lsub (λ x : o.out.α × o.out.α, op (typein (<) x.1) (typein (<) x.2))
theorem lt_blsub₂ (op : ordinal → ordinal → ordinal) {o : ordinal} {a b : ordinal} (ha : a < o)
(hb : b < o) : op a b < blsub₂ op o :=
begin
convert lt_lsub _ (prod.mk (enum (<) a (by rwa type_lt)) (enum (<) b (by rwa type_lt))),
simp only [typein_enum]
end
theorem principal_nfp_blsub₂ (op : ordinal → ordinal → ordinal) (o : ordinal) :
principal op (nfp (blsub₂.{u u} op) o) :=
λ a b ha hb, begin
rw lt_nfp at *,
cases ha with m hm,
cases hb with n hn,
cases le_total ((blsub₂.{u u} op)^[m] o) ((blsub₂.{u u} op)^[n] o) with h h,
{ use n + 1,
rw function.iterate_succ',
exact lt_blsub₂ op (hm.trans_le h) hn },
{ use m + 1,
rw function.iterate_succ',
exact lt_blsub₂ op hm (hn.trans_le h) },
end
theorem unbounded_principal (op : ordinal → ordinal → ordinal) :
set.unbounded (<) {o | principal op o} :=
λ o, ⟨_, principal_nfp_blsub₂ op o, (le_nfp _ o).not_lt⟩
/-! #### Additive principal ordinals -/
theorem principal_add_one : principal (+) 1 :=
principal_one_iff.2 $ zero_add 0
theorem principal_add_of_le_one {o : ordinal} (ho : o ≤ 1) : principal (+) o :=
begin
rcases le_one_iff.1 ho with rfl | rfl,
{ exact principal_zero },
{ exact principal_add_one }
end
theorem principal_add_is_limit {o : ordinal} (ho₁ : 1 < o) (ho : principal (+) o) :
o.is_limit :=
begin
refine ⟨λ ho₀, _, λ a hao, _⟩,
{ rw ho₀ at ho₁,
exact not_lt_of_gt zero_lt_one ho₁ },
{ cases eq_or_ne a 0 with ha ha,
{ rw [ha, succ_zero],
exact ho₁ },
{ refine lt_of_le_of_lt _ (ho hao hao),
rwa [←add_one_eq_succ, add_le_add_iff_left, one_le_iff_ne_zero] } }
end
theorem principal_add_iff_add_left_eq_self {o : ordinal} :
principal (+) o ↔ ∀ a < o, a + o = o :=
begin
refine ⟨λ ho a hao, _, λ h a b hao hbo, _⟩,
{ cases lt_or_le 1 o with ho₁ ho₁,
{ exact op_eq_self_of_principal hao (add_is_normal a) ho (principal_add_is_limit ho₁ ho) },
{ rcases le_one_iff.1 ho₁ with rfl | rfl,
{ exact (ordinal.not_lt_zero a hao).elim },
{ rw lt_one_iff_zero at hao,
rw [hao, zero_add] }}},
{ rw ←h a hao,
exact (add_is_normal a).strict_mono hbo }
end
theorem exists_lt_add_of_not_principal_add {a} (ha : ¬ principal (+) a) :
∃ (b c) (hb : b < a) (hc : c < a), b + c = a :=
begin
unfold principal at ha,
push_neg at ha,
rcases ha with ⟨b, c, hb, hc, H⟩,
refine ⟨b, _, hb, lt_of_le_of_ne (sub_le_self a b) (λ hab, _),
ordinal.add_sub_cancel_of_le hb.le⟩,
rw [←sub_le, hab] at H,
exact H.not_lt hc
end
theorem principal_add_iff_add_lt_ne_self {a} :
principal (+) a ↔ ∀ ⦃b c⦄, b < a → c < a → b + c ≠ a :=
⟨λ ha b c hb hc, (ha hb hc).ne, λ H, begin
by_contra' ha,
rcases exists_lt_add_of_not_principal_add ha with ⟨b, c, hb, hc, rfl⟩,
exact (H hb hc).irrefl
end⟩
theorem add_omega {a : ordinal} (h : a < omega) : a + omega = omega :=
begin
rcases lt_omega.1 h with ⟨n, rfl⟩,
clear h, induction n with n IH,
{ rw [nat.cast_zero, zero_add] },
{ rwa [nat.cast_succ, add_assoc, one_add_of_omega_le (le_refl _)] }
end
theorem principal_add_omega : principal (+) omega :=
principal_add_iff_add_left_eq_self.2 (λ a, add_omega)
theorem add_omega_opow {a b : ordinal} (h : a < omega ^ b) : a + omega ^ b = omega ^ b :=
begin
refine le_antisymm _ (le_add_left _ _),
revert h, refine limit_rec_on b (λ h, _) (λ b _ h, _) (λ b l IH h, _),
{ rw [opow_zero, ← succ_zero, lt_succ_iff, ordinal.le_zero] at h,
rw [h, zero_add] },
{ rw opow_succ at h,
rcases (lt_mul_of_limit omega_is_limit).1 h with ⟨x, xo, ax⟩,
refine le_trans (add_le_add_right (le_of_lt ax) _) _,
rw [opow_succ, ← mul_add, add_omega xo] },
{ rcases (lt_opow_of_limit omega_ne_zero l).1 h with ⟨x, xb, ax⟩,
exact (((add_is_normal a).trans (opow_is_normal one_lt_omega)).limit_le l).2 (λ y yb,
(add_le_add_left (opow_le_opow_right omega_pos (le_max_right _ _)) _).trans
(le_trans (IH _ (max_lt xb yb) (ax.trans_le $ opow_le_opow_right omega_pos (le_max_left _ _)))
(opow_le_opow_right omega_pos $ le_of_lt $ max_lt xb yb))) }
end
theorem principal_add_omega_opow (o : ordinal) : principal (+) (omega ^ o) :=
principal_add_iff_add_left_eq_self.2 (λ a, add_omega_opow)
/-- The main characterization theorem for additive principal ordinals. -/
theorem principal_add_iff_zero_or_omega_opow {o : ordinal} :
principal (+) o ↔ o = 0 ∨ ∃ a, o = omega ^ a :=
begin
rcases eq_or_ne o 0 with rfl | ho,
{ simp only [principal_zero, or.inl] },
{ rw [principal_add_iff_add_left_eq_self],
simp only [ho, false_or],
refine ⟨λ H, ⟨_, ((lt_or_eq_of_le (opow_log_le_self _ ho))
.resolve_left $ λ h, _).symm⟩, λ ⟨b, e⟩, e.symm ▸ λ a, add_omega_opow⟩,
have := H _ h,
have := lt_opow_succ_log_self one_lt_omega o,
rw [opow_succ, lt_mul_of_limit omega_is_limit] at this,
rcases this with ⟨a, ao, h'⟩,
rcases lt_omega.1 ao with ⟨n, rfl⟩, clear ao,
revert h', apply not_lt_of_le,
suffices e : omega ^ log omega o * ↑n + o = o,
{ simpa only [e] using le_add_right (omega ^ log omega o * ↑n) o },
induction n with n IH, {simp only [nat.cast_zero, mul_zero, zero_add]},
simp only [nat.cast_succ, mul_add_one, add_assoc, this, IH] }
end
theorem opow_principal_add_of_principal_add {a} (ha : principal (+) a) (b : ordinal) :
principal (+) (a ^ b) :=
begin
rcases principal_add_iff_zero_or_omega_opow.1 ha with rfl | ⟨c, rfl⟩,
{ rcases eq_or_ne b 0 with rfl | hb,
{ rw opow_zero, exact principal_add_one },
{ rwa zero_opow hb } },
{ rw ←opow_mul, exact principal_add_omega_opow _ }
end
theorem add_absorp {a b c : ordinal} (h₁ : a < omega ^ b) (h₂ : omega ^ b ≤ c) : a + c = c :=
by rw [← ordinal.add_sub_cancel_of_le h₂, ← add_assoc, add_omega_opow h₁]
theorem mul_principal_add_is_principal_add (a : ordinal.{u}) {b : ordinal.{u}} (hb₁ : b ≠ 1)
(hb : principal (+) b) : principal (+) (a * b) :=
begin
rcases eq_zero_or_pos a with rfl | ha,
{ rw zero_mul,
exact principal_zero },
{ rcases eq_zero_or_pos b with rfl | hb₁',
{ rw mul_zero,
exact principal_zero },
{ rw [← succ_le_iff, succ_zero] at hb₁',
intros c d hc hd,
rw lt_mul_of_limit (principal_add_is_limit (lt_of_le_of_ne hb₁' hb₁.symm) hb) at *,
{ rcases hc with ⟨x, hx, hx'⟩,
rcases hd with ⟨y, hy, hy'⟩,
use [x + y, hb hx hy],
rw mul_add,
exact left.add_lt_add hx' hy' },
assumption' } }
end
/-! #### Multiplicative principal ordinals -/
theorem principal_mul_one : principal (*) 1 :=
by { rw principal_one_iff, exact zero_mul _ }
theorem principal_mul_two : principal (*) 2 :=
λ a b ha hb, begin
have h₂ : succ (1 : ordinal) = 2 := rfl,
rw [←h₂, lt_succ_iff] at *,
convert mul_le_mul' ha hb,
exact (mul_one 1).symm
end
theorem principal_mul_of_le_two {o : ordinal} (ho : o ≤ 2) : principal (*) o :=
begin
rcases lt_or_eq_of_le ho with ho | rfl,
{ have h₂ : succ (1 : ordinal) = 2 := rfl,
rw [←h₂, lt_succ_iff] at ho,
rcases lt_or_eq_of_le ho with ho | rfl,
{ rw lt_one_iff_zero.1 ho,
exact principal_zero },
{ exact principal_mul_one } },
{ exact principal_mul_two }
end
theorem principal_add_of_principal_mul {o : ordinal} (ho : principal (*) o) (ho₂ : o ≠ 2) :
principal (+) o :=
begin
cases lt_or_gt_of_ne ho₂ with ho₁ ho₂,
{ change o < succ 1 at ho₁,
rw lt_succ_iff at ho₁,
exact principal_add_of_le_one ho₁ },
{ refine λ a b hao hbo, lt_of_le_of_lt _ (ho (max_lt hao hbo) ho₂),
rw mul_two,
exact add_le_add (le_max_left a b) (le_max_right a b) }
end
theorem principal_mul_is_limit {o : ordinal.{u}} (ho₂ : 2 < o) (ho : principal (*) o) :
o.is_limit :=
principal_add_is_limit
((lt_succ 1).trans ho₂)
(principal_add_of_principal_mul ho (ne_of_gt ho₂))
theorem principal_mul_iff_mul_left_eq {o : ordinal} :
principal (*) o ↔ ∀ a, 0 < a → a < o → a * o = o :=
begin
refine ⟨λ h a ha₀ hao, _, λ h a b hao hbo, _⟩,
{ cases le_or_gt o 2 with ho ho,
{ convert one_mul o,
apply le_antisymm,
{ have : a < succ 1 := hao.trans_le ho,
rwa lt_succ_iff at this },
{ rwa [←succ_le_iff, succ_zero] at ha₀ } },
{ exact op_eq_self_of_principal hao (mul_is_normal ha₀) h (principal_mul_is_limit ho h) } },
{ rcases eq_or_ne a 0 with rfl | ha, { rwa zero_mul },
rw ←ordinal.pos_iff_ne_zero at ha,
rw ←h a ha hao,
exact (mul_is_normal ha).strict_mono hbo }
end
theorem principal_mul_omega : principal (*) omega :=
λ a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by { rw [← nat_cast_mul], apply nat_lt_omega }
end
theorem mul_omega {a : ordinal} (a0 : 0 < a) (ha : a < omega) : a * omega = omega :=
principal_mul_iff_mul_left_eq.1 (principal_mul_omega) a a0 ha
theorem mul_lt_omega_opow {a b c : ordinal}
(c0 : 0 < c) (ha : a < omega ^ c) (hb : b < omega) : a * b < omega ^ c :=
begin
rcases zero_or_succ_or_limit c with rfl|⟨c,rfl⟩|l,
{ exact (lt_irrefl _).elim c0 },
{ rw opow_succ at ha,
rcases ((mul_is_normal $ opow_pos _ omega_pos).limit_lt
omega_is_limit).1 ha with ⟨n, hn, an⟩,
apply (mul_le_mul_right' (le_of_lt an) _).trans_lt,
rw [opow_succ, mul_assoc, mul_lt_mul_iff_left (opow_pos _ omega_pos)],
exact principal_mul_omega hn hb },
{ rcases ((opow_is_normal one_lt_omega).limit_lt l).1 ha with ⟨x, hx, ax⟩,
refine (mul_le_mul' (le_of_lt ax) (le_of_lt hb)).trans_lt _,
rw [← opow_succ, opow_lt_opow_iff_right one_lt_omega],
exact l.2 _ hx }
end
theorem mul_omega_opow_opow {a b : ordinal} (a0 : 0 < a) (h : a < omega ^ omega ^ b) :
a * omega ^ omega ^ b = omega ^ omega ^ b :=
begin
by_cases b0 : b = 0, {rw [b0, opow_zero, opow_one] at h ⊢, exact mul_omega a0 h},
refine le_antisymm _
(by simpa only [one_mul] using mul_le_mul_right' (one_le_iff_pos.2 a0) (omega ^ omega ^ b)),
rcases (lt_opow_of_limit omega_ne_zero (opow_is_limit_left omega_is_limit b0)).1 h
with ⟨x, xb, ax⟩,
apply (mul_le_mul_right' (le_of_lt ax) _).trans,
rw [← opow_add, add_omega_opow xb]
end
theorem principal_mul_omega_opow_opow (o : ordinal) : principal (*) (omega ^ omega ^ o) :=
principal_mul_iff_mul_left_eq.2 (λ a, mul_omega_opow_opow)
theorem principal_add_of_principal_mul_opow {o b : ordinal} (hb : 1 < b)
(ho : principal (*) (b ^ o)) : principal (+) o :=
λ x y hx hy, begin
have := ho ((opow_lt_opow_iff_right hb).2 hx) ((opow_lt_opow_iff_right hb).2 hy),
rwa [←opow_add, opow_lt_opow_iff_right hb] at this
end
/-- The main characterization theorem for multiplicative principal ordinals. -/
theorem principal_mul_iff_le_two_or_omega_opow_opow {o : ordinal} :
principal (*) o ↔ o ≤ 2 ∨ ∃ a, o = omega ^ omega ^ a :=
begin
refine ⟨λ ho, _, _⟩,
{ cases le_or_lt o 2 with ho₂ ho₂,
{ exact or.inl ho₂ },
rcases principal_add_iff_zero_or_omega_opow.1 (principal_add_of_principal_mul ho ho₂.ne')
with rfl | ⟨a, rfl⟩,
{ exact (ordinal.not_lt_zero 2 ho₂).elim },
rcases principal_add_iff_zero_or_omega_opow.1
(principal_add_of_principal_mul_opow one_lt_omega ho) with rfl | ⟨b, rfl⟩,
{ rw opow_zero at ho₂,
exact ((lt_succ 1).not_le ho₂.le).elim },
exact or.inr ⟨b, rfl⟩ },
{ rintro (ho₂ | ⟨a, rfl⟩),
{ exact principal_mul_of_le_two ho₂ },
{ exact principal_mul_omega_opow_opow a } }
end
theorem mul_omega_dvd {a : ordinal}
(a0 : 0 < a) (ha : a < omega) : ∀ {b}, omega ∣ b → a * b = b
| _ ⟨b, rfl⟩ := by rw [← mul_assoc, mul_omega a0 ha]
theorem mul_eq_opow_log_succ {a b : ordinal.{u}} (ha : a ≠ 0) (hb : principal (*) b) (hb₂ : 2 < b) :
a * b = b ^ succ (log b a) :=
begin
apply le_antisymm,
{ have hbl := principal_mul_is_limit hb₂ hb,
rw [←is_normal.bsup_eq.{u u} (mul_is_normal (ordinal.pos_iff_ne_zero.2 ha)) hbl, bsup_le_iff],
intros c hcb,
have hb₁ : 1 < b := (lt_succ 1).trans hb₂,
have hbo₀ : b ^ b.log a ≠ 0 := ordinal.pos_iff_ne_zero.1 (opow_pos _ (zero_lt_one.trans hb₁)),
apply le_trans (mul_le_mul_right' (le_of_lt (lt_mul_succ_div a hbo₀)) c),
rw [mul_assoc, opow_succ],
refine mul_le_mul_left' (le_of_lt (hb (hbl.2 _ _) hcb)) _,
rw [div_lt hbo₀, ←opow_succ],
exact lt_opow_succ_log_self hb₁ _ },
{ rw opow_succ,
exact mul_le_mul_right' (opow_log_le_self b ha) b }
end
/-! #### Exponential principal ordinals -/
theorem principal_opow_omega : principal (^) omega :=
λ a b ha hb, match a, b, lt_omega.1 ha, lt_omega.1 hb with
| _, _, ⟨m, rfl⟩, ⟨n, rfl⟩ := by { simp_rw ←nat_cast_opow, apply nat_lt_omega }
end
theorem opow_omega {a : ordinal} (a1 : 1 < a) (h : a < omega) : a ^ omega = omega :=
le_antisymm
((opow_le_of_limit (one_le_iff_ne_zero.1 $ le_of_lt a1) omega_is_limit).2
(λ b hb, (principal_opow_omega h hb).le))
(right_le_opow _ a1)
end ordinal
|
f765a0e7179236a279fb5d3a0f265708d4fb8455
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/group_theory/finiteness.lean
|
f6f9f4f4390687ec2cc1f3f1df591d2e77f3c904
|
[
"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
| 9,980
|
lean
|
/-
Copyright (c) 2021 Riccardo Brasca. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Riccardo Brasca
-/
import data.set.finite
import data.finset
import group_theory.submonoid.operations
import group_theory.subgroup.basic
/-!
# Finitely generated monoids and groups
We define finitely generated monoids and groups. See also `submodule.fg` and `module.finite` for
finitely-generated modules.
## Main definition
* `submonoid.fg S`, `add_submonoid.fg S` : A submonoid `S` is finitely generated.
* `monoid.fg M`, `add_monoid.fg M` : A typeclass indicating a type `M` is finitely generated as a
monoid.
* `subgroup.fg S`, `add_subgroup.fg S` : A subgroup `S` is finitely generated.
* `group.fg M`, `add_group.fg M` : A typeclass indicating a type `M` is finitely generated as a
group.
-/
/-! ### Monoids and submonoids -/
open_locale pointwise
variables {M N : Type*} [monoid M] [add_monoid N]
section submonoid
/-- A submonoid of `M` is finitely generated if it is the closure of a finite subset of `M`. -/
@[to_additive]
def submonoid.fg (P : submonoid M) : Prop := ∃ S : finset M, submonoid.closure ↑S = P
/-- An additive submonoid of `N` is finitely generated if it is the closure of a finite subset of
`M`. -/
add_decl_doc add_submonoid.fg
/-- An equivalent expression of `submonoid.fg` in terms of `set.finite` instead of `finset`. -/
@[to_additive "An equivalent expression of `add_submonoid.fg` in terms of `set.finite` instead of
`finset`."]
lemma submonoid.fg_iff (P : submonoid M) : submonoid.fg P ↔
∃ S : set M, submonoid.closure S = P ∧ S.finite :=
⟨λ ⟨S, hS⟩, ⟨S, hS, finset.finite_to_set S⟩, λ ⟨S, hS, hf⟩, ⟨set.finite.to_finset hf, by simp [hS]⟩⟩
lemma submonoid.fg_iff_add_fg (P : submonoid M) : P.fg ↔ P.to_add_submonoid.fg :=
⟨λ h, let ⟨S, hS, hf⟩ := (submonoid.fg_iff _).1 h in (add_submonoid.fg_iff _).mpr
⟨additive.to_mul ⁻¹' S, by simp [← submonoid.to_add_submonoid_closure, hS], hf⟩,
λ h, let ⟨T, hT, hf⟩ := (add_submonoid.fg_iff _).1 h in (submonoid.fg_iff _).mpr
⟨multiplicative.of_add ⁻¹' T, by simp [← add_submonoid.to_submonoid'_closure, hT], hf⟩⟩
lemma add_submonoid.fg_iff_mul_fg (P : add_submonoid N) : P.fg ↔ P.to_submonoid.fg :=
begin
convert (submonoid.fg_iff_add_fg P.to_submonoid).symm,
exact set_like.ext' rfl
end
end submonoid
section monoid
variables (M N)
/-- A monoid is finitely generated if it is finitely generated as a submonoid of itself. -/
class monoid.fg : Prop := (out : (⊤ : submonoid M).fg)
/-- An additive monoid is finitely generated if it is finitely generated as an additive submonoid of
itself. -/
class add_monoid.fg : Prop := (out : (⊤ : add_submonoid N).fg)
attribute [to_additive] monoid.fg
variables {M N}
lemma monoid.fg_def : monoid.fg M ↔ (⊤ : submonoid M).fg := ⟨λ h, h.1, λ h, ⟨h⟩⟩
lemma add_monoid.fg_def : add_monoid.fg N ↔ (⊤ : add_submonoid N).fg := ⟨λ h, h.1, λ h, ⟨h⟩⟩
/-- An equivalent expression of `monoid.fg` in terms of `set.finite` instead of `finset`. -/
@[to_additive "An equivalent expression of `add_monoid.fg` in terms of `set.finite` instead of
`finset`."]
lemma monoid.fg_iff : monoid.fg M ↔
∃ S : set M, submonoid.closure S = (⊤ : submonoid M) ∧ S.finite :=
⟨λ h, (submonoid.fg_iff ⊤).1 h.out, λ h, ⟨(submonoid.fg_iff ⊤).2 h⟩⟩
lemma monoid.fg_iff_add_fg : monoid.fg M ↔ add_monoid.fg (additive M) :=
⟨λ h, ⟨(submonoid.fg_iff_add_fg ⊤).1 h.out⟩, λ h, ⟨(submonoid.fg_iff_add_fg ⊤).2 h.out⟩⟩
lemma add_monoid.fg_iff_mul_fg : add_monoid.fg N ↔ monoid.fg (multiplicative N) :=
⟨λ h, ⟨(add_submonoid.fg_iff_mul_fg ⊤).1 h.out⟩, λ h, ⟨(add_submonoid.fg_iff_mul_fg ⊤).2 h.out⟩⟩
instance add_monoid.fg_of_monoid_fg [monoid.fg M] : add_monoid.fg (additive M) :=
monoid.fg_iff_add_fg.1 ‹_›
instance monoid.fg_of_add_monoid_fg [add_monoid.fg N] : monoid.fg (multiplicative N) :=
add_monoid.fg_iff_mul_fg.1 ‹_›
end monoid
@[to_additive]
lemma submonoid.fg.map {M' : Type*} [monoid M'] {P : submonoid M} (h : P.fg) (e : M →* M') :
(P.map e).fg :=
begin
classical,
obtain ⟨s, rfl⟩ := h,
exact ⟨s.image e, by rw [finset.coe_image, monoid_hom.map_mclosure]⟩
end
@[to_additive]
lemma submonoid.fg.map_injective {M' : Type*} [monoid M'] {P : submonoid M}
(e : M →* M') (he : function.injective e) (h : (P.map e).fg) : P.fg :=
begin
obtain ⟨s, hs⟩ := h,
use s.preimage e (he.inj_on _),
apply submonoid.map_injective_of_injective he,
rw [← hs, e.map_mclosure, finset.coe_preimage],
congr,
rw [set.image_preimage_eq_iff, ← e.coe_mrange, ← submonoid.closure_le, hs, e.mrange_eq_map],
exact submonoid.monotone_map le_top
end
@[simp, to_additive]
lemma monoid.fg_iff_submonoid_fg (N : submonoid M) : monoid.fg N ↔ N.fg :=
begin
conv_rhs { rw [← N.range_subtype, monoid_hom.mrange_eq_map] },
exact ⟨λ h, h.out.map N.subtype, λ h, ⟨h.map_injective N.subtype subtype.coe_injective⟩⟩
end
@[to_additive]
lemma monoid.fg_of_surjective {M' : Type*} [monoid M'] [monoid.fg M]
(f : M →* M') (hf : function.surjective f) : monoid.fg M' :=
begin
classical,
obtain ⟨s, hs⟩ := monoid.fg_def.mp ‹_›,
use s.image f,
rwa [finset.coe_image, ← monoid_hom.map_mclosure, hs, ← monoid_hom.mrange_eq_map,
monoid_hom.mrange_top_iff_surjective],
end
@[to_additive]
lemma submonoid.powers_fg (r : M) : (submonoid.powers r).fg :=
⟨{r}, (finset.coe_singleton r).symm ▸ (submonoid.powers_eq_closure r).symm⟩
@[to_additive]
instance (r : M) : monoid.fg (submonoid.powers r) :=
(monoid.fg_iff_submonoid_fg _).mpr (submonoid.powers_fg r)
/-! ### Groups and subgroups -/
variables {G H : Type*} [group G] [add_group H]
section subgroup
/-- A subgroup of `G` is finitely generated if it is the closure of a finite subset of `G`. -/
@[to_additive]
def subgroup.fg (P : subgroup G) : Prop := ∃ S : finset G, subgroup.closure ↑S = P
/-- An additive subgroup of `H` is finitely generated if it is the closure of a finite subset of
`H`. -/
add_decl_doc add_subgroup.fg
/-- An equivalent expression of `subgroup.fg` in terms of `set.finite` instead of `finset`. -/
@[to_additive "An equivalent expression of `add_subgroup.fg` in terms of `set.finite` instead of
`finset`."]
lemma subgroup.fg_iff (P : subgroup G) : subgroup.fg P ↔
∃ S : set G, subgroup.closure S = P ∧ S.finite :=
⟨λ⟨S, hS⟩, ⟨S, hS, finset.finite_to_set S⟩, λ⟨S, hS, hf⟩, ⟨set.finite.to_finset hf, by simp [hS]⟩⟩
/-- A subgroup is finitely generated if and only if it is finitely generated as a submonoid. -/
@[to_additive add_subgroup.fg_iff_add_submonoid.fg "An additive subgroup is finitely generated if
and only if it is finitely generated as an additive submonoid."]
lemma subgroup.fg_iff_submonoid_fg (P : subgroup G) : P.fg ↔ P.to_submonoid.fg :=
begin
split,
{ rintro ⟨S, rfl⟩,
rw submonoid.fg_iff,
refine ⟨S ∪ S⁻¹, _, S.finite_to_set.union S.finite_to_set.inv⟩,
exact (subgroup.closure_to_submonoid _).symm },
{ rintro ⟨S, hS⟩,
refine ⟨S, le_antisymm _ _⟩,
{ rw [subgroup.closure_le, ←subgroup.coe_to_submonoid, ←hS],
exact submonoid.subset_closure },
{ rw [← subgroup.to_submonoid_le, ← hS, submonoid.closure_le],
exact subgroup.subset_closure } }
end
lemma subgroup.fg_iff_add_fg (P : subgroup G) : P.fg ↔ P.to_add_subgroup.fg :=
begin
rw [subgroup.fg_iff_submonoid_fg, add_subgroup.fg_iff_add_submonoid.fg],
exact (subgroup.to_submonoid P).fg_iff_add_fg
end
lemma add_subgroup.fg_iff_mul_fg (P : add_subgroup H) :
P.fg ↔ P.to_subgroup.fg :=
begin
rw [add_subgroup.fg_iff_add_submonoid.fg, subgroup.fg_iff_submonoid_fg],
exact add_submonoid.fg_iff_mul_fg (add_subgroup.to_add_submonoid P)
end
end subgroup
section group
variables (G H)
/-- A group is finitely generated if it is finitely generated as a submonoid of itself. -/
class group.fg : Prop := (out : (⊤ : subgroup G).fg)
/-- An additive group is finitely generated if it is finitely generated as an additive submonoid of
itself. -/
class add_group.fg : Prop := (out : (⊤ : add_subgroup H).fg)
attribute [to_additive] group.fg
variables {G H}
lemma group.fg_def : group.fg G ↔ (⊤ : subgroup G).fg := ⟨λ h, h.1, λ h, ⟨h⟩⟩
lemma add_group.fg_def : add_group.fg H ↔ (⊤ : add_subgroup H).fg := ⟨λ h, h.1, λ h, ⟨h⟩⟩
/-- An equivalent expression of `group.fg` in terms of `set.finite` instead of `finset`. -/
@[to_additive "An equivalent expression of `add_group.fg` in terms of `set.finite` instead of
`finset`."]
lemma group.fg_iff : group.fg G ↔
∃ S : set G, subgroup.closure S = (⊤ : subgroup G) ∧ S.finite :=
⟨λ h, (subgroup.fg_iff ⊤).1 h.out, λ h, ⟨(subgroup.fg_iff ⊤).2 h⟩⟩
/-- A group is finitely generated if and only if it is finitely generated as a monoid. -/
@[to_additive add_group.fg_iff_add_monoid.fg "An additive group is finitely generated if and only
if it is finitely generated as an additive monoid."]
lemma group.fg_iff_monoid.fg : group.fg G ↔ monoid.fg G :=
⟨λ h, monoid.fg_def.2 $ (subgroup.fg_iff_submonoid_fg ⊤).1 (group.fg_def.1 h),
λ h, group.fg_def.2 $ (subgroup.fg_iff_submonoid_fg ⊤).2 (monoid.fg_def.1 h)⟩
lemma group_fg.iff_add_fg : group.fg G ↔ add_group.fg (additive G) :=
⟨λ h, ⟨(subgroup.fg_iff_add_fg ⊤).1 h.out⟩, λ h, ⟨(subgroup.fg_iff_add_fg ⊤).2 h.out⟩⟩
lemma add_group.fg_iff_mul_fg : add_group.fg H ↔ group.fg (multiplicative H) :=
⟨λ h, ⟨(add_subgroup.fg_iff_mul_fg ⊤).1 h.out⟩, λ h, ⟨(add_subgroup.fg_iff_mul_fg ⊤).2 h.out⟩⟩
instance add_group.fg_of_group_fg [group.fg G] : add_group.fg (additive G) :=
group_fg.iff_add_fg.1 ‹_›
instance group.fg_of_mul_group_fg [add_group.fg H] : group.fg (multiplicative H) :=
add_group.fg_iff_mul_fg.1 ‹_›
end group
|
56b021b12f0378fa8553e96f45c8c9d3b7c4f6b1
|
8b9f17008684d796c8022dab552e42f0cb6fb347
|
/hott/init/logic.hlean
|
348fdc4f5d66cc8c130e27d889d7b9c04a69ed42
|
[
"Apache-2.0"
] |
permissive
|
chubbymaggie/lean
|
0d06ae25f9dd396306fb02190e89422ea94afd7b
|
d2c7b5c31928c98f545b16420d37842c43b4ae9a
|
refs/heads/master
| 1,611,313,622,901
| 1,430,266,839,000
| 1,430,267,083,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 11,773
|
hlean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: init.logic
Authors: Leonardo de Moura
-/
prelude
import init.datatypes init.reserved_notation
definition not.{l} (a : Type.{l}) := a → empty.{l}
prefix `¬` := not
definition absurd {a : Type} {b : Type} (H₁ : a) (H₂ : ¬a) : b :=
empty.rec (λ e, b) (H₂ H₁)
definition mt {a b : Type} (H₁ : a → b) (H₂ : ¬b) : ¬a :=
assume Ha : a, absurd (H₁ Ha) H₂
/- not -/
protected definition not_empty : ¬ empty :=
assume H : empty, H
definition not_not_intro {a : Type} (Ha : a) : ¬¬a :=
assume Hna : ¬a, absurd Ha Hna
definition not.intro {a : Type} (H : a → empty) : ¬a := H
definition not.elim {a : Type} (H₁ : ¬a) (H₂ : a) : empty := H₁ H₂
definition not_not_of_not_implies {a b : Type} (H : ¬(a → b)) : ¬¬a :=
assume Hna : ¬a, absurd (assume Ha : a, absurd Ha Hna) H
definition not_of_not_implies {a b : Type} (H : ¬(a → b)) : ¬b :=
assume Hb : b, absurd (assume Ha : a, Hb) H
/- eq -/
notation a = b := eq a b
definition rfl {A : Type} {a : A} := eq.refl a
namespace eq
variables {A : Type}
variables {a b c a' : A}
definition subst {P : A → Type} (H₁ : a = b) (H₂ : P a) : P b :=
eq.rec H₂ H₁
definition trans (H₁ : a = b) (H₂ : b = c) : a = c :=
subst H₂ H₁
definition symm (H : a = b) : b = a :=
subst H (refl a)
namespace ops
notation H `⁻¹` := symm H --input with \sy or \-1 or \inv
notation H1 ⬝ H2 := trans H1 H2
notation H1 ▸ H2 := subst H1 H2
end ops
end eq
section
variables {A : Type} {a b c: A}
open eq.ops
definition trans_rel_left (R : A → A → Type) (H₁ : R a b) (H₂ : b = c) : R a c :=
H₂ ▸ H₁
definition trans_rel_right (R : A → A → Type) (H₁ : a = b) (H₂ : R b c) : R a c :=
H₁⁻¹ ▸ H₂
end
calc_subst eq.subst
calc_refl eq.refl
calc_trans eq.trans
calc_symm eq.symm
namespace lift
definition down_up.{l₁ l₂} {A : Type.{l₁}} (a : A) : down (up.{l₁ l₂} a) = a :=
rfl
definition up_down.{l₁ l₂} {A : Type.{l₁}} (a : lift.{l₁ l₂} A) : up (down a) = a :=
lift.rec_on a (λ d, rfl)
end lift
/- ne -/
definition ne {A : Type} (a b : A) := ¬(a = b)
notation a ≠ b := ne a b
namespace ne
open eq.ops
variable {A : Type}
variables {a b : A}
definition intro : (a = b → empty) → a ≠ b :=
assume H, H
definition elim : a ≠ b → a = b → empty :=
assume H₁ H₂, H₁ H₂
definition irrefl : a ≠ a → empty :=
assume H, H rfl
definition symm : a ≠ b → b ≠ a :=
assume (H : a ≠ b) (H₁ : b = a), H H₁⁻¹
end ne
section
open eq.ops
variables {A : Type} {a b c : A}
definition false.of_ne : a ≠ a → empty :=
assume H, H rfl
definition ne.of_eq_of_ne : a = b → b ≠ c → a ≠ c :=
assume H₁ H₂, H₁⁻¹ ▸ H₂
definition ne.of_ne_of_eq : a ≠ b → b = c → a ≠ c :=
assume H₁ H₂, H₂ ▸ H₁
end
calc_trans ne.of_eq_of_ne
calc_trans ne.of_ne_of_eq
/- iff -/
definition iff (a b : Type) := prod (a → b) (b → a)
notation a <-> b := iff a b
notation a ↔ b := iff a b
namespace iff
variables {a b c : Type}
definition def : (a ↔ b) = (prod (a → b) (b → a)) :=
rfl
definition intro (H₁ : a → b) (H₂ : b → a) : a ↔ b :=
prod.mk H₁ H₂
definition elim (H₁ : (a → b) → (b → a) → c) (H₂ : a ↔ b) : c :=
prod.rec H₁ H₂
definition elim_left (H : a ↔ b) : a → b :=
elim (assume H₁ H₂, H₁) H
definition mp := @elim_left
definition elim_right (H : a ↔ b) : b → a :=
elim (assume H₁ H₂, H₂) H
definition flip_sign (H₁ : a ↔ b) : ¬a ↔ ¬b :=
intro
(assume Hna, mt (elim_right H₁) Hna)
(assume Hnb, mt (elim_left H₁) Hnb)
definition refl (a : Type) : a ↔ a :=
intro (assume H, H) (assume H, H)
definition rfl {a : Type} : a ↔ a :=
refl a
definition trans (H₁ : a ↔ b) (H₂ : b ↔ c) : a ↔ c :=
intro
(assume Ha, elim_left H₂ (elim_left H₁ Ha))
(assume Hc, elim_right H₁ (elim_right H₂ Hc))
definition symm (H : a ↔ b) : b ↔ a :=
intro
(assume Hb, elim_right H Hb)
(assume Ha, elim_left H Ha)
definition true_elim (H : a ↔ unit) : a :=
mp (symm H) unit.star
definition false_elim (H : a ↔ empty) : ¬a :=
assume Ha : a, mp H Ha
open eq.ops
definition of_eq {a b : Type} (H : a = b) : a ↔ b :=
iff.intro (λ Ha, H ▸ Ha) (λ Hb, H⁻¹ ▸ Hb)
end iff
calc_refl iff.refl
calc_trans iff.trans
/- inhabited -/
inductive inhabited [class] (A : Type) : Type :=
mk : A → inhabited A
namespace inhabited
protected definition destruct {A : Type} {B : Type} (H1 : inhabited A) (H2 : A → B) : B :=
inhabited.rec H2 H1
definition inhabited_fun [instance] (A : Type) {B : Type} [H : inhabited B] : inhabited (A → B) :=
destruct H (λb, mk (λa, b))
definition inhabited_Pi [instance] (A : Type) {B : A → Type} [H : Πx, inhabited (B x)] :
inhabited (Πx, B x) :=
mk (λa, destruct (H a) (λb, b))
definition default (A : Type) [H : inhabited A] : A := destruct H (take a, a)
end inhabited
/- decidable -/
inductive decidable.{l} [class] (p : Type.{l}) : Type.{l} :=
| inl : p → decidable p
| inr : ¬p → decidable p
namespace decidable
variables {p q : Type}
definition pos_witness [C : decidable p] (H : p) : p :=
decidable.rec_on C (λ Hp, Hp) (λ Hnp, absurd H Hnp)
definition neg_witness [C : decidable p] (H : ¬ p) : ¬ p :=
decidable.rec_on C (λ Hp, absurd Hp H) (λ Hnp, Hnp)
definition by_cases {q : Type} [C : decidable p] (Hpq : p → q) (Hnpq : ¬p → q) : q :=
decidable.rec_on C (assume Hp, Hpq Hp) (assume Hnp, Hnpq Hnp)
definition em (p : Type) [H : decidable p] : sum p ¬p :=
by_cases (λ Hp, sum.inl Hp) (λ Hnp, sum.inr Hnp)
definition by_contradiction [Hp : decidable p] (H : ¬p → empty) : p :=
by_cases
(assume H₁ : p, H₁)
(assume H₁ : ¬p, empty.rec (λ e, p) (H H₁))
definition decidable_iff_equiv (Hp : decidable p) (H : p ↔ q) : decidable q :=
decidable.rec_on Hp
(assume Hp : p, inl (iff.elim_left H Hp))
(assume Hnp : ¬p, inr (iff.elim_left (iff.flip_sign H) Hnp))
definition decidable_eq_equiv.{l} {p q : Type.{l}} (Hp : decidable p) (H : p = q) : decidable q :=
decidable_iff_equiv Hp (iff.of_eq H)
end decidable
section
variables {p q : Type}
open decidable (rec_on inl inr)
definition decidable_unit [instance] : decidable unit :=
inl unit.star
definition decidable_empty [instance] : decidable empty :=
inr not_empty
definition decidable_prod [instance] [Hp : decidable p] [Hq : decidable q] : decidable (prod p q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (prod.mk Hp Hq))
(assume Hnq : ¬q, inr (λ H : prod p q, prod.rec_on H (λ Hp Hq, absurd Hq Hnq))))
(assume Hnp : ¬p, inr (λ H : prod p q, prod.rec_on H (λ Hp Hq, absurd Hp Hnp)))
definition decidable_sum [instance] [Hp : decidable p] [Hq : decidable q] : decidable (sum p q) :=
rec_on Hp
(assume Hp : p, inl (sum.inl Hp))
(assume Hnp : ¬p, rec_on Hq
(assume Hq : q, inl (sum.inr Hq))
(assume Hnq : ¬q, inr (λ H : sum p q, sum.rec_on H (λ Hp, absurd Hp Hnp) (λ Hq, absurd Hq Hnq))))
definition decidable_not [instance] [Hp : decidable p] : decidable (¬p) :=
rec_on Hp
(assume Hp, inr (not_not_intro Hp))
(assume Hnp, inl Hnp)
definition decidable_implies [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p → q) :=
rec_on Hp
(assume Hp : p, rec_on Hq
(assume Hq : q, inl (assume H, Hq))
(assume Hnq : ¬q, inr (assume H : p → q, absurd (H Hp) Hnq)))
(assume Hnp : ¬p, inl (assume Hp, absurd Hp Hnp))
definition decidable_if [instance] [Hp : decidable p] [Hq : decidable q] : decidable (p ↔ q) :=
show decidable (prod (p → q) (q → p)), from _
end
definition decidable_pred [reducible] {A : Type} (R : A → Type) := Π (a : A), decidable (R a)
definition decidable_rel [reducible] {A : Type} (R : A → A → Type) := Π (a b : A), decidable (R a b)
definition decidable_eq [reducible] (A : Type) := decidable_rel (@eq A)
definition decidable_ne [instance] {A : Type} [H : decidable_eq A] : decidable_rel (@ne A) :=
show ∀ x y : A, decidable (x = y → empty), from _
definition ite (c : Type) [H : decidable c] {A : Type} (t e : A) : A :=
decidable.rec_on H (λ Hc, t) (λ Hnc, e)
definition if_pos {c : Type} [H : decidable c] (Hc : c) {A : Type} {t e : A} : (if c then t else e) = t :=
decidable.rec
(λ Hc : c, eq.refl (@ite c (decidable.inl Hc) A t e))
(λ Hnc : ¬c, absurd Hc Hnc)
H
definition if_neg {c : Type} [H : decidable c] (Hnc : ¬c) {A : Type} {t e : A} : (if c then t else e) = e :=
decidable.rec
(λ Hc : c, absurd Hc Hnc)
(λ Hnc : ¬c, eq.refl (@ite c (decidable.inr Hnc) A t e))
H
definition if_t_t (c : Type) [H : decidable c] {A : Type} (t : A) : (if c then t else t) = t :=
decidable.rec
(λ Hc : c, eq.refl (@ite c (decidable.inl Hc) A t t))
(λ Hnc : ¬c, eq.refl (@ite c (decidable.inr Hnc) A t t))
H
definition if_unit {A : Type} (t e : A) : (if unit then t else e) = t :=
if_pos unit.star
definition if_empty {A : Type} (t e : A) : (if empty then t else e) = e :=
if_neg not_empty
section
open eq.ops
definition if_cond_congr {c₁ c₂ : Type} [H₁ : decidable c₁] [H₂ : decidable c₂] (Heq : c₁ ↔ c₂) {A : Type} (t e : A)
: (if c₁ then t else e) = (if c₂ then t else e) :=
decidable.rec_on H₁
(λ Hc₁ : c₁, decidable.rec_on H₂
(λ Hc₂ : c₂, if_pos Hc₁ ⬝ (if_pos Hc₂)⁻¹)
(λ Hnc₂ : ¬c₂, absurd (iff.elim_left Heq Hc₁) Hnc₂))
(λ Hnc₁ : ¬c₁, decidable.rec_on H₂
(λ Hc₂ : c₂, absurd (iff.elim_right Heq Hc₂) Hnc₁)
(λ Hnc₂ : ¬c₂, if_neg Hnc₁ ⬝ (if_neg Hnc₂)⁻¹))
definition if_congr_aux {c₁ c₂ : Type} [H₁ : decidable c₁] [H₂ : decidable c₂] {A : Type} {t₁ t₂ e₁ e₂ : A}
(Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) :
(if c₁ then t₁ else e₁) = (if c₂ then t₂ else e₂) :=
Ht ▸ He ▸ (if_cond_congr Hc t₁ e₁)
definition if_congr {c₁ c₂ : Type} [H₁ : decidable c₁] {A : Type} {t₁ t₂ e₁ e₂ : A} (Hc : c₁ ↔ c₂) (Ht : t₁ = t₂) (He : e₁ = e₂) :
(if c₁ then t₁ else e₁) = (@ite c₂ (decidable.decidable_iff_equiv H₁ Hc) A t₂ e₂) :=
have H2 [visible] : decidable c₂, from (decidable.decidable_iff_equiv H₁ Hc),
if_congr_aux Hc Ht He
-- We use "dependent" if-then-else to be able to communicate the if-then-else condition
-- to the branches
definition dite (c : Type) [H : decidable c] {A : Type} (t : c → A) (e : ¬ c → A) : A :=
decidable.rec_on H (λ Hc, t Hc) (λ Hnc, e Hnc)
definition dif_pos {c : Type} [H : decidable c] (Hc : c) {A : Type} {t : c → A} {e : ¬ c → A} : (if H : c then t H else e H) = t (decidable.pos_witness Hc) :=
decidable.rec
(λ Hc : c, eq.refl (@dite c (decidable.inl Hc) A t e))
(λ Hnc : ¬c, absurd Hc Hnc)
H
definition dif_neg {c : Type} [H : decidable c] (Hnc : ¬c) {A : Type} {t : c → A} {e : ¬ c → A} : (if H : c then t H else e H) = e (decidable.neg_witness Hnc) :=
decidable.rec
(λ Hc : c, absurd Hc Hnc)
(λ Hnc : ¬c, eq.refl (@dite c (decidable.inr Hnc) A t e))
H
-- Remark: dite and ite are "definitionally equal" when we ignore the proofs.
definition dite_ite_eq (c : Type) [H : decidable c] {A : Type} (t : A) (e : A) : dite c (λh, t) (λh, e) = ite c t e :=
rfl
end
|
b7b92b759d8732ca7523878704828e3c2c5a1897
|
5d166a16ae129621cb54ca9dde86c275d7d2b483
|
/library/init/data/bool/lemmas.lean
|
da0bbd7df2c9bbb98d972c12f989363fe12f1836
|
[
"Apache-2.0"
] |
permissive
|
jcarlson23/lean
|
b00098763291397e0ac76b37a2dd96bc013bd247
|
8de88701247f54d325edd46c0eed57aeacb64baf
|
refs/heads/master
| 1,611,571,813,719
| 1,497,020,963,000
| 1,497,021,515,000
| 93,882,536
| 1
| 0
| null | 1,497,029,896,000
| 1,497,029,896,000
| null |
UTF-8
|
Lean
| false
| false
| 2,624
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.data.bool.basic init.meta
attribute [simp] cond bor band bnot bxor
@[simp] lemma {u} cond_a_a {α : Type u} (b : bool) (a : α) : cond b a a = a :=
by cases b; simp
@[simp] lemma band_self (b : bool) : b && b = b :=
by cases b; simp
@[simp] lemma band_tt (b : bool) : b && tt = b :=
by cases b; simp
@[simp] lemma band_ff (b : bool) : b && ff = ff :=
by cases b; simp
@[simp] lemma tt_band (b : bool) : tt && b = b :=
by cases b; simp
@[simp] lemma ff_band (b : bool) : ff && b = ff :=
by cases b; simp
@[simp] lemma bor_self (b : bool) : b || b = b :=
by cases b; simp
@[simp] lemma bor_tt (b : bool) : b || tt = tt :=
by cases b; simp
@[simp] lemma bor_ff (b : bool) : b || ff = b :=
by cases b; simp
@[simp] lemma tt_bor (b : bool) : tt || b = tt :=
by cases b; simp
@[simp] lemma ff_bor (b : bool) : ff || b = b :=
by cases b; simp
@[simp] lemma bxor_self (b : bool) : bxor b b = ff :=
by cases b; simp
@[simp] lemma bxor_tt (b : bool) : bxor b tt = bnot b :=
by cases b; simp
@[simp] lemma bxor_ff (b : bool) : bxor b ff = b :=
by cases b; simp
@[simp] lemma tt_bxor (b : bool) : bxor tt b = bnot b :=
by cases b; simp
@[simp] lemma ff_bxor (b : bool) : bxor ff b = b :=
by cases b; simp
@[simp] lemma bnot_bnot (b : bool) : bnot (bnot b) = b :=
by cases b; simp
@[simp] lemma tt_eq_ff_eq_false : ¬(tt = ff) :=
by contradiction
@[simp] lemma ff_eq_tt_eq_false : ¬(ff = tt) :=
by contradiction
@[simp] lemma eq_ff_eq_not_eq_tt (b : bool) : (¬(b = tt)) = (b = ff) :=
by cases b; simp
@[simp] lemma eq_tt_eq_not_eq_ff (b : bool) : (¬(b = ff)) = (b = tt) :=
by cases b; simp
@[simp] lemma band_eq_true_eq_eq_tt_and_eq_tt (a b : bool) : (a && b = tt) = (a = tt ∧ b = tt) :=
by cases a; cases b; simp
@[simp] lemma bor_eq_true_eq_eq_tt_or_eq_tt (a b : bool) : (a || b = tt) = (a = tt ∨ b = tt) :=
by cases a; cases b; simp
@[simp] lemma bnot_eq_true_eq_eq_ff (a : bool) : (bnot a = tt) = (a = ff) :=
by cases a; simp
@[simp] lemma band_eq_false_eq_eq_ff_or_eq_ff (a b : bool) : (a && b = ff) = (a = ff ∨ b = ff) :=
by cases a; cases b; simp
@[simp] lemma bor_eq_false_eq_eq_ff_and_eq_ff (a b : bool) : (a || b = ff) = (a = ff ∧ b = ff) :=
by cases a; cases b; simp
@[simp] lemma bnot_eq_ff_eq_eq_tt (a : bool) : (bnot a = ff) = (a = tt) :=
by cases a; simp
@[simp] lemma coe_ff : ↑ff = false :=
show (ff = tt) = false, by simp
@[simp] lemma coe_tt : ↑tt = true :=
show (tt = tt) = true, by simp
|
807385ed063b87c4abe030405eaabcfdcfb9bab9
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/converter/binders_auto.lean
|
ee64529aef3d9eae063bd4170c3bb61705ef1d4e
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,836
|
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
Binder elimination
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.order.default
import Mathlib.PostPort
universes u v
namespace Mathlib
namespace old_conv
/- congr should forward data! -/
end old_conv
/- Binder elimination:
We assume a binder `B : p → Π (α : Sort u), (α → t) → t`, where `t` is a type depending on `p`.
Examples:
∃: there is no `p` and `t` is `Prop`.
⨅, ⨆: here p is `β` and `[complete_lattice β]`, `p` is `β`
Problem: ∀x, _ should be a binder, but is not a constant!
Provide a mechanism to rewrite:
B (x : α) ..x.. (h : x = t), p x = B ..x/t.., p t
Here ..x.. are binders, maybe also some constants which provide commutativity rules with `B`.
-/
theorem exists_elim_eq_left {α : Sort u} (a : α) (p : (a' : α) → a' = a → Prop) :
(∃ (a' : α), ∃ (h : a' = a), p a' h) ↔ p a rfl :=
sorry
theorem exists_elim_eq_right {α : Sort u} (a : α) (p : (a' : α) → a = a' → Prop) :
(∃ (a' : α), ∃ (h : a = a'), p a' h) ↔ p a rfl :=
sorry
theorem forall_comm {α : Sort u} {β : Sort v} (p : α → β → Prop) :
(∀ (a : α) (b : β), p a b) ↔ ∀ (b : β) (a : α), p a b :=
{ mp := fun (h : ∀ (a : α) (b : β), p a b) (b : β) (a : α) => h a b,
mpr := fun (h : ∀ (b : β) (a : α), p a b) (b : α) (a : β) => h a b }
theorem forall_elim_eq_left {α : Sort u} (a : α) (p : (a' : α) → a' = a → Prop) :
(∀ (a' : α) (h : a' = a), p a' h) ↔ p a rfl :=
sorry
theorem forall_elim_eq_right {α : Sort u} (a : α) (p : (a' : α) → a = a' → Prop) :
(∀ (a' : α) (h : a = a'), p a' h) ↔ p a rfl :=
sorry
end Mathlib
|
3000b3b4db8499a23b49e0fdb1a6fdf1ed70c93b
|
556aeb81a103e9e0ac4e1fe0ce1bc6e6161c3c5e
|
/src/starkware/cairo/lean/semantics/air_encoding/range_check_builtin.lean
|
cb732346453eaee55b506e445a579f0fe02664a4
|
[
"Apache-2.0"
] |
permissive
|
starkware-libs/formal-proofs
|
d6b731604461bf99e6ba820e68acca62a21709e8
|
f5fa4ba6a471357fd171175183203d0b437f6527
|
refs/heads/master
| 1,691,085,444,753
| 1,690,507,386,000
| 1,690,507,386,000
| 410,476,629
| 32
| 9
|
Apache-2.0
| 1,690,506,773,000
| 1,632,639,790,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,442
|
lean
|
import starkware.cairo.lean.semantics.cpu
variables {F : Type*} [field F]
-- number of 16-bit range-checked values
variable {rc16_len : ℕ}
-- number of 128-bit range-checked values
variables {rc_len : ℕ}
-- this is public data
variable {initial_rc_addr : F}
-- this comes from range check constraints
variable {rc16_val : fin rc16_len → F}
-- these come from memory constraints
variable {rc_addr : fin rc_len → F} -- rc_builtin__mem__addr
variable {rc_val : fin rc_len → F} -- rc_builtin__mem__value
-- map eight rc16 values to one rc value
variable {rc_to_rc16 : fin rc_len → fin 8 → fin rc16_len}
-- this comes from range check constraints
variable h_rc16_val : ∀ i : fin rc16_len, ∃ k : ℕ, k < 2^16 ∧ rc16_val i = ↑k
-- these are the range check builtin constraints
variable h_rc_init_addr : ∀ h : 0 < rc_len, rc_addr ⟨0, h⟩ = initial_rc_addr
variable h_rc_addr_step : ∀ i : ℕ, ∀ h : i.succ < rc_len,
rc_addr ⟨i.succ, h⟩ = rc_addr ⟨i, (nat.lt_succ_self _).trans h⟩ + 1
variable h_rc_value : ∀ i : fin rc_len,
rc_val i = (((((((rc16_val (rc_to_rc16 i 0))
* 2^16 + rc16_val (rc_to_rc16 i 1))
* 2^16 + rc16_val (rc_to_rc16 i 2))
* 2^16 + rc16_val (rc_to_rc16 i 3))
* 2^16 + rc16_val (rc_to_rc16 i 4))
* 2^16 + rc16_val (rc_to_rc16 i 5))
* 2^16 + rc16_val (rc_to_rc16 i 6))
* 2^16 + rc16_val (rc_to_rc16 i 7)
section
include h_rc_init_addr h_rc_addr_step
theorem rc_addr_eq (i : fin rc_len) : rc_addr i = initial_rc_addr + i :=
begin
cases i with i h,
induction i with i ih,
{ simp [h_rc_init_addr] },
rw [h_rc_addr_step i h, ih ((nat.lt_succ_self _).trans h), add_assoc],
simp
end
end
section
include h_rc16_val h_rc_value
theorem rc_val_checked (i : fin rc_len) : ∃ k : ℕ, k < 2^128 ∧ rc_val i = ↑k :=
have rc_val_aux : ∀ {n : ℕ} (h : n < 2^16), n ≤ 2^16-1 :=
begin
intros n h,
apply nat.le_of_succ_le_succ,
apply le_trans (nat.succ_le_of_lt h),
norm_num
end,
begin
rw [h_rc_value],
rcases h_rc16_val (rc_to_rc16 i 0) with ⟨k0, k0_lt, k0eq⟩, rw k0eq,
rcases h_rc16_val (rc_to_rc16 i 1) with ⟨k1, k1_lt, k1eq⟩, rw k1eq,
rcases h_rc16_val (rc_to_rc16 i 2) with ⟨k2, k2_lt, k2eq⟩, rw k2eq,
rcases h_rc16_val (rc_to_rc16 i 3) with ⟨k3, k3_lt, k3eq⟩, rw k3eq,
rcases h_rc16_val (rc_to_rc16 i 4) with ⟨k4, k4_lt, k4eq⟩, rw k4eq,
rcases h_rc16_val (rc_to_rc16 i 5) with ⟨k5, k5_lt, k5eq⟩, rw k5eq,
rcases h_rc16_val (rc_to_rc16 i 6) with ⟨k6, k6_lt, k6eq⟩, rw k6eq,
rcases h_rc16_val (rc_to_rc16 i 7) with ⟨k7, k7_lt, k7eq⟩, rw k7eq,
norm_cast,
refine ⟨_, _, rfl⟩,
have : ((((((((2^16 - 1)
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1))
* 2^16 + (2^16 - 1)) < 2^128, by norm_num,
apply lt_of_le_of_lt _ this,
apply add_le_add _ (rc_val_aux k7_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k6_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k5_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k4_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k3_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k2_lt),
apply nat.mul_le_mul_right,
apply add_le_add _ (rc_val_aux k1_lt),
apply nat.mul_le_mul_right,
apply rc_val_aux k0_lt
end
end
|
fb505a475a72112fc901c1856f8dad9d17210618
|
8b9f17008684d796c8022dab552e42f0cb6fb347
|
/hott/algebra/groupoid.hlean
|
3cea3268a31d190194e0c6850e31dd346fb37e2d
|
[
"Apache-2.0"
] |
permissive
|
chubbymaggie/lean
|
0d06ae25f9dd396306fb02190e89422ea94afd7b
|
d2c7b5c31928c98f545b16420d37842c43b4ae9a
|
refs/heads/master
| 1,611,313,622,901
| 1,430,266,839,000
| 1,430,267,083,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,054
|
hlean
|
/-
Copyright (c) 2014 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Module: algebra.groupoid
Author: Jakob von Raumer
Ported from Coq HoTT
-/
import .precategory.iso .group
open eq is_trunc iso category path_algebra nat unit
namespace category
structure groupoid [class] (ob : Type) extends parent : precategory ob :=
(all_iso : Π ⦃a b : ob⦄ (f : hom a b), @is_iso ob parent a b f)
abbreviation all_iso := @groupoid.all_iso
attribute groupoid.all_iso [instance] [priority 100000]
definition groupoid.mk' [reducible] (ob : Type) (C : precategory ob)
(H : Π (a b : ob) (f : a ⟶ b), is_iso f) : groupoid ob :=
precategory.rec_on C groupoid.mk H
definition groupoid_of_1_type.{l} (A : Type.{l})
[H : is_trunc 1 A] : groupoid.{l l} A :=
groupoid.mk
(λ (a b : A), a = b)
(λ (a b : A), have ish : is_hset (a = b), from is_trunc_eq nat.zero a b, ish)
(λ (a b c : A) (p : b = c) (q : a = b), q ⬝ p)
(λ (a : A), refl a)
(λ (a b c d : A) (p : c = d) (q : b = c) (r : a = b), con.assoc r q p)
(λ (a b : A) (p : a = b), con_idp p)
(λ (a b : A) (p : a = b), idp_con p)
(λ (a b : A) (p : a = b), @is_iso.mk A _ a b p p⁻¹
!con.right_inv !con.left_inv)
-- A groupoid with a contractible carrier is a group
definition group_of_is_contr_groupoid {ob : Type} [H : is_contr ob]
[G : groupoid ob] : group (hom (center ob) (center ob)) :=
begin
fapply group.mk,
intros [f, g], apply (comp f g),
apply homH,
intros [f, g, h], apply (assoc f g h)⁻¹,
apply (ID (center ob)),
intro f, apply id_left,
intro f, apply id_right,
intro f, exact (iso.inverse f),
intro f, exact (iso.left_inverse f),
end
definition group_of_groupoid_unit [G : groupoid unit] : group (hom ⋆ ⋆) :=
begin
fapply group.mk,
intros [f, g], apply (comp f g),
apply homH,
intros [f, g, h], apply (assoc f g h)⁻¹,
apply (ID ⋆),
intro f, apply id_left,
intro f, apply id_right,
intro f, exact (iso.inverse f),
intro f, exact (iso.left_inverse f),
end
-- Conversely we can turn each group into a groupoid on the unit type
definition groupoid_of_group.{l} (A : Type.{l}) [G : group A] : groupoid.{l l} unit :=
begin
fapply groupoid.mk,
intros, exact A,
intros, apply (@group.carrier_hset A G),
intros [a, b, c, g, h], exact (@group.mul A G g h),
intro a, exact (@group.one A G),
intros, exact (@group.mul_assoc A G h g f)⁻¹,
intros, exact (@group.one_mul A G f),
intros, exact (@group.mul_one A G f),
intros, apply is_iso.mk,
apply mul_left_inv,
apply mul_right_inv,
end
protected definition hom_group {A : Type} [G : groupoid A] (a : A) :
group (hom a a) :=
begin
fapply group.mk,
intros [f, g], apply (comp f g),
apply homH,
intros [f, g, h], apply (assoc f g h)⁻¹,
apply (ID a),
intro f, apply id_left,
intro f, apply id_right,
intro f, exact (iso.inverse f),
intro f, exact (iso.left_inverse f),
end
-- Bundled version of categories
-- we don't use Groupoid.carrier explicitly, but rather use Groupoid.carrier (to_Precategory C)
structure Groupoid : Type :=
(carrier : Type)
(struct : groupoid carrier)
attribute Groupoid.struct [instance] [coercion]
-- definition objects [reducible] := Category.objects
-- definition category_instance [instance] [coercion] [reducible] := Category.category_instance
definition Groupoid.to_Precategory [coercion] [reducible] (C : Groupoid) : Precategory :=
Precategory.mk (Groupoid.carrier C) C
definition groupoid.Mk [reducible] := Groupoid.mk
definition groupoid.MK [reducible] (C : Precategory) (H : Π (a b : C) (f : a ⟶ b), is_iso f)
: Groupoid :=
Groupoid.mk C (groupoid.mk' C C H)
definition Groupoid.eta (C : Groupoid) : Groupoid.mk C C = C :=
Groupoid.rec (λob c, idp) C
end category
|
ce5ccbd54bbf85b0f88a05dd927888e4881bd602
|
4aca55eba10c989f0d58647d3c2f371e7da44355
|
/src/monoid_hom.lean
|
af3acfe5d145ad455241a7d0909ddda32b9f4fa0
|
[] |
no_license
|
eric-wieser/l534zhan-my_project
|
f9fc75fb5454405e1a2fa9b56cf96c355f6f2336
|
febc91e76b7b00fe2517f258ca04d27b7f35fcf3
|
refs/heads/master
| 1,689,218,910,420
| 1,630,439,440,000
| 1,630,439,440,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 881
|
lean
|
import group_theory.subgroup
/-!
This file supplements two instances relavant to monoid homomorphisms
-/
namespace monoid_hom
variables {G N: Type*} [group G] [group N]
/-- If the equality in `N` is decidable and `f : G →* N` is a `monoid_hom`,
then the membership of `f.ker.carrier` is decidable. -/
instance [decidable_eq N] (f : G →* N) (x : G) :
decidable (x ∈ f.ker.carrier) := f.decidable_mem_ker x
/-- If `G` is a finite type, and the equality in `N` is decidable,
and `f : G →* N` is a `monoid_hom`, then `f.ker.carrier` is a finite type. -/
instance [fintype G] [decidable_eq N] (f : G →* N) :
fintype (f.ker.carrier) := set_fintype (f.ker.carrier)
/-
lemma fintype_card_ker_eq_card_ker_carrier [fintype G] [decidable_eq N] (f : G →* N) :
fintype.card f.ker = fintype.card f.ker.carrier :=
by refl
-/
end monoid_hom
|
521bc0c0b8351ff25859b335172463d858d8dbdb
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/interactive/stdOutput.lean
|
856a63b5898e8b51ca3a2920e0bba2a5715b3375
|
[
"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
| 68
|
lean
|
import Lean
elab "foo" : command => IO.println "hi"
#eval "ho"
foo
|
99271a2f65996e908398d9667e208f009fff75c7
|
4e3bf8e2b29061457a887ac8889e88fa5aa0e34c
|
/lean/love08_operational_semantics_exercise_sheet.lean
|
ba379880c7cd07f53b38143f20742dd3ecb36441
|
[] |
no_license
|
mukeshtiwari/logical_verification_2019
|
9f964c067a71f65eb8884743273fbeef99e6503d
|
16f62717f55ed5b7b87e03ae0134791a9bef9b9a
|
refs/heads/master
| 1,619,158,844,208
| 1,585,139,500,000
| 1,585,139,500,000
| 249,906,380
| 0
| 0
| null | 1,585,118,728,000
| 1,585,118,727,000
| null |
UTF-8
|
Lean
| false
| false
| 5,000
|
lean
|
/- LoVe Exercise 8: Operational Semantics -/
import .love08_operational_semantics_demo
namespace LoVe
/- Question 1: Program Equivalence -/
/- For this question, we introduce the notation of program equivalence
`p₁ ≈ p₂`. -/
def program_equiv (S₁ S₂ : program) : Prop :=
∀s t, (S₁, s) ⟹ t ↔ (S₂, s) ⟹ t
local infix ` ≈ ` := program_equiv
/- Program equivalence is a equivalence relation, i.e., it is reflexive,
symmetric, and transitive. -/
@[refl] lemma program_equiv.refl {S} :
S ≈ S :=
assume s t,
show (S, s) ⟹ t ↔ (S, s) ⟹ t,
by refl
@[symm] lemma program_equiv.symm {S₁ S₂}:
S₁ ≈ S₂ → S₂ ≈ S₁ :=
assume h s t,
show (S₂, s) ⟹ t ↔ (S₁, s) ⟹ t,
from iff.symm (h s t)
@[trans] lemma program_equiv.trans {S₁ S₂ S₃} (h₁₂ : S₁ ≈ S₂) (h₂₃ : S₂ ≈ S₃) :
S₁ ≈ S₃ :=
assume s t,
show (S₁, s) ⟹ t ↔ (S₃, s) ⟹ t,
from iff.trans (h₁₂ s t) (h₂₃ s t)
/- 1.1. Prove the following program equivalences. -/
lemma program_equiv.seq_skip_left {S} :
skip ;; S ≈ S :=
sorry
lemma program_equiv.seq_skip_right {S} :
S ;; skip ≈ S :=
sorry
lemma program_equiv.seq_congr {S₁ S₂ T₁ T₂} (hS : S₁ ≈ S₂) (hT : T₁ ≈ T₂) :
S₁ ;; T₁ ≈ S₂ ;; T₂ :=
sorry
lemma program_equiv.ite_seq_while {b S} :
ite b (S ;; while b S) skip ≈ while b S :=
sorry
/- 1.2. Prove one more equivalence. -/
lemma program_equiv.skip_assign_id {x} :
assign x (λs, s x) ≈ skip :=
sorry
/- Question 2: Guarded Command Language (GCL) -/
/- In 1976, E. W. Dijkstra introduced the guarded command language, a
minimalistic imperative language with built-in nondeterminism. A grammar for one
of its variants is given below:
S ::= x := e -- assignment
| assert b -- assertion
| S ; S -- sequential composition
| S | ⋯ | S -- nondeterministic choice
| loop S -- nondeterministic iteration
Assignment and sequential composition are as in the WHILE language. The other
statements have the following semantics:
* `assert b` aborts if `b` evaluates to false; otherwise, the command is a
no-op.
* `S | ⋯ | S` chooses **any** of the branches and executes it, ignoring the
other branches.
* `loop S` executes `S` **any** number of times.
In Lean, GCL is captured by the following inductive type: -/
inductive gcl (σ : Type) : Type
| assign : string → (σ → ℕ) → gcl
| assert : (σ → Prop) → gcl
| seq : gcl → gcl → gcl
| choice : list gcl → gcl
| loop : gcl → gcl
infixr ` ;; `:90 := gcl.seq
namespace gcl
/- The parameter `σ` abstracts over the state type. It is necessary to work
around a bug in Lean.
The big-step semantics is defined as follows: -/
inductive big_step : (gcl state × state) → state → Prop
| assign {x a s} :
big_step (assign x a, s) (s{x ↦ a s})
| assert {b : state → Prop} {s} (hcond : b s) :
big_step (assert b, s) s
| seq {S T s t u} (h₁ : big_step (S, s) t) (h₂ : big_step (T, t) u) :
big_step (S ;; T, s) u
| choice {Ss : list (gcl state)} {s t} (i : ℕ) (hless : i < list.length Ss)
(hbody : big_step (list.nth_le Ss i hless, s) t) :
big_step (choice Ss, s) t
| loop_base {S s} :
big_step (loop S, s) s
| loop_step {S s u} (t) (hbody : big_step (S, s) t)
(hrest : big_step (loop S, t) u) :
big_step (loop S, s) u
/- Convenience syntax: -/
infix ` ~~> `:110 := big_step
/- 2.1. Prove the following inversion rules, as we did in the lecture for the
WHILE language. -/
@[simp] lemma big_step_assign_iff {x a s t} :
(assign x a, s) ~~> t ↔ t = s{x ↦ a s} :=
sorry
@[simp] lemma big_step_assert {b s t} :
(assert b, s) ~~> t ↔ t = s ∧ b s :=
sorry
@[simp] lemma big_step_seq_iff {S₁ S₂ s t} :
(S₁ ;; S₂, s) ~~> t ↔ (∃u, (S₁, s) ~~> u ∧ (S₂, u) ~~> t) :=
sorry
lemma big_step_loop {S s u} :
(loop S, s) ~~> u ↔ (s = u ∨ (∃t, (S, s) ~~> t ∧ (loop S, t) ~~> u)) :=
sorry
@[simp] lemma big_step_choice {Ss s t} :
(choice Ss, s) ~~> t ↔
(∃(i : ℕ) (hless : i < list.length Ss),
(list.nth_le Ss i hless, s) ~~> t) :=
sorry
/- 2.2. Complete the translation below of a deterministic program to a GCL
program, by filling in the `sorry` placeholders below. -/
def of_program : program → gcl state
| program.skip := assert (λ_, true)
| (program.assign x f) :=
sorry
| (program.seq S₁ S₂) :=
sorry
| (program.ite b S₁ S₂) :=
choice [seq (assert b) (of_program S₁),
seq (assert (λs, ¬ b s)) (of_program S₂)]
| (program.while b S) :=
seq (loop (seq (assert b) (of_program S))) (assert (λs, ¬ b s))
/- 2.3. In the definition of `of_program` above, `skip` is translated to
`assert (λ_, true)`. Looking at the big-step semantics of both constructs, we
can convince ourselves that it makes sense. Can you think of other correct ways
to define the `skip` case? -/
-- enter your answer here
end gcl
end LoVe
|
f489b62338220faa067a2849da7c57877d1ee58b
|
da3a76c514d38801bae19e8a9e496dc31f8e5866
|
/library/init/meta/quote.lean
|
73ddb72439dfa1342e782a4f5c8d3795c88415d8
|
[
"Apache-2.0"
] |
permissive
|
cipher1024/lean
|
270c1ac5781e6aee12f5c8d720d267563a164beb
|
f5cbdff8932dd30c6dd8eec68f3059393b4f8b3a
|
refs/heads/master
| 1,611,223,459,029
| 1,487,566,573,000
| 1,487,566,573,000
| 83,356,543
| 0
| 0
| null | 1,488,229,336,000
| 1,488,229,336,000
| null |
UTF-8
|
Lean
| false
| false
| 2,020
|
lean
|
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
-/
prelude
import init.meta.tactic
open tactic
meta class has_quote (α : Type) :=
(quote : α → pexpr)
@[inline] meta def quote {α : Type} [has_quote α] : α → pexpr :=
has_quote.quote
meta instance : has_quote nat := ⟨pexpr.mk_prenum_macro⟩
@[priority std.priority.default + 1]
meta instance : has_quote string := ⟨pexpr.mk_string_macro⟩
meta instance : has_quote pexpr := ⟨pexpr.mk_quote_macro⟩
meta instance : has_quote char :=
⟨λ ⟨n, pr⟩, ``(char.of_nat %%(quote n))⟩
meta instance : has_quote unsigned :=
⟨λ ⟨n, pr⟩, ``(unsigned.of_nat %%(quote n))⟩
meta def name.quote : name → pexpr
| name.anonymous := ``(name.anonymous)
| (name.mk_string s n) := ``(name.mk_string %%(quote s) %%(name.quote n))
| (name.mk_numeral i n) := ``(name.mk_numeral %%(quote i) %%(name.quote n))
meta instance : has_quote name := ⟨name.quote⟩
private meta def list.quote {α : Type} [has_quote α] : list α → pexpr
| [] := ``([])
| (h::t) := ``(%%(quote h) :: %%(list.quote t))
meta instance {α : Type} [has_quote α] : has_quote (list α) := ⟨list.quote⟩
meta instance {α : Type} [has_quote α] : has_quote (option α) :=
⟨λ opt, match opt with
| some x := ``(option.some %%(quote x))
| none := ``(option.none)
end⟩
meta instance : has_quote unit := ⟨λ _, ``(unit.star)⟩
meta instance {α β : Type} [has_quote α] [has_quote β] : has_quote (α × β) :=
⟨λ ⟨x, y⟩, ``((%%(quote x), %%(quote y)))⟩
meta def nat.to_expr : nat → tactic expr := λ n, to_expr $ quote n
meta def char.to_expr : char → tactic expr := λ n, to_expr $ quote n
meta def unsigned.to_expr : unsigned → tactic expr := λ n, to_expr $ quote n
meta def name.to_expr : name → tactic expr := λ n, to_expr $ quote n
meta def list_name.to_expr : list name → tactic expr := λ n, to_expr $ quote n
|
c35dc4935e81877962cc19666ed8be83636bc140
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/omega/nat/preterm.lean
|
0a052e624ddecb11738543484257c36897baccee
|
[] |
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
| 2,624
|
lean
|
/-
Copyright (c) 2019 Seul Baek. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Seul Baek
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.omega.term
import Mathlib.PostPort
universes l
namespace Mathlib
/-
Linear natural number arithmetic terms in pre-normalized form.
-/
namespace omega
namespace nat
/-- The shadow syntax for arithmetic terms. All constants are reified to `cst`
(e.g., `5` is reified to `cst 5`) and all other atomic terms are reified to
`exp` (e.g., `5 * (list.length l)` is reified to `exp 5 \`(list.length l)`).
`exp` accepts a coefficient of type `nat` as its first argument because
multiplication by constant is allowed by the omega test. -/
/-- Similar to `exprterm`, except that all exprs are now replaced with
de Brujin indices of type `nat`. This is akin to generalizing over
the terms represented by the said exprs. -/
inductive preterm
where
| cst : ℕ → preterm
| var : ℕ → ℕ → preterm
| add : preterm → preterm → preterm
| sub : preterm → preterm → preterm
namespace preterm
/-- Helper tactic for proof by induction over preterms -/
/-- Preterm evaluation -/
def val (v : ℕ → ℕ) : preterm → ℕ :=
sorry
@[simp] theorem val_const {v : ℕ → ℕ} {m : ℕ} : val v (cst m) = m :=
rfl
@[simp] theorem val_var {v : ℕ → ℕ} {m : ℕ} {n : ℕ} : val v (var m n) = m * v n := sorry
@[simp] theorem val_add {v : ℕ → ℕ} {t : preterm} {s : preterm} : val v (add t s) = val v t + val v s :=
rfl
@[simp] theorem val_sub {v : ℕ → ℕ} {t : preterm} {s : preterm} : val v (sub t s) = val v t - val v s :=
rfl
/-- Fresh de Brujin index not used by any variable in argument -/
def fresh_index : preterm → ℕ :=
sorry
/-- If variable assignments `v` and `w` agree on all variables that occur
in term `t`, the value of `t` under `v` and `w` are identical. -/
theorem val_constant (v : ℕ → ℕ) (w : ℕ → ℕ) (t : preterm) : (∀ (x : ℕ), x < fresh_index t → v x = w x) → val v t = val w t := sorry
def repr : preterm → string :=
sorry
@[simp] def add_one (t : preterm) : preterm :=
add t (cst 1)
/-- Preterm is free of subtractions -/
def sub_free : preterm → Prop :=
sorry
end preterm
/-- Return a term (which is in canonical form by definition)
that is equivalent to the input preterm -/
@[simp] def canonize : preterm → term :=
sorry
@[simp] theorem val_canonize {v : ℕ → ℕ} {t : preterm} : preterm.sub_free t → term.val (fun (x : ℕ) => ↑(v x)) (canonize t) = ↑(preterm.val v t) := sorry
|
9899e301c882a512cafbf7c281aa7c3895be17f3
|
dd0f5513e11c52db157d2fcc8456d9401a6cd9da
|
/03_Propositions_and_Proofs.org.38.lean
|
7e141cfca7f290dc2ccb30ed26e9616a2f5f1c3a
|
[] |
no_license
|
cjmazey/lean-tutorial
|
ba559a49f82aa6c5848b9bf17b7389bf7f4ba645
|
381f61c9fcac56d01d959ae0fa6e376f2c4e3b34
|
refs/heads/master
| 1,610,286,098,832
| 1,447,124,923,000
| 1,447,124,923,000
| 43,082,433
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 949
|
lean
|
/- page 45 -/
import standard
open classical
variables p q r : Prop
-- distributivity
example : p ∧ (q ∨ r) ↔ (p ∧ q) ∨ (p ∧ r) :=
iff.intro
(assume H : p ∧ (q ∨ r),
have Hp : p, from and.left H,
or.elim (and.right H)
(assume Hq : q,
show (p ∧ q) ∨ (p ∧ r), from or.inl (and.intro Hp Hq))
(assume Hr : r,
show (p ∧ q) ∨ (p ∧ r), from or.inr (and.intro Hp Hr)))
(assume H : (p ∧ q) ∨ (p ∧ r),
or.elim H
(assume Hpq : p ∧ q,
have Hp : p, from and.left Hpq,
have Hq : q, from and.right Hpq,
show p ∧ (q ∨ r), from and.intro Hp (or.inl Hq))
(assume Hpr : p ∧ r,
have Hp : p, from and.left Hpr,
have Hr : r, from and.right Hpr,
show p ∧ (q ∨ r), from and.intro Hp (or.inr Hr)))
-- an example that requires classical reasoning
example : ¬(p ∧ ¬q) → (p → q) :=
assume H : ¬(p ∧ ¬q),
assume Hp : p,
show q, from
or.elim (em q)
(assume Hq : q, Hq)
(assume Hnq : ¬q, absurd (and.intro Hp Hnq) H)
|
22259269307d8bd8e4932aa1689097aafe6c7151
|
5c7fe6c4a9d4079b5457ffa5f061797d42a1cd65
|
/src/library/src_real_field_lemmas.lean
|
c5c9b7fb74eb10f36072b69b4c39ad9b53688c0a
|
[] |
no_license
|
gihanmarasingha/mth1001_tutorial
|
8e0817feeb96e7c1bb3bac49b63e3c9a3a329061
|
bb277eebd5013766e1418365b91416b406275130
|
refs/heads/master
| 1,675,008,746,310
| 1,607,993,443,000
| 1,607,993,443,000
| 321,511,270
| 3
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,593
|
lean
|
import .src_real_field
import .src_ordered_field_lemmas
import data.set.basic
import tactic
namespace mth1001
namespace myreal
open myreal_field myordered_field classical
open_locale classical
variables {R : Type} [myreal_field R]
def has_upper_bound (S : set R) := ∃ u : R, upper_bound u S
def has_lower_bound (S : set R) := ∃ v : R, lower_bound v S
lemma sup_is_sup {S : set R} (h₁ : has_upper_bound S) (h₂ : S ≠ ∅) : is_sup (sup S) S :=
begin
have h₃ : ∃ x : R, is_sup x S, from completeness h₂ h₁,
have h₄ : sup S = some h₃, from dif_pos h₃,
rw h₄,
exact some_spec h₃,
end
theorem sup_monotone (S T : set R) (h₁ : has_upper_bound S) (h₂ : has_upper_bound T)
(h₃ : S ≠ ∅) (h₄ : T ≠ ∅) : S ⊆ T → sup S ≤ sup T :=
begin
have h₅ : ∀ (v : R), upper_bound v S → sup S ≤ v, from (sup_is_sup h₁ h₃).right,
have h₆ : upper_bound (sup T) T, from (sup_is_sup h₂ h₄).left,
intro k,
apply h₅ (sup T),
intros s hs,
have ht : s ∈ T, from k hs,
exact h₆ s ht,
end
theorem archimedean : ∀ x : R, ∃ n : ℕ, x < n :=
begin
by_contra h,
push_neg at h,
cases h with x hx,
let S := {m : R | ∃ n : ℕ, (m = n) ∧ (x ≥ n)},
have h₁ : ↑1 ∈ S, from ⟨1, ⟨rfl, hx 1⟩⟩,
have h₂ : S ≠ ∅,
{ intro h, rw h at h₁, exact h₁, },
have h₃ : has_upper_bound S, from ⟨x, λ s ⟨n,hs,hn⟩, hs.symm ▸ hn⟩,
have h₄ : is_sup (sup S) S, from sup_is_sup h₃ h₂,
suffices k : upper_bound (sup S +- 1) S,
{ have k₂, from add_le_add (h₄.right (sup S + - 1) k) (le_refl (1 +- sup S)),
have k₃ : sup S + (1 + -sup S) = 1, rw [add_comm 1 (-sup S), ←add_assoc, add_neg', zero_add],
have k₄ : sup S +-1 + (1 + -sup S) = 0,
{ rw [add_assoc, ←add_assoc (-1) 1 (-sup S), neg_add, zero_add, add_neg'], },
rw [k₃, k₄, ←not_lt_iff_le] at k₂,
apply k₂,
rw [lt_iff_pos_neg, neg_zero, add_zero], exact pos_one, },
rintros _ ⟨m, rfl, xgem⟩,
have h₆ : ↑(m + 1) ∈ S, from ⟨m+1, rfl, hx (m+1)⟩,
convert (add_le_add (h₄.left (↑m + 1) h₆) (le_refl (-1))),
rw [add_assoc,add_neg',add_zero],
end
theorem inv_lt_of_pos (ε : R) (h : 0 < ε) : ∃ n : ℕ, n ≠ 0 ∧ (↑n)⁻¹ < ε :=
begin
cases archimedean ε⁻¹ with n hn,
use n,
have h₁ : ε ≠ 0, from ne_of_gt h,
have h₂ : 0 < ε⁻¹, from (inv_pos h₁).mpr h,
rw ←inv_inv' ε h₁ ,
have h₃ : (0 : R) < ↑n, from lt_trans h₂ hn,
rw (inv_lt_inv h₃ h₂),
split,
{ intro heq0,
rw heq0 at h₃,
exact lt_irrefl h₃, },
{ exact hn, },
end
lemma zero_of_non_neg_of_lt_pos (a : R) (h : 0 ≤ a) (h₂ : ∀ ε > 0, a < ε) : a = 0 :=
begin
rw le_iff_lt_or_eq at h,
cases h with hpos heq0,
{ rcases inv_lt_of_pos a hpos with ⟨n, hn0, hn⟩,
have hnpos : pos (n : R), from pos_nat n hn0,
have h₃ : (n : R) ≠ 0,
{ intro k, rw [k, ←add_neg' (0 : R), ←lt_iff_pos_neg] at hnpos,
exact lt_irrefl hnpos, },
have hninvpos : (0 : R) < (n : R)⁻¹,
{ rwa [(inv_pos h₃), lt_iff_pos_sub, sub_zero], },
have h₄ : a < n⁻¹, from h₂ _ hninvpos,
exfalso,
exact lt_irrefl (lt_trans h₄ hn), },
{ exact heq0.symm, }
end
theorem bounded_iff_abs_lt (S : set R) : bounded S ↔ ∃ m : ℕ, ∀ s ∈ S, abs s < ↑m :=
begin
split,
{ rintro ⟨⟨ub, hub⟩, lb, hlb⟩,
rcases archimedean (max (abs ub) (abs lb)) with ⟨n, hn⟩,
use n,
intros s hs,
unfold abs,
cases max_choice s (-s) with hms hmns,
{ rw hms,
have h₂ : s ≤ ub, from hub s hs,
have h₃ : ub ≤ abs ub, from le_abs_self ub,
have h₄ : abs ub ≤ max (abs ub) (abs lb), from le_max_left _ _,
apply lt_of_le_of_lt,
{ exact le_trans _ _ _ h₂ (le_trans _ _ _ h₃ h₄)},
{ exact hn, }, },
{ rw hmns,
have h₂ : -s ≤ -lb, from neg_le_neg_iff.mpr (hlb s hs),
have h₃ : -lb ≤ abs lb, from neg_le_abs lb,
have h₄ : abs lb ≤ max (abs ub) (abs lb), from le_max_right _ _,
apply lt_of_le_of_lt,
{ exact le_trans _ _ _ h₂ (le_trans _ _ _ h₃ h₄) },
{ exact hn, }, }, },
{ rintro ⟨m, hm⟩,
split,
{ use m,
intros s hs,
apply le_trans,
{ exact le_abs_self s, },
{ exact le_iff_lt_or_eq.mpr (or.inl (hm s hs)) }, },
{ use (-m),
intros s hs,
rw [←neg_le_neg_iff, neg_neg],
apply le_trans,
{ exact neg_le_abs s, },
{ exact le_iff_lt_or_eq.mpr (or.inl (hm s hs)), }, }, },
end
end myreal
end mth1001
|
3c25c4459d4699842b9967a0420c5e6c3c6d16c5
|
3dd1b66af77106badae6edb1c4dea91a146ead30
|
/library/standard/decidable.lean
|
3546956ab24f8f6fb238e7ba3fd99239a179045a
|
[
"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
| 2,891
|
lean
|
-- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura
import logic
namespace decidable
inductive decidable (p : Prop) : Type :=
| inl : p → decidable p
| inr : ¬p → decidable p
theorem induction_on {p : Prop} {C : Prop} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C
:= decidable_rec H1 H2 H
theorem em (p : Prop) (H : decidable p) : p ∨ ¬p
:= induction_on H (λ Hp, or_inl Hp) (λ Hnp, or_inr Hnp)
definition rec_on [inline] {p : Prop} {C : Type} (H : decidable p) (H1 : p → C) (H2 : ¬p → C) : C
:= decidable_rec H1 H2 H
theorem irrelevant {p : Prop} (d1 d2 : decidable p) : d1 = d2
:= decidable_rec
(assume Hp1 : p, decidable_rec
(assume Hp2 : p, congr2 inl (refl Hp1)) -- using proof irrelevance for Prop
(assume Hnp2 : ¬p, absurd_elim (inl Hp1 = inr Hnp2) Hp1 Hnp2)
d2)
(assume Hnp1 : ¬p, decidable_rec
(assume Hp2 : p, absurd_elim (inr Hnp1 = inl Hp2) Hp2 Hnp1)
(assume Hnp2 : ¬p, congr2 inr (refl Hnp1)) -- using proof irrelevance for Prop
d2)
d1
theorem decidable_true [instance] : decidable true
:= inl trivial
theorem decidable_false [instance] : decidable false
:= inr not_false_trivial
theorem decidable_and [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) : decidable (a ∧ b)
:= rec_on Ha
(assume Ha : a, rec_on Hb
(assume Hb : b, inl (and_intro Ha Hb))
(assume Hnb : ¬b, inr (and_not_right a Hnb)))
(assume Hna : ¬a, inr (and_not_left b Hna))
theorem decidable_or [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) : decidable (a ∨ b)
:= rec_on Ha
(assume Ha : a, inl (or_inl Ha))
(assume Hna : ¬a, rec_on Hb
(assume Hb : b, inl (or_inr Hb))
(assume Hnb : ¬b, inr (or_not_intro Hna Hnb)))
theorem decidable_not [instance] {a : Prop} (Ha : decidable a) : decidable (¬a)
:= rec_on Ha
(assume Ha, inr (not_not_intro Ha))
(assume Hna, inl Hna)
theorem decidable_iff [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) : decidable (a ↔ b)
:= rec_on Ha
(assume Ha, rec_on Hb
(assume Hb : b, inl (iff_intro (assume H, Hb) (assume H, Ha)))
(assume Hnb : ¬b, inr (assume H : a ↔ b, absurd (iff_mp_left H Ha) Hnb)))
(assume Hna, rec_on Hb
(assume Hb : b, inr (assume H : a ↔ b, absurd (iff_mp_right H Hb) Hna))
(assume Hnb : ¬b, inl (iff_intro (assume Ha, absurd_elim b Ha Hna) (assume Hb, absurd_elim a Hb Hnb))))
theorem decidable_implies [instance] {a b : Prop} (Ha : decidable a) (Hb : decidable b) : decidable (a → b)
:= rec_on Ha
(assume Ha : a, rec_on Hb
(assume Hb : b, inl (assume H, Hb))
(assume Hnb : ¬b, inr (assume H : a → b, absurd (H Ha) Hnb)))
(assume Hna : ¬a, inl (assume Ha, absurd_elim b Ha Hna))
|
5251c45e3af9bd812337c08fd6455fc3c3fd0691
|
618003631150032a5676f229d13a079ac875ff77
|
/src/tactic/tauto.lean
|
9b0274f472d6b595768985e4e441bcc214ee390d
|
[
"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
| 9,702
|
lean
|
/-
Copyright (c) 2018 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import tactic.hint
namespace tactic
open expr
open tactic.interactive ( casesm constructor_matching )
/--
find all assumptions of the shape `¬ (p ∧ q)` or `¬ (p ∨ q)` and
replace them using de Morgan's law.
-/
meta def distrib_not : tactic unit :=
do hs ← local_context,
hs.for_each $ λ h,
all_goals' $
iterate_at_most' 3 $
do h ← get_local h.local_pp_name,
e ← infer_type h,
match e with
| `(¬ _ = _) := replace h.local_pp_name ``(mt iff.to_eq %%h)
| `(_ ≠ _) := replace h.local_pp_name ``(mt iff.to_eq %%h)
| `(_ = _) := replace h.local_pp_name ``(eq.to_iff %%h)
| `(¬ (_ ∧ _)) := replace h.local_pp_name ``(not_and_distrib'.mp %%h) <|>
replace h.local_pp_name ``(not_and_distrib.mp %%h)
| `(¬ (_ ∨ _)) := replace h.local_pp_name ``(not_or_distrib.mp %%h)
| `(¬ ¬ _) := replace h.local_pp_name ``(of_not_not %%h)
| `(¬ (_ → (_ : Prop))) := replace h.local_pp_name ``(not_imp.mp %%h)
| `(¬ (_ ↔ _)) := replace h.local_pp_name ``(not_iff.mp %%h)
| `(_ ↔ _) := replace h.local_pp_name ``(iff_iff_and_or_not_and_not.mp %%h) <|>
replace h.local_pp_name ``(iff_iff_and_or_not_and_not.mp (%%h).symm) <|>
() <$ tactic.cases h
| `(_ → _) := replace h.local_pp_name ``(not_or_of_imp %%h)
| _ := failed
end
meta def tauto_state := ref $ expr_map (option (expr × expr))
meta def modify_ref {α : Type} (r : ref α) (f : α → α) :=
read_ref r >>= write_ref r ∘ f
meta def add_refl (r : tauto_state) (e : expr) : tactic (expr × expr) :=
do m ← read_ref r,
p ← mk_mapp `rfl [none,e],
write_ref r $ m.insert e none,
return (e,p)
meta def add_symm_proof (r : tauto_state) (e : expr) : tactic (expr × expr) :=
do env ← get_env,
let rel := e.get_app_fn.const_name,
some symm ← pure $ environment.symm_for env rel
| add_refl r e,
(do e' ← mk_meta_var `(Prop),
iff_t ← to_expr ``(%%e = %%e'),
(_,p) ← solve_aux iff_t
(applyc `iff.to_eq ; () <$ split ; applyc symm),
e' ← instantiate_mvars e',
m ← read_ref r,
write_ref r $ (m.insert e (e',p)).insert e' none,
return (e',p) )
<|> add_refl r e
meta def add_edge (r : tauto_state) (x y p : expr) : tactic unit :=
modify_ref r $ λ m, m.insert x (y,p)
meta def root (r : tauto_state) : expr → tactic (expr × expr) | e :=
do m ← read_ref r,
let record_e : tactic (expr × expr) :=
match e with
| v@(expr.mvar _ _ _) :=
(do (e,p) ← get_assignment v >>= root,
add_edge r v e p,
return (e,p)) <|>
add_refl r e
| _ := add_refl r e
end,
some e' ← pure $ m.find e | record_e,
match e' with
| (some (e',p')) :=
do (e'',p'') ← root e',
p'' ← mk_app `eq.trans [p',p''],
add_edge r e e'' p'',
pure (e'',p'')
| none := prod.mk e <$> mk_mapp `rfl [none,some e]
end
meta def symm_eq (r : tauto_state) : expr → expr → tactic expr | a b :=
do m ← read_ref r,
(a',pa) ← root r a,
(b',pb) ← root r b,
(unify a' b' >> add_refl r a' *> mk_mapp `rfl [none,a]) <|>
do p ← match (a', b') with
| (`(¬ %%a₀), `(¬ %%b₀)) :=
do p ← symm_eq a₀ b₀,
p' ← mk_app `congr_arg [`(not),p],
add_edge r a' b' p',
return p'
| (`(%%a₀ ∧ %%a₁), `(%%b₀ ∧ %%b₁)) :=
do p₀ ← symm_eq a₀ b₀,
p₁ ← symm_eq a₁ b₁,
p' ← to_expr ``(congr (congr_arg and %%p₀) %%p₁),
add_edge r a' b' p',
return p'
| (`(%%a₀ ∨ %%a₁), `(%%b₀ ∨ %%b₁)) :=
do p₀ ← symm_eq a₀ b₀,
p₁ ← symm_eq a₁ b₁,
p' ← to_expr ``(congr (congr_arg or %%p₀) %%p₁),
add_edge r a' b' p',
return p'
| (`(%%a₀ ↔ %%a₁), `(%%b₀ ↔ %%b₁)) :=
(do p₀ ← symm_eq a₀ b₀,
p₁ ← symm_eq a₁ b₁,
p' ← to_expr ``(congr (congr_arg iff %%p₀) %%p₁),
add_edge r a' b' p',
return p') <|>
do p₀ ← symm_eq a₀ b₁,
p₁ ← symm_eq a₁ b₀,
p' ← to_expr ``(eq.trans (congr (congr_arg iff %%p₀) %%p₁)
(iff.to_eq iff.comm ) ),
add_edge r a' b' p',
return p'
| (`(%%a₀ → %%a₁), `(%%b₀ → %%b₁)) :=
if ¬ a₁.has_var ∧ ¬ b₁.has_var then
do p₀ ← symm_eq a₀ b₀,
p₁ ← symm_eq a₁ b₁,
p' ← mk_app `congr_arg [`(implies),p₀,p₁],
add_edge r a' b' p',
return p'
else unify a' b' >> add_refl r a' *> mk_mapp `rfl [none,a]
| (_, _) :=
(do guard $ a'.get_app_fn.is_constant ∧
a'.get_app_fn.const_name = b'.get_app_fn.const_name,
(a'',pa') ← add_symm_proof r a',
guard $ a'' =ₐ b',
pure pa' )
end,
p' ← mk_eq_trans pa p,
add_edge r a' b' p',
mk_eq_symm pb >>= mk_eq_trans p'
meta def find_eq_type (r : tauto_state) : expr → list expr → tactic (expr × expr)
| e [] := failed
| e (H :: Hs) :=
do t ← infer_type H,
t' ← infer_type e,
(prod.mk H <$> symm_eq r e t) <|> find_eq_type e Hs
private meta def contra_p_not_p (r : tauto_state) : list expr → list expr → tactic unit
| [] Hs := failed
| (H1 :: Rs) Hs :=
do t ← (extract_opt_auto_param <$> infer_type H1) >>= whnf,
(do a ← match_not t,
(H2,p) ← find_eq_type r a Hs,
H2 ← to_expr ``( (%%p).mpr %%H2 ),
tgt ← target,
pr ← mk_app `absurd [tgt, H2, H1],
tactic.exact pr)
<|> contra_p_not_p Rs Hs
meta def contradiction_with (r : tauto_state) : tactic unit :=
contradiction <|>
do tactic.try intro1,
ctx ← local_context,
contra_p_not_p r ctx ctx
meta def contradiction_symm :=
using_new_ref (native.rb_map.mk _ _) contradiction_with
meta def assumption_with (r : tauto_state) : tactic unit :=
do { ctx ← local_context,
t ← target,
(H,p) ← find_eq_type r t ctx,
mk_eq_mpr p H >>= tactic.exact }
<|> fail "assumption tactic failed"
meta def assumption_symm :=
using_new_ref (native.rb_map.mk _ _) assumption_with
meta def tautology (c : bool := ff) : tactic unit :=
do when c classical,
using_new_ref (expr_map.mk _) $ λ r,
do try (contradiction_with r);
try (assumption_with r);
repeat (do
gs ← get_goals,
repeat (() <$ tactic.intro1);
distrib_not;
casesm (some ()) [``(_ ∧ _),``(_ ∨ _),``(Exists _),``(false)];
try (contradiction_with r);
try (target >>= match_or >> refine ``( or_iff_not_imp_left.mpr _));
try (target >>= match_or >> refine ``( or_iff_not_imp_right.mpr _));
repeat (() <$ tactic.intro1);
constructor_matching (some ()) [``(_ ∧ _),``(_ ↔ _),``(true)];
try (assumption_with r),
gs' ← get_goals,
guard (gs ≠ gs') ) ;
repeat
(reflexivity <|> solve_by_elim <|>
constructor_matching none [``(_ ∧ _),``(_ ↔ _),``(Exists _),``(true)] ) ;
done
open interactive lean.parser
namespace interactive
local postfix `?`:9001 := optional
/--
`tautology` breaks down assumptions of the form `_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `∃ _, _`
and splits a goal of the form `_ ∧ _`, `_ ↔ _` or `∃ _, _` until it can be discharged
using `reflexivity` or `solve_by_elim`.
This is a finishing tactic: it either closes the goal or raises an error.
The variant `tautology!` uses the law of excluded middle.
-/
meta def tautology (c : parse $ (tk "!")?) := tactic.tautology c.is_some
-- Now define a shorter name for the tactic `tautology`.
/--
`tauto` breaks down assumptions of the form `_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `∃ _, _`
and splits a goal of the form `_ ∧ _`, `_ ↔ _` or `∃ _, _` until it can be discharged
using `reflexivity` or `solve_by_elim`.
This is a finishing tactic: it either closes the goal or raises an error.
The variant `tauto!` uses the law of excluded middle.
-/
meta def tauto (c : parse $ (tk "!")?) := tautology c
add_hint_tactic "tauto"
/--
This tactic (with shorthand `tauto`) breaks down assumptions of the form
`_ ∧ _`, `_ ∨ _`, `_ ↔ _` and `∃ _, _`
and splits a goal of the form `_ ∧ _`, `_ ↔ _` or `∃ _, _` until it can be discharged
using `reflexivity` or `solve_by_elim`. This is a finishing tactic: it
either closes the goal or raises an error.
The variants `tautology!` and `tauto!` use the law of excluded middle.
For instance, one can write:
```lean
example (p q r : Prop) [decidable p] [decidable r] : p ∨ (q ∧ r) ↔ (p ∨ q) ∧ (r ∨ p ∨ r) := by tauto
```
and the decidability assumptions can be dropped if `tauto!` is used
instead of `tauto`.
-/
add_tactic_doc
{ name := "tautology",
category := doc_category.tactic,
decl_names := [`tactic.interactive.tautology, `tactic.interactive.tauto],
tags := ["logic", "decision procedure"] }
end interactive
end tactic
|
63bad01ae7364d2309af48f97c56c86385888bd3
|
2c41ae31b2b771ad5646ad880201393f5269a7f0
|
/Lean/Qualities/Speed.lean
|
49390551268609295b3809f3a4597d3bd0b738c6
|
[] |
no_license
|
kevinsullivan/Boehm
|
926f25bc6f1a8b6bd47d333d936fdfc278228312
|
55208395bff20d48a598b7fa33a4d55a2447a9cf
|
refs/heads/master
| 1,586,127,134,302
| 1,488,252,326,000
| 1,488,252,326,000
| 32,836,930
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 538
|
lean
|
-- Speed
/-
[Speed] is parameterized by an instance of type [SystemType], and it's a sub-attribute to [MissionEffective].
-/
import SystemModel.System
inductive Speed (sys_type: SystemType): Prop
| intro : (exists speed: sys_type ^.Contexts -> sys_type ^.Phases -> sys_type ^.Stakeholders -> @SystemInstance sys_type -> Prop,
forall c: sys_type ^.Contexts, forall p: sys_type ^.Phases,
forall s: sys_type ^.Stakeholders, forall st: @SystemInstance sys_type, speed c p s st) ->
Speed
|
c1e2255e86fe0fc977dfb3a895168ba43517e5ca
|
7cef822f3b952965621309e88eadf618da0c8ae9
|
/src/data/set/intervals/basic.lean
|
50b06d79a57e5f3d96daa97dde640391c0af7bc2
|
[
"Apache-2.0"
] |
permissive
|
rmitta/mathlib
|
8d90aee30b4db2b013e01f62c33f297d7e64a43d
|
883d974b608845bad30ae19e27e33c285200bf84
|
refs/heads/master
| 1,585,776,832,544
| 1,576,874,096,000
| 1,576,874,096,000
| 153,663,165
| 0
| 2
|
Apache-2.0
| 1,544,806,490,000
| 1,539,884,365,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 20,743
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Patrick Massot
-/
import order.lattice algebra.order_functions algebra.ordered_field tactic.tauto
/-!
# Intervals
In any preorder `α`, we define intervals (which on each side can be either infinite, open, or
closed) using the following naming conventions:
- `i`: infinite
- `o`: open
- `c`: closed
Each interval has the name `I` + letter for left side + letter for right side. For instance,
`Ioc a b` denotes the inverval `(a, b]`.
This file contains these definitions, and basic facts on inclusion, intersection, difference of
intervals (where the precise statements may depend on the properties of the order, in particular
for some statements it should be `linear_order` or `densely_ordered`).
This file also contains statements on lower and upper bounds of intervals.
TODO: This is just the beginning; a lot of rules are missing
-/
universe u
namespace set
open set
section intervals
variables {α : Type u} [preorder α] {a a₁ a₂ b b₁ b₂ x : α}
/-- Left-open right-open interval -/
def Ioo (a b : α) := {x | a < x ∧ x < b}
/-- Left-closed right-open interval -/
def Ico (a b : α) := {x | a ≤ x ∧ x < b}
/-- Left-infinite right-open interval -/
def Iio (a : α) := {x | x < a}
/-- Left-closed right-closed interval -/
def Icc (a b : α) := {x | a ≤ x ∧ x ≤ b}
/-- Left-infinite right-closed interval -/
def Iic (b : α) := {x | x ≤ b}
/-- Left-open right-closed interval -/
def Ioc (a b : α) := {x | a < x ∧ x ≤ b}
/-- Left-closed right-infinite interval -/
def Ici (a : α) := {x | a ≤ x}
/-- Left-open right-infinite interval -/
def Ioi (a : α) := {x | a < x}
@[simp] lemma mem_Ioo : x ∈ Ioo a b ↔ a < x ∧ x < b := iff.rfl
@[simp] lemma mem_Ico : x ∈ Ico a b ↔ a ≤ x ∧ x < b := iff.rfl
@[simp] lemma mem_Iio : x ∈ Iio b ↔ x < b := iff.rfl
@[simp] lemma mem_Icc : x ∈ Icc a b ↔ a ≤ x ∧ x ≤ b := iff.rfl
@[simp] lemma mem_Iic : x ∈ Iic b ↔ x ≤ b := iff.rfl
@[simp] lemma mem_Ioc : x ∈ Ioc a b ↔ a < x ∧ x ≤ b := iff.rfl
@[simp] lemma mem_Ici : x ∈ Ici a ↔ a ≤ x := iff.rfl
@[simp] lemma mem_Ioi : x ∈ Ioi a ↔ a < x := iff.rfl
@[simp] lemma left_mem_Ioo : a ∈ Ioo a b ↔ false := by simp [lt_irrefl]
@[simp] lemma left_mem_Ico : a ∈ Ico a b ↔ a < b := by simp [le_refl]
@[simp] lemma left_mem_Icc : a ∈ Icc a b ↔ a ≤ b := by simp [le_refl]
@[simp] lemma left_mem_Ioc : a ∈ Ioc a b ↔ false := by simp [lt_irrefl]
lemma left_mem_Ici : a ∈ Ici a := by simp
@[simp] lemma right_mem_Ioo : b ∈ Ioo a b ↔ false := by simp [lt_irrefl]
@[simp] lemma right_mem_Ico : b ∈ Ico a b ↔ false := by simp [lt_irrefl]
@[simp] lemma right_mem_Icc : b ∈ Icc a b ↔ a ≤ b := by simp [le_refl]
@[simp] lemma right_mem_Ioc : b ∈ Ioc a b ↔ a < b := by simp [le_refl]
lemma right_mem_Iic : a ∈ Iic a := by simp
@[simp] lemma dual_Ici : @Ici (order_dual α) _ a = @Iic α _ a := rfl
@[simp] lemma dual_Iic : @Iic (order_dual α) _ a = @Ici α _ a := rfl
@[simp] lemma dual_Ioi : @Ioi (order_dual α) _ a = @Iio α _ a := rfl
@[simp] lemma dual_Iio : @Iio (order_dual α) _ a = @Ioi α _ a := rfl
@[simp] lemma dual_Icc : @Icc (order_dual α) _ a b = @Icc α _ b a :=
set.ext $ λ x, and_comm _ _
@[simp] lemma dual_Ioc : @Ioc (order_dual α) _ a b = @Ico α _ b a :=
set.ext $ λ x, and_comm _ _
@[simp] lemma dual_Ico : @Ico (order_dual α) _ a b = @Ioc α _ b a :=
set.ext $ λ x, and_comm _ _
@[simp] lemma dual_Ioo : @Ioo (order_dual α) _ a b = @Ioo α _ b a :=
set.ext $ λ x, and_comm _ _
@[simp] lemma nonempty_Icc : (Icc a b).nonempty ↔ a ≤ b :=
⟨λ ⟨x, hx⟩, le_trans hx.1 hx.2, λ h, ⟨a, left_mem_Icc.2 h⟩⟩
@[simp] lemma nonempty_Ico : (Ico a b).nonempty ↔ a < b :=
⟨λ ⟨x, hx⟩, lt_of_le_of_lt hx.1 hx.2, λ h, ⟨a, left_mem_Ico.2 h⟩⟩
@[simp] lemma nonempty_Ioc : (Ioc a b).nonempty ↔ a < b :=
⟨λ ⟨x, hx⟩, lt_of_lt_of_le hx.1 hx.2, λ h, ⟨b, right_mem_Ioc.2 h⟩⟩
lemma nonempty_Ici : (Ici a).nonempty := ⟨a, left_mem_Ici⟩
lemma nonempty_Iic : (Iic a).nonempty := ⟨a, right_mem_Iic⟩
@[simp] lemma Ioo_eq_empty (h : b ≤ a) : Ioo a b = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ x ⟨h₁, h₂⟩, not_le_of_lt (lt_trans h₁ h₂) h
@[simp] lemma Ico_eq_empty (h : b ≤ a) : Ico a b = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ x ⟨h₁, h₂⟩, not_le_of_lt (lt_of_le_of_lt h₁ h₂) h
@[simp] lemma Icc_eq_empty (h : b < a) : Icc a b = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ x ⟨h₁, h₂⟩, not_lt_of_le (le_trans h₁ h₂) h
@[simp] lemma Ioc_eq_empty (h : b ≤ a) : Ioc a b = ∅ :=
eq_empty_iff_forall_not_mem.2 $ λ x ⟨h₁, h₂⟩, not_lt_of_le (le_trans h₂ h) h₁
@[simp] lemma Ioo_self (a : α) : Ioo a a = ∅ := Ioo_eq_empty $ le_refl _
@[simp] lemma Ico_self (a : α) : Ico a a = ∅ := Ico_eq_empty $ le_refl _
@[simp] lemma Ioc_self (a : α) : Ioc a a = ∅ := Ioc_eq_empty $ le_refl _
lemma Iio_ne_empty [no_bot_order α] (a : α) : Iio a ≠ ∅ :=
ne_empty_iff_exists_mem.2 (no_bot a)
lemma Ioi_ne_empty [no_top_order α] (a : α) : Ioi a ≠ ∅ :=
ne_empty_iff_exists_mem.2 (no_top a)
lemma Iic_ne_empty (b : α) : Iic b ≠ ∅ :=
ne_empty_iff_exists_mem.2 ⟨b, le_refl b⟩
lemma Ici_ne_empty (a : α) : Ici a ≠ ∅ :=
ne_empty_iff_exists_mem.2 ⟨a, le_refl a⟩
lemma Ici_subset_Ioi : Ici a ⊆ Ioi b ↔ b < a :=
⟨λ h, h left_mem_Ici, λ h x hx, lt_of_lt_of_le h hx⟩
lemma Iic_subset_Iio : Iic a ⊆ Iio b ↔ a < b :=
⟨λ h, h right_mem_Iic, λ h x hx, lt_of_le_of_lt hx h⟩
lemma Ioo_subset_Ioo (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) :
Ioo a₁ b₁ ⊆ Ioo a₂ b₂ :=
λ x ⟨hx₁, hx₂⟩, ⟨lt_of_le_of_lt h₁ hx₁, lt_of_lt_of_le hx₂ h₂⟩
lemma Ioo_subset_Ioo_left (h : a₁ ≤ a₂) : Ioo a₂ b ⊆ Ioo a₁ b :=
Ioo_subset_Ioo h (le_refl _)
lemma Ioo_subset_Ioo_right (h : b₁ ≤ b₂) : Ioo a b₁ ⊆ Ioo a b₂ :=
Ioo_subset_Ioo (le_refl _) h
lemma Ico_subset_Ico (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ :=
λ x ⟨hx₁, hx₂⟩, ⟨le_trans h₁ hx₁, lt_of_lt_of_le hx₂ h₂⟩
lemma Ico_subset_Ico_left (h : a₁ ≤ a₂) : Ico a₂ b ⊆ Ico a₁ b :=
Ico_subset_Ico h (le_refl _)
lemma Ico_subset_Ico_right (h : b₁ ≤ b₂) : Ico a b₁ ⊆ Ico a b₂ :=
Ico_subset_Ico (le_refl _) h
lemma Icc_subset_Icc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) :
Icc a₁ b₁ ⊆ Icc a₂ b₂ :=
λ x ⟨hx₁, hx₂⟩, ⟨le_trans h₁ hx₁, le_trans hx₂ h₂⟩
lemma Icc_subset_Icc_left (h : a₁ ≤ a₂) : Icc a₂ b ⊆ Icc a₁ b :=
Icc_subset_Icc h (le_refl _)
lemma Icc_subset_Icc_right (h : b₁ ≤ b₂) : Icc a b₁ ⊆ Icc a b₂ :=
Icc_subset_Icc (le_refl _) h
lemma Ioc_subset_Ioc (h₁ : a₂ ≤ a₁) (h₂ : b₁ ≤ b₂) :
Ioc a₁ b₁ ⊆ Ioc a₂ b₂ :=
λ x ⟨hx₁, hx₂⟩, ⟨lt_of_le_of_lt h₁ hx₁, le_trans hx₂ h₂⟩
lemma Ioc_subset_Ioc_left (h : a₁ ≤ a₂) : Ioc a₂ b ⊆ Ioc a₁ b :=
Ioc_subset_Ioc h (le_refl _)
lemma Ioc_subset_Ioc_right (h : b₁ ≤ b₂) : Ioc a b₁ ⊆ Ioc a b₂ :=
Ioc_subset_Ioc (le_refl _) h
lemma Ico_subset_Ioo_left (h₁ : a₁ < a₂) : Ico a₂ b ⊆ Ioo a₁ b :=
λ x, and.imp_left $ lt_of_lt_of_le h₁
lemma Icc_subset_Ico_right (h₁ : b₁ < b₂) : Icc a b₁ ⊆ Ico a b₂ :=
λ x, and.imp_right $ λ h₂, lt_of_le_of_lt h₂ h₁
lemma Ioo_subset_Ico_self : Ioo a b ⊆ Ico a b := λ x, and.imp_left le_of_lt
lemma Ioo_subset_Ioc_self : Ioo a b ⊆ Ioc a b := λ x, and.imp_right le_of_lt
lemma Ico_subset_Icc_self : Ico a b ⊆ Icc a b := λ x, and.imp_right le_of_lt
lemma Ioc_subset_Icc_self : Ioc a b ⊆ Icc a b := λ x, and.imp_left le_of_lt
lemma Ioo_subset_Icc_self : Ioo a b ⊆ Icc a b :=
subset.trans Ioo_subset_Ico_self Ico_subset_Icc_self
lemma Ico_subset_Iio_self : Ico a b ⊆ Iio b := λ x, and.right
lemma Ioo_subset_Iio_self : Ioo a b ⊆ Iio b := λ x, and.right
lemma Ioc_subset_Ioi_self : Ioc a b ⊆ Ioi a := λ x, and.left
lemma Ioo_subset_Ioi_self : Ioo a b ⊆ Ioi a := λ x, and.left
lemma Ioi_subset_Ici_self : Ioi a ⊆ Ici a := λx hx, le_of_lt hx
lemma Iio_subset_Iic_self : Iio a ⊆ Iic a := λx hx, le_of_lt hx
lemma Icc_subset_Icc_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Icc a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨λ h, ⟨(h ⟨le_refl _, h₁⟩).1, (h ⟨h₁, le_refl _⟩).2⟩,
λ ⟨h, h'⟩ x ⟨hx, hx'⟩, ⟨le_trans h hx, le_trans hx' h'⟩⟩
lemma Icc_subset_Ioo_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ < a₁ ∧ b₁ < b₂ :=
⟨λ h, ⟨(h ⟨le_refl _, h₁⟩).1, (h ⟨h₁, le_refl _⟩).2⟩,
λ ⟨h, h'⟩ x ⟨hx, hx'⟩, ⟨lt_of_lt_of_le h hx, lt_of_le_of_lt hx' h'⟩⟩
lemma Icc_subset_Ico_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ < b₂ :=
⟨λ h, ⟨(h ⟨le_refl _, h₁⟩).1, (h ⟨h₁, le_refl _⟩).2⟩,
λ ⟨h, h'⟩ x ⟨hx, hx'⟩, ⟨le_trans h hx, lt_of_le_of_lt hx' h'⟩⟩
lemma Icc_subset_Ioc_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Ioc a₂ b₂ ↔ a₂ < a₁ ∧ b₁ ≤ b₂ :=
⟨λ h, ⟨(h ⟨le_refl _, h₁⟩).1, (h ⟨h₁, le_refl _⟩).2⟩,
λ ⟨h, h'⟩ x ⟨hx, hx'⟩, ⟨lt_of_lt_of_le h hx, le_trans hx' h'⟩⟩
lemma Icc_subset_Iio_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Iio b₂ ↔ b₁ < b₂ :=
⟨λ h, h ⟨h₁, le_refl _⟩, λ h x ⟨hx, hx'⟩, lt_of_le_of_lt hx' h⟩
lemma Icc_subset_Ioi_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Ioi a₂ ↔ a₂ < a₁ :=
⟨λ h, h ⟨le_refl _, h₁⟩, λ h x ⟨hx, hx'⟩, lt_of_lt_of_le h hx⟩
lemma Icc_subset_Iic_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Iic b₂ ↔ b₁ ≤ b₂ :=
⟨λ h, h ⟨h₁, le_refl _⟩, λ h x ⟨hx, hx'⟩, le_trans hx' h⟩
lemma Icc_subset_Ici_iff (h₁ : a₁ ≤ b₁) :
Icc a₁ b₁ ⊆ Ici a₂ ↔ a₂ ≤ a₁ :=
⟨λ h, h ⟨le_refl _, h₁⟩, λ h x ⟨hx, hx'⟩, le_trans h hx⟩
/-- If `a ≤ b`, then `(b, +∞) ⊆ (a, +∞)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Ioi_subset_Ioi_iff`. -/
lemma Ioi_subset_Ioi (h : a ≤ b) : Ioi b ⊆ Ioi a :=
λx hx, lt_of_le_of_lt h hx
/-- If `a ≤ b`, then `(b, +∞) ⊆ [a, +∞)`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Ioi_subset_Ici_iff`. -/
lemma Ioi_subset_Ici (h : a ≤ b) : Ioi b ⊆ Ici a :=
subset.trans (Ioi_subset_Ioi h) Ioi_subset_Ici_self
/-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b)`. In preorders, this is just an implication. If you need
the equivalence in linear orders, use `Iio_subset_Iio_iff`. -/
lemma Iio_subset_Iio (h : a ≤ b) : Iio a ⊆ Iio b :=
λx hx, lt_of_lt_of_le hx h
/-- If `a ≤ b`, then `(-∞, a) ⊆ (-∞, b]`. In preorders, this is just an implication. If you need
the equivalence in dense linear orders, use `Iio_subset_Iic_iff`. -/
lemma Iio_subset_Iic (h : a ≤ b) : Iio a ⊆ Iic b :=
subset.trans (Iio_subset_Iio h) Iio_subset_Iic_self
lemma Ici_inter_Iic : Ici a ∩ Iic b = Icc a b := rfl
lemma Ici_inter_Iio : Ici a ∩ Iio b = Ico a b := rfl
lemma Ioi_inter_Iic : Ioi a ∩ Iic b = Ioc a b := rfl
lemma Ioi_inter_Iio : Ioi a ∩ Iio b = Ioo a b := rfl
end intervals
section partial_order
variables {α : Type u} [partial_order α] {a b : α}
@[simp] lemma Icc_self (a : α) : Icc a a = {a} :=
set.ext $ by simp [Icc, le_antisymm_iff, and_comm]
lemma Ico_diff_Ioo_eq_singleton (h : a < b) : Ico a b \ Ioo a b = {a} :=
set.ext $ λ x, begin
simp [not_and'], split,
{ rintro ⟨⟨ax, xb⟩, hne⟩,
exact (eq_or_lt_of_le ax).elim eq.symm (λ h', absurd h' (hne xb)) },
{ rintro rfl, exact ⟨⟨le_refl _, h⟩, λ _, lt_irrefl x⟩ }
end
lemma Ioc_diff_Ioo_eq_singleton (h : a < b) : Ioc a b \ Ioo a b = {b} :=
set.ext $ λ x, begin
simp, split,
{ rintro ⟨⟨ax, xb⟩, hne⟩,
exact (eq_or_lt_of_le xb).elim id (λ h', absurd h' (hne ax)) },
{ rintro rfl, exact ⟨⟨h, le_refl _⟩, λ _, lt_irrefl x⟩ }
end
lemma Icc_diff_Ico_eq_singleton (h : a ≤ b) : Icc a b \ Ico a b = {b} :=
set.ext $ λ x, begin
simp, split,
{ rintro ⟨⟨ax, xb⟩, h⟩,
exact classical.by_contradiction
(λ ne, h ax (lt_of_le_of_ne xb ne)) },
{ rintro rfl, exact ⟨⟨h, le_refl _⟩, λ _, lt_irrefl x⟩ }
end
lemma Icc_diff_Ioc_eq_singleton (h : a ≤ b) : Icc a b \ Ioc a b = {a} :=
set.ext $ λ x, begin
simp [not_and'], split,
{ rintro ⟨⟨ax, xb⟩, h⟩,
exact classical.by_contradiction
(λ hne, h xb (lt_of_le_of_ne ax (ne.symm hne))) },
{ rintro rfl, exact ⟨⟨le_refl _, h⟩, λ _, lt_irrefl x⟩ }
end
end partial_order
section linear_order
variables {α : Type u} [linear_order α] {a a₁ a₂ b b₁ b₂ : α}
lemma Ioo_eq_empty_iff [densely_ordered α] : Ioo a b = ∅ ↔ b ≤ a :=
⟨λ eq, le_of_not_lt $ λ h,
let ⟨x, h₁, h₂⟩ := dense h in
eq_empty_iff_forall_not_mem.1 eq x ⟨h₁, h₂⟩,
Ioo_eq_empty⟩
lemma Ico_eq_empty_iff : Ico a b = ∅ ↔ b ≤ a :=
⟨λ eq, le_of_not_lt $ λ h, eq_empty_iff_forall_not_mem.1 eq a ⟨le_refl _, h⟩,
Ico_eq_empty⟩
lemma Icc_eq_empty_iff : Icc a b = ∅ ↔ b < a :=
⟨λ eq, lt_of_not_ge $ λ h, eq_empty_iff_forall_not_mem.1 eq a ⟨le_refl _, h⟩,
Icc_eq_empty⟩
lemma Ico_subset_Ico_iff (h₁ : a₁ < b₁) :
Ico a₁ b₁ ⊆ Ico a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨λ h, have a₂ ≤ a₁ ∧ a₁ < b₂ := h ⟨le_refl _, h₁⟩,
⟨this.1, le_of_not_lt $ λ h', lt_irrefl b₂ (h ⟨le_of_lt this.2, h'⟩).2⟩,
λ ⟨h₁, h₂⟩, Ico_subset_Ico h₁ h₂⟩
lemma Ioo_subset_Ioo_iff [densely_ordered α] (h₁ : a₁ < b₁) :
Ioo a₁ b₁ ⊆ Ioo a₂ b₂ ↔ a₂ ≤ a₁ ∧ b₁ ≤ b₂ :=
⟨λ h, begin
rcases dense h₁ with ⟨x, xa, xb⟩,
split; refine le_of_not_lt (λ h', _),
{ have ab := lt_trans (h ⟨xa, xb⟩).1 xb,
exact lt_irrefl _ (h ⟨h', ab⟩).1 },
{ have ab := lt_trans xa (h ⟨xa, xb⟩).2,
exact lt_irrefl _ (h ⟨ab, h'⟩).2 }
end, λ ⟨h₁, h₂⟩, Ioo_subset_Ioo h₁ h₂⟩
lemma Ico_eq_Ico_iff (h : a₁ < b₁ ∨ a₂ < b₂) : Ico a₁ b₁ = Ico a₂ b₂ ↔ a₁ = a₂ ∧ b₁ = b₂ :=
⟨λ e, begin
simp [subset.antisymm_iff] at e, simp [le_antisymm_iff],
cases h; simp [Ico_subset_Ico_iff h] at e;
[ rcases e with ⟨⟨h₁, h₂⟩, e'⟩, rcases e with ⟨e', ⟨h₁, h₂⟩⟩ ];
have := (Ico_subset_Ico_iff (lt_of_le_of_lt h₁ $ lt_of_lt_of_le h h₂)).1 e';
tauto
end, λ ⟨h₁, h₂⟩, by rw [h₁, h₂]⟩
@[simp] lemma Ioi_subset_Ioi_iff : Ioi b ⊆ Ioi a ↔ a ≤ b :=
begin
refine ⟨λh, _, λh, Ioi_subset_Ioi h⟩,
classical,
by_contradiction ba,
exact lt_irrefl _ (h (not_le.mp ba))
end
@[simp] lemma Ioi_subset_Ici_iff [densely_ordered α] : Ioi b ⊆ Ici a ↔ a ≤ b :=
begin
refine ⟨λh, _, λh, Ioi_subset_Ici h⟩,
classical,
by_contradiction ba,
obtain ⟨c, bc, ca⟩ : ∃c, b < c ∧ c < a := dense (not_le.mp ba),
exact lt_irrefl _ (lt_of_lt_of_le ca (h bc))
end
@[simp] lemma Iio_subset_Iio_iff : Iio a ⊆ Iio b ↔ a ≤ b :=
begin
refine ⟨λh, _, λh, Iio_subset_Iio h⟩,
classical,
by_contradiction ab,
exact lt_irrefl _ (h (not_le.mp ab))
end
@[simp] lemma Iio_subset_Iic_iff [densely_ordered α] : Iio a ⊆ Iic b ↔ a ≤ b :=
begin
refine ⟨λh, _, λh, Iio_subset_Iic h⟩,
classical,
by_contradiction ba,
obtain ⟨c, bc, ca⟩ : ∃c, b < c ∧ c < a := dense (not_le.mp ba),
exact lt_irrefl _ (lt_of_lt_of_le bc (h ca))
end
end linear_order
section lattice
open lattice
section inf
variables {α : Type u} [semilattice_inf α]
@[simp] lemma Iic_inter_Iic {a b : α} : Iic a ∩ Iic b = Iic (a ⊓ b) :=
by { ext x, simp [Iic] }
@[simp] lemma Iio_inter_Iio [is_total α (≤)] {a b : α} : Iio a ∩ Iio b = Iio (a ⊓ b) :=
by { ext x, simp [Iio] }
end inf
section sup
variables {α : Type u} [semilattice_sup α]
@[simp] lemma Ici_inter_Ici {a b : α} : Ici a ∩ Ici b = Ici (a ⊔ b) :=
by { ext x, simp [Ici] }
@[simp] lemma Ioi_inter_Ioi [is_total α (≤)] {a b : α} : Ioi a ∩ Ioi b = Ioi (a ⊔ b) :=
by { ext x, simp [Ioi] }
end sup
section both
variables {α : Type u} [lattice α] [ht : is_total α (≤)] {a₁ a₂ b₁ b₂ : α}
lemma Icc_inter_Icc : Icc a₁ b₁ ∩ Icc a₂ b₂ = Icc (a₁ ⊔ a₂) (b₁ ⊓ b₂) :=
by simp only [Ici_inter_Iic.symm, Ici_inter_Ici.symm, Iic_inter_Iic.symm]; ac_refl
include ht
lemma Ico_inter_Ico : Ico a₁ b₁ ∩ Ico a₂ b₂ = Ico (a₁ ⊔ a₂) (b₁ ⊓ b₂) :=
by simp only [Ici_inter_Iio.symm, Ici_inter_Ici.symm, Iio_inter_Iio.symm]; ac_refl
lemma Ioc_inter_Ioc : Ioc a₁ b₁ ∩ Ioc a₂ b₂ = Ioc (a₁ ⊔ a₂) (b₁ ⊓ b₂) :=
by simp only [Ioi_inter_Iic.symm, Ioi_inter_Ioi.symm, Iic_inter_Iic.symm]; ac_refl
lemma Ioo_inter_Ioo : Ioo a₁ b₁ ∩ Ioo a₂ b₂ = Ioo (a₁ ⊔ a₂) (b₁ ⊓ b₂) :=
by simp only [Ioi_inter_Iio.symm, Ioi_inter_Ioi.symm, Iio_inter_Iio.symm]; ac_refl
end both
end lattice
section decidable_linear_order
variables {α : Type u} [decidable_linear_order α] {a a₁ a₂ b b₁ b₂ : α}
@[simp] lemma Ico_diff_Iio {a b c : α} : Ico a b \ Iio c = Ico (max a c) b :=
set.ext $ by simp [Ico, Iio, iff_def, max_le_iff] {contextual:=tt}
@[simp] lemma Ico_inter_Iio {a b c : α} : Ico a b ∩ Iio c = Ico a (min b c) :=
set.ext $ by simp [Ico, Iio, iff_def, lt_min_iff] {contextual:=tt}
end decidable_linear_order
section ordered_comm_group
variables {α : Type u} [ordered_comm_group α]
lemma image_add_left_Icc (a b c : α) : ((+) a) '' Icc b c = Icc (a + b) (a + c) :=
begin
ext x,
split,
{ rintros ⟨x, hx, rfl⟩,
exact ⟨add_le_add_left hx.1 a, add_le_add_left hx.2 a⟩},
{ intro hx,
refine ⟨-a + x, _, add_neg_cancel_left _ _⟩,
exact ⟨le_neg_add_iff_add_le.2 hx.1, neg_add_le_iff_le_add.2 hx.2⟩ }
end
lemma image_add_right_Icc (a b c : α) : (λ x, x + c) '' Icc a b = Icc (a + c) (b + c) :=
by convert image_add_left_Icc c a b using 1; simp only [add_comm _ c]
lemma image_neg_Iio (r : α) : image (λz, -z) (Iio r) = Ioi (-r) :=
begin
ext z,
apply iff.intro,
{ intros hz,
apply exists.elim hz,
intros z' hz',
rw [←hz'.2],
simp only [mem_Ioi, neg_lt_neg_iff],
exact hz'.1 },
{ intros hz,
simp only [mem_image, mem_Iio],
use -z,
simp [hz],
exact neg_lt.1 hz }
end
lemma image_neg_Iic (r : α) : image (λz, -z) (Iic r) = Ici (-r) :=
begin
apply set.ext,
intros z,
apply iff.intro,
{ intros hz,
apply exists.elim hz,
intros z' hz',
rw [←hz'.2],
simp only [neg_le_neg_iff, mem_Ici],
exact hz'.1 },
{ intros hz,
simp only [mem_image, mem_Iic],
use -z,
simp [hz],
exact neg_le.1 hz }
end
end ordered_comm_group
section decidable_linear_ordered_comm_group
variables {α : Type u} [decidable_linear_ordered_comm_group α]
/-- If we remove a smaller interval from a larger, the result is nonempty -/
lemma nonempty_Ico_sdiff {x dx y dy : α} (h : dy < dx) (hx : 0 < dx) :
nonempty ↥(Ico x (x + dx) \ Ico y (y + dy)) :=
begin
cases lt_or_le x y with h' h',
{ use x, simp* },
{ use max x (x + dy), simp [*, le_refl] }
end
end decidable_linear_ordered_comm_group
section linear_ordered_field
variables {α : Type u} [linear_ordered_field α]
lemma image_mul_right_Icc' (a b : α) {c : α} (h : 0 < c) :
(λ x, x * c) '' Icc a b = Icc (a * c) (b * c) :=
begin
ext x,
split,
{ rintros ⟨x, hx, rfl⟩,
exact ⟨mul_le_mul_of_nonneg_right hx.1 (le_of_lt h),
mul_le_mul_of_nonneg_right hx.2 (le_of_lt h)⟩ },
{ intro hx,
refine ⟨x / c, _, div_mul_cancel x (ne_of_gt h)⟩,
exact ⟨le_div_of_mul_le h hx.1, div_le_of_le_mul h (mul_comm b c ▸ hx.2)⟩ }
end
lemma image_mul_right_Icc {a b c : α} (hab : a ≤ b) (hc : 0 ≤ c) :
(λ x, x * c) '' Icc a b = Icc (a * c) (b * c) :=
begin
cases eq_or_lt_of_le hc,
{ subst c,
simp [(nonempty_Icc.2 hab).image_const] },
exact image_mul_right_Icc' a b ‹0 < c›
end
lemma image_mul_left_Icc' {a : α} (h : 0 < a) (b c : α) :
((*) a) '' Icc b c = Icc (a * b) (a * c) :=
by { convert image_mul_right_Icc' b c h using 1; simp only [mul_comm _ a] }
lemma image_mul_left_Icc {a b c : α} (ha : 0 ≤ a) (hbc : b ≤ c) :
((*) a) '' Icc b c = Icc (a * b) (a * c) :=
by { convert image_mul_right_Icc hbc ha using 1; simp only [mul_comm _ a] }
end linear_ordered_field
end set
|
422a8dde32787f2869755901c16370756bf2e237
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/topology/instances/add_circle.lean
|
008031f3968c7244f1eeb5e4e30ce1d52ed4f1d0
|
[
"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
| 12,143
|
lean
|
/-
Copyright (c) 2022 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import group_theory.divisible
import group_theory.order_of_element
import ring_theory.int.basic
import algebra.order.floor
import algebra.order.to_interval_mod
import topology.instances.real
/-!
# The additive circle
We define the additive circle `add_circle p` as the quotient `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`.
See also `circle` and `real.angle`. For the normed group structure on `add_circle`, see
`add_circle.normed_add_comm_group` in a later file.
## Main definitions:
* `add_circle`: the additive circle `𝕜 ⧸ (ℤ ∙ p)` for some period `p : 𝕜`
* `unit_add_circle`: the special case `ℝ ⧸ ℤ`
* `add_circle.equiv_add_circle`: the rescaling equivalence `add_circle p ≃+ add_circle q`
* `add_circle.equiv_Ico`: the natural equivalence `add_circle p ≃ Ico 0 p`
* `add_circle.add_order_of_div_of_gcd_eq_one`: rational points have finite order
* `add_circle.exists_gcd_eq_one_of_is_of_fin_add_order`: finite-order points are rational
## Implementation notes:
Although the most important case is `𝕜 = ℝ` we wish to support other types of scalars, such as
the rational circle `add_circle (1 : ℚ)`, and so we set things up more generally.
## TODO
* Link with periodicity
* Lie group structure
* Exponential equivalence to `circle`
-/
noncomputable theory
open set add_subgroup topological_space
variables {𝕜 : Type*}
/-- The "additive circle": `𝕜 ⧸ (ℤ ∙ p)`. See also `circle` and `real.angle`. -/
@[derive [add_comm_group, topological_space, topological_add_group, inhabited, has_coe_t 𝕜],
nolint unused_arguments]
def add_circle [linear_ordered_add_comm_group 𝕜] [topological_space 𝕜] [order_topology 𝕜] (p : 𝕜) :=
𝕜 ⧸ zmultiples p
namespace add_circle
section linear_ordered_add_comm_group
variables [linear_ordered_add_comm_group 𝕜] [topological_space 𝕜] [order_topology 𝕜] (p : 𝕜)
lemma coe_nsmul {n : ℕ} {x : 𝕜} : (↑(n • x) : add_circle p) = n • (x : add_circle p) := rfl
lemma coe_zsmul {n : ℤ} {x : 𝕜} : (↑(n • x) : add_circle p) = n • (x : add_circle p) := rfl
lemma coe_neg {x : 𝕜} : (↑(-x) : add_circle p) = -(x : add_circle p) := rfl
lemma coe_eq_zero_iff {x : 𝕜} : (x : add_circle p) = 0 ↔ ∃ (n : ℤ), n • p = x :=
by simp [add_subgroup.mem_zmultiples_iff]
lemma coe_eq_zero_of_pos_iff (hp : 0 < p) {x : 𝕜} (hx : 0 < x) :
(x : add_circle p) = 0 ↔ ∃ (n : ℕ), n • p = x :=
begin
rw coe_eq_zero_iff,
split;
rintros ⟨n, rfl⟩,
{ replace hx : 0 < n,
{ contrapose! hx,
simpa only [←neg_nonneg, ←zsmul_neg, zsmul_neg'] using zsmul_nonneg hp.le (neg_nonneg.2 hx) },
exact ⟨n.to_nat, by rw [← coe_nat_zsmul, int.to_nat_of_nonneg hx.le]⟩, },
{ exact ⟨(n : ℤ), by simp⟩, },
end
@[continuity, nolint unused_arguments] protected lemma continuous_mk' :
continuous (quotient_add_group.mk' (zmultiples p) : 𝕜 → add_circle p) :=
continuous_coinduced_rng
variables [hp : fact (0 < p)]
include hp
variables [archimedean 𝕜]
/-- The natural equivalence between `add_circle p` and the half-open interval `[0, p)`. -/
def equiv_Ico : add_circle p ≃ Ico 0 p :=
(quotient_add_group.equiv_Ico_mod 0 hp.out).trans $ equiv.set.of_eq $ by rw zero_add
@[continuity] lemma continuous_equiv_Ico_symm : continuous (equiv_Ico p).symm :=
continuous_quotient_mk.comp continuous_subtype_coe
/-- The image of the closed-open interval `[0, p)` under the quotient map `𝕜 → add_circle p` is the
entire space. -/
@[simp] lemma coe_image_Ico_eq : (coe : 𝕜 → add_circle p) '' Ico 0 p = univ :=
by { rw image_eq_range, exact (equiv_Ico p).symm.range_eq_univ }
/-- The image of the closed interval `[0, p]` under the quotient map `𝕜 → add_circle p` is the
entire space. -/
@[simp] lemma coe_image_Icc_eq : (coe : 𝕜 → add_circle p) '' Icc 0 p = univ :=
eq_top_mono (image_subset _ Ico_subset_Icc_self) $ coe_image_Ico_eq _
end linear_ordered_add_comm_group
section linear_ordered_field
variables [linear_ordered_field 𝕜] [topological_space 𝕜] [order_topology 𝕜] (p q : 𝕜)
/-- An auxiliary definition used only for constructing `add_circle.equiv_add_circle`. -/
private def equiv_add_circle_aux (hp : p ≠ 0) : add_circle p →+ add_circle q :=
quotient_add_group.lift _
((quotient_add_group.mk' (zmultiples q)).comp $ add_monoid_hom.mul_right (p⁻¹ * q))
(λ x h, by obtain ⟨z, rfl⟩ := mem_zmultiples_iff.1 h; simp [hp, mul_assoc (z : 𝕜), ← mul_assoc p])
/-- The rescaling equivalence between additive circles with different periods. -/
def equiv_add_circle (hp : p ≠ 0) (hq : q ≠ 0) : add_circle p ≃+ add_circle q :=
{ to_fun := equiv_add_circle_aux p q hp,
inv_fun := equiv_add_circle_aux q p hq,
left_inv := by { rintros ⟨x⟩, show quotient_add_group.mk _ = _, congr, field_simp [hp, hq], },
right_inv := by { rintros ⟨x⟩, show quotient_add_group.mk _ = _, congr, field_simp [hp, hq], },
.. equiv_add_circle_aux p q hp }
@[simp] lemma equiv_add_circle_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
equiv_add_circle p q hp hq (x : 𝕜) = (x * (p⁻¹ * q) : 𝕜) :=
rfl
@[simp] lemma equiv_add_circle_symm_apply_mk (hp : p ≠ 0) (hq : q ≠ 0) (x : 𝕜) :
(equiv_add_circle p q hp hq).symm (x : 𝕜) = (x * (q⁻¹ * p) : 𝕜) :=
rfl
variables [hp : fact (0 < p)]
include hp
section floor_ring
variables [floor_ring 𝕜]
@[simp] lemma coe_equiv_Ico_mk_apply (x : 𝕜) :
(equiv_Ico p $ quotient_add_group.mk x : 𝕜) = int.fract (x / p) * p :=
to_Ico_mod_eq_fract_mul _ x
instance : divisible_by (add_circle p) ℤ :=
{ div := λ x n, (↑(((n : 𝕜)⁻¹) * (equiv_Ico p x : 𝕜)) : add_circle p),
div_zero := λ x,
by simp only [algebra_map.coe_zero, quotient_add_group.coe_zero, inv_zero, zero_mul],
div_cancel := λ n x hn,
begin
replace hn : (n : 𝕜) ≠ 0, { norm_cast, assumption, },
change n • quotient_add_group.mk' _ ((n : 𝕜)⁻¹ * ↑(equiv_Ico p x)) = x,
rw [← map_zsmul, ← smul_mul_assoc, zsmul_eq_mul, mul_inv_cancel hn, one_mul],
exact (equiv_Ico p).symm_apply_apply x,
end, }
end floor_ring
section finite_order_points
variables {p}
lemma add_order_of_div_of_gcd_eq_one {m n : ℕ} (hn : 0 < n) (h : gcd m n = 1) :
add_order_of (↑(↑m / ↑n * p) : add_circle p) = n :=
begin
rcases m.eq_zero_or_pos with rfl | hm, { rw [gcd_zero_left, normalize_eq] at h, simp [h], },
set x : add_circle p := ↑(↑m / ↑n * p),
have hn₀ : (n : 𝕜) ≠ 0, { norm_cast, exact ne_of_gt hn, },
have hnx : n • x = 0,
{ rw [← coe_nsmul, nsmul_eq_mul, ← mul_assoc, mul_div, mul_div_cancel_left _ hn₀,
← nsmul_eq_mul, quotient_add_group.eq_zero_iff],
exact nsmul_mem_zmultiples p m, },
apply nat.dvd_antisymm (add_order_of_dvd_of_nsmul_eq_zero hnx),
suffices : ∃ (z : ℕ), z * n = (add_order_of x) * m,
{ obtain ⟨z, hz⟩ := this,
simpa only [h, mul_one, gcd_comm n] using dvd_mul_gcd_of_dvd_mul (dvd.intro_left z hz), },
replace hp := hp.out,
have : 0 < add_order_of x • (↑m / ↑n * p) := smul_pos
(add_order_of_pos' $ (is_of_fin_add_order_iff_nsmul_eq_zero _).2 ⟨n, hn, hnx⟩) (by positivity),
obtain ⟨z, hz⟩ := (coe_eq_zero_of_pos_iff p hp this).mp (add_order_of_nsmul_eq_zero x),
rw [← smul_mul_assoc, nsmul_eq_mul, nsmul_eq_mul, mul_left_inj' hp.ne.symm, mul_div,
eq_div_iff hn₀] at hz,
norm_cast at hz,
exact ⟨z, hz⟩,
end
lemma add_order_of_div_of_gcd_eq_one' {m : ℤ} {n : ℕ} (hn : 0 < n) (h : gcd m.nat_abs n = 1) :
add_order_of (↑(↑m / ↑n * p) : add_circle p) = n :=
begin
induction m,
{ simp only [int.of_nat_eq_coe, int.cast_coe_nat, int.nat_abs_of_nat] at h ⊢,
exact add_order_of_div_of_gcd_eq_one hn h, },
{ simp only [int.cast_neg_succ_of_nat, neg_div, neg_mul, coe_neg, order_of_neg],
exact add_order_of_div_of_gcd_eq_one hn h, },
end
lemma add_order_of_coe_rat {q : ℚ} : add_order_of (↑(↑q * p) : add_circle p) = q.denom :=
begin
have : (↑(q.denom : ℤ) : 𝕜) ≠ 0, { norm_cast, exact q.pos.ne.symm, },
rw [← @rat.num_denom q, rat.cast_mk_of_ne_zero _ _ this, int.cast_coe_nat, rat.num_denom,
add_order_of_div_of_gcd_eq_one' q.pos q.cop],
apply_instance,
end
variables (p)
lemma gcd_mul_add_order_of_div_eq {n : ℕ} (m : ℕ) (hn : 0 < n) :
gcd m n * add_order_of (↑(↑m / ↑n * p) : add_circle p) = n :=
begin
let n' := n / gcd m n,
let m' := m / gcd m n,
have h₀ : 0 < gcd m n,
{ rw zero_lt_iff at hn ⊢, contrapose! hn, exact ((gcd_eq_zero_iff m n).mp hn).2, },
have hk' : 0 < n' := nat.div_pos (nat.le_of_dvd hn $ gcd_dvd_right m n) h₀,
have hgcd : gcd m' n' = 1 := nat.coprime_div_gcd_div_gcd h₀,
simp only [mul_left_inj' hp.out.ne.symm,
← nat.cast_div_div_div_cancel_right (gcd_dvd_right m n) (gcd_dvd_left m n),
add_order_of_div_of_gcd_eq_one hk' hgcd, mul_comm _ n', nat.div_mul_cancel (gcd_dvd_right m n)],
end
variables {p} [floor_ring 𝕜]
lemma exists_gcd_eq_one_of_is_of_fin_add_order {u : add_circle p} (h : is_of_fin_add_order u) :
∃ m, gcd m (add_order_of u) = 1 ∧
m < (add_order_of u) ∧
↑(((m : 𝕜) / add_order_of u) * p) = u :=
begin
rcases eq_or_ne u 0 with rfl | hu, { exact ⟨0, by simp⟩, },
set n := add_order_of u,
change ∃ m, gcd m n = 1 ∧ m < n ∧ ↑((↑m / ↑n) * p) = u,
have hn : 0 < n := add_order_of_pos' h,
have hn₀ : (n : 𝕜) ≠ 0, { norm_cast, exact ne_of_gt hn, },
let x := (equiv_Ico p u : 𝕜),
have hxu : (x : add_circle p) = u := (equiv_Ico p).symm_apply_apply u,
have hx₀ : 0 < (add_order_of (x : add_circle p)), { rw ← hxu at h, exact add_order_of_pos' h, },
have hx₁ : 0 < x,
{ refine lt_of_le_of_ne (equiv_Ico p u).2.1 _,
contrapose! hu,
rw [← hxu, ← hu, quotient_add_group.coe_zero], },
obtain ⟨m, hm : m • p = add_order_of ↑x • x⟩ := (coe_eq_zero_of_pos_iff p hp.out
(by positivity)).mp (add_order_of_nsmul_eq_zero (x : add_circle p)),
replace hm : ↑m * p = ↑n * x, { simpa only [hxu, nsmul_eq_mul] using hm, },
have hux : ↑(↑m / ↑n * p) = u,
{ rw [← hxu, ← mul_div_right_comm, hm, mul_comm _ x, mul_div_cancel x hn₀], },
refine ⟨m, (_ : gcd m n = 1), (_ : m < n), hux⟩,
{ have := gcd_mul_add_order_of_div_eq p m hn,
rwa [hux, nat.mul_left_eq_self_iff hn] at this, },
{ have : n • x < n • p := smul_lt_smul_of_pos (equiv_Ico p u).2.2 hn,
rwa [nsmul_eq_mul, nsmul_eq_mul, ← hm, mul_lt_mul_right hp.out, nat.cast_lt] at this, },
end
end finite_order_points
end linear_ordered_field
variables (p : ℝ)
/-- The "additive circle" `ℝ ⧸ (ℤ ∙ p)` is compact. -/
instance compact_space [fact (0 < p)] : compact_space $ add_circle p :=
begin
rw [← is_compact_univ_iff, ← coe_image_Icc_eq p],
exact is_compact_Icc.image (add_circle.continuous_mk' p),
end
/-- The action on `ℝ` by right multiplication of its the subgroup `zmultiples p` (the multiples of
`p:ℝ`) is properly discontinuous. -/
instance : properly_discontinuous_vadd (zmultiples p).opposite ℝ :=
(zmultiples p).properly_discontinuous_vadd_opposite_of_tendsto_cofinite
(add_subgroup.tendsto_zmultiples_subtype_cofinite p)
/-- The "additive circle" `ℝ ⧸ (ℤ ∙ p)` is Hausdorff. -/
instance : t2_space (add_circle p) := t2_space_of_properly_discontinuous_vadd_of_t2_space
/-- The "additive circle" `ℝ ⧸ (ℤ ∙ p)` is normal. -/
instance [fact (0 < p)] : normal_space (add_circle p) := normal_of_compact_t2
/-- The "additive circle" `ℝ ⧸ (ℤ ∙ p)` is second-countable. -/
instance : second_countable_topology (add_circle p) := quotient_add_group.second_countable_topology
end add_circle
private lemma fact_zero_lt_one : fact ((0:ℝ) < 1) := ⟨zero_lt_one⟩
local attribute [instance] fact_zero_lt_one
/-- The unit circle `ℝ ⧸ ℤ`. -/
@[derive [compact_space, normal_space, second_countable_topology]]
abbreviation unit_add_circle := add_circle (1 : ℝ)
|
2498feb942232c0755b210fa7d10d6eaac08e47f
|
b2fe74b11b57d362c13326bc5651244f111fa6f4
|
/src/analysis/specific_limits.lean
|
fbee36253c7cd14907fb3b599c02fdd9404da399
|
[
"Apache-2.0"
] |
permissive
|
midfield/mathlib
|
c4db5fa898b5ac8f2f80ae0d00c95eb6f745f4c7
|
775edc615ecec631d65b6180dbcc7bc26c3abc26
|
refs/heads/master
| 1,675,330,551,921
| 1,608,304,514,000
| 1,608,304,514,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 24,670
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import analysis.normed_space.basic
import algebra.geom_sum
import order.filter.archimedean
import order.iterate
import topology.instances.ennreal
import tactic.ring_exp
/-!
# A collection of specific limit computations
-/
noncomputable theory
open classical function filter finset metric
open_locale classical topological_space nat big_operators uniformity nnreal
variables {α : Type*} {β : Type*} {ι : Type*}
lemma tendsto_norm_at_top_at_top : tendsto (norm : ℝ → ℝ) at_top at_top :=
tendsto_abs_at_top_at_top
lemma summable_of_absolute_convergence_real {f : ℕ → ℝ} :
(∃r, tendsto (λn, (∑ i in range n, abs (f i))) at_top (𝓝 r)) → summable f
| ⟨r, hr⟩ :=
begin
refine summable_of_summable_norm ⟨r, (has_sum_iff_tendsto_nat_of_nonneg _ _).2 _⟩,
exact assume i, norm_nonneg _,
simpa only using hr
end
lemma tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ)⁻¹) at_top (𝓝 0) :=
tendsto_inv_at_top_zero.comp tendsto_coe_nat_at_top_at_top
lemma tendsto_const_div_at_top_nhds_0_nat (C : ℝ) : tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa only [mul_zero] using tendsto_const_nhds.mul tendsto_inverse_at_top_nhds_0_nat
lemma nnreal.tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ≥0)⁻¹) at_top (𝓝 0) :=
by { rw ← nnreal.tendsto_coe, convert tendsto_inverse_at_top_nhds_0_nat, simp }
lemma nnreal.tendsto_const_div_at_top_nhds_0_nat (C : ℝ≥0) :
tendsto (λ n : ℕ, C / n) at_top (𝓝 0) :=
by simpa using tendsto_const_nhds.mul nnreal.tendsto_inverse_at_top_nhds_0_nat
lemma tendsto_one_div_add_at_top_nhds_0_nat :
tendsto (λ n : ℕ, 1 / ((n : ℝ) + 1)) at_top (𝓝 0) :=
suffices tendsto (λ n : ℕ, 1 / (↑(n + 1) : ℝ)) at_top (𝓝 0), by simpa,
(tendsto_add_at_top_iff_nat 1).2 (tendsto_const_div_at_top_nhds_0_nat 1)
/-! ### Powers -/
lemma tendsto_add_one_pow_at_top_at_top_of_pos [linear_ordered_semiring α] [archimedean α] {r : α}
(h : 0 < r) :
tendsto (λ n:ℕ, (r + 1)^n) at_top at_top :=
tendsto_at_top_at_top_of_monotone' (λ n m, pow_le_pow (le_add_of_nonneg_left (le_of_lt h))) $
not_bdd_above_iff.2 $ λ x, set.exists_range_iff.2 $ add_one_pow_unbounded_of_pos _ h
lemma tendsto_pow_at_top_at_top_of_one_lt [linear_ordered_ring α] [archimedean α]
{r : α} (h : 1 < r) :
tendsto (λn:ℕ, r ^ n) at_top at_top :=
sub_add_cancel r 1 ▸ tendsto_add_one_pow_at_top_at_top_of_pos (sub_pos.2 h)
lemma nat.tendsto_pow_at_top_at_top_of_one_lt {m : ℕ} (h : 1 < m) :
tendsto (λn:ℕ, m ^ n) at_top at_top :=
nat.sub_add_cancel (le_of_lt h) ▸
tendsto_add_one_pow_at_top_at_top_of_pos (nat.sub_pos_of_lt h)
lemma tendsto_norm_zero' {𝕜 : Type*} [normed_group 𝕜] :
tendsto (norm : 𝕜 → ℝ) (𝓝[{x | x ≠ 0}] 0) (𝓝[set.Ioi 0] 0) :=
tendsto_norm_zero.inf $ tendsto_principal_principal.2 $ λ x hx, norm_pos_iff.2 hx
lemma normed_field.tendsto_norm_inverse_nhds_within_0_at_top {𝕜 : Type*} [normed_field 𝕜] :
tendsto (λ x:𝕜, ∥x⁻¹∥) (𝓝[{x | x ≠ 0}] 0) at_top :=
(tendsto_inv_zero_at_top.comp tendsto_norm_zero').congr $ λ x, (normed_field.norm_inv x).symm
lemma tendsto_pow_at_top_nhds_0_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
by_cases
(assume : r = 0, (tendsto_add_at_top_iff_nat 1).mp $ by simp [pow_succ, this, tendsto_const_nhds])
(assume : r ≠ 0,
have tendsto (λn, (r⁻¹ ^ n)⁻¹) at_top (𝓝 0),
from tendsto_inv_at_top_zero.comp
(tendsto_pow_at_top_at_top_of_one_lt $ one_lt_inv (lt_of_le_of_ne h₁ this.symm) h₂),
tendsto.congr' (univ_mem_sets' $ by simp *) this)
lemma uniformity_basis_dist_pow_of_lt_1 {α : Type*} [metric_space α]
{r : ℝ} (h₀ : 0 < r) (h₁ : r < 1) :
(𝓤 α).has_basis (λ k : ℕ, true) (λ k, {p : α × α | dist p.1 p.2 < r ^ k}) :=
metric.mk_uniformity_basis (λ i _, pow_pos h₀ _) $ λ ε ε0,
(exists_pow_lt_of_lt_one ε0 h₁).imp $ λ k hk, ⟨trivial, hk.le⟩
lemma geom_lt {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) {n : ℕ} (hn : 0 < n)
(h : ∀ k < n, c * u k < u (k + 1)) :
c ^ n * u 0 < u n :=
(monotone_mul_left_of_nonneg hc).seq_pos_lt_seq_of_le_of_lt hn (by simp)
(λ k hk, by simp [pow_succ, mul_assoc]) h
lemma geom_le {u : ℕ → ℝ} {c : ℝ} (hc : 0 ≤ c) (n : ℕ) (h : ∀ k < n, c * u k ≤ u (k + 1)) :
c ^ n * u 0 ≤ u n :=
by refine (monotone_mul_left_of_nonneg hc).seq_le_seq n _ _ h; simp [pow_succ, mul_assoc, le_refl]
/-- If a sequence `v` of real numbers satisfies `k * v n ≤ v (n+1)` with `1 < k`,
then it goes to +∞. -/
lemma tendsto_at_top_of_geom_le {v : ℕ → ℝ} {c : ℝ} (h₀ : 0 < v 0) (hc : 1 < c)
(hu : ∀ n, c * v n ≤ v (n + 1)) : tendsto v at_top at_top :=
tendsto_at_top_mono (λ n, geom_le (zero_le_one.trans hc.le) n (λ k hk, hu k)) $
(tendsto_pow_at_top_at_top_of_one_lt hc).at_top_mul_const h₀
lemma nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ℝ≥0} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
nnreal.tendsto_coe.1 $ by simp only [nnreal.coe_pow, nnreal.coe_zero,
tendsto_pow_at_top_nhds_0_of_lt_1 r.coe_nonneg hr]
lemma ennreal.tendsto_pow_at_top_nhds_0_of_lt_1 {r : ennreal} (hr : r < 1) :
tendsto (λ n:ℕ, r^n) at_top (𝓝 0) :=
begin
rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
rw [← ennreal.coe_zero],
norm_cast at *,
apply nnreal.tendsto_pow_at_top_nhds_0_of_lt_1 hr
end
/-- In a normed ring, the powers of an element x with `∥x∥ < 1` tend to zero. -/
lemma tendsto_pow_at_top_nhds_0_of_norm_lt_1 {R : Type*} [normed_ring R] {x : R}
(h : ∥x∥ < 1) : tendsto (λ (n : ℕ), x ^ n) at_top (𝓝 0) :=
begin
apply squeeze_zero_norm' (eventually_norm_pow_le x),
exact tendsto_pow_at_top_nhds_0_of_lt_1 (norm_nonneg _) h,
end
lemma tendsto_pow_at_top_nhds_0_of_abs_lt_1 {r : ℝ} (h : abs r < 1) :
tendsto (λn:ℕ, r^n) at_top (𝓝 0) :=
tendsto_pow_at_top_nhds_0_of_norm_lt_1 h
/-! ### Geometric series-/
section geometric
lemma has_sum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) :
has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
have r ≠ 1, from ne_of_lt h₂,
have tendsto (λn, (r ^ n - 1) * (r - 1)⁻¹) at_top (𝓝 ((0 - 1) * (r - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_lt_1 h₁ h₂).sub tendsto_const_nhds).mul tendsto_const_nhds,
have (λ n, (∑ i in range n, r ^ i)) = (λ n, geom_series r n) := rfl,
(has_sum_iff_tendsto_nat_of_nonneg (pow_nonneg h₁) _).mpr $
by simp [neg_inv, geom_sum, div_eq_mul_inv, *] at *
lemma summable_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, has_sum_geometric_of_lt_1 h₁ h₂⟩
lemma tsum_geometric_of_lt_1 {r : ℝ} (h₁ : 0 ≤ r) (h₂ : r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
(has_sum_geometric_of_lt_1 h₁ h₂).tsum_eq
lemma has_sum_geometric_two : has_sum (λn:ℕ, ((1:ℝ)/2) ^ n) 2 :=
by convert has_sum_geometric_of_lt_1 _ _; norm_num
lemma summable_geometric_two : summable (λn:ℕ, ((1:ℝ)/2) ^ n) :=
⟨_, has_sum_geometric_two⟩
lemma tsum_geometric_two : (∑'n:ℕ, ((1:ℝ)/2) ^ n) = 2 :=
has_sum_geometric_two.tsum_eq
lemma sum_geometric_two_le (n : ℕ) : ∑ (i : ℕ) in range n, (1 / (2 : ℝ)) ^ i ≤ 2 :=
begin
have : ∀ i, 0 ≤ (1 / (2 : ℝ)) ^ i,
{ intro i, apply pow_nonneg, norm_num },
convert sum_le_tsum (range n) (λ i _, this i) summable_geometric_two,
exact tsum_geometric_two.symm
end
lemma has_sum_geometric_two' (a : ℝ) : has_sum (λn:ℕ, (a / 2) / 2 ^ n) a :=
begin
convert has_sum.mul_left (a / 2) (has_sum_geometric_of_lt_1
(le_of_lt one_half_pos) one_half_lt_one),
{ funext n, simp, refl, },
{ norm_num }
end
lemma summable_geometric_two' (a : ℝ) : summable (λ n:ℕ, (a / 2) / 2 ^ n) :=
⟨a, has_sum_geometric_two' a⟩
lemma tsum_geometric_two' (a : ℝ) : (∑' n:ℕ, (a / 2) / 2^n) = a :=
(has_sum_geometric_two' a).tsum_eq
lemma nnreal.has_sum_geometric {r : ℝ≥0} (hr : r < 1) :
has_sum (λ n : ℕ, r ^ n) (1 - r)⁻¹ :=
begin
apply nnreal.has_sum_coe.1,
push_cast,
rw [nnreal.coe_sub (le_of_lt hr)],
exact has_sum_geometric_of_lt_1 r.coe_nonneg hr
end
lemma nnreal.summable_geometric {r : ℝ≥0} (hr : r < 1) : summable (λn:ℕ, r ^ n) :=
⟨_, nnreal.has_sum_geometric hr⟩
lemma tsum_geometric_nnreal {r : ℝ≥0} (hr : r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
(nnreal.has_sum_geometric hr).tsum_eq
/-- The series `pow r` converges to `(1-r)⁻¹`. For `r < 1` the RHS is a finite number,
and for `1 ≤ r` the RHS equals `∞`. -/
lemma ennreal.tsum_geometric (r : ennreal) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
begin
cases lt_or_le r 1 with hr hr,
{ rcases ennreal.lt_iff_exists_coe.1 hr with ⟨r, rfl, hr'⟩,
norm_cast at *,
convert ennreal.tsum_coe_eq (nnreal.has_sum_geometric hr),
rw [ennreal.coe_inv $ ne_of_gt $ nnreal.sub_pos.2 hr] },
{ rw [ennreal.sub_eq_zero_of_le hr, ennreal.inv_zero, ennreal.tsum_eq_supr_nat, supr_eq_top],
refine λ a ha, (ennreal.exists_nat_gt (lt_top_iff_ne_top.1 ha)).imp
(λ n hn, lt_of_lt_of_le hn _),
have : ∀ k:ℕ, 1 ≤ r^k, by simpa using canonically_ordered_semiring.pow_le_pow_of_le_left hr,
calc (n:ennreal) = (∑ i in range n, 1) : by rw [sum_const, nsmul_one, card_range]
... ≤ ∑ i in range n, r ^ i : sum_le_sum (λ k _, this k) }
end
variables {K : Type*} [normed_field K] {ξ : K}
lemma has_sum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : has_sum (λn:ℕ, ξ ^ n) (1 - ξ)⁻¹ :=
begin
have xi_ne_one : ξ ≠ 1, by { contrapose! h, simp [h] },
have A : tendsto (λn, (ξ ^ n - 1) * (ξ - 1)⁻¹) at_top (𝓝 ((0 - 1) * (ξ - 1)⁻¹)),
from ((tendsto_pow_at_top_nhds_0_of_norm_lt_1 h).sub tendsto_const_nhds).mul tendsto_const_nhds,
have B : (λ n, (∑ i in range n, ξ ^ i)) = (λ n, geom_series ξ n) := rfl,
rw [has_sum_iff_tendsto_nat_of_summable_norm, B],
{ simpa [geom_sum, xi_ne_one, neg_inv] using A },
{ simp [normed_field.norm_pow, summable_geometric_of_lt_1 (norm_nonneg _) h] }
end
lemma summable_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : summable (λn:ℕ, ξ ^ n) :=
⟨_, has_sum_geometric_of_norm_lt_1 h⟩
lemma tsum_geometric_of_norm_lt_1 (h : ∥ξ∥ < 1) : (∑'n:ℕ, ξ ^ n) = (1 - ξ)⁻¹ :=
(has_sum_geometric_of_norm_lt_1 h).tsum_eq
lemma has_sum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : has_sum (λn:ℕ, r ^ n) (1 - r)⁻¹ :=
has_sum_geometric_of_norm_lt_1 h
lemma summable_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : summable (λn:ℕ, r ^ n) :=
summable_geometric_of_norm_lt_1 h
lemma tsum_geometric_of_abs_lt_1 {r : ℝ} (h : abs r < 1) : (∑'n:ℕ, r ^ n) = (1 - r)⁻¹ :=
tsum_geometric_of_norm_lt_1 h
/-- A geometric series in a normed field is summable iff the norm of the common ratio is less than
one. -/
@[simp] lemma summable_geometric_iff_norm_lt_1 : summable (λ n : ℕ, ξ ^ n) ↔ ∥ξ∥ < 1 :=
begin
refine ⟨λ h, _, summable_geometric_of_norm_lt_1⟩,
obtain ⟨k : ℕ, hk : dist (ξ ^ k) 0 < 1⟩ :=
(h.tendsto_cofinite_zero.eventually (ball_mem_nhds _ zero_lt_one)).exists,
simp only [normed_field.norm_pow, dist_zero_right] at hk,
rw [← one_pow k] at hk,
exact lt_of_pow_lt_pow _ zero_le_one hk
end
end geometric
/-!
### Sequences with geometrically decaying distance in metric spaces
In this paragraph, we discuss sequences in metric spaces or emetric spaces for which the distance
between two consecutive terms decays geometrically. We show that such sequences are Cauchy
sequences, and bound their distances to the limit. We also discuss series with geometrically
decaying terms.
-/
section edist_le_geometric
variables [emetric_space α] (r C : ennreal) (hr : r < 1) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C * r^n)
include hr hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, `C ≠ ∞`, `r < 1`,
then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric : cauchy_seq f :=
begin
refine cauchy_seq_of_edist_le_of_tsum_ne_top _ hu _,
rw [ennreal.tsum_mul_left, ennreal.tsum_geometric],
refine ennreal.mul_ne_top hC (ennreal.inv_ne_top.2 _),
exact ne_of_gt (ennreal.zero_lt_sub_iff_lt.2 hr)
end
omit hr hC
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
edist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
convert edist_le_tsum_of_edist_le_of_tendsto _ hu ha _,
simp only [pow_add, ennreal.tsum_mul_left, ennreal.tsum_geometric, ennreal.div_def, mul_assoc]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * r^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma edist_le_of_edist_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
edist (f 0) a ≤ C / (1 - r) :=
by simpa only [pow_zero, mul_one] using edist_le_of_edist_le_geometric_of_tendsto r C hu ha 0
end edist_le_geometric
section edist_le_geometric_two
variables [emetric_space α] (C : ennreal) (hC : C ≠ ⊤) {f : ℕ → α}
(hu : ∀n, edist (f n) (f (n+1)) ≤ C / 2^n) {a : α} (ha : tendsto f at_top (𝓝 a))
include hC hu
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then `f` is a Cauchy sequence.-/
lemma cauchy_seq_of_edist_le_geometric_two : cauchy_seq f :=
begin
simp only [ennreal.div_def, ennreal.inv_pow] at hu,
refine cauchy_seq_of_edist_le_geometric 2⁻¹ C _ hC hu,
simp [ennreal.one_lt_two]
end
omit hC
include ha
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f n` to the limit of `f` is bounded above by `2 * C * 2^-n`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto (n : ℕ) :
edist (f n) a ≤ 2 * C / 2^n :=
begin
simp only [ennreal.div_def, ennreal.inv_pow] at hu,
rw [ennreal.div_def, mul_assoc, mul_comm, ennreal.inv_pow],
convert edist_le_of_edist_le_geometric_of_tendsto 2⁻¹ C hu ha n,
rw [ennreal.one_sub_inv_two, ennreal.inv_inv]
end
/-- If `edist (f n) (f (n+1))` is bounded by `C * 2^-n`, then the distance from
`f 0` to the limit of `f` is bounded above by `2 * C`. -/
lemma edist_le_of_edist_le_geometric_two_of_tendsto₀: edist (f 0) a ≤ 2 * C :=
by simpa only [pow_zero, ennreal.div_def, ennreal.inv_one, mul_one]
using edist_le_of_edist_le_geometric_two_of_tendsto C hu ha 0
end edist_le_geometric_two
section le_geometric
variables [metric_space α] {r C : ℝ} (hr : r < 1) {f : ℕ → α}
(hu : ∀n, dist (f n) (f (n+1)) ≤ C * r^n)
include hr hu
lemma aux_has_sum_of_le_geometric : has_sum (λ n : ℕ, C * r^n) (C / (1 - r)) :=
begin
have h0 : 0 ≤ C,
by simpa using le_trans dist_nonneg (hu 0),
rcases eq_or_lt_of_le h0 with rfl | Cpos,
{ simp [has_sum_zero] },
{ have rnonneg: r ≥ 0, from nonneg_of_mul_nonneg_left
(by simpa only [pow_one] using le_trans dist_nonneg (hu 1)) Cpos,
refine has_sum.mul_left C _,
by simpa using has_sum_geometric_of_lt_1 rnonneg hr }
end
variables (r C)
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then `f` is a Cauchy sequence.
Note that this lemma does not assume `0 ≤ C` or `0 ≤ r`. -/
lemma cauchy_seq_of_le_geometric : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f n` to the limit of `f` is bounded above by `C * r^n / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C / (1 - r) :=
(aux_has_sum_of_le_geometric hr hu).tsum_eq ▸
dist_le_tsum_of_dist_le_of_tendsto₀ _ hu ⟨_, aux_has_sum_of_le_geometric hr hu⟩ ha
/-- If `dist (f n) (f (n+1))` is bounded by `C * r^n`, `r < 1`, then the distance from
`f 0` to the limit of `f` is bounded above by `C / (1 - r)`. -/
lemma dist_le_of_le_geometric_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ (C * r^n) / (1 - r) :=
begin
have := aux_has_sum_of_le_geometric hr hu,
convert dist_le_tsum_of_dist_le_of_tendsto _ hu ⟨_, this⟩ ha n,
simp only [pow_add, mul_left_comm C, mul_div_right_comm],
rw [mul_comm],
exact (this.mul_left _).tsum_eq.symm
end
omit hr hu
variable (hu₂ : ∀ n, dist (f n) (f (n+1)) ≤ (C / 2) / 2^n)
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then `f` is a Cauchy sequence. -/
lemma cauchy_seq_of_le_geometric_two : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ hu₂ $ ⟨_, has_sum_geometric_two' C⟩
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f 0` to the limit of `f` is bounded above by `C`. -/
lemma dist_le_of_le_geometric_two_of_tendsto₀ {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ C :=
(tsum_geometric_two' C) ▸ dist_le_tsum_of_dist_le_of_tendsto₀ _ hu₂ (summable_geometric_two' C) ha
include hu₂
/-- If `dist (f n) (f (n+1))` is bounded by `(C / 2) / 2^n`, then the distance from
`f n` to the limit of `f` is bounded above by `C / 2^n`. -/
lemma dist_le_of_le_geometric_two_of_tendsto {a : α} (ha : tendsto f at_top (𝓝 a)) (n : ℕ) :
dist (f n) a ≤ C / 2^n :=
begin
convert dist_le_tsum_of_dist_le_of_tendsto _ hu₂ (summable_geometric_two' C) ha n,
simp only [add_comm n, pow_add, (div_div_eq_div_mul _ _ _).symm],
symmetry,
exact ((has_sum_geometric_two' C).mul_right _).tsum_eq
end
end le_geometric
section summable_le_geometric
variables [normed_group α] {r C : ℝ} {f : ℕ → α}
lemma dist_partial_sum_le_of_le_geometric (hf : ∀n, ∥f n∥ ≤ C * r^n) (n : ℕ) :
dist (∑ i in range n, f i) (∑ i in range (n+1), f i) ≤ C * r ^ n :=
begin
rw [sum_range_succ, dist_eq_norm, ← norm_neg],
convert hf n,
rw [neg_sub, add_sub_cancel]
end
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` form a
Cauchy sequence. This lemma does not assume `0 ≤ r` or `0 ≤ C`. -/
lemma cauchy_seq_finset_of_geometric_bound (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n) :
cauchy_seq (λ s : finset (ℕ), ∑ x in s, f x) :=
cauchy_seq_finset_of_norm_bounded _
(aux_has_sum_of_le_geometric hr (dist_partial_sum_le_of_le_geometric hf)).summable hf
/-- If `∥f n∥ ≤ C * r ^ n` for all `n : ℕ` and some `r < 1`, then the partial sums of `f` are within
distance `C * r ^ n / (1 - r)` of the sum of the series. This lemma does not assume `0 ≤ r` or
`0 ≤ C`. -/
lemma norm_sub_le_of_geometric_bound_of_has_sum (hr : r < 1) (hf : ∀n, ∥f n∥ ≤ C * r^n)
{a : α} (ha : has_sum f a) (n : ℕ) :
∥(∑ x in finset.range n, f x) - a∥ ≤ (C * r ^ n) / (1 - r) :=
begin
rw ← dist_eq_norm,
apply dist_le_of_le_geometric_of_tendsto r C hr (dist_partial_sum_le_of_le_geometric hf),
exact ha.tendsto_sum_nat
end
end summable_le_geometric
section normed_ring_geometric
variables {R : Type*} [normed_ring R] [complete_space R]
open normed_space
/-- A geometric series in a complete normed ring is summable.
Proved above (same name, different namespace) for not-necessarily-complete normed fields. -/
lemma normed_ring.summable_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : summable (λ (n:ℕ), x ^ n) :=
begin
have h1 : summable (λ (n:ℕ), ∥x∥ ^ n) := summable_geometric_of_lt_1 (norm_nonneg _) h,
refine summable_of_norm_bounded_eventually _ h1 _,
rw nat.cofinite_eq_at_top,
exact eventually_norm_pow_le x,
end
/-- Bound for the sum of a geometric series in a normed ring. This formula does not assume that the
normed ring satisfies the axiom `∥1∥ = 1`. -/
lemma normed_ring.tsum_geometric_of_norm_lt_1
(x : R) (h : ∥x∥ < 1) : ∥(∑' (n:ℕ), x ^ n)∥ ≤ ∥(1:R)∥ - 1 + (1 - ∥x∥)⁻¹ :=
begin
rw tsum_eq_zero_add (normed_ring.summable_geometric_of_norm_lt_1 x h),
simp only [pow_zero],
refine le_trans (norm_add_le _ _) _,
have : ∥(∑' (b : ℕ), (λ n, x ^ (n + 1)) b)∥ ≤ (1 - ∥x∥)⁻¹ - 1,
{ refine tsum_of_norm_bounded _ (λ b, norm_pow_le' _ (nat.succ_pos b)),
convert (has_sum_nat_add_iff' 1).mpr (has_sum_geometric_of_lt_1 (norm_nonneg x) h),
simp },
linarith
end
lemma geom_series_mul_neg (x : R) (h : ∥x∥ < 1) :
(∑' (i:ℕ), x ^ i) * (1 - x) = 1 :=
begin
have := ((normed_ring.summable_geometric_of_norm_lt_1 x h).has_sum.mul_right (1 - x)),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (𝓝 1),
{ simpa using tendsto_const_nhds.sub (tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←geom_sum_mul_neg, geom_series_def, finset.sum_mul],
end
lemma mul_neg_geom_series (x : R) (h : ∥x∥ < 1) :
(1 - x) * (∑' (i:ℕ), x ^ i) = 1 :=
begin
have := (normed_ring.summable_geometric_of_norm_lt_1 x h).has_sum.mul_left (1 - x),
refine tendsto_nhds_unique this.tendsto_sum_nat _,
have : tendsto (λ (n : ℕ), 1 - x ^ n) at_top (nhds 1),
{ simpa using tendsto_const_nhds.sub
(tendsto_pow_at_top_nhds_0_of_norm_lt_1 h) },
convert ← this,
ext n,
rw [←mul_neg_geom_sum, geom_series_def, finset.mul_sum]
end
end normed_ring_geometric
/-! ### Positive sequences with small sums on encodable types -/
/-- For any positive `ε`, define on an encodable type a positive sequence with sum less than `ε` -/
def pos_sum_of_encodable {ε : ℝ} (hε : 0 < ε)
(ι) [encodable ι] : {ε' : ι → ℝ // (∀ i, 0 < ε' i) ∧ ∃ c, has_sum ε' c ∧ c ≤ ε} :=
begin
let f := λ n, (ε / 2) / 2 ^ n,
have hf : has_sum f ε := has_sum_geometric_two' _,
have f0 : ∀ n, 0 < f n := λ n, div_pos (half_pos hε) (pow_pos zero_lt_two _),
refine ⟨f ∘ encodable.encode, λ i, f0 _, _⟩,
rcases hf.summable.comp_injective (@encodable.encode_injective ι _) with ⟨c, hg⟩,
refine ⟨c, hg, has_sum_le_inj _ (@encodable.encode_injective ι _) _ _ hg hf⟩,
{ assume i _, exact le_of_lt (f0 _) },
{ assume n, exact le_refl _ }
end
namespace nnreal
theorem exists_pos_sum_of_encodable {ε : ℝ≥0} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ ∃c, has_sum ε' c ∧ c < ε :=
let ⟨a, a0, aε⟩ := exists_between hε in
let ⟨ε', hε', c, hc, hcε⟩ := pos_sum_of_encodable a0 ι in
⟨ λi, ⟨ε' i, le_of_lt $ hε' i⟩, assume i, nnreal.coe_lt_coe.2 $ hε' i,
⟨c, has_sum_le (assume i, le_of_lt $ hε' i) has_sum_zero hc ⟩, nnreal.has_sum_coe.1 hc,
lt_of_le_of_lt (nnreal.coe_le_coe.1 hcε) aε ⟩
end nnreal
namespace ennreal
theorem exists_pos_sum_of_encodable {ε : ennreal} (hε : 0 < ε) (ι) [encodable ι] :
∃ ε' : ι → ℝ≥0, (∀ i, 0 < ε' i) ∧ (∑' i, (ε' i : ennreal)) < ε :=
begin
rcases exists_between hε with ⟨r, h0r, hrε⟩,
rcases lt_iff_exists_coe.1 hrε with ⟨x, rfl, hx⟩,
rcases nnreal.exists_pos_sum_of_encodable (coe_lt_coe.1 h0r) ι with ⟨ε', hp, c, hc, hcr⟩,
exact ⟨ε', hp, (ennreal.tsum_coe_eq hc).symm ▸ lt_trans (coe_lt_coe.2 hcr) hrε⟩
end
end ennreal
/-!
### Factorial
-/
lemma factorial_tendsto_at_top : tendsto nat.factorial at_top at_top :=
tendsto_at_top_at_top_of_monotone nat.monotone_factorial (λ n, ⟨n, n.self_le_factorial⟩)
lemma tendsto_factorial_div_pow_self_at_top : tendsto (λ n, n! / n^n : ℕ → ℝ) at_top (𝓝 0) :=
tendsto_of_tendsto_of_tendsto_of_le_of_le'
tendsto_const_nhds
(tendsto_const_div_at_top_nhds_0_nat 1)
(eventually_of_forall $ λ n, div_nonneg (by exact_mod_cast n.factorial_pos.le)
(pow_nonneg (by exact_mod_cast n.zero_le) _))
begin
rw eventually_iff_exists_mem,
use [set.Ioi 0, Ioi_mem_at_top 0],
rintros n (hn : 0 < n),
rcases nat.exists_eq_succ_of_ne_zero hn.ne.symm with ⟨k, rfl⟩,
rw [← prod_range_add_one_eq_factorial, pow_eq_prod_const, div_eq_mul_inv, ← inv_eq_one_div, prod_nat_cast,
nat.cast_succ, ← prod_inv_distrib', ← prod_mul_distrib, finset.prod_range_succ'],
simp only [prod_range_succ', one_mul, nat.cast_add, zero_add, nat.cast_one],
refine mul_le_of_le_one_left (inv_nonneg.mpr $ by exact_mod_cast hn.le) (prod_le_one _ _);
intros x hx;
rw finset.mem_range at hx,
{ refine mul_nonneg _ (inv_nonneg.mpr _); norm_cast; linarith },
{ refine (div_le_one $ by exact_mod_cast hn).mpr _, norm_cast, linarith }
end
|
da69e384c2ec311bcf62f5ce4717fe17859b0d7d
|
c777c32c8e484e195053731103c5e52af26a25d1
|
/src/measure_theory/function/ae_eq_of_integral.lean
|
9ab0cfcf0be01546c1f0431efc7c2fdf8ab54404
|
[
"Apache-2.0"
] |
permissive
|
kbuzzard/mathlib
|
2ff9e85dfe2a46f4b291927f983afec17e946eb8
|
58537299e922f9c77df76cb613910914a479c1f7
|
refs/heads/master
| 1,685,313,702,744
| 1,683,974,212,000
| 1,683,974,212,000
| 128,185,277
| 1
| 0
| null | 1,522,920,600,000
| 1,522,920,600,000
| null |
UTF-8
|
Lean
| false
| false
| 29,220
|
lean
|
/-
Copyright (c) 2021 Rémy Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Rémy Degenne
-/
import analysis.normed_space.dual
import measure_theory.function.strongly_measurable.lp
import measure_theory.integral.set_integral
/-! # From equality of integrals to equality of functions
This file provides various statements of the general form "if two functions have the same integral
on all sets, then they are equal almost everywhere".
The different lemmas use various hypotheses on the class of functions, on the target space or on the
possible finiteness of the measure.
## Main statements
All results listed below apply to two functions `f, g`, together with two main hypotheses,
* `f` and `g` are integrable on all measurable sets with finite measure,
* for all measurable sets `s` with finite measure, `∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ`.
The conclusion is then `f =ᵐ[μ] g`. The main lemmas are:
* `ae_eq_of_forall_set_integral_eq_of_sigma_finite`: case of a sigma-finite measure.
* `ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq`: for functions which are
`ae_fin_strongly_measurable`.
* `Lp.ae_eq_of_forall_set_integral_eq`: for elements of `Lp`, for `0 < p < ∞`.
* `integrable.ae_eq_of_forall_set_integral_eq`: for integrable functions.
For each of these results, we also provide a lemma about the equality of one function and 0. For
example, `Lp.ae_eq_zero_of_forall_set_integral_eq_zero`.
We also register the corresponding lemma for integrals of `ℝ≥0∞`-valued functions, in
`ae_eq_of_forall_set_lintegral_eq_of_sigma_finite`.
Generally useful lemmas which are not related to integrals:
* `ae_eq_zero_of_forall_inner`: if for all constants `c`, `λ x, inner c (f x) =ᵐ[μ] 0` then
`f =ᵐ[μ] 0`.
* `ae_eq_zero_of_forall_dual`: if for all constants `c` in the dual space, `λ x, c (f x) =ᵐ[μ] 0`
then `f =ᵐ[μ] 0`.
-/
open measure_theory topological_space normed_space filter
open_locale ennreal nnreal measure_theory
namespace measure_theory
section ae_eq_of_forall
variables {α E 𝕜 : Type*} {m : measurable_space α} {μ : measure α} [is_R_or_C 𝕜]
lemma ae_eq_zero_of_forall_inner
[normed_add_comm_group E] [inner_product_space 𝕜 E] [second_countable_topology E]
{f : α → E} (hf : ∀ c : E, (λ x, (inner c (f x) : 𝕜)) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 :=
begin
let s := dense_seq E,
have hs : dense_range s := dense_range_dense_seq E,
have hf' : ∀ᵐ x ∂μ, ∀ n : ℕ, inner (s n) (f x) = (0 : 𝕜), from ae_all_iff.mpr (λ n, hf (s n)),
refine hf'.mono (λ x hx, _),
rw [pi.zero_apply, ← @inner_self_eq_zero 𝕜],
have h_closed : is_closed {c : E | inner c (f x) = (0 : 𝕜)},
from is_closed_eq (continuous_id.inner continuous_const) continuous_const,
exact @is_closed_property ℕ E _ s (λ c, inner c (f x) = (0 : 𝕜)) hs h_closed (λ n, hx n) _,
end
local notation `⟪`x`, `y`⟫` := y x
variables (𝕜)
lemma ae_eq_zero_of_forall_dual_of_is_separable [normed_add_comm_group E] [normed_space 𝕜 E]
{t : set E} (ht : topological_space.is_separable t)
{f : α → E} (hf : ∀ c : dual 𝕜 E, (λ x, ⟪f x, c⟫) =ᵐ[μ] 0) (h't : ∀ᵐ x ∂μ, f x ∈ t) :
f =ᵐ[μ] 0 :=
begin
rcases ht with ⟨d, d_count, hd⟩,
haveI : encodable d := d_count.to_encodable,
have : ∀ (x : d), ∃ g : E →L[𝕜] 𝕜, ‖g‖ ≤ 1 ∧ g x = ‖(x : E)‖ := λ x, exists_dual_vector'' 𝕜 x,
choose s hs using this,
have A : ∀ (a : E), a ∈ t → (∀ x, ⟪a, s x⟫ = (0 : 𝕜)) → a = 0,
{ assume a hat ha,
contrapose! ha,
have a_pos : 0 < ‖a‖, by simp only [ha, norm_pos_iff, ne.def, not_false_iff],
have a_mem : a ∈ closure d := hd hat,
obtain ⟨x, hx⟩ : ∃ (x : d), dist a x < ‖a‖ / 2,
{ rcases metric.mem_closure_iff.1 a_mem (‖a‖/2) (half_pos a_pos) with ⟨x, h'x, hx⟩,
exact ⟨⟨x, h'x⟩, hx⟩ },
use x,
have I : ‖a‖/2 < ‖(x : E)‖,
{ have : ‖a‖ ≤ ‖(x : E)‖ + ‖a - x‖ := norm_le_insert' _ _,
have : ‖a - x‖ < ‖a‖/2, by rwa dist_eq_norm at hx,
linarith },
assume h,
apply lt_irrefl (‖s x x‖),
calc ‖s x x‖ = ‖s x (x - a)‖ : by simp only [h, sub_zero, continuous_linear_map.map_sub]
... ≤ 1 * ‖(x : E) - a‖ : continuous_linear_map.le_of_op_norm_le _ (hs x).1 _
... < ‖a‖ / 2 : by { rw [one_mul], rwa dist_eq_norm' at hx }
... < ‖(x : E)‖ : I
... = ‖s x x‖ : by rw [(hs x).2, is_R_or_C.norm_coe_norm] },
have hfs : ∀ (y : d), ∀ᵐ x ∂μ, ⟪f x, s y⟫ = (0 : 𝕜), from λ y, hf (s y),
have hf' : ∀ᵐ x ∂μ, ∀ (y : d), ⟪f x, s y⟫ = (0 : 𝕜), by rwa ae_all_iff,
filter_upwards [hf', h't] with x hx h'x,
exact A (f x) h'x hx,
end
lemma ae_eq_zero_of_forall_dual [normed_add_comm_group E] [normed_space 𝕜 E]
[second_countable_topology E] {f : α → E} (hf : ∀ c : dual 𝕜 E, (λ x, ⟪f x, c⟫) =ᵐ[μ] 0) :
f =ᵐ[μ] 0 :=
ae_eq_zero_of_forall_dual_of_is_separable 𝕜 (is_separable_of_separable_space (set.univ : set E)) hf
(eventually_of_forall (λ x, set.mem_univ _))
variables {𝕜}
end ae_eq_of_forall
variables {α E : Type*}
{m m0 : measurable_space α} {μ : measure α} {s t : set α}
[normed_add_comm_group E] [normed_space ℝ E]
[complete_space E]
{p : ℝ≥0∞}
section ae_eq_of_forall_set_integral_eq
lemma ae_const_le_iff_forall_lt_measure_zero {β} [linear_order β] [topological_space β]
[order_topology β] [first_countable_topology β] (f : α → β) (c : β) :
(∀ᵐ x ∂μ, c ≤ f x) ↔ ∀ b < c, μ {x | f x ≤ b} = 0 :=
begin
rw ae_iff,
push_neg,
split,
{ assume h b hb,
exact measure_mono_null (λ y hy, (lt_of_le_of_lt hy hb : _)) h },
assume hc,
by_cases h : ∀ b, c ≤ b,
{ have : {a : α | f a < c} = ∅,
{ apply set.eq_empty_iff_forall_not_mem.2 (λ x hx, _),
exact (lt_irrefl _ (lt_of_lt_of_le hx (h (f x)))).elim },
simp [this] },
by_cases H : ¬ (is_lub (set.Iio c) c),
{ have : c ∈ upper_bounds (set.Iio c) := λ y hy, le_of_lt hy,
obtain ⟨b, b_up, bc⟩ : ∃ (b : β), b ∈ upper_bounds (set.Iio c) ∧ b < c,
by simpa [is_lub, is_least, this, lower_bounds] using H,
exact measure_mono_null (λ x hx, b_up hx) (hc b bc) },
push_neg at H h,
obtain ⟨u, u_mono, u_lt, u_lim, -⟩ : ∃ (u : ℕ → β), strict_mono u ∧ (∀ (n : ℕ), u n < c)
∧ tendsto u at_top (nhds c) ∧ ∀ (n : ℕ), u n ∈ set.Iio c :=
H.exists_seq_strict_mono_tendsto_of_not_mem (lt_irrefl c) h,
have h_Union : {x | f x < c} = ⋃ (n : ℕ), {x | f x ≤ u n},
{ ext1 x,
simp_rw [set.mem_Union, set.mem_set_of_eq],
split; intro h,
{ obtain ⟨n, hn⟩ := ((tendsto_order.1 u_lim).1 _ h).exists, exact ⟨n, hn.le⟩ },
{ obtain ⟨n, hn⟩ := h, exact hn.trans_lt (u_lt _), }, },
rw [h_Union, measure_Union_null_iff],
assume n,
exact hc _ (u_lt n),
end
section ennreal
open_locale topology
lemma ae_le_of_forall_set_lintegral_le_of_sigma_finite [sigma_finite μ]
{f g : α → ℝ≥0∞} (hf : measurable f) (hg : measurable g)
(h : ∀ s, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ ≤ ∫⁻ x in s, g x ∂μ) :
f ≤ᵐ[μ] g :=
begin
have A : ∀ (ε N : ℝ≥0) (p : ℕ), 0 < ε →
μ ({x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanning_sets μ p) = 0,
{ assume ε N p εpos,
let s := {x | g x + ε ≤ f x ∧ g x ≤ N} ∩ spanning_sets μ p,
have s_meas : measurable_set s,
{ have A : measurable_set {x | g x + ε ≤ f x} := measurable_set_le (hg.add measurable_const) hf,
have B : measurable_set {x | g x ≤ N} := measurable_set_le hg measurable_const,
exact (A.inter B).inter (measurable_spanning_sets μ p) },
have s_lt_top : μ s < ∞ :=
(measure_mono (set.inter_subset_right _ _)).trans_lt (measure_spanning_sets_lt_top μ p),
have A : ∫⁻ x in s, g x ∂μ + ε * μ s ≤ ∫⁻ x in s, g x ∂μ + 0 := calc
∫⁻ x in s, g x ∂μ + ε * μ s = ∫⁻ x in s, g x ∂μ + ∫⁻ x in s, ε ∂μ :
by simp only [lintegral_const, set.univ_inter, measurable_set.univ, measure.restrict_apply]
... = ∫⁻ x in s, (g x + ε) ∂μ : (lintegral_add_right _ measurable_const).symm
... ≤ ∫⁻ x in s, f x ∂μ : set_lintegral_mono (hg.add measurable_const) hf (λ x hx, hx.1.1)
... ≤ ∫⁻ x in s, g x ∂μ + 0 : by { rw [add_zero], exact h s s_meas s_lt_top },
have B : ∫⁻ x in s, g x ∂μ ≠ ∞,
{ apply ne_of_lt,
calc ∫⁻ x in s, g x ∂μ ≤ ∫⁻ x in s, N ∂μ :
set_lintegral_mono hg measurable_const (λ x hx, hx.1.2)
... = N * μ s :
by simp only [lintegral_const, set.univ_inter, measurable_set.univ, measure.restrict_apply]
... < ∞ : by simp only [lt_top_iff_ne_top, s_lt_top.ne, and_false,
ennreal.coe_ne_top, with_top.mul_eq_top_iff, ne.def, not_false_iff, false_and, or_self] },
have : (ε : ℝ≥0∞) * μ s ≤ 0 := ennreal.le_of_add_le_add_left B A,
simpa only [ennreal.coe_eq_zero, nonpos_iff_eq_zero, mul_eq_zero, εpos.ne', false_or] },
obtain ⟨u, u_mono, u_pos, u_lim⟩ : ∃ (u : ℕ → ℝ≥0), strict_anti u ∧ (∀ n, 0 < u n) ∧
tendsto u at_top (nhds 0) := exists_seq_strict_anti_tendsto (0 : ℝ≥0),
let s := λ (n : ℕ), {x | g x + u n ≤ f x ∧ g x ≤ (n : ℝ≥0)} ∩ spanning_sets μ n,
have μs : ∀ n, μ (s n) = 0 := λ n, A _ _ _ (u_pos n),
have B : {x | f x ≤ g x}ᶜ ⊆ ⋃ n, s n,
{ assume x hx,
simp at hx,
have L1 : ∀ᶠ n in at_top, g x + u n ≤ f x,
{ have : tendsto (λ n, g x + u n) at_top (𝓝 (g x + (0 : ℝ≥0))) :=
tendsto_const_nhds.add (ennreal.tendsto_coe.2 u_lim),
simp at this,
exact eventually_le_of_tendsto_lt hx this },
have L2 : ∀ᶠ (n : ℕ) in (at_top : filter ℕ), g x ≤ (n : ℝ≥0),
{ have : tendsto (λ (n : ℕ), ((n : ℝ≥0) : ℝ≥0∞)) at_top (𝓝 ∞),
{ simp only [ennreal.coe_nat],
exact ennreal.tendsto_nat_nhds_top },
exact eventually_ge_of_tendsto_gt (hx.trans_le le_top) this },
apply set.mem_Union.2,
exact ((L1.and L2).and (eventually_mem_spanning_sets μ x)).exists },
refine le_antisymm _ bot_le,
calc μ {x : α | (λ (x : α), f x ≤ g x) x}ᶜ ≤ μ (⋃ n, s n) : measure_mono B
... ≤ ∑' n, μ (s n) : measure_Union_le _
... = 0 : by simp only [μs, tsum_zero]
end
lemma ae_eq_of_forall_set_lintegral_eq_of_sigma_finite [sigma_finite μ]
{f g : α → ℝ≥0∞} (hf : measurable f) (hg : measurable g)
(h : ∀ s, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
have A : f ≤ᵐ[μ] g :=
ae_le_of_forall_set_lintegral_le_of_sigma_finite hf hg (λ s hs h's, le_of_eq (h s hs h's)),
have B : g ≤ᵐ[μ] f :=
ae_le_of_forall_set_lintegral_le_of_sigma_finite hg hf (λ s hs h's, ge_of_eq (h s hs h's)),
filter_upwards [A, B] with x using le_antisymm,
end
end ennreal
section real
variables {f : α → ℝ}
/-- Don't use this lemma. Use `ae_nonneg_of_forall_set_integral_nonneg`. -/
lemma ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable
(hfm : strongly_measurable f)
(hf : integrable f μ) (hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
simp_rw [eventually_le, pi.zero_apply],
rw ae_const_le_iff_forall_lt_measure_zero,
intros b hb_neg,
let s := {x | f x ≤ b},
have hs : measurable_set s, from hfm.measurable_set_le strongly_measurable_const,
have mus : μ s < ∞,
{ let c : ℝ≥0 := ⟨|b|, abs_nonneg _⟩,
have c_pos : (c : ℝ≥0∞) ≠ 0, by simpa using hb_neg.ne,
calc μ s ≤ μ {x | (c : ℝ≥0∞) ≤ ‖f x‖₊} :
begin
apply measure_mono,
assume x hx,
simp only [set.mem_set_of_eq] at hx,
simpa only [nnnorm, abs_of_neg hb_neg, abs_of_neg (hx.trans_lt hb_neg), real.norm_eq_abs,
subtype.mk_le_mk, neg_le_neg_iff, set.mem_set_of_eq, ennreal.coe_le_coe] using hx,
end
... ≤ (∫⁻ x, ‖f x‖₊ ∂μ) / c :
meas_ge_le_lintegral_div hfm.ae_measurable.ennnorm c_pos ennreal.coe_ne_top
... < ∞ : ennreal.div_lt_top (ne_of_lt hf.2) c_pos },
have h_int_gt : ∫ x in s, f x ∂μ ≤ b * (μ s).to_real,
{ have h_const_le : ∫ x in s, f x ∂μ ≤ ∫ x in s, b ∂μ,
{ refine set_integral_mono_ae_restrict hf.integrable_on
(integrable_on_const.mpr (or.inr mus)) _,
rw [eventually_le, ae_restrict_iff hs],
exact eventually_of_forall (λ x hxs, hxs), },
rwa [set_integral_const, smul_eq_mul, mul_comm] at h_const_le, },
by_contra,
refine (lt_self_iff_false (∫ x in s, f x ∂μ)).mp (h_int_gt.trans_lt _),
refine (mul_neg_iff.mpr (or.inr ⟨hb_neg, _⟩)).trans_le _,
swap, { simp_rw measure.restrict_restrict hs, exact hf_zero s hs mus, },
refine (ennreal.to_real_nonneg).lt_of_ne (λ h_eq, h _),
cases (ennreal.to_real_eq_zero_iff _).mp h_eq.symm with hμs_eq_zero hμs_eq_top,
{ exact hμs_eq_zero, },
{ exact absurd hμs_eq_top mus.ne, },
end
lemma ae_nonneg_of_forall_set_integral_nonneg (hf : integrable f μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
rcases hf.1 with ⟨f', hf'_meas, hf_ae⟩,
have hf'_integrable : integrable f' μ, from integrable.congr hf hf_ae,
have hf'_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f' x ∂μ,
{ intros s hs h's,
rw set_integral_congr_ae hs (hf_ae.mono (λ x hx hxs, hx.symm)),
exact hf_zero s hs h's, },
exact (ae_nonneg_of_forall_set_integral_nonneg_of_strongly_measurable hf'_meas
hf'_integrable hf'_zero).trans hf_ae.symm.le,
end
lemma ae_le_of_forall_set_integral_le {f g : α → ℝ} (hf : integrable f μ) (hg : integrable g μ)
(hf_le : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ ≤ ∫ x in s, g x ∂μ) :
f ≤ᵐ[μ] g :=
begin
rw ← eventually_sub_nonneg,
refine ae_nonneg_of_forall_set_integral_nonneg (hg.sub hf) (λ s hs, _),
rw [integral_sub' hg.integrable_on hf.integrable_on, sub_nonneg],
exact hf_le s hs
end
lemma ae_nonneg_restrict_of_forall_set_integral_nonneg_inter {f : α → ℝ} {t : set α}
(hf : integrable_on f t μ)
(hf_zero : ∀ s, measurable_set s → μ (s ∩ t) < ∞ → 0 ≤ ∫ x in (s ∩ t), f x ∂μ) :
0 ≤ᵐ[μ.restrict t] f :=
begin
refine ae_nonneg_of_forall_set_integral_nonneg hf (λ s hs h's, _),
simp_rw measure.restrict_restrict hs,
apply hf_zero s hs,
rwa measure.restrict_apply hs at h's,
end
lemma ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite [sigma_finite μ] {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
apply ae_of_forall_measure_lt_top_ae_restrict,
assume t t_meas t_lt_top,
apply ae_nonneg_restrict_of_forall_set_integral_nonneg_inter
(hf_int_finite t t_meas t_lt_top),
assume s s_meas hs,
exact hf_zero _ (s_meas.inter t_meas)
(lt_of_le_of_lt (measure_mono (set.inter_subset_right _ _)) t_lt_top)
end
lemma ae_fin_strongly_measurable.ae_nonneg_of_forall_set_integral_nonneg {f : α → ℝ}
(hf : ae_fin_strongly_measurable f μ)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ) :
0 ≤ᵐ[μ] f :=
begin
let t := hf.sigma_finite_set,
suffices : 0 ≤ᵐ[μ.restrict t] f,
from ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl.symm.le,
haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict,
refine ae_nonneg_of_forall_set_integral_nonneg_of_sigma_finite (λ s hs hμts, _)
(λ s hs hμts, _),
{ rw [integrable_on, measure.restrict_restrict hs],
rw measure.restrict_apply hs at hμts,
exact hf_int_finite (s ∩ t) (hs.inter hf.measurable_set) hμts, },
{ rw measure.restrict_restrict hs,
rw measure.restrict_apply hs at hμts,
exact hf_zero (s ∩ t) (hs.inter hf.measurable_set) hμts, },
end
lemma ae_nonneg_restrict_of_forall_set_integral_nonneg {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → 0 ≤ ∫ x in s, f x ∂μ)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
0 ≤ᵐ[μ.restrict t] f :=
begin
refine ae_nonneg_restrict_of_forall_set_integral_nonneg_inter
(hf_int_finite t ht (lt_top_iff_ne_top.mpr hμt)) (λ s hs h's, _),
refine (hf_zero (s ∩ t) (hs.inter ht) _),
exact (measure_mono (set.inter_subset_right s t)).trans_lt (lt_top_iff_ne_top.mpr hμt),
end
lemma ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real {f : α → ℝ}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] 0 :=
begin
suffices h_and : f ≤ᵐ[μ.restrict t] 0 ∧ 0 ≤ᵐ[μ.restrict t] f,
from h_and.1.mp (h_and.2.mono (λ x hx1 hx2, le_antisymm hx2 hx1)),
refine ⟨_, ae_nonneg_restrict_of_forall_set_integral_nonneg hf_int_finite
(λ s hs hμs, (hf_zero s hs hμs).symm.le) ht hμt⟩,
suffices h_neg : 0 ≤ᵐ[μ.restrict t] -f,
{ refine h_neg.mono (λ x hx, _),
rw pi.neg_apply at hx,
simpa using hx, },
refine ae_nonneg_restrict_of_forall_set_integral_nonneg
(λ s hs hμs, (hf_int_finite s hs hμs).neg) (λ s hs hμs, _) ht hμt,
simp_rw pi.neg_apply,
rw [integral_neg, neg_nonneg],
exact (hf_zero s hs hμs).le,
end
end real
lemma ae_eq_zero_restrict_of_forall_set_integral_eq_zero {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] 0 :=
begin
rcases (hf_int_finite t ht hμt.lt_top).ae_strongly_measurable.is_separable_ae_range
with ⟨u, u_sep, hu⟩,
refine ae_eq_zero_of_forall_dual_of_is_separable ℝ u_sep (λ c, _) hu,
refine ae_eq_zero_restrict_of_forall_set_integral_eq_zero_real _ _ ht hμt,
{ assume s hs hμs,
exact continuous_linear_map.integrable_comp c (hf_int_finite s hs hμs) },
{ assume s hs hμs,
rw [continuous_linear_map.integral_comp_comm c (hf_int_finite s hs hμs), hf_zero s hs hμs],
exact continuous_linear_map.map_zero _ }
end
lemma ae_eq_restrict_of_forall_set_integral_eq {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
{t : set α} (ht : measurable_set t) (hμt : μ t ≠ ∞) :
f =ᵐ[μ.restrict t] g :=
begin
rw ← sub_ae_eq_zero,
have hfg' : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
exact sub_eq_zero.mpr (hfg_zero s hs hμs), },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hfg_int hfg' ht hμt,
end
lemma ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite [sigma_finite μ] {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
let S := spanning_sets μ,
rw [← @measure.restrict_univ _ _ μ, ← Union_spanning_sets μ, eventually_eq, ae_iff,
measure.restrict_apply' (measurable_set.Union (measurable_spanning_sets μ))],
rw [set.inter_Union, measure_Union_null_iff],
intro n,
have h_meas_n : measurable_set (S n), from (measurable_spanning_sets μ n),
have hμn : μ (S n) < ∞, from measure_spanning_sets_lt_top μ n,
rw ← measure.restrict_apply' h_meas_n,
exact ae_eq_zero_restrict_of_forall_set_integral_eq_zero hf_int_finite hf_zero h_meas_n hμn.ne,
end
lemma ae_eq_of_forall_set_integral_eq_of_sigma_finite [sigma_finite μ] {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_eq : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
sub_eq_zero.mpr (hfg_eq s hs hμs)], },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite hfg_int hfg,
end
lemma ae_fin_strongly_measurable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
(hf : ae_fin_strongly_measurable f μ) :
f =ᵐ[μ] 0 :=
begin
let t := hf.sigma_finite_set,
suffices : f =ᵐ[μ.restrict t] 0,
from ae_of_ae_restrict_of_ae_restrict_compl _ this hf.ae_eq_zero_compl,
haveI : sigma_finite (μ.restrict t) := hf.sigma_finite_restrict,
refine ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _,
{ intros s hs hμs,
rw [integrable_on, measure.restrict_restrict hs],
rw [measure.restrict_apply hs] at hμs,
exact hf_int_finite _ (hs.inter hf.measurable_set) hμs, },
{ intros s hs hμs,
rw [measure.restrict_restrict hs],
rw [measure.restrict_apply hs] at hμs,
exact hf_zero _ (hs.inter hf.measurable_set) hμs, },
end
lemma ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq {f g : α → E}
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg_eq : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ)
(hf : ae_fin_strongly_measurable f μ) (hg : ae_fin_strongly_measurable g μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw [integral_sub' (hf_int_finite s hs hμs) (hg_int_finite s hs hμs),
sub_eq_zero.mpr (hfg_eq s hs hμs)], },
have hfg_int : ∀ s, measurable_set s → μ s < ∞ → integrable_on (f-g) s μ,
from λ s hs hμs, (hf_int_finite s hs hμs).sub (hg_int_finite s hs hμs),
exact (hf.sub hg).ae_eq_zero_of_forall_set_integral_eq_zero hfg_int hfg,
end
lemma Lp.ae_eq_zero_of_forall_set_integral_eq_zero
(f : Lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
ae_fin_strongly_measurable.ae_eq_zero_of_forall_set_integral_eq_zero hf_int_finite hf_zero
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
lemma Lp.ae_eq_of_forall_set_integral_eq (f g : Lp E p μ) (hp_ne_zero : p ≠ 0) (hp_ne_top : p ≠ ∞)
(hf_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on f s μ)
(hg_int_finite : ∀ s, measurable_set s → μ s < ∞ → integrable_on g s μ)
(hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
ae_fin_strongly_measurable.ae_eq_of_forall_set_integral_eq hf_int_finite hg_int_finite hfg
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
(Lp.fin_strongly_measurable _ hp_ne_zero hp_ne_top).ae_fin_strongly_measurable
lemma ae_eq_zero_of_forall_set_integral_eq_of_fin_strongly_measurable_trim (hm : m ≤ m0)
{f : α → E} (hf_int_finite : ∀ s, measurable_set[m] s → μ s < ∞ → integrable_on f s μ)
(hf_zero : ∀ s : set α, measurable_set[m] s → μ s < ∞ → ∫ x in s, f x ∂μ = 0)
(hf : fin_strongly_measurable f (μ.trim hm)) :
f =ᵐ[μ] 0 :=
begin
obtain ⟨t, ht_meas, htf_zero, htμ⟩ := hf.exists_set_sigma_finite,
haveI : sigma_finite ((μ.restrict t).trim hm) := by rwa restrict_trim hm μ ht_meas at htμ,
have htf_zero : f =ᵐ[μ.restrict tᶜ] 0,
{ rw [eventually_eq, ae_restrict_iff' (measurable_set.compl (hm _ ht_meas))],
exact eventually_of_forall htf_zero, },
have hf_meas_m : strongly_measurable[m] f, from hf.strongly_measurable,
suffices : f =ᵐ[μ.restrict t] 0,
from ae_of_ae_restrict_of_ae_restrict_compl _ this htf_zero,
refine measure_eq_zero_of_trim_eq_zero hm _,
refine ae_eq_zero_of_forall_set_integral_eq_of_sigma_finite _ _,
{ intros s hs hμs,
rw [integrable_on, restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)],
rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs,
trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs,
refine integrable.trim hm _ hf_meas_m,
exact hf_int_finite _ (hs.inter ht_meas) hμs, },
{ intros s hs hμs,
rw [restrict_trim hm (μ.restrict t) hs, measure.restrict_restrict (hm s hs)],
rw [← restrict_trim hm μ ht_meas, measure.restrict_apply hs,
trim_measurable_set_eq hm (hs.inter ht_meas)] at hμs,
rw ← integral_trim hm hf_meas_m,
exact hf_zero _ (hs.inter ht_meas) hμs, },
end
lemma integrable.ae_eq_zero_of_forall_set_integral_eq_zero {f : α → E} (hf : integrable f μ)
(hf_zero : ∀ s, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = 0) :
f =ᵐ[μ] 0 :=
begin
have hf_Lp : mem_ℒp f 1 μ, from mem_ℒp_one_iff_integrable.mpr hf,
let f_Lp := hf_Lp.to_Lp f,
have hf_f_Lp : f =ᵐ[μ] f_Lp, from (mem_ℒp.coe_fn_to_Lp hf_Lp).symm,
refine hf_f_Lp.trans _,
refine Lp.ae_eq_zero_of_forall_set_integral_eq_zero f_Lp one_ne_zero ennreal.coe_ne_top _ _,
{ exact λ s hs hμs, integrable.integrable_on (L1.integrable_coe_fn _), },
{ intros s hs hμs,
rw integral_congr_ae (ae_restrict_of_ae hf_f_Lp.symm),
exact hf_zero s hs hμs, },
end
lemma integrable.ae_eq_of_forall_set_integral_eq (f g : α → E)
(hf : integrable f μ) (hg : integrable g μ)
(hfg : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, f x ∂μ = ∫ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
rw ← sub_ae_eq_zero,
have hfg' : ∀ s : set α, measurable_set s → μ s < ∞ → ∫ x in s, (f - g) x ∂μ = 0,
{ intros s hs hμs,
rw integral_sub' hf.integrable_on hg.integrable_on,
exact sub_eq_zero.mpr (hfg s hs hμs), },
exact integrable.ae_eq_zero_of_forall_set_integral_eq_zero (hf.sub hg) hfg',
end
end ae_eq_of_forall_set_integral_eq
section lintegral
lemma ae_measurable.ae_eq_of_forall_set_lintegral_eq {f g : α → ℝ≥0∞}
(hf : ae_measurable f μ) (hg : ae_measurable g μ)
(hfi : ∫⁻ x, f x ∂μ ≠ ∞) (hgi : ∫⁻ x, g x ∂μ ≠ ∞)
(hfg : ∀ ⦃s⦄, measurable_set s → μ s < ∞ → ∫⁻ x in s, f x ∂μ = ∫⁻ x in s, g x ∂μ) :
f =ᵐ[μ] g :=
begin
refine ennreal.eventually_eq_of_to_real_eventually_eq
(ae_lt_top' hf hfi).ne_of_lt (ae_lt_top' hg hgi).ne_of_lt
(integrable.ae_eq_of_forall_set_integral_eq _ _
(integrable_to_real_of_lintegral_ne_top hf hfi)
(integrable_to_real_of_lintegral_ne_top hg hgi) (λ s hs hs', _)),
rw [integral_eq_lintegral_of_nonneg_ae, integral_eq_lintegral_of_nonneg_ae],
{ congr' 1,
rw [lintegral_congr_ae (of_real_to_real_ae_eq _),
lintegral_congr_ae (of_real_to_real_ae_eq _)],
{ exact hfg hs hs' },
{ refine (ae_lt_top' hg.restrict (ne_of_lt (lt_of_le_of_lt _ hgi.lt_top))),
exact @set_lintegral_univ α _ μ g ▸ lintegral_mono_set (set.subset_univ _) },
{ refine (ae_lt_top' hf.restrict (ne_of_lt (lt_of_le_of_lt _ hfi.lt_top))),
exact @set_lintegral_univ α _ μ f ▸ lintegral_mono_set (set.subset_univ _) } },
-- putting the proofs where they are used is extremely slow
exacts
[ ae_of_all _ (λ x, ennreal.to_real_nonneg), hg.ennreal_to_real.restrict.ae_strongly_measurable,
ae_of_all _ (λ x, ennreal.to_real_nonneg), hf.ennreal_to_real.restrict.ae_strongly_measurable]
end
end lintegral
end measure_theory
|
b9a58fd128aaee6c74280319c43954b7db3f03ed
|
dfd42d30132c2867977fefe7edae98b6dc703aeb
|
/src/complex_analysis_prep.lean
|
c28ecd83014f01ddb74a847e11ce03fc8e53d0de
|
[] |
no_license
|
justadzr/lean-2021
|
1e42057ac75c794c94b8f148a27a24150c685f68
|
dfc6b30de2f27bdba5fbc51183e2b84e73a920d1
|
refs/heads/master
| 1,689,652,366,522
| 1,630,313,809,000
| 1,630,313,809,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 26,992
|
lean
|
--- Will clean up these imports
import tactic
import analysis.calculus.iterated_deriv
import topology.continuous_function.polynomial
import topology.separation
import topology.path_connected
import analysis.complex.basic
import analysis.calculus.tangent_cone
import analysis.normed_space.units
import analysis.asymptotics.asymptotic_equivalent
import analysis.analytic.basic
import geometry.manifold.algebra.smooth_functions
import linear_algebra.finite_dimensional
import analysis.normed_space.inner_product
import topology.metric_space.basic
import topology.continuous_on
import analysis.calculus.formal_multilinear_series
open set complex classical filter asymptotics continuous_linear_map set metric is_open differentiable
open_locale topological_space classical nnreal asymptotics filter ennreal unit_interval
noncomputable theory
--- Some assumptions
theorem holomorph_analytic (f : ℂ → ℂ) (z : ℂ) : differentiable_at ℂ f z ↔ analytic_at ℂ f z :=
sorry
theorem smooth_within_at_iff_holomorph_within_at (f : ℂ → ℂ) {s : set ℂ} (h : is_open s) : ∀ (z : ℂ), (differentiable_within_at ℂ f s z ↔ times_cont_diff_within_at ℂ ⊤ f s z):=
sorry
theorem smooth_at_iff_holomorph_at (f : ℂ → ℂ) : ∀ (z : ℂ), (differentiable_at ℂ f z ↔ times_cont_diff_at ℂ ⊤ f z) :=
sorry
theorem smooth_on_iff_holomorph_on (f : ℂ → ℂ) {s : set ℂ} (h : is_open s) : differentiable_on ℂ f s ↔ times_cont_diff_on ℂ ⊤ f s :=
sorry
section accuml_pts
--- Need this?
--- def isolated_pt (X : Type*) [topological_space X] (U : set X) (z : X) : Prop :=
--- ∃ (V : set X), is_open V ∧ U ∩ (V \ {z}) = ∅
def accumulation_pt (X : Type*) [topological_space X] (U : set X) (z : X) : Prop :=
∀ (V : set X), V ∈ (𝓝 z) → ∃ (v : X), v ∈ U ∩ V ∧ ¬ v = z
lemma accumulation_pt_open_inter {X : Type*} [topological_space X]
{U : set X} {U' : set X} {z : X}
(hU' : is_open U') (HU' : z ∈ U') (hz : accumulation_pt X U z) :
accumulation_pt X (U ∩ U') z :=
λ V hV, (set.inter_assoc U U' V).symm ▸
(hz (U' ∩ V) $ _root_.mem_nhds_iff.mpr $
let ⟨t, ht, ht₁, ht₂⟩ := _root_.mem_nhds_iff.mp hV in
⟨U' ∩ t, ⟨set.inter_subset_inter_right U' ht, ⟨is_open.inter hU' ht₁, ⟨HU', ht₂⟩⟩⟩⟩)
--
lemma accumulation_pt_mem_closure {X : Type*} [topological_space X]
{U : set X} {z : X} (hz : accumulation_pt X U z) :
z ∈ closure U :=
begin
rw _root_.mem_closure_iff,
intros o ho hxo,
rcases hz o (is_open.mem_nhds ho hxo) with ⟨v, hv₁, hv₂⟩,
use v,
rw set.inter_comm at hv₁,
exact hv₁,
end
end accuml_pts
section crowded_space
class crowded_space (X : Type*) [t : topological_space X] :=
(is_crowded : ∀ (x : X), ¬ t.is_open {x})
lemma crowded_space.def (X : Type*) [t : topological_space X] [cr : crowded_space X] :
∀ (x : X), ¬ t.is_open {x} := cr.is_crowded
lemma mem_frontier (X : Type*) [t : topological_space X] {U : set X} {z : X} :
z ∈ frontier U → ∀ (V : set X), V ∈ 𝓝 z → (V ∩ U ≠ ∅ ∧ V \ U ≠ ∅) :=
begin
intros hz,
rw frontier at hz,
have h : ∀ (o : set X), is_open o → z ∈ o → (o ∩ U).nonempty :=
_root_.mem_closure_iff.mp (mem_of_mem_diff hz),
have h' : ¬ (∃ (o : set X) (H : o ⊆ U), is_open o ∧ z ∈ o),
{ let p := not_mem_of_mem_diff hz, rw [mem_interior] at p, exact p, },
simp at h',
intros V hV,
rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩,
split,
{ exact set.nonempty.ne_empty (set.nonempty.mono (set.inter_subset_inter_left _ hV'₁) $ h V' hV'₂ hV'₃), },
{ by_contra w,
simp at w,
rw [diff_eq_empty] at w,
show false, from (h' V' (set.subset.trans hV'₁ w) hV'₂) hV'₃, },
end
lemma t1_space_connected_with_two_points_is_crowded (X : Type*)
[t : topological_space X] [c : connected_space X] [h : t1_space X]
(hX : ∀ (x : X), ∃ (y : X), ¬ y = x) (x : X) : ¬ t.is_open {x} :=
begin
by_contra w,
rcases hX x with ⟨y, hy⟩,
have minor₁ : is_open {x}ᶜ := is_open_compl_singleton,
have : set.nonempty {x}ᶜ,
{ use y, rw [← ne.def, ← mem_compl_singleton_iff] at hy, exact hy, },
exact (ne_empty_iff_nonempty.mpr $ nonempty_inter w (is_open_compl_singleton)
(union_compl_self {x}) (set.singleton_nonempty x) this) (set.inter_compl_self {x}),
end
lemma accumulation_pt_of_mem_open_nondiscrete
(X : Type*) [t : topological_space X] [cr : crowded_space X]
{U : set X} (hU : is_open U) {z : X} (hz : z ∈ U) :
accumulation_pt X U z :=
begin
let ht := crowded_space.def X,
intros V hV,
rw is_open_iff_forall_mem_open at hU,
rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩,
rcases hU z hz with ⟨U', hU'₁, hU'₂, hU'₃⟩,
have : ¬ (U' ∩ V') = {z} := by_contra (λ h, ht z $ (not_not.mp h) ▸ is_open.inter hU'₂ hV'₂),
rw set.ext_iff at this,
simp at this,
rcases this with ⟨v, hV⟩,
use v,
rw iff_iff_implies_and_implies at hV,
cases not_and_distrib.mp hV,
{ simp at h,
exact ⟨⟨hU'₁ h.1, hV'₁ h.2.1⟩, h.2.2⟩, },
{ simp at h,
exfalso,
exact h.2 (h.1.symm ▸ hU'₃) (h.1.symm ▸ hV'₃), },
end
lemma accumulation_pt_of_open_mem_frontier
{X : Type*} [t : topological_space X] [cr : crowded_space X] {U : set X}
(hU : is_open U) {z : X} (hz : z ∈ frontier U) :
accumulation_pt X U z :=
if h : z ∈ U then accumulation_pt_of_mem_open_nondiscrete X hU h
else begin
rw accumulation_pt,
intros V hV,
let p := (mem_frontier X hz V hV).1,
rcases set.nonempty_def.mp (set.ne_empty_iff_nonempty.mp p) with ⟨v, hv⟩,
use v,
have : ¬ v = z := begin
by_contra w,
rw ← w at h,
exact h hv.2,
end,
rw set.inter_comm at hv,
exact ⟨hv, this⟩,
end
instance complex_plane_crowded_space : crowded_space ℂ :=
{ is_crowded := begin
have : ∀ (x : ℂ), ∃ y, ¬ y = x :=
begin
intros x,
by_cases (x = 0),
{ rw h,
exact ⟨1, one_ne_zero⟩, },
{ exact ⟨0, λ h', h h'.symm⟩, },
end,
exact t1_space_connected_with_two_points_is_crowded ℂ this,
end }
end crowded_space
section accuml_pts_homeomorph
lemma mem_image_closure_mem_closure
{X : Type*} [topological_space X] {U : set X} {x : X} (hx : x ∈ closure U)
{Y : Type*} [topological_space Y] {e : local_homeomorph X Y} (he : x ∈ e.to_local_equiv.source) :
e x ∈ closure (e '' U) :=
begin
rw _root_.mem_closure_iff at hx ⊢,
intros o ho hxo,
have : e.is_image (e⁻¹' o) o :=
begin
intros y hy,
split,
{ intros h, exact h, },
{ intros h, exact set.mem_preimage.mp h },
end,
let o' := e.to_local_equiv.source ∩ e⁻¹' o,
have subkey : x ∈ o' := ⟨he, hxo⟩,
have key : is_open o' :=
(local_homeomorph.is_image.is_open_iff this).mpr (is_open.inter e.open_target ho),
rcases hx o' key subkey with ⟨z, hz₁, hz₂⟩,
rcases hz₁ with ⟨hz₁₁, hz₁₂⟩,
use e z,
exact ⟨hz₁₂, set.mem_image_of_mem e hz₂⟩,
end
lemma mem_closure_inter
{X : Type*} [topological_space X] {U : set X} {x : X} (hx : x ∈ closure U)
{U' : set X} (hU' : is_open U') (h : x ∈ U') :
x ∈ closure (U ∩ U') :=
begin
rw _root_.mem_closure_iff at hx ⊢,
intros o ho hxo,
specialize hx (o ∩ U') (is_open.inter ho hU') ⟨hxo, h⟩,
rw set.inter_assoc at hx,
nth_rewrite 1 set.inter_comm at hx,
exact hx,
end
lemma accumulation_pt_local_homeomorph
{X : Type*} [topological_space X] {U : set X} {x : X} (hx : accumulation_pt X U x)
{Y : Type*} [topological_space Y] {e : local_homeomorph X Y} (he : x ∈ e.to_local_equiv.source) :
accumulation_pt Y (e '' U) (e x) :=
begin
rw accumulation_pt at hx ⊢,
intros V hV,
rcases _root_.mem_nhds_iff.mp hV with ⟨V', hV'₁, hV'₂, hV'₃⟩,
specialize hx (e.to_local_equiv.source ∩ e⁻¹' (V' ∩ e.to_local_equiv.target)),
have : (e.to_local_equiv.source ∩ e⁻¹' (V' ∩ e.to_local_equiv.target)) ∈ 𝓝 x :=
begin
have minor : is_open (V' ∩ e.to_local_equiv.target) := is_open.inter hV'₂ e.open_target,
have key : x ∈ (e⁻¹' (V' ∩ e.to_local_equiv.target)) := set.mem_preimage.mpr ⟨hV'₃, local_equiv.map_source _ he⟩,
refine is_open.mem_nhds _ ⟨he, key⟩,
apply local_homeomorph.preimage_open_of_open,
exact is_open.inter hV'₂ e.open_target,
end,
rcases hx this with ⟨a, ha₁, ha₂⟩,
rcases ha₁ with ⟨haa, hab⟩,
let p := set.mem_image_of_mem e hab,
use e a,
split,
{ split, exact set.mem_image_of_mem e haa,
nth_rewrite 1 set.inter_comm at p,
rw [← local_homeomorph.coe_coe,
← local_equiv.symm_image_target_inter_eq e.to_local_equiv V'] at p,
have : set.left_inv_on ⇑(e.to_local_equiv)
⇑(e.to_local_equiv.symm) e.to_local_equiv.target :=
begin
nth_rewrite 0 ← local_equiv.symm_symm e.to_local_equiv,
rw [←local_homeomorph.symm_source, local_homeomorph.symm_to_local_equiv],
exact local_equiv.left_inv_on e.to_local_equiv.symm,
end,
rw set.left_inv_on.image_image' this (set.inter_subset_left e.to_local_equiv.target V') at p,
exact hV'₁ p.2, },
rw set.mem_image at p,
rcases p with ⟨b, hb⟩,
rcases hb with ⟨left, right⟩,
rcases left with ⟨hb₁, hb₂⟩,
{ intros w,
have key : a = b := by rwa [eq_comm, ←local_homeomorph.coe_coe e,
set.inj_on.eq_iff (local_equiv.inj_on e.to_local_equiv) hab.1 hb₁] at right,
rw ← right at w,
rw [eq_comm, ←local_homeomorph.coe_coe e,
set.inj_on.eq_iff (local_equiv.inj_on e.to_local_equiv) he hb₁] at w,
rw ← key at w,
exact ha₂ (eq_comm.mp w), },
end
end accuml_pts_homeomorph
section complex_theorems
theorem identity_theorem
{f : ℂ → ℂ} {g : ℂ → ℂ}
{U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U)
(hf : differentiable_on ℂ f U) (hg : differentiable_on ℂ g U)
{s₀ : ℂ} {S : set ℂ} (hS : S ⊆ U) (hS' : set.eq_on f g S)
(hs₀ : s₀ ∈ S) (hs₀' : accumulation_pt ℂ S s₀):
set.eq_on f g U :=
sorry
theorem eq_of_eq_on_open
{f : ℂ → ℂ} {g : ℂ → ℂ}
{U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U)
(hf : differentiable_on ℂ f U) (hg : differentiable_on ℂ g U)
{V : set ℂ} (hV₁ : is_open V) (hV₂ : V.nonempty) (hV₃ : set.eq_on f g V) (hV₄ : V ⊆ U) :
set.eq_on f g U :=
let ⟨v, hv⟩ := hV₂ in
identity_theorem hU₁ hU₂ hf hg hV₄ hV₃ hv $ accumulation_pt_of_mem_open_nondiscrete ℂ hV₁ hv
theorem open_mapping_complex
{f : ℂ → ℂ}
{U : set ℂ} (hU₁ : is_open U) (hU₂ : is_connected U)
(hf₁ : differentiable_on ℂ f U)
(hf₂ : ∃ (x y : ℂ), x ∈ U ∧ y ∈ U ∧ ¬ f x = f y) :
∀ (U' : set ℂ), U' ⊆ U → is_open U' → is_open (f '' U'):=
sorry
end complex_theorems
/-
Trash codes. A bad attempt to prove the identity theorem only assuming some
standard results
-/
/-
lemma nonvanishing_has_local_expansion
(ε : ℝ) {hε : ε > 0}
(f : ℂ → ℂ)
(w : ℂ)
{hf₁ : ∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0}
{hf₂ : ∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z} {hf₂ : f w = 0}:
∃ (k : ℕ) (r : ℝ) (g : ℂ → ℂ),
k > 0 ∧ r ≤ ε ∧ 0 < r ∧
∀ (x : ℂ), x ∈ ball w r → f = (λ x, ((x - w) ^ k) * g x)
∧ ¬ g x = 0 ∧ analytic_at ℂ g x:=
sorry
-- I cannot prove the following theorem neatly. I tried to prove it with some disguting inductions,
-- but Lean's treatments of derivatives are not quite nice in this case. Maybe using g's expansion
-- would be easier. But again, that requires at least one induction.
lemma nonvanishing_iter_deriv_of_nonvanishing
(f : ℂ → ℂ)
(w : ℂ)
{hf : analytic_at ℂ f w}:
(∃ (k : ℕ),
¬ iterated_deriv k f w = 0)
↔ (∃ (ε : ℝ), 0 < ε ∧ (∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z)
∧ (∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0)) :=
sorry
lemma nonvanishing_disk_of_continuous
(f : ℂ → ℂ)
(z : ℂ) {hf₁ : continuous_at f z} {hf₂ : ¬ f z = 0}:
∃ (ε : ℝ),
0 < ε ∧ ∀ (x : ℂ), x ∈ ball z ε → ¬ f x = 0 :=
begin
have := hf₁,
rw continuous_at_iff at this,
let ε' := ∥f z∥ / 2,
rw [← ne.def, ← norm_pos_iff] at hf₂,
have hε' : 0 < ∥f z∥ / 2 := by linarith,
rcases this ε' hε' with ⟨δ, hδ, h⟩,
use min ε' δ,
split,
simp,
exact ⟨hε', hδ⟩,
{
intros x hx,
rw [mem_ball', dist_comm] at hx,
have lt_δ : dist x z < δ := lt_of_lt_of_le hx (min_le_right _ _),
specialize h lt_δ,
rw [dist_eq_norm, norm_sub_rev] at h,
have key : 0 < ∥f x∥ :=
calc ∥f x∥ = ∥f z - (f z - f x)∥ : by simp
... ≥ ∥f z∥ - ∥f z - f x∥ : norm_sub_norm_le _ _
... ≥ ∥f z∥ - ε' : begin simp, apply le_of_lt, exact h, end
... ≥ ∥f z∥ - ∥f z∥ / 2 : begin simp, apply le_of_eq, rw ← norm_eq_abs, end
... = ∥f z∥ / 2 : by linarith
... > 0 : hε',
rw [norm_pos_iff] at key,
exact key,
},
end
lemma is_open_nonvanishing_of_continuous
(f : ℂ → ℂ)
(U : set ℂ) {hU : is_open U}
{hf : ∀ (z : ℂ), z ∈ U → continuous_at f z} :
is_open {z : ℂ | z ∈ U ∧ ¬ f z = 0} :=
begin
rw metric.is_open_iff at *,
dsimp,
intros z hz,
rcases hz with ⟨hz₁, hz₂⟩,
specialize hU z hz₁,
specialize hf z hz₁,
rcases hU with ⟨δ, hδ₁, hδ₂⟩,
rcases nonvanishing_disk_of_continuous f z with ⟨ε, hε₁, hε₂⟩,
assumption',
use min δ ε,
split,
simp at hδ₁,
exact lt_min hδ₁ hε₁,
rw subset_def,
dsimp,
intros x hx,
have key₁ : x ∈ U := hδ₂ ((ball_subset_ball $ min_le_left δ ε) hx),
have key₂ : ¬ f x = 0 := hε₂ x ((ball_subset_ball $ min_le_right δ ε) hx),
exact ⟨key₁, key₂⟩,
end
lemma isolated_zeros_of_nonvanishing
(ε : ℝ) {hε : ε > 0}
(f : ℂ → ℂ)
(w : ℂ)
{hf₁ : ∃ (z : ℂ), z ∈ ball w ε ∧ ¬f z = 0}
{hf₂ : ∀ (z : ℂ), z ∈ ball w ε → analytic_at ℂ f z}:
∃ (r : ℝ),
r ≤ ε ∧ 0 < r ∧
∀ (x : ℂ), x ∈ ball w r → ¬ x - w = 0 → ¬ f x = 0:=
begin
by_cases (f w = 0),
-- the case where f w = 0; use f's local expansion around w
{
rcases nonvanishing_has_local_expansion ε f w with ⟨k, r, g, H⟩,
rcases H with ⟨H₁, H₂, H₃, H₄⟩,
use r,
split,
exact H₂,
{
split,
exact H₃,
{
intros x hx₁ hx₂,
by_contra h',
specialize H₄ x hx₁,
rcases H₄ with ⟨h₂₁, h₂₂, h₂₃⟩,
rw h₂₁ at h',
have key : (x - w) ^ k = 0 ∨ g x = 0 := eq_zero_or_eq_zero_of_mul_eq_zero h',
cases key with key₁ key₂,
{
rw [← complex.cpow_nat_cast, complex.cpow_eq_zero_iff] at key₁,
exact hx₂ key₁.1,
},
{
exact h₂₂ key₂,
},
},
},
assumption',
},
-- the case where f w ≠ 0; use the continuity of f at w
{
specialize hf₂ w (mem_ball_self hε),
rcases nonvanishing_disk_of_continuous f w with ⟨r, hr⟩,
assumption',
use min r ε,
split,
exact min_le_right _ _,
split,
{
simp,
exact ⟨hr.1, hε⟩,
},
{
intros x hx₁ hx₂,
rw [mem_ball'] at hx₁,
have key : dist w x < r := lt_of_lt_of_le hx₁ (min_le_left _ _),
rw [← mem_ball'] at key,
exact hr.2 x key,
},
exact analytic_at.continuous_at hf₂,
},
end
def is_accumulation_point (U : set ℂ) (z : ℂ) : Prop :=
∀ (V : set ℂ), V ∈ (𝓝 z) → ∃ (v : ℂ), v ∈ U ∩ V ∧ ¬ v - z = 0
lemma vanishing_disk_of_accumulation_point
(U : set ℂ) {hU : is_open U}
(f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z}
(s₀ : ℂ)
{hs₀ : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} s₀}
{hs₀' : s₀ ∈ {s : ℂ | f s = 0 ∧ s ∈ U}}:
∃ (ε : ℝ), 0 < ε ∧ ball s₀ ε ⊆ U ∧
∀ (z : ℂ), z ∈ ball s₀ ε → f z = 0 :=
begin
by_contra w,
simp only [not_exists, not_and] at w,
dsimp at hs₀',
rw metric.is_open_iff at hU,
specialize hU s₀ hs₀'.2,
rcases hU with ⟨ε, hε₁, hε₂⟩,
specialize w ε hε₁ hε₂,
simp only [not_forall] at w,
rcases w with ⟨z, hz₁, hz₂⟩,
have hf₁ : ∃ (z : ℂ), z ∈ ball s₀ ε ∧ ¬f z = 0 := ⟨z, ⟨hz₁, hz₂⟩⟩,
have hf₂ : ∀ (x : ℂ), x ∈ ball s₀ ε → analytic_at ℂ f x := λ x hx, hf x $ hε₂ hx,
rcases isolated_zeros_of_nonvanishing ε f s₀ with ⟨r, hr₁, hr₂, hr₃⟩,
assumption',
have : ∃ (v : ℂ), v ∈ {s : ℂ | f s = 0 ∧ s ∈ U} ∩ (ball s₀ r) ∧ ¬ v - s₀ = 0 :=
hs₀ (ball s₀ r) (ball_mem_nhds s₀ hr₂),
rcases this with ⟨v, hv₁, hv₂⟩,
dsimp at hv₁,
show false, from (hr₃ v hv₁.2 hv₂) hv₁.1.1,
end
theorem vanishing_if_zeros_accumulate
(U : set ℂ) {hU₁ : is_open U} {hU₂ : is_connected U}
(f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z}
(s₀ : ℂ)
{hs₀ : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} s₀}
{hs₀' : s₀ ∈ {s : ℂ | f s = 0 ∧ s ∈ U}}:
∀ (z : ℂ), z ∈ U → f z = 0:=
begin
let U₁ : set ℂ := {z : ℂ | z ∈ U ∧ ∃ (r : ℝ), 0 < r ∧ ball z r ⊆ U ∧ ∀ (x : ℂ), x ∈ ball z r → f x = 0},
let U₂ : set ℂ := {z : ℂ | z ∈ U ∧ ∃ (k : ℕ), ¬ iterated_deriv k f z = 0},
have h₁ : U₁ ∪ U₂ = U :=
begin
ext,
split,
{
intro h,
dsimp at h,
cases h with H₁ H₂,
exact H₁.1,
exact H₂.1,
},
{
intro H,
by_cases (x ∈ U₂),
exact (mem_union_right U₁) h,
{
by_cases h' : f x = 0,
{
have key : is_accumulation_point {s : ℂ | f s = 0 ∧ s ∈ U} x ∧ x ∈ {s : ℂ | f s = 0 ∧ s ∈ U}:=
begin
by_contradiction w,
rw not_and_distrib at w,
cases w with w₁ w₂,
{
-- sorry,
unfold is_accumulation_point at w₁,
simp at w₁,
rcases w₁ with ⟨U', hU₁', hU₂'⟩,
rw metric.mem_nhds_iff at hU₁',
rcases hU₁' with ⟨r, hr₁, hr₂⟩,
let U'' : set ℂ := ball x r ∩ U,
have key₁ : is_open U'' := is_open.inter metric.is_open_ball hU₁,
rw metric.is_open_iff at key₁,
specialize key₁ x (mem_inter (mem_ball_self hr₁) H),
rcases key₁ with ⟨ε, hε₁, hε₂⟩,
let x' : ℂ := x + ε / 2,
have key₂ : x' ∈ ball x ε :=
begin
simp,
have : 0 ≤ ε / 2 := by linarith,
exact calc dist x' x = ∥(x + ε / 2) - x∥ : by rw dist_eq_norm
... = complex.abs ↑(ε / 2) : by simp
... = ε / 2 : by rw complex.abs_of_nonneg this
... < ε : by linarith,
end,
have key₃ : ¬ f x' = 0 :=
begin
by_contra w',
have : x' ∈ U'' := hε₂ key₂,
simp only [mem_inter_eq] at this,
specialize hU₂' x' w' this.2 (hr₂ this.1),
have key : ¬ x' - x = 0 := begin
simp,
exact ne_of_gt hε₁,
end,
show false, from key hU₂',
end,
have : ∃ (ε : ℝ), ε > 0 ∧ (∀ (z : ℂ), z ∈ ball x ε → analytic_at ℂ f z) ∧ ∃ (z : ℂ), z ∈ ball x ε ∧ ¬f z = 0 :=
begin
use ε,
split,
exact hε₁,
split,
intros z hz,
exact hf z (mem_of_mem_inter_right (hε₂ hz)),
exact ⟨x', ⟨key₂, key₃⟩⟩,
end,
have key₄ : x ∈ U₂ :=
begin
dsimp,
split,
exact H,
rcases iff.elim_right (nonvanishing_iter_deriv_of_nonvanishing f x) this with ⟨k, hk⟩,
use k,
exact hf x H,
end,
show false, from h key₄,
},
{
simp at w₂,
show false, from (w₂ h') H,
},
end,
rcases vanishing_disk_of_accumulation_point U f x with ⟨ε, hε₁, hε₂, hε₃⟩,
assumption',
have : x ∈ U₁ :=
begin
dsimp [U₁],
split,
exact H,
{
use ε,
exact ⟨hε₁, ⟨hε₂, hε₃⟩⟩,
},
end,
exact (mem_union_left U₂) this,
exact key.1,
exact key.2,
},
{
have key₁ : ∃ (k : ℕ), ¬ iterated_deriv k f x = 0 := by use 0,
have key₂ : x ∈ U₂ := begin
simp,
exact ⟨H, key₁⟩,
end,
exfalso,
exact h key₂,
},
},
},
end,
have h₂ : U₁ ∩ U₂ = ∅ :=
begin
by_contra,
rw [← ne.def, ne_empty_iff_nonempty, nonempty_def] at h,
rcases h with ⟨x, hx⟩,
dsimp at hx,
rcases iff.elim_left (nonvanishing_iter_deriv_of_nonvanishing f x) hx.2.2 with ⟨ε, hε₁, hε₂, hε₃⟩,
rcases isolated_zeros_of_nonvanishing ε f x with ⟨r, hr₁, hr₂, hr₃⟩,
assumption',
swap,
exact hf x hx.1.1,
rcases hx.1.2 with ⟨r', hr₁', hr₂', hr₃'⟩,
let r'' : ℝ := min r r',
have minor₁ : 0 < r'' :=
begin
rw lt_min_iff,
exact ⟨hr₂, gt.lt hr₁'⟩,
end,
have minor₂ : ∃ (x' : ℂ), x' ∈ ball x r'' ∧ ¬ x' - x = 0 :=
begin
let x' : ℂ := x + r'' / 2,
use x',
split,
simp only [metric.mem_ball],
have : 0 ≤ r'' / 2 := by linarith,
exact calc dist x' x = ∥(x + r'' / 2) - x∥ : by rw dist_eq_norm
... = complex.abs ↑(r'' / 2) : by simp
... = r'' / 2 : by rw complex.abs_of_nonneg this
... < r'' : by linarith,
simp,
exact ne_of_gt minor₁,
end,
rcases minor₂ with ⟨x', hx₁', hx₂'⟩,
have key₁ : f x' = 0 := hr₃' x' ((ball_subset_ball (min_le_right r r')) hx₁'),
have key₂ : ¬ f x' = 0 := hr₃ x' ((ball_subset_ball (min_le_left r r')) hx₁') hx₂',
show false, from key₂ key₁,
end,
have h₃ : is_open U₁ :=
begin
rw metric.is_open_iff,
intros x hx,
dsimp at hx,
rcases hx with ⟨hx₁, ε, hε₁, hε₂, hε₃⟩,
use ε,
split,
exact hε₁,
intros z hz,
dsimp,
split,
exact hε₂ hz,
have : ∃ (r : ℝ), (0 < r ∧ ball z r ⊆ U) ∧ ball z r ⊆ ball x ε :=
begin
have key : is_open (ball x ε) := is_open_ball,
rw metric.is_open_iff at key,
specialize key z hz,
rcases key with ⟨r, hr₁, hr₂⟩,
use r,
split,
exact ⟨hr₁, subset.trans hr₂ hε₂⟩,
exact hr₂,
end,
rcases this with ⟨r, hr₁, hr₂⟩,
use r,
split,
exact hr₁.1,
split,
exact hr₁.2,
intros x' hx',
exact hε₃ x' (hr₂ hx'),
end,
have h₄ : is_open U₂ :=
begin
sorry,
end,
have h₅ : U₁.nonempty :=
begin
rw nonempty_def,
use s₀,
dsimp,
simp at hs₀',
split,
exact hs₀'.2,
rcases vanishing_disk_of_accumulation_point U f s₀ with ⟨ε, hε₁, hε₂, hε₃⟩,
assumption',
use ε,
exact ⟨hε₁, ⟨hε₂, hε₃⟩⟩,
end,
have hfinal : U₁ = U :=
begin
have : is_preconnected U := is_connected.is_preconnected hU₂,
rw is_preconnected_iff_subset_of_disjoint at this,
specialize this U₁ U₂ h₃ h₄ (eq.subset (eq.symm h₁)),
have minor : U ∩ (U₁ ∩ U₂) = ∅ :=
begin
rw h₂,
simp,
end,
specialize this minor,
cases this,
{
have minor' : U₁ ⊆ U :=
begin
let h := set.subset_union_left U₁ U₂,
rw h₁ at h,
exact h,
end,
exact has_subset.subset.antisymm minor' this,
},
{
have minor₁ : U₁ ⊆ U :=
begin
let h := set.subset_union_left U₁ U₂,
rw h₁ at h,
exact h,
end,
have minor₂ : U₂ ⊆ U :=
begin
let h := set.subset_union_right U₁ U₂,
rw h₁ at h,
exact h,
end,
have minor₃ : U₂ = U := has_subset.subset.antisymm minor₂ this,
have key : U₁ = ∅ :=
begin
rw [inter_comm, ← set.subset_empty_iff, ← set.diff_eq_self] at h₂,
rw ← h₂,
by_contra w,
rw [← ne.def, set.ne_empty_iff_nonempty, set.nonempty_diff, minor₃] at w,
show false, from w minor₁,
end,
rw [← set.not_nonempty_iff_eq_empty] at key,
exfalso,
exact key h₅,
},
end,
intros z hz,
have : z ∈ U₁ := (eq.subset (eq.symm hfinal)) hz,
dsimp at this,
rcases this.2 with ⟨r, hr₁, hr₂, hr₃⟩,
specialize hr₃ z (mem_ball_self hr₁),
exact hr₃,
end
theorem eq_if_eq_points_accumulate
(U : set ℂ) {hU₁ : is_open U} {hU₂ : is_connected U}
(f : ℂ → ℂ) {hf : ∀ (z : ℂ), z ∈ U → analytic_at ℂ f z}
(g : ℂ → ℂ) {hg : ∀ (z : ℂ), z ∈ U → analytic_at ℂ g z}
(s₀ : ℂ)
{hs₀ : is_accumulation_point {s : ℂ | f s = g s ∧ s ∈ U} s₀}
{hs₀' : s₀ ∈ {s : ℂ | f s = g s ∧ s ∈ U}} :
∀ (z : ℂ), z ∈ U → f z = g z :=
begin
let h : ℂ → ℂ := f - g,
have minor : ∀ (z : ℂ), z ∈ U → analytic_at ℂ h z := λ z hz, analytic_at.sub (hf z hz) $ hg z hz,
have key : {s : ℂ | f s = g s ∧ s ∈ U} = {s : ℂ | h s = 0 ∧ s ∈ U} :=
begin
ext,
split,
{
intros hx,
dsimp at hx,
simp, split,
exact calc h x = (f - g) x : by refl
... = f x - g x : by simp
... = f x - f x : by rw ← hx.1
... = 0 : by ring,
exact hx.2,
},
{
intros hx,
dsimp at hx,
simp, split,
exact calc f x = f x - g x + g x : by simp
... = (f - g) x + g x : by simp
... = h x + g x : by refl
... = 0 + g x : by rw hx.1
... = g x : by ring,
exact hx.2,
},
end,
rw key at hs₀ hs₀',
intros z hz,
have : h z = 0 := vanishing_if_zeros_accumulate U h s₀ z hz,
assumption',
exact calc f z = f z - g z + g z : by simp
... = (f - g) z + g z : by simp
... = h z + g z : by refl
... = 0 + g z : by rw this
... = g z : by ring,
end
-/
|
c0c0328d3408496f938cdceb36cda8d4401f7835
|
ba4794a0deca1d2aaa68914cd285d77880907b5c
|
/src/game/world9/level4.lean
|
999bb784b5bcad6ebc73015f66bcd06150811a3e
|
[
"Apache-2.0"
] |
permissive
|
ChrisHughes24/natural_number_game
|
c7c00aa1f6a95004286fd456ed13cf6e113159ce
|
9d09925424da9f6275e6cfe427c8bcf12bb0944f
|
refs/heads/master
| 1,600,715,773,528
| 1,573,910,462,000
| 1,573,910,462,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,288
|
lean
|
import game.world9.level3 -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 4: `mul_left_cancel`
This is the last of the bonus multiplication levels.
`mul_left_cancel` will be useful in inequality world.
It might be worth noting that `revert` is the opposite of `intro`.
`revert` can be a convenient tactic just before the beginning of
an induction proof.
-/
/- Theorem
If $a \neq 0$, $b$ and $c$ are natural numbers such that
$ ab = ac, $
then $b = c$.
-/
theorem mul_left_cancel (a b c : mynat) (ha : a ≠ 0) : a * b = a * c → b = c :=
begin [less_leaky]
revert b,
induction c with d hd,
{ intro b,
rw mul_zero,
intro h,
cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ h) with h1 h2,
exfalso,
apply ha,
assumption,
assumption
},
{ intros b hb,
cases b with c,
{ rw mul_zero at hb,
exfalso,
apply ha,
symmetry at hb,
cases (eq_zero_or_eq_zero_of_mul_eq_zero _ _ hb) with h h,
exact h,
exfalso,
exact succ_ne_zero _ h,
},
{ have h : c = d,
apply hd,
rw mul_succ at hb,
rw mul_succ at hb,
apply add_right_cancel _ _ _ hb,
rw h,
refl,
}
}
end
end mynat -- hide
/-
You should now be ready for inequality world.
-/
|
c1c8a38d1126de3d28bb07ba6722375cec010e68
|
a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940
|
/src/Lean/Data/Name.lean
|
c853d9b55c99e7bd0204b26d1ce92522da896cca
|
[
"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
| 5,465
|
lean
|
/-
Copyright (c) 2018 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Std.Data.HashSet
import Std.Data.RBMap
import Std.Data.RBTree
namespace Lean
instance : Coe String Name := ⟨Name.mkSimple⟩
namespace Name
@[export lean_name_hash] def hashEx : Name → UInt64 :=
Name.hash
def getPrefix : Name → Name
| anonymous => anonymous
| str p s _ => p
| num p s _ => p
def getString! : Name → String
| str _ s _ => s
| _ => unreachable!
def getNumParts : Name → Nat
| anonymous => 0
| str p _ _ => getNumParts p + 1
| num p _ _ => getNumParts p + 1
def updatePrefix : Name → Name → Name
| anonymous, newP => anonymous
| str p s _, newP => Name.mkStr newP s
| num p s _, newP => Name.mkNum newP s
def components' : Name → List Name
| anonymous => []
| str n s _ => Name.mkStr anonymous s :: components' n
| num n v _ => Name.mkNum anonymous v :: components' n
def components (n : Name) : List Name :=
n.components'.reverse
def eqStr : Name → String → Bool
| str anonymous s _, s' => s == s'
| _, _ => false
def isPrefixOf : Name → Name → Bool
| p, anonymous => p == anonymous
| p, n@(num p' _ _) => p == n || isPrefixOf p p'
| p, n@(str p' _ _) => p == n || isPrefixOf p p'
def isSuffixOf : Name → Name → Bool
| anonymous, _ => true
| str p₁ s₁ _, str p₂ s₂ _ => s₁ == s₂ && isSuffixOf p₁ p₂
| num p₁ n₁ _, num p₂ n₂ _ => n₁ == n₂ && isSuffixOf p₁ p₂
| _, _ => false
def cmp : Name → Name → Ordering
| anonymous, anonymous => Ordering.eq
| anonymous, _ => Ordering.lt
| _, anonymous => Ordering.gt
| num p₁ i₁ _, num p₂ i₂ _ =>
match cmp p₁ p₂ with
| Ordering.eq => compare i₁ i₂
| ord => ord
| num _ _ _, str _ _ _ => Ordering.lt
| str _ _ _, num _ _ _ => Ordering.gt
| str p₁ n₁ _, str p₂ n₂ _ =>
match cmp p₁ p₂ with
| Ordering.eq => compare n₁ n₂
| ord => ord
def lt (x y : Name) : Bool :=
cmp x y == Ordering.lt
def quickCmpAux : Name → Name → Ordering
| anonymous, anonymous => Ordering.eq
| anonymous, _ => Ordering.lt
| _, anonymous => Ordering.gt
| num n v _, num n' v' _ =>
match compare v v' with
| Ordering.eq => n.quickCmpAux n'
| ord => ord
| num _ _ _, str _ _ _ => Ordering.lt
| str _ _ _, num _ _ _ => Ordering.gt
| str n s _, str n' s' _ =>
match compare s s' with
| Ordering.eq => n.quickCmpAux n'
| ord => ord
def quickCmp (n₁ n₂ : Name) : Ordering :=
match compare n₁.hash n₂.hash with
| Ordering.eq => quickCmpAux n₁ n₂
| ord => ord
def quickLt (n₁ n₂ : Name) : Bool :=
quickCmp n₁ n₂ == Ordering.lt
/- Alternative HasLt instance. -/
@[inline] protected def hasLtQuick : LT Name :=
⟨fun a b => Name.quickLt a b = true⟩
@[inline] instance : DecidableRel (@LT.lt Name Name.hasLtQuick) :=
inferInstanceAs (DecidableRel (fun a b => Name.quickLt a b = true))
/- The frontend does not allow user declarations to start with `_` in any of its parts.
We use name parts starting with `_` internally to create auxiliary names (e.g., `_private`). -/
def isInternal : Name → Bool
| str p s _ => s.get 0 == '_' || isInternal p
| num p _ _ => isInternal p
| _ => false
def isAtomic : Name → Bool
| anonymous => true
| str anonymous _ _ => true
| num anonymous _ _ => true
| _ => false
def isAnonymous : Name → Bool
| anonymous => true
| _ => false
def isStr : Name → Bool
| str .. => true
| _ => false
def isNum : Name → Bool
| num .. => true
| _ => false
end Name
open Std (RBMap RBTree mkRBMap mkRBTree)
def NameMap (α : Type) := Std.RBMap Name α Name.quickCmp
@[inline] def mkNameMap (α : Type) : NameMap α := Std.mkRBMap Name α Name.quickCmp
namespace NameMap
variable {α : Type}
instance (α : Type) : EmptyCollection (NameMap α) := ⟨mkNameMap α⟩
instance (α : Type) : Inhabited (NameMap α) where
default := {}
def insert (m : NameMap α) (n : Name) (a : α) := Std.RBMap.insert m n a
def contains (m : NameMap α) (n : Name) : Bool := Std.RBMap.contains m n
@[inline] def find? (m : NameMap α) (n : Name) : Option α := Std.RBMap.find? m n
end NameMap
def NameSet := RBTree Name Name.quickCmp
namespace NameSet
def empty : NameSet := mkRBTree Name Name.quickCmp
instance : EmptyCollection NameSet := ⟨empty⟩
instance : Inhabited NameSet := ⟨{}⟩
def insert (s : NameSet) (n : Name) : NameSet := Std.RBTree.insert s n
def contains (s : NameSet) (n : Name) : Bool := Std.RBMap.contains s n
instance : ForIn m NameSet Name :=
inferInstanceAs (ForIn _ (Std.RBTree ..) ..)
end NameSet
def NameHashSet := Std.HashSet Name
namespace NameHashSet
@[inline] def empty : NameHashSet := Std.HashSet.empty
instance : EmptyCollection NameHashSet := ⟨empty⟩
instance : Inhabited NameHashSet := ⟨{}⟩
def insert (s : NameHashSet) (n : Name) := Std.HashSet.insert s n
def contains (s : NameHashSet) (n : Name) : Bool := Std.HashSet.contains s n
end NameHashSet
end Lean
open Lean
def String.toName (s : String) : Name :=
let ps := s.splitOn ".";
ps.foldl (fun n p => Name.mkStr n p.trim) Name.anonymous
|
3493215bd310c031e6724b8d3759506d196ec346
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/cc_ac_bug.lean
|
a55367e8701b68f190415b2d9d110fa8ac508dee
|
[
"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
| 349
|
lean
|
instance aa : is_associative ℕ (+) := ⟨nat.add_assoc⟩
instance ac : is_commutative ℕ (+) := ⟨nat.add_comm⟩
instance ma : is_associative ℕ (*) := ⟨nat.mul_assoc⟩
instance mc : is_commutative ℕ (*) := ⟨nat.mul_comm⟩
example (a b c : nat) (f : nat → nat → nat) : f (b * c) (c * b * a) = f (c * b) (a * c * b) :=
by ac_refl
|
93affb9e0e48c09ce467cef941531dce382b3a4b
|
491068d2ad28831e7dade8d6dff871c3e49d9431
|
/tests/lean/nary_overload2.lean
|
483cc9271e2d064bdc284019c18e8f693e132c8b
|
[
"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
| 366
|
lean
|
import data.list data.examples.vector
open nat list vector
check [1, 2, 3]
check ([1, 2, 3] : vector nat _)
check ([1, 2, 3] : list nat)
check (#list [1, 2, 3])
check (#vector [1, 2, 3])
example : (#vector [1, 2, 3]) = [1, 2, 3] :=
rfl
example : (#vector [1, 2, 3]) = ([1, 2, 3] : vector nat _) :=
rfl
example : (#list [1, 2, 3]) = ([1, 2, 3] : list nat) :=
rfl
|
3ab197b18666d94cf7de78dc157c154d1f801a20
|
31f556cdeb9239ffc2fad8f905e33987ff4feab9
|
/src/Lean/Compiler/LCNF/MonoTypes.lean
|
f3a1e7e6afd9cffc839fbe57f5a9244661848627
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
tobiasgrosser/lean4
|
ce0fd9cca0feba1100656679bf41f0bffdbabb71
|
ebdbdc10436a4d9d6b66acf78aae7a23f5bd073f
|
refs/heads/master
| 1,673,103,412,948
| 1,664,930,501,000
| 1,664,930,501,000
| 186,870,185
| 0
| 0
|
Apache-2.0
| 1,665,129,237,000
| 1,557,939,901,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,557
|
lean
|
/-
Copyright (c) 2022 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Compiler.LCNF.InferType
namespace Lean.Compiler.LCNF
/--
Convert a LCNF type from the base phase to the mono phase.
LCNF types in the mono phase do not have dependencies,
and universe levels have been erased.
The type contains only `→` and constants.
-/
partial def toMonoType (type : Expr) : CompilerM Expr := do
let type := type.headBeta
if type.isAnyType then
return anyTypeExpr
else if type.isErased then
return erasedExpr
else if isTypeFormerType type then
return erasedExpr
else match type with
| .const .. => visitApp type #[]
| .app .. => type.withApp visitApp
| .forallE _ d b _ => mkArrow (← toMonoType d) (← toMonoType (b.instantiate1 anyTypeExpr))
| _ => return anyTypeExpr
where
visitApp (f : Expr) (args : Array Expr) : CompilerM Expr := do
match f with
| .const declName _ =>
let mut result := mkConst declName
for arg in args do
let arg := arg.headBeta
if arg.isAnyType || arg.isErased then
result := mkApp result arg
else
let argType := (← inferType arg).headBeta
if argType.isAnyType || argType matches .sort _ then
result := mkApp result (← toMonoType arg)
else
result := mkApp result erasedExpr
return result
| _ => return anyTypeExpr
end Lean.Compiler.LCNF
|
325bab44f77ee6200388668150b86af163ff2884
|
42610cc2e5db9c90269470365e6056df0122eaa0
|
/hott/algebra/category/iso.hlean
|
cec39ec3197527fc4658bd385a73b05e665a2837
|
[
"Apache-2.0"
] |
permissive
|
tomsib2001/lean
|
2ab59bfaebd24a62109f800dcf4a7139ebd73858
|
eb639a7d53fb40175bea5c8da86b51d14bb91f76
|
refs/heads/master
| 1,586,128,387,740
| 1,468,968,950,000
| 1,468,968,950,000
| 61,027,234
| 0
| 0
| null | 1,465,813,585,000
| 1,465,813,585,000
| null |
UTF-8
|
Lean
| false
| false
| 16,906
|
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, Jakob von Raumer
-/
import .precategory types.sigma arity
open eq category prod equiv is_equiv sigma sigma.ops is_trunc
namespace iso
structure split_mono [class] {ob : Type} [C : precategory ob] {a b : ob} (f : a ⟶ b) :=
{retraction_of : b ⟶ a}
(retraction_comp : retraction_of ∘ f = id)
structure split_epi [class] {ob : Type} [C : precategory ob] {a b : ob} (f : a ⟶ b) :=
{section_of : b ⟶ a}
(comp_section : f ∘ section_of = id)
structure is_iso [class] {ob : Type} [C : precategory ob] {a b : ob} (f : a ⟶ b) :=
(inverse : b ⟶ a)
(left_inverse : inverse ∘ f = id)
(right_inverse : f ∘ inverse = id)
attribute is_iso.inverse [reducible]
open split_mono split_epi is_iso
abbreviation retraction_of [unfold 6] := @split_mono.retraction_of
abbreviation retraction_comp [unfold 6] := @split_mono.retraction_comp
abbreviation section_of [unfold 6] := @split_epi.section_of
abbreviation comp_section [unfold 6] := @split_epi.comp_section
abbreviation inverse [unfold 6] := @is_iso.inverse
abbreviation left_inverse [unfold 6] := @is_iso.left_inverse
abbreviation right_inverse [unfold 6] := @is_iso.right_inverse
postfix ⁻¹ := inverse
--a second notation for the inverse, which is not overloaded
postfix [parsing_only] `⁻¹ʰ`:std.prec.max_plus := inverse -- input using \-1h
variables {ob : Type} [C : precategory ob]
variables {a b c : ob} {g : b ⟶ c} {f : a ⟶ b} {h : b ⟶ a}
include C
definition split_mono_of_is_iso [constructor] [instance] [priority 300]
(f : a ⟶ b) [H : is_iso f] : split_mono f :=
split_mono.mk !left_inverse
definition split_epi_of_is_iso [constructor] [instance] [priority 300]
(f : a ⟶ b) [H : is_iso f] : split_epi f :=
split_epi.mk !right_inverse
definition is_iso_id [constructor] [instance] [priority 500] (a : ob) : is_iso (ID a) :=
is_iso.mk _ !id_id !id_id
definition is_iso_inverse [constructor] [instance] [priority 200] (f : a ⟶ b) {H : is_iso f}
: is_iso f⁻¹ :=
is_iso.mk _ !right_inverse !left_inverse
theorem left_inverse_eq_right_inverse {f : a ⟶ b} {g g' : hom b a}
(Hl : g ∘ f = id) (Hr : f ∘ g' = id) : g = g' :=
by rewrite [-(id_right g), -Hr, assoc, Hl, id_left]
theorem retraction_eq [H : split_mono f] (H2 : f ∘ h = id) : retraction_of f = h :=
left_inverse_eq_right_inverse !retraction_comp H2
theorem section_eq [H : split_epi f] (H2 : h ∘ f = id) : section_of f = h :=
(left_inverse_eq_right_inverse H2 !comp_section)⁻¹
theorem inverse_eq_right [H : is_iso f] (H2 : f ∘ h = id) : f⁻¹ = h :=
left_inverse_eq_right_inverse !left_inverse H2
theorem inverse_eq_left [H : is_iso f] (H2 : h ∘ f = id) : f⁻¹ = h :=
(left_inverse_eq_right_inverse H2 !right_inverse)⁻¹
theorem retraction_eq_section (f : a ⟶ b) [Hl : split_mono f] [Hr : split_epi f] :
retraction_of f = section_of f :=
retraction_eq !comp_section
definition is_iso_of_split_epi_of_split_mono [constructor] (f : a ⟶ b)
[Hl : split_mono f] [Hr : split_epi f] : is_iso f :=
is_iso.mk _ ((retraction_eq_section f) ▸ (retraction_comp f)) (comp_section f)
theorem inverse_unique (H H' : is_iso f) : @inverse _ _ _ _ f H = @inverse _ _ _ _ f H' :=
@inverse_eq_left _ _ _ _ _ _ H !left_inverse
theorem inverse_involutive (f : a ⟶ b) [H : is_iso f] [H : is_iso (f⁻¹)]
: (f⁻¹)⁻¹ = f :=
inverse_eq_right !left_inverse
theorem inverse_eq_inverse {f g : a ⟶ b} [H : is_iso f] [H : is_iso g] (p : f = g)
: f⁻¹ = g⁻¹ :=
by cases p;apply inverse_unique
theorem retraction_id (a : ob) : retraction_of (ID a) = id :=
retraction_eq !id_id
theorem section_id (a : ob) : section_of (ID a) = id :=
section_eq !id_id
theorem id_inverse (a : ob) [H : is_iso (ID a)] : (ID a)⁻¹ = id :=
inverse_eq_left !id_id
definition split_mono_comp [constructor] [instance] [priority 150] (g : b ⟶ c) (f : a ⟶ b)
[Hf : split_mono f] [Hg : split_mono g] : split_mono (g ∘ f) :=
split_mono.mk
(show (retraction_of f ∘ retraction_of g) ∘ g ∘ f = id,
by rewrite [-assoc, assoc _ g f, retraction_comp, id_left, retraction_comp])
definition split_epi_comp [constructor] [instance] [priority 150] (g : b ⟶ c) (f : a ⟶ b)
[Hf : split_epi f] [Hg : split_epi g] : split_epi (g ∘ f) :=
split_epi.mk
(show (g ∘ f) ∘ section_of f ∘ section_of g = id,
by rewrite [-assoc, {f ∘ _}assoc, comp_section, id_left, comp_section])
definition is_iso_comp [constructor] [instance] [priority 150] (g : b ⟶ c) (f : a ⟶ b)
[Hf : is_iso f] [Hg : is_iso g] : is_iso (g ∘ f) :=
!is_iso_of_split_epi_of_split_mono
theorem is_prop_is_iso [instance] (f : hom a b) : is_prop (is_iso f) :=
begin
apply is_prop.mk, intro H H',
cases H with g li ri, cases H' with g' li' ri',
fapply (apd0111 (@is_iso.mk ob C a b f)),
apply left_inverse_eq_right_inverse,
apply li,
apply ri',
apply is_prop.elim,
apply is_prop.elim,
end
end iso open iso
/- isomorphic objects -/
structure iso {ob : Type} [C : precategory ob] (a b : ob) :=
(to_hom : hom a b)
(struct : is_iso to_hom)
infix ` ≅ `:50 := iso
notation c ` ≅[`:50 C:0 `] `:0 c':50 := @iso C _ c c'
attribute iso.struct [instance] [priority 2000]
namespace iso
variables {ob : Type} [C : precategory ob]
variables {a b c : ob} {g : b ⟶ c} {f : a ⟶ b} {h : b ⟶ a}
include C
attribute to_hom [coercion]
protected definition MK [constructor] (f : a ⟶ b) (g : b ⟶ a)
(H1 : g ∘ f = id) (H2 : f ∘ g = id) :=
@(mk f) (is_iso.mk _ H1 H2)
variable {C}
definition to_inv [reducible] [unfold 5] (f : a ≅ b) : b ⟶ a := (to_hom f)⁻¹
definition to_left_inverse [unfold 5] (f : a ≅ b) : (to_hom f)⁻¹ ∘ (to_hom f) = id :=
left_inverse (to_hom f)
definition to_right_inverse [unfold 5] (f : a ≅ b) : (to_hom f) ∘ (to_hom f)⁻¹ = id :=
right_inverse (to_hom f)
variable [C]
protected definition refl [constructor] (a : ob) : a ≅ a :=
mk (ID a) _
protected definition symm [constructor] ⦃a b : ob⦄ (H : a ≅ b) : b ≅ a :=
mk (to_hom H)⁻¹ _
protected definition trans [constructor] ⦃a b c : ob⦄ (H1 : a ≅ b) (H2 : b ≅ c) : a ≅ c :=
mk (to_hom H2 ∘ to_hom H1) _
infixl ` ⬝i `:75 := iso.trans
postfix [parsing_only] `⁻¹ⁱ`:(max + 1) := iso.symm
definition change_hom [constructor] (H : a ≅ b) (f : a ⟶ b) (p : to_hom H = f) : a ≅ b :=
iso.MK f (to_inv H) (p ▸ to_left_inverse H) (p ▸ to_right_inverse H)
definition change_inv [constructor] (H : a ≅ b) (g : b ⟶ a) (p : to_inv H = g) : a ≅ b :=
iso.MK (to_hom H) g (p ▸ to_left_inverse H) (p ▸ to_right_inverse H)
definition iso_mk_eq {f f' : a ⟶ b} [H : is_iso f] [H' : is_iso f'] (p : f = f')
: iso.mk f _ = iso.mk f' _ :=
apd011 iso.mk p !is_prop.elim
variable {C}
definition iso_eq {f f' : a ≅ b} (p : to_hom f = to_hom f') : f = f' :=
by (cases f; cases f'; apply (iso_mk_eq p))
variable [C]
-- The structure for isomorphism can be characterized up to equivalence by a sigma type.
protected definition sigma_char ⦃a b : ob⦄ : (Σ (f : hom a b), is_iso f) ≃ (a ≅ b) :=
begin
fapply (equiv.mk),
{intro S, apply iso.mk, apply (S.2)},
{fapply adjointify,
{intro p, cases p with f H, exact sigma.mk f H},
{intro p, cases p, apply idp},
{intro S, cases S, apply idp}},
end
-- The type of isomorphisms between two objects is a set
definition is_set_iso [instance] : is_set (a ≅ b) :=
begin
apply is_trunc_is_equiv_closed,
apply equiv.to_is_equiv (!iso.sigma_char),
end
definition iso_of_eq [unfold 5] (p : a = b) : a ≅ b :=
eq.rec_on p (iso.refl a)
definition hom_of_eq [reducible] [unfold 5] (p : a = b) : a ⟶ b :=
iso.to_hom (iso_of_eq p)
definition inv_of_eq [reducible] [unfold 5] (p : a = b) : b ⟶ a :=
iso.to_inv (iso_of_eq p)
definition iso_of_eq_inv (p : a = b) : iso_of_eq p⁻¹ = iso.symm (iso_of_eq p) :=
eq.rec_on p idp
theorem hom_of_eq_inv (p : a = b) : hom_of_eq p⁻¹ = inv_of_eq p :=
eq.rec_on p idp
theorem inv_of_eq_inv (p : a = b) : inv_of_eq p⁻¹ = hom_of_eq p :=
eq.rec_on p idp
definition iso_of_eq_con (p : a = b) (q : b = c)
: iso_of_eq (p ⬝ q) = iso.trans (iso_of_eq p) (iso_of_eq q) :=
eq.rec_on q (eq.rec_on p (iso_eq !id_id⁻¹))
section
open funext
variables {X : Type} {x y : X} {F G : X → ob}
definition transport_hom_of_eq (p : F = G) (f : hom (F x) (F y))
: p ▸ f = hom_of_eq (apd10 p y) ∘ f ∘ inv_of_eq (apd10 p x) :=
by induction p; exact !id_leftright⁻¹
definition transport_hom_of_eq_right (p : x = y) (f : hom c (F x))
: p ▸ f = hom_of_eq (ap F p) ∘ f :=
by induction p; exact !id_left⁻¹
definition transport_hom_of_eq_left (p : x = y) (f : hom (F x) c)
: p ▸ f = f ∘ inv_of_eq (ap F p) :=
by induction p; exact !id_right⁻¹
definition transport_hom (p : F ~ G) (f : hom (F x) (F y))
: eq_of_homotopy p ▸ f = hom_of_eq (p y) ∘ f ∘ inv_of_eq (p x) :=
calc
eq_of_homotopy p ▸ f =
hom_of_eq (apd10 (eq_of_homotopy p) y) ∘ f ∘ inv_of_eq (apd10 (eq_of_homotopy p) x)
: transport_hom_of_eq
... = hom_of_eq (p y) ∘ f ∘ inv_of_eq (p x) : {right_inv apd10 p}
end
structure mono [class] (f : a ⟶ b) :=
(elim : ∀c (g h : hom c a), f ∘ g = f ∘ h → g = h)
structure epi [class] (f : a ⟶ b) :=
(elim : ∀c (g h : hom b c), g ∘ f = h ∘ f → g = h)
definition mono_of_split_mono [instance] (f : a ⟶ b) [H : split_mono f] : mono f :=
mono.mk
(λ c g h H,
calc
g = id ∘ g : by rewrite id_left
... = (retraction_of f ∘ f) ∘ g : by rewrite retraction_comp
... = (retraction_of f ∘ f) ∘ h : by rewrite [-assoc, H, -assoc]
... = id ∘ h : by rewrite retraction_comp
... = h : by rewrite id_left)
definition epi_of_split_epi [instance] (f : a ⟶ b) [H : split_epi f] : epi f :=
epi.mk
(λ c g h H,
calc
g = g ∘ id : by rewrite id_right
... = g ∘ f ∘ section_of f : by rewrite -(comp_section f)
... = h ∘ f ∘ section_of f : by rewrite [assoc, H, -assoc]
... = h ∘ id : by rewrite comp_section
... = h : by rewrite id_right)
definition mono_comp [instance] (g : b ⟶ c) (f : a ⟶ b) [Hf : mono f] [Hg : mono g]
: mono (g ∘ f) :=
mono.mk
(λ d h₁ h₂ H,
have H2 : g ∘ (f ∘ h₁) = g ∘ (f ∘ h₂),
begin
rewrite *assoc, exact H
end,
!mono.elim (!mono.elim H2))
definition epi_comp [instance] (g : b ⟶ c) (f : a ⟶ b) [Hf : epi f] [Hg : epi g]
: epi (g ∘ f) :=
epi.mk
(λ d h₁ h₂ H,
have H2 : (h₁ ∘ g) ∘ f = (h₂ ∘ g) ∘ f,
begin
rewrite -*assoc, exact H
end,
!epi.elim (!epi.elim H2))
end iso
attribute iso.refl [refl]
attribute iso.symm [symm]
attribute iso.trans [trans]
namespace iso
/-
rewrite lemmas for inverses, modified from
https://github.com/JasonGross/HoTT-categories/blob/master/theories/Categories/Category/Morphisms.v
-/
section
variables {ob : Type} [C : precategory ob] include C
variables {a b c d : ob} (f : b ⟶ a)
(r : c ⟶ d) (q : b ⟶ c) (p : a ⟶ b)
(g : d ⟶ c)
variable [Hq : is_iso q] include Hq
theorem comp.right_inverse : q ∘ q⁻¹ = id := !right_inverse
theorem comp.left_inverse : q⁻¹ ∘ q = id := !left_inverse
theorem inverse_comp_cancel_left : q⁻¹ ∘ (q ∘ p) = p :=
by rewrite [assoc, left_inverse, id_left]
theorem comp_inverse_cancel_left : q ∘ (q⁻¹ ∘ g) = g :=
by rewrite [assoc, right_inverse, id_left]
theorem comp_inverse_cancel_right : (r ∘ q) ∘ q⁻¹ = r :=
by rewrite [-assoc, right_inverse, id_right]
theorem inverse_comp_cancel_right : (f ∘ q⁻¹) ∘ q = f :=
by rewrite [-assoc, left_inverse, id_right]
theorem comp_inverse [Hp : is_iso p] [Hpq : is_iso (q ∘ p)] : (q ∘ p)⁻¹ʰ = p⁻¹ʰ ∘ q⁻¹ʰ :=
inverse_eq_left
(show (p⁻¹ʰ ∘ q⁻¹ʰ) ∘ q ∘ p = id, from
by rewrite [-assoc, inverse_comp_cancel_left, left_inverse])
theorem inverse_comp_inverse_left [H' : is_iso g] : (q⁻¹ ∘ g)⁻¹ = g⁻¹ ∘ q :=
inverse_involutive q ▸ comp_inverse q⁻¹ g
theorem inverse_comp_inverse_right [H' : is_iso f] : (q ∘ f⁻¹)⁻¹ = f ∘ q⁻¹ :=
inverse_involutive f ▸ comp_inverse q f⁻¹
theorem inverse_comp_inverse_inverse [H' : is_iso r] : (q⁻¹ ∘ r⁻¹)⁻¹ = r ∘ q :=
inverse_involutive r ▸ inverse_comp_inverse_left q r⁻¹
end
section
variables {ob : Type} {C : precategory ob} include C
variables {d c b a : ob}
{r' : c ⟶ d} {i : b ⟶ c} {f : b ⟶ a}
{r : c ⟶ d} {q : b ⟶ c} {p : a ⟶ b}
{g : d ⟶ c} {h : c ⟶ b} {p' : a ⟶ b}
{x : b ⟶ d} {z : a ⟶ c}
{y : d ⟶ b} {w : c ⟶ a}
variable [Hq : is_iso q] include Hq
theorem comp_eq_of_eq_inverse_comp (H : y = q⁻¹ ∘ g) : q ∘ y = g :=
H⁻¹ ▸ comp_inverse_cancel_left q g
theorem comp_eq_of_eq_comp_inverse (H : w = f ∘ q⁻¹) : w ∘ q = f :=
H⁻¹ ▸ inverse_comp_cancel_right f q
theorem eq_comp_of_inverse_comp_eq (H : q⁻¹ ∘ g = y) : g = q ∘ y :=
(comp_eq_of_eq_inverse_comp H⁻¹)⁻¹
theorem eq_comp_of_comp_inverse_eq (H : f ∘ q⁻¹ = w) : f = w ∘ q :=
(comp_eq_of_eq_comp_inverse H⁻¹)⁻¹
variable {Hq}
theorem inverse_comp_eq_of_eq_comp (H : z = q ∘ p) : q⁻¹ ∘ z = p :=
H⁻¹ ▸ inverse_comp_cancel_left q p
theorem comp_inverse_eq_of_eq_comp (H : x = r ∘ q) : x ∘ q⁻¹ = r :=
H⁻¹ ▸ comp_inverse_cancel_right r q
theorem eq_inverse_comp_of_comp_eq (H : q ∘ p = z) : p = q⁻¹ ∘ z :=
(inverse_comp_eq_of_eq_comp H⁻¹)⁻¹
theorem eq_comp_inverse_of_comp_eq (H : r ∘ q = x) : r = x ∘ q⁻¹ :=
(comp_inverse_eq_of_eq_comp H⁻¹)⁻¹
theorem eq_inverse_of_comp_eq_id' (H : h ∘ q = id) : h = q⁻¹ := (inverse_eq_left H)⁻¹
theorem eq_inverse_of_comp_eq_id (H : q ∘ h = id) : h = q⁻¹ := (inverse_eq_right H)⁻¹
theorem inverse_eq_of_id_eq_comp (H : id = h ∘ q) : q⁻¹ = h :=
(eq_inverse_of_comp_eq_id' H⁻¹)⁻¹
theorem inverse_eq_of_id_eq_comp' (H : id = q ∘ h) : q⁻¹ = h :=
(eq_inverse_of_comp_eq_id H⁻¹)⁻¹
variable [Hq]
theorem eq_of_comp_inverse_eq_id (H : i ∘ q⁻¹ = id) : i = q :=
eq_inverse_of_comp_eq_id' H ⬝ inverse_involutive q
theorem eq_of_inverse_comp_eq_id (H : q⁻¹ ∘ i = id) : i = q :=
eq_inverse_of_comp_eq_id H ⬝ inverse_involutive q
theorem eq_of_id_eq_comp_inverse (H : id = i ∘ q⁻¹) : q = i := (eq_of_comp_inverse_eq_id H⁻¹)⁻¹
theorem eq_of_id_eq_inverse_comp (H : id = q⁻¹ ∘ i) : q = i := (eq_of_inverse_comp_eq_id H⁻¹)⁻¹
variables (q)
theorem comp.cancel_left (H : q ∘ p = q ∘ p') : p = p' :=
by rewrite [-inverse_comp_cancel_left q p, H, inverse_comp_cancel_left q]
theorem comp.cancel_right (H : r ∘ q = r' ∘ q) : r = r' :=
by rewrite [-comp_inverse_cancel_right r q, H, comp_inverse_cancel_right _ q]
end
end iso
namespace iso
/- precomposition and postcomposition by an iso is an equivalence -/
definition is_equiv_postcompose [constructor] {ob : Type} [precategory ob] {a b c : ob}
(g : b ⟶ c) [is_iso g] : is_equiv (λ(f : a ⟶ b), g ∘ f) :=
begin
fapply adjointify,
{ exact λf', g⁻¹ ∘ f'},
{ intro f', apply comp_inverse_cancel_left},
{ intro f, apply inverse_comp_cancel_left}
end
definition equiv_postcompose [constructor] {ob : Type} [precategory ob] {a b c : ob}
(g : b ⟶ c) [is_iso g] : (a ⟶ b) ≃ (a ⟶ c) :=
equiv.mk (λ(f : a ⟶ b), g ∘ f) (is_equiv_postcompose g)
definition is_equiv_precompose [constructor] {ob : Type} [precategory ob] {a b c : ob}
(f : a ⟶ b) [is_iso f] : is_equiv (λ(g : b ⟶ c), g ∘ f) :=
begin
fapply adjointify,
{ exact λg', g' ∘ f⁻¹},
{ intro g', apply comp_inverse_cancel_right},
{ intro g, apply inverse_comp_cancel_right}
end
definition equiv_precompose [constructor] {ob : Type} [precategory ob] {a b c : ob}
(f : a ⟶ b) [is_iso f] : (b ⟶ c) ≃ (a ⟶ c) :=
equiv.mk (λ(g : b ⟶ c), g ∘ f) (is_equiv_precompose f)
end iso
|
01d0a9ee88eebffe1e2907f21874fcc96e0b1d75
|
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
|
/tests/lean/run/hmul2.lean
|
2dfceddb128c02e97e630ce84a3f76fa77fbc1a4
|
[
"Apache-2.0"
] |
permissive
|
williamdemeo/lean4
|
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
|
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
|
refs/heads/master
| 1,678,305,356,877
| 1,614,708,995,000
| 1,614,708,995,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 652
|
lean
|
instance [Mul α] : HMul α (Array α) (Array α) where
hMul a as := as.map (a * .)
#check fun x => x * 2
#check fun y : Int => let x := 1; x * y
#check fun y : Int => let* x := 1; x * y
def f1 (n : Nat) (i : Int) :=
i * n
def f2 (n : Nat) (i : Int) :=
n * i
def f3 (n : Nat) (i : Int) :=
n * (n * (n * (n * i)))
def f4 (n : Nat) (i : Int) :=
n + (n + (n * (n * i)))
def f5 (n : Nat) (i : Int) :=
n + (n + (n * (i, i).1))
#eval (2:Nat) * #[3, 4, 5]
def f6 (n : Nat) (i : Int) :=
let y := 2 * i
let x := y * n
n + x
def f7 (n : Nat) (i : Int) :=
n + (n * 2 * i)
def f8 (n : Nat) (i : Int) :=
n * 2 + (i * 1 * n * 2 * i)
|
c4b55d83e34a389b6d041493b52d9c256632ba5e
|
af6139dd14451ab8f69cf181cf3a20f22bd699be
|
/library/init/native/default.lean
|
0a5e8fe4c4d0720acd92454e961b5dc2a53a7c7c
|
[
"Apache-2.0"
] |
permissive
|
gitter-badger/lean-1
|
1cca01252d3113faa45681b6a00e1b5e3a0f6203
|
5c7ade4ee4f1cdf5028eabc5db949479d6737c85
|
refs/heads/master
| 1,611,425,383,521
| 1,487,871,140,000
| 1,487,871,140,000
| 82,995,612
| 0
| 0
| null | 1,487,905,618,000
| 1,487,905,618,000
| null |
UTF-8
|
Lean
| false
| false
| 23,794
|
lean
|
/-
Copyright (c) 2016 Jared Roesch. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jared Roesch
-/
prelude
import init.meta.format
import init.meta.expr
import init.category.state
import init.data.string
import init.data.list.instances
import init.native.ir
import init.native.format
import init.native.internal
import init.native.anf
import init.native.cf
import init.native.pass
import init.native.util
import init.native.config
import init.native.result
namespace native
inductive error : Type
| string : string → error
| many : list error → error
meta def error.to_string : error → string
| (error.string s) := s
| (error.many es) := to_string $ list.map error.to_string es
meta def arity_map : Type :=
rb_map name nat
meta def get_arity : expr → nat
| (expr.lam _ _ _ body) := 1 + get_arity body
| _ := 0
@[reducible] def ir_result (A : Type*) :=
native.result error A
meta def mk_arity_map : list (name × expr) → arity_map
| [] := rb_map.mk name nat
| ((n, body) :: rest) := rb_map.insert (mk_arity_map rest) n (get_arity body)
@[reducible] meta def ir_compiler_state :=
(config × arity_map × nat)
@[reducible] meta def ir_compiler (A : Type) :=
native.resultT (state ir_compiler_state) error A
meta def lift {A} (action : state ir_compiler_state A) : ir_compiler A :=
⟨fmap (fun (a : A), native.result.ok a) action⟩
meta def trace_ir (s : string) : ir_compiler unit := do
(conf, map, counter) ← lift $ state.read,
if config.debug conf
then trace s (return ())
else return ()
-- An `exotic` monad combinator that accumulates errors.
meta def run {M E A} (res : native.resultT M E A) : M (native.result E A) :=
match res with
| ⟨action⟩ := action
end
meta def sequence_err : list (ir_compiler format) → ir_compiler (list format × list error)
| [] := return ([], [])
| (action :: remaining) :=
⟨ fun s,
match (run (sequence_err remaining)) s with
| (native.result.err e, s') := (native.result.err e, s)
| (native.result.ok (res, errs), s') :=
match (run action) s' with
| (native.result.err e, s'') := (native.result.ok (res, e :: errs), s'')
| (native.result.ok v, s'') := (native.result.ok (v :: res, errs), s'')
end
end
⟩
-- meta lemma sequence_err_always_ok :
-- forall xs v s s', sequence_err xs s = native.result.ok (v, s') := sorry
meta def lift_result {A} (action : ir_result A) : ir_compiler A :=
⟨fun s, (action, s)⟩
-- TODO: fix naming here
private meta def take_arguments' : expr → list name → (list name × expr)
| (expr.lam n _ _ body) ns := take_arguments' body (n :: ns)
| e' ns := (ns, e')
meta def fresh_name : ir_compiler name := do
(conf, map, counter) ← lift state.read,
let fresh := name.mk_numeral (unsigned.of_nat counter) `native._ir_compiler_
in do
lift $ state.write (conf, map, counter + 1),
return fresh
meta def take_arguments (e : expr) : ir_compiler (list name × expr) :=
let (arg_names, body) := take_arguments' e [] in do
fresh_names ← monad.mapm (fun x, fresh_name) arg_names,
let locals := list.map mk_local fresh_names in
return $ (fresh_names, expr.instantiate_vars body (list.reverse locals))
-- meta def lift_state {A} (action : state arity_map A) : ir_compiler A :=
-- fun (s : arity_map), match action s with
-- | (a, s) := (return a, s)
-- end
meta def mk_error {T} : string → ir_compiler T :=
fun s, do
trace_ir "CREATEDERROR",
lift_result (native.result.err $ error.string s)
meta def lookup_arity (n : name) : ir_compiler nat := do
(_, map, counter) ← lift state.read,
if n = `nat.cases_on
then pure 2
else
match rb_map.find map n with
| option.none := mk_error $ "could not find arity for: " ++ to_string n
| option.some n := return n
end
meta def mk_nat_literal (n : nat) : ir_compiler ir.expr :=
return (ir.expr.lit $ ir.literal.nat n)
def repeat {A : Type} : nat → A → list A
| 0 _ := []
| (n + 1) a := a :: repeat n a
def zip {A B : Type} : list A → list B → list (A × B)
| [] [] := []
| [] (y :: ys) := []
| (x :: xs) [] := []
| (x :: xs) (y :: ys) := (x, y) :: zip xs ys
private def upto' : ℕ → list ℕ
| 0 := []
| (n + 1) := n :: upto' n
def upto (n : ℕ) : list ℕ :=
list.reverse $ upto' n
def label {A : Type} (xs : list A) : list (nat × A) :=
zip (upto (list.length xs)) xs
-- lemma label_size_eq :
-- forall A (xs : list A),
-- list.length (label xs) = list.length xs :=
-- begin
-- intros,
-- induction xs,
-- apply sorry
-- apply sorry
-- end
-- HELPERS --
meta def assert_name : ir.expr → ir_compiler name
| (ir.expr.locl n) := lift_result $ native.result.ok n
| e := mk_error $ "expected name found: " ++ to_string (format_cpp.expr e)
meta def assert_expr : ir.stmt → ir_compiler ir.expr
| (ir.stmt.e exp) := return exp
| s := mk_error ("internal invariant violated, found: " ++ (to_string (format_cpp.stmt s)))
meta def mk_call (head : name) (args : list ir.expr) : ir_compiler ir.expr :=
let args'' := list.map assert_name args
in do
args' ← monad.sequence args'',
return (ir.expr.call head args')
meta def mk_under_sat_call (head : name) (args : list ir.expr) : ir_compiler ir.expr :=
let args'' := list.map assert_name args in do
args' ← monad.sequence args'',
return $ ir.expr.mk_native_closure head args'
meta def bind_value_with_ty (val : ir.expr) (ty : ir.ty) (body : name → ir_compiler ir.stmt) : ir_compiler ir.stmt := do
fresh ← fresh_name,
ir.stmt.letb fresh ty val <$> (body fresh)
meta def bind_value (val : ir.expr) (body : name → ir_compiler ir.stmt) : ir_compiler ir.stmt :=
bind_value_with_ty val ir.ty.object body
-- not in love with this --solution-- hack, revisit
meta def compile_local (n : name) : ir_compiler name :=
return $ (mk_str_name "_$local$_" (name.to_string_with_sep "_" n))
meta def mk_invoke (loc : name) (args : list ir.expr) : ir_compiler ir.expr :=
let args'' := list.map assert_name args
in do
args' ← monad.sequence args'',
loc' ← compile_local loc,
lift_result (native.result.ok $ ir.expr.invoke loc' args')
meta def mk_over_sat_call (head : name) (fst snd : list ir.expr) : ir_compiler ir.expr :=
let fst' := list.map assert_name fst,
snd' := list.map assert_name snd in do
args' ← monad.sequence fst',
args'' ← monad.sequence snd',
fresh ← fresh_name,
locl ← compile_local fresh,
invoke ← ir.stmt.e <$> (mk_invoke fresh (fmap ir.expr.locl args'')),
return $ ir.expr.block (ir.stmt.seq [
ir.stmt.letb locl ir.ty.object (ir.expr.call head args') ir.stmt.nop,
invoke
])
meta def is_return (n : name) : bool :=
`native_compiler.return = n
meta def compile_call (head : name) (arity : nat) (args : list ir.expr) : ir_compiler ir.expr := do
trace_ir $ "compile_call: " ++ (to_string head),
if list.length args = arity
then mk_call head args
else if list.length args < arity
then mk_under_sat_call head args
else mk_over_sat_call head (list.taken arity args) (list.dropn arity args)
meta def mk_object (arity : unsigned) (args : list ir.expr) : ir_compiler ir.expr :=
let args'' := list.map assert_name args
in do args' ← monad.sequence args'',
lift_result (native.result.ok $ ir.expr.mk_object (unsigned.to_nat arity) args')
meta def one_or_error (args : list expr) : ir_compiler expr :=
match args with
| ((h : expr) :: []) := lift_result $ native.result.ok h
| _ := mk_error "internal invariant violated, should only have one argument"
end
meta def panic (msg : string) : ir_compiler ir.expr :=
return $ ir.expr.panic msg
-- END HELPERS --
meta def bind_case_fields' (scrut : name) : list (nat × name) → ir.stmt → ir_compiler ir.stmt
| [] body := return body
| ((n, f) :: fs) body := do
loc ← compile_local f,
ir.stmt.letb f ir.ty.object (ir.expr.project scrut n) <$> (bind_case_fields' fs body)
meta def bind_case_fields (scrut : name) (fs : list name) (body : ir.stmt) : ir_compiler ir.stmt :=
bind_case_fields' scrut (label fs) body
meta def mk_cases_on (case_name scrut : name) (cases : list (nat × ir.stmt)) (default : ir.stmt) : ir.stmt :=
ir.stmt.seq [
ir.stmt.letb `ctor_index ir.ty.int (ir.expr.call `cidx [scrut]) ir.stmt.nop,
ir.stmt.switch `ctor_index cases default
]
meta def compile_cases (action : expr → ir_compiler ir.stmt) (scrut : name)
: list (nat × expr) → ir_compiler (list (nat × ir.stmt))
| [] := return []
| ((n, body) :: cs) := do
(fs, body') ← take_arguments body,
body'' ← action body',
cs' ← compile_cases cs,
case ← bind_case_fields scrut fs body'',
return $ (n, case) :: cs'
meta def compile_cases_on_to_ir_expr
(case_name : name)
(cases : list expr)
(action : expr → ir_compiler ir.stmt) : ir_compiler ir.expr := do
default ← panic "default case should never be reached",
match cases with
| [] := mk_error $ "found " ++ to_string case_name ++ "applied to zero arguments"
| (h :: cs) := do
ir_scrut ← action h >>= assert_expr,
ir.expr.block <$> bind_value ir_scrut (fun scrut, do
cs' ← compile_cases action scrut (label cs),
return (mk_cases_on case_name scrut cs' (ir.stmt.e default)))
end
meta def bind_builtin_case_fields' (scrut : name) : list (nat × name) → ir.stmt → ir_compiler ir.stmt
| [] body := return body
| ((n, f) :: fs) body := do
loc ← compile_local f,
ir.stmt.letb loc ir.ty.object (ir.expr.project scrut n) <$> (bind_builtin_case_fields' fs body)
meta def bind_builtin_case_fields (scrut : name) (fs : list name) (body : ir.stmt) : ir_compiler ir.stmt :=
bind_builtin_case_fields' scrut (label fs) body
meta def compile_builtin_cases (action : expr → ir_compiler ir.stmt) (scrut : name)
: list (nat × expr) → ir_compiler (list (nat × ir.stmt))
| [] := return []
| ((n, body) :: cs) := do
(fs, body') ← take_arguments body,
body'' ← action body',
cs' ← compile_builtin_cases cs,
case ← bind_builtin_case_fields scrut fs body'',
return $ (n, case) :: cs'
meta def in_lean_ns (n : name) : name :=
mk_simple_name ("lean::" ++ name.to_string_with_sep "_" n)
meta def mk_builtin_cases_on (case_name scrut : name) (cases : list (nat × ir.stmt)) (default : ir.stmt) : ir.stmt :=
-- replace `ctor_index with a generated name
ir.stmt.seq [
ir.stmt.letb `buffer ir.ty.object_buffer ir.expr.uninitialized ir.stmt.nop,
ir.stmt.letb `ctor_index ir.ty.int (ir.expr.call (in_lean_ns case_name) [scrut, `buffer]) ir.stmt.nop,
ir.stmt.switch `ctor_index cases default
]
meta def compile_builtin_cases_on_to_ir_expr
(case_name : name)
(cases : list expr)
(action : expr → ir_compiler ir.stmt) : ir_compiler ir.expr := do
default ← panic "default case should never be reached",
match cases with
| [] := mk_error $ "found " ++ to_string case_name ++ "applied to zero arguments"
| (h :: cs) := do
ir_scrut ← action h >>= assert_expr,
ir.expr.block <$> bind_value ir_scrut (fun scrut, do
cs' ← compile_builtin_cases action scrut (label cs),
return (mk_builtin_cases_on case_name scrut cs' (ir.stmt.e default)))
end
meta def mk_is_simple (scrut : name) : ir.expr :=
ir.expr.call `is_simple [scrut]
meta def mk_is_zero (n : name) : ir.expr :=
ir.expr.equals (ir.expr.raw_int 0) (ir.expr.locl n)
meta def mk_cidx (obj : name) : ir.expr :=
ir.expr.call `cidx [obj]
-- we should add applicative brackets
meta def mk_simple_nat_cases_on (scrut : name) (zero_case succ_case : ir.stmt) : ir_compiler ir.stmt :=
bind_value_with_ty (mk_cidx scrut) (ir.ty.name `int) (fun cidx,
bind_value_with_ty (mk_is_zero cidx) (ir.ty.name `bool) (fun is_zero,
pure $ ir.stmt.ite is_zero zero_case succ_case))
meta def mk_mpz_nat_cases_on (scrut : name) (zero_case succ_case : ir.stmt) : ir_compiler ir.stmt :=
ir.stmt.e <$> panic "mpz"
meta def mk_nat_cases_on (scrut : name) (zero_case succ_case : ir.stmt) : ir_compiler ir.stmt :=
bind_value_with_ty (mk_is_simple scrut) (ir.ty.name `bool) (fun is_simple,
ir.stmt.ite is_simple <$>
mk_simple_nat_cases_on scrut zero_case succ_case <*>
mk_mpz_nat_cases_on scrut zero_case succ_case)
meta def assert_two_cases (cases : list expr) : ir_compiler (expr × expr) :=
match cases with
| c1 :: c2 :: _ := return (c1, c2)
| _ := mk_error "nat.cases_on should have exactly two cases"
end
meta def mk_vm_nat (n : name) : ir.expr :=
ir.expr.call (in_lean_ns `mk_vm_simple) [n]
meta def compile_succ_case (action : expr → ir_compiler ir.stmt) (scrut : name) (succ_case : expr) : ir_compiler ir.stmt := do
(fs, body') ← take_arguments succ_case,
body'' ← action body',
match fs with
| pred :: _ := do
loc ← compile_local pred,
fresh ← fresh_name,
bind_value_with_ty (mk_cidx scrut) (ir.ty.name `int) (fun cidx,
bind_value_with_ty (ir.expr.sub (ir.expr.locl cidx) (ir.expr.raw_int 1)) (ir.ty.name `int) (fun sub,
pure $ ir.stmt.letb loc ir.ty.object (mk_vm_nat sub) body''
))
| _ := mk_error "compile_succ_case too many fields"
end
meta def compile_nat_cases_on_to_ir_expr
(case_name : name)
(cases : list expr)
(action : expr → ir_compiler ir.stmt) : ir_compiler ir.expr :=
match cases with
| [] := mk_error $ "found " ++ to_string case_name ++ "applied to zero arguments"
| (h :: cs) := do
ir_scrut ← action h >>= assert_expr,
(zero_case, succ_case) ← assert_two_cases cs,
trace_ir (to_string zero_case),
trace_ir (to_string succ_case),
ir.expr.block <$> bind_value ir_scrut (fun scrut, do
zc ← action zero_case,
sc ← compile_succ_case action scrut succ_case,
mk_nat_cases_on scrut zc sc
)
end
-- this→emit_indented("if (is_simple(");
-- action(scrutinee);
-- this→emit_string("))");
-- this→emit_block([&] () {
-- this→emit_indented("if (cidx(");
-- action(scrutinee);
-- this→emit_string(") == 0) ");
-- this→emit_block([&] () {
-- action(zero_case);
-- *this→m_output_stream << ";\n";
-- });
-- this→emit_string("else ");
-- this→emit_block([&] () {
-- action(succ_case);
-- *this→m_output_stream << ";\n";
-- });
-- });
-- this→emit_string("else ");
-- this→emit_block([&] () {
-- this→emit_indented("if (to_mpz(");
-- action(scrutinee);
-- this→emit_string(") == 0) ");
-- this→emit_block([&] () {
-- action(zero_case);
-- *this→m_output_stream << ";\n";
-- });
-- this→emit_string("else ");
-- this→emit_block([&] () {
-- action(succ_case);
-- });
-- });
-- this code isnt' great working around the semi-functional frontend
meta def compile_expr_app_to_ir_expr
(head : expr)
(args : list expr)
(action : expr → ir_compiler ir.stmt) : ir_compiler ir.expr := do
trace_ir (to_string head ++ to_string args),
if expr.is_constant head = bool.tt
then (if is_return (expr.const_name head)
then do
rexp ← one_or_error args,
(ir.expr.block ∘ ir.stmt.return) <$> ((action rexp) >>= assert_expr)
else if is_nat_cases_on (expr.const_name head)
then compile_nat_cases_on_to_ir_expr (expr.const_name head) args action
else match is_internal_cnstr head with
| option.some n := do
args' ← monad.sequence $ list.map (fun x, action x >>= assert_expr) args,
mk_object n args'
| option.none := match is_internal_cases head with
| option.some n := compile_cases_on_to_ir_expr (expr.const_name head) args action
| option.none := match get_builtin (expr.const_name head) with
| option.some builtin :=
match builtin with
| builtin.vm n := mk_error "vm"
| builtin.cfun n arity := do
args' ← monad.sequence $ list.map (fun x, action x >>= assert_expr) args,
compile_call n arity args'
| builtin.cases n arity :=
compile_builtin_cases_on_to_ir_expr (expr.const_name head) args action
end
| option.none := do
args' ← monad.sequence $ list.map (fun x, action x >>= assert_expr) args,
arity ← lookup_arity (expr.const_name head),
compile_call (expr.const_name head) arity args'
end
end end)
else if expr.is_local_constant head
then do
args' ← monad.sequence $ list.map (fun x, action x >>= assert_expr) args,
mk_invoke (expr.local_uniq_name head) args'
else (mk_error ("unsupported call position" ++ (to_string head)))
meta def compile_expr_macro_to_ir_expr (e : expr) : ir_compiler ir.expr :=
match native.get_nat_value e with
| option.none := mk_error "unsupported macro"
| option.some n := mk_nat_literal n
end
meta def compile_expr_to_ir_expr (action : expr → ir_compiler ir.stmt): expr → ir_compiler ir.expr
| (expr.const n ls) :=
match native.is_internal_cnstr (expr.const n ls) with
| option.none :=
-- TODO, do I need to case on arity here? I should probably always emit a call
match get_builtin n with
| option.some (builtin.cfun n' arity) :=
compile_call n arity []
| _ :=
if n = "_neutral_"
then (pure $ ir.expr.mk_object 0 [])
else do
arity ← lookup_arity n,
compile_call n arity []
end
| option.some arity := pure $ ir.expr.mk_object (unsigned.to_nat arity) []
end
| (expr.var i) := mk_error "there should be no bound variables in compiled terms"
| (expr.sort _) := mk_error "found sort"
| (expr.mvar _ _) := mk_error "unexpected meta-variable in expr"
| (expr.local_const n _ _ _) := ir.expr.locl <$> compile_local n
| (expr.app f x) :=
let head := expr.get_app_fn (expr.app f x),
args := expr.get_app_args (expr.app f x)
in compile_expr_app_to_ir_expr head args action
| (expr.lam _ _ _ _) := mk_error "found lam"
| (expr.pi _ _ _ _) := mk_error "found pi"
| (expr.elet n _ v body) := mk_error "internal error: can not translate let binding into a ir_expr"
| (expr.macro d sz args) := compile_expr_macro_to_ir_expr (expr.macro d sz args)
meta def compile_expr_to_ir_stmt : expr → ir_compiler ir.stmt
| (expr.pi _ _ _ _) := mk_error "found pi, should not be translating a Pi for any reason (yet ...)"
| (expr.elet n _ v body) := do
n' ← compile_local n,
v' ← compile_expr_to_ir_expr compile_expr_to_ir_stmt v,
-- this is a scoping fail, we need to fix how we compile locals
body' ← compile_expr_to_ir_stmt (expr.instantiate_vars body [mk_local n]),
-- not the best solution, here need to think hard about how to prevent thing, more aggressive anf?
match v' with
| ir.expr.block stmt := return (ir.stmt.seq [ir.stmt.letb n' ir.ty.object ir.expr.uninitialized ir.stmt.nop, body'])
| _ := return (ir.stmt.letb n' ir.ty.object v' body')
end
| e' := ir.stmt.e <$> compile_expr_to_ir_expr compile_expr_to_ir_stmt e'
meta def compile_defn_to_ir (decl_name : name) (args : list name) (body : expr) : ir_compiler ir.defn := do
body' ← compile_expr_to_ir_stmt body,
let params := (zip args (repeat (list.length args) (ir.ty.ref ir.ty.object))) in
pure (ir.defn.mk decl_name params ir.ty.object body')
def unwrap_or_else {T R : Type} : ir_result T → (T → R) → (error → R) → R
| (native.result.err e) f err := err e
| (native.result.ok t) f err := f t
meta def replace_main (n : name) : name :=
if n = `main
then "___lean__main"
else n
meta def trace_expr (e : expr) : ir_compiler unit :=
trace ("trace_expr: " ++ to_string e) (return ())
meta def compile_defn (decl_name : name) (e : expr) : ir_compiler format :=
let arity := get_arity e in do
(args, body) ← take_arguments e,
ir ← compile_defn_to_ir (replace_main decl_name) args body,
return $ format_cpp.defn ir
meta def compile' : list (name × expr) → list (ir_compiler format)
| [] := []
| ((n, e) :: rest) := do
let decl := (fun d, d ++ format.line ++ format.line) <$> compile_defn n e
in decl :: (compile' rest)
meta def format_error : error → format
| (error.string s) := to_fmt s
| (error.many es) := format_concat (list.map format_error es)
meta def mk_lean_name (n : name) : ir.expr :=
ir.expr.constructor (in_lean_ns `name) (name.components n)
meta def emit_declare_vm_builtins : list (name × expr) → ir_compiler (list ir.stmt)
| [] := return []
| ((n, body) :: es) := do
vm_name ← pure $ (mk_lean_name n),
tail ← emit_declare_vm_builtins es,
fresh ← fresh_name,
let cpp_name := in_lean_ns `name,
single_binding := ir.stmt.seq [
ir.stmt.letb fresh (ir.ty.name cpp_name) vm_name ir.stmt.nop,
ir.stmt.e $ ir.expr.assign `env (ir.expr.call `add_native [`env, fresh, replace_main n])
] in return $ single_binding :: tail
meta def emit_main (procs : list (name × expr)) : ir_compiler ir.defn := do
builtins ← emit_declare_vm_builtins procs,
arity ← lookup_arity `main,
vm_simple_obj ← fresh_name,
call_main ← compile_call "___lean__main" arity [ir.expr.locl vm_simple_obj],
return (ir.defn.mk `main [] ir.ty.int $ ir.stmt.seq ([
ir.stmt.e $ ir.expr.call (in_lean_ns `initialize) [],
ir.stmt.letb `env (ir.ty.name (in_lean_ns `environment)) ir.expr.uninitialized ir.stmt.nop
] ++ builtins ++ [
ir.stmt.letb `ios (ir.ty.name (in_lean_ns `io_state)) (ir.expr.call (in_lean_ns `get_global_ios) []) ir.stmt.nop,
ir.stmt.letb `opts (ir.ty.name (in_lean_ns `options)) (ir.expr.call (in_lean_ns `get_options_from_ios) [`ios]) ir.stmt.nop,
ir.stmt.letb `S (ir.ty.name (in_lean_ns `vm_state)) (ir.expr.constructor (in_lean_ns `vm_state) [`env, `opts]) ir.stmt.nop,
ir.stmt.letb `scoped (ir.ty.name (in_lean_ns `scope_vm_state)) (ir.expr.constructor (in_lean_ns `scope_vm_state) [`S]) ir.stmt.nop,
ir.stmt.e $ ir.expr.assign `g_env (ir.expr.address_of `env),
ir.stmt.letb vm_simple_obj ir.ty.object (ir.expr.mk_object 0 []) ir.stmt.nop,
ir.stmt.e call_main
]))
-- -- call_mains
-- -- buffer<expr> args;
-- -- auto unit = mk_neutral_expr();
-- -- args.push_back(unit);
-- -- // Make sure to invoke the C call machinery since it is non-deterministic
-- -- // which case we enter here.
-- -- compile_to_c_call(main_fn, args, 0, name_map<unsigned>());
-- -- *this→m_output_stream << ";\n return 0;\n}" << std::endl;
-- ]
meta def unzip {A B} : list (A × B) → (list A × list B)
| [] := ([], [])
| ((x, y) :: rest) :=
let (xs, ys) := unzip rest
in (x :: xs, y :: ys)
meta def configuration : ir_compiler config := do
(conf, _, _) ← lift $ state.read,
pure conf
meta def apply_pre_ir_passes (procs : list procedure) (conf : config) : list procedure :=
run_passes conf [anf, cf] procs
meta def driver (procs : list (name × expr)) : ir_compiler (list format × list error) := do
procs' ← apply_pre_ir_passes procs <$> configuration,
(fmt_decls, errs) ← sequence_err (compile' procs'),
main ← emit_main procs',
return (format_cpp.defn main :: fmt_decls, errs)
meta def compile (conf : config) (procs : list (name × expr)) : format :=
let arities := mk_arity_map procs in
-- Put this in a combinator or something ...
match run (driver procs) (conf, arities, 0) with
| (native.result.err e, s) := error.to_string e
| (native.result.ok (decls, errs), s) :=
if list.length errs = 0
then format_concat decls
else format_error (error.many errs)
end
-- meta def compile (procs : list (name))
end native
|
6a4e1771d23dcbedf920439e3d4af7cbcf3a1544
|
947fa6c38e48771ae886239b4edce6db6e18d0fb
|
/src/analysis/convex/krein_milman.lean
|
e1f8047f531c47d3a9e023486a132e86d5c5b659
|
[
"Apache-2.0"
] |
permissive
|
ramonfmir/mathlib
|
c5dc8b33155473fab97c38bd3aa6723dc289beaa
|
14c52e990c17f5a00c0cc9e09847af16fabbed25
|
refs/heads/master
| 1,661,979,343,526
| 1,660,830,384,000
| 1,660,830,384,000
| 182,072,989
| 0
| 0
| null | 1,555,585,876,000
| 1,555,585,876,000
| null |
UTF-8
|
Lean
| false
| false
| 5,438
|
lean
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import analysis.convex.exposed
import analysis.normed_space.hahn_banach.separation
/-!
# The Krein-Milman theorem
This file proves the Krein-Milman lemma and the Krein-Milman theorem.
## The lemma
The lemma states that a nonempty compact set `s` has an extreme point. The proof goes:
1. Using Zorn's lemma, find a minimal nonempty closed `t` that is an extreme subset of `s`. We will
show that `t` is a singleton, thus corresponding to an extreme point.
2. By contradiction, `t` contains two distinct points `x` and `y`.
3. With the (geometric) Hahn-Banach theorem, find an hyperplane that separates `x` and `y`.
4. Look at the extreme (actually exposed) subset of `t` obtained by going the furthest away from
the separating hyperplane in the direction of `x`. It is nonempty, closed and an extreme subset
of `s`.
5. It is a strict subset of `t` (`y` isn't in it), so `t` isn't minimal. Absurd.
## The theorem
The theorem states that a compact convex set `s` is the closure of the convex hull of its extreme
points. It is an almost immediate strengthening of the lemma. The proof goes:
1. By contradiction, `s \ closure (convex_hull ℝ (extreme_points ℝ s))` is nonempty, say with `x`.
2. With the (geometric) Hahn-Banach theorem, find an hyperplane that separates `x` from
`closure (convex_hull ℝ (extreme_points ℝ s))`.
3. Look at the extreme (actually exposed) subset of
`s \ closure (convex_hull ℝ (extreme_points ℝ s))` obtained by going the furthest away from the
separating hyperplane. It is nonempty by assumption of nonemptiness and compactness, so by the
lemma it has an extreme point.
4. This point is also an extreme point of `s`. Absurd.
## Related theorems
When the space is finite dimensional, the `closure` can be dropped to strengthen the result of the
Krein-Milman theorem. This leads to the Minkowski-Carathéodory theorem (currently not in mathlib).
Birkhoff's theorem is the Minkowski-Carathéodory theorem applied to the set of bistochastic
matrices, permutation matrices being the extreme points.
## References
See chapter 8 of [Barry Simon, *Convexity*][simon2011]
## TODO
* Both theorems are currently stated for normed `ℝ`-spaces due to our version of geometric
Hahn-Banach. They are more generally true in a LCTVS without changes to the proofs.
-/
open set
open_locale classical
variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] {s : set E}
/-- **Krein-Milman lemma**: In a LCTVS (currently only in normed `ℝ`-spaces), any nonempty compact
set has an extreme point. -/
lemma is_compact.has_extreme_point (hscomp : is_compact s) (hsnemp : s.nonempty) :
(s.extreme_points ℝ).nonempty :=
begin
let S : set (set E) := {t | t.nonempty ∧ is_closed t ∧ is_extreme ℝ s t},
suffices h : ∃ t ∈ S, ∀ u ∈ S, u ⊆ t → u = t,
{ obtain ⟨t, ⟨⟨x, hxt⟩, htclos, hst⟩, hBmin⟩ := h,
refine ⟨x, mem_extreme_points_iff_extreme_singleton.2 _⟩,
rwa ←eq_singleton_iff_unique_mem.2 ⟨hxt, λ y hyB, _⟩,
by_contra hyx,
obtain ⟨l, hl⟩ := geometric_hahn_banach_point_point hyx,
obtain ⟨z, hzt, hz⟩ := (compact_of_is_closed_subset hscomp htclos hst.1).exists_forall_ge
⟨x, hxt⟩ l.continuous.continuous_on,
have h : is_exposed ℝ t {z ∈ t | ∀ w ∈ t, l w ≤ l z} := λ h, ⟨l, rfl⟩,
rw ←hBmin {z ∈ t | ∀ w ∈ t, l w ≤ l z} ⟨⟨z, hzt, hz⟩, h.is_closed htclos, hst.trans
h.is_extreme⟩ (t.sep_subset _) at hyB,
exact hl.not_le (hyB.2 x hxt) },
refine zorn_superset _ (λ F hFS hF, _),
obtain rfl | hFnemp := F.eq_empty_or_nonempty,
{ exact ⟨s, ⟨hsnemp, hscomp.is_closed, is_extreme.rfl⟩, λ _, false.elim⟩ },
refine ⟨⋂₀ F, ⟨_, is_closed_sInter $ λ t ht, (hFS ht).2.1, is_extreme_sInter hFnemp $
λ t ht, (hFS ht).2.2⟩, λ t ht, sInter_subset_of_mem ht⟩,
haveI : nonempty ↥F := hFnemp.to_subtype,
rw sInter_eq_Inter,
refine is_compact.nonempty_Inter_of_directed_nonempty_compact_closed _ (λ t u, _)
(λ t, (hFS t.mem).1) (λ t, compact_of_is_closed_subset hscomp (hFS t.mem).2.1 (hFS t.mem).2.2.1)
(λ t, (hFS t.mem).2.1),
obtain htu | hut := hF.total t.mem u.mem,
exacts [⟨t, subset.rfl, htu⟩, ⟨u, hut, subset.rfl⟩],
end
/-- **Krein-Milman theorem**: In a LCTVS (currently only in normed `ℝ`-spaces), any compact convex
set is the closure of the convex hull of its extreme points. -/
lemma closure_convex_hull_extreme_points (hscomp : is_compact s) (hAconv : convex ℝ s) :
closure (convex_hull ℝ $ s.extreme_points ℝ) = s :=
begin
apply (closure_minimal (convex_hull_min extreme_points_subset hAconv) hscomp.is_closed).antisymm,
by_contra hs,
obtain ⟨x, hxA, hxt⟩ := not_subset.1 hs,
obtain ⟨l, r, hlr, hrx⟩ := geometric_hahn_banach_closed_point (convex_convex_hull _ _).closure
is_closed_closure hxt,
have h : is_exposed ℝ s {y ∈ s | ∀ z ∈ s, l z ≤ l y} := λ _, ⟨l, rfl⟩,
obtain ⟨z, hzA, hz⟩ := hscomp.exists_forall_ge ⟨x, hxA⟩ l.continuous.continuous_on,
obtain ⟨y, hy⟩ := (h.is_compact hscomp).has_extreme_point ⟨z, hzA, hz⟩,
linarith [hlr _ (subset_closure $ subset_convex_hull _ _ $
h.is_extreme.extreme_points_subset_extreme_points hy), hy.1.2 x hxA],
end
|
f7c47cae1685e2aa48611229e0cb50200bd8e4c3
|
d9d511f37a523cd7659d6f573f990e2a0af93c6f
|
/src/analysis/calculus/parametric_integral.lean
|
1e03a079d2c31afe08250ace973404643b4d1a9f
|
[
"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
| 14,570
|
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 measure_theory.integral.set_integral
import analysis.calculus.mean_value
/-!
# Derivatives of integrals depending on parameters
A parametric integral is a function with shape `f = λ x : H, ∫ a : α, F x a ∂μ` for some
`F : H → α → E`, where `H` and `E` are normed spaces and `α` is a measured space with measure `μ`.
We already know from `continuous_of_dominated` in `measure_theory.bochner_integral` how to
guarantee that `f` is continuous using the dominated convergence theorem. In this file,
we want to express the derivative of `f` as the integral of the derivative of `F` with respect
to `x`.
## Main results
As explained above, all results express the derivative of a parametric integral as the integral of
a derivative. The variations come from the assumptions and from the different ways of expressing
derivative, especially Fréchet derivatives vs elementary derivative of function of one real
variable.
* `has_fderiv_at_of_dominated_loc_of_lip`: this version assumes
`F x` is ae-measurable for x near `x₀`, `F x₀` is integrable,
`λ x, F x a` has derivative `F' a : H →L[ℝ] E` at `x₀` which is ae-measurable,
`λ x, F x a` is locally Lipschitz near `x₀` for almost every `a`, with a Lipschitz bound which
is integrable with respect to `a`. A subtle point is that the "near x₀" in the last condition
has to be uniform in `a`. This is controlled by a positive number `ε`.
* `has_fderiv_at_of_dominated_of_fderiv_le`: this version assume `λ x, F x a` has derivative
`F' x a` for `x` near `x₀` and `F' x` is bounded by an integrable function independent from
`x` near `x₀`.
`has_deriv_at_of_dominated_loc_of_lip` and `has_deriv_at_of_dominated_loc_of_deriv_le ` are versions
of the above two results that assume `H = ℝ` and use the high-school derivative `deriv` instead of
Fréchet derivative `fderiv`.
-/
noncomputable theory
open topological_space measure_theory filter metric
open_locale topological_space filter
variables {α : Type*} [measurable_space α] {μ : measure α}
{E : Type*} [normed_group E] [normed_space ℝ E]
[complete_space E] [second_countable_topology E]
[measurable_space E] [borel_space E]
{H : Type*} [normed_group H] [normed_space ℝ H]
[second_countable_topology $ H →L[ℝ] E]
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming
`F x₀` is integrable, `x ↦ F x a` is locally Lipschitz on a ball around `x₀` for ae `a` with
integrable Lipschitz bound (with a ball radius independent of `a`), and `F x` is
ae-measurable for `x` in the same ball. See `has_fderiv_at_of_dominated_loc_of_lip` for a
slightly more general version. -/
lemma has_fderiv_at_of_dominated_loc_of_lip' {F : H → α → E} {F' : α → (H →L[ℝ] E)} {x₀ : H}
{bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ x ∈ ball x₀ ε, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ)
(h_lipsch : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ ε))
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' a) x₀) :
integrable F' μ ∧ has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have nneg : ∀ x, 0 ≤ ∥x - x₀∥⁻¹ := λ x, inv_nonneg.mpr (norm_nonneg _) ,
set b : α → ℝ := λ a, abs (bound a),
have b_int : integrable b μ := bound_integrable.norm,
have b_nonneg : ∀ a, 0 ≤ b a := λ a, abs_nonneg _,
have hF_int' : ∀ x ∈ ball x₀ ε, integrable (F x) μ,
{ intros x x_in,
have : ∀ᵐ a ∂μ, ∥F x₀ a - F x a∥ ≤ ε * ∥(bound a : ℝ)∥,
{ apply h_lipsch.mono,
intros a ha,
rw lipschitz_on_with_iff_norm_sub_le at ha,
apply (ha x₀ x₀_in x x_in).trans,
rw [mul_comm, real.coe_nnabs, real.norm_eq_abs],
rw [mem_ball, dist_eq_norm, norm_sub_rev] at x_in,
exact mul_le_mul_of_nonneg_right (le_of_lt x_in) (abs_nonneg _) },
exact integrable_of_norm_sub_le (hF_meas x x_in) hF_int
(integrable.const_mul bound_integrable.norm ε) this },
have hF'_int : integrable F' μ,
{ have : ∀ᵐ a ∂μ, ∥F' a∥ ≤ b a,
{ apply (h_diff.and h_lipsch).mono,
rintros a ⟨ha_diff, ha_lip⟩,
exact ha_diff.le_of_lip (ball_mem_nhds _ ε_pos) ha_lip },
exact b_int.mono' hF'_meas this },
refine ⟨hF'_int, _⟩,
have h_ball: ball x₀ ε ∈ 𝓝 x₀ := ball_mem_nhds x₀ ε_pos,
have : ∀ᶠ x in 𝓝 x₀,
∥x - x₀∥⁻¹ * ∥∫ a, F x a ∂μ - ∫ a, F x₀ a ∂μ - (∫ a, F' a ∂μ) (x - x₀)∥ =
∥∫ a, ∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀)) ∂μ∥,
{ apply mem_of_superset (ball_mem_nhds _ ε_pos),
intros x x_in,
rw [set.mem_set_of_eq, ← norm_smul_of_nonneg (nneg _), integral_smul,
integral_sub, integral_sub, ← continuous_linear_map.integral_apply hF'_int],
exacts [hF_int' x x_in, hF_int, (hF_int' x x_in).sub hF_int,
hF'_int.apply_continuous_linear_map _] },
rw [has_fderiv_at_iff_tendsto, tendsto_congr' this, ← tendsto_zero_iff_norm_tendsto_zero,
← show ∫ (a : α), ∥x₀ - x₀∥⁻¹ • (F x₀ a - F x₀ a - (F' a) (x₀ - x₀)) ∂μ = 0, by simp],
apply tendsto_integral_filter_of_dominated_convergence,
{ apply is_countably_generated_nhds },
{ filter_upwards [h_ball],
intros x x_in,
apply ae_measurable.const_smul,
exact ((hF_meas _ x_in).sub (hF_meas _ x₀_in)).sub (hF'_meas.apply_continuous_linear_map _) },
{ simp [measurable_const] },
{ apply mem_of_superset h_ball,
intros x hx,
apply (h_diff.and h_lipsch).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
show ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥ ≤ b a + ∥F' a∥,
replace ha_bound : ∥F x a - F x₀ a∥ ≤ b a * ∥x - x₀∥,
{ rw lipschitz_on_with_iff_norm_sub_le at ha_bound,
exact ha_bound _ hx _ x₀_in },
calc ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥
= ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a) - ∥x - x₀∥⁻¹ • F' a (x - x₀)∥ : by rw smul_sub
... ≤ ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a)∥ + ∥∥x - x₀∥⁻¹ • F' a (x - x₀)∥ : norm_sub_le _ _
... = ∥x - x₀∥⁻¹ * ∥F x a - F x₀ a∥ + ∥x - x₀∥⁻¹ * ∥F' a (x - x₀)∥ :
by { rw [norm_smul_of_nonneg, norm_smul_of_nonneg] ; exact nneg _}
... ≤ ∥x - x₀∥⁻¹ * (b a * ∥x - x₀∥) + ∥x - x₀∥⁻¹ * (∥F' a∥ * ∥x - x₀∥) : add_le_add _ _
... ≤ b a + ∥F' a∥ : _,
exact mul_le_mul_of_nonneg_left ha_bound (nneg _),
apply mul_le_mul_of_nonneg_left ((F' a).le_op_norm _) (nneg _),
by_cases h : ∥x - x₀∥ = 0,
{ simpa [h] using add_nonneg (b_nonneg a) (norm_nonneg (F' a)) },
{ field_simp [h] } },
{ exact b_int.add hF'_int.norm },
{ apply h_diff.mono,
intros a ha,
suffices : tendsto (λ x, ∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))) (𝓝 x₀) (𝓝 0),
by simpa,
rw tendsto_zero_iff_norm_tendsto_zero,
have : (λ x, ∥x - x₀∥⁻¹ * ∥F x a - F x₀ a - F' a (x - x₀)∥) =
λ x, ∥∥x - x₀∥⁻¹ • (F x a - F x₀ a - F' a (x - x₀))∥,
{ ext x,
rw norm_smul_of_nonneg (nneg _) },
rwa [has_fderiv_at_iff_tendsto, this] at ha },
end
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming
`F x₀` is integrable, `x ↦ F x a` is locally Lipschitz on a ball around `x₀` for ae `a`
(with a ball radius independent of `a`) with integrable Lipschitz bound, and `F x` is ae-measurable
for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_fderiv_at_of_dominated_loc_of_lip {F : H → α → E} {F' : α → (H →L[ℝ] E)} {x₀ : H}
{bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ)
(h_lip : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ ε))
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' a) x₀) :
integrable F' μ ∧ has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
obtain ⟨ε', ε'_pos, h'⟩ : ∃ ε' > 0, ∀ x ∈ ball x₀ ε', ae_measurable (F x) μ,
by simpa using nhds_basis_ball.eventually_iff.mp hF_meas,
set δ := min ε ε',
have δ_pos : 0 < δ := lt_min ε_pos ε'_pos,
replace h' : ∀ x, x ∈ ball x₀ δ → ae_measurable (F x) μ,
{ intros x x_in,
exact h' _ (ball_subset_ball (min_le_right ε ε') x_in) },
replace h_lip : ∀ᵐ (a : α) ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ δ),
{ apply h_lip.mono,
intros a lip,
exact lip.mono (ball_subset_ball $ min_le_left ε ε') },
apply has_fderiv_at_of_dominated_loc_of_lip' δ_pos ; assumption
end
/-- Differentiation under integral of `x ↦ ∫ F x a` at a given point `x₀`, assuming
`F x₀` is integrable, `x ↦ F x a` is differentiable on a ball around `x₀` for ae `a` with
derivative norm uniformly bounded by an integrable function (the ball radius is independent of `a`),
and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_fderiv_at_of_dominated_of_fderiv_le {F : H → α → E} {F' : H → α → (H →L[ℝ] E)} {x₀ : H}
{bound : α → ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable (F' x₀) μ)
(h_bound : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F' x a∥ ≤ bound a)
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, has_fderiv_at (λ x, F x a) (F' x a) x) :
has_fderiv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' x₀ a ∂μ) x₀ :=
begin
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have diff_x₀ : ∀ᵐ a ∂μ, has_fderiv_at (λ x, F x a) (F' x₀ a) x₀ :=
h_diff.mono (λ a ha, ha x₀ x₀_in),
have : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs (bound a)) (λ x, F x a) (ball x₀ ε),
{ apply (h_diff.and h_bound).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
refine (convex_ball _ _).lipschitz_on_with_of_nnnorm_has_fderiv_within_le
(λ x x_in, (ha_deriv x x_in).has_fderiv_within_at) (λ x x_in, _),
rw [← nnreal.coe_le_coe, coe_nnnorm, real.coe_nnabs],
exact (ha_bound x x_in).trans (le_abs_self _) },
exact (has_fderiv_at_of_dominated_loc_of_lip ε_pos hF_meas hF_int
hF'_meas this bound_integrable diff_x₀).2
end
/-- Derivative under integral of `x ↦ ∫ F x a` at a given point `x₀ : ℝ`, assuming
`F x₀` is integrable, `x ↦ F x a` is locally Lipschitz on an interval around `x₀` for ae `a`
(with interval radius independent of `a`) with integrable Lipschitz bound, and `F x` is
ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_deriv_at_of_dominated_loc_of_lip {F : ℝ → α → E} {F' : α → E} {x₀ : ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable F' μ) {bound : α → ℝ}
(h_lipsch : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs $ bound a) (λ x, F x a) (ball x₀ ε))
(bound_integrable : integrable (bound : α → ℝ) μ)
(h_diff : ∀ᵐ a ∂μ, has_deriv_at (λ x, F x a) (F' a) x₀) :
(integrable F' μ) ∧ has_deriv_at (λ x, ∫ a, F x a ∂μ) (∫ a, F' a ∂μ) x₀ :=
begin
have hm := (continuous_linear_map.smul_rightL ℝ ℝ E 1).continuous.measurable.comp_ae_measurable
hF'_meas,
cases has_fderiv_at_of_dominated_loc_of_lip ε_pos hF_meas hF_int hm h_lipsch bound_integrable
h_diff with hF'_int key,
replace hF'_int : integrable F' μ,
{ rw [← integrable_norm_iff hm] at hF'_int,
simpa only [integrable_norm_iff, hF'_meas, one_mul, norm_one,
continuous_linear_map.norm_smul_rightL_apply] using hF'_int},
refine ⟨hF'_int, _⟩,
simp_rw has_deriv_at_iff_has_fderiv_at at h_diff ⊢,
rwa continuous_linear_map.integral_comp_comm _ hF'_int at key,
all_goals { apply_instance, },
end
/-- Derivative under integral of `x ↦ ∫ F x a` at a given point `x₀ : ℝ`, assuming
`F x₀` is integrable, `x ↦ F x a` is differentiable on an interval around `x₀` for ae `a`
(with interval radius independent of `a`) with derivative uniformly bounded by an integrable
function, and `F x` is ae-measurable for `x` in a possibly smaller neighborhood of `x₀`. -/
lemma has_deriv_at_of_dominated_loc_of_deriv_le {F : ℝ → α → E} {F' : ℝ → α → E} {x₀ : ℝ}
{ε : ℝ} (ε_pos : 0 < ε)
(hF_meas : ∀ᶠ x in 𝓝 x₀, ae_measurable (F x) μ)
(hF_int : integrable (F x₀) μ)
(hF'_meas : ae_measurable (F' x₀) μ)
{bound : α → ℝ}
(h_bound : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, ∥F' x a∥ ≤ bound a)
(bound_integrable : integrable bound μ)
(h_diff : ∀ᵐ a ∂μ, ∀ x ∈ ball x₀ ε, has_deriv_at (λ x, F x a) (F' x a) x) :
(integrable (F' x₀) μ) ∧ has_deriv_at (λn, ∫ a, F n a ∂μ) (∫ a, F' x₀ a ∂μ) x₀ :=
begin
have x₀_in : x₀ ∈ ball x₀ ε := mem_ball_self ε_pos,
have diff_x₀ : ∀ᵐ a ∂μ, has_deriv_at (λ x, F x a) (F' x₀ a) x₀ :=
h_diff.mono (λ a ha, ha x₀ x₀_in),
have : ∀ᵐ a ∂μ, lipschitz_on_with (real.nnabs (bound a)) (λ (x : ℝ), F x a) (ball x₀ ε),
{ apply (h_diff.and h_bound).mono,
rintros a ⟨ha_deriv, ha_bound⟩,
refine (convex_ball _ _).lipschitz_on_with_of_nnnorm_has_deriv_within_le
(λ x x_in, (ha_deriv x x_in).has_deriv_within_at) (λ x x_in, _),
rw [← nnreal.coe_le_coe, coe_nnnorm, real.coe_nnabs],
exact (ha_bound x x_in).trans (le_abs_self _) },
exact has_deriv_at_of_dominated_loc_of_lip ε_pos hF_meas hF_int hF'_meas this
bound_integrable diff_x₀
end
|
b6bcfdb2f861eac0f4fda3a303a4abb9ccd7c19a
|
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
|
/library/init/algebra/ring.lean
|
ab1d561c0a80ca7c1c8e73f89663e7afd10e6017
|
[
"Apache-2.0"
] |
permissive
|
pacchiano/lean
|
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
|
fdadada3a970377a6df8afcd629a6f2eab6e84e8
|
refs/heads/master
| 1,611,357,380,399
| 1,489,870,101,000
| 1,489,870,101,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 7,876
|
lean
|
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
prelude
import init.algebra.group
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
set_option default_priority 100
universe u
class distrib (α : Type u) extends has_mul α, has_add α :=
(left_distrib : ∀ a b c : α, a * (b + c) = (a * b) + (a * c))
(right_distrib : ∀ a b c : α, (a + b) * c = (a * c) + (b * c))
variable {α : Type u}
lemma left_distrib [distrib α] (a b c : α) : a * (b + c) = a * b + a * c :=
distrib.left_distrib a b c
def mul_add := @left_distrib
lemma right_distrib [distrib α] (a b c : α) : (a + b) * c = a * c + b * c :=
distrib.right_distrib a b c
def add_mul := @right_distrib
class mul_zero_class (α : Type u) extends has_mul α, has_zero α :=
(zero_mul : ∀ a : α, 0 * a = 0)
(mul_zero : ∀ a : α, a * 0 = 0)
@[simp] lemma zero_mul [mul_zero_class α] (a : α) : 0 * a = 0 :=
mul_zero_class.zero_mul a
@[simp] lemma mul_zero [mul_zero_class α] (a : α) : a * 0 = 0 :=
mul_zero_class.mul_zero a
class zero_ne_one_class (α : Type u) extends has_zero α, has_one α :=
(zero_ne_one : 0 ≠ (1:α))
lemma zero_ne_one [s: zero_ne_one_class α] : 0 ≠ (1:α) :=
@zero_ne_one_class.zero_ne_one α s
/- semiring -/
class semiring (α : Type u) extends add_comm_monoid α, monoid α, distrib α, mul_zero_class α
section semiring
variables [semiring α]
lemma one_add_one_eq_two : 1 + 1 = (2 : α) :=
begin unfold bit0, reflexivity end
lemma ne_zero_of_mul_ne_zero_right {a b : α} (h : a * b ≠ 0) : a ≠ 0 :=
suppose a = 0,
have a * b = 0, by rw [this, zero_mul],
h this
lemma ne_zero_of_mul_ne_zero_left {a b : α} (h : a * b ≠ 0) : b ≠ 0 :=
suppose b = 0,
have a * b = 0, by rw [this, mul_zero],
h this
lemma distrib_three_right (a b c d : α) : (a + b + c) * d = a * d + b * d + c * d :=
by simp [right_distrib]
end semiring
class comm_semiring (α : Type u) extends semiring α, comm_monoid α
/- ring -/
class ring (α : Type u) extends add_comm_group α, monoid α, distrib α
lemma ring.mul_zero [ring α] (a : α) : a * 0 = 0 :=
have a * 0 + 0 = a * 0 + a * 0, from calc
a * 0 + 0 = a * (0 + 0) : by simp
... = a * 0 + a * 0 : by rw left_distrib,
show a * 0 = 0, from (add_left_cancel this)^.symm
lemma ring.zero_mul [ring α] (a : α) : 0 * a = 0 :=
have 0 * a + 0 = 0 * a + 0 * a, from calc
0 * a + 0 = (0 + 0) * a : by simp
... = 0 * a + 0 * a : by rewrite right_distrib,
show 0 * a = 0, from (add_left_cancel this)^.symm
instance ring.to_semiring [s : ring α] : semiring α :=
{ s with
mul_zero := ring.mul_zero,
zero_mul := ring.zero_mul }
lemma neg_mul_eq_neg_mul [s : ring α] (a b : α) : -(a * b) = -a * b :=
neg_eq_of_add_eq_zero
begin rw [-right_distrib, add_right_neg, zero_mul] end
lemma neg_mul_eq_mul_neg [s : ring α] (a b : α) : -(a * b) = a * -b :=
neg_eq_of_add_eq_zero
begin rw [-left_distrib, add_right_neg, mul_zero] end
@[simp] lemma neg_mul_eq_neg_mul_symm [s : ring α] (a b : α) : - a * b = - (a * b) :=
eq.symm (neg_mul_eq_neg_mul a b)
@[simp] lemma mul_neg_eq_neg_mul_symm [s : ring α] (a b : α) : a * - b = - (a * b) :=
eq.symm (neg_mul_eq_mul_neg a b)
lemma neg_mul_neg [s : ring α] (a b : α) : -a * -b = a * b :=
by simp
lemma neg_mul_comm [s : ring α] (a b : α) : -a * b = a * -b :=
by simp
theorem neg_eq_neg_one_mul [s : ring α] (a : α) : -a = -1 * a :=
by simp
lemma mul_sub_left_distrib [s : ring α] (a b c : α) : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : left_distrib a b (-c)
... = a * b - a * c : by simp
def mul_sub := @mul_sub_left_distrib
lemma mul_sub_right_distrib [s : ring α] (a b c : α) : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : right_distrib a (-b) c
... = a * c - b * c : by simp
def sub_mul := @mul_sub_right_distrib
class comm_ring (α : Type u) extends ring α, comm_semigroup α
instance comm_ring.to_comm_semiring [s : comm_ring α] : comm_semiring α :=
{ s with
mul_zero := mul_zero,
zero_mul := zero_mul }
section comm_ring
variable [comm_ring α]
lemma mul_self_sub_mul_self_eq (a b : α) : a * a - b * b = (a + b) * (a - b) :=
by simp [right_distrib, left_distrib]
lemma mul_self_sub_one_eq (a : α) : a * a - 1 = (a + 1) * (a - 1) :=
by simp [right_distrib, left_distrib]
lemma add_mul_self_eq (a b : α) : (a + b) * (a + b) = a*a + 2*a*b + b*b :=
calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : by simp [right_distrib, left_distrib]
... = a*a + 2*a*b + b*b : by rw one_add_one_eq_two
end comm_ring
class no_zero_divisors (α : Type u) extends has_mul α, has_zero α :=
(eq_zero_or_eq_zero_of_mul_eq_zero : ∀ a b : α, a * b = 0 → a = 0 ∨ b = 0)
lemma eq_zero_or_eq_zero_of_mul_eq_zero [no_zero_divisors α] {a b : α} (h : a * b = 0) : a = 0 ∨ b = 0 :=
no_zero_divisors.eq_zero_or_eq_zero_of_mul_eq_zero a b h
lemma eq_zero_of_mul_self_eq_zero [no_zero_divisors α] {a : α} (h : a * a = 0) : a = 0 :=
or.elim (eq_zero_or_eq_zero_of_mul_eq_zero h) (assume h', h') (assume h', h')
class integral_domain (α : Type u) extends comm_ring α, no_zero_divisors α, zero_ne_one_class α
section integral_domain
variable [integral_domain α]
lemma mul_ne_zero {a b : α} (h₁ : a ≠ 0) (h₂ : b ≠ 0) : a * b ≠ 0 :=
λ h, or.elim (eq_zero_or_eq_zero_of_mul_eq_zero h) (assume h₃, h₁ h₃) (assume h₄, h₂ h₄)
lemma eq_of_mul_eq_mul_right {a b c : α} (ha : a ≠ 0) (h : b * a = c * a) : b = c :=
have b * a - c * a = 0, from sub_eq_zero_of_eq h,
have (b - c) * a = 0, by rw [mul_sub_right_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right ha,
eq_of_sub_eq_zero this
lemma eq_of_mul_eq_mul_left {a b c : α} (ha : a ≠ 0) (h : a * b = a * c) : b = c :=
have a * b - a * c = 0, from sub_eq_zero_of_eq h,
have a * (b - c) = 0, by rw [mul_sub_left_distrib, this],
have b - c = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_left ha,
eq_of_sub_eq_zero this
lemma eq_zero_of_mul_eq_self_right {a b : α} (h₁ : b ≠ 1) (h₂ : a * b = a) : a = 0 :=
have hb : b - 1 ≠ 0, from
suppose b - 1 = 0,
have b = 0 + 1, from eq_add_of_sub_eq this,
have b = 1, by rwa zero_add at this,
h₁ this,
have a * b - a = 0, by simp [h₂],
have a * (b - 1) = 0, by rwa [mul_sub_left_distrib, mul_one],
show a = 0, from (eq_zero_or_eq_zero_of_mul_eq_zero this)^.resolve_right hb
lemma eq_zero_of_mul_eq_self_left {a b : α} (h₁ : b ≠ 1) (h₂ : b * a = a) : a = 0 :=
eq_zero_of_mul_eq_self_right h₁ (by rwa mul_comm at h₂)
lemma mul_self_eq_mul_self_iff (a b : α) : a * a = b * b ↔ a = b ∨ a = -b :=
iff.intro
(suppose a * a = b * b,
have (a - b) * (a + b) = 0,
by rewrite [mul_comm, -mul_self_sub_mul_self_eq, this, sub_self],
have a - b = 0 ∨ a + b = 0, from eq_zero_or_eq_zero_of_mul_eq_zero this,
or.elim this
(suppose a - b = 0, or.inl (eq_of_sub_eq_zero this))
(suppose a + b = 0, or.inr (eq_neg_of_add_eq_zero this)))
(suppose a = b ∨ a = -b, or.elim this
(suppose a = b, by rewrite this)
(suppose a = -b, by rewrite [this, neg_mul_neg]))
lemma mul_self_eq_one_iff (a : α) : a * a = 1 ↔ a = 1 ∨ a = -1 :=
have a * a = 1 * 1 ↔ a = 1 ∨ a = -1, from mul_self_eq_mul_self_iff a 1,
by rwa mul_one at this
end integral_domain
/- TODO(Leo): remove the following annotations as soon as we have support for arithmetic
in the SMT tactic framework -/
attribute [ematch] add_zero zero_add mul_one one_mul mul_zero zero_mul
|
ce943479a407e9da65fb6a6905745438ec7b335e
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/topology/continuous_function/bounded.lean
|
97d79c627990e05e3e6afc68bd34ba484deace25
|
[
"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
| 52,315
|
lean
|
/-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Mario Carneiro, Yury Kudryashov, Heather Macbeth
-/
import analysis.normed_space.operator_norm
import analysis.normed_space.star.basic
import topology.continuous_function.algebra
import data.real.sqrt
import analysis.normed_space.lattice_ordered_group
/-!
# Bounded continuous functions
The type of bounded continuous functions taking values in a metric space, with
the uniform distance.
-/
noncomputable theory
open_locale topological_space classical nnreal
open set filter metric function
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
/-- The type of bounded continuous functions from a topological space to a metric space -/
structure bounded_continuous_function
(α : Type u) (β : Type v) [topological_space α] [metric_space β] extends continuous_map α β :
Type (max u v) :=
(bounded' : ∃C, ∀x y:α, dist (to_fun x) (to_fun y) ≤ C)
localized "infixr ` →ᵇ `:25 := bounded_continuous_function" in bounded_continuous_function
namespace bounded_continuous_function
section basics
variables [topological_space α] [metric_space β] [metric_space γ]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
instance : has_coe_to_fun (α →ᵇ β) (λ _, α → β) := ⟨λ f, f.to_fun⟩
@[simp] lemma coe_to_continuous_fun (f : α →ᵇ β) : (f.to_continuous_map : α → β) = f := rfl
/-- See Note [custom simps projection]. We need to specify this projection explicitly in this case,
because it is a composition of multiple projections. -/
def simps.apply (h : α →ᵇ β) : α → β := h
initialize_simps_projections bounded_continuous_function (to_continuous_map_to_fun → apply)
protected lemma bounded (f : α →ᵇ β) : ∃C, ∀ x y : α, dist (f x) (f y) ≤ C := f.bounded'
@[continuity]
protected lemma continuous (f : α →ᵇ β) : continuous f := f.to_continuous_map.continuous
@[ext] lemma ext (H : ∀x, f x = g x) : f = g :=
by { cases f, cases g, congr, ext, exact H x, }
lemma ext_iff : f = g ↔ ∀ x, f x = g x :=
⟨λ h, λ x, h ▸ rfl, ext⟩
lemma coe_injective : @injective (α →ᵇ β) (α → β) coe_fn := λ f g h, ext $ congr_fun h
lemma bounded_range (f : α →ᵇ β) : bounded (range f) :=
bounded_range_iff.2 f.bounded
lemma bounded_image (f : α →ᵇ β) (s : set α) : bounded (f '' s) :=
f.bounded_range.mono $ image_subset_range _ _
lemma eq_of_empty [is_empty α] (f g : α →ᵇ β) : f = g :=
ext $ is_empty.elim ‹_›
/-- A continuous function with an explicit bound is a bounded continuous function. -/
def mk_of_bound (f : C(α, β)) (C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β :=
⟨f, ⟨C, h⟩⟩
@[simp] lemma mk_of_bound_coe {f} {C} {h} : (mk_of_bound f C h : α → β) = (f : α → β) :=
rfl
/-- A continuous function on a compact space is automatically a bounded continuous function. -/
def mk_of_compact [compact_space α] (f : C(α, β)) : α →ᵇ β :=
⟨f, bounded_range_iff.1 (is_compact_range f.continuous).bounded⟩
@[simp] lemma mk_of_compact_apply [compact_space α] (f : C(α, β)) (a : α) :
mk_of_compact f a = f a :=
rfl
/-- If a function is bounded on a discrete space, it is automatically continuous,
and therefore gives rise to an element of the type of bounded continuous functions -/
@[simps] def mk_of_discrete [discrete_topology α] (f : α → β)
(C : ℝ) (h : ∀ x y : α, dist (f x) (f y) ≤ C) : α →ᵇ β :=
⟨⟨f, continuous_of_discrete_topology⟩, ⟨C, h⟩⟩
/-- The uniform distance between two bounded continuous functions -/
instance : has_dist (α →ᵇ β) :=
⟨λf g, Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C}⟩
lemma dist_eq : dist f g = Inf {C | 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C} := rfl
lemma dist_set_exists : ∃ C, 0 ≤ C ∧ ∀ x : α, dist (f x) (g x) ≤ C :=
begin
rcases f.bounded_range.union g.bounded_range with ⟨C, hC⟩,
refine ⟨max 0 C, le_max_left _ _, λ x, (hC _ _ _ _).trans (le_max_right _ _)⟩;
[left, right]; apply mem_range_self
end
/-- The pointwise distance is controlled by the distance between functions, by definition. -/
lemma dist_coe_le_dist (x : α) : dist (f x) (g x) ≤ dist f g :=
le_cInf dist_set_exists $ λb hb, hb.2 x
/- This lemma will be needed in the proof of the metric space instance, but it will become
useless afterwards as it will be superseded by the general result that the distance is nonnegative
in metric spaces. -/
private lemma dist_nonneg' : 0 ≤ dist f g :=
le_cInf dist_set_exists (λ C, and.left)
/-- The distance between two functions is controlled by the supremum of the pointwise distances -/
lemma dist_le (C0 : (0 : ℝ) ≤ C) : dist f g ≤ C ↔ ∀x:α, dist (f x) (g x) ≤ C :=
⟨λ h x, le_trans (dist_coe_le_dist x) h, λ H, cInf_le ⟨0, λ C, and.left⟩ ⟨C0, H⟩⟩
lemma dist_le_iff_of_nonempty [nonempty α] :
dist f g ≤ C ↔ ∀ x, dist (f x) (g x) ≤ C :=
⟨λ h x, le_trans (dist_coe_le_dist x) h,
λ w, (dist_le (le_trans dist_nonneg (w (nonempty.some ‹_›)))).mpr w⟩
lemma dist_lt_of_nonempty_compact [nonempty α] [compact_space α]
(w : ∀x:α, dist (f x) (g x) < C) : dist f g < C :=
begin
have c : continuous (λ x, dist (f x) (g x)), { continuity, },
obtain ⟨x, -, le⟩ :=
is_compact.exists_forall_ge compact_univ set.univ_nonempty (continuous.continuous_on c),
exact lt_of_le_of_lt (dist_le_iff_of_nonempty.mpr (λ y, le y trivial)) (w x),
end
lemma dist_lt_iff_of_compact [compact_space α] (C0 : (0 : ℝ) < C) :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
begin
fsplit,
{ intros w x,
exact lt_of_le_of_lt (dist_coe_le_dist x) w, },
{ by_cases h : nonempty α,
{ resetI,
exact dist_lt_of_nonempty_compact, },
{ rintro -,
convert C0,
apply le_antisymm _ dist_nonneg',
rw [dist_eq],
exact cInf_le ⟨0, λ C, and.left⟩ ⟨le_rfl, λ x, false.elim (h (nonempty.intro x))⟩, }, },
end
lemma dist_lt_iff_of_nonempty_compact [nonempty α] [compact_space α] :
dist f g < C ↔ ∀x:α, dist (f x) (g x) < C :=
⟨λ w x, lt_of_le_of_lt (dist_coe_le_dist x) w, dist_lt_of_nonempty_compact⟩
/-- The type of bounded continuous functions, with the uniform distance, is a metric space. -/
instance : metric_space (α →ᵇ β) :=
{ dist_self := λ f, le_antisymm ((dist_le le_rfl).2 $ λ x, by simp) dist_nonneg',
eq_of_dist_eq_zero := λ f g hfg, by ext x; exact
eq_of_dist_eq_zero (le_antisymm (hfg ▸ dist_coe_le_dist _) dist_nonneg),
dist_comm := λ f g, by simp [dist_eq, dist_comm],
dist_triangle := λ f g h,
(dist_le (add_nonneg dist_nonneg' dist_nonneg')).2 $ λ x,
le_trans (dist_triangle _ _ _) (add_le_add (dist_coe_le_dist _) (dist_coe_le_dist _)) }
/-- On an empty space, bounded continuous functions are at distance 0 -/
lemma dist_zero_of_empty [is_empty α] : dist f g = 0 :=
dist_eq_zero.2 (eq_of_empty f g)
lemma dist_eq_supr : dist f g = ⨆ x : α, dist (f x) (g x) :=
begin
casesI is_empty_or_nonempty α, { rw [supr_of_empty', real.Sup_empty, dist_zero_of_empty] },
refine (dist_le_iff_of_nonempty.mpr $ le_csupr _).antisymm (csupr_le dist_coe_le_dist),
exact dist_set_exists.imp (λ C hC, forall_range_iff.2 hC.2)
end
variables (α) {β}
/-- Constant as a continuous bounded function. -/
@[simps {fully_applied := ff}] def const (b : β) : α →ᵇ β :=
⟨continuous_map.const b, 0, by simp [le_refl]⟩
variable {α}
lemma const_apply' (a : α) (b : β) : (const α b : α → β) a = b := rfl
/-- If the target space is inhabited, so is the space of bounded continuous functions -/
instance [inhabited β] : inhabited (α →ᵇ β) := ⟨const α default⟩
lemma lipschitz_evalx (x : α) : lipschitz_with 1 (λ f : α →ᵇ β, f x) :=
lipschitz_with.mk_one $ λ f g, dist_coe_le_dist x
theorem uniform_continuous_coe : @uniform_continuous (α →ᵇ β) (α → β) _ _ coe_fn :=
uniform_continuous_pi.2 $ λ x, (lipschitz_evalx x).uniform_continuous
lemma continuous_coe : continuous (λ (f : α →ᵇ β) x, f x) :=
uniform_continuous.continuous uniform_continuous_coe
/-- When `x` is fixed, `(f : α →ᵇ β) ↦ f x` is continuous -/
@[continuity] theorem continuous_evalx {x : α} : continuous (λ f : α →ᵇ β, f x) :=
(continuous_apply x).comp continuous_coe
/-- The evaluation map is continuous, as a joint function of `u` and `x` -/
@[continuity] theorem continuous_eval : continuous (λ p : (α →ᵇ β) × α, p.1 p.2) :=
continuous_prod_of_continuous_lipschitz _ 1 (λ f, f.continuous) $ lipschitz_evalx
/-- Bounded continuous functions taking values in a complete space form a complete space. -/
instance [complete_space β] : complete_space (α →ᵇ β) :=
complete_of_cauchy_seq_tendsto $ λ (f : ℕ → α →ᵇ β) (hf : cauchy_seq f),
begin
/- We have to show that `f n` converges to a bounded continuous function.
For this, we prove pointwise convergence to define the limit, then check
it is a continuous bounded function, and then check the norm convergence. -/
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩,
have f_bdd := λx n m N hn hm, le_trans (dist_coe_le_dist x) (b_bound n m N hn hm),
have fx_cau : ∀x, cauchy_seq (λn, f n x) :=
λx, cauchy_seq_iff_le_tendsto_0.2 ⟨b, b0, f_bdd x, b_lim⟩,
choose F hF using λx, cauchy_seq_tendsto_of_complete (fx_cau x),
/- F : α → β, hF : ∀ (x : α), tendsto (λ (n : ℕ), f n x) at_top (𝓝 (F x))
`F` is the desired limit function. Check that it is uniformly approximated by `f N` -/
have fF_bdd : ∀x N, dist (f N x) (F x) ≤ b N :=
λ x N, le_of_tendsto (tendsto_const_nhds.dist (hF x))
(filter.eventually_at_top.2 ⟨N, λn hn, f_bdd x N n N (le_refl N) hn⟩),
refine ⟨⟨⟨F, _⟩, _⟩, _⟩,
{ /- Check that `F` is continuous, as a uniform limit of continuous functions -/
have : tendsto_uniformly (λn x, f n x) F at_top,
{ refine metric.tendsto_uniformly_iff.2 (λ ε ε0, _),
refine ((tendsto_order.1 b_lim).2 ε ε0).mono (λ n hn x, _),
rw dist_comm,
exact lt_of_le_of_lt (fF_bdd x n) hn },
exact this.continuous (eventually_of_forall $ λ N, (f N).continuous) },
{ /- Check that `F` is bounded -/
rcases (f 0).bounded with ⟨C, hC⟩,
refine ⟨C + (b 0 + b 0), λ x y, _⟩,
calc dist (F x) (F y) ≤ dist (f 0 x) (f 0 y) + (dist (f 0 x) (F x) + dist (f 0 y) (F y)) :
dist_triangle4_left _ _ _ _
... ≤ C + (b 0 + b 0) : by mono* },
{ /- Check that `F` is close to `f N` in distance terms -/
refine tendsto_iff_dist_tendsto_zero.2 (squeeze_zero (λ _, dist_nonneg) _ b_lim),
exact λ N, (dist_le (b0 _)).2 (λx, fF_bdd x N) }
end
/-- Composition of a bounded continuous function and a continuous function. -/
@[simps { fully_applied := ff }]
def comp_continuous {δ : Type*} [topological_space δ] (f : α →ᵇ β) (g : C(δ, α)) : δ →ᵇ β :=
{ to_continuous_map := f.1.comp g,
bounded' := f.bounded'.imp (λ C hC x y, hC _ _) }
lemma lipschitz_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) :
lipschitz_with 1 (λ f : α →ᵇ β, f.comp_continuous g) :=
lipschitz_with.mk_one $ λ f₁ f₂, (dist_le dist_nonneg).2 $ λ x, dist_coe_le_dist (g x)
lemma continuous_comp_continuous {δ : Type*} [topological_space δ] (g : C(δ, α)) :
continuous (λ f : α →ᵇ β, f.comp_continuous g) :=
(lipschitz_comp_continuous g).continuous
/-- Restrict a bounded continuous function to a set. -/
@[simps apply { fully_applied := ff }]
def restrict (f : α →ᵇ β) (s : set α) : s →ᵇ β := f.comp_continuous (continuous_map.id.restrict s)
/-- Composition (in the target) of a bounded continuous function with a Lipschitz map again
gives a bounded continuous function -/
def comp (G : β → γ) {C : ℝ≥0} (H : lipschitz_with C G)
(f : α →ᵇ β) : α →ᵇ γ :=
⟨⟨λx, G (f x), H.continuous.comp f.continuous⟩,
let ⟨D, hD⟩ := f.bounded in
⟨max C 0 * D, λ x y, calc
dist (G (f x)) (G (f y)) ≤ C * dist (f x) (f y) : H.dist_le_mul _ _
... ≤ max C 0 * dist (f x) (f y) : mul_le_mul_of_nonneg_right (le_max_left C 0) dist_nonneg
... ≤ max C 0 * D : mul_le_mul_of_nonneg_left (hD _ _) (le_max_right C 0)⟩⟩
/-- The composition operator (in the target) with a Lipschitz map is Lipschitz -/
lemma lipschitz_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
lipschitz_with C (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
lipschitz_with.of_dist_le_mul $ λ f g,
(dist_le (mul_nonneg C.2 dist_nonneg)).2 $ λ x,
calc dist (G (f x)) (G (g x)) ≤ C * dist (f x) (g x) : H.dist_le_mul _ _
... ≤ C * dist f g : mul_le_mul_of_nonneg_left (dist_coe_le_dist _) C.2
/-- The composition operator (in the target) with a Lipschitz map is uniformly continuous -/
lemma uniform_continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
uniform_continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
(lipschitz_comp H).uniform_continuous
/-- The composition operator (in the target) with a Lipschitz map is continuous -/
lemma continuous_comp {G : β → γ} {C : ℝ≥0} (H : lipschitz_with C G) :
continuous (comp G H : (α →ᵇ β) → α →ᵇ γ) :=
(lipschitz_comp H).continuous
/-- Restriction (in the target) of a bounded continuous function taking values in a subset -/
def cod_restrict (s : set β) (f : α →ᵇ β) (H : ∀x, f x ∈ s) : α →ᵇ s :=
⟨⟨s.cod_restrict f H, continuous_subtype_mk _ f.continuous⟩, f.bounded⟩
section extend
variables {δ : Type*} [topological_space δ] [discrete_topology δ]
/-- A version of `function.extend` for bounded continuous maps. We assume that the domain has
discrete topology, so we only need to verify boundedness. -/
def extend (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : δ →ᵇ β :=
{ to_fun := extend f g h,
continuous_to_fun := continuous_of_discrete_topology,
bounded' :=
begin
rw [← bounded_range_iff, range_extend f.injective, metric.bounded_union],
exact ⟨g.bounded_range, h.bounded_image _⟩
end }
@[simp] lemma extend_apply (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) (x : α) :
extend f g h (f x) = g x :=
extend_apply f.injective _ _ _
@[simp] lemma extend_comp (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) : extend f g h ∘ f = g :=
extend_comp f.injective _ _
lemma extend_apply' {f : α ↪ δ} {x : δ} (hx : x ∉ range f) (g : α →ᵇ β) (h : δ →ᵇ β) :
extend f g h x = h x :=
extend_apply' _ _ _ hx
lemma extend_of_empty [is_empty α] (f : α ↪ δ) (g : α →ᵇ β) (h : δ →ᵇ β) :
extend f g h = h :=
coe_injective $ function.extend_of_empty f g h
@[simp] lemma dist_extend_extend (f : α ↪ δ) (g₁ g₂ : α →ᵇ β) (h₁ h₂ : δ →ᵇ β) :
dist (g₁.extend f h₁) (g₂.extend f h₂) =
max (dist g₁ g₂) (dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ)) :=
begin
refine le_antisymm ((dist_le $ le_max_iff.2 $ or.inl dist_nonneg).2 $ λ x, _) (max_le _ _),
{ rcases em (∃ y, f y = x) with (⟨x, rfl⟩|hx),
{ simp only [extend_apply],
exact (dist_coe_le_dist x).trans (le_max_left _ _) },
{ simp only [extend_apply' hx],
lift x to ((range f)ᶜ : set δ) using hx,
calc dist (h₁ x) (h₂ x) = dist (h₁.restrict (range f)ᶜ x) (h₂.restrict (range f)ᶜ x) : rfl
... ≤ dist (h₁.restrict (range f)ᶜ) (h₂.restrict (range f)ᶜ) : dist_coe_le_dist x
... ≤ _ : le_max_right _ _ } },
{ refine (dist_le dist_nonneg).2 (λ x, _),
rw [← extend_apply f g₁ h₁, ← extend_apply f g₂ h₂],
exact dist_coe_le_dist _ },
{ refine (dist_le dist_nonneg).2 (λ x, _),
calc dist (h₁ x) (h₂ x) = dist (extend f g₁ h₁ x) (extend f g₂ h₂ x) :
by rw [extend_apply' x.coe_prop, extend_apply' x.coe_prop]
... ≤ _ : dist_coe_le_dist _ }
end
lemma isometry_extend (f : α ↪ δ) (h : δ →ᵇ β) :
isometry (λ g : α →ᵇ β, extend f g h) :=
isometry_emetric_iff_metric.2 $ λ g₁ g₂, by simp [dist_nonneg]
end extend
end basics
section arzela_ascoli
variables [topological_space α] [compact_space α] [metric_space β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
/- Arzela-Ascoli theorem asserts that, on a compact space, a set of functions sharing
a common modulus of continuity and taking values in a compact set forms a compact
subset for the topology of uniform convergence. In this section, we prove this theorem
and several useful variations around it. -/
/-- First version, with pointwise equicontinuity and range in a compact space -/
theorem arzela_ascoli₁ [compact_space β]
(A : set (α →ᵇ β))
(closed : is_closed A)
(H : ∀ (x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact A :=
begin
refine compact_of_totally_bounded_is_closed _ closed,
refine totally_bounded_of_finite_discretization (λ ε ε0, _),
rcases exists_between ε0 with ⟨ε₁, ε₁0, εε₁⟩,
let ε₂ := ε₁/2/2,
/- We have to find a finite discretization of `u`, i.e., finite information
that is sufficient to reconstruct `u` up to ε. This information will be
provided by the values of `u` on a sufficiently dense set tα,
slightly translated to fit in a finite ε₂-dense set tβ in the image. Such
sets exist by compactness of the source and range. Then, to check that these
data determine the function up to ε, one uses the control on the modulus of
continuity to extend the closeness on tα to closeness everywhere. -/
have ε₂0 : ε₂ > 0 := half_pos (half_pos ε₁0),
have : ∀x:α, ∃U, x ∈ U ∧ is_open U ∧ ∀ (y z ∈ U) {f : α →ᵇ β},
f ∈ A → dist (f y) (f z) < ε₂ := λ x,
let ⟨U, nhdsU, hU⟩ := H x _ ε₂0,
⟨V, VU, openV, xV⟩ := _root_.mem_nhds_iff.1 nhdsU in
⟨V, xV, openV, λy hy z hz f hf, hU y (VU hy) z (VU hz) f hf⟩,
choose U hU using this,
/- For all x, the set hU x is an open set containing x on which the elements of A
fluctuate by at most ε₂.
We extract finitely many of these sets that cover the whole space, by compactness -/
rcases compact_univ.elim_finite_subcover_image
(λx _, (hU x).2.1) (λx hx, mem_bUnion (mem_univ _) (hU x).1)
with ⟨tα, _, ⟨_⟩, htα⟩,
/- tα : set α, htα : univ ⊆ ⋃x ∈ tα, U x -/
rcases @finite_cover_balls_of_compact β _ _ compact_univ _ ε₂0
with ⟨tβ, _, ⟨_⟩, htβ⟩, resetI,
/- tβ : set β, htβ : univ ⊆ ⋃y ∈ tβ, ball y ε₂ -/
/- Associate to every point `y` in the space a nearby point `F y` in tβ -/
choose F hF using λy, show ∃z∈tβ, dist y z < ε₂, by simpa using htβ (mem_univ y),
/- F : β → β, hF : ∀ (y : β), F y ∈ tβ ∧ dist y (F y) < ε₂ -/
/- Associate to every function a discrete approximation, mapping each point in `tα`
to a point in `tβ` close to its true image by the function. -/
refine ⟨tα → tβ, by apply_instance, λ f a, ⟨F (f a), (hF (f a)).1⟩, _⟩,
rintro ⟨f, hf⟩ ⟨g, hg⟩ f_eq_g,
/- If two functions have the same approximation, then they are within distance ε -/
refine lt_of_le_of_lt ((dist_le $ le_of_lt ε₁0).2 (λ x, _)) εε₁,
obtain ⟨x', x'tα, hx'⟩ : ∃x' ∈ tα, x ∈ U x' := mem_Union₂.1 (htα (mem_univ x)),
calc dist (f x) (g x)
≤ dist (f x) (f x') + dist (g x) (g x') + dist (f x') (g x') : dist_triangle4_right _ _ _ _
... ≤ ε₂ + ε₂ + ε₁/2 : le_of_lt (add_lt_add (add_lt_add _ _) _)
... = ε₁ : by rw [add_halves, add_halves],
{ exact (hU x').2.2 _ hx' _ ((hU x').1) hf },
{ exact (hU x').2.2 _ hx' _ ((hU x').1) hg },
{ have F_f_g : F (f x') = F (g x') :=
(congr_arg (λ f:tα → tβ, (f ⟨x', x'tα⟩ : β)) f_eq_g : _),
calc dist (f x') (g x')
≤ dist (f x') (F (f x')) + dist (g x') (F (f x')) : dist_triangle_right _ _ _
... = dist (f x') (F (f x')) + dist (g x') (F (g x')) : by rw F_f_g
... < ε₂ + ε₂ : add_lt_add (hF (f x')).2 (hF (g x')).2
... = ε₁/2 : add_halves _ }
end
/-- Second version, with pointwise equicontinuity and range in a compact subset -/
theorem arzela_ascoli₂
(s : set β) (hs : is_compact s)
(A : set (α →ᵇ β))
(closed : is_closed A)
(in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s)
(H : ∀(x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact A :=
/- This version is deduced from the previous one by restricting to the compact type in the target,
using compactness there and then lifting everything to the original space. -/
begin
have M : lipschitz_with 1 coe := lipschitz_with.subtype_coe s,
let F : (α →ᵇ s) → α →ᵇ β := comp coe M,
refine compact_of_is_closed_subset
((_ : is_compact (F ⁻¹' A)).image (continuous_comp M)) closed (λ f hf, _),
{ haveI : compact_space s := is_compact_iff_compact_space.1 hs,
refine arzela_ascoli₁ _ (continuous_iff_is_closed.1 (continuous_comp M) _ closed)
(λ x ε ε0, bex.imp_right (λ U U_nhds hU y hy z hz f hf, _) (H x ε ε0)),
calc dist (f y) (f z) = dist (F f y) (F f z) : rfl
... < ε : hU y hy z hz (F f) hf },
{ let g := cod_restrict s f (λx, in_s f x hf),
rw [show f = F g, by ext; refl] at hf ⊢,
exact ⟨g, hf, rfl⟩ }
end
/-- Third (main) version, with pointwise equicontinuity and range in a compact subset, but
without closedness. The closure is then compact -/
theorem arzela_ascoli
(s : set β) (hs : is_compact s)
(A : set (α →ᵇ β))
(in_s : ∀(f : α →ᵇ β) (x : α), f ∈ A → f x ∈ s)
(H : ∀(x:α) (ε > 0), ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε) :
is_compact (closure A) :=
/- This version is deduced from the previous one by checking that the closure of A, in
addition to being closed, still satisfies the properties of compact range and equicontinuity -/
arzela_ascoli₂ s hs (closure A) is_closed_closure
(λ f x hf, (mem_of_closed' hs.is_closed).2 $ λ ε ε0,
let ⟨g, gA, dist_fg⟩ := metric.mem_closure_iff.1 hf ε ε0 in
⟨g x, in_s g x gA, lt_of_le_of_lt (dist_coe_le_dist _) dist_fg⟩)
(λ x ε ε0, show ∃ U ∈ 𝓝 x,
∀ y z ∈ U, ∀ (f : α →ᵇ β), f ∈ closure A → dist (f y) (f z) < ε,
begin
refine bex.imp_right (λ U U_set hU y hy z hz f hf, _) (H x (ε/2) (half_pos ε0)),
rcases metric.mem_closure_iff.1 hf (ε/2/2) (half_pos (half_pos ε0)) with ⟨g, gA, dist_fg⟩,
replace dist_fg := λ x, lt_of_le_of_lt (dist_coe_le_dist x) dist_fg,
calc dist (f y) (f z) ≤ dist (f y) (g y) + dist (f z) (g z) + dist (g y) (g z) :
dist_triangle4_right _ _ _ _
... < ε/2/2 + ε/2/2 + ε/2 :
add_lt_add (add_lt_add (dist_fg y) (dist_fg z)) (hU y hy z hz g gA)
... = ε : by rw [add_halves, add_halves]
end)
/- To apply the previous theorems, one needs to check the equicontinuity. An important
instance is when the source space is a metric space, and there is a fixed modulus of continuity
for all the functions in the set A -/
lemma equicontinuous_of_continuity_modulus {α : Type u} [metric_space α]
(b : ℝ → ℝ) (b_lim : tendsto b (𝓝 0) (𝓝 0))
(A : set (α →ᵇ β))
(H : ∀(x y:α) (f : α →ᵇ β), f ∈ A → dist (f x) (f y) ≤ b (dist x y))
(x:α) (ε : ℝ) (ε0 : 0 < ε) : ∃U ∈ 𝓝 x, ∀ (y z ∈ U) (f : α →ᵇ β),
f ∈ A → dist (f y) (f z) < ε :=
begin
rcases tendsto_nhds_nhds.1 b_lim ε ε0 with ⟨δ, δ0, hδ⟩,
refine ⟨ball x (δ/2), ball_mem_nhds x (half_pos δ0), λ y hy z hz f hf, _⟩,
have : dist y z < δ := calc
dist y z ≤ dist y x + dist z x : dist_triangle_right _ _ _
... < δ/2 + δ/2 : add_lt_add hy hz
... = δ : add_halves _,
calc
dist (f y) (f z) ≤ b (dist y z) : H y z f hf
... ≤ |b (dist y z)| : le_abs_self _
... = dist (b (dist y z)) 0 : by simp [real.dist_eq]
... < ε : hδ (by simpa [real.dist_eq] using this),
end
end arzela_ascoli
section has_lipschitz_add
/- In this section, if `β` is an `add_monoid` whose addition operation is Lipschitz, then we show
that the space of bounded continuous functions from `α` to `β` inherits a topological `add_monoid`
structure, by using pointwise operations and checking that they are compatible with the uniform
distance.
Implementation note: The material in this section could have been written for `has_lipschitz_mul`
and transported by `@[to_additive]`. We choose not to do this because this causes a few lemma
names (for example, `coe_mul`) to conflict with later lemma names for normed rings; this is only a
trivial inconvenience, but in any case there are no obvious applications of the multiplicative
version. -/
variables [topological_space α] [metric_space β] [add_monoid β]
instance : has_zero (α →ᵇ β) := ⟨const α 0⟩
@[simp] lemma coe_zero : ((0 : α →ᵇ β) : α → β) = 0 := rfl
lemma forall_coe_zero_iff_zero (f : α →ᵇ β) : (∀x, f x = 0) ↔ f = 0 := (@ext_iff _ _ _ _ f 0).symm
@[simp] lemma zero_comp_continuous [topological_space γ] (f : C(γ, α)) :
(0 : α →ᵇ β).comp_continuous f = 0 := rfl
variables [has_lipschitz_add β]
variables (f g : α →ᵇ β) {x : α} {C : ℝ}
/-- The pointwise sum of two bounded continuous functions is again bounded continuous. -/
instance : has_add (α →ᵇ β) :=
{ add := λ f g,
bounded_continuous_function.mk_of_bound (f.to_continuous_map + g.to_continuous_map)
(↑(has_lipschitz_add.C β) * max (classical.some f.bounded) (classical.some g.bounded))
begin
intros x y,
refine le_trans (lipschitz_with_lipschitz_const_add ⟨f x, g x⟩ ⟨f y, g y⟩) _,
rw prod.dist_eq,
refine mul_le_mul_of_nonneg_left _ (has_lipschitz_add.C β).coe_nonneg,
apply max_le_max,
exact classical.some_spec f.bounded x y,
exact classical.some_spec g.bounded x y,
end }
@[simp] lemma coe_add : ⇑(f + g) = f + g := rfl
lemma add_apply : (f + g) x = f x + g x := rfl
lemma add_comp_continuous [topological_space γ] (h : C(γ, α)) :
(g + f).comp_continuous h = g.comp_continuous h + f.comp_continuous h := rfl
instance : add_monoid (α →ᵇ β) :=
{ add_assoc := assume f g h, by ext; simp [add_assoc],
zero_add := assume f, by ext; simp,
add_zero := assume f, by ext; simp,
.. bounded_continuous_function.has_add,
.. bounded_continuous_function.has_zero }
instance : has_lipschitz_add (α →ᵇ β) :=
{ lipschitz_add := ⟨has_lipschitz_add.C β, begin
have C_nonneg := (has_lipschitz_add.C β).coe_nonneg,
rw lipschitz_with_iff_dist_le_mul,
rintros ⟨f₁, g₁⟩ ⟨f₂, g₂⟩,
rw dist_le (mul_nonneg C_nonneg dist_nonneg),
intros x,
refine le_trans (lipschitz_with_lipschitz_const_add ⟨f₁ x, g₁ x⟩ ⟨f₂ x, g₂ x⟩) _,
refine mul_le_mul_of_nonneg_left _ C_nonneg,
apply max_le_max; exact dist_coe_le_dist x,
end⟩ }
/-- Coercion of a `normed_group_hom` is an `add_monoid_hom`. Similar to `add_monoid_hom.coe_fn` -/
@[simps] def coe_fn_add_hom : (α →ᵇ β) →+ (α → β) :=
{ to_fun := coe_fn, map_zero' := coe_zero, map_add' := coe_add }
variables (α β)
/-- The additive map forgetting that a bounded continuous function is bounded.
-/
@[simps] def to_continuous_map_add_hom : (α →ᵇ β) →+ C(α, β) :=
{ to_fun := to_continuous_map,
map_zero' := by { ext, simp, },
map_add' := by { intros, ext, simp, }, }
end has_lipschitz_add
section comm_has_lipschitz_add
variables [topological_space α] [metric_space β] [add_comm_monoid β] [has_lipschitz_add β]
@[to_additive] instance : add_comm_monoid (α →ᵇ β) :=
{ add_comm := assume f g, by ext; simp [add_comm],
.. bounded_continuous_function.add_monoid }
open_locale big_operators
@[simp] lemma coe_sum {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) :
⇑(∑ i in s, f i) = (∑ i in s, (f i : α → β)) :=
(@coe_fn_add_hom α β _ _ _ _).map_sum f s
lemma sum_apply {ι : Type*} (s : finset ι) (f : ι → (α →ᵇ β)) (a : α) :
(∑ i in s, f i) a = (∑ i in s, f i a) :=
by simp
end comm_has_lipschitz_add
section normed_group
/- In this section, if β is a normed group, then we show that the space of bounded
continuous functions from α to β inherits a normed group structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] [normed_group β]
variables (f g : α →ᵇ β) {x : α} {C : ℝ}
instance : has_norm (α →ᵇ β) := ⟨λu, dist u 0⟩
lemma norm_def : ∥f∥ = dist f 0 := rfl
/-- The norm of a bounded continuous function is the supremum of `∥f x∥`.
We use `Inf` to ensure that the definition works if `α` has no elements. -/
lemma norm_eq (f : α →ᵇ β) :
∥f∥ = Inf {C : ℝ | 0 ≤ C ∧ ∀ (x : α), ∥f x∥ ≤ C} :=
by simp [norm_def, bounded_continuous_function.dist_eq]
/-- When the domain is non-empty, we do not need the `0 ≤ C` condition in the formula for ∥f∥ as an
`Inf`. -/
lemma norm_eq_of_nonempty [h : nonempty α] : ∥f∥ = Inf {C : ℝ | ∀ (x : α), ∥f x∥ ≤ C} :=
begin
unfreezingI { obtain ⟨a⟩ := h, },
rw norm_eq,
congr,
ext,
simp only [and_iff_right_iff_imp],
exact λ h', le_trans (norm_nonneg (f a)) (h' a),
end
@[simp] lemma norm_eq_zero_of_empty [h : is_empty α] : ∥f∥ = 0 :=
dist_zero_of_empty
lemma norm_coe_le_norm (x : α) : ∥f x∥ ≤ ∥f∥ := calc
∥f x∥ = dist (f x) ((0 : α →ᵇ β) x) : by simp [dist_zero_right]
... ≤ ∥f∥ : dist_coe_le_dist _
lemma dist_le_two_norm' {f : γ → β} {C : ℝ} (hC : ∀ x, ∥f x∥ ≤ C) (x y : γ) :
dist (f x) (f y) ≤ 2 * C :=
calc dist (f x) (f y) ≤ ∥f x∥ + ∥f y∥ : dist_le_norm_add_norm _ _
... ≤ C + C : add_le_add (hC x) (hC y)
... = 2 * C : (two_mul _).symm
/-- Distance between the images of any two points is at most twice the norm of the function. -/
lemma dist_le_two_norm (x y : α) : dist (f x) (f y) ≤ 2 * ∥f∥ :=
dist_le_two_norm' f.norm_coe_le_norm x y
variable {f}
/-- The norm of a function is controlled by the supremum of the pointwise norms -/
lemma norm_le (C0 : (0 : ℝ) ≤ C) : ∥f∥ ≤ C ↔ ∀x:α, ∥f x∥ ≤ C :=
by simpa using @dist_le _ _ _ _ f 0 _ C0
lemma norm_le_of_nonempty [nonempty α]
{f : α →ᵇ β} {M : ℝ} : ∥f∥ ≤ M ↔ ∀ x, ∥f x∥ ≤ M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_le_iff_of_nonempty,
end
lemma norm_lt_iff_of_compact [compact_space α]
{f : α →ᵇ β} {M : ℝ} (M0 : 0 < M) : ∥f∥ < M ↔ ∀ x, ∥f x∥ < M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_lt_iff_of_compact M0,
end
lemma norm_lt_iff_of_nonempty_compact [nonempty α] [compact_space α]
{f : α →ᵇ β} {M : ℝ} : ∥f∥ < M ↔ ∀ x, ∥f x∥ < M :=
begin
simp_rw [norm_def, ←dist_zero_right],
exact dist_lt_iff_of_nonempty_compact,
end
variable (f)
/-- Norm of `const α b` is less than or equal to `∥b∥`. If `α` is nonempty,
then it is equal to `∥b∥`. -/
lemma norm_const_le (b : β) : ∥const α b∥ ≤ ∥b∥ :=
(norm_le (norm_nonneg b)).2 $ λ x, le_rfl
@[simp] lemma norm_const_eq [h : nonempty α] (b : β) : ∥const α b∥ = ∥b∥ :=
le_antisymm (norm_const_le b) $ h.elim $ λ x, (const α b).norm_coe_le_norm x
/-- Constructing a bounded continuous function from a uniformly bounded continuous
function taking values in a normed group. -/
def of_normed_group {α : Type u} {β : Type v} [topological_space α] [normed_group β]
(f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ∥f x∥ ≤ C) : α →ᵇ β :=
⟨⟨λn, f n, Hf⟩, ⟨_, dist_le_two_norm' H⟩⟩
@[simp] lemma coe_of_normed_group
{α : Type u} {β : Type v} [topological_space α] [normed_group β]
(f : α → β) (Hf : continuous f) (C : ℝ) (H : ∀x, ∥f x∥ ≤ C) :
(of_normed_group f Hf C H : α → β) = f := rfl
lemma norm_of_normed_group_le {f : α → β} (hfc : continuous f) {C : ℝ} (hC : 0 ≤ C)
(hfC : ∀ x, ∥f x∥ ≤ C) : ∥of_normed_group f hfc C hfC∥ ≤ C :=
(norm_le hC).2 hfC
/-- Constructing a bounded continuous function from a uniformly bounded
function on a discrete space, taking values in a normed group -/
def of_normed_group_discrete {α : Type u} {β : Type v}
[topological_space α] [discrete_topology α] [normed_group β]
(f : α → β) (C : ℝ) (H : ∀x, norm (f x) ≤ C) : α →ᵇ β :=
of_normed_group f continuous_of_discrete_topology C H
@[simp] lemma coe_of_normed_group_discrete
{α : Type u} {β : Type v} [topological_space α] [discrete_topology α] [normed_group β]
(f : α → β) (C : ℝ) (H : ∀x, ∥f x∥ ≤ C) :
(of_normed_group_discrete f C H : α → β) = f := rfl
/-- Taking the pointwise norm of a bounded continuous function with values in a `normed_group`,
yields a bounded continuous function with values in ℝ. -/
def norm_comp : α →ᵇ ℝ :=
f.comp norm lipschitz_with_one_norm
@[simp] lemma coe_norm_comp : (f.norm_comp : α → ℝ) = norm ∘ f := rfl
@[simp] lemma norm_norm_comp : ∥f.norm_comp∥ = ∥f∥ :=
by simp only [norm_eq, coe_norm_comp, norm_norm]
lemma bdd_above_range_norm_comp : bdd_above $ set.range $ norm ∘ f :=
(real.bounded_iff_bdd_below_bdd_above.mp $ @bounded_range _ _ _ _ f.norm_comp).2
lemma norm_eq_supr_norm : ∥f∥ = ⨆ x : α, ∥f x∥ :=
begin
casesI is_empty_or_nonempty α with hα _,
{ suffices : range (norm ∘ f) = ∅, { rw [f.norm_eq_zero_of_empty, supr, this, real.Sup_empty], },
simp only [hα, range_eq_empty, not_nonempty_iff], },
{ rw [norm_eq_of_nonempty, supr,
← cInf_upper_bounds_eq_cSup f.bdd_above_range_norm_comp (range_nonempty _)],
congr,
ext,
simp only [forall_apply_eq_imp_iff', mem_range, exists_imp_distrib], },
end
/-- The pointwise opposite of a bounded continuous function is again bounded continuous. -/
instance : has_neg (α →ᵇ β) :=
⟨λf, of_normed_group (-f) f.continuous.neg ∥f∥ $ λ x,
trans_rel_right _ (norm_neg _) (f.norm_coe_le_norm x)⟩
/-- The pointwise difference of two bounded continuous functions is again bounded continuous. -/
instance : has_sub (α →ᵇ β) :=
⟨λf g, of_normed_group (f - g) (f.continuous.sub g.continuous) (∥f∥ + ∥g∥) $ λ x,
by { simp only [sub_eq_add_neg],
exact le_trans (norm_add_le _ _) (add_le_add (f.norm_coe_le_norm x) $
trans_rel_right _ (norm_neg _) (g.norm_coe_le_norm x)) }⟩
@[simp] lemma coe_neg : ⇑(-f) = -f := rfl
lemma neg_apply : (-f) x = -f x := rfl
instance : add_comm_group (α →ᵇ β) :=
{ add_left_neg := assume f, by ext; simp,
add_comm := assume f g, by ext; simp [add_comm],
sub_eq_add_neg := assume f g, by { ext, apply sub_eq_add_neg },
..bounded_continuous_function.add_monoid,
..bounded_continuous_function.has_neg,
..bounded_continuous_function.has_sub }
@[simp] lemma coe_sub : ⇑(f - g) = f - g := rfl
lemma sub_apply : (f - g) x = f x - g x := rfl
instance : normed_group (α →ᵇ β) :=
{ dist_eq := λ f g, by simp only [norm_eq, dist_eq, dist_eq_norm, sub_apply] }
lemma abs_diff_coe_le_dist : ∥f x - g x∥ ≤ dist f g :=
by { rw dist_eq_norm, exact (f - g).norm_coe_le_norm x }
lemma coe_le_coe_add_dist {f g : α →ᵇ ℝ} : f x ≤ g x + dist f g :=
sub_le_iff_le_add'.1 $ (abs_le.1 $ @dist_coe_le_dist _ _ _ _ f g x).2
lemma norm_comp_continuous_le [topological_space γ] (f : α →ᵇ β) (g : C(γ, α)) :
∥f.comp_continuous g∥ ≤ ∥f∥ :=
((lipschitz_comp_continuous g).dist_le_mul f 0).trans $
by rw [nnreal.coe_one, one_mul, dist_zero_right]
end normed_group
section has_bounded_smul
/-!
### `has_bounded_smul` (in particular, topological module) structure
In this section, if `β` is a metric space and a `𝕜`-module whose addition and scalar multiplication
are compatible with the metric structure, then we show that the space of bounded continuous
functions from `α` to `β` inherits a so-called `has_bounded_smul` structure (in particular, a
`has_continuous_mul` structure, which is the mathlib formulation of being a topological module), by
using pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*} [metric_space 𝕜] [semiring 𝕜]
variables [topological_space α] [metric_space β] [add_comm_monoid β]
[module 𝕜 β] [has_bounded_smul 𝕜 β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
instance : has_scalar 𝕜 (α →ᵇ β) :=
⟨λ c f,
bounded_continuous_function.mk_of_bound
(c • f.to_continuous_map)
(dist c 0 * (classical.some f.bounded))
begin
intros x y,
refine (dist_smul_pair c (f x) (f y)).trans _,
refine mul_le_mul_of_nonneg_left _ dist_nonneg,
exact classical.some_spec f.bounded x y
end ⟩
@[simp] lemma coe_smul (c : 𝕜) (f : α →ᵇ β) : ⇑(c • f) = λ x, c • (f x) := rfl
lemma smul_apply (c : 𝕜) (f : α →ᵇ β) (x : α) : (c • f) x = c • f x := rfl
instance : has_bounded_smul 𝕜 (α →ᵇ β) :=
{ dist_smul_pair' := λ c f₁ f₂, begin
rw dist_le (mul_nonneg dist_nonneg dist_nonneg),
intros x,
refine (dist_smul_pair c (f₁ x) (f₂ x)).trans _,
exact mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg
end,
dist_pair_smul' := λ c₁ c₂ f, begin
rw dist_le (mul_nonneg dist_nonneg dist_nonneg),
intros x,
refine (dist_pair_smul c₁ c₂ (f x)).trans _,
convert mul_le_mul_of_nonneg_left (dist_coe_le_dist x) dist_nonneg,
simp
end }
variables [has_lipschitz_add β]
instance : module 𝕜 (α →ᵇ β) :=
{ smul := (•),
smul_add := λ c f g, ext $ λ x, smul_add c (f x) (g x),
add_smul := λ c₁ c₂ f, ext $ λ x, add_smul c₁ c₂ (f x),
mul_smul := λ c₁ c₂ f, ext $ λ x, mul_smul c₁ c₂ (f x),
one_smul := λ f, ext $ λ x, one_smul 𝕜 (f x),
smul_zero := λ c, ext $ λ x, smul_zero c,
zero_smul := λ f, ext $ λ x, zero_smul 𝕜 (f x),
.. bounded_continuous_function.add_comm_monoid }
variables (𝕜)
/-- The evaluation at a point, as a continuous linear map from `α →ᵇ β` to `β`. -/
def eval_clm (x : α) : (α →ᵇ β) →L[𝕜] β :=
{ to_fun := λ f, f x,
map_add' := λ f g, by simp only [pi.add_apply, coe_add],
map_smul' := λ c f, by simp only [coe_smul, ring_hom.id_apply] }
@[simp] lemma eval_clm_apply (x : α) (f : α →ᵇ β) :
eval_clm 𝕜 x f = f x := rfl
variables (α β)
/-- The linear map forgetting that a bounded continuous function is bounded. -/
@[simps]
def to_continuous_map_linear_map : (α →ᵇ β) →ₗ[𝕜] C(α, β) :=
{ to_fun := to_continuous_map,
map_smul' := by { intros, ext, simp, },
map_add' := by { intros, ext, simp, }, }
end has_bounded_smul
section normed_space
/-!
### Normed space structure
In this section, if `β` is a normed space, then we show that the space of bounded
continuous functions from `α` to `β` inherits a normed space structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*}
variables [topological_space α] [normed_group β]
variables {f g : α →ᵇ β} {x : α} {C : ℝ}
instance [normed_field 𝕜] [normed_space 𝕜 β] : normed_space 𝕜 (α →ᵇ β) := ⟨λ c f, begin
refine norm_of_normed_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,
exact (λ x, trans_rel_right _ (norm_smul _ _)
(mul_le_mul_of_nonneg_left (f.norm_coe_le_norm _) (norm_nonneg _))) end⟩
variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 β]
variables [normed_group γ] [normed_space 𝕜 γ]
variables (α)
-- TODO does this work in the `has_bounded_smul` setting, too?
/--
Postcomposition of bounded continuous functions into a normed module by a continuous linear map is
a continuous linear map.
Upgraded version of `continuous_linear_map.comp_left_continuous`, similar to
`linear_map.comp_left`. -/
protected def _root_.continuous_linear_map.comp_left_continuous_bounded (g : β →L[𝕜] γ) :
(α →ᵇ β) →L[𝕜] (α →ᵇ γ) :=
linear_map.mk_continuous
{ to_fun := λ f, of_normed_group
(g ∘ f)
(g.continuous.comp f.continuous)
(∥g∥ * ∥f∥)
(λ x, (g.le_op_norm_of_le (f.norm_coe_le_norm x))),
map_add' := λ f g, by ext; simp,
map_smul' := λ c f, by ext; simp }
∥g∥
(λ f, norm_of_normed_group_le _ (mul_nonneg (norm_nonneg g) (norm_nonneg f)) _)
@[simp] lemma _root_.continuous_linear_map.comp_left_continuous_bounded_apply (g : β →L[𝕜] γ)
(f : α →ᵇ β) (x : α) :
(g.comp_left_continuous_bounded α f) x = g (f x) :=
rfl
end normed_space
section normed_ring
/-!
### Normed ring structure
In this section, if `R` is a normed ring, then we show that the space of bounded
continuous functions from `α` to `R` inherits a normed ring structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] {R : Type*} [normed_ring R]
instance : ring (α →ᵇ R) :=
{ one := const α 1,
mul := λ f g, of_normed_group (f * g) (f.continuous.mul g.continuous) (∥f∥ * ∥g∥) $ λ x,
le_trans (normed_ring.norm_mul (f x) (g x)) $
mul_le_mul (f.norm_coe_le_norm x) (g.norm_coe_le_norm x) (norm_nonneg _) (norm_nonneg _),
one_mul := λ f, ext $ λ x, one_mul (f x),
mul_one := λ f, ext $ λ x, mul_one (f x),
mul_assoc := λ f₁ f₂ f₃, ext $ λ x, mul_assoc _ _ _,
left_distrib := λ f₁ f₂ f₃, ext $ λ x, left_distrib _ _ _,
right_distrib := λ f₁ f₂ f₃, ext $ λ x, right_distrib _ _ _,
.. bounded_continuous_function.add_comm_group }
@[simp] lemma coe_mul (f g : α →ᵇ R) : ⇑(f * g) = f * g := rfl
lemma mul_apply (f g : α →ᵇ R) (x : α) : (f * g) x = f x * g x := rfl
instance : normed_ring (α →ᵇ R) :=
{ norm_mul := λ f g, norm_of_normed_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,
.. bounded_continuous_function.normed_group }
end normed_ring
section normed_comm_ring
/-!
### Normed commutative ring structure
In this section, if `R` is a normed commutative ring, then we show that the space of bounded
continuous functions from `α` to `R` inherits a normed commutative ring structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables [topological_space α] {R : Type*} [normed_comm_ring R]
instance : comm_ring (α →ᵇ R) :=
{ mul_comm := λ f₁ f₂, ext $ λ x, mul_comm _ _,
.. bounded_continuous_function.ring }
instance : normed_comm_ring (α →ᵇ R) :=
{ .. bounded_continuous_function.comm_ring, .. bounded_continuous_function.normed_group }
end normed_comm_ring
section normed_algebra
/-!
### Normed algebra structure
In this section, if `γ` is a normed algebra, then we show that the space of bounded
continuous functions from `α` to `γ` inherits a normed algebra structure, by using
pointwise operations and checking that they are compatible with the uniform distance. -/
variables {𝕜 : Type*} [normed_field 𝕜]
variables [topological_space α] [normed_group β] [normed_space 𝕜 β]
variables [normed_ring γ] [normed_algebra 𝕜 γ]
variables {f g : α →ᵇ γ} {x : α} {c : 𝕜}
/-- `bounded_continuous_function.const` as a `ring_hom`. -/
def C : 𝕜 →+* (α →ᵇ γ) :=
{ to_fun := λ (c : 𝕜), const α ((algebra_map 𝕜 γ) c),
map_one' := ext $ λ x, (algebra_map 𝕜 γ).map_one,
map_mul' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_mul _ _,
map_zero' := ext $ λ x, (algebra_map 𝕜 γ).map_zero,
map_add' := λ c₁ c₂, ext $ λ x, (algebra_map 𝕜 γ).map_add _ _ }
instance : algebra 𝕜 (α →ᵇ γ) :=
{ to_ring_hom := C,
commutes' := λ c f, ext $ λ x, algebra.commutes' _ _,
smul_def' := λ c f, ext $ λ x, algebra.smul_def' _ _,
..bounded_continuous_function.module,
..bounded_continuous_function.ring }
@[simp] lemma algebra_map_apply (k : 𝕜) (a : α) :
algebra_map 𝕜 (α →ᵇ γ) k a = k • 1 :=
by { rw algebra.algebra_map_eq_smul_one, refl, }
instance [nonempty α] : normed_algebra 𝕜 (α →ᵇ γ) :=
{ norm_algebra_map_eq := λ c, begin
calc ∥ (algebra_map 𝕜 (α →ᵇ γ)).to_fun c∥ = ∥(algebra_map 𝕜 γ) c∥ : _
... = ∥c∥ : norm_algebra_map_eq _ _,
apply norm_const_eq ((algebra_map 𝕜 γ) c), assumption,
end,
..bounded_continuous_function.algebra }
/-!
### Structure as normed module over scalar functions
If `β` is a normed `𝕜`-space, then we show that the space of bounded continuous
functions from `α` to `β` is naturally a module over the algebra of bounded continuous
functions from `α` to `𝕜`. -/
instance has_scalar' : has_scalar (α →ᵇ 𝕜) (α →ᵇ β) :=
⟨λ (f : α →ᵇ 𝕜) (g : α →ᵇ β), of_normed_group (λ x, (f x) • (g x))
(f.continuous.smul g.continuous) (∥f∥ * ∥g∥) (λ x, calc
∥f x • g x∥ ≤ ∥f x∥ * ∥g x∥ : normed_space.norm_smul_le _ _
... ≤ ∥f∥ * ∥g∥ : mul_le_mul (f.norm_coe_le_norm _) (g.norm_coe_le_norm _) (norm_nonneg _)
(norm_nonneg _)) ⟩
instance module' : module (α →ᵇ 𝕜) (α →ᵇ β) :=
module.of_core $
{ smul := (•),
smul_add := λ c f₁ f₂, ext $ λ x, smul_add _ _ _,
add_smul := λ c₁ c₂ f, ext $ λ x, add_smul _ _ _,
mul_smul := λ c₁ c₂ f, ext $ λ x, mul_smul _ _ _,
one_smul := λ f, ext $ λ x, one_smul 𝕜 (f x) }
lemma norm_smul_le (f : α →ᵇ 𝕜) (g : α →ᵇ β) : ∥f • g∥ ≤ ∥f∥ * ∥g∥ :=
norm_of_normed_group_le _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _
/- TODO: When `normed_module` has been added to `normed_space.basic`, the above facts
show that the space of bounded continuous functions from `α` to `β` is naturally a normed
module over the algebra of bounded continuous functions from `α` to `𝕜`. -/
end normed_algebra
lemma nnreal.upper_bound {α : Type*} [topological_space α]
(f : α →ᵇ ℝ≥0) (x : α) : f x ≤ nndist f 0 :=
begin
have key : nndist (f x) ((0 : α →ᵇ ℝ≥0) x) ≤ nndist f 0,
{ exact @dist_coe_le_dist α ℝ≥0 _ _ f 0 x, },
simp only [coe_zero, pi.zero_apply] at key,
rwa nnreal.nndist_zero_eq_val' (f x) at key,
end
/-!
### Star structures
In this section, if `β` is a normed ⋆-group, then so is the space of bounded
continuous functions from `α` to `β`, by using the star operation pointwise.
If `𝕜` is normed field and a ⋆-ring over which `β` is a normed algebra and a
star module, then the space of bounded continuous functions from `α` to `β`
is a star module.
If `β` is a ⋆-ring in addition to being a normed ⋆-group, then `α →ᵇ β`
inherits a ⋆-ring structure.
In summary, if `β` is a C⋆-algebra over `𝕜`, then so is `α →ᵇ β`; note that
completeness is guaranteed when `β` is complete (see
`bounded_continuous_function.complete`). -/
section normed_group
variables {𝕜 : Type*} [normed_field 𝕜] [star_ring 𝕜]
variables [topological_space α] [normed_group β] [star_add_monoid β] [normed_star_monoid β]
variables [normed_space 𝕜 β] [star_module 𝕜 β]
instance : star_add_monoid (α →ᵇ β) :=
{ star := λ f, f.comp star star_normed_group_hom.lipschitz,
star_involutive := λ f, ext $ λ x, star_star (f x),
star_add := λ f g, ext $ λ x, star_add (f x) (g x) }
/-- The right-hand side of this equality can be parsed `star ∘ ⇑f` because of the
instance `pi.has_star`. Upon inspecting the goal, one sees `⊢ ⇑(star f) = star ⇑f`.-/
@[simp] lemma coe_star (f : α →ᵇ β) : ⇑(star f) = star f := rfl
@[simp] lemma star_apply (f : α →ᵇ β) (x : α) : star f x = star (f x) := rfl
instance : normed_star_monoid (α →ᵇ β) :=
{ norm_star := λ f, by
{ simp only [norm_eq], congr, ext, conv_lhs { find (∥_∥) { erw (@norm_star β _ _ _ (f x)) } } } }
instance : star_module 𝕜 (α →ᵇ β) :=
{ star_smul := λ k f, ext $ λ x, star_smul k (f x) }
end normed_group
section cstar_ring
variables [topological_space α]
variables [normed_ring β] [star_ring β]
instance [normed_star_monoid β] : star_ring (α →ᵇ β) :=
{ star_mul := λ f g, ext $ λ x, star_mul (f x) (g x),
..bounded_continuous_function.star_add_monoid }
variable [cstar_ring β]
instance : cstar_ring (α →ᵇ β) :=
{ norm_star_mul_self :=
begin
intro f,
refine le_antisymm _ _,
{ rw [←sq, norm_le (sq_nonneg _)],
dsimp [star_apply],
intro x,
rw [cstar_ring.norm_star_mul_self, ←sq],
refine sq_le_sq' _ _,
{ linarith [norm_nonneg (f x), norm_nonneg f] },
{ exact norm_coe_le_norm f x }, },
{ rw [←sq, ←real.le_sqrt (norm_nonneg _) (norm_nonneg _), norm_le (real.sqrt_nonneg _)],
intro x,
rw [real.le_sqrt (norm_nonneg _) (norm_nonneg _), sq, ←cstar_ring.norm_star_mul_self],
exact norm_coe_le_norm (star f * f) x }
end }
end cstar_ring
section normed_lattice_ordered_group
variables [topological_space α] [normed_lattice_add_comm_group β]
instance : partial_order (α →ᵇ β) := partial_order.lift (λ f, f.to_fun) (by tidy)
/--
Continuous normed lattice group valued functions form a meet-semilattice
-/
instance : semilattice_inf (α →ᵇ β) :=
{ inf := λ f g,
{ to_fun := λ t, f t ⊓ g t,
continuous_to_fun := f.continuous.inf g.continuous,
bounded' := begin
cases f.bounded' with C₁ hf,
cases g.bounded' with C₂ hg,
refine ⟨C₁ + C₂, λ x y, _⟩,
simp_rw normed_group.dist_eq at hf hg ⊢,
exact (norm_inf_sub_inf_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)),
end },
inf_le_left := λ f g, continuous_map.le_def.mpr (λ _, inf_le_left),
inf_le_right := λ f g, continuous_map.le_def.mpr (λ _, inf_le_right),
le_inf := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, le_inf (continuous_map.le_def.mp w₁ _)
(continuous_map.le_def.mp w₂ _)),
..bounded_continuous_function.partial_order }
instance : semilattice_sup (α →ᵇ β) :=
{ sup := λ f g,
{ to_fun := λ t, f t ⊔ g t,
continuous_to_fun := f.continuous.sup g.continuous,
bounded' := begin
cases f.bounded' with C₁ hf,
cases g.bounded' with C₂ hg,
refine ⟨C₁ + C₂, λ x y, _⟩,
simp_rw normed_group.dist_eq at hf hg ⊢,
exact (norm_sup_sub_sup_le_add_norm _ _ _ _).trans (add_le_add (hf _ _) (hg _ _)),
end },
le_sup_left := λ f g, continuous_map.le_def.mpr (λ _, le_sup_left),
le_sup_right := λ f g, continuous_map.le_def.mpr (λ _, le_sup_right),
sup_le := λ f g₁ g₂ w₁ w₂, continuous_map.le_def.mpr (λ _, sup_le (continuous_map.le_def.mp w₁ _)
(continuous_map.le_def.mp w₂ _)),
..bounded_continuous_function.partial_order }
instance : lattice (α →ᵇ β) :=
{ .. bounded_continuous_function.semilattice_sup, .. bounded_continuous_function.semilattice_inf }
@[simp] lemma coe_fn_sup (f g : α →ᵇ β) : ⇑(f ⊔ g) = f ⊔ g := rfl
@[simp] lemma coe_fn_abs (f : α →ᵇ β) : ⇑|f| = |f| := rfl
instance : normed_lattice_add_comm_group (α →ᵇ β) :=
{ add_le_add_left := begin
intros f g h₁ h t,
simp only [coe_to_continuous_fun, pi.add_apply, add_le_add_iff_left, coe_add,
continuous_map.to_fun_eq_coe],
exact h₁ _,
end,
solid :=
begin
intros f g h,
have i1: ∀ t, ∥f t∥ ≤ ∥g t∥ := λ t, solid (h t),
rw norm_le (norm_nonneg _),
exact λ t, (i1 t).trans (norm_coe_le_norm g t),
end,
..bounded_continuous_function.lattice, }
end normed_lattice_ordered_group
end bounded_continuous_function
|
b69f29ccc1e82fddc201dce314f456dbb5fc859b
|
cf39355caa609c0f33405126beee2739aa3cb77e
|
/tests/lean/run/constructor_cases.lean
|
590f151539ce97c9a5737c46a8dc6155bc37df23
|
[
"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
| 910
|
lean
|
example (p q r : Prop) : p → q → r → r ∧ p ∧ q :=
begin
intros hp hq hr,
with_cases { repeat { constructor } },
case left { exact hr },
case right left { exact hp },
case right right { exact hq }
end
example (p q r : Prop) : p → q → r → r ∧ p ∧ q :=
begin
intros hp hq hr,
with_cases { repeat { constructor } },
case right left { exact hp },
case right right { exact hq },
case left { exact hr }
end
example (p q r : Prop) : p → q → r → r ∧ p ∧ q :=
begin
intros hp hq hr,
with_cases { repeat { split } },
case right left { exact hp },
case right right { exact hq },
case left { exact hr }
end
open tactic
example (n : nat) : nat :=
begin
with_cases { right },
/- The tactic `right` should not extend the tag since nat.succ has only one argument. -/
(do t : list name ← get_main_tag, trace t, guard (t.tail = [])),
case { exact n }
end
|
17cae0a0daced66ae928ca4fe8261aa2dd015e77
|
649957717d58c43b5d8d200da34bf374293fe739
|
/src/data/equiv/denumerable.lean
|
091a74b63a4dfe3d05b3dc82d4a562b365ced53a
|
[
"Apache-2.0"
] |
permissive
|
Vtec234/mathlib
|
b50c7b21edea438df7497e5ed6a45f61527f0370
|
fb1848bbbfce46152f58e219dc0712f3289d2b20
|
refs/heads/master
| 1,592,463,095,113
| 1,562,737,749,000
| 1,562,737,749,000
| 196,202,858
| 0
| 0
|
Apache-2.0
| 1,562,762,338,000
| 1,562,762,337,000
| null |
UTF-8
|
Lean
| false
| false
| 8,833
|
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 data.sigma data.fintype 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
@[simp] 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] 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 lattice
variables {s : set ℕ} [decidable_pred s] [infinite s]
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, multiset.mem_filter, -multiset.range_succ]⟩
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, t]; intros; refl,
if ht : t = [] then ⟨0, le_antisymm (@bot_le s _ _)
(le_of_not_gt (λ h, list.not_mem_nil ⊥ $
by rw [← ht, hmt]; exact h))⟩
else by letI : inhabited s := ⟨⊥⟩;
exact have wf : (list.maximum t).1 < x, by simpa [hmt] using list.maximum_mem ht,
let ⟨a, ha⟩ := of_nat_surjective_aux (list.maximum t).2 in
⟨a + 1, le_antisymm
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf)) $
by rw of_nat; exact le_succ_of_forall_lt_le
(λ z hz, by rw ha; exact list.le_maximum_of_mem (hmt.2 hz))⟩
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, 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
|
9fdd61d63cb41cf9c44c62be8774a766c316f7eb
|
5756a081670ba9c1d1d3fca7bd47cb4e31beae66
|
/Test/importMathbin/ImportMathbin.lean
|
e83c9558f59518fbb32c95f4e0da6c59a8bcd47d
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathport
|
2c9bdc8292168febf59799efdc5451dbf0450d4a
|
13051f68064f7638970d39a8fecaede68ffbf9e1
|
refs/heads/master
| 1,693,841,364,079
| 1,693,813,111,000
| 1,693,813,111,000
| 379,357,010
| 27
| 10
|
Apache-2.0
| 1,691,309,132,000
| 1,624,384,521,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 83
|
lean
|
import Mathbin
#lookup3 algebraic_geometry.Scheme
#check AlgebraicGeometry.Scheme
|
136675b3a101306859731bf08f2eaf319e534869
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/do_eqv_proofs.lean
|
6b822d3dd1ee2b44e3c70edd4277e81e460dd755
|
[
"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
| 612
|
lean
|
theorem ex1 [Monad m] [LawfulMonad m] (b : Bool) (ma : m α) (mb : α → m α) :
(do let mut x ← ma
if b then
x ← mb x
pure x)
=
(ma >>= fun x => if b then mb x else pure x) := by
cases b <;> simp
attribute [simp] map_eq_pure_bind seq_eq_bind_map
theorem ex2 [Monad m] [LawfulMonad m] (b : Bool) (ma : m α) (mb : α → m α) (a : α) :
(do let mut x ← ma
if b then
x ← mb x
pure x)
=
(StateT.run' (m := m)
(do ma >>= set
if b then get >>= fun x => mb x >>= set
get) a) := by
cases b <;> simp
|
a62fc8201c0b01615a3315214a7bf03865f54c7c
|
130c49f47783503e462c16b2eff31933442be6ff
|
/stage0/src/Lean/Server/Rpc/Basic.lean
|
9254288f160bf5927b670b0baa082f035e6632ea
|
[
"Apache-2.0"
] |
permissive
|
Hazel-Brown/lean4
|
8aa5860e282435ffc30dcdfccd34006c59d1d39c
|
79e6732fc6bbf5af831b76f310f9c488d44e7a16
|
refs/heads/master
| 1,689,218,208,951
| 1,629,736,869,000
| 1,629,736,896,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 4,541
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Wojciech Nawrocki
-/
import Lean.Data.Lsp.Extra
/-! Allows LSP clients to make Remote Procedure Calls to the server.
The single use case for these is to allow the infoview UI to refer to and manipulate heavy-weight
objects residing on the server. It would be inefficient to serialize these into JSON and send over.
For example, the client can format an `Expr` without transporting the whole `Environment`.
All RPC requests are relative to an open file and an RPC session for that file. The client must
first connect to the session using `$/lean/rpc/connect`. -/
namespace Lean.Server
/-- Monads with an RPC session in their state. -/
class MonadRpcSession (m : Type → Type) where
rpcSessionId : m UInt64
rpcStoreRef (typeName : Name) (obj : NonScalar) : m Lsp.RpcRef
rpcGetRef (r : Lsp.RpcRef) : m (Option (Name × NonScalar))
rpcReleaseRef (r : Lsp.RpcRef) : m Bool
export MonadRpcSession (rpcSessionId rpcStoreRef rpcGetRef rpcReleaseRef)
instance {m n : Type → Type} [MonadLift m n] [MonadRpcSession m] : MonadRpcSession n where
rpcSessionId := liftM (rpcSessionId : m _)
rpcStoreRef typeName obj := liftM (rpcStoreRef typeName obj : m _)
rpcGetRef r := liftM (rpcGetRef r : m _)
rpcReleaseRef r := liftM (rpcReleaseRef r : m _)
/-- `RpcEncoding α β` means that `α` may participate in RPC calls with its on-the-wire LSP encoding
being `β`. This is useful when `α` contains fields which must be marshalled in a special way. In
particular, we encode `WithRpcRef` fields as opaque references rather than send their content.
Structures with `From/ToJson` use JSON as their `RpcEncoding`. Structures containing
non-JSON-serializable fields can be auto-encoded in two ways:
- `deriving RpcEncoding` acts like `From/ToJson` but marshalls any `WithRpcRef` fields
as `Lsp.RpcRef`s.
- `deriving RpcEncoding with { withRef := true }` generates an encoding for
`WithRpcRef TheType`. -/
-- TODO(WN): for Lean.js, have third parameter defining the client-side structure;
-- or, compile `WithRpcRef` to "opaque reference" on the client
class RpcEncoding (α : Type) (β : outParam Type) where
rpcEncode {m : Type → Type} [Monad m] [MonadRpcSession m] : α → m β
-- TODO(WN): ExceptT String or RpcError where | InvalidSession | InvalidParams (msg : String) | ..
rpcDecode {m : Type → Type} [Monad m] [MonadRpcSession m] : β → ExceptT String m α
export RpcEncoding (rpcEncode rpcDecode)
instance [FromJson α] [ToJson α] : RpcEncoding α α where
rpcEncode := pure
rpcDecode := pure
instance [RpcEncoding α β] : RpcEncoding (Option α) (Option β) where
rpcEncode v := match v with
| none => none
| some v => some <$> rpcEncode v
rpcDecode v := match v with
| none => none
| some v => some <$> rpcDecode v
-- TODO(WN): instance [RpcEncoding α β] [Traversable t] : RpcEncoding (t α) (t β)
instance [RpcEncoding α β] : RpcEncoding (Array α) (Array β) where
rpcEncode a := a.mapM rpcEncode
rpcDecode b := b.mapM rpcDecode
instance [RpcEncoding α α'] [RpcEncoding β β'] : RpcEncoding (α × β) (α' × β') where
rpcEncode := fun (a, b) => do
let a' ← rpcEncode a
let b' ← rpcEncode b
return (a', b')
rpcDecode := fun (a', b') => do
let a ← rpcDecode a'
let b ← rpcDecode b'
return (a, b)
structure RpcEncoding.DerivingParams where
withRef : Bool := false
/-- Marks fields to encode as opaque references in LSP packets. -/
structure WithRpcRef (α : Type u) where
val : α
namespace WithRpcRef
variable {m : Type → Type} [Monad m] [MonadRpcSession m]
/-- This is unsafe because we must ensure that:
- the stored `NonScalar` is never used to access the value as a type other than `α`
- the type `α` is not a scalar
-/
protected unsafe def encodeUnsafe [Monad m] (typeName : Name) (r : WithRpcRef α) : m Lsp.RpcRef := do
let obj := @unsafeCast α NonScalar r.val
rpcStoreRef typeName obj
protected unsafe def decodeUnsafeAs (α) (typeName : Name) (r : Lsp.RpcRef) : ExceptT String m (WithRpcRef α) := do
match (← rpcGetRef r) with
| none => throw s!"RPC reference '{r}' is not valid"
| some (nm, obj) =>
if nm != typeName then
throw s!"RPC call type mismatch in reference '{r}'\nexpected '{typeName}', got '{nm}'"
WithRpcRef.mk <| @unsafeCast NonScalar α obj
end WithRpcRef
end Lean.Server
|
d900c258dd98dedac7d2f443ffa9cd8a2c42bb24
|
bbecf0f1968d1fba4124103e4f6b55251d08e9c4
|
/src/algebra/module/submodule_lattice.lean
|
65ee4271dab8487ddc01f85a4cd090c1a4827f54
|
[
"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
| 8,783
|
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, Kevin Buzzard, Yury Kudryashov
-/
import algebra.module.submodule
import algebra.punit_instances
/-!
# The lattice structure on `submodule`s
This file defines the lattice structure on submodules, `submodule.complete_lattice`, with `⊥`
defined as `{0}` and `⊓` defined as intersection of the underlying carrier.
If `p` and `q` are submodules of a module, `p ≤ q` means that `p ⊆ q`.
Many results about operations on this lattice structure are defined in `linear_algebra/basic.lean`,
most notably those which use `span`.
## Implementation notes
This structure should match the `add_submonoid.complete_lattice` structure, and we should try
to unify the APIs where possible.
-/
variables {R S M : Type*}
section add_comm_monoid
variables [semiring R] [semiring S] [add_comm_monoid M] [module R M] [module S M]
variables [has_scalar S R] [is_scalar_tower S R M]
variables {p q : submodule R M}
namespace submodule
/-- The set `{0}` is the bottom element of the lattice of submodules. -/
instance : has_bot (submodule R M) :=
⟨{ carrier := {0}, smul_mem' := by simp { contextual := tt }, .. (⊥ : add_submonoid M)}⟩
instance inhabited' : inhabited (submodule R M) := ⟨⊥⟩
@[simp] lemma bot_coe : ((⊥ : submodule R M) : set M) = {0} := rfl
@[simp] lemma bot_to_add_submonoid : (⊥ : submodule R M).to_add_submonoid = ⊥ := rfl
section
variables (R)
@[simp] lemma restrict_scalars_bot : restrict_scalars S (⊥ : submodule R M) = ⊥ := rfl
@[simp] lemma mem_bot {x : M} : x ∈ (⊥ : submodule R M) ↔ x = 0 := set.mem_singleton_iff
end
instance unique_bot : unique (⊥ : submodule R M) :=
⟨infer_instance, λ x, subtype.ext $ (mem_bot R).1 x.mem⟩
lemma nonzero_mem_of_bot_lt {I : submodule R M} (bot_lt : ⊥ < I) : ∃ a : I, a ≠ 0 :=
begin
have h := (set_like.lt_iff_le_and_exists.1 bot_lt).2,
tidy,
end
instance : order_bot (submodule R M) :=
{ bot := ⊥,
bot_le := λ p x, by simp {contextual := tt},
..set_like.partial_order }
protected lemma eq_bot_iff (p : submodule R M) : p = ⊥ ↔ ∀ x ∈ p, x = (0 : M) :=
⟨ λ h, h.symm ▸ λ x hx, (mem_bot R).mp hx,
λ h, eq_bot_iff.mpr (λ x hx, (mem_bot R).mpr (h x hx)) ⟩
@[ext] protected lemma bot_ext (x y : (⊥ : submodule R M)) : x = y :=
begin
rcases x with ⟨x, xm⟩, rcases y with ⟨y, ym⟩, congr,
rw (submodule.eq_bot_iff _).mp rfl x xm,
rw (submodule.eq_bot_iff _).mp rfl y ym,
end
protected lemma ne_bot_iff (p : submodule R M) : p ≠ ⊥ ↔ ∃ x ∈ p, x ≠ (0 : M) :=
by { haveI := classical.prop_decidable, simp_rw [ne.def, p.eq_bot_iff, not_forall] }
/-- The bottom submodule is linearly equivalent to punit as an `R`-module. -/
@[simps] def bot_equiv_punit : (⊥ : submodule R M) ≃ₗ[R] punit :=
{ to_fun := λ x, punit.star,
inv_fun := λ x, 0,
map_add' := by { intros, ext, },
map_smul' := by { intros, ext, },
left_inv := by { intro x, ext, },
right_inv := by { intro x, ext, }, }
/-- The universal set is the top element of the lattice of submodules. -/
instance : has_top (submodule R M) :=
⟨{ carrier := set.univ, smul_mem' := λ _ _ _, trivial, .. (⊤ : add_submonoid M)}⟩
@[simp] lemma top_coe : ((⊤ : submodule R M) : set M) = set.univ := rfl
@[simp] lemma top_to_add_submonoid : (⊤ : submodule R M).to_add_submonoid = ⊤ := rfl
@[simp] lemma mem_top {x : M} : x ∈ (⊤ : submodule R M) := trivial
section
variables (R)
@[simp] lemma restrict_scalars_top : restrict_scalars S (⊤ : submodule R M) = ⊤ := rfl
end
instance : order_top (submodule R M) :=
{ top := ⊤,
le_top := λ p x _, trivial,
..set_like.partial_order }
lemma eq_top_iff' {p : submodule R M} : p = ⊤ ↔ ∀ x, x ∈ p :=
eq_top_iff.trans ⟨λ h x, h trivial, λ h x _, h x⟩
/-- The top submodule is linearly equivalent to the module. -/
@[simps] def top_equiv_self : (⊤ : submodule R M) ≃ₗ[R] M :=
{ to_fun := λ x, x,
inv_fun := λ x, ⟨x, by simp⟩,
map_add' := by { intros, refl, },
map_smul' := by { intros, refl, },
left_inv := by { intro x, ext, refl, },
right_inv := by { intro x, refl, }, }
instance : has_Inf (submodule R M) :=
⟨λ S, {
carrier := ⋂ s ∈ S, (s : set M),
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }⟩
private lemma Inf_le' {S : set (submodule R M)} {p} : p ∈ S → Inf S ≤ p :=
set.bInter_subset_of_mem
private lemma le_Inf' {S : set (submodule R M)} {p} : (∀q ∈ S, p ≤ q) → p ≤ Inf S :=
set.subset_bInter
instance : has_inf (submodule R M) :=
⟨λ p q, {
carrier := p ∩ q,
zero_mem' := by simp,
add_mem' := by simp [add_mem] {contextual := tt},
smul_mem' := by simp [smul_mem] {contextual := tt} }⟩
instance : complete_lattice (submodule R M) :=
{ sup := λ a b, Inf {x | a ≤ x ∧ b ≤ x},
le_sup_left := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, ha,
le_sup_right := λ a b, le_Inf' $ λ x ⟨ha, hb⟩, hb,
sup_le := λ a b c h₁ h₂, Inf_le' ⟨h₁, h₂⟩,
inf := (⊓),
le_inf := λ a b c, set.subset_inter,
inf_le_left := λ a b, set.inter_subset_left _ _,
inf_le_right := λ a b, set.inter_subset_right _ _,
Sup := λtt, Inf {t | ∀t'∈tt, t' ≤ t},
le_Sup := λ s p hs, le_Inf' $ λ q hq, hq _ hs,
Sup_le := λ s p hs, Inf_le' hs,
Inf := Inf,
le_Inf := λ s a, le_Inf',
Inf_le := λ s a, Inf_le',
..submodule.order_top,
..submodule.order_bot }
@[simp] theorem inf_coe : (p ⊓ q : set M) = p ∩ q := rfl
@[simp] theorem mem_inf {p q : submodule R M} {x : M} :
x ∈ p ⊓ q ↔ x ∈ p ∧ x ∈ q := iff.rfl
@[simp] theorem Inf_coe (P : set (submodule R M)) : (↑(Inf P) : set M) = ⋂ p ∈ P, ↑p := rfl
@[simp] theorem infi_coe {ι} (p : ι → submodule R M) :
(↑⨅ i, p i : set M) = ⋂ i, ↑(p i) :=
by rw [infi, Inf_coe]; ext a; simp; exact
⟨λ h i, h _ i rfl, λ h i x e, e ▸ h _⟩
@[simp] lemma mem_Inf {S : set (submodule R M)} {x : M} : x ∈ Inf S ↔ ∀ p ∈ S, x ∈ p :=
set.mem_bInter_iff
@[simp] theorem mem_infi {ι} (p : ι → submodule R M) {x} :
x ∈ (⨅ i, p i) ↔ ∀ i, x ∈ p i :=
by rw [← set_like.mem_coe, infi_coe, set.mem_Inter]; refl
lemma mem_sup_left {S T : submodule R M} : ∀ {x : M}, x ∈ S → x ∈ S ⊔ T :=
show S ≤ S ⊔ T, from le_sup_left
lemma mem_sup_right {S T : submodule R M} : ∀ {x : M}, x ∈ T → x ∈ S ⊔ T :=
show T ≤ S ⊔ T, from le_sup_right
lemma add_mem_sup {S T : submodule R M} {s t : M} (hs : s ∈ S) (ht : t ∈ T) : s + t ∈ S ⊔ T :=
add_mem _ (mem_sup_left hs) (mem_sup_right ht)
lemma mem_supr_of_mem {ι : Sort*} {b : M} {p : ι → submodule R M} (i : ι) (h : b ∈ p i) :
b ∈ (⨆i, p i) :=
have p i ≤ (⨆i, p i) := le_supr p i,
@this b h
open_locale big_operators
lemma sum_mem_supr {ι : Type*} [fintype ι] {f : ι → M} {p : ι → submodule R M}
(h : ∀ i, f i ∈ p i) :
∑ i, f i ∈ ⨆ i, p i :=
sum_mem _ $ λ i hi, mem_supr_of_mem i (h i)
lemma sum_mem_bsupr {ι : Type*} {s : finset ι} {f : ι → M} {p : ι → submodule R M}
(h : ∀ i ∈ s, f i ∈ p i) :
∑ i in s, f i ∈ ⨆ i ∈ s, p i :=
sum_mem _ $ λ i hi, mem_supr_of_mem i $ mem_supr_of_mem hi (h i hi)
/-! Note that `submodule.mem_supr` is provided in `linear_algebra/basic.lean`. -/
lemma mem_Sup_of_mem {S : set (submodule R M)} {s : submodule R M}
(hs : s ∈ S) : ∀ {x : M}, x ∈ s → x ∈ Sup S :=
show s ≤ Sup S, from le_Sup hs
end submodule
section nat_submodule
/-- An additive submonoid is equivalent to a ℕ-submodule. -/
def add_submonoid.to_nat_submodule : add_submonoid M ≃o submodule ℕ M :=
{ to_fun := λ S,
{ smul_mem' := λ r s hs, S.nsmul_mem hs _, ..S },
inv_fun := submodule.to_add_submonoid,
left_inv := λ ⟨S, _, _⟩, rfl,
right_inv := λ ⟨S, _, _, _⟩, rfl,
map_rel_iff' := λ a b, iff.rfl }
@[simp]
lemma add_submonoid.to_nat_submodule_symm :
⇑(add_submonoid.to_nat_submodule.symm : _ ≃o add_submonoid M) = submodule.to_add_submonoid := rfl
@[simp]
lemma add_submonoid.coe_to_nat_submodule (S : add_submonoid M) :
(S.to_nat_submodule : set M) = S := rfl
@[simp]
lemma add_submonoid.to_nat_submodule_to_add_submonoid (S : add_submonoid M) :
S.to_nat_submodule.to_add_submonoid = S :=
add_submonoid.to_nat_submodule.symm_apply_apply S
@[simp]
lemma submodule.to_add_submonoid_to_nat_submodule (S : submodule ℕ M) :
S.to_add_submonoid.to_nat_submodule = S :=
add_submonoid.to_nat_submodule.apply_symm_apply S
end nat_submodule
end add_comm_monoid
|
3282ab6907a1a41bfef1001d253fa67ebc7226f2
|
7cdf3413c097e5d36492d12cdd07030eb991d394
|
/src/game/world3/level5.lean
|
0cb4dc6f77a214dbb3a3cd2581ce2f6abd721097
|
[] |
no_license
|
alreadydone/natural_number_game
|
3135b9385a9f43e74cfbf79513fc37e69b99e0b3
|
1a39e693df4f4e871eb449890d3c7715a25c2ec9
|
refs/heads/master
| 1,599,387,390,105
| 1,573,200,587,000
| 1,573,200,691,000
| 220,397,084
| 0
| 0
| null | 1,573,192,734,000
| 1,573,192,733,000
| null |
UTF-8
|
Lean
| false
| false
| 1,158
|
lean
|
import game.world3.level4 -- hide
import mynat.mul -- hide
namespace mynat -- hide
/-
# Multiplication World
## Level 5: `mul_assoc`
Currently our tools for multiplication include the
following:
* `mul_zero m : m * 0 = 0`
* `zero_mul m : 0 * m = 0`
* `mul_succ a b : a * succ b = a * b + a`
* `mul_add t a b : t * (a + b) = t * a + t * b`
These things above are the tools we need to prove that multiplication is associative.
## Random tactic hints
1) Did you know you can do `repeat {rw mul_succ}`?
2) Did you know you can do `rwa [hd, mul_add]`? (I learnt that trick from Ken Lee)
-/
/- Lemma
Multiplication is associative.
In other words, for all natural numbers $a$, $b$ and $c$, we have
$$ (ab)c = a(bc). $$
-/
lemma mul_assoc (a b c : mynat) : (a * b) * c = a * (b * c) :=
begin [less_leaky]
induction c with d hd,
{
repeat {rw mul_zero},
},
{
rw mul_succ,
rw mul_succ,
rw hd,
rw mul_add,
refl,
}
end
/-
A mathematician could now remark that you have proved that the natural
numbers form a monoid under multiplication.
-/
def collectible_4 : monoid mynat := by structure_helper -- hide
end mynat -- hide
|
4fe7862cda0bce79f94b06ba3148cd9b057faf43
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/fresh_names_auto.lean
|
d9924f8ad83b8a729be39fc28533d9a86f9dffea
|
[] |
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
| 987
|
lean
|
/-
Copyright (c) 2020 Jannis Limperg. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jannis Limperg
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.sum
import Mathlib.meta.rb_map
import Mathlib.tactic.dependencies
import Mathlib.PostPort
namespace Mathlib
/-!
# Tactics for giving hypotheses fresh names
When introducing hypotheses, we often want to make sure that their names are
fresh, i.e. not used by any other hypothesis in the context. This file provides
tactics which allow you to give a list of possible names for each hypothesis,
with the tactics picking the first name that is not yet used in the context. If
all names are already used, the tactics use a name derived from the first name
in the list.
-/
namespace tactic
-- This implementation is a bit of a hack, but probably fine in practice since
-- we're unlikely to need more than two or three iterations of the loop.
end Mathlib
|
c7a9aa1fb38eb8dd08da502ed27d9e183b3f38ad
|
57c233acf9386e610d99ed20ef139c5f97504ba3
|
/src/ring_theory/witt_vector/identities.lean
|
5c98a4fe921e888a88e7d161f20e558d3d611910
|
[
"Apache-2.0"
] |
permissive
|
robertylewis/mathlib
|
3d16e3e6daf5ddde182473e03a1b601d2810952c
|
1d13f5b932f5e40a8308e3840f96fc882fae01f0
|
refs/heads/master
| 1,651,379,945,369
| 1,644,276,960,000
| 1,644,276,960,000
| 98,875,504
| 0
| 0
|
Apache-2.0
| 1,644,253,514,000
| 1,501,495,700,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,750
|
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 ring_theory.witt_vector.frobenius
import ring_theory.witt_vector.verschiebung
import ring_theory.witt_vector.mul_p
/-!
## Identities between operations on the ring of Witt vectors
In this file we derive common identities between the Frobenius and Verschiebung operators.
## Main declarations
* `frobenius_verschiebung`: the composition of Frobenius and Verschiebung is multiplication by `p`
* `verschiebung_mul_frobenius`: the “projection formula”: `V(x * F y) = V x * y`
* `iterate_verschiebung_mul_coeff`: an identity from [Haze09] 6.2
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
namespace witt_vector
variables {p : ℕ} {R : Type*} [hp : fact p.prime] [comm_ring R]
local notation `𝕎` := witt_vector p -- type as `\bbW`
include hp
noncomputable theory
/-- The composition of Frobenius and Verschiebung is multiplication by `p`. -/
lemma frobenius_verschiebung (x : 𝕎 R) :
frobenius (verschiebung x) = x * p :=
by { ghost_calc x, ghost_simp [mul_comm] }
/-- Verschiebung is the same as multiplication by `p` on the ring of Witt vectors of `zmod p`. -/
lemma verschiebung_zmod (x : 𝕎 (zmod p)) :
verschiebung x = x * p :=
by rw [← frobenius_verschiebung, frobenius_zmodp]
lemma coeff_p_pow [char_p R p] (i : ℕ) : (p ^ i : 𝕎 R).coeff i = 1 :=
begin
induction i with i h,
{ simp only [one_coeff_zero, ne.def, pow_zero] },
{ rw [pow_succ', ← frobenius_verschiebung, coeff_frobenius_char_p,
verschiebung_coeff_succ, h, one_pow], }
end
lemma coeff_p_pow_eq_zero [char_p R p] {i j : ℕ} (hj : j ≠ i) : (p ^ i : 𝕎 R).coeff j = 0 :=
begin
induction i with i hi generalizing j,
{ rw [pow_zero, one_coeff_eq_of_pos],
exact nat.pos_of_ne_zero hj },
{ rw [pow_succ', ← frobenius_verschiebung, coeff_frobenius_char_p],
cases j,
{ rw [verschiebung_coeff_zero, zero_pow],
exact nat.prime.pos hp.out },
{ rw [verschiebung_coeff_succ, hi, zero_pow],
{ exact nat.prime.pos hp.out },
{ exact ne_of_apply_ne (λ (j : ℕ), j.succ) hj } } }
end
/-- The “projection formula” for Frobenius and Verschiebung. -/
lemma verschiebung_mul_frobenius (x y : 𝕎 R) :
verschiebung (x * frobenius y) = verschiebung x * y :=
by { ghost_calc x y, rintro ⟨⟩; ghost_simp [mul_assoc] }
lemma mul_char_p_coeff_zero [char_p R p] (x : 𝕎 R) : (x * p).coeff 0 = 0 :=
begin
rw [← frobenius_verschiebung, coeff_frobenius_char_p, verschiebung_coeff_zero, zero_pow],
exact nat.prime.pos hp.out
end
lemma mul_char_p_coeff_succ [char_p R p] (x : 𝕎 R) (i : ℕ) :
(x * p).coeff (i + 1) = (x.coeff i)^p :=
by rw [← frobenius_verschiebung, coeff_frobenius_char_p, verschiebung_coeff_succ]
lemma verschiebung_frobenius [char_p R p] (x : 𝕎 R) :
verschiebung (frobenius x) = x * p :=
begin
ext ⟨i⟩,
{ rw [mul_char_p_coeff_zero, verschiebung_coeff_zero], },
{ rw [mul_char_p_coeff_succ, verschiebung_coeff_succ, coeff_frobenius_char_p], }
end
lemma verschiebung_frobenius_comm [char_p R p] :
function.commute (verschiebung : 𝕎 R → 𝕎 R) frobenius :=
λ x, by rw [verschiebung_frobenius, frobenius_verschiebung]
/-!
## Iteration lemmas
-/
open function
lemma iterate_verschiebung_coeff (x : 𝕎 R) (n k : ℕ) :
(verschiebung^[n] x).coeff (k + n) = x.coeff k :=
begin
induction n with k ih,
{ simp },
{ rw [iterate_succ_apply', nat.add_succ, verschiebung_coeff_succ],
exact ih }
end
lemma iterate_verschiebung_mul_left (x y : 𝕎 R) (i : ℕ) :
(verschiebung^[i] x) * y = (verschiebung^[i] (x * (frobenius^[i] y))) :=
begin
induction i with i ih generalizing y,
{ simp },
{ rw [iterate_succ_apply', ← verschiebung_mul_frobenius, ih, iterate_succ_apply'], refl }
end
section char_p
variable [char_p R p]
lemma iterate_verschiebung_mul (x y : 𝕎 R) (i j : ℕ) :
(verschiebung^[i] x) * (verschiebung^[j] y) =
(verschiebung^[i + j] ((frobenius^[j] x) * (frobenius^[i] y))) :=
begin
calc
_ = (verschiebung^[i] (x * (frobenius^[i] ((verschiebung^[j] y))))) : _
... = (verschiebung^[i] (x * (verschiebung^[j] ((frobenius^[i] y))))) : _
... = (verschiebung^[i] ((verschiebung^[j] ((frobenius^[i] y)) * x))) : _
... = (verschiebung^[i] ((verschiebung^[j] ((frobenius^[i] y) * (frobenius^[j] x))))) : _
... = (verschiebung^[i + j] ((frobenius^[i] y) * (frobenius^[j] x))) : _
... = _ : _,
{ apply iterate_verschiebung_mul_left },
{ rw verschiebung_frobenius_comm.iterate_iterate; apply_instance },
{ rw mul_comm },
{ rw iterate_verschiebung_mul_left },
{ rw iterate_add_apply },
{ rw mul_comm }
end
lemma iterate_frobenius_coeff (x : 𝕎 R) (i k : ℕ) :
((frobenius^[i] x)).coeff k = (x.coeff k)^(p^i) :=
begin
induction i with i ih,
{ simp },
{ rw [iterate_succ_apply', coeff_frobenius_char_p, ih],
ring_exp }
end
/-- This is a slightly specialized form of [Hazewinkel, *Witt Vectors*][Haze09] 6.2 equation 5. -/
lemma iterate_verschiebung_mul_coeff (x y : 𝕎 R) (i j : ℕ) :
((verschiebung^[i] x) * (verschiebung^[j] y)).coeff (i + j) =
(x.coeff 0)^(p ^ j) * (y.coeff 0)^(p ^ i) :=
begin
calc
_ = (verschiebung^[i + j] ((frobenius^[j] x) * (frobenius^[i] y))).coeff (i + j) : _
... = ((frobenius^[j] x) * (frobenius^[i] y)).coeff 0 : _
... = (frobenius^[j] x).coeff 0 * ((frobenius^[i] y)).coeff 0 : _
... = _ : _,
{ rw iterate_verschiebung_mul },
{ convert iterate_verschiebung_coeff _ _ _ using 2,
rw zero_add },
{ apply mul_coeff_zero },
{ simp only [iterate_frobenius_coeff] }
end
end char_p
end witt_vector
|
8df022f9fa1556bf0c070e63dd4c880661152fe2
|
6dc0c8ce7a76229dd81e73ed4474f15f88a9e294
|
/stage0/src/Lean/Parser/StrInterpolation.lean
|
25322b4825f9b906e79e4081a6c4b0f84c7f1610
|
[
"Apache-2.0"
] |
permissive
|
williamdemeo/lean4
|
72161c58fe65c3ad955d6a3050bb7d37c04c0d54
|
6d00fcf1d6d873e195f9220c668ef9c58e9c4a35
|
refs/heads/master
| 1,678,305,356,877
| 1,614,708,995,000
| 1,614,708,995,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,786
|
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.Parser.Basic
namespace Lean.Parser
def isQuotableCharForStrInterpolant (c : Char) : Bool :=
c == '{' || isQuotableCharDefault c
partial def interpolatedStrFn (p : ParserFn) : ParserFn := fun c s =>
let input := c.input
let stackSize := s.stackSize
let rec parse (startPos : Nat) (c : ParserContext) (s : ParserState) : ParserState :=
let i := s.pos
if input.atEnd i then
s.mkEOIError
else
let curr := input.get i
let s := s.setPos (input.next i)
if curr == '\"' then
let s := mkNodeToken interpolatedStrLitKind startPos c s
s.mkNode interpolatedStrKind stackSize
else if curr == '\\' then
andthenFn (quotedCharCoreFn isQuotableCharForStrInterpolant) (parse startPos) c s
else if curr == '{' then
let s := mkNodeToken interpolatedStrLitKind startPos c s
let s := p c s
if s.hasError then s
else
let pos := s.pos
andthenFn (satisfyFn (· == '}') "expected '}'") (parse pos) c s
else
parse startPos c s
let startPos := s.pos
if input.atEnd startPos then
s.mkEOIError
else
let curr := input.get s.pos;
if curr != '\"' then
s.mkError "interpolated string"
else
let s := s.next input startPos
parse startPos c s
@[inline] def interpolatedStrNoAntiquot (p : Parser) : Parser := {
fn := interpolatedStrFn p.fn,
info := mkAtomicInfo "interpolatedStr"
}
def interpolatedStr (p : Parser) : Parser :=
withAntiquot (mkAntiquot "interpolatedStr" interpolatedStrKind) $ interpolatedStrNoAntiquot p
end Lean.Parser
|
b3fd9717309ce7c4b7c620e7d9e15b048224d100
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/analysis/inner_product_space/of_norm.lean
|
7c36dba00df14b273e17f36689d81e9f1c3d41bb
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 16,022
|
lean
|
/-
Copyright (c) 2020 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import topology.algebra.algebra
import analysis.inner_product_space.basic
/-!
# Inner product space derived from a norm
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines an `inner_product_space` instance from a norm that respects the
parallellogram identity. The parallelogram identity is a way to express the inner product of `x` and
`y` in terms of the norms of `x`, `y`, `x + y`, `x - y`.
## Main results
- `inner_product_space.of_norm`: a normed space whose norm respects the parallellogram identity,
can be seen as an inner product space.
## Implementation notes
We define `inner_`
$$\langle x, y \rangle := \frac{1}{4} (‖x + y‖^2 - ‖x - y‖^2 + i ‖ix + y‖ ^ 2 - i ‖ix - y‖^2)$$
and use the parallelogram identity
$$‖x + y‖^2 + ‖x - y‖^2 = 2 (‖x‖^2 + ‖y‖^2)$$
to prove it is an inner product, i.e., that it is conjugate-symmetric (`inner_.conj_symm`) and
linear in the first argument. `add_left` is proved by judicious application of the parallelogram
identity followed by tedious arithmetic. `smul_left` is proved step by step, first noting that
$\langle λ x, y \rangle = λ \langle x, y \rangle$ for $λ ∈ ℕ$, $λ = -1$, hence $λ ∈ ℤ$ and $λ ∈ ℚ$
by arithmetic. Then by continuity and the fact that ℚ is dense in ℝ, the same is true for ℝ.
The case of ℂ then follows by applying the result for ℝ and more arithmetic.
## TODO
Move upstream to `analysis.inner_product_space.basic`.
## References
- [Jordan, P. and von Neumann, J., *On inner products in linear, metric spaces*][Jordan1935]
- https://math.stackexchange.com/questions/21792/norms-induced-by-inner-products-and-the-parallelogram-law
- https://math.dartmouth.edu/archive/m113w10/public_html/jordan-vneumann-thm.pdf
## Tags
inner product space, Hilbert space, norm
-/
open is_R_or_C
open_locale complex_conjugate
variables {𝕜 : Type*} [is_R_or_C 𝕜] (E : Type*) [normed_add_comm_group E]
/-- Predicate for the parallelogram identity to hold in a normed group. This is a scalar-less
version of `inner_product_space`. If you have an `inner_product_spaceable` assumption, you can
locally upgrade that to `inner_product_space 𝕜 E` using `casesI nonempty_inner_product_space 𝕜 E`.
-/
class inner_product_spaceable : Prop :=
(parallelogram_identity :
∀ x y : E, ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖))
variables (𝕜) {E}
lemma inner_product_space.to_inner_product_spaceable [inner_product_space 𝕜 E] :
inner_product_spaceable E :=
⟨parallelogram_law_with_norm 𝕜⟩
@[priority 100] -- See note [lower instance priority]
instance inner_product_space.to_inner_product_spaceable_of_real [inner_product_space ℝ E] :
inner_product_spaceable E :=
⟨parallelogram_law_with_norm ℝ⟩
variables [normed_space 𝕜 E]
local notation `𝓚` := algebra_map ℝ 𝕜
/-- Auxiliary definition of the inner product derived from the norm. -/
private noncomputable def inner_ (x y : E) : 𝕜 :=
4⁻¹ * ((𝓚 ‖x + y‖) * (𝓚 ‖x + y‖) - (𝓚 ‖x - y‖) * (𝓚 ‖x - y‖)
+ (I:𝕜) * (𝓚 ‖(I:𝕜) • x + y‖) * (𝓚 ‖(I:𝕜) • x + y‖)
- (I:𝕜) * (𝓚 ‖(I:𝕜) • x - y‖) * (𝓚 ‖(I:𝕜) • x - y‖))
namespace inner_product_spaceable
variables {𝕜} (E)
/-- Auxiliary definition for the `add_left` property -/
private def inner_prop (r : 𝕜) : Prop := ∀ x y : E, inner_ 𝕜 (r • x) y = conj r * inner_ 𝕜 x y
variables {E}
lemma inner_prop_neg_one : inner_prop E ((-1 : ℤ) : 𝕜) :=
begin
intros x y,
simp only [inner_, neg_mul_eq_neg_mul, one_mul, int.cast_one, one_smul, ring_hom.map_one,
map_neg, int.cast_neg, neg_smul, neg_one_mul],
rw neg_mul_comm,
congr' 1,
have h₁ : ‖-x - y‖ = ‖x + y‖,
{ rw [←neg_add', norm_neg], },
have h₂ : ‖-x + y‖ = ‖x - y‖,
{ rw [←neg_sub, norm_neg, sub_eq_neg_add], },
have h₃ : ‖(I : 𝕜) • (-x) + y‖ = ‖(I : 𝕜) • x - y‖,
{ rw [←neg_sub, norm_neg, sub_eq_neg_add, ←smul_neg], },
have h₄ : ‖(I : 𝕜) • (-x) - y‖ = ‖(I : 𝕜) • x + y‖,
{ rw [smul_neg, ←neg_add', norm_neg] },
rw [h₁, h₂, h₃, h₄],
ring,
end
lemma continuous.inner_ {f g : ℝ → E} (hf : continuous f) (hg : continuous g) :
continuous (λ x, inner_ 𝕜 (f x) (g x)) :=
by { unfold inner_, continuity }
lemma inner_.norm_sq (x : E) : ‖x‖ ^ 2 = re (inner_ 𝕜 x x) :=
begin
simp only [inner_],
have h₁ : norm_sq (4 : 𝕜) = 16,
{ have : ((4 : ℝ) : 𝕜) = (4 : 𝕜),
{ simp only [of_real_one, of_real_bit0] },
rw [←this, norm_sq_eq_def',
is_R_or_C.norm_of_nonneg (by norm_num : (0 : ℝ) ≤ 4)],
norm_num },
have h₂ : ‖x + x‖ = 2 * ‖x‖,
{ rw [←two_smul 𝕜, norm_smul, is_R_or_C.norm_two] },
simp only [inner, h₁, h₂, one_im, bit0_zero, add_zero, norm_zero, I_re, of_real_im, map_add,
bit0_im, zero_div, zero_mul, add_monoid_hom.map_neg, of_real_re, map_sub, sub_zero, inv_re,
one_re, inv_im, bit0_re, mul_re, mul_zero, sub_self, neg_zero, algebra_map_eq_of_real],
ring,
end
lemma inner_.conj_symm (x y : E) : conj (inner_ 𝕜 y x) = inner_ 𝕜 x y :=
begin
simp only [inner_],
have h4 : conj (4⁻¹ : 𝕜) = 4⁻¹,
{ rw [is_R_or_C.conj_inv, ←of_real_one, ←of_real_bit0, ←of_real_bit0, conj_of_real] },
rw [map_mul, h4],
congr' 1,
simp only [map_sub, map_add, algebra_map_eq_of_real, ←of_real_mul, conj_of_real, map_mul, conj_I],
rw [add_comm y x, norm_sub_rev],
by_cases hI : (I : 𝕜) = 0,
{ simp only [hI, neg_zero, zero_mul] },
have h₁ : ‖(I : 𝕜) • y - x‖ = ‖(I : 𝕜) • x + y‖,
{ transitivity ‖(I : 𝕜) • ((I : 𝕜) • y - x)‖,
{ rw [norm_smul, norm_I_of_ne_zero hI, one_mul] },
{ rw [smul_sub, smul_smul, I_mul_I_of_nonzero hI, neg_one_smul, ←neg_add', add_comm,
norm_neg] } },
have h₂ : ‖(I : 𝕜) • y + x‖ = ‖(I : 𝕜) • x - y‖,
{ transitivity ‖(I : 𝕜) • ((I : 𝕜) • y + x)‖,
{ rw [norm_smul, norm_I_of_ne_zero hI, one_mul] },
{ rw [smul_add, smul_smul, I_mul_I_of_nonzero hI, neg_one_smul, ←neg_add_eq_sub] }},
rw [h₁, h₂, ←sub_add_eq_add_sub],
simp only [neg_mul, sub_eq_add_neg, neg_neg],
end
variables [inner_product_spaceable E]
private lemma add_left_aux1 (x y z : E) :
‖x + y + z‖ * ‖x + y + z‖ =
(‖2 • x + y‖ * ‖2 • x + y‖ + ‖2 • z + y‖ * ‖2 • z + y‖) / 2 - ‖x - z‖ * ‖x - z‖ :=
begin
rw [eq_sub_iff_add_eq, eq_div_iff (two_ne_zero' ℝ), mul_comm _ (2 : ℝ), eq_comm],
convert parallelogram_identity (x + y + z) (x - z) using 4; { rw two_smul, abel }
end
private lemma add_left_aux2 (x y z : E) :
‖x + y - z‖ * ‖x + y - z‖ =
(‖2 • x + y‖ * ‖2 • x + y‖ + ‖y - 2 • z‖ * ‖y - 2 • z‖) / 2 - ‖x + z‖ * ‖x + z‖ :=
begin
rw [eq_sub_iff_add_eq, eq_div_iff (two_ne_zero' ℝ), mul_comm _ (2 : ℝ), eq_comm],
have h₀ := parallelogram_identity (x + y - z) (x + z),
convert h₀ using 4; { rw two_smul, abel }
end
private lemma add_left_aux2' (x y z : E) :
‖x + y + z‖ * ‖x + y + z‖ - ‖x + y - z‖ * ‖x + y - z‖ =
‖x + z‖ * ‖x + z‖ - ‖x - z‖ * ‖x - z‖ +
(‖2 • z + y‖ * ‖2 • z + y‖ - ‖y - 2 • z‖ * ‖y - 2 • z‖) / 2 :=
by { rw [add_left_aux1 , add_left_aux2], ring }
private lemma add_left_aux3 (y z : E) :
‖2 • z + y‖ * ‖2 • z + y‖ = 2 * (‖y + z‖ * ‖y + z‖ + ‖z‖ * ‖z‖) - ‖y‖ * ‖y‖ :=
begin
apply eq_sub_of_add_eq,
convert parallelogram_identity (y + z) z using 4; { try { rw two_smul }, abel }
end
private lemma add_left_aux4 (y z : E) :
‖y - 2 • z‖ * ‖y - 2 • z‖ = 2 * (‖y - z‖ * ‖y - z‖ + ‖z‖ * ‖z‖) - ‖y‖ * ‖y‖ :=
begin
apply eq_sub_of_add_eq',
have h₀ := parallelogram_identity (y - z) z,
convert h₀ using 4; { try { rw two_smul }, abel }
end
private lemma add_left_aux4' (y z : E) :
(‖2 • z + y‖ * ‖2 • z + y‖ - ‖y - 2 • z‖ * ‖y - 2 • z‖) / 2 =
(‖y + z‖ * ‖y + z‖) - (‖y - z‖ * ‖y - z‖) :=
by { rw [add_left_aux3 , add_left_aux4], ring }
private lemma add_left_aux5 (x y z : E) :
‖(I : 𝕜) • (x + y) + z‖ * ‖(I : 𝕜) • (x + y) + z‖ =
(‖(I : 𝕜) • (2 • x + y)‖ * ‖(I : 𝕜) • (2 • x + y)‖ +
‖(I : 𝕜) • y + 2 • z‖ * ‖(I : 𝕜) • y + 2 • z‖) / 2 - ‖(I : 𝕜) • x - z‖ * ‖(I : 𝕜) • x - z‖ :=
begin
rw [eq_sub_iff_add_eq, eq_div_iff (two_ne_zero' ℝ), mul_comm _ (2 : ℝ), eq_comm],
have h₀ := parallelogram_identity ((I : 𝕜) • (x + y) + z) ((I : 𝕜) • x - z),
convert h₀ using 4; { try { simp only [two_smul, smul_add] }, abel }
end
private lemma add_left_aux6 (x y z : E) :
‖(I : 𝕜) • (x + y) - z‖ * ‖(I : 𝕜) • (x + y) - z‖ =
(‖(I : 𝕜) • (2 • x + y)‖ * ‖(I : 𝕜) • (2 • x + y)‖ +
‖(I : 𝕜) • y - 2 • z‖ * ‖(I : 𝕜) • y - 2 • z‖) / 2 -
‖(I : 𝕜) • x + z‖ * ‖(I : 𝕜) • x + z‖ :=
begin
rw [eq_sub_iff_add_eq, eq_div_iff (two_ne_zero' ℝ), mul_comm _ (2 : ℝ), eq_comm],
have h₀ := parallelogram_identity ((I : 𝕜) • (x + y) - z) ((I : 𝕜) • x + z),
convert h₀ using 4; { try { simp only [two_smul, smul_add] }, abel }
end
private lemma add_left_aux7 (y z : E) :
‖(I : 𝕜) • y + 2 • z‖ * ‖(I : 𝕜) • y + 2 • z‖ =
2 * (‖(I : 𝕜) • y + z‖ * ‖(I : 𝕜) • y + z‖ + ‖z‖ * ‖z‖) - ‖(I : 𝕜) • y‖ * ‖(I : 𝕜) • y‖ :=
begin
apply eq_sub_of_add_eq,
have h₀ := parallelogram_identity ((I : 𝕜) • y + z) z,
convert h₀ using 4; { try { simp only [two_smul, smul_add] }, abel }
end
private lemma add_left_aux8 (y z : E) :
‖(I : 𝕜) • y - 2 • z‖ * ‖(I : 𝕜) • y - 2 • z‖ =
2 * (‖(I : 𝕜) • y - z‖ * ‖(I : 𝕜) • y - z‖ + ‖z‖ * ‖z‖) - ‖(I : 𝕜) • y‖ * ‖(I : 𝕜) • y‖ :=
begin
apply eq_sub_of_add_eq',
have h₀ := parallelogram_identity ((I : 𝕜) • y - z) z,
convert h₀ using 4; { try { simp only [two_smul, smul_add] }, abel }
end
lemma add_left (x y z : E) : inner_ 𝕜 (x + y) z = inner_ 𝕜 x z + inner_ 𝕜 y z :=
begin
simp only [inner_, ←mul_add],
congr,
simp only [mul_assoc, ←map_mul, add_sub_assoc, ←mul_sub, ←map_sub],
rw add_add_add_comm,
simp only [←map_add, ←mul_add],
congr,
{ rw [←add_sub_assoc, add_left_aux2', add_left_aux4'] },
{ rw [add_left_aux5, add_left_aux6, add_left_aux7, add_left_aux8],
simp only [map_sub, map_mul, map_add, div_eq_mul_inv],
ring }
end
lemma nat (n : ℕ) (x y : E) : inner_ 𝕜 ((n : 𝕜) • x) y = (n : 𝕜) * inner_ 𝕜 x y :=
begin
induction n with n ih,
{ simp only [inner_, nat.nat_zero_eq_zero, zero_sub, nat.cast_zero, zero_mul, eq_self_iff_true,
zero_smul, zero_add, mul_zero, sub_self, norm_neg, smul_zero], },
{ simp only [nat.cast_succ, add_smul, one_smul],
rw [add_left, ih, add_mul, one_mul] }
end
private lemma nat_prop (r : ℕ) : inner_prop E (r : 𝕜) :=
λ x y, by { simp only [map_nat_cast], exact nat r x y }
private lemma int_prop (n : ℤ) : inner_prop E (n : 𝕜) :=
begin
intros x y,
rw ←n.sign_mul_nat_abs,
simp only [int.cast_coe_nat, map_nat_cast, map_int_cast, int.cast_mul, map_mul, mul_smul],
obtain hn | rfl | hn := lt_trichotomy n 0,
{ rw [int.sign_eq_neg_one_of_neg hn, inner_prop_neg_one ((n.nat_abs : 𝕜) • x), nat],
simp only [map_neg, neg_mul, one_mul, mul_eq_mul_left_iff, true_or,
int.nat_abs_eq_zero, eq_self_iff_true, int.cast_one, map_one, neg_inj, nat.cast_eq_zero,
int.cast_neg] },
{ simp only [inner_, int.cast_zero, zero_sub, nat.cast_zero, zero_mul, eq_self_iff_true,
int.sign_zero, zero_smul, zero_add, mul_zero, smul_zero, sub_self, norm_neg,
int.nat_abs_zero] },
{ rw int.sign_eq_one_of_pos hn,
simp only [one_mul, mul_eq_mul_left_iff, true_or, int.nat_abs_eq_zero, eq_self_iff_true,
int.cast_one, one_smul, nat.cast_eq_zero, nat] }
end
private lemma rat_prop (r : ℚ) : inner_prop E (r : 𝕜) :=
begin
intros x y,
have : (r.denom : 𝕜) ≠ 0,
{ haveI : char_zero 𝕜 := is_R_or_C.char_zero_R_or_C,
exact_mod_cast r.pos.ne' },
rw [←r.num_div_denom, ←mul_right_inj' this, ←nat r.denom _ y, smul_smul, rat.cast_div],
simp only [map_nat_cast, rat.cast_coe_nat, map_int_cast, rat.cast_coe_int, map_div₀],
rw [←mul_assoc, mul_div_cancel' _ this, int_prop _ x, map_int_cast],
end
private lemma real_prop (r : ℝ) : inner_prop E (r : 𝕜) :=
begin
intros x y,
revert r,
rw ←function.funext_iff,
refine rat.dense_embedding_coe_real.dense.equalizer _ _ (funext $ λ X, _),
{ exact (continuous_of_real.smul continuous_const).inner_ continuous_const },
{ exact (continuous_conj.comp continuous_of_real).mul continuous_const },
{ simp only [function.comp_app, is_R_or_C.of_real_rat_cast, rat_prop _ _] }
end
private lemma I_prop : inner_prop E (I : 𝕜) :=
begin
by_cases hI : (I : 𝕜) = 0,
{ rw [hI, ←nat.cast_zero], exact nat_prop _ },
intros x y,
have hI' : (-I : 𝕜) * I = 1,
{ rw [←inv_I, inv_mul_cancel hI], },
rw [conj_I, inner_, inner_, mul_left_comm],
congr' 1,
rw [smul_smul, I_mul_I_of_nonzero hI, neg_one_smul],
rw [mul_sub, mul_add, mul_sub,
mul_assoc I (𝓚 ‖I • x - y‖), ←mul_assoc (-I) I, hI', one_mul,
mul_assoc I (𝓚 ‖I • x + y‖), ←mul_assoc (-I) I, hI', one_mul],
have h₁ : ‖-x - y‖ = ‖x + y‖,
{ rw [←neg_add', norm_neg], },
have h₂ : ‖-x + y‖ = ‖x - y‖,
{ rw [←neg_sub, norm_neg, sub_eq_neg_add], },
rw [h₁, h₂],
simp only [sub_eq_add_neg, mul_assoc],
rw [←neg_mul_eq_neg_mul, ←neg_mul_eq_neg_mul],
abel
end
lemma inner_prop (r : 𝕜) : inner_prop E r :=
begin
intros x y,
rw [←re_add_im r, add_smul, add_left, real_prop _ x, ←smul_smul, real_prop _ _ y, I_prop,
map_add, map_mul, conj_of_real, conj_of_real, conj_I],
ring,
end
end inner_product_spaceable
open inner_product_spaceable
/-- **Fréchet–von Neumann–Jordan Theorem**. A normed space `E` whose norm satisfies the
parallelogram identity can be given a compatible inner product. -/
noncomputable def inner_product_space.of_norm
(h : ∀ x y : E, ‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖)) :
inner_product_space 𝕜 E :=
begin
haveI : inner_product_spaceable E := ⟨h⟩,
exact
{ inner := inner_ 𝕜,
norm_sq_eq_inner := inner_.norm_sq,
conj_symm := inner_.conj_symm,
add_left := add_left,
smul_left := λ _ _ _, inner_prop _ _ _ }
end
variables (𝕜 E) [inner_product_spaceable E]
/-- **Fréchet–von Neumann–Jordan Theorem**. A normed space `E` whose norm satisfies the
parallelogram identity can be given a compatible inner product. Do
`casesI nonempty_inner_product_space 𝕜 E` to locally upgrade `inner_product_spaceable E` to
`inner_product_space 𝕜 E`. -/
lemma nonempty_inner_product_space : nonempty (inner_product_space 𝕜 E) :=
⟨{ inner := inner_ 𝕜,
norm_sq_eq_inner := inner_.norm_sq,
conj_symm := inner_.conj_symm,
add_left := add_left,
smul_left := λ _ _ _, inner_prop _ _ _ }⟩
variables {𝕜 E} [normed_space ℝ E]
-- TODO: Replace `inner_product_space.to_uniform_convex_space`
@[priority 100] -- See note [lower instance priority]
instance inner_product_spaceable.to_uniform_convex_space : uniform_convex_space E :=
by { casesI nonempty_inner_product_space ℝ E, apply_instance }
|
9b993d370cd3237c69644586dca2ccea485fe6fe
|
1446f520c1db37e157b631385707cc28a17a595e
|
/stage0/src/Init/Lean/Elab/Quotation.lean
|
26d0d9491d128afdbcf649718b6630ebcee372f5
|
[
"Apache-2.0"
] |
permissive
|
bdbabiak/lean4
|
cab06b8a2606d99a168dd279efdd404edb4e825a
|
3f4d0d78b2ce3ef541cb643bbe21496bd6b057ac
|
refs/heads/master
| 1,615,045,275,530
| 1,583,793,696,000
| 1,583,793,696,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 22,461
|
lean
|
/-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sebastian Ullrich
Elaboration of syntax quotations as terms and patterns (in `match_syntax`). See also `./Hygiene.lean` for the basic
hygiene workings and data types.
-/
prelude
import Init.Lean.Syntax
import Init.Lean.Elab.ResolveName
import Init.Lean.Elab.Term
import Init.Lean.Parser -- TODO: remove after removing old elaborator
/- TODO
Quotations are currently integrated hackily into the old frontend. This implies the following restrictions:
* quotations have to fit in a single line, because that's how the old scanner works :)
* `open` commands are not respected (but `export`, `namespace` are)
* antiquotation terms have to be trivial (locals, consts (w/ projections), and apps, basically)
After removing the old frontend, quotations in this and other files should be cleaned up.
-/
namespace Lean
/-- Reflect a runtime datum back to surface syntax (best-effort). -/
class HasQuote (α : Type) :=
(quote : α → Syntax)
export HasQuote (quote)
instance Syntax.HasQuote : HasQuote Syntax := ⟨id⟩
instance String.HasQuote : HasQuote String := ⟨fun s => Syntax.node `Lean.Parser.Term.str #[mkStxStrLit s]⟩
instance Nat.HasQuote : HasQuote Nat := ⟨fun n => Syntax.node `Lean.Parser.Term.num #[mkStxNumLit $ toString n]⟩
instance Substring.HasQuote : HasQuote Substring := ⟨fun s => mkCAppStx `String.toSubstring #[quote s.toString]⟩
private def quoteName : Name → Syntax
| Name.anonymous => mkCTermId `Lean.Name.anonymous
| Name.str n s _ => mkCAppStx `Lean.mkNameStr #[quoteName n, quote s]
| Name.num n i _ => mkCAppStx `Lean.mkNameNum #[quoteName n, quote i]
instance Name.hasQuote : HasQuote Name := ⟨quoteName⟩
instance Prod.hasQuote {α β : Type} [HasQuote α] [HasQuote β] : HasQuote (α × β) :=
⟨fun ⟨a, b⟩ => mkCAppStx `Prod.mk #[quote a, quote b]⟩
private def quoteList {α : Type} [HasQuote α] : List α → Syntax
| [] => mkCTermId `List.nil
| (x::xs) => mkCAppStx `List.cons #[quote x, quoteList xs]
instance List.hasQuote {α : Type} [HasQuote α] : HasQuote (List α) := ⟨quoteList⟩
instance Array.hasQuote {α : Type} [HasQuote α] : HasQuote (Array α) :=
⟨fun xs => mkCAppStx `List.toArray #[quote xs.toList]⟩
private def quoteOption {α : Type} [HasQuote α] : Option α → Syntax
| none => mkTermId `Option.none
| (some x) => mkCAppStx `Option.some #[quote x]
instance Option.hasQuote {α : Type} [HasQuote α] : HasQuote (Option α) := ⟨quoteOption⟩
namespace Elab
namespace Term
namespace Quotation
-- antiquotation node kinds are formed from the original node kind (if any) plus "antiquot"
def isAntiquot : Syntax → Bool
| Syntax.node (Name.str _ "antiquot" _) _ => true
| _ => false
-- Antiquotations can be escaped as in `$$x`, which is useful for nesting macros.
def isEscapedAntiquot (stx : Syntax) : Bool :=
!(stx.getArg 1).getArgs.isEmpty
def unescapeAntiquot (stx : Syntax) : Syntax :=
if isAntiquot stx then
stx.setArg 1 $ mkNullNode (stx.getArg 1).getArgs.pop
else stx
def getAntiquotTerm (stx : Syntax) : Syntax :=
let e := stx.getArg 2;
if e.isIdent then mkTermIdFromIdent e
else
-- `e` is from `"(" >> termParser >> ")"`
e.getArg 1
def antiquotKind? : Syntax → Option SyntaxNodeKind
| Syntax.node (Name.str k "antiquot" _) args =>
-- we treat all antiquotations where the kind was left implicit (`$e`) the same (see `elimAntiquotChoices`)
if (args.get! 3).isNone then some Name.anonymous
else some k
| _ => none
-- `$e*` is an antiquotation "splice" matching an arbitrary number of syntax nodes
def isAntiquotSplice (stx : Syntax) : Bool :=
isAntiquot stx && (stx.getArg 5).getOptional?.isSome
-- If any item of a `many` node is an antiquotation splice, its result should
-- be substituted into the `many` node's children
def isAntiquotSplicePat (stx : Syntax) : Bool :=
stx.isOfKind nullKind && stx.getArgs.any (fun arg => isAntiquotSplice arg && !isEscapedAntiquot arg)
/-- A term like `($e) is actually ambiguous: the antiquotation could be of kind `term`,
or `ident`, or ... . But it shouldn't really matter because antiquotations without
explicit kinds behave the same at runtime. So we replace `choice` nodes that contain
at least one implicit antiquotation with that antiquotation. -/
private partial def elimAntiquotChoices : Syntax → Syntax
| Syntax.node `choice args => match args.find? (fun arg => antiquotKind? arg == Name.anonymous) with
| some anti => anti
| none => Syntax.node `choice $ args.map elimAntiquotChoices
| Syntax.node k args => Syntax.node k $ args.map elimAntiquotChoices
| stx => stx
-- Elaborate the content of a syntax quotation term
private partial def quoteSyntax : Syntax → TermElabM Syntax
| Syntax.ident info rawVal val preresolved => do
-- Add global scopes at compilation time (now), add macro scope at runtime (in the quotation).
-- See the paper for details.
r ← resolveGlobalName val;
let preresolved := r ++ preresolved;
let val := quote val;
-- `scp` is bound in stxQuot.expand
`(Syntax.ident none $(quote rawVal) (addMacroScope mainModule $val scp) $(quote preresolved))
-- if antiquotation, insert contents as-is, else recurse
| stx@(Syntax.node k _) =>
if isAntiquot stx && !isEscapedAntiquot stx then
-- splices must occur in a `many` node
if isAntiquotSplice stx then throwError stx "unexpected antiquotation splice"
else pure $ getAntiquotTerm stx
else do
empty ← `(Array.empty);
-- if escaped antiquotation, decrement by one escape level
let stx := unescapeAntiquot stx;
args ← stx.getArgs.foldlM (fun args arg =>
if k == nullKind && isAntiquotSplice arg then
-- antiquotation splice pattern: inject args array
`(Array.append $args $(getAntiquotTerm arg))
else do
arg ← quoteSyntax arg;
`(Array.push $args $arg)) empty;
`(Syntax.node $(quote k) $args)
| Syntax.atom info val =>
`(Syntax.atom none $(quote val))
| Syntax.missing => unreachable!
def stxQuot.expand (stx : Syntax) : TermElabM Syntax := do
let quoted := stx.getArg 1;
/- Syntax quotations are monadic values depending on the current macro scope. For efficiency, we bind
the macro scope once for each quotation, then build the syntax tree in a completely pure computation
depending on this binding. Note that regular function calls do not introduce a new macro scope (i.e.
we preserve referential transparency), so we can refer to this same `scp` inside `quoteSyntax` by
including it literally in a syntax quotation. -/
-- TODO: simplify to `(do scp ← getCurrMacroScope; pure $(quoteSyntax quoted))
stx ← quoteSyntax (elimAntiquotChoices quoted);
`(bind getCurrMacroScope (fun scp => bind getMainModule (fun mainModule => pure $stx)))
/- NOTE: It may seem like the newly introduced binding `scp` may accidentally
capture identifiers in an antiquotation introduced by `quoteSyntax`. However,
note that the syntax quotation above enjoys the same hygiene guarantees as
anywhere else in Lean; that is, we implement hygienic quotations by making
use of the hygienic quotation support of the bootstrapped Lean compiler!
Aside: While this might sound "dangerous", it is in fact less reliant on a
"chain of trust" than other bootstrapping parts of Lean: because this
implementation itself never uses `scp` (or any other identifier) both inside
and outside quotations, it can actually correctly be compiled by an
unhygienic (but otherwise correct) implementation of syntax quotations. As
long as it is then compiled again with the resulting executable (i.e. up to
stage 2), the result is a correct hygienic implementation. In this sense the
implementation is "self-stabilizing". It was in fact originally compiled
by an unhygienic prototype implementation. -/
@[builtinTermElab stxQuot] def elabStxQuot : TermElab :=
adaptExpander stxQuot.expand
/- match_syntax -/
-- an "alternative" of patterns plus right-hand side
private abbrev Alt := List Syntax × Syntax
/-- Information on a pattern's head that influences the compilation of a single
match step. -/
structure HeadInfo :=
-- Node kind to match, if any
(kind : Option SyntaxNodeKind := none)
-- Nested patterns for each argument, if any. In a single match step, we only
-- check that the arity matches. The arity is usually implied by the node kind,
-- but not in the case of `many` nodes.
(argPats : Option (Array Syntax) := none)
-- Function to apply to the right-hand side in case the match succeeds. Used to
-- bind pattern variables.
(rhsFn : Syntax → TermElabM Syntax := pure)
instance HeadInfo.Inhabited : Inhabited HeadInfo := ⟨{}⟩
/-- `h1.generalizes h2` iff h1 is equal to or more general than h2, i.e. it matches all nodes
h2 matches. This induces a partial ordering. -/
def HeadInfo.generalizes : HeadInfo → HeadInfo → Bool
| { kind := none, .. }, _ => true
| { kind := some k1, argPats := none, .. },
{ kind := some k2, .. } => k1 == k2
| { kind := some k1, argPats := some ps1, .. },
{ kind := some k2, argPats := some ps2, .. } => k1 == k2 && ps1.size == ps2.size
| _, _ => false
private def getHeadInfo (alt : Alt) : HeadInfo :=
let pat := alt.fst.head!;
let unconditional (rhsFn) := { HeadInfo . rhsFn := rhsFn };
-- variable pattern
if pat.isOfKind `Lean.Parser.Term.id then unconditional $ fun rhs => `(let $pat := discr; $rhs)
-- wildcard pattern
else if pat.isOfKind `Lean.Parser.Term.hole then unconditional pure
-- quotation pattern
else if pat.isOfKind `Lean.Parser.Term.stxQuot then
let quoted := pat.getArg 1;
if quoted.isAtom then
-- We assume that atoms are uniquely determined by the node kind and never have to be checked
unconditional pure
else if isAntiquot quoted && !isEscapedAntiquot quoted then
-- quotation contains a single antiquotation
let k := antiquotKind? quoted;
-- Antiquotation kinds like `$id:id` influence the parser, but also need to be considered by
-- match_syntax (but not by quotation terms). For example, `($id:id) and `($e) are not
-- distinguishable without checking the kind of the node to be captured. Note that some
-- antiquotations like the latter one for terms do not correspond to any actual node kind
-- (signified by `k == Name.anonymous`), so we would only check for `Term.id` here.
--
-- if stx.isOfKind `Lean.Parser.Term.id then
-- let id := stx; ...
-- else
-- let e := stx; ...
let kind := if k == Name.anonymous then none else k;
let anti := getAntiquotTerm quoted;
-- Splices should only appear inside a nullKind node, see next case
if isAntiquotSplice quoted then unconditional $ fun _ => throwError quoted "unexpected antiquotation splice"
else if anti.isOfKind `Lean.Parser.Term.id then { kind := kind, rhsFn := fun rhs => `(let $anti := discr; $rhs) }
else unconditional $ fun _ => throwError anti ("match_syntax: antiquotation must be variable " ++ toString anti)
else if isAntiquotSplicePat quoted && quoted.getArgs.size == 1 then
-- quotation is a single antiquotation splice => bind args array
let anti := getAntiquotTerm (quoted.getArg 0);
unconditional $ fun rhs => `(let $anti := Syntax.getArgs discr; $rhs)
-- TODO: support for more complex antiquotation splices
else
-- not an antiquotation or escaped antiquotation: match head shape
let quoted := unescapeAntiquot quoted;
let argPats := quoted.getArgs.map $ fun arg => Syntax.node `Lean.Parser.Term.stxQuot #[mkAtom "`(", arg, mkAtom ")"];
{ kind := quoted.getKind, argPats := argPats }
else
unconditional $ fun _ => throwError pat ("match_syntax: unexpected pattern kind " ++ toString pat)
-- Assuming that the first pattern of the alternative is taken, replace it with patterns (if any) for its
-- child nodes.
-- Ex: `($a + (- $b)) => `($a), `(+), `(- $b)
-- Note: The atom pattern `(+) will be discarded in a later step
private def explodeHeadPat (numArgs : Nat) : HeadInfo × Alt → TermElabM Alt
| (info, (pat::pats, rhs)) => do
let newPats := match info.argPats with
| some argPats => argPats.toList
| none => List.replicate numArgs $ Unhygienic.run `(_);
rhs ← info.rhsFn rhs;
pure (newPats ++ pats, rhs)
| _ => unreachable!
private partial def compileStxMatch (ref : Syntax) : List Syntax → List Alt → TermElabM Syntax
| [], ([], rhs)::_ => pure rhs -- nothing left to match
| _, [] => throwError ref "non-exhaustive 'match_syntax'"
| discr::discrs, alts => do
let alts := (alts.map getHeadInfo).zip alts;
-- Choose a most specific pattern, ie. a minimal element according to `generalizes`.
-- If there are multiple minimal elements, the choice does not matter.
let (info, alt) := alts.tail!.foldl (fun (min : HeadInfo × Alt) (alt : HeadInfo × Alt) => if min.1.generalizes alt.1 then alt else min) alts.head!;
-- introduce pattern matches on the discriminant's children if there are any nested patterns
newDiscrs ← match info.argPats with
| some pats => (List.range pats.size).mapM $ fun i => `(Syntax.getArg discr $(quote i))
| none => pure [];
-- collect matching alternatives and explode them
let yesAlts := alts.filter $ fun (alt : HeadInfo × Alt) => alt.1.generalizes info;
yesAlts ← yesAlts.mapM $ explodeHeadPat newDiscrs.length;
-- NOTE: use fresh macro scopes for recursive call so that different `discr`s introduced by the quotations below do not collide
yes ← withFreshMacroScope $ compileStxMatch (newDiscrs ++ discrs) yesAlts;
some kind ← pure info.kind
-- unconditional match step
| `(let discr := $discr; $yes);
-- conditional match step
let noAlts := (alts.filter $ fun (alt : HeadInfo × Alt) => !info.generalizes alt.1).map Prod.snd;
no ← withFreshMacroScope $ compileStxMatch (discr::discrs) noAlts;
cond ← match info.argPats with
| some pats => `(Syntax.isOfKind discr $(quote kind) && Array.size (Syntax.getArgs discr) == $(quote pats.size))
| none => `(Syntax.isOfKind discr $(quote kind));
`(let discr := $discr; if $cond = true then $yes else $no)
| _, _ => unreachable!
private partial def getPatternVarsAux : Syntax → List Syntax
| stx@(Syntax.node k args) =>
if isAntiquot stx && !isEscapedAntiquot stx then
let anti := getAntiquotTerm stx;
if anti.isOfKind `Lean.Parser.Term.id then [anti]
else []
else
List.join $ args.toList.map getPatternVarsAux
| _ => []
-- Get all pattern vars (as Term.id nodes) in `stx`
partial def getPatternVars (stx : Syntax) : List Syntax :=
if stx.isOfKind `Lean.Parser.Term.stxQuot then do
let quoted := stx.getArg 1;
getPatternVarsAux stx
else if stx.isOfKind `Lean.Parser.Term.id then
[stx]
else []
-- Transform alternatives by binding all right-hand sides to outside the match_syntax in order to prevent
-- code duplication during match_syntax compilation
private def letBindRhss (cont : List Alt → TermElabM Syntax) : List Alt → List Alt → TermElabM Syntax
| [], altsRev' => cont altsRev'.reverse
| (pats, rhs)::alts, altsRev' => do
let vars := List.join $ pats.map getPatternVars;
match vars with
-- no antiquotations => introduce Unit parameter to preserve evaluation order
| [] => do
-- NOTE: references binding below
rhs' ← `(rhs ());
-- NOTE: new macro scope so that introduced bindings do not collide
stx ← withFreshMacroScope $ letBindRhss alts ((pats, rhs')::altsRev');
`(let rhs := fun _ => $rhs; $stx)
| _ => do
-- rhs ← `(fun $vars* => $rhs)
let rhs := Syntax.node `Lean.Parser.Term.fun #[mkAtom "fun", Syntax.node `null vars.toArray, mkAtom "=>", rhs];
rhs' ← `(rhs);
stx ← withFreshMacroScope $ letBindRhss alts ((pats, rhs')::altsRev');
`(let rhs := $rhs; $stx)
def match_syntax.expand (stx : Syntax) : TermElabM Syntax := do
let discr := stx.getArg 1;
let alts := stx.getArg 4;
alts ← alts.getArgs.getSepElems.mapM $ fun alt => do {
let pats := alt.getArg 0;
pat ← if pats.getArgs.size == 1 then pure $ pats.getArg 0
else throwError stx "match_syntax: expected exactly one pattern per alternative";
let pat := if pat.isOfKind `Lean.Parser.Term.stxQuot then pat.setArg 1 $ elimAntiquotChoices $ pat.getArg 1 else pat;
match pat.find? $ fun stx => stx.getKind == choiceKind with
| some choiceStx => throwError choiceStx "invalid pattern, nested syntax has multiple interpretations"
| none =>
let rhs := alt.getArg 2;
pure ([pat], rhs)
};
-- letBindRhss (compileStxMatch stx [discr]) alts.toList []
compileStxMatch stx [discr] alts.toList
@[builtinTermElab «match_syntax»] def elabMatchSyntax : TermElab :=
adaptExpander match_syntax.expand
-- REMOVE with old frontend
private def exprPlaceholder := mkMVar Name.anonymous
private unsafe partial def toPreterm : Syntax → TermElabM Expr
| stx =>
let args := stx.getArgs;
match stx.getKind with
| `Lean.Parser.Term.id =>
match args.get! 0 with
| Syntax.ident _ _ val preresolved => do
resolved ← resolveName stx val preresolved [];
match resolved with
| (pre,projs)::_ =>
let pre := match pre with
| Expr.const c _ _ => Lean.mkConst c -- remove universes confusing the old frontend
| _ => pre;
pure $ projs.foldl (fun e proj => mkMData (MData.empty.setName `fieldNotation proj) e) pre
| [] => unreachable!
| _ => unreachable!
| `Lean.Parser.Term.fun => do
let params := (args.get! 1).getArgs;
let body := args.get! 3;
if params.size == 0 then toPreterm body
else do
let param := params.get! 0;
(n, ty) ← if param.isOfKind `Lean.Parser.Term.id then
pure (param.getIdAt 0, exprPlaceholder)
else if param.isOfKind `Lean.Parser.Term.hole then
pure (`_a, exprPlaceholder)
else do {
let n := ((param.getArg 1).getArg 0).getIdAt 0;
ty ← toPreterm $ (((param.getArg 1).getArg 1).getArg 0).getArg 1;
pure (n, ty)
};
lctx ← getLCtx;
let lctx := lctx.mkLocalDecl n n ty;
let params := params.eraseIdx 0;
stx ← `(fun $params* => $body);
adaptReader (fun (ctx : Context) => { lctx := lctx, .. ctx }) $ do
e ← toPreterm stx;
pure $ lctx.mkLambda #[mkFVar n] e
| `Lean.Parser.Term.let => do
let decl := args.get! 1;
let n := if (decl.getArg 0).isIdent then (decl.getArg 0).getId else (decl.getArg 0).getIdAt 0;
let val := decl.getArg 4;
let body := args.get! 3;
val ← toPreterm val;
lctx ← getLCtx;
let lctx := lctx.mkLetDecl n n exprPlaceholder val;
adaptReader (fun (ctx : Context) => { lctx := lctx, .. ctx }) $ do
e ← toPreterm $ body;
pure $ lctx.mkLambda #[mkFVar n] e
| `Lean.Parser.Term.app => do
fn ← toPreterm $ args.get! 0;
as ← (args.get! 1).getArgs.mapM toPreterm;
pure $ mkAppN fn as
| `Lean.Parser.Term.if => do
let con := args.get! 2;
let yes := args.get! 4;
let no := args.get! 6;
toPreterm $ Unhygienic.run `(ite $con $yes $no)
| `Lean.Parser.Term.paren =>
let inner := (args.get! 1).getArgs;
if inner.size == 0 then pure $ Lean.mkConst `Unit.unit
else toPreterm $ inner.get! 0
| `Lean.Parser.Term.band =>
let lhs := args.get! 0; let rhs := args.get! 2;
toPreterm $ Unhygienic.run `(and $lhs $rhs)
| `Lean.Parser.Term.beq =>
let lhs := args.get! 0; let rhs := args.get! 2;
toPreterm $ Unhygienic.run `(HasBeq.beq $lhs $rhs)
| `Lean.Parser.Term.eq =>
let lhs := args.get! 0; let rhs := args.get! 2;
toPreterm $ Unhygienic.run `(Eq $lhs $rhs)
| `Lean.Parser.Term.str => pure $ mkStrLit $ (stx.getArg 0).isStrLit?.getD ""
| `Lean.Parser.Term.num => pure $ mkNatLit $ (stx.getArg 0).isNatLit?.getD 0
| `expr => pure $ unsafeCast $ stx.getArg 0 -- HACK: see below
| k => throwError stx $ "stxQuot: unimplemented kind " ++ toString k
@[export lean_parse_expr]
def oldParseExpr (env : Environment) (input : String) (pos : String.Pos) : Except String (Syntax × String.Pos) := do
let c := Parser.mkParserContext env (Parser.mkInputContext input "<foo>");
let s := Parser.mkParserState c.input;
let s := s.setPos pos;
let s := (Parser.termParser Parser.appPrec : Parser.Parser).fn { rbp := Parser.appPrec, .. c } s;
let stx := s.stxStack.back;
match s.errorMsg with
| some errorMsg =>
Except.error $ toString errorMsg
| none =>
Except.ok (stx, s.pos)
structure OldContext :=
(env : Environment)
(locals : List Name)
(open_nss : List Name)
private def oldRunTermElabM {α} (ctx : OldContext) (x : TermElabM α) : Except String α := do
match x {fileName := "foo", fileMap := FileMap.ofString "", cmdPos := 0,
currNamespace := ctx.env.getNamespace, currRecDepth := 0, maxRecDepth := 10000,
openDecls := ctx.open_nss.map $ fun n => OpenDecl.simple n [],
lctx := ctx.locals.foldl (fun lctx l => LocalContext.mkLocalDecl lctx l l exprPlaceholder) $ LocalContext.mkEmpty ()}
{env := ctx.env} with
| EStateM.Result.ok a _ => Except.ok a
| EStateM.Result.error msg _ => Except.error $ toString msg
@[export lean_expand_stx_quot]
unsafe def oldExpandStxQuot (ctx : OldContext) (stx : Syntax) : Except String Expr := oldRunTermElabM ctx $ do
stx ← stxQuot.expand stx;
toPreterm stx
@[export lean_get_antiquot_vars]
def oldGetPatternVars (ctx : OldContext) (pats : List Syntax) : Except String (List Name) := oldRunTermElabM ctx $ do
let vars := List.join $ pats.map getPatternVars;
pure $ vars.map $ fun var => var.getIdAt 0
@[export lean_expand_match_syntax]
unsafe def oldExpandMatchSyntax (ctx : OldContext) (discr : Syntax) (alts : List (List Syntax × Syntax)) : Except String Expr := oldRunTermElabM ctx $ do
-- HACK: discr and the RHSs are actually `Expr`
let discr := Syntax.node `expr #[discr];
let alts := alts.map $ fun alt =>
let pats := alt.1.map elimAntiquotChoices;
(pats, Syntax.node `expr #[alt.2]);
-- letBindRhss (compileStxMatch Syntax.missing [discr]) alts []
stx ← compileStxMatch Syntax.missing [discr] alts;
toPreterm stx
end Quotation
end Term
end Elab
end Lean
|
9ff083ed57d738179d58241ded5766781f642efa
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/data/finset/sum.lean
|
8933dd3cdc3e6073583b0931e8c550fd376e559e
|
[
"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,824
|
lean
|
/-
Copyright (c) 2022 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.finset.card
import data.multiset.sum
/-!
# Disjoint sum of finsets
This file defines the disjoint sum of two finsets as `finset (α ⊕ β)`. Beware not to confuse with
the `finset.sum` operation which computes the additive sum.
## Main declarations
* `finset.disj_sum`: `s.disj_sum t` is the disjoint sum of `s` and `t`.
-/
open function multiset sum
namespace finset
variables {α β : Type*} (s : finset α) (t : finset β)
/-- Disjoint sum of finsets. -/
def disj_sum : finset (α ⊕ β) := ⟨s.1.disj_sum t.1, s.2.disj_sum t.2⟩
@[simp] lemma val_disj_sum : (s.disj_sum t).1 = s.1.disj_sum t.1 := rfl
@[simp] lemma empty_disj_sum : (∅ : finset α).disj_sum t = t.map embedding.inr :=
val_inj.1 $ multiset.zero_disj_sum _
@[simp] lemma disj_sum_empty : s.disj_sum (∅ : finset β) = s.map embedding.inl :=
val_inj.1 $ multiset.disj_sum_zero _
@[simp] lemma card_disj_sum : (s.disj_sum t).card = s.card + t.card := multiset.card_disj_sum _ _
variables {s t} {s₁ s₂ : finset α} {t₁ t₂ : finset β} {a : α} {b : β} {x : α ⊕ β}
lemma mem_disj_sum : x ∈ s.disj_sum t ↔ (∃ a, a ∈ s ∧ inl a = x) ∨ ∃ b, b ∈ t ∧ inr b = x :=
multiset.mem_disj_sum
@[simp] lemma inl_mem_disj_sum : inl a ∈ s.disj_sum t ↔ a ∈ s := inl_mem_disj_sum
@[simp] lemma inr_mem_disj_sum : inr b ∈ s.disj_sum t ↔ b ∈ t := inr_mem_disj_sum
lemma disj_sum_mono (hs : s₁ ⊆ s₂) (ht : t₁ ⊆ t₂) : s₁.disj_sum t₁ ⊆ s₂.disj_sum t₂ :=
val_le_iff.1 $ disj_sum_mono (val_le_iff.2 hs) (val_le_iff.2 ht)
lemma disj_sum_mono_left (t : finset β) : monotone (λ s : finset α, s.disj_sum t) :=
λ s₁ s₂ hs, disj_sum_mono hs subset.rfl
lemma disj_sum_mono_right (s : finset α) : monotone (s.disj_sum : finset β → finset (α ⊕ β)) :=
λ t₁ t₂, disj_sum_mono subset.rfl
lemma disj_sum_ssubset_disj_sum_of_ssubset_of_subset (hs : s₁ ⊂ s₂) (ht : t₁ ⊆ t₂) :
s₁.disj_sum t₁ ⊂ s₂.disj_sum t₂ :=
val_lt_iff.1 $ disj_sum_lt_disj_sum_of_lt_of_le (val_lt_iff.2 hs) (val_le_iff.2 ht)
lemma disj_sum_ssubset_disj_sum_of_subset_of_ssubset (hs : s₁ ⊆ s₂) (ht : t₁ ⊂ t₂) :
s₁.disj_sum t₁ ⊂ s₂.disj_sum t₂ :=
val_lt_iff.1 $ disj_sum_lt_disj_sum_of_le_of_lt (val_le_iff.2 hs) (val_lt_iff.2 ht)
lemma disj_sum_strict_mono_left (t : finset β) : strict_mono (λ s : finset α, s.disj_sum t) :=
λ s₁ s₂ hs, disj_sum_ssubset_disj_sum_of_ssubset_of_subset hs subset.rfl
lemma disj_sum_strict_mono_right (s : finset α) :
strict_mono (s.disj_sum : finset β → finset (α ⊕ β)) :=
λ s₁ s₂, disj_sum_ssubset_disj_sum_of_subset_of_ssubset subset.rfl
end finset
|
035258348d3bd7579b532594b33cb4e6cc4bc85d
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/topology/sheaves/sheaf_condition/opens_le_cover.lean
|
42427fa1f5c9236fa0da853f117c7e21c6009f11
|
[
"Apache-2.0"
] |
permissive
|
AntoineChambert-Loir/mathlib
|
64aabb896129885f12296a799818061bc90da1ff
|
07be904260ab6e36a5769680b6012f03a4727134
|
refs/heads/master
| 1,693,187,631,771
| 1,636,719,886,000
| 1,636,719,886,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 9,457
|
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 topology.sheaves.presheaf
import category_theory.limits.final
import topology.sheaves.sheaf_condition.pairwise_intersections
/-!
# Another version of the sheaf condition.
Given a family of open sets `U : ι → opens X` we can form the subcategory
`{ V : opens X // ∃ i, V ≤ U i }`, which has `supr U` as a cocone.
The sheaf condition on a presheaf `F` is equivalent to
`F` sending the opposite of this cocone to a limit cone in `C`, for every `U`.
This condition is particularly nice when checking the sheaf condition
because we don't need to do any case bashing
(depending on whether we're looking at single or double intersections,
or equivalently whether we're looking at the first or second object in an equalizer diagram).
## References
* This is the definition Lurie uses in [Spectral Algebraic Geometry][LurieSAG].
-/
universes v u
noncomputable theory
open category_theory
open category_theory.limits
open topological_space
open opposite
open topological_space.opens
namespace Top
variables {C : Type u} [category.{v} C]
variables {X : Top.{v}} (F : presheaf C X) {ι : Type v} (U : ι → opens X)
namespace presheaf
namespace sheaf_condition
/--
The category of open sets contained in some element of the cover.
-/
def opens_le_cover : Type v := { V : opens X // ∃ i, V ≤ U i }
instance [inhabited ι] : inhabited (opens_le_cover U) :=
⟨⟨⊥, default ι, bot_le⟩⟩
instance : category (opens_le_cover U) := category_theory.full_subcategory _
namespace opens_le_cover
variables {U}
/--
An arbitrarily chosen index such that `V ≤ U i`.
-/
def index (V : opens_le_cover U) : ι := V.property.some
/--
The morphism from `V` to `U i` for some `i`.
-/
def hom_to_index (V : opens_le_cover U) : V.val ⟶ U (index V) :=
(V.property.some_spec).hom
end opens_le_cover
/--
`supr U` as a cocone over the opens sets contained in some element of the cover.
(In fact this is a colimit cocone.)
-/
def opens_le_cover_cocone : cocone (full_subcategory_inclusion _ : opens_le_cover U ⥤ opens X) :=
{ X := supr U,
ι := { app := λ V : opens_le_cover U, V.hom_to_index ≫ opens.le_supr U _, } }
end sheaf_condition
open sheaf_condition
/--
An equivalent formulation of the sheaf condition
(which we prove equivalent to the usual one below as
`is_sheaf_iff_is_sheaf_opens_le_cover`).
A presheaf is a sheaf if `F` sends the cone `(opens_le_cover_cocone U).op` to a limit cone.
(Recall `opens_le_cover_cocone U`, has cone point `supr U`,
mapping down to any `V` which is contained in some `U i`.)
-/
def is_sheaf_opens_le_cover : Prop :=
∀ ⦃ι : Type v⦄ (U : ι → opens X), nonempty (is_limit (F.map_cone (opens_le_cover_cocone U).op))
namespace sheaf_condition
open category_theory.pairwise
/--
Implementation detail:
the object level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
@[simp]
def pairwise_to_opens_le_cover_obj : pairwise ι → opens_le_cover U
| (single i) := ⟨U i, ⟨i, le_refl _⟩⟩
| (pair i j) := ⟨U i ⊓ U j, ⟨i, inf_le_left⟩⟩
open category_theory.pairwise.hom
/--
Implementation detail:
the morphism level of `pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U`
-/
def pairwise_to_opens_le_cover_map :
Π {V W : pairwise ι},
(V ⟶ W) → (pairwise_to_opens_le_cover_obj U V ⟶ pairwise_to_opens_le_cover_obj U W)
| _ _ (id_single i) := 𝟙 _
| _ _ (id_pair i j) := 𝟙 _
| _ _ (left i j) := hom_of_le inf_le_left
| _ _ (right i j) := hom_of_le inf_le_right
/--
The category of single and double intersections of the `U i` maps into the category
of open sets below some `U i`.
-/
@[simps]
def pairwise_to_opens_le_cover : pairwise ι ⥤ opens_le_cover U :=
{ obj := pairwise_to_opens_le_cover_obj U,
map := λ V W i, pairwise_to_opens_le_cover_map U i, }
instance (V : opens_le_cover U) :
nonempty (structured_arrow V (pairwise_to_opens_le_cover U)) :=
⟨{ right := single (V.index), hom := V.hom_to_index }⟩
/--
The diagram consisting of the `U i` and `U i ⊓ U j` is cofinal in the diagram
of all opens contained in some `U i`.
-/
-- This is a case bash: for each pair of types of objects in `pairwise ι`,
-- we have to explicitly construct a zigzag.
instance : functor.final (pairwise_to_opens_le_cover U) :=
⟨λ V, is_connected_of_zigzag $ λ A B, begin
rcases A with ⟨⟨⟩, ⟨i⟩|⟨i,j⟩, a⟩;
rcases B with ⟨⟨⟩, ⟨i'⟩|⟨i',j'⟩, b⟩;
dsimp at *,
{ refine ⟨[
{ left := punit.star, right := pair i i',
hom := (le_inf a.le b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil) },
{ refine ⟨[
{ left := punit.star, right := pair i' i,
hom := (le_inf (b.le.trans inf_le_left) a.le).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := right i' i, }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i' i, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i', hom :=
(le_inf (a.le.trans inf_le_left) b.le).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩) list.chain.nil)) },
{ refine ⟨[
{ left := punit.star, right := single i,
hom := (a.le.trans inf_le_left).hom, },
{ left := punit.star, right := pair i i',
hom := (le_inf (a.le.trans inf_le_left) (b.le.trans inf_le_left)).hom, },
{ left := punit.star, right := single i',
hom := (b.le.trans inf_le_left).hom, }, _], _, rfl⟩,
exact
list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := left i j, }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i i', }⟩)
(list.chain.cons (or.inl ⟨{ left := 𝟙 _, right := right i i', }⟩)
(list.chain.cons (or.inr ⟨{ left := 𝟙 _, right := left i' j', }⟩) list.chain.nil))), },
end⟩
/--
The diagram in `opens X` indexed by pairwise intersections from `U` is isomorphic
(in fact, equal) to the diagram factored through `opens_le_cover U`.
-/
def pairwise_diagram_iso :
pairwise.diagram U ≅
pairwise_to_opens_le_cover U ⋙ full_subcategory_inclusion _ :=
{ hom := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, },
inv := { app := begin rintro (i|⟨i,j⟩); exact 𝟙 _, end, }, }
/--
The cocone `pairwise.cocone U` with cocone point `supr U` over `pairwise.diagram U` is isomorphic
to the cocone `opens_le_cover_cocone U` (with the same cocone point)
after appropriate whiskering and postcomposition.
-/
def pairwise_cocone_iso :
(pairwise.cocone U).op ≅
(cones.postcompose_equivalence (nat_iso.op (pairwise_diagram_iso U : _) : _)).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op) :=
cones.ext (iso.refl _) (by tidy)
end sheaf_condition
open sheaf_condition
/--
The sheaf condition
in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`
is equivalent to the reformulation
in terms of a limit diagram over `U i` and `U i ⊓ U j`.
-/
lemma is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections (F : presheaf C X) :
F.is_sheaf_opens_le_cover ↔ F.is_sheaf_pairwise_intersections :=
forall_congr (λ ι, forall_congr (λ U, equiv.nonempty_congr $
calc is_limit (F.map_cone (opens_le_cover_cocone U).op)
≃ is_limit ((F.map_cone (opens_le_cover_cocone U).op).whisker (pairwise_to_opens_le_cover U).op)
: (functor.initial.is_limit_whisker_equiv (pairwise_to_opens_le_cover U).op _).symm
... ≃ is_limit (F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op))
: is_limit.equiv_iso_limit F.map_cone_whisker.symm
... ≃ is_limit ((cones.postcompose_equivalence _).functor.obj
(F.map_cone ((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: (is_limit.postcompose_hom_equiv _ _).symm
... ≃ is_limit (F.map_cone ((cones.postcompose_equivalence _).functor.obj
((opens_le_cover_cocone U).op.whisker (pairwise_to_opens_le_cover U).op)))
: is_limit.equiv_iso_limit (functor.map_cone_postcompose_equivalence_functor _).symm
... ≃ is_limit (F.map_cone (pairwise.cocone U).op)
: is_limit.equiv_iso_limit
((cones.functoriality _ _).map_iso (pairwise_cocone_iso U : _).symm)))
variables [has_products C]
/--
The sheaf condition in terms of an equalizer diagram is equivalent
to the reformulation in terms of a limit diagram over all `{ V : opens X // ∃ i, V ≤ U i }`.
-/
lemma is_sheaf_iff_is_sheaf_opens_le_cover (F : presheaf C X) :
F.is_sheaf ↔ F.is_sheaf_opens_le_cover :=
iff.trans
(is_sheaf_iff_is_sheaf_pairwise_intersections F)
(is_sheaf_opens_le_cover_iff_is_sheaf_pairwise_intersections F).symm
end presheaf
end Top
|
89f8c28d1cd1903d82a6607c1515ed2c3186c67d
|
2c096fdfecf64e46ea7bc6ce5521f142b5926864
|
/src/Lean/Elab/ElabRules.lean
|
a47bab0bfc2c8e5dad47763a8d91ec022d16b867
|
[
"Apache-2.0",
"LLVM-exception",
"NCSA",
"LGPL-3.0-only",
"LicenseRef-scancode-inner-net-2.0",
"BSD-3-Clause",
"LGPL-2.0-or-later",
"Spencer-94",
"LGPL-2.1-or-later",
"HPND",
"LicenseRef-scancode-pcre",
"ISC",
"LGPL-2.1-only",
"LicenseRef-scancode-other-permissive",
"SunPro",
"CMU-Mach"
] |
permissive
|
Kha/lean4
|
1005785d2c8797ae266a303968848e5f6ce2fe87
|
b99e11346948023cd6c29d248cd8f3e3fb3474cf
|
refs/heads/master
| 1,693,355,498,027
| 1,669,080,461,000
| 1,669,113,138,000
| 184,748,176
| 0
| 0
|
Apache-2.0
| 1,665,995,520,000
| 1,556,884,930,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 5,630
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
import Lean.Elab.MacroArgUtil
import Lean.Elab.AuxDef
namespace Lean.Elab.Command
open Lean.Syntax
open Lean.Parser.Term hiding macroArg
open Lean.Parser.Command
def withExpectedType (expectedType? : Option Expr) (x : Expr → TermElabM Expr) : TermElabM Expr := do
Term.tryPostponeIfNoneOrMVar expectedType?
let some expectedType ← pure expectedType?
| throwError "expected type must be known"
x expectedType
def elabElabRulesAux (doc? : Option (TSyntax ``docComment))
(attrs? : Option (TSepArray ``attrInstance ",")) (attrKind : TSyntax ``attrKind)
(k : SyntaxNodeKind) (cat? expty? : Option (Ident)) (alts : Array (TSyntax ``matchAlt)) :
CommandElabM Syntax := do
let alts ← alts.mapM fun (alt : TSyntax ``matchAlt) => match alt with
| `(matchAltExpr| | $pats,* => $rhs) => do
let pat := pats.elemsAndSeps[0]!
if !pat.isQuot then
throwUnsupportedSyntax
let quoted := getQuotContent pat
let k' := quoted.getKind
if checkRuleKind k' k then
pure alt
else if k' == choiceKind then
match quoted.getArgs.find? fun quotAlt => checkRuleKind quotAlt.getKind k with
| none => throwErrorAt alt "invalid elab_rules alternative, expected syntax node kind '{k}'"
| some quoted =>
let pat := pat.setArg 1 quoted
let pats := ⟨pats.elemsAndSeps.set! 0 pat⟩
`(matchAltExpr| | $pats,* => $rhs)
else
throwErrorAt alt "invalid elab_rules alternative, unexpected syntax node kind '{k'}'"
| _ => throwUnsupportedSyntax
let catName ← match cat?, expty? with
| some cat, _ => pure cat.getId
| _, some _ => pure `term
-- TODO: infer category from quotation kind, possibly even kind of quoted syntax?
| _, _ => throwError "invalid elab_rules command, specify category using `elab_rules : <cat> ...`"
let mkAttrs (kind : Name) : CommandElabM (TSyntaxArray ``attrInstance) := do
let attr ← `(attrInstance| $attrKind:attrKind $(mkIdent kind):ident $(← mkIdentFromRef k):ident)
pure <| match attrs? with
| some attrs => attrs.getElems.push attr
| none => #[attr]
if let some expId := expty? then
if catName == `term then
`($[$doc?:docComment]? @[$(← mkAttrs `term_elab),*]
aux_def elabRules $(mkIdent k) : Lean.Elab.Term.TermElab :=
fun stx expectedType? => Lean.Elab.Command.withExpectedType expectedType? fun $expId => match stx with
$alts:matchAlt* | _ => no_error_if_unused% throwUnsupportedSyntax)
else
throwErrorAt expId "syntax category '{catName}' does not support expected type specification"
else if catName == `term then
`($[$doc?:docComment]? @[$(← mkAttrs `term_elab),*]
aux_def elabRules $(mkIdent k) : Lean.Elab.Term.TermElab :=
fun stx _ => match stx with
$alts:matchAlt* | _ => no_error_if_unused% throwUnsupportedSyntax)
else if catName == `command then
`($[$doc?:docComment]? @[$(← mkAttrs `command_elab),*]
aux_def elabRules $(mkIdent k) : Lean.Elab.Command.CommandElab :=
fun $alts:matchAlt* | _ => no_error_if_unused% throwUnsupportedSyntax)
else if catName == `tactic || catName == `conv then
`($[$doc?:docComment]? @[$(← mkAttrs `tactic),*]
aux_def elabRules $(mkIdent k) : Lean.Elab.Tactic.Tactic :=
fun $alts:matchAlt* | _ => no_error_if_unused% throwUnsupportedSyntax)
else
-- We considered making the command extensible and support new user-defined categories. We think it is unnecessary.
-- If users want this feature, they add their own `elab_rules` macro that uses this one as a fallback.
throwError "unsupported syntax category '{catName}'"
@[builtin_command_elab «elab_rules»] def elabElabRules : CommandElab :=
adaptExpander fun stx => match stx with
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind elab_rules $[: $cat?]? $[<= $expty?]? $alts:matchAlt*) =>
expandNoKindMacroRulesAux alts "elab_rules" fun kind? alts =>
`($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind elab_rules $[(kind := $(mkIdent <$> kind?))]? $[: $cat?]? $[<= $expty?]? $alts:matchAlt*)
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind elab_rules (kind := $kind) $[: $cat?]? $[<= $expty?]? $alts:matchAlt*) =>
do elabElabRulesAux doc? attrs? attrKind (← resolveSyntaxKind kind.getId) cat? expty? alts
| _ => throwUnsupportedSyntax
@[builtin_command_elab Lean.Parser.Command.elab]
def elabElab : CommandElab
| `($[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
elab%$tk$[:$prec?]? $[(name := $name?)]? $[(priority := $prio?)]? $args:macroArg* :
$cat $[<= $expectedType?]? => $rhs) => do
let prio ← liftMacroM <| evalOptPrio prio?
let (stxParts, patArgs) := (← args.mapM expandMacroArg).unzip
-- name
let name ← match name? with
| some name => pure name.getId
| none => liftMacroM <| mkNameFromParserSyntax cat.getId (mkNullNode stxParts)
let nameId := name?.getD (mkIdentFrom tk name (canonical := true))
let pat := ⟨mkNode ((← getCurrNamespace) ++ name) patArgs⟩
elabCommand <|← `(
$[$doc?:docComment]? $[@[$attrs?,*]]? $attrKind:attrKind
syntax%$tk$[:$prec?]? (name := $nameId) (priority := $(quote prio):num) $[$stxParts]* : $cat
$[$doc?:docComment]? elab_rules : $cat $[<= $expectedType?]? | `($pat) => $rhs)
| _ => throwUnsupportedSyntax
end Lean.Elab.Command
|
7da1ba012d78f586051dedf431b0ea6dbfbd9ac5
|
fa02ed5a3c9c0adee3c26887a16855e7841c668b
|
/src/topology/algebra/infinite_sum.lean
|
3656c1706bba2851b1447be320ba062bcb8d199f
|
[
"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
| 50,757
|
lean
|
/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl
-/
import algebra.big_operators.intervals
import topology.instances.real
import topology.algebra.module
import algebra.indicator_function
import data.equiv.encodable.lattice
import data.nat.parity
import order.filter.at_top_bot
/-!
# Infinite sum over a topological monoid
This sum is known as unconditionally convergent, as it sums to the same value under all possible
permutations. For Euclidean spaces (finite dimensional Banach spaces) this is equivalent to absolute
convergence.
Note: There are summable sequences which are not unconditionally convergent! The other way holds
generally, see `has_sum.tendsto_sum_nat`.
## References
* Bourbaki: General Topology (1995), Chapter 3 §5 (Infinite sums in commutative groups)
-/
noncomputable theory
open finset filter function classical
open_locale topological_space classical big_operators nnreal
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
section has_sum
variables [add_comm_monoid α] [topological_space α]
/-- Infinite sum on a topological monoid
The `at_top` filter on `finset β` is the limit of all finite sets towards the entire type. So we sum
up bigger and bigger sets. This sum operation is invariant under reordering. In particular,
the function `ℕ → ℝ` sending `n` to `(-1)^n / (n+1)` does not have a
sum for this definition, but a series which is absolutely convergent will have the correct sum.
This is based on Mario Carneiro's
[infinite sum `df-tsms` in Metamath](http://us.metamath.org/mpeuni/df-tsms.html).
For the definition or many statements, `α` does not need to be a topological monoid. We only add
this assumption later, for the lemmas where it is relevant.
-/
def has_sum (f : β → α) (a : α) : Prop := tendsto (λs:finset β, ∑ b in s, f b) at_top (𝓝 a)
/-- `summable f` means that `f` has some (infinite) sum. Use `tsum` to get the value. -/
def summable (f : β → α) : Prop := ∃a, has_sum f a
/-- `∑' i, f i` is the sum of `f` it exists, or 0 otherwise -/
@[irreducible] def tsum {β} (f : β → α) := if h : summable f then classical.some h else 0
-- see Note [operator precedence of big operators]
notation `∑'` binders `, ` r:(scoped:67 f, tsum f) := r
variables {f g : β → α} {a b : α} {s : finset β}
lemma summable.has_sum (ha : summable f) : has_sum f (∑'b, f b) :=
by simp [ha, tsum]; exact some_spec ha
lemma has_sum.summable (h : has_sum f a) : summable f := ⟨a, h⟩
/-- Constant zero function has sum `0` -/
lemma has_sum_zero : has_sum (λb, 0 : β → α) 0 :=
by simp [has_sum, tendsto_const_nhds]
lemma summable_zero : summable (λb, 0 : β → α) := has_sum_zero.summable
lemma tsum_eq_zero_of_not_summable (h : ¬ summable f) : ∑'b, f b = 0 :=
by simp [tsum, h]
lemma has_sum.has_sum_of_sum_eq {g : γ → α}
(h_eq : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b)
(hf : has_sum g a) :
has_sum f a :=
le_trans (map_at_top_finset_sum_le_of_sum_eq h_eq) hf
lemma has_sum_iff_has_sum {g : γ → α}
(h₁ : ∀u:finset γ, ∃v:finset β, ∀v', v ⊆ v' → ∃u', u ⊆ u' ∧ ∑ x in u', g x = ∑ b in v', f b)
(h₂ : ∀v:finset β, ∃u:finset γ, ∀u', u ⊆ u' → ∃v', v ⊆ v' ∧ ∑ b in v', f b = ∑ x in u', g x) :
has_sum f a ↔ has_sum g a :=
⟨has_sum.has_sum_of_sum_eq h₂, has_sum.has_sum_of_sum_eq h₁⟩
lemma function.injective.has_sum_iff {g : γ → β} (hg : injective g)
(hf : ∀ x ∉ set.range g, f x = 0) :
has_sum (f ∘ g) a ↔ has_sum f a :=
by simp only [has_sum, tendsto, hg.map_at_top_finset_sum_eq hf]
lemma function.injective.summable_iff {g : γ → β} (hg : injective g)
(hf : ∀ x ∉ set.range g, f x = 0) :
summable (f ∘ g) ↔ summable f :=
exists_congr $ λ _, hg.has_sum_iff hf
lemma has_sum_subtype_iff_of_support_subset {s : set β} (hf : support f ⊆ s) :
has_sum (f ∘ coe : s → α) a ↔ has_sum f a :=
subtype.coe_injective.has_sum_iff $ by simpa using support_subset_iff'.1 hf
lemma has_sum_subtype_iff_indicator {s : set β} :
has_sum (f ∘ coe : s → α) a ↔ has_sum (s.indicator f) a :=
by rw [← set.indicator_range_comp, subtype.range_coe,
has_sum_subtype_iff_of_support_subset set.support_indicator_subset]
@[simp] lemma has_sum_subtype_support : has_sum (f ∘ coe : support f → α) a ↔ has_sum f a :=
has_sum_subtype_iff_of_support_subset $ set.subset.refl _
lemma has_sum_fintype [fintype β] (f : β → α) : has_sum f (∑ b, f b) :=
order_top.tendsto_at_top_nhds _
protected lemma finset.has_sum (s : finset β) (f : β → α) :
has_sum (f ∘ coe : (↑s : set β) → α) (∑ b in s, f b) :=
by { rw ← sum_attach, exact has_sum_fintype _ }
protected lemma finset.summable (s : finset β) (f : β → α) :
summable (f ∘ coe : (↑s : set β) → α) :=
(s.has_sum f).summable
protected lemma set.finite.summable {s : set β} (hs : s.finite) (f : β → α) :
summable (f ∘ coe : s → α) :=
by convert hs.to_finset.summable f; simp only [hs.coe_to_finset]
/-- If a function `f` vanishes outside of a finite set `s`, then it `has_sum` `∑ b in s, f b`. -/
lemma has_sum_sum_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : has_sum f (∑ b in s, f b) :=
(has_sum_subtype_iff_of_support_subset $ support_subset_iff'.2 hf).1 $ s.has_sum f
lemma summable_of_ne_finset_zero (hf : ∀b∉s, f b = 0) : summable f :=
(has_sum_sum_of_ne_finset_zero hf).summable
lemma has_sum_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
has_sum f (f b) :=
suffices has_sum f (∑ b' in {b}, f b'),
by simpa using this,
has_sum_sum_of_ne_finset_zero $ by simpa [hf]
lemma has_sum_ite_eq (b : β) [decidable_pred (= b)] (a : α) :
has_sum (λb', if b' = b then a else 0) a :=
begin
convert has_sum_single b _,
{ exact (if_pos rfl).symm },
assume b' hb',
exact if_neg hb'
end
lemma equiv.has_sum_iff (e : γ ≃ β) :
has_sum (f ∘ e) a ↔ has_sum f a :=
e.injective.has_sum_iff $ by simp
lemma function.injective.has_sum_range_iff {g : γ → β} (hg : injective g) :
has_sum (λ x : set.range g, f x) a ↔ has_sum (f ∘ g) a :=
(equiv.of_injective g hg).has_sum_iff.symm
lemma equiv.summable_iff (e : γ ≃ β) :
summable (f ∘ e) ↔ summable f :=
exists_congr $ λ a, e.has_sum_iff
lemma summable.prod_symm {f : β × γ → α} (hf : summable f) : summable (λ p : γ × β, f p.swap) :=
(equiv.prod_comm γ β).summable_iff.2 hf
lemma equiv.has_sum_iff_of_support {g : γ → α} (e : support f ≃ support g)
(he : ∀ x : support f, g (e x) = f x) :
has_sum f a ↔ has_sum g a :=
have (g ∘ coe) ∘ e = f ∘ coe, from funext he,
by rw [← has_sum_subtype_support, ← this, e.has_sum_iff, has_sum_subtype_support]
lemma has_sum_iff_has_sum_of_ne_zero_bij {g : γ → α} (i : support g → β)
(hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y)
(hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) :
has_sum f a ↔ has_sum g a :=
iff.symm $ equiv.has_sum_iff_of_support
(equiv.of_bijective (λ x, ⟨i x, λ hx, x.coe_prop $ hfg x ▸ hx⟩)
⟨λ x y h, subtype.ext $ hi $ subtype.ext_iff.1 h,
λ y, (hf y.coe_prop).imp $ λ x hx, subtype.ext hx⟩)
hfg
lemma equiv.summable_iff_of_support {g : γ → α} (e : support f ≃ support g)
(he : ∀ x : support f, g (e x) = f x) :
summable f ↔ summable g :=
exists_congr $ λ _, e.has_sum_iff_of_support he
protected lemma has_sum.map [add_comm_monoid γ] [topological_space γ] (hf : has_sum f a)
(g : α →+ γ) (hg : continuous g) :
has_sum (g ∘ f) (g a) :=
have g ∘ (λs:finset β, ∑ b in s, f b) = (λs:finset β, ∑ b in s, g (f b)),
from funext $ g.map_sum _,
show tendsto (λs:finset β, ∑ b in s, g (f b)) at_top (𝓝 (g a)),
from this ▸ (hg.tendsto a).comp hf
protected lemma summable.map [add_comm_monoid γ] [topological_space γ] (hf : summable f)
(g : α →+ γ) (hg : continuous g) :
summable (g ∘ f) :=
(hf.has_sum.map g hg).summable
/-- If `f : ℕ → α` has sum `a`, then the partial sums `∑_{i=0}^{n-1} f i` converge to `a`. -/
lemma has_sum.tendsto_sum_nat {f : ℕ → α} (h : has_sum f a) :
tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
h.comp tendsto_finset_range
lemma has_sum.unique {a₁ a₂ : α} [t2_space α] : has_sum f a₁ → has_sum f a₂ → a₁ = a₂ :=
tendsto_nhds_unique
lemma summable.has_sum_iff_tendsto_nat [t2_space α] {f : ℕ → α} {a : α} (hf : summable f) :
has_sum f a ↔ tendsto (λn:ℕ, ∑ i in range n, f i) at_top (𝓝 a) :=
begin
refine ⟨λ h, h.tendsto_sum_nat, λ h, _⟩,
rw tendsto_nhds_unique h hf.has_sum.tendsto_sum_nat,
exact hf.has_sum
end
lemma equiv.summable_iff_of_has_sum_iff {α' : Type*} [add_comm_monoid α']
[topological_space α'] (e : α' ≃ α) {f : β → α} {g : γ → α'}
(he : ∀ {a}, has_sum f (e a) ↔ has_sum g a) :
summable f ↔ summable g :=
⟨λ ⟨a, ha⟩, ⟨e.symm a, he.1 $ by rwa [e.apply_symm_apply]⟩, λ ⟨a, ha⟩, ⟨e a, he.2 ha⟩⟩
variable [has_continuous_add α]
lemma has_sum.add (hf : has_sum f a) (hg : has_sum g b) : has_sum (λb, f b + g b) (a + b) :=
by simp only [has_sum, sum_add_distrib]; exact hf.add hg
lemma summable.add (hf : summable f) (hg : summable g) : summable (λb, f b + g b) :=
(hf.has_sum.add hg.has_sum).summable
lemma has_sum_sum {f : γ → β → α} {a : γ → α} {s : finset γ} :
(∀i∈s, has_sum (f i) (a i)) → has_sum (λb, ∑ i in s, f i b) (∑ i in s, a i) :=
finset.induction_on s (by simp only [has_sum_zero, sum_empty, forall_true_iff])
(by simp only [has_sum.add, sum_insert, mem_insert, forall_eq_or_imp,
forall_2_true_iff, not_false_iff, forall_true_iff] {contextual := tt})
lemma summable_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
summable (λb, ∑ i in s, f i b) :=
(has_sum_sum $ assume i hi, (hf i hi).has_sum).summable
lemma has_sum.add_disjoint {s t : set β} (hs : disjoint s t)
(ha : has_sum (f ∘ coe : s → α) a) (hb : has_sum (f ∘ coe : t → α) b) :
has_sum (f ∘ coe : s ∪ t → α) (a + b) :=
begin
rw has_sum_subtype_iff_indicator at *,
rw set.indicator_union_of_disjoint hs,
exact ha.add hb
end
lemma has_sum.add_is_compl {s t : set β} (hs : is_compl s t)
(ha : has_sum (f ∘ coe : s → α) a) (hb : has_sum (f ∘ coe : t → α) b) :
has_sum f (a + b) :=
by simpa [← hs.compl_eq]
using (has_sum_subtype_iff_indicator.1 ha).add (has_sum_subtype_iff_indicator.1 hb)
lemma has_sum.add_compl {s : set β} (ha : has_sum (f ∘ coe : s → α) a)
(hb : has_sum (f ∘ coe : sᶜ → α) b) :
has_sum f (a + b) :=
ha.add_is_compl is_compl_compl hb
lemma summable.add_compl {s : set β} (hs : summable (f ∘ coe : s → α))
(hsc : summable (f ∘ coe : sᶜ → α)) :
summable f :=
(hs.has_sum.add_compl hsc.has_sum).summable
lemma has_sum.compl_add {s : set β} (ha : has_sum (f ∘ coe : sᶜ → α) a)
(hb : has_sum (f ∘ coe : s → α) b) :
has_sum f (a + b) :=
ha.add_is_compl is_compl_compl.symm hb
lemma has_sum.even_add_odd {f : ℕ → α} (he : has_sum (λ k, f (2 * k)) a)
(ho : has_sum (λ k, f (2 * k + 1)) b) :
has_sum f (a + b) :=
begin
have := mul_right_injective' (@two_ne_zero ℕ _ _),
replace he := this.has_sum_range_iff.2 he,
replace ho := ((add_left_injective 1).comp this).has_sum_range_iff.2 ho,
refine he.add_is_compl _ ho,
simpa [(∘)] using nat.is_compl_even_odd
end
lemma summable.compl_add {s : set β} (hs : summable (f ∘ coe : sᶜ → α))
(hsc : summable (f ∘ coe : s → α)) :
summable f :=
(hs.has_sum.compl_add hsc.has_sum).summable
lemma summable.even_add_odd {f : ℕ → α} (he : summable (λ k, f (2 * k)))
(ho : summable (λ k, f (2 * k + 1))) :
summable f :=
(he.has_sum.even_add_odd ho.has_sum).summable
lemma has_sum.sigma [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α} {a : α}
(ha : has_sum f a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) : has_sum g a :=
begin
refine (at_top_basis.tendsto_iff (closed_nhds_basis a)).mpr _,
rintros s ⟨hs, hsc⟩,
rcases mem_at_top_sets.mp (ha hs) with ⟨u, hu⟩,
use [u.image sigma.fst, trivial],
intros bs hbs,
simp only [set.mem_preimage, ge_iff_le, finset.le_iff_subset] at hu,
have : tendsto (λ t : finset (Σ b, γ b), ∑ p in t.filter (λ p, p.1 ∈ bs), f p)
at_top (𝓝 $ ∑ b in bs, g b),
{ simp only [← sigma_preimage_mk, sum_sigma],
refine tendsto_finset_sum _ (λ b hb, _),
change tendsto (λ t, (λ t, ∑ s in t, f ⟨b, s⟩) (preimage t (sigma.mk b) _)) at_top (𝓝 (g b)),
exact tendsto.comp (hf b) (tendsto_finset_preimage_at_top_at_top _) },
refine hsc.mem_of_tendsto this (eventually_at_top.2 ⟨u, λ t ht, hu _ (λ x hx, _)⟩),
exact mem_filter.2 ⟨ht hx, hbs $ mem_image_of_mem _ hx⟩
end
/-- If a series `f` on `β × γ` has sum `a` and for each `b` the restriction of `f` to `{b} × γ`
has sum `g b`, then the series `g` has sum `a`. -/
lemma has_sum.prod_fiberwise [regular_space α] {f : β × γ → α} {g : β → α} {a : α}
(ha : has_sum f a) (hf : ∀b, has_sum (λc, f (b, c)) (g b)) :
has_sum g a :=
has_sum.sigma ((equiv.sigma_equiv_prod β γ).has_sum_iff.2 ha) hf
lemma summable.sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (hf : ∀b, summable (λc, f ⟨b, c⟩)) :
summable (λb, ∑'c, f ⟨b, c⟩) :=
(ha.has_sum.sigma (assume b, (hf b).has_sum)).summable
lemma has_sum.sigma_of_has_sum [regular_space α] {γ : β → Type*} {f : (Σ b:β, γ b) → α} {g : β → α}
{a : α} (ha : has_sum g a) (hf : ∀b, has_sum (λc, f ⟨b, c⟩) (g b)) (hf' : summable f) :
has_sum f a :=
by simpa [(hf'.has_sum.sigma hf).unique ha] using hf'.has_sum
end has_sum
section tsum
variables [add_comm_monoid α] [topological_space α] [t2_space α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.tsum_eq (ha : has_sum f a) : ∑'b, f b = a :=
(summable.has_sum ⟨a, ha⟩).unique ha
lemma summable.has_sum_iff (h : summable f) : has_sum f a ↔ ∑'b, f b = a :=
iff.intro has_sum.tsum_eq (assume eq, eq ▸ h.has_sum)
@[simp] lemma tsum_zero : ∑'b:β, (0:α) = 0 := has_sum_zero.tsum_eq
lemma tsum_eq_sum {f : β → α} {s : finset β} (hf : ∀b∉s, f b = 0) :
∑' b, f b = ∑ b in s, f b :=
(has_sum_sum_of_ne_finset_zero hf).tsum_eq
lemma tsum_congr {α β : Type*} [add_comm_monoid α] [topological_space α]
{f g : β → α} (hfg : ∀ b, f b = g b) : ∑' b, f b = ∑' b, g b :=
congr_arg tsum (funext hfg)
lemma tsum_fintype [fintype β] (f : β → α) : ∑'b, f b = ∑ b, f b :=
(has_sum_fintype f).tsum_eq
@[simp] lemma finset.tsum_subtype (s : finset β) (f : β → α) :
∑' x : {x // x ∈ s}, f x = ∑ x in s, f x :=
(s.has_sum f).tsum_eq
@[simp] lemma finset.tsum_subtype' (s : finset β) (f : β → α) :
∑' x : (s : set β), f x = ∑ x in s, f x :=
s.tsum_subtype f
lemma tsum_eq_single {f : β → α} (b : β) (hf : ∀b' ≠ b, f b' = 0) :
∑'b, f b = f b :=
(has_sum_single b hf).tsum_eq
@[simp] lemma tsum_ite_eq (b : β) [decidable_pred (= b)] (a : α) :
∑' b', (if b' = b then a else 0) = a :=
(has_sum_ite_eq b a).tsum_eq
lemma tsum_dite_right (P : Prop) [decidable P] (x : β → ¬ P → α) :
∑' (b : β), (if h : P then (0 : α) else x b h) = if h : P then (0 : α) else ∑' (b : β), x b h :=
by by_cases hP : P; simp [hP]
lemma tsum_dite_left (P : Prop) [decidable P] (x : β → P → α) :
∑' (b : β), (if h : P then x b h else 0) = if h : P then (∑' (b : β), x b h) else 0 :=
by by_cases hP : P; simp [hP]
lemma equiv.tsum_eq_tsum_of_has_sum_iff_has_sum {α' : Type*} [add_comm_monoid α']
[topological_space α'] (e : α' ≃ α) (h0 : e 0 = 0) {f : β → α} {g : γ → α'}
(h : ∀ {a}, has_sum f (e a) ↔ has_sum g a) :
∑' b, f b = e (∑' c, g c) :=
by_cases
(assume : summable g, (h.mpr this.has_sum).tsum_eq)
(assume hg : ¬ summable g,
have hf : ¬ summable f, from mt (e.summable_iff_of_has_sum_iff @h).1 hg,
by simp [tsum, hf, hg, h0])
lemma tsum_eq_tsum_of_has_sum_iff_has_sum {f : β → α} {g : γ → α}
(h : ∀{a}, has_sum f a ↔ has_sum g a) :
∑'b, f b = ∑'c, g c :=
(equiv.refl α).tsum_eq_tsum_of_has_sum_iff_has_sum rfl @h
lemma equiv.tsum_eq (j : γ ≃ β) (f : β → α) : ∑'c, f (j c) = ∑'b, f b :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ a, j.has_sum_iff
lemma equiv.tsum_eq_tsum_of_support {f : β → α} {g : γ → α} (e : support f ≃ support g)
(he : ∀ x, g (e x) = f x) :
(∑' x, f x) = ∑' y, g y :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, e.has_sum_iff_of_support he
lemma tsum_eq_tsum_of_ne_zero_bij {g : γ → α} (i : support g → β)
(hi : ∀ ⦃x y⦄, i x = i y → (x : γ) = y)
(hf : support f ⊆ set.range i) (hfg : ∀ x, f (i x) = g x) :
∑' x, f x = ∑' y, g y :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_iff_has_sum_of_ne_zero_bij i hi hf hfg
lemma tsum_subtype (s : set β) (f : β → α) :
∑' x:s, f x = ∑' x, s.indicator f x :=
tsum_eq_tsum_of_has_sum_iff_has_sum $ λ _, has_sum_subtype_iff_indicator
section has_continuous_add
variable [has_continuous_add α]
lemma tsum_add (hf : summable f) (hg : summable g) : ∑'b, (f b + g b) = (∑'b, f b) + (∑'b, g b) :=
(hf.has_sum.add hg.has_sum).tsum_eq
lemma tsum_sum {f : γ → β → α} {s : finset γ} (hf : ∀i∈s, summable (f i)) :
∑'b, ∑ i in s, f i b = ∑ i in s, ∑'b, f i b :=
(has_sum_sum $ assume i hi, (hf i hi).has_sum).tsum_eq
lemma tsum_sigma' [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(h₁ : ∀b, summable (λc, f ⟨b, c⟩)) (h₂ : summable f) : ∑'p, f p = ∑'b c, f ⟨b, c⟩ :=
(h₂.has_sum.sigma (assume b, (h₁ b).has_sum)).tsum_eq.symm
lemma tsum_prod' [regular_space α] {f : β × γ → α} (h : summable f)
(h₁ : ∀b, summable (λc, f (b, c))) :
∑'p, f p = ∑'b c, f (b, c) :=
(h.has_sum.prod_fiberwise (assume b, (h₁ b).has_sum)).tsum_eq.symm
lemma tsum_comm' [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f))
(h₁ : ∀b, summable (f b)) (h₂ : ∀ c, summable (λ b, f b c)) :
∑' c b, f b c = ∑' b c, f b c :=
begin
erw [← tsum_prod' h h₁, ← tsum_prod' h.prod_symm h₂, ← (equiv.prod_comm β γ).tsum_eq],
refl,
assumption
end
end has_continuous_add
section encodable
open encodable
variable [encodable γ]
/-- You can compute a sum over an encodably type by summing over the natural numbers and
taking a supremum. This is useful for outer measures. -/
theorem tsum_supr_decode₂ [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(s : γ → β) : ∑' i : ℕ, m (⨆ b ∈ decode₂ γ i, s b) = ∑' b : γ, m (s b) :=
begin
have H : ∀ n, m (⨆ b ∈ decode₂ γ n, s b) ≠ 0 → (decode₂ γ n).is_some,
{ intros n h,
cases decode₂ γ n with b,
{ refine (h $ by simp [m0]).elim },
{ exact rfl } },
symmetry, refine tsum_eq_tsum_of_ne_zero_bij (λ a, option.get (H a.1 a.2)) _ _ _,
{ rintros ⟨m, hm⟩ ⟨n, hn⟩ e,
have := mem_decode₂.1 (option.get_mem (H n hn)),
rwa [← e, mem_decode₂.1 (option.get_mem (H m hm))] at this },
{ intros b h,
refine ⟨⟨encode b, _⟩, _⟩,
{ simp only [mem_support, encodek₂] at h ⊢, convert h, simp [set.ext_iff, encodek₂] },
{ exact option.get_of_mem _ (encodek₂ _) } },
{ rintros ⟨n, h⟩, dsimp only [subtype.coe_mk],
transitivity, swap,
rw [show decode₂ γ n = _, from option.get_mem (H n h)],
congr, simp [ext_iff, -option.some_get] }
end
/-- `tsum_supr_decode₂` specialized to the complete lattice of sets. -/
theorem tsum_Union_decode₂ (m : set β → α) (m0 : m ∅ = 0)
(s : γ → set β) : ∑' i, m (⋃ b ∈ decode₂ γ i, s b) = ∑' b, m (s b) :=
tsum_supr_decode₂ m m0 s
/-! Some properties about measure-like functions.
These could also be functions defined on complete sublattices of sets, with the property
that they are countably sub-additive.
`R` will probably be instantiated with `(≤)` in all applications.
-/
/-- If a function is countably sub-additive then it is sub-additive on encodable types -/
theorem rel_supr_tsum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) ∑' i, m (s i))
(s : γ → β) : R (m (⨆ b : γ, s b)) ∑' b : γ, m (s b) :=
by { rw [← supr_decode₂, ← tsum_supr_decode₂ _ m0 s], exact m_supr _ }
/-- If a function is countably sub-additive then it is sub-additive on finite sets -/
theorem rel_supr_sum [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i)))
(s : δ → β) (t : finset δ) :
R (m (⨆ d ∈ t, s d)) (∑ d in t, m (s d)) :=
by { cases t.nonempty_encodable, rw [supr_subtype'], convert rel_supr_tsum m m0 R m_supr _,
rw [← finset.tsum_subtype], assumption }
/-- If a function is countably sub-additive then it is binary sub-additive -/
theorem rel_sup_add [complete_lattice β] (m : β → α) (m0 : m ⊥ = 0)
(R : α → α → Prop) (m_supr : ∀(s : ℕ → β), R (m (⨆ i, s i)) (∑' i, m (s i)))
(s₁ s₂ : β) : R (m (s₁ ⊔ s₂)) (m s₁ + m s₂) :=
begin
convert rel_supr_tsum m m0 R m_supr (λ b, cond b s₁ s₂),
{ simp only [supr_bool_eq, cond] },
{ rw [tsum_fintype, fintype.sum_bool, cond, cond] }
end
end encodable
variables [has_continuous_add α]
lemma tsum_add_tsum_compl {s : set β} (hs : summable (f ∘ coe : s → α))
(hsc : summable (f ∘ coe : sᶜ → α)) :
(∑' x : s, f x) + (∑' x : sᶜ, f x) = ∑' x, f x :=
(hs.has_sum.add_compl hsc.has_sum).tsum_eq.symm
lemma tsum_union_disjoint {s t : set β} (hd : disjoint s t)
(hs : summable (f ∘ coe : s → α)) (ht : summable (f ∘ coe : t → α)) :
(∑' x : s ∪ t, f x) = (∑' x : s, f x) + (∑' x : t, f x) :=
(hs.has_sum.add_disjoint hd ht.has_sum).tsum_eq
lemma tsum_even_add_odd {f : ℕ → α} (he : summable (λ k, f (2 * k)))
(ho : summable (λ k, f (2 * k + 1))) :
(∑' k, f (2 * k)) + (∑' k, f (2 * k + 1)) = ∑' k, f k :=
(he.has_sum.even_add_odd ho.has_sum).tsum_eq.symm
end tsum
section pi
variables {ι : Type*} {π : α → Type*} [∀ x, add_comm_monoid (π x)] [∀ x, topological_space (π x)]
lemma pi.has_sum {f : ι → ∀ x, π x} {g : ∀ x, π x} :
has_sum f g ↔ ∀ x, has_sum (λ i, f i x) (g x) :=
by simp only [has_sum, tendsto_pi, sum_apply]
lemma pi.summable {f : ι → ∀ x, π x} : summable f ↔ ∀ x, summable (λ i, f i x) :=
by simp only [summable, pi.has_sum, skolem]
lemma tsum_apply [∀ x, t2_space (π x)] {f : ι → ∀ x, π x}{x : α} (hf : summable f) :
(∑' i, f i) x = ∑' i, f i x :=
(pi.has_sum.mp hf.has_sum x).tsum_eq.symm
end pi
section topological_group
variables [add_comm_group α] [topological_space α] [topological_add_group α]
variables {f g : β → α} {a a₁ a₂ : α}
-- `by simpa using` speeds up elaboration. Why?
lemma has_sum.neg (h : has_sum f a) : has_sum (λb, - f b) (- a) :=
by simpa only using h.map (-add_monoid_hom.id α) continuous_neg
lemma summable.neg (hf : summable f) : summable (λb, - f b) :=
hf.has_sum.neg.summable
lemma summable.of_neg (hf : summable (λb, - f b)) : summable f :=
by simpa only [neg_neg] using hf.neg
lemma summable_neg_iff : summable (λ b, - f b) ↔ summable f :=
⟨summable.of_neg, summable.neg⟩
lemma has_sum.sub (hf : has_sum f a₁) (hg : has_sum g a₂) : has_sum (λb, f b - g b) (a₁ - a₂) :=
by { simp only [sub_eq_add_neg], exact hf.add hg.neg }
lemma summable.sub (hf : summable f) (hg : summable g) : summable (λb, f b - g b) :=
(hf.has_sum.sub hg.has_sum).summable
lemma has_sum.update (hf : has_sum f a₁) (b : β) [decidable_eq β] (a : α) :
has_sum (update f b a) (a - f b + a₁) :=
begin
convert ((has_sum_ite_eq b _).add hf),
ext b',
by_cases h : b' = b,
{ rw [h, update_same],
simp only [eq_self_iff_true, if_true, sub_add_cancel] },
simp only [h, update_noteq, if_false, ne.def, zero_add, not_false_iff],
end
lemma summable.update (hf : summable f) (b : β) [decidable_eq β] (a : α) :
summable (update f b a) :=
(hf.has_sum.update b a).summable
lemma has_sum.has_sum_compl_iff {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) :
has_sum (f ∘ coe : sᶜ → α) a₂ ↔ has_sum f (a₁ + a₂) :=
begin
refine ⟨λ h, hf.add_compl h, λ h, _⟩,
rw [has_sum_subtype_iff_indicator] at hf ⊢,
rw [set.indicator_compl],
simpa only [add_sub_cancel'] using h.sub hf
end
lemma has_sum.has_sum_iff_compl {s : set β} (hf : has_sum (f ∘ coe : s → α) a₁) :
has_sum f a₂ ↔ has_sum (f ∘ coe : sᶜ → α) (a₂ - a₁) :=
iff.symm $ hf.has_sum_compl_iff.trans $ by rw [add_sub_cancel'_right]
lemma summable.summable_compl_iff {s : set β} (hf : summable (f ∘ coe : s → α)) :
summable (f ∘ coe : sᶜ → α) ↔ summable f :=
⟨λ ⟨a, ha⟩, (hf.has_sum.has_sum_compl_iff.1 ha).summable,
λ ⟨a, ha⟩, (hf.has_sum.has_sum_iff_compl.1 ha).summable⟩
protected lemma finset.has_sum_compl_iff (s : finset β) :
has_sum (λ x : {x // x ∉ s}, f x) a ↔ has_sum f (a + ∑ i in s, f i) :=
(s.has_sum f).has_sum_compl_iff.trans $ by rw [add_comm]
protected lemma finset.has_sum_iff_compl (s : finset β) :
has_sum f a ↔ has_sum (λ x : {x // x ∉ s}, f x) (a - ∑ i in s, f i) :=
(s.has_sum f).has_sum_iff_compl
protected lemma finset.summable_compl_iff (s : finset β) :
summable (λ x : {x // x ∉ s}, f x) ↔ summable f :=
(s.summable f).summable_compl_iff
lemma set.finite.summable_compl_iff {s : set β} (hs : s.finite) :
summable (f ∘ coe : sᶜ → α) ↔ summable f :=
(hs.summable f).summable_compl_iff
lemma has_sum_ite_eq_extract [decidable_eq β] (hf : has_sum f a) (b : β) :
has_sum (λ n, ite (n = b) 0 (f n)) (a - f b) :=
begin
convert hf.update b 0 using 1,
{ ext n, rw function.update_apply, },
{ rw [sub_add_eq_add_sub, zero_add], },
end
section tsum
variables [t2_space α]
lemma tsum_neg (hf : summable f) : ∑'b, - f b = - ∑'b, f b :=
hf.has_sum.neg.tsum_eq
lemma tsum_sub (hf : summable f) (hg : summable g) : ∑'b, (f b - g b) = ∑'b, f b - ∑'b, g b :=
(hf.has_sum.sub hg.has_sum).tsum_eq
lemma sum_add_tsum_compl {s : finset β} (hf : summable f) :
(∑ x in s, f x) + (∑' x : (↑s : set β)ᶜ, f x) = ∑' x, f x :=
((s.has_sum f).add_compl (s.summable_compl_iff.2 hf).has_sum).tsum_eq.symm
/-- Let `f : β → α` be a sequence with summable series and let `b ∈ β` be an index.
Lemma `tsum_ite_eq_extract` writes `Σ f n` as the sum of `f b` plus the series of the
remaining terms. -/
lemma tsum_ite_eq_extract [decidable_eq β] (hf : summable f) (b : β) :
∑' n, f n = f b + ∑' n, ite (n = b) 0 (f n) :=
begin
rw (has_sum_ite_eq_extract hf.has_sum b).tsum_eq,
exact (add_sub_cancel'_right _ _).symm,
end
end tsum
/-!
### Sums on subtypes
If `s` is a finset of `α`, we show that the summability of `f` in the whole space and on the subtype
`univ - s` are equivalent, and relate their sums. For a function defined on `ℕ`, we deduce the
formula `(∑ i in range k, f i) + (∑' i, f (i + k)) = (∑' i, f i)`, in `sum_add_tsum_nat_add`.
-/
section subtype
lemma has_sum_nat_add_iff {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) a ↔ has_sum f (a + ∑ i in range k, f i) :=
begin
refine iff.trans _ ((range k).has_sum_compl_iff),
rw [← (not_mem_range_equiv k).symm.has_sum_iff],
refl
end
lemma summable_nat_add_iff {f : ℕ → α} (k : ℕ) : summable (λ n, f (n + k)) ↔ summable f :=
iff.symm $ (equiv.add_right (∑ i in range k, f i)).summable_iff_of_has_sum_iff $
λ a, (has_sum_nat_add_iff k).symm
lemma has_sum_nat_add_iff' {f : ℕ → α} (k : ℕ) {a : α} :
has_sum (λ n, f (n + k)) (a - ∑ i in range k, f i) ↔ has_sum f a :=
by simp [has_sum_nat_add_iff]
lemma sum_add_tsum_nat_add [t2_space α] {f : ℕ → α} (k : ℕ) (h : summable f) :
(∑ i in range k, f i) + (∑' i, f (i + k)) = ∑' i, f i :=
by simpa only [add_comm] using
((has_sum_nat_add_iff k).1 ((summable_nat_add_iff k).2 h).has_sum).unique h.has_sum
lemma tsum_eq_zero_add [t2_space α] {f : ℕ → α} (hf : summable f) :
∑'b, f b = f 0 + ∑'b, f (b + 1) :=
by simpa only [sum_range_one] using (sum_add_tsum_nat_add 1 hf).symm
/-- For `f : ℕ → α`, then `∑' k, f (k + i)` tends to zero. This does not require a summability
assumption on `f`, as otherwise all sums are zero. -/
lemma tendsto_sum_nat_add [t2_space α] (f : ℕ → α) : tendsto (λ i, ∑' k, f (k + i)) at_top (𝓝 0) :=
begin
by_cases hf : summable f,
{ have h₀ : (λ i, (∑' i, f i) - ∑ j in range i, f j) = λ i, ∑' (k : ℕ), f (k + i),
{ ext1 i,
rw [sub_eq_iff_eq_add, add_comm, sum_add_tsum_nat_add i hf] },
have h₁ : tendsto (λ i : ℕ, ∑' i, f i) at_top (𝓝 (∑' i, f i)) := tendsto_const_nhds,
simpa only [h₀, sub_self] using tendsto.sub h₁ hf.has_sum.tendsto_sum_nat },
{ convert tendsto_const_nhds,
ext1 i,
rw ← summable_nat_add_iff i at hf,
{ exact tsum_eq_zero_of_not_summable hf },
{ apply_instance } }
end
end subtype
end topological_group
section topological_semiring
variables [semiring α] [topological_space α] [topological_semiring α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum.mul_left (a₂) (h : has_sum f a₁) : has_sum (λb, a₂ * f b) (a₂ * a₁) :=
by simpa only using h.map (add_monoid_hom.mul_left a₂) (continuous_const.mul continuous_id)
lemma has_sum.mul_right (a₂) (hf : has_sum f a₁) : has_sum (λb, f b * a₂) (a₁ * a₂) :=
by simpa only using hf.map (add_monoid_hom.mul_right a₂) (continuous_id.mul continuous_const)
lemma summable.mul_left (a) (hf : summable f) : summable (λb, a * f b) :=
(hf.has_sum.mul_left _).summable
lemma summable.mul_right (a) (hf : summable f) : summable (λb, f b * a) :=
(hf.has_sum.mul_right _).summable
section tsum
variables [t2_space α]
lemma summable.tsum_mul_left (a) (hf : summable f) : ∑'b, a * f b = a * ∑'b, f b :=
(hf.has_sum.mul_left _).tsum_eq
lemma summable.tsum_mul_right (a) (hf : summable f) : (∑'b, f b * a) = (∑'b, f b) * a :=
(hf.has_sum.mul_right _).tsum_eq
end tsum
end topological_semiring
section has_continuous_smul
variables {R : Type*}
[semiring R] [topological_space R]
[topological_space α] [add_comm_monoid α]
[module R α] [has_continuous_smul R α]
{f : β → α}
lemma has_sum.smul {a : α} {r : R} (hf : has_sum f a) : has_sum (λ z, r • f z) (r • a) :=
hf.map (const_smul_hom α r) (continuous_const.smul continuous_id)
lemma summable.smul {r : R} (hf : summable f) : summable (λ z, r • f z) :=
hf.has_sum.smul.summable
lemma tsum_smul [t2_space α] {r : R} (hf : summable f) : ∑' z, r • f z = r • ∑' z, f z :=
hf.has_sum.smul.tsum_eq
end has_continuous_smul
section division_ring
variables [division_ring α] [topological_space α] [topological_semiring α]
{f g : β → α} {a a₁ a₂ : α}
lemma has_sum.div_const (h : has_sum f a) (b : α) : has_sum (λ x, f x / b) (a / b) :=
by simp only [div_eq_mul_inv, h.mul_right b⁻¹]
lemma has_sum_mul_left_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, a₂ * f b) (a₂ * a₁) :=
⟨has_sum.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a₂⁻¹⟩
lemma has_sum_mul_right_iff (h : a₂ ≠ 0) : has_sum f a₁ ↔ has_sum (λb, f b * a₂) (a₁ * a₂) :=
⟨has_sum.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a₂⁻¹⟩
lemma summable_mul_left_iff (h : a ≠ 0) : summable f ↔ summable (λb, a * f b) :=
⟨λ H, H.mul_left _, λ H, by simpa only [inv_mul_cancel_left' h] using H.mul_left a⁻¹⟩
lemma summable_mul_right_iff (h : a ≠ 0) : summable f ↔ summable (λb, f b * a) :=
⟨λ H, H.mul_right _, λ H, by simpa only [mul_inv_cancel_right' h] using H.mul_right a⁻¹⟩
lemma tsum_mul_left [t2_space α] : (∑' x, a * f x) = a * ∑' x, f x :=
if hf : summable f then hf.tsum_mul_left a
else if ha : a = 0 then by simp [ha]
else by rw [tsum_eq_zero_of_not_summable hf,
tsum_eq_zero_of_not_summable (mt (summable_mul_left_iff ha).2 hf), mul_zero]
lemma tsum_mul_right [t2_space α] : (∑' x, f x * a) = (∑' x, f x) * a :=
if hf : summable f then hf.tsum_mul_right a
else if ha : a = 0 then by simp [ha]
else by rw [tsum_eq_zero_of_not_summable hf,
tsum_eq_zero_of_not_summable (mt (summable_mul_right_iff ha).2 hf), zero_mul]
end division_ring
section order_topology
variables [ordered_add_comm_monoid α] [topological_space α] [order_closed_topology α]
variables {f g : β → α} {a a₁ a₂ : α}
lemma has_sum_le (h : ∀b, f b ≤ g b) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
le_of_tendsto_of_tendsto' hf hg $ assume s, sum_le_sum $ assume b _, h b
@[mono] lemma has_sum_mono (hf : has_sum f a₁) (hg : has_sum g a₂) (h : f ≤ g) : a₁ ≤ a₂ :=
has_sum_le h hf hg
lemma has_sum_le_of_sum_le (hf : has_sum f a) (h : ∀ s : finset β, ∑ b in s, f b ≤ a₂) :
a ≤ a₂ :=
le_of_tendsto' hf h
lemma le_has_sum_of_le_sum (hf : has_sum f a) (h : ∀ s : finset β, a₂ ≤ ∑ b in s, f b) :
a₂ ≤ a :=
ge_of_tendsto' hf h
lemma has_sum_le_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : has_sum f a₁) (hg : has_sum g a₂) : a₁ ≤ a₂ :=
have has_sum (λc, (partial_inv i c).cases_on' 0 f) a₁,
begin
refine (has_sum_iff_has_sum_of_ne_zero_bij (i ∘ coe) _ _ _).2 hf,
{ exact assume c₁ c₂ eq, hi eq },
{ intros c hc,
rw [mem_support] at hc,
cases eq : partial_inv i c with b; rw eq at hc,
{ contradiction },
{ rw [partial_inv_of_injective hi] at eq,
exact ⟨⟨b, hc⟩, eq⟩ } },
{ assume c, simp [partial_inv_left hi, option.cases_on'] }
end,
begin
refine has_sum_le (assume c, _) this hg,
by_cases c ∈ set.range i,
{ rcases h with ⟨b, rfl⟩,
rw [partial_inv_left hi, option.cases_on'],
exact h _ },
{ have : partial_inv i c = none := dif_neg h,
rw [this, option.cases_on'],
exact hs _ h }
end
lemma tsum_le_tsum_of_inj {g : γ → α} (i : β → γ) (hi : injective i) (hs : ∀c∉set.range i, 0 ≤ g c)
(h : ∀b, f b ≤ g (i b)) (hf : summable f) (hg : summable g) : tsum f ≤ tsum g :=
has_sum_le_inj i hi hs h hf.has_sum hg.has_sum
lemma sum_le_has_sum (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : has_sum f a) :
∑ b in s, f b ≤ a :=
ge_of_tendsto hf (eventually_at_top.2 ⟨s, λ t hst,
sum_le_sum_of_subset_of_nonneg hst $ λ b hbt hbs, hs b hbs⟩)
lemma is_lub_has_sum (h : ∀ b, 0 ≤ f b) (hf : has_sum f a) :
is_lub (set.range (λ s : finset β, ∑ b in s, f b)) a :=
is_lub_of_tendsto (finset.sum_mono_set_of_nonneg h) hf
lemma le_has_sum (hf : has_sum f a) (b : β) (hb : ∀ b' ≠ b, 0 ≤ f b') : f b ≤ a :=
calc f b = ∑ b in {b}, f b : finset.sum_singleton.symm
... ≤ a : sum_le_has_sum _ (by { convert hb, simp }) hf
lemma sum_le_tsum {f : β → α} (s : finset β) (hs : ∀ b∉s, 0 ≤ f b) (hf : summable f) :
∑ b in s, f b ≤ ∑' b, f b :=
sum_le_has_sum s hs hf.has_sum
lemma le_tsum (hf : summable f) (b : β) (hb : ∀ b' ≠ b, 0 ≤ f b') : f b ≤ ∑' b, f b :=
le_has_sum (summable.has_sum hf) b hb
lemma tsum_le_tsum (h : ∀b, f b ≤ g b) (hf : summable f) (hg : summable g) : ∑'b, f b ≤ ∑'b, g b :=
has_sum_le h hf.has_sum hg.has_sum
@[mono] lemma tsum_mono (hf : summable f) (hg : summable g) (h : f ≤ g) :
∑' n, f n ≤ ∑' n, g n :=
tsum_le_tsum h hf hg
lemma tsum_le_of_sum_le (hf : summable f) (h : ∀ s : finset β, ∑ b in s, f b ≤ a₂) :
∑' b, f b ≤ a₂ :=
has_sum_le_of_sum_le hf.has_sum h
lemma tsum_le_of_sum_le' (ha₂ : 0 ≤ a₂) (h : ∀ s : finset β, ∑ b in s, f b ≤ a₂) :
∑' b, f b ≤ a₂ :=
begin
by_cases hf : summable f,
{ exact tsum_le_of_sum_le hf h },
{ rw tsum_eq_zero_of_not_summable hf,
exact ha₂ }
end
lemma has_sum.nonneg (h : ∀ b, 0 ≤ g b) (ha : has_sum g a) : 0 ≤ a :=
has_sum_le h has_sum_zero ha
lemma has_sum.nonpos (h : ∀ b, g b ≤ 0) (ha : has_sum g a) : a ≤ 0 :=
has_sum_le h ha has_sum_zero
lemma tsum_nonneg (h : ∀ b, 0 ≤ g b) : 0 ≤ ∑'b, g b :=
begin
by_cases hg : summable g,
{ exact hg.has_sum.nonneg h },
{ simp [tsum_eq_zero_of_not_summable hg] }
end
lemma tsum_nonpos (h : ∀ b, f b ≤ 0) : ∑'b, f b ≤ 0 :=
begin
by_cases hf : summable f,
{ exact hf.has_sum.nonpos h },
{ simp [tsum_eq_zero_of_not_summable hf] }
end
end order_topology
section ordered_topological_group
variables [ordered_add_comm_group α] [topological_space α] [topological_add_group α]
[order_closed_topology α] {f g : β → α} {a₁ a₂ : α}
lemma has_sum_lt {i : β} (h : ∀ (b : β), f b ≤ g b) (hi : f i < g i)
(hf : has_sum f a₁) (hg : has_sum g a₂) :
a₁ < a₂ :=
have update f i 0 ≤ update g i 0 := update_le_update_iff.mpr ⟨rfl.le, λ i _, h i⟩,
have 0 - f i + a₁ ≤ 0 - g i + a₂ := has_sum_le this (hf.update i 0) (hg.update i 0),
by simpa only [zero_sub, add_neg_cancel_left] using add_lt_add_of_lt_of_le hi this
@[mono] lemma has_sum_strict_mono (hf : has_sum f a₁) (hg : has_sum g a₂) (h : f < g) : a₁ < a₂ :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in has_sum_lt hle hi hf hg
lemma tsum_lt_tsum {i : β} (h : ∀ (b : β), f b ≤ g b) (hi : f i < g i)
(hf : summable f) (hg : summable g) :
∑' n, f n < ∑' n, g n :=
has_sum_lt h hi hf.has_sum hg.has_sum
@[mono] lemma tsum_strict_mono (hf : summable f) (hg : summable g) (h : f < g) :
∑' n, f n < ∑' n, g n :=
let ⟨hle, i, hi⟩ := pi.lt_def.mp h in tsum_lt_tsum hle hi hf hg
lemma tsum_pos (hsum : summable g) (hg : ∀ b, 0 ≤ g b) (i : β) (hi : 0 < g i) :
0 < ∑' b, g b :=
by { rw ← tsum_zero, exact tsum_lt_tsum hg hi summable_zero hsum }
end ordered_topological_group
section canonically_ordered
variables [canonically_ordered_add_monoid α] [topological_space α] [order_closed_topology α]
variables {f : β → α} {a : α}
lemma le_has_sum' (hf : has_sum f a) (b : β) : f b ≤ a :=
le_has_sum hf b $ λ _ _, zero_le _
lemma le_tsum' (hf : summable f) (b : β) : f b ≤ ∑' b, f b :=
le_tsum hf b $ λ _ _, zero_le _
lemma has_sum_zero_iff : has_sum f 0 ↔ ∀ x, f x = 0 :=
begin
refine ⟨_, λ h, _⟩,
{ contrapose!,
exact λ ⟨x, hx⟩ h, irrefl _ (lt_of_lt_of_le (pos_iff_ne_zero.2 hx) (le_has_sum' h x)) },
{ convert has_sum_zero,
exact funext h }
end
lemma tsum_eq_zero_iff (hf : summable f) : ∑' i, f i = 0 ↔ ∀ x, f x = 0 :=
by rw [←has_sum_zero_iff, hf.has_sum_iff]
lemma tsum_ne_zero_iff (hf : summable f) : ∑' i, f i ≠ 0 ↔ ∃ x, f x ≠ 0 :=
by rw [ne.def, tsum_eq_zero_iff hf, not_forall]
lemma is_lub_has_sum' (hf : has_sum f a) : is_lub (set.range (λ s : finset β, ∑ b in s, f b)) a :=
is_lub_of_tendsto (finset.sum_mono_set f) hf
end canonically_ordered
section uniform_group
variables [add_comm_group α] [uniform_space α]
lemma summable_iff_cauchy_seq_finset [complete_space α] {f : β → α} :
summable f ↔ cauchy_seq (λ (s : finset β), ∑ b in s, f b) :=
cauchy_map_iff_exists_tendsto.symm
variables [uniform_add_group α] {f g : β → α} {a a₁ a₂ : α}
lemma cauchy_seq_finset_iff_vanishing :
cauchy_seq (λ (s : finset β), ∑ b in s, f b)
↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) :=
begin
simp only [cauchy_seq, cauchy_map_iff, and_iff_right at_top_ne_bot,
prod_at_top_at_top_eq, uniformity_eq_comap_nhds_zero α, tendsto_comap_iff, (∘)],
rw [tendsto_at_top'],
split,
{ assume h e he,
rcases h e he with ⟨⟨s₁, s₂⟩, h⟩,
use [s₁ ∪ s₂],
assume t ht,
specialize h (s₁ ∪ s₂, (s₁ ∪ s₂) ∪ t) ⟨le_sup_left, le_sup_of_le_left le_sup_right⟩,
simpa only [finset.sum_union ht.symm, add_sub_cancel'] using h },
{ assume h e he,
rcases exists_nhds_half_neg he with ⟨d, hd, hde⟩,
rcases h d hd with ⟨s, h⟩,
use [(s, s)],
rintros ⟨t₁, t₂⟩ ⟨ht₁, ht₂⟩,
have : ∑ b in t₂, f b - ∑ b in t₁, f b = ∑ b in t₂ \ s, f b - ∑ b in t₁ \ s, f b,
{ simp only [(finset.sum_sdiff ht₁).symm, (finset.sum_sdiff ht₂).symm,
add_sub_add_right_eq_sub] },
simp only [this],
exact hde _ (h _ finset.sdiff_disjoint) _ (h _ finset.sdiff_disjoint) }
end
variable [complete_space α]
lemma summable_iff_vanishing :
summable f ↔ ∀ e ∈ 𝓝 (0:α), (∃s:finset β, ∀t, disjoint t s → ∑ b in t, f b ∈ e) :=
by rw [summable_iff_cauchy_seq_finset, cauchy_seq_finset_iff_vanishing]
/- TODO: generalize to monoid with a uniform continuous subtraction operator: `(a + b) - b = a` -/
lemma summable.summable_of_eq_zero_or_self (hf : summable f) (h : ∀b, g b = 0 ∨ g b = f b) :
summable g :=
summable_iff_vanishing.2 $
assume e he,
let ⟨s, hs⟩ := summable_iff_vanishing.1 hf e he in
⟨s, assume t ht,
have eq : ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t, g b :=
calc ∑ b in t.filter (λb, g b = f b), f b = ∑ b in t.filter (λb, g b = f b), g b :
finset.sum_congr rfl (assume b hb, (finset.mem_filter.1 hb).2.symm)
... = ∑ b in t, g b :
begin
refine finset.sum_subset (finset.filter_subset _ _) _,
assume b hbt hb,
simp only [(∉), finset.mem_filter, and_iff_right hbt] at hb,
exact (h b).resolve_right hb
end,
eq ▸ hs _ $ finset.disjoint_of_subset_left (finset.filter_subset _ _) ht⟩
protected lemma summable.indicator (hf : summable f) (s : set β) :
summable (s.indicator f) :=
hf.summable_of_eq_zero_or_self $ set.indicator_eq_zero_or_self _ _
lemma summable.comp_injective {i : γ → β} (hf : summable f) (hi : injective i) :
summable (f ∘ i) :=
begin
simpa only [set.indicator_range_comp]
using (hi.summable_iff _).2 (hf.indicator (set.range i)),
exact λ x hx, set.indicator_of_not_mem hx _
end
lemma summable.subtype (hf : summable f) (s : set β) : summable (f ∘ coe : s → α) :=
hf.comp_injective subtype.coe_injective
lemma summable_subtype_and_compl {s : set β} :
summable (λ x : s, f x) ∧ summable (λ x : sᶜ, f x) ↔ summable f :=
⟨and_imp.2 summable.add_compl, λ h, ⟨h.subtype s, h.subtype sᶜ⟩⟩
lemma summable.sigma_factor {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) (b : β) : summable (λc, f ⟨b, c⟩) :=
ha.comp_injective sigma_mk_injective
lemma summable.sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : summable (λb, ∑'c, f ⟨b, c⟩) :=
ha.sigma' (λ b, ha.sigma_factor b)
lemma summable.prod_factor {f : β × γ → α} (h : summable f) (b : β) :
summable (λ c, f (b, c)) :=
h.comp_injective $ λ c₁ c₂ h, (prod.ext_iff.1 h).2
lemma tsum_sigma [regular_space α] {γ : β → Type*} {f : (Σb:β, γ b) → α}
(ha : summable f) : ∑'p, f p = ∑'b c, f ⟨b, c⟩ :=
tsum_sigma' (λ b, ha.sigma_factor b) ha
lemma tsum_prod [regular_space α] {f : β × γ → α} (h : summable f) :
∑'p, f p = ∑'b c, f ⟨b, c⟩ :=
tsum_prod' h h.prod_factor
lemma tsum_comm [regular_space α] {f : β → γ → α} (h : summable (function.uncurry f)) :
∑' c b, f b c = ∑' b c, f b c :=
tsum_comm' h h.prod_factor h.prod_symm.prod_factor
end uniform_group
section topological_group
variables {G : Type*} [topological_space G] [add_comm_group G] [topological_add_group G]
{f : α → G}
lemma summable.vanishing (hf : summable f) ⦃e : set G⦄ (he : e ∈ 𝓝 (0 : G)) :
∃ s : finset α, ∀ t, disjoint t s → ∑ k in t, f k ∈ e :=
begin
letI : uniform_space G := topological_add_group.to_uniform_space G,
letI : uniform_add_group G := topological_add_group_is_uniform,
rcases hf with ⟨y, hy⟩,
exact cauchy_seq_finset_iff_vanishing.1 hy.cauchy_seq e he
end
/-- Series divergence test: if `f` is a convergent series, then `f x` tends to zero along
`cofinite`. -/
lemma summable.tendsto_cofinite_zero (hf : summable f) : tendsto f cofinite (𝓝 0) :=
begin
intros e he,
rw [filter.mem_map],
rcases hf.vanishing he with ⟨s, hs⟩,
refine s.eventually_cofinite_nmem.mono (λ x hx, _),
by simpa using hs {x} (singleton_disjoint.2 hx)
end
lemma summable.tendsto_at_top_zero {f : ℕ → G} (hf : summable f) : tendsto f at_top (𝓝 0) :=
by { rw ←nat.cofinite_eq_at_top, exact hf.tendsto_cofinite_zero }
end topological_group
section linear_order
/-! For infinite sums taking values in a linearly ordered monoid, the existence of a least upper
bound for the finite sums is a criterion for summability.
This criterion is useful when applied in a linearly ordered monoid which is also a complete or
conditionally complete linear order, such as `ℝ`, `ℝ≥0`, `ℝ≥0∞`, because it is then easy to check
the existence of a least upper bound.
-/
lemma has_sum_of_is_lub_of_nonneg [linear_ordered_add_comm_monoid β] [topological_space β]
[order_topology β] {f : α → β} (b : β) (h : ∀ b, 0 ≤ f b)
(hf : is_lub (set.range (λ s, ∑ a in s, f a)) b) :
has_sum f b :=
tendsto_at_top_is_lub (finset.sum_mono_set_of_nonneg h) hf
lemma has_sum_of_is_lub [canonically_linear_ordered_add_monoid β] [topological_space β]
[order_topology β] {f : α → β} (b : β) (hf : is_lub (set.range (λ s, ∑ a in s, f a)) b) :
has_sum f b :=
tendsto_at_top_is_lub (finset.sum_mono_set f) hf
lemma summable_abs_iff [linear_ordered_add_comm_group β] [uniform_space β]
[uniform_add_group β] [complete_space β] {f : α → β} :
summable (λ x, abs (f x)) ↔ summable f :=
have h1 : ∀ x : {x | 0 ≤ f x}, abs (f x) = f x := λ x, abs_of_nonneg x.2,
have h2 : ∀ x : {x | 0 ≤ f x}ᶜ, abs (f x) = -f x := λ x, abs_of_neg (not_le.1 x.2),
calc summable (λ x, abs (f x)) ↔
summable (λ x : {x | 0 ≤ f x}, abs (f x)) ∧ summable (λ x : {x | 0 ≤ f x}ᶜ, abs (f x)) :
summable_subtype_and_compl.symm
... ↔ summable (λ x : {x | 0 ≤ f x}, f x) ∧ summable (λ x : {x | 0 ≤ f x}ᶜ, -f x) :
by simp only [h1, h2]
... ↔ _ : by simp only [summable_neg_iff, summable_subtype_and_compl]
alias summable_abs_iff ↔ summable.of_abs summable.abs
end linear_order
section cauchy_seq
open finset.Ico filter
/-- If the extended distance between consecutive points of a sequence is estimated
by a summable series of `nnreal`s, then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_edist_le_of_summable [pseudo_emetric_space α] {f : ℕ → α} (d : ℕ → ℝ≥0)
(hf : ∀ n, edist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine emetric.cauchy_seq_iff_nnreal.2 (λ ε εpos, _),
-- Actually we need partial sums of `d` to be a Cauchy sequence
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in H.tendsto_sum_nat.cauchy_seq,
-- Now we take the same `N` as in one of the definitions of a Cauchy sequence
refine (metric.cauchy_seq_iff'.1 hd ε (nnreal.coe_pos.2 εpos)).imp (λ N hN n hn, _),
have hsum := hN n hn,
-- We simplify the known inequality
rw [dist_nndist, nnreal.nndist_eq, ← sum_range_add_sum_Ico _ hn, nnreal.add_sub_cancel'] at hsum,
norm_cast at hsum,
replace hsum := lt_of_le_of_lt (le_max_left _ _) hsum,
rw edist_comm,
-- Then use `hf` to simplify the goal to the same form
apply lt_of_le_of_lt (edist_le_Ico_sum_of_edist_le hn (λ k _ _, hf k)),
assumption_mod_cast
end
/-- If the distance between consecutive points of a sequence is estimated by a summable series,
then the original sequence is a Cauchy sequence. -/
lemma cauchy_seq_of_dist_le_of_summable [pseudo_metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) : cauchy_seq f :=
begin
refine metric.cauchy_seq_iff'.2 (λε εpos, _),
replace hd : cauchy_seq (λ (n : ℕ), ∑ x in range n, d x) :=
let ⟨_, H⟩ := hd in H.tendsto_sum_nat.cauchy_seq,
refine (metric.cauchy_seq_iff'.1 hd ε εpos).imp (λ N hN n hn, _),
have hsum := hN n hn,
rw [real.dist_eq, ← sum_Ico_eq_sub _ hn] at hsum,
calc dist (f n) (f N) = dist (f N) (f n) : dist_comm _ _
... ≤ ∑ x in Ico N n, d x : dist_le_Ico_sum_of_dist_le hn (λ k _ _, hf k)
... ≤ abs (∑ x in Ico N n, d x) : le_abs_self _
... < ε : hsum
end
lemma cauchy_seq_of_summable_dist [pseudo_metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) : cauchy_seq f :=
cauchy_seq_of_dist_le_of_summable _ (λ _, le_refl _) h
lemma dist_le_tsum_of_dist_le_of_tendsto [pseudo_metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a))
(n : ℕ) :
dist (f n) a ≤ ∑' m, d (n + m) :=
begin
refine le_of_tendsto (tendsto_const_nhds.dist ha)
(eventually_at_top.2 ⟨n, λ m hnm, _⟩),
refine le_trans (dist_le_Ico_sum_of_dist_le hnm (λ k _ _, hf k)) _,
rw [sum_Ico_eq_sum_range],
refine sum_le_tsum (range _) (λ _ _, le_trans dist_nonneg (hf _)) _,
exact hd.comp_injective (add_right_injective n)
end
lemma dist_le_tsum_of_dist_le_of_tendsto₀ [pseudo_metric_space α] {f : ℕ → α} (d : ℕ → ℝ)
(hf : ∀ n, dist (f n) (f n.succ) ≤ d n) (hd : summable d) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ tsum d :=
by simpa only [zero_add] using dist_le_tsum_of_dist_le_of_tendsto d hf hd ha 0
lemma dist_le_tsum_dist_of_tendsto [pseudo_metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) (n) :
dist (f n) a ≤ ∑' m, dist (f (n+m)) (f (n+m).succ) :=
show dist (f n) a ≤ ∑' m, (λx, dist (f x) (f x.succ)) (n + m), from
dist_le_tsum_of_dist_le_of_tendsto (λ n, dist (f n) (f n.succ)) (λ _, le_refl _) h ha n
lemma dist_le_tsum_dist_of_tendsto₀ [pseudo_metric_space α] {f : ℕ → α}
(h : summable (λn, dist (f n) (f n.succ))) {a : α} (ha : tendsto f at_top (𝓝 a)) :
dist (f 0) a ≤ ∑' n, dist (f n) (f n.succ) :=
by simpa only [zero_add] using dist_le_tsum_dist_of_tendsto h ha 0
end cauchy_seq
|
92c0aca8851c005d383dda89ce12fb2e9ea8e0c2
|
bdb33f8b7ea65f7705fc342a178508e2722eb851
|
/analysis/real.lean
|
e12e7fd14582225fc0b6c74f663220235eaae650
|
[
"Apache-2.0"
] |
permissive
|
rwbarton/mathlib
|
939ae09bf8d6eb1331fc2f7e067d39567e10e33d
|
c13c5ea701bb1eec057e0a242d9f480a079105e9
|
refs/heads/master
| 1,584,015,335,862
| 1,524,142,167,000
| 1,524,142,167,000
| 130,614,171
| 0
| 0
|
Apache-2.0
| 1,548,902,667,000
| 1,524,437,371,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 15,142
|
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
The real numbers ℝ.
They are constructed as the topological completion of ℚ. With the following steps:
(1) prove that ℚ forms a uniform space.
(2) subtraction and addition are uniform continuous functions in this space
(3) for multiplication and inverse this only holds on bounded subsets
(4) ℝ is defined as separated Cauchy filters over ℚ (the separation requires a quotient construction)
(5) extend the uniform continuous functions along the completion
(6) proof field properties using the principle of extension of identities
TODO
generalizations:
* topological groups & rings
* order topologies
* Archimedean fields
-/
import logic.function analysis.metric_space
noncomputable theory
open classical set lattice filter
local attribute [instance] prop_decidable
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w}
instance : metric_space ℚ :=
metric_space.induced coe rat.cast_injective real.metric_space
theorem rat.dist_eq (x y : ℚ) : dist x y = abs (x - y) := rfl
instance : metric_space ℤ :=
begin
letI M := metric_space.induced coe int.cast_injective real.metric_space,
refine @metric_space.replace_uniformity _ int.uniform_space M
(le_antisymm refl_le_uniformity $ λ r ru,
mem_uniformity_dist.2 ⟨1, zero_lt_one, λ a b h,
mem_principal_sets.1 ru $ dist_le_zero.1 (_ : (abs (a - b) : ℝ) ≤ 0)⟩),
simpa using (@int.cast_le ℝ _ _ 0).2 (int.lt_add_one_iff.1 $
(@int.cast_lt ℝ _ (abs (a - b)) 1).1 $ by simpa using h)
end
theorem uniform_continuous_of_rat : uniform_continuous (coe : ℚ → ℝ) :=
uniform_continuous_vmap
theorem uniform_embedding_of_rat : uniform_embedding (coe : ℚ → ℝ) :=
metric_space.induced_uniform_embedding _ _ _
theorem dense_embedding_of_rat : dense_embedding (coe : ℚ → ℝ) :=
uniform_embedding_of_rat.dense_embedding $
λ x, mem_closure_iff_nhds.2 $ λ t ht,
let ⟨ε,ε0, hε⟩ := mem_nhds_iff_metric.1 ht in
let ⟨q, h⟩ := exists_rat_near x ε0 in
ne_empty_iff_exists_mem.2 ⟨_, hε (mem_ball'.2 h), q, rfl⟩
theorem embedding_of_rat : embedding (coe : ℚ → ℝ) := dense_embedding_of_rat.embedding
theorem continuous_of_rat : continuous (coe : ℚ → ℝ) := uniform_continuous_of_rat.continuous
theorem real.uniform_continuous_add : uniform_continuous (λp : ℝ × ℝ, p.1 + p.2) :=
uniform_continuous_of_metric.2 $ λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_add_continuous_lemma abs ε0 in
⟨δ, δ0, λ a b h, let ⟨h₁, h₂⟩ := max_lt_iff.1 h in Hδ h₁ h₂⟩
-- TODO(Mario): Find a way to use rat_add_continuous_lemma
theorem rat.uniform_continuous_add : uniform_continuous (λp : ℚ × ℚ, p.1 + p.2) :=
uniform_embedding_of_rat.uniform_continuous_iff.2 $ by simp [(∘)]; exact
((uniform_continuous_fst.comp uniform_continuous_of_rat).prod_mk
(uniform_continuous_snd.comp uniform_continuous_of_rat)).comp real.uniform_continuous_add
theorem real.uniform_continuous_neg : uniform_continuous (@has_neg.neg ℝ _) :=
uniform_continuous_of_metric.2 $ λ ε ε0, ⟨_, ε0, λ a b h,
by rw dist_comm at h; simpa [real.dist_eq] using h⟩
theorem rat.uniform_continuous_neg : uniform_continuous (@has_neg.neg ℚ _) :=
uniform_continuous_of_metric.2 $ λ ε ε0, ⟨_, ε0, λ a b h,
by rw dist_comm at h; simpa [rat.dist_eq] using h⟩
instance : uniform_add_group ℝ :=
uniform_add_group.mk' real.uniform_continuous_add real.uniform_continuous_neg
instance : uniform_add_group ℚ :=
uniform_add_group.mk' rat.uniform_continuous_add rat.uniform_continuous_neg
instance : topological_add_group ℝ := by apply_instance
instance : topological_add_group ℚ := by apply_instance
instance : orderable_topology ℚ :=
induced_orderable_topology _ (λ x y, rat.cast_lt) (@exists_rat_btwn _ _ _)
/- TODO(Mario): Prove that these are uniform isomorphisms instead of uniform embeddings
lemma uniform_embedding_add_rat {r : ℚ} : uniform_embedding (λp:ℚ, p + r) :=
_
lemma uniform_embedding_mul_rat {q : ℚ} (hq : q ≠ 0) : uniform_embedding ((*) q) :=
_ -/
lemma real.uniform_continuous_inv (s : set ℝ) {r : ℝ} (r0 : 0 < r) (H : ∀ x ∈ s, r ≤ abs x) :
uniform_continuous (λp:s, p.1⁻¹) :=
uniform_continuous_of_metric.2 $ λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_inv_continuous_lemma abs ε0 r0 in
⟨δ, δ0, λ a b h, Hδ (H _ a.2) (H _ b.2) h⟩
lemma real.uniform_continuous_abs : uniform_continuous (abs : ℝ → ℝ) :=
uniform_continuous_of_metric.2 $ λ ε ε0,
⟨ε, ε0, λ a b, lt_of_le_of_lt (abs_abs_sub_abs_le_abs_sub _ _)⟩
lemma real.continuous_abs : continuous (abs : ℝ → ℝ) :=
real.uniform_continuous_abs.continuous
lemma rat.uniform_continuous_abs : uniform_continuous (abs : ℚ → ℚ) :=
uniform_continuous_of_metric.2 $ λ ε ε0,
⟨ε, ε0, λ a b h, lt_of_le_of_lt
(by simpa [rat.dist_eq] using abs_abs_sub_abs_le_abs_sub _ _) h⟩
lemma rat.continuous_abs : continuous (abs : ℚ → ℚ) :=
rat.uniform_continuous_abs.continuous
lemma real.tendsto_inv {r : ℝ} (r0 : r ≠ 0) : tendsto (λq, q⁻¹) (nhds r) (nhds r⁻¹) :=
by rw ← abs_pos_iff at r0; exact
tendsto_of_uniform_continuous_subtype
(real.uniform_continuous_inv {x | abs r / 2 < abs x} (half_pos r0) (λ x h, le_of_lt h))
(mem_nhds_sets (real.continuous_abs _ $ is_open_lt' (abs r / 2)) (half_lt_self r0))
lemma real.continuous_inv' : continuous (λa:{r:ℝ // r ≠ 0}, a.val⁻¹) :=
continuous_iff_tendsto.mpr $ assume ⟨r, hr⟩,
(continuous_iff_tendsto.mp continuous_subtype_val _).comp (real.tendsto_inv hr)
lemma real.continuous_inv [topological_space α] {f : α → ℝ} (h : ∀a, f a ≠ 0) (hf : continuous f) :
continuous (λa, (f a)⁻¹) :=
show continuous ((has_inv.inv ∘ @subtype.val ℝ (λr, r ≠ 0)) ∘ λa, ⟨f a, h a⟩),
from (continuous_subtype_mk _ hf).comp real.continuous_inv'
lemma real.uniform_continuous_mul_const {x : ℝ} : uniform_continuous ((*) x) :=
uniform_continuous_of_metric.2 $ λ ε ε0, begin
cases no_top (abs x) with y xy,
have y0 := lt_of_le_of_lt (abs_nonneg _) xy,
refine ⟨_, div_pos ε0 y0, λ a b h, _⟩,
rw [real.dist_eq, ← mul_sub, abs_mul, ← mul_div_cancel' ε (ne_of_gt y0)],
exact mul_lt_mul' (le_of_lt xy) h (abs_nonneg _) y0
end
lemma real.uniform_continuous_mul (s : set (ℝ × ℝ))
{r₁ r₂ : ℝ} (r₁0 : 0 < r₁) (r₂0 : 0 < r₂)
(H : ∀ x ∈ s, abs (x : ℝ × ℝ).1 < r₁ ∧ abs x.2 < r₂) :
uniform_continuous (λp:s, p.1.1 * p.1.2) :=
uniform_continuous_of_metric.2 $ λ ε ε0,
let ⟨δ, δ0, Hδ⟩ := rat_mul_continuous_lemma abs ε0 r₁0 r₂0 in
⟨δ, δ0, λ a b h,
let ⟨h₁, h₂⟩ := max_lt_iff.1 h in Hδ (H _ a.2).1 (H _ b.2).2 h₁ h₂⟩
lemma real.continuous_mul : continuous (λp : ℝ × ℝ, p.1 * p.2) :=
continuous_iff_tendsto.2 $ λ ⟨a₁, a₂⟩,
tendsto_of_uniform_continuous_subtype
(real.uniform_continuous_mul
({x | abs x < abs a₁ + 1}.prod {x | abs x < abs a₂ + 1})
(lt_of_le_of_lt (abs_nonneg _) (lt_add_one _))
(lt_of_le_of_lt (abs_nonneg _) (lt_add_one _))
(λ x, id))
(mem_nhds_sets
(is_open_prod
(real.continuous_abs _ $ is_open_gt' _)
(real.continuous_abs _ $ is_open_gt' _))
⟨lt_add_one (abs a₁), lt_add_one (abs a₂)⟩)
instance : topological_ring ℝ :=
{ continuous_mul := real.continuous_mul, ..real.topological_add_group }
instance : topological_semiring ℝ := by apply_instance
lemma rat.continuous_mul : continuous (λp : ℚ × ℚ, p.1 * p.2) :=
embedding_of_rat.continuous_iff.2 $ by simp [(∘)]; exact
((continuous_fst.comp continuous_of_rat).prod_mk
(continuous_snd.comp continuous_of_rat)).comp real.continuous_mul
instance : topological_ring ℚ :=
{ continuous_mul := rat.continuous_mul, ..rat.topological_add_group }
theorem real.ball_eq_Ioo (x ε : ℝ) : ball x ε = Ioo (x - ε) (x + ε) :=
set.ext $ λ y, by rw [mem_ball, real.dist_eq,
abs_sub_lt_iff, sub_lt_iff_lt_add', and_comm, sub_lt]; refl
theorem real.Ioo_eq_ball (x y : ℝ) : Ioo x y = ball ((x + y) / 2) ((y - x) / 2) :=
by rw [real.ball_eq_Ioo, ← sub_div, add_comm, ← sub_add,
add_sub_cancel', add_self_div_two, ← add_div,
add_assoc, add_sub_cancel'_right, add_self_div_two]
lemma real.totally_bounded_Ioo (a b : ℝ) : totally_bounded (Ioo a b) :=
totally_bounded_of_metric.2 $ λ ε ε0, begin
rcases exists_nat_gt ((b - a) / ε) with ⟨n, ba⟩,
rw [div_lt_iff' ε0, sub_lt_iff_lt_add'] at ba,
let s := (λ i:ℕ, a + ε * i) '' {i:ℕ | i < n},
refine ⟨s, finite_image _ ⟨set.fintype_lt_nat _⟩, λ x h, _⟩,
rcases h with ⟨ax, xb⟩,
let i : ℕ := ⌊(x - a) / ε⌋.to_nat,
have : (i : ℤ) = ⌊(x - a) / ε⌋ :=
int.to_nat_of_nonneg (floor_nonneg.2 $ le_of_lt (div_pos (sub_pos.2 ax) ε0)),
simp, refine ⟨_, ⟨i, _, rfl⟩, _⟩,
{ rw [← int.coe_nat_lt, this],
refine int.cast_lt.1 (lt_of_le_of_lt (floor_le _) _),
rw [int.cast_coe_nat, div_lt_iff' ε0, sub_lt_iff_lt_add'],
exact lt_trans xb ba },
{ rw [real.dist_eq, ← int.cast_coe_nat, this, abs_of_nonneg,
← sub_sub, sub_lt_iff_lt_add'],
{ have := lt_floor_add_one ((x - a) / ε),
rwa [div_lt_iff' ε0, mul_add, mul_one] at this },
{ have := floor_le ((x - a) / ε),
rwa [ge, sub_nonneg, ← le_sub_iff_add_le', ← le_div_iff' ε0] } }
end
lemma real.totally_bounded_ball (x ε : ℝ) : totally_bounded (ball x ε) :=
by rw real.ball_eq_Ioo; apply real.totally_bounded_Ioo
lemma real.totally_bounded_Ico (a b : ℝ) : totally_bounded (Ico a b) :=
let ⟨c, ac⟩ := no_bot a in totally_bounded_subset
(by exact λ x ⟨h₁, h₂⟩, ⟨lt_of_lt_of_le ac h₁, h₂⟩)
(real.totally_bounded_Ioo c b)
lemma real.totally_bounded_Icc (a b : ℝ) : totally_bounded {q:ℝ | a ≤ q ∧ q ≤ b} :=
let ⟨c, bc⟩ := no_top b in totally_bounded_subset
(by exact λ x ⟨h₁, h₂⟩, ⟨h₁, lt_of_le_of_lt h₂ bc⟩)
(real.totally_bounded_Ico a c)
lemma rat.totally_bounded_Icc (a b : ℚ) : totally_bounded {q:ℚ | a ≤ q ∧ q ≤ b} :=
begin
have := totally_bounded_preimage uniform_embedding_of_rat (real.totally_bounded_Icc a b),
rwa (set.ext (λ q, _) : set_of _ = _),
dsimp, rw ← @rat.cast_le ℝ _ q b, simp
end
-- TODO(Mario): Generalize to first-countable uniform spaces?
instance : complete_space ℝ :=
⟨λ f cf, begin
have := (cauchy_of_metric.1 cf).2,
let S : ∀ ε:{ε:ℝ//ε>0}, {t : f.sets // ∀ x y ∈ t.1, dist x y < ε} :=
λ ε, classical.choice
(let ⟨t, tf, h⟩ := (cauchy_of_metric.1 cf).2 ε ε.2 in ⟨⟨⟨t, tf⟩, h⟩⟩),
let g : ℕ → {ε:ℝ//ε>0} := λ n, ⟨(n:ℕ+)⁻¹, inv_pos (nat.cast_pos.2 (n:ℕ+).pos)⟩,
have hg : ∀ ε > 0, ∃ n, ∀ j ≥ n, (g j : ℝ) < ε,
{ intros ε ε0,
cases exists_nat_gt ε⁻¹ with n hn,
refine ⟨n, λ j nj, _⟩,
have hj := lt_of_lt_of_le hn (nat.cast_le.2 nj),
have j0 := lt_trans (inv_pos ε0) hj,
have jε := (inv_lt j0 ε0).2 hj,
rwa ← pnat.nat_coe_coe (nat.cast_pos.1 j0) at jε },
let F : ∀ n : ℕ, {t : f.sets // ∀ x y ∈ t.1, dist x y < g n},
{ refine λ n, ⟨⟨_, Inter_mem_sets (finite_le_nat n) (λ i _, (S (g i)).1.2)⟩, _⟩,
have : (⋂ i ∈ {i : ℕ | i ≤ n}, (S (g i)).1.1) ⊆ S (g n) :=
bInter_subset_of_mem (le_refl n),
exact λ x y xs ys, (S (g n)).2 _ _ (this xs) (this ys) },
let G : ∀ n : ℕ, F n,
{ refine λ n, classical.choice _,
cases inhabited_of_mem_sets cf.1 (F n).1.2 with x xS,
exact ⟨⟨x, xS⟩⟩ },
let c : cau_seq ℝ abs,
{ refine ⟨λ n, G n, λ ε ε0, _⟩,
cases hg _ ε0 with n hn,
refine ⟨n, λ j jn, _⟩,
have : (F j).1.1 ⊆ (F n) :=
bInter_subset_bInter_left (λ i h, @le_trans _ _ i n j h jn),
exact lt_trans ((F n).2 _ _ (this (G j).2) (G n).2) (hn _ $ le_refl _) },
refine ⟨real.lim c, λ s h, _⟩,
rcases mem_nhds_iff_metric.1 h with ⟨ε, ε0, hε⟩,
cases exists_forall_ge_and (hg _ $ half_pos ε0)
(real.equiv_lim c _ $ half_pos ε0) with n hn,
cases hn _ (le_refl _) with h₁ h₂,
refine upwards_sets _ (F n).1.2 (subset.trans _ $
subset.trans (ball_half_subset (G n) h₂) hε),
exact λ x h, lt_trans ((F n).2 x (G n) h (G n).2) h₁
end⟩
-- TODO(Mario): This proof has nothing to do with reals
theorem real.Cauchy_eq {f g : Cauchy ℝ} :
lim f.1 = lim g.1 ↔ (f, g) ∈ separation_rel (Cauchy ℝ) :=
begin
split,
{ intros e s hs,
rcases Cauchy.mem_uniformity'.1 hs with ⟨t, tu, ts⟩,
apply ts,
rcases comp_mem_uniformity_sets tu with ⟨d, du, dt⟩,
refine mem_prod_iff.2
⟨_, le_nhds_lim_of_cauchy f.2 (mem_nhds_right (lim f.1) du),
_, le_nhds_lim_of_cauchy g.2 (mem_nhds_left (lim g.1) du), λ x h, _⟩,
cases x with a b, cases h with h₁ h₂,
rw ← e at h₂,
exact dt ⟨_, h₁, h₂⟩ },
{ intros H,
refine separated_def.1 (by apply_instance) _ _ (λ t tu, _),
rcases mem_uniformity_is_closed tu with ⟨d, du, dc, dt⟩,
refine H {p | (lim p.1.1, lim p.2.1) ∈ t}
(Cauchy.mem_uniformity'.2 ⟨d, du, λ f g h, _⟩),
rcases mem_prod_iff.1 h with ⟨x, xf, y, yg, h⟩,
have limc : ∀ (f : Cauchy ℝ) (x ∈ f.1.sets), lim f.1 ∈ closure x,
{ intros f x xf,
rw closure_eq_nhds,
exact neq_bot_of_le_neq_bot f.2.1
(le_inf (le_nhds_lim_of_cauchy f.2) (le_principal_iff.2 xf)) },
have := (closure_subset_iff_subset_of_is_closed dc).2 h,
rw closure_prod_eq at this,
refine dt (this ⟨_, _⟩); dsimp; apply limc; assumption }
end
section
lemma closure_of_rat_image_lt {q : ℚ} : closure ((coe:ℚ → ℝ) '' {x | q < x}) = {r | ↑q ≤ r} :=
subset.antisymm
((closure_subset_iff_subset_of_is_closed (is_closed_ge' _)).2
(image_subset_iff.2 $ λ p h, le_of_lt $ (@rat.cast_lt ℝ _ _ _).2 h)) $
λ x hx, mem_closure_iff_nhds.2 $ λ t ht,
let ⟨ε, ε0, hε⟩ := mem_nhds_iff_metric.1 ht in
let ⟨p, h₁, h₂⟩ := exists_rat_btwn ((lt_add_iff_pos_right x).2 ε0) in
ne_empty_iff_exists_mem.2 ⟨_, hε (show abs _ < _,
by rwa [abs_of_nonneg (le_of_lt $ sub_pos.2 h₁), sub_lt_iff_lt_add']),
p, rat.cast_lt.1 (@lt_of_le_of_lt ℝ _ _ _ _ hx h₁), rfl⟩
/- TODO(Mario): Put these back only if needed later
lemma closure_of_rat_image_le_eq {q : ℚ} : closure ((coe:ℚ → ℝ) '' {x | q ≤ x}) = {r | ↑q ≤ r} :=
_
lemma closure_of_rat_image_le_le_eq {a b : ℚ} (hab : a ≤ b) :
closure (of_rat '' {q:ℚ | a ≤ q ∧ q ≤ b}) = {r:ℝ | of_rat a ≤ r ∧ r ≤ of_rat b} :=
_-/
lemma compact_ivl {a b : ℝ} : compact {r:ℝ | a ≤ r ∧ r ≤ b} :=
compact_of_totally_bounded_is_closed
(real.totally_bounded_Icc a b)
(is_closed_inter (is_closed_ge' a) (is_closed_le' b))
lemma exists_supremum_real {s : set ℝ} {a b : ℝ} (ha : a ∈ s) (hb : b ∈ upper_bounds s) :
∃x, is_lub s x :=
⟨real.Sup s,
λ x xs, real.le_Sup s ⟨_, hb⟩ xs,
λ u h, real.Sup_le_ub _ ⟨_, ha⟩ h⟩
end
|
3d71940c528b79370ecc9d464a138706203309d1
|
037dba89703a79cd4a4aec5e959818147f97635d
|
/src/2020/logic/logic_video.lean
|
643b5fa0e3f29f9786be11ab30b2989fff9f39d9
|
[] |
no_license
|
ImperialCollegeLondon/M40001_lean
|
3a6a09298da395ab51bc220a535035d45bbe919b
|
62a76fa92654c855af2b2fc2bef8e60acd16ccec
|
refs/heads/master
| 1,666,750,403,259
| 1,665,771,117,000
| 1,665,771,117,000
| 209,141,835
| 115
| 12
| null | 1,640,270,596,000
| 1,568,749,174,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 2,102
|
lean
|
import tactic
-- Definition: a Proposition is a type `P`, where `P : Prop`.
variables (P Q R : Prop)
-- In Lean, `P → Q` means `P ⇒ Q`
example : P → P :=
begin
intro hP, -- let hP be the hypothesis that P is true
exact hP, -- our goal is exactly our hypothesis
end
example : P → (Q → P) :=
begin
intro hP, -- let hP be the hypothesis that P is true
intro hQ,
exact hP,
end
-- is → associative? i.e. Does (P → Q) → R equal P → (Q → R) ?
-- (A+B)+C = A+(B+C)
-- (A-B)-C ≠ A-(B-C)
-- (A-B)-C
-- 2^(1^3) -- this is the convention for powers
-- CONVENTION: P → Q → R with no brackets MEANS P → (Q → R)
example : P → Q → P :=
begin
intro hP,
intro hQ,
exact hP,
end
/-- Modus Ponens : if P is true, and P → Q, then Q is true -/
theorem modus_ponens : P → (P → Q) → Q :=
begin
intro hP,
intro hPQ, -- hPQ is the hypothesis that P → Q
apply hPQ, -- apply the hypothesis that P → Q
exact hP,
end
-- If `a<b` and `b<c` then `a<c` -- that's called "transitivity of <"
-- theorem transitivity : (P → Q) → (Q → R) → (P → R) :=
-- begin
-- sorry
-- end
example : (P → Q → R) → (P → Q) → (P → R) :=
begin
intro hPQR,
intro hPQ,
intro hP,
apply hPQR,
assumption,
apply hPQ,
assumption,
end
-- in Lean, the definition of ¬ P is `P → false`
-- if P is true, ¬ P is false, and P → false is false
-- if P is false, then ¬ P is true, and P → false is true
example : P → ¬ (¬ P) :=
begin
intro hP,
change (¬ P → false),
intro hnP,
change P → false at hnP,
apply hnP,
assumption,
end
example : ¬ (¬ P) → P :=
begin
finish,
end
example : P → ¬ (¬ P) :=
begin
apply modus_ponens,
end
-- and
example : P ∧ Q → P :=
begin
intro hPaQ,
cases hPaQ with hP hQ,
assumption,
end
theorem and.elim' : P ∧ Q → (P → Q → R) → R :=
begin
intro hPaQ,
intro hPQR,
cases hPaQ with hP hQ,
apply hPQR;
assumption,
end
theorem and.intro' : P → Q → P ∧ Q :=
begin
intro hP,
intro hQ,
split,
assumption,
assumption,
end
|
1fd8b7bfc53a117b9c5c5a15de87324655fa04f9
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/algebra/group/commute.lean
|
b8227479be7cc704cf0c974a9a6d07566da16a5f
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 9,662
|
lean
|
/-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland, Yury Kudryashov
-/
import algebra.group.semiconj
/-!
# Commuting pairs of elements in monoids
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We define the predicate `commute a b := a * b = b * a` and provide some operations on terms `(h :
commute a b)`. E.g., if `a`, `b`, and c are elements of a semiring, and that `hb : commute a b` and
`hc : commute a c`. Then `hb.pow_left 5` proves `commute (a ^ 5) b` and `(hb.pow_right 2).add_right
(hb.mul_right hc)` proves `commute a (b ^ 2 + b * c)`.
Lean does not immediately recognise these terms as equations, so for rewriting we need syntax like
`rw [(hb.pow_left 5).eq]` rather than just `rw [hb.pow_left 5]`.
This file defines only a few operations (`mul_left`, `inv_right`, etc). Other operations
(`pow_right`, field inverse etc) are in the files that define corresponding notions.
## Implementation details
Most of the proofs come from the properties of `semiconj_by`.
-/
variables {G : Type*}
/-- Two elements commute if `a * b = b * a`. -/
@[to_additive add_commute "Two elements additively commute if `a + b = b + a`"]
def commute {S : Type*} [has_mul S] (a b : S) : Prop := semiconj_by a b b
namespace commute
section has_mul
variables {S : Type*} [has_mul S]
/-- Equality behind `commute a b`; useful for rewriting. -/
@[to_additive "Equality behind `add_commute a b`; useful for rewriting."]
protected lemma eq {a b : S} (h : commute a b) : a * b = b * a := h
/-- Any element commutes with itself. -/
@[refl, simp, to_additive "Any element commutes with itself."]
protected lemma refl (a : S) : commute a a := eq.refl (a * a)
/-- If `a` commutes with `b`, then `b` commutes with `a`. -/
@[symm, to_additive "If `a` commutes with `b`, then `b` commutes with `a`."]
protected lemma symm {a b : S} (h : commute a b) : commute b a := eq.symm h
@[to_additive] protected theorem semiconj_by {a b : S} (h : commute a b) : semiconj_by a b b := h
@[to_additive]
protected theorem symm_iff {a b : S} : commute a b ↔ commute b a :=
⟨commute.symm, commute.symm⟩
@[to_additive] instance : is_refl S commute := ⟨commute.refl⟩
-- This instance is useful for `finset.noncomm_prod`
@[to_additive] instance on_is_refl {f : G → S} : is_refl G (λ a b, commute (f a) (f b)) :=
⟨λ _, commute.refl _⟩
end has_mul
section semigroup
variables {S : Type*} [semigroup S] {a b c : S}
/-- If `a` commutes with both `b` and `c`, then it commutes with their product. -/
@[simp, to_additive "If `a` commutes with both `b` and `c`, then it commutes with their sum."]
lemma mul_right (hab : commute a b) (hac : commute a c) : commute a (b * c) := hab.mul_right hac
/-- If both `a` and `b` commute with `c`, then their product commutes with `c`. -/
@[simp, to_additive "If both `a` and `b` commute with `c`, then their product commutes with `c`."]
lemma mul_left (hac : commute a c) (hbc : commute b c) : commute (a * b) c := hac.mul_left hbc
@[to_additive] protected lemma right_comm (h : commute b c) (a : S) :
a * b * c = a * c * b :=
by simp only [mul_assoc, h.eq]
@[to_additive] protected lemma left_comm (h : commute a b) (c) :
a * (b * c) = b * (a * c) :=
by simp only [← mul_assoc, h.eq]
@[to_additive] protected lemma mul_mul_mul_comm (hbc : commute b c) (a d : S) :
(a * b) * (c * d) = (a * c) * (b * d) :=
by simp only [hbc.left_comm, mul_assoc]
end semigroup
@[to_additive]
protected theorem all {S : Type*} [comm_semigroup S] (a b : S) : commute a b := mul_comm a b
section mul_one_class
variables {M : Type*} [mul_one_class M]
@[simp, to_additive] theorem one_right (a : M) : commute a 1 := semiconj_by.one_right a
@[simp, to_additive] theorem one_left (a : M) : commute 1 a := semiconj_by.one_left a
end mul_one_class
section monoid
variables {M : Type*} [monoid M] {a b : M} {u u₁ u₂ : Mˣ}
@[simp, to_additive]
theorem pow_right (h : commute a b) (n : ℕ) : commute a (b ^ n) := h.pow_right n
@[simp, to_additive]
theorem pow_left (h : commute a b) (n : ℕ) : commute (a ^ n) b := (h.symm.pow_right n).symm
@[simp, to_additive]
theorem pow_pow (h : commute a b) (m n : ℕ) : commute (a ^ m) (b ^ n) :=
(h.pow_left m).pow_right n
@[simp, to_additive]
theorem self_pow (a : M) (n : ℕ) : commute a (a ^ n) := (commute.refl a).pow_right n
@[simp, to_additive]
theorem pow_self (a : M) (n : ℕ) : commute (a ^ n) a := (commute.refl a).pow_left n
@[simp, to_additive]
theorem pow_pow_self (a : M) (m n : ℕ) : commute (a ^ m) (a ^ n) :=
(commute.refl a).pow_pow m n
@[to_additive succ_nsmul'] theorem _root_.pow_succ' (a : M) (n : ℕ) : a ^ (n + 1) = a ^ n * a :=
(pow_succ a n).trans (self_pow _ _)
@[to_additive] theorem units_inv_right : commute a u → commute a ↑u⁻¹ :=
semiconj_by.units_inv_right
@[simp, to_additive] theorem units_inv_right_iff :
commute a ↑u⁻¹ ↔ commute a u :=
semiconj_by.units_inv_right_iff
@[to_additive] theorem units_inv_left : commute ↑u a → commute ↑u⁻¹ a :=
semiconj_by.units_inv_symm_left
@[simp, to_additive]
theorem units_inv_left_iff: commute ↑u⁻¹ a ↔ commute ↑u a :=
semiconj_by.units_inv_symm_left_iff
@[to_additive]
theorem units_coe : commute u₁ u₂ → commute (u₁ : M) u₂ := semiconj_by.units_coe
@[to_additive]
theorem units_of_coe : commute (u₁ : M) u₂ → commute u₁ u₂ := semiconj_by.units_of_coe
@[simp, to_additive]
theorem units_coe_iff : commute (u₁ : M) u₂ ↔ commute u₁ u₂ := semiconj_by.units_coe_iff
/-- If the product of two commuting elements is a unit, then the left multiplier is a unit. -/
@[to_additive "If the sum of two commuting elements is an additive unit, then the left summand is an
additive unit."]
def _root_.units.left_of_mul (u : Mˣ) (a b : M) (hu : a * b = u) (hc : commute a b) : Mˣ :=
{ val := a,
inv := b * ↑u⁻¹,
val_inv := by rw [← mul_assoc, hu, u.mul_inv],
inv_val := have commute a u, from hu ▸ (commute.refl _).mul_right hc,
by rw [← this.units_inv_right.right_comm, ← hc.eq, hu, u.mul_inv] }
/-- If the product of two commuting elements is a unit, then the right multiplier is a unit. -/
@[to_additive "If the sum of two commuting elements is an additive unit, then the right summand is
an additive unit."]
def _root_.units.right_of_mul (u : Mˣ) (a b : M) (hu : a * b = u) (hc : commute a b) : Mˣ :=
u.left_of_mul b a (hc.eq ▸ hu) hc.symm
@[to_additive] lemma is_unit_mul_iff (h : commute a b) :
is_unit (a * b) ↔ is_unit a ∧ is_unit b :=
⟨λ ⟨u, hu⟩, ⟨(u.left_of_mul a b hu.symm h).is_unit, (u.right_of_mul a b hu.symm h).is_unit⟩,
λ H, H.1.mul H.2⟩
@[simp, to_additive] lemma _root_.is_unit_mul_self_iff :
is_unit (a * a) ↔ is_unit a :=
(commute.refl a).is_unit_mul_iff.trans (and_self _)
end monoid
section division_monoid
variables [division_monoid G] {a b c d : G}
@[to_additive] protected lemma inv_inv : commute a b → commute a⁻¹ b⁻¹ := semiconj_by.inv_inv_symm
@[simp, to_additive]
lemma inv_inv_iff : commute a⁻¹ b⁻¹ ↔ commute a b := semiconj_by.inv_inv_symm_iff
@[to_additive] protected lemma mul_inv (hab : commute a b) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
by rw [hab.eq, mul_inv_rev]
@[to_additive] protected lemma inv (hab : commute a b) : (a * b)⁻¹ = a⁻¹ * b⁻¹ :=
by rw [hab.eq, mul_inv_rev]
@[to_additive] protected lemma div_mul_div_comm (hbd : commute b d) (hbc : commute b⁻¹ c) :
a / b * (c / d) = a * c / (b * d) :=
by simp_rw [div_eq_mul_inv, mul_inv_rev, hbd.inv_inv.symm.eq, hbc.mul_mul_mul_comm]
@[to_additive] protected lemma mul_div_mul_comm (hcd : commute c d) (hbc : commute b c⁻¹) :
a * b / (c * d) = a / c * (b / d) :=
(hcd.div_mul_div_comm hbc.symm).symm
@[to_additive] protected lemma div_div_div_comm (hbc : commute b c) (hbd : commute b⁻¹ d)
(hcd : commute c⁻¹ d) : a / b / (c / d) = a / c / (b / d) :=
by simp_rw [div_eq_mul_inv, mul_inv_rev, inv_inv, hbd.symm.eq, hcd.symm.eq,
hbc.inv_inv.mul_mul_mul_comm]
end division_monoid
section group
variables [group G] {a b : G}
@[to_additive]
theorem inv_right : commute a b → commute a b⁻¹ := semiconj_by.inv_right
@[simp, to_additive]
theorem inv_right_iff : commute a b⁻¹ ↔ commute a b := semiconj_by.inv_right_iff
@[to_additive] theorem inv_left : commute a b → commute a⁻¹ b := semiconj_by.inv_symm_left
@[simp, to_additive]
theorem inv_left_iff : commute a⁻¹ b ↔ commute a b := semiconj_by.inv_symm_left_iff
@[to_additive]
protected theorem inv_mul_cancel (h : commute a b) : a⁻¹ * b * a = b :=
by rw [h.inv_left.eq, inv_mul_cancel_right]
@[to_additive]
theorem inv_mul_cancel_assoc (h : commute a b) : a⁻¹ * (b * a) = b :=
by rw [← mul_assoc, h.inv_mul_cancel]
@[to_additive]
protected theorem mul_inv_cancel (h : commute a b) : a * b * a⁻¹ = b :=
by rw [h.eq, mul_inv_cancel_right]
@[to_additive]
theorem mul_inv_cancel_assoc (h : commute a b) : a * (b * a⁻¹) = b :=
by rw [← mul_assoc, h.mul_inv_cancel]
end group
end commute
section comm_group
variables [comm_group G] (a b : G)
@[simp, to_additive] lemma mul_inv_cancel_comm : a * b * a⁻¹ = b :=
(commute.all a b).mul_inv_cancel
@[simp, to_additive] lemma mul_inv_cancel_comm_assoc : a * (b * a⁻¹) = b :=
(commute.all a b).mul_inv_cancel_assoc
@[simp, to_additive] lemma inv_mul_cancel_comm : a⁻¹ * b * a = b :=
(commute.all a b).inv_mul_cancel
@[simp, to_additive] lemma inv_mul_cancel_comm_assoc : a⁻¹ * (b * a) = b :=
(commute.all a b).inv_mul_cancel_assoc
end comm_group
|
195d11a0d7587105e4d2337d68e849456202512f
|
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
|
/library/init/data/option/basic.lean
|
aa98a6cb1eab4084fce598a1e368fce2f0f7b26c
|
[
"Apache-2.0"
] |
permissive
|
pacchiano/lean
|
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
|
fdadada3a970377a6df8afcd629a6f2eab6e84e8
|
refs/heads/master
| 1,611,357,380,399
| 1,489,870,101,000
| 1,489,870,101,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,148
|
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
-/
prelude
import init.logic init.category
open decidable
universes u v
namespace option
def to_monad {m : Type → Type} [monad m] [alternative m] {A} : option A → m A
| none := failure
| (some a) := return a
def get_or_else {α : Type u} : option α → α → α
| (some x) _ := x
| none e := e
def is_some {α : Type u} : option α → bool
| (some _) := tt
| none := ff
def is_none {α : Type u} : option α → bool
| (some _) := ff
| none := tt
def rhoare {α : Type u} : bool → α → option α
| tt a := none
| ff a := some a
def lhoare {α : Type u} : α → option α → α
| a none := a
| _ (some b) := b
infixr `|>`:1 := rhoare
infixr `<|`:1 := lhoare
end option
instance (α : Type u) : inhabited (option α) :=
⟨none⟩
instance {α : Type u} [d : decidable_eq α] : decidable_eq (option α)
| none none := is_true rfl
| none (some v₂) := is_false (λ h, option.no_confusion h)
| (some v₁) none := is_false (λ h, option.no_confusion h)
| (some v₁) (some v₂) :=
match (d v₁ v₂) with
| (is_true e) := is_true (congr_arg (@some α) e)
| (is_false n) := is_false (λ h, option.no_confusion h (λ e, absurd e n))
end
@[inline] def option_bind {α : Type u} {β : Type v} : option α → (α → option β) → option β
| none b := none
| (some a) b := b a
instance : monad option :=
{pure := @some, bind := @option_bind}
def option_orelse {α : Type u} : option α → option α → option α
| (some a) o := some a
| none (some a) := some a
| none none := none
instance : alternative option :=
{ option.monad with
failure := @none,
orelse := @option_orelse }
def option_t (m : Type u → Type v) [monad m] (α : Type u) : Type v :=
m (option α)
@[inline] def option_t_bind {m : Type u → Type v} [monad m] {α β : Type u} (a : option_t m α) (b : α → option_t m β)
: option_t m β :=
show m (option β), from
do o ← a,
match o with
| none := return none
| (some a) := b a
end
@[inline] def option_t_return {m : Type u → Type v} [monad m] {α : Type u} (a : α) : option_t m α :=
show m (option α), from
return (some a)
instance {m : Type u → Type v} [monad m] : monad (option_t m) :=
{pure := @option_t_return m _, bind := @option_t_bind m _}
def option_t_orelse {m : Type u → Type v} [monad m] {α : Type u} (a : option_t m α) (b : option_t m α) : option_t m α :=
show m (option α), from
do o ← a,
match o with
| none := b
| (some v) := return (some v)
end
def option_t_fail {m : Type u → Type v} [monad m] {α : Type u} : option_t m α :=
show m (option α), from
return none
instance {m : Type u → Type v} [monad m] : alternative (option_t m) :=
{ option_t.monad with
failure := @option_t_fail m _,
orelse := @option_t_orelse m _ }
def option_t.lift {m : Type u → Type v} [monad m] {α : Type u} (a : m α) : option_t m α :=
(some <$> a : m (option α))
|
33e62343f37416c336fb21249e495bf1a2855047
|
4b846d8dabdc64e7ea03552bad8f7fa74763fc67
|
/tests/lean/let_elim_issue.lean
|
6e002b596560260fba7b232e87b3ee362f8b404e
|
[
"Apache-2.0"
] |
permissive
|
pacchiano/lean
|
9324b33f3ac3b5c5647285160f9f6ea8d0d767dc
|
fdadada3a970377a6df8afcd629a6f2eab6e84e8
|
refs/heads/master
| 1,611,357,380,399
| 1,489,870,101,000
| 1,489,870,101,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 124
|
lean
|
import system.io
open io
def tst : io unit :=
put_str "hello\n"
>> put_str "world\n"
>> put_str "from Lean\n"
#eval tst
|
c39a556af891428af39d24aaecef30061d00373e
|
4d2583807a5ac6caaffd3d7a5f646d61ca85d532
|
/src/linear_algebra/quadratic_form/basic.lean
|
d67715f33d6d6fd30c02efa162c4023bc6b58e81
|
[
"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
| 36,605
|
lean
|
/-
Copyright (c) 2020 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen, Kexing Ying, Eric Wieser
-/
import algebra.invertible
import linear_algebra.bilinear_form
import linear_algebra.matrix.determinant
import linear_algebra.special_linear_group
/-!
# Quadratic forms
This file defines quadratic forms over a `R`-module `M`.
A quadratic form is a map `Q : M → R` such that
(`to_fun_smul`) `Q (a • x) = a * a * Q x`
(`polar_...`) The map `polar Q := λ x y, Q (x + y) - Q x - Q y` is bilinear.
They come with a scalar multiplication, `(a • Q) x = Q (a • x) = a * a * Q x`,
and composition with linear maps `f`, `Q.comp f x = Q (f x)`.
## Main definitions
* `quadratic_form.associated`: associated bilinear form
* `quadratic_form.pos_def`: positive definite quadratic forms
* `quadratic_form.anisotropic`: anisotropic quadratic forms
* `quadratic_form.discr`: discriminant of a quadratic form
## Main statements
* `quadratic_form.associated_left_inverse`,
* `quadratic_form.associated_right_inverse`: in a commutative ring where 2 has
an inverse, there is a correspondence between quadratic forms and symmetric
bilinear forms
* `bilin_form.exists_orthogonal_basis`: There exists an orthogonal basis with
respect to any nondegenerate, symmetric bilinear form `B`.
## Notation
In this file, the variable `R` is used when a `ring` structure is sufficient and
`R₁` is used when specifically a `comm_ring` is required. This allows us to keep
`[module R M]` and `[module R₁ M]` assumptions in the variables without
confusion between `*` from `ring` and `*` from `comm_ring`.
The variable `S` is used when `R` itself has a `•` action.
## References
* https://en.wikipedia.org/wiki/Quadratic_form
* https://en.wikipedia.org/wiki/Discriminant#Quadratic_forms
## Tags
quadratic form, homogeneous polynomial, quadratic polynomial
-/
universes u v w
variables {S : Type*}
variables {R : Type*} {M : Type*} [add_comm_group M] [ring R]
variables {R₁ : Type*} [comm_ring R₁]
namespace quadratic_form
/-- Up to a factor 2, `Q.polar` is the associated bilinear form for a quadratic form `Q`.d
Source of this name: https://en.wikipedia.org/wiki/Quadratic_form#Generalization
-/
def polar (f : M → R) (x y : M) :=
f (x + y) - f x - f y
lemma polar_add (f g : M → R) (x y : M) :
polar (f + g) x y = polar f x y + polar g x y :=
by { simp only [polar, pi.add_apply], abel }
lemma polar_neg (f : M → R) (x y : M) :
polar (-f) x y = - polar f x y :=
by { simp only [polar, pi.neg_apply, sub_eq_add_neg, neg_add] }
lemma polar_smul [monoid S] [distrib_mul_action S R] (f : M → R) (s : S) (x y : M) :
polar (s • f) x y = s • polar f x y :=
by { simp only [polar, pi.smul_apply, smul_sub] }
lemma polar_comm (f : M → R) (x y : M) : polar f x y = polar f y x :=
by rw [polar, polar, add_comm, sub_sub, sub_sub, add_comm (f x) (f y)]
end quadratic_form
variables [module R M] [module R₁ M]
open quadratic_form
/-- A quadratic form over a module. -/
structure quadratic_form (R : Type u) (M : Type v) [ring R] [add_comm_group M] [module R M] :=
(to_fun : M → R)
(to_fun_smul : ∀ (a : R) (x : M), to_fun (a • x) = a * a * to_fun x)
(polar_add_left' : ∀ (x x' y : M), polar to_fun (x + x') y = polar to_fun x y + polar to_fun x' y)
(polar_smul_left' : ∀ (a : R) (x y : M), polar to_fun (a • x) y = a • polar to_fun x y)
(polar_add_right' : ∀ (x y y' : M), polar to_fun x (y + y') = polar to_fun x y + polar to_fun x y')
(polar_smul_right' : ∀ (a : R) (x y : M), polar to_fun x (a • y) = a • polar to_fun x y)
namespace quadratic_form
variables {Q : quadratic_form R M}
instance : has_coe_to_fun (quadratic_form R M) (λ _, M → R) := ⟨to_fun⟩
/-- The `simp` normal form for a quadratic form is `coe_fn`, not `to_fun`. -/
@[simp] lemma to_fun_eq_apply : Q.to_fun = ⇑ Q := rfl
lemma map_smul (a : R) (x : M) : Q (a • x) = a * a * Q x := Q.to_fun_smul a x
lemma map_add_self (x : M) : Q (x + x) = 4 * Q x :=
by { rw [←one_smul R x, ←add_smul, map_smul], norm_num }
@[simp] lemma map_zero : Q 0 = 0 :=
by rw [←@zero_smul R _ _ _ _ (0 : M), map_smul, zero_mul, zero_mul]
@[simp] lemma map_neg (x : M) : Q (-x) = Q x :=
by rw [←@neg_one_smul R _ _ _ _ x, map_smul, neg_one_mul, neg_neg, one_mul]
lemma map_sub (x y : M) : Q (x - y) = Q (y - x) :=
by rw [←neg_sub, map_neg]
@[simp]
lemma polar_zero_left (y : M) : polar Q 0 y = 0 :=
by simp only [polar, zero_add, quadratic_form.map_zero, sub_zero, sub_self]
@[simp]
lemma polar_add_left (x x' y : M) :
polar Q (x + x') y = polar Q x y + polar Q x' y :=
Q.polar_add_left' x x' y
@[simp]
lemma polar_smul_left (a : R) (x y : M) :
polar Q (a • x) y = a * polar Q x y :=
Q.polar_smul_left' a x y
@[simp]
lemma polar_neg_left (x y : M) :
polar Q (-x) y = -polar Q x y :=
by rw [←neg_one_smul R x, polar_smul_left, neg_one_mul]
@[simp]
lemma polar_sub_left (x x' y : M) :
polar Q (x - x') y = polar Q x y - polar Q x' y :=
by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_left, polar_neg_left]
@[simp]
lemma polar_zero_right (y : M) : polar Q y 0 = 0 :=
by simp only [add_zero, polar, quadratic_form.map_zero, sub_self]
@[simp]
lemma polar_add_right (x y y' : M) :
polar Q x (y + y') = polar Q x y + polar Q x y' :=
Q.polar_add_right' x y y'
@[simp]
lemma polar_smul_right (a : R) (x y : M) :
polar Q x (a • y) = a * polar Q x y :=
Q.polar_smul_right' a x y
@[simp]
lemma polar_neg_right (x y : M) :
polar Q x (-y) = -polar Q x y :=
by rw [←neg_one_smul R y, polar_smul_right, neg_one_mul]
@[simp]
lemma polar_sub_right (x y y' : M) :
polar Q x (y - y') = polar Q x y - polar Q x y' :=
by rw [sub_eq_add_neg, sub_eq_add_neg, polar_add_right, polar_neg_right]
@[simp]
lemma polar_self (x : M) : polar Q x x = 2 * Q x :=
begin
rw [polar, map_add_self, sub_sub, sub_eq_iff_eq_add, ←two_mul, ←two_mul, ←mul_assoc],
norm_num
end
section of_tower
variables [comm_semiring S] [algebra S R] [module S M] [is_scalar_tower S R M]
@[simp]
lemma polar_smul_left_of_tower (a : S) (x y : M) :
polar Q (a • x) y = a • polar Q x y :=
by rw [←is_scalar_tower.algebra_map_smul R a x, polar_smul_left, algebra.smul_def]
@[simp]
lemma polar_smul_right_of_tower (a : S) (x y : M) :
polar Q x (a • y) = a • polar Q x y :=
by rw [←is_scalar_tower.algebra_map_smul R a y, polar_smul_right, algebra.smul_def]
end of_tower
variable {Q' : quadratic_form R M}
@[ext] lemma ext (H : ∀ (x : M), Q x = Q' x) : Q = Q' :=
by { cases Q, cases Q', congr, funext, apply H }
lemma congr_fun (h : Q = Q') (x : M) : Q x = Q' x := h ▸ rfl
lemma ext_iff : Q = Q' ↔ (∀ x, Q x = Q' x) := ⟨congr_fun, ext⟩
instance : has_zero (quadratic_form R M) :=
⟨ { to_fun := λ x, 0,
to_fun_smul := λ a x, by simp only [mul_zero],
polar_add_left' := λ x x' y, by simp only [add_zero, polar, sub_self],
polar_smul_left' := λ a x y, by simp only [polar, smul_zero, sub_self],
polar_add_right' := λ x y y', by simp only [add_zero, polar, sub_self],
polar_smul_right' := λ a x y, by simp only [polar, smul_zero, sub_self]} ⟩
@[simp] lemma coe_fn_zero : ⇑(0 : quadratic_form R M) = 0 := rfl
@[simp] lemma zero_apply (x : M) : (0 : quadratic_form R M) x = 0 := rfl
instance : inhabited (quadratic_form R M) := ⟨0⟩
instance : has_add (quadratic_form R M) :=
⟨ λ Q Q',
{ to_fun := Q + Q',
to_fun_smul := λ a x,
by simp only [pi.add_apply, map_smul, mul_add],
polar_add_left' := λ x x' y,
by simp only [polar_add, polar_add_left, add_assoc, add_left_comm],
polar_smul_left' := λ a x y,
by simp only [polar_add, smul_eq_mul, mul_add, polar_smul_left],
polar_add_right' := λ x y y',
by simp only [polar_add, polar_add_right, add_assoc, add_left_comm],
polar_smul_right' := λ a x y,
by simp only [polar_add, smul_eq_mul, mul_add, polar_smul_right] } ⟩
@[simp] lemma coe_fn_add (Q Q' : quadratic_form R M) : ⇑(Q + Q') = Q + Q' := rfl
@[simp] lemma add_apply (Q Q' : quadratic_form R M) (x : M) : (Q + Q') x = Q x + Q' x := rfl
instance : has_neg (quadratic_form R M) :=
⟨ λ Q,
{ to_fun := -Q,
to_fun_smul := λ a x,
by simp only [pi.neg_apply, map_smul, mul_neg_eq_neg_mul_symm],
polar_add_left' := λ x x' y,
by simp only [polar_neg, polar_add_left, neg_add],
polar_smul_left' := λ a x y,
by simp only [polar_neg, polar_smul_left, mul_neg_eq_neg_mul_symm, smul_eq_mul],
polar_add_right' := λ x y y',
by simp only [polar_neg, polar_add_right, neg_add],
polar_smul_right' := λ a x y,
by simp only [polar_neg, polar_smul_right, mul_neg_eq_neg_mul_symm, smul_eq_mul] } ⟩
@[simp] lemma coe_fn_neg (Q : quadratic_form R M) : ⇑(-Q) = -Q := rfl
@[simp] lemma neg_apply (Q : quadratic_form R M) (x : M) : (-Q) x = -Q x := rfl
instance : add_comm_group (quadratic_form R M) :=
{ add := (+),
zero := 0,
neg := has_neg.neg,
add_comm := λ Q Q', by { ext, simp only [add_apply, add_comm] },
add_assoc := λ Q Q' Q'', by { ext, simp only [add_apply, add_assoc] },
add_left_neg := λ Q, by { ext, simp only [add_apply, neg_apply, zero_apply, add_left_neg] },
add_zero := λ Q, by { ext, simp only [zero_apply, add_apply, add_zero] },
zero_add := λ Q, by { ext, simp only [zero_apply, add_apply, zero_add] } }
@[simp] lemma coe_fn_sub (Q Q' : quadratic_form R M) : ⇑(Q - Q') = Q - Q' :=
by simp only [quadratic_form.coe_fn_neg, add_left_inj, quadratic_form.coe_fn_add, sub_eq_add_neg]
@[simp] lemma sub_apply (Q Q' : quadratic_form R M) (x : M) : (Q - Q') x = Q x - Q' x :=
by simp only [quadratic_form.neg_apply, add_left_inj, quadratic_form.add_apply, sub_eq_add_neg]
/-- `@coe_fn (quadratic_form R M)` as an `add_monoid_hom`.
This API mirrors `add_monoid_hom.coe_fn`. -/
@[simps apply]
def coe_fn_add_monoid_hom : quadratic_form R M →+ (M → R) :=
{ to_fun := coe_fn, map_zero' := coe_fn_zero, map_add' := coe_fn_add }
/-- Evaluation on a particular element of the module `M` is an additive map over quadratic forms. -/
@[simps apply]
def eval_add_monoid_hom (m : M) : quadratic_form R M →+ R :=
(pi.eval_add_monoid_hom _ m).comp coe_fn_add_monoid_hom
section sum
open_locale big_operators
@[simp] lemma coe_fn_sum {ι : Type*} (Q : ι → quadratic_form R M) (s : finset ι) :
⇑(∑ i in s, Q i) = ∑ i in s, Q i :=
(coe_fn_add_monoid_hom : _ →+ (M → R)).map_sum Q s
@[simp] lemma sum_apply {ι : Type*} (Q : ι → quadratic_form R M) (s : finset ι) (x : M) :
(∑ i in s, Q i) x = ∑ i in s, Q i x :=
(eval_add_monoid_hom x : _ →+ R).map_sum Q s
end sum
section has_scalar
variables [monoid S] [distrib_mul_action S R] [smul_comm_class S R R]
/-- `quadratic_form R M` inherits the scalar action from any algebra over `R`.
When `R` is commutative, this provides an `R`-action via `algebra.id`. -/
instance : has_scalar S (quadratic_form R M) :=
⟨ λ a Q,
{ to_fun := a • Q,
to_fun_smul := λ b x, by rw [pi.smul_apply, map_smul, pi.smul_apply, mul_smul_comm],
polar_add_left' := λ x x' y, by simp only [polar_smul, polar_add_left, smul_add],
polar_smul_left' := λ b x y, begin
simp only [polar_smul, polar_smul_left, ←mul_smul_comm, smul_eq_mul],
end,
polar_add_right' := λ x y y', by simp only [polar_smul, polar_add_right, smul_add],
polar_smul_right' := λ b x y, begin
simp only [polar_smul, polar_smul_right, ←mul_smul_comm, smul_eq_mul],
end } ⟩
@[simp] lemma coe_fn_smul (a : S) (Q : quadratic_form R M) : ⇑(a • Q) = a • Q := rfl
@[simp] lemma smul_apply (a : S) (Q : quadratic_form R M) (x : M) :
(a • Q) x = a • Q x := rfl
instance : distrib_mul_action S (quadratic_form R M) :=
{ mul_smul := λ a b Q, ext (λ x, by simp only [smul_apply, mul_smul]),
one_smul := λ Q, ext (λ x, by simp only [quadratic_form.smul_apply, one_smul]),
smul_add := λ a Q Q', by { ext, simp only [add_apply, smul_apply, smul_add] },
smul_zero := λ a, by { ext, simp only [zero_apply, smul_apply, smul_zero] }, }
end has_scalar
section module
instance [semiring S] [module S R] [smul_comm_class S R R] : module S (quadratic_form R M) :=
{ zero_smul := λ Q, by { ext, simp only [zero_apply, smul_apply, zero_smul] },
add_smul := λ a b Q, by { ext, simp only [add_apply, smul_apply, add_smul] } }
end module
section comp
variables {N : Type v} [add_comm_group N] [module R N]
/-- Compose the quadratic form with a linear function. -/
def comp (Q : quadratic_form R N) (f : M →ₗ[R] N) :
quadratic_form R M :=
{ to_fun := λ x, Q (f x),
to_fun_smul := λ a x, by simp only [map_smul, f.map_smul],
polar_add_left' := λ x x' y,
by convert polar_add_left (f x) (f x') (f y) using 1;
simp only [polar, f.map_add],
polar_smul_left' := λ a x y,
by convert polar_smul_left a (f x) (f y) using 1;
simp only [polar, f.map_smul, f.map_add, smul_eq_mul],
polar_add_right' := λ x y y',
by convert polar_add_right (f x) (f y) (f y') using 1;
simp only [polar, f.map_add],
polar_smul_right' := λ a x y,
by convert polar_smul_right a (f x) (f y) using 1;
simp only [polar, f.map_smul, f.map_add, smul_eq_mul] }
@[simp] lemma comp_apply (Q : quadratic_form R N) (f : M →ₗ[R] N) (x : M) :
(Q.comp f) x = Q (f x) := rfl
end comp
section comm_ring
/-- Create a quadratic form in a commutative ring by proving only one side of the bilinearity. -/
def mk_left (f : M → R₁)
(to_fun_smul : ∀ a x, f (a • x) = a * a * f x)
(polar_add_left : ∀ x x' y, polar f (x + x') y = polar f x y + polar f x' y)
(polar_smul_left : ∀ a x y, polar f (a • x) y = a * polar f x y) :
quadratic_form R₁ M :=
{ to_fun := f,
to_fun_smul := to_fun_smul,
polar_add_left' := polar_add_left,
polar_smul_left' := polar_smul_left,
polar_add_right' :=
λ x y y', by rw [polar_comm, polar_add_left, polar_comm f y x, polar_comm f y' x],
polar_smul_right' :=
λ a x y, by rw [polar_comm, polar_smul_left, polar_comm f y x, smul_eq_mul] }
/-- The product of linear forms is a quadratic form. -/
def lin_mul_lin (f g : M →ₗ[R₁] R₁) : quadratic_form R₁ M :=
mk_left (f * g)
(λ a x,
by { simp only [smul_eq_mul, ring_hom.id_apply, pi.mul_apply, linear_map.map_smulₛₗ], ring })
(λ x x' y, by { simp only [polar, pi.mul_apply, linear_map.map_add], ring })
(λ a x y, begin
simp only [polar, pi.mul_apply, linear_map.map_add, linear_map.map_smul, smul_eq_mul], ring
end)
@[simp]
lemma lin_mul_lin_apply (f g : M →ₗ[R₁] R₁) (x) : lin_mul_lin f g x = f x * g x := rfl
@[simp]
lemma add_lin_mul_lin (f g h : M →ₗ[R₁] R₁) :
lin_mul_lin (f + g) h = lin_mul_lin f h + lin_mul_lin g h :=
ext (λ x, add_mul _ _ _)
@[simp]
lemma lin_mul_lin_add (f g h : M →ₗ[R₁] R₁) :
lin_mul_lin f (g + h) = lin_mul_lin f g + lin_mul_lin f h :=
ext (λ x, mul_add _ _ _)
variables {N : Type v} [add_comm_group N] [module R₁ N]
@[simp]
lemma lin_mul_lin_comp (f g : M →ₗ[R₁] R₁) (h : N →ₗ[R₁] M) :
(lin_mul_lin f g).comp h = lin_mul_lin (f.comp h) (g.comp h) :=
rfl
variables {n : Type*}
/-- `proj i j` is the quadratic form mapping the vector `x : n → R₁` to `x i * x j` -/
def proj (i j : n) : quadratic_form R₁ (n → R₁) :=
lin_mul_lin (@linear_map.proj _ _ _ (λ _, R₁) _ _ i) (@linear_map.proj _ _ _ (λ _, R₁) _ _ j)
@[simp]
lemma proj_apply (i j : n) (x : n → R₁) : proj i j x = x i * x j := rfl
end comm_ring
end quadratic_form
/-!
### Associated bilinear forms
Over a commutative ring with an inverse of 2, the theory of quadratic forms is
basically identical to that of symmetric bilinear forms. The map from quadratic
forms to bilinear forms giving this identification is called the `associated`
quadratic form.
-/
variables {B : bilin_form R M}
namespace bilin_form
open quadratic_form
lemma polar_to_quadratic_form (x y : M) : polar (λ x, B x x) x y = B x y + B y x :=
by { simp only [add_assoc, add_sub_cancel', add_right, polar, add_left_inj, add_neg_cancel_left,
add_left, sub_eq_add_neg _ (B y y), add_comm (B y x) _] }
/-- A bilinear form gives a quadratic form by applying the argument twice. -/
def to_quadratic_form (B : bilin_form R M) : quadratic_form R M :=
⟨ λ x, B x x,
λ a x, by simp only [mul_assoc, smul_right, smul_left],
λ x x' y, by simp only [add_assoc, add_right, add_left_inj, polar_to_quadratic_form, add_left,
add_left_comm],
λ a x y, by simp only [smul_add, add_left_inj, polar_to_quadratic_form,
smul_right, smul_eq_mul, smul_left, smul_right, mul_add],
λ x y y', by simp only [add_assoc, add_right, add_left_inj,
polar_to_quadratic_form, add_left, add_left_comm],
λ a x y, by simp only [smul_add, add_left_inj, polar_to_quadratic_form,
smul_right, smul_eq_mul, smul_left, smul_right, mul_add]⟩
@[simp] lemma to_quadratic_form_apply (B : bilin_form R M) (x : M) :
B.to_quadratic_form x = B x x :=
rfl
section
variables (R M)
@[simp] lemma to_quadratic_form_zero : (0 : bilin_form R M).to_quadratic_form = 0 := rfl
end
end bilin_form
namespace quadratic_form
open bilin_form sym_bilin_form
section associated_hom
variables (S) [comm_semiring S] [algebra S R]
variables [invertible (2 : R)] {B₁ : bilin_form R M}
/-- `associated_hom` is the map that sends a quadratic form on a module `M` over `R` to its
associated symmetric bilinear form. As provided here, this has the structure of an `S`-linear map
where `S` is a commutative subring of `R`.
Over a commutative ring, use `associated`, which gives an `R`-linear map. Over a general ring with
no nontrivial distinguished commutative subring, use `associated'`, which gives an additive
homomorphism (or more precisely a `ℤ`-linear map.) -/
def associated_hom : quadratic_form R M →ₗ[S] bilin_form R M :=
{ to_fun := λ Q,
{ bilin := λ x y, ⅟2 * polar Q x y,
bilin_add_left := λ x y z, by rw [← mul_add, polar_add_left],
bilin_smul_left := λ x y z, begin
have htwo : x * ⅟2 = ⅟2 * x := (commute.one_right x).bit0_right.inv_of_right,
simp only [polar_smul_left, ← mul_assoc, htwo]
end,
bilin_add_right := λ x y z, by rw [← mul_add, polar_add_right],
bilin_smul_right := λ x y z, begin
have htwo : x * ⅟2 = ⅟2 * x := (commute.one_right x).bit0_right.inv_of_right,
simp only [polar_smul_right, ← mul_assoc, htwo]
end },
map_add' := λ Q Q', by { ext, simp only [bilin_form.add_apply, coe_fn_mk, polar_add, coe_fn_add,
mul_add] },
map_smul' := λ s Q, by { ext, simp only [ring_hom.id_apply, polar_smul, algebra.mul_smul_comm,
coe_fn_mk, coe_fn_smul, bilin_form.smul_apply] } }
variables (Q : quadratic_form R M) (S)
@[simp] lemma associated_apply (x y : M) :
associated_hom S Q x y = ⅟2 * (Q (x + y) - Q x - Q y) := rfl
lemma associated_is_sym : is_sym (associated_hom S Q) :=
λ x y, by simp only [associated_apply, add_comm, add_left_comm, sub_eq_add_neg]
@[simp] lemma associated_comp {N : Type v} [add_comm_group N] [module R N] (f : N →ₗ[R] M) :
associated_hom S (Q.comp f) = (associated_hom S Q).comp f f :=
by { ext, simp only [quadratic_form.comp_apply, bilin_form.comp_apply, associated_apply,
linear_map.map_add] }
lemma associated_to_quadratic_form (B : bilin_form R M) (x y : M) :
associated_hom S B.to_quadratic_form x y = ⅟2 * (B x y + B y x) :=
by simp only [associated_apply, ← polar_to_quadratic_form, polar, to_quadratic_form_apply]
lemma associated_left_inverse (h : is_sym B₁) :
associated_hom S (B₁.to_quadratic_form) = B₁ :=
bilin_form.ext $ λ x y,
by rw [associated_to_quadratic_form, sym h x y, ←two_mul, ←mul_assoc, inv_of_mul_self, one_mul]
lemma to_quadratic_form_associated : (associated_hom S Q).to_quadratic_form = Q :=
quadratic_form.ext $ λ x,
calc (associated_hom S Q).to_quadratic_form x
= ⅟2 * (Q x + Q x) : by simp only [add_assoc, add_sub_cancel', one_mul,
to_quadratic_form_apply, add_mul, associated_apply, map_add_self, bit0]
... = Q x : by rw [← two_mul (Q x), ←mul_assoc, inv_of_mul_self, one_mul]
-- note: usually `right_inverse` lemmas are named the other way around, but this is consistent
-- with historical naming in this file.
lemma associated_right_inverse :
function.right_inverse (associated_hom S)
(bilin_form.to_quadratic_form : _ → quadratic_form R M) :=
λ Q, to_quadratic_form_associated S Q
lemma associated_eq_self_apply (x : M) : associated_hom S Q x x = Q x :=
begin
rw [associated_apply, map_add_self],
suffices : (⅟2) * (2 * Q x) = Q x,
{ convert this,
simp only [bit0, add_mul, one_mul],
abel },
simp only [← mul_assoc, one_mul, inv_of_mul_self],
end
/-- `associated'` is the `ℤ`-linear map that sends a quadratic form on a module `M` over `R` to its
associated symmetric bilinear form. -/
abbreviation associated' : quadratic_form R M →ₗ[ℤ] bilin_form R M :=
associated_hom ℤ
/-- Symmetric bilinear forms can be lifted to quadratic forms -/
instance : can_lift (bilin_form R M) (quadratic_form R M) :=
{ coe := associated_hom ℕ,
cond := is_sym,
prf := λ B hB, ⟨B.to_quadratic_form, associated_left_inverse _ hB⟩ }
/-- There exists a non-null vector with respect to any quadratic form `Q` whose associated
bilinear form is non-zero, i.e. there exists `x` such that `Q x ≠ 0`. -/
lemma exists_quadratic_form_ne_zero {Q : quadratic_form R M} (hB₁ : Q.associated' ≠ 0) :
∃ x, Q x ≠ 0 :=
begin
rw ←not_forall,
intro h,
apply hB₁,
rw [(quadratic_form.ext h : Q = 0), linear_map.map_zero],
end
end associated_hom
section associated
variables [invertible (2 : R₁)]
-- Note: When possible, rather than writing lemmas about `associated`, write a lemma applying to
-- the more general `associated_hom` and place it in the previous section.
/-- `associated` is the linear map that sends a quadratic form over a commutative ring to its
associated symmetric bilinear form. -/
abbreviation associated : quadratic_form R₁ M →ₗ[R₁] bilin_form R₁ M :=
associated_hom R₁
@[simp] lemma associated_lin_mul_lin (f g : M →ₗ[R₁] R₁) :
(lin_mul_lin f g).associated =
⅟(2 : R₁) • (bilin_form.lin_mul_lin f g + bilin_form.lin_mul_lin g f) :=
by { ext, simp only [smul_add, algebra.id.smul_eq_mul, bilin_form.lin_mul_lin_apply,
quadratic_form.lin_mul_lin_apply, bilin_form.smul_apply, associated_apply, bilin_form.add_apply,
linear_map.map_add], ring }
end associated
section anisotropic
/-- An anisotropic quadratic form is zero only on zero vectors. -/
def anisotropic (Q : quadratic_form R M) : Prop := ∀ x, Q x = 0 → x = 0
lemma not_anisotropic_iff_exists (Q : quadratic_form R M) :
¬anisotropic Q ↔ ∃ x ≠ 0, Q x = 0 :=
by simp only [anisotropic, not_forall, exists_prop, and_comm]
/-- The associated bilinear form of an anisotropic quadratic form is nondegenerate. -/
lemma nondegenerate_of_anisotropic [invertible (2 : R)] (Q : quadratic_form R M)
(hB : Q.anisotropic) : Q.associated'.nondegenerate :=
begin
intros x hx,
refine hB _ _,
rw ← hx x,
exact (associated_eq_self_apply _ _ x).symm,
end
end anisotropic
section pos_def
variables {R₂ : Type u} [ordered_ring R₂] [module R₂ M] {Q₂ : quadratic_form R₂ M}
/-- A positive definite quadratic form is positive on nonzero vectors. -/
def pos_def (Q₂ : quadratic_form R₂ M) : Prop := ∀ x ≠ 0, 0 < Q₂ x
lemma pos_def.smul {R} [linear_ordered_comm_ring R] [module R M]
{Q : quadratic_form R M} (h : pos_def Q) {a : R} (a_pos : 0 < a) : pos_def (a • Q) :=
λ x hx, mul_pos a_pos (h x hx)
variables {n : Type*}
lemma pos_def.add (Q Q' : quadratic_form R₂ M) (hQ : pos_def Q) (hQ' : pos_def Q') :
pos_def (Q + Q') :=
λ x hx, add_pos (hQ x hx) (hQ' x hx)
lemma lin_mul_lin_self_pos_def {R} [linear_ordered_comm_ring R] [module R M]
(f : M →ₗ[R] R) (hf : linear_map.ker f = ⊥) :
pos_def (lin_mul_lin f f) :=
λ x hx, mul_self_pos (λ h, hx (linear_map.ker_eq_bot.mp hf (by rw [h, linear_map.map_zero])))
end pos_def
end quadratic_form
section
/-!
### Quadratic forms and matrices
Connect quadratic forms and matrices, in order to explicitly compute with them.
The convention is twos out, so there might be a factor 2⁻¹ in the entries of the
matrix.
The determinant of the matrix is the discriminant of the quadratic form.
-/
variables {n : Type w} [fintype n] [decidable_eq n]
/-- `M.to_quadratic_form` is the map `λ x, col x ⬝ M ⬝ row x` as a quadratic form. -/
def matrix.to_quadratic_form' (M : matrix n n R₁) :
quadratic_form R₁ (n → R₁) :=
M.to_bilin'.to_quadratic_form
variables [invertible (2 : R₁)]
/-- A matrix representation of the quadratic form. -/
def quadratic_form.to_matrix' (Q : quadratic_form R₁ (n → R₁)) : matrix n n R₁ :=
Q.associated.to_matrix'
open quadratic_form
lemma quadratic_form.to_matrix'_smul (a : R₁) (Q : quadratic_form R₁ (n → R₁)) :
(a • Q).to_matrix' = a • Q.to_matrix' :=
by simp only [to_matrix', linear_equiv.map_smul, linear_map.map_smul]
end
namespace quadratic_form
variables {n : Type w} [fintype n]
variables [decidable_eq n] [invertible (2 : R₁)]
variables {m : Type w} [decidable_eq m] [fintype m]
open_locale matrix
@[simp]
lemma to_matrix'_comp (Q : quadratic_form R₁ (m → R₁)) (f : (n → R₁) →ₗ[R₁] (m → R₁)) :
(Q.comp f).to_matrix' = f.to_matrix'ᵀ ⬝ Q.to_matrix' ⬝ f.to_matrix' :=
by { ext, simp only [quadratic_form.associated_comp, bilin_form.to_matrix'_comp, to_matrix'] }
section discriminant
variables {Q : quadratic_form R₁ (n → R₁)}
/-- The discriminant of a quadratic form generalizes the discriminant of a quadratic polynomial. -/
def discr (Q : quadratic_form R₁ (n → R₁)) : R₁ := Q.to_matrix'.det
lemma discr_smul (a : R₁) : (a • Q).discr = a ^ fintype.card n * Q.discr :=
by simp only [discr, to_matrix'_smul, matrix.det_smul]
lemma discr_comp (f : (n → R₁) →ₗ[R₁] (n → R₁)) :
(Q.comp f).discr = f.to_matrix'.det * f.to_matrix'.det * Q.discr :=
by simp only [matrix.det_transpose, mul_left_comm, quadratic_form.to_matrix'_comp, mul_comm,
matrix.det_mul, discr]
end discriminant
end quadratic_form
namespace quadratic_form
variables {M₁ : Type*} {M₂ : Type*} {M₃ : Type*}
variables [add_comm_group M₁] [add_comm_group M₂] [add_comm_group M₃]
variables [module R M₁] [module R M₂] [module R M₃]
/-- An isometry between two quadratic spaces `M₁, Q₁` and `M₂, Q₂` over a ring `R`,
is a linear equivalence between `M₁` and `M₂` that commutes with the quadratic forms. -/
@[nolint has_inhabited_instance] structure isometry
(Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) extends M₁ ≃ₗ[R] M₂ :=
(map_app' : ∀ m, Q₂ (to_fun m) = Q₁ m)
/-- Two quadratic forms over a ring `R` are equivalent
if there exists an isometry between them:
a linear equivalence that transforms one quadratic form into the other. -/
def equivalent (Q₁ : quadratic_form R M₁) (Q₂ : quadratic_form R M₂) := nonempty (Q₁.isometry Q₂)
namespace isometry
variables {Q₁ : quadratic_form R M₁} {Q₂ : quadratic_form R M₂} {Q₃ : quadratic_form R M₃}
instance : has_coe (Q₁.isometry Q₂) (M₁ ≃ₗ[R] M₂) := ⟨isometry.to_linear_equiv⟩
@[simp] lemma to_linear_equiv_eq_coe (f : Q₁.isometry Q₂) : f.to_linear_equiv = f := rfl
instance : has_coe_to_fun (Q₁.isometry Q₂) (λ _, M₁ → M₂) := ⟨λ f, ⇑(f : M₁ ≃ₗ[R] M₂)⟩
@[simp] lemma coe_to_linear_equiv (f : Q₁.isometry Q₂) : ⇑(f : M₁ ≃ₗ[R] M₂) = f := rfl
@[simp] lemma map_app (f : Q₁.isometry Q₂) (m : M₁) : Q₂ (f m) = Q₁ m := f.map_app' m
/-- The identity isometry from a quadratic form to itself. -/
@[refl]
def refl (Q : quadratic_form R M) : Q.isometry Q :=
{ map_app' := λ m, rfl,
.. linear_equiv.refl R M }
/-- The inverse isometry of an isometry between two quadratic forms. -/
@[symm]
def symm (f : Q₁.isometry Q₂) : Q₂.isometry Q₁ :=
{ map_app' := by { intro m, rw ← f.map_app, congr, exact f.to_linear_equiv.apply_symm_apply m },
.. (f : M₁ ≃ₗ[R] M₂).symm }
/-- The composition of two isometries between quadratic forms. -/
@[trans]
def trans (f : Q₁.isometry Q₂) (g : Q₂.isometry Q₃) : Q₁.isometry Q₃ :=
{ map_app' := by { intro m, rw [← f.map_app, ← g.map_app], refl },
.. (f : M₁ ≃ₗ[R] M₂).trans (g : M₂ ≃ₗ[R] M₃) }
end isometry
namespace equivalent
variables {Q₁ : quadratic_form R M₁} {Q₂ : quadratic_form R M₂} {Q₃ : quadratic_form R M₃}
@[refl]
lemma refl (Q : quadratic_form R M) : Q.equivalent Q := ⟨isometry.refl Q⟩
@[symm]
lemma symm (h : Q₁.equivalent Q₂) : Q₂.equivalent Q₁ := h.elim $ λ f, ⟨f.symm⟩
@[trans]
lemma trans (h : Q₁.equivalent Q₂) (h' : Q₂.equivalent Q₃) : Q₁.equivalent Q₃ :=
h'.elim $ h.elim $ λ f g, ⟨f.trans g⟩
end equivalent
end quadratic_form
namespace bilin_form
/-- A bilinear form is nondegenerate if the quadratic form it is associated with is anisotropic. -/
lemma nondegenerate_of_anisotropic
{B : bilin_form R M} (hB : B.to_quadratic_form.anisotropic) : B.nondegenerate :=
λ x hx, hB _ (hx x)
/-- There exists a non-null vector with respect to any symmetric, nonzero bilinear form `B`
on a module `M` over a ring `R` with invertible `2`, i.e. there exists some
`x : M` such that `B x x ≠ 0`. -/
lemma exists_bilin_form_self_ne_zero [htwo : invertible (2 : R)]
{B : bilin_form R M} (hB₁ : B ≠ 0) (hB₂ : sym_bilin_form.is_sym B) :
∃ x, ¬ B.is_ortho x x :=
begin
lift B to quadratic_form R M using hB₂ with Q,
obtain ⟨x, hx⟩ := quadratic_form.exists_quadratic_form_ne_zero hB₁,
exact ⟨x, λ h, hx (Q.associated_eq_self_apply ℕ x ▸ h)⟩,
end
open finite_dimensional
variables {V : Type u} {K : Type v} [field K] [add_comm_group V] [module K V]
variable [finite_dimensional K V]
/-- Given a symmetric bilinear form `B` on some vector space `V` over a field `K`
in which `2` is invertible, there exists an orthogonal basis with respect to `B`. -/
lemma exists_orthogonal_basis [hK : invertible (2 : K)]
{B : bilin_form K V} (hB₂ : sym_bilin_form.is_sym B) :
∃ (v : basis (fin (finrank K V)) K V), B.is_Ortho v :=
begin
tactic.unfreeze_local_instances,
induction hd : finrank K V with d ih generalizing V,
{ exact ⟨basis_of_finrank_zero hd, λ _ _ _, zero_left _⟩ },
haveI := finrank_pos_iff.1 (hd.symm ▸ nat.succ_pos d : 0 < finrank K V),
-- either the bilinear form is trivial or we can pick a non-null `x`
obtain rfl | hB₁ := eq_or_ne B 0,
{ let b := finite_dimensional.fin_basis K V,
rw hd at b,
refine ⟨b, λ i j hij, rfl⟩, },
obtain ⟨x, hx⟩ := exists_bilin_form_self_ne_zero hB₁ hB₂,
rw [← submodule.finrank_add_eq_of_is_compl (is_compl_span_singleton_orthogonal hx).symm,
finrank_span_singleton (ne_zero_of_not_is_ortho_self x hx)] at hd,
let B' := B.restrict (B.orthogonal $ K ∙ x),
obtain ⟨v', hv₁⟩ := ih (B.restrict_sym hB₂ _ : sym_bilin_form.is_sym B') (nat.succ.inj hd),
-- concatenate `x` with the basis obtained by induction
let b := basis.mk_fin_cons x v'
(begin
rintros c y hy hc,
rw add_eq_zero_iff_neg_eq at hc,
rw [← hc, submodule.neg_mem_iff] at hy,
have := (is_compl_span_singleton_orthogonal hx).disjoint,
rw submodule.disjoint_def at this,
have := this (c • x) (submodule.smul_mem _ _ $ submodule.mem_span_singleton_self _) hy,
exact (smul_eq_zero.1 this).resolve_right (λ h, hx $ h.symm ▸ zero_left _),
end)
(begin
intro y,
refine ⟨-B x y/B x x, λ z hz, _⟩,
obtain ⟨c, rfl⟩ := submodule.mem_span_singleton.1 hz,
rw [is_ortho, smul_left, add_right, smul_right, div_mul_cancel _ hx, add_neg_self, mul_zero],
end),
refine ⟨b, _⟩,
{ rw basis.coe_mk_fin_cons,
intros j i,
refine fin.cases _ (λ i, _) i; refine fin.cases _ (λ j, _) j; intro hij;
simp only [function.on_fun, fin.cons_zero, fin.cons_succ, function.comp_apply],
{ exact (hij rfl).elim },
{ rw [is_ortho, hB₂],
exact (v' j).prop _ (submodule.mem_span_singleton_self x) },
{ exact (v' i).prop _ (submodule.mem_span_singleton_self x) },
{ exact hv₁ _ _ (ne_of_apply_ne _ hij), }, }
end
end bilin_form
namespace quadratic_form
open_locale big_operators
open finset bilin_form
variables {M₁ : Type*} [add_comm_group M₁] [module R M₁]
variables {ι : Type*} [fintype ι] {v : basis ι R M}
/-- A quadratic form composed with a `linear_equiv` is isometric to itself. -/
def isometry_of_comp_linear_equiv (Q : quadratic_form R M) (f : M₁ ≃ₗ[R] M) :
Q.isometry (Q.comp (f : M₁ →ₗ[R] M)) :=
{ map_app' :=
begin
intro,
simp only [comp_apply, linear_equiv.coe_coe, linear_equiv.to_fun_eq_coe,
linear_equiv.apply_symm_apply, f.apply_symm_apply],
end,
.. f.symm }
/-- Given a quadratic form `Q` and a basis, `basis_repr` is the basis representation of `Q`. -/
noncomputable def basis_repr (Q : quadratic_form R M) (v : basis ι R M) :
quadratic_form R (ι → R) :=
Q.comp v.equiv_fun.symm
@[simp]
lemma basis_repr_apply (Q : quadratic_form R M) (w : ι → R) :
Q.basis_repr v w = Q (∑ i : ι, w i • v i) :=
by { rw ← v.equiv_fun_symm_apply, refl }
/-- A quadratic form is isometric to its bases representations. -/
noncomputable def isometry_basis_repr (Q : quadratic_form R M) (v : basis ι R M):
isometry Q (Q.basis_repr v) :=
isometry_of_comp_linear_equiv Q v.equiv_fun.symm
section
variable (R₁)
/-- The weighted sum of squares with respect to some weight as a quadratic form.
The weights are applied using `•`; typically this definition is used either with `S = R₁` or
`[algebra S R₁]`, although this is stated more generally. -/
def weighted_sum_squares [monoid S] [distrib_mul_action S R₁] [smul_comm_class S R₁ R₁]
(w : ι → S) : quadratic_form R₁ (ι → R₁) :=
∑ i : ι, w i • proj i i
end
@[simp]
lemma weighted_sum_squares_apply [monoid S] [distrib_mul_action S R₁] [smul_comm_class S R₁ R₁]
(w : ι → S) (v : ι → R₁) :
weighted_sum_squares R₁ w v = ∑ i : ι, w i • (v i * v i) :=
quadratic_form.sum_apply _ _ _
/-- On an orthogonal basis, the basis representation of `Q` is just a sum of squares. -/
lemma basis_repr_eq_of_is_Ortho [invertible (2 : R₁)]
(Q : quadratic_form R₁ M) (v : basis ι R₁ M) (hv₂ : (associated Q).is_Ortho v) :
Q.basis_repr v = weighted_sum_squares _ (λ i, Q (v i)) :=
begin
ext w,
rw [basis_repr_apply, ←@associated_eq_self_apply R₁, sum_left, weighted_sum_squares_apply],
refine sum_congr rfl (λ j hj, _),
rw [←@associated_eq_self_apply R₁, sum_right, sum_eq_single_of_mem j hj],
{ rw [smul_left, smul_right, smul_eq_mul], ring },
{ intros i _ hij,
rw [smul_left, smul_right,
show associated_hom R₁ Q (v j) (v i) = 0, from hv₂ j i hij.symm,
mul_zero, mul_zero] },
end
variables {V : Type*} {K : Type*} [field K] [invertible (2 : K)]
variables [add_comm_group V] [module K V]
/-- Given an orthogonal basis, a quadratic form is isometric with a weighted sum of squares. -/
noncomputable def isometry_weighted_sum_squares (Q : quadratic_form K V)
(v : basis (fin (finite_dimensional.finrank K V)) K V)
(hv₁ : (associated Q).is_Ortho v):
Q.isometry (weighted_sum_squares K (λ i, Q (v i))) :=
begin
let iso := Q.isometry_basis_repr v,
refine ⟨iso, λ m, _⟩,
convert iso.map_app m,
rw basis_repr_eq_of_is_Ortho _ _ hv₁,
end
variables [finite_dimensional K V]
lemma equivalent_weighted_sum_squares (Q : quadratic_form K V) :
∃ w : fin (finite_dimensional.finrank K V) → K, equivalent Q (weighted_sum_squares K w) :=
let ⟨v, hv₁⟩ := exists_orthogonal_basis (associated_is_sym _ Q) in
⟨_, ⟨Q.isometry_weighted_sum_squares v hv₁⟩⟩
lemma equivalent_weighted_sum_squares_units_of_nondegenerate'
(Q : quadratic_form K V) (hQ : (associated Q).nondegenerate) :
∃ w : fin (finite_dimensional.finrank K V) → units K,
equivalent Q (weighted_sum_squares K w) :=
begin
obtain ⟨v, hv₁⟩ := exists_orthogonal_basis (associated_is_sym _ Q),
have hv₂ := hv₁.not_is_ortho_basis_self_of_nondegenerate hQ,
simp_rw [is_ortho, associated_eq_self_apply] at hv₂,
exact ⟨λ i, units.mk0 _ (hv₂ i), ⟨Q.isometry_weighted_sum_squares v hv₁⟩⟩,
end
end quadratic_form
|
5a686746517161d5faeb6a7064210026b19aebac
|
fecda8e6b848337561d6467a1e30cf23176d6ad0
|
/src/data/padics/padic_norm.lean
|
221f80a272163970df9ebdfa5c46be4fb2a51baf
|
[
"Apache-2.0"
] |
permissive
|
spolu/mathlib
|
bacf18c3d2a561d00ecdc9413187729dd1f705ed
|
480c92cdfe1cf3c2d083abded87e82162e8814f4
|
refs/heads/master
| 1,671,684,094,325
| 1,600,736,045,000
| 1,600,736,045,000
| 297,564,749
| 1
| 0
| null | 1,600,758,368,000
| 1,600,758,367,000
| null |
UTF-8
|
Lean
| false
| false
| 25,160
|
lean
|
/-
Copyright (c) 2018 Robert Y. Lewis. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robert Y. Lewis
-/
import algebra.gcd_monoid
import algebra.field_power
import ring_theory.multiplicity
import data.real.cau_seq
import tactic.ring_exp
import tactic.basic
/-!
# p-adic norm
This file defines the p-adic valuation and the p-adic norm on ℚ.
The p-adic valuation on ℚ is the difference of the multiplicities of `p` in the numerator and
denominator of `q`. This function obeys the standard properties of a valuation, with the appropriate
assumptions on p.
The valuation induces a norm on ℚ. This norm is a nonarchimedean absolute value.
It takes values in {0} ∪ {1/p^k | k ∈ ℤ}.
## Notations
This file uses the local notation `/.` for `rat.mk`.
## Implementation notes
Much, but not all, of this file assumes that `p` is prime. This assumption is inferred automatically
by taking `[fact (prime p)]` as a type class argument.
## References
* [F. Q. Gouêva, *p-adic numbers*][gouvea1997]
* [R. Y. Lewis, *A formal proof of Hensel's lemma over the p-adic integers*][lewis2019]
* <https://en.wikipedia.org/wiki/P-adic_number>
## Tags
p-adic, p adic, padic, norm, valuation
-/
universe u
open nat
open_locale rat
open multiplicity
/--
For `p ≠ 1`, the p-adic valuation of an integer `z ≠ 0` is the largest natural number `n` such that
p^n divides z.
`padic_val_rat` defines the valuation of a rational `q` to be the valuation of `q.num` minus the
valuation of `q.denom`.
If `q = 0` or `p = 1`, then `padic_val_rat p q` defaults to 0.
-/
def padic_val_rat (p : ℕ) (q : ℚ) : ℤ :=
if h : q ≠ 0 ∧ p ≠ 1
then (multiplicity (p : ℤ) q.num).get
(multiplicity.finite_int_iff.2 ⟨h.2, rat.num_ne_zero_of_ne_zero h.1⟩) -
(multiplicity (p : ℤ) q.denom).get
(multiplicity.finite_int_iff.2 ⟨h.2, by exact_mod_cast rat.denom_ne_zero _⟩)
else 0
/--
A simplification of the definition of `padic_val_rat p q` when `q ≠ 0` and `p` is prime.
-/
lemma padic_val_rat_def (p : ℕ) [hp : fact p.prime] {q : ℚ} (hq : q ≠ 0) : padic_val_rat p q =
(multiplicity (p : ℤ) q.num).get (finite_int_iff.2 ⟨hp.ne_one, rat.num_ne_zero_of_ne_zero hq⟩) -
(multiplicity (p : ℤ) q.denom).get
(finite_int_iff.2 ⟨hp.ne_one, by exact_mod_cast rat.denom_ne_zero _⟩) :=
dif_pos ⟨hq, hp.ne_one⟩
namespace padic_val_rat
open multiplicity
variables {p : ℕ}
/--
`padic_val_rat p q` is symmetric in `q`.
-/
@[simp] protected lemma neg (q : ℚ) : padic_val_rat p (-q) = padic_val_rat p q :=
begin
unfold padic_val_rat,
split_ifs,
{ simp [-add_comm]; refl },
{ exfalso, simp * at * },
{ exfalso, simp * at * },
{ refl }
end
/--
`padic_val_rat p 1` is 0 for any `p`.
-/
@[simp] protected lemma one : padic_val_rat p 1 = 0 :=
by unfold padic_val_rat; split_ifs; simp *
/--
For `p ≠ 0, p ≠ 1, `padic_val_rat p p` is 1.
-/
@[simp] lemma padic_val_rat_self (hp : 1 < p) : padic_val_rat p p = 1 :=
by unfold padic_val_rat; split_ifs; simp [*, nat.one_lt_iff_ne_zero_and_ne_one] at *
/--
The p-adic value of an integer `z ≠ 0` is the multiplicity of `p` in `z`.
-/
lemma padic_val_rat_of_int (z : ℤ) (hp : p ≠ 1) (hz : z ≠ 0) :
padic_val_rat p (z : ℚ) = (multiplicity (p : ℤ) z).get
(finite_int_iff.2 ⟨hp, hz⟩) :=
by rw [padic_val_rat, dif_pos]; simp *; refl
end padic_val_rat
/--
A convenience function for the case of `padic_val_rat` when both inputs are natural numbers.
-/
def padic_val_nat (p : ℕ) (n : ℕ) : ℕ :=
int.to_nat (padic_val_rat p n)
section padic_val_nat
/--
`padic_val_nat` is defined as an `int.to_nat` cast; this lemma ensures that the cast is well-behaved.
-/
lemma zero_le_padic_val_rat_of_nat (p n : ℕ) : 0 ≤ padic_val_rat p n :=
begin
unfold padic_val_rat,
split_ifs,
{ simp, },
{ trivial, },
end
/--
`padic_val_rat` coincides with `padic_val_nat`.
-/
@[simp, norm_cast] lemma padic_val_rat_of_nat (p n : ℕ) : ↑(padic_val_nat p n) = padic_val_rat p n :=
begin
unfold padic_val_nat,
rw int.to_nat_of_nonneg (zero_le_padic_val_rat_of_nat p n),
end
/--
A simplification of `padic_val_nat` when one input is prime, by analogy with `padic_val_rat_def`.
-/
lemma padic_val_nat_def {p : ℕ} [hp : fact p.prime] {n : ℕ} (hn : n ≠ 0) :
padic_val_nat p n =
(multiplicity p n).get (multiplicity.finite_nat_iff.2 ⟨nat.prime.ne_one hp, bot_lt_iff_ne_bot.mpr hn⟩) :=
begin
have n_nonzero : (n : ℚ) ≠ 0, by simpa only [cast_eq_zero, ne.def],
-- Infinite loop with @simp padic_val_rat_of_nat unless we restrict the available lemmas here,
-- hence the very long list
simpa only
[ int.coe_nat_multiplicity p n, rat.coe_nat_denom n, (padic_val_rat_of_nat p n).symm,
int.coe_nat_zero, int.coe_nat_inj', sub_zero, get_one_right, int.coe_nat_succ, zero_add,
rat.coe_nat_num ]
using padic_val_rat_def p n_nonzero,
end
lemma one_le_padic_val_nat_of_dvd {n p : nat} [prime : fact p.prime] (nonzero : n ≠ 0) (div : p ∣ n) :
1 ≤ padic_val_nat p n :=
begin
rw @padic_val_nat_def _ prime _ nonzero,
let one_le_mul : _ ≤ multiplicity p n :=
@multiplicity.le_multiplicity_of_pow_dvd _ _ _ p n 1 (begin norm_num, exact div end),
simp only [enat.coe_one] at one_le_mul,
rcases one_le_mul with ⟨_, q⟩,
dsimp at q,
solve_by_elim,
end
@[simp]
lemma padic_val_nat_zero (m : nat) : padic_val_nat m 0 = 0 := by simpa
@[simp]
lemma padic_val_nat_one (m : nat) : padic_val_nat m 1 = 0 := by simp [padic_val_nat]
end padic_val_nat
namespace padic_val_rat
open multiplicity
variables (p : ℕ) [p_prime : fact p.prime]
include p_prime
/--
The multiplicity of `p : ℕ` in `a : ℤ` is finite exactly when `a ≠ 0`.
-/
lemma finite_int_prime_iff {p : ℕ} [p_prime : fact p.prime] {a : ℤ} : finite (p : ℤ) a ↔ a ≠ 0 :=
by simp [finite_int_iff, ne.symm (ne_of_lt (p_prime.one_lt))]
/--
A rewrite lemma for `padic_val_rat p q` when `q` is expressed in terms of `rat.mk`.
-/
protected lemma defn {q : ℚ} {n d : ℤ} (hqz : q ≠ 0) (qdf : q = n /. d) :
padic_val_rat p q = (multiplicity (p : ℤ) n).get (finite_int_iff.2
⟨ne.symm $ ne_of_lt p_prime.one_lt, λ hn, by simp * at *⟩) -
(multiplicity (p : ℤ) d).get (finite_int_iff.2 ⟨ne.symm $ ne_of_lt p_prime.one_lt,
λ hd, by simp * at *⟩) :=
have hn : n ≠ 0, from rat.mk_num_ne_zero_of_ne_zero hqz qdf,
have hd : d ≠ 0, from rat.mk_denom_ne_zero_of_ne_zero hqz qdf,
let ⟨c, hc1, hc2⟩ := rat.num_denom_mk hn hd qdf in
by rw [padic_val_rat, dif_pos];
simp [hc1, hc2, multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime),
(ne.symm (ne_of_lt p_prime.one_lt)), hqz]
/--
A rewrite lemma for `padic_val_rat p (q * r)` with conditions `q ≠ 0`, `r ≠ 0`.
-/
protected lemma mul {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padic_val_rat p (q * r) = padic_val_rat p q + padic_val_rat p r :=
have q*r = (q.num * r.num) /. (↑q.denom * ↑r.denom), by rw_mod_cast rat.mul_num_denom,
have hq' : q.num /. q.denom ≠ 0, by rw rat.num_denom; exact hq,
have hr' : r.num /. r.denom ≠ 0, by rw rat.num_denom; exact hr,
have hp' : _root_.prime (p : ℤ), from nat.prime_iff_prime_int.1 p_prime,
begin
rw [padic_val_rat.defn p (mul_ne_zero hq hr) this],
conv_rhs { rw [←(@rat.num_denom q), padic_val_rat.defn p hq',
←(@rat.num_denom r), padic_val_rat.defn p hr'] },
rw [multiplicity.mul' hp', multiplicity.mul' hp']; simp [add_comm, add_left_comm, sub_eq_add_neg]
end
/--
A rewrite lemma for `padic_val_rat p (q^k) with condition `q ≠ 0`.
-/
protected lemma pow {q : ℚ} (hq : q ≠ 0) {k : ℕ} :
padic_val_rat p (q ^ k) = k * padic_val_rat p q :=
by induction k; simp [*, padic_val_rat.mul _ hq (pow_ne_zero _ hq),
pow_succ, add_mul, add_comm]
/--
A rewrite lemma for `padic_val_rat p (q⁻¹)` with condition `q ≠ 0`.
-/
protected lemma inv {q : ℚ} (hq : q ≠ 0) :
padic_val_rat p (q⁻¹) = -padic_val_rat p q :=
by rw [eq_neg_iff_add_eq_zero, ← padic_val_rat.mul p (inv_ne_zero hq) hq,
inv_mul_cancel hq, padic_val_rat.one]
/--
A rewrite lemma for `padic_val_rat p (q / r)` with conditions `q ≠ 0`, `r ≠ 0`.
-/
protected lemma div {q r : ℚ} (hq : q ≠ 0) (hr : r ≠ 0) :
padic_val_rat p (q / r) = padic_val_rat p q - padic_val_rat p r :=
by rw [div_eq_mul_inv, padic_val_rat.mul p hq (inv_ne_zero hr),
padic_val_rat.inv p hr, sub_eq_add_neg]
/--
A condition for `padic_val_rat p (n₁ / d₁) ≤ padic_val_rat p (n₂ / d₂),
in terms of divisibility by `p^n`.
-/
lemma padic_val_rat_le_padic_val_rat_iff {n₁ n₂ d₁ d₂ : ℤ}
(hn₁ : n₁ ≠ 0) (hn₂ : n₂ ≠ 0) (hd₁ : d₁ ≠ 0) (hd₂ : d₂ ≠ 0) :
padic_val_rat p (n₁ /. d₁) ≤ padic_val_rat p (n₂ /. d₂) ↔
∀ (n : ℕ), ↑p ^ n ∣ n₁ * d₂ → ↑p ^ n ∣ n₂ * d₁ :=
have hf1 : finite (p : ℤ) (n₁ * d₂),
from finite_int_prime_iff.2 (mul_ne_zero hn₁ hd₂),
have hf2 : finite (p : ℤ) (n₂ * d₁),
from finite_int_prime_iff.2 (mul_ne_zero hn₂ hd₁),
by conv {
to_lhs,
rw [padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn₁ hd₁) rfl,
padic_val_rat.defn p (rat.mk_ne_zero_of_ne_zero hn₂ hd₂) rfl,
sub_le_iff_le_add',
← add_sub_assoc,
le_sub_iff_add_le],
norm_cast,
rw [← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime) hf1, add_comm,
← multiplicity.mul' (nat.prime_iff_prime_int.1 p_prime) hf2,
enat.get_le_get, multiplicity_le_multiplicity_iff]
}
/--
Sufficient conditions to show that the p-adic valuation of `q` is less than or equal to the
p-adic vlauation of `q + r`.
-/
theorem le_padic_val_rat_add_of_le {q r : ℚ}
(hq : q ≠ 0) (hr : r ≠ 0) (hqr : q + r ≠ 0)
(h : padic_val_rat p q ≤ padic_val_rat p r) :
padic_val_rat p q ≤ padic_val_rat p (q + r) :=
have hqn : q.num ≠ 0, from rat.num_ne_zero_of_ne_zero hq,
have hqd : (q.denom : ℤ) ≠ 0, by exact_mod_cast rat.denom_ne_zero _,
have hrn : r.num ≠ 0, from rat.num_ne_zero_of_ne_zero hr,
have hrd : (r.denom : ℤ) ≠ 0, by exact_mod_cast rat.denom_ne_zero _,
have hqdv : q.num /. q.denom ≠ 0, from rat.mk_ne_zero_of_ne_zero hqn hqd,
have hrdv : r.num /. r.denom ≠ 0, from rat.mk_ne_zero_of_ne_zero hrn hrd,
have hqreq : q + r = (((q.num * r.denom + q.denom * r.num : ℤ)) /. (↑q.denom * ↑r.denom : ℤ)),
from rat.add_num_denom _ _,
have hqrd : q.num * ↑(r.denom) + ↑(q.denom) * r.num ≠ 0,
from rat.mk_num_ne_zero_of_ne_zero hqr hqreq,
begin
conv_lhs { rw ←(@rat.num_denom q) },
rw [hqreq, padic_val_rat_le_padic_val_rat_iff p hqn hqrd hqd (mul_ne_zero hqd hrd),
← multiplicity_le_multiplicity_iff, mul_left_comm,
multiplicity.mul (nat.prime_iff_prime_int.1 p_prime), add_mul],
rw [←(@rat.num_denom q), ←(@rat.num_denom r),
padic_val_rat_le_padic_val_rat_iff p hqn hrn hqd hrd, ← multiplicity_le_multiplicity_iff] at h,
calc _ ≤ min (multiplicity ↑p (q.num * ↑(r.denom) * ↑(q.denom)))
(multiplicity ↑p (↑(q.denom) * r.num * ↑(q.denom))) : (le_min
(by rw [@multiplicity.mul _ _ _ _ (_ * _) _ (nat.prime_iff_prime_int.1 p_prime), add_comm])
(by rw [mul_assoc, @multiplicity.mul _ _ _ _ (q.denom : ℤ)
(_ * _) (nat.prime_iff_prime_int.1 p_prime)];
exact add_le_add_left h _))
... ≤ _ : min_le_multiplicity_add
end
/--
The minimum of the valuations of `q` and `r` is less than or equal to the valuation of `q + r`.
-/
theorem min_le_padic_val_rat_add {q r : ℚ}
(hq : q ≠ 0) (hr : r ≠ 0) (hqr : q + r ≠ 0) :
min (padic_val_rat p q) (padic_val_rat p r) ≤ padic_val_rat p (q + r) :=
(le_total (padic_val_rat p q) (padic_val_rat p r)).elim
(λ h, by rw [min_eq_left h]; exact le_padic_val_rat_add_of_le _ hq hr hqr h)
(λ h, by rw [min_eq_right h, add_comm]; exact le_padic_val_rat_add_of_le _ hr hq
(by rwa add_comm) h)
end padic_val_rat
namespace padic_val_nat
/--
A rewrite lemma for `padic_val_nat p (q * r)` with conditions `q ≠ 0`, `r ≠ 0`.
-/
protected lemma mul (p : ℕ) [p_prime : fact p.prime] {q r : ℕ} (hq : q ≠ 0) (hr : r ≠ 0) :
padic_val_nat p (q * r) = padic_val_nat p q + padic_val_nat p r :=
begin
apply int.coe_nat_inj,
simp only [padic_val_rat_of_nat, nat.cast_mul],
rw padic_val_rat.mul,
norm_cast,
exact cast_ne_zero.mpr hq,
exact cast_ne_zero.mpr hr,
end
/--
Dividing out by a prime factor reduces the padic_val_nat by 1.
-/
protected lemma div {p : ℕ} [p_prime : fact p.prime] {b : ℕ} (dvd : p ∣ b) :
(padic_val_nat p (b / p)) = (padic_val_nat p b) - 1 :=
begin
by_cases b_split : (b = 0),
{ simp [b_split], },
{ have split_frac : padic_val_rat p (b / p) = padic_val_rat p b - padic_val_rat p p :=
padic_val_rat.div p (nat.cast_ne_zero.mpr b_split) (nat.cast_ne_zero.mpr (nat.prime.ne_zero p_prime)),
rw padic_val_rat.padic_val_rat_self (nat.prime.one_lt p_prime) at split_frac,
have r : 1 ≤ padic_val_nat p b := one_le_padic_val_nat_of_dvd b_split dvd,
exact_mod_cast split_frac, }
end
end padic_val_nat
section padic_val_nat
/--
If a prime doesn't appear in `n`, `padic_val_nat p n` is `0`.
-/
lemma padic_val_nat_of_not_dvd {p : ℕ} [fact p.prime] {n : ℕ} (not_dvd : ¬(p ∣ n)) :
padic_val_nat p n = 0 :=
begin
by_cases hn : n = 0,
{ subst hn, simp at not_dvd, trivial, },
{ rw padic_val_nat_def hn,
exact (@multiplicity.unique' _ _ _ p n 0 (by simp) (by simpa using not_dvd)).symm,
assumption, },
end
lemma padic_val_nat_primes {p q : ℕ} [p_prime : fact p.prime] [q_prime : fact q.prime] (neq : p ≠ q) :
padic_val_nat p q = 0 :=
@padic_val_nat_of_not_dvd p p_prime q $ (not_congr (iff.symm (prime_dvd_prime_iff_eq p_prime q_prime))).mp neq
protected lemma padic_val_nat.div' {p : ℕ} [p_prime : fact p.prime] :
∀ {m : ℕ} (cpm : coprime p m) {b : ℕ} (dvd : m ∣ b), padic_val_nat p (b / m) = padic_val_nat p b
| 0 := λ cpm b dvd, by { rw zero_dvd_iff at dvd, rw [dvd, nat.zero_div], }
| (n + 1) :=
λ cpm b dvd,
begin
rcases dvd with ⟨c, rfl⟩,
rw [mul_div_right c (nat.succ_pos _)],by_cases hc : c = 0,
{ rw [hc, mul_zero] },
{ rw padic_val_nat.mul,
{ suffices : ¬ p ∣ (n+1),
{ rw [padic_val_nat_of_not_dvd this, zero_add] },
contrapose! cpm,
exact p_prime.dvd_iff_not_coprime.mp cpm },
{ exact nat.succ_ne_zero _ },
{ exact hc } },
end
lemma padic_val_nat_eq_factors_count (p : ℕ) [hp : fact p.prime] :
∀ (n : ℕ), padic_val_nat p n = (factors n).count p
| 0 := rfl
| 1 := by { rw padic_val_nat_one, refl }
| (m + 2) :=
let n := m + 2 in
let q := min_fac n in
have hq : fact q.prime := min_fac_prime (show m + 2 ≠ 1, by linarith),
have wf : n / q < n := nat.div_lt_self (nat.succ_pos _) hq.one_lt,
begin
rw factors_add_two,
show padic_val_nat p n = list.count p (q :: (factors (n / q))),
rw [list.count_cons', ← padic_val_nat_eq_factors_count],
split_ifs with h,
have p_dvd_n : p ∣ n,
{ have: q ∣ n := nat.min_fac_dvd n,
cc },
{ rw [←h, padic_val_nat.div],
{ have: 1 ≤ padic_val_nat p n := one_le_padic_val_nat_of_dvd (by linarith) p_dvd_n,
exact (nat.sub_eq_iff_eq_add this).mp rfl, },
{ exact p_dvd_n, }, },
{ suffices : p.coprime q,
{ rw [padic_val_nat.div' this (min_fac_dvd n), add_zero], },
rwa nat.coprime_primes hp hq, },
end
open_locale big_operators
lemma prod_pow_prime_padic_val_nat (n : nat) (hn : n ≠ 0) (m : nat) (pr : n < m) :
∏ p in finset.filter nat.prime (finset.range m), p ^ (padic_val_nat p n) = n :=
begin
rw ← nat.pos_iff_ne_zero at hn,
have H : (factors n : multiset ℕ).prod = n,
{ rw [multiset.coe_prod, prod_factors hn], },
rw finset.prod_multiset_count at H,
conv_rhs { rw ← H, },
refine finset.prod_bij_ne_one (λ p hp hp', p) _ _ _ _,
{ rintro p hp hpn,
rw [finset.mem_filter, finset.mem_range] at hp,
haveI Hp : fact p.prime := hp.2,
rw [multiset.mem_to_finset, multiset.mem_coe, mem_factors_iff_dvd hn Hp],
contrapose! hpn,
rw [padic_val_nat_of_not_dvd hpn, nat.pow_zero], },
{ intros, assumption },
{ intros p hp hpn,
rw [multiset.mem_to_finset, multiset.mem_coe] at hp,
haveI Hp : fact p.prime := mem_factors hp,
simp only [exists_prop, ne.def, finset.mem_filter, finset.mem_range],
refine ⟨p, ⟨_, Hp⟩, ⟨_, rfl⟩⟩,
{ rw mem_factors_iff_dvd hn Hp at hp, exact lt_of_le_of_lt (le_of_dvd hn hp) pr },
{ rw padic_val_nat_eq_factors_count,
simpa [ne.def, multiset.coe_count] using hpn } },
{ intros p hp hpn,
rw [finset.mem_filter, finset.mem_range] at hp,
haveI Hp : fact p.prime := hp.2,
rw [padic_val_nat_eq_factors_count, multiset.coe_count] }
end
end padic_val_nat
/--
If `q ≠ 0`, the p-adic norm of a rational `q` is `p ^ (-(padic_val_rat p q))`.
If `q = 0`, the p-adic norm of `q` is 0.
-/
def padic_norm (p : ℕ) (q : ℚ) : ℚ :=
if q = 0 then 0 else (↑p : ℚ) ^ (-(padic_val_rat p q))
namespace padic_norm
section padic_norm
open padic_val_rat
variables (p : ℕ)
/--
Unfolds the definition of the p-adic norm of `q` when `q ≠ 0`.
-/
@[simp] protected lemma eq_fpow_of_nonzero {q : ℚ} (hq : q ≠ 0) :
padic_norm p q = p ^ (-(padic_val_rat p q)) :=
by simp [hq, padic_norm]
/--
The p-adic norm is nonnegative.
-/
protected lemma nonneg (q : ℚ) : 0 ≤ padic_norm p q :=
if hq : q = 0 then by simp [hq, padic_norm]
else
begin
unfold padic_norm; split_ifs,
apply fpow_nonneg_of_nonneg,
exact_mod_cast nat.zero_le _
end
/--
The p-adic norm of 0 is 0.
-/
@[simp] protected lemma zero : padic_norm p 0 = 0 := by simp [padic_norm]
/--
The p-adic norm of 1 is 1.
-/
@[simp] protected lemma one : padic_norm p 1 = 1 := by simp [padic_norm]
/--
The p-adic norm of `p` is `1/p` if `p > 1`.
See also `padic_norm.padic_norm_p_of_prime` for a version that assumes `p` is prime.
-/
lemma padic_norm_p {p : ℕ} (hp : 1 < p) : padic_norm p p = 1 / p :=
by simp [padic_norm, (show p ≠ 0, by linarith), padic_val_rat.padic_val_rat_self hp]
/--
The p-adic norm of `p` is `1/p` if `p` is prime.
See also `padic_norm.padic_norm_p` for a version that assumes `1 < p`.
-/
@[simp] lemma padic_norm_p_of_prime (p : ℕ) [fact p.prime] : padic_norm p p = 1 / p :=
padic_norm_p $ nat.prime.one_lt ‹_›
/--
The p-adic norm of `p` is less than 1 if `1 < p`.
See also `padic_norm.padic_norm_p_lt_one_of_prime` for a version assuming `prime p`.
-/
lemma padic_norm_p_lt_one {p : ℕ} (hp : 1 < p) : padic_norm p p < 1 :=
begin
rw [padic_norm_p hp, div_lt_iff, one_mul],
{ exact_mod_cast hp },
{ exact_mod_cast zero_lt_one.trans hp },
end
/--
The p-adic norm of `p` is less than 1 if `p` is prime.
See also `padic_norm.padic_norm_p_lt_one` for a version assuming `1 < p`.
-/
lemma padic_norm_p_lt_one_of_prime (p : ℕ) [fact p.prime] : padic_norm p p < 1 :=
padic_norm_p_lt_one $ nat.prime.one_lt ‹_›
/--
`padic_norm p q` takes discrete values `p ^ -z` for `z : ℤ`.
-/
protected theorem values_discrete {q : ℚ} (hq : q ≠ 0) : ∃ z : ℤ, padic_norm p q = p ^ (-z) :=
⟨ (padic_val_rat p q), by simp [padic_norm, hq] ⟩
variable [hp : fact p.prime]
include hp
/--
If `q ≠ 0`, then `padic_norm p q ≠ 0`.
-/
protected lemma nonzero {q : ℚ} (hq : q ≠ 0) : padic_norm p q ≠ 0 :=
begin
rw padic_norm.eq_fpow_of_nonzero p hq,
apply fpow_ne_zero_of_ne_zero,
exact_mod_cast ne_of_gt hp.pos
end
/--
`padic_norm p` is symmetric.
-/
@[simp] protected lemma neg (q : ℚ) : padic_norm p (-q) = padic_norm p q :=
if hq : q = 0 then by simp [hq]
else by simp [padic_norm, hq, hp.one_lt]
/--
If the p-adic norm of `q` is 0, then `q` is 0.
-/
lemma zero_of_padic_norm_eq_zero {q : ℚ} (h : padic_norm p q = 0) : q = 0 :=
begin
apply by_contradiction, intro hq,
unfold padic_norm at h, rw if_neg hq at h,
apply absurd h,
apply fpow_ne_zero_of_ne_zero,
exact_mod_cast hp.ne_zero
end
/--
The p-adic norm is multiplicative.
-/
@[simp] protected theorem mul (q r : ℚ) : padic_norm p (q*r) = padic_norm p q * padic_norm p r :=
if hq : q = 0 then
by simp [hq]
else if hr : r = 0 then
by simp [hr]
else
have q*r ≠ 0, from mul_ne_zero hq hr,
have (↑p : ℚ) ≠ 0, by simp [hp.ne_zero],
by simp [padic_norm, *, padic_val_rat.mul, fpow_add this, mul_comm]
/--
The p-adic norm respects division.
-/
@[simp] protected theorem div (q r : ℚ) : padic_norm p (q / r) = padic_norm p q / padic_norm p r :=
if hr : r = 0 then by simp [hr] else
eq_div_of_mul_eq (padic_norm.nonzero _ hr) (by rw [←padic_norm.mul, div_mul_cancel _ hr])
/--
The p-adic norm of an integer is at most 1.
-/
protected theorem of_int (z : ℤ) : padic_norm p ↑z ≤ 1 :=
if hz : z = 0 then by simp [hz, zero_le_one] else
begin
unfold padic_norm,
rw [if_neg _],
{ refine fpow_le_one_of_nonpos _ _,
{ exact_mod_cast le_of_lt hp.one_lt, },
{ rw [padic_val_rat_of_int _ hp.ne_one hz, neg_nonpos],
norm_cast, simp }},
exact_mod_cast hz
end
private lemma nonarchimedean_aux {q r : ℚ} (h : padic_val_rat p q ≤ padic_val_rat p r) :
padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) :=
have hnqp : padic_norm p q ≥ 0, from padic_norm.nonneg _ _,
have hnrp : padic_norm p r ≥ 0, from padic_norm.nonneg _ _,
if hq : q = 0 then
by simp [hq, max_eq_right hnrp, le_max_right]
else if hr : r = 0 then
by simp [hr, max_eq_left hnqp, le_max_left]
else if hqr : q + r = 0 then
le_trans (by simpa [hqr] using hnqp) (le_max_left _ _)
else
begin
unfold padic_norm, split_ifs,
apply le_max_iff.2,
left,
apply fpow_le_of_le,
{ exact_mod_cast le_of_lt hp.one_lt },
{ apply neg_le_neg,
have : padic_val_rat p q =
min (padic_val_rat p q) (padic_val_rat p r),
from (min_eq_left h).symm,
rw this,
apply min_le_padic_val_rat_add; assumption }
end
/--
The p-adic norm is nonarchimedean: the norm of `p + q` is at most the max of the norm of `p` and
the norm of `q`.
-/
protected theorem nonarchimedean {q r : ℚ} :
padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) :=
begin
wlog hle := le_total (padic_val_rat p q) (padic_val_rat p r) using [q r],
exact nonarchimedean_aux p hle
end
/--
The p-adic norm respects the triangle inequality: the norm of `p + q` is at most the norm of `p`
plus the norm of `q`.
-/
theorem triangle_ineq (q r : ℚ) : padic_norm p (q + r) ≤ padic_norm p q + padic_norm p r :=
calc padic_norm p (q + r) ≤ max (padic_norm p q) (padic_norm p r) : padic_norm.nonarchimedean p
... ≤ padic_norm p q + padic_norm p r :
max_le_add_of_nonneg (padic_norm.nonneg p _) (padic_norm.nonneg p _)
/--
The p-adic norm of a difference is at most the max of each component. Restates the archimedean
property of the p-adic norm.
-/
protected theorem sub {q r : ℚ} : padic_norm p (q - r) ≤ max (padic_norm p q) (padic_norm p r) :=
by rw [sub_eq_add_neg, ←padic_norm.neg p r]; apply padic_norm.nonarchimedean
/--
If the p-adic norms of `q` and `r` are different, then the norm of `q + r` is equal to the max of
the norms of `q` and `r`.
-/
lemma add_eq_max_of_ne {q r : ℚ} (hne : padic_norm p q ≠ padic_norm p r) :
padic_norm p (q + r) = max (padic_norm p q) (padic_norm p r) :=
begin
wlog hle := le_total (padic_norm p r) (padic_norm p q) using [q r],
have hlt : padic_norm p r < padic_norm p q, from lt_of_le_of_ne hle hne.symm,
have : padic_norm p q ≤ max (padic_norm p (q + r)) (padic_norm p r), from calc
padic_norm p q = padic_norm p (q + r - r) : by congr; ring
... ≤ max (padic_norm p (q + r)) (padic_norm p (-r)) : padic_norm.nonarchimedean p
... = max (padic_norm p (q + r)) (padic_norm p r) : by simp,
have hnge : padic_norm p r ≤ padic_norm p (q + r),
{ apply le_of_not_gt,
intro hgt,
rw max_eq_right_of_lt hgt at this,
apply not_lt_of_ge this,
assumption },
have : padic_norm p q ≤ padic_norm p (q + r), by rwa [max_eq_left hnge] at this,
apply _root_.le_antisymm,
{ apply padic_norm.nonarchimedean p },
{ rw max_eq_left_of_lt hlt,
assumption }
end
/--
The p-adic norm is an absolute value: positive-definite and multiplicative, satisfying the triangle
inequality.
-/
instance : is_absolute_value (padic_norm p) :=
{ abv_nonneg := padic_norm.nonneg p,
abv_eq_zero :=
begin
intros,
constructor; intro,
{ apply zero_of_padic_norm_eq_zero p, assumption },
{ simp [*] }
end,
abv_add := padic_norm.triangle_ineq p,
abv_mul := padic_norm.mul p }
variable {p}
lemma dvd_iff_norm_le {n : ℕ} {z : ℤ} : ↑(p^n) ∣ z ↔ padic_norm p z ≤ ↑p ^ (-n : ℤ) :=
begin
unfold padic_norm, split_ifs with hz,
{ norm_cast at hz,
have : 0 ≤ (p^n : ℚ), {apply pow_nonneg, exact_mod_cast le_of_lt hp.pos },
simp [hz, this] },
{ rw [fpow_le_iff_le, neg_le_neg_iff, padic_val_rat_of_int _ hp.ne_one _],
{ norm_cast,
rw [← enat.coe_le_coe, enat.coe_get, ← multiplicity.pow_dvd_iff_le_multiplicity],
simp },
{ exact_mod_cast hz },
{ exact_mod_cast hp.one_lt } }
end
end padic_norm
end padic_norm
|
0527ac4c7a6e2e5dfb263464cf7a10fd112c9fd7
|
4727251e0cd73359b15b664c3170e5d754078599
|
/src/category_theory/limits/colimit_limit.lean
|
443a4fdc24ba3d612fa8b35019cc3ce20a1c5198
|
[
"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,441
|
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.limits.types
import category_theory.functor.currying
import category_theory.limits.functor_category
/-!
# The morphism comparing a colimit of limits with the corresponding limit of colimits.
For `F : J × K ⥤ C` there is always a morphism $\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$.
While it is not usually an isomorphism, with additional hypotheses on `J` and `K` it may be,
in which case we say that "colimits commute with limits".
The prototypical example, proved in `category_theory.limits.filtered_colimit_commutes_finite_limit`,
is that when `C = Type`, filtered colimits commute with finite limits.
## References
* Borceux, Handbook of categorical algebra 1, Section 2.13
* [Stacks: Filtered colimits](https://stacks.math.columbia.edu/tag/002W)
-/
universes v₂ v u
open category_theory
namespace category_theory.limits
variables {J K : Type v} [small_category J] [small_category K]
variables {C : Type u} [category.{v} C]
variables (F : J × K ⥤ C)
open category_theory.prod
lemma map_id_left_eq_curry_map {j : J} {k k' : K} {f : k ⟶ k'} :
F.map ((𝟙 j, f) : (j, k) ⟶ (j, k')) = ((curry.obj F).obj j).map f :=
rfl
lemma map_id_right_eq_curry_swap_map {j j' : J} {f : j ⟶ j'} {k : K} :
F.map ((f, 𝟙 k) : (j, k) ⟶ (j', k)) = ((curry.obj (swap K J ⋙ F)).obj k).map f :=
rfl
variables [has_limits_of_shape J C]
variables [has_colimits_of_shape K C]
/--
The universal morphism
$\colim_k \lim_j F(j,k) → \lim_j \colim_k F(j, k)$.
-/
noncomputable
def colimit_limit_to_limit_colimit :
colimit ((curry.obj (swap K J ⋙ F)) ⋙ lim) ⟶ limit ((curry.obj F) ⋙ colim) :=
limit.lift ((curry.obj F) ⋙ colim)
{ X := _,
π :=
{ app := λ j, colimit.desc ((curry.obj (swap K J ⋙ F)) ⋙ lim)
{ X := _,
ι :=
{ app := λ k,
limit.π ((curry.obj (swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k,
naturality' :=
begin
dsimp,
intros k k' f,
simp only [functor.comp_map, curry.obj_map_app, limits.lim_map_π_assoc, swap_map,
category.comp_id, map_id_left_eq_curry_map, colimit.w],
end }, },
naturality' :=
begin
dsimp,
intros j j' f,
ext k,
simp only [limits.colimit.ι_map, curry.obj_map_app, limits.colimit.ι_desc_assoc,
limits.colimit.ι_desc, category.id_comp, category.assoc, map_id_right_eq_curry_swap_map,
limit.w_assoc],
end } }
/--
Since `colimit_limit_to_limit_colimit` is a morphism from a colimit to a limit,
this lemma characterises it.
-/
@[simp, reassoc] lemma ι_colimit_limit_to_limit_colimit_π (j) (k) :
colimit.ι _ k ≫ colimit_limit_to_limit_colimit F ≫ limit.π _ j =
limit.π ((curry.obj (swap K J ⋙ F)).obj k) j ≫ colimit.ι ((curry.obj F).obj j) k :=
by { dsimp [colimit_limit_to_limit_colimit], simp, }
@[simp] lemma ι_colimit_limit_to_limit_colimit_π_apply (F : J × K ⥤ Type v) (j) (k) (f) :
limit.π ((curry.obj F) ⋙ colim) j
(colimit_limit_to_limit_colimit F (colimit.ι ((curry.obj (swap K J ⋙ F)) ⋙ lim) k f)) =
colimit.ι ((curry.obj F).obj j) k (limit.π ((curry.obj (swap K J ⋙ F)).obj k) j f) :=
by { dsimp [colimit_limit_to_limit_colimit], simp, }
/-- The map `colimit_limit_to_limit_colimit` realized as a map of cones. -/
@[simps] noncomputable def colimit_limit_to_limit_colimit_cone (G : J ⥤ K ⥤ C) [has_limit G] :
colim.map_cone (limit.cone G) ⟶ limit.cone (G ⋙ colim) :=
{ hom := colim.map (limit_iso_swap_comp_lim G).hom ≫
colimit_limit_to_limit_colimit (uncurry.obj G : _) ≫
lim.map (whisker_right (currying.unit_iso.app G).inv colim),
w' := λ j,
begin
ext1 k,
simp only [limit_obj_iso_limit_comp_evaluation_hom_π_assoc, iso.app_inv,
ι_colimit_limit_to_limit_colimit_π_assoc, whisker_right_app,
colimit.ι_map, functor.map_cone_π_app, category.id_comp,
eq_to_hom_refl, eq_to_hom_app, colimit.ι_map_assoc, limit.cone_π,
lim_map_π_assoc, lim_map_π, category.assoc, currying_unit_iso_inv_app_app_app,
limit_iso_swap_comp_lim_hom_app, lim_map_eq_lim_map],
dsimp,
simp only [category.id_comp],
erw limit_obj_iso_limit_comp_evaluation_hom_π_assoc,
end }
end category_theory.limits
|
72274d37a9d49517d4be9a1939f8ce16582664f3
|
1d265c7dd8cb3d0e1d645a19fd6157a2084c3921
|
/src/lessons/lesson13.lean
|
6f2c3bc05a28fa6623577a8b0b3e7f389dd342cd
|
[
"MIT"
] |
permissive
|
hanzhi713/lean-proofs
|
de432372f220d302be09b5ca4227f8986567e4fd
|
4d8356a878645b9ba7cb036f87737f3f1e68ede5
|
refs/heads/master
| 1,585,580,245,658
| 1,553,646,623,000
| 1,553,646,623,000
| 151,342,188
| 0
| 1
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,352
|
lean
|
example : ∃ P Q : Prop, (P ∨ Q) ∧ (¬P ∨ ¬Q) ∧ (¬P ∨ Q) :=
begin
apply exists.intro false,
apply exists.intro true,
split,
show false ∨ true, from or.inr true.intro,
split,
show ¬false ∨ ¬true,
apply or.inl,
assume f, assumption,
show ¬false ∨ true, from or.inr true.intro,
end
example : ¬ ∃ P Q : Prop, (P ∨ Q) ∧ (¬P ∨ ¬Q) ∧ (¬P ∨ Q) ∧ (¬Q) :=
begin
assume h,
apply exists.elim h,
intros,
apply exists.elim a_1,
intros,
have na2 : ¬a_2 := a_3.2.2.2,
cases a_3.1 with pfa pfa_2,
cases a_3.2.1 with pfna pfna_2,
exact pfna pfa,
cases a_3.2.2.1 with pfna pfa_2,
exact pfna pfa,
exact na2 pfa_2,
exact na2 pfa_2,
end
example : ∃ P Q R : Prop,(P ∨ Q ∨ R) ∧ (¬P ∨ ¬Q ∨ ¬R) ∧ (¬P ∨ Q ∨ R) ∧ (¬Q ∨ ¬R)
:=
begin
apply exists.intro true,
apply exists.intro true,
apply exists.intro false,
split,
exact or.inl true.intro,
split,
apply or.inr,
apply or.inr,
assume f, assumption,
split,
apply or.inr,
apply or.inl,
exact true.intro,
apply or.inr,
assume f, assumption
end
|
b8af3d2fe0633efddd9fa7eee332d6fe4f742cb7
|
e00ea76a720126cf9f6d732ad6216b5b824d20a7
|
/src/ring_theory/algebraic.lean
|
71c34334bbd9a5a4c6827049d3410c0cf28c80bd
|
[
"Apache-2.0"
] |
permissive
|
vaibhavkarve/mathlib
|
a574aaf68c0a431a47fa82ce0637f0f769826bfe
|
17f8340912468f49bdc30acdb9a9fa02eeb0473a
|
refs/heads/master
| 1,621,263,802,637
| 1,585,399,588,000
| 1,585,399,588,000
| 250,833,447
| 0
| 0
|
Apache-2.0
| 1,585,410,341,000
| 1,585,410,341,000
| null |
UTF-8
|
Lean
| false
| false
| 3,408
|
lean
|
/-
Copyright (c) 2019 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
-/
import ring_theory.integral_closure
/-!
# Algebraic elements and algebraic extensions
An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial.
An R-algebra is algebraic over R if and only if all its elements are algebraic over R.
The main result in this file proves transitivity of algebraicity:
a tower of algebraic field extensions is algebraic.
-/
universe variables u v
open_locale classical
open polynomial
section
variables (R : Type u) {A : Type v} [comm_ring R] [comm_ring A] [algebra R A]
/-- An element of an R-algebra is algebraic over R if it is the root of a nonzero polynomial. -/
def is_algebraic (x : A) : Prop :=
∃ p : polynomial R, p ≠ 0 ∧ aeval R A x p = 0
variables {R}
/-- A subalgebra is algebraic if all its elements are algebraic. -/
def subalgebra.is_algebraic (S : subalgebra R A) : Prop := ∀ x ∈ S, is_algebraic R x
variables (R A)
/-- An algebra is algebraic if all its elements are algebraic. -/
def algebra.is_algebraic : Prop := ∀ x : A, is_algebraic R x
variables {R A}
/-- A subalgebra is algebraic if and only if it is algebraic an algebra. -/
lemma subalgebra.is_algebraic_iff (S : subalgebra R A) :
S.is_algebraic ↔ @algebra.is_algebraic R S _ _ (by convert S.algebra) :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
rw [subtype.forall'],
apply forall_congr, rintro ⟨x, hx⟩,
apply exists_congr, intro p,
apply and_congr iff.rfl,
have h : function.injective (S.val) := subtype.val_injective,
conv_rhs { rw [← h.eq_iff, alg_hom.map_zero], },
apply eq_iff_eq_cancel_right.mpr,
symmetry, apply hom_eval₂,
end
/-- An algebra is algebraic if and only if it is algebraic as a subalgebra. -/
lemma algebra.is_algebraic_iff : algebra.is_algebraic R A ↔ (⊤ : subalgebra R A).is_algebraic :=
begin
delta algebra.is_algebraic subalgebra.is_algebraic,
simp only [algebra.mem_top, forall_prop_of_true, iff_self],
end
end
section zero_ne_one
variables (R : Type u) {A : Type v} [nonzero_comm_ring R] [comm_ring A] [algebra R A]
/-- An integral element of an algebra is algebraic.-/
lemma is_integral.is_algebraic {x : A} (h : is_integral R x) : is_algebraic R x :=
by { rcases h with ⟨p, hp, hpx⟩, exact ⟨p, hp.ne_zero, hpx⟩ }
end zero_ne_one
section field
variables (K : Type u) {A : Type v} [field K] [comm_ring A] [algebra K A]
/-- An element of an algebra over a field is algebraic if and only if it is integral.-/
lemma is_algebraic_iff_is_integral {x : A} :
is_algebraic K x ↔ is_integral K x :=
begin
refine ⟨_, is_integral.is_algebraic K⟩,
rintro ⟨p, hp, hpx⟩,
refine ⟨_, monic_mul_leading_coeff_inv hp, _⟩,
rw [alg_hom.map_mul, hpx, zero_mul],
end
end field
namespace algebra
variables {K : Type*} {L : Type*} {A : Type*}
variables [field K] [field L] [comm_ring A]
variables [algebra K L] [algebra L A]
/-- If L is an algebraic field extension of K and A is an algebraic algebra over L,
then A is algebraic over K. -/
lemma is_algebraic_trans (L_alg : is_algebraic K L) (A_alg : is_algebraic L A) :
is_algebraic K (comap K L A) :=
begin
simp only [is_algebraic, is_algebraic_iff_is_integral] at L_alg A_alg ⊢,
exact is_integral_trans L_alg A_alg,
end
end algebra
|
5dfafae195f516410a8800d61c54d5e44e6b3078
|
5ae26df177f810c5006841e9c73dc56e01b978d7
|
/src/category/monad/cont.lean
|
02c0fad9c53f542f75a4681d2f80963ccb01e5dc
|
[
"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
| 8,780
|
lean
|
/-
Copyright (c) 2019 Simon Hudon. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Simon Hudon
Monad encapsulating continuation passing programming style, similar to
Haskell's `Cont`, `ContT` and `MonadCont`:
http://hackage.haskell.org/package/mtl-2.2.2/docs/Control-Monad-Cont.html
-/
import tactic.ext
import category.monad.basic category.monad.writer
universes u v w
structure monad_cont.label (α : Type w) (m : Type u → Type v) (β : Type u) :=
(apply : α → m β)
def monad_cont.goto {α β} {m : Type u → Type v} (f : monad_cont.label α m β) (x : α) := f.apply x
class monad_cont (m : Type u → Type v) :=
(call_cc : Π {α β}, ((monad_cont.label α m β) → m α) → m α)
open monad_cont
class is_lawful_monad_cont (m : Type u → Type v) [monad m] [monad_cont m]
extends is_lawful_monad m :=
(call_cc_bind_right {α ω γ} (cmd : m α) (next : (label ω m γ) → α → m ω) :
call_cc (λ f, cmd >>= next f) = cmd >>= λ x, call_cc (λ f, next f x))
(call_cc_bind_left {α} (β) (x : α) (dead : label α m β → β → m α) :
call_cc (λ f : label α m β, goto f x >>= dead f) = pure x)
(call_cc_dummy {α β} (dummy : m α) :
call_cc (λ f : label α m β, dummy) = dummy)
export is_lawful_monad_cont
def cont_t (r : Type u) (m : Type u → Type v) (α : Type w) := (α → m r) → m r
@[reducible] def cont (r : Type u) (α : Type w) := cont_t r id α
namespace cont_t
export monad_cont (label goto)
variables {r : Type u} {m : Type u → Type v} {α β γ ω : Type w}
def run : cont_t r m α → (α → m r) → m r := id
def map (f : m r → m r) (x : cont_t r m α) : cont_t r m α := f ∘ x
lemma run_cont_t_map_cont_t (f : m r → m r) (x : cont_t r m α) :
run (map f x) = f ∘ run x := rfl
def with_cont_t (f : (β → m r) → α → m r) (x : cont_t r m α) : cont_t r m β :=
λ g, x $ f g
lemma run_with_cont_t (f : (β → m r) → α → m r) (x : cont_t r m α) :
run (with_cont_t f x) = run x ∘ f := rfl
@[extensionality]
protected lemma ext {x y : cont_t r m α}
(h : ∀ f, x.run f = y.run f) :
x = y := by { ext; apply h }
instance : monad (cont_t r m) :=
{ pure := λ α x f, f x,
bind := λ α β x f g, x $ λ i, f i g }
instance : is_lawful_monad (cont_t r m) :=
{ id_map := by { intros, refl },
pure_bind := by { intros, ext, refl },
bind_assoc := by { intros, ext, refl } }
def cont_t.monad_lift [monad m] {α} : m α → cont_t r m α :=
λ x f, x >>= f
instance [monad m] : has_monad_lift m (cont_t r m) :=
{ monad_lift := λ α, cont_t.monad_lift }
lemma monad_lift_bind [monad m] [is_lawful_monad m] {α β} (x : m α) (f : α → m β) :
(monad_lift (x >>= f) : cont_t r m β) = monad_lift x >>= monad_lift ∘ f :=
by { ext, simp only [monad_lift,has_monad_lift.monad_lift,(∘),(>>=),bind_assoc,id.def,run,cont_t.monad_lift] }
instance : monad_cont (cont_t r m) :=
{ call_cc := λ α β f g, f ⟨λ x h, g x⟩ g }
instance : is_lawful_monad_cont (cont_t r m) :=
{ call_cc_bind_right := by intros; ext; refl,
call_cc_bind_left := by intros; ext; refl,
call_cc_dummy := by intros; ext; refl }
instance (ε) [monad_except ε m] : monad_except ε (cont_t r m) :=
{ throw := λ x e f, throw e,
catch := λ α act h f, catch (act f) (λ e, h e f) }
instance : monad_run (λ α, (α → m r) → ulift.{u v} (m r)) (cont_t.{u v u} r m) :=
{ run := λ α f x, ⟨ f x ⟩ }
end cont_t
variables {m : Type u → Type v} [monad m]
def except_t.mk_label {α β ε} : label (except.{u u} ε α) m β → label α (except_t ε m) β
| ⟨ f ⟩ := ⟨ λ a, monad_lift $ f (except.ok a) ⟩
lemma except_t.goto_mk_label {α β ε : Type*} (x : label (except.{u u} ε α) m β) (i : α) :
goto (except_t.mk_label x) i = ⟨ except.ok <$> goto x (except.ok i) ⟩ := by cases x; refl
def except_t.call_cc {ε} [monad_cont m] {α β : Type*} (f : label α (except_t ε m) β → except_t ε m α) : except_t ε m α :=
except_t.mk (call_cc $ λ x : label _ m β, except_t.run $ f (except_t.mk_label x) : m (except ε α))
instance {ε} [monad_cont m] : monad_cont (except_t ε m) :=
{ call_cc := λ α β, except_t.call_cc }
instance {ε} [monad_cont m] [is_lawful_monad_cont m] : is_lawful_monad_cont (except_t ε m) :=
{ call_cc_bind_right := by { intros, simp [call_cc,except_t.call_cc,call_cc_bind_right], ext, dsimp, congr, ext ⟨ ⟩; simp [except_t.bind_cont,@call_cc_dummy m _], },
call_cc_bind_left := by { intros, simp [call_cc,except_t.call_cc,call_cc_bind_right,except_t.goto_mk_label,map_eq_bind_pure_comp,bind_assoc,@call_cc_bind_left m _], ext, refl },
call_cc_dummy := by { intros, simp [call_cc,except_t.call_cc,@call_cc_dummy m _], ext, refl }, }
def option_t.mk_label {α β} : label (option.{u} α) m β → label α (option_t m) β
| ⟨ f ⟩ := ⟨ λ a, monad_lift $ f (some a) ⟩
lemma option_t.goto_mk_label {α β : Type*} (x : label (option.{u} α) m β) (i : α) :
goto (option_t.mk_label x) i = ⟨ some <$> goto x (some i) ⟩ := by cases x; refl
def option_t.call_cc [monad_cont m] {α β : Type*} (f : label α (option_t m) β → option_t m α) : option_t m α :=
option_t.mk (call_cc $ λ x : label _ m β, option_t.run $ f (option_t.mk_label x) : m (option α))
instance [monad_cont m] : monad_cont (option_t m) :=
{ call_cc := λ α β, option_t.call_cc }
instance [monad_cont m] [is_lawful_monad_cont m] : is_lawful_monad_cont (option_t m) :=
{ call_cc_bind_right := by { intros, simp [call_cc,option_t.call_cc,call_cc_bind_right], ext, dsimp, congr, ext ⟨ ⟩; simp [option_t.bind_cont,@call_cc_dummy m _], },
call_cc_bind_left := by { intros, simp [call_cc,option_t.call_cc,call_cc_bind_right,option_t.goto_mk_label,map_eq_bind_pure_comp,bind_assoc,@call_cc_bind_left m _], ext, refl },
call_cc_dummy := by { intros, simp [call_cc,option_t.call_cc,@call_cc_dummy m _], ext, refl }, }
def writer_t.mk_label {α β ω} [has_one ω] : label (α × ω) m β → label α (writer_t ω m) β
| ⟨ f ⟩ := ⟨ λ a, monad_lift $ f (a,1) ⟩
lemma writer_t.goto_mk_label {α β ω : Type*} [has_one ω] (x : label (α × ω) m β) (i : α) :
goto (writer_t.mk_label x) i = monad_lift (goto x (i,1)) := by cases x; refl
def writer_t.call_cc [monad_cont m] {α β ω : Type*} [has_one ω] (f : label α (writer_t ω m) β → writer_t ω m α) : writer_t ω m α :=
⟨ call_cc (writer_t.run ∘ f ∘ writer_t.mk_label : label (α × ω) m β → m (α × ω)) ⟩
instance (ω) [monad m] [has_one ω] [monad_cont m] : monad_cont (writer_t ω m) :=
{ call_cc := λ α β, writer_t.call_cc }
def state_t.mk_label {α β σ : Type u} : label (α × σ) m (β × σ) → label α (state_t σ m) β
| ⟨ f ⟩ := ⟨ λ a, ⟨ λ s, f (a,s) ⟩ ⟩
lemma state_t.goto_mk_label {α β σ : Type u} (x : label (α × σ) m (β × σ)) (i : α) :
goto (state_t.mk_label x) i = ⟨ λ s, (goto x (i,s)) ⟩ := by cases x; refl
def state_t.call_cc {σ} [monad_cont m] {α β : Type*} (f : label α (state_t σ m) β → state_t σ m α) : state_t σ m α :=
⟨ λ r, call_cc (λ f', (f $ state_t.mk_label f').run r) ⟩
instance {σ} [monad_cont m] : monad_cont (state_t σ m) :=
{ call_cc := λ α β, state_t.call_cc }
instance {σ} [monad_cont m] [is_lawful_monad_cont m] : is_lawful_monad_cont (state_t σ m) :=
{ call_cc_bind_right := by { intros, simp [call_cc,state_t.call_cc,call_cc_bind_right,(>>=),state_t.bind], ext, dsimp, congr, ext ⟨x₀,x₁⟩, refl },
call_cc_bind_left := by { intros, simp [call_cc,state_t.call_cc,call_cc_bind_left,(>>=),state_t.bind,state_t.goto_mk_label], ext, refl },
call_cc_dummy := by { intros, simp [call_cc,state_t.call_cc,call_cc_bind_right,(>>=),state_t.bind,@call_cc_dummy m _], ext, refl }, }
def reader_t.mk_label {α β} (ρ) : label α m β → label α (reader_t ρ m) β
| ⟨ f ⟩ := ⟨ monad_lift ∘ f ⟩
lemma reader_t.goto_mk_label {α ρ β} (x : label α m β) (i : α) :
goto (reader_t.mk_label ρ x) i = monad_lift (goto x i) := by cases x; refl
def reader_t.call_cc {ε} [monad_cont m] {α β : Type*} (f : label α (reader_t ε m) β → reader_t ε m α) : reader_t ε m α :=
⟨ λ r, call_cc (λ f', (f $ reader_t.mk_label _ f').run r) ⟩
instance {ρ} [monad_cont m] : monad_cont (reader_t ρ m) :=
{ call_cc := λ α β, reader_t.call_cc }
instance {ρ} [monad_cont m] [is_lawful_monad_cont m] : is_lawful_monad_cont (reader_t ρ m) :=
{ call_cc_bind_right := by { intros, simp [call_cc,reader_t.call_cc,call_cc_bind_right], ext, refl },
call_cc_bind_left := by { intros, simp [call_cc,reader_t.call_cc,call_cc_bind_left,reader_t.goto_mk_label], ext, refl },
call_cc_dummy := by { intros, simp [call_cc,reader_t.call_cc,@call_cc_dummy m _], ext, refl } }
|
2a73497ed0ea25e2ce519b13668fe96b3f3081e2
|
4f643cce24b2d005aeeb5004c2316a8d6cc7f3b1
|
/omin/cells.lean
|
b963796c492658228a270738b0594b5b082946e2
|
[] |
no_license
|
rwbarton/lean-omin
|
da209ed061d64db65a8f7f71f198064986f30eb9
|
fd733c6d95ef6f4743aae97de5e15df79877c00e
|
refs/heads/master
| 1,674,408,673,325
| 1,607,343,535,000
| 1,607,343,535,000
| 285,150,399
| 9
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,653
|
lean
|
import o_minimal.o_minimal
import data.set.disjointed
import data.setoid.partition
namespace o_minimal
variables {R : Type*} [DUNLO R]
variables (S : struc R) [definable_constants S] [is_definable_le S R]
namespace struc
def cell : Π {n}, set (finvec n R) → Prop
| 0 s := s = set.univ
| (n+1) s := ∃ (s₀ : set (finvec n R)) (h : cell s₀),
s = {x | x.init ∈ s₀}
∨
(∃ (f : finvec n R → R) (hf : def_fun S f),
s = {x | x.init ∈ s₀ ∧ x (fin.last n) = f x.init}
∨ s = {x | x.init ∈ s₀ ∧ x (fin.last n) ∈ set.Ioi (f x.init)}
∨ s = {x | x.init ∈ s₀ ∧ x (fin.last n) ∈ set.Iio (f x.init)})
∨
(∃ (f g : finvec n R → R) (hf : def_fun S f) (hg : def_fun S g),
(∀ x₀ ∈ s₀, f x₀ < g x₀) ∧
s = {x | x.init ∈ s₀ ∧ x (fin.last n) ∈ set.Ioo (f x.init) (g x.init)})
lemma init_definable (n : ℕ) :
def_fun S (finvec.init : finvec (n+1) R → finvec n R) :=
begin
sorry
end
lemma cell.definable : ∀ {n} (s : set (finvec n R)) (hs : S.cell s), def_set S s
| 0 s hs := by { cases hs, apply def_set_univ }
| (n+1) s hs :=
begin
obtain ⟨s₀, hs₀, H|H|H⟩ := hs,
{ cases H,
show def_set S (finvec.init ⁻¹' s₀), sorry },
sorry,
sorry,
end
def decomposition : Π {n} (C : set (set (finvec n R))), Prop
| 0 C := C = {set.univ}
| (n+1) C := C.finite ∧ setoid.is_partition C
∧ ∀ s ∈ C, S.cell s
∧ decomposition ((set.image finvec.init) '' C)
end struc
end o_minimal
|
2a167eadf2349c331626bce67d57facea0afd16d
|
83c8119e3298c0bfc53fc195c41a6afb63d01513
|
/tests/lean/run/simp_tc_err.lean
|
f728247647101d114fd29a421a47db5177538fc5
|
[
"Apache-2.0"
] |
permissive
|
anfelor/lean
|
584b91c4e87a6d95f7630c2a93fb082a87319ed0
|
31cfc2b6bf7d674f3d0f73848b842c9c9869c9f1
|
refs/heads/master
| 1,610,067,141,310
| 1,585,992,232,000
| 1,585,992,232,000
| 251,683,543
| 0
| 0
|
Apache-2.0
| 1,585,676,570,000
| 1,585,676,569,000
| null |
UTF-8
|
Lean
| false
| false
| 470
|
lean
|
def c : ℕ := default _
def d : ℕ := default _
class foo (α : Type)
-- type class resolution for [foo α] will always time out
instance foo.foo {α} [foo α] : foo α := ‹foo α›
-- would break simp on any term containing c
@[simp] lemma c_eq_d [foo ℕ] : c = d := by refl
set_option trace.simplify.rewrite true
example : c = d + 0 :=
begin
-- shouldn't fail, even though type class resolution for c_eq_d times out
simp,
guard_target c = d,
refl,
end
|
bd94f385a3691392fc105ea67a75976044f2730f
|
d406927ab5617694ec9ea7001f101b7c9e3d9702
|
/src/data/nat/with_bot.lean
|
6f1b74c9e3dae374dd3edb4e2d0154a9c3a66c76
|
[
"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
| 2,164
|
lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import data.nat.order.basic
import algebra.order.monoid.with_top
/-!
# `with_bot ℕ`
Lemmas about the type of natural numbers with a bottom element adjoined.
-/
namespace nat
namespace with_bot
lemma add_eq_zero_iff {n m : with_bot ℕ} : n + m = 0 ↔ n = 0 ∧ m = 0 :=
begin
rcases ⟨n, m⟩ with ⟨_ | _, _ | _⟩,
any_goals { tautology },
repeat { erw [with_bot.coe_eq_coe] },
exact add_eq_zero_iff
end
lemma add_eq_one_iff {n m : with_bot ℕ} : n + m = 1 ↔ n = 0 ∧ m = 1 ∨ n = 1 ∧ m = 0 :=
begin
rcases ⟨n, m⟩ with ⟨_ | _, _ | _⟩,
any_goals { tautology },
repeat { erw [with_bot.coe_eq_coe] },
exact add_eq_one_iff
end
lemma add_eq_two_iff {n m : with_bot ℕ} :
n + m = 2 ↔ n = 0 ∧ m = 2 ∨ n = 1 ∧ m = 1 ∨ n = 2 ∧ m = 0 :=
begin
rcases ⟨n, m⟩ with ⟨_ | _, _ | _⟩,
any_goals { tautology },
repeat { erw [with_bot.coe_eq_coe] },
exact add_eq_two_iff
end
lemma add_eq_three_iff {n m : with_bot ℕ} :
n + m = 3 ↔ n = 0 ∧ m = 3 ∨ n = 1 ∧ m = 2 ∨ n = 2 ∧ m = 1 ∨ n = 3 ∧ m = 0 :=
begin
rcases ⟨n, m⟩ with ⟨_ | _, _ | _⟩,
any_goals { tautology },
repeat { erw [with_bot.coe_eq_coe] },
exact add_eq_three_iff
end
@[simp] lemma coe_nonneg {n : ℕ} : 0 ≤ (n : with_bot ℕ) :=
by { rw [← with_bot.coe_zero, with_bot.coe_le_coe], exact nat.zero_le _ }
@[simp] lemma lt_zero_iff (n : with_bot ℕ) : n < 0 ↔ n = ⊥ :=
option.cases_on n dec_trivial $ λ n, iff_of_false
(by simp [with_bot.some_eq_coe]) (λ h, option.no_confusion h)
lemma one_le_iff_zero_lt {x : with_bot ℕ} : 1 ≤ x ↔ 0 < x :=
begin
refine ⟨λ h, lt_of_lt_of_le (with_bot.coe_lt_coe.mpr zero_lt_one) h, λ h, _⟩,
induction x using with_bot.rec_bot_coe,
{ exact (not_lt_bot h).elim },
{ exact with_bot.coe_le_coe.mpr (nat.succ_le_iff.mpr (with_bot.coe_lt_coe.mp h)) }
end
lemma lt_one_iff_le_zero {x : with_bot ℕ} : x < 1 ↔ x ≤ 0 :=
not_iff_not.mp (by simpa using one_le_iff_zero_lt)
end with_bot
end nat
|
b4b2a4547d981fedf91bbacc2aaa65234ed2802b
|
8cae430f0a71442d02dbb1cbb14073b31048e4b0
|
/src/topology/metric_space/baire.lean
|
21e4a43a3f940d65bb1c6fe0795bbed4db01fa4f
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathlib
|
56a2cadd17ac88caf4ece0a775932fa26327ba0e
|
442a83d738cb208d3600056c489be16900ba701d
|
refs/heads/master
| 1,693,584,102,358
| 1,693,471,902,000
| 1,693,471,902,000
| 97,922,418
| 1,595
| 352
|
Apache-2.0
| 1,694,693,445,000
| 1,500,624,130,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 16,555
|
lean
|
/-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel
-/
import analysis.specific_limits.basic
import topology.G_delta
import topology.sets.compacts
/-!
# Baire theorem
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In a complete metric space, a countable intersection of dense open subsets is dense.
The good concept underlying the theorem is that of a Gδ set, i.e., a countable intersection
of open sets. Then Baire theorem can also be formulated as the fact that a countable
intersection of dense Gδ sets is a dense Gδ set. We prove Baire theorem, giving several different
formulations that can be handy. We also prove the important consequence that, if the space is
covered by a countable union of closed sets, then the union of their interiors is dense.
We also prove that in Baire spaces, the `residual` sets are exactly those containing a dense Gδ set.
-/
noncomputable theory
open_locale classical topology filter ennreal
open filter encodable set topological_space
variables {α : Type*} {β : Type*} {γ : Type*} {ι : Type*}
section Baire_theorem
open emetric ennreal
/-- The property `baire_space α` means that the topological space `α` has the Baire property:
any countable intersection of open dense subsets is dense.
Formulated here when the source space is ℕ (and subsumed below by `dense_Inter_of_open` working
with any encodable source space).-/
class baire_space (α : Type*) [topological_space α] : Prop :=
(baire_property : ∀ f : ℕ → set α, (∀ n, is_open (f n)) → (∀ n, dense (f n)) → dense (⋂n, f n))
/-- Baire theorems asserts that various topological spaces have the Baire property.
Two versions of these theorems are given.
The first states that complete pseudo_emetric spaces are Baire. -/
@[priority 100]
instance baire_category_theorem_emetric_complete [pseudo_emetric_space α] [complete_space α] :
baire_space α :=
begin
refine ⟨λ f ho hd, _⟩,
let B : ℕ → ℝ≥0∞ := λn, 1/2^n,
have Bpos : ∀n, 0 < B n,
{ intro n,
simp only [B, one_div, one_mul, ennreal.inv_pos],
exact pow_ne_top two_ne_top },
/- Translate the density assumption into two functions `center` and `radius` associating
to any n, x, δ, δpos a center and a positive radius such that
`closed_ball center radius` is included both in `f n` and in `closed_ball x δ`.
We can also require `radius ≤ (1/2)^(n+1)`, to ensure we get a Cauchy sequence later. -/
have : ∀n x δ, δ ≠ 0 → ∃y r, 0 < r ∧ r ≤ B (n+1) ∧ closed_ball y r ⊆ (closed_ball x δ) ∩ f n,
{ assume n x δ δpos,
have : x ∈ closure (f n) := hd n x,
rcases emetric.mem_closure_iff.1 this (δ/2) (ennreal.half_pos δpos) with ⟨y, ys, xy⟩,
rw edist_comm at xy,
obtain ⟨r, rpos, hr⟩ : ∃ r > 0, closed_ball y r ⊆ f n :=
nhds_basis_closed_eball.mem_iff.1 (is_open_iff_mem_nhds.1 (ho n) y ys),
refine ⟨y, min (min (δ/2) r) (B (n+1)), _, _, λz hz, ⟨_, _⟩⟩,
show 0 < min (min (δ / 2) r) (B (n+1)),
from lt_min (lt_min (ennreal.half_pos δpos) rpos) (Bpos (n+1)),
show min (min (δ / 2) r) (B (n+1)) ≤ B (n+1), from min_le_right _ _,
show z ∈ closed_ball x δ, from calc
edist z x ≤ edist z y + edist y x : edist_triangle _ _ _
... ≤ (min (min (δ / 2) r) (B (n+1))) + (δ/2) : add_le_add hz (le_of_lt xy)
... ≤ δ/2 + δ/2 : add_le_add (le_trans (min_le_left _ _) (min_le_left _ _)) le_rfl
... = δ : ennreal.add_halves δ,
show z ∈ f n, from hr (calc
edist z y ≤ min (min (δ / 2) r) (B (n+1)) : hz
... ≤ r : le_trans (min_le_left _ _) (min_le_right _ _)) },
choose! center radius Hpos HB Hball using this,
refine λ x, (mem_closure_iff_nhds_basis nhds_basis_closed_eball).2 (λ ε εpos, _),
/- `ε` is positive. We have to find a point in the ball of radius `ε` around `x` belonging to all
`f n`. For this, we construct inductively a sequence `F n = (c n, r n)` such that the closed ball
`closed_ball (c n) (r n)` is included in the previous ball and in `f n`, and such that
`r n` is small enough to ensure that `c n` is a Cauchy sequence. Then `c n` converges to a
limit which belongs to all the `f n`. -/
let F : ℕ → (α × ℝ≥0∞) := λn, nat.rec_on n (prod.mk x (min ε (B 0)))
(λn p, prod.mk (center n p.1 p.2) (radius n p.1 p.2)),
let c : ℕ → α := λn, (F n).1,
let r : ℕ → ℝ≥0∞ := λn, (F n).2,
have rpos : ∀ n, 0 < r n,
{ assume n,
induction n with n hn,
exact lt_min εpos (Bpos 0),
exact Hpos n (c n) (r n) hn.ne' },
have r0 : ∀ n, r n ≠ 0 := λ n, (rpos n).ne',
have rB : ∀n, r n ≤ B n,
{ assume n,
induction n with n hn,
exact min_le_right _ _,
exact HB n (c n) (r n) (r0 n) },
have incl : ∀n, closed_ball (c (n+1)) (r (n+1)) ⊆ (closed_ball (c n) (r n)) ∩ (f n) :=
λ n, Hball n (c n) (r n) (r0 n),
have cdist : ∀n, edist (c n) (c (n+1)) ≤ B n,
{ assume n,
rw edist_comm,
have A : c (n+1) ∈ closed_ball (c (n+1)) (r (n+1)) := mem_closed_ball_self,
have I := calc
closed_ball (c (n+1)) (r (n+1)) ⊆ closed_ball (c n) (r n) :
subset.trans (incl n) (inter_subset_left _ _)
... ⊆ closed_ball (c n) (B n) : closed_ball_subset_closed_ball (rB n),
exact I A },
have : cauchy_seq c :=
cauchy_seq_of_edist_le_geometric_two _ one_ne_top cdist,
-- as the sequence `c n` is Cauchy in a complete space, it converges to a limit `y`.
rcases cauchy_seq_tendsto_of_complete this with ⟨y, ylim⟩,
-- this point `y` will be the desired point. We will check that it belongs to all
-- `f n` and to `ball x ε`.
use y,
simp only [exists_prop, set.mem_Inter],
have I : ∀n, ∀m ≥ n, closed_ball (c m) (r m) ⊆ closed_ball (c n) (r n),
{ assume n,
refine nat.le_induction _ (λm hnm h, _),
{ exact subset.refl _ },
{ exact subset.trans (incl m) (subset.trans (inter_subset_left _ _) h) }},
have yball : ∀n, y ∈ closed_ball (c n) (r n),
{ assume n,
refine is_closed_ball.mem_of_tendsto ylim _,
refine (filter.eventually_ge_at_top n).mono (λ m hm, _),
exact I n m hm mem_closed_ball_self },
split,
show ∀n, y ∈ f n,
{ assume n,
have : closed_ball (c (n+1)) (r (n+1)) ⊆ f n := subset.trans (incl n) (inter_subset_right _ _),
exact this (yball (n+1)) },
show edist y x ≤ ε, from le_trans (yball 0) (min_le_left _ _),
end
/-- The second theorem states that locally compact spaces are Baire. -/
@[priority 100]
instance baire_category_theorem_locally_compact [topological_space α] [t2_space α]
[locally_compact_space α] :
baire_space α :=
begin
constructor,
intros f ho hd,
/- To prove that an intersection of open dense subsets is dense, prove that its intersection
with any open neighbourhood `U` is dense. Define recursively a decreasing sequence `K` of
compact neighbourhoods: start with some compact neighbourhood inside `U`, then at each step,
take its interior, intersect with `f n`, then choose a compact neighbourhood inside the
intersection.-/
apply dense_iff_inter_open.2,
intros U U_open U_nonempty,
rcases exists_positive_compacts_subset U_open U_nonempty with ⟨K₀, hK₀⟩,
have : ∀ n (K : positive_compacts α), ∃ K' : positive_compacts α, ↑K' ⊆ f n ∩ interior K,
{ refine λ n K, exists_positive_compacts_subset ((ho n).inter is_open_interior) _,
rw inter_comm,
exact (hd n).inter_open_nonempty _ is_open_interior K.interior_nonempty },
choose K_next hK_next,
let K : ℕ → positive_compacts α := λ n, nat.rec_on n K₀ K_next,
/- This is a decreasing sequence of positive compacts contained in suitable open sets `f n`.-/
have hK_decreasing : ∀ (n : ℕ), ↑(K (n + 1)) ⊆ f n ∩ K n,
from λ n, (hK_next n (K n)).trans $ inter_subset_inter_right _ interior_subset,
/- Prove that ̀`⋂ n : ℕ, K n` is inside `U ∩ ⋂ n : ℕ, (f n)`. -/
have hK_subset : (⋂ n, K n : set α) ⊆ U ∩ (⋂ n, f n),
{ intros x hx,
simp only [mem_inter_iff, mem_Inter] at hx ⊢,
exact ⟨hK₀ $ hx 0, λ n, (hK_decreasing n (hx (n + 1))).1⟩ },
/- Prove that `⋂ n : ℕ, K n` is not empty, as an intersection of a decreasing sequence
of nonempty compact subsets.-/
have hK_nonempty : (⋂ n, K n : set α).nonempty,
from is_compact.nonempty_Inter_of_sequence_nonempty_compact_closed _
(λ n, (hK_decreasing n).trans (inter_subset_right _ _))
(λ n, (K n).nonempty) (K 0).is_compact (λ n, (K n).is_compact.is_closed),
exact hK_nonempty.mono hK_subset
end
variables [topological_space α] [baire_space α]
/-- Definition of a Baire space. -/
theorem dense_Inter_of_open_nat {f : ℕ → set α} (ho : ∀ n, is_open (f n)) (hd : ∀ n, dense (f n)) :
dense (⋂ n, f n) :=
baire_space.baire_property f ho hd
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_open {S : set (set α)} (ho : ∀s∈S, is_open s) (hS : S.countable)
(hd : ∀s∈S, dense s) : dense (⋂₀S) :=
begin
cases S.eq_empty_or_nonempty with h h,
{ simp [h] },
{ rcases hS.exists_eq_range h with ⟨f, hf⟩,
have F : ∀n, f n ∈ S := λn, by rw hf; exact mem_range_self _,
rw [hf, sInter_range],
exact dense_Inter_of_open_nat (λn, ho _ (F n)) (λn, hd _ (F n)) }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_open {S : set β} {f : β → set α} (ho : ∀s∈S, is_open (f s))
(hS : S.countable) (hd : ∀s∈S, dense (f s)) : dense (⋂s∈S, f s) :=
begin
rw ← sInter_image,
apply dense_sInter_of_open,
{ rwa ball_image_iff },
{ exact hS.image _ },
{ rwa ball_image_iff }
end
/-- Baire theorem: a countable intersection of dense open sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_open [encodable β] {f : β → set α} (ho : ∀s, is_open (f s))
(hd : ∀s, dense (f s)) : dense (⋂s, f s) :=
begin
rw ← sInter_range,
apply dense_sInter_of_open,
{ rwa forall_range_iff },
{ exact countable_range _ },
{ rwa forall_range_iff }
end
/-- A set is residual (comeagre) if and only if it includes a dense `Gδ` set. -/
lemma mem_residual {s : set α} :
s ∈ residual α ↔ ∃ t ⊆ s, is_Gδ t ∧ dense t :=
begin
split,
{ rw mem_residual_iff,
rintros ⟨S, hSo, hSd, Sct, Ss⟩,
refine ⟨_, Ss, ⟨_, λ t ht, hSo _ ht, Sct, rfl⟩, _⟩,
exact dense_sInter_of_open hSo Sct hSd, },
rintros ⟨t, ts, ho, hd⟩,
exact mem_of_superset (residual_of_dense_Gδ ho hd) ts,
end
/-- A property holds on a residual (comeagre) set if and only if it holds on some dense `Gδ` set. -/
lemma eventually_residual {p : α → Prop} :
(∀ᶠ x in residual α, p x) ↔ ∃ (t : set α), is_Gδ t ∧ dense t ∧ ∀ (x : α), x ∈ t → p x :=
begin
-- this can probably be improved...
convert @mem_residual _ _ _ p,
simp_rw [exists_prop, and_comm ((_ : set α) ⊆ p), and_assoc],
refl,
end
lemma dense_of_mem_residual {s : set α} (hs : s ∈ residual α) : dense s :=
let ⟨t, hts, _, hd⟩ := mem_residual.1 hs in hd.mono hts
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with ⋂₀. -/
theorem dense_sInter_of_Gδ {S : set (set α)} (ho : ∀s∈S, is_Gδ s) (hS : S.countable)
(hd : ∀s∈S, dense s) : dense (⋂₀S) :=
dense_of_mem_residual ((countable_sInter_mem hS).mpr
(λ s hs, residual_of_dense_Gδ (ho _ hs) (hd _ hs)))
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is an encodable type. -/
theorem dense_Inter_of_Gδ [encodable β] {f : β → set α} (ho : ∀s, is_Gδ (f s))
(hd : ∀s, dense (f s)) : dense (⋂s, f s) :=
begin
rw ← sInter_range,
exact dense_sInter_of_Gδ (forall_range_iff.2 ‹_›) (countable_range _) (forall_range_iff.2 ‹_›)
end
/-- Baire theorem: a countable intersection of dense Gδ sets is dense. Formulated here with
an index set which is a countable set in any type. -/
theorem dense_bInter_of_Gδ {S : set β} {f : Π x ∈ S, set α} (ho : ∀s∈S, is_Gδ (f s ‹_›))
(hS : S.countable) (hd : ∀s∈S, dense (f s ‹_›)) : dense (⋂s∈S, f s ‹_›) :=
begin
rw bInter_eq_Inter,
haveI := hS.to_encodable,
exact dense_Inter_of_Gδ (λ s, ho s s.2) (λ s, hd s s.2)
end
/-- Baire theorem: the intersection of two dense Gδ sets is dense. -/
theorem dense.inter_of_Gδ {s t : set α} (hs : is_Gδ s) (ht : is_Gδ t) (hsc : dense s)
(htc : dense t) :
dense (s ∩ t) :=
begin
rw [inter_eq_Inter],
apply dense_Inter_of_Gδ; simp [bool.forall_bool, *]
end
/-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors
is dense. Formulated here with `⋃`. -/
lemma is_Gδ.dense_Union_interior_of_closed [encodable ι] {s : set α} (hs : is_Gδ s)
(hd : dense s) {f : ι → set α} (hc : ∀ i, is_closed (f i)) (hU : s ⊆ ⋃ i, f i) :
dense (⋃ i, interior (f i)) :=
begin
let g := λ i, (frontier (f i))ᶜ,
have hgo : ∀ i, is_open (g i), from λ i, is_closed_frontier.is_open_compl,
have hgd : dense (⋂ i, g i),
{ refine dense_Inter_of_open hgo (λ i x, _),
rw [closure_compl, interior_frontier (hc _)],
exact id },
refine (hd.inter_of_Gδ hs (is_Gδ_Inter_of_open $ λ i, hgo i) hgd).mono _,
rintro x ⟨hxs, hxg⟩,
rw [mem_Inter] at hxg,
rcases mem_Union.1 (hU hxs) with ⟨i, hi⟩,
exact mem_Union.2 ⟨i, self_diff_frontier (f i) ▸ ⟨hi, hxg _⟩⟩,
end
/-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors
is dense. Formulated here with a union over a countable set in any type. -/
lemma is_Gδ.dense_bUnion_interior_of_closed {t : set ι} {s : set α} (hs : is_Gδ s)
(hd : dense s) (ht : t.countable) {f : ι → set α} (hc : ∀ i ∈ t, is_closed (f i))
(hU : s ⊆ ⋃ i ∈ t, f i) :
dense (⋃ i ∈ t, interior (f i)) :=
begin
haveI := ht.to_encodable,
simp only [bUnion_eq_Union, set_coe.forall'] at *,
exact hs.dense_Union_interior_of_closed hd hc hU
end
/-- If a countable family of closed sets cover a dense `Gδ` set, then the union of their interiors
is dense. Formulated here with `⋃₀`. -/
lemma is_Gδ.dense_sUnion_interior_of_closed {T : set (set α)} {s : set α} (hs : is_Gδ s)
(hd : dense s) (hc : T.countable) (hc' : ∀ t ∈ T, is_closed t) (hU : s ⊆ ⋃₀ T) :
dense (⋃ t ∈ T, interior t) :=
hs.dense_bUnion_interior_of_closed hd hc hc' $ by rwa [← sUnion_eq_bUnion]
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is a countable set in any type. -/
theorem dense_bUnion_interior_of_closed {S : set β} {f : β → set α} (hc : ∀s∈S, is_closed (f s))
(hS : S.countable) (hU : (⋃s∈S, f s) = univ) : dense (⋃s∈S, interior (f s)) :=
is_Gδ_univ.dense_bUnion_interior_of_closed dense_univ hS hc hU.ge
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with `⋃₀`. -/
theorem dense_sUnion_interior_of_closed {S : set (set α)} (hc : ∀s∈S, is_closed s)
(hS : S.countable) (hU : (⋃₀ S) = univ) : dense (⋃s∈S, interior s) :=
is_Gδ_univ.dense_sUnion_interior_of_closed dense_univ hS hc hU.ge
/-- Baire theorem: if countably many closed sets cover the whole space, then their interiors
are dense. Formulated here with an index set which is an encodable type. -/
theorem dense_Union_interior_of_closed [encodable β] {f : β → set α} (hc : ∀s, is_closed (f s))
(hU : (⋃s, f s) = univ) : dense (⋃s, interior (f s)) :=
is_Gδ_univ.dense_Union_interior_of_closed dense_univ hc hU.ge
/-- One of the most useful consequences of Baire theorem: if a countable union of closed sets
covers the space, then one of the sets has nonempty interior. -/
theorem nonempty_interior_of_Union_of_closed [nonempty α] [encodable β] {f : β → set α}
(hc : ∀s, is_closed (f s)) (hU : (⋃s, f s) = univ) :
∃s, (interior $ f s).nonempty :=
by simpa using (dense_Union_interior_of_closed hc hU).nonempty
end Baire_theorem
|
cbcbfc6fb26f06856026ae1d85c62ccd0f81266e
|
d7189ea2ef694124821b033e533f18905b5e87ef
|
/galois/vector/default.lean
|
971039cf36e177b978b49c987f4a8a45f87e7246
|
[
"Apache-2.0"
] |
permissive
|
digama0/lean-protocol-support
|
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
|
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
|
refs/heads/master
| 1,625,421,450,627
| 1,506,035,462,000
| 1,506,035,462,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 753
|
lean
|
import .basic .simplify_eq .init_last .map_accum_lemmas .repeat_lemmas .rotate .tail_lemmas .zero_length_lemmas
universe variables u
namespace vector
variable {α : Type u}
section ind
open nat
parameter {α' : Type u}
variables {P : ∀ {n : ℕ}, vector α' n → Prop}
variables {n : ℕ} (v : vector α' n)
variables h₀ : P nil
variables hn : ∀ {n : ℕ} (x : α') (v : vector α' n), P v → P (x :: v)
include hn
lemma induction : ∀ {n : ℕ} (v : vector α' n), P v
| 0 ⟨[],P⟩ := h₀
| (succ n) ⟨x :: xs, P⟩ :=
begin
apply hn x ⟨xs,_⟩ (induction ⟨xs, _⟩),
have P' : succ (list.length xs) = succ n, { apply P },
injection P',
end
lemma induction_on : P v := induction h₀ @hn v
end ind
end vector
|
4ff2a4cd1f5bed2e09bdb96f36766a0d9e9d46d2
|
da23b545e1653cafd4ab88b3a42b9115a0b1355f
|
/src/tidy/its.lean
|
0c0b263a172e2a357e760f5aff063b467208de2f
|
[] |
no_license
|
minchaowu/lean-tidy
|
137f5058896e0e81dae84bf8d02b74101d21677a
|
2d4c52d66cf07c59f8746e405ba861b4fa0e3835
|
refs/heads/master
| 1,585,283,406,120
| 1,535,094,033,000
| 1,535,094,033,000
| 145,945,792
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 574
|
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 .transport
namespace tactic
meta def its { α : Type } (e : expr) (discharger : tactic α) : tactic α := (`[refine (transport %%e _)] <|> `[refine (cast _ %%e)]) >> discharger
end tactic
open tactic
open interactive
open interactive.types
namespace tactic.interactive
meta def its (q : parse texpr) : tactic unit := i_to_expr ``(%%q) >>= λ e, tactic.its e (skip)
end tactic.interactive
|
f06d2067026f4279ef814f9d5d87f1a71a122c2b
|
0851884047bb567d19e188e8f1ad959c5ae9c5ce
|
/src/M1P2/sheet-6.lean
|
c1610a8748826cb38209e3f9694c13b634f28b3e
|
[
"Apache-2.0"
] |
permissive
|
yz5216/xena-UROP-2018
|
00d3f71a831324966d40d302544ed2cbbec3fd0f
|
5e9da9dc64dc51897677f8b73ab9f94061a8d977
|
refs/heads/master
| 1,584,922,436,989
| 1,531,487,250,000
| 1,531,487,250,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 3,235
|
lean
|
import algebra.order data.fintype group_theory.subgroup data.set.basic data.equiv
variables {G : Type*} [group G]
variables (H K : set G)
variables [is_subgroup H] [is_subgroup K]
-- sheet 6
-- 1. Let G be a group. For each of the following statements, say whether or not it is true in general, and give a proof or a counterexample.
-- (a) If G is not cyclic then G is not abelian.
-- False (e.g : (ℝ,+))
-- -- (b) For every element g of G there is an abelian subgroup of G which contains g.
-- theorem sheet06_q1b:
-- -- (c) If G = ⟨g⟩ is an infinite cyclic group, then the only generators for G are g
-- -- and g−1.
-- theorem sheet06_q1c:
-- -- (d) If G is infinite then G has an element of infinite order.
-- theorem sheet06_q1d:
-- -- (e) If the order of every non-identity element of G is a prime number, then G is cyclic.
-- theorem sheet06_q1e:
-- (f) If G has order 4, then G is abelian.
--False. (e.g: Klein Four Group)
-- (g) If G is abelian then every subgroup of G is abelian.
theorem sheet06_q1g (G : Type*) [comm_group G] (H : set G) [is_subgroup H] : comm_group H := sorry
-- -- (h) If G is cyclic then every subgroup of G is cyclic.
-- theorem sheet06_q1h:
-- -- (i) If x, y ∈ G, then x and y−1xy have the same order.
-- theorem sheet06_q1i:
-- (j) If x,y ∈ G have order 2, then xy has order 2.
--theorem sheet06_q1j:
definition gsymmetric (n : ℕ) := equiv.perm (fin n)
-- -- *2. (a) Write down all of the cycle shapes of the elements of S5. For each cycle shape, calculate how many elements there are with that shape. (Check that your answers add up to |S5| = 120.)
-- theorem sheet06_q2a:
-- -- (b) How many elements of S5 have order 2?
-- theorem sheet06_q2b:
-- -- (c) How many subgroups of size 3 are there in the group S5?
-- theorem sheet06_q2c:
-- -- 3. (a) Let H1 be the cyclic subgroup ⟨(1234)⟩ of S4. Write down the right cosets of H in S4.
-- theorem sheet06_q2d:
-- -- (b) Find a subgroup H2 of S4 of order 4, in which all of the non-identity elements have the same cycle shape. Write down its right cosets in S4.
-- theorem sheet06_q2e:
-- -- (c) Which of the right cosets you have found for H1 and H2 are also left cosets?
-- theorem sheet06_q2f:
-- 4. Let G be a finite group of order n, and H a subgroup of G of order m.
-- -- (a) Forx,y∈G,showthatHx=Hy⇐⇒xy−1 ∈H.
-- theorem sheet06_q4a (x y : G) : x * l = x * l ↔ x * y⁻¹ ∈ H := sorry
-- -- (b) Suppose that r = n/m. Let x ∈ G. Show that there is an integer k in the range 1≤k≤r,suchthatxk ∈H.
-- theorem sheet06_q4b:
-- -- (c) Give an example to show that in (b), the integer k need not divide r.
-- theorem sheet06_q4c:
-- -- 5. Let G be a group,and let S be a subset of G.We say that S generates G if every element in G can be written as a product of elements of S and their inverses. (For example, if G is the cyclic group ⟨g⟩, then {g} generates G.)
-- theorem sheet06_q4d:
-- -- (a) Let 2≤k≤n. Show that a k-cycle(a1 ...,ak)in S n can be written as a product of k−1 distinct cycles of length 2. Deduce that the set of 2-cycles in Sn generates Sn.
-- theorem sheet06_q4e:
-- -- (b) Show that the group (Q, +) is not generated by any finite subset.
-- theorem sheet06_q4f:
|
4271957616fbbb184c69e98b85b9436c97474fe9
|
a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91
|
/tests/lean/run/817.lean
|
f658ce79951478cb1e649367edaa3a0c0523da9d
|
[
"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
| 254
|
lean
|
variables A B : Prop
premises (H₁ : A) (H₂ : A → B)
example : B :=
suffices A ∧ (A → B), from and.right this (and.left this),
and.intro H₁ H₂
example : B :=
suffices H : A ∧ (A → B), from and.right H (and.left H),
and.intro H₁ H₂
|
5e5424868352e93396d182ba82f985fcb6732913
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/cache.lean
|
2616b6dbcfacfabad7e1290e454f81f04fe72757
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,819
|
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 Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.tactic.doc_commands
import Mathlib.PostPort
namespace Mathlib
/-!
# Instance cache tactics
For performance reasons, Lean does not automatically update its database
of class instances during a proof. The group of tactics in this file
helps to force such updates.
-/
namespace tactic
/-- Reset the instance cache for the main goal. -/
/-- Unfreeze the local instances while executing `tac` on the main goal. -/
/--
Unfreeze local instances while executing `tac`,
if the passed expression is amongst the frozen instances.
-/
namespace interactive
/--
`unfreezingI { tac }` executes tac while temporarily unfreezing the instance cache.
-/
/-- Reset the instance cache. This allows any new instances
added to the context to be used in typeclass inference. -/
/-- Like `subst`, but can also substitute in instance arguments. -/
/-- Like `cases`, but can also be used with instance arguments. -/
/-- Like `intro`, but uses the introduced variable
in typeclass inference. -/
/-- Like `intros`, but uses the introduced variable(s)
in typeclass inference. -/
/-- Used to add typeclasses to the context so that they can
be used in typeclass inference. The syntax is the same as `have`,
but the proof-omitted version is not supported. For
this one must write `have : t, { <proof> }, resetI, <proof>`. -/
/-- Used to add typeclasses to the context so that they can
be used in typeclass inference. The syntax is the same as `let`. -/
/-- Like `exact`, but uses all variables in the context
for typeclass inference. -/
/--
For performance reasons, Lean does not automatically update its database
|
a2712e05580d5a218e50d4329950da86b63285ab
|
6432ea7a083ff6ba21ea17af9ee47b9c371760f7
|
/tests/lean/run/enumNoConfusionIssue.lean
|
5324dd263c5e5c029c6c921daf3f593598ba057a
|
[
"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
| 249
|
lean
|
inductive MyBool :=
| MyTrue
| MyFalse
inductive T :=
| mk (b: MyBool) (u: Unit)
inductive isTrue: T → Type :=
| intro: isTrue (.mk .MyTrue ())
example {τ: T} (h: isTrue τ): Unit :=
match τ, h with
| .mk .MyTrue (), .intro => ()
|
ebb261d754217cf47d8402e172025189e66fa8b4
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/data/finsupp/pointwise.lean
|
2daa18123b874af935745c3f4235a146e1a624e9
|
[
"Apache-2.0"
] |
permissive
|
urkud/mathlib
|
eab80095e1b9f1513bfb7f25b4fa82fa4fd02989
|
6379d39e6b5b279df9715f8011369a301b634e41
|
refs/heads/master
| 1,658,425,342,662
| 1,658,078,703,000
| 1,658,078,703,000
| 186,910,338
| 0
| 0
|
Apache-2.0
| 1,568,512,083,000
| 1,557,958,709,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 3,754
|
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 data.finsupp.basic
/-!
# The pointwise product on `finsupp`.
For the convolution product on `finsupp` when the domain has a binary operation,
see the type synonyms `add_monoid_algebra`
(which is in turn used to define `polynomial` and `mv_polynomial`)
and `monoid_algebra`.
-/
noncomputable theory
open finset
universes u₁ u₂ u₃ u₄ u₅
variables {α : Type u₁} {β : Type u₂} {γ : Type u₃} {δ : Type u₄} {ι : Type u₅}
namespace finsupp
/-! ### Declarations about the pointwise product on `finsupp`s -/
section
variables [mul_zero_class β]
/-- The product of `f g : α →₀ β` is the finitely supported function
whose value at `a` is `f a * g a`. -/
instance : has_mul (α →₀ β) := ⟨zip_with (*) (mul_zero 0)⟩
lemma coe_mul (g₁ g₂ : α →₀ β) : ⇑(g₁ * g₂) = g₁ * g₂ := rfl
@[simp] lemma mul_apply {g₁ g₂ : α →₀ β} {a : α} : (g₁ * g₂) a = g₁ a * g₂ a :=
rfl
lemma support_mul [decidable_eq α] {g₁ g₂ : α →₀ β} : (g₁ * g₂).support ⊆ g₁.support ∩ g₂.support :=
begin
intros a h,
simp only [mul_apply, mem_support_iff] at h,
simp only [mem_support_iff, mem_inter, ne.def],
rw ←not_or_distrib,
intro w,
apply h,
cases w; { rw w, simp },
end
instance : mul_zero_class (α →₀ β) :=
finsupp.coe_fn_injective.mul_zero_class _ coe_zero coe_mul
end
instance [semigroup_with_zero β] : semigroup_with_zero (α →₀ β) :=
finsupp.coe_fn_injective.semigroup_with_zero _ coe_zero coe_mul
instance [non_unital_non_assoc_semiring β] : non_unital_non_assoc_semiring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_non_assoc_semiring _ coe_zero coe_add coe_mul (λ _ _, rfl)
instance [non_unital_semiring β] : non_unital_semiring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_semiring _ coe_zero coe_add coe_mul (λ _ _, rfl)
instance [non_unital_comm_semiring β] : non_unital_comm_semiring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_comm_semiring _ coe_zero coe_add coe_mul (λ _ _, rfl)
instance [non_unital_non_assoc_ring β] : non_unital_non_assoc_ring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_non_assoc_ring _
coe_zero coe_add coe_mul coe_neg coe_sub (λ _ _, rfl) (λ _ _, rfl)
instance [non_unital_ring β] : non_unital_ring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_ring _
coe_zero coe_add coe_mul coe_neg coe_sub (λ _ _, rfl) (λ _ _, rfl)
instance [non_unital_comm_ring β] : non_unital_comm_ring (α →₀ β) :=
finsupp.coe_fn_injective.non_unital_comm_ring _
coe_zero coe_add coe_mul coe_neg coe_sub (λ _ _, rfl) (λ _ _, rfl)
-- TODO can this be generalized in the direction of `pi.has_smul'`
-- (i.e. dependent functions and finsupps)
-- TODO in theory this could be generalised, we only really need `smul_zero` for the definition
instance pointwise_scalar [semiring β] : has_smul (α → β) (α →₀ β) :=
{ smul := λ f g, finsupp.of_support_finite (λ a, f a • g a) begin
apply set.finite.subset g.finite_support,
simp only [function.support_subset_iff, finsupp.mem_support_iff, ne.def,
finsupp.fun_support_eq, finset.mem_coe],
intros x hx h,
apply hx,
rw [h, smul_zero],
end }
@[simp]
lemma coe_pointwise_smul [semiring β] (f : α → β) (g : α →₀ β) :
⇑(f • g) = f • g := rfl
/-- The pointwise multiplicative action of functions on finitely supported functions -/
instance pointwise_module [semiring β] : module (α → β) (α →₀ β) :=
function.injective.module _ coe_fn_add_hom coe_fn_injective coe_pointwise_smul
end finsupp
|
7b3e86cd1956ff0ae2b96523af83c87abbd8b7bf
|
0c2a1563358eee96560284575fc5cfbac6eddd09
|
/src/polyomino/basic.lean
|
73dfa67a4c3a3e22654d4b7f563baed5a4d05ee2
|
[] |
no_license
|
kendfrey/polyomino
|
2f51d691418cf71180b8a938af66de2281694162
|
a795101d85ee4d91aa33981381fbbcd10157dae7
|
refs/heads/master
| 1,670,925,213,201
| 1,598,668,120,000
| 1,598,668,120,000
| 291,185,915
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,632
|
lean
|
import tactic
import tactic.nth_rewrite
namespace polyomino
inductive adjacent : ℤ × ℤ → ℤ × ℤ → Prop
| up {x y} : adjacent ⟨x, y⟩ ⟨x, y + 1⟩
| down {x y} : adjacent ⟨x, y⟩ ⟨x, y - 1⟩
| right {x y} : adjacent ⟨x, y⟩ ⟨x + 1, y⟩
| left {x y} : adjacent ⟨x, y⟩ ⟨x - 1, y⟩
@[symm] theorem adjacent.symm {x y} : adjacent x y → adjacent y x :=
begin
intros adj_x_y,
cases adj_x_y with x y x y x y x y,
{
nth_rewrite 1 ← add_sub_cancel y 1,
apply adjacent.down,
},
{
nth_rewrite 1 ← sub_add_cancel y 1,
apply adjacent.up,
},
{
nth_rewrite 1 ← add_sub_cancel x 1,
apply adjacent.left,
},
{
nth_rewrite 1 ← sub_add_cancel x 1,
apply adjacent.right,
},
end
inductive connected : finset (ℤ × ℤ) → Prop
| empty : connected ∅
| singleton (x : ℤ × ℤ) : connected {x}
| insert (s x y) : y ∈ s → adjacent x y → connected s → connected (insert x s)
lemma connected.induction_on {p : finset (ℤ × ℤ) → Prop} {s} : connected s → p ∅ → (∀ x, p {x}) → (∀ x y s, x ∉ s → y ∈ s → adjacent x y → connected s → p (insert x s)) → p s :=
begin
intros conn_s p_empty p_singleton p_insert,
induction conn_s with _ s₁ a b b_mem_s _ _ ih,
{
apply p_empty,
},
{
apply p_singleton,
},
clear s,
rename s₁ s,
by_cases h : a ∈ s,
{
rw finset.insert_eq_of_mem h,
apply ih,
},
{
apply p_insert; assumption,
},
end
end polyomino
structure polyomino (n : ℕ) :=
(shape : finset (ℤ × ℤ))
(card : shape.card = n)
(conn : polyomino.connected shape)
|
6814d178a5986c9c1444a3c757f5bf850e9afa68
|
d7189ea2ef694124821b033e533f18905b5e87ef
|
/galois/temporal/fixpoint.lean
|
a9ca3959f7756617b882e0d9dff744ff3ee82e29
|
[
"Apache-2.0"
] |
permissive
|
digama0/lean-protocol-support
|
eaa7e6f8b8e0d5bbfff1f7f52bfb79a3b11b0f59
|
cabfa3abedbdd6fdca6e2da6fbbf91a13ed48dda
|
refs/heads/master
| 1,625,421,450,627
| 1,506,035,462,000
| 1,506,035,462,000
| null | 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 11,555
|
lean
|
import .temporal
.first
import galois.subset.fixpoint
open subset
namespace temporal
universes u v
def always_fixpoint {T : Type u} (P : tProp T) (X : tProp T) := P ∩ ◯ X
def until_fixpoint {T : Type u} (P Q : tProp T) (X : tProp T) :=
Q ∪ (P ∩ ◯ X)
lemma always_fixpoint_mono {T : Type u} (P : tProp T) :
monotone (always_fixpoint P)
:= begin
unfold monotone, intros X Y H,
unfold always_fixpoint, apply bintersection_mono,
apply included_refl, apply next_mono, assumption
end
lemma nextn_continuous {T : Type u} (n : ℕ)
: continuous (@nextn T n)
:= begin
unfold continuous, intros Ix f,
apply included_eq,
{ intros x H, intros ix,
dsimp [function.comp], apply H, },
{ intros x H,
unfold nextn, intros ix, apply H, }
end
lemma next_continuous {T : Type u}
: continuous (@next T) := nextn_continuous 1
lemma always_fixpoint_continuous {T : Type u} (P : tProp T)
: continuous_inh (always_fixpoint P)
:= begin
unfold continuous_inh, intros Ix inh f,
unfold always_fixpoint,
rw next_continuous,
unfold has_inter.inter, rw and_continuous_r,
reflexivity,
end
lemma until_fixpoint_mono {T : Type u} (P Q : tProp T) :
monotone (until_fixpoint P Q)
:= begin
unfold monotone, intros X Y H,
unfold until_fixpoint, apply bunion_mono,
apply included_refl, apply bintersection_mono,
apply included_refl, apply next_mono, assumption
end
lemma until_fixpoint_continuous {T : Type u} (P Q : tProp T)
[decidable_pred Q]
: continuous_inh (until_fixpoint P Q)
:= begin
unfold continuous_inh, intros Ix inh f,
unfold until_fixpoint,
rw next_continuous,
unfold has_inter.inter, rw and_continuous_r,
unfold has_union.union,
rw or_continuous_r,
reflexivity,
end
lemma nextn_cocontinuous {T : Type u} (n : ℕ)
: cocontinuous (@nextn T n)
:= begin
unfold cocontinuous, intros Ix f,
apply included_eq,
{ intros x H, induction H, constructor; assumption },
{ intros x H, induction H, constructor; assumption }
end
lemma next_cocontinuous {T : Type u}
: cocontinuous (@next T)
:= nextn_cocontinuous 1
lemma until_fixpoint_cocontinuous_l {T : Type u}
{Ix : Type} [inhabited Ix] (P : Ix → tProp T)
(Q : tProp T)
: until_fixpoint (union_ix P) Q
= λ x, union_ix (λ ix, until_fixpoint (P ix) Q x)
:= begin
apply funext, intros X,
unfold until_fixpoint,
rw inter_comm,
unfold has_inter.inter,
rw and_cocontinuous_r,
unfold has_union.union,
rw or_cocontinuous_r,
dsimp [function.comp],
f_equal, apply funext, intros ix,
f_equal, apply inter_comm,
end
def weak_until {T : Type u} (P Q : tProp T) : tProp T :=
greatest_fixpointn (until_fixpoint P Q)
-- \MCW
infix `𝓦` : 50 := weak_until
@[trace_map]
lemma weak_until_map {A : Type v} {T : Type u} (P Q : tProp T)
(f : A → T)
: (P 𝓦 Q) ∘ trace.map f = ((P ∘ trace.map f) 𝓦 (Q ∘ trace.map f))
:= begin
unfold weak_until,
unfold greatest_fixpointn, rw intersection_ix_precompose,
f_equal, apply funext, intros n,
induction n; simp [iterate],
reflexivity, rw ← ih_1, unfold until_fixpoint,
rw or_precompose,
rw and_precompose, rw next_map,
end
@[ltl]
def release {T : Type u} (P Q : tProp T) : tProp T :=
Q 𝓦 (Q ∩ P)
-- \MCR
infix `𝓡` : 50 := release
lemma always_fixpoint_fixes {T : Type u} (P : tProp T)
: always_fixpoint P (□ P) = □ P
:= begin
unfold always_fixpoint, symmetry, apply always_and_next
end
lemma always_greatest_fixpoint {T : Type u} (P : tProp T)
: □ P = greatest_fixpoint (always_fixpoint P)
:= begin
apply included_eq,
{ intros x H, apply (union_st.mk (□ P)),
unfold always_fixpoint,
rw ← always_and_next, apply (included_refl _),
assumption },
{ apply (greatest_fixpoint_le _ _),
apply always_fixpoint_mono,
intros x H,
unfold always_fixpoint at H,
intros tr xtr,
have Hx : □ x tr,
{ apply temporal_induction, assumption,
intros n IH, rw H at IH, induction IH with H1 H2,
assumption
},
{ rw H at Hx,
rw ← always_and at Hx,
induction Hx with H1 H2, assumption,
}
}
end
lemma always_greatest_fixpointn {T : Type u} (P : tProp T)
: □ P = greatest_fixpointn (always_fixpoint P)
:= begin
rw always_greatest_fixpoint, symmetry,
apply greatest_fixpointn_same,
apply continuous_chain_cocont, apply always_fixpoint_continuous,
end
lemma curry {T : Type u} {P Q R : tProp T}
(H : ⊩ P ∩ Q => R)
: ⊩ P => Q => R
:= begin
intros tr HP HQ, apply H, constructor; assumption
end
lemma weak_until_unfold {T : Type u} (P Q : tProp T)
[decidable_pred Q]
: P 𝓦 Q = (Q ∪ (P ∩ ◯ (P 𝓦 Q)))
:= begin
have H : P 𝓦 Q = until_fixpoint P Q (P 𝓦 Q),
unfold weak_until,
symmetry, apply greatest_fixpointn_fixed,
apply continuous_chain_cocont,
apply until_fixpoint_continuous,
apply H
end
lemma weak_until_not_always_lemma
{T : Type u} (P Q : tProp T) (n : ℕ)
: ⊩ □ (tNot Q)
=> iterate (until_fixpoint P Q) tt n
=> iterate (always_fixpoint P) tt n
:= begin
induction n; intros tr notQ H; simp [iterate],
simp [iterate] at H,
unfold until_fixpoint at H,
unfold always_fixpoint,
induction H with H H,
specialize (notQ 0),
rw delayn_zero at notQ, contradiction,
induction H with Hl Hr,
constructor, assumption,
unfold next nextn, apply ih_1,
intros n, rw delayn_combine, apply notQ,
apply next_delay, rw delayn_zero, assumption
end
lemma weak_until_not_always {T : Type u} (P Q : tProp T)
: ⊩ P 𝓦 Q => □ (tNot Q) => □ P
:= begin
intros tr PWQ notQ,
rw always_greatest_fixpointn,
intros n, apply weak_until_not_always_lemma, assumption,
apply PWQ,
end
lemma weak_until_always_mono {T : Type u} (A B P : tProp T)
: ⊩ □ (A => B) => A 𝓦 P => B 𝓦 P
:= begin
intros tr H AWP n,
specialize (AWP n), revert tr,
induction n,
case nat.zero { simp [iterate], },
case nat.succ a ih_1 {
simp [iterate],
intros tr AB H,
unfold until_fixpoint, unfold until_fixpoint at H,
induction H with H H, apply or.inl, assumption,
apply or.inr, induction H with Hl Hr,
constructor, rw ← (delayn_zero tr), apply AB,
rw delayn_zero, assumption,
unfold next nextn, apply ih_1,
intros n, rw delayn_combine, apply AB,
apply Hr
},
end
lemma weak_until_mono {T : Type u} {A B P : tProp T}
(AB : A ≤ B)
: (A 𝓦 P) ≤ (B 𝓦 P)
:= begin
intros tr AP, apply weak_until_always_mono,
intros n, apply AB, assumption
end
lemma not_weakuntil_yes {T : Type u}
(P : tProp T) [decP : decidable_pred P]
: ⊩ tNot P 𝓦 P
:= begin
intros tr n, revert tr, induction n; simp [iterate]; intros tr,
trivial,
have H := decP tr, induction H with H H,
{ apply or.inr,
constructor, apply H,
apply ih_1 },
{ apply or.inl, assumption }
end
lemma always_weak_until {T : Type u} (P Q : tProp T) [decidable_pred Q] :
⊩ □ (P ∪ Q) => P 𝓦 Q
:= begin
rw always_greatest_fixpointn,
apply greatest_fixpointn_mono,
apply chain_cocont_mono,
apply continuous_chain_cocont,
apply always_fixpoint_continuous,
unfold always_fixpoint until_fixpoint,
intros X tr H, induction H with Hl Hr,
induction Hl with Hl Hl,
{ apply or.inr,
constructor; assumption },
{ apply or.inl, assumption }
end
/-- An anologue of `temporal_induction`. If we can prove
`P` holds now, and if, assuming `Q` doesn't hold,
`P` implies `◯ P`, then `◯ P` holds weak-until `Q`.
-/
lemma weak_until_induction {T : Type u} (P Q : tProp T)
[decQ : decidable_pred Q]
: ⊩ (P => □ (tNot Q => P => (◯ P)) => ◯ P 𝓦 Q) :=
begin
intros tr H0 HS n,
revert tr, induction n; simp [iterate]; intros tr H0 HS,
trivial,
unfold until_fixpoint,
have H := decQ tr, induction H with HQ HQ,
{ apply or.inr, constructor, specialize (HS 0),
rw delayn_zero at HS, specialize (HS HQ H0), assumption,
unfold next nextn, apply ih_1,
specialize (HS 0 HQ H0), assumption,
intros n, rw delayn_combine, apply HS },
{ apply or.inl, assumption }
end
lemma eventually_strengthen_until {T : Type u}
{P Q : tProp T}
[decidable_pred Q]
: ⊩ ◇ Q => (P 𝓦 Q) => (P 𝓤 Q)
:= begin
intros tr evQ PWQ,
have H := eventually_first_dec _ _ evQ,
clear evQ,
unfold first at H,
induction H with k Hk, induction Hk with Hkl Hkr,
constructor, split, assumption, clear Hkl,
revert tr,
induction k; intros,
{ exfalso, apply nat.not_lt_zero, assumption, },
{
cases n' with n' n',
specialize (Hkr _ a_1),
specialize (PWQ 1),
simp [iterate] at PWQ,
unfold until_fixpoint at PWQ,
induction PWQ with H H,
exfalso, apply Hkr, assumption,
induction H with Hl Hr,
rw delayn_zero, assumption,
rw ← (@delayn_combine _ 1 n'),
apply ih_1, rw weak_until_unfold at PWQ,
induction PWQ with H H,
exfalso, apply Hkr, tactic.swap,
rw delayn_zero, assumption,
apply nat.zero_lt_succ,
induction H with Hl Hr,
assumption,
intros,
rw delayn_combine, apply Hkr,
rw nat.succ_lt_succ_iff, assumption,
rw ← nat.succ_lt_succ_iff, assumption,
}
end
lemma fair_strengthen_until {T : Type u}
(P Q : tProp T) [decidable_pred Q] :
⊩ □ (P 𝓦 Q)
=> □ (◇ Q)
=> □ (P 𝓤 Q)
:= begin
intros tr PQ fairQ n,
apply eventually_strengthen_until; apply PQ <|> apply fairQ,
end
lemma weak_until_implies_release {T : Type u} {P Q : tProp T}
: ⊩ P => (◯ P 𝓦 Q) => Q 𝓡 P
:= begin
intros tr HP HPimpQ n,
specialize (HPimpQ n), revert tr,
induction n; simp [iterate]; intros tr H0 HS,
unfold until_fixpoint, unfold until_fixpoint at HS,
induction HS with HS HS,
{ apply or.inl, constructor; assumption },
{ apply or.inr, induction HS with HSl HSr,
constructor, assumption,
unfold next nextn, apply ih_1, assumption,
apply HSr }
end
lemma release_induction {T : Type u} (P Q : tProp T)
[decQ : decidable_pred Q]
: ⊩ (P => □ (tNot Q => P => (◯ P)) => Q 𝓡 P)
:= begin
intros tr H0 HS,
apply weak_until_implies_release, assumption,
apply weak_until_induction; assumption
end
lemma next_weak_until_always_loop_lemma {T : Type u}
(P Q : tProp T)
: ⊩ □ (P=>◯ P𝓦Q) => □ (P ∩ Q=>◯ P) => □ (P=>◯ P)
:= begin
intros tr PuntilQ QimpP n HP,
specialize (PuntilQ n HP),
specialize (PuntilQ 1), simp [iterate] at PuntilQ,
unfold until_fixpoint at PuntilQ,
induction PuntilQ with H H, apply QimpP, split; assumption,
induction H with H H, assumption,
end
lemma next_weak_until_always_loop {T : Type u}
(P Q : tProp T)
: ⊩ P => □ (P => ◯ P 𝓦 Q) => □ (Q => ◯ P) => □ P
:= begin
intros tr HP PuntilQ QimpP,
apply temporal_induction, assumption,
clear HP,
apply next_weak_until_always_loop_lemma; try { assumption },
intros n Hn, induction Hn with HP HQ, apply QimpP, assumption,
end
lemma next_weak_until_always_loop' {T : Type u}
(P Q : tProp T)
: ⊩ P => □ (P => ◯ P 𝓦 Q) => □ (P ∩ Q => ◯ P) => □ P
:= begin
intros tr HP PuntilQ QimpP,
apply temporal_induction, assumption,
clear HP,
apply next_weak_until_always_loop_lemma; assumption
end
lemma next_weak_until_combine {T : Type u}
(P Q : tProp T) [decidable_pred Q]
: ⊩ ◇ P => □ (P => ◯ P 𝓦 Q) => fair Q => ◇ (P ∩ Q)
:= begin
intros tr evP PuntilQ evQ,
apply eventually_cut, apply evP,
intros n Pnow,
specialize (evQ n),
specialize (PuntilQ n Pnow),
have H := eventually_strengthen_until _ evQ PuntilQ,
apply now_until_eventually, assumption, assumption,
end
lemma now_continuous {T : Type u}
: continuous (@now T)
:= begin
unfold continuous now later intersection_ix,
dsimp [function.comp], intros,
apply funext, intros tr, unfold now later,
end
lemma now_cocontinuous {T : Type u}
: cocontinuous (@now T)
:= begin
unfold cocontinuous now later intersection_ix,
dsimp [function.comp], intros,
apply funext, intros tr, unfold now later,
apply propext, split; intros H; induction H;
constructor; assumption,
end
end temporal
|
09e5c0419605a9911e720dbee20c1c59a997f2fa
|
94e33a31faa76775069b071adea97e86e218a8ee
|
/src/category_theory/abelian/basic.lean
|
f720095bfa1e22b7508ee6f0f273add14ebd1183
|
[
"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
| 30,092
|
lean
|
/-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel, Johan Commelin, Scott Morrison
-/
import category_theory.limits.constructions.pullbacks
import category_theory.limits.shapes.biproducts
import category_theory.limits.shapes.images
import category_theory.limits.constructions.limits_of_products_and_equalizers
import category_theory.limits.constructions.epi_mono
import category_theory.abelian.non_preadditive
/-!
# Abelian categories
This file contains the definition and basic properties of abelian categories.
There are many definitions of abelian category. Our definition is as follows:
A category is called abelian if it is preadditive,
has a finite products, kernels and cokernels,
and if every monomorphism and epimorphism is normal.
It should be noted that if we also assume coproducts, then preadditivity is
actually a consequence of the other properties, as we show in
`non_preadditive_abelian.lean`. However, this fact is of little practical
relevance, since essentially all interesting abelian categories come with a
preadditive structure. In this way, by requiring preadditivity, we allow the
user to pass in the "native" preadditive structure for the specific category they are
working with.
## Main definitions
* `abelian` is the type class indicating that a category is abelian. It extends `preadditive`.
* `abelian.image f` is `kernel (cokernel.π f)`, and
* `abelian.coimage f` is `cokernel (kernel.ι f)`.
## Main results
* In an abelian category, mono + epi = iso.
* If `f : X ⟶ Y`, then the map `factor_thru_image f : X ⟶ image f` is an epimorphism, and the map
`factor_thru_coimage f : coimage f ⟶ Y` is a monomorphism.
* Factoring through the image and coimage is a strong epi-mono factorisation. This means that
* every abelian category has images. We provide the isomorphism
`image_iso_image : abelian.image f ≅ limits.image f`.
* the canonical morphism `coimage_image_comparison : coimage f ⟶ image f`
is an isomorphism.
* We provide the alternate characterisation of an abelian category as a category with
(co)kernels and finite products, and in which the canonical coimage-image comparison morphism
is always an isomorphism.
* Every epimorphism is a cokernel of its kernel. Every monomorphism is a kernel of its cokernel.
* The pullback of an epimorphism is an epimorphism. The pushout of a monomorphism is a monomorphism.
(This is not to be confused with the fact that the pullback of a monomorphism is a monomorphism,
which is true in any category).
## Implementation notes
The typeclass `abelian` does not extend `non_preadditive_abelian`,
to avoid having to deal with comparing the two `has_zero_morphisms` instances
(one from `preadditive` in `abelian`, and the other a field of `non_preadditive_abelian`).
As a consequence, at the beginning of this file we trivially build
a `non_preadditive_abelian` instance from an `abelian` instance,
and use this to restate a number of theorems,
in each case just reusing the proof from `non_preadditive_abelian.lean`.
We don't show this yet, but abelian categories are finitely complete and finitely cocomplete.
However, the limits we can construct at this level of generality will most likely be less nice than
the ones that can be created in specific applications. For this reason, we adopt the following
convention:
* If the statement of a theorem involves limits, the existence of these limits should be made an
explicit typeclass parameter.
* If a limit only appears in a proof, but not in the statement of a theorem, the limit should not
be a typeclass parameter, but instead be created using `abelian.has_pullbacks` or a similar
definition.
## References
* [F. Borceux, *Handbook of Categorical Algebra 2*][borceux-vol2]
* [P. Aluffi, *Algebra: Chapter 0*][aluffi2016]
-/
noncomputable theory
open category_theory
open category_theory.preadditive
open category_theory.limits
universes v u
namespace category_theory
variables {C : Type u} [category.{v} C]
variables (C)
/--
A (preadditive) category `C` is called abelian if it has all finite products,
all kernels and cokernels, and if every monomorphism is the kernel of some morphism
and every epimorphism is the cokernel of some morphism.
(This definition implies the existence of zero objects:
finite products give a terminal object, and in a preadditive category
any terminal object is a zero object.)
-/
class abelian extends preadditive C, normal_mono_category C, normal_epi_category C :=
[has_finite_products : has_finite_products C]
[has_kernels : has_kernels C]
[has_cokernels : has_cokernels C]
attribute [instance, priority 100] abelian.has_finite_products
attribute [instance, priority 100] abelian.has_kernels abelian.has_cokernels
end category_theory
open category_theory
/-!
We begin by providing an alternative constructor:
a preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category.
-/
namespace category_theory.abelian
variables {C : Type u} [category.{v} C] [preadditive C]
variables [limits.has_kernels C] [limits.has_cokernels C]
namespace of_coimage_image_comparison_is_iso
/-- The factorisation of a morphism through its abelian image. -/
@[simps]
def image_mono_factorisation {X Y : C} (f : X ⟶ Y) : mono_factorisation f :=
{ I := abelian.image f,
m := kernel.ι _,
m_mono := infer_instance,
e := kernel.lift _ f (cokernel.condition _),
fac' := kernel.lift_ι _ _ _ }
lemma image_mono_factorisation_e' {X Y : C} (f : X ⟶ Y) :
(image_mono_factorisation f).e = cokernel.π _ ≫ abelian.coimage_image_comparison f :=
begin
ext,
simp only [abelian.coimage_image_comparison, image_mono_factorisation_e,
category.assoc, cokernel.π_desc_assoc],
end
/-- If the coimage-image comparison morphism for a morphism `f` is an isomorphism,
we obtain an image factorisation of `f`. -/
def image_factorisation {X Y : C} (f : X ⟶ Y) [is_iso (abelian.coimage_image_comparison f)] :
image_factorisation f :=
{ F := image_mono_factorisation f,
is_image :=
{ lift := λ F, inv (abelian.coimage_image_comparison f) ≫ cokernel.desc _ F.e F.kernel_ι_comp,
lift_fac' := λ F, begin
simp only [image_mono_factorisation_m, is_iso.inv_comp_eq, category.assoc,
abelian.coimage_image_comparison],
ext,
rw [limits.coequalizer.π_desc_assoc, limits.coequalizer.π_desc_assoc, F.fac, kernel.lift_ι]
end } }
instance [has_zero_object C] {X Y : C} (f : X ⟶ Y) [mono f]
[is_iso (abelian.coimage_image_comparison f)] :
is_iso (image_mono_factorisation f).e :=
by { rw image_mono_factorisation_e', exact is_iso.comp_is_iso }
instance [has_zero_object C] {X Y : C} (f : X ⟶ Y) [epi f] :
is_iso (image_mono_factorisation f).m :=
by { dsimp, apply_instance }
variables [∀ {X Y : C} (f : X ⟶ Y), is_iso (abelian.coimage_image_comparison f)]
/-- A category in which coimage-image comparisons are all isomorphisms has images. -/
lemma has_images : has_images C :=
{ has_image := λ X Y f,
{ exists_image := ⟨image_factorisation f⟩ } }
variables [limits.has_finite_products C]
local attribute [instance] limits.has_finite_biproducts.of_has_finite_products
/--
A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal mono category.
-/
def normal_mono_category : normal_mono_category C :=
{ normal_mono_of_mono := λ X Y f m,
{ Z := _,
g := cokernel.π f,
w := by simp,
is_limit := begin
haveI : limits.has_images C := has_images,
haveI : has_equalizers C := preadditive.has_equalizers_of_has_kernels,
haveI : has_zero_object C := limits.has_zero_object_of_has_finite_biproducts _,
have aux : _ := _,
refine is_limit_aux _ (λ A, limit.lift _ _ ≫ inv (image_mono_factorisation f).e) aux _,
{ intros A g hg,
rw [kernel_fork.ι_of_ι] at hg,
rw [← cancel_mono f, hg, ← aux, kernel_fork.ι_of_ι], },
{ intro A,
simp only [kernel_fork.ι_of_ι, category.assoc],
convert limit.lift_π _ _ using 2,
rw [is_iso.inv_comp_eq, eq_comm],
exact (image_mono_factorisation f).fac, },
end }, }
/--
A category with finite products in which coimage-image comparisons are all isomorphisms
is a normal epi category.
-/
def normal_epi_category : normal_epi_category C :=
{ normal_epi_of_epi := λ X Y f m,
{ W := kernel f,
g := kernel.ι _,
w := kernel.condition _,
is_colimit := begin
haveI : limits.has_images C := has_images,
haveI : has_equalizers C := preadditive.has_equalizers_of_has_kernels,
haveI : has_zero_object C := limits.has_zero_object_of_has_finite_biproducts _,
have aux : _ := _,
refine is_colimit_aux _
(λ A, inv (image_mono_factorisation f).m ≫
inv (abelian.coimage_image_comparison f) ≫ colimit.desc _ _)
aux _,
{ intros A g hg,
rw [cokernel_cofork.π_of_π] at hg,
rw [← cancel_epi f, hg, ← aux, cokernel_cofork.π_of_π], },
{ intro A,
simp only [cokernel_cofork.π_of_π, ← category.assoc],
convert colimit.ι_desc _ _ using 2,
rw [is_iso.comp_inv_eq, is_iso.comp_inv_eq, eq_comm, ←image_mono_factorisation_e'],
exact (image_mono_factorisation f).fac, }
end }, }
end of_coimage_image_comparison_is_iso
variables [∀ {X Y : C} (f : X ⟶ Y), is_iso (abelian.coimage_image_comparison f)]
[limits.has_finite_products C]
local attribute [instance] of_coimage_image_comparison_is_iso.normal_mono_category
local attribute [instance] of_coimage_image_comparison_is_iso.normal_epi_category
/--
A preadditive category with kernels, cokernels, and finite products,
in which the coimage-image comparison morphism is always an isomorphism,
is an abelian category.
The Stacks project uses this characterisation at the definition of an abelian category.
See <https://stacks.math.columbia.edu/tag/0109>.
-/
def of_coimage_image_comparison_is_iso : abelian C := {}
end category_theory.abelian
namespace category_theory.abelian
variables {C : Type u} [category.{v} C] [abelian C]
/-- An abelian category has finite biproducts. -/
@[priority 100]
instance has_finite_biproducts : has_finite_biproducts C :=
limits.has_finite_biproducts.of_has_finite_products
@[priority 100]
instance has_binary_biproducts : has_binary_biproducts C :=
limits.has_binary_biproducts_of_finite_biproducts _
@[priority 100]
instance has_zero_object : has_zero_object C :=
has_zero_object_of_has_initial_object
section to_non_preadditive_abelian
/-- Every abelian category is, in particular, `non_preadditive_abelian`. -/
def non_preadditive_abelian : non_preadditive_abelian C := { ..‹abelian C› }
end to_non_preadditive_abelian
section
/-! We now promote some instances that were constructed using `non_preadditive_abelian`. -/
local attribute [instance] non_preadditive_abelian
variables {P Q : C} (f : P ⟶ Q)
/-- The map `p : P ⟶ image f` is an epimorphism -/
instance : epi (abelian.factor_thru_image f) := by apply_instance
instance is_iso_factor_thru_image [mono f] : is_iso (abelian.factor_thru_image f) :=
by apply_instance
/-- The canonical morphism `i : coimage f ⟶ Q` is a monomorphism -/
instance : mono (abelian.factor_thru_coimage f) := by apply_instance
instance is_iso_factor_thru_coimage [epi f] : is_iso (abelian.factor_thru_coimage f) :=
by apply_instance
end
section factor
local attribute [instance] non_preadditive_abelian
variables {P Q : C} (f : P ⟶ Q)
section
lemma mono_of_kernel_ι_eq_zero (h : kernel.ι f = 0) : mono f :=
mono_of_kernel_zero h
lemma epi_of_cokernel_π_eq_zero (h : cokernel.π f = 0) : epi f :=
begin
apply normal_mono_category.epi_of_zero_cokernel _ (cokernel f),
simp_rw ←h,
exact is_colimit.of_iso_colimit (colimit.is_colimit (parallel_pair f 0)) (iso_of_π _)
end
end
section
variables {f}
lemma image_ι_comp_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : abelian.image.ι f ≫ g = 0 :=
zero_of_epi_comp (abelian.factor_thru_image f) $ by simp [h]
lemma comp_coimage_π_eq_zero {R : C} {g : Q ⟶ R} (h : f ≫ g = 0) : f ≫ abelian.coimage.π g = 0 :=
zero_of_comp_mono (abelian.factor_thru_coimage g) $ by simp [h]
end
/-- Factoring through the image is a strong epi-mono factorisation. -/
@[simps] def image_strong_epi_mono_factorisation : strong_epi_mono_factorisation f :=
{ I := abelian.image f,
m := image.ι f,
m_mono := by apply_instance,
e := abelian.factor_thru_image f,
e_strong_epi := strong_epi_of_epi _ }
/-- Factoring through the coimage is a strong epi-mono factorisation. -/
@[simps] def coimage_strong_epi_mono_factorisation : strong_epi_mono_factorisation f :=
{ I := abelian.coimage f,
m := abelian.factor_thru_coimage f,
m_mono := by apply_instance,
e := coimage.π f,
e_strong_epi := strong_epi_of_epi _ }
end factor
section has_strong_epi_mono_factorisations
/-- An abelian category has strong epi-mono factorisations. -/
@[priority 100] instance : has_strong_epi_mono_factorisations C :=
has_strong_epi_mono_factorisations.mk $ λ X Y f, image_strong_epi_mono_factorisation f
/- In particular, this means that it has well-behaved images. -/
example : has_images C := by apply_instance
example : has_image_maps C := by apply_instance
end has_strong_epi_mono_factorisations
section images
variables {X Y : C} (f : X ⟶ Y)
/--
The coimage-image comparison morphism is always an isomorphism in an abelian category.
See `category_theory.abelian.of_coimage_image_comparison_is_iso` for the converse.
-/
instance : is_iso (coimage_image_comparison f) :=
begin
convert is_iso.of_iso (is_image.iso_ext (coimage_strong_epi_mono_factorisation f).to_mono_is_image
(image_strong_epi_mono_factorisation f).to_mono_is_image),
ext,
change _ = _ ≫ (image_strong_epi_mono_factorisation f).m,
simp [-image_strong_epi_mono_factorisation_to_mono_factorisation_m]
end
/-- There is a canonical isomorphism between the abelian coimage and the abelian image of a
morphism. -/
abbreviation coimage_iso_image : abelian.coimage f ≅ abelian.image f :=
as_iso (coimage_image_comparison f)
/-- There is a canonical isomorphism between the abelian coimage and the categorical image of a
morphism. -/
abbreviation coimage_iso_image' : abelian.coimage f ≅ image f :=
is_image.iso_ext (coimage_strong_epi_mono_factorisation f).to_mono_is_image
(image.is_image f)
/-- There is a canonical isomorphism between the abelian image and the categorical image of a
morphism. -/
abbreviation image_iso_image : abelian.image f ≅ image f :=
is_image.iso_ext (image_strong_epi_mono_factorisation f).to_mono_is_image (image.is_image f)
end images
section cokernel_of_kernel
variables {X Y : C} {f : X ⟶ Y}
local attribute [instance] non_preadditive_abelian
/-- In an abelian category, an epi is the cokernel of its kernel. More precisely:
If `f` is an epimorphism and `s` is some limit kernel cone on `f`, then `f` is a cokernel
of `fork.ι s`. -/
def epi_is_cokernel_of_kernel [epi f] (s : fork f 0) (h : is_limit s) :
is_colimit (cokernel_cofork.of_π f (kernel_fork.condition s)) :=
non_preadditive_abelian.epi_is_cokernel_of_kernel s h
/-- In an abelian category, a mono is the kernel of its cokernel. More precisely:
If `f` is a monomorphism and `s` is some colimit cokernel cocone on `f`, then `f` is a kernel
of `cofork.π s`. -/
def mono_is_kernel_of_cokernel [mono f] (s : cofork f 0) (h : is_colimit s) :
is_limit (kernel_fork.of_ι f (cokernel_cofork.condition s)) :=
non_preadditive_abelian.mono_is_kernel_of_cokernel s h
variables (f)
/-- In an abelian category, any morphism that turns to zero when precomposed with the kernel of an
epimorphism factors through that epimorphism. -/
def epi_desc [epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) : Y ⟶ T :=
(epi_is_cokernel_of_kernel _ (limit.is_limit _)).desc (cokernel_cofork.of_π _ hg)
@[simp, reassoc]
lemma comp_epi_desc [epi f] {T : C} (g : X ⟶ T) (hg : kernel.ι f ≫ g = 0) :
f ≫ epi_desc f g hg = g :=
(epi_is_cokernel_of_kernel _ (limit.is_limit _)).fac (cokernel_cofork.of_π _ hg)
walking_parallel_pair.one
/-- In an abelian category, any morphism that turns to zero when postcomposed with the cokernel of a
monomorphism factors through that monomorphism. -/
def mono_lift [mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) : T ⟶ X :=
(mono_is_kernel_of_cokernel _ (colimit.is_colimit _)).lift (kernel_fork.of_ι _ hg)
@[simp, reassoc]
lemma mono_lift_comp [mono f] {T : C} (g : T ⟶ Y) (hg : g ≫ cokernel.π f = 0) :
mono_lift f g hg ≫ f = g :=
(mono_is_kernel_of_cokernel _ (colimit.is_colimit _)).fac (kernel_fork.of_ι _ hg)
walking_parallel_pair.zero
end cokernel_of_kernel
section
@[priority 100]
instance has_equalizers : has_equalizers C :=
preadditive.has_equalizers_of_has_kernels
/-- Any abelian category has pullbacks -/
@[priority 100]
instance has_pullbacks : has_pullbacks C :=
has_pullbacks_of_has_binary_products_of_has_equalizers C
end
section
@[priority 100]
instance has_coequalizers : has_coequalizers C :=
preadditive.has_coequalizers_of_has_cokernels
/-- Any abelian category has pushouts -/
@[priority 100]
instance has_pushouts : has_pushouts C :=
has_pushouts_of_has_binary_coproducts_of_has_coequalizers C
@[priority 100]
instance has_finite_limits : has_finite_limits C :=
limits.finite_limits_from_equalizers_and_finite_products
@[priority 100]
instance has_finite_colimits : has_finite_colimits C :=
limits.finite_colimits_from_coequalizers_and_finite_coproducts
end
namespace pullback_to_biproduct_is_kernel
variables [limits.has_pullbacks C] {X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-! This section contains a slightly technical result about pullbacks and biproducts.
We will need it in the proof that the pullback of an epimorphism is an epimorpism. -/
/-- The canonical map `pullback f g ⟶ X ⊞ Y` -/
abbreviation pullback_to_biproduct : pullback f g ⟶ X ⊞ Y :=
biprod.lift pullback.fst pullback.snd
/-- The canonical map `pullback f g ⟶ X ⊞ Y` induces a kernel cone on the map
`biproduct X Y ⟶ Z` induced by `f` and `g`. A slightly more intuitive way to think of
this may be that it induces an equalizer fork on the maps induced by `(f, 0)` and
`(0, g)`. -/
abbreviation pullback_to_biproduct_fork : kernel_fork (biprod.desc f (-g)) :=
kernel_fork.of_ι (pullback_to_biproduct f g) $
by rw [biprod.lift_desc, comp_neg, pullback.condition, add_right_neg]
/-- The canonical map `pullback f g ⟶ X ⊞ Y` is a kernel of the map induced by
`(f, -g)`. -/
def is_limit_pullback_to_biproduct : is_limit (pullback_to_biproduct_fork f g) :=
fork.is_limit.mk _
(λ s, pullback.lift (fork.ι s ≫ biprod.fst) (fork.ι s ≫ biprod.snd) $
sub_eq_zero.1 $ by rw [category.assoc, category.assoc, ←comp_sub, sub_eq_add_neg, ←comp_neg,
←biprod.desc_eq, kernel_fork.condition s])
(λ s,
begin
ext; rw [fork.ι_of_ι, category.assoc],
{ rw [biprod.lift_fst, pullback.lift_fst] },
{ rw [biprod.lift_snd, pullback.lift_snd] }
end)
(λ s m h, by ext; simp [←h])
end pullback_to_biproduct_is_kernel
namespace biproduct_to_pushout_is_cokernel
variables [limits.has_pushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` -/
abbreviation biproduct_to_pushout : Y ⊞ Z ⟶ pushout f g :=
biprod.desc pushout.inl pushout.inr
/-- The canonical map `Y ⊞ Z ⟶ pushout f g` induces a cokernel cofork on the map
`X ⟶ Y ⊞ Z` induced by `f` and `-g`. -/
abbreviation biproduct_to_pushout_cofork : cokernel_cofork (biprod.lift f (-g)) :=
cokernel_cofork.of_π (biproduct_to_pushout f g) $
by rw [biprod.lift_desc, neg_comp, pushout.condition, add_right_neg]
/-- The cofork induced by the canonical map `Y ⊞ Z ⟶ pushout f g` is in fact a colimit cokernel
cofork. -/
def is_colimit_biproduct_to_pushout : is_colimit (biproduct_to_pushout_cofork f g) :=
cofork.is_colimit.mk _
(λ s, pushout.desc (biprod.inl ≫ cofork.π s) (biprod.inr ≫ cofork.π s) $
sub_eq_zero.1 $ by rw [←category.assoc, ←category.assoc, ←sub_comp, sub_eq_add_neg, ←neg_comp,
←biprod.lift_eq, cofork.condition s, zero_comp])
(λ s, by ext; simp)
(λ s m h, by ext; simp [←h] )
end biproduct_to_pushout_is_cokernel
section epi_pullback
variables [limits.has_pullbacks C] {W X Y Z : C} (f : X ⟶ Z) (g : Y ⟶ Z)
/-- In an abelian category, the pullback of an epimorphism is an epimorphism.
Proof from [aluffi2016, IX.2.3], cf. [borceux-vol2, 1.7.6] -/
instance epi_pullback_of_epi_f [epi f] : epi (pullback.snd : pullback f g ⟶ Y) :=
-- It will suffice to consider some morphism e : Y ⟶ R such that
-- pullback.snd ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ $ λ R e h,
begin
-- Consider the morphism u := (0, e) : X ⊞ Y⟶ R.
let u := biprod.desc (0 : X ⟶ R) e,
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : pullback_to_biproduct_is_kernel.pullback_to_biproduct f g ≫ u = 0 := by simpa,
-- pullback_to_biproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullback_to_biproduct f g
have := epi_is_cokernel_of_kernel _
(pullback_to_biproduct_is_kernel.is_limit_pullback_to_biproduct f g),
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := cokernel_cofork.is_colimit.desc' this u hu,
change Z ⟶ R at d,
change biprod.desc f (-g) ≫ d = u at hd,
-- But then f ≫ d = 0:
have : f ≫ d = 0, calc
f ≫ d = (biprod.inl ≫ biprod.desc f (-g)) ≫ d : by rw biprod.inl_desc
... = biprod.inl ≫ u : by rw [category.assoc, hd]
... = 0 : biprod.inl_desc _ _,
-- But f is an epimorphism, so d = 0...
have : d = 0 := (cancel_epi f).1 (by simpa),
-- ...or, in other words, e = 0.
calc
e = biprod.inr ≫ u : by rw biprod.inr_desc
... = biprod.inr ≫ biprod.desc f (-g) ≫ d : by rw ←hd
... = biprod.inr ≫ biprod.desc f (-g) ≫ 0 : by rw this
... = (biprod.inr ≫ biprod.desc f (-g)) ≫ 0 : by rw ←category.assoc
... = 0 : has_zero_morphisms.comp_zero _ _
end
/-- In an abelian category, the pullback of an epimorphism is an epimorphism. -/
instance epi_pullback_of_epi_g [epi g] : epi (pullback.fst : pullback f g ⟶ X) :=
-- It will suffice to consider some morphism e : X ⟶ R such that
-- pullback.fst ≫ e = 0 and show that e = 0.
epi_of_cancel_zero _ $ λ R e h,
begin
-- Consider the morphism u := (e, 0) : X ⊞ Y ⟶ R.
let u := biprod.desc e (0 : Y ⟶ R),
-- The composite pullback f g ⟶ X ⊞ Y ⟶ R is zero by assumption.
have hu : pullback_to_biproduct_is_kernel.pullback_to_biproduct f g ≫ u = 0 := by simpa,
-- pullback_to_biproduct f g is a kernel of (f, -g), so (f, -g) is a
-- cokernel of pullback_to_biproduct f g
have := epi_is_cokernel_of_kernel _
(pullback_to_biproduct_is_kernel.is_limit_pullback_to_biproduct f g),
-- We use this fact to obtain a factorization of u through (f, -g) via some d : Z ⟶ R.
obtain ⟨d, hd⟩ := cokernel_cofork.is_colimit.desc' this u hu,
change Z ⟶ R at d,
change biprod.desc f (-g) ≫ d = u at hd,
-- But then (-g) ≫ d = 0:
have : (-g) ≫ d = 0, calc
(-g) ≫ d = (biprod.inr ≫ biprod.desc f (-g)) ≫ d : by rw biprod.inr_desc
... = biprod.inr ≫ u : by rw [category.assoc, hd]
... = 0 : biprod.inr_desc _ _,
-- But g is an epimorphism, thus so is -g, so d = 0...
have : d = 0 := (cancel_epi (-g)).1 (by simpa),
-- ...or, in other words, e = 0.
calc
e = biprod.inl ≫ u : by rw biprod.inl_desc
... = biprod.inl ≫ biprod.desc f (-g) ≫ d : by rw ←hd
... = biprod.inl ≫ biprod.desc f (-g) ≫ 0 : by rw this
... = (biprod.inl ≫ biprod.desc f (-g)) ≫ 0 : by rw ←category.assoc
... = 0 : has_zero_morphisms.comp_zero _ _
end
lemma epi_snd_of_is_limit [epi f] {s : pullback_cone f g} (hs : is_limit s) : epi s.snd :=
begin
convert epi_of_epi_fac (is_limit.cone_point_unique_up_to_iso_hom_comp (limit.is_limit _) hs _),
{ refl },
{ exact abelian.epi_pullback_of_epi_f _ _ }
end
lemma epi_fst_of_is_limit [epi g] {s : pullback_cone f g} (hs : is_limit s) : epi s.fst :=
begin
convert epi_of_epi_fac (is_limit.cone_point_unique_up_to_iso_hom_comp (limit.is_limit _) hs _),
{ refl },
{ exact abelian.epi_pullback_of_epi_g _ _ }
end
/-- Suppose `f` and `g` are two morphisms with a common codomain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the mono part of this
factorization, then any pullback of `g` along `f` is an epimorphism. -/
lemma epi_fst_of_factor_thru_epi_mono_factorization
(g₁ : Y ⟶ W) [epi g₁] (g₂ : W ⟶ Z) [mono g₂] (hg : g₁ ≫ g₂ = g) (f' : X ⟶ W) (hf : f' ≫ g₂ = f)
(t : pullback_cone f g) (ht : is_limit t) : epi t.fst :=
by apply epi_fst_of_is_limit _ _ (pullback_cone.is_limit_of_factors f g g₂ f' g₁ hf hg t ht)
end epi_pullback
section mono_pushout
variables [limits.has_pushouts C] {W X Y Z : C} (f : X ⟶ Y) (g : X ⟶ Z)
instance mono_pushout_of_mono_f [mono f] : mono (pushout.inr : Z ⟶ pushout f g) :=
mono_of_cancel_zero _ $ λ R e h,
begin
let u := biprod.lift (0 : R ⟶ Y) e,
have hu : u ≫ biproduct_to_pushout_is_cokernel.biproduct_to_pushout f g = 0 := by simpa,
have := mono_is_kernel_of_cokernel _
(biproduct_to_pushout_is_cokernel.is_colimit_biproduct_to_pushout f g),
obtain ⟨d, hd⟩ := kernel_fork.is_limit.lift' this u hu,
change R ⟶ X at d,
change d ≫ biprod.lift f (-g) = u at hd,
have : d ≫ f = 0, calc
d ≫ f = d ≫ biprod.lift f (-g) ≫ biprod.fst : by rw biprod.lift_fst
... = u ≫ biprod.fst : by rw [←category.assoc, hd]
... = 0 : biprod.lift_fst _ _,
have : d = 0 := (cancel_mono f).1 (by simpa),
calc
e = u ≫ biprod.snd : by rw biprod.lift_snd
... = (d ≫ biprod.lift f (-g)) ≫ biprod.snd : by rw ←hd
... = (0 ≫ biprod.lift f (-g)) ≫ biprod.snd : by rw this
... = 0 ≫ biprod.lift f (-g) ≫ biprod.snd : by rw category.assoc
... = 0 : zero_comp
end
instance mono_pushout_of_mono_g [mono g] : mono (pushout.inl : Y ⟶ pushout f g) :=
mono_of_cancel_zero _ $ λ R e h,
begin
let u := biprod.lift e (0 : R ⟶ Z),
have hu : u ≫ biproduct_to_pushout_is_cokernel.biproduct_to_pushout f g = 0 := by simpa,
have := mono_is_kernel_of_cokernel _
(biproduct_to_pushout_is_cokernel.is_colimit_biproduct_to_pushout f g),
obtain ⟨d, hd⟩ := kernel_fork.is_limit.lift' this u hu,
change R ⟶ X at d,
change d ≫ biprod.lift f (-g) = u at hd,
have : d ≫ (-g) = 0, calc
d ≫ (-g) = d ≫ biprod.lift f (-g) ≫ biprod.snd : by rw biprod.lift_snd
... = u ≫ biprod.snd : by rw [←category.assoc, hd]
... = 0 : biprod.lift_snd _ _,
have : d = 0 := (cancel_mono (-g)).1 (by simpa),
calc
e = u ≫ biprod.fst : by rw biprod.lift_fst
... = (d ≫ biprod.lift f (-g)) ≫ biprod.fst : by rw ←hd
... = (0 ≫ biprod.lift f (-g)) ≫ biprod.fst : by rw this
... = 0 ≫ biprod.lift f (-g) ≫ biprod.fst : by rw category.assoc
... = 0 : zero_comp
end
lemma mono_inr_of_is_colimit [mono f] {s : pushout_cocone f g} (hs : is_colimit s) : mono s.inr :=
begin
convert mono_of_mono_fac
(is_colimit.comp_cocone_point_unique_up_to_iso_hom hs (colimit.is_colimit _) _),
{ refl },
{ exact abelian.mono_pushout_of_mono_f _ _ }
end
lemma mono_inl_of_is_colimit [mono g] {s : pushout_cocone f g} (hs : is_colimit s) : mono s.inl :=
begin
convert mono_of_mono_fac
(is_colimit.comp_cocone_point_unique_up_to_iso_hom hs (colimit.is_colimit _) _),
{ refl },
{ exact abelian.mono_pushout_of_mono_g _ _ }
end
/-- Suppose `f` and `g` are two morphisms with a common domain and suppose we have written `g` as
an epimorphism followed by a monomorphism. If `f` factors through the epi part of this
factorization, then any pushout of `g` along `f` is a monomorphism. -/
lemma mono_inl_of_factor_thru_epi_mono_factorization (f : X ⟶ Y) (g : X ⟶ Z)
(g₁ : X ⟶ W) [epi g₁] (g₂ : W ⟶ Z) [mono g₂] (hg : g₁ ≫ g₂ = g) (f' : W ⟶ Y) (hf : g₁ ≫ f' = f)
(t : pushout_cocone f g) (ht : is_colimit t) : mono t.inl :=
by apply mono_inl_of_is_colimit _ _ (pushout_cocone.is_colimit_of_factors _ _ _ _ _ hf hg t ht)
end mono_pushout
end category_theory.abelian
namespace category_theory.non_preadditive_abelian
variables (C : Type u) [category.{v} C] [non_preadditive_abelian C]
/-- Every non_preadditive_abelian category can be promoted to an abelian category. -/
def abelian : abelian C :=
{ has_finite_products := by apply_instance,
/- We need the `convert`s here because the instances we have are slightly different from the
instances we need: `has_kernels` depends on an instance of `has_zero_morphisms`. In the
case of `non_preadditive_abelian`, this instance is an explicit argument. However, in the case
of `abelian`, the `has_zero_morphisms` instance is derived from `preadditive`. So we need to
transform an instance of "has kernels with non_preadditive_abelian.has_zero_morphisms" to an
instance of "has kernels with non_preadditive_abelian.preadditive.has_zero_morphisms". Luckily,
we have a `subsingleton` instance for `has_zero_morphisms`, so `convert` can immediately close
the goal it creates for the two instances of `has_zero_morphisms`, and the proof is complete. -/
has_kernels := by convert (by apply_instance : limits.has_kernels C),
has_cokernels := by convert (by apply_instance : limits.has_cokernels C),
normal_mono_of_mono := by { introsI, convert normal_mono_of_mono f },
normal_epi_of_epi := by { introsI, convert normal_epi_of_epi f },
..non_preadditive_abelian.preadditive }
end category_theory.non_preadditive_abelian
|
41e47038636f653bb8adc2de611ce4e295bcdb22
|
367134ba5a65885e863bdc4507601606690974c1
|
/src/ring_theory/polynomial/vieta.lean
|
84ea0f6e6513c278728ae68a706d605e4268f06e
|
[
"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
| 4,419
|
lean
|
/-
Copyright (c) 2020 Hanting Zhang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Hanting Zhang
-/
import ring_theory.polynomial.symmetric
/-!
# Vieta's Formula
The main result is `vieta.prod_X_add_C_eq_sum_esymm`, which shows that the product of linear terms
`λ + X i` is equal to a linear combination of the symmetric polynomials `esymm σ R j`.
## Implementation Notes:
We first take the viewpoint where the "roots" `X i` are variables. This means we work over
`polynomial (mv_polynomial σ R)`, which enables us to talk about linear combinations of
`esymm σ R j`. We then derive Vieta's formula in `polynomial R` by giving a
valuation from each `X i` to `r i`.
-/
universes u
open_locale big_operators
open finset polynomial fintype
namespace mv_polynomial
variables {R : Type u} [comm_semiring R]
variables (σ : Type u) [fintype σ]
/-- A sum version of Vieta's formula. Viewing `X i` as variables,
the product of linear terms `λ + X i` is equal to a linear combination of
the symmetric polynomials `esymm σ R j`. -/
lemma prod_X_add_C_eq_sum_esymm :
(∏ i : σ, (polynomial.C (X i) + polynomial.X) : polynomial (mv_polynomial σ R) )=
∑ j in range (card σ + 1),
(polynomial.C (esymm σ R j) * polynomial.X ^ (card σ - j)) :=
begin
classical,
rw [prod_add, sum_powerset],
refine sum_congr begin congr end (λ j hj, _),
rw [esymm, polynomial.C.map_sum, sum_mul],
refine sum_congr rfl (λ t ht, _),
have h : (univ \ t).card = card σ - j :=
by { rw card_sdiff (mem_powerset_len.mp ht).1, congr, exact (mem_powerset_len.mp ht).2 },
rw [(polynomial.C : mv_polynomial σ R →+* polynomial _).map_prod, prod_const, ← h],
congr,
end
/-- A fully expanded sum version of Vieta's formula, evaluated at the roots.
The product of linear terms `X + r i` is equal to `∑ j in range (n + 1), e_j * X ^ (n - j)`,
where `e_j` is the `j`th symmetric polynomial of the constant terms `r i`. -/
lemma prod_X_add_C_eval (r : σ → R) : ∏ i : σ, (polynomial.C (r i) + polynomial.X) =
∑ i in range (card σ + 1), (∑ t in powerset_len i (univ : finset σ),
∏ i in t, polynomial.C (r i)) * polynomial.X ^ (card σ - i) :=
begin
classical,
have h := @prod_X_add_C_eq_sum_esymm _ _ σ _,
apply_fun (polynomial.map (eval r)) at h,
rw [map_prod, map_sum] at h,
convert h,
simp only [eval_X, map_add, polynomial.map_C, polynomial.map_X, eq_self_iff_true],
funext,
simp only [function.funext_iff, esymm, polynomial.map_C, map_sum, polynomial.C.map_sum,
polynomial.map_C, map_pow, polynomial.map_X, map_mul],
congr,
funext,
simp only [eval_prod, eval_X, (polynomial.C : R →+* polynomial R).map_prod],
end
lemma esymm_to_sum (r : σ → R) (j : ℕ) : polynomial.C (eval r (esymm σ R j)) =
∑ t in powerset_len j (univ : finset σ), ∏ i in t, polynomial.C (r i) :=
by simp only [esymm, eval_sum, eval_prod, eval_X, polynomial.C.map_sum,
(polynomial.C : R →+* polynomial _).map_prod]
/-- Vieta's formula for the coefficients of the product of linear terms `X + r i`,
The `k`th coefficient is `∑ t in powerset_len (card σ - k) (univ : finset σ), ∏ i in t, r i`,
i.e. the symmetric polynomial `esymm σ R (card σ - k)` of the constant terms `r i`. -/
lemma prod_X_add_C_coeff (r : σ → R) (k : ℕ) (h : k ≤ card σ):
polynomial.coeff (∏ i : σ, (polynomial.C (r i) + polynomial.X)) k =
∑ t in powerset_len (card σ - k) (univ : finset σ), ∏ i in t, r i :=
begin
have hk : filter (λ (x : ℕ), k = card σ - x) (range (card σ + 1)) = {card σ - k} :=
begin
refine finset.ext (λ a, ⟨λ ha, _, λ ha, _ ⟩),
rw mem_singleton,
have hσ := (nat.sub_eq_iff_eq_add (mem_range_succ_iff.mp
(mem_filter.mp ha).1)).mp ((mem_filter.mp ha).2).symm,
symmetry,
rwa [(nat.sub_eq_iff_eq_add h), add_comm],
rw mem_filter,
have haσ : a ∈ range (card σ + 1) :=
by { rw mem_singleton.mp ha, exact mem_range_succ_iff.mpr (nat.sub_le_self _ k) },
refine ⟨haσ, eq.symm _⟩,
rw nat.sub_eq_iff_eq_add (mem_range_succ_iff.mp haσ),
have hσ := (nat.sub_eq_iff_eq_add h).mp (mem_singleton.mp ha).symm,
rwa add_comm,
end,
simp only [prod_X_add_C_eval, ← esymm_to_sum, finset_sum_coeff, coeff_C_mul_X, sum_ite, hk,
sum_singleton, esymm, eval_sum, eval_prod, eval_X, add_zero, sum_const_zero],
end
end mv_polynomial
|
f8301c5808288a7f6455df5efda08e017cb52b55
|
74addaa0e41490cbaf2abd313a764c96df57b05d
|
/Mathlib/tactic/rewrite_search/search_auto.lean
|
752d4e99e49125cc32c36a334256fb36bad68a5a
|
[] |
no_license
|
AurelienSaue/Mathlib4_auto
|
f538cfd0980f65a6361eadea39e6fc639e9dae14
|
590df64109b08190abe22358fabc3eae000943f2
|
refs/heads/master
| 1,683,906,849,776
| 1,622,564,669,000
| 1,622,564,669,000
| 371,723,747
| 0
| 0
| null | null | null | null |
UTF-8
|
Lean
| false
| false
| 1,096
|
lean
|
/-
Copyright (c) 2020 Kevin Lacker, Keeley Hoek, Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Lacker, Keeley Hoek, Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.data.buffer.basic
import Mathlib.meta.rb_map
import Mathlib.tactic.rewrite_search.discovery
import Mathlib.tactic.rewrite_search.types
import Mathlib.PostPort
namespace Mathlib
/-!
# The graph algorithm part of rewrite search
`search.lean` contains the logic to do a graph search. The search algorithm
starts with an equation to prove, treats the left hand side and right hand side as
two vertices in a graph, and uses rewrite rules to find a path that connects the two sides.
-/
namespace tactic.rewrite_search
/--
An edge represents a proof that can get from one expression to another.
It represents the fact that, starting from the vertex `fr`, the expression in `proof`
can prove the vertex `to`.
`how` contains information that the explainer will use to generate Lean code for the
proof.
-/
end Mathlib
|
bb049402b22e0f09b1912291647efc0b0e064503
|
618003631150032a5676f229d13a079ac875ff77
|
/src/analysis/asymptotics.lean
|
79140b3cff90dd37d2ba0329526763a264a897c3
|
[
"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
| 46,332
|
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 : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l ↔ is_O_with c₂ f₂ g₂ l :=
begin
subst c₂,
apply filter.congr_sets,
filter_upwards [hf, hg],
assume x e₁ e₂,
dsimp at e₁ e₂ ⊢,
rw [e₁, e₂]
end
theorem is_O_with.congr' {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
(is_O_with_congr hc hf hg).mp
theorem is_O_with.congr {c₁ c₂} {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hc : c₁ = c₂) (hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c₁ f₁ g₁ l → is_O_with c₂ f₂ g₂ l :=
λ h, h.congr' hc (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O_with.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O_with c f₁ g l → is_O_with c f₂ g l :=
is_O_with.congr rfl hf (λ _, rfl)
theorem is_O_with.congr_right {g₁ g₂ : α → F} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O_with c f g₁ l → is_O_with c f g₂ l :=
is_O_with.congr rfl (λ _, rfl) hg
theorem is_O_with.congr_const {c₁ c₂} {l : filter α} (hc : c₁ = c₂) :
is_O_with c₁ f g l → is_O_with c₂ f g l :=
is_O_with.congr hc (λ _, rfl) (λ _, rfl)
theorem is_O_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O f₁ g₁ l ↔ is_O f₂ g₂ l :=
exists_congr $ λ c, is_O_with_congr rfl hf hg
theorem is_O.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
(is_O_congr hf hg).mp
theorem is_O.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_O f₁ g₁ l → is_O f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_O.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_O f₁ g l → is_O f₂ g l :=
is_O.congr hf (λ _, rfl)
theorem is_O.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_O f g₁ l → is_O f g₂ l :=
is_O.congr (λ _, rfl) hg
theorem is_o_congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_o f₁ g₁ l ↔ is_o f₂ g₂ l :=
ball_congr (λ c hc, is_O_with_congr (eq.refl c) hf hg)
theorem is_o.congr' {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ᶠ x in l, f₁ x = f₂ x) (hg : ∀ᶠ x in l, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
(is_o_congr hf hg).mp
theorem is_o.congr {f₁ f₂ : α → E} {g₁ g₂ : α → F} {l : filter α}
(hf : ∀ x, f₁ x = f₂ x) (hg : ∀ x, g₁ x = g₂ x) :
is_o f₁ g₁ l → is_o f₂ g₂ l :=
λ h, h.congr' (univ_mem_sets' hf) (univ_mem_sets' hg)
theorem is_o.congr_left {f₁ f₂ : α → E} {l : filter α} (hf : ∀ x, f₁ x = f₂ x) :
is_o f₁ g l → is_o f₂ g l :=
is_o.congr hf (λ _, rfl)
theorem is_o.congr_right {g₁ g₂ : α → E} {l : filter α} (hg : ∀ x, g₁ x = g₂ x) :
is_o f g₁ l → is_o f g₂ l :=
is_o.congr (λ _, rfl) hg
/-! ### Filter operations and transitivity -/
theorem is_O_with.comp_tendsto (hcfg : is_O_with c f g l)
{k : β → α} {l' : filter β} (hk : tendsto k l' l):
is_O_with c (f ∘ k) (g ∘ k) l' :=
hk hcfg
theorem is_O.comp_tendsto (hfg : is_O f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_O (f ∘ k) (g ∘ k) l' :=
hfg.imp (λ c h, h.comp_tendsto hk)
theorem is_o.comp_tendsto (hfg : is_o f g l) {k : β → α} {l' : filter β} (hk : tendsto k l' l) :
is_o (f ∘ k) (g ∘ k) l' :=
λ c cpos, (hfg cpos).comp_tendsto hk
theorem is_O_with.mono (h : is_O_with c f g l') (hl : l ≤ l') : is_O_with c f g l :=
hl h
theorem is_O.mono (h : is_O f g l') (hl : l ≤ l') : is_O f g l :=
h.imp (λ c h, h.mono hl)
theorem is_o.mono (h : is_o f g l') (hl : l ≤ l') : is_o f g l :=
λ c cpos, (h cpos).mono hl
theorem is_O_with.trans (hfg : is_O_with c f g l) (hgk : is_O_with c' g k l) (hc : 0 ≤ c) :
is_O_with (c * c') f k l :=
begin
filter_upwards [hfg, hgk],
assume x hx hx',
calc ∥f x∥ ≤ c * ∥g x∥ : hx
... ≤ c * (c' * ∥k x∥) : mul_le_mul_of_nonneg_left hx' hc
... = c * c' * ∥k x∥ : (mul_assoc _ _ _).symm
end
theorem is_O.trans (hfg : is_O f g' l) (hgk : is_O g' k l) : is_O f k l :=
let ⟨c, cnonneg, hc⟩ := hfg.exists_nonneg, ⟨c', hc'⟩ := hgk in (hc.trans hc' cnonneg).is_O
theorem is_o.trans_is_O_with (hfg : is_o f g l) (hgk : is_O_with c g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact ((hfg this).trans hgk (le_of_lt this)).congr_const (div_mul_cancel _ (ne_of_gt hc))
end
theorem is_o.trans_is_O (hfg : is_o f g l) (hgk : is_O g k' l) : is_o f k' l :=
let ⟨c, cpos, hc⟩ := hgk.exists_pos in hfg.trans_is_O_with hc cpos
theorem is_O_with.trans_is_o (hfg : is_O_with c f g l) (hgk : is_o g k l) (hc : 0 < c) :
is_o f k l :=
begin
intros c' c'pos,
have : 0 < c' / c, from div_pos c'pos hc,
exact (hfg.trans (hgk this) (le_of_lt hc)).congr_const (mul_div_cancel' _ (ne_of_gt hc))
end
theorem is_O.trans_is_o (hfg : is_O f g' l) (hgk : is_o g' k l) : is_o f k l :=
let ⟨c, cpos, hc⟩ := hfg.exists_pos in hc.trans_is_o hgk cpos
theorem is_o.trans (hfg : is_o f g l) (hgk : is_o g k' l) : is_o f k' l :=
hfg.trans_is_O hgk.is_O
theorem is_o.trans' (hfg : is_o f g' l) (hgk : is_o g' k l) : is_o f k l :=
hfg.is_O.trans_is_o hgk
section
variable (l)
theorem is_O_with_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O_with c f g l :=
univ_mem_sets' hfg
theorem is_O_with_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O_with 1 f g l :=
is_O_with_of_le' l $ λ x, by { rw one_mul, exact hfg x }
theorem is_O_of_le' (hfg : ∀ x, ∥f x∥ ≤ c * ∥g x∥) : is_O f g l :=
(is_O_with_of_le' l hfg).is_O
theorem is_O_of_le (hfg : ∀ x, ∥f x∥ ≤ ∥g x∥) : is_O f g l :=
(is_O_with_of_le l hfg).is_O
end
theorem is_O_with_refl (f : α → E) (l : filter α) : is_O_with 1 f f l :=
is_O_with_of_le l $ λ _, le_refl _
theorem is_O_refl (f : α → E) (l : filter α) : is_O f f l := (is_O_with_refl f l).is_O
theorem is_O_with.trans_le (hfg : is_O_with c f g l) (hgk : ∀ x, ∥g x∥ ≤ ∥k x∥) (hc : 0 ≤ c) :
is_O_with c f k l :=
(hfg.trans (is_O_with_of_le l hgk) hc).congr_const $ mul_one c
theorem is_O.trans_le (hfg : is_O f g' l) (hgk : ∀ x, ∥g' x∥ ≤ ∥k x∥) :
is_O f k l :=
hfg.trans (is_O_of_le l hgk)
section bot
variables (c f g)
theorem is_O_with_bot : is_O_with c f g ⊥ := trivial
theorem is_O_bot : is_O f g ⊥ := (is_O_with_bot c f g).is_O
theorem is_o_bot : is_o f g ⊥ := λ c _, is_O_with_bot c f g
end bot
theorem is_O_with.join (h : is_O_with c f g l) (h' : is_O_with c f g l') :
is_O_with c f g (l ⊔ l') :=
mem_sup_sets.2 ⟨h, h'⟩
theorem is_O_with.join' (h : is_O_with c f g' l) (h' : is_O_with c' f g' l') :
is_O_with (max c c') f g' (l ⊔ l') :=
mem_sup_sets.2 ⟨(h.weaken $ le_max_left c c'), (h'.weaken $ le_max_right c c')⟩
theorem is_O.join (h : is_O f g' l) (h' : is_O f g' l') : is_O f g' (l ⊔ l') :=
let ⟨c, hc⟩ := h, ⟨c', hc'⟩ := h' in (hc.join' hc').is_O
theorem is_o.join (h : is_o f g l) (h' : is_o f g l') :
is_o f g (l ⊔ l') :=
λ c cpos, (h cpos).join (h' cpos)
/-! ### Simplification : norm -/
@[simp] theorem is_O_with_norm_right : is_O_with c f (λ x, ∥g' x∥) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_right ↔ asymptotics.is_O_with.of_norm_right asymptotics.is_O_with.norm_right
@[simp] theorem is_O_norm_right : is_O f (λ x, ∥g' x∥) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_norm_right
alias is_O_norm_right ↔ asymptotics.is_O.of_norm_right asymptotics.is_O.norm_right
@[simp] theorem is_o_norm_right : is_o f (λ x, ∥g' x∥) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_right
alias is_o_norm_right ↔ asymptotics.is_o.of_norm_right asymptotics.is_o.norm_right
@[simp] theorem is_O_with_norm_left : is_O_with c (λ x, ∥f' x∥) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_norm]
alias is_O_with_norm_left ↔ asymptotics.is_O_with.of_norm_left asymptotics.is_O_with.norm_left
@[simp] theorem is_O_norm_left : is_O (λ x, ∥f' x∥) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_norm_left
alias is_O_norm_left ↔ asymptotics.is_O.of_norm_left asymptotics.is_O.norm_left
@[simp] theorem is_o_norm_left : is_o (λ x, ∥f' x∥) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_norm_left
alias is_o_norm_left ↔ asymptotics.is_o.of_norm_left asymptotics.is_o.norm_left
theorem is_O_with_norm_norm :
is_O_with c (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O_with c f' g' l :=
is_O_with_norm_left.trans is_O_with_norm_right
alias is_O_with_norm_norm ↔ asymptotics.is_O_with.of_norm_norm asymptotics.is_O_with.norm_norm
theorem is_O_norm_norm :
is_O (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_O f' g' l :=
is_O_norm_left.trans is_O_norm_right
alias is_O_norm_norm ↔ asymptotics.is_O.of_norm_norm asymptotics.is_O.norm_norm
theorem is_o_norm_norm :
is_o (λ x, ∥f' x∥) (λ x, ∥g' x∥) l ↔ is_o f' g' l :=
is_o_norm_left.trans is_o_norm_right
alias is_o_norm_norm ↔ asymptotics.is_o.of_norm_norm asymptotics.is_o.norm_norm
/-! ### Simplification: negate -/
@[simp] theorem is_O_with_neg_right : is_O_with c f (λ x, -(g' x)) l ↔ is_O_with c f g' l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_right ↔ asymptotics.is_O_with.of_neg_right asymptotics.is_O_with.neg_right
@[simp] theorem is_O_neg_right : is_O f (λ x, -(g' x)) l ↔ is_O f g' l :=
exists_congr $ λ _, is_O_with_neg_right
alias is_O_neg_right ↔ asymptotics.is_O.of_neg_right asymptotics.is_O.neg_right
@[simp] theorem is_o_neg_right : is_o f (λ x, -(g' x)) l ↔ is_o f g' l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_right
alias is_o_neg_right ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_right
@[simp] theorem is_O_with_neg_left : is_O_with c (λ x, -(f' x)) g l ↔ is_O_with c f' g l :=
by simp only [is_O_with, norm_neg]
alias is_O_with_neg_left ↔ asymptotics.is_O_with.of_neg_left asymptotics.is_O_with.neg_left
@[simp] theorem is_O_neg_left : is_O (λ x, -(f' x)) g l ↔ is_O f' g l :=
exists_congr $ λ _, is_O_with_neg_left
alias is_O_neg_left ↔ asymptotics.is_O.of_neg_left asymptotics.is_O.neg_left
@[simp] theorem is_o_neg_left : is_o (λ x, -(f' x)) g l ↔ is_o f' g l :=
forall_congr $ λ _, forall_congr $ λ _, is_O_with_neg_left
alias is_o_neg_left ↔ asymptotics.is_o.of_neg_right asymptotics.is_o.neg_left
/-! ### Product of functions (right) -/
lemma is_O_with_fst_prod : is_O_with 1 f' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_left _ _
lemma is_O_with_snd_prod : is_O_with 1 g' (λ x, (f' x, g' x)) l :=
is_O_with_of_le l $ λ x, le_max_right _ _
lemma is_O_fst_prod : is_O f' (λ x, (f' x, g' x)) l := is_O_with_fst_prod.is_O
lemma is_O_snd_prod : is_O g' (λ x, (f' x, g' x)) l := is_O_with_snd_prod.is_O
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_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
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_eq_inv, ← div_eq_mul_inv, le_div_iff, mul_sub, mul_one, mul_comm],
{ exact le_trans (sub_le_sub_left hx _) (norm_sub_norm_le _ _) },
{ exact sub_pos.2 hc }
end
theorem is_O_with.right_le_add_of_lt_1 {f₁ f₂ : α → E'} (h : is_O_with c f₁ f₂ l) (hc : c < 1) :
is_O_with (1 / (1 - c)) f₂ (λx, f₁ x + f₂ x) l :=
(h.neg_right.right_le_sub_of_lt_1 hc).neg_right.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
|
a9e2fac135bb07311bba8e0ef5d5a46c7ad61641
|
4e3bf8e2b29061457a887ac8889e88fa5aa0e34c
|
/lean/love09_hoare_logic_homework_solution.lean
|
7607800cddef3fae4fe29888abd7bb27ad9e1182
|
[] |
no_license
|
mukeshtiwari/logical_verification_2019
|
9f964c067a71f65eb8884743273fbeef99e6503d
|
16f62717f55ed5b7b87e03ae0134791a9bef9b9a
|
refs/heads/master
| 1,619,158,844,208
| 1,585,139,500,000
| 1,585,139,500,000
| 249,906,380
| 0
| 0
| null | 1,585,118,728,000
| 1,585,118,727,000
| null |
UTF-8
|
Lean
| false
| false
| 1,261
|
lean
|
/- LoVe Homework 9: Hoare Logic -/
import .love08_operational_semantics_exercise_sheet
import .love09_hoare_logic_demo
namespace LoVe
/- Question 1: Hoare Logic for Dijkstra's Guarded Command Language -/
/- Recall the definition of GCL from exercise 8: -/
#check gcl
namespace gcl
#check big_step
/- The definition of Hoare triples for partial correctness is unsurprising: -/
def partial_hoare (P : state → Prop) (S : gcl state) (Q : state → Prop) :
Prop :=
∀s t, P s → (S, s) ~~> t → Q t
local notation `{* ` P : 1 ` *} ` S : 1 ` {* ` Q : 1 ` *}` :=
partial_hoare P S Q
namespace partial_hoare
variables {P : state → Prop} {S : gcl state}
/- 1.7 **optional**. Prove the rule you stated for `loop`.
Hint: This one is difficult and requires some generalization, as explained in
Section 5.8 ("Induction Pitfalls") of the lecture notes. -/
lemma loop_intro (h : {* P *} S {* P *}) :
{* P *} loop S {* P *} :=
begin
intros s t hs,
generalize eq : (loop S, s) = ps,
intro hst,
induction hst generalizing s;
cases eq,
{ assumption },
{ clear eq, rename hst_s s, rename hst_t t, rename hst_u u,
apply hst_ih_hrest t,
apply h s,
repeat { assumption },
{ refl } }
end
end partial_hoare
end gcl
end LoVe
|
7487929a4c82a78177f638da37cf17ebaed06ae9
|
5756a081670ba9c1d1d3fca7bd47cb4e31beae66
|
/Mathport/Syntax/Translate/Tactic/Mathlib/Congr.lean
|
18ff30e90bed2280be6dc237c0b7e5bc8b1dbc2e
|
[
"Apache-2.0"
] |
permissive
|
leanprover-community/mathport
|
2c9bdc8292168febf59799efdc5451dbf0450d4a
|
13051f68064f7638970d39a8fecaede68ffbf9e1
|
refs/heads/master
| 1,693,841,364,079
| 1,693,813,111,000
| 1,693,813,111,000
| 379,357,010
| 27
| 10
|
Apache-2.0
| 1,691,309,132,000
| 1,624,384,521,000
|
Lean
|
UTF-8
|
Lean
| false
| false
| 1,574
|
lean
|
/-
Copyright (c) 2021 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro
-/
import Mathport.Syntax.Translate.Tactic.Basic
import Mathport.Syntax.Translate.Tactic.Lean3
import Mathport.Syntax.Translate.Tactic.Mathlib.RCases
open Lean
open Lean.Elab.Tactic (Location)
namespace Mathport.Translate.Tactic
open AST3 Parser
-- # tactic.congr
@[tr_tactic congr'] def trCongr' : TacM Syntax.Tactic := do
let n := (← parse (smallNat)?).map quote
match ← parse (tk "with" *> return (← rintroPat*, ← (tk ":" *> smallNat)?))? with
| none => `(tactic| congr $(n)?)
| some (pats, ks) =>
`(tactic| congr $[$(n):num]? with $(← liftM <| pats.mapM trRIntroPat)* $[: $(ks.map quote)]?)
@[tr_tactic rcongr] def trRCongr : TacM Syntax.Tactic := do
`(tactic| rcongr $(← liftM $ (← parse rintroPat*).mapM trRIntroPat):rintroPat*)
@[tr_tactic convert] def trConvert : TacM Syntax.Tactic := do
let sym := optTk (← parse (tk "<-")?).isSome
let r ← trExpr (← parse pExpr)
let n ← parse (tk "using" *> smallNat)?
`(tactic| convert $[←%$sym]? $r $[using $(n.map quote)]?)
@[tr_tactic convert_to] def trConvertTo : TacM Syntax.Tactic := do
`(tactic| convert_to $(← trExpr (← parse pExpr)):term
$[using $((← parse (tk "using" *> smallNat)?).map Quote.quote)]?)
@[tr_tactic ac_change] def trAcChange : TacM Syntax.Tactic := do
`(tactic| ac_change $(← trExpr (← parse pExpr))
$[using $((← parse (tk "using" *> smallNat)?).map Quote.quote)]?)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.