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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
03a0b09ede6d0269750b584a07bddea2dced65b6 | ce6917c5bacabee346655160b74a307b4a5ab620 | /src/ch3/ex0316.lean | 615903947dfdc96d1993892600ea625ab9543860 | [] | no_license | Ailrun/Theorem_Proving_in_Lean | ae6a23f3c54d62d401314d6a771e8ff8b4132db2 | 2eb1b5caf93c6a5a555c79e9097cf2ba5a66cf68 | refs/heads/master | 1,609,838,270,467 | 1,586,846,743,000 | 1,586,846,743,000 | 240,967,761 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 71 | lean | variables p q : Prop
example (hp : p) (hnp: ¬p) : q := absurd hp hnp
|
c3cc515800b2e0e5bb7b27a5459b6c6d1274cd10 | 947b78d97130d56365ae2ec264df196ce769371a | /stage0/src/Std/Data/PersistentHashSet.lean | ed2947da7d962aab2929d2dc5a6344fa31857844 | [
"Apache-2.0"
] | permissive | shyamalschandra/lean4 | 27044812be8698f0c79147615b1d5090b9f4b037 | 6e7a883b21eaf62831e8111b251dc9b18f40e604 | refs/heads/master | 1,671,417,126,371 | 1,601,859,995,000 | 1,601,860,020,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,621 | lean | /-
Copyright (c) 2019 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Leonardo de Moura
-/
import Std.Data.PersistentHashMap
namespace Std
universes u v
structure PersistentHashSet (α : Type u) [HasBeq α] [Hashable α] :=
(set : PersistentHashMap α Unit)
abbrev PHashSet (α : Type u) [HasBeq α] [Hashable α] := PersistentHashSet α
namespace PersistentHashSet
variables {α : Type u} [HasBeq α] [Hashable α]
@[inline] def isEmpty (s : PersistentHashSet α) : Bool :=
s.set.isEmpty
@[inline] def empty : PersistentHashSet α :=
{ set := PersistentHashMap.empty }
instance : Inhabited (PersistentHashSet α) :=
⟨empty⟩
instance : HasEmptyc (PersistentHashSet α) :=
⟨empty⟩
@[inline] def insert (s : PersistentHashSet α) (a : α) : PersistentHashSet α :=
{ set := s.set.insert a () }
@[inline] def erase (s : PersistentHashSet α) (a : α) : PersistentHashSet α :=
{ set := s.set.erase a }
@[inline] def find? (s : PersistentHashSet α) (a : α) : Option α :=
match s.set.findEntry? a with
| some (a, _) => some a
| none => none
@[inline] def contains (s : PersistentHashSet α) (a : α) : Bool :=
s.set.contains a
@[inline] def size (s : PersistentHashSet α) : Nat :=
s.set.size
@[inline] def foldM {β : Type v} {m : Type v → Type v} [Monad m] (f : β → α → m β) (d : β) (s : PersistentHashSet α) : m β :=
s.set.foldlM (fun d a _ => f d a) d
@[inline] def fold {β : Type v} (f : β → α → β) (d : β) (s : PersistentHashSet α) : β :=
Id.run $ s.foldM f d
end PersistentHashSet
end Std
|
8796f27e91ce940f45d6877c39a4b05e03eebf12 | 947fa6c38e48771ae886239b4edce6db6e18d0fb | /src/geometry/manifold/partition_of_unity.lean | d5c795f33cc344ea80692409fd48adb1d3c58dad | [
"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 | 27,487 | lean | /-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov
-/
import geometry.manifold.algebra.structures
import geometry.manifold.bump_function
import topology.metric_space.partition_of_unity
import topology.shrinking_lemma
/-!
# Smooth partition of unity
In this file we define two structures, `smooth_bump_covering` and `smooth_partition_of_unity`. Both
structures describe coverings of a set by a locally finite family of supports of smooth functions
with some additional properties. The former structure is mostly useful as an intermediate step in
the construction of a smooth partition of unity but some proofs that traditionally deal with a
partition of unity can use a `smooth_bump_covering` as well.
Given a real manifold `M` and its subset `s`, a `smooth_bump_covering ι I M s` is a collection of
`smooth_bump_function`s `f i` indexed by `i : ι` such that
* the center of each `f i` belongs to `s`;
* the family of sets `support (f i)` is locally finite;
* for each `x ∈ s`, there exists `i : ι` such that `f i =ᶠ[𝓝 x] 1`.
In the same settings, a `smooth_partition_of_unity ι I M s` is a collection of smooth nonnegative
functions `f i : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯`, `i : ι`, such that
* the family of sets `support (f i)` is locally finite;
* for each `x ∈ s`, the sum `∑ᶠ i, f i x` equals one;
* for each `x`, the sum `∑ᶠ i, f i x` is less than or equal to one.
We say that `f : smooth_bump_covering ι I M s` is *subordinate* to a map `U : M → set M` if for each
index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than
being subordinate to an open covering of `M`, because we make no assumption about the way `U x`
depends on `x`.
We prove that on a smooth finitely dimensional real manifold with `σ`-compact Hausdorff topology,
for any `U : M → set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `smooth_bump_covering ι I M s`
subordinate to `U`. Then we use this fact to prove a similar statement about smooth partitions of
unity, see `smooth_partition_of_unity.exists_is_subordinate`.
Finally, we use existence of a partition of unity to prove lemma
`exists_smooth_forall_mem_convex_of_local` that allows us to construct a globally defined smooth
function from local functions.
## TODO
* Build a framework for to transfer local definitions to global using partition of unity and use it
to define, e.g., the integral of a differential form over a manifold. Lemma
`exists_smooth_forall_mem_convex_of_local` is a first step in this direction.
## Tags
smooth bump function, partition of unity
-/
universes uι uE uH uM uF
open function filter finite_dimensional set
open_locale topological_space manifold classical filter big_operators
noncomputable theory
variables {ι : Type uι}
{E : Type uE} [normed_add_comm_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
{F : Type uF} [normed_add_comm_group F] [normed_space ℝ F]
{H : Type uH} [topological_space H] (I : model_with_corners ℝ E H)
{M : Type uM} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
/-!
### Covering by supports of smooth bump functions
In this section we define `smooth_bump_covering ι I M s` to be a collection of
`smooth_bump_function`s such that their supports is a locally finite family of sets and for each `x
∈ s` some function `f i` from the collection is equal to `1` in a neighborhood of `x`. A covering of
this type is useful to construct a smooth partition of unity and can be used instead of a partition
of unity in some proofs.
We prove that on a smooth finite dimensional real manifold with `σ`-compact Hausdorff topology, for
any `U : M → set M` such that `∀ x ∈ s, U x ∈ 𝓝 x` there exists a `smooth_bump_covering ι I M s`
subordinate to `U`. Then we use this fact to prove a version of the Whitney embedding theorem: any
compact real manifold can be embedded into `ℝ^n` for large enough `n`. -/
variables (ι M)
/-- We say that a collection of `smooth_bump_function`s is a `smooth_bump_covering` of a set `s` if
* `(f i).c ∈ s` for all `i`;
* the family `λ i, support (f i)` is locally finite;
* for each point `x ∈ s` there exists `i` such that `f i =ᶠ[𝓝 x] 1`;
in other words, `x` belongs to the interior of `{y | f i y = 1}`;
If `M` is a finite dimensional real manifold which is a `σ`-compact Hausdorff topological space,
then for every covering `U : M → set M`, `∀ x, U x ∈ 𝓝 x`, there exists a `smooth_bump_covering`
subordinate to `U`, see `smooth_bump_covering.exists_is_subordinate`.
This covering can be used, e.g., to construct a partition of unity and to prove the weak
Whitney embedding theorem. -/
@[nolint has_nonempty_instance]
structure smooth_bump_covering (s : set M := univ) :=
(c : ι → M)
(to_fun : Π i, smooth_bump_function I (c i))
(c_mem' : ∀ i, c i ∈ s)
(locally_finite' : locally_finite (λ i, support (to_fun i)))
(eventually_eq_one' : ∀ x ∈ s, ∃ i, to_fun i =ᶠ[𝓝 x] 1)
/-- We say that that a collection of functions form a smooth partition of unity on a set `s` if
* all functions are infinitely smooth and nonnegative;
* the family `λ i, support (f i)` is locally finite;
* for all `x ∈ s` the sum `∑ᶠ i, f i x` equals one;
* for all `x`, the sum `∑ᶠ i, f i x` is less than or equal to one. -/
structure smooth_partition_of_unity (s : set M := univ) :=
(to_fun : ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯)
(locally_finite' : locally_finite (λ i, support (to_fun i)))
(nonneg' : ∀ i x, 0 ≤ to_fun i x)
(sum_eq_one' : ∀ x ∈ s, ∑ᶠ i, to_fun i x = 1)
(sum_le_one' : ∀ x, ∑ᶠ i, to_fun i x ≤ 1)
variables {ι I M}
namespace smooth_partition_of_unity
variables {s : set M} (f : smooth_partition_of_unity ι I M s) {n : with_top ℕ}
instance {s : set M} : has_coe_to_fun (smooth_partition_of_unity ι I M s)
(λ _, ι → C^∞⟮I, M; 𝓘(ℝ), ℝ⟯) :=
⟨smooth_partition_of_unity.to_fun⟩
protected lemma locally_finite : locally_finite (λ i, support (f i)) :=
f.locally_finite'
lemma nonneg (i : ι) (x : M) : 0 ≤ f i x := f.nonneg' i x
lemma sum_eq_one {x} (hx : x ∈ s) : ∑ᶠ i, f i x = 1 := f.sum_eq_one' x hx
lemma sum_le_one (x : M) : ∑ᶠ i, f i x ≤ 1 := f.sum_le_one' x
/-- Reinterpret a smooth partition of unity as a continuous partition of unity. -/
def to_partition_of_unity : partition_of_unity ι M s :=
{ to_fun := λ i, f i, .. f }
lemma smooth_sum : smooth I 𝓘(ℝ) (λ x, ∑ᶠ i, f i x) :=
smooth_finsum (λ i, (f i).smooth) f.locally_finite
lemma le_one (i : ι) (x : M) : f i x ≤ 1 := f.to_partition_of_unity.le_one i x
lemma sum_nonneg (x : M) : 0 ≤ ∑ᶠ i, f i x := f.to_partition_of_unity.sum_nonneg x
lemma cont_mdiff_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), cont_mdiff_at I 𝓘(ℝ, F) n g x) :
cont_mdiff I 𝓘(ℝ, F) n (λ x, f i x • g x) :=
cont_mdiff_of_support $ λ x hx, ((f i).cont_mdiff.cont_mdiff_at.of_le le_top).smul $ hg x $
tsupport_smul_subset_left _ _ hx
lemma smooth_smul {g : M → F} {i} (hg : ∀ x ∈ tsupport (f i), smooth_at I 𝓘(ℝ, F) g x) :
smooth I 𝓘(ℝ, F) (λ x, f i x • g x) :=
f.cont_mdiff_smul hg
/-- If `f` is a smooth partition of unity on a set `s : set M` and `g : ι → M → F` is a family of
functions such that `g i` is $C^n$ smooth at every point of the topological support of `f i`, then
the sum `λ x, ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/
lemma cont_mdiff_finsum_smul {g : ι → M → F}
(hg : ∀ i (x ∈ tsupport (f i)), cont_mdiff_at I 𝓘(ℝ, F) n (g i) x) :
cont_mdiff I 𝓘(ℝ, F) n (λ x, ∑ᶠ i, f i x • g i x) :=
cont_mdiff_finsum (λ i, f.cont_mdiff_smul (hg i)) $ f.locally_finite.subset $
λ i, support_smul_subset_left _ _
/-- If `f` is a smooth partition of unity on a set `s : set M` and `g : ι → M → F` is a family of
functions such that `g i` is smooth at every point of the topological support of `f i`, then the sum
`λ x, ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/
lemma smooth_finsum_smul {g : ι → M → F}
(hg : ∀ i (x ∈ tsupport (f i)), smooth_at I 𝓘(ℝ, F) (g i) x) :
smooth I 𝓘(ℝ, F) (λ x, ∑ᶠ i, f i x • g i x) :=
f.cont_mdiff_finsum_smul hg
lemma finsum_smul_mem_convex {g : ι → M → F} {t : set F} {x : M} (hx : x ∈ s)
(hg : ∀ i, f i x ≠ 0 → g i x ∈ t) (ht : convex ℝ t) :
∑ᶠ i, f i x • g i x ∈ t :=
ht.finsum_mem (λ i, f.nonneg _ _) (f.sum_eq_one hx) hg
/-- A smooth partition of unity `f i` is subordinate to a family of sets `U i` indexed by the same
type if for each `i` the closure of the support of `f i` is a subset of `U i`. -/
def is_subordinate (f : smooth_partition_of_unity ι I M s) (U : ι → set M) :=
∀ i, tsupport (f i) ⊆ U i
variables {f} {U : ι → set M}
@[simp] lemma is_subordinate_to_partition_of_unity :
f.to_partition_of_unity.is_subordinate U ↔ f.is_subordinate U :=
iff.rfl
alias is_subordinate_to_partition_of_unity ↔ _ is_subordinate.to_partition_of_unity
/-- If `f` is a smooth partition of unity on a set `s : set M` subordinate to a family of open sets
`U : ι → set M` and `g : ι → M → F` is a family of functions such that `g i` is $C^n$ smooth on
`U i`, then the sum `λ x, ∑ᶠ i, f i x • g i x` is $C^n$ smooth on the whole manifold. -/
lemma is_subordinate.cont_mdiff_finsum_smul {g : ι → M → F} (hf : f.is_subordinate U)
(ho : ∀ i, is_open (U i)) (hg : ∀ i, cont_mdiff_on I 𝓘(ℝ, F) n (g i) (U i)) :
cont_mdiff I 𝓘(ℝ, F) n (λ x, ∑ᶠ i, f i x • g i x) :=
f.cont_mdiff_finsum_smul $ λ i x hx, (hg i).cont_mdiff_at $ (ho i).mem_nhds (hf i hx)
/-- If `f` is a smooth partition of unity on a set `s : set M` subordinate to a family of open sets
`U : ι → set M` and `g : ι → M → F` is a family of functions such that `g i` is smooth on `U i`,
then the sum `λ x, ∑ᶠ i, f i x • g i x` is smooth on the whole manifold. -/
lemma is_subordinate.smooth_finsum_smul {g : ι → M → F} (hf : f.is_subordinate U)
(ho : ∀ i, is_open (U i)) (hg : ∀ i, smooth_on I 𝓘(ℝ, F) (g i) (U i)) :
smooth I 𝓘(ℝ, F) (λ x, ∑ᶠ i, f i x • g i x) :=
hf.cont_mdiff_finsum_smul ho hg
end smooth_partition_of_unity
namespace bump_covering
-- Repeat variables to drop [finite_dimensional ℝ E] and [smooth_manifold_with_corners I M]
lemma smooth_to_partition_of_unity {E : Type uE} [normed_add_comm_group E] [normed_space ℝ E]
{H : Type uH} [topological_space H] {I : model_with_corners ℝ E H}
{M : Type uM} [topological_space M] [charted_space H M] {s : set M}
(f : bump_covering ι M s) (hf : ∀ i, smooth I 𝓘(ℝ) (f i)) (i : ι) :
smooth I 𝓘(ℝ) (f.to_partition_of_unity i) :=
(hf i).mul $ smooth_finprod_cond (λ j _, smooth_const.sub (hf j)) $
by { simp only [mul_support_one_sub], exact f.locally_finite }
variables {s : set M}
/-- A `bump_covering` such that all functions in this covering are smooth generates a smooth
partition of unity.
In our formalization, not every `f : bump_covering ι M s` with smooth functions `f i` is a
`smooth_bump_covering`; instead, a `smooth_bump_covering` is a covering by supports of
`smooth_bump_function`s. So, we define `bump_covering.to_smooth_partition_of_unity`, then reuse it
in `smooth_bump_covering.to_smooth_partition_of_unity`. -/
def to_smooth_partition_of_unity (f : bump_covering ι M s) (hf : ∀ i, smooth I 𝓘(ℝ) (f i)) :
smooth_partition_of_unity ι I M s :=
{ to_fun := λ i, ⟨f.to_partition_of_unity i, f.smooth_to_partition_of_unity hf i⟩,
.. f.to_partition_of_unity }
@[simp] lemma to_smooth_partition_of_unity_to_partition_of_unity (f : bump_covering ι M s)
(hf : ∀ i, smooth I 𝓘(ℝ) (f i)) :
(f.to_smooth_partition_of_unity hf).to_partition_of_unity = f.to_partition_of_unity :=
rfl
@[simp] lemma coe_to_smooth_partition_of_unity (f : bump_covering ι M s)
(hf : ∀ i, smooth I 𝓘(ℝ) (f i)) (i : ι) :
⇑(f.to_smooth_partition_of_unity hf i) = f.to_partition_of_unity i :=
rfl
lemma is_subordinate.to_smooth_partition_of_unity {f : bump_covering ι M s}
{U : ι → set M} (h : f.is_subordinate U) (hf : ∀ i, smooth I 𝓘(ℝ) (f i)) :
(f.to_smooth_partition_of_unity hf).is_subordinate U :=
h.to_partition_of_unity
end bump_covering
namespace smooth_bump_covering
variables {s : set M} {U : M → set M} (fs : smooth_bump_covering ι I M s) {I}
instance : has_coe_to_fun (smooth_bump_covering ι I M s)
(λ x, Π (i : ι), smooth_bump_function I (x.c i)) :=
⟨to_fun⟩
@[simp] lemma coe_mk (c : ι → M) (to_fun : Π i, smooth_bump_function I (c i))
(h₁ h₂ h₃) : ⇑(mk c to_fun h₁ h₂ h₃ : smooth_bump_covering ι I M s) = to_fun :=
rfl
/--
We say that `f : smooth_bump_covering ι I M s` is *subordinate* to a map `U : M → set M` if for each
index `i`, we have `tsupport (f i) ⊆ U (f i).c`. This notion is a bit more general than
being subordinate to an open covering of `M`, because we make no assumption about the way `U x`
depends on `x`.
-/
def is_subordinate {s : set M} (f : smooth_bump_covering ι I M s) (U : M → set M) :=
∀ i, tsupport (f i) ⊆ U (f.c i)
lemma is_subordinate.support_subset {fs : smooth_bump_covering ι I M s} {U : M → set M}
(h : fs.is_subordinate U) (i : ι) :
support (fs i) ⊆ U (fs.c i) :=
subset.trans subset_closure (h i)
variable (I)
/-- Let `M` be a smooth manifold with corners modelled on a finite dimensional real vector space.
Suppose also that `M` is a Hausdorff `σ`-compact topological space. Let `s` be a closed set
in `M` and `U : M → set M` be a collection of sets such that `U x ∈ 𝓝 x` for every `x ∈ s`.
Then there exists a smooth bump covering of `s` that is subordinate to `U`. -/
lemma exists_is_subordinate [t2_space M] [sigma_compact_space M] (hs : is_closed s)
(hU : ∀ x ∈ s, U x ∈ 𝓝 x) :
∃ (ι : Type uM) (f : smooth_bump_covering ι I M s), f.is_subordinate U :=
begin
-- First we deduce some missing instances
haveI : locally_compact_space H := I.locally_compact,
haveI : locally_compact_space M := charted_space.locally_compact H M,
haveI : normal_space M := normal_of_paracompact_t2,
-- Next we choose a covering by supports of smooth bump functions
have hB := λ x hx, smooth_bump_function.nhds_basis_support I (hU x hx),
rcases refinement_of_locally_compact_sigma_compact_of_nhds_basis_set hs hB
with ⟨ι, c, f, hf, hsub', hfin⟩, choose hcs hfU using hf,
/- Then we use the shrinking lemma to get a covering by smaller open -/
rcases exists_subset_Union_closed_subset hs (λ i, (f i).open_support)
(λ x hx, hfin.point_finite x) hsub' with ⟨V, hsV, hVc, hVf⟩,
choose r hrR hr using λ i, (f i).exists_r_pos_lt_subset_ball (hVc i) (hVf i),
refine ⟨ι, ⟨c, λ i, (f i).update_r (r i) (hrR i), hcs, _, λ x hx, _⟩, λ i, _⟩,
{ simpa only [smooth_bump_function.support_update_r] },
{ refine (mem_Union.1 $ hsV hx).imp (λ i hi, _),
exact ((f i).update_r _ _).eventually_eq_one_of_dist_lt
((f i).support_subset_source $ hVf _ hi) (hr i hi).2 },
{ simpa only [coe_mk, smooth_bump_function.support_update_r, tsupport] using hfU i }
end
variables {I M}
protected lemma locally_finite : locally_finite (λ i, support (fs i)) := fs.locally_finite'
protected lemma point_finite (x : M) : {i | fs i x ≠ 0}.finite :=
fs.locally_finite.point_finite x
lemma mem_chart_at_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) :
x ∈ (chart_at H (fs.c i)).source :=
(fs i).support_subset_source $ by simp [h]
lemma mem_ext_chart_at_source_of_eq_one {i : ι} {x : M} (h : fs i x = 1) :
x ∈ (ext_chart_at I (fs.c i)).source :=
by { rw ext_chart_at_source, exact fs.mem_chart_at_source_of_eq_one h }
/-- Index of a bump function such that `fs i =ᶠ[𝓝 x] 1`. -/
def ind (x : M) (hx : x ∈ s) : ι := (fs.eventually_eq_one' x hx).some
lemma eventually_eq_one (x : M) (hx : x ∈ s) : fs (fs.ind x hx) =ᶠ[𝓝 x] 1 :=
(fs.eventually_eq_one' x hx).some_spec
lemma apply_ind (x : M) (hx : x ∈ s) : fs (fs.ind x hx) x = 1 :=
(fs.eventually_eq_one x hx).eq_of_nhds
lemma mem_support_ind (x : M) (hx : x ∈ s) : x ∈ support (fs $ fs.ind x hx) :=
by simp [fs.apply_ind x hx]
lemma mem_chart_at_ind_source (x : M) (hx : x ∈ s) :
x ∈ (chart_at H (fs.c (fs.ind x hx))).source :=
fs.mem_chart_at_source_of_eq_one (fs.apply_ind x hx)
lemma mem_ext_chart_at_ind_source (x : M) (hx : x ∈ s) :
x ∈ (ext_chart_at I (fs.c (fs.ind x hx))).source :=
fs.mem_ext_chart_at_source_of_eq_one (fs.apply_ind x hx)
/-- The index type of a `smooth_bump_covering` of a compact manifold is finite. -/
protected def fintype [compact_space M] : fintype ι :=
fs.locally_finite.fintype_of_compact $ λ i, (fs i).nonempty_support
variable [t2_space M]
/-- Reinterpret a `smooth_bump_covering` as a continuous `bump_covering`. Note that not every
`f : bump_covering ι M s` with smooth functions `f i` is a `smooth_bump_covering`. -/
def to_bump_covering : bump_covering ι M s :=
{ to_fun := λ i, ⟨fs i, (fs i).continuous⟩,
locally_finite' := fs.locally_finite,
nonneg' := λ i x, (fs i).nonneg,
le_one' := λ i x, (fs i).le_one,
eventually_eq_one' := fs.eventually_eq_one' }
@[simp] lemma is_subordinate_to_bump_covering {f : smooth_bump_covering ι I M s} {U : M → set M} :
f.to_bump_covering.is_subordinate (λ i, U (f.c i)) ↔ f.is_subordinate U :=
iff.rfl
alias is_subordinate_to_bump_covering ↔ _ is_subordinate.to_bump_covering
/-- Every `smooth_bump_covering` defines a smooth partition of unity. -/
def to_smooth_partition_of_unity : smooth_partition_of_unity ι I M s :=
fs.to_bump_covering.to_smooth_partition_of_unity (λ i, (fs i).smooth)
lemma to_smooth_partition_of_unity_apply (i : ι) (x : M) :
fs.to_smooth_partition_of_unity i x = fs i x * ∏ᶠ j (hj : well_ordering_rel j i), (1 - fs j x) :=
rfl
lemma to_smooth_partition_of_unity_eq_mul_prod (i : ι) (x : M) (t : finset ι)
(ht : ∀ j, well_ordering_rel j i → fs j x ≠ 0 → j ∈ t) :
fs.to_smooth_partition_of_unity i x =
fs i x * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - fs j x) :=
fs.to_bump_covering.to_partition_of_unity_eq_mul_prod i x t ht
lemma exists_finset_to_smooth_partition_of_unity_eventually_eq (i : ι) (x : M) :
∃ t : finset ι, fs.to_smooth_partition_of_unity i =ᶠ[𝓝 x]
fs i * ∏ j in t.filter (λ j, well_ordering_rel j i), (1 - fs j) :=
fs.to_bump_covering.exists_finset_to_partition_of_unity_eventually_eq i x
lemma to_smooth_partition_of_unity_zero_of_zero {i : ι} {x : M} (h : fs i x = 0) :
fs.to_smooth_partition_of_unity i x = 0 :=
fs.to_bump_covering.to_partition_of_unity_zero_of_zero h
lemma support_to_smooth_partition_of_unity_subset (i : ι) :
support (fs.to_smooth_partition_of_unity i) ⊆ support (fs i) :=
fs.to_bump_covering.support_to_partition_of_unity_subset i
lemma is_subordinate.to_smooth_partition_of_unity {f : smooth_bump_covering ι I M s} {U : M → set M}
(h : f.is_subordinate U) :
f.to_smooth_partition_of_unity.is_subordinate (λ i, U (f.c i)) :=
h.to_bump_covering.to_partition_of_unity
lemma sum_to_smooth_partition_of_unity_eq (x : M) :
∑ᶠ i, fs.to_smooth_partition_of_unity i x = 1 - ∏ᶠ i, (1 - fs i x) :=
fs.to_bump_covering.sum_to_partition_of_unity_eq x
end smooth_bump_covering
variable (I)
/-- Given two disjoint closed sets in a Hausdorff σ-compact finite dimensional manifold, there
exists an infinitely smooth function that is equal to `0` on one of them and is equal to one on the
other. -/
lemma exists_smooth_zero_one_of_closed [t2_space M] [sigma_compact_space M] {s t : set M}
(hs : is_closed s) (ht : is_closed t) (hd : disjoint s t) :
∃ f : C^∞⟮I, M; 𝓘(ℝ), ℝ⟯, eq_on f 0 s ∧ eq_on f 1 t ∧ ∀ x, f x ∈ Icc (0 : ℝ) 1 :=
begin
have : ∀ x ∈ t, sᶜ ∈ 𝓝 x, from λ x hx, hs.is_open_compl.mem_nhds (disjoint_right.1 hd hx),
rcases smooth_bump_covering.exists_is_subordinate I ht this with ⟨ι, f, hf⟩,
set g := f.to_smooth_partition_of_unity,
refine ⟨⟨_, g.smooth_sum⟩, λ x hx, _, λ x, g.sum_eq_one, λ x, ⟨g.sum_nonneg x, g.sum_le_one x⟩⟩,
suffices : ∀ i, g i x = 0,
by simp only [this, cont_mdiff_map.coe_fn_mk, finsum_zero, pi.zero_apply],
refine λ i, f.to_smooth_partition_of_unity_zero_of_zero _,
exact nmem_support.1 (subset_compl_comm.1 (hf.support_subset i) hx)
end
namespace smooth_partition_of_unity
/-- A `smooth_partition_of_unity` that consists of a single function, uniformly equal to one,
defined as an example for `inhabited` instance. -/
def single (i : ι) (s : set M) : smooth_partition_of_unity ι I M s :=
(bump_covering.single i s).to_smooth_partition_of_unity $ λ j,
begin
rcases eq_or_ne j i with rfl|h,
{ simp only [smooth_one, continuous_map.coe_one, bump_covering.coe_single, pi.single_eq_same] },
{ simp only [smooth_zero, bump_covering.coe_single, pi.single_eq_of_ne h,
continuous_map.coe_zero] }
end
instance [inhabited ι] (s : set M) : inhabited (smooth_partition_of_unity ι I M s) :=
⟨single I default s⟩
variables [t2_space M] [sigma_compact_space M]
/-- If `X` is a paracompact normal topological space and `U` is an open covering of a closed set
`s`, then there exists a `bump_covering ι X s` that is subordinate to `U`. -/
lemma exists_is_subordinate {s : set M} (hs : is_closed s) (U : ι → set M) (ho : ∀ i, is_open (U i))
(hU : s ⊆ ⋃ i, U i) :
∃ f : smooth_partition_of_unity ι I M s, f.is_subordinate U :=
begin
haveI : locally_compact_space H := I.locally_compact,
haveI : locally_compact_space M := charted_space.locally_compact H M,
haveI : normal_space M := normal_of_paracompact_t2,
rcases bump_covering.exists_is_subordinate_of_prop (smooth I 𝓘(ℝ)) _ hs U ho hU
with ⟨f, hf, hfU⟩,
{ exact ⟨f.to_smooth_partition_of_unity hf, hfU.to_smooth_partition_of_unity hf⟩ },
{ intros s t hs ht hd,
rcases exists_smooth_zero_one_of_closed I hs ht hd with ⟨f, hf⟩,
exact ⟨f, f.smooth, hf⟩ }
end
end smooth_partition_of_unity
variables [sigma_compact_space M] [t2_space M] {t : M → set F} {n : with_top ℕ}
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → set F`
be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood
`U ∈ 𝓝 x` and a function `g : M → F` such that `g` is $C^n$ smooth on `U` and `g y ∈ t y` for all
`y ∈ U`. Then there exists a $C^n$ smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x`
for all `x`. See also `exists_smooth_forall_mem_convex_of_local` and
`exists_smooth_forall_mem_convex_of_local_const`. -/
lemma exists_cont_mdiff_forall_mem_convex_of_local (ht : ∀ x, convex ℝ (t x))
(Hloc : ∀ x : M, ∃ (U ∈ 𝓝 x) (g : M → F), cont_mdiff_on I 𝓘(ℝ, F) n g U ∧ ∀ y ∈ U, g y ∈ t y) :
∃ g : C^n⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x :=
begin
choose U hU g hgs hgt using Hloc,
obtain ⟨f, hf⟩ := smooth_partition_of_unity.exists_is_subordinate I is_closed_univ
(λ x, interior (U x)) (λ x, is_open_interior)
(λ x hx, mem_Union.2 ⟨x, mem_interior_iff_mem_nhds.2 (hU x)⟩),
refine ⟨⟨λ x, ∑ᶠ i, f i x • g i x,
hf.cont_mdiff_finsum_smul (λ i, is_open_interior) $ λ i, (hgs i).mono interior_subset⟩,
λ x, f.finsum_smul_mem_convex (mem_univ x) (λ i hi, hgt _ _ _) (ht _)⟩,
exact interior_subset (hf _ $ subset_closure hi)
end
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → set F`
be a family of convex sets. Suppose that for each point `x : M` there exists a neighborhood
`U ∈ 𝓝 x` and a function `g : M → F` such that `g` is smooth on `U` and `g y ∈ t y` for all `y ∈ U`.
Then there exists a smooth function `g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`.
See also `exists_cont_mdiff_forall_mem_convex_of_local` and
`exists_smooth_forall_mem_convex_of_local_const`. -/
lemma exists_smooth_forall_mem_convex_of_local (ht : ∀ x, convex ℝ (t x))
(Hloc : ∀ x : M, ∃ (U ∈ 𝓝 x) (g : M → F), smooth_on I 𝓘(ℝ, F) g U ∧ ∀ y ∈ U, g y ∈ t y) :
∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x :=
exists_cont_mdiff_forall_mem_convex_of_local I ht Hloc
/-- Let `M` be a σ-compact Hausdorff finite dimensional topological manifold. Let `t : M → set F` be
a family of convex sets. Suppose that for each point `x : M` there exists a vector `c : F` such that
for all `y` in a neighborhood of `x` we have `c ∈ t y`. Then there exists a smooth function
`g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯` such that `g x ∈ t x` for all `x`. See also
`exists_cont_mdiff_forall_mem_convex_of_local` and `exists_smooth_forall_mem_convex_of_local`. -/
lemma exists_smooth_forall_mem_convex_of_local_const (ht : ∀ x, convex ℝ (t x))
(Hloc : ∀ x : M, ∃ c : F, ∀ᶠ y in 𝓝 x, c ∈ t y) :
∃ g : C^∞⟮I, M; 𝓘(ℝ, F), F⟯, ∀ x, g x ∈ t x :=
exists_smooth_forall_mem_convex_of_local I ht $ λ x,
let ⟨c, hc⟩ := Hloc x in ⟨_, hc, λ _, c, smooth_on_const, λ y, id⟩
/-- Let `M` be a smooth σ-compact manifold with extended distance. Let `K : ι → set M` be a locally
finite family of closed sets, let `U : ι → set M` be a family of open sets such that `K i ⊆ U i` for
all `i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and
`x ∈ K i`, we have `emetric.closed_ball x (δ x) ⊆ U i`. -/
lemma emetric.exists_smooth_forall_closed_ball_subset {M} [emetric_space M] [charted_space H M]
[smooth_manifold_with_corners I M] [sigma_compact_space M] {K : ι → set M}
{U : ι → set M} (hK : ∀ i, is_closed (K i)) (hU : ∀ i, is_open (U i)) (hKU : ∀ i, K i ⊆ U i)
(hfin : locally_finite K) :
∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧
∀ i (x ∈ K i), emetric.closed_ball x (ennreal.of_real (δ x)) ⊆ U i :=
by simpa only [mem_inter_eq, forall_and_distrib, mem_preimage, mem_Inter, @forall_swap ι M]
using exists_smooth_forall_mem_convex_of_local_const I
emetric.exists_forall_closed_ball_subset_aux₂
(emetric.exists_forall_closed_ball_subset_aux₁ hK hU hKU hfin)
/-- Let `M` be a smooth σ-compact manifold with a metric. Let `K : ι → set M` be a locally finite
family of closed sets, let `U : ι → set M` be a family of open sets such that `K i ⊆ U i` for all
`i`. Then there exists a positive smooth function `δ : M → ℝ≥0` such that for any `i` and `x ∈ K i`,
we have `metric.closed_ball x (δ x) ⊆ U i`. -/
lemma metric.exists_smooth_forall_closed_ball_subset {M} [metric_space M] [charted_space H M]
[smooth_manifold_with_corners I M] [sigma_compact_space M] {K : ι → set M}
{U : ι → set M} (hK : ∀ i, is_closed (K i)) (hU : ∀ i, is_open (U i)) (hKU : ∀ i, K i ⊆ U i)
(hfin : locally_finite K) :
∃ δ : C^∞⟮I, M; 𝓘(ℝ, ℝ), ℝ⟯, (∀ x, 0 < δ x) ∧ ∀ i (x ∈ K i), metric.closed_ball x (δ x) ⊆ U i :=
begin
rcases emetric.exists_smooth_forall_closed_ball_subset I hK hU hKU hfin with ⟨δ, hδ0, hδ⟩,
refine ⟨δ, hδ0, λ i x hx, _⟩,
rw [← metric.emetric_closed_ball (hδ0 _).le],
exact hδ i x hx
end
|
4ced0812fb8502c5190a0f17ba3339f0323371a1 | 624f6f2ae8b3b1adc5f8f67a365c51d5126be45a | /tests/lean/run/ptrAddr.lean | 640fd1ede1c24e8865667f99a614928fd510ad72 | [
"Apache-2.0"
] | permissive | mhuisi/lean4 | 28d35a4febc2e251c7f05492e13f3b05d6f9b7af | dda44bc47f3e5d024508060dac2bcb59fd12e4c0 | refs/heads/master | 1,621,225,489,283 | 1,585,142,689,000 | 1,585,142,689,000 | 250,590,438 | 0 | 2 | Apache-2.0 | 1,602,443,220,000 | 1,585,327,814,000 | C | UTF-8 | Lean | false | false | 463 | lean | axiom TrustMe {p : Prop} : p
def x := (1, 2)
def y := x
@[noinline] def mk (v : Nat) := (v, v+1)
#eval withPtrAddr x (fun a => dbgTrace (">> " ++ toString a) $ fun _ => 0) TrustMe
#eval withPtrEq x y (fun _ => dbgTrace (">> " ++ toString x ++ " == " ++ toString y) $ fun _ => x == y) TrustMe -- should not print message
#eval withPtrEq x (mk 1) (fun _ => dbgTrace (">> " ++ toString x ++ " == " ++ toString y) $ fun _ => x == y) TrustMe -- should print message
|
dc99fa6de97098879f5e3acde2224ee36c6d3cdd | 5e3548e65f2c037cb94cd5524c90c623fbd6d46a | /src_icannos_totilas/groupes/cpge_groupe_9_a.lean | 0713a8e73bd49e8990ef1ee7ba0bdd88d3f57064 | [] | no_license | ahayat16/lean_exos | d4f08c30adb601a06511a71b5ffb4d22d12ef77f | 682f2552d5b04a8c8eb9e4ab15f875a91b03845c | refs/heads/main | 1,693,101,073,585 | 1,636,479,336,000 | 1,636,479,336,000 | 415,000,441 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 201 | lean | import group_theory.subgroup
theorem cpge_groupe_9_a {G1 : Type*} [group G1] {G2 : Type*} [group G2]
(f : G1 →* G2) : ∀ (a : G1), ( (f a = 1) → (∀ (x : G1), f (x * a * x⁻¹) = 1)) := sorry
|
da749d6a0005de7a91aed07c0a2b3141272c087b | 8c3de0f4873364ba4a1bb0f7791f3a52876ecea2 | /src/maclane_birkhoff_survey_modern_algebra_sections_1.1_to_1.2.lean | 0f1d8d2025bd477456512c21c6adce02225985c0 | [
"Apache-2.0"
] | permissive | catskillsresearch/grundbegriffe | 7c2d410fabe59b8cbc19af694ec5cf30ee3ffa93 | e8aa4fe66308d9e6e85d5bdedd9d981af99f17f7 | refs/heads/master | 1,677,131,919,219 | 1,611,887,691,000 | 1,611,887,691,000 | 318,888,979 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 25,712 | lean | import algebra.ring.basic
import algebra.algebra.subalgebra
import algebra.group.defs
import analysis.special_functions.pow
import data.nat.parity
import data.nat.prime
import data.pnat.basic
import data.int.parity
import data.zmod.basic
import data.rat.basic
import data.real.basic
import data.real.irrational
import data.zsqrtd.basic
import ring_theory.subring
import tactic
import tactic.slim_check
import data.equiv.ring
import algebra.punit_instances
open rat
open nat
open tactic
open real
-- Garrett Birkhoff and Saunders Mac Lane: A survey of modern algebra, 4th ed
namespace ch1A
-- 1.1 Commutative Rings
-- Integral domain
#check integral_domain
-- An integral domain of interest for number theory consists of all a + b √ 2, a and b ∈ ℤ
#check ℤ√2
-- 1.2. Elementary Properties of Commutative Rings
universe u
variables {α : Type u} [comm_ring α] {a b c d z x₁ x₂ : α}
lemma rule_1 : (a+b)*c=a*c+b*c := add_mul _ _ _
lemma rule_2_plus : (0 + a = a) := zero_add _
lemma rule_2_times : (1 * a = a) := one_mul _
lemma rule_3 : (∀ (a : α), a + z = a) → z = 0 :=
begin
intro h1,
have h2 := h1 0,
exact add_left_eq_self.mp (congr_arg (has_add.add z) (congr_arg (has_add.add z) (h1 z))),
end
lemma rule_4 : a + b = a + c → b = c := (add_right_inj a).mp
lemma rule_5 : a + x₁ = 0 → a + x₂ = 0 → x₁ = x₂ :=
begin
intro h1,
intro h2,
exact neg_unique h1 h2,
end
lemma rule_6 : a + x₁ = b → a + x₂ = b → x₁ = x₂ :=
begin
intro h1,
intro h2,
rw ← h1 at h2,
exact rule_4 (eq.symm h2),
end
lemma rule_7a : a * 0 = 0 := mul_zero a
lemma rule_7b : 0 * a = 0 := zero_mul a
lemma rule_8 : (∀ (a : α), a*z = a) → z = 1 :=
begin
intro h1,
exact (eq_one_iff_eq_one_of_mul_eq_one (h1 1)).mp rfl,
end
lemma rule_9 : (-a)*(-b) = a*b := neg_mul_neg _ _
/- Theorem 1. The cancellation law of multiplication for integral domains
is equivalent in a commutative ring to the assertion that
a product of nonzero factors is not 0. -/
theorem theorem_1 :
(∀ a b c : α, c ≠ 0 → c*a = c*b → a = b) ↔
(∀ a b : α, a ≠ 0 → b ≠ 0 → a * b ≠ 0) :=
begin
split,
{ intros H a b ha hb ab,
refine hb (H _ _ _ ha _),
have hc := mul_zero a,
rw hc,
rw ab,
},
{ intros H a b c hc e,
rw ← sub_eq_zero at e ⊢,
refine by_contra (λ h, _),
refine H c (a - b) hc h _,
have hd := left_distrib c a (-b),
have he := sub_eq_add_neg a b,
rw ← he at hd,
have hf := norm_num.mul_pos_neg c b (c * b) rfl,
rw hf at hd,
have hg := sub_eq_add_neg (c*a) (c*b),
rw ← hg at hd,
rw hd,
exact e,
},
end
#check left_distrib c a (-b)
/- A subdomain of an integral domain D is a subset of D
which is also an integral domain, for the same operations of addition and
multiplication. -/
variables {R : Type*} [integral_domain R] {D : subring R}
example : integral_domain D := subring.subring.domain D
-- Exercises for section 1.2
lemma ex1a : (a+b)*(c+d) = (a*c+b*c) + (a*d + b*d) :=
begin
ring,
end
lemma ex1b1 : a+(b+(c+d))=(a+b)+(c+d) :=
begin
ring,
end
lemma ex1b2 : (a+b)+(c+d)=((a+b)+c)+d :=
begin
ring,
end
lemma ex1c : a+(b+c) = (c+a)+b:=
begin
ring,
end
lemma ex1d : a*(b*c)=c*(a*b) :=
begin
ring,
end
lemma ex1e : a*(b+(c+d))=(a*b+a*c)+a*d :=
begin
ring,
end
lemma ex1f : (a+b)*(c+d) = (a*c+b*c) + (a*d + b*d) :=
begin
ring,
end
#check rule_8
lemma ex2b : 1*1=1 :=
begin
ring,
end
/- Exercise 2c. The only idempotents of an integral domain are 0 and 1. -/
variables {β : Type u} [integral_domain β] {x : β}
lemma ex2c : ∀ (x : β), x*x = x → (x = 0 ∨ x = 1) :=
begin
intro x,
intro h1,
conv_rhs at h1 { rw ← mul_one x, },
have h2 := sub_eq_zero.mpr h1,
rw (mul_sub x x 1).symm at h2,
have h3 := mul_eq_zero.mp h2,
by_cases h4 : x = 0,
by_cases h5 : x-1 = 0,
exact or.inl h4,
exact or.inl h4,
refine or.inr _,
exact (mul_right_inj' h4).mp h1,
end
lemma ex2c_JC (h1 : x * x = x) : x = 0 ∨ x = 1 := -- Johan Commelin
by simp [← @sub_eq_zero β _ _ 1, ← mul_eq_zero, mul_sub, h1]
lemma ex2c_KL {x : β} (h1 : x * x = x) : x = 0 ∨ x = 1 := -- Kenny Lau
or_iff_not_imp_left.2 $ λ hx, mul_left_cancel' hx $ h1.trans (mul_one x).symm
lemma ex3a : -(-a) = a :=
begin
ring,
end
lemma ex3b : -(0 : α ) = 0 :=
begin
ring,
end
lemma ex3c : -(a+b) = (-a) + (-b) :=
begin
ring,
end
lemma ex3d : -a = (-1)*a :=
begin
ring,
end
lemma ex3e1 : (-a)*b=a*(-b) :=
begin
ring,
end
lemma ex3e2 : a*(-b)=-(a*b) :=
begin
ring,
end
#check rule_9
lemma ex4 : (-1)*(-1) = (1:α) :=
begin
ring,
end
end ch1A
namespace ch1B
universe u
variables {α : Type u} [integral_domain α] {a b c d : α}
lemma ex5a: (a-b) + (c-d) = (a+c)-(b+d) :=
begin
ring,
end
lemma ex5b : (a-b)-(c-d) = (a+d)-(b+c) :=
begin
ring,
end
lemma ex5c : (a-b)*(c-d) = (a*c + b*d)-(a*d+b*c) :=
begin
ring,
end
lemma ex5d : a-b=c-d ↔ a+d=b+c :=
begin
split,
{
intro h,
apply_fun (λ t, t+b+d) at h,
conv at h
begin
to_lhs,
rw sub_add_cancel,
end,
conv at h
begin
to_rhs,
rw sub_add_eq_add_sub,
rw sub_add,
rw sub_self,
rw sub_zero,
end,
have swap := add_comm c b,
rw swap at h,
assumption,
},
{
intro h,
apply_fun (λ t, t-b-d) at h,
conv at h
begin
to_lhs,
rw ← sub_add_eq_add_sub,
rw ← add_sub,
rw sub_self,
rw add_zero,
end,
conv at h
begin
to_rhs,
rw ← sub_add_eq_add_sub,
rw sub_self,
rw zero_add,
end,
assumption,
},
end
lemma ex5e : (a-b)*c = a*c - b*c :=
begin
ring,
end
instance (x : ℤ) : decidable (even x) :=
decidable_of_iff' _ even_iff_two_dvd
theorem ex6a : ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ even x := -- Mario Carneiro
λ ⟨S, h⟩, absurd ((h 1).1 S.one_mem) dec_trivial
theorem ex6b : ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ odd x :=
begin
intro h1,
cases h1 with S h,
have h2 := h 0,
have h3 := h2.1,
have h4 := S.zero_mem,
have h5 := h3 h4,
have h6 := (@int.odd_iff_not_even 0).1,
have h7 := h6 h5,
have h8 := absurd h7 dec_trivial,
exact h8,
end
theorem ex6c : ¬ ∃ s : subring ℤ, ∀ x, x ∈ s ↔ (0:ℤ) < x :=
begin
intro h1,
cases h1 with S h,
have h2 := h (0:ℤ),
have h3 := subring.zero_mem S,
have h4 := h2.1,
have h5 := h4 h3,
have h6 := lt_irrefl (0:ℤ),
exact h6 h5,
end
-- Mario Carneiro
theorem ex6d : ¬ ∃ s : subring ℝ, ∀ x : ℝ, x ∈ s ↔ ∃ a b : ℤ, x = a + b * 5 ^ (1/4:ℝ) :=
begin
rintro ⟨S, h⟩,
simp only [one_div] at h,
have hY : (5 ^ (2⁻¹:ℝ) : ℝ) = (5 ^ (4⁻¹:ℝ) : ℝ) * (5 ^ (4⁻¹:ℝ) : ℝ),
by rw ← real.rpow_add; norm_num,
have hX : (5 : ℝ) = (5 ^ (2⁻¹:ℝ) : ℝ) * (5 ^ (2⁻¹:ℝ) : ℝ),
by rw ← real.rpow_add; norm_num,
set X := (5 ^ (2⁻¹:ℝ):ℝ) with eX,
have : X ∈ S,
{ have : (5 ^ (4⁻¹:ℝ) : ℝ) ∈ S := (h _).2 ⟨0, 1, by simp⟩,
have := S.mul_mem this this,
rwa hY },
rcases (h _).1 this with ⟨a, b, e⟩, clear this,
rw ← sub_eq_iff_eq_add' at e,
have := congr (congr_arg (*) e) e,
rw [mul_mul_mul_comm, ← hY, sub_mul, mul_sub, ← hX, ← sub_eq_zero] at this,
have : X * (2 * a + b * b : ℤ) = (5 + a * a : ℤ),
{ symmetry, simp [← sub_eq_zero], refine eq.trans (by ring) this },
by_cases h0 : ((2 * a + b * b : ℤ) : ℝ) = 0,
{ simp [h0] at this, linarith only [mul_self_nonneg ((a:ℤ):ℝ), this] },
rw ← eq_div_iff h0 at this,
refine (irrational_iff_ne_rational _).1 _ _ _ this,
rw ← show real.sqrt 5 = X, by rw [eX, real.sqrt_eq_rpow, one_div],
exact_mod_cast nat.prime.irrational_sqrt (by norm_num : nat.prime 5),
end
/- Set s is closed under addition and multiplication, so if
a b c d : ℤ
x = a + b * 9 ^ (1/4:ℝ)
y = c + d * 9 ^ (1/4:ℝ)
then
x + y = (a+c) + (b +d)* 9 ^ (1/4:ℝ)
(a+c): ℤ
(b+d): ℤ
hence
(x+y)∈ s
and
9 ^ (1/4:ℝ) *9 ^ (1/4:ℝ) =(3:ℤ)
and
x *y=(a*c+b*d*3)+(a*d+b*c)* 9 ^ (1/4:ℝ)
(a*c+b*d*3): ℤ
(a*d+b*c): ℤ
hence
(x*y)∈ s
and hence
s : subring ℝ -/
-- Eric Wieser
/-- The image of `zsqrtd` in `ℝ`. -/
@[simps]
noncomputable def zsqrtd.to_real {d : ℤ } (h : 0 ≤ d) : ℤ√d →+* ℝ := {
to_fun := λ a, a.1 + a.2*real.sqrt d,
map_zero' := by simp,
map_add' := λ a b, by { simp, ring, },
map_one' := by simp,
map_mul' := λ a b, by {
have : (↑a.re + ↑a.im * real.sqrt d) * (↑b.re + ↑b.im * real.sqrt d) =
↑a.re * ↑b.re + (↑a.re * ↑b.im + ↑a.im * ↑b.re) * real.sqrt d
+ ↑a.im * ↑b.im * (real.sqrt d * real.sqrt d) := by ring,
simp [this, real.mul_self_sqrt (int.cast_nonneg.mpr h)],
ring, } }
-- Eric Wieser
abbreviation is_an_integral_domain {α : Type*} [ring α] (s : set α) := ∃ (sr : subring α) [integral_domain sr], s = sr
lemma nine_equals_3_times_3 : (9:ℝ)=(3:ℝ)*(3:ℝ) :=
begin
linarith,
end
lemma three_is_gt_0 : (0:ℝ) < (3:ℝ) :=
begin
linarith,
end
lemma three_is_gte_0 : (0:ℝ) ≤ (3:ℝ) :=
begin
linarith,
end
lemma sqrt_of_9_is_3 : (3:ℝ) = (real.sqrt (9:ℝ)) :=
begin
have h1 := nine_equals_3_times_3,
rw h1,
have h2 := three_is_gte_0,
have h3 := real.sqrt_mul_self h2,
rw ← h1 at h3,
rw ← h1,
exact eq.symm h3,
end
lemma half_plus_half_equals_1: (1/2:ℝ)+(1/2:ℝ)=1 :=
begin
linarith,
end
lemma x_equals_sqrtx_times_sqrtx (x:ℝ): 0 < x → x = x^(1/2:ℝ) * x^(1/2:ℝ) :=
begin
intro h1,
have h2 := real.rpow_add h1,
have h3 := h2 (1/2) (1/2),
have h4 := half_plus_half_equals_1,
rw h4 at h3,
have h5 := real.rpow_one x,
rw h5 at h3,
exact h3,
end
lemma x_is_0 (x:ℝ) : x ≥ 0 → ¬(0 < x) → x = 0 :=
begin
intro h1,
intro h2,
linarith,
end
lemma half_ne_0 : (1/2:ℝ) ≠ (0:ℝ) :=
begin
linarith,
end
lemma zero_le_0 : (0:ℝ) ≤ (0:ℝ) :=
begin
linarith,
end
lemma sqrt_0_equals_0 : real.sqrt 0 = 0 :=
begin
have h1 := zero_le_0,
exact real.sqrt_eq_zero_of_nonpos h1,
end
lemma x_gt_0_implies_sqrt_x_gt_0 (x:ℝ): x ≥ 0 → x^(1/2:ℝ) ≥ 0 :=
begin
intro h1,
exact real.rpow_nonneg_of_nonneg h1 (1 / 2),
end
lemma sqrt_x_equals_sqrt_x (x:ℝ) : x ≥ 0 → x^(1/2:ℝ) = real.sqrt x :=
begin
intro h,
have h1 := x_equals_sqrtx_times_sqrtx x,
by_cases h2 : 0 < x,
{
have h3 := h1 h2,
conv
begin
to_rhs,
rw h3,
end,
have h5 := x_gt_0_implies_sqrt_x_gt_0 x,
have h6 := h5 h,
have h4 := real.sqrt_mul_self h6,
exact eq.symm h4,
},
{
have h3 := x_is_0 x,
have h4 := h3 h,
have h5 := h4 h2,
rw h5,
have h6 := @real.zero_rpow (1/2:ℝ),
have h7 := half_ne_0,
have h8 := h6 h7,
rw h8,
have h9 := sqrt_0_equals_0,
exact eq.symm h9,
}
end
lemma x_mul_x_pow_y_equals_x_pow_y_plus_y (x y : ℝ) : 0 < x → (x * x)^y = x^(y+y) :=
begin
intro h,
have h1 := le_of_lt h,
have h2 := @real.mul_rpow x x y h1 h1,
rw h2,
have h3 := real.rpow_add h y y,
exact eq.symm h3,
end
lemma fourth_root_of_9_equals_sqrt_sqrt : (9:ℝ) ^ (1/4:ℝ) = real.sqrt (real.sqrt (9:ℝ)) :=
begin
have h1 := nine_equals_3_times_3,
have h2 := three_is_gt_0,
have h7 := three_is_gte_0,
have h3 := sqrt_of_9_is_3,
rw ← h3,
rw h1,
have h4 := sqrt_x_equals_sqrt_x (3:ℝ),
have h5 := h4 h7,
rw ← h5,
have h6 := x_mul_x_pow_y_equals_x_pow_y_plus_y 3 (1/4),
have h8 := h6 h2,
rw h8,
ring,
end
lemma fourth_root_of_nine_equals_sqrt_3 : (9:ℝ) ^ (1/4:ℝ) = real.sqrt 3 :=
begin
have h1 := fourth_root_of_9_equals_sqrt_sqrt,
rw h1,
have h2 := sqrt_of_9_is_3,
rw h2,
end
theorem ex6e : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=
begin
refine ⟨(zsqrtd.to_real (show 0 ≤ (3 : ℤ), by norm_num)).range, _, _⟩,
apply_instance,
ext,
rw [fourth_root_of_nine_equals_sqrt_3],
simp [zsqrtd.to_real],
split,
{
intro h1,
cases h1 with a ha,
cases ha with b hb,
use {re := a, im := b},
rw hb,
},
{
intro h1,
cases h1 with y hy,
rw ← hy,
use [y.re, y.im],
}
end
lemma useful : ((9 : ℝ) ^ (4⁻¹ : ℝ)) * (9 ^ (4⁻¹ : ℝ)) = 3 :=
begin
rw ← mul_rpow,
convert pow_nat_rpow_nat_inv (show (0 : ℝ) ≤ 3, by norm_num) (show 0 < 4, by norm_num) using 2,
all_goals {norm_num}
end
def A : subring ℝ :=
{ carrier := {x | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)},
one_mem' := ⟨1, 0, by simp⟩,
mul_mem' := begin
rintro _ _ ⟨a1, b1, rfl⟩ ⟨a2, b2, rfl⟩,
use [a1 * a2 + 3 * b1 * b2, a1 * b2 + a2 * b1],
simp [mul_add, add_mul, mul_assoc, mul_left_comm, useful],
ring,
end,
zero_mem' := ⟨0, 0, by simp⟩,
add_mem' := by { rintro _ _ ⟨a1, b1, rfl⟩ ⟨a2, b2, rfl⟩,
use [a1 + a2, b1 + b2],
simp, ring },
neg_mem' := by { rintro _ ⟨a, b, rfl⟩,
use [-a, -b],
simp, ring },
}
theorem ex6e_kevin_buzzard : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=
⟨A, infer_instance, rfl⟩
theorem ex6e_mario_carneiro : is_an_integral_domain {x : ℝ | ∃ a b : ℤ, x = a + b * (9:ℝ) ^ (1/4:ℝ)} :=
begin
refine ⟨(zsqrtd.to_real (show 0 ≤ (3 : ℤ), by norm_num)).range, _, _⟩,
apply_instance,
ext,
rw calc (9:ℝ) ^ (1/4:ℝ) = (9:ℝ)^((2:ℕ)⁻¹ * (1/2) : ℝ) : by norm_num
... = ((3^2:ℝ)^((2:ℕ)⁻¹:ℝ)) ^ (1/2:ℝ) : by rw real.rpow_mul; norm_num
... = real.sqrt 3 : by rw [real.pow_nat_rpow_nat_inv, real.sqrt_eq_rpow]; norm_num,
simp [zsqrtd.to_real],
exact ⟨λ ⟨x,y,h⟩, ⟨⟨x,y⟩, h.symm⟩, λ ⟨⟨x,y⟩,h⟩, ⟨x,y, h.symm⟩⟩,
end
-- Exercise 6F
-- Mario Carneiro, Hanting Zhang
lemma eq_two_pow_of_dvd_two_pow {a n : ℕ} : a ∣ 2 ^ n → ∃ m : ℕ, a = 2 ^ m :=
begin
intro h1,
have h2 := (@dvd_prime_pow 2 nat.prime_two n a).1 h1,
cases h2 with m hm,
cases hm with H hH,
finish,
end
lemma succ_def (m: ℕ) : m.succ = m + 1 := rfl
lemma pow_two_ne_zero (n : ℕ): 2^n ≠ 0 :=
begin
induction n with d hd,
simp,
rw (succ_def d),
rw (pow_succ 2 d),
simp,
intro h,
finish,
end
-- Mario Carneiro
lemma plus_injective {a b : ℚ} {n m : ℕ} (ha : a.denom = 2 ^ n) (hb : b.denom = 2 ^ m) :
∃ k : ℕ, (a + b).denom = 2 ^ k :=
begin
apply @eq_two_pow_of_dvd_two_pow _ (n + m),
rw [rat.add_num_denom, ← int.coe_nat_mul, ha, hb, ← pow_add, ← int.coe_nat_dvd],
apply rat.denom_dvd,
end
-- Mario Carneiro
lemma mul_injective {a b : ℚ} {n m : ℕ} (ha : a.denom = 2 ^ n) (hb : b.denom = 2 ^ m) :
∃ k : ℕ, (a * b).denom = 2 ^ k :=
begin
apply @eq_two_pow_of_dvd_two_pow _ (n + m),
rw [rat.mul_num_denom, ha, hb, ← pow_add, ← int.coe_nat_dvd],
apply rat.denom_dvd,
end
noncomputable def B : subring ℚ :=
{
carrier := {x : ℚ | ∃ n : ℕ, x.denom = 2 ^ n },
one_mem' /- (1 : M) ∈ carrier) -/ :=
begin
rw set.mem_set_of_eq,
use 0,
simp,
end,
mul_mem' /- {a b} : a ∈ carrier → b ∈ carrier → a * b ∈ carrier) -/ :=
begin
intros a b h1 h2,
rw set.mem_set_of_eq at h1,
rw set.mem_set_of_eq at h2,
cases h1 with n hn,
cases h2 with m hm,
rw set.mem_set_of_eq,
exact (mul_injective hn hm),
end,
zero_mem' /- (0 : M) ∈ carrier -/ :=
begin
rw set.mem_set_of_eq,
use 0,
simp,
exact rfl,
end,
add_mem' /- {a b} : a ∈ carrier → b ∈ carrier → a + b ∈ carrier -/:=
begin
intro a,
intro b,
intro h1,
intro h2,
rw set.mem_set_of_eq at h1,
rw set.mem_set_of_eq at h2,
cases h1 with n hn,
cases h2 with m hm,
rw set.mem_set_of_eq,
exact (plus_injective hn hm),
end,
neg_mem' /- {x} : x ∈ carrier →d -x ∈ carrier -/:=
begin
intro x,
intro h1,
rw set.mem_set_of_eq at h1,
cases h1 with n hn,
rw set.mem_set_of_eq,
use n,
simp,
exact hn,
end,
}
theorem ex6f : is_an_integral_domain {x : ℚ | ∃ n : ℕ, x.denom = 2 ^ n } :=
⟨B, infer_instance, rfl⟩
namespace ex7A
inductive R
| zero
| one
open R
def R.add : R → R → R
| zero zero := zero
| zero one := one
| one zero := one
| one one := zero
def R.mul : R → R → R
| zero zero := zero
| zero one := zero
| one zero := zero
| one one := one
def R.neg : R → R
| zero := zero
| one := one
instance : has_add R := ⟨R.add⟩
instance : has_mul R := ⟨R.mul⟩
instance : has_zero R := ⟨zero⟩
instance : has_one R := ⟨one⟩
instance : has_neg R := ⟨R.neg⟩
theorem R.exists_pair_ne : ∃ (x y : R), x ≠ y :=
begin
use [R.zero, R.one],
end
theorem R.zero_add (a : R): 0 + a = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.add_zero (a : R): a + 0 = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.one_mul (a : R): 1 * a = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.mul_one (a : R): a * 1 = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.add_assoc (a b c : R): a + b + c = a + (b + c) :=
begin
cases a,
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
end
theorem R.add_left_neg (a : R): -a + a = 0 :=
begin
cases a,
repeat { exact rfl },
end
theorem R.add_comm (a b : R): a + b = b + a :=
begin
cases a,
cases b,
repeat { exact rfl },
cases b,
repeat { exact rfl },
end
theorem R.mul_assoc (a b c : R): a * b * c = a * (b * c) :=
begin
cases a,
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
end
theorem R.left_distrib (a b c : R): a * (b + c) = a * b + a * c :=
begin
cases a,
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
end
theorem R.right_distrib (a b c : R): (a + b) * c = a * c + b * c :=
begin
cases a,
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
cases b,
cases c,
repeat { exact rfl },
cases c,
repeat { exact rfl },
end
theorem R.mul_comm (a b : R): a * b = b * a :=
begin
cases a,
cases b,
repeat { exact rfl },
cases b,
repeat { exact rfl },
end
theorem R.eq_zero_or_eq_zero_of_mul_eq_zero (a b : R) (h: a * b = 0): a = 0 ∨ b = 0:=
begin
cases a,
cases b,
left,
exact rfl,
left,
exact rfl,
cases b,
right,
exact rfl,
exfalso,
finish,
end
instance ex7a_kyle_miller : integral_domain R :=
{
zero := R.zero,
one := R.one,
add := R.add,
mul := R.mul,
add_assoc := R.add_assoc,
zero_add := R.zero_add,
add_zero := R.add_zero,
neg := R.neg,
add_left_neg := R.add_left_neg,
add_comm := R.add_comm,
one_mul := R.one_mul,
mul_assoc := R.mul_assoc,
mul_one := R.mul_one ,
left_distrib := R.left_distrib,
right_distrib := R.right_distrib,
mul_comm := R.mul_comm,
exists_pair_ne := R.exists_pair_ne,
eq_zero_or_eq_zero_of_mul_eq_zero := R.eq_zero_or_eq_zero_of_mul_eq_zero,
}
instance : fact (nat.prime 2) := nat.prime_two
-- this is `@field.to_integral_domain _ (zmod.field 2)` under the hood
instance ex7a_eric_wieser : integral_domain (zmod 2) := by apply_instance
end ex7A
namespace ex7b
inductive R
| zero
open R
def R.add : R → R → R
| zero zero := zero
def R.mul : R → R → R
| zero zero := zero
def R.neg : R → R
| zero := zero
instance : has_add R := ⟨R.add⟩
instance : has_mul R := ⟨R.mul⟩
instance : has_zero R := ⟨zero⟩
instance : has_neg R := ⟨R.neg⟩
theorem R.zero_add (a : R): 0 + a = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.add_zero (a : R): a + 0 = a :=
begin
cases a,
repeat { exact rfl },
end
theorem R.add_assoc (a b c : R): a + b + c = a + (b + c) :=
begin
cases a,
cases b,
cases c,
refl,
end
theorem R.add_left_neg (a : R): -a + a = 0 :=
begin
cases a,
refl,
end
theorem R.add_comm (a b : R): a + b = b + a :=
begin
cases a,
cases b,
refl,
end
theorem R.mul_assoc (a b c : R): a * b * c = a * (b * c) :=
begin
cases a,
cases b,
cases c,
refl,
end
theorem R.left_distrib (a b c : R): a * (b + c) = a * b + a * c :=
begin
cases a,
cases b,
cases c,
refl,
end
theorem R.right_distrib (a b c : R): (a + b) * c = a * c + b * c :=
begin
cases a,
cases b,
cases c,
refl,
end
theorem R.mul_comm (a b : R): a * b = b * a :=
begin
cases a,
cases b,
refl,
end
theorem R.eq_zero_or_eq_zero_of_mul_eq_zero (a b : R) (h: a * b = 0): a = 0 ∨ b = 0:=
begin
cases a,
cases b,
left,
refl,
end
end ex7b
lemma ex8a_eric_wieser {S: Type*} [CR: comm_ring S]
[NZD: no_zero_divisors S] (h : (0 : S) = 1) : S ≃+* unit :=
begin
refine ring_equiv.symm _,
refine {to_fun := _, inv_fun := _, left_inv := _, right_inv := _, map_mul' := _, map_add' := _},
intro h,
exact ring.one,
intro h1,
exact (),
rw function.left_inverse,
intro x,
exact unit.ext,
rw function.right_inverse,
rw function.left_inverse,
intro x,
exact eq_of_zero_eq_one h ring.one x,
intro u1,
intro u2,
ring,
exact eq_of_zero_eq_one h ring.one (ring.one * ring.one),
intro u1,
intro u2,
exact eq_of_zero_eq_one h ring.one (ring.one + ring.one),
end
def is_zero_ring (α : Type u) [ring α] : Prop := ∀ (x : α), x = 0
lemma ex8a_kyle_miller (S : Type u) [comm_ring S] [no_zero_divisors S] :
is_integral_domain S ∨ is_zero_ring S :=
begin
by_cases h: (1:S) ≠ (0:S),
fconstructor,
refine {exists_pair_ne := _, mul_comm := _, eq_zero_or_eq_zero_of_mul_eq_zero := _},
use [0,1],
refine ne_comm.mp _,
assumption,
exact mul_comm,
exact λ {a b : S}, mul_eq_zero.mp,
refine or.inr _,
rw is_zero_ring,
refine eq_zero_of_zero_eq_one _,
finish,
end
--exercise 8b: No
-- exercise 9:
namespace ex9
structure M := Mk :: (x : ℤ)
open M
def M.add (a b : M) := Mk (a.x + b.x)
def M.mul (a b : M) := Mk 0
def M.neg (a : M) := Mk (-a.x)
def M.zero : M := Mk 0
def M.one : M := Mk 1
instance : has_add M := ⟨M.add⟩
instance : has_mul M := ⟨M.mul⟩
instance : has_zero M := ⟨M.zero⟩
instance : has_one M := ⟨M.one⟩
instance : has_neg M := ⟨M.neg⟩
@[ext] lemma ext (a b : M) : a.x = b.x → a = b := -- Yakov Pechersky
by cases a; cases b; simp
theorem M.zero_add (a : M): (0:M) + a = a :=
begin
ext,
unfold has_zero.zero,
rw M.zero,
unfold has_add.add,
rw M.add,
simp [int.zero_add],
end
theorem M.exists_pair_ne : ∃ (x y : M), x ≠ y :=
begin
use [M.zero, M.one],
rw [M.zero, M.one],
simp,
end
theorem M.add_zero (a : M): a + 0 = a :=
begin
ext,
unfold has_zero.zero,
rw M.zero,
unfold has_add.add,
rw M.add,
simp [int.zero_add],
end
theorem M.add_assoc (a b c : M): a + b + c = a + (b + c) :=
begin
ext,
unfold has_add.add,
repeat { rw M.add },
finish,
end
theorem M.add_left_neg (a : M): -a + a = 0 :=
begin
ext,
unfold has_neg.neg,
unfold has_add.add,
rw M.neg,
rw M.add,
finish,
end
theorem M.add_comm (a b : M): a + b = b + a :=
begin
ext,
unfold has_add.add,
repeat { rw M.add },
finish,
end
theorem M.mul_assoc (a b c : M): a * b * c = a * (b * c) :=
begin
ext,
unfold has_mul.mul,
repeat { rw M.mul },
end
theorem M.left_distrib (a b c : M): a * (b + c) = a * b + a * c :=
begin
ext,
unfold has_mul.mul,
unfold has_add.add,
repeat { rw M.add },
repeat { rw M.mul },
finish,
end
theorem M.right_distrib (a b c : M): (a + b) * c = a * c + b * c :=
begin
ext,
unfold has_mul.mul,
unfold has_add.add,
repeat { rw M.add },
repeat { rw M.mul },
finish,
end
theorem M.mul_comm (a b : M): a * b = b * a :=
begin
ext,
unfold has_mul.mul,
repeat { rw M.mul },
end
lemma M.not_one_mul_or_mul_one: (1:M) * (1:M) ≠ (1:M):=
begin
unfold has_one.one,
unfold has_mul.mul,
rw M.one,
rw M.mul,
finish,
end
lemma M.not_eq_zero_or_eq_zero_of_mul_eq_zero : ¬∀ (a b : M), a * b = (0:M) → (a = (0:M) ∨ b = (0:M)) :=
begin
unfold has_mul.mul,
unfold has_zero.zero,
rw M.zero,
simp at *,
use (1:M),
use (1:M),
rw M.mul,
split,
simp,
intro h,
simp at *,
unfold has_one.one at h,
rw M.one at h,
simp at h,
assumption,
end
end ex9
namespace ex10
def g (x: ℤ ) := x / x
def f (x: ℤ ) := x - 1
lemma two_minus_one_eq_1 : (2:ℤ)-(1:ℤ) = (1:ℤ) :=
begin
ring,
end
theorem f_ne_zero : ∃ x : ℤ, f x ≠ 0 :=
begin
use (2:ℤ),
rw f,
rw two_minus_one_eq_1,
finish,
end
theorem g_ne_zero : ∃ x : ℤ, g x ≠ 0 :=
begin
use 1,
rw g,
simp,
end
theorem fg_zero (x : ℕ ) (h: x ≠ 0): (f ∘ g) x = 0 :=
begin
rw function.comp,
simp,
rw g,
rw f,
finish,
end
end ex10
end ch1B
-- 1.3. Properties of Ordered Domains
-- Exercises for section 1.3
-- 1.4. Well-Ordering Principle
-- Exercises for section 1.4
-- 1.5. Finite Induction; Laws of Exponents
-- Exercises for section 1.5
-- 1.6. Divisibility
-- Exercises for section 1.6
-- 1.7. The Euclidean Algorithm
-- Exercises for section 1.7
-- 1.8. Fundamental Theorem of Arithmetic
-- Exercises for section 1.8
-- 1.9. Congruences
-- Exercises for section 1.9
-- 1.10. The Rings ℤn
-- Exercises for section 1.10
-- 1.11. Sets, Functions, and Relations
-- Exercises for section 1.11
-- 1.12. Isomorphisms and Automorphisms
-- Exercises for section 1.12
|
f29ebf74edf9f21ae8ba71efe31a631589c974a1 | 0c9bf7cb6a1c54d29b2ccab41edca8401372b526 | /imp.lean | fb559a2c1f70530e769c4f4df796e540a360e21e | [] | no_license | akuhlens/lemur | 3a79e61478f6e1b52515cf1dd7cf825d32ad8b9e | deea493aa6bcf3ad4f4fa1d27f325d0b75ba9e79 | refs/heads/master | 1,585,400,588,851 | 1,536,694,311,000 | 1,536,694,311,000 | 148,361,116 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 855 | lean | inductive aexp : Type
| ANum : nat -> aexp
| APlus : aexp -> aexp -> aexp
| AMinus : aexp -> aexp -> aexp
| AMult : aexp -> aexp -> aexp
inductive bexp : Type
| BTrue : bexp
| BFalse : bexp
| BEq : aexp -> aexp -> bexp
| BLe : aexp -> aexp -> bexp
| BNot : bexp -> bexp
| BAnd : bexp -> bexp -> bexp.
open aexp bexp
def aeval : aexp -> nat
|(ANum n) := n
|(APlus a1 a2) := (aeval a1) + (aeval a2)
|(AMinus a1 a2):= (aeval a1) - (aeval a2)
|(AMult a1 a2) := (aeval a1) * (aeval a2)
example : aeval (APlus (ANum 2) (ANum 2)) = 4 := rfl
def beval : bexp -> bool
| BTrue := true
| BFalse := false
|(BEq a1 a2) := (aeval a1) = (aeval a2)
|(BLe a1 a2) := (aeval a1) <= (aeval a2)
|(BNot b1) := bnot $ beval b1
|(BAnd b1 b2) := (beval b1) && (beval b2)
example : beval (BEq (APlus (ANum 2) (ANum 3)) (ANum 5)) = true := rfl
|
ae2d626610274ac0a0b5e857fb912fec81b8214c | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/ring_theory/discrete_valuation_ring/basic.lean | 27a78c164a18bab5287aa7a435f90a9c9a027959 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 17,595 | lean | /-
Copyright (c) 2020 Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard
-/
import ring_theory.principal_ideal_domain
import ring_theory.ideal.local_ring
import ring_theory.multiplicity
import ring_theory.valuation.basic
import linear_algebra.adic_completion
/-!
# Discrete valuation rings
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file defines discrete valuation rings (DVRs) and develops a basic interface
for them.
## Important definitions
There are various definitions of a DVR in the literature; we define a DVR to be a local PID
which is not a field (the first definition in Wikipedia) and prove that this is equivalent
to being a PID with a unique non-zero prime ideal (the definition in Serre's
book "Local Fields").
Let R be an integral domain, assumed to be a principal ideal ring and a local ring.
* `discrete_valuation_ring R` : a predicate expressing that R is a DVR
### Definitions
* `add_val R : add_valuation R part_enat` : the additive valuation on a DVR.
## Implementation notes
It's a theorem that an element of a DVR is a uniformizer if and only if it's irreducible.
We do not hence define `uniformizer` at all, because we can use `irreducible` instead.
## Tags
discrete valuation ring
-/
open_locale classical
universe u
open ideal local_ring
/-- An integral domain is a *discrete valuation ring* (DVR) if it's a local PID which
is not a field. -/
class discrete_valuation_ring (R : Type u) [comm_ring R] [is_domain R]
extends is_principal_ideal_ring R, local_ring R : Prop :=
(not_a_field' : maximal_ideal R ≠ ⊥)
namespace discrete_valuation_ring
variables (R : Type u) [comm_ring R] [is_domain R] [discrete_valuation_ring R]
lemma not_a_field : maximal_ideal R ≠ ⊥ := not_a_field'
/-- A discrete valuation ring `R` is not a field. -/
lemma not_is_field : ¬ is_field R :=
local_ring.is_field_iff_maximal_ideal_eq.not.mpr (not_a_field R)
variable {R}
open principal_ideal_ring
theorem irreducible_of_span_eq_maximal_ideal {R : Type*} [comm_ring R] [local_ring R] [is_domain R]
(ϖ : R) (hϖ : ϖ ≠ 0) (h : maximal_ideal R = ideal.span {ϖ}) : irreducible ϖ :=
begin
have h2 : ¬(is_unit ϖ) := show ϖ ∈ maximal_ideal R,
from h.symm ▸ submodule.mem_span_singleton_self ϖ,
refine ⟨h2, _⟩,
intros a b hab,
by_contra' h,
obtain ⟨ha : a ∈ maximal_ideal R, hb : b ∈ maximal_ideal R⟩ := h,
rw [h, mem_span_singleton'] at ha hb,
rcases ha with ⟨a, rfl⟩,
rcases hb with ⟨b, rfl⟩,
rw (show a * ϖ * (b * ϖ) = ϖ * (ϖ * (a * b)), by ring) at hab,
apply hϖ,
apply eq_zero_of_mul_eq_self_right _ hab.symm,
exact λ hh, h2 (is_unit_of_dvd_one ϖ ⟨_, hh.symm⟩)
end
/-- An element of a DVR is irreducible iff it is a uniformizer, that is, generates the
maximal ideal of R -/
theorem irreducible_iff_uniformizer (ϖ : R) :
irreducible ϖ ↔ maximal_ideal R = ideal.span {ϖ} :=
⟨λ hϖ, (eq_maximal_ideal (is_maximal_of_irreducible hϖ)).symm, λ h,
irreducible_of_span_eq_maximal_ideal ϖ (λ e, not_a_field R $ by rwa [h, span_singleton_eq_bot]) h⟩
lemma _root_.irreducible.maximal_ideal_eq {ϖ : R} (h : irreducible ϖ) :
maximal_ideal R = ideal.span {ϖ} :=
(irreducible_iff_uniformizer _).mp h
variable (R)
/-- Uniformisers exist in a DVR -/
theorem exists_irreducible : ∃ ϖ : R, irreducible ϖ :=
by {simp_rw [irreducible_iff_uniformizer],
exact (is_principal_ideal_ring.principal $ maximal_ideal R).principal}
/-- Uniformisers exist in a DVR -/
theorem exists_prime : ∃ ϖ : R, prime ϖ :=
(exists_irreducible R).imp (λ _, principal_ideal_ring.irreducible_iff_prime.1)
/-- an integral domain is a DVR iff it's a PID with a unique non-zero prime ideal -/
theorem iff_pid_with_one_nonzero_prime (R : Type u) [comm_ring R] [is_domain R] :
discrete_valuation_ring R ↔ is_principal_ideal_ring R ∧ ∃! P : ideal R, P ≠ ⊥ ∧ is_prime P :=
begin
split,
{ intro RDVR,
rcases id RDVR with ⟨Rlocal⟩,
split, assumption,
resetI,
use local_ring.maximal_ideal R,
split, split,
{ assumption },
{ apply_instance } ,
{ rintro Q ⟨hQ1, hQ2⟩,
obtain ⟨q, rfl⟩ := (is_principal_ideal_ring.principal Q).1,
have hq : q ≠ 0,
{ rintro rfl,
apply hQ1,
simp },
erw span_singleton_prime hq at hQ2,
replace hQ2 := hQ2.irreducible,
rw irreducible_iff_uniformizer at hQ2,
exact hQ2.symm } },
{ rintro ⟨RPID, Punique⟩,
haveI : local_ring R := local_ring.of_unique_nonzero_prime Punique,
refine {not_a_field' := _},
rcases Punique with ⟨P, ⟨hP1, hP2⟩, hP3⟩,
have hPM : P ≤ maximal_ideal R := le_maximal_ideal (hP2.1),
intro h, rw [h, le_bot_iff] at hPM, exact hP1 hPM }
end
lemma associated_of_irreducible {a b : R} (ha : irreducible a) (hb : irreducible b) :
associated a b :=
begin
rw irreducible_iff_uniformizer at ha hb,
rw [←span_singleton_eq_span_singleton, ←ha, hb],
end
end discrete_valuation_ring
namespace discrete_valuation_ring
variable (R : Type*)
/-- Alternative characterisation of discrete valuation rings. -/
def has_unit_mul_pow_irreducible_factorization [comm_ring R] : Prop :=
∃ p : R, irreducible p ∧ ∀ {x : R}, x ≠ 0 → ∃ (n : ℕ), associated (p ^ n) x
namespace has_unit_mul_pow_irreducible_factorization
variables {R} [comm_ring R] (hR : has_unit_mul_pow_irreducible_factorization R)
include hR
lemma unique_irreducible ⦃p q : R⦄ (hp : irreducible p) (hq : irreducible q) :
associated p q :=
begin
rcases hR with ⟨ϖ, hϖ, hR⟩,
suffices : ∀ {p : R} (hp : irreducible p), associated p ϖ,
{ apply associated.trans (this hp) (this hq).symm, },
clear hp hq p q,
intros p hp,
obtain ⟨n, hn⟩ := hR hp.ne_zero,
have : irreducible (ϖ ^ n) := hn.symm.irreducible hp,
rcases lt_trichotomy n 1 with (H|rfl|H),
{ obtain rfl : n = 0, { clear hn this, revert H n, exact dec_trivial },
simpa only [not_irreducible_one, pow_zero] using this, },
{ simpa only [pow_one] using hn.symm, },
{ obtain ⟨n, rfl⟩ : ∃ k, n = 1 + k + 1 := nat.exists_eq_add_of_lt H,
rw pow_succ at this,
rcases this.is_unit_or_is_unit rfl with H0|H0,
{ exact (hϖ.not_unit H0).elim, },
{ rw [add_comm, pow_succ] at H0,
exact (hϖ.not_unit (is_unit_of_mul_is_unit_left H0)).elim } }
end
variables [is_domain R]
/-- An integral domain in which there is an irreducible element `p`
such that every nonzero element is associated to a power of `p` is a unique factorization domain.
See `discrete_valuation_ring.of_has_unit_mul_pow_irreducible_factorization`. -/
theorem to_unique_factorization_monoid : unique_factorization_monoid R :=
let p := classical.some hR in
let spec := classical.some_spec hR in
unique_factorization_monoid.of_exists_prime_factors $ λ x hx,
begin
use multiset.replicate (classical.some (spec.2 hx)) p,
split,
{ intros q hq,
have hpq := multiset.eq_of_mem_replicate hq,
rw hpq,
refine ⟨spec.1.ne_zero, spec.1.not_unit, _⟩,
intros a b h,
by_cases ha : a = 0,
{ rw ha, simp only [true_or, dvd_zero], },
obtain ⟨m, u, rfl⟩ := spec.2 ha,
rw [mul_assoc, mul_left_comm, is_unit.dvd_mul_left _ _ _ (units.is_unit _)] at h,
rw is_unit.dvd_mul_right (units.is_unit _),
by_cases hm : m = 0,
{ simp only [hm, one_mul, pow_zero] at h ⊢, right, exact h },
left,
obtain ⟨m, rfl⟩ := nat.exists_eq_succ_of_ne_zero hm,
rw pow_succ,
apply dvd_mul_of_dvd_left dvd_rfl _ },
{ rw [multiset.prod_replicate], exact (classical.some_spec (spec.2 hx)), }
end
omit hR
lemma of_ufd_of_unique_irreducible [unique_factorization_monoid R]
(h₁ : ∃ p : R, irreducible p)
(h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) :
has_unit_mul_pow_irreducible_factorization R :=
begin
obtain ⟨p, hp⟩ := h₁,
refine ⟨p, hp, _⟩,
intros x hx,
cases wf_dvd_monoid.exists_factors x hx with fx hfx,
refine ⟨fx.card, _⟩,
have H := hfx.2,
rw ← associates.mk_eq_mk_iff_associated at H ⊢,
rw [← H, ← associates.prod_mk, associates.mk_pow, ← multiset.prod_replicate],
congr' 1,
symmetry,
rw multiset.eq_replicate,
simp only [true_and, and_imp, multiset.card_map, eq_self_iff_true,
multiset.mem_map, exists_imp_distrib],
rintros _ q hq rfl,
rw associates.mk_eq_mk_iff_associated,
apply h₂ (hfx.1 _ hq) hp,
end
end has_unit_mul_pow_irreducible_factorization
lemma aux_pid_of_ufd_of_unique_irreducible
(R : Type u) [comm_ring R] [is_domain R] [unique_factorization_monoid R]
(h₁ : ∃ p : R, irreducible p)
(h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) :
is_principal_ideal_ring R :=
begin
constructor,
intro I,
by_cases I0 : I = ⊥, { rw I0, use 0, simp only [set.singleton_zero, submodule.span_zero], },
obtain ⟨x, hxI, hx0⟩ : ∃ x ∈ I, x ≠ (0:R) := I.ne_bot_iff.mp I0,
obtain ⟨p, hp, H⟩ :=
has_unit_mul_pow_irreducible_factorization.of_ufd_of_unique_irreducible h₁ h₂,
have ex : ∃ n : ℕ, p ^ n ∈ I,
{ obtain ⟨n, u, rfl⟩ := H hx0,
refine ⟨n, _⟩,
simpa only [units.mul_inv_cancel_right] using I.mul_mem_right ↑u⁻¹ hxI, },
constructor,
use p ^ (nat.find ex),
show I = ideal.span _,
apply le_antisymm,
{ intros r hr,
by_cases hr0 : r = 0,
{ simp only [hr0, submodule.zero_mem], },
obtain ⟨n, u, rfl⟩ := H hr0,
simp only [mem_span_singleton, units.is_unit, is_unit.dvd_mul_right],
apply pow_dvd_pow,
apply nat.find_min',
simpa only [units.mul_inv_cancel_right] using I.mul_mem_right ↑u⁻¹ hr, },
{ erw submodule.span_singleton_le_iff_mem,
exact nat.find_spec ex, },
end
/--
A unique factorization domain with at least one irreducible element
in which all irreducible elements are associated
is a discrete valuation ring.
-/
lemma of_ufd_of_unique_irreducible
{R : Type u} [comm_ring R] [is_domain R] [unique_factorization_monoid R]
(h₁ : ∃ p : R, irreducible p)
(h₂ : ∀ ⦃p q : R⦄, irreducible p → irreducible q → associated p q) :
discrete_valuation_ring R :=
begin
rw iff_pid_with_one_nonzero_prime,
haveI PID : is_principal_ideal_ring R := aux_pid_of_ufd_of_unique_irreducible R h₁ h₂,
obtain ⟨p, hp⟩ := h₁,
refine ⟨PID, ⟨ideal.span {p}, ⟨_, _⟩, _⟩⟩,
{ rw submodule.ne_bot_iff,
refine ⟨p, ideal.mem_span_singleton.mpr (dvd_refl p), hp.ne_zero⟩, },
{ rwa [ideal.span_singleton_prime hp.ne_zero,
← unique_factorization_monoid.irreducible_iff_prime], },
{ intro I,
rw ← submodule.is_principal.span_singleton_generator I,
rintro ⟨I0, hI⟩,
apply span_singleton_eq_span_singleton.mpr,
apply h₂ _ hp,
erw [ne.def, span_singleton_eq_bot] at I0,
rwa [unique_factorization_monoid.irreducible_iff_prime, ← ideal.span_singleton_prime I0],
apply_instance, },
end
/--
An integral domain in which there is an irreducible element `p`
such that every nonzero element is associated to a power of `p`
is a discrete valuation ring.
-/
lemma of_has_unit_mul_pow_irreducible_factorization {R : Type u} [comm_ring R] [is_domain R]
(hR : has_unit_mul_pow_irreducible_factorization R) :
discrete_valuation_ring R :=
begin
letI : unique_factorization_monoid R := hR.to_unique_factorization_monoid,
apply of_ufd_of_unique_irreducible _ hR.unique_irreducible,
unfreezingI { obtain ⟨p, hp, H⟩ := hR, exact ⟨p, hp⟩, },
end
section
variables [comm_ring R] [is_domain R] [discrete_valuation_ring R]
variable {R}
lemma associated_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : irreducible ϖ) :
∃ (n : ℕ), associated x (ϖ ^ n) :=
begin
have : wf_dvd_monoid R := is_noetherian_ring.wf_dvd_monoid,
cases wf_dvd_monoid.exists_factors x hx with fx hfx,
unfreezingI { use fx.card },
have H := hfx.2,
rw ← associates.mk_eq_mk_iff_associated at H ⊢,
rw [← H, ← associates.prod_mk, associates.mk_pow, ← multiset.prod_replicate],
congr' 1,
rw multiset.eq_replicate,
simp only [true_and, and_imp, multiset.card_map, eq_self_iff_true,
multiset.mem_map, exists_imp_distrib],
rintros _ _ _ rfl,
rw associates.mk_eq_mk_iff_associated,
refine associated_of_irreducible _ _ hirr,
apply hfx.1,
assumption
end
lemma eq_unit_mul_pow_irreducible {x : R} (hx : x ≠ 0) {ϖ : R} (hirr : irreducible ϖ) :
∃ (n : ℕ) (u : Rˣ), x = u * ϖ ^ n :=
begin
obtain ⟨n, hn⟩ := associated_pow_irreducible hx hirr,
obtain ⟨u, rfl⟩ := hn.symm,
use [n, u],
apply mul_comm,
end
open submodule.is_principal
lemma ideal_eq_span_pow_irreducible {s : ideal R} (hs : s ≠ ⊥) {ϖ : R} (hirr : irreducible ϖ) :
∃ n : ℕ, s = ideal.span {ϖ ^ n} :=
begin
have gen_ne_zero : generator s ≠ 0,
{ rw [ne.def, ← eq_bot_iff_generator_eq_zero], assumption },
rcases associated_pow_irreducible gen_ne_zero hirr with ⟨n, u, hnu⟩,
use n,
have : span _ = _ := span_singleton_generator s,
rw [← this, ← hnu, span_singleton_eq_span_singleton],
use u
end
lemma unit_mul_pow_congr_pow {p q : R} (hp : irreducible p) (hq : irreducible q)
(u v : Rˣ) (m n : ℕ) (h : ↑u * p ^ m = v * q ^ n) :
m = n :=
begin
have key : associated (multiset.replicate m p).prod (multiset.replicate n q).prod,
{ rw [multiset.prod_replicate, multiset.prod_replicate, associated],
refine ⟨u * v⁻¹, _⟩,
simp only [units.coe_mul],
rw [mul_left_comm, ← mul_assoc, h, mul_right_comm, units.mul_inv, one_mul], },
have := multiset.card_eq_card_of_rel (unique_factorization_monoid.factors_unique _ _ key),
{ simpa only [multiset.card_replicate] },
all_goals
{ intros x hx,
unfreezingI { obtain rfl := multiset.eq_of_mem_replicate hx, assumption } },
end
lemma unit_mul_pow_congr_unit {ϖ : R} (hirr : irreducible ϖ) (u v : Rˣ) (m n : ℕ)
(h : ↑u * ϖ ^ m = v * ϖ ^ n) :
u = v :=
begin
obtain rfl : m = n := unit_mul_pow_congr_pow hirr hirr u v m n h,
rw ← sub_eq_zero at h,
rw [← sub_mul, mul_eq_zero] at h,
cases h,
{ rw sub_eq_zero at h, exact_mod_cast h },
{ apply (hirr.ne_zero (pow_eq_zero h)).elim, }
end
/-!
## The additive valuation on a DVR
-/
open multiplicity
/-- The `part_enat`-valued additive valuation on a DVR -/
noncomputable def add_val
(R : Type u) [comm_ring R] [is_domain R] [discrete_valuation_ring R] :
add_valuation R part_enat :=
add_valuation (classical.some_spec (exists_prime R))
lemma add_val_def (r : R) (u : Rˣ) {ϖ : R} (hϖ : irreducible ϖ) (n : ℕ) (hr : r = u * ϖ ^ n) :
add_val R r = n :=
by rw [add_val, add_valuation_apply, hr,
eq_of_associated_left (associated_of_irreducible R hϖ
(classical.some_spec (exists_prime R)).irreducible),
eq_of_associated_right (associated.symm ⟨u, mul_comm _ _⟩),
multiplicity_pow_self_of_prime (principal_ideal_ring.irreducible_iff_prime.1 hϖ)]
lemma add_val_def' (u : Rˣ) {ϖ : R} (hϖ : irreducible ϖ) (n : ℕ) :
add_val R ((u : R) * ϖ ^ n) = n :=
add_val_def _ u hϖ n rfl
@[simp] lemma add_val_zero : add_val R 0 = ⊤ :=
(add_val R).map_zero
@[simp] lemma add_val_one : add_val R 1 = 0 :=
(add_val R).map_one
@[simp] lemma add_val_uniformizer {ϖ : R} (hϖ : irreducible ϖ) : add_val R ϖ = 1 :=
by simpa only [one_mul, eq_self_iff_true, units.coe_one, pow_one, forall_true_left, nat.cast_one]
using add_val_def ϖ 1 hϖ 1
@[simp] lemma add_val_mul {a b : R} :
add_val R (a * b) = add_val R a + add_val R b :=
(add_val R).map_mul _ _
lemma add_val_pow (a : R) (n : ℕ) : add_val R (a ^ n) = n • add_val R a :=
(add_val R).map_pow _ _
lemma _root_.irreducible.add_val_pow {ϖ : R} (h : irreducible ϖ) (n : ℕ) :
add_val R (ϖ ^ n) = n :=
by rw [add_val_pow, add_val_uniformizer h, nsmul_one]
lemma add_val_eq_top_iff {a : R} : add_val R a = ⊤ ↔ a = 0 :=
begin
have hi := (classical.some_spec (exists_prime R)).irreducible,
split,
{ contrapose,
intro h,
obtain ⟨n, ha⟩ := associated_pow_irreducible h hi,
obtain ⟨u, rfl⟩ := ha.symm,
rw [mul_comm, add_val_def' u hi n],
exact part_enat.coe_ne_top _ },
{ rintro rfl,
exact add_val_zero }
end
lemma add_val_le_iff_dvd {a b : R} : add_val R a ≤ add_val R b ↔ a ∣ b :=
begin
have hp := classical.some_spec (exists_prime R),
split; intro h,
{ by_cases ha0 : a = 0,
{ rw [ha0, add_val_zero, top_le_iff, add_val_eq_top_iff] at h,
rw h,
apply dvd_zero },
obtain ⟨n, ha⟩ := associated_pow_irreducible ha0 hp.irreducible,
rw [add_val, add_valuation_apply, add_valuation_apply,
multiplicity_le_multiplicity_iff] at h,
exact ha.dvd.trans (h n ha.symm.dvd), },
{ rw [add_val, add_valuation_apply, add_valuation_apply],
exact multiplicity_le_multiplicity_of_dvd_right h }
end
lemma add_val_add {a b : R} :
min (add_val R a) (add_val R b) ≤ add_val R (a + b) :=
(add_val R).map_add _ _
end
instance (R : Type*) [comm_ring R] [is_domain R] [discrete_valuation_ring R] :
is_Hausdorff (maximal_ideal R) R :=
{ haus' := λ x hx,
begin
obtain ⟨ϖ, hϖ⟩ := exists_irreducible R,
simp only [← ideal.one_eq_top, smul_eq_mul, mul_one, smodeq.zero,
hϖ.maximal_ideal_eq, ideal.span_singleton_pow, ideal.mem_span_singleton,
← add_val_le_iff_dvd, hϖ.add_val_pow] at hx,
rwa [← add_val_eq_top_iff, part_enat.eq_top_iff_forall_le],
end }
end discrete_valuation_ring
|
3ea02dda6d665c007cf077900d85dbb479b07688 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/order/filter/pi.lean | f1c6e3a7ee21f7b5f8b2d0bdda5f5e7b532c97b3 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 8,175 | lean | /-
Copyright (c) 2021 Yury G. Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury G. Kudryashov, Alex Kontorovich
-/
import order.filter.bases
/-!
# (Co)product of a family of filters
In this file we define two filters on `Π i, α i` and prove some basic properties of these filters.
* `filter.pi (f : Π i, filter (α i))` to be the maximal filter on `Π i, α i` such that
`∀ i, filter.tendsto (function.eval i) (filter.pi f) (f i)`. It is defined as
`Π i, filter.comap (function.eval i) (f i)`. This is a generalization of `filter.prod` to indexed
products.
* `filter.Coprod (f : Π i, filter (α i))`: a generalization of `filter.coprod`; it is the supremum
of `comap (eval i) (f i)`.
-/
open set function
open_locale classical filter
namespace filter
variables {ι : Type*} {α : ι → Type*} {f f₁ f₂ : Π i, filter (α i)} {s : Π i, set (α i)}
section pi
/-- The product of an indexed family of filters. -/
def pi (f : Π i, filter (α i)) : filter (Π i, α i) := ⨅ i, comap (eval i) (f i)
instance pi.is_countably_generated [countable ι] [∀ i, is_countably_generated (f i)] :
is_countably_generated (pi f) :=
infi.is_countably_generated _
lemma tendsto_eval_pi (f : Π i, filter (α i)) (i : ι) :
tendsto (eval i) (pi f) (f i) :=
tendsto_infi' i tendsto_comap
lemma tendsto_pi {β : Type*} {m : β → Π i, α i} {l : filter β} :
tendsto m l (pi f) ↔ ∀ i, tendsto (λ x, m x i) l (f i) :=
by simp only [pi, tendsto_infi, tendsto_comap_iff]
lemma le_pi {g : filter (Π i, α i)} : g ≤ pi f ↔ ∀ i, tendsto (eval i) g (f i) := tendsto_pi
@[mono] lemma pi_mono (h : ∀ i, f₁ i ≤ f₂ i) : pi f₁ ≤ pi f₂ := infi_mono $ λ i, comap_mono $ h i
lemma mem_pi_of_mem (i : ι) {s : set (α i)} (hs : s ∈ f i) :
eval i ⁻¹' s ∈ pi f :=
mem_infi_of_mem i $ preimage_mem_comap hs
lemma pi_mem_pi {I : set ι} (hI : I.finite) (h : ∀ i ∈ I, s i ∈ f i) :
I.pi s ∈ pi f :=
begin
rw [pi_def, bInter_eq_Inter],
refine mem_infi_of_Inter hI (λ i, _) subset.rfl,
exact preimage_mem_comap (h i i.2)
end
lemma mem_pi {s : set (Π i, α i)} : s ∈ pi f ↔
∃ (I : set ι), I.finite ∧ ∃ t : Π i, set (α i), (∀ i, t i ∈ f i) ∧ I.pi t ⊆ s :=
begin
split,
{ simp only [pi, mem_infi', mem_comap, pi_def],
rintro ⟨I, If, V, hVf, hVI, rfl, -⟩, choose t htf htV using hVf,
exact ⟨I, If, t, htf, Inter₂_mono (λ i _, htV i)⟩ },
{ rintro ⟨I, If, t, htf, hts⟩,
exact mem_of_superset (pi_mem_pi If $ λ i _, htf i) hts }
end
lemma mem_pi' {s : set (Π i, α i)} : s ∈ pi f ↔
∃ (I : finset ι), ∃ t : Π i, set (α i), (∀ i, t i ∈ f i) ∧ set.pi ↑I t ⊆ s :=
mem_pi.trans exists_finite_iff_finset
lemma mem_of_pi_mem_pi [∀ i, ne_bot (f i)] {I : set ι} (h : I.pi s ∈ pi f) {i : ι} (hi : i ∈ I) :
s i ∈ f i :=
begin
rcases mem_pi.1 h with ⟨I', I'f, t, htf, hts⟩,
refine mem_of_superset (htf i) (λ x hx, _),
have : ∀ i, (t i).nonempty, from λ i, nonempty_of_mem (htf i),
choose g hg,
have : update g i x ∈ I'.pi t,
{ intros j hj, rcases eq_or_ne j i with (rfl|hne); simp * },
simpa using hts this i hi
end
@[simp] lemma pi_mem_pi_iff [∀ i, ne_bot (f i)] {I : set ι} (hI : I.finite) :
I.pi s ∈ pi f ↔ ∀ i ∈ I, s i ∈ f i :=
⟨λ h i hi, mem_of_pi_mem_pi h hi, pi_mem_pi hI⟩
lemma has_basis_pi {ι' : ι → Type} {s : Π i, ι' i → set (α i)} {p : Π i, ι' i → Prop}
(h : ∀ i, (f i).has_basis (p i) (s i)) :
(pi f).has_basis (λ If : set ι × Π i, ι' i, If.1.finite ∧ ∀ i ∈ If.1, p i (If.2 i))
(λ If : set ι × Π i, ι' i, If.1.pi (λ i, s i $ If.2 i)) :=
begin
have : (pi f).has_basis _ _ := has_basis_infi' (λ i, (h i).comap (eval i : (Π j, α j) → α i)),
convert this,
ext,
simp
end
@[simp] lemma pi_inf_principal_univ_pi_eq_bot :
pi f ⊓ 𝓟 (set.pi univ s) = ⊥ ↔ ∃ i, f i ⊓ 𝓟 (s i) = ⊥ :=
begin
split,
{ simp only [inf_principal_eq_bot, mem_pi], contrapose!,
rintros (hsf : ∀ i, ∃ᶠ x in f i, x ∈ s i) I If t htf hts,
have : ∀ i, (s i ∩ t i).nonempty, from λ i, ((hsf i).and_eventually (htf i)).exists,
choose x hxs hxt,
exact hts (λ i hi, hxt i) (mem_univ_pi.2 hxs) },
{ simp only [inf_principal_eq_bot],
rintro ⟨i, hi⟩,
filter_upwards [mem_pi_of_mem i hi] with x using mt (λ h, h i trivial), },
end
@[simp] lemma pi_inf_principal_pi_eq_bot [Π i, ne_bot (f i)] {I : set ι} :
pi f ⊓ 𝓟 (set.pi I s) = ⊥ ↔ ∃ i ∈ I, f i ⊓ 𝓟 (s i) = ⊥ :=
begin
rw [← univ_pi_piecewise I, pi_inf_principal_univ_pi_eq_bot],
refine exists_congr (λ i, _),
by_cases hi : i ∈ I; simp [hi, (‹Π i, ne_bot (f i)› i).ne]
end
@[simp] lemma pi_inf_principal_univ_pi_ne_bot :
ne_bot (pi f ⊓ 𝓟 (set.pi univ s)) ↔ ∀ i, ne_bot (f i ⊓ 𝓟 (s i)) :=
by simp [ne_bot_iff]
@[simp] lemma pi_inf_principal_pi_ne_bot [Π i, ne_bot (f i)] {I : set ι} :
ne_bot (pi f ⊓ 𝓟 (I.pi s)) ↔ ∀ i ∈ I, ne_bot (f i ⊓ 𝓟 (s i)) :=
by simp [ne_bot_iff]
instance pi_inf_principal_pi.ne_bot [h : ∀ i, ne_bot (f i ⊓ 𝓟 (s i))] {I : set ι} :
ne_bot (pi f ⊓ 𝓟 (I.pi s)) :=
(pi_inf_principal_univ_pi_ne_bot.2 ‹_›).mono $ inf_le_inf_left _ $ principal_mono.2 $
λ x hx i hi, hx i trivial
@[simp] lemma pi_eq_bot : pi f = ⊥ ↔ ∃ i, f i = ⊥ :=
by simpa using @pi_inf_principal_univ_pi_eq_bot ι α f (λ _, univ)
@[simp] lemma pi_ne_bot : ne_bot (pi f) ↔ ∀ i, ne_bot (f i) := by simp [ne_bot_iff]
instance [∀ i, ne_bot (f i)] : ne_bot (pi f) := pi_ne_bot.2 ‹_›
end pi
/-! ### `n`-ary coproducts of filters -/
section Coprod
/-- Coproduct of filters. -/
protected def Coprod (f : Π i, filter (α i)) : filter (Π i, α i) :=
⨆ i : ι, comap (eval i) (f i)
lemma mem_Coprod_iff {s : set (Π i, α i)} :
(s ∈ filter.Coprod f) ↔ (∀ i : ι, (∃ t₁ ∈ f i, eval i ⁻¹' t₁ ⊆ s)) :=
by simp [filter.Coprod]
lemma compl_mem_Coprod {s : set (Π i, α i)} :
sᶜ ∈ filter.Coprod f ↔ ∀ i, (eval i '' s)ᶜ ∈ f i :=
by simp only [filter.Coprod, mem_supr, compl_mem_comap]
lemma Coprod_ne_bot_iff' :
ne_bot (filter.Coprod f) ↔ (∀ i, nonempty (α i)) ∧ ∃ d, ne_bot (f d) :=
by simp only [filter.Coprod, supr_ne_bot, ← exists_and_distrib_left, ← comap_eval_ne_bot_iff']
@[simp] lemma Coprod_ne_bot_iff [∀ i, nonempty (α i)] :
ne_bot (filter.Coprod f) ↔ ∃ d, ne_bot (f d) :=
by simp [Coprod_ne_bot_iff', *]
lemma Coprod_eq_bot_iff' : filter.Coprod f = ⊥ ↔ (∃ i, is_empty (α i)) ∨ f = ⊥ :=
by simpa [not_and_distrib, funext_iff] using not_congr Coprod_ne_bot_iff'
@[simp] lemma Coprod_eq_bot_iff [∀ i, nonempty (α i)] : filter.Coprod f = ⊥ ↔ f = ⊥ :=
by simpa [funext_iff] using not_congr Coprod_ne_bot_iff
@[simp] lemma Coprod_bot' : filter.Coprod (⊥ : Π i, filter (α i)) = ⊥ :=
Coprod_eq_bot_iff'.2 (or.inr rfl)
@[simp] lemma Coprod_bot : filter.Coprod (λ _, ⊥ : Π i, filter (α i)) = ⊥ := Coprod_bot'
lemma ne_bot.Coprod [∀ i, nonempty (α i)] {i : ι} (h : ne_bot (f i)) :
ne_bot (filter.Coprod f) :=
Coprod_ne_bot_iff.2 ⟨i, h⟩
@[instance] lemma Coprod_ne_bot [∀ i, nonempty (α i)] [nonempty ι] (f : Π i, filter (α i))
[H : ∀ i, ne_bot (f i)] : ne_bot (filter.Coprod f) :=
(H (classical.arbitrary ι)).Coprod
@[mono] lemma Coprod_mono (hf : ∀ i, f₁ i ≤ f₂ i) : filter.Coprod f₁ ≤ filter.Coprod f₂ :=
supr_mono $ λ i, comap_mono (hf i)
variables {β : ι → Type*} {m : Π i, α i → β i}
lemma map_pi_map_Coprod_le :
map (λ (k : Π i, α i), λ i, m i (k i)) (filter.Coprod f) ≤ filter.Coprod (λ i, map (m i) (f i)) :=
begin
simp only [le_def, mem_map, mem_Coprod_iff],
intros s h i,
obtain ⟨t, H, hH⟩ := h i,
exact ⟨{x : α i | m i x ∈ t}, H, λ x hx, hH hx⟩
end
lemma tendsto.pi_map_Coprod {g : Π i, filter (β i)} (h : ∀ i, tendsto (m i) (f i) (g i)) :
tendsto (λ (k : Π i, α i), λ i, m i (k i)) (filter.Coprod f) (filter.Coprod g) :=
map_pi_map_Coprod_le.trans (Coprod_mono h)
end Coprod
end filter
|
af8428f2d471fd0f1da2aff4d52fb7ad6b5bd822 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/special_functions/gamma/bohr_mollerup.lean | 3a6b66bd0659db9455334dd9bef352070ea9d993 | [
"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 | 24,066 | lean | /-
Copyright (c) 2023 David Loeffler. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: David Loeffler
-/
import analysis.special_functions.gamma.basic
import analysis.special_functions.gaussian
/-! # Convexity properties of the Gamma function
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
In this file, we prove that `Gamma` and `log ∘ Gamma` are convex functions on the positive real
line. We then prove the Bohr-Mollerup theorem, which characterises `Gamma` as the *unique*
positive-real-valued, log-convex function on the positive reals satisfying `f (x + 1) = x f x` and
`f 1 = 1`.
The proof of the Bohr-Mollerup theorem is bound up with the proof of (a weak form of) the Euler
limit formula, `real.bohr_mollerup.tendsto_log_gamma_seq`, stating that for positive
real `x` the sequence `x * log n + log n! - ∑ (m : ℕ) in finset.range (n + 1), log (x + m)`
tends to `log Γ(x)` as `n → ∞`. We prove that any function satisfying the hypotheses of the
Bohr-Mollerup theorem must agree with the limit in the Euler limit formula, so there is at most one
such function; then we show that `Γ` satisfies these conditions.
Since most of the auxiliary lemmas for the Bohr-Mollerup theorem are of no relevance outside the
context of this proof, we place them in a separate namespace `real.bohr_mollerup` to avoid clutter.
(This includes the logarithmic form of the Euler limit formula, since later we will prove a more
general form of the Euler limit formula valid for any real or complex `x`; see
`real.Gamma_seq_tendsto_Gamma` and `complex.Gamma_seq_tendsto_Gamma` in the file
`analysis.special_functions.gamma.beta`.)
As an application of the Bohr-Mollerup theorem we prove the Legendre doubling formula for the
Gamma function for real positive `s` (which will be upgraded to a proof for all complex `s` in a
later file).
TODO: This argument can be extended to prove the general `k`-multiplication formula (at least up
to a constant, and it should be possible to deduce the value of this constant using Stirling's
formula).
-/
noncomputable theory
open filter set measure_theory
open_locale nat ennreal topology big_operators real
section convexity
-- Porting note: move the following lemmas to `Analysis.Convex.Function`
variables {𝕜 E β : Type*} {s : set E} {f g : E → β}
[ordered_semiring 𝕜] [has_smul 𝕜 E] [add_comm_monoid E] [ordered_add_comm_monoid β]
lemma convex_on.congr [has_smul 𝕜 β] (hf : convex_on 𝕜 s f) (hfg : eq_on f g s) :
convex_on 𝕜 s g :=
⟨hf.1, λ x hx y hy a b ha hb hab,
by simpa only [←hfg hx, ←hfg hy, ←hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
lemma concave_on.congr [has_smul 𝕜 β](hf : concave_on 𝕜 s f) (hfg : eq_on f g s) :
concave_on 𝕜 s g :=
⟨hf.1, λ x hx y hy a b ha hb hab,
by simpa only [←hfg hx, ←hfg hy, ←hfg (hf.1 hx hy ha hb hab)] using hf.2 hx hy ha hb hab⟩
lemma strict_convex_on.congr [has_smul 𝕜 β] (hf : strict_convex_on 𝕜 s f) (hfg : eq_on f g s) :
strict_convex_on 𝕜 s g :=
⟨hf.1, λ x hx y hy hxy a b ha hb hab, by simpa only
[←hfg hx, ←hfg hy, ←hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩
lemma strict_concave_on.congr [has_smul 𝕜 β] (hf : strict_concave_on 𝕜 s f) (hfg : eq_on f g s) :
strict_concave_on 𝕜 s g :=
⟨hf.1, λ x hx y hy hxy a b ha hb hab, by simpa only
[←hfg hx, ←hfg hy, ←hfg (hf.1 hx hy ha.le hb.le hab)] using hf.2 hx hy hxy ha hb hab⟩
lemma convex_on.add_const [module 𝕜 β] (hf : convex_on 𝕜 s f) (b : β) :
convex_on 𝕜 s (f + (λ _, b)) :=
hf.add (convex_on_const _ hf.1)
lemma concave_on.add_const [module 𝕜 β] (hf : concave_on 𝕜 s f) (b : β) :
concave_on 𝕜 s (f + (λ _, b)) :=
hf.add (concave_on_const _ hf.1)
lemma strict_convex_on.add_const {γ : Type*} {f : E → γ}
[ordered_cancel_add_comm_monoid γ] [module 𝕜 γ] (hf : strict_convex_on 𝕜 s f) (b : γ) :
strict_convex_on 𝕜 s (f + (λ _, b)) :=
hf.add_convex_on (convex_on_const _ hf.1)
lemma strict_concave_on.add_const {γ : Type*} {f : E → γ}
[ordered_cancel_add_comm_monoid γ] [module 𝕜 γ] (hf : strict_concave_on 𝕜 s f) (b : γ) :
strict_concave_on 𝕜 s (f + (λ _, b)) :=
hf.add_concave_on (concave_on_const _ hf.1)
end convexity
namespace real
section convexity
/-- Log-convexity of the Gamma function on the positive reals (stated in multiplicative form),
proved using the Hölder inequality applied to Euler's integral. -/
lemma Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma {s t a b : ℝ}
(hs : 0 < s) (ht : 0 < t) (ha : 0 < a) (hb : 0 < b) (hab : a + b = 1) :
Gamma (a * s + b * t) ≤ Gamma s ^ a * Gamma t ^ b :=
begin
-- We will apply Hölder's inequality, for the conjugate exponents `p = 1 / a`
-- and `q = 1 / b`, to the functions `f a s` and `f b t`, where `f` is as follows:
let f : ℝ → ℝ → ℝ → ℝ := λ c u x, exp (-c * x) * x ^ (c * (u - 1)),
have e : is_conjugate_exponent (1 / a) (1 / b) := real.is_conjugate_exponent_one_div ha hb hab,
have hab' : b = 1 - a := by linarith,
have hst : 0 < a * s + b * t := add_pos (mul_pos ha hs) (mul_pos hb ht),
-- some properties of f:
have posf : ∀ (c u x : ℝ), x ∈ Ioi (0:ℝ) → 0 ≤ f c u x :=
λ c u x hx, mul_nonneg (exp_pos _).le (rpow_pos_of_pos hx _).le,
have posf' : ∀ (c u : ℝ), ∀ᵐ (x : ℝ) ∂volume.restrict (Ioi 0), 0 ≤ f c u x :=
λ c u, (ae_restrict_iff' measurable_set_Ioi).mpr (ae_of_all _ (posf c u)),
have fpow : ∀ {c x : ℝ} (hc : 0 < c) (u : ℝ) (hx : 0 < x),
exp (-x) * x ^ (u - 1) = f c u x ^ (1 / c),
{ intros c x hc u hx,
dsimp only [f],
rw [mul_rpow (exp_pos _).le ((rpow_nonneg_of_nonneg hx.le) _), ←exp_mul, ←rpow_mul hx.le],
congr' 2;
{ field_simp [hc.ne'], ring } },
-- show `f c u` is in `ℒp` for `p = 1/c`:
have f_mem_Lp : ∀ {c u : ℝ} (hc : 0 < c) (hu : 0 < u),
mem_ℒp (f c u) (ennreal.of_real (1 / c)) (volume.restrict (Ioi 0)),
{ intros c u hc hu,
have A : ennreal.of_real (1 / c) ≠ 0,
by rwa [ne.def, ennreal.of_real_eq_zero, not_le, one_div_pos],
have B : ennreal.of_real (1 / c) ≠ ∞, from ennreal.of_real_ne_top,
rw [←mem_ℒp_norm_rpow_iff _ A B, ennreal.to_real_of_real (one_div_nonneg.mpr hc.le),
ennreal.div_self A B, mem_ℒp_one_iff_integrable],
{ apply integrable.congr (Gamma_integral_convergent hu),
refine eventually_eq_of_mem (self_mem_ae_restrict measurable_set_Ioi) (λ x hx, _),
dsimp only,
rw fpow hc u hx,
congr' 1,
exact (norm_of_nonneg (posf _ _ x hx)).symm },
{ refine continuous_on.ae_strongly_measurable _ measurable_set_Ioi,
refine (continuous.continuous_on _).mul (continuous_at.continuous_on (λ x hx, _)),
{ exact continuous_exp.comp (continuous_const.mul continuous_id'), },
{ exact continuous_at_rpow_const _ _ (or.inl (ne_of_lt hx).symm), } } },
-- now apply Hölder:
rw [Gamma_eq_integral hs, Gamma_eq_integral ht, Gamma_eq_integral hst],
convert measure_theory.integral_mul_le_Lp_mul_Lq_of_nonneg e (posf' a s) (posf' b t)
(f_mem_Lp ha hs) (f_mem_Lp hb ht) using 1,
{ refine set_integral_congr measurable_set_Ioi (λ x hx, _),
dsimp only [f],
have A : exp (-x) = exp (-a * x) * exp (-b * x),
{ rw [←exp_add, ←add_mul, ←neg_add, hab, neg_one_mul] },
have B : x ^ (a * s + b * t - 1) = (x ^ (a * (s - 1))) * (x ^ (b * (t - 1))),
{ rw [←rpow_add hx, hab'], congr' 1, ring },
rw [A, B],
ring },
{ rw [one_div_one_div, one_div_one_div],
congr' 2;
exact set_integral_congr measurable_set_Ioi (λ x hx, fpow (by assumption) _ hx) },
end
lemma convex_on_log_Gamma : convex_on ℝ (Ioi 0) (log ∘ Gamma) :=
begin
refine convex_on_iff_forall_pos.mpr ⟨convex_Ioi _, λ x hx y hy a b ha hb hab, _⟩,
have : b = 1 - a := by linarith, subst this,
simp_rw [function.comp_app, smul_eq_mul],
rw [←log_rpow (Gamma_pos_of_pos hy), ←log_rpow (Gamma_pos_of_pos hx),
←log_mul
((rpow_pos_of_pos (Gamma_pos_of_pos hx) _).ne') (rpow_pos_of_pos (Gamma_pos_of_pos hy) _).ne',
log_le_log
(Gamma_pos_of_pos (add_pos (mul_pos ha hx) (mul_pos hb hy)))
(mul_pos
(rpow_pos_of_pos (Gamma_pos_of_pos hx) _) (rpow_pos_of_pos (Gamma_pos_of_pos hy) _))],
exact Gamma_mul_add_mul_le_rpow_Gamma_mul_rpow_Gamma hx hy ha hb hab,
end
lemma convex_on_Gamma : convex_on ℝ (Ioi 0) Gamma :=
begin
refine ((convex_on_exp.subset (subset_univ _) _).comp convex_on_log_Gamma
(exp_monotone.monotone_on _)).congr (λ x hx, exp_log (Gamma_pos_of_pos hx)),
rw convex_iff_is_preconnected,
refine is_preconnected_Ioi.image _ (λ x hx, continuous_at.continuous_within_at _),
refine (differentiable_at_Gamma (λ m, _)).continuous_at.log (Gamma_pos_of_pos hx).ne',
exact (neg_lt_iff_pos_add.mpr (add_pos_of_pos_of_nonneg hx (nat.cast_nonneg m))).ne',
end
end convexity
section bohr_mollerup
namespace bohr_mollerup
/-- The function `n ↦ x log n + log n! - (log x + ... + log (x + n))`, which we will show tends to
`log (Gamma x)` as `n → ∞`. -/
def log_gamma_seq (x : ℝ) (n : ℕ) : ℝ :=
x * log n + log n! - ∑ (m : ℕ) in finset.range (n + 1), log (x + m)
variables {f : ℝ → ℝ} {x : ℝ} {n : ℕ}
lemma f_nat_eq (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y) (hn : n ≠ 0) :
f n = f 1 + log (n - 1)! :=
begin
refine nat.le_induction (by simp) (λ m hm IH, _) n (nat.one_le_iff_ne_zero.2 hn),
have A : 0 < (m : ℝ), from nat.cast_pos.2 hm,
simp only [hf_feq A, nat.cast_add, algebra_map.coe_one, nat.add_succ_sub_one, add_zero],
rw [IH, add_assoc, ← log_mul (nat.cast_ne_zero.mpr (nat.factorial_ne_zero _)) A.ne',
← nat.cast_mul],
conv_rhs { rw [← nat.succ_pred_eq_of_pos hm, nat.factorial_succ, mul_comm] },
congr,
exact (nat.succ_pred_eq_of_pos hm).symm
end
lemma f_add_nat_eq (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y) (hx : 0 < x) (n : ℕ) :
f (x + n) = f x + ∑ (m : ℕ) in finset.range n, log (x + m) :=
begin
induction n with n hn,
{ simp },
{ have : x + n.succ = (x + n) + 1,
{ push_cast, ring },
rw [this, hf_feq, hn],
rw [finset.range_succ, finset.sum_insert (finset.not_mem_range_self)],
abel,
linarith [(nat.cast_nonneg n : 0 ≤ (n:ℝ))] },
end
/-- Linear upper bound for `f (x + n)` on unit interval -/
lemma f_add_nat_le
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hn : n ≠ 0) (hx : 0 < x) (hx' : x ≤ 1) :
f (n + x) ≤ f n + x * log n :=
begin
have hn': 0 < (n:ℝ) := nat.cast_pos.mpr (nat.pos_of_ne_zero hn),
have : f n + x * log n = (1 - x) * f n + x * f (n + 1),
{ rw [hf_feq hn'], ring, },
rw [this, (by ring : (n:ℝ) + x = (1 - x) * n + x * (n + 1))],
simpa only [smul_eq_mul] using hf_conv.2 hn' (by linarith : 0 < (n + 1 : ℝ))
(by linarith : 0 ≤ 1 - x) hx.le (by linarith),
end
/-- Linear lower bound for `f (x + n)` on unit interval -/
lemma f_add_nat_ge
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hn : 2 ≤ n) (hx : 0 < x) :
f n + x * log (n - 1) ≤ f (n + x) :=
begin
have npos : 0 < (n:ℝ) - 1,
{ rw [←nat.cast_one, sub_pos, nat.cast_lt], linarith, },
have c := (convex_on_iff_slope_mono_adjacent.mp $ hf_conv).2
npos (by linarith : 0 < (n:ℝ) + x) (by linarith : (n:ℝ) - 1 < (n:ℝ)) (by linarith),
rw [add_sub_cancel', sub_sub_cancel, div_one] at c,
have : f (↑n - 1) = f n - log (↑n - 1),
{ nth_rewrite_rhs 0 (by ring : (n:ℝ) = (↑n - 1) + 1),
rw [hf_feq npos, add_sub_cancel] },
rwa [this, le_div_iff hx, sub_sub_cancel, le_sub_iff_add_le, mul_comm _ x, add_comm] at c,
end
lemma log_gamma_seq_add_one (x : ℝ) (n : ℕ) :
log_gamma_seq (x + 1) n = log_gamma_seq x (n + 1) + log x - (x + 1) * (log (n + 1) - log n) :=
begin
dsimp only [nat.factorial_succ, log_gamma_seq],
conv_rhs { rw [finset.sum_range_succ', nat.cast_zero, add_zero], },
rw [nat.cast_mul, log_mul], rotate,
{ rw nat.cast_ne_zero, exact nat.succ_ne_zero n },
{ rw nat.cast_ne_zero, exact nat.factorial_ne_zero n, },
have : ∑ (m : ℕ) in finset.range (n + 1), log (x + 1 + ↑m) =
∑ (k : ℕ) in finset.range (n + 1), log (x + ↑(k + 1)),
{ refine finset.sum_congr (by refl) (λ m hm, _),
congr' 1,
push_cast,
abel },
rw [←this, nat.cast_add_one n],
ring,
end
lemma le_log_gamma_seq
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hx : 0 < x) (hx' : x ≤ 1) (n : ℕ) :
f x ≤ f 1 + x * log (n + 1) - x * log n + log_gamma_seq x n :=
begin
rw [log_gamma_seq, ←add_sub_assoc, le_sub_iff_add_le, ←f_add_nat_eq @hf_feq hx, add_comm x],
refine (f_add_nat_le hf_conv @hf_feq (nat.add_one_ne_zero n) hx hx').trans (le_of_eq _),
rw [f_nat_eq @hf_feq (by linarith : n + 1 ≠ 0), nat.add_sub_cancel, nat.cast_add_one],
ring,
end
lemma ge_log_gamma_seq
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hx : 0 < x) (hn : n ≠ 0) :
f 1 + log_gamma_seq x n ≤ f x :=
begin
dsimp [log_gamma_seq],
rw [←add_sub_assoc, sub_le_iff_le_add, ←f_add_nat_eq @hf_feq hx, add_comm x _],
refine le_trans (le_of_eq _) (f_add_nat_ge hf_conv @hf_feq _ hx),
{ rw [f_nat_eq @hf_feq, nat.add_sub_cancel, nat.cast_add_one, add_sub_cancel],
{ ring },
{ exact nat.succ_ne_zero _} },
{ apply nat.succ_le_succ,
linarith [nat.pos_of_ne_zero hn] },
end
lemma tendsto_log_gamma_seq_of_le_one
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hx : 0 < x) (hx' : x ≤ 1) :
tendsto (log_gamma_seq x) at_top (𝓝 $ f x - f 1) :=
begin
refine tendsto_of_tendsto_of_tendsto_of_le_of_le' _ tendsto_const_nhds _ _,
show ∀ᶠ (n : ℕ) in at_top, log_gamma_seq x n ≤ f x - f 1,
{ refine eventually.mp (eventually_ne_at_top 0) (eventually_of_forall (λ n hn, _)),
exact le_sub_iff_add_le'.mpr (ge_log_gamma_seq hf_conv @hf_feq hx hn) },
show ∀ᶠ (n : ℕ) in at_top, f x - f 1 - x * (log (n + 1) - log n) ≤ log_gamma_seq x n,
{ refine eventually_of_forall (λ n, _),
rw [sub_le_iff_le_add', sub_le_iff_le_add'],
convert le_log_gamma_seq hf_conv @hf_feq hx hx' n using 1,
ring },
{ have : f x - f 1 = (f x - f 1) - x * 0 := by ring,
nth_rewrite 0 this,
exact tendsto.sub tendsto_const_nhds (tendsto_log_nat_add_one_sub_log.const_mul _), }
end
lemma tendsto_log_gamma_seq
(hf_conv : convex_on ℝ (Ioi 0) f) (hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = f y + log y)
(hx : 0 < x) :
tendsto (log_gamma_seq x) at_top (𝓝 $ f x - f 1) :=
begin
suffices : ∀ (m : ℕ), ↑m < x → x ≤ m + 1 →
tendsto (log_gamma_seq x) at_top (𝓝 $ f x - f 1),
{ refine this (⌈x - 1⌉₊) _ _,
{ rcases lt_or_le x 1,
{ rwa [nat.ceil_eq_zero.mpr (by linarith : x - 1 ≤ 0), nat.cast_zero] },
{ convert nat.ceil_lt_add_one (by linarith : 0 ≤ x - 1),
abel } },
{ rw ←sub_le_iff_le_add, exact nat.le_ceil _}, },
intro m,
induction m with m hm generalizing x,
{ rw [nat.cast_zero, zero_add],
exact λ _ hx', tendsto_log_gamma_seq_of_le_one hf_conv @hf_feq hx hx' },
{ intros hy hy',
rw [nat.cast_succ, ←sub_le_iff_le_add] at hy',
rw [nat.cast_succ, ←lt_sub_iff_add_lt] at hy,
specialize hm ((nat.cast_nonneg _).trans_lt hy) hy hy',
-- now massage gauss_product n (x - 1) into gauss_product (n - 1) x
have : ∀ᶠ (n:ℕ) in at_top, log_gamma_seq (x - 1) n = log_gamma_seq x (n - 1) +
x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1),
{ refine eventually.mp (eventually_ge_at_top 1) (eventually_of_forall (λ n hn, _)),
have := log_gamma_seq_add_one (x - 1) (n - 1),
rw [sub_add_cancel, nat.sub_add_cancel hn] at this,
rw this,
ring },
replace hm := ((tendsto.congr' this hm).add
(tendsto_const_nhds : tendsto (λ _, log (x - 1)) _ _)).comp (tendsto_add_at_top_nat 1),
have :
(λ (x_1 : ℕ), (λ (n : ℕ), log_gamma_seq x (n - 1) +
x * (log (↑(n - 1) + 1) - log ↑(n - 1)) - log (x - 1)) x_1 +
(λ (b : ℕ), log (x - 1)) x_1) ∘ (λ (a : ℕ), a + 1) =
λ n, log_gamma_seq x n + x * (log (↑n + 1) - log ↑n),
{ ext1 n,
dsimp only [function.comp_app],
rw [sub_add_cancel, nat.add_sub_cancel] },
rw this at hm,
convert hm.sub (tendsto_log_nat_add_one_sub_log.const_mul x) using 2,
{ ext1 n, ring },
{ have := hf_feq ((nat.cast_nonneg m).trans_lt hy),
rw sub_add_cancel at this,
rw this,
ring } },
end
lemma tendsto_log_Gamma {x : ℝ} (hx : 0 < x) :
tendsto (log_gamma_seq x) at_top (𝓝 $ log (Gamma x)) :=
begin
have : log (Gamma x) = (log ∘ Gamma) x - (log ∘ Gamma) 1,
{ simp_rw [function.comp_app, Gamma_one, log_one, sub_zero] },
rw this,
refine bohr_mollerup.tendsto_log_gamma_seq convex_on_log_Gamma (λ y hy, _) hx,
rw [function.comp_app, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne', add_comm],
end
end bohr_mollerup -- (namespace)
/-- The **Bohr-Mollerup theorem**: the Gamma function is the *unique* log-convex, positive-valued
function on the positive reals which satisfies `f 1 = 1` and `f (x + 1) = x * f x` for all `x`. -/
lemma eq_Gamma_of_log_convex {f : ℝ → ℝ}
(hf_conv : convex_on ℝ (Ioi 0) (log ∘ f))
(hf_feq : ∀ {y:ℝ}, 0 < y → f (y + 1) = y * f y)
(hf_pos : ∀ {y:ℝ}, 0 < y → 0 < f y)
(hf_one : f 1 = 1) :
eq_on f Gamma (Ioi (0:ℝ)) :=
begin
suffices : eq_on (log ∘ f) (log ∘ Gamma) (Ioi (0:ℝ)),
from λ x hx, log_inj_on_pos (hf_pos hx) (Gamma_pos_of_pos hx) (this hx),
intros x hx,
have e1 := bohr_mollerup.tendsto_log_gamma_seq hf_conv _ hx,
{ rw [function.comp_app log f 1, hf_one, log_one, sub_zero] at e1,
exact tendsto_nhds_unique e1 (bohr_mollerup.tendsto_log_Gamma hx) },
{ intros y hy,
rw [function.comp_app, hf_feq hy, log_mul hy.ne' (hf_pos hy).ne'],
ring }
end
end bohr_mollerup -- (section)
section strict_mono
lemma Gamma_two : Gamma 2 = 1 := by simpa using Gamma_nat_eq_factorial 1
lemma Gamma_three_div_two_lt_one : Gamma (3 / 2) < 1 :=
begin
-- This can also be proved using the closed-form evaluation of `Gamma (1 / 2)` in
-- `analysis.special_functions.gaussian`, but we give a self-contained proof using log-convexity
-- to avoid unnecessary imports.
have A : (0:ℝ) < 3/2, by norm_num,
have := bohr_mollerup.f_add_nat_le convex_on_log_Gamma (λ y hy, _) two_ne_zero one_half_pos
(by norm_num : 1/2 ≤ (1:ℝ)),
swap, { rw [function.comp_app, Gamma_add_one hy.ne', log_mul hy.ne' (Gamma_pos_of_pos hy).ne',
add_comm] },
rw [function.comp_app, function.comp_app, nat.cast_two, Gamma_two, log_one, zero_add,
(by norm_num : (2:ℝ) + 1/2 = 3/2 + 1), Gamma_add_one A.ne',
log_mul A.ne' (Gamma_pos_of_pos A).ne', ←le_sub_iff_add_le',
log_le_iff_le_exp (Gamma_pos_of_pos A)] at this,
refine this.trans_lt (exp_lt_one_iff.mpr _),
rw [mul_comm, ←mul_div_assoc, div_sub' _ _ (2:ℝ) two_ne_zero],
refine div_neg_of_neg_of_pos _ two_pos,
rw [sub_neg, mul_one, ←nat.cast_two, ←log_pow, ←exp_lt_exp, nat.cast_two, exp_log two_pos,
exp_log];
norm_num,
end
lemma Gamma_strict_mono_on_Ici : strict_mono_on Gamma (Ici 2) :=
begin
convert convex_on_Gamma.strict_mono_of_lt (by norm_num : (0:ℝ) < 3/2)
(by norm_num : (3/2 : ℝ) < 2) (Gamma_two.symm ▸ Gamma_three_div_two_lt_one),
symmetry,
rw inter_eq_right_iff_subset,
exact λ x hx, two_pos.trans_le hx,
end
end strict_mono
section doubling
/-!
## The Gamma doubling formula
As a fun application of the Bohr-Mollerup theorem, we prove the Gamma-function doubling formula
(for positive real `s`). The idea is that `2 ^ s * Gamma (s / 2) * Gamma (s / 2 + 1 / 2)` is
log-convex and satisfies the Gamma functional equation, so it must actually be a constant
multiple of `Gamma`, and we can compute the constant by specialising at `s = 1`. -/
/-- Auxiliary definition for the doubling formula (we'll show this is equal to `Gamma s`) -/
def doubling_Gamma (s : ℝ) : ℝ := Gamma (s / 2) * Gamma (s / 2 + 1 / 2) * 2 ^ (s - 1) / sqrt π
lemma doubling_Gamma_add_one (s : ℝ) (hs : s ≠ 0) :
doubling_Gamma (s + 1) = s * doubling_Gamma s :=
begin
rw [doubling_Gamma, doubling_Gamma, (by abel : s + 1 - 1 = s - 1 + 1), add_div, add_assoc,
add_halves (1 : ℝ), Gamma_add_one (div_ne_zero hs two_ne_zero), rpow_add two_pos, rpow_one],
ring,
end
lemma doubling_Gamma_one : doubling_Gamma 1 = 1 :=
by simp_rw [doubling_Gamma, Gamma_one_half_eq, add_halves (1 : ℝ), sub_self, Gamma_one, mul_one,
rpow_zero, mul_one, div_self (sqrt_ne_zero'.mpr pi_pos)]
lemma log_doubling_Gamma_eq :
eq_on (log ∘ doubling_Gamma) (λ s, log (Gamma (s / 2)) + log (Gamma (s / 2 + 1 / 2))
+ s * log 2 - log (2 * sqrt π)) (Ioi 0) :=
begin
intros s hs,
have h1 : sqrt π ≠ 0, from sqrt_ne_zero'.mpr pi_pos,
have h2 : Gamma (s / 2) ≠ 0, from (Gamma_pos_of_pos $ div_pos hs two_pos).ne',
have h3 : Gamma (s / 2 + 1 / 2) ≠ 0,
from (Gamma_pos_of_pos $ add_pos (div_pos hs two_pos) one_half_pos).ne',
have h4 : (2 : ℝ) ^ (s - 1) ≠ 0, from (rpow_pos_of_pos two_pos _).ne',
rw [function.comp_app, doubling_Gamma, log_div (mul_ne_zero (mul_ne_zero h2 h3) h4) h1,
log_mul (mul_ne_zero h2 h3) h4, log_mul h2 h3, log_rpow two_pos, log_mul two_ne_zero h1],
ring_nf,
end
lemma doubling_Gamma_log_convex_Ioi : convex_on ℝ (Ioi (0:ℝ)) (log ∘ doubling_Gamma) :=
begin
refine (((convex_on.add _ _).add _).add_const _).congr log_doubling_Gamma_eq.symm,
{ convert convex_on_log_Gamma.comp_affine_map
(distrib_mul_action.to_linear_map ℝ ℝ (1 / 2 : ℝ)).to_affine_map,
{ simpa only [zero_div] using (preimage_const_mul_Ioi (0 : ℝ) one_half_pos).symm, },
{ ext1 x,
change log (Gamma (x / 2)) = log (Gamma ((1 / 2 : ℝ) • x)),
rw [smul_eq_mul, mul_comm, mul_one_div] } },
{ refine convex_on.subset _ (Ioi_subset_Ioi $ neg_one_lt_zero.le) (convex_Ioi _),
convert convex_on_log_Gamma.comp_affine_map ((distrib_mul_action.to_linear_map ℝ ℝ
(1 / 2 : ℝ)).to_affine_map + affine_map.const _ _ (1 / 2 : ℝ)),
{ change Ioi (-1 : ℝ) = ((λ x : ℝ, x + 1 / 2) ∘ (λ x : ℝ, (1 / 2 : ℝ) * x)) ⁻¹' (Ioi 0),
rw [preimage_comp, preimage_add_const_Ioi, zero_sub, preimage_const_mul_Ioi (_ : ℝ)
one_half_pos, neg_div, div_self (@one_half_pos ℝ _).ne'] },
{ ext1 x,
change log (Gamma (x / 2 + 1 / 2)) = log (Gamma ((1 / 2 : ℝ) • x + 1 / 2)),
rw [smul_eq_mul, mul_comm, mul_one_div] } },
{ simpa only [mul_comm _ (log _)]
using (convex_on_id (convex_Ioi (0 : ℝ))).smul (log_pos one_lt_two).le }
end
lemma doubling_Gamma_eq_Gamma {s : ℝ} (hs : 0 < s) : doubling_Gamma s = Gamma s :=
begin
refine eq_Gamma_of_log_convex doubling_Gamma_log_convex_Ioi
(λ y hy, doubling_Gamma_add_one y hy.ne') (λ y hy, _) doubling_Gamma_one hs,
apply_rules [mul_pos, Gamma_pos_of_pos, add_pos, inv_pos_of_pos,
rpow_pos_of_pos, two_pos, one_pos, sqrt_pos_of_pos pi_pos]
end
/-- Legendre's doubling formula for the Gamma function, for positive real arguments. Note that
we shall later prove this for all `s` as `real.Gamma_mul_Gamma_add_half` (superseding this result)
but this result is needed as an intermediate step. -/
lemma Gamma_mul_Gamma_add_half_of_pos {s : ℝ} (hs : 0 < s) :
Gamma s * Gamma (s + 1 / 2) = Gamma (2 * s) * 2 ^ (1 - 2 * s) * sqrt π :=
begin
rw [←(doubling_Gamma_eq_Gamma (mul_pos two_pos hs)),
doubling_Gamma, mul_div_cancel_left _ (two_ne_zero' ℝ),
(by abel : 1 - 2 * s = -(2 * s - 1)), rpow_neg zero_le_two],
field_simp [(sqrt_pos_of_pos pi_pos).ne', (rpow_pos_of_pos two_pos (2 * s - 1)).ne'],
ring,
end
end doubling
end real
|
42ecf690f1ae5499de8951a537a01563ffadbf3e | ba4794a0deca1d2aaa68914cd285d77880907b5c | /src/game/world1/level4.lean | 4117353dff885a5cc06ba3497ad7a1afce631d06 | [
"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 | 3,457 | lean | import mynat.add -- definition of addition
namespace mynat -- hide
/- Axiom : add_zero (a : mynat) :
a + 0 = a
-/
/- Axiom : add_succ (a b : mynat) :
a + succ(b) = succ(a + b)
-/
/-
# Tutorial world
## Level 4: addition
We have a new import -- the definition of addition.
Peano defined addition `a + b` by induction on `b`, or,
more precisely, by *recursion* on `b`. He first explained how to add 0 to a number:
this is the base case.
* `add_zero (a : mynat) : a + 0 = a`
We will call this theorem `add_zero`. More precisely, `add_zero` is the name
of the *proof* of the theorem. **Note the name of this proof**.
Mathematicians sometimes call it "Lemma 2.1" or "Hypothesis P6" or something. But
computer scientists call it `add_zero` because it tells you
what the answer to "$x$ add zero" is. It's a *much* better name than "Lemma 2.1".
Even better, we can use the rewrite tactic with `add_zero`.
If you ever see `x + 0` in your goal, `rw add_zero` should simplify it to `x`.
This is because `add_zero` is a proof that `x + 0 = x` (more precisely,
`add_zero x` is a proof that `x + 0 = x` but Lean can figure out the `x` from the context).
Now here's the inductive step. If you know how to add `d` to `a`, then
Peano tells you how to add `succ(d)` to `a`. It looks like this:
* `add_succ (a d : mynat) : a + succ(d) = succ (a + d)`
What's going on here is that we assume `a + d` is already
defined, and we define `a + succ(d)` to be the number after it.
**Note the name of this proof too** -- `add_succ` tells you
how to add a successor to something. If you ever see `... + succ ...`
in your goal, you should be able to use `rw add_succ,` to make
progress. Here is a simple example where we shall see both. Let's prove
that $x$ add the number after $0$ is the number after $x$.
Delete `sorry` (don't forget you can widen this box if you can't see the sorry).
Observe that the goal mentions `... + succ ...`. So type
`rw add_succ,`
and hit enter; see the goal change. **Don't forget the commma**.
Do you see that the goal now mentions ` ... + 0 ...`? So type
`rw add_zero,`
and then observe that you can close the goal with
`refl,`
and you're done. You have finished tutorial world!
## Examining proofs.
You might want to review this proof now; at
three lines long it is our current record. Click on a line in the proof
and use the L/R arrow keys to put your cursor as far left as it will go.
Then use the U/D arrow keys to move your cursor
up and down from line to line, and you can see what
Lean is thinking on each line of the proof.
## Fixing problems.
Question: why has the top right hand box gone blank?
Answer: Maybe you tried a tactic which didn't work. Or maybe you're
in the middle of typing a tactic. Try deleting up to the last
comma, *or adding a comma at the end of your code*. Look at the
error message. What line is the first error on? Perhaps
Lean thinks you're in the middle of writing a tactic command that you
think you finished. If Lean is still attempting to process a tactic
command it won't display anything.
When you're happy, let's move onto Addition World, and
learn about proof by induction. Go back to the main menu and select addition world.
-/
/- Lemma : no-side-bar
For all natural numbers $a$, we have
$$a + \operatorname{succ}(0) = \operatorname{succ}(a).$$
-/
lemma add_succ_zero (a : mynat) : a + succ(0) = succ(a) :=
begin [less_leaky]
rw add_succ,
rw add_zero,
refl,
end
end mynat |
218166ed5b6683bfd069447e052426878dc004f6 | e0b0b1648286e442507eb62344760d5cd8d13f2d | /tests/lean/run/inductive_pred.lean | 8bb7fd05c1fbd947f59c2e2a14d6bfd749119e18 | [
"Apache-2.0"
] | permissive | MULXCODE/lean4 | 743ed389e05e26e09c6a11d24607ad5a697db39b | 4675817a9e89824eca37192364cd47a4027c6437 | refs/heads/master | 1,682,231,879,857 | 1,620,423,501,000 | 1,620,423,501,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 4,202 | lean | namespace Ex
inductive LE : Nat → Nat → Prop
| refl : LE n n
| succ : LE n m → LE n m.succ
def typeOf {α : Sort u} (a : α) := α
theorem LE_brecOn : typeOf @LE.brecOn =
∀ {motive : (a a_1 : Nat) → LE a a_1 → Prop} {a a_1 : Nat} (x : LE a a_1),
(∀ (a a_2 : Nat) (x : LE a a_2), @LE.below motive a a_2 x → motive a a_2 x) → motive a a_1 x := rfl
theorem LE.trans : LE m n → LE n o → LE m o := by
intro h1 h2
induction h2 with
| refl => assumption
| succ h2 ih => exact succ (ih h1)
theorem LE.trans' : LE m n → LE n o → LE m o
| h1, refl => h1
| h1, succ h2 => succ (trans' h1 h2) -- the structural recursion in being performed on the implicit `Nat` parameter
inductive Even : Nat → Prop
| zero : Even 0
| ss : Even n → Even n.succ.succ
theorem Even_brecOn : typeOf @Even.brecOn = ∀ {motive : (a : Nat) → Even a → Prop} {a : Nat} (x : Even a),
(∀ (a : Nat) (x : Even a), @Even.below motive a x → motive a x) → motive a x := rfl
theorem Even.add : Even n → Even m → Even (n+m) := by
intro h1 h2
induction h2 with
| zero => exact h1
| ss h2 ih => exact ss ih
theorem Even.add' : Even n → Even m → Even (n+m)
| h1, zero => h1
| h1, ss h2 => ss (add' h1 h2) -- the structural recursion in being performed on the implicit `Nat` parameter
theorem mul_left_comm (n m o : Nat) : n * (m * o) = m * (n * o) := by
rw [← Nat.mul_assoc, Nat.mul_comm n m, Nat.mul_assoc]
inductive Power2 : Nat → Prop
| base : Power2 1
| ind : Power2 n → Power2 (2*n) -- Note that index here is not a constructor
theorem Power2_brecOn : typeOf @Power2.brecOn = ∀ {motive : (a : Nat) → Power2 a → Prop} {a : Nat} (x : Power2 a),
(∀ (a : Nat) (x : Power2 a), @Power2.below motive a x → motive a x) → motive a x := rfl
theorem Power2.mul : Power2 n → Power2 m → Power2 (n*m) := by
intro h1 h2
induction h2 with
| base => simp_all
| ind h2 ih => exact mul_left_comm .. ▸ ind ih
/- The following example fails because the structural recursion cannot be performed on the `Nat`s and
the `brecOn` construction doesn't work for inductive predicates -/
-- theorem Power2.mul' : Power2 n → Power2 m → Power2 (n*m)
-- | h1, base => by simp_all
-- | h1, ind h2 => mul_left_comm .. ▸ ind (mul' h1 h2)
inductive tm : Type :=
| C : Nat → tm
| P : tm → tm → tm
open tm
set_option hygiene false in
infixl:40 " ==> " => step
inductive step : tm → tm → Prop :=
| ST_PlusConstConst : ∀ n1 n2,
P (C n1) (C n2) ==> C (n1 + n2)
| ST_Plus1 : ∀ t1 t1' t2,
t1 ==> t1' →
P t1 t2 ==> P t1' t2
| ST_Plus2 : ∀ n1 t2 t2',
t2 ==> t2' →
P (C n1) t2 ==> P (C n1) t2'
def deterministic {X : Type} (R : X → X → Prop) :=
∀ x y1 y2 : X, R x y1 → R x y2 → y1 = y2
theorem step_deterministic' : deterministic step := λ x y₁ y₂ hy₁ hy₂ =>
@step.brecOn (λ s t st => ∀ y₂, s ==> y₂ → t = y₂) _ _ hy₁ (λ s t st hy₁ y₂ hy₂ =>
match hy₁, hy₂ with
| step.below.ST_PlusConstConst _ _, step.ST_PlusConstConst _ _ => rfl
| step.below.ST_Plus1 _ _ _ _ hy₁ ih, step.ST_Plus1 _ t₁' _ _ => by rw [←ih t₁']; assumption
| step.below.ST_Plus1 _ _ _ _ hy₁ ih, step.ST_Plus2 _ _ _ _ => by cases hy₁
| step.below.ST_Plus2 _ _ _ _ _ ih, step.ST_Plus2 _ _ t₂ _ => by rw [←ih t₂]; assumption
| step.below.ST_Plus2 _ _ _ _ hy₁ _, step.ST_PlusConstConst _ _ => by cases hy₁
) y₂ hy₂
section NestedRecursion
axiom f : Nat → Nat
inductive is_nat : Nat -> Prop
| Z : is_nat 0
| S {n} : is_nat n → is_nat (f n)
axiom P : Nat → Prop
axiom F0 : P 0
axiom F1 : P (f 0)
axiom FS {n : Nat} : P n → P (f (f n))
-- we would like to write this
-- theorem foo : ∀ {n}, is_nat n → P n
-- | _, is_nat.Z => F0
-- | _, is_nat.S is_nat.Z => F1
-- | _, is_nat.S (@is_nat.S n h) => FS (foo h)
theorem foo' : ∀ {n}, is_nat n → P n := fun h =>
@is_nat.brecOn (fun n hn => P n) _ h fun n h ih =>
match ih with
| is_nat.below.Z => F0
| is_nat.below.S _ is_nat.below.Z _ => F1
| is_nat.below.S _ (is_nat.below.S a b hx) h₂ => FS hx
end NestedRecursion
end Ex
|
3e7004d7dc837bd7d313a3abf9c90be0a917ccc3 | 5df84495ec6c281df6d26411cc20aac5c941e745 | /src/formal_ml/uniform_probability.lean | bff7449f440cfa5e4e426d8152286a748d6eaf57 | [
"Apache-2.0"
] | permissive | eric-wieser/formal-ml | e278df5a8df78aa3947bc8376650419e1b2b0a14 | 630011d19fdd9539c8d6493a69fe70af5d193590 | refs/heads/master | 1,681,491,589,256 | 1,612,642,743,000 | 1,612,642,743,000 | 360,114,136 | 0 | 0 | Apache-2.0 | 1,618,998,189,000 | 1,618,998,188,000 | null | UTF-8 | Lean | false | false | 33,601 | lean | /-
Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
import measure_theory.measurable_space
import measure_theory.measure_space
import measure_theory.outer_measure
import measure_theory.lebesgue_measure
import measure_theory.integration
import measure_theory.borel_space
import data.set.countable
import formal_ml.nnreal
import formal_ml.sum
import formal_ml.lattice
import formal_ml.measurable_space
import formal_ml.classical
import data.equiv.list
import formal_ml.probability_space
import formal_ml.prod_probability_space
import formal_ml.random_variable_independent_pair
import formal_ml.random_variable_identical_IID
/- This file introduces the uniform probability space over a finite outcome type.
This is in turn used to define a uniform distribution over permutations. -/
--Probably stay here.------------------------
noncomputable def set.cardF {α:Type*} [F:fintype α] (s:set α):nat :=
(@set.to_finset α s (@subtype.fintype α s (classical.decidable_pred s) F)).card
lemma set.univ_cardF_eq_fintype_card {α:Type*} [F:fintype α]:
(@set.univ α).cardF = fintype.card α := begin
simp [set.cardF],
have h1:
@finset.filter α (@set.univ α) (λ (a : α), @set.univ_decidable α a) (@finset.univ α F) =
(@finset.univ α F),
{ ext1 a, split; intros A1; simp, },
rw h1,
simp [fintype.card],
end
lemma finset.disjoint_card_sum {α β:Type*} [decidable_eq α] [fintype α] [decidable_eq β]
(f:β → finset α) (h:pairwise (disjoint on f)) (t:finset β):∀ (s:finset α),
(⋃ (x:β) (h2:x∈ t), (@coe (finset α) (set α) _ (f x))) = ↑s → (s.card = t.sum (λ x, (f x).card)) := begin
classical,
apply finset.induction_on t,
{ intros s h1, simp, simp at h1,
rw finset.ext_iff,
intros a,
rw set.ext_iff at h1,
have h2 := h1 a,
simp at h2,
simp,
apply h2 },
{ intros a s h3 h4 t' h5,
rw finset.sum_insert,
simp at h5,
have h6:(f a) ∪ ((⋃ (x : β) (H : x ∈ s), ↑(f x)).to_finset) = t',
{ rw set.ext_iff at h5,
rw finset.ext_iff,
intros a',
have h6_1 := h5 a',
rw finset.mem_coe at h6_1,
rw ← h6_1,
split; intros h6_2; simp at h6_2; simp [h6_2] },
rw ← h4 ((⋃ (x : β) (H : x ∈ s), ↑(f x)).to_finset),
rw ← finset.card_union_eq,
rw h6,
rw disjoint_iff,
simp, ext x, split; intros h1, simp at h1, cases h1 with h1 h2,
cases h2 with i h2,
cases h2 with h2 h7,
have h8:i ≠ a,
{ intros contra,
subst i, apply h3, apply h2, },
have h9 := h i a h8,
simp [function.on_fun] at h9,
rw disjoint_iff at h9,
simp at h9,
rw ← h9,
simp [h1, h7],
exfalso,
apply h1,
simp,
apply h3,
},
end
def semiring.of_nat_hom (α:Type*) [semiring α]:nat →+* α := {
to_fun := coe,
map_one' := begin
simp,
end,
map_mul' := begin
intros x y,
simp,
end,
map_add' := begin
intros x y,
simp,
end,
map_zero' := begin
simp,
end
}
lemma finset.prod_coe_nat {α β:Type*} [comm_semiring α] {s:finset β} {f:β → nat}:
(@coe nat α _) (s.prod f) = s.prod (λ (b:β), (@coe nat α _) (f b)) := begin
have h1:(@coe nat α _) = (semiring.of_nat_hom α).to_fun,
{ refl },
rw h1,
simp,
end
lemma finset.sum_coe_nat {α β:Type*} [comm_semiring α] {s:finset β} {f:β → nat}:
(@coe nat α _) (s.sum f) = s.sum (λ (b:β), (@coe nat α _) (f b)) := begin
have h1:(@coe nat α _) = ⇑(semiring.of_nat_hom α),
{ refl },
rw h1,
rw ring_hom.map_sum,
end
/- TODO: reverse direction if you get a chance. -/
lemma disjoint_to_finset_iff {α:Type*} [F:fintype α] [decidable_eq α]
{s t:set α} [decidable_pred s] [decidable_pred t]:disjoint s t ↔ disjoint (s.to_finset) (t.to_finset) :=
begin
rw disjoint_iff,
rw disjoint_iff,
rw set.ext_iff,
rw finset.ext_iff,
simp, split; intros h1 x; have h2 := h1 x,
{ split; intros h3, apply absurd h3.right,
apply h2, apply h3.left, exfalso, apply h3 },
{ intros h3 h4, have h5 := and.intro h3 h4,
rw h2 at h5, apply h5 },
end
---DEFINITELY stay here.--------------------
noncomputable def uniform_measure (α:Type*) [F:fintype α]:
@measure_theory.measure α ⊤ := @measure_theory.measure.of_measurable α ⊤
(λ (s:set α) (h:@measurable_set α ⊤ s),
((s.cardF):ennreal)/((fintype.card α):ennreal))
begin
simp [set.cardF],
end
begin
classical,
intros f h_meas h_disjoint,
let s:finset α := (⋃ (i : ℕ), f i).to_finset,
begin
simp,
have h0:s = (⋃ (i : ℕ), f i).to_finset := rfl,
rw div_eq_mul_inv,
have h2:(λ (i:ℕ), (((f i).cardF):ennreal) / ((@fintype.card α F):ennreal)) =
λ (i:ℕ), (((f i).cardF):ennreal) * ((@fintype.card α F):ennreal)⁻¹,
{ ext1 i, rw div_eq_mul_inv },
rw h2,
rw ennreal.tsum_mul_right,
have h3:↑((@set.Union α ℕ f).cardF) = (∑' (i : ℕ), ↑((f i).cardF)),
{
have h4:∀ (x:α), ∃ (i:ℕ), x∈ s → x ∈ f i,
{ intros x, cases classical.em (x ∈ s) with h4_1 h4_1,
rw h0 at h4_1,simp at h4_1, cases h4_1 with i h4_1,
apply exists.intro i, intros h4_2, apply h4_1,
apply exists.intro 0, intros h4_2, apply absurd h4_2, apply h4_1, },
rw classical.skolem at h4,
cases h4 with g h4,
let t := s.image g,
rw @tsum_eq_sum ennreal ℕ _ _ _ _ t,
have h5:s.card = (@set.Union α ℕ f).cardF,
{ simp [set.cardF], have h5_1:(λ (x : α), ∃ (i : ℕ), x ∈ f i) = (set.Union f),
{ ext;split; intros A1; simp at A1; cases A1 with i A1;
simp; apply exists.intro i; apply A1, },
rw h5_1, },
rw ← h5,
rw ← finset.sum_coe_nat,
simp only [nat.cast_inj, set.cardF],
rw ← finset.disjoint_card_sum,
{ intros i j h_ne, simp [function.on_fun], rw ← disjoint_to_finset_iff,
apply h_disjoint, apply h_ne },
{ simp, ext a, split, intros h6, simp at h6, simp,
{ cases h6 with a' h6, cases h6 with h6 h7,
apply exists.intro (g a'), apply h7 },
{ intros h6, simp, apply exists.intro a, split,
{ simp at h6, apply h6 },
{ apply h4, simp [s], simp at h6, apply h6 }, } },
intros i h8,
have h9:f i = ∅,
{ ext a, split; intros A1,
exfalso, apply h8,
have h9_1:a ∈ s,
{ simp [s], apply exists.intro i, apply A1 },
have h9_2:a∈ f (g a) := h4 a h9_1,
have h9_3:g a = i,
{ apply by_contradiction,
intros h9_3_1,
have h9_3_2:disjoint (f (g a)) (f i),
{ apply h_disjoint, apply h9_3_1, },
rw disjoint_iff at h9_3_2,
simp at h9_3_2,
have h9_3_3:a∈ (f (g a)) ∩ (f i),
{ simp, apply and.intro h9_2 A1 },
rw h9_3_2 at h9_3_3,
apply h9_3_3 },
subst i, simp [t], apply exists.intro a,
split,
apply exists.intro (g a),
apply A1, refl, exfalso, apply A1 },
rw h9,
simp [set.cardF], refl,
},
rw h3,
end
end
lemma uniform_measure_apply (α:Type*) [F:fintype α] (s:set α):
(uniform_measure α) s =
((s.cardF):ennreal)/((fintype.card α):ennreal) := begin
apply measure_theory.measure.of_measurable_apply,
simp,
end
noncomputable def uniform_measure_space (α:Type*) [F:fintype α]:
measure_theory.measure_space α := @measure_theory.measure_space.mk α ⊤
(uniform_measure α)
lemma uniform_measure_space_apply (α:Type*) [F:fintype α] (s:set α):
@measure_theory.measure_space.volume _ (uniform_measure_space α) s =
((s.cardF):ennreal)/((fintype.card α):ennreal) := begin
have h1: (@measure_theory.measure_space.volume α (@uniform_measure_space α F)) =
(uniform_measure α),
{ refl },
rw h1,
apply uniform_measure_apply,
end
lemma uniform_measure_space.to_measurable_space_eq_top (α:Type*) [F:fintype α]:
(uniform_measure_space α).to_measurable_space = ⊤ := rfl
lemma uniform_measure_space.measurable_set'_all (α:Type*) [F:fintype α] (s:set α):
(uniform_measure_space α).to_measurable_space.measurable_set' s := begin
rw uniform_measure_space.to_measurable_space_eq_top,
apply measurable_space.measurable_set_top,
end
/- DO NOT DELETE!
There is already proven:
1. permutations are finite.
2. There cardinality is the factorial.
This tells me we are on the right track! -/
#check fintype.card_perm
lemma fintype.card_ne_zero {α:Type*} [F:fintype α] [N:nonempty α]:
¬(fintype.card α = 0) := begin
apply pos_iff_ne_zero.1,
rw fintype.card_pos_iff,
apply N,
end
noncomputable def uniform_probability_space (α:Type*) [F:fintype α] [N:nonempty α]:
probability_space α := @probability_space.mk α (uniform_measure_space α)
begin
simp,
rw uniform_measure_space_apply,
rw set.univ_cardF_eq_fintype_card,
rw div_eq_mul_inv,
apply ennreal.mul_inv_cancel,
{ simp, apply fintype.card_ne_zero },
{ simp },
end
lemma uniform_probability_space.to_measurable_space_eq_top (α:Type*) [F:fintype α] [NE:nonempty α]:
(uniform_probability_space α).to_measurable_space = ⊤ := rfl
lemma uniform_probability_space.to_measure_space_eq (α:Type*) [F:fintype α] [NE:nonempty α]:
(uniform_probability_space α).to_measure_space = uniform_measure_space α := rfl
lemma uniform_probability_space.measurable_set'_all (α:Type*) [F:fintype α] [nonempty α] (s:set α):
(uniform_probability_space α).to_measurable_space.measurable_set' s := begin
rw uniform_probability_space.to_measurable_space_eq_top,
apply measurable_space.measurable_set_top,
end
def uniform_event {α:Type*} (s:set α) [F:fintype α] [N:nonempty α]:
event (uniform_probability_space α) := {
val := s,
property := begin
apply uniform_probability_space.measurable_set'_all,
end
}
def uniform_probability_space.measurable_all {α β:Type*} [F:fintype α] [nonempty α]
(M:measurable_space β) (f:α → β):@measurable α β
(uniform_probability_space α).to_measurable_space M f := begin
intros S h1,
apply uniform_probability_space.measurable_set'_all,
end
lemma uniform_probability_space_apply' (α:Type*) [F:fintype α] [nonempty α] (s:event (uniform_probability_space α)):
Pr[s] =
((s.val.cardF):nnreal)/((fintype.card α):nnreal) := begin
rw ← ennreal.coe_eq_coe,
rw event_prob_def,
rw uniform_probability_space.to_measure_space_eq,
simp,
rw ← subtype.val_eq_coe,
rw @uniform_measure_space_apply α F s.val,
rw ennreal.coe_div,
have h1:∀ (n:ℕ), (@coe nnreal ennreal _ (@coe nat nnreal _ n)) = (@coe nat ennreal _ n),
{ simp },
rw h1,
rw h1,
simp,
apply fintype.card_ne_zero,
end
lemma uniform_probability_space_apply (α:Type*) [F:fintype α] [nonempty α] (s:set α):
Pr[uniform_event s] =
((s.cardF):nnreal)/((fintype.card α):nnreal) := begin
apply uniform_probability_space_apply',
end
def uniform_rv {α:Type*} [F:fintype α] [N:nonempty α] (M:measurable_space α):
(uniform_probability_space α) →ᵣ M := {
val := id,
property := begin
apply uniform_probability_space.measurable_all,
end
}
def is_uniform_rv {Ω α:Type*} {P:probability_space Ω} [F:fintype α] {M:measurable_space α}
(X:P →ᵣ M):Prop := ∀ (S:measurable_setB M),
Pr[X ∈ᵣ S] = ((S.val.cardF):nnreal)/((fintype.card α):nnreal)
@[simp]
lemma is_uniform_rv_uniform_rv {α:Type*} [F:fintype α] [N:nonempty α] (M:measurable_space α):
is_uniform_rv (uniform_rv M) := begin
intros S,
let S':= uniform_event S.val,
begin
have h1:@uniform_rv α F N M ∈ᵣ S = S',
{ apply event.eq, simp [uniform_rv, S', uniform_event], },
rw h1,
rw uniform_probability_space_apply,
end
end
def nonempty_perm {α:Type*}:nonempty (equiv.perm α) := nonempty.intro (equiv.refl α)
def uniform_perm_rv (α:Type*) [D:decidable_eq α] [F:fintype α] (M:measurable_space (equiv.perm α)):_ →ᵣ M :=
--(@uniform_probability_space (equiv.perm α) (@fintype_perm α D F) nonempty_perm) →ᵣ M :=
@uniform_rv (equiv.perm α) (@fintype_perm α D F) nonempty_perm M
lemma is_uniform_rv_uniform_perm_rv {α:Type*} [F:fintype α] [N:decidable_eq α]
(M:measurable_space (equiv.perm α)):
@is_uniform_rv _ (equiv.perm α) _ (@fintype_perm α N F) _ (@uniform_perm_rv α N F M) := begin
apply is_uniform_rv_uniform_rv,
end
lemma select_rv_union_helper {Ω α γ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{M:measurable_space γ} (TM:top_measurable α)
(X:α → P →ᵣ M) (Y:P →ᵣ (TM.to_measurable_space)) (S:set γ):
((λ (ω : Ω), (X (Y.val ω)).val ω) ⁻¹' S) =
⋃ (a:α), ((Y.val ⁻¹' {a}) ∩ ((X a).val ⁻¹' S)) := begin
ext1 ω,split; intros h1; simp at h1; simp [h1],
end
def select_rv {Ω α γ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{M:measurable_space γ}
{TM:top_measurable α} (X:α → P →ᵣ M) (Y:P →ᵣ TM.to_measurable_space):
P →ᵣ M := {
val := (λ ω:Ω, (X (Y.val ω)).val ω),
property := begin
intros S h1,
have h2:((λ (ω : Ω), (X (Y.val ω)).val ω) ⁻¹' S) =
⋃ (a:α), ((Y.val ⁻¹' {a}) ∩ ((X a).val ⁻¹' S)),
{ apply select_rv_union_helper },
rw h2,
haveI:encodable α := fintype.encodable α,
apply measurable_set.Union,
intros a,
apply measurable_set.inter,
apply Y.property,
apply TM.all_measurable,
apply (X a).property,
apply h1,
end
}
lemma select_rv_apply {Ω α γ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{M:measurable_space γ} {TM:top_measurable α}
(X:α → P →ᵣ M) (Y:P →ᵣ (TM.to_measurable_space)) (S:measurable_setB M):
(select_rv X Y ∈ᵣ S) = (∃ᵣ (a:α), ((Y =ᵣ a) ∧ ((X a) ∈ᵣ S))) := begin
apply event.eq,
simp [select_rv],
ext; split; intros h1; simp at h1; simp [h1],
end
def perm_value_rv {Ω α:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{TMp:top_measurable (equiv.perm α)}
(Y:P →ᵣ (TMp.to_measurable_space)) (a:α)
(M:measurable_space α):
P →ᵣ M := {
val := (λ ω:Ω, (Y.val ω) a),
property := begin
classical,
intros S A1,
let T := {p:equiv.perm α|p a ∈ S},
begin
have h1:((λ (ω : Ω), (Y.val ω) a) ⁻¹' S) = ⋃ (p∈ T), ((Y.val) ⁻¹' {p}),
{ ext ω, split; intros h1_1; simp [T] at h1_1; simp [h1_1,T] },
rw h1,
haveI:encodable (equiv.perm α) := fintype.encodable (equiv.perm α),
apply measurable_set.Union,
intros p,
apply measurable_set.Union_Prop,
intros h2,
apply Y.property,
apply TMp.all_measurable,
end
end
}
lemma perm_value_rv_apply {Ω α:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{TMp:top_measurable (equiv.perm α)}
(Y:P →ᵣ (TMp.to_measurable_space)) (a:α)
(M:measurable_space α) (S:measurable_setB M)
[D:decidable_pred (λ (p:equiv.perm α), p a ∈ S.val)]:
(perm_value_rv Y a M) ∈ᵣ S =
∃ᵣ (p:equiv.perm α) in (set.to_finset (λ (p:equiv.perm α), p a ∈ S.val)),
(Y =ᵣ p) :=
begin
apply event.eq, ext ω, split; intros h1; simp [perm_value_rv] at h1;
simp [perm_value_rv, h1]; apply h1,
end
--set_option pp.implicit true
lemma perm_value_rv_independent {Ω α κ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{TMp:top_measurable (equiv.perm α)}
{Mκ:measurable_space κ}
(Y:P →ᵣ (TMp.to_measurable_space)) (a:α) (X:P →ᵣ Mκ)
(M:measurable_space α):
random_variable_independent_pair X Y →
random_variable_independent_pair X (perm_value_rv Y a M) :=
begin
classical,
intro h1,
intros S T,
rw perm_value_rv_apply,
apply independent_event_pair_exists,
{ intros p h2,
have h3:Y =ᵣ ↑p = Y ∈ᵣ ({p}:set (equiv.perm α)),
{ apply equal_eq_mem },
rw h3,
apply h1 },
intros i h2 j h3 h_ne,
simp [function.on_fun, disjoint_iff],
{ ext ω, split; intros h3,
{ simp at h3, exfalso, apply h_ne,
cases h3, subst i, subst j },
{ exfalso, apply h3 } },
end
def permute_rv {Ω α γ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{TM:top_measurable (equiv.perm α)}
{M:measurable_space γ} (X:α → P →ᵣ M) (perm:P →ᵣ TM.to_measurable_space)
(TMα:top_measurable α):
α → P →ᵣ M := (λ (a:α), select_rv X (perm_value_rv perm a TMα))
lemma permute_rv_identical {Ω α γ:Type*} [F:fintype α] [decidable_eq α]
{P:probability_space Ω}
{M:measurable_space γ} {TM:top_measurable (equiv.perm α)}
(TMα:top_measurable α)
(X:α → P →ᵣ M) (perm:P →ᵣ (TM.to_measurable_space)):
(∀ (a:α), random_variable_independent_pair perm (X a)) →
(∀ (a a':α), random_variable_identical (X a) (X a')) →
(∀ (a a':α), random_variable_identical (X a) ((permute_rv X perm TMα) a'))
:= begin
intros h1 h2 a a',
simp [permute_rv],
intros S,
rw select_rv_apply,
have h3:eany_finset finset.univ (λ (a : α), perm_value_rv perm a' TMα =ᵣ a∧X a ∈ᵣ S)
= (∃ᵣ (a : α), perm_value_rv perm a' TMα =ᵣ a∧X a ∈ᵣ S),
{
apply event.eq, simp,
},
rw ← h3,
haveI:encodable α := fintype.encodable α,
rw Pr_sum_disjoint_eq,
have h4:(λ (b : α), Pr[perm_value_rv perm a' TMα =ᵣ b∧X b ∈ᵣ S]) =
(λ (b : α), Pr[perm_value_rv perm a' TMα =ᵣ b] * Pr[X a ∈ᵣ S]),
{ ext b,
have h4_1:random_variable_independent_pair (X b) perm,
{ apply random_variable_independent_pair.symm, apply (h1 b), },
have h4_2 := perm_value_rv_independent perm a' (X b) TMα.to_measurable_space h4_1,
have h4_3:(perm_value_rv perm a' TMα =ᵣ b) =
perm_value_rv perm a' TMα ∈ᵣ (measurable_setB_top {b}),
{ apply equal_eq_mem },
rw h4_3,
have h4_4:independent_event_pair
(perm_value_rv perm a' TMα ∈ᵣ (measurable_setB_top {b})) (X b ∈ᵣ S),
{ apply random_variable_independent_pair.symm,
apply h4_2, },
unfold independent_event_pair at h4_4,
rw h4_4,
--rw mul_comm,
simp,
left, apply h2 b a,
},
rw h4,
rw ← @finset.sum_mul α nnreal finset.univ,
rw Pr_sum_univ_eq_one,
simp,
intros i j h_ne,
rw function.on_fun,
rw disjoint_iff,
simp,
ext ω, split; intros A1; simp at A1; simp [A1],
apply h_ne,
rw ← A1.left.left,
rw ← A1.right.left,
apply false.elim A1,
end
lemma random_variables_independent_proj {Ω α β γ:Type*} [fintype α] [fintype β]
(P:probability_space Ω) (M:measurable_space γ) (X:α → P →ᵣ M) (f:β → α):
(function.injective f) →
(random_variable_independent X) →
(random_variable_independent (λ (b:β), X (f b))) := begin
classical,
intros h1 h2,
intros g T,
simp,
have h3:∀ (a:α), ∃ (S:measurable_setB M), ∀ (b:β), (f b = a) → (g b = S),
{ intros a, cases classical.em (∃ (b:β), f b = a) with h3_1 h3_1,
{ cases h3_1 with b h3_1,
apply exists.intro (g b),
intros b' h_b',
rw ← h3_1 at h_b',
have h3_2 := h1 h_b', rw h3_2 },
{ apply exists.intro measurable_setB_univ,
intros b' h_b',
exfalso,
apply h3_1,
apply exists.intro b',
apply h_b' }, },
have h4 := classical.axiom_of_choice h3,
cases h4 with g' h4,
have h5:∀ (b:β), g b = g' (f b),
{ intros b, apply h4 (f b) b _, refl },
have h6:(λ (b : β), Pr[X (f b) ∈ᵣ g b]) = (λ (a:α), Pr[X a ∈ᵣ g' a]) ∘ f,
{ ext1 b, simp, rw h5 },
rw h6,
have h7:T.prod ((λ (a:α), Pr[X a ∈ᵣ g' a]) ∘ f) = (T.image f).prod (λ (a:α), Pr[X a ∈ᵣ g' a]),
{ rw finset.prod_image, intros b h_b b' h_b' h_eq,
apply h1, apply h_eq },
rw h7,
have h8: (∀ᵣ (s : β) in T,X (f s) ∈ᵣ g s) = (∀ᵣ (a:α) in (T.image f), X a ∈ᵣ g' a),
{ apply event.eq, simp, ext ω, split; intros h8_1; simp at h8_1; simp [h8_1];
intros i h_i,
{ rw ← h5, apply h8_1 i h_i },
{ rw h5, apply h8_1 i h_i } },
rw h8,
apply h2,
end
lemma random_variables_IID_proj {Ω α β γ:Type*} [fintype α] [fintype β]
(P:probability_space Ω) (M:measurable_space γ) (X:α → P →ᵣ M) (f:β → α):
(function.injective f) →
(random_variables_IID X) →
(random_variables_IID (λ (b:β), X (f b))) := begin
intros h1 h2, split,
{ apply random_variables_independent_proj, apply h1, apply h2.left },
intros i j,
apply h2.right,
end
lemma random_variable_independent_pair_combine_apply {Ω α γ κ:Type*}
[F:fintype α]
{P:probability_space Ω}
{M:measurable_space γ} {Mκ:measurable_space κ}
(X:P →ᵣ Mκ) (Y:α → P →ᵣ M) (a:α):
random_variable_independent_pair X (pi.random_variable_combine Y) →
random_variable_independent_pair X (Y a) := begin
intros h1,
intros S₁ S₂,
have h2:(Y a ∈ᵣ S₂) = ((mf_pi (λ (a:α), M) a) ∘r (pi.random_variable_combine Y)) ∈ᵣ S₂,
{ apply event.eq, simp, split; intros h2_1; simp at h2_1; simp at h2_1, },
rw h2,
rw rv_compose_measurable_setB,
apply h1,
end
lemma pairwise_disjoint_left {Ω α:Type*}
{P:probability_space Ω}
{E F:α → event P}:
(pairwise (disjoint on (λ a, (E a).val))) →
(pairwise (disjoint on (λ a, (E a ∧ F a).val))) := begin
intros h1,
intros i j h_eq,
have h2 := h1 i j h_eq,
simp [function.on_fun],
simp [function.on_fun] at h2,
rw disjoint_iff,
rw disjoint_iff at h2,
simp,
rw ← set.subset_empty_iff,
apply set.subset.trans,
apply set.inter_subset_inter,
apply set.inter_subset_left,
apply set.inter_subset_left,
simp at h2,
rw h2,
end
/- Take a given event: The arugment for this is that for any fixed permutation,
the IID property holds. If we can show that this holds for every permutation,
then we will be done. -/
lemma permute_rv_independent {Ω α γ:Type*} [F:fintype α] [D:decidable_eq α] [inhabited α]
{P:probability_space Ω}
{M:measurable_space γ} {TM:top_measurable (equiv.perm α)}
{TMα:top_measurable α}
(X:α → P →ᵣ M) (perm:P →ᵣ (TM.to_measurable_space)):
(random_variable_independent_pair perm (pi.random_variable_combine X)) →
(random_variables_IID X) →
(random_variable_independent (permute_rv X perm TMα)) := begin
intros h1 h2,
intros S T,
simp,
let a := inhabited.default α,
begin
have h4:∀ (S:measurable_setB M), ∀ (a':α),
Pr[X a' ∈ᵣ S] = Pr[X a ∈ᵣ S],
{ intros S a', apply h2.right a' a },
have h_pair_ind:∀ (a':α), random_variable_independent_pair perm (X a'),
{ intros a', apply random_variable_independent_pair_combine_apply perm X a' h1 },
have h5:∀ (S:measurable_setB M), ∀ (a':α),
Pr[permute_rv X perm TMα a' ∈ᵣ S] = Pr[X a ∈ᵣ S],
{ intros S a', symmetry,
have h5_1 := permute_rv_identical TMα X perm h_pair_ind _ a a',
apply h5_1,
apply h2.right },
rw @finset.prod_congr α nnreal _ T _ (λ (b:α), Pr[X a ∈ᵣ S b]),
have h7:(∀ᵣ (s : α) in T, permute_rv X perm TMα s ∈ᵣ S s) =
eany_finset (finset.univ) (λ (p:equiv.perm α), (perm =ᵣ p) ∧
(∀ᵣ (s : α) in (T.image p),X s ∈ᵣ S (p.inv_fun s))),
{ apply event.eq, ext ω, split; intros h7_1;
simp [equiv_cancel_left, permute_rv, select_rv, perm_value_rv] at h7_1;
simp [equiv_cancel_left, permute_rv, select_rv, perm_value_rv, h7_1]; intros i h_i,
{ rw equiv_cancel_left, apply h7_1 i h_i },
{ have h7_2 := h7_1 i h_i, rw equiv_cancel_left at h7_2, apply h7_2 } },
rw h7,
--haveI:fintype (equiv.perm α) := infer_instance,
haveI E:encodable (equiv.perm α) := fintype.encodable (equiv.perm α),
rw @Pr_sum_disjoint_eq Ω (equiv.perm α) P,
have h8:(λ (b : equiv.perm α), Pr[perm =ᵣ ↑b∧∀ᵣ (s : α) in (T.image b),X s ∈ᵣ S (b.inv_fun s)]) =
(λ (b : equiv.perm α), T.prod (λ a', Pr[X a ∈ᵣ S a']) * Pr[perm =ᵣ ↑b]),
{ ext1 b,
have h8_1:independent_event_pair (perm =ᵣ b) (∀ᵣ (s : α) in (T.image b),X s ∈ᵣ S (b.inv_fun s)),
{ apply random_variable_independent_pair_apply h1,
apply equal_eq_mem_exists,
apply joint_random_variable_mem_exists X (T.image b) (S ∘ (b.inv_fun)),
},
unfold independent_event_pair at h8_1,
rw h8_1,
rw mul_comm,
have h8_2:random_variable_independent X :=h2.left,
have h8_3:independent_events (λ (s : α),X s ∈ᵣ S (b.inv_fun s)),
{ apply h8_2 },
rw ← h8_3 (T.image b), rw finset.prod_image, simp,
left,
apply finset.prod_congr, refl, intros x h_x, rw equiv_cancel_left, apply h4,
intros i h_i j h_j h_eq, simp at h_eq, apply h_eq },
rw h8,
rw finset.sum_distrib_left,
have h9:finset.univ.sum (λ (a : equiv.perm α), Pr[perm =ᵣ ↑a]) = 1,
{ rw Pr_sum_univ_eq_one },
rw h9,
simp,
{ apply pairwise_disjoint_left, apply event_eq_disjoint },
refl,
{ intros x h_x, rw h5 },
end
end
lemma permute_rv_IID' {Ω α γ:Type*} [fintype α] [decidable_eq α] [I:inhabited α]
{P:probability_space Ω}
{M:measurable_space γ} {TM:top_measurable (equiv.perm α)}
{TMα:top_measurable α}
(X:α → P →ᵣ M) (perm:P →ᵣ (TM.to_measurable_space)):
(random_variables_IID X) →
(random_variable_independent_pair perm (pi.random_variable_combine X)) →
(random_variables_IID (permute_rv X perm TMα)) := begin
intros h1 h2,
split,
apply permute_rv_independent,
apply h2,
apply h1,
have h4:∀ (a a'), random_variable_identical (X a) (permute_rv X perm TMα a'),
{ apply permute_rv_identical,
intros a'',
apply random_variable_independent_pair_combine_apply,
apply h2,
apply h1.right },
intros i j,
apply random_variable_identical.trans,
apply random_variable_identical.symm,
apply h4 (inhabited.default α) i,
apply h4,
end
lemma permute_rv_IID {Ω α γ:Type*} [fintype α] [decidable_eq α] {P:probability_space Ω}
{M:measurable_space γ} {TM:top_measurable (equiv.perm α)}
{TMα:top_measurable α}
(X:α → P →ᵣ M) (perm:P →ᵣ (TM.to_measurable_space)):
(random_variables_IID X) →
(random_variable_independent_pair perm (pi.random_variable_combine X)) →
(random_variables_IID (permute_rv X perm TMα)) := begin
classical,
cases classical.em (nonempty α) with h1 h1,
{ haveI:inhabited α := classical.inhabited_of_nonempty h1,
apply permute_rv_IID' },
intros h2 h3, apply random_variables_IID_empty,
apply h1,
end
/--
This is a core result, that a partition of an IID random variable results in two independent
random variables.
It is not as trivial as it appears, as one must handle events that expose correlations
within each set. Again, the monotone class theorem is useful.
Note: functions do not have to be injective, nor does β₁ or β₂ have to be nonempty.
However, this can be used to prove the case when they
are not, as you can create an injective function as an intermediate step,
and case-based analysis can handle the cases where β₁ or β₂ are empty. -/
lemma random_variables_independent_disjoint_proj {Ω α β₁ β₂ γ:Type*} [fintype α] [fintype β₁] [fintype β₂] [nonempty β₁] [nonempty β₂]
(P:probability_space Ω) (M:measurable_space γ) (X:α → P →ᵣ M) (f₁:β₁ → α) (f₂:β₂ → α):
(function.injective f₁) →
(function.injective f₂) →
(disjoint (set.range f₁) (set.range f₂)) →
(random_variable_independent X) →
(random_variable_independent_pair (pi.random_variable_combine (λ (b:β₁), X (f₁ b))) (pi.random_variable_combine (λ (b:β₂), X (f₂ b)))) := begin
intros h1 h2 h_disjoint_range h3,
haveI:encodable β₁ := fintype.encodable β₁,
haveI:encodable β₂ := fintype.encodable β₂,
apply random_variable_independent_pair_on_semialgebra' pi_base,
apply pi_base_is_semialgebra,
apply pi_base_is_semialgebra,
apply pi_base_eq_measurable_space_pi,
apply pi_base_eq_measurable_space_pi,
intros T₁ T₂ h_T₁ h_T₂,
unfold independent_event_pair,
have h_T₁_def := pi_base_eq T₁ h_T₁,
have h_T₂_def := pi_base_eq T₂ h_T₂,
cases h_T₁_def with g₁ h_T₁_def,
cases h_T₂_def with g₂ h_T₂_def,
subst T₁,
subst T₂,
classical,
let U₁:finset α := (finset.image f₁ (@finset.univ β₁ _)),
let U₂:finset α := (finset.image f₂ (@finset.univ β₂ _)),
begin
have h_mem_U₁:∀ (a:α), a ∈ U₁ ↔ a ∈ (set.range f₁),
{ simp [U₁], },
have h_mem_U₂:∀ (a:α), a ∈ U₂ ↔ a ∈ (set.range f₂),
{ simp [U₂], },
have h_b₁_ne_b₂:∀ (b₁:β₁) (b₂:β₂), f₁ b₁ ≠ f₂ b₂,
{ intros b₁ b₂ h_contra,
rw disjoint_iff at h_disjoint_range,
simp at h_disjoint_range,
rw ← set.subset_empty_iff at h_disjoint_range,
rw set.subset_def at h_disjoint_range,
apply h_disjoint_range (f₁ b₁),
rw set.mem_inter_iff,
split,
simp,
rw h_contra,
simp },
have h_disjoint:disjoint U₁ U₂,
{ rw disjoint_iff, simp, ext a, split; intros h_sub1,
{ exfalso,
rw finset.mem_inter at h_sub1,
rw h_mem_U₁ at h_sub1,
rw h_mem_U₂ at h_sub1,
rw ← set.mem_inter_iff at h_sub1,
rw disjoint_iff at h_disjoint_range,
simp at h_disjoint_range,
rw ← set.subset_empty_iff at h_disjoint_range,
rw set.subset_def at h_disjoint_range,
--have h_disjoint_range_contra := h_disjoint_range a h_sub1,
apply h_disjoint_range,
apply h_sub1 },
{ exfalso, apply h_sub1 } },
have h_inv:∀ (a:α), ∃ (S:measurable_setB M),
(∀ (b:β₁), f₁ b = a → S = g₁ b) ∧ (∀ (b:β₂), f₂ b = a → S = g₂ b),
{ intros a,
cases classical.em (∃ (b:β₁), f₁ b = a) with h_in_U₁ h_notin_U₁,
{ cases h_in_U₁ with b₁ h_b₁,
subst a,
apply exists.intro (g₁ b₁),
split,
{ intros b₁' h_b₁', simp [h1] at h_b₁', subst b₁' },
{ intros b₂' h_b₂', exfalso, apply h_b₁_ne_b₂ b₁ b₂', rw h_b₂' } },
-- If a is not in U₁, then we consider when it is in U₂.
cases classical.em (∃ (b₂:β₂), f₂ b₂ = a) with h_in_U₂ h_notin_U₂,
{ cases h_in_U₂ with b₂ h_b₂,
subst a,
apply exists.intro (g₂ b₂),
split,
{ intros b₁' h_b₁', exfalso, apply h_b₁_ne_b₂ b₁' b₂, rw h_b₁' },
{ intros b₂' h_b₂', simp [h2] at h_b₂', subst b₂' } },
-- If a is not in U₁ or U₂, then just use the universal set.
{ apply exists.intro (∅:measurable_setB M),
split,
{ intros b₁ h_b₁, exfalso, apply h_notin_U₁,
apply exists.intro b₁, apply h_b₁ },
{ intros b₂ h_b₂, exfalso, apply h_notin_U₂,
apply exists.intro b₂, apply h_b₂ } } },
rw classical.skolem at h_inv,
cases h_inv with g_inv h_inv,
have h_inv₁:pi.random_variable_combine (λ (b : β₁), X (f₁ b)) ∈ᵣ
set.pi_measurable (set.univ) g₁ = (∀ᵣ a in U₁, X a ∈ᵣ g_inv a),
{ apply event.eq, ext1 ω, split; intros h_sub1;
simp [pi.random_variable_combine, set.pi_measurable,
pi.measurable_fun] at h_sub1;
simp [pi.random_variable_combine, set.pi_measurable,
pi.measurable_fun, h_sub1];
intros b₁,
{ rw (h_inv (f₁ b₁)).left b₁ _, apply h_sub1, refl },
{ rw ← (h_inv (f₁ b₁)).left b₁ _, apply h_sub1, refl } },
rw h_inv₁,
have h_inv₂:pi.random_variable_combine (λ (b : β₂), X (f₂ b)) ∈ᵣ
set.pi_measurable (set.univ) g₂ = (∀ᵣ a in U₂, X a ∈ᵣ g_inv a),
{ apply event.eq, ext1 ω, split; intros h_sub1;
simp [pi.random_variable_combine, set.pi_measurable,
pi.measurable_fun] at h_sub1;
simp [pi.random_variable_combine, set.pi_measurable,
pi.measurable_fun, h_sub1];
intros b₂,
{ rw (h_inv (f₂ b₂)).right b₂ _, apply h_sub1, refl },
{ rw ← (h_inv (f₂ b₂)).right b₂ _, apply h_sub1, refl }, },
rw h_inv₂,
have h_union:((∀ᵣ (a : α) in U₁,X a ∈ᵣ g_inv a)∧(∀ᵣ (a : α) in U₂,X a ∈ᵣ g_inv a))
= (∀ᵣ (a : α) in (U₁∪ U₂),X a ∈ᵣ g_inv a),
{ apply event.eq, ext1 ω, split; intros h_sub1; simp at h_sub1; simp [h_sub1],
-- Simplification solves one direction.
intros a h_sub2, cases h_sub2 with h_in_U₁ h_in_U₂,
{ cases h_in_U₁ with b₁ h_b₁, subst a, apply h_sub1.left },
{ cases h_in_U₂ with b₂ h_b₂, subst a, apply h_sub1.right } },
rw h_union,
rw ← h3 g_inv U₁,
rw ← h3 g_inv U₂,
rw ← h3 g_inv (U₁ ∪ U₂),
rw finset.prod_union,
apply h_disjoint,
end
end
|
f2c413813c1efd184b5b8e0516f37b574c5051e6 | 82e44445c70db0f03e30d7be725775f122d72f3e | /src/measure_theory/continuous_map_dense.lean | 0983a6fbf302782c2ffaaecc3cb90c5ae23dac8f | [
"Apache-2.0"
] | permissive | stjordanis/mathlib | 51e286d19140e3788ef2c470bc7b953e4991f0c9 | 2568d41bca08f5d6bf39d915434c8447e21f42ee | refs/heads/master | 1,631,748,053,501 | 1,627,938,886,000 | 1,627,938,886,000 | 228,728,358 | 0 | 0 | Apache-2.0 | 1,576,630,588,000 | 1,576,630,587,000 | null | UTF-8 | Lean | false | false | 10,279 | lean | /-
Copyright (c) 2021 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import measure_theory.regular
import measure_theory.simple_func_dense
import topology.urysohns_lemma
/-!
# Approximation in Lᵖ by continuous functions
This file proves that bounded continuous functions are dense in `Lp E p μ`, for `1 ≤ p < ∞`, if the
domain `α` of the functions is a normal topological space and the measure `μ` is weakly regular.
The result is presented in several versions:
* `measure_theory.Lp.bounded_continuous_function_dense`: The subgroup
`measure_theory.Lp.bounded_continuous_function` of `Lp E p μ`, the additive subgroup of
`Lp E p μ` consisting of equivalence classes containing a continuous representative, is dense in
`Lp E p μ`.
* `bounded_continuous_function.to_Lp_dense_range`: For finite-measure `μ`, the continuous linear
map `bounded_continuous_function.to_Lp p μ 𝕜` from `α →ᵇ E` to `Lp E p μ` has dense range.
* `continuous_map.to_Lp_dense_range`: For compact `α` and finite-measure `μ`, the continuous linear
map `continuous_map.to_Lp p μ 𝕜` from `C(α, E)` to `Lp E p μ` has dense range.
Note that for `p = ∞` this result is not true: the characteristic function of the set `[0, ∞)` in
`ℝ` cannot be continuously approximated in `L∞`.
The proof is in three steps. First, since simple functions are dense in `Lp`, it suffices to prove
the result for a scalar multiple of a characteristic function of a measurable set `s`. Secondly,
since the measure `μ` is weakly regular, the set `s` can be approximated above by an open set and
below by a closed set. Finally, since the domain `α` is normal, we use Urysohn's lemma to find a
continuous function interpolating between these two sets.
## Related results
Are you looking for a result on "directional" approximation (above or below with respect to an
order) of functions whose codomain is `ℝ≥0∞` or `ℝ`, by semicontinuous functions? See the
Vitali-Carathéodory theorem, in the file `measure_theory.vitali_caratheodory`.
-/
open_locale ennreal nnreal topological_space bounded_continuous_function
open measure_theory topological_space continuous_map
variables {α : Type*} [measurable_space α] [topological_space α] [normal_space α] [borel_space α]
variables (E : Type*) [measurable_space E] [normed_group E] [borel_space E]
[second_countable_topology E]
variables {p : ℝ≥0∞} [_i : fact (1 ≤ p)] (hp : p ≠ ∞) (μ : measure α)
include _i hp
namespace measure_theory.Lp
variables [normed_space ℝ E]
/-- A function in `Lp` can be approximated in `Lp` by continuous functions. -/
lemma bounded_continuous_function_dense [μ.weakly_regular] :
(bounded_continuous_function E p μ).topological_closure = ⊤ :=
begin
have hp₀ : 0 < p := lt_of_lt_of_le ennreal.zero_lt_one _i.elim,
have hp₀' : 0 ≤ 1 / p.to_real := div_nonneg zero_le_one ennreal.to_real_nonneg,
have hp₀'' : 0 < p.to_real,
{ simpa [← ennreal.to_real_lt_to_real ennreal.zero_ne_top hp] using hp₀ },
-- It suffices to prove that scalar multiples of the indicator function of a finite-measure
-- measurable set can be approximated by continuous functions
suffices : ∀ (c : E) {s : set α} (hs : measurable_set s) (hμs : μ s < ⊤),
(Lp.simple_func.indicator_const p hs hμs.ne c : Lp E p μ)
∈ (bounded_continuous_function E p μ).topological_closure,
{ rw add_subgroup.eq_top_iff',
refine Lp.induction hp _ _ _ _,
{ exact this },
{ exact λ f g hf hg hfg', add_subgroup.add_mem _ },
{ exact add_subgroup.is_closed_topological_closure _ } },
-- Let `s` be a finite-measure measurable set, let's approximate `c` times its indicator function
intros c s hs hsμ,
refine mem_closure_iff_frequently.mpr _,
rw metric.nhds_basis_closed_ball.frequently_iff,
intros ε hε,
-- A little bit of pre-emptive work, to find `η : ℝ≥0` which will be a margin small enough for
-- our purposes
obtain ⟨η, hη_pos, hη_le⟩ : ∃ η, 0 < η ∧ (↑(∥bit0 (∥c∥)∥₊ * (2 * η) ^ (1 / p.to_real)) : ℝ) ≤ ε,
{ have : filter.tendsto (λ x : ℝ≥0, ∥bit0 (∥c∥)∥₊ * (2 * x) ^ (1 / p.to_real)) (𝓝 0) (𝓝 0),
{ have : filter.tendsto (λ x : ℝ≥0, 2 * x) (𝓝 0) (𝓝 (2 * 0)) := filter.tendsto_id.const_mul 2,
convert ((nnreal.continuous_at_rpow_const (or.inr hp₀')).tendsto.comp this).const_mul _,
simp [hp₀''.ne'] },
let ε' : ℝ≥0 := ⟨ε, hε.le⟩,
have hε' : 0 < ε' := by exact_mod_cast hε,
obtain ⟨δ, hδ, hδε'⟩ :=
nnreal.nhds_zero_basis.eventually_iff.mp (eventually_le_of_tendsto_lt hε' this),
obtain ⟨η, hη, hηδ⟩ := exists_between hδ,
refine ⟨η, hη, _⟩,
exact_mod_cast hδε' hηδ },
have hη_pos' : (0 : ℝ≥0∞) < ↑η := by exact_mod_cast hη_pos,
-- Use the regularity of the measure to `η`-approximate `s` by an open superset and a closed
-- subset
obtain ⟨u, u_open, su, μu⟩ : ∃ u, is_open u ∧ s ⊆ u ∧ μ u < μ s + ↑η,
{ refine hs.exists_is_open_lt_of_lt _ _,
simpa using (ennreal.add_lt_add_iff_left hsμ).2 hη_pos' },
obtain ⟨F, F_closed, Fs, μF⟩ : ∃ F, is_closed F ∧ F ⊆ s ∧ μ s < μ F + ↑η :=
hs.exists_lt_is_closed_of_lt_top_of_pos hsμ hη_pos',
have : disjoint uᶜ F,
{ rw [set.disjoint_iff_inter_eq_empty, set.inter_comm, ← set.subset_compl_iff_disjoint],
simpa using Fs.trans su },
have h_μ_sdiff : μ (u \ F) ≤ 2 * η,
{ have hFμ : μ F < ⊤ := (measure_mono Fs).trans_lt hsμ,
refine ennreal.le_of_add_le_add_left hFμ _,
have : μ u < μ F + ↑η + ↑η,
{ refine μu.trans _,
rwa ennreal.add_lt_add_iff_right (ennreal.coe_lt_top : ↑η < ⊤) },
convert this.le using 1,
{ rw [add_comm, ← measure_union, set.diff_union_of_subset (Fs.trans su)],
{ exact disjoint_sdiff_self_left },
{ exact (u_open.sdiff F_closed).measurable_set },
{ exact F_closed.measurable_set } },
have : (2:ℝ≥0∞) * η = η + η := by simpa using add_mul (1:ℝ≥0∞) 1 η,
rw this,
abel },
-- Apply Urysohn's lemma to get a continuous approximation to the characteristic function of
-- the set `s`
obtain ⟨g, hgu, hgF, hg_range⟩ :=
exists_continuous_zero_one_of_closed u_open.is_closed_compl F_closed this,
-- Multiply this by `c` to get a continuous approximation to the function `f`; the key point is
-- that this is pointwise bounded by the indicator of the set `u \ F`
have g_norm : ∀ x, ∥g x∥ = g x := λ x, by rw [real.norm_eq_abs, abs_of_nonneg (hg_range x).1],
have gc_bd : ∀ x, ∥g x • c - s.indicator (λ x, c) x∥ ≤ ∥(u \ F).indicator (λ x, bit0 ∥c∥) x∥,
{ intros x,
by_cases hu : x ∈ u,
{ rw ← set.diff_union_of_subset (Fs.trans su) at hu,
cases hu with hFu hF,
{ refine (norm_sub_le _ _).trans _,
refine (add_le_add_left (norm_indicator_le_norm_self (λ x, c) x) _).trans _,
have h₀ : g x * ∥c∥ + ∥c∥ ≤ 2 * ∥c∥,
{ nlinarith [(hg_range x).1, (hg_range x).2, norm_nonneg c] },
have h₁ : (2:ℝ) * ∥c∥ = bit0 (∥c∥) := by simpa using add_mul (1:ℝ) 1 (∥c∥),
simp [hFu, norm_smul, h₀, ← h₁, g_norm x] },
{ simp [hgF hF, Fs hF] } },
{ have : x ∉ s := λ h, hu (su h),
simp [hgu hu, this] } },
-- The rest is basically just `ennreal`-arithmetic
have gc_snorm : snorm ((λ x, g x • c) - s.indicator (λ x, c)) p μ
≤ (↑(∥bit0 (∥c∥)∥₊ * (2 * η) ^ (1 / p.to_real)) : ℝ≥0∞),
{ refine (snorm_mono_ae (filter.eventually_of_forall gc_bd)).trans _,
rw snorm_indicator_const (u_open.sdiff F_closed).measurable_set hp₀.ne' hp,
push_cast [← ennreal.coe_rpow_of_nonneg _ hp₀'],
exact ennreal.mul_left_mono (ennreal.rpow_left_monotone_of_nonneg hp₀' h_μ_sdiff) },
have gc_cont : continuous (λ x, g x • c) := g.continuous.smul continuous_const,
have gc_mem_ℒp : mem_ℒp (λ x, g x • c) p μ,
{ have : mem_ℒp ((λ x, g x • c) - s.indicator (λ x, c)) p μ :=
⟨(gc_cont.ae_measurable μ).sub (measurable_const.indicator hs).ae_measurable,
gc_snorm.trans_lt ennreal.coe_lt_top⟩,
simpa using this.add (mem_ℒp_indicator_const p hs c (or.inr hsμ.ne)) },
refine ⟨gc_mem_ℒp.to_Lp _, _, _⟩,
{ rw mem_closed_ball_iff_norm,
refine le_trans _ hη_le,
rw [simple_func.coe_indicator_const, indicator_const_Lp, ← mem_ℒp.to_Lp_sub, Lp.norm_to_Lp],
exact ennreal.to_real_le_coe_of_le_coe gc_snorm },
{ rw [set_like.mem_coe, mem_bounded_continuous_function_iff],
refine ⟨bounded_continuous_function.of_normed_group _ gc_cont (∥c∥) _, rfl⟩,
intros x,
have h₀ : g x * ∥c∥ ≤ ∥c∥,
{ nlinarith [(hg_range x).1, (hg_range x).2, norm_nonneg c] },
simp [norm_smul, g_norm x, h₀] },
end
end measure_theory.Lp
variables (𝕜 : Type*) [measurable_space 𝕜] [normed_field 𝕜] [opens_measurable_space 𝕜]
[normed_algebra ℝ 𝕜] [normed_space 𝕜 E]
namespace bounded_continuous_function
lemma to_Lp_dense_range [μ.weakly_regular] [finite_measure μ] :
dense_range ⇑(to_Lp p μ 𝕜 : (α →ᵇ E) →L[𝕜] Lp E p μ) :=
begin
haveI : normed_space ℝ E := restrict_scalars.normed_space ℝ 𝕜 E,
rw dense_range_iff_closure_range,
suffices : (to_Lp p μ 𝕜 : _ →L[𝕜] Lp E p μ).range.to_add_subgroup.topological_closure = ⊤,
{ exact congr_arg coe this },
simp [range_to_Lp p μ, measure_theory.Lp.bounded_continuous_function_dense E hp],
end
end bounded_continuous_function
namespace continuous_map
lemma to_Lp_dense_range [compact_space α] [μ.weakly_regular] [finite_measure μ] :
dense_range ⇑(to_Lp p μ 𝕜 : C(α, E) →L[𝕜] Lp E p μ) :=
begin
haveI : normed_space ℝ E := restrict_scalars.normed_space ℝ 𝕜 E,
rw dense_range_iff_closure_range,
suffices : (to_Lp p μ 𝕜 : _ →L[𝕜] Lp E p μ).range.to_add_subgroup.topological_closure = ⊤,
{ exact congr_arg coe this },
simp [range_to_Lp p μ, measure_theory.Lp.bounded_continuous_function_dense E hp]
end
end continuous_map
|
50f4b20a6c33d30c0c8b0c4e9470d7a8f483dfb5 | b2fe74b11b57d362c13326bc5651244f111fa6f4 | /test/ring_exp.lean | 56aab784a9dfe1b413b5314d5f0d63c289624852 | [
"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 | 6,546 | lean | import tactic.ring_exp
import tactic.zify
import algebra.group_with_zero.power
universes u
section addition
/-!
### `addition` section
Test associativity and commutativity of `(+)`.
-/
example (a b : ℚ) : a = a := by ring_exp
example (a b : ℚ) : a + b = a + b := by ring_exp
example (a b : ℚ) : b + a = a + b := by ring_exp
example (a b : ℤ) : a + b + b = b + (a + b) := by ring_exp
example (a b c : ℕ) : a + b + b + (c + c) = c + (b + c) + (a + b) := by ring_exp
end addition
section numerals
/-!
### `numerals` section
Test that numerals behave like rational numbers.
-/
example (a : ℕ) : a + 5 + 5 = 0 + a + 10 := by ring_exp
example (a : ℤ) : a + 5 + 5 = 0 + a + 10 := by ring_exp
example (a : ℚ) : (1/2) * a + (1/2) * a = a := by ring_exp
end numerals
section multiplication
/-!
### `multiplication section`
Test that multiplication is associative and commutative.
Also test distributivity of `(+)` and `(*)`.
-/
example (a : ℕ) : 0 = a * 0 := by ring_exp_eq
example (a : ℕ) : a = a * 1 := by ring_exp
example (a : ℕ) : a + a = a * 2 := by ring_exp
example (a b : ℤ) : a * b = b * a := by ring_exp
example (a b : ℕ) : a * 4 * b + a = a * (4 * b + 1) := by ring_exp
end multiplication
section exponentiation
/-!
### `exponentiation` section
Test that exponentiation has the correct distributivity properties.
-/
example : 0 ^ 1 = 0 := by ring_exp
example : 0 ^ 2 = 0 := by ring_exp
example (a : ℕ) : a ^ 0 = 1 := by ring_exp
example (a : ℕ) : a ^ 1 = a := by ring_exp
example (a : ℕ) : a ^ 2 = a * a := by ring_exp
example (a b : ℕ) : a ^ b = a ^ b := by ring_exp
example (a b : ℕ) : a ^ (b + 1) = a * a ^ b := by ring_exp
example (n : ℕ) (a m : ℕ) : a * a^n * m = a^(n+1) * m := by ring_exp
example (n : ℕ) (a m : ℕ) : m * a^n * a = a^(n+1) * m := by ring_exp
example (n : ℕ) (a m : ℤ) : a * a^n * m = a^(n+1) * m := by ring_exp
example (n : ℕ) (m : ℤ) : 2 * 2^n * m = 2^(n+1) * m := by ring_exp
example (n : ℕ) (m : ℤ) : 2^(n+1) * m = 2 * 2^n * m := by ring_exp
example (n m : ℕ) (a : ℤ) : (a ^ n)^m = a^(n * m) := by ring_exp
example (n m : ℕ) (a : ℤ) : a^(n^0) = a^1 := by ring_exp
example (n : ℕ) : 0^(n + 1) = 0 := by ring_exp
example {α} [comm_ring α] (x : α) (k : ℕ) : x ^ (k + 2) = x * x * x^k := by ring_exp
example {α} [comm_ring α] (k : ℕ) (x y z : α) :
x * (z * (x - y)) + (x * (y * y ^ k) - y * (y * y ^ k)) = (z * x + y * y ^ k) * (x - y)
:= by ring_exp
-- We can represent a large exponent `n` more efficiently than just `n` multiplications:
example (a b : ℚ) : (a * b) ^ 1000000 = (b * a) ^ 1000000 := by ring_exp
example (n : ℕ) : 2 ^ (n + 1 + 1) = 2 * 2 ^ (n + 1) :=
by ring_exp_eq
end exponentiation
section power_of_sum
/-!
### `power_of_sum` section
Test that raising a sum to a power behaves like repeated multiplication,
if needed.
-/
example (a b : ℤ) : (a + b)^2 = a^2 + b^2 + a * b + b * a := by ring_exp
example (a b : ℤ) (n : ℕ) : (a + b)^(n + 2) = (a^2 + b^2 + a * b + b * a) * (a + b)^n := by ring_exp
end power_of_sum
section negation
/-!
### `negation` section
Test that negation and subtraction satisfy the expected properties,
also in semirings such as `ℕ`.
-/
example {α} [comm_ring α] (a : α) : a - a = 0 := by ring_exp_eq
example (a : ℤ) : a - a = 0 := by ring_exp
example (a : ℤ) : a + - a = 0 := by ring_exp
example (a : ℤ) : - a = (-1) * a := by ring_exp
-- Here, (a - b) is treated as an atom.
example (a b : ℕ) : a - b + a + a = a - b + 2 * a := by ring_exp
example (n : ℕ) : n + 1 - 1 = n := by ring_exp! -- But we can force a bit of evaluation anyway.
end negation
constant f {α} : α → α
section complicated
/-!
### `complicated` section
Test that complicated, real-life expressions also get normalized.
-/
example {α : Type} [linear_ordered_field α] (x : α) :
2 * x + 1 * 1 - (2 * f (x + 1 / 2) + 2 * 1) + (1 * 1 - (2 * x - 2 * f (x + 1 / 2))) = 0
:= by ring_exp_eq
example {α : Type u} [linear_ordered_field α] (x : α) :
f (x + 1 / 2) ^ 1 * -2 + (f (x + 1 / 2) ^ 1 * 2 + 0) = 0
:= by ring_exp_eq
example (x y : ℕ) : x + id y = y + id x := by ring_exp!
-- Here, we check that `n - s` is not treated as `n + additive_inverse s`,
-- if `s` doesn't have an additive inverse.
example (B s n : ℕ) : B * (f s * ((n - s) * f (n - s - 1))) = B * (n - s) * (f s * f (n - s - 1)) :=
by ring_exp
-- This is a somewhat subtle case: `-c/b` is parsed as `(-c)/b`,
-- so we can't simply treat both sides of the division as atoms.
-- Instead, we follow the `ring` tactic in interpreting `-c / b` as `-c * b⁻¹`,
-- with only `b⁻¹` an atom.
example {α} [linear_ordered_field α] (a b c : α) : a*(-c/b)*(-c/b) = a*((c/b)*(c/b)) := by ring_exp
-- test that `field_simp` works fine with powers and `ring_exp`.
example (x y : ℚ) (n : ℕ) (hx : x ≠ 0) (hy : y ≠ 0) :
1/ (2/(x / y))^(2 * n) + y / y^(n+1) - (x/y)^n * (x/(2 * y))^n / 2 ^n = 1/y^n :=
begin
simp [sub_eq_add_neg],
field_simp [hx, hy],
ring_exp
end
end complicated
-- Test that `nat.succ d` gets handled as `d + 1`.
example (d : ℕ) : 2 * (2 ^ d - 1) + 1 = 2 ^ d.succ - 1 :=
begin
zify [nat.one_le_pow'],
ring_exp,
end
section conv
/-!
### `conv` section
Test that `ring_exp` works inside of `conv`, both with and without `!`.
-/
example (n : ℕ) : (2^n * 2 + 1)^10 = (2^(n+1) + 1)^10 :=
begin
conv_rhs
{ congr,
ring_exp, },
conv_lhs
{ congr,
ring_exp, },
end
example (x y : ℤ) : x + id y - y + id x = x * 2 := begin
conv_lhs { ring_exp!, },
end
end conv
section benchmark
/-!
### `benchmark` section
The `ring_exp` tactic shouldn't be too slow.
-/
-- This last example was copied from `data/polynomial.lean`, because it timed out.
-- After some optimization, it doesn't.
variables {α : Type} [comm_ring α]
def pow_sub_pow_factor (x y : α) : Π {i : ℕ},{z // x^i - y^i = z*(x - y)}
| 0 := ⟨0, by simp⟩
| 1 := ⟨1, by simp⟩
| (k+2) :=
begin
cases @pow_sub_pow_factor (k+1) with z hz,
existsi z*x + y^(k+1),
rw [pow_succ x, pow_succ y, ←sub_add_sub_cancel (x*x^(k+1)) (x*y^(k+1)),
←mul_sub x, hz],
ring_exp_eq
end
-- Another benchmark: bound the growth of the complexity somewhat.
example {α} [comm_semiring α] (x : α) : (x + 1) ^ 4 = (1 + x) ^ 4 := by try_for 5000 {ring_exp}
example {α} [comm_semiring α] (x : α) : (x + 1) ^ 6 = (1 + x) ^ 6 := by try_for 10000 {ring_exp}
example {α} [comm_semiring α] (x : α) : (x + 1) ^ 8 = (1 + x) ^ 8 := by try_for 15000 {ring_exp}
end benchmark
|
755f3f0b2a3028888eda1ecd914e3f7bf3f71b23 | 367134ba5a65885e863bdc4507601606690974c1 | /src/geometry/manifold/smooth_manifold_with_corners.lean | 55565841a48f2f32b3e3504a4c8a6c7bd88e3b1e | [
"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 | 38,557 | 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.calculus.times_cont_diff
import geometry.manifold.charted_space
/-!
# Smooth manifolds (possibly with boundary or corners)
A smooth manifold is a manifold modelled on a normed vector space, or a subset like a
half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps.
We define a model with corners as a map `I : H → E` embedding nicely the topological space `H` in
the vector space `E` (or more precisely as a structure containing all the relevant properties).
Given such a model with corners `I` on `(E, H)`, we define the groupoid of local
homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : with_top ℕ`).
With this groupoid at hand and the general machinery of charted spaces, we thus get the notion
of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a
specific type class for `C^∞` manifolds as these are the most commonly used.
## Main definitions
* `model_with_corners 𝕜 E H` :
a structure containing informations on the way a space `H` embeds in a
model vector space E over the field `𝕜`. This is all that is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
* `model_with_corners_self 𝕜 E` :
trivial model with corners structure on the space `E` embedded in itself by the identity.
* `times_cont_diff_groupoid n I` :
when `I` is a model with corners on `(𝕜, E, H)`, this is the groupoid of local homeos of `H`
which are of class `C^n` over the normed field `𝕜`, when read in `E`.
* `smooth_manifold_with_corners I M` :
a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of
coordinates with respect to the model with corners `I` on `(𝕜, E, H)`. This type class is just
a shortcut for `has_groupoid M (times_cont_diff_groupoid ∞ I)`.
* `ext_chart_at I x`:
in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`,
but often we may want to use their `E`-valued version, obtained by composing the charts with `I`.
Since the target is in general not open, we can not register them as local homeomorphisms, but
we register them as local equivs. `ext_chart_at I x` is the canonical such local equiv around `x`.
As specific examples of models with corners, we define (in the file `real_instances.lean`)
* `model_with_corners_self ℝ (euclidean_space (fin n))` for the model space used to define
`n`-dimensional real manifolds without boundary (with notation `𝓡 n` in the locale `manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary (with notation `𝓡∂ n` in the locale
`manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary,
one could use
`variables {n : ℕ} {M : Type*} [topological_space M] [charted_space (euclidean_space (fin n)) M]
[smooth_manifold_with_corners (𝓡 n) M]`.
However, this is not the recommended way: a theorem proved using this assumption would not apply
for instance to the tangent space of such a manifold, which is modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin n))` and not on `euclidean_space (fin (2 * n))`!
In the same way, it would not apply to product manifolds, modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin m))`.
The right invocation does not focus on one specific construction, but on all constructions sharing
the right properties, like
`variables {E : Type*} [normed_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
{I : model_with_corners ℝ E E} [I.boundaryless]
{M : Type*} [topological_space M] [charted_space E M] [smooth_manifold_with_corners I M]`
Here, `I.boundaryless` is a typeclass property ensuring that there is no boundary (this is for
instance the case for `model_with_corners_self`, or products of these). Note that one could consider
as a natural assumption to only use the trivial model with corners `model_with_corners_self ℝ E`,
but again in product manifolds the natural model with corners will not be this one but the product
one (and they are not defeq as `(λp : E × F, (p.1, p.2))` is not defeq to the identity). So, it is
important to use the above incantation to maximize the applicability of theorems.
## Implementation notes
We want to talk about manifolds modelled on a vector space, but also on manifolds with
boundary, modelled on a half space (or even manifolds with corners). For the latter examples,
we still want to define smooth functions, tangent bundles, and so on. As smooth functions are
well defined on vector spaces or subsets of these, one could take for model space a subtype of a
vector space. With the drawback that the whole vector space itself (which is the most basic
example) is not directly a subtype of itself: the inclusion of `univ : set E` in `set E` would
show up in the definition, instead of `id`.
A good abstraction covering both cases it to have a vector
space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper
half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or
`subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a
model with corners, and we encompass all the relevant properties (in particular the fact that the
image of `H` in `E` should have unique differentials) in the definition of `model_with_corners`.
We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but
later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal
with `C^k` functions as there would be additional conditions `k ≤ n` everywhere. Since one deals
almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that
one could revisit later if needed. `C^k` manifolds are still available, but they should be called
using `has_groupoid M (times_cont_diff_groupoid k I)` where `I` is the model with corners.
I have considered using the model with corners `I` as a typeclass argument, possibly `out_param`, to
get lighter notations later on, but it did not turn out right, as on `E × F` there are two natural
model with corners, the trivial (identity) one, and the product one, and they are not defeq and one
needs to indicate to Lean which one we want to use.
This means that when talking on objects on manifolds one will most often need to specify the model
with corners one is using. For instance, the tangent bundle will be `tangent_bundle I M` and the
derivative will be `mfderiv I I' f`, instead of the more natural notations `tangent_bundle 𝕜 M` and
`mfderiv 𝕜 f` (the field has to be explicit anyway, as some manifolds could be considered both as
real and complex manifolds).
-/
noncomputable theory
universes u v w u' v' w'
open set filter
open_locale manifold filter topological_space
localized "notation `∞` := (⊤ : with_top ℕ)" in manifold
section model_with_corners
/-! ### Models with corners. -/
/-- A structure containing informations on the way a space `H` embeds in a
model vector space `E` over the field `𝕜`. This is all what is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
-/
@[nolint has_inhabited_instance]
structure model_with_corners (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
extends local_equiv H E :=
(source_eq : source = univ)
(unique_diff' : unique_diff_on 𝕜 (range to_fun))
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
attribute [simp, mfld_simps] model_with_corners.source_eq
/-- A vector space is a model with corners. -/
def model_with_corners_self (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : model_with_corners 𝕜 E E :=
{ to_fun := id,
inv_fun := id,
source := univ,
target := univ,
source_eq := rfl,
map_source' := λ_ _, mem_univ _,
map_target' := λ_ _, mem_univ _,
left_inv' := λ_ _, rfl,
right_inv' := λ_ _, rfl,
unique_diff' := by { rw range_id, exact unique_diff_on_univ },
continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id }
localized "notation `𝓘(` 𝕜 `, ` E `)` := model_with_corners_self 𝕜 E" in manifold
localized "notation `𝓘(` 𝕜 `)` := model_with_corners_self 𝕜 𝕜" in manifold
section
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
namespace model_with_corners
instance : has_coe_to_fun (model_with_corners 𝕜 E H) := ⟨_, λ e, e.to_fun⟩
/-- The inverse to a model with corners, only registered as a local equiv. -/
protected def symm : local_equiv E H := I.to_local_equiv.symm
/- Register a few lemmas to make sure that `simp` puts expressions in normal form -/
@[simp, mfld_simps] lemma to_local_equiv_coe : (I.to_local_equiv : H → E) = I :=
rfl
@[simp, mfld_simps] lemma mk_coe (e : local_equiv H E) (a b c d) :
((model_with_corners.mk e a b c d : model_with_corners 𝕜 E H) : H → E) = (e : H → E) := rfl
@[simp, mfld_simps] lemma to_local_equiv_coe_symm : (I.to_local_equiv.symm : E → H) = I.symm := rfl
@[simp, mfld_simps] lemma mk_symm (e : local_equiv H E) (a b c d) :
(model_with_corners.mk e a b c d : model_with_corners 𝕜 E H).symm = e.symm :=
rfl
protected lemma unique_diff : unique_diff_on 𝕜 (range I) := I.unique_diff'
@[continuity] protected lemma continuous : continuous I := I.continuous_to_fun
@[continuity] lemma continuous_symm : continuous I.symm := I.continuous_inv_fun
@[simp, mfld_simps] lemma target_eq : I.target = range (I : H → E) :=
by { rw [← image_univ, ← I.source_eq], exact (I.to_local_equiv.image_source_eq_target).symm }
@[simp, mfld_simps] protected lemma left_inv (x : H) : I.symm (I x) = x :=
by { refine I.left_inv' _, simp }
protected lemma left_inverse : function.left_inverse I.symm I := I.left_inv
@[simp, mfld_simps] lemma symm_comp_self : I.symm ∘ I = id :=
I.left_inverse.comp_eq_id
protected lemma right_inv_on : right_inv_on I.symm I (range I) :=
I.left_inverse.right_inv_on_range
@[simp, mfld_simps] protected lemma right_inv {x : E} (hx : x ∈ range I) : I (I.symm x) = x :=
I.right_inv_on hx
protected lemma image_eq (s : set H) : I '' s = I.symm ⁻¹' s ∩ range I :=
begin
refine (I.to_local_equiv.image_eq_target_inter_inv_preimage _).trans _,
{ rw I.source_eq, exact subset_univ _ },
{ rw [inter_comm, I.target_eq, I.to_local_equiv_coe_symm] }
end
protected lemma closed_embedding : closed_embedding I :=
I.left_inverse.closed_embedding I.continuous_symm I.continuous
lemma closed_range : is_closed (range I) :=
I.closed_embedding.closed_range
lemma map_nhds_eq (x : H) : map I (𝓝 x) = 𝓝[range I] (I x) :=
I.closed_embedding.to_embedding.map_nhds_eq x
lemma image_mem_nhds_within {x : H} {s : set H} (hs : s ∈ 𝓝 x) :
I '' s ∈ 𝓝[range I] (I x) :=
I.map_nhds_eq x ▸ image_mem_map hs
lemma symm_map_nhds_within_range (x : H) :
map I.symm (𝓝[range I] (I x)) = 𝓝 x :=
by rw [← I.map_nhds_eq, map_map, I.symm_comp_self, map_id]
lemma unique_diff_preimage {s : set H} (hs : is_open s) :
unique_diff_on 𝕜 (I.symm ⁻¹' s ∩ range I) :=
by { rw inter_comm, exact I.unique_diff.inter (hs.preimage I.continuous_inv_fun) }
lemma unique_diff_preimage_source {β : Type*} [topological_space β]
{e : local_homeomorph H β} : unique_diff_on 𝕜 (I.symm ⁻¹' (e.source) ∩ range I) :=
I.unique_diff_preimage e.open_source
lemma unique_diff_at_image {x : H} : unique_diff_within_at 𝕜 (range I) (I x) :=
I.unique_diff _ (mem_range_self _)
protected lemma locally_compact [locally_compact_space E] (I : model_with_corners 𝕜 E H) :
locally_compact_space H :=
begin
have : ∀ (x : H), (𝓝 x).has_basis (λ s, s ∈ 𝓝 (I x) ∧ is_compact s)
(λ s, I.symm '' (s ∩ range ⇑I)),
{ intro x,
rw ← I.symm_map_nhds_within_range,
exact ((compact_basis_nhds (I x)).inf_principal _).map _ },
refine locally_compact_space_of_has_basis this _,
rintro x s ⟨-, hsc⟩,
exact (hsc.inter_right I.closed_range).image I.continuous_symm
end
end model_with_corners
section
variables (𝕜 E)
/-- In the trivial model with corners, the associated local equiv is the identity. -/
@[simp, mfld_simps] lemma model_with_corners_self_local_equiv :
(𝓘(𝕜, E)).to_local_equiv = local_equiv.refl E := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe :
(𝓘(𝕜, E) : E → E) = id := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe_symm :
(𝓘(𝕜, E).symm : E → E) = id := rfl
end
end
section model_with_corners_prod
/-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with
corners `I.prod I'` on `(E × E', H × H')`. This appears in particular for the manifold structure on
the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on `(E × E, H × E)`. -/
def model_with_corners.prod
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H)
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') : model_with_corners 𝕜 (E × E') (model_prod H H') :=
{ to_fun := λ p, (I p.1, I' p.2),
inv_fun := λ p, (I.symm p.1, I'.symm p.2),
source := (univ : set (H × H')),
target := set.prod (range I) (range I'),
map_source' := λ ⟨x, x'⟩ _, by simp [-mem_range, mem_range_self],
map_target' := λ ⟨x, x'⟩ _, mem_univ _,
left_inv' := λ ⟨x, x'⟩ _, by simp,
right_inv' := λ ⟨x, x'⟩ ⟨hx, hx'⟩, by simp [hx, hx'],
source_eq := rfl,
unique_diff' := begin
have : range (λ(p : model_prod H H'), (I p.1, I' p.2)) = set.prod (range I) (range I'),
by { dsimp [model_prod], rw ← prod_range_range_eq },
rw this,
exact unique_diff_on.prod I.unique_diff I'.unique_diff,
end,
continuous_to_fun := (continuous.comp I.continuous_to_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_to_fun continuous_snd),
continuous_inv_fun := (continuous.comp I.continuous_inv_fun continuous_fst).prod_mk
(continuous.comp I'.continuous_inv_fun continuous_snd) }
/-- Special case of product model with corners, which is trivial on the second factor. This shows up
as the model to tangent bundles. -/
@[reducible] def model_with_corners.tangent
{𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) : model_with_corners 𝕜 (E × E) (model_prod H E) :=
I.prod (𝓘(𝕜, E))
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{F : Type*} [normed_group F] [normed_space 𝕜 F] {F' : Type*} [normed_group F'] [normed_space 𝕜 F']
{H : Type*} [topological_space H] {H' : Type*} [topological_space H']
{G : Type*} [topological_space G] {G' : Type*} [topological_space G']
{I : model_with_corners 𝕜 E H} {J : model_with_corners 𝕜 F G}
@[simp, mfld_simps] lemma model_with_corners_prod_to_local_equiv :
(I.prod J).to_local_equiv = (I.to_local_equiv).prod (J.to_local_equiv) :=
begin
ext1 x,
{ refl, },
{ intro x, refl, },
{ simp only [set.univ_prod_univ, model_with_corners.source_eq, local_equiv.prod_source], }
end
@[simp, mfld_simps] lemma model_with_corners_prod_coe
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
(I.prod I' : _ × _ → _ × _) = prod.map I I' := rfl
@[simp, mfld_simps] lemma model_with_corners_prod_coe_symm
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
((I.prod I').symm : _ × _ → _ × _) = prod.map I.symm I'.symm := rfl
end model_with_corners_prod
section boundaryless
/-- Property ensuring that the model with corners `I` defines manifolds without boundary. -/
class model_with_corners.boundaryless {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H) : Prop :=
(range_eq_univ : range I = univ)
/-- The trivial model with corners has no boundary -/
instance model_with_corners_self_boundaryless (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
(E : Type*) [normed_group E] [normed_space 𝕜 E] : (model_with_corners_self 𝕜 E).boundaryless :=
⟨by simp⟩
/-- If two model with corners are boundaryless, their product also is -/
instance model_with_corners.range_eq_univ_prod {𝕜 : Type u} [nondiscrete_normed_field 𝕜]
{E : Type v} [normed_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) [I.boundaryless]
{E' : Type v'} [normed_group E'] [normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') [I'.boundaryless] :
(I.prod I').boundaryless :=
begin
split,
dsimp [model_with_corners.prod, model_prod],
rw [← prod_range_range_eq, model_with_corners.boundaryless.range_eq_univ,
model_with_corners.boundaryless.range_eq_univ, univ_prod_univ]
end
end boundaryless
section times_cont_diff_groupoid
/-! ### Smooth functions on models with corners -/
variables {m n : with_top ℕ} {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
variable (n)
/-- Given a model with corners `(E, H)`, we define the groupoid of `C^n` transformations of `H` as
the maps that are `C^n` when read in `E` through `I`. -/
def times_cont_diff_groupoid : structure_groupoid H :=
pregroupoid.groupoid
{ property := λf s, times_cont_diff_on 𝕜 n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
comp := λf g u v hf hg hu hv huv, begin
have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ (I ∘ f ∘ I.symm),
by { ext x, simp },
rw this,
apply times_cont_diff_on.comp hg _,
{ rintros x ⟨hx1, hx2⟩,
simp only with mfld_simps at ⊢ hx1,
exact hx1.2 },
{ refine hf.mono _,
rintros x ⟨hx1, hx2⟩,
exact ⟨hx1.1, hx2⟩ }
end,
id_mem := begin
apply times_cont_diff_on.congr (times_cont_diff_id.times_cont_diff_on),
rintros x ⟨hx1, hx2⟩,
rcases mem_range.1 hx2 with ⟨y, hy⟩,
rw ← hy,
simp only with mfld_simps,
end,
locality := λf u hu H, begin
apply times_cont_diff_on_of_locally_times_cont_diff_on,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rcases H x hy1 with ⟨v, v_open, xv, hv⟩,
have : ((I.symm ⁻¹' (u ∩ v)) ∩ (range I))
= ((I.symm ⁻¹' u) ∩ (range I) ∩ I.symm ⁻¹' v),
{ rw [preimage_inter, inter_assoc, inter_assoc],
congr' 1,
rw inter_comm },
rw this at hv,
exact ⟨I.symm ⁻¹' v, v_open.preimage I.continuous_symm, by simpa, hv⟩
end,
congr := λf g u hu fg hf, begin
apply hf.congr,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rw fg _ hy1
end }
variable {n}
/-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when
`m ≤ n` -/
lemma times_cont_diff_groupoid_le (h : m ≤ n) :
times_cont_diff_groupoid n I ≤ times_cont_diff_groupoid m I :=
begin
rw [times_cont_diff_groupoid, times_cont_diff_groupoid],
apply groupoid_of_pregroupoid_le,
assume f s hfs,
exact times_cont_diff_on.of_le hfs h
end
/-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all
local homeomorphisms -/
lemma times_cont_diff_groupoid_zero_eq :
times_cont_diff_groupoid 0 I = continuous_groupoid H :=
begin
apply le_antisymm le_top,
assume u hu,
-- we have to check that every local homeomorphism belongs to `times_cont_diff_groupoid 0 I`,
-- by unfolding its definition
change u ∈ times_cont_diff_groupoid 0 I,
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
simp only [times_cont_diff_on_zero],
split,
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_to_fun I.continuous_symm.continuous_on
(inter_subset_left _ _) },
{ apply continuous_on.comp (@continuous.continuous_on _ _ _ _ _ univ I.continuous)
_ (subset_univ _),
apply continuous_on.comp u.continuous_inv_fun I.continuous_inv_fun.continuous_on
(inter_subset_left _ _) },
end
variable (n)
/-- An identity local homeomorphism belongs to the `C^n` groupoid. -/
lemma of_set_mem_times_cont_diff_groupoid {s : set H} (hs : is_open s) :
local_homeomorph.of_set s hs ∈ times_cont_diff_groupoid n I :=
begin
rw [times_cont_diff_groupoid, mem_groupoid_of_pregroupoid],
suffices h : times_cont_diff_on 𝕜 n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
by simp [h],
have : times_cont_diff_on 𝕜 n id (univ : set E) :=
times_cont_diff_id.times_cont_diff_on,
exact this.congr_mono (λ x hx, by simp [hx.2]) (subset_univ _)
end
/-- The composition of a local homeomorphism from `H` to `M` and its inverse belongs to
the `C^n` groupoid. -/
lemma symm_trans_mem_times_cont_diff_groupoid (e : local_homeomorph M H) :
e.symm.trans e ∈ times_cont_diff_groupoid n I :=
begin
have : e.symm.trans e ≈ local_homeomorph.of_set e.target e.open_target :=
local_homeomorph.trans_symm_self _,
exact structure_groupoid.eq_on_source _
(of_set_mem_times_cont_diff_groupoid n I e.open_target) this
end
variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E'] {H' : Type*} [topological_space H']
/-- The product of two smooth local homeomorphisms is smooth. -/
lemma times_cont_diff_groupoid_prod
{I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'}
{e : local_homeomorph H H} {e' : local_homeomorph H' H'}
(he : e ∈ times_cont_diff_groupoid ⊤ I) (he' : e' ∈ times_cont_diff_groupoid ⊤ I') :
e.prod e' ∈ times_cont_diff_groupoid ⊤ (I.prod I') :=
begin
cases he with he he_symm,
cases he' with he' he'_symm,
simp only at he he_symm he' he'_symm,
split;
simp only [local_equiv.prod_source, local_homeomorph.prod_to_local_equiv],
{ have h3 := times_cont_diff_on.prod_map he he',
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, },
{ have h3 := times_cont_diff_on.prod_map he_symm he'_symm,
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, }
end
/-- The `C^n` groupoid is closed under restriction. -/
instance : closed_under_restriction (times_cont_diff_groupoid n I) :=
(closed_under_restriction_iff_id_le _).mpr
begin
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
apply (times_cont_diff_groupoid n I).eq_on_source' _ _ _ hes,
exact of_set_mem_times_cont_diff_groupoid n I hs,
end
end times_cont_diff_groupoid
end model_with_corners
section smooth_manifold_with_corners
/-! ### Smooth manifolds with corners -/
set_option old_structure_cmd true
/-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a
field `𝕜` and with infinite smoothness to simplify typeclass search and statements later on. -/
@[ancestor has_groupoid]
class smooth_manifold_with_corners {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M] extends
has_groupoid M (times_cont_diff_groupoid ∞ I) : Prop
lemma smooth_manifold_with_corners_of_times_cont_diff_on
{𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
(h : ∀ (e e' : local_homeomorph M H), e ∈ atlas H M → e' ∈ atlas H M →
times_cont_diff_on 𝕜 ⊤ (I ∘ (e.symm ≫ₕ e') ∘ I.symm)
(I.symm ⁻¹' (e.symm ≫ₕ e').source ∩ range I)) :
smooth_manifold_with_corners I M :=
{ compatible :=
begin
haveI : has_groupoid M (times_cont_diff_groupoid ∞ I) := has_groupoid_of_pregroupoid _ h,
apply structure_groupoid.compatible,
end }
/-- For any model with corners, the model space is a smooth manifold -/
instance model_space_smooth {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
{I : model_with_corners 𝕜 E H} :
smooth_manifold_with_corners I H := { .. has_groupoid_model_space _ _ }
end smooth_manifold_with_corners
namespace smooth_manifold_with_corners
/- We restate in the namespace `smooth_manifolds_with_corners` some lemmas that hold for general
charted space with a structure groupoid, avoiding the need to specify the groupoid
`times_cont_diff_groupoid ∞ I` explicitly. -/
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
/-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the
model with corners `I`. -/
def maximal_atlas := (times_cont_diff_groupoid ∞ I).maximal_atlas M
variable {M}
lemma mem_maximal_atlas_of_mem_atlas [smooth_manifold_with_corners I M]
{e : local_homeomorph M H} (he : e ∈ atlas H M) : e ∈ maximal_atlas I M :=
structure_groupoid.mem_maximal_atlas_of_mem_atlas _ he
lemma chart_mem_maximal_atlas [smooth_manifold_with_corners I M] (x : M) :
chart_at H x ∈ maximal_atlas I M :=
structure_groupoid.chart_mem_maximal_atlas _ x
variable {I}
lemma compatible_of_mem_maximal_atlas
{e e' : local_homeomorph M H} (he : e ∈ maximal_atlas I M) (he' : e' ∈ maximal_atlas I M) :
e.symm.trans e' ∈ times_cont_diff_groupoid ∞ I :=
structure_groupoid.compatible_of_mem_maximal_atlas he he'
/-- The product of two smooth manifolds with corners is naturally a smooth manifold with corners. -/
instance prod {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_group E'] [normed_space 𝕜 E']
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
(M' : Type*) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] :
smooth_manifold_with_corners (I.prod I') (M×M') :=
{ compatible :=
begin
rintros f g ⟨f1, hf1, f2, hf2, hf⟩ ⟨g1, hg1, g2, hg2, hg⟩,
rw [hf, hg, local_homeomorph.prod_symm, local_homeomorph.prod_trans],
have h1 := has_groupoid.compatible (times_cont_diff_groupoid ⊤ I) hf1 hg1,
have h2 := has_groupoid.compatible (times_cont_diff_groupoid ⊤ I') hf2 hg2,
exact times_cont_diff_groupoid_prod h1 h2,
end }
end smooth_manifold_with_corners
section extended_charts
open_locale topological_space
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M]
(x : M) {s t : set M}
/-!
### Extended charts
In a smooth manifold with corners, the model space is the space `H`. However, we will also
need to use extended charts taking values in the model vector space `E`. These extended charts are
not `local_homeomorph` as the target is not open in `E` in general, but we can still register them
as `local_equiv`.
-/
/-- The preferred extended chart on a manifold with corners around a point `x`, from a neighborhood
of `x` to the model vector space. -/
@[simp, mfld_simps] def ext_chart_at (x : M) : local_equiv M E :=
(chart_at H x).to_local_equiv.trans I.to_local_equiv
lemma ext_chart_at_coe : ⇑(ext_chart_at I x) = I ∘ chart_at H x := rfl
lemma ext_chart_at_coe_symm :
⇑(ext_chart_at I x).symm = (chart_at H x).symm ∘ I.symm := rfl
lemma ext_chart_at_source : (ext_chart_at I x).source = (chart_at H x).source :=
by rw [ext_chart_at, local_equiv.trans_source, I.source_eq, preimage_univ, inter_univ]
lemma ext_chart_at_open_source : is_open (ext_chart_at I x).source :=
by { rw ext_chart_at_source, exact (chart_at H x).open_source }
lemma mem_ext_chart_source : x ∈ (ext_chart_at I x).source :=
by simp only [ext_chart_at_source, mem_chart_source]
lemma ext_chart_at_to_inv :
(ext_chart_at I x).symm ((ext_chart_at I x) x) = x :=
(ext_chart_at I x).left_inv (mem_ext_chart_source I x)
lemma ext_chart_at_source_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝 x' :=
mem_nhds_sets (ext_chart_at_open_source I x) h
lemma ext_chart_at_source_mem_nhds : (ext_chart_at I x).source ∈ 𝓝 x :=
ext_chart_at_source_mem_nhds' I x (mem_ext_chart_source I x)
lemma ext_chart_at_source_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝[s] x' :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds' I x h)
lemma ext_chart_at_source_mem_nhds_within :
(ext_chart_at I x).source ∈ 𝓝[s] x :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds I x)
lemma ext_chart_at_continuous_on :
continuous_on (ext_chart_at I x) (ext_chart_at I x).source :=
begin
refine I.continuous.comp_continuous_on _,
rw ext_chart_at_source,
exact (chart_at H x).continuous_on
end
lemma ext_chart_at_continuous_at' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x) x' :=
(ext_chart_at_continuous_on I x).continuous_at $ ext_chart_at_source_mem_nhds' I x h
lemma ext_chart_at_continuous_at : continuous_at (ext_chart_at I x) x :=
ext_chart_at_continuous_at' _ _ (mem_ext_chart_source I x)
lemma ext_chart_at_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
begin
apply continuous_on.comp (chart_at H x).continuous_on_symm I.continuous_symm.continuous_on,
simp [ext_chart_at, local_equiv.trans_target]
end
lemma ext_chart_at_map_nhds' {x y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝 y) = 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [ext_chart_at_coe, (∘), ← I.map_nhds_eq, ← (chart_at H x).map_nhds_eq, map_map],
rwa ext_chart_at_source at hy
end
lemma ext_chart_at_map_nhds :
map (ext_chart_at I x) (𝓝 x) = 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds' I $ mem_ext_chart_source I x
lemma ext_chart_at_target_mem_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [← local_equiv.image_source_eq_target, ← ext_chart_at_map_nhds' I hy],
exact image_mem_map (ext_chart_at_source_mem_nhds' _ _ hy)
end
lemma ext_chart_at_target_mem_nhds_within :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_target_mem_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_target_subset_range : (ext_chart_at I x).target ⊆ range I :=
by simp only with mfld_simps
lemma nhds_within_ext_chart_target_eq' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
𝓝[(ext_chart_at I x).target] (ext_chart_at I x y) =
𝓝[range I] (ext_chart_at I x y) :=
(nhds_within_mono _ (ext_chart_at_target_subset_range _ _)).antisymm $
nhds_within_le_of_mem (ext_chart_at_target_mem_nhds_within' _ _ hy)
lemma nhds_within_ext_chart_target_eq :
𝓝[(ext_chart_at I x).target] ((ext_chart_at I x) x) =
𝓝[range I] ((ext_chart_at I x) x) :=
nhds_within_ext_chart_target_eq' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_at_symm'' {y : E} (h : y ∈ (ext_chart_at I x).target) :
continuous_at (ext_chart_at I x).symm y :=
continuous_at.comp ((chart_at H x).continuous_at_symm h.2) (I.continuous_symm.continuous_at)
lemma ext_chart_continuous_at_symm' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x).symm (ext_chart_at I x x') :=
ext_chart_continuous_at_symm'' I _ $ (ext_chart_at I x).map_source h
lemma ext_chart_continuous_at_symm :
continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x) :=
ext_chart_continuous_at_symm' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
λ y hy, (ext_chart_continuous_at_symm'' _ _ hy).continuous_within_at
lemma ext_chart_at_map_nhds_within_eq_image' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x y) :=
by set e := ext_chart_at I x;
calc map e (𝓝[s] y) = map e (𝓝[e.source ∩ s] y) :
congr_arg (map e) (nhds_within_inter_of_mem (ext_chart_at_source_mem_nhds_within' I x hy)).symm
... = 𝓝[e '' (e.source ∩ s)] (e y) :
((ext_chart_at I x).left_inv_on.mono $ inter_subset_left _ _).map_nhds_within_eq
((ext_chart_at I x).left_inv hy)
(ext_chart_continuous_at_symm' I x hy).continuous_within_at
(ext_chart_at_continuous_at' I x hy).continuous_within_at
lemma ext_chart_at_map_nhds_within_eq_image :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within_eq_image' I x (mem_ext_chart_source I x)
lemma ext_chart_at_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y) :=
by rw [ext_chart_at_map_nhds_within_eq_image' I x hy, nhds_within_inter,
← nhds_within_ext_chart_target_eq' _ _ hy, ← nhds_within_inter,
(ext_chart_at I x).image_source_inter_eq', inter_comm]
lemma ext_chart_at_map_nhds_within :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y)) = 𝓝[s] y :=
begin
rw [← ext_chart_at_map_nhds_within' I x hy, map_map, map_congr, map_id],
exact (ext_chart_at I x).left_inv_on.eq_on.eventually_eq_of_mem
(ext_chart_at_source_mem_nhds_within' _ _ hy)
end
lemma ext_chart_at_symm_map_nhds_within_range' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x y)) = 𝓝 y :=
by rw [← nhds_within_univ, ← ext_chart_at_symm_map_nhds_within' I x hy, preimage_univ, univ_inter]
lemma ext_chart_at_symm_map_nhds_within :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x)) = 𝓝[s] x :=
ext_chart_at_symm_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within_range :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x x)) = 𝓝 x :=
ext_chart_at_symm_map_nhds_within_range' I x (mem_ext_chart_source I x)
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
in the source is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source)
(ht : t ∈ 𝓝[s] x') :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x') :=
by rwa [← ext_chart_at_symm_map_nhds_within' I x h, mem_map] at ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of the
base point is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within (ht : t ∈ 𝓝[s] x) :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x) :=
ext_chart_preimage_mem_nhds_within' I x (mem_ext_chart_source I x) ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
is a neighborhood of the preimage. -/
lemma ext_chart_preimage_mem_nhds (ht : t ∈ 𝓝 x) :
(ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 ((ext_chart_at I x) x) :=
begin
apply (ext_chart_continuous_at_symm I x).preimage_mem_nhds,
rwa (ext_chart_at I x).left_inv (mem_ext_chart_source _ _)
end
/-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to
bring it into a convenient form to apply derivative lemmas. -/
lemma ext_chart_preimage_inter_eq :
((ext_chart_at I x).symm ⁻¹' (s ∩ t) ∩ range I)
= ((ext_chart_at I x).symm ⁻¹' s ∩ range I) ∩ ((ext_chart_at I x).symm ⁻¹' t) :=
by mfld_set_tac
end extended_charts
/-- In the case of the manifold structure on a vector space, the extended charts are just the
identity.-/
lemma ext_chart_model_space_eq_id (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E] (x : E) :
ext_chart_at (model_with_corners_self 𝕜 E) x = local_equiv.refl E :=
by simp only with mfld_simps
|
65b2750498d66fb88c53e7746e9fd94db7d1ea04 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/data/int/parity.lean | 945b5cec31bad02c1695c94ada372d901ef6fd70 | [
"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 | 7,621 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Benjamin Davidson
-/
import data.nat.parity
/-!
# Parity of integers
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
This file contains theorems about the `even` and `odd` predicates on the integers.
## Tags
even, odd
-/
namespace int
variables {m n : ℤ}
@[simp] theorem mod_two_ne_one : ¬ n % 2 = 1 ↔ n % 2 = 0 :=
by cases mod_two_eq_zero_or_one n with h h; simp [h]
local attribute [simp] -- euclidean_domain.mod_eq_zero uses (2 ∣ n) as normal form
theorem mod_two_ne_zero : ¬ n % 2 = 0 ↔ n % 2 = 1 :=
by cases mod_two_eq_zero_or_one n with h h; simp [h]
theorem even_iff : even n ↔ n % 2 = 0 :=
⟨λ ⟨m, hm⟩, by simp [← two_mul, hm], λ h, ⟨n / 2, (mod_add_div n 2).symm.trans
(by simp [← two_mul, h])⟩⟩
theorem odd_iff : odd n ↔ n % 2 = 1 :=
⟨λ ⟨m, hm⟩, by { rw [hm, add_mod], norm_num },
λ h, ⟨n / 2, (mod_add_div n 2).symm.trans (by { rw h, abel })⟩⟩
lemma not_even_iff : ¬ even n ↔ n % 2 = 1 :=
by rw [even_iff, mod_two_ne_zero]
lemma not_odd_iff : ¬ odd n ↔ n % 2 = 0 :=
by rw [odd_iff, mod_two_ne_one]
lemma even_iff_not_odd : even n ↔ ¬ odd n :=
by rw [not_odd_iff, even_iff]
@[simp] lemma odd_iff_not_even : odd n ↔ ¬ even n :=
by rw [not_even_iff, odd_iff]
lemma is_compl_even_odd : is_compl {n : ℤ | even n} {n | odd n} :=
by simp [← set.compl_set_of, is_compl_compl]
lemma even_or_odd (n : ℤ) : even n ∨ odd n :=
or.imp_right odd_iff_not_even.2 $ em $ even n
lemma even_or_odd' (n : ℤ) : ∃ k, n = 2 * k ∨ n = 2 * k + 1 :=
by simpa only [← two_mul, exists_or_distrib, ← odd, ← even] using even_or_odd n
lemma even_xor_odd (n : ℤ) : xor (even n) (odd n) :=
begin
cases even_or_odd n with h,
{ exact or.inl ⟨h, even_iff_not_odd.mp h⟩ },
{ exact or.inr ⟨h, odd_iff_not_even.mp h⟩ },
end
lemma even_xor_odd' (n : ℤ) : ∃ k, xor (n = 2 * k) (n = 2 * k + 1) :=
begin
rcases even_or_odd n with ⟨k, rfl⟩ | ⟨k, rfl⟩;
use k,
{ simpa only [← two_mul, xor, true_and, eq_self_iff_true, not_true, or_false, and_false]
using (succ_ne_self (2*k)).symm },
{ simp only [xor, add_right_eq_self, false_or, eq_self_iff_true, not_true, not_false_iff,
one_ne_zero, and_self] },
end
@[simp] theorem two_dvd_ne_zero : ¬ 2 ∣ n ↔ n % 2 = 1 :=
even_iff_two_dvd.symm.not.trans not_even_iff
instance : decidable_pred (even : ℤ → Prop) := λ n, decidable_of_iff _ even_iff.symm
instance : decidable_pred (odd : ℤ → Prop) := λ n, decidable_of_iff _ odd_iff_not_even.symm
@[simp] theorem not_even_one : ¬ even (1 : ℤ) :=
by rw even_iff; norm_num
@[parity_simps] theorem even_add : even (m + n) ↔ (even m ↔ even n) :=
by cases mod_two_eq_zero_or_one m with h₁ h₁;
cases mod_two_eq_zero_or_one n with h₂ h₂;
simp [even_iff, h₁, h₂, int.add_mod];
norm_num
theorem even_add' : even (m + n) ↔ (odd m ↔ odd n) :=
by rw [even_add, even_iff_not_odd, even_iff_not_odd, not_iff_not]
@[simp] theorem not_even_bit1 (n : ℤ) : ¬ even (bit1 n) :=
by simp [bit1] with parity_simps
lemma two_not_dvd_two_mul_add_one (n : ℤ) : ¬(2 ∣ 2 * n + 1) :=
by { simp [add_mod], refl }
@[parity_simps] theorem even_sub : even (m - n) ↔ (even m ↔ even n) :=
by simp [sub_eq_add_neg] with parity_simps
theorem even_sub' : even (m - n) ↔ (odd m ↔ odd n) :=
by rw [even_sub, even_iff_not_odd, even_iff_not_odd, not_iff_not]
@[parity_simps] theorem even_add_one : even (n + 1) ↔ ¬ even n :=
by simp [even_add]
@[parity_simps] theorem even_mul : even (m * n) ↔ even m ∨ even n :=
by cases mod_two_eq_zero_or_one m with h₁ h₁;
cases mod_two_eq_zero_or_one n with h₂ h₂;
simp [even_iff, h₁, h₂, int.mul_mod];
norm_num
theorem odd_mul : odd (m * n) ↔ odd m ∧ odd n :=
by simp [not_or_distrib] with parity_simps
theorem odd.of_mul_left (h : odd (m * n)) : odd m :=
(odd_mul.mp h).1
theorem odd.of_mul_right (h : odd (m * n)) : odd n :=
(odd_mul.mp h).2
@[parity_simps] theorem even_pow {n : ℕ} : even (m ^ n) ↔ even m ∧ n ≠ 0 :=
by { induction n with n ih; simp [*, even_mul, pow_succ], tauto }
theorem even_pow' {n : ℕ} (h : n ≠ 0) : even (m ^ n) ↔ even m :=
even_pow.trans $ and_iff_left h
@[parity_simps] theorem odd_add : odd (m + n) ↔ (odd m ↔ even n) :=
by rw [odd_iff_not_even, even_add, not_iff, odd_iff_not_even]
theorem odd_add' : odd (m + n) ↔ (odd n ↔ even m) :=
by rw [add_comm, odd_add]
lemma ne_of_odd_add (h : odd (m + n)) : m ≠ n :=
λ hnot, by simpa [hnot] with parity_simps using h
@[parity_simps] theorem odd_sub : odd (m - n) ↔ (odd m ↔ even n) :=
by rw [odd_iff_not_even, even_sub, not_iff, odd_iff_not_even]
theorem odd_sub' : odd (m - n) ↔ (odd n ↔ even m) :=
by rw [odd_iff_not_even, even_sub, not_iff, not_iff_comm, odd_iff_not_even]
lemma even_mul_succ_self (n : ℤ) : even (n * (n + 1)) :=
begin
rw even_mul,
convert n.even_or_odd,
simp with parity_simps
end
@[simp, norm_cast] theorem even_coe_nat (n : ℕ) : even (n : ℤ) ↔ even n :=
by rw_mod_cast [even_iff, nat.even_iff]
@[simp, norm_cast] theorem odd_coe_nat (n : ℕ) : odd (n : ℤ) ↔ odd n :=
by rw [odd_iff_not_even, nat.odd_iff_not_even, even_coe_nat]
@[simp] theorem nat_abs_even : even n.nat_abs ↔ even n :=
by simp [even_iff_two_dvd, dvd_nat_abs, coe_nat_dvd_left.symm]
@[simp] theorem nat_abs_odd : odd n.nat_abs ↔ odd n :=
by rw [odd_iff_not_even, nat.odd_iff_not_even, nat_abs_even]
alias nat_abs_even ↔ _ _root_.even.nat_abs
alias nat_abs_odd ↔ _ _root_.odd.nat_abs
attribute [protected] even.nat_abs odd.nat_abs
lemma four_dvd_add_or_sub_of_odd {a b : ℤ} (ha : odd a) (hb : odd b) : 4 ∣ a + b ∨ 4 ∣ a - b :=
begin
obtain ⟨m, rfl⟩ := ha,
obtain ⟨n, rfl⟩ := hb,
obtain h|h := int.even_or_odd (m + n),
{ right,
rw [int.even_add, ←int.even_sub] at h,
obtain ⟨k, hk⟩ := h,
convert dvd_mul_right 4 k,
rw [eq_add_of_sub_eq hk, mul_add, add_assoc, add_sub_cancel, ← two_mul, ←mul_assoc],
refl },
{ left,
obtain ⟨k, hk⟩ := h,
convert dvd_mul_right 4 (k + 1),
rw [eq_sub_of_add_eq hk, add_right_comm, ←add_sub, mul_add, mul_sub, add_assoc, add_assoc,
sub_add, add_assoc, ←sub_sub (2 * n), sub_self, zero_sub, sub_neg_eq_add, ←mul_assoc,
mul_add],
refl },
end
lemma two_mul_div_two_of_even : even n → 2 * (n / 2) = n :=
λ h, int.mul_div_cancel' (even_iff_two_dvd.mp h)
lemma div_two_mul_two_of_even : even n → n / 2 * 2 = n := --int.div_mul_cancel
λ h, int.div_mul_cancel (even_iff_two_dvd.mp h)
lemma two_mul_div_two_add_one_of_odd : odd n → 2 * (n / 2) + 1 = n :=
by { rintro ⟨c, rfl⟩, rw mul_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }
lemma div_two_mul_two_add_one_of_odd : odd n → n / 2 * 2 + 1 = n :=
by { rintro ⟨c, rfl⟩, convert int.div_add_mod' _ _, simpa [int.add_mod] }
lemma add_one_div_two_mul_two_of_odd : odd n → 1 + n / 2 * 2 = n :=
by { rintro ⟨c, rfl⟩, rw add_comm, convert int.div_add_mod' _ _, simpa [int.add_mod] }
lemma two_mul_div_two_of_odd (h : odd n) : 2 * (n / 2) = n - 1 :=
eq_sub_of_add_eq (two_mul_div_two_add_one_of_odd h)
-- Here are examples of how `parity_simps` can be used with `int`.
example (m n : ℤ) (h : even m) : ¬ even (n + 3) ↔ even (m^2 + m + n) :=
by simp [*, (dec_trivial : ¬ 2 = 0)] with parity_simps
example : ¬ even (25394535 : ℤ) :=
by simp
end int
|
48cb14a878ffea6957421fb3a8fd7c5732ee4464 | 856e2e1615a12f95b551ed48fa5b03b245abba44 | /src/analysis/calculus/tangent_cone.lean | d2d5cac753245c1b07bc992faa19d7e631a8742b | [
"Apache-2.0"
] | permissive | pimsp/mathlib | 8b77e1ccfab21703ba8fbe65988c7de7765aa0e5 | 913318ca9d6979686996e8d9b5ebf7e74aae1c63 | refs/heads/master | 1,669,812,465,182 | 1,597,133,610,000 | 1,597,133,610,000 | 281,890,685 | 1 | 0 | null | 1,595,491,577,000 | 1,595,491,576,000 | null | UTF-8 | Lean | false | false | 16,528 | 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.convex.basic
import analysis.normed_space.bounded_linear_maps
import analysis.specific_limits
/-!
# Tangent cone
In this file, we define two predicates `unique_diff_within_at 𝕜 s x` and `unique_diff_on 𝕜 s`
ensuring that, if a function has two derivatives, then they have to coincide. As a direct
definition of this fact (quantifying on all target types and all functions) would depend on
universes, we use a more intrinsic definition: if all the possible tangent directions to the set
`s` at the point `x` span a dense subset of the whole subset, it is easy to check that the
derivative has to be unique.
Therefore, we introduce the set of all tangent directions, named `tangent_cone_at`,
and express `unique_diff_within_at` and `unique_diff_on` in terms of it.
One should however think of this definition as an implementation detail: the only reason to
introduce the predicates `unique_diff_within_at` and `unique_diff_on` is to ensure the uniqueness
of the derivative. This is why their names reflect their uses, and not how they are defined.
## Implementation details
Note that this file is imported by `fderiv.lean`. Hence, derivatives are not defined yet. The
property of uniqueness of the derivative is therefore proved in `fderiv.lean`, but based on the
properties of the tangent cone we prove here.
-/
variables (𝕜 : Type*) [nondiscrete_normed_field 𝕜]
variables {E : Type*} [normed_group E] [normed_space 𝕜 E]
variables {F : Type*} [normed_group F] [normed_space 𝕜 F]
variables {G : Type*} [normed_group G] [normed_space ℝ G]
open filter set
open_locale topological_space
/-- The set of all tangent directions to the set `s` at the point `x`. -/
def tangent_cone_at (s : set E) (x : E) : set E :=
{y : E | ∃(c : ℕ → 𝕜) (d : ℕ → E), (∀ᶠ n in at_top, x + d n ∈ s) ∧
(tendsto (λn, ∥c n∥) at_top at_top) ∧ (tendsto (λn, c n • d n) at_top (𝓝 y))}
/-- A property ensuring that the tangent cone to `s` at `x` spans a dense subset of the whole space.
The main role of this property is to ensure that the differential within `s` at `x` is unique,
hence this name. The uniqueness it asserts is proved in `unique_diff_within_at.eq` in `fderiv.lean`.
To avoid pathologies in dimension 0, we also require that `x` belongs to the closure of `s` (which
is automatic when `E` is not `0`-dimensional).
-/
def unique_diff_within_at (s : set E) (x : E) : Prop :=
closure ((submodule.span 𝕜 (tangent_cone_at 𝕜 s x)) : set E) = univ ∧ x ∈ closure s
/-- A property ensuring that the tangent cone to `s` at any of its points spans a dense subset of
the whole space. The main role of this property is to ensure that the differential along `s` is
unique, hence this name. The uniqueness it asserts is proved in `unique_diff_on.eq` in
`fderiv.lean`. -/
def unique_diff_on (s : set E) : Prop :=
∀x ∈ s, unique_diff_within_at 𝕜 s x
variables {𝕜} {x y : E} {s t : set E}
section tangent_cone
/- This section is devoted to the properties of the tangent cone. -/
open normed_field
lemma tangent_cone_univ : tangent_cone_at 𝕜 univ x = univ :=
begin
refine univ_subset_iff.1 (λy hy, _),
rcases exists_one_lt_norm 𝕜 with ⟨w, hw⟩,
refine ⟨λn, w^n, λn, (w^n)⁻¹ • y, univ_mem_sets' (λn, mem_univ _), _, _⟩,
{ simp only [norm_pow],
exact tendsto_pow_at_top_at_top_of_one_lt hw },
{ convert tendsto_const_nhds,
ext n,
have : w ^ n * (w ^ n)⁻¹ = 1,
{ apply mul_inv_cancel,
apply pow_ne_zero,
simpa [norm_eq_zero] using (ne_of_lt (lt_trans zero_lt_one hw)).symm },
rw [smul_smul, this, one_smul] }
end
lemma tangent_cone_mono (h : s ⊆ t) :
tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x :=
begin
rintros y ⟨c, d, ds, ctop, clim⟩,
exact ⟨c, d, mem_sets_of_superset ds (λn hn, h hn), ctop, clim⟩
end
/-- Auxiliary lemma ensuring that, under the assumptions defining the tangent cone,
the sequence `d` tends to 0 at infinity. -/
lemma tangent_cone_at.lim_zero {α : Type*} (l : filter α) {c : α → 𝕜} {d : α → E}
(hc : tendsto (λn, ∥c n∥) l at_top) (hd : tendsto (λn, c n • d n) l (𝓝 y)) :
tendsto d l (𝓝 0) :=
begin
have A : tendsto (λn, ∥c n∥⁻¹) l (𝓝 0) := tendsto_inv_at_top_zero.comp hc,
have B : tendsto (λn, ∥c n • d n∥) l (𝓝 ∥y∥) :=
(continuous_norm.tendsto _).comp hd,
have C : tendsto (λn, ∥c n∥⁻¹ * ∥c n • d n∥) l (𝓝 (0 * ∥y∥)) := A.mul B,
rw zero_mul at C,
have : ∀ᶠ n in l, ∥c n∥⁻¹ * ∥c n • d n∥ = ∥d n∥,
{ apply (eventually_ne_of_tendsto_norm_at_top hc 0).mono (λn hn, _),
rw [norm_smul, ← mul_assoc, inv_mul_cancel, one_mul],
rwa [ne.def, norm_eq_zero] },
have D : tendsto (λ n, ∥d n∥) l (𝓝 0) :=
tendsto.congr' this C,
rw tendsto_zero_iff_norm_tendsto_zero,
exact D
end
lemma tangent_cone_mono_nhds (h : nhds_within x s ≤ nhds_within x t) :
tangent_cone_at 𝕜 s x ⊆ tangent_cone_at 𝕜 t x :=
begin
rintros y ⟨c, d, ds, ctop, clim⟩,
refine ⟨c, d, _, ctop, clim⟩,
suffices : tendsto (λ n, x + d n) at_top (nhds_within x t),
from tendsto_principal.1 (tendsto_inf.1 this).2,
apply tendsto_le_right h,
refine tendsto_inf.2 ⟨_, tendsto_principal.2 ds⟩,
simpa only [add_zero] using tendsto_const_nhds.add (tangent_cone_at.lim_zero at_top ctop clim)
end
/-- Tangent cone of `s` at `x` depends only on `nhds_within x s`. -/
lemma tangent_cone_congr (h : nhds_within x s = nhds_within x t) :
tangent_cone_at 𝕜 s x = tangent_cone_at 𝕜 t x :=
subset.antisymm
(tangent_cone_mono_nhds $ le_of_eq h)
(tangent_cone_mono_nhds $ le_of_eq h.symm)
/-- Intersecting with a neighborhood of the point does not change the tangent cone. -/
lemma tangent_cone_inter_nhds (ht : t ∈ 𝓝 x) :
tangent_cone_at 𝕜 (s ∩ t) x = tangent_cone_at 𝕜 s x :=
tangent_cone_congr (nhds_within_restrict' _ ht).symm
/-- The tangent cone of a product contains the tangent cone of its left factor. -/
lemma subset_tangent_cone_prod_left {t : set F} {y : F} (ht : y ∈ closure t) :
prod.inl '' (tangent_cone_at 𝕜 s x) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) :=
begin
rintros _ ⟨v, ⟨c, d, hd, hc, hy⟩, rfl⟩,
have : ∀n, ∃d', y + d' ∈ t ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n,
{ assume n,
have c_pos : 0 < 1 + ∥c n∥ :=
add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _),
rcases metric.mem_closure_iff.1 ht ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩,
refine ⟨z - y, _, _⟩,
{ convert z_pos, abel },
{ rw [norm_smul, ← dist_eq_norm, dist_comm],
calc ∥c n∥ * dist y z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) :
begin
apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos),
simp only [zero_le_one, le_add_iff_nonneg_left]
end
... = (1/2)^n :
begin
rw [← mul_assoc, mul_inv_cancel, one_mul],
exact ne_of_gt c_pos
end },
{ apply mul_pos (inv_pos.2 c_pos) (pow_pos _ _),
norm_num } },
choose d' hd' using this,
refine ⟨c, λn, (d n, d' n), _, hc, _⟩,
show ∀ᶠ n in at_top, (x, y) + (d n, d' n) ∈ set.prod s t,
{ apply filter.mem_sets_of_superset hd,
assume n hn,
simp at hn,
simp [hn, (hd' n).1] },
{ apply hy.prod_mk_nhds,
change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0),
rw tendsto_zero_iff_norm_tendsto_zero,
refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _,
apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num }
end
/-- The tangent cone of a product contains the tangent cone of its right factor. -/
lemma subset_tangent_cone_prod_right {t : set F} {y : F}
(hs : x ∈ closure s) :
prod.inr '' (tangent_cone_at 𝕜 t y) ⊆ tangent_cone_at 𝕜 (set.prod s t) (x, y) :=
begin
rintros _ ⟨w, ⟨c, d, hd, hc, hy⟩, rfl⟩,
have : ∀n, ∃d', x + d' ∈ s ∧ ∥c n • d'∥ ≤ ((1:ℝ)/2)^n,
{ assume n,
have c_pos : 0 < 1 + ∥c n∥ :=
add_pos_of_pos_of_nonneg zero_lt_one (norm_nonneg _),
rcases metric.mem_closure_iff.1 hs ((1 + ∥c n∥)⁻¹ * (1/2)^n) _ with ⟨z, z_pos, hz⟩,
refine ⟨z - x, _, _⟩,
{ convert z_pos, abel },
{ rw [norm_smul, ← dist_eq_norm, dist_comm],
calc ∥c n∥ * dist x z ≤ (1 + ∥c n∥) * ((1 + ∥c n∥)⁻¹ * (1/2)^n) :
begin
apply mul_le_mul _ (le_of_lt hz) dist_nonneg (le_of_lt c_pos),
simp only [zero_le_one, le_add_iff_nonneg_left]
end
... = (1/2)^n :
begin
rw [← mul_assoc, mul_inv_cancel, one_mul],
exact ne_of_gt c_pos
end },
{ apply mul_pos (inv_pos.2 c_pos) (pow_pos _ _),
norm_num } },
choose d' hd' using this,
refine ⟨c, λn, (d' n, d n), _, hc, _⟩,
show ∀ᶠ n in at_top, (x, y) + (d' n, d n) ∈ set.prod s t,
{ apply filter.mem_sets_of_superset hd,
assume n hn,
simp at hn,
simp [hn, (hd' n).1] },
{ apply tendsto.prod_mk_nhds _ hy,
change tendsto (λ (n : ℕ), c n • d' n) at_top (𝓝 0),
rw tendsto_zero_iff_norm_tendsto_zero,
refine squeeze_zero (λn, norm_nonneg _) (λn, (hd' n).2) _,
apply tendsto_pow_at_top_nhds_0_of_lt_1; norm_num }
end
/-- If a subset of a real vector space contains a segment, then the direction of this
segment belongs to the tangent cone at its endpoints. -/
lemma mem_tangent_cone_of_segment_subset {s : set G} {x y : G} (h : segment x y ⊆ s) :
y - x ∈ tangent_cone_at ℝ s x :=
begin
let w : ℝ := 2,
let c := λn:ℕ, (2:ℝ)^n,
let d := λn:ℕ, (c n)⁻¹ • (y-x),
refine ⟨c, d, filter.univ_mem_sets' (λn, h _), _, _⟩,
show x + d n ∈ segment x y,
{ rw segment_eq_image,
refine ⟨(c n)⁻¹, ⟨_, _⟩, _⟩,
{ rw inv_nonneg, apply pow_nonneg, norm_num },
{ apply inv_le_one, apply one_le_pow_of_one_le, norm_num },
{ simp only [d, sub_smul, smul_sub, one_smul], abel } },
show filter.tendsto (λ (n : ℕ), ∥c n∥) filter.at_top filter.at_top,
{ have : (λ (n : ℕ), ∥c n∥) = c,
by { ext n, exact abs_of_nonneg (pow_nonneg (by norm_num) _) },
rw this,
exact tendsto_pow_at_top_at_top_of_one_lt (by norm_num) },
show filter.tendsto (λ (n : ℕ), c n • d n) filter.at_top (𝓝 (y - x)),
{ have : (λ (n : ℕ), c n • d n) = (λn, y - x),
{ ext n,
simp only [d, smul_smul],
rw [mul_inv_cancel, one_smul],
exact pow_ne_zero _ (by norm_num) },
rw this,
apply tendsto_const_nhds }
end
end tangent_cone
section unique_diff
/- This section is devoted to properties of the predicates `unique_diff_within_at` and
`unique_diff_on`. -/
lemma unique_diff_within_at_univ : unique_diff_within_at 𝕜 univ x :=
by { rw [unique_diff_within_at, tangent_cone_univ], simp }
lemma unique_diff_on_univ : unique_diff_on 𝕜 (univ : set E) :=
λx hx, unique_diff_within_at_univ
lemma unique_diff_on_empty : unique_diff_on 𝕜 (∅ : set E) :=
λ x hx, hx.elim
lemma unique_diff_within_at.mono_nhds (h : unique_diff_within_at 𝕜 s x)
(st : nhds_within x s ≤ nhds_within x t) :
unique_diff_within_at 𝕜 t x :=
begin
unfold unique_diff_within_at at *,
rw [← univ_subset_iff, ← h.1],
rw [mem_closure_iff_nhds_within_ne_bot] at h ⊢,
exact ⟨closure_mono (submodule.span_mono (tangent_cone_mono_nhds st)),
ne_bot_of_le_ne_bot h.2 st⟩
end
lemma unique_diff_within_at.mono (h : unique_diff_within_at 𝕜 s x) (st : s ⊆ t) :
unique_diff_within_at 𝕜 t x :=
h.mono_nhds $ nhds_within_mono _ st
lemma unique_diff_within_at_congr (st : nhds_within x s = nhds_within x t) :
unique_diff_within_at 𝕜 s x ↔ unique_diff_within_at 𝕜 t x :=
⟨λ h, h.mono_nhds $ le_of_eq st, λ h, h.mono_nhds $ le_of_eq st.symm⟩
lemma unique_diff_within_at_inter (ht : t ∈ 𝓝 x) :
unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x :=
unique_diff_within_at_congr $ (nhds_within_restrict' _ ht).symm
lemma unique_diff_within_at.inter (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ 𝓝 x) :
unique_diff_within_at 𝕜 (s ∩ t) x :=
(unique_diff_within_at_inter ht).2 hs
lemma unique_diff_within_at_inter' (ht : t ∈ nhds_within x s) :
unique_diff_within_at 𝕜 (s ∩ t) x ↔ unique_diff_within_at 𝕜 s x :=
unique_diff_within_at_congr $ (nhds_within_restrict'' _ ht).symm
lemma unique_diff_within_at.inter' (hs : unique_diff_within_at 𝕜 s x) (ht : t ∈ nhds_within x s) :
unique_diff_within_at 𝕜 (s ∩ t) x :=
(unique_diff_within_at_inter' ht).2 hs
lemma is_open.unique_diff_within_at (hs : is_open s) (xs : x ∈ s) : unique_diff_within_at 𝕜 s x :=
begin
have := unique_diff_within_at_univ.inter (mem_nhds_sets hs xs),
rwa univ_inter at this
end
lemma unique_diff_on.inter (hs : unique_diff_on 𝕜 s) (ht : is_open t) : unique_diff_on 𝕜 (s ∩ t) :=
λx hx, (hs x hx.1).inter (mem_nhds_sets ht hx.2)
lemma is_open.unique_diff_on (hs : is_open s) : unique_diff_on 𝕜 s :=
λx hx, is_open.unique_diff_within_at hs hx
/-- The product of two sets of unique differentiability at points `x` and `y` has unique
differentiability at `(x, y)`. -/
lemma unique_diff_within_at.prod {t : set F} {y : F}
(hs : unique_diff_within_at 𝕜 s x) (ht : unique_diff_within_at 𝕜 t y) :
unique_diff_within_at 𝕜 (set.prod s t) (x, y) :=
begin
rw [unique_diff_within_at] at ⊢ hs ht,
rw [← univ_subset_iff, closure_prod_eq],
refine ⟨_, hs.2, ht.2⟩,
have : _ ⊆ tangent_cone_at 𝕜 (s.prod t) (x, y) :=
union_subset (subset_tangent_cone_prod_left ht.2) (subset_tangent_cone_prod_right hs.2),
refine subset.trans _ (closure_mono $ submodule.span_mono this),
erw [linear_map.span_inl_union_inr, submodule.prod_coe, closure_prod_eq,
hs.1, ht.1, univ_prod_univ]
end
/-- The product of two sets of unique differentiability is a set of unique differentiability. -/
lemma unique_diff_on.prod {t : set F} (hs : unique_diff_on 𝕜 s) (ht : unique_diff_on 𝕜 t) :
unique_diff_on 𝕜 (set.prod s t) :=
λ ⟨x, y⟩ h, unique_diff_within_at.prod (hs x h.1) (ht y h.2)
/-- In a real vector space, a convex set with nonempty interior is a set of unique
differentiability. -/
theorem unique_diff_on_convex {s : set G} (conv : convex s) (hs : (interior s).nonempty) :
unique_diff_on ℝ s :=
begin
assume x xs,
rcases hs with ⟨y, hy⟩,
suffices : y - x ∈ interior (tangent_cone_at ℝ s x),
{ refine ⟨_, subset_closure xs⟩,
rw [submodule.eq_top_of_nonempty_interior' _ ⟨y - x, interior_mono submodule.subset_span this⟩,
submodule.top_coe, closure_univ]; apply_instance },
rw [mem_interior_iff_mem_nhds] at hy ⊢,
apply mem_sets_of_superset ((is_open_map_add_right (-x)).image_mem_nhds hy),
rintros _ ⟨z, zs, rfl⟩,
exact mem_tangent_cone_of_segment_subset (conv.segment_subset xs zs)
end
lemma unique_diff_on_Ici (a : ℝ) : unique_diff_on ℝ (Ici a) :=
unique_diff_on_convex (convex_Ici a) $ by simp only [interior_Ici, nonempty_Ioi]
lemma unique_diff_on_Iic (a : ℝ) : unique_diff_on ℝ (Iic a) :=
unique_diff_on_convex (convex_Iic a) $ by simp only [interior_Iic, nonempty_Iio]
lemma unique_diff_on_Ioi (a : ℝ) : unique_diff_on ℝ (Ioi a) :=
is_open_Ioi.unique_diff_on
lemma unique_diff_on_Iio (a : ℝ) : unique_diff_on ℝ (Iio a) :=
is_open_Iio.unique_diff_on
lemma unique_diff_on_Icc {a b : ℝ} (hab : a < b) : unique_diff_on ℝ (Icc a b) :=
unique_diff_on_convex (convex_Icc a b) $ by simp only [interior_Icc, nonempty_Ioo, hab]
lemma unique_diff_on_Ico (a b : ℝ) : unique_diff_on ℝ (Ico a b) :=
if hab : a < b
then unique_diff_on_convex (convex_Ico a b) $ by simp only [interior_Ico, nonempty_Ioo, hab]
else by simp only [Ico_eq_empty (le_of_not_lt hab), unique_diff_on_empty]
lemma unique_diff_on_Ioc (a b : ℝ) : unique_diff_on ℝ (Ioc a b) :=
if hab : a < b
then unique_diff_on_convex (convex_Ioc a b) $ by simp only [interior_Ioc, nonempty_Ioo, hab]
else by simp only [Ioc_eq_empty (le_of_not_lt hab), unique_diff_on_empty]
lemma unique_diff_on_Ioo (a b : ℝ) : unique_diff_on ℝ (Ioo a b) :=
is_open_Ioo.unique_diff_on
/-- The real interval `[0, 1]` is a set of unique differentiability. -/
lemma unique_diff_on_Icc_zero_one : unique_diff_on ℝ (Icc (0:ℝ) 1) :=
unique_diff_on_Icc zero_lt_one
end unique_diff
|
752d676fed299e25f9501ad873d2663110cdfbf1 | c777c32c8e484e195053731103c5e52af26a25d1 | /src/analysis/inner_product_space/basic.lean | 5535f38f68fcd2fa28d7552eb75c360229cf4e8e | [
"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 | 96,841 | lean | /-
Copyright (c) 2019 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou, Sébastien Gouëzel, Frédéric Dupuis
-/
import algebra.direct_sum.module
import analysis.complex.basic
import analysis.convex.uniform
import analysis.normed_space.completion
import analysis.normed_space.bounded_linear_maps
import linear_algebra.bilinear_form
/-!
# Inner product space
This file defines inner product spaces and proves the basic properties. We do not formally
define Hilbert spaces, but they can be obtained using the set of assumptions
`[normed_add_comm_group E] [inner_product_space 𝕜 E] [complete_space E]`.
An inner product space is a vector space endowed with an inner product. It generalizes the notion of
dot product in `ℝ^n` and provides the means of defining the length of a vector and the angle between
two vectors. In particular vectors `x` and `y` are orthogonal if their inner product equals zero.
We define both the real and complex cases at the same time using the `is_R_or_C` typeclass.
This file proves general results on inner product spaces. For the specific construction of an inner
product structure on `n → 𝕜` for `𝕜 = ℝ` or `ℂ`, see `euclidean_space` in
`analysis.inner_product_space.pi_L2`.
## Main results
- We define the class `inner_product_space 𝕜 E` extending `normed_space 𝕜 E` with a number of basic
properties, most notably the Cauchy-Schwarz inequality. Here `𝕜` is understood to be either `ℝ`
or `ℂ`, through the `is_R_or_C` typeclass.
- We show that the inner product is continuous, `continuous_inner`, and bundle it as the
the continuous sesquilinear map `innerSL` (see also `innerₛₗ` for the non-continuous version).
- We define `orthonormal`, a predicate on a function `v : ι → E`, and prove the existence of a
maximal orthonormal set, `exists_maximal_orthonormal`. Bessel's inequality,
`orthonormal.tsum_inner_products_le`, states that given an orthonormal set `v` and a vector `x`,
the sum of the norm-squares of the inner products `⟪v i, x⟫` is no more than the norm-square of
`x`. For the existence of orthonormal bases, Hilbert bases, etc., see the file
`analysis.inner_product_space.projection`.
## Notation
We globally denote the real and complex inner products by `⟪·, ·⟫_ℝ` and `⟪·, ·⟫_ℂ` respectively.
We also provide two notation namespaces: `real_inner_product_space`, `complex_inner_product_space`,
which respectively introduce the plain notation `⟪·, ·⟫` for the real and complex inner product.
## Implementation notes
We choose the convention that inner products are conjugate linear in the first argument and linear
in the second.
## Tags
inner product space, Hilbert space, norm
## References
* [Clément & Martin, *The Lax-Milgram Theorem. A detailed proof to be formalized in Coq*]
* [Clément & Martin, *A Coq formal proof of the Lax–Milgram theorem*]
The Coq code is available at the following address: <http://www.lri.fr/~sboldo/elfic/index.html>
-/
noncomputable theory
open is_R_or_C real filter
open_locale big_operators topology complex_conjugate
variables {𝕜 E F : Type*} [is_R_or_C 𝕜]
/-- Syntactic typeclass for types endowed with an inner product -/
class has_inner (𝕜 E : Type*) := (inner : E → E → 𝕜)
export has_inner (inner)
notation `⟪`x`, `y`⟫_ℝ` := @inner ℝ _ _ x y
notation `⟪`x`, `y`⟫_ℂ` := @inner ℂ _ _ x y
section notations
localized "notation (name := inner.real)
`⟪`x`, `y`⟫` := @inner ℝ _ _ x y" in real_inner_product_space
localized "notation (name := inner.complex)
`⟪`x`, `y`⟫` := @inner ℂ _ _ x y" in complex_inner_product_space
end notations
/--
An inner product space is a vector space with an additional operation called inner product.
The norm could be derived from the inner product, instead we require the existence of a norm and
the fact that `‖x‖^2 = re ⟪x, x⟫` to be able to put instances on `𝕂` or product
spaces.
To construct a norm from an inner product, see `inner_product_space.of_core`.
-/
class inner_product_space (𝕜 : Type*) (E : Type*) [is_R_or_C 𝕜] [normed_add_comm_group E]
extends normed_space 𝕜 E, has_inner 𝕜 E :=
(norm_sq_eq_inner : ∀ (x : E), ‖x‖^2 = re (inner x x))
(conj_symm : ∀ x y, conj (inner y x) = inner x y)
(add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z)
(smul_left : ∀ x y r, inner (r • x) y = (conj r) * inner x y)
/-!
### Constructing a normed space structure from an inner product
In the definition of an inner product space, we require the existence of a norm, which is equal
(but maybe not defeq) to the square root of the scalar product. This makes it possible to put
an inner product space structure on spaces with a preexisting norm (for instance `ℝ`), with good
properties. However, sometimes, one would like to define the norm starting only from a well-behaved
scalar product. This is what we implement in this paragraph, starting from a structure
`inner_product_space.core` stating that we have a nice scalar product.
Our goal here is not to develop a whole theory with all the supporting API, as this will be done
below for `inner_product_space`. Instead, we implement the bare minimum to go as directly as
possible to the construction of the norm and the proof of the triangular inequality.
Warning: Do not use this `core` structure if the space you are interested in already has a norm
instance defined on it, otherwise this will create a second non-defeq norm instance!
-/
/-- A structure requiring that a scalar product is positive definite and symmetric, from which one
can construct an `inner_product_space` instance in `inner_product_space.of_core`. -/
@[nolint has_nonempty_instance]
structure inner_product_space.core (𝕜 : Type*) (F : Type*)
[is_R_or_C 𝕜] [add_comm_group F] [module 𝕜 F] extends has_inner 𝕜 F :=
(conj_symm : ∀ x y, conj (inner y x) = inner x y)
(nonneg_re : ∀ x, 0 ≤ re (inner x x))
(definite : ∀ x, inner x x = 0 → x = 0)
(add_left : ∀ x y z, inner (x + y) z = inner x z + inner y z)
(smul_left : ∀ x y r, inner (r • x) y = (conj r) * inner x y)
/- We set `inner_product_space.core` to be a class as we will use it as such in the construction
of the normed space structure that it produces. However, all the instances we will use will be
local to this proof. -/
attribute [class] inner_product_space.core
/-- Define `inner_product_space.core` from `inner_product_space`. Defined to reuse lemmas about
`inner_product_space.core` for `inner_product_space`s. Note that the `has_norm` instance provided by
`inner_product_space.core.has_norm` is propositionally but not definitionally equal to the original
norm. -/
def inner_product_space.to_core [normed_add_comm_group E] [c : inner_product_space 𝕜 E] :
inner_product_space.core 𝕜 E :=
{ nonneg_re := λ x, by { rw [← inner_product_space.norm_sq_eq_inner], apply sq_nonneg },
definite := λ x hx, norm_eq_zero.1 $ pow_eq_zero $
by rw [inner_product_space.norm_sq_eq_inner x, hx, map_zero],
.. c }
namespace inner_product_space.core
variables [add_comm_group F] [module 𝕜 F] [c : inner_product_space.core 𝕜 F]
include c
local notation `⟪`x`, `y`⟫` := @inner 𝕜 F _ x y
local notation `norm_sqK` := @is_R_or_C.norm_sq 𝕜 _
local notation `reK` := @is_R_or_C.re 𝕜 _
local notation `ext_iff` := @is_R_or_C.ext_iff 𝕜 _
local postfix `†`:90 := star_ring_end _
/-- Inner product defined by the `inner_product_space.core` structure. We can't reuse
`inner_product_space.core.to_has_inner` because it takes `inner_product_space.core` as an explicit
argument. -/
def to_has_inner' : has_inner 𝕜 F := c.to_has_inner
local attribute [instance] to_has_inner'
/-- The norm squared function for `inner_product_space.core` structure. -/
def norm_sq (x : F) := reK ⟪x, x⟫
local notation `norm_sqF` := @norm_sq 𝕜 F _ _ _ _
lemma inner_conj_symm (x y : F) : ⟪y, x⟫† = ⟪x, y⟫ := c.conj_symm x y
lemma inner_self_nonneg {x : F} : 0 ≤ re ⟪x, x⟫ := c.nonneg_re _
lemma inner_self_im (x : F) : im ⟪x, x⟫ = 0 :=
by rw [← @of_real_inj 𝕜, im_eq_conj_sub]; simp [inner_conj_symm]
lemma inner_add_left (x y z : F) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
c.add_left _ _ _
lemma inner_add_right (x y z : F) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ :=
by rw [←inner_conj_symm, inner_add_left, ring_hom.map_add]; simp only [inner_conj_symm]
lemma coe_norm_sq_eq_inner_self (x : F) : (norm_sqF x : 𝕜) = ⟪x, x⟫ :=
begin
rw ext_iff,
exact ⟨by simp only [of_real_re]; refl, by simp only [inner_self_im, of_real_im]⟩
end
lemma inner_re_symm (x y : F) : re ⟪x, y⟫ = re ⟪y, x⟫ :=
by rw [←inner_conj_symm, conj_re]
lemma inner_im_symm (x y : F) : im ⟪x, y⟫ = -im ⟪y, x⟫ :=
by rw [←inner_conj_symm, conj_im]
lemma inner_smul_left (x y : F) {r : 𝕜} : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
c.smul_left _ _ _
lemma inner_smul_right (x y : F) {r : 𝕜} : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
by rw [←inner_conj_symm, inner_smul_left]; simp only [conj_conj, inner_conj_symm, ring_hom.map_mul]
lemma inner_zero_left (x : F) : ⟪0, x⟫ = 0 :=
by rw [←zero_smul 𝕜 (0 : F), inner_smul_left]; simp only [zero_mul, ring_hom.map_zero]
lemma inner_zero_right (x : F) : ⟪x, 0⟫ = 0 :=
by rw [←inner_conj_symm, inner_zero_left]; simp only [ring_hom.map_zero]
lemma inner_self_eq_zero {x : F} : ⟪x, x⟫ = 0 ↔ x = 0 :=
⟨c.definite _, by { rintro rfl, exact inner_zero_left _ }⟩
lemma norm_sq_eq_zero {x : F} : norm_sqF x = 0 ↔ x = 0 :=
iff.trans (by simp only [norm_sq, ext_iff, map_zero, inner_self_im, eq_self_iff_true, and_true])
(@inner_self_eq_zero 𝕜 _ _ _ _ _ x)
lemma inner_self_ne_zero {x : F} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
lemma inner_self_re_to_K (x : F) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
by norm_num [ext_iff, inner_self_im]
lemma norm_inner_symm (x y : F) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ :=
by rw [←inner_conj_symm, norm_conj]
lemma inner_neg_left (x y : F) : ⟪-x, y⟫ = -⟪x, y⟫ :=
by { rw [← neg_one_smul 𝕜 x, inner_smul_left], simp }
lemma inner_neg_right (x y : F) : ⟪x, -y⟫ = -⟪x, y⟫ :=
by rw [←inner_conj_symm, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_symm]
lemma inner_sub_left (x y z : F) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ :=
by { simp [sub_eq_add_neg, inner_add_left, inner_neg_left] }
lemma inner_sub_right (x y z : F) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ :=
by { simp [sub_eq_add_neg, inner_add_right, inner_neg_right] }
lemma inner_mul_symm_re_eq_norm (x y : F) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ :=
by { rw [←inner_conj_symm, mul_comm], exact re_eq_norm_of_mul_conj (inner y x), }
/-- Expand `inner (x + y) (x + y)` -/
lemma inner_add_add_self (x y : F) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ :=
by simp only [inner_add_left, inner_add_right]; ring
/- Expand `inner (x - y) (x - y)` -/
lemma inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ :=
by simp only [inner_sub_left, inner_sub_right]; ring
/-- An auxiliary equality useful to prove the **Cauchy–Schwarz inequality**: the square of the norm
of `⟪x, y⟫ • x - ⟪x, x⟫ • y` is equal to `‖x‖ ^ 2 * (‖x‖ ^ 2 * ‖y‖ ^ 2 - ‖⟪x, y⟫‖ ^ 2)`. We use
`inner_product_space.of_core.norm_sq x` etc (defeq to `is_R_or_C.re ⟪x, x⟫`) instead of `‖x‖ ^ 2`
etc to avoid extra rewrites when applying it to an `inner_product_space`. -/
theorem cauchy_schwarz_aux (x y : F) :
norm_sqF (⟪x, y⟫ • x - ⟪x, x⟫ • y) =
norm_sqF x * (norm_sqF x * norm_sqF y - ‖⟪x, y⟫‖ ^ 2) :=
begin
rw [← @of_real_inj 𝕜, coe_norm_sq_eq_inner_self],
simp only [inner_sub_sub_self, inner_smul_left, inner_smul_right, conj_of_real, mul_sub,
← coe_norm_sq_eq_inner_self x, ← coe_norm_sq_eq_inner_self y],
rw [← mul_assoc, mul_conj, is_R_or_C.conj_mul, norm_sq_eq_def',
mul_left_comm, ← inner_conj_symm y, mul_conj, norm_sq_eq_def'],
push_cast,
ring
end
/--
**Cauchy–Schwarz inequality**.
We need this for the `core` structure to prove the triangle inequality below when
showing the core is a normed group.
-/
lemma inner_mul_inner_self_le (x y : F) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
begin
rcases eq_or_ne x 0 with (rfl | hx),
{ simp only [inner_zero_left, map_zero, zero_mul, norm_zero] },
{ have hx' : 0 < norm_sqF x := inner_self_nonneg.lt_of_ne' (mt norm_sq_eq_zero.1 hx),
rw [← sub_nonneg, ← mul_nonneg_iff_right_nonneg_of_pos hx', ← norm_sq, ← norm_sq,
norm_inner_symm y, ← sq, ← cauchy_schwarz_aux],
exact inner_self_nonneg }
end
/-- Norm constructed from a `inner_product_space.core` structure, defined to be the square root
of the scalar product. -/
def to_has_norm : has_norm F :=
{ norm := λ x, sqrt (re ⟪x, x⟫) }
local attribute [instance] to_has_norm
lemma norm_eq_sqrt_inner (x : F) : ‖x‖ = sqrt (re ⟪x, x⟫) := rfl
lemma inner_self_eq_norm_mul_norm (x : F) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ :=
by rw [norm_eq_sqrt_inner, ←sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
lemma sqrt_norm_sq_eq_norm (x : F) : sqrt (norm_sqF x) = ‖x‖ := rfl
/-- Cauchy–Schwarz inequality with norm -/
lemma norm_inner_le_norm (x y : F) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ :=
nonneg_le_nonneg_of_sq_le_sq (mul_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) $
calc ‖⟪x, y⟫‖ * ‖⟪x, y⟫‖ = ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ : by rw [norm_inner_symm]
... ≤ re ⟪x, x⟫ * re ⟪y, y⟫ : inner_mul_inner_self_le x y
... = ‖x‖ * ‖y‖ * (‖x‖ * ‖y‖) : by simp only [inner_self_eq_norm_mul_norm]; ring
/-- Normed group structure constructed from an `inner_product_space.core` structure -/
def to_normed_add_comm_group : normed_add_comm_group F :=
add_group_norm.to_normed_add_comm_group
{ to_fun := λ x, sqrt (re ⟪x, x⟫),
map_zero' := by simp only [sqrt_zero, inner_zero_right, map_zero],
neg' := λ x, by simp only [inner_neg_left, neg_neg, inner_neg_right],
add_le' := λ x y, begin
have h₁ : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ := norm_inner_le_norm _ _,
have h₂ : re ⟪x, y⟫ ≤ ‖⟪x, y⟫‖ := re_le_norm _,
have h₃ : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ := h₂.trans h₁,
have h₄ : re ⟪y, x⟫ ≤ ‖x‖ * ‖y‖ := by rwa [←inner_conj_symm, conj_re],
have : ‖x + y‖ * ‖x + y‖ ≤ (‖x‖ + ‖y‖) * (‖x‖ + ‖y‖),
{ simp only [←inner_self_eq_norm_mul_norm, inner_add_add_self, mul_add, mul_comm, map_add],
linarith },
exact nonneg_le_nonneg_of_sq_le_sq (add_nonneg (sqrt_nonneg _) (sqrt_nonneg _)) this,
end,
eq_zero_of_map_eq_zero' := λ x hx, norm_sq_eq_zero.1 $ (sqrt_eq_zero inner_self_nonneg).1 hx }
local attribute [instance] to_normed_add_comm_group
/-- Normed space structure constructed from a `inner_product_space.core` structure -/
def to_normed_space : normed_space 𝕜 F :=
{ norm_smul_le := assume r x,
begin
rw [norm_eq_sqrt_inner, inner_smul_left, inner_smul_right, ←mul_assoc],
rw [is_R_or_C.conj_mul, of_real_mul_re, sqrt_mul, ← coe_norm_sq_eq_inner_self, of_real_re],
{ simp [sqrt_norm_sq_eq_norm, is_R_or_C.sqrt_norm_sq_eq_norm] },
{ exact norm_sq_nonneg r }
end }
end inner_product_space.core
section
local attribute [instance] inner_product_space.core.to_normed_add_comm_group
/-- Given a `inner_product_space.core` structure on a space, one can use it to turn
the space into an inner product space. The `normed_add_comm_group` structure is expected
to already be defined with `inner_product_space.of_core.to_normed_add_comm_group`. -/
def inner_product_space.of_core [add_comm_group F] [module 𝕜 F]
(c : inner_product_space.core 𝕜 F) : inner_product_space 𝕜 F :=
begin
letI : normed_space 𝕜 F := @inner_product_space.core.to_normed_space 𝕜 F _ _ _ c,
exact { norm_sq_eq_inner := λ x,
begin
have h₁ : ‖x‖^2 = (sqrt (re (c.inner x x))) ^ 2 := rfl,
have h₂ : 0 ≤ re (c.inner x x) := inner_product_space.core.inner_self_nonneg,
simp [h₁, sq_sqrt, h₂],
end,
..c }
end
end
/-! ### Properties of inner product spaces -/
variables [normed_add_comm_group E] [inner_product_space 𝕜 E]
variables [normed_add_comm_group F] [inner_product_space ℝ F]
variables [dec_E : decidable_eq E]
local notation `⟪`x`, `y`⟫` := @inner 𝕜 _ _ x y
local notation `IK` := @is_R_or_C.I 𝕜 _
local postfix `†`:90 := star_ring_end _
export inner_product_space (norm_sq_eq_inner)
section basic_properties
@[simp] lemma inner_conj_symm (x y : E) : ⟪y, x⟫† = ⟪x, y⟫ := inner_product_space.conj_symm _ _
lemma real_inner_comm (x y : F) : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := @inner_conj_symm ℝ _ _ _ _ x y
lemma inner_eq_zero_symm {x y : E} : ⟪x, y⟫ = 0 ↔ ⟪y, x⟫ = 0 :=
by { rw [← inner_conj_symm], exact star_eq_zero }
@[simp] lemma inner_self_im (x : E) : im ⟪x, x⟫ = 0 :=
by rw [← @of_real_inj 𝕜, im_eq_conj_sub]; simp
lemma inner_add_left (x y z : E) : ⟪x + y, z⟫ = ⟪x, z⟫ + ⟪y, z⟫ :=
inner_product_space.add_left _ _ _
lemma inner_add_right (x y z : E) : ⟪x, y + z⟫ = ⟪x, y⟫ + ⟪x, z⟫ :=
by { rw [←inner_conj_symm, inner_add_left, ring_hom.map_add], simp only [inner_conj_symm] }
lemma inner_re_symm (x y : E) : re ⟪x, y⟫ = re ⟪y, x⟫ :=
by rw [←inner_conj_symm, conj_re]
lemma inner_im_symm (x y : E) : im ⟪x, y⟫ = -im ⟪y, x⟫ :=
by rw [←inner_conj_symm, conj_im]
lemma inner_smul_left (x y : E) (r : 𝕜) : ⟪r • x, y⟫ = r† * ⟪x, y⟫ :=
inner_product_space.smul_left _ _ _
lemma real_inner_smul_left (x y : F) (r : ℝ) : ⟪r • x, y⟫_ℝ = r * ⟪x, y⟫_ℝ := inner_smul_left _ _ _
lemma inner_smul_real_left (x y : E) (r : ℝ) : ⟪(r : 𝕜) • x, y⟫ = r • ⟪x, y⟫ :=
by { rw [inner_smul_left, conj_of_real, algebra.smul_def], refl }
lemma inner_smul_right (x y : E) (r : 𝕜) : ⟪x, r • y⟫ = r * ⟪x, y⟫ :=
by rw [←inner_conj_symm, inner_smul_left, ring_hom.map_mul, conj_conj, inner_conj_symm]
lemma real_inner_smul_right (x y : F) (r : ℝ) : ⟪x, r • y⟫_ℝ = r * ⟪x, y⟫_ℝ :=
inner_smul_right _ _ _
lemma inner_smul_real_right (x y : E) (r : ℝ) : ⟪x, (r : 𝕜) • y⟫ = r • ⟪x, y⟫ :=
by { rw [inner_smul_right, algebra.smul_def], refl }
/-- The inner product as a sesquilinear form.
Note that in the case `𝕜 = ℝ` this is a bilinear form. -/
@[simps]
def sesq_form_of_inner : E →ₗ[𝕜] E →ₗ⋆[𝕜] 𝕜 :=
linear_map.mk₂'ₛₗ (ring_hom.id 𝕜) (star_ring_end _)
(λ x y, ⟪y, x⟫)
(λ x y z, inner_add_right _ _ _)
(λ r x y, inner_smul_right _ _ _)
(λ x y z, inner_add_left _ _ _)
(λ r x y, inner_smul_left _ _ _)
/-- The real inner product as a bilinear form. -/
@[simps]
def bilin_form_of_real_inner : bilin_form ℝ F :=
{ bilin := inner,
bilin_add_left := inner_add_left,
bilin_smul_left := λ a x y, inner_smul_left _ _ _,
bilin_add_right := inner_add_right,
bilin_smul_right := λ a x y, inner_smul_right _ _ _ }
/-- An inner product with a sum on the left. -/
lemma sum_inner {ι : Type*} (s : finset ι) (f : ι → E) (x : E) :
⟪∑ i in s, f i, x⟫ = ∑ i in s, ⟪f i, x⟫ := (sesq_form_of_inner x).map_sum
/-- An inner product with a sum on the right. -/
lemma inner_sum {ι : Type*} (s : finset ι) (f : ι → E) (x : E) :
⟪x, ∑ i in s, f i⟫ = ∑ i in s, ⟪x, f i⟫ := (linear_map.flip sesq_form_of_inner x).map_sum
/-- An inner product with a sum on the left, `finsupp` version. -/
lemma finsupp.sum_inner {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪l.sum (λ (i : ι) (a : 𝕜), a • v i), x⟫
= l.sum (λ (i : ι) (a : 𝕜), (conj a) • ⟪v i, x⟫) :=
by { convert sum_inner l.support (λ a, l a • v a) x,
simp only [inner_smul_left, finsupp.sum, smul_eq_mul] }
/-- An inner product with a sum on the right, `finsupp` version. -/
lemma finsupp.inner_sum {ι : Type*} (l : ι →₀ 𝕜) (v : ι → E) (x : E) :
⟪x, l.sum (λ (i : ι) (a : 𝕜), a • v i)⟫ = l.sum (λ (i : ι) (a : 𝕜), a • ⟪x, v i⟫) :=
by { convert inner_sum l.support (λ a, l a • v a) x,
simp only [inner_smul_right, finsupp.sum, smul_eq_mul] }
lemma dfinsupp.sum_inner {ι : Type*} [dec : decidable_eq ι] {α : ι → Type*}
[Π i, add_zero_class (α i)] [Π i (x : α i), decidable (x ≠ 0)]
(f : Π i, α i → E) (l : Π₀ i, α i) (x : E) :
⟪l.sum f, x⟫ = l.sum (λ i a, ⟪f i a, x⟫) :=
by simp only [dfinsupp.sum, sum_inner, smul_eq_mul] {contextual := tt}
lemma dfinsupp.inner_sum {ι : Type*} [dec : decidable_eq ι] {α : ι → Type*}
[Π i, add_zero_class (α i)] [Π i (x : α i), decidable (x ≠ 0)]
(f : Π i, α i → E) (l : Π₀ i, α i) (x : E) :
⟪x, l.sum f⟫ = l.sum (λ i a, ⟪x, f i a⟫) :=
by simp only [dfinsupp.sum, inner_sum, smul_eq_mul] {contextual := tt}
@[simp] lemma inner_zero_left (x : E) : ⟪0, x⟫ = 0 :=
by rw [← zero_smul 𝕜 (0:E), inner_smul_left, ring_hom.map_zero, zero_mul]
lemma inner_re_zero_left (x : E) : re ⟪0, x⟫ = 0 :=
by simp only [inner_zero_left, add_monoid_hom.map_zero]
@[simp] lemma inner_zero_right (x : E) : ⟪x, 0⟫ = 0 :=
by rw [←inner_conj_symm, inner_zero_left, ring_hom.map_zero]
lemma inner_re_zero_right (x : E) : re ⟪x, 0⟫ = 0 :=
by simp only [inner_zero_right, add_monoid_hom.map_zero]
lemma inner_self_nonneg {x : E} : 0 ≤ re ⟪x, x⟫ :=
inner_product_space.to_core.nonneg_re x
lemma real_inner_self_nonneg {x : F} : 0 ≤ ⟪x, x⟫_ℝ := @inner_self_nonneg ℝ F _ _ _ x
@[simp] lemma inner_self_re_to_K (x : E) : (re ⟪x, x⟫ : 𝕜) = ⟪x, x⟫ :=
((is_R_or_C.is_real_tfae (⟪x, x⟫ : 𝕜)).out 2 3).2 (inner_self_im _)
lemma inner_self_eq_norm_sq_to_K (x : E) : ⟪x, x⟫ = (‖x‖ ^ 2 : 𝕜) :=
by rw [← inner_self_re_to_K, ← norm_sq_eq_inner, of_real_pow]
lemma inner_self_re_eq_norm (x : E) : re ⟪x, x⟫ = ‖⟪x, x⟫‖ :=
begin
conv_rhs { rw [←inner_self_re_to_K] },
symmetry,
exact norm_of_nonneg inner_self_nonneg,
end
lemma inner_self_norm_to_K (x : E) : (‖⟪x, x⟫‖ : 𝕜) = ⟪x, x⟫ :=
by { rw [←inner_self_re_eq_norm], exact inner_self_re_to_K _ }
lemma real_inner_self_abs (x : F) : |⟪x, x⟫_ℝ| = ⟪x, x⟫_ℝ :=
@inner_self_norm_to_K ℝ F _ _ _ x
@[simp] lemma inner_self_eq_zero {x : E} : ⟪x, x⟫ = 0 ↔ x = 0 :=
by rw [inner_self_eq_norm_sq_to_K, sq_eq_zero_iff, of_real_eq_zero, norm_eq_zero]
lemma inner_self_ne_zero {x : E} : ⟪x, x⟫ ≠ 0 ↔ x ≠ 0 :=
inner_self_eq_zero.not
@[simp] lemma inner_self_nonpos {x : E} : re ⟪x, x⟫ ≤ 0 ↔ x = 0 :=
by rw [← norm_sq_eq_inner, (sq_nonneg _).le_iff_eq, sq_eq_zero_iff, norm_eq_zero]
lemma real_inner_self_nonpos {x : F} : ⟪x, x⟫_ℝ ≤ 0 ↔ x = 0 :=
@inner_self_nonpos ℝ F _ _ _ x
lemma norm_inner_symm (x y : E) : ‖⟪x, y⟫‖ = ‖⟪y, x⟫‖ :=
by rw [←inner_conj_symm, norm_conj]
@[simp] lemma inner_neg_left (x y : E) : ⟪-x, y⟫ = -⟪x, y⟫ :=
by { rw [← neg_one_smul 𝕜 x, inner_smul_left], simp }
@[simp] lemma inner_neg_right (x y : E) : ⟪x, -y⟫ = -⟪x, y⟫ :=
by rw [←inner_conj_symm, inner_neg_left]; simp only [ring_hom.map_neg, inner_conj_symm]
lemma inner_neg_neg (x y : E) : ⟪-x, -y⟫ = ⟪x, y⟫ := by simp
@[simp] lemma inner_self_conj (x : E) : ⟪x, x⟫† = ⟪x, x⟫ :=
by rw [is_R_or_C.ext_iff]; exact ⟨by rw [conj_re], by rw [conj_im, inner_self_im, neg_zero]⟩
lemma inner_sub_left (x y z : E) : ⟪x - y, z⟫ = ⟪x, z⟫ - ⟪y, z⟫ :=
by { simp [sub_eq_add_neg, inner_add_left] }
lemma inner_sub_right (x y z : E) : ⟪x, y - z⟫ = ⟪x, y⟫ - ⟪x, z⟫ :=
by { simp [sub_eq_add_neg, inner_add_right] }
lemma inner_mul_symm_re_eq_norm (x y : E) : re (⟪x, y⟫ * ⟪y, x⟫) = ‖⟪x, y⟫ * ⟪y, x⟫‖ :=
by { rw [←inner_conj_symm, mul_comm], exact re_eq_norm_of_mul_conj (inner y x), }
/-- Expand `⟪x + y, x + y⟫` -/
lemma inner_add_add_self (x y : E) : ⟪x + y, x + y⟫ = ⟪x, x⟫ + ⟪x, y⟫ + ⟪y, x⟫ + ⟪y, y⟫ :=
by simp only [inner_add_left, inner_add_right]; ring
/-- Expand `⟪x + y, x + y⟫_ℝ` -/
lemma real_inner_add_add_self (x y : F) : ⟪x + y, x + y⟫_ℝ = ⟪x, x⟫_ℝ + 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=
begin
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [←inner_conj_symm]; refl,
simp only [inner_add_add_self, this, add_left_inj],
ring,
end
/- Expand `⟪x - y, x - y⟫` -/
lemma inner_sub_sub_self (x y : E) : ⟪x - y, x - y⟫ = ⟪x, x⟫ - ⟪x, y⟫ - ⟪y, x⟫ + ⟪y, y⟫ :=
by simp only [inner_sub_left, inner_sub_right]; ring
/-- Expand `⟪x - y, x - y⟫_ℝ` -/
lemma real_inner_sub_sub_self (x y : F) : ⟪x - y, x - y⟫_ℝ = ⟪x, x⟫_ℝ - 2 * ⟪x, y⟫_ℝ + ⟪y, y⟫_ℝ :=
begin
have : ⟪y, x⟫_ℝ = ⟪x, y⟫_ℝ := by rw [←inner_conj_symm]; refl,
simp only [inner_sub_sub_self, this, add_left_inj],
ring,
end
variable (𝕜)
include 𝕜
lemma ext_inner_left {x y : E} (h : ∀ v, ⟪v, x⟫ = ⟪v, y⟫) : x = y :=
by rw [←sub_eq_zero, ←@inner_self_eq_zero 𝕜, inner_sub_right, sub_eq_zero, h (x - y)]
lemma ext_inner_right {x y : E} (h : ∀ v, ⟪x, v⟫ = ⟪y, v⟫) : x = y :=
by rw [←sub_eq_zero, ←@inner_self_eq_zero 𝕜, inner_sub_left, sub_eq_zero, h (x - y)]
omit 𝕜
variable {𝕜}
/-- Parallelogram law -/
lemma parallelogram_law {x y : E} :
⟪x + y, x + y⟫ + ⟪x - y, x - y⟫ = 2 * (⟪x, x⟫ + ⟪y, y⟫) :=
by simp [inner_add_add_self, inner_sub_sub_self, two_mul, sub_eq_add_neg, add_comm, add_left_comm]
/-- **Cauchy–Schwarz inequality**. -/
lemma inner_mul_inner_self_le (x y : E) : ‖⟪x, y⟫‖ * ‖⟪y, x⟫‖ ≤ re ⟪x, x⟫ * re ⟪y, y⟫ :=
begin
letI c : inner_product_space.core 𝕜 E := inner_product_space.to_core,
exact inner_product_space.core.inner_mul_inner_self_le x y
end
/-- Cauchy–Schwarz inequality for real inner products. -/
lemma real_inner_mul_inner_self_le (x y : F) : ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ :=
calc ⟪x, y⟫_ℝ * ⟪x, y⟫_ℝ ≤ ‖⟪x, y⟫_ℝ‖ * ‖⟪y, x⟫_ℝ‖ :
by { rw [real_inner_comm y, ← norm_mul], exact le_abs_self _ }
... ≤ ⟪x, x⟫_ℝ * ⟪y, y⟫_ℝ : @inner_mul_inner_self_le ℝ _ _ _ _ x y
/-- A family of vectors is linearly independent if they are nonzero
and orthogonal. -/
lemma linear_independent_of_ne_zero_of_inner_eq_zero {ι : Type*} {v : ι → E}
(hz : ∀ i, v i ≠ 0) (ho : ∀ i j, i ≠ j → ⟪v i, v j⟫ = 0) : linear_independent 𝕜 v :=
begin
rw linear_independent_iff',
intros s g hg i hi,
have h' : g i * inner (v i) (v i) = inner (v i) (∑ j in s, g j • v j),
{ rw inner_sum,
symmetry,
convert finset.sum_eq_single i _ _,
{ rw inner_smul_right },
{ intros j hj hji,
rw [inner_smul_right, ho i j hji.symm, mul_zero] },
{ exact λ h, false.elim (h hi) } },
simpa [hg, hz] using h'
end
end basic_properties
section orthonormal_sets
variables {ι : Type*} [dec_ι : decidable_eq ι] (𝕜)
include 𝕜
/-- An orthonormal set of vectors in an `inner_product_space` -/
def orthonormal (v : ι → E) : Prop :=
(∀ i, ‖v i‖ = 1) ∧ (∀ {i j}, i ≠ j → ⟪v i, v j⟫ = 0)
omit 𝕜
variables {𝕜}
include dec_ι
/-- `if ... then ... else` characterization of an indexed set of vectors being orthonormal. (Inner
product equals Kronecker delta.) -/
lemma orthonormal_iff_ite {v : ι → E} :
orthonormal 𝕜 v ↔ ∀ i j, ⟪v i, v j⟫ = if i = j then (1:𝕜) else (0:𝕜) :=
begin
split,
{ intros hv i j,
split_ifs,
{ simp [h, inner_self_eq_norm_sq_to_K, hv.1] },
{ exact hv.2 h } },
{ intros h,
split,
{ intros i,
have h' : ‖v i‖ ^ 2 = 1 ^ 2 := by simp [@norm_sq_eq_inner 𝕜, h i i],
have h₁ : 0 ≤ ‖v i‖ := norm_nonneg _,
have h₂ : (0:ℝ) ≤ 1 := zero_le_one,
rwa sq_eq_sq h₁ h₂ at h' },
{ intros i j hij,
simpa [hij] using h i j } }
end
omit dec_ι
include dec_E
/-- `if ... then ... else` characterization of a set of vectors being orthonormal. (Inner product
equals Kronecker delta.) -/
theorem orthonormal_subtype_iff_ite {s : set E} :
orthonormal 𝕜 (coe : s → E) ↔
(∀ v ∈ s, ∀ w ∈ s, ⟪v, w⟫ = if v = w then 1 else 0) :=
begin
rw orthonormal_iff_ite,
split,
{ intros h v hv w hw,
convert h ⟨v, hv⟩ ⟨w, hw⟩ using 1,
simp },
{ rintros h ⟨v, hv⟩ ⟨w, hw⟩,
convert h v hv w hw using 1,
simp }
end
omit dec_E
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_right_finsupp {v : ι → E} (hv : orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :
⟪v i, finsupp.total ι E 𝕜 v l⟫ = l i :=
by classical; simp [finsupp.total_apply, finsupp.inner_sum, orthonormal_iff_ite.mp hv]
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_right_sum
{v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) {s : finset ι} {i : ι} (hi : i ∈ s) :
⟪v i, ∑ i in s, (l i) • (v i)⟫ = l i :=
by classical; simp [inner_sum, inner_smul_right, orthonormal_iff_ite.mp hv, hi]
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_right_fintype [fintype ι]
{v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) :
⟪v i, ∑ i : ι, (l i) • (v i)⟫ = l i :=
hv.inner_right_sum l (finset.mem_univ _)
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_left_finsupp {v : ι → E} (hv : orthonormal 𝕜 v) (l : ι →₀ 𝕜) (i : ι) :
⟪finsupp.total ι E 𝕜 v l, v i⟫ = conj (l i) :=
by rw [← inner_conj_symm, hv.inner_right_finsupp]
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_left_sum
{v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) {s : finset ι} {i : ι} (hi : i ∈ s) :
⟪∑ i in s, (l i) • (v i), v i⟫ = conj (l i) :=
by classical; simp only
[sum_inner, inner_smul_left, orthonormal_iff_ite.mp hv, hi, mul_boole, finset.sum_ite_eq', if_true]
/-- The inner product of a linear combination of a set of orthonormal vectors with one of those
vectors picks out the coefficient of that vector. -/
lemma orthonormal.inner_left_fintype [fintype ι]
{v : ι → E} (hv : orthonormal 𝕜 v) (l : ι → 𝕜) (i : ι) :
⟪∑ i : ι, (l i) • (v i), v i⟫ = conj (l i) :=
hv.inner_left_sum l (finset.mem_univ _)
/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as
a sum over the first `finsupp`. -/
lemma orthonormal.inner_finsupp_eq_sum_left
{v : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :
⟪finsupp.total ι E 𝕜 v l₁, finsupp.total ι E 𝕜 v l₂⟫ = l₁.sum (λ i y, conj y * l₂ i) :=
by simp only [l₁.total_apply _, finsupp.sum_inner, hv.inner_right_finsupp, smul_eq_mul]
/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as
a sum over the second `finsupp`. -/
lemma orthonormal.inner_finsupp_eq_sum_right
{v : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι →₀ 𝕜) :
⟪finsupp.total ι E 𝕜 v l₁, finsupp.total ι E 𝕜 v l₂⟫ = l₂.sum (λ i y, conj (l₁ i) * y) :=
by simp only [l₂.total_apply _, finsupp.inner_sum, hv.inner_left_finsupp, mul_comm, smul_eq_mul]
/-- The inner product of two linear combinations of a set of orthonormal vectors, expressed as
a sum. -/
lemma orthonormal.inner_sum
{v : ι → E} (hv : orthonormal 𝕜 v) (l₁ l₂ : ι → 𝕜) (s : finset ι) :
⟪∑ i in s, l₁ i • v i, ∑ i in s, l₂ i • v i⟫ = ∑ i in s, conj (l₁ i) * l₂ i :=
begin
simp_rw [sum_inner, inner_smul_left],
refine finset.sum_congr rfl (λ i hi, _),
rw hv.inner_right_sum l₂ hi
end
/--
The double sum of weighted inner products of pairs of vectors from an orthonormal sequence is the
sum of the weights.
-/
lemma orthonormal.inner_left_right_finset {s : finset ι} {v : ι → E} (hv : orthonormal 𝕜 v)
{a : ι → ι → 𝕜} : ∑ i in s, ∑ j in s, (a i j) • ⟪v j, v i⟫ = ∑ k in s, a k k :=
by classical; simp [orthonormal_iff_ite.mp hv, finset.sum_ite_of_true]
/-- An orthonormal set is linearly independent. -/
lemma orthonormal.linear_independent {v : ι → E} (hv : orthonormal 𝕜 v) :
linear_independent 𝕜 v :=
begin
rw linear_independent_iff,
intros l hl,
ext i,
have key : ⟪v i, finsupp.total ι E 𝕜 v l⟫ = ⟪v i, 0⟫ := by rw hl,
simpa only [hv.inner_right_finsupp, inner_zero_right] using key
end
/-- A subfamily of an orthonormal family (i.e., a composition with an injective map) is an
orthonormal family. -/
lemma orthonormal.comp
{ι' : Type*} {v : ι → E} (hv : orthonormal 𝕜 v) (f : ι' → ι) (hf : function.injective f) :
orthonormal 𝕜 (v ∘ f) :=
begin
classical,
rw orthonormal_iff_ite at ⊢ hv,
intros i j,
convert hv (f i) (f j) using 1,
simp [hf.eq_iff]
end
/-- An injective family `v : ι → E` is orthonormal if and only if `coe : (range v) → E` is
orthonormal. -/
lemma orthonormal_subtype_range {v : ι → E} (hv : function.injective v) :
orthonormal 𝕜 (coe : set.range v → E) ↔ orthonormal 𝕜 v :=
begin
let f : ι ≃ set.range v := equiv.of_injective v hv,
refine ⟨λ h, h.comp f f.injective, λ h, _⟩,
rw ← equiv.self_comp_of_injective_symm hv,
exact h.comp f.symm f.symm.injective,
end
/-- If `v : ι → E` is an orthonormal family, then `coe : (range v) → E` is an orthonormal
family. -/
lemma orthonormal.to_subtype_range {v : ι → E} (hv : orthonormal 𝕜 v) :
orthonormal 𝕜 (coe : set.range v → E) :=
(orthonormal_subtype_range hv.linear_independent.injective).2 hv
/-- A linear combination of some subset of an orthonormal set is orthogonal to other members of the
set. -/
lemma orthonormal.inner_finsupp_eq_zero
{v : ι → E} (hv : orthonormal 𝕜 v) {s : set ι} {i : ι} (hi : i ∉ s) {l : ι →₀ 𝕜}
(hl : l ∈ finsupp.supported 𝕜 𝕜 s) :
⟪finsupp.total ι E 𝕜 v l, v i⟫ = 0 :=
begin
rw finsupp.mem_supported' at hl,
simp only [hv.inner_left_finsupp, hl i hi, map_zero],
end
/-- Given an orthonormal family, a second family of vectors is orthonormal if every vector equals
the corresponding vector in the original family or its negation. -/
lemma orthonormal.orthonormal_of_forall_eq_or_eq_neg {v w : ι → E} (hv : orthonormal 𝕜 v)
(hw : ∀ i, w i = v i ∨ w i = -(v i)) : orthonormal 𝕜 w :=
begin
classical,
rw orthonormal_iff_ite at *,
intros i j,
cases hw i with hi hi; cases hw j with hj hj; split_ifs with h;
simpa only [hi, hj, h, inner_neg_right, inner_neg_left,
neg_neg, eq_self_iff_true, neg_eq_zero] using hv i j
end
/- The material that follows, culminating in the existence of a maximal orthonormal subset, is
adapted from the corresponding development of the theory of linearly independents sets. See
`exists_linear_independent` in particular. -/
variables (𝕜 E)
lemma orthonormal_empty : orthonormal 𝕜 (λ x, x : (∅ : set E) → E) :=
by classical; simp [orthonormal_subtype_iff_ite]
variables {𝕜 E}
lemma orthonormal_Union_of_directed
{η : Type*} {s : η → set E} (hs : directed (⊆) s) (h : ∀ i, orthonormal 𝕜 (λ x, x : s i → E)) :
orthonormal 𝕜 (λ x, x : (⋃ i, s i) → E) :=
begin
classical,
rw orthonormal_subtype_iff_ite,
rintros x ⟨_, ⟨i, rfl⟩, hxi⟩ y ⟨_, ⟨j, rfl⟩, hyj⟩,
obtain ⟨k, hik, hjk⟩ := hs i j,
have h_orth : orthonormal 𝕜 (λ x, x : (s k) → E) := h k,
rw orthonormal_subtype_iff_ite at h_orth,
exact h_orth x (hik hxi) y (hjk hyj)
end
lemma orthonormal_sUnion_of_directed
{s : set (set E)} (hs : directed_on (⊆) s)
(h : ∀ a ∈ s, orthonormal 𝕜 (λ x, x : (a : set E) → E)) :
orthonormal 𝕜 (λ x, x : (⋃₀ s) → E) :=
by rw set.sUnion_eq_Union; exact orthonormal_Union_of_directed hs.directed_coe (by simpa using h)
/-- Given an orthonormal set `v` of vectors in `E`, there exists a maximal orthonormal set
containing it. -/
lemma exists_maximal_orthonormal {s : set E} (hs : orthonormal 𝕜 (coe : s → E)) :
∃ w ⊇ s, orthonormal 𝕜 (coe : w → E) ∧ ∀ u ⊇ w, orthonormal 𝕜 (coe : u → E) → u = w :=
begin
obtain ⟨b, bi, sb, h⟩ := zorn_subset_nonempty {b | orthonormal 𝕜 (coe : b → E)} _ _ hs,
{ refine ⟨b, sb, bi, _⟩,
exact λ u hus hu, h u hu hus },
{ refine λ c hc cc c0, ⟨⋃₀ c, _, _⟩,
{ exact orthonormal_sUnion_of_directed cc.directed_on (λ x xc, hc xc) },
{ exact λ _, set.subset_sUnion_of_mem } }
end
lemma orthonormal.ne_zero {v : ι → E} (hv : orthonormal 𝕜 v) (i : ι) : v i ≠ 0 :=
begin
have : ‖v i‖ ≠ 0,
{ rw hv.1 i,
norm_num },
simpa using this
end
open finite_dimensional
/-- A family of orthonormal vectors with the correct cardinality forms a basis. -/
def basis_of_orthonormal_of_card_eq_finrank [fintype ι] [nonempty ι] {v : ι → E}
(hv : orthonormal 𝕜 v) (card_eq : fintype.card ι = finrank 𝕜 E) :
basis ι 𝕜 E :=
basis_of_linear_independent_of_card_eq_finrank hv.linear_independent card_eq
@[simp] lemma coe_basis_of_orthonormal_of_card_eq_finrank [fintype ι] [nonempty ι] {v : ι → E}
(hv : orthonormal 𝕜 v) (card_eq : fintype.card ι = finrank 𝕜 E) :
(basis_of_orthonormal_of_card_eq_finrank hv card_eq : ι → E) = v :=
coe_basis_of_linear_independent_of_card_eq_finrank _ _
end orthonormal_sets
section norm
lemma norm_eq_sqrt_inner (x : E) : ‖x‖ = sqrt (re ⟪x, x⟫) :=
calc ‖x‖ = sqrt (‖x‖ ^ 2) : (sqrt_sq (norm_nonneg _)).symm
... = sqrt (re ⟪x, x⟫) : congr_arg _ (norm_sq_eq_inner _)
lemma norm_eq_sqrt_real_inner (x : F) : ‖x‖ = sqrt ⟪x, x⟫_ℝ :=
@norm_eq_sqrt_inner ℝ _ _ _ _ x
lemma inner_self_eq_norm_mul_norm (x : E) : re ⟪x, x⟫ = ‖x‖ * ‖x‖ :=
by rw [@norm_eq_sqrt_inner 𝕜, ←sqrt_mul inner_self_nonneg (re ⟪x, x⟫),
sqrt_mul_self inner_self_nonneg]
lemma inner_self_eq_norm_sq (x : E) : re ⟪x, x⟫ = ‖x‖^2 :=
by rw [pow_two, inner_self_eq_norm_mul_norm]
lemma real_inner_self_eq_norm_mul_norm (x : F) : ⟪x, x⟫_ℝ = ‖x‖ * ‖x‖ :=
by { have h := @inner_self_eq_norm_mul_norm ℝ F _ _ _ x, simpa using h }
lemma real_inner_self_eq_norm_sq (x : F) : ⟪x, x⟫_ℝ = ‖x‖^2 :=
by rw [pow_two, real_inner_self_eq_norm_mul_norm]
variables (𝕜)
/-- Expand the square -/
lemma norm_add_sq (x y : E) : ‖x + y‖^2 = ‖x‖^2 + 2 * (re ⟪x, y⟫) + ‖y‖^2 :=
begin
repeat {rw [sq, ←@inner_self_eq_norm_mul_norm 𝕜]},
rw [inner_add_add_self, two_mul],
simp only [add_assoc, add_left_inj, add_right_inj, add_monoid_hom.map_add],
rw [←inner_conj_symm, conj_re],
end
alias norm_add_sq ← norm_add_pow_two
/-- Expand the square -/
lemma norm_add_sq_real (x y : F) : ‖x + y‖^2 = ‖x‖^2 + 2 * ⟪x, y⟫_ℝ + ‖y‖^2 :=
by { have h := @norm_add_sq ℝ _ _ _ _ x y, simpa using h }
alias norm_add_sq_real ← norm_add_pow_two_real
/-- Expand the square -/
lemma norm_add_mul_self (x y : E) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * (re ⟪x, y⟫) + ‖y‖ * ‖y‖ :=
by { repeat {rw [← sq]}, exact norm_add_sq _ _ }
/-- Expand the square -/
lemma norm_add_mul_self_real (x y : F) : ‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ :=
by { have h := @norm_add_mul_self ℝ _ _ _ _ x y, simpa using h }
/-- Expand the square -/
lemma norm_sub_sq (x y : E) : ‖x - y‖^2 = ‖x‖^2 - 2 * (re ⟪x, y⟫) + ‖y‖^2 :=
by rw [sub_eq_add_neg, @norm_add_sq 𝕜 _ _ _ _ x (-y), norm_neg, inner_neg_right, map_neg, mul_neg,
sub_eq_add_neg]
alias norm_sub_sq ← norm_sub_pow_two
/-- Expand the square -/
lemma norm_sub_sq_real (x y : F) : ‖x - y‖^2 = ‖x‖^2 - 2 * ⟪x, y⟫_ℝ + ‖y‖^2 :=
@norm_sub_sq ℝ _ _ _ _ _ _
alias norm_sub_sq_real ← norm_sub_pow_two_real
/-- Expand the square -/
lemma norm_sub_mul_self (x y : E) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * re ⟪x, y⟫ + ‖y‖ * ‖y‖ :=
by { repeat {rw [← sq]}, exact norm_sub_sq _ _ }
/-- Expand the square -/
lemma norm_sub_mul_self_real (x y : F) : ‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ - 2 * ⟪x, y⟫_ℝ + ‖y‖ * ‖y‖ :=
by { have h := @norm_sub_mul_self ℝ _ _ _ _ x y, simpa using h }
/-- Cauchy–Schwarz inequality with norm -/
lemma norm_inner_le_norm (x y : E) : ‖⟪x, y⟫‖ ≤ ‖x‖ * ‖y‖ :=
begin
rw [norm_eq_sqrt_inner x, norm_eq_sqrt_inner y],
letI : inner_product_space.core 𝕜 E := inner_product_space.to_core,
exact inner_product_space.core.norm_inner_le_norm x y
end
lemma nnnorm_inner_le_nnnorm (x y : E) : ‖⟪x, y⟫‖₊ ≤ ‖x‖₊ * ‖y‖₊ :=
norm_inner_le_norm x y
lemma re_inner_le_norm (x y : E) : re ⟪x, y⟫ ≤ ‖x‖ * ‖y‖ :=
le_trans (re_le_norm (inner x y)) (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
lemma abs_real_inner_le_norm (x y : F) : |⟪x, y⟫_ℝ| ≤ ‖x‖ * ‖y‖ :=
(real.norm_eq_abs _).ge.trans (norm_inner_le_norm x y)
/-- Cauchy–Schwarz inequality with norm -/
lemma real_inner_le_norm (x y : F) : ⟪x, y⟫_ℝ ≤ ‖x‖ * ‖y‖ :=
le_trans (le_abs_self _) (abs_real_inner_le_norm _ _)
include 𝕜
variables (𝕜)
lemma parallelogram_law_with_norm (x y : E) :
‖x + y‖ * ‖x + y‖ + ‖x - y‖ * ‖x - y‖ = 2 * (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) :=
begin
simp only [← @inner_self_eq_norm_mul_norm 𝕜],
rw [← re.map_add, parallelogram_law, two_mul, two_mul],
simp only [re.map_add],
end
lemma parallelogram_law_with_nnnorm (x y : E) :
‖x + y‖₊ * ‖x + y‖₊ + ‖x - y‖₊ * ‖x - y‖₊ = 2 * (‖x‖₊ * ‖x‖₊ + ‖y‖₊ * ‖y‖₊) :=
subtype.ext $ parallelogram_law_with_norm 𝕜 x y
variables {𝕜}
omit 𝕜
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
lemma re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=
by { rw @norm_add_mul_self 𝕜, ring }
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
lemma re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : E) :
re ⟪x, y⟫ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=
by { rw [@norm_sub_mul_self 𝕜], ring }
/-- Polarization identity: The real part of the inner product, in terms of the norm. -/
lemma re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four (x y : E) :
re ⟪x, y⟫ = (‖x + y‖ * ‖x + y‖ - ‖x - y‖ * ‖x - y‖) / 4 :=
by { rw [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜], ring }
/-- Polarization identity: The imaginary part of the inner product, in terms of the norm. -/
lemma im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four (x y : E) :
im ⟪x, y⟫ = (‖x - IK • y‖ * ‖x - IK • y‖ - ‖x + IK • y‖ * ‖x + IK • y‖) / 4 :=
by { simp only [@norm_add_mul_self 𝕜, @norm_sub_mul_self 𝕜, inner_smul_right, I_mul_re], ring }
/-- Polarization identity: The inner product, in terms of the norm. -/
lemma inner_eq_sum_norm_sq_div_four (x y : E) :
⟪x, y⟫ = (‖x + y‖ ^ 2 - ‖x - y‖ ^ 2 + (‖x - IK • y‖ ^ 2 - ‖x + IK • y‖ ^ 2) * IK) / 4 :=
begin
rw [← re_add_im ⟪x, y⟫, re_inner_eq_norm_add_mul_self_sub_norm_sub_mul_self_div_four,
im_inner_eq_norm_sub_I_smul_mul_self_sub_norm_add_I_smul_mul_self_div_four],
push_cast,
simp only [sq, ← mul_div_right_comm, ← add_div]
end
/-- Formula for the distance between the images of two nonzero points under an inversion with center
zero. See also `euclidean_geometry.dist_inversion_inversion` for inversions around a general
point. -/
lemma dist_div_norm_sq_smul {x y : F} (hx : x ≠ 0) (hy : y ≠ 0) (R : ℝ) :
dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y) = (R ^ 2 / (‖x‖ * ‖y‖)) * dist x y :=
have hx' : ‖x‖ ≠ 0, from norm_ne_zero_iff.2 hx,
have hy' : ‖y‖ ≠ 0, from norm_ne_zero_iff.2 hy,
calc dist ((R / ‖x‖) ^ 2 • x) ((R / ‖y‖) ^ 2 • y)
= sqrt (‖(R / ‖x‖) ^ 2 • x - (R / ‖y‖) ^ 2 • y‖^2) :
by rw [dist_eq_norm, sqrt_sq (norm_nonneg _)]
... = sqrt ((R ^ 2 / (‖x‖ * ‖y‖)) ^ 2 * ‖x - y‖ ^ 2) :
congr_arg sqrt $ by { field_simp [sq, norm_sub_mul_self_real, norm_smul, real_inner_smul_left,
inner_smul_right, real.norm_of_nonneg (mul_self_nonneg _)], ring }
... = (R ^ 2 / (‖x‖ * ‖y‖)) * dist x y :
by rw [sqrt_mul (sq_nonneg _), sqrt_sq (norm_nonneg _),
sqrt_sq (div_nonneg (sq_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _))), dist_eq_norm]
@[priority 100] -- See note [lower instance priority]
instance inner_product_space.to_uniform_convex_space : uniform_convex_space F :=
⟨λ ε hε, begin
refine ⟨2 - sqrt (4 - ε^2), sub_pos_of_lt $ (sqrt_lt' zero_lt_two).2 _, λ x hx y hy hxy, _⟩,
{ norm_num,
exact pow_pos hε _ },
rw sub_sub_cancel,
refine le_sqrt_of_sq_le _,
rw [sq, eq_sub_iff_add_eq.2 (parallelogram_law_with_norm ℝ x y), ←sq (‖x - y‖), hx, hy],
norm_num,
exact pow_le_pow_of_le_left hε.le hxy _,
end⟩
section complex
variables {V : Type*} [normed_add_comm_group V] [inner_product_space ℂ V]
/--
A complex polarization identity, with a linear map
-/
lemma inner_map_polarization (T : V →ₗ[ℂ] V) (x y : V):
⟪ T y, x ⟫_ℂ = (⟪T (x + y) , x + y⟫_ℂ - ⟪T (x - y) , x - y⟫_ℂ +
complex.I * ⟪T (x + complex.I • y) , x + complex.I • y⟫_ℂ -
complex.I * ⟪T (x - complex.I • y), x - complex.I • y ⟫_ℂ) / 4 :=
begin
simp only [map_add, map_sub, inner_add_left, inner_add_right, linear_map.map_smul,
inner_smul_left, inner_smul_right, complex.conj_I, ←pow_two, complex.I_sq,
inner_sub_left, inner_sub_right, mul_add, ←mul_assoc, mul_neg, neg_neg,
sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub],
ring,
end
lemma inner_map_polarization' (T : V →ₗ[ℂ] V) (x y : V):
⟪ T x, y ⟫_ℂ = (⟪T (x + y) , x + y⟫_ℂ - ⟪T (x - y) , x - y⟫_ℂ -
complex.I * ⟪T (x + complex.I • y) , x + complex.I • y⟫_ℂ +
complex.I * ⟪T (x - complex.I • y), x - complex.I • y ⟫_ℂ) / 4 :=
begin
simp only [map_add, map_sub, inner_add_left, inner_add_right, linear_map.map_smul,
inner_smul_left, inner_smul_right, complex.conj_I, ←pow_two, complex.I_sq,
inner_sub_left, inner_sub_right, mul_add, ←mul_assoc, mul_neg, neg_neg,
sub_neg_eq_add, one_mul, neg_one_mul, mul_sub, sub_sub],
ring,
end
/--
A linear map `T` is zero, if and only if the identity `⟪T x, x⟫_ℂ = 0` holds for all `x`.
-/
lemma inner_map_self_eq_zero (T : V →ₗ[ℂ] V) :
(∀ (x : V), ⟪T x, x⟫_ℂ = 0) ↔ T = 0 :=
begin
split,
{ intro hT,
ext x,
simp only [linear_map.zero_apply, ← @inner_self_eq_zero ℂ, inner_map_polarization, hT],
norm_num },
{ rintro rfl x,
simp only [linear_map.zero_apply, inner_zero_left] }
end
/--
Two linear maps `S` and `T` are equal, if and only if the identity `⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ` holds
for all `x`.
-/
lemma ext_inner_map (S T : V →ₗ[ℂ] V) :
(∀ (x : V), ⟪S x, x⟫_ℂ = ⟪T x, x⟫_ℂ) ↔ S = T :=
begin
rw [←sub_eq_zero, ←inner_map_self_eq_zero],
refine forall_congr (λ x, _),
rw [linear_map.sub_apply, inner_sub_left, sub_eq_zero],
end
end complex
section
variables {ι : Type*} {ι' : Type*} {ι'' : Type*}
variables {E' : Type*} [normed_add_comm_group E'] [inner_product_space 𝕜 E']
variables {E'' : Type*} [normed_add_comm_group E''] [inner_product_space 𝕜 E'']
/-- A linear isometry preserves the inner product. -/
@[simp] lemma linear_isometry.inner_map_map (f : E →ₗᵢ[𝕜] E') (x y : E) : ⟪f x, f y⟫ = ⟪x, y⟫ :=
by simp [inner_eq_sum_norm_sq_div_four, ← f.norm_map]
/-- A linear isometric equivalence preserves the inner product. -/
@[simp] lemma linear_isometry_equiv.inner_map_map (f : E ≃ₗᵢ[𝕜] E') (x y : E) :
⟪f x, f y⟫ = ⟪x, y⟫ :=
f.to_linear_isometry.inner_map_map x y
/-- A linear map that preserves the inner product is a linear isometry. -/
def linear_map.isometry_of_inner (f : E →ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) : E →ₗᵢ[𝕜] E' :=
⟨f, λ x, by simp only [@norm_eq_sqrt_inner 𝕜, h]⟩
@[simp] lemma linear_map.coe_isometry_of_inner (f : E →ₗ[𝕜] E') (h) :
⇑(f.isometry_of_inner h) = f := rfl
@[simp] lemma linear_map.isometry_of_inner_to_linear_map (f : E →ₗ[𝕜] E') (h) :
(f.isometry_of_inner h).to_linear_map = f := rfl
/-- A linear equivalence that preserves the inner product is a linear isometric equivalence. -/
def linear_equiv.isometry_of_inner (f : E ≃ₗ[𝕜] E') (h : ∀ x y, ⟪f x, f y⟫ = ⟪x, y⟫) :
E ≃ₗᵢ[𝕜] E' :=
⟨f, ((f : E →ₗ[𝕜] E').isometry_of_inner h).norm_map⟩
@[simp] lemma linear_equiv.coe_isometry_of_inner (f : E ≃ₗ[𝕜] E') (h) :
⇑(f.isometry_of_inner h) = f := rfl
@[simp] lemma linear_equiv.isometry_of_inner_to_linear_equiv (f : E ≃ₗ[𝕜] E') (h) :
(f.isometry_of_inner h).to_linear_equiv = f := rfl
/-- A linear isometry preserves the property of being orthonormal. -/
lemma linear_isometry.orthonormal_comp_iff {v : ι → E} (f : E →ₗᵢ[𝕜] E') :
orthonormal 𝕜 (f ∘ v) ↔ orthonormal 𝕜 v :=
begin
classical,
simp_rw [orthonormal_iff_ite, linear_isometry.inner_map_map]
end
/-- A linear isometry preserves the property of being orthonormal. -/
lemma orthonormal.comp_linear_isometry {v : ι → E} (hv : orthonormal 𝕜 v) (f : E →ₗᵢ[𝕜] E') :
orthonormal 𝕜 (f ∘ v) :=
by rwa f.orthonormal_comp_iff
/-- A linear isometric equivalence preserves the property of being orthonormal. -/
lemma orthonormal.comp_linear_isometry_equiv {v : ι → E} (hv : orthonormal 𝕜 v) (f : E ≃ₗᵢ[𝕜] E') :
orthonormal 𝕜 (f ∘ v) :=
hv.comp_linear_isometry f.to_linear_isometry
/-- A linear isometric equivalence, applied with `basis.map`, preserves the property of being
orthonormal. -/
lemma orthonormal.map_linear_isometry_equiv {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)
(f : E ≃ₗᵢ[𝕜] E') : orthonormal 𝕜 (v.map f.to_linear_equiv) :=
hv.comp_linear_isometry_equiv f
/-- A linear map that sends an orthonormal basis to orthonormal vectors is a linear isometry. -/
def linear_map.isometry_of_orthonormal (f : E →ₗ[𝕜] E') {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)
(hf : orthonormal 𝕜 (f ∘ v)) : E →ₗᵢ[𝕜] E' :=
f.isometry_of_inner $ λ x y, by rw [←v.total_repr x, ←v.total_repr y, finsupp.apply_total,
finsupp.apply_total, hv.inner_finsupp_eq_sum_left,
hf.inner_finsupp_eq_sum_left]
@[simp] lemma linear_map.coe_isometry_of_orthonormal (f : E →ₗ[𝕜] E') {v : basis ι 𝕜 E}
(hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :
⇑(f.isometry_of_orthonormal hv hf) = f :=
rfl
@[simp] lemma linear_map.isometry_of_orthonormal_to_linear_map (f : E →ₗ[𝕜] E') {v : basis ι 𝕜 E}
(hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :
(f.isometry_of_orthonormal hv hf).to_linear_map = f :=
rfl
/-- A linear equivalence that sends an orthonormal basis to orthonormal vectors is a linear
isometric equivalence. -/
def linear_equiv.isometry_of_orthonormal (f : E ≃ₗ[𝕜] E') {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)
(hf : orthonormal 𝕜 (f ∘ v)) : E ≃ₗᵢ[𝕜] E' :=
f.isometry_of_inner $ λ x y, begin
rw ←linear_equiv.coe_coe at hf,
rw [←v.total_repr x, ←v.total_repr y, ←linear_equiv.coe_coe, finsupp.apply_total,
finsupp.apply_total, hv.inner_finsupp_eq_sum_left, hf.inner_finsupp_eq_sum_left]
end
@[simp] lemma linear_equiv.coe_isometry_of_orthonormal (f : E ≃ₗ[𝕜] E') {v : basis ι 𝕜 E}
(hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :
⇑(f.isometry_of_orthonormal hv hf) = f :=
rfl
@[simp] lemma linear_equiv.isometry_of_orthonormal_to_linear_equiv (f : E ≃ₗ[𝕜] E')
{v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) (hf : orthonormal 𝕜 (f ∘ v)) :
(f.isometry_of_orthonormal hv hf).to_linear_equiv = f :=
rfl
/-- A linear isometric equivalence that sends an orthonormal basis to a given orthonormal basis. -/
def orthonormal.equiv {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}
(hv' : orthonormal 𝕜 v') (e : ι ≃ ι') : E ≃ₗᵢ[𝕜] E' :=
(v.equiv v' e).isometry_of_orthonormal hv begin
have h : (v.equiv v' e) ∘ v = v' ∘ e,
{ ext i,
simp },
rw h,
exact hv'.comp _ e.injective
end
@[simp] lemma orthonormal.equiv_to_linear_equiv {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)
{v' : basis ι' 𝕜 E'} (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') :
(hv.equiv hv' e).to_linear_equiv = v.equiv v' e :=
rfl
@[simp] lemma orthonormal.equiv_apply {ι' : Type*} {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v)
{v' : basis ι' 𝕜 E'} (hv' : orthonormal 𝕜 v') (e : ι ≃ ι') (i : ι) :
hv.equiv hv' e (v i) = v' (e i) :=
basis.equiv_apply _ _ _ _
@[simp] lemma orthonormal.equiv_refl {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) :
hv.equiv hv (equiv.refl ι) = linear_isometry_equiv.refl 𝕜 E :=
v.ext_linear_isometry_equiv $ λ i,
by simp only [orthonormal.equiv_apply, equiv.coe_refl, id.def, linear_isometry_equiv.coe_refl]
@[simp] lemma orthonormal.equiv_symm {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}
(hv' : orthonormal 𝕜 v') (e : ι ≃ ι') : (hv.equiv hv' e).symm = hv'.equiv hv e.symm :=
v'.ext_linear_isometry_equiv $ λ i, (hv.equiv hv' e).injective $
by simp only [linear_isometry_equiv.apply_symm_apply, orthonormal.equiv_apply, e.apply_symm_apply]
@[simp] lemma orthonormal.equiv_trans {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}
(hv' : orthonormal 𝕜 v') (e : ι ≃ ι') {v'' : basis ι'' 𝕜 E''} (hv'' : orthonormal 𝕜 v'')
(e' : ι' ≃ ι'') : (hv.equiv hv' e).trans (hv'.equiv hv'' e') = hv.equiv hv'' (e.trans e') :=
v.ext_linear_isometry_equiv $ λ i,
by simp only [linear_isometry_equiv.trans_apply, orthonormal.equiv_apply, e.coe_trans]
lemma orthonormal.map_equiv {v : basis ι 𝕜 E} (hv : orthonormal 𝕜 v) {v' : basis ι' 𝕜 E'}
(hv' : orthonormal 𝕜 v') (e : ι ≃ ι') :
v.map ((hv.equiv hv' e).to_linear_equiv) = v'.reindex e.symm :=
v.map_equiv _ _
end
/-- Polarization identity: The real inner product, in terms of the norm. -/
lemma real_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x + y‖ * ‖x + y‖ - ‖x‖ * ‖x‖ - ‖y‖ * ‖y‖) / 2 :=
re_to_real.symm.trans $
re_inner_eq_norm_add_mul_self_sub_norm_mul_self_sub_norm_mul_self_div_two x y
/-- Polarization identity: The real inner product, in terms of the norm. -/
lemma real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two (x y : F) :
⟪x, y⟫_ℝ = (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ - ‖x - y‖ * ‖x - y‖) / 2 :=
re_to_real.symm.trans $
re_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two x y
/-- Pythagorean theorem, if-and-only-if vector inner product form. -/
lemma norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 :=
begin
rw [@norm_add_mul_self ℝ, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],
norm_num
end
/-- Pythagorean theorem, if-and-if vector inner product form using square roots. -/
lemma norm_add_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x + y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 :=
by rw [←norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm,
sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)]
/-- Pythagorean theorem, vector inner product form. -/
lemma norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x y : E) (h : ⟪x, y⟫ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
begin
rw [@norm_add_mul_self 𝕜, add_right_cancel_iff, add_right_eq_self, mul_eq_zero],
apply or.inr,
simp only [h, zero_re'],
end
/-- Pythagorean theorem, vector inner product form. -/
lemma norm_add_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x + y‖ * ‖x + y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_add_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- Pythagorean theorem, subtracting vectors, if-and-only-if vector
inner product form. -/
lemma norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero (x y : F) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ ↔ ⟪x, y⟫_ℝ = 0 :=
begin
rw [@norm_sub_mul_self ℝ, add_right_cancel_iff, sub_eq_add_neg, add_right_eq_self, neg_eq_zero,
mul_eq_zero],
norm_num
end
/-- Pythagorean theorem, subtracting vectors, if-and-if vector inner product form using square
roots. -/
lemma norm_sub_eq_sqrt_iff_real_inner_eq_zero {x y : F} :
‖x - y‖ = sqrt (‖x‖ * ‖x‖ + ‖y‖ * ‖y‖) ↔ ⟪x, y⟫_ℝ = 0 :=
by rw [←norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero, eq_comm,
sqrt_eq_iff_mul_self_eq (add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)) (norm_nonneg _)]
/-- Pythagorean theorem, subtracting vectors, vector inner product
form. -/
lemma norm_sub_sq_eq_norm_sq_add_norm_sq_real {x y : F} (h : ⟪x, y⟫_ℝ = 0) :
‖x - y‖ * ‖x - y‖ = ‖x‖ * ‖x‖ + ‖y‖ * ‖y‖ :=
(norm_sub_sq_eq_norm_sq_add_norm_sq_iff_real_inner_eq_zero x y).2 h
/-- The sum and difference of two vectors are orthogonal if and only
if they have the same norm. -/
lemma real_inner_add_sub_eq_zero_iff (x y : F) : ⟪x + y, x - y⟫_ℝ = 0 ↔ ‖x‖ = ‖y‖ :=
begin
conv_rhs { rw ←mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _) },
simp only [←@inner_self_eq_norm_mul_norm ℝ, inner_add_left, inner_sub_right,
real_inner_comm y x, sub_eq_zero, re_to_real],
split,
{ intro h,
rw [add_comm] at h,
linarith },
{ intro h,
linarith }
end
/-- Given two orthogonal vectors, their sum and difference have equal norms. -/
lemma norm_sub_eq_norm_add {v w : E} (h : ⟪v, w⟫ = 0) : ‖w - v‖ = ‖w + v‖ :=
begin
rw ←mul_self_inj_of_nonneg (norm_nonneg _) (norm_nonneg _),
simp only [h, ←@inner_self_eq_norm_mul_norm 𝕜, sub_neg_eq_add, sub_zero, map_sub, zero_re',
zero_sub,
add_zero, map_add, inner_add_right, inner_sub_left, inner_sub_right, inner_re_symm, zero_add]
end
/-- The real inner product of two vectors, divided by the product of their
norms, has absolute value at most 1. -/
lemma abs_real_inner_div_norm_mul_norm_le_one (x y : F) : |⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| ≤ 1 :=
begin
rw [abs_div, abs_mul, abs_norm, abs_norm],
exact div_le_one_of_le (abs_real_inner_le_norm x y) (by positivity)
end
/-- The inner product of a vector with a multiple of itself. -/
lemma real_inner_smul_self_left (x : F) (r : ℝ) : ⟪r • x, x⟫_ℝ = r * (‖x‖ * ‖x‖) :=
by rw [real_inner_smul_left, ←real_inner_self_eq_norm_mul_norm]
/-- The inner product of a vector with a multiple of itself. -/
lemma real_inner_smul_self_right (x : F) (r : ℝ) : ⟪x, r • x⟫_ℝ = r * (‖x‖ * ‖x‖) :=
by rw [inner_smul_right, ←real_inner_self_eq_norm_mul_norm]
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
lemma norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul
{x : E} {r : 𝕜} (hx : x ≠ 0) (hr : r ≠ 0) : ‖⟪x, r • x⟫‖ / (‖x‖ * ‖r • x‖) = 1 :=
begin
have hx' : ‖x‖ ≠ 0 := by simp [hx],
have hr' : ‖r‖ ≠ 0 := by simp [hr],
rw [inner_smul_right, norm_mul, ← inner_self_re_eq_norm, inner_self_eq_norm_mul_norm, norm_smul],
rw [← mul_assoc, ← div_div, mul_div_cancel _ hx',
← div_div, mul_comm, mul_div_cancel _ hr', div_self hx'],
end
/-- The inner product of a nonzero vector with a nonzero multiple of
itself, divided by the product of their norms, has absolute value
1. -/
lemma abs_real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul
{x : F} {r : ℝ} (hx : x ≠ 0) (hr : r ≠ 0) : |⟪x, r • x⟫_ℝ| / (‖x‖ * ‖r • x‖) = 1 :=
norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr
/-- The inner product of a nonzero vector with a positive multiple of
itself, divided by the product of their norms, has value 1. -/
lemma real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul
{x : F} {r : ℝ} (hx : x ≠ 0) (hr : 0 < r) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = 1 :=
begin
rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ‖x‖, mul_comm _ (|r|),
mul_assoc, abs_of_nonneg hr.le, div_self],
exact mul_ne_zero hr.ne' (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
end
/-- The inner product of a nonzero vector with a negative multiple of
itself, divided by the product of their norms, has value -1. -/
lemma real_inner_div_norm_mul_norm_eq_neg_one_of_ne_zero_of_neg_mul
{x : F} {r : ℝ} (hx : x ≠ 0) (hr : r < 0) : ⟪x, r • x⟫_ℝ / (‖x‖ * ‖r • x‖) = -1 :=
begin
rw [real_inner_smul_self_right, norm_smul, real.norm_eq_abs, ←mul_assoc ‖x‖, mul_comm _ (|r|),
mul_assoc, abs_of_neg hr, neg_mul, div_neg_eq_neg_div, div_self],
exact mul_ne_zero hr.ne (mul_self_ne_zero.2 (norm_ne_zero_iff.2 hx))
end
lemma norm_inner_eq_norm_tfae (x y : E) :
tfae [‖⟪x, y⟫‖ = ‖x‖ * ‖y‖,
x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫) • x,
x = 0 ∨ ∃ r : 𝕜, y = r • x,
x = 0 ∨ y ∈ 𝕜 ∙ x] :=
begin
tfae_have : 1 → 2,
{ refine λ h, or_iff_not_imp_left.2 (λ hx₀, _),
have : ‖x‖ ^ 2 ≠ 0 := pow_ne_zero _ (norm_ne_zero_iff.2 hx₀),
rw [← sq_eq_sq (norm_nonneg _) (mul_nonneg (norm_nonneg _) (norm_nonneg _)),
mul_pow, ← mul_right_inj' this, eq_comm, ← sub_eq_zero, ← mul_sub] at h,
simp only [@norm_sq_eq_inner 𝕜] at h,
letI : inner_product_space.core 𝕜 E := inner_product_space.to_core,
erw [← inner_product_space.core.cauchy_schwarz_aux,
inner_product_space.core.norm_sq_eq_zero, sub_eq_zero] at h,
rw [div_eq_inv_mul, mul_smul, h, inv_smul_smul₀],
rwa [inner_self_ne_zero] },
tfae_have : 2 → 3, from λ h, h.imp_right (λ h', ⟨_, h'⟩),
tfae_have : 3 → 1,
{ rintro (rfl | ⟨r, rfl⟩); simp [inner_smul_right, norm_smul, inner_self_eq_norm_sq_to_K,
inner_self_eq_norm_mul_norm, sq, mul_left_comm] },
tfae_have : 3 ↔ 4, by simp only [submodule.mem_span_singleton, eq_comm],
tfae_finish
end
/--
If the inner product of two vectors is equal to the product of their norms, then the two vectors
are multiples of each other. One form of the equality case for Cauchy-Schwarz.
Compare `inner_eq_norm_mul_iff`, which takes the stronger hypothesis `⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
lemma norm_inner_eq_norm_iff {x y : E} (hx₀ : x ≠ 0) (hy₀ : y ≠ 0) :
‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ ∃ (r : 𝕜), r ≠ 0 ∧ y = r • x :=
calc ‖⟪x, y⟫‖ = ‖x‖ * ‖y‖ ↔ x = 0 ∨ ∃ r : 𝕜, y = r • x :
(@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 2
... ↔ ∃ r : 𝕜, y = r • x : or_iff_right hx₀
... ↔ ∃ r : 𝕜, r ≠ 0 ∧ y = r • x :
⟨λ ⟨r, h⟩, ⟨r, λ hr₀, hy₀ $ h.symm ▸ smul_eq_zero.2 $ or.inl hr₀, h⟩, λ ⟨r, hr₀, h⟩, ⟨r, h⟩⟩
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
lemma norm_inner_div_norm_mul_norm_eq_one_iff (x y : E) :
‖(⟪x, y⟫ / (‖x‖ * ‖y‖))‖ = 1 ↔ (x ≠ 0 ∧ ∃ (r : 𝕜), r ≠ 0 ∧ y = r • x) :=
begin
split,
{ intro h,
have hx₀ : x ≠ 0 := λ h₀, by simpa [h₀] using h,
have hy₀ : y ≠ 0 := λ h₀, by simpa [h₀] using h,
refine ⟨hx₀, (norm_inner_eq_norm_iff hx₀ hy₀).1 $ eq_of_div_eq_one _⟩,
simpa using h },
{ rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩,
simp only [norm_div, norm_mul, norm_of_real, abs_norm],
exact norm_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_ne_zero_mul hx hr }
end
/-- The inner product of two vectors, divided by the product of their
norms, has absolute value 1 if and only if they are nonzero and one is
a multiple of the other. One form of equality case for Cauchy-Schwarz. -/
lemma abs_real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
|⟪x, y⟫_ℝ / (‖x‖ * ‖y‖)| = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r ≠ 0 ∧ y = r • x) :=
@norm_inner_div_norm_mul_norm_eq_one_iff ℝ F _ _ _ x y
lemma inner_eq_norm_mul_iff_div {x y : E} (h₀ : x ≠ 0) :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ / ‖x‖ : 𝕜) • x = y :=
begin
have h₀' := h₀,
rw [← norm_ne_zero_iff, ne.def, ← @of_real_eq_zero 𝕜] at h₀',
split; intro h,
{ have : x = 0 ∨ y = (⟪x, y⟫ / ⟪x, x⟫ : 𝕜) • x :=
((@norm_inner_eq_norm_tfae 𝕜 _ _ _ _ x y).out 0 1).1 (by simp [h]),
rw [this.resolve_left h₀, h],
simp [norm_smul, inner_self_norm_to_K, h₀'] },
{ conv_lhs { rw [← h, inner_smul_right, inner_self_eq_norm_sq_to_K] },
field_simp [sq, mul_left_comm] }
end
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
lemma inner_eq_norm_mul_iff {x y : E} :
⟪x, y⟫ = (‖x‖ : 𝕜) * ‖y‖ ↔ (‖y‖ : 𝕜) • x = (‖x‖ : 𝕜) • y :=
begin
rcases eq_or_ne x 0 with (rfl | h₀),
{ simp },
{ rw [inner_eq_norm_mul_iff_div h₀, div_eq_inv_mul, mul_smul, inv_smul_eq_iff₀],
rwa [ne.def, of_real_eq_zero, norm_eq_zero] },
end
/-- If the inner product of two vectors is equal to the product of their norms (i.e.,
`⟪x, y⟫ = ‖x‖ * ‖y‖`), then the two vectors are nonnegative real multiples of each other. One form
of the equality case for Cauchy-Schwarz.
Compare `norm_inner_eq_norm_iff`, which takes the weaker hypothesis `abs ⟪x, y⟫ = ‖x‖ * ‖y‖`. -/
lemma inner_eq_norm_mul_iff_real {x y : F} : ⟪x, y⟫_ℝ = ‖x‖ * ‖y‖ ↔ ‖y‖ • x = ‖x‖ • y :=
inner_eq_norm_mul_iff
/-- The inner product of two vectors, divided by the product of their
norms, has value 1 if and only if they are nonzero and one is
a positive multiple of the other. -/
lemma real_inner_div_norm_mul_norm_eq_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = 1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), 0 < r ∧ y = r • x) :=
begin
split,
{ intro h,
have hx₀ : x ≠ 0 := λ h₀, by simpa [h₀] using h,
have hy₀ : y ≠ 0 := λ h₀, by simpa [h₀] using h,
refine ⟨hx₀, ‖y‖ / ‖x‖, div_pos (norm_pos_iff.2 hy₀) (norm_pos_iff.2 hx₀), _⟩,
exact ((inner_eq_norm_mul_iff_div hx₀).1 (eq_of_div_eq_one h)).symm },
{ rintro ⟨hx, ⟨r, ⟨hr, rfl⟩⟩⟩,
exact real_inner_div_norm_mul_norm_eq_one_of_ne_zero_of_pos_mul hx hr }
end
/-- The inner product of two vectors, divided by the product of their
norms, has value -1 if and only if they are nonzero and one is
a negative multiple of the other. -/
lemma real_inner_div_norm_mul_norm_eq_neg_one_iff (x y : F) :
⟪x, y⟫_ℝ / (‖x‖ * ‖y‖) = -1 ↔ (x ≠ 0 ∧ ∃ (r : ℝ), r < 0 ∧ y = r • x) :=
begin
rw [← neg_eq_iff_eq_neg, ← neg_div, ← inner_neg_right, ← norm_neg y,
real_inner_div_norm_mul_norm_eq_one_iff, (@neg_surjective ℝ _).exists],
refine iff.rfl.and (exists_congr $ λ r, _),
rw [neg_pos, neg_smul, neg_inj]
end
/-- If the inner product of two unit vectors is `1`, then the two vectors are equal. One form of
the equality case for Cauchy-Schwarz. -/
lemma inner_eq_one_iff_of_norm_one {x y : E} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫ = 1 ↔ x = y :=
by { convert inner_eq_norm_mul_iff using 2; simp [hx, hy] }
lemma inner_lt_norm_mul_iff_real {x y : F} :
⟪x, y⟫_ℝ < ‖x‖ * ‖y‖ ↔ ‖y‖ • x ≠ ‖x‖ • y :=
calc ⟪x, y⟫_ℝ < ‖x‖ * ‖y‖
↔ ⟪x, y⟫_ℝ ≠ ‖x‖ * ‖y‖ : ⟨ne_of_lt, lt_of_le_of_ne (real_inner_le_norm _ _)⟩
... ↔ ‖y‖ • x ≠ ‖x‖ • y : not_congr inner_eq_norm_mul_iff_real
/-- If the inner product of two unit vectors is strictly less than `1`, then the two vectors are
distinct. One form of the equality case for Cauchy-Schwarz. -/
lemma inner_lt_one_iff_real_of_norm_one {x y : F} (hx : ‖x‖ = 1) (hy : ‖y‖ = 1) :
⟪x, y⟫_ℝ < 1 ↔ x ≠ y :=
by { convert inner_lt_norm_mul_iff_real; simp [hx, hy] }
/-- The inner product of two weighted sums, where the weights in each
sum add to 0, in terms of the norms of pairwise differences. -/
lemma inner_sum_smul_sum_smul_of_sum_eq_zero {ι₁ : Type*} {s₁ : finset ι₁} {w₁ : ι₁ → ℝ}
(v₁ : ι₁ → F) (h₁ : ∑ i in s₁, w₁ i = 0) {ι₂ : Type*} {s₂ : finset ι₂} {w₂ : ι₂ → ℝ}
(v₂ : ι₂ → F) (h₂ : ∑ i in s₂, w₂ i = 0) :
⟪(∑ i₁ in s₁, w₁ i₁ • v₁ i₁), (∑ i₂ in s₂, w₂ i₂ • v₂ i₂)⟫_ℝ =
(-∑ i₁ in s₁, ∑ i₂ in s₂, w₁ i₁ * w₂ i₂ * (‖v₁ i₁ - v₂ i₂‖ * ‖v₁ i₁ - v₂ i₂‖)) / 2 :=
by simp_rw [sum_inner, inner_sum, real_inner_smul_left, real_inner_smul_right,
real_inner_eq_norm_mul_self_add_norm_mul_self_sub_norm_sub_mul_self_div_two,
←div_sub_div_same, ←div_add_div_same, mul_sub_left_distrib, left_distrib,
finset.sum_sub_distrib, finset.sum_add_distrib, ←finset.mul_sum, ←finset.sum_mul,
h₁, h₂, zero_mul, mul_zero, finset.sum_const_zero, zero_add, zero_sub, finset.mul_sum,
neg_div, finset.sum_div, mul_div_assoc, mul_assoc]
variables (𝕜)
/-- The inner product as a sesquilinear map. -/
def innerₛₗ : E →ₗ⋆[𝕜] E →ₗ[𝕜] 𝕜 :=
linear_map.mk₂'ₛₗ _ _ (λ v w, ⟪v, w⟫) inner_add_left (λ _ _ _, inner_smul_left _ _ _)
inner_add_right (λ _ _ _, inner_smul_right _ _ _)
@[simp] lemma innerₛₗ_apply_coe (v : E) : ⇑(innerₛₗ 𝕜 v) = λ w, ⟪v, w⟫ := rfl
@[simp] lemma innerₛₗ_apply (v w : E) : innerₛₗ 𝕜 v w = ⟪v, w⟫ := rfl
/-- The inner product as a continuous sesquilinear map. Note that `to_dual_map` (resp. `to_dual`)
in `inner_product_space.dual` is a version of this given as a linear isometry (resp. linear
isometric equivalence). -/
def innerSL : E →L⋆[𝕜] E →L[𝕜] 𝕜 :=
linear_map.mk_continuous₂ (innerₛₗ 𝕜) 1
(λ x y, by simp only [norm_inner_le_norm, one_mul, innerₛₗ_apply])
@[simp] lemma innerSL_apply_coe (v : E) : ⇑(innerSL 𝕜 v) = λ w, ⟪v, w⟫ := rfl
@[simp] lemma innerSL_apply (v w : E) : innerSL 𝕜 v w = ⟪v, w⟫ := rfl
/-- `innerSL` is an isometry. Note that the associated `linear_isometry` is defined in
`inner_product_space.dual` as `to_dual_map`. -/
@[simp] lemma innerSL_apply_norm (x : E) : ‖innerSL 𝕜 x‖ = ‖x‖ :=
begin
refine le_antisymm ((innerSL 𝕜 x).op_norm_le_bound (norm_nonneg _)
(λ y, norm_inner_le_norm _ _)) _,
rcases eq_or_ne x 0 with (rfl | h),
{ simp },
{ refine (mul_le_mul_right (norm_pos_iff.2 h)).mp _,
calc ‖x‖ * ‖x‖ = ‖(⟪x, x⟫ : 𝕜)‖ : by rw [← sq, inner_self_eq_norm_sq_to_K, norm_pow,
norm_of_real, abs_norm]
... ≤ ‖innerSL 𝕜 x‖ * ‖x‖ : (innerSL 𝕜 x).le_op_norm _ }
end
/-- The inner product as a continuous sesquilinear map, with the two arguments flipped. -/
def innerSL_flip : E →L[𝕜] E →L⋆[𝕜] 𝕜 :=
@continuous_linear_map.flipₗᵢ' 𝕜 𝕜 𝕜 E E 𝕜 _ _ _ _ _ _ _ _ _ (ring_hom.id 𝕜) (star_ring_end 𝕜) _ _
(innerSL 𝕜)
@[simp] lemma innerSL_flip_apply (x y : E) : innerSL_flip 𝕜 x y = ⟪y, x⟫ := rfl
variables {𝕜}
namespace continuous_linear_map
variables {E' : Type*} [normed_add_comm_group E'] [inner_product_space 𝕜 E']
/-- Given `f : E →L[𝕜] E'`, construct the continuous sesquilinear form `λ x y, ⟪x, A y⟫`, given
as a continuous linear map. -/
def to_sesq_form : (E →L[𝕜] E') →L[𝕜] E' →L⋆[𝕜] E →L[𝕜] 𝕜 :=
↑((continuous_linear_map.flipₗᵢ' E E' 𝕜
(star_ring_end 𝕜) (ring_hom.id 𝕜)).to_continuous_linear_equiv) ∘L
(continuous_linear_map.compSL E E' (E' →L⋆[𝕜] 𝕜) (ring_hom.id 𝕜) (ring_hom.id 𝕜) (innerSL_flip 𝕜))
@[simp] lemma to_sesq_form_apply_coe (f : E →L[𝕜] E') (x : E') :
to_sesq_form f x = (innerSL 𝕜 x).comp f := rfl
lemma to_sesq_form_apply_norm_le {f : E →L[𝕜] E'} {v : E'} : ‖to_sesq_form f v‖ ≤ ‖f‖ * ‖v‖ :=
begin
refine op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) _,
intro x,
have h₁ : ‖f x‖ ≤ ‖f‖ * ‖x‖ := le_op_norm _ _,
have h₂ := @norm_inner_le_norm 𝕜 E' _ _ _ v (f x),
calc ‖⟪v, f x⟫‖ ≤ ‖v‖ * ‖f x‖ : h₂
... ≤ ‖v‖ * (‖f‖ * ‖x‖) : mul_le_mul_of_nonneg_left h₁ (norm_nonneg v)
... = ‖f‖ * ‖v‖ * ‖x‖ : by ring,
end
end continuous_linear_map
/-- When an inner product space `E` over `𝕜` is considered as a real normed space, its inner
product satisfies `is_bounded_bilinear_map`.
In order to state these results, we need a `normed_space ℝ E` instance. We will later establish
such an instance by restriction-of-scalars, `inner_product_space.is_R_or_C_to_real 𝕜 E`, but this
instance may be not definitionally equal to some other “natural” instance. So, we assume
`[normed_space ℝ E]`.
-/
lemma is_bounded_bilinear_map_inner [normed_space ℝ E] :
is_bounded_bilinear_map ℝ (λ p : E × E, ⟪p.1, p.2⟫) :=
{ add_left := inner_add_left,
smul_left := λ r x y,
by simp only [← algebra_map_smul 𝕜 r x, algebra_map_eq_of_real, inner_smul_real_left],
add_right := inner_add_right,
smul_right := λ r x y,
by simp only [← algebra_map_smul 𝕜 r y, algebra_map_eq_of_real, inner_smul_real_right],
bound := ⟨1, zero_lt_one, λ x y,
by { rw [one_mul], exact norm_inner_le_norm x y, }⟩ }
end norm
section bessels_inequality
variables {ι: Type*} (x : E) {v : ι → E}
/-- Bessel's inequality for finite sums. -/
lemma orthonormal.sum_inner_products_le {s : finset ι} (hv : orthonormal 𝕜 v) :
∑ i in s, ‖⟪v i, x⟫‖ ^ 2 ≤ ‖x‖ ^ 2 :=
begin
have h₂ : ∑ i in s, ∑ j in s, ⟪v i, x⟫ * ⟪x, v j⟫ * ⟪v j, v i⟫
= (∑ k in s, (⟪v k, x⟫ * ⟪x, v k⟫) : 𝕜),
{ exact hv.inner_left_right_finset },
have h₃ : ∀ z : 𝕜, re (z * conj (z)) = ‖z‖ ^ 2,
{ intro z,
simp only [mul_conj, norm_sq_eq_def'],
norm_cast, },
suffices hbf: ‖x - ∑ i in s, ⟪v i, x⟫ • (v i)‖ ^ 2 = ‖x‖ ^ 2 - ∑ i in s, ‖⟪v i, x⟫‖ ^ 2,
{ rw [←sub_nonneg, ←hbf],
simp only [norm_nonneg, pow_nonneg], },
rw [@norm_sub_sq 𝕜, sub_add],
simp only [@inner_product_space.norm_sq_eq_inner 𝕜, inner_sum],
simp only [sum_inner, two_mul, inner_smul_right, inner_conj_symm, ←mul_assoc, h₂, ←h₃,
inner_conj_symm, add_monoid_hom.map_sum, finset.mul_sum, ←finset.sum_sub_distrib, inner_smul_left,
add_sub_cancel'],
end
/-- Bessel's inequality. -/
lemma orthonormal.tsum_inner_products_le (hv : orthonormal 𝕜 v) :
∑' i, ‖⟪v i, x⟫‖ ^ 2 ≤ ‖x‖ ^ 2 :=
begin
refine tsum_le_of_sum_le' _ (λ s, hv.sum_inner_products_le x),
simp only [norm_nonneg, pow_nonneg]
end
/-- The sum defined in Bessel's inequality is summable. -/
lemma orthonormal.inner_products_summable (hv : orthonormal 𝕜 v) : summable (λ i, ‖⟪v i, x⟫‖ ^ 2) :=
begin
use ⨆ s : finset ι, ∑ i in s, ‖⟪v i, x⟫‖ ^ 2,
apply has_sum_of_is_lub_of_nonneg,
{ intro b,
simp only [norm_nonneg, pow_nonneg], },
{ refine is_lub_csupr _,
use ‖x‖ ^ 2,
rintro y ⟨s, rfl⟩,
exact hv.sum_inner_products_le x }
end
end bessels_inequality
/-- A field `𝕜` satisfying `is_R_or_C` is itself a `𝕜`-inner product space. -/
instance is_R_or_C.inner_product_space : inner_product_space 𝕜 𝕜 :=
{ inner := λ x y, conj x * y,
norm_sq_eq_inner := λ x,
by { unfold inner, rw [mul_comm, mul_conj, of_real_re, norm_sq_eq_def'] },
conj_symm := λ x y, by simp only [mul_comm, map_mul, star_ring_end_self_apply],
add_left := λ x y z, by simp only [add_mul, map_add],
smul_left := λ x y z, by simp only [mul_assoc, smul_eq_mul, map_mul] }
@[simp] lemma is_R_or_C.inner_apply (x y : 𝕜) : ⟪x, y⟫ = (conj x) * y := rfl
/-! ### Inner product space structure on subspaces -/
/-- Induced inner product on a submodule. -/
instance submodule.inner_product_space (W : submodule 𝕜 E) : inner_product_space 𝕜 W :=
{ inner := λ x y, ⟪(x:E), (y:E)⟫,
conj_symm := λ _ _, inner_conj_symm _ _,
norm_sq_eq_inner := λ x, norm_sq_eq_inner (x : E),
add_left := λ _ _ _, inner_add_left _ _ _,
smul_left := λ _ _ _, inner_smul_left _ _ _,
..submodule.normed_space W }
/-- The inner product on submodules is the same as on the ambient space. -/
@[simp] lemma submodule.coe_inner (W : submodule 𝕜 E) (x y : W) : ⟪x, y⟫ = ⟪(x:E), ↑y⟫ := rfl
lemma orthonormal.cod_restrict {ι : Type*} {v : ι → E} (hv : orthonormal 𝕜 v)
(s : submodule 𝕜 E) (hvs : ∀ i, v i ∈ s) :
@orthonormal 𝕜 s _ _ _ ι (set.cod_restrict v s hvs) :=
s.subtypeₗᵢ.orthonormal_comp_iff.mp hv
lemma orthonormal_span {ι : Type*} {v : ι → E} (hv : orthonormal 𝕜 v) :
@orthonormal 𝕜 (submodule.span 𝕜 (set.range v)) _ _ _ ι
(λ i : ι, ⟨v i, submodule.subset_span (set.mem_range_self i)⟩) :=
hv.cod_restrict (submodule.span 𝕜 (set.range v))
(λ i, submodule.subset_span (set.mem_range_self i))
/-! ### Families of mutually-orthogonal subspaces of an inner product space -/
section orthogonal_family
variables {ι : Type*} [dec_ι : decidable_eq ι] (𝕜)
open_locale direct_sum
/-- An indexed family of mutually-orthogonal subspaces of an inner product space `E`.
The simple way to express this concept would be as a condition on `V : ι → submodule 𝕜 E`. We
We instead implement it as a condition on a family of inner product spaces each equipped with an
isometric embedding into `E`, thus making it a property of morphisms rather than subobjects.
The connection to the subobject spelling is shown in `orthogonal_family_iff_pairwise`.
This definition is less lightweight, but allows for better definitional properties when the inner
product space structure on each of the submodules is important -- for example, when considering
their Hilbert sum (`pi_lp V 2`). For example, given an orthonormal set of vectors `v : ι → E`,
we have an associated orthogonal family of one-dimensional subspaces of `E`, which it is convenient
to be able to discuss using `ι → 𝕜` rather than `Π i : ι, span 𝕜 (v i)`. -/
def orthogonal_family (G : ι → Type*)
[Π i, normed_add_comm_group (G i)] [Π i, inner_product_space 𝕜 (G i)] (V : Π i, G i →ₗᵢ[𝕜] E) :
Prop :=
∀ ⦃i j⦄, i ≠ j → ∀ v : G i, ∀ w : G j, ⟪V i v, V j w⟫ = 0
variables {𝕜} {G : ι → Type*}
[Π i, normed_add_comm_group (G i)] [Π i, inner_product_space 𝕜 (G i)] {V : Π i, G i →ₗᵢ[𝕜] E}
(hV : orthogonal_family 𝕜 G V) [dec_V : Π i (x : G i), decidable (x ≠ 0)]
lemma orthonormal.orthogonal_family {v : ι → E} (hv : orthonormal 𝕜 v) :
orthogonal_family 𝕜 (λ i : ι, 𝕜)
(λ i, linear_isometry.to_span_singleton 𝕜 E (hv.1 i)) :=
λ i j hij a b, by simp [inner_smul_left, inner_smul_right, hv.2 hij]
include hV dec_ι
lemma orthogonal_family.eq_ite {i j : ι} (v : G i) (w : G j) :
⟪V i v, V j w⟫ = ite (i = j) ⟪V i v, V j w⟫ 0 :=
begin
split_ifs,
{ refl },
{ exact hV h v w }
end
include dec_V
lemma orthogonal_family.inner_right_dfinsupp (l : ⨁ i, G i) (i : ι) (v : G i) :
⟪V i v, l.sum (λ j, V j)⟫ = ⟪v, l i⟫ :=
calc ⟪V i v, l.sum (λ j, V j)⟫
= l.sum (λ j, λ w, ⟪V i v, V j w⟫) : dfinsupp.inner_sum (λ j, V j) l (V i v)
... = l.sum (λ j, λ w, ite (i=j) ⟪V i v, V j w⟫ 0) :
congr_arg l.sum $ funext $ λ j, funext $ hV.eq_ite v
... = ⟪v, l i⟫ :
begin
simp only [dfinsupp.sum, submodule.coe_inner, finset.sum_ite_eq, ite_eq_left_iff,
dfinsupp.mem_support_to_fun],
split_ifs with h h,
{ simp only [linear_isometry.inner_map_map] },
{ simp only [of_not_not h, inner_zero_right] },
end
omit dec_ι dec_V
lemma orthogonal_family.inner_right_fintype [fintype ι] (l : Π i, G i) (i : ι) (v : G i) :
⟪V i v, ∑ j : ι, V j (l j)⟫ = ⟪v, l i⟫ :=
by classical;
calc ⟪V i v, ∑ j : ι, V j (l j)⟫
= ∑ j : ι, ⟪V i v, V j (l j)⟫: by rw inner_sum
... = ∑ j, ite (i = j) ⟪V i v, V j (l j)⟫ 0 :
congr_arg (finset.sum finset.univ) $ funext $ λ j, (hV.eq_ite v (l j))
... = ⟪v, l i⟫ : by simp only [finset.sum_ite_eq, finset.mem_univ, (V i).inner_map_map, if_true]
lemma orthogonal_family.inner_sum (l₁ l₂ : Π i, G i) (s : finset ι) :
⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫ = ∑ i in s, ⟪l₁ i, l₂ i⟫ :=
by classical;
calc ⟪∑ i in s, V i (l₁ i), ∑ j in s, V j (l₂ j)⟫
= ∑ j in s, ∑ i in s, ⟪V i (l₁ i), V j (l₂ j)⟫ : by simp only [sum_inner, inner_sum]
... = ∑ j in s, ∑ i in s, ite (i = j) ⟪V i (l₁ i), V j (l₂ j)⟫ 0 :
begin
congr' with i,
congr' with j,
apply hV.eq_ite,
end
... = ∑ i in s, ⟪l₁ i, l₂ i⟫ : by simp only [finset.sum_ite_of_true,
finset.sum_ite_eq', linear_isometry.inner_map_map, imp_self, implies_true_iff]
lemma orthogonal_family.norm_sum (l : Π i, G i) (s : finset ι) :
‖∑ i in s, V i (l i)‖ ^ 2 = ∑ i in s, ‖l i‖ ^ 2 :=
begin
have : (‖∑ i in s, V i (l i)‖ ^ 2 : 𝕜) = ∑ i in s, ‖l i‖ ^ 2,
{ simp only [← inner_self_eq_norm_sq_to_K, hV.inner_sum] },
exact_mod_cast this,
end
/-- The composition of an orthogonal family of subspaces with an injective function is also an
orthogonal family. -/
lemma orthogonal_family.comp {γ : Type*} {f : γ → ι} (hf : function.injective f) :
orthogonal_family 𝕜 (λ g, G (f g)) (λ g, V (f g)) :=
λ i j hij v w, hV (hf.ne hij) v w
lemma orthogonal_family.orthonormal_sigma_orthonormal {α : ι → Type*} {v_family : Π i, (α i) → G i}
(hv_family : ∀ i, orthonormal 𝕜 (v_family i)) :
orthonormal 𝕜 (λ a : Σ i, α i, V a.1 (v_family a.1 a.2)) :=
begin
split,
{ rintros ⟨i, v⟩,
simpa only [linear_isometry.norm_map] using (hv_family i).left v },
rintros ⟨i, v⟩ ⟨j, w⟩ hvw,
by_cases hij : i = j,
{ subst hij,
have : v ≠ w := λ h, by { subst h, exact hvw rfl },
simpa only [linear_isometry.inner_map_map] using (hv_family i).2 this },
{ exact hV hij (v_family i v) (v_family j w) }
end
include dec_ι
lemma orthogonal_family.norm_sq_diff_sum (f : Π i, G i) (s₁ s₂ : finset ι) :
‖∑ i in s₁, V i (f i) - ∑ i in s₂, V i (f i)‖ ^ 2
= ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 :=
begin
rw [← finset.sum_sdiff_sub_sum_sdiff, sub_eq_add_neg, ← finset.sum_neg_distrib],
let F : Π i, G i := λ i, if i ∈ s₁ then f i else - (f i),
have hF₁ : ∀ i ∈ s₁ \ s₂, F i = f i := λ i hi, if_pos (finset.sdiff_subset _ _ hi),
have hF₂ : ∀ i ∈ s₂ \ s₁, F i = - f i := λ i hi, if_neg (finset.mem_sdiff.mp hi).2,
have hF : ∀ i, ‖F i‖ = ‖f i‖,
{ intros i,
dsimp only [F],
split_ifs;
simp only [eq_self_iff_true, norm_neg], },
have : ‖∑ i in s₁ \ s₂, V i (F i) + ∑ i in s₂ \ s₁, V i (F i)‖ ^ 2 =
∑ i in s₁ \ s₂, ‖F i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖F i‖ ^ 2,
{ have hs : disjoint (s₁ \ s₂) (s₂ \ s₁) := disjoint_sdiff_sdiff,
simpa only [finset.sum_union hs] using hV.norm_sum F (s₁ \ s₂ ∪ s₂ \ s₁) },
convert this using 4,
{ refine finset.sum_congr rfl (λ i hi, _),
simp only [hF₁ i hi] },
{ refine finset.sum_congr rfl (λ i hi, _),
simp only [hF₂ i hi, linear_isometry.map_neg] },
{ simp only [hF] },
{ simp only [hF] },
end
omit dec_ι
/-- A family `f` of mutually-orthogonal elements of `E` is summable, if and only if
`(λ i, ‖f i‖ ^ 2)` is summable. -/
lemma orthogonal_family.summable_iff_norm_sq_summable [complete_space E] (f : Π i, G i) :
summable (λ i, V i (f i)) ↔ summable (λ i, ‖f i‖ ^ 2) :=
begin
classical,
simp only [summable_iff_cauchy_seq_finset, normed_add_comm_group.cauchy_seq_iff,
real.norm_eq_abs],
split,
{ intros hf ε hε,
obtain ⟨a, H⟩ := hf _ (sqrt_pos.mpr hε),
use a,
intros s₁ hs₁ s₂ hs₂,
rw ← finset.sum_sdiff_sub_sum_sdiff,
refine (abs_sub _ _).trans_lt _,
have : ∀ i, 0 ≤ ‖f i‖ ^ 2 := λ i : ι, sq_nonneg _,
simp only [finset.abs_sum_of_nonneg' this],
have : ∑ i in s₁ \ s₂, ‖f i‖ ^ 2 + ∑ i in s₂ \ s₁, ‖f i‖ ^ 2 < (sqrt ε) ^ 2,
{ rw [← hV.norm_sq_diff_sum, sq_lt_sq, abs_of_nonneg (sqrt_nonneg _),
abs_of_nonneg (norm_nonneg _)],
exact H s₁ hs₁ s₂ hs₂ },
have hη := sq_sqrt (le_of_lt hε),
linarith },
{ intros hf ε hε,
have hε' : 0 < ε ^ 2 / 2 := half_pos (sq_pos_of_pos hε),
obtain ⟨a, H⟩ := hf _ hε',
use a,
intros s₁ hs₁ s₂ hs₂,
refine (abs_lt_of_sq_lt_sq' _ (le_of_lt hε)).2,
have has : a ≤ s₁ ⊓ s₂ := le_inf hs₁ hs₂,
rw hV.norm_sq_diff_sum,
have Hs₁ : ∑ (x : ι) in s₁ \ s₂, ‖f x‖ ^ 2 < ε ^ 2 / 2,
{ convert H _ hs₁ _ has,
have : s₁ ⊓ s₂ ⊆ s₁ := finset.inter_subset_left _ _,
rw [← finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],
{ simp },
{ exact λ i, sq_nonneg _ } },
have Hs₂ : ∑ (x : ι) in s₂ \ s₁, ‖f x‖ ^ 2 < ε ^ 2 /2,
{ convert H _ hs₂ _ has,
have : s₁ ⊓ s₂ ⊆ s₂ := finset.inter_subset_right _ _,
rw [← finset.sum_sdiff this, add_tsub_cancel_right, finset.abs_sum_of_nonneg'],
{ simp },
{ exact λ i, sq_nonneg _ } },
linarith },
end
omit hV
/-- An orthogonal family forms an independent family of subspaces; that is, any collection of
elements each from a different subspace in the family is linearly independent. In particular, the
pairwise intersections of elements of the family are 0. -/
lemma orthogonal_family.independent {V : ι → submodule 𝕜 E}
(hV : orthogonal_family 𝕜 (λ i, V i) (λ i, (V i).subtypeₗᵢ)) :
complete_lattice.independent V :=
begin
classical,
apply complete_lattice.independent_of_dfinsupp_lsum_injective,
rw [← @linear_map.ker_eq_bot _ _ _ _ _ _ (direct_sum.add_comm_group (λ i, V i)),
submodule.eq_bot_iff],
intros v hv,
rw linear_map.mem_ker at hv,
ext i,
suffices : ⟪(v i : E), v i⟫ = 0,
{ simpa only [inner_self_eq_zero] using this },
calc ⟪(v i : E), v i⟫ = ⟪(v i : E), dfinsupp.lsum ℕ (λ i, (V i).subtype) v⟫ :
by simpa only [dfinsupp.sum_add_hom_apply, dfinsupp.lsum_apply_apply]
using (hV.inner_right_dfinsupp v i (v i)).symm
... = 0 : by simp only [hv, inner_zero_right],
end
include dec_ι
lemma direct_sum.is_internal.collected_basis_orthonormal {V : ι → submodule 𝕜 E}
(hV : orthogonal_family 𝕜 (λ i, V i) (λ i, (V i).subtypeₗᵢ))
(hV_sum : direct_sum.is_internal (λ i, V i))
{α : ι → Type*}
{v_family : Π i, basis (α i) 𝕜 (V i)} (hv_family : ∀ i, orthonormal 𝕜 (v_family i)) :
orthonormal 𝕜 (hV_sum.collected_basis v_family) :=
by simpa only [hV_sum.collected_basis_coe] using hV.orthonormal_sigma_orthonormal hv_family
end orthogonal_family
section is_R_or_C_to_real
variables {G : Type*}
variables (𝕜 E)
include 𝕜
/-- A general inner product implies a real inner product. This is not registered as an instance
since it creates problems with the case `𝕜 = ℝ`. -/
def has_inner.is_R_or_C_to_real : has_inner ℝ E :=
{ inner := λ x y, re ⟪x, y⟫ }
/-- A general inner product space structure implies a real inner product structure. This is not
registered as an instance since it creates problems with the case `𝕜 = ℝ`, but in can be used in a
proof to obtain a real inner product space structure from a given `𝕜`-inner product space
structure. -/
def inner_product_space.is_R_or_C_to_real : inner_product_space ℝ E :=
{ norm_sq_eq_inner := norm_sq_eq_inner,
conj_symm := λ x y, inner_re_symm _ _,
add_left := λ x y z, by
{ change re ⟪x + y, z⟫ = re ⟪x, z⟫ + re ⟪y, z⟫,
simp only [inner_add_left, map_add] },
smul_left := λ x y r, by
{ change re ⟪(r : 𝕜) • x, y⟫ = r * re ⟪x, y⟫,
simp only [inner_smul_left, conj_of_real, of_real_mul_re] },
..has_inner.is_R_or_C_to_real 𝕜 E,
..normed_space.restrict_scalars ℝ 𝕜 E }
variable {E}
lemma real_inner_eq_re_inner (x y : E) :
@has_inner.inner ℝ E (has_inner.is_R_or_C_to_real 𝕜 E) x y = re ⟪x, y⟫ := rfl
lemma real_inner_I_smul_self (x : E) :
@has_inner.inner ℝ E (has_inner.is_R_or_C_to_real 𝕜 E) x ((I : 𝕜) • x) = 0 :=
by simp [real_inner_eq_re_inner, inner_smul_right]
omit 𝕜
/-- A complex inner product implies a real inner product -/
instance inner_product_space.complex_to_real
[normed_add_comm_group G] [inner_product_space ℂ G] : inner_product_space ℝ G :=
inner_product_space.is_R_or_C_to_real ℂ G
@[simp] protected lemma complex.inner (w z : ℂ) : ⟪w, z⟫_ℝ = (conj w * z).re := rfl
/-- The inner product on an inner product space of dimension 2 can be evaluated in terms
of a complex-number representation of the space. -/
lemma inner_map_complex [normed_add_comm_group G] [inner_product_space ℝ G]
(f : G ≃ₗᵢ[ℝ] ℂ) (x y : G) :
⟪x, y⟫_ℝ = (conj (f x) * f y).re :=
by rw [← complex.inner, f.inner_map_map]
end is_R_or_C_to_real
section continuous
/-!
### Continuity of the inner product
-/
lemma continuous_inner : continuous (λ p : E × E, ⟪p.1, p.2⟫) :=
begin
letI : inner_product_space ℝ E := inner_product_space.is_R_or_C_to_real 𝕜 E,
exact is_bounded_bilinear_map_inner.continuous
end
variables {α : Type*}
lemma filter.tendsto.inner {f g : α → E} {l : filter α} {x y : E} (hf : tendsto f l (𝓝 x))
(hg : tendsto g l (𝓝 y)) :
tendsto (λ t, ⟪f t, g t⟫) l (𝓝 ⟪x, y⟫) :=
(continuous_inner.tendsto _).comp (hf.prod_mk_nhds hg)
variables [topological_space α] {f g : α → E} {x : α} {s : set α}
include 𝕜
lemma continuous_within_at.inner (hf : continuous_within_at f s x)
(hg : continuous_within_at g s x) :
continuous_within_at (λ t, ⟪f t, g t⟫) s x :=
hf.inner hg
lemma continuous_at.inner (hf : continuous_at f x) (hg : continuous_at g x) :
continuous_at (λ t, ⟪f t, g t⟫) x :=
hf.inner hg
lemma continuous_on.inner (hf : continuous_on f s) (hg : continuous_on g s) :
continuous_on (λ t, ⟪f t, g t⟫) s :=
λ x hx, (hf x hx).inner (hg x hx)
@[continuity]
lemma continuous.inner (hf : continuous f) (hg : continuous g) : continuous (λ t, ⟪f t, g t⟫) :=
continuous_iff_continuous_at.2 $ λ x, hf.continuous_at.inner hg.continuous_at
end continuous
section re_apply_inner_self
/-- Extract a real bilinear form from an operator `T`, by taking the pairing `λ x, re ⟪T x, x⟫`. -/
def continuous_linear_map.re_apply_inner_self (T : E →L[𝕜] E) (x : E) : ℝ := re ⟪T x, x⟫
lemma continuous_linear_map.re_apply_inner_self_apply (T : E →L[𝕜] E) (x : E) :
T.re_apply_inner_self x = re ⟪T x, x⟫ :=
rfl
lemma continuous_linear_map.re_apply_inner_self_continuous (T : E →L[𝕜] E) :
continuous T.re_apply_inner_self :=
re_clm.continuous.comp $ T.continuous.inner continuous_id
lemma continuous_linear_map.re_apply_inner_self_smul (T : E →L[𝕜] E) (x : E) {c : 𝕜} :
T.re_apply_inner_self (c • x) = ‖c‖ ^ 2 * T.re_apply_inner_self x :=
by simp only [continuous_linear_map.map_smul, continuous_linear_map.re_apply_inner_self_apply,
inner_smul_left, inner_smul_right, ← mul_assoc, mul_conj, norm_sq_eq_def', ← smul_re,
algebra.smul_def (‖c‖ ^ 2) ⟪T x, x⟫, algebra_map_eq_of_real]
end re_apply_inner_self
namespace uniform_space.completion
open uniform_space function
instance {𝕜' E' : Type*} [topological_space 𝕜'] [uniform_space E'] [has_inner 𝕜' E'] :
has_inner 𝕜' (completion E') :=
{ inner := curry $ (dense_inducing_coe.prod dense_inducing_coe).extend (uncurry inner) }
@[simp] lemma inner_coe (a b : E) :
inner (a : completion E) (b : completion E) = (inner a b : 𝕜) :=
(dense_inducing_coe.prod dense_inducing_coe).extend_eq
(continuous_inner : continuous (uncurry inner : E × E → 𝕜)) (a, b)
protected lemma continuous_inner :
continuous (uncurry inner : completion E × completion E → 𝕜) :=
begin
let inner' : E →+ E →+ 𝕜 :=
{ to_fun := λ x, (innerₛₗ 𝕜 x).to_add_monoid_hom,
map_zero' := by ext x; exact inner_zero_left _,
map_add' := λ x y, by ext z; exact inner_add_left _ _ _ },
have : continuous (λ p : E × E, inner' p.1 p.2) := continuous_inner,
rw [completion.has_inner, uncurry_curry _],
change continuous (((dense_inducing_to_compl E).prod (dense_inducing_to_compl E)).extend
(λ p : E × E, inner' p.1 p.2)),
exact (dense_inducing_to_compl E).extend_Z_bilin (dense_inducing_to_compl E) this,
end
protected lemma continuous.inner {α : Type*} [topological_space α]
{f g : α → completion E} (hf : continuous f) (hg : continuous g) :
continuous (λ x : α, inner (f x) (g x) : α → 𝕜) :=
uniform_space.completion.continuous_inner.comp (hf.prod_mk hg : _)
instance : inner_product_space 𝕜 (completion E) :=
{ norm_sq_eq_inner := λ x, completion.induction_on x
(is_closed_eq
(continuous_norm.pow 2)
(continuous_re.comp (continuous.inner continuous_id' continuous_id')))
(λ a, by simp only [norm_coe, inner_coe, inner_self_eq_norm_sq]),
conj_symm := λ x y, completion.induction_on₂ x y
(is_closed_eq
(continuous_conj.comp (continuous.inner continuous_snd continuous_fst))
(continuous.inner continuous_fst continuous_snd))
(λ a b, by simp only [inner_coe, inner_conj_symm]),
add_left := λ x y z, completion.induction_on₃ x y z
(is_closed_eq
(continuous.inner (continuous_fst.add (continuous_fst.comp continuous_snd))
(continuous_snd.comp continuous_snd))
((continuous.inner continuous_fst (continuous_snd.comp continuous_snd)).add
(continuous.inner (continuous_fst.comp continuous_snd)
(continuous_snd.comp continuous_snd))))
(λ a b c, by simp only [← coe_add, inner_coe, inner_add_left]),
smul_left := λ x y c, completion.induction_on₂ x y
(is_closed_eq
(continuous.inner (continuous_fst.const_smul c) continuous_snd)
((continuous_mul_left _).comp (continuous.inner continuous_fst continuous_snd)))
(λ a b, by simp only [← coe_smul c a, inner_coe, inner_smul_left]) }
end uniform_space.completion
|
5270e84b8510afaf736a1546cdea7c169a5bd3c6 | 1abd1ed12aa68b375cdef28959f39531c6e95b84 | /src/data/complex/module.lean | 69834383e41fb3cdc4ad1f34c97ddc89623141d6 | [
"Apache-2.0"
] | permissive | jumpy4/mathlib | d3829e75173012833e9f15ac16e481e17596de0f | af36f1a35f279f0e5b3c2a77647c6bf2cfd51a13 | refs/heads/master | 1,693,508,842,818 | 1,636,203,271,000 | 1,636,203,271,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 10,540 | lean | /-
Copyright (c) 2020 Alexander Bentkamp, Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Sébastien Gouëzel, Eric Wieser
-/
import algebra.order.module
import data.complex.basic
import data.matrix.notation
import field_theory.tower
/-!
# Complex number as a vector space over `ℝ`
This file contains the following instances:
* Any `•`-structure (`has_scalar`, `mul_action`, `distrib_mul_action`, `module`, `algebra`) on
`ℝ` imbues a corresponding structure on `ℂ`. This includes the statement that `ℂ` is an `ℝ`
algebra.
* any complex vector space is a real vector space;
* any finite dimensional complex vector space is a finite dimensional real vector space;
* the space of `ℝ`-linear maps from a real vector space to a complex vector space is a complex
vector space.
It also defines bundled versions of four standard maps (respectively, the real part, the imaginary
part, the embedding of `ℝ` in `ℂ`, and the complex conjugate):
* `complex.re_lm` (`ℝ`-linear map);
* `complex.im_lm` (`ℝ`-linear map);
* `complex.of_real_am` (`ℝ`-algebra (homo)morphism);
* `complex.conj_ae` (`ℝ`-algebra equivalence).
It also provides a universal property of the complex numbers `complex.lift`, which constructs a
`ℂ →ₐ[ℝ] A` into any `ℝ`-algebra `A` given a square root of `-1`.
-/
namespace complex
open_locale complex_conjugate
variables {R : Type*} {S : Type*}
section
variables [has_scalar R ℝ]
/- The useless `0` multiplication in `smul` is to make sure that
`restrict_scalars.module ℝ ℂ ℂ = complex.module` definitionally. -/
instance : has_scalar R ℂ :=
{ smul := λ r x, ⟨r • x.re - 0 * x.im, r • x.im + 0 * x.re⟩ }
lemma smul_re (r : R) (z : ℂ) : (r • z).re = r • z.re := by simp [(•)]
lemma smul_im (r : R) (z : ℂ) : (r • z).im = r • z.im := by simp [(•)]
@[simp] lemma real_smul {x : ℝ} {z : ℂ} : x • z = x * z := rfl
end
instance [has_scalar R ℝ] [has_scalar S ℝ] [smul_comm_class R S ℝ] : smul_comm_class R S ℂ :=
{ smul_comm := λ r s x, by ext; simp [smul_re, smul_im, smul_comm] }
instance [has_scalar R S] [has_scalar R ℝ] [has_scalar S ℝ] [is_scalar_tower R S ℝ] :
is_scalar_tower R S ℂ :=
{ smul_assoc := λ r s x, by ext; simp [smul_re, smul_im, smul_assoc] }
instance [monoid R] [mul_action R ℝ] : mul_action R ℂ :=
{ one_smul := λ x, by ext; simp [smul_re, smul_im, one_smul],
mul_smul := λ r s x, by ext; simp [smul_re, smul_im, mul_smul] }
instance [semiring R] [distrib_mul_action R ℝ] : distrib_mul_action R ℂ :=
{ smul_add := λ r x y, by ext; simp [smul_re, smul_im, smul_add],
smul_zero := λ r, by ext; simp [smul_re, smul_im, smul_zero] }
instance [semiring R] [module R ℝ] : module R ℂ :=
{ add_smul := λ r s x, by ext; simp [smul_re, smul_im, add_smul],
zero_smul := λ r, by ext; simp [smul_re, smul_im, zero_smul] }
instance [comm_semiring R] [algebra R ℝ] : algebra R ℂ :=
{ smul := (•),
smul_def' := λ r x, by ext; simp [smul_re, smul_im, algebra.smul_def],
commutes' := λ r ⟨xr, xi⟩, by ext; simp [smul_re, smul_im, algebra.commutes],
..complex.of_real.comp (algebra_map R ℝ) }
@[simp] lemma coe_algebra_map : (algebra_map ℝ ℂ : ℝ → ℂ) = coe := rfl
section
variables {A : Type*} [semiring A] [algebra ℝ A]
/-- We need this lemma since `complex.coe_algebra_map` diverts the simp-normal form away from
`alg_hom.commutes`. -/
@[simp] lemma _root_.alg_hom.map_coe_real_complex (f : ℂ →ₐ[ℝ] A) (x : ℝ) :
f x = algebra_map ℝ A x :=
f.commutes x
/-- Two `ℝ`-algebra homomorphisms from ℂ are equal if they agree on `complex.I`. -/
@[ext]
lemma alg_hom_ext ⦃f g : ℂ →ₐ[ℝ] A⦄ (h : f I = g I) : f = g :=
begin
ext ⟨x, y⟩,
simp only [mk_eq_add_mul_I, alg_hom.map_add, alg_hom.map_coe_real_complex, alg_hom.map_mul, h]
end
end
section
open_locale complex_order
protected lemma ordered_smul : ordered_smul ℝ ℂ :=
ordered_smul.mk' $ λ a b r hab hr, ⟨by simp [hr, hab.1.le], by simp [hab.2]⟩
localized "attribute [instance] complex.ordered_smul" in complex_order
end
open submodule finite_dimensional
/-- `ℂ` has a basis over `ℝ` given by `1` and `I`. -/
noncomputable def basis_one_I : basis (fin 2) ℝ ℂ :=
basis.of_equiv_fun
{ to_fun := λ z, ![z.re, z.im],
inv_fun := λ c, c 0 + c 1 • I,
left_inv := λ z, by simp,
right_inv := λ c, by { ext i, fin_cases i; simp },
map_add' := λ z z', by simp,
map_smul' := λ c z, by simp }
@[simp] lemma coe_basis_one_I_repr (z : ℂ) : ⇑(basis_one_I.repr z) = ![z.re, z.im] := rfl
@[simp] lemma coe_basis_one_I : ⇑basis_one_I = ![1, I] :=
funext $ λ i, basis.apply_eq_iff.mpr $ finsupp.ext $ λ j,
by fin_cases i; fin_cases j;
simp only [coe_basis_one_I_repr, finsupp.single_eq_same, finsupp.single_eq_of_ne,
matrix.cons_val_zero, matrix.cons_val_one, matrix.head_cons,
nat.one_ne_zero, fin.one_eq_zero_iff, fin.zero_eq_one_iff, ne.def, not_false_iff,
one_re, one_im, I_re, I_im]
instance : finite_dimensional ℝ ℂ := of_fintype_basis basis_one_I
@[simp] lemma finrank_real_complex : finite_dimensional.finrank ℝ ℂ = 2 :=
by rw [finrank_eq_card_basis basis_one_I, fintype.card_fin]
@[simp] lemma dim_real_complex : module.rank ℝ ℂ = 2 :=
by simp [← finrank_eq_dim, finrank_real_complex]
lemma {u} dim_real_complex' : cardinal.lift.{u} (module.rank ℝ ℂ) = 2 :=
by simp [← finrank_eq_dim, finrank_real_complex, bit0]
/-- `fact` version of the dimension of `ℂ` over `ℝ`, locally useful in the definition of the
circle. -/
lemma finrank_real_complex_fact : fact (finrank ℝ ℂ = 2) := ⟨finrank_real_complex⟩
end complex
/- Register as an instance (with low priority) the fact that a complex vector space is also a real
vector space. -/
@[priority 900]
instance module.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E] : module ℝ E :=
restrict_scalars.module ℝ ℂ E
instance module.real_complex_tower (E : Type*) [add_comm_group E] [module ℂ E] :
is_scalar_tower ℝ ℂ E :=
restrict_scalars.is_scalar_tower ℝ ℂ E
@[simp, norm_cast] lemma complex.coe_smul {E : Type*} [add_comm_group E] [module ℂ E]
(x : ℝ) (y : E) :
(x : ℂ) • y = x • y :=
rfl
@[priority 100]
instance finite_dimensional.complex_to_real (E : Type*) [add_comm_group E] [module ℂ E]
[finite_dimensional ℂ E] : finite_dimensional ℝ E :=
finite_dimensional.trans ℝ ℂ E
lemma dim_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :
module.rank ℝ E = 2 * module.rank ℂ E :=
cardinal.lift_inj.1 $
by { rw [← dim_mul_dim' ℝ ℂ E, complex.dim_real_complex], simp [bit0] }
lemma finrank_real_of_complex (E : Type*) [add_comm_group E] [module ℂ E] :
finite_dimensional.finrank ℝ E = 2 * finite_dimensional.finrank ℂ E :=
by rw [← finite_dimensional.finrank_mul_finrank ℝ ℂ E, complex.finrank_real_complex]
namespace complex
open_locale complex_conjugate
/-- Linear map version of the real part function, from `ℂ` to `ℝ`. -/
def re_lm : ℂ →ₗ[ℝ] ℝ :=
{ to_fun := λx, x.re,
map_add' := add_re,
map_smul' := by simp, }
@[simp] lemma re_lm_coe : ⇑re_lm = re := rfl
/-- Linear map version of the imaginary part function, from `ℂ` to `ℝ`. -/
def im_lm : ℂ →ₗ[ℝ] ℝ :=
{ to_fun := λx, x.im,
map_add' := add_im,
map_smul' := by simp, }
@[simp] lemma im_lm_coe : ⇑im_lm = im := rfl
/-- `ℝ`-algebra morphism version of the canonical embedding of `ℝ` in `ℂ`. -/
def of_real_am : ℝ →ₐ[ℝ] ℂ := algebra.of_id ℝ ℂ
@[simp] lemma of_real_am_coe : ⇑of_real_am = coe := rfl
/-- `ℝ`-algebra isomorphism version of the complex conjugation function from `ℂ` to `ℂ` -/
def conj_ae : ℂ ≃ₐ[ℝ] ℂ :=
{ inv_fun := conj,
left_inv := star_star,
right_inv := star_star,
commutes' := conj_of_real,
.. conj }
@[simp] lemma conj_ae_coe : ⇑conj_ae = conj := rfl
section lift
variables {A : Type*} [ring A] [algebra ℝ A]
/-- There is an alg_hom from `ℂ` to any `ℝ`-algebra with an element that squares to `-1`.
See `complex.lift` for this as an equiv. -/
def lift_aux (I' : A) (hf : I' * I' = -1) : ℂ →ₐ[ℝ] A :=
alg_hom.of_linear_map
((algebra.of_id ℝ A).to_linear_map.comp re_lm + (linear_map.to_span_singleton _ _ I').comp im_lm)
(show algebra_map ℝ A 1 + (0 : ℝ) • I' = 1,
by rw [ring_hom.map_one, zero_smul, add_zero])
(λ ⟨x₁, y₁⟩ ⟨x₂, y₂⟩, show algebra_map ℝ A (x₁ * x₂ - y₁ * y₂) + (x₁ * y₂ + y₁ * x₂) • I'
= (algebra_map ℝ A x₁ + y₁ • I') * (algebra_map ℝ A x₂ + y₂ • I'),
begin
rw [add_mul, mul_add, mul_add, add_comm _ (y₁ • I' * y₂ • I'), add_add_add_comm],
congr' 1, -- equate "real" and "imaginary" parts
{ rw [smul_mul_smul, hf, smul_neg, ←algebra.algebra_map_eq_smul_one, ←sub_eq_add_neg,
←ring_hom.map_mul, ←ring_hom.map_sub], },
{ rw [algebra.smul_def, algebra.smul_def, algebra.smul_def, ←algebra.right_comm _ x₂,
←mul_assoc, ←add_mul, ←ring_hom.map_mul, ←ring_hom.map_mul, ←ring_hom.map_add] }
end)
@[simp]
lemma lift_aux_apply (I' : A) (hI') (z : ℂ) :
lift_aux I' hI' z = algebra_map ℝ A z.re + z.im • I' := rfl
lemma lift_aux_apply_I (I' : A) (hI') : lift_aux I' hI' I = I' := by simp
/-- A universal property of the complex numbers, providing a unique `ℂ →ₐ[ℝ] A` for every element
of `A` which squares to `-1`.
This can be used to embed the complex numbers in the `quaternion`s.
This isomorphism is named to match the very similar `zsqrtd.lift`. -/
@[simps {simp_rhs := tt}]
def lift : {I' : A // I' * I' = -1} ≃ (ℂ →ₐ[ℝ] A) :=
{ to_fun := λ I', lift_aux I' I'.prop,
inv_fun := λ F, ⟨F I, by rw [←F.map_mul, I_mul_I, alg_hom.map_neg, alg_hom.map_one]⟩,
left_inv := λ I', subtype.ext $ lift_aux_apply_I I' I'.prop,
right_inv := λ F, alg_hom_ext $ lift_aux_apply_I _ _, }
/- When applied to `complex.I` itself, `lift` is the identity. -/
@[simp]
lemma lift_aux_I : lift_aux I I_mul_I = alg_hom.id ℝ ℂ :=
alg_hom_ext $ lift_aux_apply_I _ _
/- When applied to `-complex.I`, `lift` is conjugation, `conj`. -/
@[simp]
lemma lift_aux_neg_I : lift_aux (-I) ((neg_mul_neg _ _).trans I_mul_I) = conj_ae :=
alg_hom_ext $ (lift_aux_apply_I _ _).trans conj_I.symm
end lift
end complex
|
92136770a4dff6254330da41f0d7c497eb2b900f | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/category/Module/kernels.lean | cb462c024eb36b2f591720ead10d1085fec0e350 | [
"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 | 4,172 | lean | /-
Copyright (c) 2020 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import algebra.category.Module.epi_mono
/-!
# The concrete (co)kernels in the category of modules are (co)kernels in the categorical sense.
-/
open category_theory
open category_theory.limits
open category_theory.limits.walking_parallel_pair
universes u v
namespace Module
variables {R : Type u} [ring R]
section
variables {M N : Module.{v} R} (f : M ⟶ N)
/-- The kernel cone induced by the concrete kernel. -/
def kernel_cone : kernel_fork f :=
kernel_fork.of_ι (as_hom f.ker.subtype) $ by tidy
/-- The kernel of a linear map is a kernel in the categorical sense. -/
def kernel_is_limit : is_limit (kernel_cone f) :=
fork.is_limit.mk _
(λ s, linear_map.cod_restrict f.ker (fork.ι s) (λ c, linear_map.mem_ker.2 $
by { rw [←@function.comp_apply _ _ _ f (fork.ι s) c, ←coe_comp, fork.condition,
has_zero_morphisms.comp_zero (fork.ι s) N], refl }))
(λ s, linear_map.subtype_comp_cod_restrict _ _ _)
(λ s m h, linear_map.ext $ λ x, subtype.ext_iff_val.2 $
have h₁ : (m ≫ (kernel_cone f).π.app zero).to_fun = (s.π.app zero).to_fun,
by { congr, exact h zero },
by convert @congr_fun _ _ _ _ h₁ x )
/-- The cokernel cocone induced by the projection onto the quotient. -/
def cokernel_cocone : cokernel_cofork f :=
cokernel_cofork.of_π (as_hom f.range.mkq) $ linear_map.range_mkq_comp _
/-- The projection onto the quotient is a cokernel in the categorical sense. -/
def cokernel_is_colimit : is_colimit (cokernel_cocone f) :=
cofork.is_colimit.mk _
(λ s, f.range.liftq (cofork.π s) $ linear_map.range_le_ker_iff.2 $ cokernel_cofork.condition s)
(λ s, f.range.liftq_mkq (cofork.π s) _)
(λ s m h,
begin
haveI : epi (as_hom f.range.mkq) := (epi_iff_range_eq_top _).mpr (submodule.range_mkq _),
apply (cancel_epi (as_hom f.range.mkq)).1,
convert h walking_parallel_pair.one,
exact submodule.liftq_mkq _ _ _
end)
end
/-- The category of R-modules has kernels, given by the inclusion of the kernel submodule. -/
lemma has_kernels_Module : has_kernels (Module R) :=
⟨λ X Y f, has_limit.mk ⟨_, kernel_is_limit f⟩⟩
/-- The category or R-modules has cokernels, given by the projection onto the quotient. -/
lemma has_cokernels_Module : has_cokernels (Module R) :=
⟨λ X Y f, has_colimit.mk ⟨_, cokernel_is_colimit f⟩⟩
open_locale Module
local attribute [instance] has_kernels_Module
local attribute [instance] has_cokernels_Module
variables {G H : Module.{v} R} (f : G ⟶ H)
/--
The categorical kernel of a morphism in `Module`
agrees with the usual module-theoretical kernel.
-/
noncomputable def kernel_iso_ker {G H : Module.{v} R} (f : G ⟶ H) :
kernel f ≅ Module.of R (f.ker) :=
limit.iso_limit_cone ⟨_, kernel_is_limit f⟩
-- We now show this isomorphism commutes with the inclusion of the kernel into the source.
@[simp, elementwise] lemma kernel_iso_ker_inv_kernel_ι :
(kernel_iso_ker f).inv ≫ kernel.ι f = f.ker.subtype :=
limit.iso_limit_cone_inv_π _ _
@[simp, elementwise] lemma kernel_iso_ker_hom_ker_subtype :
(kernel_iso_ker f).hom ≫ f.ker.subtype = kernel.ι f :=
is_limit.cone_point_unique_up_to_iso_inv_comp _ (limit.is_limit _) zero
/--
The categorical cokernel of a morphism in `Module`
agrees with the usual module-theoretical quotient.
-/
noncomputable def cokernel_iso_range_quotient {G H : Module.{v} R} (f : G ⟶ H) :
cokernel f ≅ Module.of R (f.range.quotient) :=
colimit.iso_colimit_cocone ⟨_, cokernel_is_colimit f⟩
-- We now show this isomorphism commutes with the projection of target to the cokernel.
@[simp, elementwise] lemma cokernel_π_cokernel_iso_range_quotient_hom :
cokernel.π f ≫ (cokernel_iso_range_quotient f).hom = f.range.mkq :=
by { convert colimit.iso_colimit_cocone_ι_hom _ _; refl, }
@[simp, elementwise] lemma range_mkq_cokernel_iso_range_quotient_inv :
↿f.range.mkq ≫ (cokernel_iso_range_quotient f).inv = cokernel.π f :=
by { convert colimit.iso_colimit_cocone_ι_inv ⟨_, cokernel_is_colimit f⟩ _; refl, }
end Module
|
c6aa077dca92d5826bccfa5b2d273634aad6c058 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/group_theory/finiteness.lean | a8a109cd90b0e0acb9c7f4d3172e77f1f7695be6 | [
"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 | 15,193 | 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.pointwise.finite
import group_theory.quotient_group
import group_theory.submonoid.operations
import group_theory.subgroup.basic
import set_theory.cardinal.finite
import data.finset.preimage
/-!
# 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 ‹_›
@[to_additive, priority 100]
instance monoid.fg_of_finite [finite M] : monoid.fg M :=
by { casesI nonempty_fintype M,
exact ⟨⟨finset.univ, by rw finset.coe_univ; exact submonoid.closure_univ⟩⟩ }
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]
instance monoid.fg_range {M' : Type*} [monoid M'] [monoid.fg M] (f : M →* M') :
monoid.fg f.mrange :=
monoid.fg_of_surjective f.mrange_restrict f.mrange_restrict_surjective
@[to_additive add_submonoid.multiples_fg]
lemma submonoid.powers_fg (r : M) : (submonoid.powers r).fg :=
⟨{r}, (finset.coe_singleton r).symm ▸ (submonoid.powers_eq_closure r).symm⟩
@[to_additive add_monoid.multiples_fg]
instance monoid.powers_fg (r : M) : monoid.fg (submonoid.powers r) :=
(monoid.fg_iff_submonoid_fg _).mpr (submonoid.powers_fg r)
@[to_additive] instance monoid.closure_finset_fg (s : finset M) :
monoid.fg (submonoid.closure (s : set M)) :=
begin
refine ⟨⟨s.preimage coe (subtype.coe_injective.inj_on _), _⟩⟩,
rw [finset.coe_preimage, submonoid.closure_closure_coe_preimage],
end
@[to_additive] instance monoid.closure_finite_fg (s : set M) [finite s] :
monoid.fg (submonoid.closure s) :=
begin
haveI := fintype.of_finite s,
exact s.coe_to_finset ▸ monoid.closure_finset_fg s.to_finset,
end
/-! ### 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⟩⟩
@[to_additive] lemma group.fg_iff' :
group.fg G ↔ ∃ n (S : finset G), S.card = n ∧ subgroup.closure (S : set G) = ⊤ :=
group.fg_def.trans ⟨λ ⟨S, hS⟩, ⟨S.card, S, rfl, hS⟩, λ ⟨n, S, hn, hS⟩, ⟨S, hS⟩⟩
/-- 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 ‹_›
@[to_additive, priority 100]
instance group.fg_of_finite [finite G] : group.fg G :=
by { casesI nonempty_fintype G,
exact ⟨⟨finset.univ, by rw finset.coe_univ; exact subgroup.closure_univ⟩⟩ }
@[to_additive]
lemma group.fg_of_surjective {G' : Type*} [group G'] [hG : group.fg G] {f : G →* G'}
(hf : function.surjective f) : group.fg G' :=
group.fg_iff_monoid.fg.mpr $ @monoid.fg_of_surjective G _ G' _ (group.fg_iff_monoid.fg.mp hG) f hf
@[to_additive]
instance group.fg_range {G' : Type*} [group G'] [group.fg G] (f : G →* G') : group.fg f.range :=
group.fg_of_surjective f.range_restrict_surjective
@[to_additive] instance group.closure_finset_fg (s : finset G) :
group.fg (subgroup.closure (s : set G)) :=
begin
refine ⟨⟨s.preimage coe (subtype.coe_injective.inj_on _), _⟩⟩,
rw [finset.coe_preimage, ←subgroup.coe_subtype, subgroup.closure_preimage_eq_top],
end
@[to_additive] instance group.closure_finite_fg (s : set G) [finite s] :
group.fg (subgroup.closure s) :=
begin
haveI := fintype.of_finite s,
exact s.coe_to_finset ▸ group.closure_finset_fg s.to_finset,
end
variables (G)
/-- The minimum number of generators of a group. -/
@[to_additive "The minimum number of generators of an additive group"]
noncomputable def group.rank [h : group.fg G] :=
@nat.find _ (classical.dec_pred _) (group.fg_iff'.mp h)
@[to_additive] lemma group.rank_spec [h : group.fg G] :
∃ S : finset G, S.card = group.rank G ∧ subgroup.closure (S : set G) = ⊤ :=
@nat.find_spec _ (classical.dec_pred _) (group.fg_iff'.mp h)
@[to_additive] lemma group.rank_le [h : group.fg G]
{S : finset G} (hS : subgroup.closure (S : set G) = ⊤) : group.rank G ≤ S.card :=
@nat.find_le _ _ (classical.dec_pred _) (group.fg_iff'.mp h) ⟨S, rfl, hS⟩
variables {G} {G' : Type*} [group G']
@[to_additive] lemma group.rank_le_of_surjective [group.fg G] [group.fg G'] (f : G →* G')
(hf : function.surjective f) : group.rank G' ≤ group.rank G :=
begin
classical,
obtain ⟨S, hS1, hS2⟩ := group.rank_spec G,
transitivity (S.image f).card,
{ apply group.rank_le,
rw [finset.coe_image, ←monoid_hom.map_closure, hS2, subgroup.map_top_of_surjective f hf] },
{ exact finset.card_image_le.trans_eq hS1 },
end
@[to_additive] lemma group.rank_range_le [group.fg G] {f : G →* G'} :
group.rank f.range ≤ group.rank G :=
group.rank_le_of_surjective f.range_restrict f.range_restrict_surjective
@[to_additive] lemma group.rank_congr [group.fg G] [group.fg G'] (f : G ≃* G') :
group.rank G = group.rank G' :=
le_antisymm (group.rank_le_of_surjective f.symm f.symm.surjective)
(group.rank_le_of_surjective f f.surjective)
end group
namespace subgroup
@[to_additive] lemma rank_congr {H K : subgroup G} [group.fg H] [group.fg K] (h : H = K) :
group.rank H = group.rank K :=
by unfreezingI { subst h }
@[to_additive] lemma rank_closure_finset_le_card (s : finset G) :
group.rank (closure (s : set G)) ≤ s.card :=
begin
classical,
let t : finset (closure (s : set G)) := s.preimage coe (subtype.coe_injective.inj_on _),
have ht : closure (t : set (closure (s : set G))) = ⊤,
{ rw finset.coe_preimage,
exact closure_preimage_eq_top s },
apply (group.rank_le (closure (s : set G)) ht).trans,
rw [←finset.card_image_of_inj_on, finset.image_preimage],
{ apply finset.card_filter_le },
{ apply subtype.coe_injective.inj_on },
end
@[to_additive] lemma rank_closure_finite_le_nat_card (s : set G) [finite s] :
group.rank (closure s) ≤ nat.card s :=
begin
haveI := fintype.of_finite s,
rw [nat.card_eq_fintype_card, ←s.to_finset_card, ←rank_congr (congr_arg _ s.coe_to_finset)],
exact rank_closure_finset_le_card s.to_finset,
end
end subgroup
section quotient_group
@[to_additive]
instance quotient_group.fg [group.fg G] (N : subgroup G) [subgroup.normal N] : group.fg $ G ⧸ N :=
group.fg_of_surjective $ quotient_group.mk'_surjective N
end quotient_group
|
b91c923f6b9b67608a690497825cf236c752e73b | d7c0dac4019ec4c77a89fd6d3e672674a3cad8f8 | /Chain_Of_Reasoning.lean | 9f4b3b019a5d394ac70e63a45a3498e37abd84ef | [] | no_license | TudorTitan/Lean_ElementaryNT | 97fb78afaa07822c9ee0f563e263e16536b28638 | e9fa9e1db315fa7aca88666aee9910d5d9d34a11 | refs/heads/master | 1,630,895,651,127 | 1,517,510,995,000 | 1,517,510,995,000 | 108,649,763 | 0 | 1 | null | 1,509,757,816,000 | 1,509,195,975,000 | Lean | UTF-8 | Lean | false | false | 6,780 | lean | constants a b c: int
constants x y z m: nat
constant modus_ponens {p q : Prop} : implies p q → p → q
-- a congruent to b modulo m
def cong (a:int) (b: int) (m: int): Prop := ∃ x: int, a-b = m*x
-- p is prime
def is_prime (p:nat): Prop := ∀ x y: int, cong (x*y) 0 p → cong x 0 p ∨ cong y 0 p
-- f is the floor of a/b
def floor (a:int) (b:int) (f:int): Prop := (f*b ≤ a ∧ ∀ y: int, y*b ≤ a → y≤f)
-- g is the gcd of a and b
def gcd (a:int) (b:int) (g:int): Prop := g > 0 ∧ cong a 0 g ∧ cong b 0 g ∧
(∀ y:nat, cong a 0 y ∧ cong b 0 y → g ≥ y)
-- Solution to linear diophantine equation with constants a b k
def LDE (a:int) (b:int) (k:int): Prop := ∃ x y: int, a*x + b*y = k
-- existence of floor, gcd, and a solution to LDEs.
axiom Efloor (a: int) (b:int): ∃ x:int, floor a b x
axiom Egcd (a:int) (b: int): ∃ x: nat, gcd a b x
axiom ELDE (a:int) (b: int): ∃ k: int, LDE a b k ∧ k > 0 ∧ (∀ y: int, LDE a b y → y ≥ k)
-- All of the above can be proven from Wop, but are temporarily axiomatised
axiom WOP {k: nat} (p:nat → Prop) (H: p k): ∃ n: nat, p n ∧ (∀ y:nat, p y → y ≥ x)
--
-- Division algorithm
theorem DivAlgo (a : int) (b : int): ∃ q r : int, a = b*q + r ∧ 0 ≤ r ∧ b > r :=
begin
have Q: ∃ q r: int, a = b*q + r ∧ 0 ≤ r ∧ b > r,
from exists.elim (Efloor a b) (fun (x:int) (H: x*b ≤ a ∧ ∀ y: int, y*b ≤ a → y≤x),
have Hl: x*b ≤ a, from and.elim_left H,
have Hr: ∀ y: int, y*b ≤ a → y≤x, from and.elim_right H,
have L1: 0 = b*x - b*x, from eq.symm (sub_eq_zero_of_eq (eq.refl (b*x))),
have G1: a = b*x + (a-x*b), from calc
a = 0 + a: eq.symm (zero_add a)
... = b*x - b*x + a: by rw [L1]
... = b*x - x*b + a: by rw [mul_comm]
... = b*x + a - x*b: sub_add_eq_add_sub (b*x) (x*b) a
... = b*x + (a - x*b): add_sub_assoc (b*x) a (x*b),
have G2: 0 ≤ (a - x*b), from sub_nonneg_of_le Hl,
have Trich: b ≤ (a - x*b) ∨ b > (a - x*b), from le_or_gt b (a - x*b),
have G3: b > (a - x*b), from or.cases_on Trich
(assume ass: b ≤ (a - x*b),
have L2: a ≥ b + x*b, from add_le_of_le_sub_right ass,
have L3: b + (x*b) = 1*b + (x*b), from by rw [one_mul],
have L4: (x+1)*b = (1+x)*b, from by rw [add_comm],
have C: (x+1)*b ≤ a, from calc
a ≥ b + (x*b) : L2
... ≥ 1*b + (x*b): le_of_eq (eq.symm L3)
... ≥ (1+x)*b : le_of_eq (add_mul 1 x b)
... ≥ (x+1)*b : le_of_eq L4,
have F: x+1 ≤ x, from Hr (x+1) C,
have T: x+1 > x, from int.lt_add_one_of_le (le_of_eq (eq.refl x)),
have will: b > (a - x*b), from absurd F (not_le_of_gt T),
will)
(assume ass: b > (a - x*b),
ass),
have final: ∃ q r: int, a = b*q + r ∧ 0 ≤ r ∧ b > r,
from exists.intro x (exists.intro (a - x*b) (and.intro G1 (and.intro G2 G3))),
final),
exact Q
end
--Lemma for proving that Z is a principal ideal domain later on
lemma LDEsimp {a b p :int} (W1: (LDE a b p ∧ p > 0) ∧ (∀ (q: int), LDE a b q → q ≥ p)) : cong a 0 p:=
begin
exact exists.elim (and.elim_left (and.elim_left W1))
(fun (x : int) (W2: ∃ y:int, a*x + b*y = p),
exists.elim W2
(fun (y : int) (W3: a*x + b*y = p),
have App: ∃ m n: int, a = p*m + n ∧ 0 ≤ n ∧ p > n, from DivAlgo a p,
exists.elim (App)
(fun (m : int) (D1: ∃ n: int, a = p*m + n ∧ 0 ≤ n ∧ p > n),
exists.elim D1
(fun (n : int) (D: a = p*m + n ∧ (0 ≤ n ∧ p > n)),
have Ntest: 0 ≤ n, from and.elim_left (and.elim_right D),
have UB: p > n, from and.elim_right (and.elim_right D),
have A1: a = p*m + n, from and.elim_left D,
have A2: a = (a*x + b*y)*m + n, from eq.subst (eq.symm W3) A1,
have A3: n = a - (a*x + b*y)*m, from eq_sub_of_add_eq' (eq.symm A2),
have A: a*(1-x*m) + b*(-(y*m)) = n, from eq.symm (calc
n = a - (a*x + b*y)*m : A3
... = a - (a*x*m + b*y*m) : by rw [add_mul (a*x) (b*y) m]
... = a - a*x*m - b*y*m : sub_add_eq_sub_sub a (a*x*m) (b*y*m)
... = a*1 - a*x*m - b*y*m : by rw [mul_one]
... = a*1 - a*(x*m) - b*y*m : by rw [mul_assoc]
... = a*(1 - x*m) - (b*y*m) : by rw [eq.symm (mul_sub a 1 (x*m))]
... = a*(1-x*m) + -(b*y*m) : by rw [sub_eq_add_neg]
... = a*(1-x*m) + -(b*(y*m)) : by rw [mul_assoc]
... = a*(1-x*m) + b*(-(y*m)) : by rw [neg_mul_eq_mul_neg]
),
have Z1: n = 0, from or.by_cases (lt_or_eq_of_le Ntest)
(assume H1: n > 0,
have C0: LDE a b n, from exists.intro (1-x*m) (exists.intro (-(y*m)) A),
have C1: ∀ q: int, LDE a b q → q ≥ p, from (and.elim_right W1),
have C2: n ≥ p, from C1 n C0,
have C4: ¬ n < p, from not_lt_of_ge C2,
have E: n = 0, from absurd UB C4,
E)
(assume H: 0 = n,
eq.symm H),
have P1: a = (p*m) + 0, from eq.subst Z1 A1,
have P2: a = (p*m), from calc a = (p*m) + 0 : P1 ... = (p*m) : by rw [add_zero],
have P3: a - 0 = p*m, from eq.trans (sub_zero a) P2,
have P4: cong a 0 p, from exists.intro m P3,
P4
)
)
)
)
end
--WIP
lemma LDEcomm (a: int) (b: int) (p: int) : LDE a b p ↔ LDE b a p :=
begin
have H:LDE a b p ↔ LDE b a p, from sorry,
exact H
end
theorem IntegersFormPID (a : int) (b : int): ∃ g:int, LDE a b g ∧ gcd a b g :=
begin
have H1: ∃ g:int, LDE a b g ∧ gcd a b g, from exists.elim (ELDE a b)
(fun (p:int) (W1: (LDE a b p ∧ p > 0) ∧ (∀ q: int, LDE a b q → q ≥ p)),
have H: cong a 0 p, from LDEsimp W1,
have W11: LDE a b p, from (and.elim_left (and.elim_left W1)),
have W12: LDE b a p, from iff.elim_left (LDEcomm a b p) W11,
have W2: p > 0, from and.elim_right (and.elim_left W1),
have W31: LDE a b p → LDE b a p, from iff.elim_left (LDEcomm a b p),
have W3: (∀ q: int, LDE b a q → q ≥ p), from iff_subst (LDEcomm a b p) (and.elim_right (and.elim_right W1)),
have W2: (LDE b a p ∧ p > 0) ∧ (∀ q: int, LDE b a q → q ≥ p), from iff_subst (LDEcomm a b p) W1,
have Hb: cong b 0 p, from LDEsimp W1,
)
end
|
359599f988ebd94e83434b9dc3a97807cc58e098 | 4950bf76e5ae40ba9f8491647d0b6f228ddce173 | /src/data/list/defs.lean | 406dd0c2c3e40d7c33d36d8a26cc7ff048c77f9c | [
"Apache-2.0"
] | permissive | ntzwq/mathlib | ca50b21079b0a7c6781c34b62199a396dd00cee2 | 36eec1a98f22df82eaccd354a758ef8576af2a7f | refs/heads/master | 1,675,193,391,478 | 1,607,822,996,000 | 1,607,822,996,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 32,115 | lean | /-
Copyright (c) 2014 Parikshit Khanna. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Parikshit Khanna, Jeremy Avigad, Leonardo de Moura, Floris van Doorn, Mario Carneiro
-/
import data.option.defs
import logic.basic
import tactic.cache
/-!
## Definitions on lists
This file contains various definitions on lists. It does not contain
proofs about these definitions, those are contained in other files in `data/list`
-/
namespace list
open function nat
universes u v w x
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type x}
/-- Returns whether a list is []. Returns a boolean even if `l = []` is not decidable. -/
def is_nil {α} : list α → bool
| [] := tt
| _ := ff
instance [decidable_eq α] : has_sdiff (list α) :=
⟨ list.diff ⟩
/-- Split a list at an index.
split_at 2 [a, b, c] = ([a, b], [c]) -/
def split_at : ℕ → list α → list α × list α
| 0 a := ([], a)
| (succ n) [] := ([], [])
| (succ n) (x :: xs) := let (l, r) := split_at n xs in (x :: l, r)
/-- An auxiliary function for `split_on_p`. -/
def split_on_p_aux {α : Type u} (P : α → Prop) [decidable_pred P] :
list α → (list α → list α) → list (list α)
| [] f := [f []]
| (h :: t) f :=
if P h then f [] :: split_on_p_aux t id
else split_on_p_aux t (λ l, f (h :: l))
/-- Split a list at every element satisfying a predicate. -/
def split_on_p {α : Type u} (P : α → Prop) [decidable_pred P] (l : list α) : list (list α) :=
split_on_p_aux P l id
/-- Split a list at every occurrence of an element.
[1,1,2,3,2,4,4].split_on 2 = [[1,1],[3],[4,4]] -/
def split_on {α : Type u} [decidable_eq α] (a : α) (as : list α) : list (list α) :=
as.split_on_p (=a)
/-- Concatenate an element at the end of a list.
concat [a, b] c = [a, b, c] -/
@[simp] def concat : list α → α → list α
| [] a := [a]
| (b::l) a := b :: concat l a
/-- `head' xs` returns the first element of `xs` if `xs` is non-empty;
it returns `none` otherwise -/
@[simp] def head' : list α → option α
| [] := none
| (a :: l) := some a
/-- Convert a list into an array (whose length is the length of `l`). -/
def to_array (l : list α) : array l.length α :=
{data := λ v, l.nth_le v.1 v.2}
/-- "inhabited" `nth` function: returns `default` instead of `none` in the case
that the index is out of bounds. -/
@[simp] def inth [h : inhabited α] (l : list α) (n : nat) : α := (nth l n).iget
/-- Apply a function to the nth tail of `l`. Returns the input without
using `f` if the index is larger than the length of the list.
modify_nth_tail f 2 [a, b, c] = [a, b] ++ f [c] -/
@[simp] def modify_nth_tail (f : list α → list α) : ℕ → list α → list α
| 0 l := f l
| (n+1) [] := []
| (n+1) (a::l) := a :: modify_nth_tail n l
/-- Apply `f` to the head of the list, if it exists. -/
@[simp] def modify_head (f : α → α) : list α → list α
| [] := []
| (a::l) := f a :: l
/-- Apply `f` to the nth element of the list, if it exists. -/
def modify_nth (f : α → α) : ℕ → list α → list α :=
modify_nth_tail (modify_head f)
/-- Apply `f` to the last element of `l`, if it exists. -/
@[simp] def modify_last (f : α → α) : list α → list α
| [] := []
| [x] := [f x]
| (x :: xs) := x :: modify_last xs
/-- `insert_nth n a l` inserts `a` into the list `l` after the first `n` elements of `l`
`insert_nth 2 1 [1, 2, 3, 4] = [1, 2, 1, 3, 4]`-/
def insert_nth (n : ℕ) (a : α) : list α → list α := modify_nth_tail (list.cons a) n
section take'
variable [inhabited α]
/-- Take `n` elements from a list `l`. If `l` has less than `n` elements, append `n - length l`
elements `default α`. -/
def take' : ∀ n, list α → list α
| 0 l := []
| (n+1) l := l.head :: take' n l.tail
end take'
/-- Get the longest initial segment of the list whose members all satisfy `p`.
take_while (λ x, x < 3) [0, 2, 5, 1] = [0, 2] -/
def take_while (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then a :: take_while l else []
/-- Fold a function `f` over the list from the left, returning the list
of partial results.
scanl (+) 0 [1, 2, 3] = [0, 1, 3, 6] -/
def scanl (f : α → β → α) : α → list β → list α
| a [] := [a]
| a (b::l) := a :: scanl (f a b) l
/-- Auxiliary definition used to define `scanr`. If `scanr_aux f b l = (b', l')`
then `scanr f b l = b' :: l'` -/
def scanr_aux (f : α → β → β) (b : β) : list α → β × list β
| [] := (b, [])
| (a::l) := let (b', l') := scanr_aux l in (f a b', b' :: l')
/-- Fold a function `f` over the list from the right, returning the list
of partial results.
scanr (+) 0 [1, 2, 3] = [6, 5, 3, 0] -/
def scanr (f : α → β → β) (b : β) (l : list α) : list β :=
let (b', l') := scanr_aux f b l in b' :: l'
/-- Product of a list.
prod [a, b, c] = ((1 * a) * b) * c -/
def prod [has_mul α] [has_one α] : list α → α := foldl (*) 1
/-- Sum of a list.
sum [a, b, c] = ((0 + a) + b) + c -/
-- Later this will be tagged with `to_additive`, but this can't be done yet because of import
-- dependencies.
def sum [has_add α] [has_zero α] : list α → α := foldl (+) 0
/-- The alternating sum of a list. -/
def alternating_sum {G : Type*} [has_zero G] [has_add G] [has_neg G] : list G → G
| [] := 0
| (g :: []) := g
| (g :: h :: t) := g + -h + alternating_sum t
/-- The alternating product of a list. -/
def alternating_prod {G : Type*} [has_one G] [has_mul G] [has_inv G] : list G → G
| [] := 1
| (g :: []) := g
| (g :: h :: t) := g * h⁻¹ * alternating_prod t
/-- Given a function `f : α → β ⊕ γ`, `partition_map f l` maps the list by `f`
whilst partitioning the result it into a pair of lists, `list β × list γ`,
partitioning the `sum.inl _` into the left list, and the `sum.inr _` into the right list.
`partition_map (id : ℕ ⊕ ℕ → ℕ ⊕ ℕ) [inl 0, inr 1, inl 2] = ([0,2], [1])` -/
def partition_map (f : α → β ⊕ γ) : list α → list β × list γ
| [] := ([],[])
| (x::xs) :=
match f x with
| (sum.inr r) := prod.map id (cons r) $ partition_map xs
| (sum.inl l) := prod.map (cons l) id $ partition_map xs
end
/-- `find p l` is the first element of `l` satisfying `p`, or `none` if no such
element exists. -/
def find (p : α → Prop) [decidable_pred p] : list α → option α
| [] := none
| (a::l) := if p a then some a else find l
/-- `mfind tac l` returns the first element of `l` on which `tac` succeeds, and
fails otherwise. -/
def mfind {α} {m : Type u → Type v} [monad m] [alternative m] (tac : α → m punit) : list α → m α :=
list.mfirst $ λ a, tac a $> a
/-- `mbfind' p l` returns the first element `a` of `l` for which `p a` returns
true. `mbfind'` short-circuits, so `p` is not necessarily run on every `a` in
`l`. This is a monadic version of `list.find`. -/
def mbfind' {m : Type u → Type v} [monad m] {α : Type u} (p : α → m (ulift bool)) :
list α → m (option α)
| [] := pure none
| (x :: xs) := do
⟨px⟩ ← p x,
if px then pure (some x) else mbfind' xs
section
variables {m : Type → Type v} [monad m]
/-- A variant of `mbfind'` with more restrictive universe levels. -/
def mbfind {α} (p : α → m bool) (xs : list α) : m (option α) :=
xs.mbfind' (functor.map ulift.up ∘ p)
/-- `many p as` returns true iff `p` returns true for any element of `l`.
`many` short-circuits, so if `p` returns true for any element of `l`, later
elements are not checked. This is a monadic version of `list.any`. -/
-- Implementing this via `mbfind` would give us less universe polymorphism.
def many {α : Type u} (p : α → m bool) : list α → m bool
| [] := pure false
| (x :: xs) := do px ← p x, if px then pure tt else many xs
/-- `mall p as` returns true iff `p` returns true for all elements of `l`.
`mall` short-circuits, so if `p` returns false for any element of `l`, later
elements are not checked. This is a monadic version of `list.all`. -/
def mall {α : Type u} (p : α → m bool) (as : list α) : m bool :=
bnot <$> many (λ a, bnot <$> p a) as
/-- `mbor xs` runs the actions in `xs`, returning true if any of them returns
true. `mbor` short-circuits, so if an action returns true, later actions are
not run. This is a monadic version of `list.bor`. -/
def mbor : list (m bool) → m bool :=
many id
/-- `mband xs` runs the actions in `xs`, returning true if all of them return
true. `mband` short-circuits, so if an action returns false, later actions are
not run. This is a monadic version of `list.band`. -/
def mband : list (m bool) → m bool :=
mall id
end
/-- Auxiliary definition for `foldl_with_index`. -/
def foldl_with_index_aux (f : ℕ → α → β → α) : ℕ → α → list β → α
| _ a [] := a
| i a (b :: l) := foldl_with_index_aux (i + 1) (f i a b) l
/-- Fold a list from left to right as with `foldl`, but the combining function
also receives each element's index. -/
def foldl_with_index (f : ℕ → α → β → α) (a : α) (l : list β) : α :=
foldl_with_index_aux f 0 a l
/-- Auxiliary definition for `foldr_with_index`. -/
def foldr_with_index_aux (f : ℕ → α → β → β) : ℕ → β → list α → β
| _ b [] := b
| i b (a :: l) := f i a (foldr_with_index_aux (i + 1) b l)
/-- Fold a list from right to left as with `foldr`, but the combining function
also receives each element's index. -/
def foldr_with_index (f : ℕ → α → β → β) (b : β) (l : list α) : β :=
foldr_with_index_aux f 0 b l
/-- `find_indexes p l` is the list of indexes of elements of `l` that satisfy `p`. -/
def find_indexes (p : α → Prop) [decidable_pred p] (l : list α) : list nat :=
foldr_with_index (λ i a is, if p a then i :: is else is) [] l
/-- Returns the elements of `l` that satisfy `p` together with their indexes in
`l`. The returned list is ordered by index. -/
def indexes_values (p : α → Prop) [decidable_pred p] (l : list α) : list (ℕ × α) :=
foldr_with_index (λ i a l, if p a then (i , a) :: l else l) [] l
/-- `indexes_of a l` is the list of all indexes of `a` in `l`. For example:
```
indexes_of a [a, b, a, a] = [0, 2, 3]
```
-/
def indexes_of [decidable_eq α] (a : α) : list α → list nat := find_indexes (eq a)
section mfold_with_index
variables {m : Type v → Type w} [monad m]
/-- Monadic variant of `foldl_with_index`. -/
def mfoldl_with_index {α β} (f : ℕ → β → α → m β) (b : β) (as : list α) : m β :=
as.foldl_with_index (λ i ma b, do a ← ma, f i a b) (pure b)
/-- Monadic variant of `foldr_with_index`. -/
def mfoldr_with_index {α β} (f : ℕ → α → β → m β) (b : β) (as : list α) : m β :=
as.foldr_with_index (λ i a mb, do b ← mb, f i a b) (pure b)
end mfold_with_index
section mmap_with_index
variables {m : Type v → Type w} [applicative m]
/-- Auxiliary definition for `mmap_with_index`. -/
def mmap_with_index_aux {α β} (f : ℕ → α → m β) : ℕ → list α → m (list β)
| _ [] := pure []
| i (a :: as) := list.cons <$> f i a <*> mmap_with_index_aux (i + 1) as
/-- Applicative variant of `map_with_index`. -/
def mmap_with_index {α β} (f : ℕ → α → m β) (as : list α) : m (list β) :=
mmap_with_index_aux f 0 as
/-- Auxiliary definition for `mmap_with_index'`. -/
def mmap_with_index'_aux {α} (f : ℕ → α → m punit) : ℕ → list α → m punit
| _ [] := pure ⟨⟩
| i (a :: as) := f i a *> mmap_with_index'_aux (i + 1) as
/-- A variant of `mmap_with_index` specialised to applicative actions which
return `unit`. -/
def mmap_with_index' {α} (f : ℕ → α → m punit) (as : list α) : m punit :=
mmap_with_index'_aux f 0 as
end mmap_with_index
/-- `lookmap` is a combination of `lookup` and `filter_map`.
`lookmap f l` will apply `f : α → option α` to each element of the list,
replacing `a → b` at the first value `a` in the list such that `f a = some b`. -/
def lookmap (f : α → option α) : list α → list α
| [] := []
| (a::l) :=
match f a with
| some b := b :: l
| none := a :: lookmap l
end
/-- `countp p l` is the number of elements of `l` that satisfy `p`. -/
def countp (p : α → Prop) [decidable_pred p] : list α → nat
| [] := 0
| (x::xs) := if p x then succ (countp xs) else countp xs
/-- `count a l` is the number of occurrences of `a` in `l`. -/
def count [decidable_eq α] (a : α) : list α → nat := countp (eq a)
/-- `is_prefix l₁ l₂`, or `l₁ <+: l₂`, means that `l₁` is a prefix of `l₂`,
that is, `l₂` has the form `l₁ ++ t` for some `t`. -/
def is_prefix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, l₁ ++ t = l₂
/-- `is_suffix l₁ l₂`, or `l₁ <:+ l₂`, means that `l₁` is a suffix of `l₂`,
that is, `l₂` has the form `t ++ l₁` for some `t`. -/
def is_suffix (l₁ : list α) (l₂ : list α) : Prop := ∃ t, t ++ l₁ = l₂
/-- `is_infix l₁ l₂`, or `l₁ <:+: l₂`, means that `l₁` is a contiguous
substring of `l₂`, that is, `l₂` has the form `s ++ l₁ ++ t` for some `s, t`. -/
def is_infix (l₁ : list α) (l₂ : list α) : Prop := ∃ s t, s ++ l₁ ++ t = l₂
infix ` <+: `:50 := is_prefix
infix ` <:+ `:50 := is_suffix
infix ` <:+: `:50 := is_infix
/-- `inits l` is the list of initial segments of `l`.
inits [1, 2, 3] = [[], [1], [1, 2], [1, 2, 3]] -/
@[simp] def inits : list α → list (list α)
| [] := [[]]
| (a::l) := [] :: map (λt, a::t) (inits l)
/-- `tails l` is the list of terminal segments of `l`.
tails [1, 2, 3] = [[1, 2, 3], [2, 3], [3], []] -/
@[simp] def tails : list α → list (list α)
| [] := [[]]
| (a::l) := (a::l) :: tails l
def sublists'_aux : list α → (list α → list β) → list (list β) → list (list β)
| [] f r := f [] :: r
| (a::l) f r := sublists'_aux l f (sublists'_aux l (f ∘ cons a) r)
/-- `sublists' l` is the list of all (non-contiguous) sublists of `l`.
It differs from `sublists` only in the order of appearance of the sublists;
`sublists'` uses the first element of the list as the MSB,
`sublists` uses the first element of the list as the LSB.
sublists' [1, 2, 3] = [[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]] -/
def sublists' (l : list α) : list (list α) :=
sublists'_aux l id []
def sublists_aux : list α → (list α → list β → list β) → list β
| [] f := []
| (a::l) f := f [a] (sublists_aux l (λys r, f ys (f (a :: ys) r)))
/-- `sublists l` is the list of all (non-contiguous) sublists of `l`; cf. `sublists'`
for a different ordering.
sublists [1, 2, 3] = [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]] -/
def sublists (l : list α) : list (list α) :=
[] :: sublists_aux l cons
def sublists_aux₁ : list α → (list α → list β) → list β
| [] f := []
| (a::l) f := f [a] ++ sublists_aux₁ l (λys, f ys ++ f (a :: ys))
section forall₂
variables {r : α → β → Prop} {p : γ → δ → Prop}
/-- `forall₂ R l₁ l₂` means that `l₁` and `l₂` have the same length,
and whenever `a` is the nth element of `l₁`, and `b` is the nth element of `l₂`,
then `R a b` is satisfied. -/
inductive forall₂ (R : α → β → Prop) : list α → list β → Prop
| nil : forall₂ [] []
| cons {a b l₁ l₂} : R a b → forall₂ l₁ l₂ → forall₂ (a::l₁) (b::l₂)
attribute [simp] forall₂.nil
end forall₂
/-- Auxiliary definition used to define `transpose`.
`transpose_aux l L` takes each element of `l` and appends it to the start of
each element of `L`.
`transpose_aux [a, b, c] [l₁, l₂, l₃] = [a::l₁, b::l₂, c::l₃]` -/
def transpose_aux : list α → list (list α) → list (list α)
| [] ls := ls
| (a::i) [] := [a] :: transpose_aux i []
| (a::i) (l::ls) := (a::l) :: transpose_aux i ls
/-- transpose of a list of lists, treated as a matrix.
transpose [[1, 2], [3, 4], [5, 6]] = [[1, 3, 5], [2, 4, 6]] -/
def transpose : list (list α) → list (list α)
| [] := []
| (l::ls) := transpose_aux l (transpose ls)
/-- List of all sections through a list of lists. A section
of `[L₁, L₂, ..., Lₙ]` is a list whose first element comes from
`L₁`, whose second element comes from `L₂`, and so on. -/
def sections : list (list α) → list (list α)
| [] := [[]]
| (l::L) := bind (sections L) $ λ s, map (λ a, a::s) l
section permutations
def permutations_aux2 (t : α) (ts : list α) (r : list β) : list α → (list α → β) → list α × list β
| [] f := (ts, r)
| (y::ys) f := let (us, zs) := permutations_aux2 ys (λx : list α, f (y::x)) in
(y :: us, f (t :: y :: us) :: zs)
private def meas : (Σ'_:list α, list α) → ℕ × ℕ | ⟨l, i⟩ := (length l + length i, length l)
local infix ` ≺ `:50 := inv_image (prod.lex (<) (<)) meas
@[elab_as_eliminator] def permutations_aux.rec {C : list α → list α → Sort v}
(H0 : ∀ is, C [] is)
(H1 : ∀ t ts is, C ts (t::is) → C is [] → C (t::ts) is) : ∀ l₁ l₂, C l₁ l₂
| [] is := H0 is
| (t::ts) is :=
have h1 : ⟨ts, t :: is⟩ ≺ ⟨t :: ts, is⟩, from
show prod.lex _ _ (succ (length ts + length is), length ts) (succ (length ts) + length is,
length (t :: ts)),
by rw nat.succ_add; exact prod.lex.right _ (lt_succ_self _),
have h2 : ⟨is, []⟩ ≺ ⟨t :: ts, is⟩, from prod.lex.left _ _ (nat.lt_add_of_pos_left (succ_pos _)),
H1 t ts is (permutations_aux.rec ts (t::is)) (permutations_aux.rec is [])
using_well_founded {
dec_tac := tactic.assumption,
rel_tac := λ _ _, `[exact ⟨(≺), @inv_image.wf _ _ _ meas (prod.lex_wf lt_wf lt_wf)⟩] }
def permutations_aux : list α → list α → list (list α) :=
@@permutations_aux.rec (λ _ _, list (list α)) (λ is, [])
(λ t ts is IH1 IH2, foldr (λy r, (permutations_aux2 t ts r y id).2) IH1 (is :: IH2))
/-- List of all permutations of `l`.
permutations [1, 2, 3] =
[[1, 2, 3], [2, 1, 3], [3, 2, 1],
[2, 3, 1], [3, 1, 2], [1, 3, 2]] -/
def permutations (l : list α) : list (list α) :=
l :: permutations_aux l []
end permutations
/-- `erasep p l` removes the first element of `l` satisfying the predicate `p`. -/
def erasep (p : α → Prop) [decidable_pred p] : list α → list α
| [] := []
| (a::l) := if p a then l else a :: erasep l
/-- `extractp p l` returns a pair of an element `a` of `l` satisfying the predicate
`p`, and `l`, with `a` removed. If there is no such element `a` it returns `(none, l)`. -/
def extractp (p : α → Prop) [decidable_pred p] : list α → option α × list α
| [] := (none, [])
| (a::l) := if p a then (some a, l) else
let (a', l') := extractp l in (a', a :: l')
/-- `revzip l` returns a list of pairs of the elements of `l` paired
with the elements of `l` in reverse order.
`revzip [1,2,3,4,5] = [(1, 5), (2, 4), (3, 3), (4, 2), (5, 1)]`
-/
def revzip (l : list α) : list (α × α) := zip l l.reverse
/-- `product l₁ l₂` is the list of pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂`.
product [1, 2] [5, 6] = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
def product (l₁ : list α) (l₂ : list β) : list (α × β) :=
l₁.bind $ λ a, l₂.map $ prod.mk a
/-- `sigma l₁ l₂` is the list of dependent pairs `(a, b)` where `a ∈ l₁` and `b ∈ l₂ a`.
sigma [1, 2] (λ_, [(5 : ℕ), 6]) = [(1, 5), (1, 6), (2, 5), (2, 6)] -/
protected def sigma {σ : α → Type*} (l₁ : list α) (l₂ : Π a, list (σ a)) : list (Σ a, σ a) :=
l₁.bind $ λ a, (l₂ a).map $ sigma.mk a
/-- Auxliary definition used to define `of_fn`.
`of_fn_aux f m h l` returns the first `m` elements of `of_fn f`
appended to `l` -/
def of_fn_aux {n} (f : fin n → α) : ∀ m, m ≤ n → list α → list α
| 0 h l := l
| (succ m) h l := of_fn_aux m (le_of_lt h) (f ⟨m, h⟩ :: l)
/-- `of_fn f` with `f : fin n → α` returns the list whose ith element is `f i`
`of_fun f = [f 0, f 1, ... , f(n - 1)]` -/
def of_fn {n} (f : fin n → α) : list α :=
of_fn_aux f n (le_refl _) []
/-- `of_fn_nth_val f i` returns `some (f i)` if `i < n` and `none` otherwise. -/
def of_fn_nth_val {n} (f : fin n → α) (i : ℕ) : option α :=
if h : i < n then some (f ⟨i, h⟩) else none
/-- `disjoint l₁ l₂` means that `l₁` and `l₂` have no elements in common. -/
def disjoint (l₁ l₂ : list α) : Prop := ∀ ⦃a⦄, a ∈ l₁ → a ∈ l₂ → false
section pairwise
variables (R : α → α → Prop)
/-- `pairwise R l` means that all the elements with earlier indexes are
`R`-related to all the elements with later indexes.
pairwise R [1, 2, 3] ↔ R 1 2 ∧ R 1 3 ∧ R 2 3
For example if `R = (≠)` then it asserts `l` has no duplicates,
and if `R = (<)` then it asserts that `l` is (strictly) sorted. -/
inductive pairwise : list α → Prop
| nil : pairwise []
| cons : ∀ {a : α} {l : list α}, (∀ a' ∈ l, R a a') → pairwise l → pairwise (a::l)
variables {R}
@[simp] theorem pairwise_cons {a : α} {l : list α} :
pairwise R (a::l) ↔ (∀ a' ∈ l, R a a') ∧ pairwise R l :=
⟨λ p, by cases p with a l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩
attribute [simp] pairwise.nil
instance decidable_pairwise [decidable_rel R] (l : list α) : decidable (pairwise R l) :=
by induction l with hd tl ih; [exact is_true pairwise.nil,
exactI decidable_of_iff' _ pairwise_cons]
end pairwise
/-- `pw_filter R l` is a maximal sublist of `l` which is `pairwise R`.
`pw_filter (≠)` is the erase duplicates function (cf. `erase_dup`), and `pw_filter (<)` finds
a maximal increasing subsequence in `l`. For example,
pw_filter (<) [0, 1, 5, 2, 6, 3, 4] = [0, 1, 2, 3, 4] -/
def pw_filter (R : α → α → Prop) [decidable_rel R] : list α → list α
| [] := []
| (x :: xs) := let IH := pw_filter xs in if ∀ y ∈ IH, R x y then x :: IH else IH
section chain
variable (R : α → α → Prop)
/-- `chain R a l` means that `R` holds between adjacent elements of `a::l`.
chain R a [b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
inductive chain : α → list α → Prop
| nil {a : α} : chain a []
| cons : ∀ {a b : α} {l : list α}, R a b → chain b l → chain a (b::l)
/-- `chain' R l` means that `R` holds between adjacent elements of `l`.
chain' R [a, b, c, d] ↔ R a b ∧ R b c ∧ R c d -/
def chain' : list α → Prop
| [] := true
| (a :: l) := chain R a l
variable {R}
@[simp] theorem chain_cons {a b : α} {l : list α} :
chain R a (b::l) ↔ R a b ∧ chain R b l :=
⟨λ p, by cases p with _ a b l n p; exact ⟨n, p⟩, λ ⟨n, p⟩, p.cons n⟩
attribute [simp] chain.nil
instance decidable_chain [decidable_rel R] (a : α) (l : list α) : decidable (chain R a l) :=
by induction l generalizing a; simp only [chain.nil, chain_cons]; resetI; apply_instance
instance decidable_chain' [decidable_rel R] (l : list α) : decidable (chain' R l) :=
by cases l; dunfold chain'; apply_instance
end chain
/-- `nodup l` means that `l` has no duplicates, that is, any element appears at most
once in the list. It is defined as `pairwise (≠)`. -/
def nodup : list α → Prop := pairwise (≠)
instance nodup_decidable [decidable_eq α] : ∀ l : list α, decidable (nodup l) :=
list.decidable_pairwise
/-- `erase_dup l` removes duplicates from `l` (taking only the first occurrence).
Defined as `pw_filter (≠)`.
erase_dup [1, 0, 2, 2, 1] = [0, 2, 1] -/
def erase_dup [decidable_eq α] : list α → list α := pw_filter (≠)
/-- `range' s n` is the list of numbers `[s, s+1, ..., s+n-1]`.
It is intended mainly for proving properties of `range` and `iota`. -/
@[simp] def range' : ℕ → ℕ → list ℕ
| s 0 := []
| s (n+1) := s :: range' (s+1) n
/-- Drop `none`s from a list, and replace each remaining `some a` with `a`. -/
def reduce_option {α} : list (option α) → list α :=
list.filter_map id
/-- `ilast' x xs` returns the last element of `xs` if `xs` is non-empty;
it returns `x` otherwise -/
@[simp] def ilast' {α} : α → list α → α
| a [] := a
| a (b::l) := ilast' b l
/-- `last' xs` returns the last element of `xs` if `xs` is non-empty;
it returns `none` otherwise -/
@[simp] def last' {α} : list α → option α
| [] := none
| [a] := some a
| (b::l) := last' l
/-- `rotate l n` rotates the elements of `l` to the left by `n`
rotate [0, 1, 2, 3, 4, 5] 2 = [2, 3, 4, 5, 0, 1] -/
def rotate (l : list α) (n : ℕ) : list α :=
let (l₁, l₂) := list.split_at (n % l.length) l in l₂ ++ l₁
/-- rotate' is the same as `rotate`, but slower. Used for proofs about `rotate`-/
def rotate' : list α → ℕ → list α
| [] n := []
| l 0 := l
| (a::l) (n+1) := rotate' (l ++ [a]) n
section choose
variables (p : α → Prop) [decidable_pred p] (l : list α)
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns both `a` and proofs
of `a ∈ l` and `p a`. -/
def choose_x : Π l : list α, Π hp : (∃ a, a ∈ l ∧ p a), { a // a ∈ l ∧ p a }
| [] hp := false.elim (exists.elim hp (assume a h, not_mem_nil a h.left))
| (l :: ls) hp := if pl : p l then ⟨l, ⟨or.inl rfl, pl⟩⟩ else
let ⟨a, ⟨a_mem_ls, pa⟩⟩ := choose_x ls (hp.imp
(λ b ⟨o, h₂⟩, ⟨o.resolve_left (λ e, pl $ e ▸ h₂), h₂⟩)) in
⟨a, ⟨or.inr a_mem_ls, pa⟩⟩
/-- Given a decidable predicate `p` and a proof of existence of `a ∈ l` such that `p a`,
choose the first element with this property. This version returns `a : α`, and properties
are given by `choose_mem` and `choose_property`. -/
def choose (hp : ∃ a, a ∈ l ∧ p a) : α := choose_x p l hp
end choose
/-- Filters and maps elements of a list -/
def mmap_filter {m : Type → Type v} [monad m] {α β} (f : α → m (option β)) :
list α → m (list β)
| [] := return []
| (h :: t) := do b ← f h, t' ← t.mmap_filter, return $
match b with none := t' | (some x) := x::t' end
/--
`mmap_upper_triangle f l` calls `f` on all elements in the upper triangular part of `l × l`.
That is, for each `e ∈ l`, it will run `f e e` and then `f e e'`
for each `e'` that appears after `e` in `l`.
Example: suppose `l = [1, 2, 3]`. `mmap_upper_triangle f l` will produce the list
`[f 1 1, f 1 2, f 1 3, f 2 2, f 2 3, f 3 3]`.
-/
def mmap_upper_triangle {m} [monad m] {α β : Type u} (f : α → α → m β) : list α → m (list β)
| [] := return []
| (h::t) := do v ← f h h, l ← t.mmap (f h), t ← t.mmap_upper_triangle, return $ (v::l) ++ t
/--
`mmap'_diag f l` calls `f` on all elements in the upper triangular part of `l × l`.
That is, for each `e ∈ l`, it will run `f e e` and then `f e e'`
for each `e'` that appears after `e` in `l`.
Example: suppose `l = [1, 2, 3]`. `mmap'_diag f l` will evaluate, in this order,
`f 1 1`, `f 1 2`, `f 1 3`, `f 2 2`, `f 2 3`, `f 3 3`.
-/
def mmap'_diag {m} [monad m] {α} (f : α → α → m unit) : list α → m unit
| [] := return ()
| (h::t) := f h h >> t.mmap' (f h) >> t.mmap'_diag
protected def traverse {F : Type u → Type v} [applicative F] {α β : Type*} (f : α → F β) :
list α → F (list β)
| [] := pure []
| (x :: xs) := list.cons <$> f x <*> traverse xs
/-- `get_rest l l₁` returns `some l₂` if `l = l₁ ++ l₂`.
If `l₁` is not a prefix of `l`, returns `none` -/
def get_rest [decidable_eq α] : list α → list α → option (list α)
| l [] := some l
| [] _ := none
| (x::l) (y::l₁) := if x = y then get_rest l l₁ else none
/--
`list.slice n m xs` removes a slice of length `m` at index `n` in list `xs`.
-/
def slice {α} : ℕ → ℕ → list α → list α
| 0 n xs := xs.drop n
| (succ n) m [] := []
| (succ n) m (x :: xs) := x :: slice n m xs
/--
Left-biased version of `list.map₂`. `map₂_left' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is
applied to `none` for the remaining `aᵢ`. Returns the results of the `f`
applications and the remaining `bs`.
```
map₂_left' prod.mk [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
map₂_left' prod.mk [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
```
-/
@[simp] def map₂_left' (f : α → option β → γ) : list α → list β → (list γ × list β)
| [] bs := ([], bs)
| (a :: as) [] :=
((a :: as).map (λ a, f a none), [])
| (a :: as) (b :: bs) :=
let rec := map₂_left' as bs in
(f a (some b) :: rec.fst, rec.snd)
/--
Right-biased version of `list.map₂`. `map₂_right' f as bs` applies `f` to each
pair of elements `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is
applied to `none` for the remaining `bᵢ`. Returns the results of the `f`
applications and the remaining `as`.
```
map₂_right' prod.mk [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
map₂_right' prod.mk [1, 2] ['a'] = ([(some 1, 'a')], [2])
```
-/
def map₂_right' (f : option α → β → γ) (as : list α) (bs : list β) : (list γ × list α) :=
map₂_left' (flip f) bs as
/--
Left-biased version of `list.zip`. `zip_left' as bs` returns the list of
pairs `(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, the
remaining `aᵢ` are paired with `none`. Also returns the remaining `bs`.
```
zip_left' [1, 2] ['a'] = ([(1, some 'a'), (2, none)], [])
zip_left' [1] ['a', 'b'] = ([(1, some 'a')], ['b'])
zip_left' = map₂_left' prod.mk
```
-/
def zip_left' : list α → list β → list (α × option β) × list β :=
map₂_left' prod.mk
/--
Right-biased version of `list.zip`. `zip_right' as bs` returns the list of
pairs `(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, the
remaining `bᵢ` are paired with `none`. Also returns the remaining `as`.
```
zip_right' [1] ['a', 'b'] = ([(some 1, 'a'), (none, 'b')], [])
zip_right' [1, 2] ['a'] = ([(some 1, 'a')], [2])
zip_right' = map₂_right' prod.mk
```
-/
def zip_right' : list α → list β → list (option α × β) × list α :=
map₂_right' prod.mk
/--
Left-biased version of `list.map₂`. `map₂_left f as bs` applies `f` to each pair
`aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, `f` is applied to `none`
for the remaining `aᵢ`.
```
map₂_left prod.mk [1, 2] ['a'] = [(1, some 'a'), (2, none)]
map₂_left prod.mk [1] ['a', 'b'] = [(1, some 'a')]
map₂_left f as bs = (map₂_left' f as bs).fst
```
-/
@[simp] def map₂_left (f : α → option β → γ) : list α → list β → list γ
| [] _ := []
| (a :: as) [] := (a :: as).map (λ a, f a none)
| (a :: as) (b :: bs) := f a (some b) :: map₂_left as bs
/--
Right-biased version of `list.map₂`. `map₂_right f as bs` applies `f` to each
pair `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, `f` is applied to
`none` for the remaining `bᵢ`.
```
map₂_right prod.mk [1, 2] ['a'] = [(some 1, 'a')]
map₂_right prod.mk [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
map₂_right f as bs = (map₂_right' f as bs).fst
```
-/
def map₂_right (f : option α → β → γ) (as : list α) (bs : list β) :
list γ :=
map₂_left (flip f) bs as
/--
Left-biased version of `list.zip`. `zip_left as bs` returns the list of pairs
`(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `bs` is shorter than `as`, the
remaining `aᵢ` are paired with `none`.
```
zip_left [1, 2] ['a'] = [(1, some 'a'), (2, none)]
zip_left [1] ['a', 'b'] = [(1, some 'a')]
zip_left = map₂_left prod.mk
```
-/
def zip_left : list α → list β → list (α × option β) :=
map₂_left prod.mk
/--
Right-biased version of `list.zip`. `zip_right as bs` returns the list of pairs
`(aᵢ, bᵢ)` for `aᵢ ∈ as` and `bᵢ ∈ bs`. If `as` is shorter than `bs`, the
remaining `bᵢ` are paired with `none`.
```
zip_right [1, 2] ['a'] = [(some 1, 'a')]
zip_right [1] ['a', 'b'] = [(some 1, 'a'), (none, 'b')]
zip_right = map₂_right prod.mk
```
-/
def zip_right : list α → list β → list (option α × β) :=
map₂_right prod.mk
end list
|
15c4e186e22fffd52fb605fbb59d3a9bb3efc98b | 0e175f34f8dca5ea099671777e8d7446d7d74227 | /library/init/data/int/order.lean | 60a5aa4740f5f22e4802adb74ade767123d88579 | [
"Apache-2.0"
] | permissive | utensil-contrib/lean | b31266738071c654d96dac8b35d9ccffc8172fda | a28b9c8f78d982a4e82b1e4f7ce7988d87183ae8 | refs/heads/master | 1,670,045,564,075 | 1,597,397,599,000 | 1,597,397,599,000 | 287,528,503 | 0 | 0 | Apache-2.0 | 1,597,408,338,000 | 1,597,408,337,000 | null | UTF-8 | Lean | false | false | 36,966 | lean | /-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
The order relation on the integers.
-/
prelude
import init.data.int.basic init.data.ordering.basic
namespace int
private def nonneg (a : ℤ) : Prop := int.cases_on a (assume n, true) (assume n, false)
protected def le (a b : ℤ) : Prop := nonneg (b - a)
instance : has_le int := ⟨int.le⟩
protected def lt (a b : ℤ) : Prop := (a + 1) ≤ b
instance : has_lt int := ⟨int.lt⟩
private def decidable_nonneg (a : ℤ) : decidable (nonneg a) :=
int.cases_on a (assume a, decidable.true) (assume a, decidable.false)
instance decidable_le (a b : ℤ) : decidable (a ≤ b) := decidable_nonneg _
instance decidable_lt (a b : ℤ) : decidable (a < b) := decidable_nonneg _
lemma lt_iff_add_one_le (a b : ℤ) : a < b ↔ a + 1 ≤ b := iff.refl _
private lemma nonneg.elim {a : ℤ} : nonneg a → ∃ n : ℕ, a = n :=
int.cases_on a (assume n H, exists.intro n rfl) (assume n', false.elim)
private lemma nonneg_or_nonneg_neg (a : ℤ) : nonneg a ∨ nonneg (-a) :=
int.cases_on a (assume n, or.inl trivial) (assume n, or.inr trivial)
lemma le.intro_sub {a b : ℤ} {n : ℕ} (h : b - a = n) : a ≤ b :=
show nonneg (b - a), by rw h; trivial
local attribute [simp] int.sub_eq_add_neg int.add_assoc int.add_right_neg int.add_left_neg
int.zero_add int.add_zero int.neg_add int.neg_neg int.neg_zero
lemma le.intro {a b : ℤ} {n : ℕ} (h : a + n = b) : a ≤ b :=
le.intro_sub (by rw [← h, int.add_comm]; simp)
lemma le.dest_sub {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, b - a = n := nonneg.elim h
lemma le.dest {a b : ℤ} (h : a ≤ b) : ∃ n : ℕ, a + n = b :=
match (le.dest_sub h) with
| ⟨n, h₁⟩ := exists.intro n begin rw [← h₁, int.add_comm], simp end
end
lemma le.elim {a b : ℤ} (h : a ≤ b) {P : Prop} (h' : ∀ n : ℕ, a + ↑n = b → P) : P :=
exists.elim (le.dest h) h'
protected lemma le_total (a b : ℤ) : a ≤ b ∨ b ≤ a :=
or.imp_right
(assume H : nonneg (-(b - a)),
have -(b - a) = a - b, by simp [int.add_comm],
show nonneg (a - b), from this ▸ H)
(nonneg_or_nonneg_neg (b - a))
lemma coe_nat_le_coe_nat_of_le {m n : ℕ} (h : m ≤ n) : (↑m : ℤ) ≤ ↑n :=
match nat.le.dest h with
| ⟨k, (hk : m + k = n)⟩ := le.intro (begin rw [← hk], reflexivity end)
end
lemma le_of_coe_nat_le_coe_nat {m n : ℕ} (h : (↑m : ℤ) ≤ ↑n) : m ≤ n :=
le.elim h (assume k, assume hk : ↑m + ↑k = ↑n,
have m + k = n, from int.coe_nat_inj ((int.coe_nat_add m k).trans hk),
nat.le.intro this)
lemma coe_nat_le_coe_nat_iff (m n : ℕ) : (↑m : ℤ) ≤ ↑n ↔ m ≤ n :=
iff.intro le_of_coe_nat_le_coe_nat coe_nat_le_coe_nat_of_le
lemma coe_zero_le (n : ℕ) : 0 ≤ (↑n : ℤ) :=
coe_nat_le_coe_nat_of_le n.zero_le
lemma eq_coe_of_zero_le {a : ℤ} (h : 0 ≤ a) : ∃ n : ℕ, a = n :=
by { have t := le.dest_sub h, simp at t, exact t }
lemma eq_succ_of_zero_lt {a : ℤ} (h : 0 < a) : ∃ n : ℕ, a = n.succ :=
let ⟨n, (h : ↑(1+n) = a)⟩ := le.dest h in
⟨n, by rw nat.add_comm at h; exact h.symm⟩
lemma lt_add_succ (a : ℤ) (n : ℕ) : a < a + ↑(nat.succ n) :=
le.intro (show a + 1 + n = a + nat.succ n, begin simp [int.coe_nat_eq, int.add_comm, int.add_left_comm], reflexivity end)
lemma lt.intro {a b : ℤ} {n : ℕ} (h : a + nat.succ n = b) : a < b :=
h ▸ lt_add_succ a n
lemma lt.dest {a b : ℤ} (h : a < b) : ∃ n : ℕ, a + ↑(nat.succ n) = b :=
le.elim h (assume n, assume hn : a + 1 + n = b,
exists.intro n begin rw [← hn, int.add_assoc, int.add_comm 1], reflexivity end)
lemma lt.elim {a b : ℤ} (h : a < b) {P : Prop} (h' : ∀ n : ℕ, a + ↑(nat.succ n) = b → P) : P :=
exists.elim (lt.dest h) h'
lemma coe_nat_lt_coe_nat_iff (n m : ℕ) : (↑n : ℤ) < ↑m ↔ n < m :=
begin rw [lt_iff_add_one_le, ← int.coe_nat_succ, coe_nat_le_coe_nat_iff], reflexivity end
lemma lt_of_coe_nat_lt_coe_nat {m n : ℕ} (h : (↑m : ℤ) < ↑n) : m < n :=
(coe_nat_lt_coe_nat_iff _ _).mp h
lemma coe_nat_lt_coe_nat_of_lt {m n : ℕ} (h : m < n) : (↑m : ℤ) < ↑n :=
(coe_nat_lt_coe_nat_iff _ _).mpr h
/- show that the integers form an ordered additive group -/
protected lemma le_refl (a : ℤ) : a ≤ a :=
le.intro (int.add_zero a)
protected lemma le_trans {a b c : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ c) : a ≤ c :=
le.elim h₁ (assume n, assume hn : a + n = b,
le.elim h₂ (assume m, assume hm : b + m = c,
begin apply le.intro, rw [← hm, ← hn, int.add_assoc], reflexivity end))
protected lemma le_antisymm {a b : ℤ} (h₁ : a ≤ b) (h₂ : b ≤ a) : a = b :=
le.elim h₁ (assume n, assume hn : a + n = b,
le.elim h₂ (assume m, assume hm : b + m = a,
have a + ↑(n + m) = a + 0, by rw [int.coe_nat_add, ← int.add_assoc, hn, hm, int.add_zero a],
have (↑(n + m) : ℤ) = 0, from int.add_left_cancel this,
have n + m = 0, from int.coe_nat_inj this,
have n = 0, from nat.eq_zero_of_add_eq_zero_right this,
show a = b, begin rw [← hn, this, int.coe_nat_zero, int.add_zero a] end))
protected lemma lt_irrefl (a : ℤ) : ¬ a < a :=
assume : a < a,
lt.elim this (assume n, assume hn : a + nat.succ n = a,
have a + nat.succ n = a + 0, by rw [hn, int.add_zero],
have nat.succ n = 0, from int.coe_nat_inj (int.add_left_cancel this),
show false, from nat.succ_ne_zero _ this)
protected lemma ne_of_lt {a b : ℤ} (h : a < b) : a ≠ b :=
(assume : a = b, absurd (begin rewrite this at h, exact h end) (int.lt_irrefl b))
lemma le_of_lt {a b : ℤ} (h : a < b) : a ≤ b :=
lt.elim h (assume n, assume hn : a + nat.succ n = b, le.intro hn)
protected lemma lt_iff_le_and_ne (a b : ℤ) : a < b ↔ (a ≤ b ∧ a ≠ b) :=
iff.intro
(assume h, ⟨le_of_lt h, int.ne_of_lt h⟩)
(assume ⟨aleb, aneb⟩,
le.elim aleb (assume n, assume hn : a + n = b,
have n ≠ 0,
from (assume : n = 0, aneb begin rw [← hn, this, int.coe_nat_zero, int.add_zero] end),
have n = nat.succ (nat.pred n),
from eq.symm (nat.succ_pred_eq_of_pos (nat.pos_of_ne_zero this)),
lt.intro (begin rewrite this at hn, exact hn end)))
lemma lt_succ (a : ℤ) : a < a + 1 :=
int.le_refl (a + 1)
protected lemma add_le_add_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c + a ≤ c + b :=
le.elim h (assume n, assume hn : a + n = b,
le.intro (show c + a + n = c + b, begin rw [int.add_assoc, hn] end))
protected lemma add_lt_add_left {a b : ℤ} (h : a < b) (c : ℤ) : c + a < c + b :=
iff.mpr (int.lt_iff_le_and_ne _ _)
(and.intro
(int.add_le_add_left (le_of_lt h) _)
(assume heq, int.lt_irrefl b begin rw int.add_left_cancel heq at h, exact h end))
protected lemma mul_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a * b :=
le.elim ha (assume n, assume hn,
le.elim hb (assume m, assume hm,
le.intro (show 0 + ↑n * ↑m = a * b, begin rw [← hn, ← hm], simp [int.zero_add] end)))
protected lemma mul_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a * b :=
lt.elim ha (assume n, assume hn,
lt.elim hb (assume m, assume hm,
lt.intro (show 0 + ↑(nat.succ (nat.succ n * m + n)) = a * b,
begin rw [← hn, ← hm], simp [int.coe_nat_zero],
rw [← int.coe_nat_mul], simp [nat.mul_succ, nat.succ_add] end)))
protected lemma zero_lt_one : (0 : ℤ) < 1 := trivial
protected lemma lt_iff_le_not_le {a b : ℤ} : a < b ↔ (a ≤ b ∧ ¬ b ≤ a) :=
begin
simp [int.lt_iff_le_and_ne], split; intro h,
{ cases h with hab hn, split,
{ assumption },
{ intro hba, simp [int.le_antisymm hab hba] at *, contradiction } },
{ cases h with hab hn, split,
{ assumption },
{ intro h, simp [*] at * } }
end
instance : decidable_linear_order int :=
{ le := int.le,
le_refl := int.le_refl,
le_trans := @int.le_trans,
le_antisymm := @int.le_antisymm,
lt := int.lt,
lt_iff_le_not_le := @int.lt_iff_le_not_le,
le_total := int.le_total,
decidable_eq := int.decidable_eq,
decidable_le := int.decidable_le,
decidable_lt := int.decidable_lt }
lemma eq_nat_abs_of_zero_le {a : ℤ} (h : 0 ≤ a) : a = nat_abs a :=
let ⟨n, e⟩ := eq_coe_of_zero_le h in by rw e; refl
lemma le_nat_abs {a : ℤ} : a ≤ nat_abs a :=
or.elim (le_total 0 a)
(λh, by rw eq_nat_abs_of_zero_le h; refl)
(λh, le_trans h (coe_zero_le _))
lemma neg_succ_lt_zero (n : ℕ) : -[1+ n] < 0 :=
lt_of_not_ge $ λ h, let ⟨m, h⟩ := eq_coe_of_zero_le h in by contradiction
lemma eq_neg_succ_of_lt_zero : ∀ {a : ℤ}, a < 0 → ∃ n : ℕ, a = -[1+ n]
| (n : ℕ) h := absurd h (not_lt_of_ge (coe_zero_le _))
| -[1+ n] h := ⟨n, rfl⟩
/- int is an ordered add comm group -/
protected lemma eq_neg_of_eq_neg {a b : ℤ} (h : a = -b) : b = -a :=
by rw [h, int.neg_neg]
protected lemma neg_add_cancel_left (a b : ℤ) : -a + (a + b) = b :=
by rw [← int.add_assoc, int.add_left_neg, int.zero_add]
protected lemma add_neg_cancel_left (a b : ℤ) : a + (-a + b) = b :=
by rw [← int.add_assoc, int.add_right_neg, int.zero_add]
protected lemma add_neg_cancel_right (a b : ℤ) : a + b + -b = a :=
by rw [int.add_assoc, int.add_right_neg, int.add_zero]
protected lemma neg_add_cancel_right (a b : ℤ) : a + -b + b = a :=
by rw [int.add_assoc, int.add_left_neg, int.add_zero]
protected lemma sub_self (a : ℤ) : a - a = 0 :=
by rw [int.sub_eq_add_neg, int.add_right_neg]
protected lemma sub_eq_zero_of_eq {a b : ℤ} (h : a = b) : a - b = 0 :=
by rw [h, int.sub_self]
protected lemma eq_of_sub_eq_zero {a b : ℤ} (h : a - b = 0) : a = b :=
have 0 + b = b, by rw int.zero_add,
have (a - b) + b = b, by rwa h,
by rwa [int.sub_eq_add_neg, int.neg_add_cancel_right] at this
protected lemma sub_eq_zero_iff_eq {a b : ℤ} : a - b = 0 ↔ a = b :=
⟨int.eq_of_sub_eq_zero, int.sub_eq_zero_of_eq⟩
@[simp] protected lemma neg_eq_of_add_eq_zero {a b : ℤ} (h : a + b = 0) : -a = b :=
by rw [← int.add_zero (-a), ←h, ←int.add_assoc, int.add_left_neg, int.zero_add]
protected lemma neg_mul_eq_neg_mul (a b : ℤ) : -(a * b) = -a * b :=
int.neg_eq_of_add_eq_zero
begin rw [← int.distrib_right, int.add_right_neg, int.zero_mul] end
protected lemma neg_mul_eq_mul_neg (a b : ℤ) : -(a * b) = a * -b :=
int.neg_eq_of_add_eq_zero
begin rw [← int.distrib_left, int.add_right_neg, int.mul_zero] end
@[simp] lemma neg_mul_eq_neg_mul_symm (a b : ℤ) : - a * b = - (a * b) :=
eq.symm (int.neg_mul_eq_neg_mul a b)
@[simp] lemma mul_neg_eq_neg_mul_symm (a b : ℤ) : a * - b = - (a * b) :=
eq.symm (int.neg_mul_eq_mul_neg a b)
protected lemma neg_mul_neg (a b : ℤ) : -a * -b = a * b :=
by simp
protected lemma neg_mul_comm (a b : ℤ) : -a * b = a * -b :=
by simp
protected lemma mul_sub (a b c : ℤ) : a * (b - c) = a * b - a * c :=
calc
a * (b - c) = a * b + a * -c : int.distrib_left a b (-c)
... = a * b - a * c : by simp
protected lemma sub_mul (a b c : ℤ) : (a - b) * c = a * c - b * c :=
calc
(a - b) * c = a * c + -b * c : int.distrib_right a (-b) c
... = a * c - b * c : by simp
section
protected lemma le_of_add_le_add_left {a b c : ℤ} (h : a + b ≤ a + c) : b ≤ c :=
have -a + (a + b) ≤ -a + (a + c), from int.add_le_add_left h _,
begin simp [int.neg_add_cancel_left] at this, assumption end
protected lemma lt_of_add_lt_add_left {a b c : ℤ} (h : a + b < a + c) : b < c :=
have -a + (a + b) < -a + (a + c), from int.add_lt_add_left h _,
begin simp [int.neg_add_cancel_left] at this, assumption end
protected lemma add_le_add_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a + c ≤ b + c :=
int.add_comm c a ▸ int.add_comm c b ▸ int.add_le_add_left h c
protected theorem add_lt_add_right {a b : ℤ} (h : a < b) (c : ℤ) : a + c < b + c :=
begin
rw [int.add_comm a c, int.add_comm b c],
exact (int.add_lt_add_left h c)
end
protected lemma add_le_add {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c ≤ d) : a + c ≤ b + d :=
le_trans (int.add_le_add_right h₁ c) (int.add_le_add_left h₂ b)
protected lemma le_add_of_nonneg_right {a b : ℤ} (h : b ≥ 0) : a ≤ a + b :=
have a + b ≥ a + 0, from int.add_le_add_left h a,
by rwa int.add_zero at this
protected lemma le_add_of_nonneg_left {a b : ℤ} (h : b ≥ 0) : a ≤ b + a :=
have 0 + a ≤ b + a, from int.add_le_add_right h a,
by rwa int.zero_add at this
protected lemma add_lt_add {a b c d : ℤ} (h₁ : a < b) (h₂ : c < d) : a + c < b + d :=
lt_trans (int.add_lt_add_right h₁ c) (int.add_lt_add_left h₂ b)
protected lemma add_lt_add_of_le_of_lt {a b c d : ℤ} (h₁ : a ≤ b) (h₂ : c < d) : a + c < b + d :=
lt_of_le_of_lt (int.add_le_add_right h₁ c) (int.add_lt_add_left h₂ b)
protected lemma add_lt_add_of_lt_of_le {a b c d : ℤ} (h₁ : a < b) (h₂ : c ≤ d) : a + c < b + d :=
lt_of_lt_of_le (int.add_lt_add_right h₁ c) (int.add_le_add_left h₂ b)
protected lemma lt_add_of_pos_right (a : ℤ) {b : ℤ} (h : b > 0) : a < a + b :=
have a + 0 < a + b, from int.add_lt_add_left h a,
by rwa [int.add_zero] at this
protected lemma lt_add_of_pos_left (a : ℤ) {b : ℤ} (h : b > 0) : a < b + a :=
have 0 + a < b + a, from int.add_lt_add_right h a,
by rwa [int.zero_add] at this
protected lemma le_of_add_le_add_right {a b c : ℤ} (h : a + b ≤ c + b) : a ≤ c :=
int.le_of_add_le_add_left
(show b + a ≤ b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end)
protected lemma lt_of_add_lt_add_right {a b c : ℤ} (h : a + b < c + b) : a < c :=
int.lt_of_add_lt_add_left
(show b + a < b + c, begin rw [int.add_comm b a, int.add_comm b c], assumption end)
-- here we start using properties of zero.
protected lemma add_nonneg {a b : ℤ} (ha : 0 ≤ a) (hb : 0 ≤ b) : 0 ≤ a + b :=
int.zero_add (0:ℤ) ▸ (int.add_le_add ha hb)
protected lemma add_pos {a b : ℤ} (ha : 0 < a) (hb : 0 < b) : 0 < a + b :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add ha hb)
protected lemma add_pos_of_pos_of_nonneg {a b : ℤ} (ha : 0 < a) (hb : 0 ≤ b) : 0 < a + b :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_lt_of_le ha hb)
protected lemma add_pos_of_nonneg_of_pos {a b : ℤ} (ha : 0 ≤ a) (hb : 0 < b) : 0 < a + b :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_le_of_lt ha hb)
protected lemma add_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : a + b ≤ 0 :=
int.zero_add (0:ℤ) ▸ (int.add_le_add ha hb)
protected lemma add_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : a + b < 0 :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add ha hb)
protected lemma add_neg_of_neg_of_nonpos {a b : ℤ} (ha : a < 0) (hb : b ≤ 0) : a + b < 0 :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_lt_of_le ha hb)
protected lemma add_neg_of_nonpos_of_neg {a b : ℤ} (ha : a ≤ 0) (hb : b < 0) : a + b < 0 :=
int.zero_add (0:ℤ) ▸ (int.add_lt_add_of_le_of_lt ha hb)
protected lemma lt_add_of_le_of_pos {a b c : ℤ} (hbc : b ≤ c) (ha : 0 < a) : b < c + a :=
int.add_zero b ▸ int.add_lt_add_of_le_of_lt hbc ha
protected lemma sub_add_cancel (a b : ℤ) : a - b + b = a :=
int.neg_add_cancel_right a b
protected lemma add_sub_cancel (a b : ℤ) : a + b - b = a :=
int.add_neg_cancel_right a b
protected lemma add_sub_assoc (a b c : ℤ) : a + b - c = a + (b - c) :=
by rw [int.sub_eq_add_neg, int.add_assoc, ←int.sub_eq_add_neg]
protected lemma neg_le_neg {a b : ℤ} (h : a ≤ b) : -b ≤ -a :=
have 0 ≤ -a + b, from int.add_left_neg a ▸ int.add_le_add_left h (-a),
have 0 + -b ≤ -a + b + -b, from int.add_le_add_right this (-b),
by rwa [int.add_neg_cancel_right, int.zero_add] at this
protected lemma le_of_neg_le_neg {a b : ℤ} (h : -b ≤ -a) : a ≤ b :=
suffices -(-a) ≤ -(-b), from
begin simp [int.neg_neg] at this, assumption end,
int.neg_le_neg h
protected lemma nonneg_of_neg_nonpos {a : ℤ} (h : -a ≤ 0) : 0 ≤ a :=
have -a ≤ -0, by rwa int.neg_zero,
int.le_of_neg_le_neg this
protected lemma neg_nonpos_of_nonneg {a : ℤ} (h : 0 ≤ a) : -a ≤ 0 :=
have -a ≤ -0, from int.neg_le_neg h,
by rwa int.neg_zero at this
protected lemma nonpos_of_neg_nonneg {a : ℤ} (h : 0 ≤ -a) : a ≤ 0 :=
have -0 ≤ -a, by rwa int.neg_zero,
int.le_of_neg_le_neg this
protected lemma neg_nonneg_of_nonpos {a : ℤ} (h : a ≤ 0) : 0 ≤ -a :=
have -0 ≤ -a, from int.neg_le_neg h,
by rwa int.neg_zero at this
protected lemma neg_lt_neg {a b : ℤ} (h : a < b) : -b < -a :=
have 0 < -a + b, from int.add_left_neg a ▸ int.add_lt_add_left h (-a),
have 0 + -b < -a + b + -b, from int.add_lt_add_right this (-b),
by rwa [int.add_neg_cancel_right, int.zero_add] at this
protected lemma lt_of_neg_lt_neg {a b : ℤ} (h : -b < -a) : a < b :=
int.neg_neg a ▸ int.neg_neg b ▸ int.neg_lt_neg h
protected lemma pos_of_neg_neg {a : ℤ} (h : -a < 0) : 0 < a :=
have -a < -0, by rwa int.neg_zero,
int.lt_of_neg_lt_neg this
protected lemma neg_neg_of_pos {a : ℤ} (h : 0 < a) : -a < 0 :=
have -a < -0, from int.neg_lt_neg h,
by rwa int.neg_zero at this
protected lemma neg_of_neg_pos {a : ℤ} (h : 0 < -a) : a < 0 :=
have -0 < -a, by rwa int.neg_zero,
int.lt_of_neg_lt_neg this
protected lemma neg_pos_of_neg {a : ℤ} (h : a < 0) : 0 < -a :=
have -0 < -a, from int.neg_lt_neg h,
by rwa int.neg_zero at this
protected lemma le_neg_of_le_neg {a b : ℤ} (h : a ≤ -b) : b ≤ -a :=
begin
have h := int.neg_le_neg h,
rwa int.neg_neg at h
end
protected lemma neg_le_of_neg_le {a b : ℤ} (h : -a ≤ b) : -b ≤ a :=
begin
have h := int.neg_le_neg h,
rwa int.neg_neg at h
end
protected lemma lt_neg_of_lt_neg {a b : ℤ} (h : a < -b) : b < -a :=
begin
have h := int.neg_lt_neg h,
rwa int.neg_neg at h
end
protected lemma neg_lt_of_neg_lt {a b : ℤ} (h : -a < b) : -b < a :=
begin
have h := int.neg_lt_neg h,
rwa int.neg_neg at h
end
protected lemma sub_nonneg_of_le {a b : ℤ} (h : b ≤ a) : 0 ≤ a - b :=
begin
have h := int.add_le_add_right h (-b),
rwa int.add_right_neg at h
end
protected lemma le_of_sub_nonneg {a b : ℤ} (h : 0 ≤ a - b) : b ≤ a :=
begin
have h := int.add_le_add_right h b,
rwa [int.sub_add_cancel, int.zero_add] at h
end
protected lemma sub_nonpos_of_le {a b : ℤ} (h : a ≤ b) : a - b ≤ 0 :=
begin
have h := int.add_le_add_right h (-b),
rwa int.add_right_neg at h
end
protected lemma le_of_sub_nonpos {a b : ℤ} (h : a - b ≤ 0) : a ≤ b :=
begin
have h := int.add_le_add_right h b,
rwa [int.sub_add_cancel, int.zero_add] at h
end
protected lemma sub_pos_of_lt {a b : ℤ} (h : b < a) : 0 < a - b :=
begin
have h := int.add_lt_add_right h (-b),
rwa int.add_right_neg at h
end
protected lemma lt_of_sub_pos {a b : ℤ} (h : 0 < a - b) : b < a :=
begin
have h := int.add_lt_add_right h b,
rwa [int.sub_add_cancel, int.zero_add] at h
end
protected lemma sub_neg_of_lt {a b : ℤ} (h : a < b) : a - b < 0 :=
begin
have h := int.add_lt_add_right h (-b),
rwa int.add_right_neg at h
end
protected lemma lt_of_sub_neg {a b : ℤ} (h : a - b < 0) : a < b :=
begin
have h := int.add_lt_add_right h b,
rwa [int.sub_add_cancel, int.zero_add] at h
end
protected lemma add_le_of_le_neg_add {a b c : ℤ} (h : b ≤ -a + c) : a + b ≤ c :=
begin
have h := int.add_le_add_left h a,
rwa int.add_neg_cancel_left at h
end
protected lemma le_neg_add_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ -a + c :=
begin
have h := int.add_le_add_left h (-a),
rwa int.neg_add_cancel_left at h
end
protected lemma add_le_of_le_sub_left {a b c : ℤ} (h : b ≤ c - a) : a + b ≤ c :=
begin
have h := int.add_le_add_left h a,
rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h
end
protected lemma le_sub_left_of_add_le {a b c : ℤ} (h : a + b ≤ c) : b ≤ c - a :=
begin
have h := int.add_le_add_right h (-a),
rwa [int.add_comm a b, int.add_neg_cancel_right] at h
end
protected lemma add_le_of_le_sub_right {a b c : ℤ} (h : a ≤ c - b) : a + b ≤ c :=
begin
have h := int.add_le_add_right h b,
rwa int.sub_add_cancel at h
end
protected lemma le_sub_right_of_add_le {a b c : ℤ} (h : a + b ≤ c) : a ≤ c - b :=
begin
have h := int.add_le_add_right h (-b),
rwa int.add_neg_cancel_right at h
end
protected lemma le_add_of_neg_add_le {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c :=
begin
have h := int.add_le_add_left h b,
rwa int.add_neg_cancel_left at h
end
protected lemma neg_add_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c :=
begin
have h := int.add_le_add_left h (-b),
rwa int.neg_add_cancel_left at h
end
protected lemma le_add_of_sub_left_le {a b c : ℤ} (h : a - b ≤ c) : a ≤ b + c :=
begin
have h := int.add_le_add_right h b,
rwa [int.sub_add_cancel, int.add_comm] at h
end
protected lemma sub_left_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - b ≤ c :=
begin
have h := int.add_le_add_right h (-b),
rwa [int.add_comm b c, int.add_neg_cancel_right] at h
end
protected lemma le_add_of_sub_right_le {a b c : ℤ} (h : a - c ≤ b) : a ≤ b + c :=
begin
have h := int.add_le_add_right h c,
rwa int.sub_add_cancel at h
end
protected lemma sub_right_le_of_le_add {a b c : ℤ} (h : a ≤ b + c) : a - c ≤ b :=
begin
have h := int.add_le_add_right h (-c),
rwa int.add_neg_cancel_right at h
end
protected lemma le_add_of_neg_add_le_left {a b c : ℤ} (h : -b + a ≤ c) : a ≤ b + c :=
begin
rw int.add_comm at h,
exact int.le_add_of_sub_left_le h
end
protected lemma neg_add_le_left_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -b + a ≤ c :=
begin
rw int.add_comm,
exact int.sub_left_le_of_le_add h
end
protected lemma le_add_of_neg_add_le_right {a b c : ℤ} (h : -c + a ≤ b) : a ≤ b + c :=
begin
rw int.add_comm at h,
exact int.le_add_of_sub_right_le h
end
protected lemma neg_add_le_right_of_le_add {a b c : ℤ} (h : a ≤ b + c) : -c + a ≤ b :=
begin
rw int.add_comm at h,
exact int.neg_add_le_left_of_le_add h
end
protected lemma le_add_of_neg_le_sub_left {a b c : ℤ} (h : -a ≤ b - c) : c ≤ a + b :=
int.le_add_of_neg_add_le_left (int.add_le_of_le_sub_right h)
protected lemma neg_le_sub_left_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -a ≤ b - c :=
begin
have h := int.le_neg_add_of_add_le (int.sub_left_le_of_le_add h),
rwa int.add_comm at h
end
protected lemma le_add_of_neg_le_sub_right {a b c : ℤ} (h : -b ≤ a - c) : c ≤ a + b :=
int.le_add_of_sub_right_le (int.add_le_of_le_sub_left h)
protected lemma neg_le_sub_right_of_le_add {a b c : ℤ} (h : c ≤ a + b) : -b ≤ a - c :=
int.le_sub_left_of_add_le (int.sub_right_le_of_le_add h)
protected lemma sub_le_of_sub_le {a b c : ℤ} (h : a - b ≤ c) : a - c ≤ b :=
int.sub_left_le_of_le_add (int.le_add_of_sub_right_le h)
protected lemma sub_le_sub_left {a b : ℤ} (h : a ≤ b) (c : ℤ) : c - b ≤ c - a :=
int.add_le_add_left (int.neg_le_neg h) c
protected lemma sub_le_sub_right {a b : ℤ} (h : a ≤ b) (c : ℤ) : a - c ≤ b - c :=
int.add_le_add_right h (-c)
protected lemma sub_le_sub {a b c d : ℤ} (hab : a ≤ b) (hcd : c ≤ d) : a - d ≤ b - c :=
int.add_le_add hab (int.neg_le_neg hcd)
protected lemma add_lt_of_lt_neg_add {a b c : ℤ} (h : b < -a + c) : a + b < c :=
begin
have h := int.add_lt_add_left h a,
rwa int.add_neg_cancel_left at h
end
protected lemma lt_neg_add_of_add_lt {a b c : ℤ} (h : a + b < c) : b < -a + c :=
begin
have h := int.add_lt_add_left h (-a),
rwa int.neg_add_cancel_left at h
end
protected lemma add_lt_of_lt_sub_left {a b c : ℤ} (h : b < c - a) : a + b < c :=
begin
have h := int.add_lt_add_left h a,
rwa [← int.add_sub_assoc, int.add_comm a c, int.add_sub_cancel] at h
end
protected lemma lt_sub_left_of_add_lt {a b c : ℤ} (h : a + b < c) : b < c - a :=
begin
have h := int.add_lt_add_right h (-a),
rwa [int.add_comm a b, int.add_neg_cancel_right] at h
end
protected lemma add_lt_of_lt_sub_right {a b c : ℤ} (h : a < c - b) : a + b < c :=
begin
have h := int.add_lt_add_right h b,
rwa int.sub_add_cancel at h
end
protected lemma lt_sub_right_of_add_lt {a b c : ℤ} (h : a + b < c) : a < c - b :=
begin
have h := int.add_lt_add_right h (-b),
rwa int.add_neg_cancel_right at h
end
protected lemma lt_add_of_neg_add_lt {a b c : ℤ} (h : -b + a < c) : a < b + c :=
begin
have h := int.add_lt_add_left h b,
rwa int.add_neg_cancel_left at h
end
protected lemma neg_add_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c :=
begin
have h := int.add_lt_add_left h (-b),
rwa int.neg_add_cancel_left at h
end
protected lemma lt_add_of_sub_left_lt {a b c : ℤ} (h : a - b < c) : a < b + c :=
begin
have h := int.add_lt_add_right h b,
rwa [int.sub_add_cancel, int.add_comm] at h
end
protected lemma sub_left_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - b < c :=
begin
have h := int.add_lt_add_right h (-b),
rwa [int.add_comm b c, int.add_neg_cancel_right] at h
end
protected lemma lt_add_of_sub_right_lt {a b c : ℤ} (h : a - c < b) : a < b + c :=
begin
have h := int.add_lt_add_right h c,
rwa int.sub_add_cancel at h
end
protected lemma sub_right_lt_of_lt_add {a b c : ℤ} (h : a < b + c) : a - c < b :=
begin
have h := int.add_lt_add_right h (-c),
rwa int.add_neg_cancel_right at h
end
protected lemma lt_add_of_neg_add_lt_left {a b c : ℤ} (h : -b + a < c) : a < b + c :=
begin
rw int.add_comm at h,
exact int.lt_add_of_sub_left_lt h
end
protected lemma neg_add_lt_left_of_lt_add {a b c : ℤ} (h : a < b + c) : -b + a < c :=
begin
rw int.add_comm,
exact int.sub_left_lt_of_lt_add h
end
protected lemma lt_add_of_neg_add_lt_right {a b c : ℤ} (h : -c + a < b) : a < b + c :=
begin
rw int.add_comm at h,
exact int.lt_add_of_sub_right_lt h
end
protected lemma neg_add_lt_right_of_lt_add {a b c : ℤ} (h : a < b + c) : -c + a < b :=
begin
rw int.add_comm at h,
exact int.neg_add_lt_left_of_lt_add h
end
protected lemma lt_add_of_neg_lt_sub_left {a b c : ℤ} (h : -a < b - c) : c < a + b :=
int.lt_add_of_neg_add_lt_left (int.add_lt_of_lt_sub_right h)
protected lemma neg_lt_sub_left_of_lt_add {a b c : ℤ} (h : c < a + b) : -a < b - c :=
begin
have h := int.lt_neg_add_of_add_lt (int.sub_left_lt_of_lt_add h),
rwa int.add_comm at h
end
protected lemma lt_add_of_neg_lt_sub_right {a b c : ℤ} (h : -b < a - c) : c < a + b :=
int.lt_add_of_sub_right_lt (int.add_lt_of_lt_sub_left h)
protected lemma neg_lt_sub_right_of_lt_add {a b c : ℤ} (h : c < a + b) : -b < a - c :=
int.lt_sub_left_of_add_lt (int.sub_right_lt_of_lt_add h)
protected lemma sub_lt_of_sub_lt {a b c : ℤ} (h : a - b < c) : a - c < b :=
int.sub_left_lt_of_lt_add (int.lt_add_of_sub_right_lt h)
protected lemma sub_lt_sub_left {a b : ℤ} (h : a < b) (c : ℤ) : c - b < c - a :=
int.add_lt_add_left (int.neg_lt_neg h) c
protected lemma sub_lt_sub_right {a b : ℤ} (h : a < b) (c : ℤ) : a - c < b - c :=
int.add_lt_add_right h (-c)
protected lemma sub_lt_sub {a b c d : ℤ} (hab : a < b) (hcd : c < d) : a - d < b - c :=
int.add_lt_add hab (int.neg_lt_neg hcd)
protected lemma sub_lt_sub_of_le_of_lt {a b c d : ℤ} (hab : a ≤ b) (hcd : c < d) : a - d < b - c :=
int.add_lt_add_of_le_of_lt hab (int.neg_lt_neg hcd)
protected lemma sub_lt_sub_of_lt_of_le {a b c d : ℤ} (hab : a < b) (hcd : c ≤ d) : a - d < b - c :=
int.add_lt_add_of_lt_of_le hab (int.neg_le_neg hcd)
protected lemma sub_le_self (a : ℤ) {b : ℤ} (h : b ≥ 0) : a - b ≤ a :=
calc
a - b = a + -b : rfl
... ≤ a + 0 : int.add_le_add_left (int.neg_nonpos_of_nonneg h) _
... = a : by rw int.add_zero
protected lemma sub_lt_self (a : ℤ) {b : ℤ} (h : b > 0) : a - b < a :=
calc
a - b = a + -b : rfl
... < a + 0 : int.add_lt_add_left (int.neg_neg_of_pos h) _
... = a : by rw int.add_zero
protected lemma add_le_add_three {a b c d e f : ℤ} (h₁ : a ≤ d) (h₂ : b ≤ e) (h₃ : c ≤ f) :
a + b + c ≤ d + e + f :=
begin
apply le_trans,
apply int.add_le_add,
apply int.add_le_add,
assumption',
apply le_refl
end
end
/- missing facts -/
protected lemma mul_lt_mul_of_pos_left {a b c : ℤ}
(h₁ : a < b) (h₂ : 0 < c) : c * a < c * b :=
have 0 < b - a, from int.sub_pos_of_lt h₁,
have 0 < c * (b - a), from int.mul_pos h₂ this,
begin
rw int.mul_sub at this,
exact int.lt_of_sub_pos this
end
protected lemma mul_lt_mul_of_pos_right {a b c : ℤ}
(h₁ : a < b) (h₂ : 0 < c) : a * c < b * c :=
have 0 < b - a, from int.sub_pos_of_lt h₁,
have 0 < (b - a) * c, from int.mul_pos this h₂,
begin
rw int.sub_mul at this,
exact int.lt_of_sub_pos this
end
protected lemma mul_le_mul_of_nonneg_left {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : c * a ≤ c * b :=
begin
by_cases hba : b ≤ a, { simp [le_antisymm hba h₁] },
by_cases hc0 : c ≤ 0, { simp [le_antisymm hc0 h₂, int.zero_mul] },
exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_left
(lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left,
end
protected lemma mul_le_mul_of_nonneg_right {a b c : ℤ} (h₁ : a ≤ b) (h₂ : 0 ≤ c) : a * c ≤ b * c :=
begin
by_cases hba : b ≤ a, { simp [le_antisymm hba h₁] },
by_cases hc0 : c ≤ 0, { simp [le_antisymm hc0 h₂, int.mul_zero] },
exact (le_not_le_of_lt (int.mul_lt_mul_of_pos_right (lt_of_le_not_le h₁ hba) (lt_of_le_not_le h₂ hc0))).left,
end
-- TODO: there are four variations, depending on which variables we assume to be nonneg
protected lemma mul_le_mul {a b c d : ℤ} (hac : a ≤ c) (hbd : b ≤ d) (nn_b : 0 ≤ b) (nn_c : 0 ≤ c) :
a * b ≤ c * d :=
calc
a * b ≤ c * b : int.mul_le_mul_of_nonneg_right hac nn_b
... ≤ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c
protected lemma mul_nonpos_of_nonneg_of_nonpos {a b : ℤ} (ha : a ≥ 0) (hb : b ≤ 0) : a * b ≤ 0 :=
have h : a * b ≤ a * 0, from int.mul_le_mul_of_nonneg_left hb ha,
by rwa int.mul_zero at h
protected lemma mul_nonpos_of_nonpos_of_nonneg {a b : ℤ} (ha : a ≤ 0) (hb : b ≥ 0) : a * b ≤ 0 :=
have h : a * b ≤ 0 * b, from int.mul_le_mul_of_nonneg_right ha hb,
by rwa int.zero_mul at h
protected lemma mul_lt_mul {a b c d : ℤ} (hac : a < c) (hbd : b ≤ d) (pos_b : 0 < b) (nn_c : 0 ≤ c) : a * b < c * d :=
calc
a * b < c * b : int.mul_lt_mul_of_pos_right hac pos_b
... ≤ c * d : int.mul_le_mul_of_nonneg_left hbd nn_c
protected lemma mul_lt_mul' {a b c d : ℤ} (h1 : a ≤ c) (h2 : b < d) (h3 : b ≥ 0) (h4 : c > 0) :
a * b < c * d :=
calc
a * b ≤ c * b : int.mul_le_mul_of_nonneg_right h1 h3
... < c * d : int.mul_lt_mul_of_pos_left h2 h4
protected lemma mul_neg_of_pos_of_neg {a b : ℤ} (ha : a > 0) (hb : b < 0) : a * b < 0 :=
have h : a * b < a * 0, from int.mul_lt_mul_of_pos_left hb ha,
by rwa int.mul_zero at h
protected lemma mul_neg_of_neg_of_pos {a b : ℤ} (ha : a < 0) (hb : b > 0) : a * b < 0 :=
have h : a * b < 0 * b, from int.mul_lt_mul_of_pos_right ha hb,
by rwa int.zero_mul at h
protected lemma mul_le_mul_of_nonpos_right {a b c : ℤ} (h : b ≤ a) (hc : c ≤ 0) : a * c ≤ b * c :=
have -c ≥ 0, from int.neg_nonneg_of_nonpos hc,
have b * -c ≤ a * -c, from int.mul_le_mul_of_nonneg_right h this,
have -(b * c) ≤ -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this,
int.le_of_neg_le_neg this
protected lemma mul_nonneg_of_nonpos_of_nonpos {a b : ℤ} (ha : a ≤ 0) (hb : b ≤ 0) : 0 ≤ a * b :=
have 0 * b ≤ a * b, from int.mul_le_mul_of_nonpos_right ha hb,
by rwa int.zero_mul at this
protected lemma mul_lt_mul_of_neg_left {a b c : ℤ} (h : b < a) (hc : c < 0) : c * a < c * b :=
have -c > 0, from int.neg_pos_of_neg hc,
have -c * b < -c * a, from int.mul_lt_mul_of_pos_left h this,
have -(c * b) < -(c * a), by rwa [← int.neg_mul_eq_neg_mul, ← int.neg_mul_eq_neg_mul] at this,
int.lt_of_neg_lt_neg this
protected lemma mul_lt_mul_of_neg_right {a b c : ℤ} (h : b < a) (hc : c < 0) : a * c < b * c :=
have -c > 0, from int.neg_pos_of_neg hc,
have b * -c < a * -c, from int.mul_lt_mul_of_pos_right h this,
have -(b * c) < -(a * c), by rwa [← int.neg_mul_eq_mul_neg, ← int.neg_mul_eq_mul_neg] at this,
int.lt_of_neg_lt_neg this
protected lemma mul_pos_of_neg_of_neg {a b : ℤ} (ha : a < 0) (hb : b < 0) : 0 < a * b :=
have 0 * b < a * b, from int.mul_lt_mul_of_neg_right ha hb,
by rwa int.zero_mul at this
protected lemma mul_self_le_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a ≤ b) : a * a ≤ b * b :=
int.mul_le_mul h2 h2 h1 (le_trans h1 h2)
protected lemma mul_self_lt_mul_self {a b : ℤ} (h1 : 0 ≤ a) (h2 : a < b) : a * a < b * b :=
int.mul_lt_mul' (le_of_lt h2) h2 h1 (lt_of_le_of_lt h1 h2)
/- more facts specific to int -/
theorem of_nat_nonneg (n : ℕ) : 0 ≤ of_nat n := trivial
theorem coe_succ_pos (n : nat) : (nat.succ n : ℤ) > 0 :=
coe_nat_lt_coe_nat_of_lt (nat.succ_pos _)
theorem exists_eq_neg_of_nat {a : ℤ} (H : a ≤ 0) : ∃n : ℕ, a = -n :=
let ⟨n, h⟩ := eq_coe_of_zero_le (int.neg_nonneg_of_nonpos H) in
⟨n, int.eq_neg_of_eq_neg h.symm⟩
theorem nat_abs_of_nonneg {a : ℤ} (H : a ≥ 0) : (nat_abs a : ℤ) = a :=
match a, eq_coe_of_zero_le H with ._, ⟨n, rfl⟩ := rfl end
theorem of_nat_nat_abs_of_nonpos {a : ℤ} (H : a ≤ 0) : (nat_abs a : ℤ) = -a :=
by rw [← nat_abs_neg, nat_abs_of_nonneg (int.neg_nonneg_of_nonpos H)]
theorem lt_of_add_one_le {a b : ℤ} (H : a + 1 ≤ b) : a < b := H
theorem add_one_le_of_lt {a b : ℤ} (H : a < b) : a + 1 ≤ b := H
theorem lt_add_one_of_le {a b : ℤ} (H : a ≤ b) : a < b + 1 :=
int.add_le_add_right H 1
theorem le_of_lt_add_one {a b : ℤ} (H : a < b + 1) : a ≤ b :=
int.le_of_add_le_add_right H
theorem sub_one_le_of_lt {a b : ℤ} (H : a ≤ b) : a - 1 < b :=
int.sub_right_lt_of_lt_add $ lt_add_one_of_le H
theorem lt_of_sub_one_le {a b : ℤ} (H : a - 1 < b) : a ≤ b :=
le_of_lt_add_one $ int.lt_add_of_sub_right_lt H
theorem le_sub_one_of_lt {a b : ℤ} (H : a < b) : a ≤ b - 1 :=
int.le_sub_right_of_add_le H
theorem lt_of_le_sub_one {a b : ℤ} (H : a ≤ b - 1) : a < b :=
int.add_le_of_le_sub_right H
theorem sign_of_succ (n : nat) : sign (nat.succ n) = 1 := rfl
theorem sign_eq_one_of_pos {a : ℤ} (h : 0 < a) : sign a = 1 :=
match a, eq_succ_of_zero_lt h with ._, ⟨n, rfl⟩ := rfl end
theorem sign_eq_neg_one_of_neg {a : ℤ} (h : a < 0) : sign a = -1 :=
match a, eq_neg_succ_of_lt_zero h with ._, ⟨n, rfl⟩ := rfl end
lemma eq_zero_of_sign_eq_zero : Π {a : ℤ}, sign a = 0 → a = 0
| 0 _ := rfl
theorem pos_of_sign_eq_one : ∀ {a : ℤ}, sign a = 1 → 0 < a
| (n+1:ℕ) _ := coe_nat_lt_coe_nat_of_lt (nat.succ_pos _)
theorem neg_of_sign_eq_neg_one : ∀ {a : ℤ}, sign a = -1 → a < 0
| (n+1:ℕ) h := match h with end
| 0 h := match h with end
| -[1+ n] _ := neg_succ_lt_zero _
theorem sign_eq_one_iff_pos (a : ℤ) : sign a = 1 ↔ 0 < a :=
⟨pos_of_sign_eq_one, sign_eq_one_of_pos⟩
theorem sign_eq_neg_one_iff_neg (a : ℤ) : sign a = -1 ↔ a < 0 :=
⟨neg_of_sign_eq_neg_one, sign_eq_neg_one_of_neg⟩
theorem sign_eq_zero_iff_zero (a : ℤ) : sign a = 0 ↔ a = 0 :=
⟨eq_zero_of_sign_eq_zero, λ h, by rw [h, sign_zero]⟩
protected lemma eq_zero_or_eq_zero_of_mul_eq_zero
{a b : ℤ} (h : a * b = 0) : a = 0 ∨ b = 0 :=
match lt_trichotomy 0 a with
| or.inl hlt₁ :=
match lt_trichotomy 0 b with
| or.inl hlt₂ :=
have 0 < a * b, from int.mul_pos hlt₁ hlt₂,
begin rw h at this, exact absurd this (lt_irrefl _) end
| or.inr (or.inl heq₂) := or.inr heq₂.symm
| or.inr (or.inr hgt₂) :=
have 0 > a * b, from int.mul_neg_of_pos_of_neg hlt₁ hgt₂,
begin rw h at this, exact absurd this (lt_irrefl _) end
end
| or.inr (or.inl heq₁) := or.inl heq₁.symm
| or.inr (or.inr hgt₁) :=
match lt_trichotomy 0 b with
| or.inl hlt₂ :=
have 0 > a * b, from int.mul_neg_of_neg_of_pos hgt₁ hlt₂,
begin rw h at this, exact absurd this (lt_irrefl _) end
| or.inr (or.inl heq₂) := or.inr heq₂.symm
| or.inr (or.inr hgt₂) :=
have 0 < a * b, from int.mul_pos_of_neg_of_neg hgt₁ hgt₂,
begin rw h at this, exact absurd this (lt_irrefl _) end
end
end
protected 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 int.sub_eq_zero_of_eq h,
have (b - c) * a = 0, by rw [int.sub_mul, this],
have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_right ha,
int.eq_of_sub_eq_zero this
protected 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 int.sub_eq_zero_of_eq h,
have a * (b - c) = 0, by rw [int.mul_sub, this],
have b - c = 0, from (int.eq_zero_or_eq_zero_of_mul_eq_zero this).resolve_left ha,
int.eq_of_sub_eq_zero this
theorem eq_one_of_mul_eq_self_left {a b : ℤ} (Hpos : a ≠ 0) (H : b * a = a) : b = 1 :=
int.eq_of_mul_eq_mul_right Hpos (by rw [int.one_mul, H])
theorem eq_one_of_mul_eq_self_right {a b : ℤ} (Hpos : b ≠ 0) (H : b * a = b) : a = 1 :=
int.eq_of_mul_eq_mul_left Hpos (by rw [int.mul_one, H])
end int
|
635bfbd44567528a01f4a843da19a7ca8b42d675 | e38e95b38a38a99ecfa1255822e78e4b26f65bb0 | /src/certigrad/tensor.lean | f98ee7b8e714a3f5d9321cd649c9cc7b357abdae | [
"Apache-2.0"
] | permissive | ColaDrill/certigrad | fefb1be3670adccd3bed2f3faf57507f156fd501 | fe288251f623ac7152e5ce555f1cd9d3a20203c2 | refs/heads/master | 1,593,297,324,250 | 1,499,903,753,000 | 1,499,903,753,000 | 97,075,797 | 1 | 0 | null | 1,499,916,210,000 | 1,499,916,210,000 | null | UTF-8 | Lean | false | false | 9,961 | lean | /-
Copyright (c) 2017 Daniel Selsam. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Daniel Selsam
Tensors and basic tensor operations.
-/
import .util .rng .dvec .id
run_cmd mk_simp_attr `cgsimp
namespace certigrad
@[reducible] def S : Type := list ℕ
constant T (shape : S) : Type
notation `ℝ` := T []
namespace T
-- Constants that compute (excluding const, lt, le)
constant const (α : ℝ) (shape : S) : T shape
constant zero (shape : S) : T shape
constant one (shape : S) : T shape
constant pi (shape : S) : T shape
constant neg {shape : S} (x : T shape) : T shape
constant inv {shape : S} (x : T shape) : T shape
constant log {shape : S} (x : T shape) : T shape
constant exp {shape : S} (x : T shape) : T shape
constant sqrt {shape : S} (x : T shape) : T shape
constant tanh {shape : S} (x : T shape) : T shape
constant add {shape : S} (x y : T shape) : T shape
constant mul {shape : S} (x y : T shape) : T shape
constant sub {shape : S} (x y : T shape) : T shape
constant div {shape : S} (x y : T shape) : T shape
constant lt {shape : S} (x y : T shape) : Prop
constant le {shape : S} (x y : T shape) : Prop
constant pow {shape : S} (x : T shape) (α : ℝ) : T shape
constant of_nat (n : ℕ) : ℝ
constant round (α : ℝ) : ℕ
constant fail (shape : S) : T shape
constant silent_fail (shape : S) : T shape
constant error {shape : S} (s : string) : T shape
-- Algebraic instances
@[inline, priority 10000] instance (shape : S) : has_zero (T shape) := ⟨T.zero shape⟩
@[inline, priority 10000] instance (shape : S) : has_one (T shape) := ⟨T.one shape⟩
@[inline, priority 10000] instance (shape : S) : has_neg (T shape) := ⟨T.neg⟩
@[inline, priority 10000] instance (shape : S) : has_add (T shape) := ⟨T.add⟩
@[inline, priority 10000] instance (shape : S) : has_mul (T shape) := ⟨T.mul⟩
@[inline, priority 10000] instance (shape : S) : has_lt (T shape) := ⟨T.lt⟩
@[inline, priority 10000] instance (shape : S) : has_le (T shape) := ⟨T.le⟩
@[inline, priority 10000] instance (shape : S) : has_inv (T shape) := ⟨T.inv⟩
@[inline, priority 10000] instance (shape : S) : has_div (T shape) := ⟨λ x y, x * y⁻¹⟩
namespace IL
-- Instance Lemmas
axiom add_comm {shape : S} : ∀ (x y : T shape), x + y = y + x
axiom add_assoc {shape : S} : ∀ (x y z : T shape), x + y + z = x + (y + z)
axiom zero_add {shape : S} : ∀ (x : T shape), 0 + x = x
axiom add_zero {shape : S} : ∀ (x : T shape), x + 0 = x
axiom add_left_neg {shape : S} : ∀ (x : T shape), -x + x = 0
axiom mul_comm {shape : S} : ∀ (x y : T shape), x * y = y * x
axiom mul_assoc {shape : S} : ∀ (x y z : T shape), x * y * z = x * (y * z)
axiom one_mul {shape : S} : ∀ (x : T shape), 1 * x = x
axiom mul_one {shape : S} : ∀ (x : T shape), x * 1 = x
axiom left_distrib {shape : S} : ∀ (x y z : T shape), x * (y + z) = x * y + x * z
axiom right_distrib {shape : S} : ∀ (x y z : T shape), (x + y) * z = x * z + y * z
axiom le_refl {shape : S} : ∀ (x : T shape), x ≤ x
axiom le_trans {shape : S} : ∀ (x y z : T shape), x ≤ y → y ≤ z → x ≤ z
axiom le_antisymm {shape : S} : ∀ (x y : T shape), x ≤ y → y ≤ x → x = y
axiom le_of_lt {shape : S} : ∀ (x y : T shape), x < y → x ≤ y
axiom lt_of_lt_of_le {shape : S} : ∀ (x y z : T shape), x < y → y ≤ z → x < z
axiom lt_of_le_of_lt {shape : S} : ∀ (x y z : T shape), x ≤ y → y < z → x < z
axiom lt_irrefl {shape : S} : ∀ (x : T shape), ¬x < x
axiom add_le_add_left {shape : S} : ∀ (x y : T shape), x ≤ y → ∀ (z : T shape), z + x ≤ z + y
axiom add_lt_add_left {shape : S} : ∀ (x y : T shape), x < y → ∀ (z : T shape), z + x < z + y
axiom zero_ne_one {shape : S} : (0 : T shape) ≠ (1 : T shape)
axiom mul_nonneg {shape : S} : ∀ (x y : T shape), 0 ≤ x → 0 ≤ y → 0 ≤ x * y
axiom mul_pos {shape : S} : ∀ (x y : T shape), 0 < x → 0 < y → 0 < x * y
axiom le_iff_lt_or_eq {shape : S} : ∀ (x y : T shape), x ≤ y ↔ x < y ∨ x = y
end IL
@[inline] instance (shape : S) : ordered_comm_ring (T shape) :=
{
-- defs
zero := T.zero shape, one := T.one shape, add := T.add, neg := T.neg, mul := T.mul,
-- noncomputable defs
le := T.le, lt := T.lt,
-- axioms
add_comm := T.IL.add_comm, add_assoc := T.IL.add_assoc, zero_add := T.IL.zero_add,
add_zero := T.IL.add_zero, add_left_neg := T.IL.add_left_neg,
mul_comm := T.IL.mul_comm, mul_assoc := T.IL.mul_assoc, one_mul := T.IL.one_mul, mul_one := T.IL.mul_one,
left_distrib := T.IL.left_distrib, right_distrib := T.IL.right_distrib,
le_refl := T.IL.le_refl, le_trans := T.IL.le_trans, le_antisymm := T.IL.le_antisymm,
le_of_lt := T.IL.le_of_lt, lt_of_lt_of_le := T.IL.lt_of_lt_of_le, lt_of_le_of_lt := T.IL.lt_of_le_of_lt,
lt_irrefl := T.IL.lt_irrefl, add_le_add_left := T.IL.add_le_add_left, add_lt_add_left := T.IL.add_lt_add_left,
zero_ne_one := T.IL.zero_ne_one, mul_nonneg := T.IL.mul_nonneg, mul_pos := T.IL.mul_pos
}
@[inline] instance (shape : S) : has_sub (T shape) := by apply_instance
attribute [inline] ordered_comm_ring.to_ordered_ring ordered_ring.to_ring ring.to_add_comm_group add_comm_group.to_add_group algebra.sub
-- We never want to do algebra with this
def scalar_mul {shape : S} (α : ℝ) (x : T shape) : T shape := const α shape * x
constant transpose {m n : ℕ} (M : T [m, n]) : T [n, m]
constant sum : Π {shape : S}, T shape → ℝ
constant prod : Π {shape : S}, T shape → ℝ
constant get_row {m n : ℕ} (M : T [m, n]) (ridx : ℕ) : T [n]
constant sum_cols {nrows ncols : ℕ} (M : T [nrows, ncols]) : T [nrows]
constant get_col {m n : ℕ} (M : T [m, n]) (cidx : ℕ) : T [m]
constant get_col_range {m n : ℕ} (ncols : ℕ) (M : T [m, n]) (cidx : ℕ) : T [m, ncols]
constant replicate_col {m : ℕ} (v : T [m]) (n : ℕ) : T [m, n]
constant gemv {m n : ℕ} (M : T [m, n]) (x : T [n]) : T [m]
constant gemm {m n p : ℕ} (M : T [m, n]) (N : T [n, p]) : T [m, p]
constant append_col {n p : ℕ} (N : T [n, p]) (x : T [n]) : T [n, p+1]
constant sample_mvn_iso : Π {shape : S} (μ σ : T shape) (rng : RNG), T shape × RNG
constant sample_uniform : Π (shape : S) (low high : ℝ) (rng : RNG), T shape × RNG
constant to_string {shape : S} : T shape → string
/- Other constants -/
constant is_integrable : Π {shape₁ shape₂ : S}, (T shape₁ → T shape₂) → Prop
constant integral : Π {shape₁ shape₂ : S}, (T shape₁ → T shape₂) → T shape₂
constant is_uniformly_integrable_around : Π {shape₁ shape₂ shape₃ : S} (f : T shape₁ → T shape₂ → T shape₃) (θ : T shape₁), Prop
-- ω(exp -x²) ∧ o(exp x²)
constant is_btw_exp₂ {shape₁ shape₂ : S} (f : T shape₁ → T shape₂) : Prop
constant is_sub_quadratic {shape₁ shape₂ : S} (f : T shape₁ → T shape₂) : Prop
constant is_bounded_btw_exp₂_around {shape₁ shape₂ shape₃ : S} (f : Π (x : T shape₁) (θ : T shape₂), T shape₃) (θ : T shape₂) : Prop
-- continuously differentiable
constant is_cdifferentiable : Π {ishape : S}, (T ishape → ℝ) → T ishape → Prop
constant grad : Π {ishape : S}, (T ishape → ℝ) → (T ishape → T ishape)
constant D {ishape oshape : S} : (T ishape → T oshape) → T ishape → T (ishape ++ oshape)
constant tmulT {ishape oshape : S} : T (ishape ++ oshape) → T oshape → T ishape
constant is_continuous {ishape oshape : S} : (T ishape → T oshape) → T ishape → Prop
noncomputable def dintegral {oshape : S} : Π {ishapes : list S}, (dvec T ishapes → T oshape) → T oshape
| [] f := f ⟦⟧
| (ishape::ishapes) f := integral (λ (x : T ishape), @dintegral ishapes (λ (v : dvec T ishapes), f (x ::: v)))
noncomputable def is_dintegrable {oshape : S} : Π {ishapes : list S}, (dvec T ishapes → T oshape) → Prop
| [] f := true
| (ishape::ishapes) f := is_integrable (λ (x : T ishape), @dintegral _ ishapes (λ (v : dvec T ishapes), f (x ::: v)))
∧ ∀ (x : T ishape), is_dintegrable (λ (v : dvec T ishapes), f (x ::: v))
/- Notation -/
notation `π` := pi []
notation `∫` := integral
notation `∇` := grad
/- Other instances -/
instance {shape : S} : has_to_string (T shape) := has_to_string.mk T.to_string
@[inline] instance {shape : S} : inhabited (T shape) := ⟨T.zero shape⟩ -- ⟨silent_fail _⟩ --⟨T.zero shape⟩ (switch back once no course-of-values)
@[inline] instance {shape : S} : has_smul (ℝ) (T shape) := ⟨scalar_mul⟩
/- Derived definitions -/
def softplus {shape : S} (x : T shape) : T shape := log (exp x + 1)
def sigmoid {shape : S} (x : T shape) : T shape := 1 / (1 + exp (- x))
def dot {shape : S} (x y : T shape) : ℝ := sum (x * y)
def square {shape : S} (x : T shape) : T shape := x * x
def mvn_iso_pdf {shape : S} (μ σ x : T shape) : ℝ :=
prod ((sqrt ((2 * pi shape) * square σ))⁻¹ * exp ((- 2⁻¹) * (square $ (x - μ) / σ)))
def mvn_iso_logpdf {shape : S} (μ σ x : T shape) : ℝ :=
(- 2⁻¹) * sum (square ((x - μ) / σ) + log (2 * pi shape) + log (square σ))
def mvn_iso_grad_logpdf_μ {shape : S} (μ σ x : T shape) : T shape :=
(x - μ) / (square σ)
def mvn_iso_grad_logpdf_σ {shape : S} (μ σ x : T shape) : T shape :=
square (x - μ) / (σ * square σ) - σ⁻¹
def mvn_iso_std_logpdf {shape : S} (x : T shape) : ℝ := mvn_iso_logpdf 0 1 x
def mvn_iso_kl {shape : S} (μ σ : T shape) : ℝ :=
(- 2⁻¹) * sum (1 + log (square σ) - square μ - square σ)
def mvn_iso_empirical_kl {shape : S} (μ σ z : T shape) : ℝ :=
mvn_iso_logpdf μ σ z - mvn_iso_std_logpdf z
def bernoulli_neglogpdf {shape : S} (p z : T shape) : ℝ :=
- sum (z * log p + (1 - z) * log (1 - p))
def force {shape₁ : S} (x : T shape₁) (shape₂ : S) : T shape₂ :=
if H : shape₁ = shape₂ then eq.rec_on H x else T.error ("force-failed: " ++ _root_.to_string shape₁ ++ " != " ++ _root_.to_string shape₂)
end T
end certigrad
|
c63634190755f662f7a1bc181cbeede869b12ad2 | 79cc757e5e5b09c7a522f717a6c490d321d36469 | /src/mywork/oct_13.lean | f5b1f157a0e3e56d2d6e0b9dced4bc3511e54adc | [] | no_license | LukeMathe/cs2120f21 | 534c3b8868dcfdea98a9d22513180c8a062794c6 | d51940b174569a8782e62ae027b108b5f099a9aa | refs/heads/main | 1,693,418,664,935 | 1,634,585,653,000 | 1,634,585,653,000 | 403,762,076 | 0 | 0 | null | 1,630,963,485,000 | 1,630,963,485,000 | null | UTF-8 | Lean | false | false | 393 | lean | /-
Set is a colleciton of objects in some structure
Types of sets:
Empty
Complete
Union- combines 2 sets
Intersection- set with shared elements of both sets
Complement- elements not in one set
Power- all of possible subsets in a given set
calculate 2 ^ (# elements) to find number of sets
Subset- set made up of elements of another set
Product- set of all possible pairs of elements
-/ |
98d1e80943cc11e418fa70552d47f448ac03a437 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/mvarAtDefaultValue.lean | c0b3cdb7a3ac33b0d0703152d2167a7b32adb8e3 | [
"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 | 146 | lean | structure A where
x : Nat
structure B extends A where
x := _ -- should be error
structure C extends A where
x := _ + 1 -- should be error
|
6e0d9d5653e492f8d5cc73f2681395d88ee880d1 | 04fb7df3dddae0c07fba3e8f2ae375f52c857286 | /src/while.lean | cb3d0c5d4d4c694604d9d0d162b73a0a1653754e | [] | no_license | ezrasitorus/ModelsOfComputation | 519137e30bb21ad406693c8f15455ffa516973eb | dfdfe9e3351b3bb01506b116fffb3ec017e9a89a | refs/heads/main | 1,679,797,496,030 | 1,616,435,697,000 | 1,616,435,697,000 | 308,993,502 | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 568 | lean | import tactic
inductive w_exp : Type
| nat : ℕ → w_exp
| add : w_exp → w_exp → w_exp
| mul : w_exp → w_exp → w_exp
inductive w_bool
| true : w_bool
| false : w_bool
| equal : w_exp → w_exp → w_bool
| not : w_bool → w_bool
| and : w_bool → w_bool → w_bool
| or : w_bool → w_bool → w_bool
inductive w_com : Type
| assign : char → w_exp → w_com
| if_then_else : w_bool → w_com → w_com
| seq_comp : w_com → w_com → w_com
| skip : w_com
| while_do : w_bool → w_com → w_com |
e1e5a08ae5b8dfd58ba429e729c7cfa6ff52b79b | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/category/Group/adjunctions.lean | 64f2caf41d79c532e3b5b732343ab611f50aa1c4 | [
"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 | 6,350 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Johannes Hölzl
-/
import algebra.category.Group.basic
import group_theory.free_abelian_group
/-!
# Adjunctions regarding the category of (abelian) groups
This file contains construction of basic adjunctions concerning the category of groups and the
category of abelian groups.
## Main definitions
* `AddCommGroup.free`: constructs the functor associating to a type `X` the free abelian group with
generators `x : X`.
* `Group.free`: constructs the functor associating to a type `X` the free group with
generators `x : X`.
* `abelianize`: constructs the functor which associates to a group `G` its abelianization `Gᵃᵇ`.
## Main statements
* `AddCommGroup.adj`: proves that `AddCommGroup.free` is the left adjoint of the forgetful functor
from abelian groups to types.
* `Group.adj`: proves that `Group.free` is the left adjoint of the forgetful functor from groups to
types.
* `abelianize_adj`: proves that `abelianize` is left adjoint to the forgetful functor from
abelian groups to groups.
-/
noncomputable theory
universe u
open category_theory
namespace AddCommGroup
open_locale classical
/--
The free functor `Type u ⥤ AddCommGroup` sending a type `X` to the
free abelian group with generators `x : X`.
-/
def free : Type u ⥤ AddCommGroup :=
{ obj := λ α, of (free_abelian_group α),
map := λ X Y, free_abelian_group.map,
map_id' := λ X, add_monoid_hom.ext free_abelian_group.map_id_apply,
map_comp' := λ X Y Z f g, add_monoid_hom.ext free_abelian_group.map_comp_apply, }
@[simp] lemma free_obj_coe {α : Type u} :
(free.obj α : Type u) = (free_abelian_group α) := rfl
@[simp] lemma free_map_coe {α β : Type u} {f : α → β} (x : free_abelian_group α) :
(free.map f) x = f <$> x := rfl
/--
The free-forgetful adjunction for abelian groups.
-/
def adj : free ⊣ forget AddCommGroup.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X G, free_abelian_group.lift.symm,
hom_equiv_naturality_left_symm' :=
by { intros, ext, refl} }
instance : is_right_adjoint (forget AddCommGroup.{u}) := ⟨_, adj⟩
/--
As an example, we now give a high-powered proof that
the monomorphisms in `AddCommGroup` are just the injective functions.
(This proof works in all universes.)
-/
example {G H : AddCommGroup.{u}} (f : G ⟶ H) [mono f] : function.injective f :=
(mono_iff_injective f).1 (show mono ((forget AddCommGroup.{u}).map f), by apply_instance)
end AddCommGroup
namespace Group
/-- The free functor `Type u ⥤ Group` sending a type `X` to the free group with generators `x : X`.
-/
def free : Type u ⥤ Group :=
{ obj := λ α, of (free_group α),
map := λ X Y, free_group.map,
map_id' := by { intros, ext1, refl },
map_comp' := by { intros, ext1, refl } }
/-- The free-forgetful adjunction for groups.
-/
def adj : free ⊣ forget Group.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ X G, free_group.lift.symm,
hom_equiv_naturality_left_symm' := λ X Y G f g, by { ext1, refl } }
instance : is_right_adjoint (forget Group.{u}) := ⟨_, adj⟩
end Group
section abelianization
/-- The abelianization functor `Group ⥤ CommGroup` sending a group `G` to its abelianization `Gᵃᵇ`.
-/
def abelianize : Group.{u} ⥤ CommGroup.{u} :=
{ obj := λ G, { α := abelianization G, str := by apply_instance },
map := λ G H f, abelianization.lift ( { to_fun := λ x, abelianization.of (f x),
map_one' := by simp,
map_mul' := by simp } ),
map_id' := by { intros, simp only [monoid_hom.mk_coe, coe_id], ext1, refl },
map_comp' := by { intros, simp only [coe_comp], ext1, refl } }
/-- The abelianization-forgetful adjuction from `Group` to `CommGroup`.-/
def abelianize_adj : abelianize ⊣ forget₂ CommGroup.{u} Group.{u} :=
adjunction.mk_of_hom_equiv
{ hom_equiv := λ G A, abelianization.lift.symm,
hom_equiv_naturality_left_symm' := λ G H A f g, by { ext1, refl } }
end abelianization
/-- The functor taking a monoid to its subgroup of units. -/
@[simps]
def Mon.units : Mon.{u} ⥤ Group.{u} :=
{ obj := λ R, Group.of Rˣ,
map := λ R S f, Group.of_hom $ units.map f,
map_id' := λ X, monoid_hom.ext (λ x, units.ext rfl),
map_comp' := λ X Y Z f g, monoid_hom.ext (λ x, units.ext rfl) }
/-- The forgetful-units adjunction between `Group` and `Mon`. -/
def Group.forget₂_Mon_adj : forget₂ Group Mon ⊣ Mon.units.{u} :=
{ hom_equiv := λ X Y,
{ to_fun := λ f, monoid_hom.to_hom_units f,
inv_fun := λ f, (units.coe_hom Y).comp f,
left_inv := λ f, monoid_hom.ext $ λ _, rfl,
right_inv := λ f, monoid_hom.ext $ λ _, units.ext rfl },
unit :=
{ app := λ X, { ..(@to_units X _).to_monoid_hom },
naturality' := λ X Y f, monoid_hom.ext $ λ x, units.ext rfl },
counit :=
{ app := λ X, units.coe_hom X,
naturality' := λ X Y f, monoid_hom.ext $ λ x, rfl },
hom_equiv_unit' := λ X Y f, monoid_hom.ext $ λ _, units.ext rfl,
hom_equiv_counit' := λ X Y f, monoid_hom.ext $ λ _, rfl }
instance : is_right_adjoint Mon.units.{u} :=
⟨_, Group.forget₂_Mon_adj⟩
/-- The functor taking a monoid to its subgroup of units. -/
@[simps]
def CommMon.units : CommMon.{u} ⥤ CommGroup.{u} :=
{ obj := λ R, CommGroup.of Rˣ,
map := λ R S f, CommGroup.of_hom $ units.map f,
map_id' := λ X, monoid_hom.ext (λ x, units.ext rfl),
map_comp' := λ X Y Z f g, monoid_hom.ext (λ x, units.ext rfl) }
/-- The forgetful-units adjunction between `CommGroup` and `CommMon`. -/
def CommGroup.forget₂_CommMon_adj : forget₂ CommGroup CommMon ⊣ CommMon.units.{u} :=
{ hom_equiv := λ X Y,
{ to_fun := λ f, monoid_hom.to_hom_units f,
inv_fun := λ f, (units.coe_hom Y).comp f,
left_inv := λ f, monoid_hom.ext $ λ _, rfl,
right_inv := λ f, monoid_hom.ext $ λ _, units.ext rfl },
unit :=
{ app := λ X, { ..(@to_units X _).to_monoid_hom },
naturality' := λ X Y f, monoid_hom.ext $ λ x, units.ext rfl },
counit :=
{ app := λ X, units.coe_hom X,
naturality' := λ X Y f, monoid_hom.ext $ λ x, rfl },
hom_equiv_unit' := λ X Y f, monoid_hom.ext $ λ _, units.ext rfl,
hom_equiv_counit' := λ X Y f, monoid_hom.ext $ λ _, rfl }
instance : is_right_adjoint CommMon.units.{u} :=
⟨_, CommGroup.forget₂_CommMon_adj⟩
|
9e4c714eeb9a988ff1efc0528cf347159ddfb2ce | 2d34dfb0a1cc250584282618dc10ea03d3fa858e | /src/NormedGroup.lean | 70cf959082da2b585f33445f49ababc053fcd519 | [] | no_license | zeta1999/lean-liquid | 61e294ec5adae959d8ee1b65d015775484ff58c2 | 96bb0fa3afc3b451bcd1fb7d974348de2f290541 | refs/heads/master | 1,676,579,150,248 | 1,610,771,445,000 | 1,610,771,445,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 3,356 | lean | import algebra.punit_instances
import category_theory.concrete_category.bundled_hom
import category_theory.limits.shapes.zero
import category_theory.limits.shapes.kernels
import category_theory.limits.creates
import .normed_group_hom
/-!
# The category of normed abelian groups and continuous group homomorphisms
-/
universes u v
-- move this
section for_mathlib
instance punit.uniform_space : uniform_space punit := ⊥
noncomputable
instance punit.metric_space : metric_space punit :=
{ dist := λ _ _, 0,
dist_self := λ _, rfl,
dist_comm := λ _ _, rfl,
eq_of_dist_eq_zero := λ _ _ _, subsingleton.elim _ _,
dist_triangle := λ _ _ _, show (0:ℝ) ≤ 0 + 0, by rw add_zero,
.. punit.uniform_space }
noncomputable
instance punit.normed_group : normed_group punit :=
{ norm := function.const _ 0,
dist_eq := λ _ _, rfl,
.. punit.add_comm_group, .. punit.metric_space }
end for_mathlib
open category_theory
/-- The category of normed abelian groups and bounded group homomorphisms. -/
def NormedGroup : Type (u+1) := bundled normed_group
namespace NormedGroup
instance bundled_hom : bundled_hom @normed_group_hom :=
⟨@normed_group_hom.to_fun, @normed_group_hom.id, @normed_group_hom.comp, @normed_group_hom.coe_inj⟩
attribute [derive [has_coe_to_sort, large_category, concrete_category]] NormedGroup
/-- Construct a bundled `NormedGroup` from the underlying type and typeclass. -/
def of (M : Type u) [normed_group M] : NormedGroup := bundled.of M
noncomputable
instance : has_zero NormedGroup := ⟨of punit⟩
noncomputable
instance : inhabited NormedGroup := ⟨0⟩
instance (M : NormedGroup) : normed_group M := M.str
@[simp] lemma coe_of (V : Type u) [normed_group V] : (NormedGroup.of V : Type u) = V := rfl
@[simp] lemma coe_id (V : NormedGroup) : ⇑(𝟙 V) = id := rfl
instance : limits.has_zero_morphisms.{u (u+1)} NormedGroup :=
{ comp_zero' := by { intros, apply normed_group_hom.zero_comp },
zero_comp' := by { intros, apply normed_group_hom.comp_zero } }
section equalizers_and_kernels
open category_theory.limits
def parallel_pair_cone {V W : NormedGroup.{u}} (f g : V ⟶ W) :
cone (parallel_pair f g) :=
@fork.of_ι _ _ _ _ _ _ (of (f - g).ker) (normed_group_hom.ker.incl (f - g)) $
begin
ext v,
have : v.1 ∈ (f - g).ker := v.2,
simpa only [normed_group_hom.ker.incl_to_fun, pi.zero_apply, coe_comp, normed_group_hom.coe_zero,
subtype.val_eq_coe, normed_group_hom.mem_ker,
normed_group_hom.coe_sub, pi.sub_apply, sub_eq_zero] using this
end
instance has_limit_parallel_pair {V W : NormedGroup.{u}} (f g : V ⟶ W) :
has_limit (parallel_pair f g) :=
{ exists_limit := nonempty.intro
{ cone := parallel_pair_cone f g,
is_limit := fork.is_limit.mk _
(λ c, normed_group_hom.ker.lift (fork.ι c) _ $
show normed_group_hom.comp_hom (f - g) c.ι = 0,
by { rw [add_monoid_hom.map_sub, add_monoid_hom.sub_apply, sub_eq_zero], exact c.condition })
(λ c, normed_group_hom.ker.incl_comp_lift _ _ _)
(λ c g h, by { ext x, dsimp, rw ← h, refl }) } }
instance : limits.has_equalizers.{u (u+1)} NormedGroup :=
@has_equalizers_of_has_limit_parallel_pair NormedGroup _ $ λ V W f g,
NormedGroup.has_limit_parallel_pair f g
instance : limits.has_kernels.{u (u+1)} NormedGroup :=
by apply_instance
end equalizers_and_kernels
end NormedGroup
|
05e074e02a2f017f2a1874e3bfa2253b51c5e956 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/sym/sym2.lean | 153f56f273a3816d808b6b5367ae374713c2fb36 | [
"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 | 22,137 | lean | /-
Copyright (c) 2020 Kyle Miller All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
import data.finset.prod
import data.sym.basic
import tactic.linarith
/-!
# The symmetric square
This file defines the symmetric square, which is `α × α` modulo
swapping. This is also known as the type of unordered pairs.
More generally, the symmetric square is the second symmetric power
(see `data.sym.basic`). The equivalence is `sym2.equiv_sym`.
From the point of view that an unordered pair is equivalent to a
multiset of cardinality two (see `sym2.equiv_multiset`), there is a
`has_mem` instance `sym2.mem`, which is a `Prop`-valued membership
test. Given `h : a ∈ z` for `z : sym2 α`, then `h.other` is the other
element of the pair, defined using `classical.choice`. If `α` has
decidable equality, then `h.other'` computably gives the other element.
The universal property of `sym2` is provided as `sym2.lift`, which
states that functions from `sym2 α` are equivalent to symmetric
two-argument functions from `α`.
Recall that an undirected graph (allowing self loops, but no multiple
edges) is equivalent to a symmetric relation on the vertex type `α`.
Given a symmetric relation on `α`, the corresponding edge set is
constructed by `sym2.from_rel` which is a special case of `sym2.lift`.
## Notation
The symmetric square has a setoid instance, so `⟦(a, b)⟧` denotes a
term of the symmetric square.
## Tags
symmetric square, unordered pairs, symmetric powers
-/
open finset function sym
universe u
variables {α β γ : Type*}
namespace sym2
/--
This is the relation capturing the notion of pairs equivalent up to permutations.
-/
inductive rel (α : Type u) : (α × α) → (α × α) → Prop
| refl (x y : α) : rel (x, y) (x, y)
| swap (x y : α) : rel (x, y) (y, x)
attribute [refl] rel.refl
@[symm] lemma rel.symm {x y : α × α} : rel α x y → rel α y x :=
by rintro ⟨_, _⟩; constructor
@[trans] lemma rel.trans {x y z : α × α} (a : rel α x y) (b : rel α y z) : rel α x z :=
by { cases_matching* rel _ _ _; apply rel.refl <|> apply rel.swap }
lemma rel.is_equivalence : equivalence (rel α) := by tidy; apply rel.trans; assumption
instance rel.setoid (α : Type u) : setoid (α × α) := ⟨rel α, rel.is_equivalence⟩
@[simp] lemma rel_iff {x y z w : α} :
(x, y) ≈ (z, w) ↔ (x = z ∧ y = w) ∨ (x = w ∧ y = z) :=
begin
split; intro h,
{ cases h; simp },
{ cases h; rw [h.1, h.2], constructor }
end
end sym2
/--
`sym2 α` is the symmetric square of `α`, which, in other words, is the
type of unordered pairs.
It is equivalent in a natural way to multisets of cardinality 2 (see
`sym2.equiv_multiset`).
-/
@[reducible]
def sym2 (α : Type u) := quotient (sym2.rel.setoid α)
namespace sym2
@[elab_as_eliminator]
protected lemma ind {f : sym2 α → Prop} (h : ∀ x y, f ⟦(x, y)⟧) : ∀ i, f i :=
quotient.ind $ prod.rec $ by exact h
@[elab_as_eliminator]
protected lemma induction_on {f : sym2 α → Prop} (i : sym2 α) (hf : ∀ x y, f ⟦(x, y)⟧) : f i :=
i.ind hf
@[elab_as_eliminator]
protected lemma induction_on₂ {f : sym2 α → sym2 β → Prop} (i : sym2 α) (j : sym2 β)
(hf : ∀ a₁ a₂ b₁ b₂, f ⟦(a₁, a₂)⟧ ⟦(b₁, b₂)⟧) : f i j :=
quotient.induction_on₂ i j $ by { rintros ⟨a₁, a₂⟩ ⟨b₁, b₂⟩, exact hf _ _ _ _ }
protected lemma «exists» {α : Sort*} {f : sym2 α → Prop} :
(∃ (x : sym2 α), f x) ↔ ∃ x y, f ⟦(x, y)⟧ :=
(surjective_quotient_mk _).exists.trans prod.exists
protected lemma «forall» {α : Sort*} {f : sym2 α → Prop} :
(∀ (x : sym2 α), f x) ↔ ∀ x y, f ⟦(x, y)⟧ :=
(surjective_quotient_mk _).forall.trans prod.forall
lemma eq_swap {a b : α} : ⟦(a, b)⟧ = ⟦(b, a)⟧ :=
by { rw quotient.eq, apply rel.swap }
@[simp] lemma mk_prod_swap_eq {p : α × α} : ⟦p.swap⟧ = ⟦p⟧ :=
by { cases p, exact eq_swap }
lemma congr_right {a b c : α} : ⟦(a, b)⟧ = ⟦(a, c)⟧ ↔ b = c :=
by { split; intro h, { rw quotient.eq at h, cases h; refl }, rw h }
lemma congr_left {a b c : α} : ⟦(b, a)⟧ = ⟦(c, a)⟧ ↔ b = c :=
by { split; intro h, { rw quotient.eq at h, cases h; refl }, rw h }
lemma eq_iff {x y z w : α} :
⟦(x, y)⟧ = ⟦(z, w)⟧ ↔ (x = z ∧ y = w) ∨ (x = w ∧ y = z) :=
by simp
lemma mk_eq_mk_iff {p q : α × α} :
⟦p⟧ = ⟦q⟧ ↔ p = q ∨ p = q.swap :=
by { cases p, cases q, simp only [eq_iff, prod.mk.inj_iff, prod.swap_prod_mk] }
/-- The universal property of `sym2`; symmetric functions of two arguments are equivalent to
functions from `sym2`. Note that when `β` is `Prop`, it can sometimes be more convenient to use
`sym2.from_rel` instead. -/
def lift : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁} ≃ (sym2 α → β) :=
{ to_fun := λ f, quotient.lift (uncurry ↑f) $ by { rintro _ _ ⟨⟩, exacts [rfl, f.prop _ _] },
inv_fun := λ F, ⟨curry (F ∘ quotient.mk), λ a₁ a₂, congr_arg F eq_swap⟩,
left_inv := λ f, subtype.ext rfl,
right_inv := λ F, funext $ sym2.ind $ by exact λ x y, rfl }
@[simp]
lemma lift_mk (f : {f : α → α → β // ∀ a₁ a₂, f a₁ a₂ = f a₂ a₁}) (a₁ a₂ : α) :
lift f ⟦(a₁, a₂)⟧ = (f : α → α → β) a₁ a₂ := rfl
@[simp]
lemma coe_lift_symm_apply (F : sym2 α → β) (a₁ a₂ : α) :
(lift.symm F : α → α → β) a₁ a₂ = F ⟦(a₁, a₂)⟧ := rfl
/-- A two-argument version of `sym2.lift`. -/
def lift₂ : {f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂,
f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁} ≃ (sym2 α → sym2 β → γ) :=
{ to_fun := λ f, quotient.lift₂ (λ (a : α × α) (b : β × β), f.1 a.1 a.2 b.1 b.2) begin
rintro _ _ _ _ ⟨⟩ ⟨⟩,
exacts [rfl, (f.2 _ _ _ _).2, (f.2 _ _ _ _).1, (f.2 _ _ _ _).1.trans (f.2 _ _ _ _).2]
end,
inv_fun := λ F, ⟨λ a₁ a₂ b₁ b₂, F ⟦(a₁, a₂)⟧ ⟦(b₁, b₂)⟧, λ a₁ a₂ b₁ b₂,
by { split, exacts [congr_arg2 F eq_swap rfl, congr_arg2 F rfl eq_swap] }⟩,
left_inv := λ f, subtype.ext rfl,
right_inv := λ F, funext₂ $ λ a b, sym2.induction_on₂ a b $ λ _ _ _ _, rfl }
@[simp]
lemma lift₂_mk (f : {f : α → α → β → β → γ // ∀ a₁ a₂ b₁ b₂,
f a₁ a₂ b₁ b₂ = f a₂ a₁ b₁ b₂ ∧ f a₁ a₂ b₁ b₂ = f a₁ a₂ b₂ b₁}) (a₁ a₂ : α) (b₁ b₂ : β) :
lift₂ f ⟦(a₁, a₂)⟧ ⟦(b₁, b₂)⟧ = (f : α → α → β → β → γ) a₁ a₂ b₁ b₂ := rfl
@[simp]
lemma coe_lift₂_symm_apply (F : sym2 α → sym2 β → γ) (a₁ a₂ : α) (b₁ b₂ : β) :
(lift₂.symm F : α → α → β → β → γ) a₁ a₂ b₁ b₂ = F ⟦(a₁, a₂)⟧ ⟦(b₁, b₂)⟧ := rfl
/--
The functor `sym2` is functorial, and this function constructs the induced maps.
-/
def map (f : α → β) : sym2 α → sym2 β :=
quotient.map (prod.map f f)
(by { rintros _ _ h, cases h, { refl }, apply rel.swap })
@[simp] lemma map_id : map (@id α) = id := by { ext ⟨⟨x,y⟩⟩, refl }
lemma map_comp {g : β → γ} {f : α → β} : sym2.map (g ∘ f) = sym2.map g ∘ sym2.map f :=
by { ext ⟨⟨x, y⟩⟩, refl }
lemma map_map {g : β → γ} {f : α → β} (x : sym2 α) :
map g (map f x) = map (g ∘ f) x := by tidy
@[simp]
lemma map_pair_eq (f : α → β) (x y : α) : map f ⟦(x, y)⟧ = ⟦(f x, f y)⟧ := rfl
lemma map.injective {f : α → β} (hinj : injective f) : injective (map f) :=
begin
intros z z',
refine quotient.ind₂ (λ z z', _) z z',
cases z with x y,
cases z' with x' y',
repeat { rw [map_pair_eq, eq_iff] },
rintro (h|h); simp [hinj h.1, hinj h.2],
end
section membership
/-! ### Declarations about membership -/
/--
This is a predicate that determines whether a given term is a member of a term of the
symmetric square. From this point of view, the symmetric square is the subtype of
cardinality-two multisets on `α`.
-/
def mem (x : α) (z : sym2 α) : Prop :=
∃ (y : α), z = ⟦(x, y)⟧
instance : has_mem α (sym2 α) := ⟨mem⟩
lemma mem_mk_left (x y : α) : x ∈ ⟦(x, y)⟧ := ⟨y, rfl⟩
lemma mem_mk_right (x y : α) : y ∈ ⟦(x, y)⟧ := eq_swap.subst $ mem_mk_left y x
@[simp] lemma mem_iff {a b c : α} : a ∈ ⟦(b, c)⟧ ↔ a = b ∨ a = c :=
{ mp := by { rintro ⟨_, h⟩, rw eq_iff at h, tidy },
mpr := by { rintro ⟨_⟩; subst a, { apply mem_mk_left }, apply mem_mk_right } }
lemma out_fst_mem (e : sym2 α) : e.out.1 ∈ e := ⟨e.out.2, by rw [prod.mk.eta, e.out_eq]⟩
lemma out_snd_mem (e : sym2 α) : e.out.2 ∈ e := ⟨e.out.1, by rw [eq_swap, prod.mk.eta, e.out_eq]⟩
lemma ball {p : α → Prop} {a b : α} : (∀ c ∈ ⟦(a, b)⟧, p c) ↔ p a ∧ p b :=
begin
refine ⟨λ h, ⟨h _ $ mem_mk_left _ _, h _ $ mem_mk_right _ _⟩, λ h c hc, _⟩,
obtain rfl | rfl := sym2.mem_iff.1 hc,
{ exact h.1 },
{ exact h.2 }
end
/--
Given an element of the unordered pair, give the other element using `classical.some`.
See also `mem.other'` for the computable version.
-/
noncomputable def mem.other {a : α} {z : sym2 α} (h : a ∈ z) : α :=
classical.some h
@[simp]
lemma other_spec {a : α} {z : sym2 α} (h : a ∈ z) : ⟦(a, h.other)⟧ = z :=
by erw ← classical.some_spec h
lemma other_mem {a : α} {z : sym2 α} (h : a ∈ z) : h.other ∈ z :=
by { convert mem_mk_right a h.other, rw other_spec h }
lemma mem_and_mem_iff {x y : α} {z : sym2 α} (hne : x ≠ y) : x ∈ z ∧ y ∈ z ↔ z = ⟦(x, y)⟧ :=
begin
split,
{ induction z using sym2.ind with x' y',
rw [mem_iff, mem_iff],
rintro ⟨rfl | rfl, rfl | rfl⟩;
try { trivial };
simp only [sym2.eq_swap] },
{ rintro rfl, simp },
end
lemma eq_of_ne_mem {x y : α} {z z' : sym2 α} (h : x ≠ y)
(h1 : x ∈ z) (h2 : y ∈ z) (h3 : x ∈ z') (h4 : y ∈ z') : z = z' :=
((mem_and_mem_iff h).mp ⟨h1, h2⟩).trans ((mem_and_mem_iff h).mp ⟨h3, h4⟩).symm
@[ext]
protected lemma ext (z z' : sym2 α) (h : ∀ x, x ∈ z ↔ x ∈ z') : z = z' :=
begin
induction z using sym2.ind with x y,
induction z' using sym2.ind with x' y',
have hx := h x, have hy := h y, have hx' := h x', have hy' := h y',
simp only [mem_iff, eq_self_iff_true, or_true, iff_true, true_or, true_iff] at hx hy hx' hy',
cases hx; cases hy; cases hx'; cases hy'; subst_vars,
simp only [sym2.eq_swap],
end
instance mem.decidable [decidable_eq α] (x : α) (z : sym2 α) : decidable (x ∈ z) :=
quotient.rec_on_subsingleton z (λ ⟨y₁, y₂⟩, decidable_of_iff' _ mem_iff)
end membership
@[simp] lemma mem_map {f : α → β} {b : β} {z : sym2 α} :
b ∈ sym2.map f z ↔ ∃ a, a ∈ z ∧ f a = b :=
begin
induction z using sym2.ind with x y,
simp only [map, quotient.map_mk, prod.map_mk, mem_iff],
split,
{ rintro (rfl | rfl),
{ exact ⟨x, by simp⟩, },
{ exact ⟨y, by simp⟩, } },
{ rintro ⟨w, rfl | rfl, rfl⟩; simp, },
end
@[congr] lemma map_congr {f g : α → β} {s : sym2 α} (h : ∀ x ∈ s, f x = g x) :
map f s = map g s :=
begin
ext y,
simp only [mem_map],
split; { rintro ⟨w, hw, rfl⟩, exact ⟨w, hw, by simp [hw, h]⟩ },
end
/-- Note: `sym2.map_id` will not simplify `sym2.map id z` due to `sym2.map_congr`. -/
@[simp] lemma map_id' : map (λ (x : α), x) = id := map_id
/-! ### Diagonal -/
/--
A type `α` is naturally included in the diagonal of `α × α`, and this function gives the image
of this diagonal in `sym2 α`.
-/
def diag (x : α) : sym2 α := ⟦(x, x)⟧
lemma diag_injective : function.injective (sym2.diag : α → sym2 α) :=
λ x y h, by cases quotient.exact h; refl
/--
A predicate for testing whether an element of `sym2 α` is on the diagonal.
-/
def is_diag : sym2 α → Prop :=
lift ⟨eq, λ _ _, propext eq_comm⟩
lemma mk_is_diag_iff {x y : α} : is_diag ⟦(x, y)⟧ ↔ x = y := iff.rfl
@[simp]
lemma is_diag_iff_proj_eq (z : α × α) : is_diag ⟦z⟧ ↔ z.1 = z.2 :=
prod.rec_on z $ λ _ _, mk_is_diag_iff
@[simp]
lemma diag_is_diag (a : α) : is_diag (diag a) := eq.refl a
lemma is_diag.mem_range_diag {z : sym2 α} : is_diag z → z ∈ set.range (@diag α) :=
begin
induction z using sym2.ind with x y,
rintro (rfl : x = y),
exact ⟨_, rfl⟩,
end
lemma is_diag_iff_mem_range_diag (z : sym2 α) : is_diag z ↔ z ∈ set.range (@diag α) :=
⟨is_diag.mem_range_diag, λ ⟨i, hi⟩, hi ▸ diag_is_diag i⟩
instance is_diag.decidable_pred (α : Type u) [decidable_eq α] : decidable_pred (@is_diag α) :=
by { refine λ z, quotient.rec_on_subsingleton z (λ a, _), erw is_diag_iff_proj_eq, apply_instance }
lemma other_ne {a : α} {z : sym2 α} (hd : ¬is_diag z) (h : a ∈ z) : h.other ≠ a :=
begin
contrapose! hd,
have h' := sym2.other_spec h,
rw hd at h',
rw ←h',
simp,
end
section relations
/-! ### Declarations about symmetric relations -/
variables {r : α → α → Prop}
/--
Symmetric relations define a set on `sym2 α` by taking all those pairs
of elements that are related.
-/
def from_rel (sym : symmetric r) : set (sym2 α) :=
set_of (lift ⟨r, λ x y, propext ⟨λ h, sym h, λ h, sym h⟩⟩)
@[simp]
lemma from_rel_proj_prop {sym : symmetric r} {z : α × α} : ⟦z⟧ ∈ from_rel sym ↔ r z.1 z.2 := iff.rfl
@[simp]
lemma from_rel_prop {sym : symmetric r} {a b : α} : ⟦(a, b)⟧ ∈ from_rel sym ↔ r a b := iff.rfl
lemma from_rel_bot : from_rel (λ (x y : α) z, z : symmetric ⊥) = ∅ :=
begin
apply set.eq_empty_of_forall_not_mem (λ e, _),
refine e.ind _,
simp [-set.bot_eq_empty, Prop.bot_eq_false],
end
lemma from_rel_top : from_rel (λ (x y : α) z, z : symmetric ⊤) = set.univ :=
begin
apply set.eq_univ_of_forall (λ e, _),
refine e.ind _,
simp [-set.top_eq_univ, Prop.top_eq_true],
end
lemma from_rel_irreflexive {sym : symmetric r} :
irreflexive r ↔ ∀ {z}, z ∈ from_rel sym → ¬is_diag z :=
{ mp := λ h, sym2.ind $ by { rintros a b hr (rfl : a = b), exact h _ hr },
mpr := λ h x hr, h (from_rel_prop.mpr hr) rfl }
lemma mem_from_rel_irrefl_other_ne {sym : symmetric r} (irrefl : irreflexive r)
{a : α} {z : sym2 α} (hz : z ∈ from_rel sym) (h : a ∈ z) : h.other ≠ a :=
other_ne (from_rel_irreflexive.mp irrefl hz) h
instance from_rel.decidable_pred (sym : symmetric r) [h : decidable_rel r] :
decidable_pred (∈ sym2.from_rel sym) :=
λ z, quotient.rec_on_subsingleton z (λ x, h _ _)
/-- The inverse to `sym2.from_rel`. Given a set on `sym2 α`, give a symmetric relation on `α`
(see `sym2.to_rel_symmetric`). -/
def to_rel (s : set (sym2 α)) (x y : α) : Prop := ⟦(x, y)⟧ ∈ s
@[simp] lemma to_rel_prop (s : set (sym2 α)) (x y : α) : to_rel s x y ↔ ⟦(x, y)⟧ ∈ s := iff.rfl
lemma to_rel_symmetric (s : set (sym2 α)) : symmetric (to_rel s) := λ x y, by simp [eq_swap]
lemma to_rel_from_rel (sym : symmetric r) : to_rel (from_rel sym) = r := rfl
lemma from_rel_to_rel (s : set (sym2 α)) : from_rel (to_rel_symmetric s) = s :=
set.ext (λ z, sym2.ind (λ x y, iff.rfl) z)
end relations
section sym_equiv
/-! ### Equivalence to the second symmetric power -/
local attribute [instance] vector.perm.is_setoid
private def from_vector : vector α 2 → α × α
| ⟨[a, b], h⟩ := (a, b)
private lemma perm_card_two_iff {a₁ b₁ a₂ b₂ : α} :
[a₁, b₁].perm [a₂, b₂] ↔ a₁ = a₂ ∧ b₁ = b₂ ∨ a₁ = b₂ ∧ b₁ = a₂ :=
{ mp := by { simp [← multiset.coe_eq_coe, ← multiset.cons_coe, multiset.cons_eq_cons], tidy },
mpr := by { intro h, cases h; rw [h.1, h.2], apply list.perm.swap', refl } }
/--
The symmetric square is equivalent to length-2 vectors up to permutations.
-/
def sym2_equiv_sym' : equiv (sym2 α) (sym' α 2) :=
{ to_fun := quotient.map
(λ (x : α × α), ⟨[x.1, x.2], rfl⟩)
(by { rintros _ _ ⟨_⟩, { refl }, apply list.perm.swap', refl }),
inv_fun := quotient.map from_vector (begin
rintros ⟨x, hx⟩ ⟨y, hy⟩ h,
cases x with _ x, { simpa using hx, },
cases x with _ x, { simpa using hx, },
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
cases y with _ y, { simpa using hy, },
cases y with _ y, { simpa using hy, },
cases y with _ y, swap, { exfalso, simp at hy, linarith [hy] },
rcases perm_card_two_iff.mp h with ⟨rfl,rfl⟩|⟨rfl,rfl⟩, { refl },
apply sym2.rel.swap,
end),
left_inv := by tidy,
right_inv := λ x, begin
refine quotient.rec_on_subsingleton x (λ x, _),
{ cases x with x hx,
cases x with _ x, { simpa using hx, },
cases x with _ x, { simpa using hx, },
cases x with _ x, swap, { exfalso, simp at hx, linarith [hx] },
refl },
end }
/--
The symmetric square is equivalent to the second symmetric power.
-/
def equiv_sym (α : Type*) : sym2 α ≃ sym α 2 :=
equiv.trans sym2_equiv_sym' sym_equiv_sym'.symm
/--
The symmetric square is equivalent to multisets of cardinality
two. (This is currently a synonym for `equiv_sym`, but it's provided
in case the definition for `sym` changes.)
-/
def equiv_multiset (α : Type*) : sym2 α ≃ {s : multiset α // s.card = 2} :=
equiv_sym α
end sym_equiv
section decidable
/--
An algorithm for computing `sym2.rel`.
-/
def rel_bool [decidable_eq α] (x y : α × α) : bool :=
if x.1 = y.1 then x.2 = y.2 else
if x.1 = y.2 then x.2 = y.1 else ff
lemma rel_bool_spec [decidable_eq α] (x y : α × α) : ↥(rel_bool x y) ↔ rel α x y :=
begin
cases x with x₁ x₂, cases y with y₁ y₂,
dsimp [rel_bool], split_ifs;
simp only [false_iff, bool.coe_sort_ff, bool.of_to_bool_iff],
rotate 2, { contrapose! h, cases h; cc },
all_goals { subst x₁, split; intro h1,
{ subst h1; apply sym2.rel.swap },
{ cases h1; cc } }
end
/--
Given `[decidable_eq α]` and `[fintype α]`, the following instance gives `fintype (sym2 α)`.
-/
instance (α : Type*) [decidable_eq α] : decidable_rel (sym2.rel α) :=
λ x y, decidable_of_bool (rel_bool x y) (rel_bool_spec x y)
/-! ### The other element of an element of the symmetric square -/
/--
A function that gives the other element of a pair given one of the elements. Used in `mem.other'`.
-/
private def pair_other [decidable_eq α] (a : α) (z : α × α) : α := if a = z.1 then z.2 else z.1
/--
Get the other element of the unordered pair using the decidable equality.
This is the computable version of `mem.other`.
-/
def mem.other' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : α :=
quot.rec (λ x h', pair_other a x) (begin
clear h z,
intros x y h,
ext hy,
convert_to pair_other a x = _,
{ have h' : ∀ {c e h}, @eq.rec _ ⟦x⟧ (λ s, a ∈ s → α)
(λ _, pair_other a x) c e h = pair_other a x,
{ intros _ e _, subst e },
apply h', },
have h' := (rel_bool_spec x y).mpr h,
cases x with x₁ x₂, cases y with y₁ y₂,
cases mem_iff.mp hy with hy'; subst a; dsimp [rel_bool] at h';
split_ifs at h'; try { rw bool.of_to_bool_iff at h', subst x₁, subst x₂ }; dsimp [pair_other],
simp only [ne.symm h_1, if_true, eq_self_iff_true, if_false],
exfalso, exact bool.not_ff h',
simp only [h_1, if_true, eq_self_iff_true, if_false],
exfalso, exact bool.not_ff h',
end) z h
@[simp]
lemma other_spec' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : ⟦(a, h.other')⟧ = z :=
begin
induction z, cases z with x y,
have h' := mem_iff.mp h,
dsimp [mem.other', quot.rec, pair_other],
cases h'; subst a,
{ simp only [eq_self_iff_true], refl, },
{ split_ifs, subst h_1, refl, rw eq_swap, refl, },
refl,
end
@[simp]
lemma other_eq_other' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : h.other = h.other' :=
by rw [←congr_right, other_spec' h, other_spec]
lemma other_mem' [decidable_eq α] {a : α} {z : sym2 α} (h : a ∈ z) : h.other' ∈ z :=
by { rw ←other_eq_other', exact other_mem h }
lemma other_invol' [decidable_eq α] {a : α} {z : sym2 α} (ha : a ∈ z) (hb : ha.other' ∈ z) :
hb.other' = a :=
begin
induction z, cases z with x y,
dsimp [mem.other', quot.rec, pair_other] at hb,
split_ifs at hb; dsimp [mem.other', quot.rec, pair_other],
simp only [h, if_true, eq_self_iff_true],
split_ifs, assumption, refl,
simp only [h, if_false, eq_self_iff_true],
exact ((mem_iff.mp ha).resolve_left h).symm,
refl,
end
lemma other_invol {a : α} {z : sym2 α} (ha : a ∈ z) (hb : ha.other ∈ z) : hb.other = a :=
begin
classical,
rw other_eq_other' at hb ⊢,
convert other_invol' ha hb,
rw other_eq_other',
end
lemma filter_image_quotient_mk_is_diag [decidable_eq α] (s : finset α) :
((s ×ˢ s).image quotient.mk).filter is_diag = s.diag.image quotient.mk :=
begin
ext z,
induction z using quotient.induction_on,
rcases z with ⟨x, y⟩,
simp only [mem_image, mem_diag, exists_prop, mem_filter, prod.exists, mem_product],
split,
{ rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩,
rw [←h, sym2.mk_is_diag_iff] at hab,
exact ⟨a, b, ⟨ha, hab⟩, h⟩ },
{ rintro ⟨a, b, ⟨ha, rfl⟩, h⟩,
rw ←h,
exact ⟨⟨a, a, ⟨ha, ha⟩, rfl⟩, rfl⟩ }
end
lemma filter_image_quotient_mk_not_is_diag [decidable_eq α] (s : finset α) :
((s ×ˢ s).image quotient.mk).filter (λ a : sym2 α, ¬a.is_diag) =
s.off_diag.image quotient.mk :=
begin
ext z,
induction z using quotient.induction_on,
rcases z with ⟨x, y⟩,
simp only [mem_image, mem_off_diag, mem_filter, prod.exists, mem_product],
split,
{ rintro ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩,
rw [←h, sym2.mk_is_diag_iff] at hab,
exact ⟨a, b, ⟨ha, hb, hab⟩, h⟩ },
{ rintro ⟨a, b, ⟨ha, hb, hab⟩, h⟩,
rw [ne.def, ←sym2.mk_is_diag_iff, h] at hab,
exact ⟨⟨a, b, ⟨ha, hb⟩, h⟩, hab⟩ }
end
end decidable
instance [subsingleton α] : subsingleton (sym2 α) :=
(equiv_sym α).injective.subsingleton
instance [unique α] : unique (sym2 α) := unique.mk' _
instance [is_empty α] : is_empty (sym2 α) := (equiv_sym α).is_empty
instance [nontrivial α] : nontrivial (sym2 α) := diag_injective.nontrivial
end sym2
|
e38b55dd3d418c0ad80022b3e5256670bcc2703f | 618003631150032a5676f229d13a079ac875ff77 | /src/data/list/intervals.lean | ee9ea75256a196430e2d467cd2c2a92d7d98d2a2 | [
"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 | 6,399 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import data.list.range
import data.list.bag_inter
open nat
namespace list
/--
`Ico n m` is the list of natural numbers `n ≤ x < m`.
(Ico stands for "interval, closed-open".)
See also `data/set/intervals.lean` for `set.Ico`, modelling intervals in general preorders, and
`multiset.Ico` and `finset.Ico` for `n ≤ x < m` as a multiset or as a finset.
@TODO (anyone): Define `Ioo` and `Icc`, state basic lemmas about them.
@TODO (anyone): Prove that `finset.Ico` and `set.Ico` agree.
@TODO (anyone): Also do the versions for integers?
@TODO (anyone): One could generalise even further, defining
'locally finite partial orders', for which `set.Ico a b` is `[finite]`, and
'locally finite total orders', for which there is a list model.
-/
def Ico (n m : ℕ) : list ℕ := range' n (m - n)
namespace Ico
theorem zero_bot (n : ℕ) : Ico 0 n = range n :=
by rw [Ico, nat.sub_zero, range_eq_range']
@[simp] theorem length (n m : ℕ) : length (Ico n m) = m - n :=
by dsimp [Ico]; simp only [length_range']
theorem pairwise_lt (n m : ℕ) : pairwise (<) (Ico n m) :=
by dsimp [Ico]; simp only [pairwise_lt_range']
theorem nodup (n m : ℕ) : nodup (Ico n m) :=
by dsimp [Ico]; simp only [nodup_range']
@[simp] theorem mem {n m l : ℕ} : l ∈ Ico n m ↔ n ≤ l ∧ l < m :=
suffices n ≤ l ∧ l < n + (m - n) ↔ n ≤ l ∧ l < m, by simp [Ico, this],
begin
cases le_total n m with hnm hmn,
{ rw [nat.add_sub_of_le hnm] },
{ rw [nat.sub_eq_zero_of_le hmn, add_zero],
exact and_congr_right (assume hnl, iff.intro
(assume hln, (not_le_of_gt hln hnl).elim)
(assume hlm, lt_of_lt_of_le hlm hmn)) }
end
theorem eq_nil_of_le {n m : ℕ} (h : m ≤ n) : Ico n m = [] :=
by simp [Ico, nat.sub_eq_zero_of_le h]
theorem map_add (n m k : ℕ) : (Ico n m).map ((+) k) = Ico (n + k) (m + k) :=
by rw [Ico, Ico, map_add_range', nat.add_sub_add_right, add_comm n k]
theorem map_sub (n m k : ℕ) (h₁ : k ≤ n) : (Ico n m).map (λ x, x - k) = Ico (n - k) (m - k) :=
begin
by_cases h₂ : n < m,
{ rw [Ico, Ico],
rw nat.sub_sub_sub_cancel_right h₁,
rw [map_sub_range' _ _ _ h₁] },
{ simp at h₂,
rw [eq_nil_of_le h₂],
rw [eq_nil_of_le (nat.sub_le_sub_right h₂ _)],
refl }
end
@[simp] theorem self_empty {n : ℕ} : Ico n n = [] :=
eq_nil_of_le (le_refl n)
@[simp] theorem eq_empty_iff {n m : ℕ} : Ico n m = [] ↔ m ≤ n :=
iff.intro (assume h, nat.le_of_sub_eq_zero $ by rw [← length, h]; refl) eq_nil_of_le
lemma append_consecutive {n m l : ℕ} (hnm : n ≤ m) (hml : m ≤ l) :
Ico n m ++ Ico m l = Ico n l :=
begin
dunfold Ico,
convert range'_append _ _ _,
{ exact (nat.add_sub_of_le hnm).symm },
{ rwa [← nat.add_sub_assoc hnm, nat.sub_add_cancel] }
end
@[simp] lemma inter_consecutive (n m l : ℕ) : Ico n m ∩ Ico m l = [] :=
begin
apply eq_nil_iff_forall_not_mem.2,
intro a,
simp only [and_imp, not_and, not_lt, list.mem_inter, list.Ico.mem],
intros h₁ h₂ h₃,
exfalso,
exact not_lt_of_ge h₃ h₂
end
@[simp] lemma bag_inter_consecutive (n m l : ℕ) : list.bag_inter (Ico n m) (Ico m l) = [] :=
(bag_inter_nil_iff_inter_nil _ _).2 (inter_consecutive n m l)
@[simp] theorem succ_singleton {n : ℕ} : Ico n (n+1) = [n] :=
by dsimp [Ico]; simp [nat.add_sub_cancel_left]
theorem succ_top {n m : ℕ} (h : n ≤ m) : Ico n (m + 1) = Ico n m ++ [m] :=
by rwa [← succ_singleton, append_consecutive]; exact nat.le_succ _
theorem eq_cons {n m : ℕ} (h : n < m) : Ico n m = n :: Ico (n + 1) m :=
by rw [← append_consecutive (nat.le_succ n) h, succ_singleton]; refl
@[simp] theorem pred_singleton {m : ℕ} (h : 0 < m) : Ico (m - 1) m = [m - 1] :=
by dsimp [Ico]; rw nat.sub_sub_self h; simp
theorem chain'_succ (n m : ℕ) : chain' (λa b, b = succ a) (Ico n m) :=
begin
by_cases n < m,
{ rw [eq_cons h], exact chain_succ_range' _ _ },
{ rw [eq_nil_of_le (le_of_not_gt h)], trivial }
end
@[simp] theorem not_mem_top {n m : ℕ} : m ∉ Ico n m :=
by simp; intros; refl
lemma filter_lt_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, x < l) = Ico n m :=
filter_eq_self.2 $ assume k hk, lt_of_lt_of_le (mem.1 hk).2 hml
lemma filter_lt_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, x < l) = [] :=
filter_eq_nil.2 $ assume k hk, not_lt_of_le $ le_trans hln $ (mem.1 hk).1
lemma filter_lt_of_ge {n m l : ℕ} (hlm : l ≤ m) : (Ico n m).filter (λ x, x < l) = Ico n l :=
begin
cases le_total n l with hnl hln,
{ rw [← append_consecutive hnl hlm, filter_append,
filter_lt_of_top_le (le_refl l), filter_lt_of_le_bot (le_refl l), append_nil] },
{ rw [eq_nil_of_le hln, filter_lt_of_le_bot hln] }
end
@[simp] lemma filter_lt (n m l : ℕ) : (Ico n m).filter (λ x, x < l) = Ico n (min m l) :=
begin
cases le_total m l with hml hlm,
{ rw [min_eq_left hml, filter_lt_of_top_le hml] },
{ rw [min_eq_right hlm, filter_lt_of_ge hlm] }
end
lemma filter_le_of_le_bot {n m l : ℕ} (hln : l ≤ n) : (Ico n m).filter (λ x, l ≤ x) = Ico n m :=
filter_eq_self.2 $ assume k hk, le_trans hln (mem.1 hk).1
lemma filter_le_of_top_le {n m l : ℕ} (hml : m ≤ l) : (Ico n m).filter (λ x, l ≤ x) = [] :=
filter_eq_nil.2 $ assume k hk, not_le_of_gt (lt_of_lt_of_le (mem.1 hk).2 hml)
lemma filter_le_of_le {n m l : ℕ} (hnl : n ≤ l) : (Ico n m).filter (λ x, l ≤ x) = Ico l m :=
begin
cases le_total l m with hlm hml,
{ rw [← append_consecutive hnl hlm, filter_append,
filter_le_of_top_le (le_refl l), filter_le_of_le_bot (le_refl l), nil_append] },
{ rw [eq_nil_of_le hml, filter_le_of_top_le hml] }
end
@[simp] lemma filter_le (n m l : ℕ) : (Ico n m).filter (λ x, l ≤ x) = Ico (_root_.max n l) m :=
begin
cases le_total n l with hnl hln,
{ rw [max_eq_right hnl, filter_le_of_le hnl] },
{ rw [max_eq_left hln, filter_le_of_le_bot hln] }
end
/--
For any natural numbers n, a, and b, one of the following holds:
1. n < a
2. n ≥ b
3. n ∈ Ico a b
-/
lemma trichotomy (n a b : ℕ) : n < a ∨ b ≤ n ∨ n ∈ Ico a b :=
begin
by_cases h₁ : n < a,
{ left, exact h₁ },
{ right,
by_cases h₂ : n ∈ Ico a b,
{ right, exact h₂ },
{ left, simp only [Ico.mem, not_and, not_lt] at *, exact h₂ h₁ }}
end
end Ico
end list
|
71182050d7b9c1b7b113a70805243c1c4525457d | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/int/associated.lean | 0927f1b24c1f72121973cbff06c8d2c0f602ef2c | [
"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 | 801 | lean | /-
Copyright (c) 2022 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import algebra.associated
import data.int.units
/-!
# Associated elements and the integers
This file contains some results on equality up to units in the integers.
## Main results
* `int.nat_abs_eq_iff_associated`: the absolute value is equal iff integers are associated
-/
lemma int.nat_abs_eq_iff_associated {a b : ℤ} :
a.nat_abs = b.nat_abs ↔ associated a b :=
begin
refine int.nat_abs_eq_nat_abs_iff.trans _,
split,
{ rintro (rfl | rfl),
{ refl },
{ exact ⟨-1, by simp⟩ } },
{ rintro ⟨u, rfl⟩,
obtain (rfl | rfl) := int.units_eq_one_or u,
{ exact or.inl (by simp) },
{ exact or.inr (by simp) } }
end
|
f0fcedcb779c55c89d3dfe43ac306e42ba39437d | bbecf0f1968d1fba4124103e4f6b55251d08e9c4 | /src/group_theory/perm/concrete_cycle.lean | fbba3da861e55d6b522049af67e6e1e0db0e2b62 | [
"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 | 19,618 | lean | /-
Copyright (c) 2021 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import group_theory.perm.list
import data.list.cycle
import group_theory.perm.cycle_type
/-!
# Properties of cyclic permutations constructed from lists/cycles
In the following, `{α : Type*} [fintype α] [decidable_eq α]`.
## Main definitions
* `cycle.form_perm`: the cyclic permutation created by looping over a `cycle α`
* `equiv.perm.to_list`: the list formed by iterating application of a permutation
* `equiv.perm.to_cycle`: the cycle formed by iterating application of a permutation
* `equiv.perm.iso_cycle`: the equivalence between cyclic permutations `f : perm α`
and the terms of `cycle α` that correspond to them
* `equiv.perm.iso_cycle'`: the same equivalence as `equiv.perm.iso_cycle`
but with evaluation via choosing over fintypes
* The notation `c[1, 2, 3]` to emulate notation of cyclic permutations `(1 2 3)`
* A `has_repr` instance for any `perm α`, by representing the `finset` of
`cycle α` that correspond to the cycle factors.
## Main results
* `list.is_cycle_form_perm`: a nontrivial list without duplicates, when interpreted as
a permutation, is cyclic
* `equiv.perm.is_cycle.exists_unique_cycle`: there is only one nontrivial `cycle α`
corresponding to each cyclic `f : perm α`
## Implementation details
The forward direction of `equiv.perm.iso_cycle'` uses `fintype.choose` of the uniqueness
result, relying on the `fintype` instance of a `cycle.nodup` subtype.
It is unclear if this works faster than the `equiv.perm.to_cycle`, which relies
on recursion over `finset.univ`.
Running `#eval` on even a simple noncyclic permutation `c[(1 : fin 7), 2, 3] * c[0, 5]`
to show it takes a long time. TODO: is this because computing the cycle factors is slow?
-/
open equiv equiv.perm list
namespace list
variables {α : Type*} [decidable_eq α] {l l' : list α}
lemma form_perm_disjoint_iff (hl : nodup l) (hl' : nodup l')
(hn : 2 ≤ l.length) (hn' : 2 ≤ l'.length) :
perm.disjoint (form_perm l) (form_perm l') ↔ l.disjoint l' :=
begin
rw [disjoint_iff_eq_or_eq, list.disjoint],
split,
{ rintro h x hx hx',
specialize h x,
rw [form_perm_apply_mem_eq_self_iff _ hl _ hx,
form_perm_apply_mem_eq_self_iff _ hl' _ hx'] at h,
rcases h with hl | hl'; linarith },
{ intros h x,
by_cases hx : x ∈ l; by_cases hx' : x ∈ l',
{ exact (h hx hx').elim },
all_goals { have := form_perm_eq_self_of_not_mem _ _ ‹_›, tauto } }
end
lemma is_cycle_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
is_cycle (form_perm l) :=
begin
cases l with x l,
{ norm_num at hn },
induction l with y l IH generalizing x,
{ norm_num at hn },
{ use x,
split,
{ rwa form_perm_apply_mem_ne_self_iff _ hl _ (mem_cons_self _ _) },
{ intros w hw,
have : w ∈ (x :: y :: l) := mem_of_form_perm_ne_self _ _ hw,
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem this,
use k,
simp only [gpow_coe_nat, form_perm_pow_apply_head _ _ hl k, nat.mod_eq_of_lt hk] } }
end
lemma pairwise_same_cycle_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
pairwise (l.form_perm.same_cycle) l :=
pairwise.imp_mem.mpr (pairwise_of_forall (λ x y hx hy, (is_cycle_form_perm hl hn).same_cycle
((form_perm_apply_mem_ne_self_iff _ hl _ hx).mpr hn)
((form_perm_apply_mem_ne_self_iff _ hl _ hy).mpr hn)))
lemma cycle_of_form_perm (hl : nodup l) (hn : 2 ≤ l.length) (x) :
cycle_of l.attach.form_perm x = l.attach.form_perm :=
have hn : 2 ≤ l.attach.length := by rwa ← length_attach at hn,
have hl : l.attach.nodup := by rwa ← nodup_attach at hl,
(is_cycle_form_perm hl hn).cycle_of_eq
((form_perm_apply_mem_ne_self_iff _ hl _ (mem_attach _ _)).mpr hn)
lemma cycle_type_form_perm (hl : nodup l) (hn : 2 ≤ l.length) :
cycle_type l.attach.form_perm = {l.length} :=
begin
rw ←length_attach at hn,
rw ←nodup_attach at hl,
rw cycle_type_eq [l.attach.form_perm],
{ simp only [map, function.comp_app],
rw [support_form_perm_of_nodup _ hl, card_to_finset, erase_dup_eq_self.mpr hl],
{ simpa },
{ intros x h,
simpa [h, nat.succ_le_succ_iff] using hn } },
{ simp },
{ simpa using is_cycle_form_perm hl hn },
{ simp }
end
lemma form_perm_apply_mem_eq_next (hl : nodup l) (x : α) (hx : x ∈ l) :
form_perm l x = next l x hx :=
begin
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx,
rw [next_nth_le _ hl, form_perm_apply_nth_le _ hl]
end
end list
namespace cycle
variables {α : Type*} [decidable_eq α] (s s' : cycle α)
/--
A cycle `s : cycle α` , given `nodup s` can be interpreted as a `equiv.perm α`
where each element in the list is permuted to the next one, defined as `form_perm`.
-/
def form_perm : Π (s : cycle α) (h : nodup s), equiv.perm α :=
λ s, quot.hrec_on s (λ l h, form_perm l)
(λ l₁ l₂ (h : l₁ ~r l₂),
begin
ext,
{ exact h.nodup_iff },
{ intros h₁ h₂ _,
exact heq_of_eq (form_perm_eq_of_is_rotated h₁ h) }
end)
@[simp] lemma form_perm_coe (l : list α) (hl : l.nodup) :
form_perm (l : cycle α) hl = l.form_perm := rfl
lemma form_perm_subsingleton (s : cycle α) (h : subsingleton s) :
form_perm s h.nodup = 1 :=
begin
induction s using quot.induction_on,
simp only [form_perm_coe, mk_eq_coe],
simp only [length_subsingleton_iff, length_coe, mk_eq_coe] at h,
cases s with hd tl,
{ simp },
{ simp only [length_eq_zero, add_le_iff_nonpos_left, list.length, nonpos_iff_eq_zero] at h,
simp [h] }
end
lemma is_cycle_form_perm (s : cycle α) (h : nodup s) (hn : nontrivial s) :
is_cycle (form_perm s h) :=
begin
induction s using quot.induction_on,
exact list.is_cycle_form_perm h (length_nontrivial hn)
end
lemma support_form_perm [fintype α] (s : cycle α) (h : nodup s) (hn : nontrivial s) :
support (form_perm s h) = s.to_finset :=
begin
induction s using quot.induction_on,
refine support_form_perm_of_nodup s h _,
rintro _ rfl,
simpa [nat.succ_le_succ_iff] using length_nontrivial hn
end
lemma form_perm_eq_self_of_not_mem (s : cycle α) (h : nodup s) (x : α) (hx : x ∉ s) :
form_perm s h x = x :=
begin
induction s using quot.induction_on,
simpa using list.form_perm_eq_self_of_not_mem _ _ hx
end
lemma form_perm_apply_mem_eq_next (s : cycle α) (h : nodup s) (x : α) (hx : x ∈ s) :
form_perm s h x = next s h x hx :=
begin
induction s using quot.induction_on,
simpa using list.form_perm_apply_mem_eq_next h _ _
end
lemma form_perm_reverse (s : cycle α) (h : nodup s) :
form_perm s.reverse (nodup_reverse_iff.mpr h) = (form_perm s h)⁻¹ :=
begin
induction s using quot.induction_on,
simpa using form_perm_reverse _ h
end
lemma form_perm_eq_form_perm_iff {α : Type*} [decidable_eq α]
{s s' : cycle α} {hs : s.nodup} {hs' : s'.nodup} :
s.form_perm hs = s'.form_perm hs' ↔ s = s' ∨ s.subsingleton ∧ s'.subsingleton :=
begin
rw [cycle.length_subsingleton_iff, cycle.length_subsingleton_iff],
revert s s',
intros s s',
apply quotient.induction_on₂' s s',
intros l l',
simpa using form_perm_eq_form_perm_iff
end
end cycle
variables {α : Type*}
namespace equiv.perm
variables [fintype α] [decidable_eq α] (p : equiv.perm α) (x : α)
/--
`equiv.perm.to_list (f : perm α) (x : α)` generates the list `[x, f x, f (f x), ...]`
until looping. That means when `f x = x`, `to_list f x = []`.
-/
def to_list : list α :=
(list.range (cycle_of p x).support.card).map (λ k, (p ^ k) x)
@[simp] lemma to_list_one : to_list (1 : perm α) x = [] :=
by simp [to_list, cycle_of_one]
@[simp] lemma to_list_eq_nil_iff {p : perm α} {x} : to_list p x = [] ↔ x ∉ p.support :=
by simp [to_list]
@[simp] lemma length_to_list : length (to_list p x) = (cycle_of p x).support.card :=
by simp [to_list]
lemma to_list_ne_singleton (y : α) : to_list p x ≠ [y] :=
begin
intro H,
simpa [card_support_ne_one] using congr_arg length H
end
lemma two_le_length_to_list_iff_mem_support {p : perm α} {x : α} :
2 ≤ length (to_list p x) ↔ x ∈ p.support :=
by simp
lemma length_to_list_pos_of_mem_support (h : x ∈ p.support) : 0 < length (to_list p x) :=
zero_lt_two.trans_le (two_le_length_to_list_iff_mem_support.mpr h)
lemma nth_le_to_list (n : ℕ) (hn : n < length (to_list p x)) :
nth_le (to_list p x) n hn = (p ^ n) x :=
by simp [to_list]
lemma to_list_nth_le_zero (h : x ∈ p.support) :
(to_list p x).nth_le 0 (length_to_list_pos_of_mem_support _ _ h) = x :=
by simp [to_list]
variables {p} {x}
lemma mem_to_list_iff {y : α} :
y ∈ to_list p x ↔ same_cycle p x y ∧ x ∈ p.support :=
begin
simp only [to_list, mem_range, mem_map],
split,
{ rintro ⟨n, hx, rfl⟩,
refine ⟨⟨n, rfl⟩, _⟩,
contrapose! hx,
rw ←support_cycle_of_eq_nil_iff at hx,
simp [hx] },
{ rintro ⟨h, hx⟩,
simpa using same_cycle.nat_of_mem_support _ h hx }
end
lemma nodup_to_list (p : perm α) (x : α) :
nodup (to_list p x) :=
begin
by_cases hx : p x = x,
{ rw [←not_mem_support, ←to_list_eq_nil_iff] at hx,
simp [hx] },
have hc : is_cycle (cycle_of p x) := is_cycle_cycle_of p hx,
rw nodup_iff_nth_le_inj,
rintros n m hn hm,
rw [length_to_list, ←order_of_is_cycle hc] at hm hn,
rw [←cycle_of_apply_self, ←ne.def, ←mem_support] at hx,
rw [nth_le_to_list, nth_le_to_list,
←cycle_of_pow_apply_self p x n, ←cycle_of_pow_apply_self p x m],
cases n; cases m,
{ simp },
{ rw [←hc.mem_support_pos_pow_iff_of_lt_order_of m.zero_lt_succ hm,
mem_support, cycle_of_pow_apply_self] at hx,
simp [hx.symm] },
{ rw [←hc.mem_support_pos_pow_iff_of_lt_order_of n.zero_lt_succ hn,
mem_support, cycle_of_pow_apply_self] at hx,
simp [hx] },
intro h,
have hn' : ¬ order_of (p.cycle_of x) ∣ n.succ := nat.not_dvd_of_pos_of_lt n.zero_lt_succ hn,
have hm' : ¬ order_of (p.cycle_of x) ∣ m.succ := nat.not_dvd_of_pos_of_lt m.zero_lt_succ hm,
rw ←hc.support_pow_eq_iff at hn' hm',
rw [←nat.mod_eq_of_lt hn, ←nat.mod_eq_of_lt hm, ←pow_inj_mod],
refine support_congr _ _,
{ rw [hm', hn'],
exact finset.subset.refl _ },
{ rw hm',
intros y hy,
obtain ⟨k, rfl⟩ := hc.exists_pow_eq (mem_support.mp hx) (mem_support.mp hy),
rw [←mul_apply, (commute.pow_pow_self _ _ _).eq, mul_apply, h, ←mul_apply, ←mul_apply,
(commute.pow_pow_self _ _ _).eq] }
end
lemma next_to_list_eq_apply (p : perm α) (x y : α) (hy : y ∈ to_list p x) :
next (to_list p x) y hy = p y :=
begin
rw mem_to_list_iff at hy,
obtain ⟨k, hk, hk'⟩ := hy.left.nat_of_mem_support _ hy.right,
rw ←nth_le_to_list p x k (by simpa using hk) at hk',
simp_rw ←hk',
rw [next_nth_le _ (nodup_to_list _ _), nth_le_to_list, nth_le_to_list, ←mul_apply, ←pow_succ,
length_to_list, pow_apply_eq_pow_mod_order_of_cycle_of_apply p (k + 1), order_of_is_cycle],
exact is_cycle_cycle_of _ (mem_support.mp hy.right)
end
lemma to_list_pow_apply_eq_rotate (p : perm α) (x : α) (k : ℕ) :
p.to_list ((p ^ k) x) = (p.to_list x).rotate k :=
begin
apply ext_le,
{ simp },
{ intros n hn hn',
rw [nth_le_to_list, nth_le_rotate, nth_le_to_list, length_to_list,
pow_mod_card_support_cycle_of_self_apply, pow_add, mul_apply] }
end
lemma same_cycle.to_list_is_rotated {f : perm α} {x y : α} (h : same_cycle f x y) :
to_list f x ~r to_list f y :=
begin
by_cases hx : x ∈ f.support,
{ obtain ⟨_ | k, hk, hy⟩ := h.nat_of_mem_support _ hx,
{ simp only [coe_one, id.def, pow_zero] at hy,
simp [hy] },
use k.succ,
rw [←to_list_pow_apply_eq_rotate, hy] },
{ rw [to_list_eq_nil_iff.mpr hx, is_rotated_nil_iff', eq_comm, to_list_eq_nil_iff],
rwa ←h.mem_support_iff }
end
lemma pow_apply_mem_to_list_iff_mem_support {n : ℕ} :
(p ^ n) x ∈ p.to_list x ↔ x ∈ p.support :=
begin
rw [mem_to_list_iff, and_iff_right_iff_imp],
refine λ _, same_cycle.symm _,
rw same_cycle_pow_left_iff
end
lemma to_list_form_perm_nil (x : α) :
to_list (form_perm ([] : list α)) x = [] :=
by simp
lemma to_list_form_perm_singleton (x y : α) :
to_list (form_perm [x]) y = [] :=
by simp
lemma to_list_form_perm_nontrivial (l : list α) (hl : 2 ≤ l.length) (hn : nodup l) :
to_list (form_perm l) (l.nth_le 0 (zero_lt_two.trans_le hl)) = l :=
begin
have hc : l.form_perm.is_cycle := list.is_cycle_form_perm hn hl,
have hs : l.form_perm.support = l.to_finset,
{ refine support_form_perm_of_nodup _ hn _,
rintro _ rfl,
simpa [nat.succ_le_succ_iff] using hl },
rw [to_list, hc.cycle_of_eq (mem_support.mp _), hs, card_to_finset, erase_dup_eq_self.mpr hn],
{ refine list.ext_le (by simp) (λ k hk hk', _),
simp [form_perm_pow_apply_nth_le _ hn, nat.mod_eq_of_lt hk'] },
{ simpa [hs] using nth_le_mem _ _ _ }
end
lemma to_list_form_perm_is_rotated_self (l : list α) (hl : 2 ≤ l.length) (hn : nodup l)
(x : α) (hx : x ∈ l):
to_list (form_perm l) x ~r l :=
begin
obtain ⟨k, hk, rfl⟩ := nth_le_of_mem hx,
have hr : l ~r l.rotate k := ⟨k, rfl⟩,
rw form_perm_eq_of_is_rotated hn hr,
rw ←nth_le_rotate' l k k,
simp only [nat.mod_eq_of_lt hk, nat.sub_add_cancel hk.le, nat.mod_self],
rw [to_list_form_perm_nontrivial],
{ simp },
{ simpa using hl },
{ simpa using hn }
end
lemma form_perm_to_list (f : perm α) (x : α) :
form_perm (to_list f x) = f.cycle_of x :=
begin
by_cases hx : f x = x,
{ rw [(cycle_of_eq_one_iff f).mpr hx, to_list_eq_nil_iff.mpr (not_mem_support.mpr hx),
form_perm_nil] },
ext y,
by_cases hy : same_cycle f x y,
{ obtain ⟨k, hk, rfl⟩ := hy.nat_of_mem_support _ (mem_support.mpr hx),
rw [cycle_of_apply_apply_pow_self, list.form_perm_apply_mem_eq_next (nodup_to_list f x),
next_to_list_eq_apply, pow_succ, mul_apply],
rw mem_to_list_iff,
exact ⟨⟨k, rfl⟩, mem_support.mpr hx⟩ },
{ rw [cycle_of_apply_of_not_same_cycle hy, form_perm_apply_of_not_mem],
simp [mem_to_list_iff, hy] }
end
lemma is_cycle.exists_unique_cycle {f : perm α} (hf : is_cycle f) :
∃! (s : cycle α), ∃ (h : s.nodup), s.form_perm h = f :=
begin
obtain ⟨x, hx, hy⟩ := id hf,
refine ⟨f.to_list x, ⟨nodup_to_list f x, _⟩, _⟩,
{ simp [form_perm_to_list, hf.cycle_of_eq hx] },
{ rintro ⟨l⟩ ⟨hn, rfl⟩,
simp only [cycle.mk_eq_coe, cycle.coe_eq_coe, subtype.coe_mk, cycle.form_perm_coe],
refine (to_list_form_perm_is_rotated_self _ _ hn _ _).symm,
{ contrapose! hx,
suffices : form_perm l = 1,
{ simp [this] },
rw form_perm_eq_one_iff _ hn,
exact nat.le_of_lt_succ hx },
{ rw ←mem_to_finset,
refine support_form_perm_le l _,
simpa using hx } }
end
lemma is_cycle.exists_unique_cycle_subtype {f : perm α} (hf : is_cycle f) :
∃! (s : {s : cycle α // s.nodup}), (s : cycle α).form_perm s.prop = f :=
begin
obtain ⟨s, ⟨hs, rfl⟩, hs'⟩ := hf.exists_unique_cycle,
refine ⟨⟨s, hs⟩, rfl, _⟩,
rintro ⟨t, ht⟩ ht',
simpa using hs' _ ⟨ht, ht'⟩
end
lemma is_cycle.exists_unique_cycle_nontrivial_subtype {f : perm α} (hf : is_cycle f) :
∃! (s : {s : cycle α // s.nodup ∧ s.nontrivial}), (s : cycle α).form_perm s.prop.left = f :=
begin
obtain ⟨⟨s, hn⟩, hs, hs'⟩ := hf.exists_unique_cycle_subtype,
refine ⟨⟨s, hn, _⟩, _, _⟩,
{ rw hn.nontrivial_iff,
subst f,
intro H,
refine hf.ne_one _,
simpa using cycle.form_perm_subsingleton _ H },
{ simpa using hs },
{ rintro ⟨t, ht, ht'⟩ ht'',
simpa using hs' ⟨t, ht⟩ ht'' }
end
/--
Given a cyclic `f : perm α`, generate the `cycle α` in the order
of application of `f`. Implemented by finding an element `x : α`
in the support of `f` in `finset.univ`, and iterating on using
`equiv.perm.to_list f x`.
-/
def to_cycle (f : perm α) (hf : is_cycle f) : cycle α :=
multiset.rec_on (finset.univ : finset α).val
(quot.mk _ [])
(λ x s l, if f x = x then l else to_list f x)
(by { intros x y m s,
refine heq_of_eq _,
split_ifs with hx hy hy; try { refl },
{ have hc : same_cycle f x y := is_cycle.same_cycle hf hx hy,
exact quotient.sound' hc.to_list_is_rotated }})
lemma to_cycle_eq_to_list (f : perm α) (hf : is_cycle f) (x : α) (hx : f x ≠ x) :
to_cycle f hf = to_list f x :=
begin
have key : (finset.univ : finset α).val = x ::ₘ finset.univ.val.erase x,
{ simp },
rw [to_cycle, key],
simp [hx]
end
lemma nodup_to_cycle (f : perm α) (hf : is_cycle f) : (to_cycle f hf).nodup :=
begin
obtain ⟨x, hx, -⟩ := id hf,
simpa [to_cycle_eq_to_list f hf x hx] using nodup_to_list _ _
end
lemma nontrivial_to_cycle (f : perm α) (hf : is_cycle f) : (to_cycle f hf).nontrivial :=
begin
obtain ⟨x, hx, -⟩ := id hf,
simp [to_cycle_eq_to_list f hf x hx, hx, cycle.nontrivial_coe_nodup_iff (nodup_to_list _ _)]
end
/--
Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by `equiv.perm.to_cycle`.
-/
def iso_cycle : {f : perm α // is_cycle f} ≃ {s : cycle α // s.nodup ∧ s.nontrivial} :=
{ to_fun := λ f, ⟨to_cycle (f : perm α) f.prop, nodup_to_cycle f f.prop,
nontrivial_to_cycle _ f.prop⟩,
inv_fun := λ s, ⟨(s : cycle α).form_perm s.prop.left,
(s : cycle α).is_cycle_form_perm _ s.prop.right⟩,
left_inv := λ f, by {
obtain ⟨x, hx, -⟩ := id f.prop,
simpa [to_cycle_eq_to_list (f : perm α) f.prop x hx, form_perm_to_list, subtype.ext_iff]
using f.prop.cycle_of_eq hx },
right_inv := λ s, by {
rcases s with ⟨⟨s⟩, hn, ht⟩,
obtain ⟨x, -, -, hx, -⟩ := id ht,
have hl : 2 ≤ s.length := by simpa using cycle.length_nontrivial ht,
simp only [cycle.mk_eq_coe, cycle.nodup_coe_iff, cycle.mem_coe_iff, subtype.coe_mk,
cycle.form_perm_coe] at hn hx ⊢,
rw to_cycle_eq_to_list _ _ x,
{ refine quotient.sound' _,
exact to_list_form_perm_is_rotated_self _ hl hn _ hx },
{ rw [←mem_support, support_form_perm_of_nodup _ hn],
{ simpa using hx },
{ rintro _ rfl,
simpa [nat.succ_le_succ_iff] using hl } } } }
/--
Any cyclic `f : perm α` is isomorphic to the nontrivial `cycle α`
that corresponds to repeated application of `f`.
The forward direction is implemented by finding this `cycle α` using `fintype.choose`.
-/
def iso_cycle' : {f : perm α // is_cycle f} ≃ {s : cycle α // s.nodup ∧ s.nontrivial} :=
{ to_fun := λ f, fintype.choose _ f.prop.exists_unique_cycle_nontrivial_subtype,
inv_fun := λ s, ⟨(s : cycle α).form_perm s.prop.left,
(s : cycle α).is_cycle_form_perm _ s.prop.right⟩,
left_inv := λ f, by simpa [subtype.ext_iff]
using fintype.choose_spec _ f.prop.exists_unique_cycle_nontrivial_subtype,
right_inv := λ ⟨s, hs, ht⟩, by {
simp [subtype.coe_mk],
convert fintype.choose_subtype_eq (λ (s' : cycle α), s'.nodup ∧ s'.nontrivial) _,
ext ⟨s', hs', ht'⟩,
simp [cycle.form_perm_eq_form_perm_iff, (iff_not_comm.mp hs.nontrivial_iff),
(iff_not_comm.mp hs'.nontrivial_iff), ht] } }
notation `c[` l:(foldr `, ` (h t, list.cons h t) list.nil `]`) :=
cycle.form_perm ↑l (cycle.nodup_coe_iff.mpr dec_trivial)
instance repr_perm [has_repr α] : has_repr (perm α) :=
⟨λ f, repr (multiset.pmap (λ (g : perm α) (hg : g.is_cycle),
iso_cycle ⟨g, hg⟩) -- to_cycle is faster?
(perm.cycle_factors_finset f).val
(λ g hg, (mem_cycle_factors_finset_iff.mp (finset.mem_def.mpr hg)).left))⟩
end equiv.perm
|
b5f6878112292ffaeb49c064ab92d26df045ebcb | 618003631150032a5676f229d13a079ac875ff77 | /src/algebraic_geometry/presheafed_space.lean | 1fffd552e3bc23c4e05fda1018ad59808f712fad | [
"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 | 8,456 | lean | /-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import topology.sheaves.presheaf
/-!
# Presheafed spaces
Introduces the category of topological spaces equipped with a presheaf (taking values in an
arbitrary target category `C`.)
We further describe how to apply functors and natural transformations to the values of the
presheaves.
-/
universes v u
open category_theory
open Top
open topological_space
open opposite
open category_theory.category category_theory.functor
variables (C : Type u) [𝒞 : category.{v} C]
include 𝒞
local attribute [tidy] tactic.op_induction'
namespace algebraic_geometry
/-- A `PresheafedSpace C` is a topological space equipped with a presheaf of `C`s. -/
structure PresheafedSpace :=
(to_Top : Top.{v})
(𝒪 : to_Top.presheaf C)
variables {C}
namespace PresheafedSpace
instance coe_to_Top : has_coe (PresheafedSpace.{v} C) Top :=
{ coe := λ X, X.to_Top }
@[simp] lemma as_coe (X : PresheafedSpace.{v} C) : X.to_Top = (X : Top.{v}) := rfl
@[simp] lemma mk_coe (to_Top) (𝒪) : (({ to_Top := to_Top, 𝒪 := 𝒪 } :
PresheafedSpace.{v} C) : Top.{v}) = to_Top := rfl
instance (X : PresheafedSpace.{v} C) : topological_space X := X.to_Top.str
/-- A morphism between presheafed spaces `X` and `Y` consists of a continuous map
`f` between the underlying topological spaces, and a (notice contravariant!) map
from the presheaf on `Y` to the pushforward of the presheaf on `X` via `f`. -/
structure hom (X Y : PresheafedSpace.{v} C) :=
(f : (X : Top.{v}) ⟶ (Y : Top.{v}))
(c : Y.𝒪 ⟶ f _* X.𝒪)
@[ext] lemma ext {X Y : PresheafedSpace.{v} C} (α β : hom X Y)
(w : α.f = β.f) (h : α.c ≫ (whisker_right (nat_trans.op (opens.map_iso _ _ w).inv) X.𝒪) = β.c) :
α = β :=
begin
cases α, cases β,
dsimp [presheaf.pushforward] at *,
tidy, -- TODO including `injections` would make tidy work earlier.
end
.
def id (X : PresheafedSpace.{v} C) : hom X X :=
{ f := 𝟙 (X : Top.{v}),
c := ((functor.left_unitor _).inv) ≫ (whisker_right (nat_trans.op (opens.map_id (X.to_Top)).hom) _) }
def comp (X Y Z : PresheafedSpace.{v} C) (α : hom X Y) (β : hom Y Z) : hom X Z :=
{ f := α.f ≫ β.f,
c := β.c ≫ (whisker_left (opens.map β.f).op α.c) ≫ (Top.presheaf.pushforward.comp _ _ _).inv }
variables (C)
section
local attribute [simp] id comp presheaf.pushforward
/- The proofs below can be done by `tidy`, but it is too slow,
and we don't have a tactic caching mechanism. -/
/-- The category of PresheafedSpaces. Morphisms are pairs, a continuous map and a presheaf map
from the presheaf on the target to the pushforward of the presheaf on the source. -/
instance category_of_PresheafedSpaces : category (PresheafedSpace.{v} C) :=
{ hom := hom,
id := id,
comp := comp,
id_comp' := λ X Y f,
begin
ext1, swap,
{ dsimp, simp only [id_comp] },
{ ext U, op_induction, cases U,
dsimp,
simp only [comp_id, id_comp, map_id, presheaf.pushforward, presheaf.pushforward.comp_inv_app],
dsimp,
simp only [comp_id], },
end,
comp_id' := λ X Y f,
begin
ext1, swap,
{ dsimp, simp only [comp_id] },
{ ext U, op_induction, cases U,
dsimp,
simp only [comp_id, id_comp, map_id, presheaf.pushforward, presheaf.pushforward.comp_inv_app],
dsimp,
simp only [comp_id], }
end,
assoc' := λ W X Y Z f g h,
begin
ext1, swap,
refl,
{ ext U, op_induction, cases U,
dsimp,
simp only [assoc, map_id, comp_id, presheaf.pushforward, presheaf.pushforward.comp_inv_app],
dsimp,
simp only [comp_id, id_comp], }
end }
end
variables {C}
instance {X Y : PresheafedSpace.{v} C} : has_coe (X ⟶ Y) (X.to_Top ⟶ Y.to_Top) :=
{ coe := λ α, α.f }
-- see Note [function coercion]
instance {X Y : PresheafedSpace.{v} C} : has_coe_to_fun (X ⟶ Y) :=
⟨λ _, X.to_Top → Y.to_Top, λ h, h⟩
@[simp] lemma hom_mk_coe {X Y : PresheafedSpace.{v} C} (f) (c) :
(({ f := f, c := c } : X ⟶ Y) : (X : Top.{v}) ⟶ (Y : Top.{v})) = f := rfl
@[simp] lemma f_as_coe {X Y : PresheafedSpace.{v} C} (α : X ⟶ Y) :
α.f = (α : (X : Top.{v}) ⟶ (Y : Top.{v})) := rfl
@[simp] lemma id_coe (X : PresheafedSpace.{v} C) :
(((𝟙 X) : X ⟶ X) : (X : Top.{v}) ⟶ X) = 𝟙 (X : Top.{v}) := rfl
@[simp] lemma id_coe_fn (X : PresheafedSpace.{v} C) :
(((𝟙 X) : X ⟶ X) : (X : Top.{v}) → X) = 𝟙 (X : Top.{v}) := rfl
@[simp] lemma comp_coe {X Y Z : PresheafedSpace.{v} C} (α : X ⟶ Y) (β : Y ⟶ Z) :
((α ≫ β : X ⟶ Z) : (X : Top.{v}) ⟶ Z) = (α : (X : Top.{v}) ⟶ Y) ≫ (β : Y ⟶ Z) := rfl
lemma id_c (X : PresheafedSpace.{v} C) :
((𝟙 X) : X ⟶ X).c =
(((functor.left_unitor _).inv) ≫ (whisker_right (nat_trans.op (opens.map_id (X.to_Top)).hom) _)) := rfl
-- Implementation note: this harmless looking lemma causes deterministic timeouts,
-- but happily we can survive without it.
-- lemma comp_c {X Y Z : PresheafedSpace.{v} C} (α : X ⟶ Y) (β : Y ⟶ Z) :
-- (α ≫ β).c = (β.c ≫ (whisker_left (opens.map β.f).op α.c)) := rfl
@[simp] lemma id_c_app (X : PresheafedSpace.{v} C) (U) :
((𝟙 X) : X ⟶ X).c.app U = eq_to_hom (by { op_induction U, cases U, refl }) :=
by { op_induction U, cases U, simp only [id_c], dsimp, simp, }
@[simp] lemma comp_c_app {X Y Z : PresheafedSpace.{v} C} (α : X ⟶ Y) (β : Y ⟶ Z) (U) :
(α ≫ β).c.app U = (β.c).app U ≫ (α.c).app (op ((opens.map (β.f)).obj (unop U))) ≫
(Top.presheaf.pushforward.comp _ _ _).inv.app U := rfl
/-- The forgetful functor from `PresheafedSpace` to `Top`. -/
def forget : PresheafedSpace.{v} C ⥤ Top :=
{ obj := λ X, (X : Top.{v}),
map := λ X Y f, f }
end PresheafedSpace
end algebraic_geometry
open algebraic_geometry algebraic_geometry.PresheafedSpace
variables {C}
namespace category_theory
variables {D : Type u} [𝒟 : category.{v} D]
include 𝒟
local attribute [simp] presheaf.pushforward
namespace functor
/-- We can apply a functor `F : C ⥤ D` to the values of the presheaf in any `PresheafedSpace C`,
giving a functor `PresheafedSpace C ⥤ PresheafedSpace D` -/
/- The proofs below can be done by `tidy`, but it is too slow,
and we don't have a tactic caching mechanism. -/
def map_presheaf (F : C ⥤ D) : PresheafedSpace.{v} C ⥤ PresheafedSpace.{v} D :=
{ obj := λ X, { to_Top := X.to_Top, 𝒪 := X.𝒪 ⋙ F },
map := λ X Y f, { f := f.f, c := whisker_right f.c F },
map_id' := λ X,
begin
ext1, swap,
{ refl },
{ ext,
dsimp,
simp only [presheaf.pushforward, eq_to_hom_map, map_id, comp_id, id_c_app],
refl }
end,
map_comp' := λ X Y Z f g,
begin
ext1, swap,
{ refl, },
{ ext, dsimp,
simp only [comp_id, assoc, map_comp, map_id, comp_c_app,
presheaf.pushforward, presheaf.pushforward.comp_inv_app],
dsimp,
simp only [comp_id, map_id] }
end }
@[simp] lemma map_presheaf_obj_X (F : C ⥤ D) (X : PresheafedSpace.{v} C) :
((F.map_presheaf.obj X) : Top.{v}) = (X : Top.{v}) := rfl
@[simp] lemma map_presheaf_obj_𝒪 (F : C ⥤ D) (X : PresheafedSpace.{v} C) :
(F.map_presheaf.obj X).𝒪 = X.𝒪 ⋙ F := rfl
@[simp] lemma map_presheaf_map_f (F : C ⥤ D) {X Y : PresheafedSpace.{v} C} (f : X ⟶ Y) :
((F.map_presheaf.map f) : (X : Top.{v}) ⟶ (Y : Top.{v})) = f := rfl
@[simp] lemma map_presheaf_map_c (F : C ⥤ D) {X Y : PresheafedSpace.{v} C} (f : X ⟶ Y) :
(F.map_presheaf.map f).c = whisker_right f.c F := rfl
end functor
namespace nat_trans
/- The proofs below can be done by `tidy`, but it is too slow,
and we don't have a tactic caching mechanism. -/
def on_presheaf {F G : C ⥤ D} (α : F ⟶ G) : G.map_presheaf ⟶ F.map_presheaf :=
{ app := λ X,
{ f := 𝟙 _,
c := whisker_left X.𝒪 α ≫ ((functor.left_unitor _).inv) ≫
(whisker_right (nat_trans.op (opens.map_id X.to_Top).hom) _) },
naturality' := λ X Y f,
begin
ext1, swap,
{ refl },
{ ext U,
op_induction,
cases U,
dsimp,
simp only [comp_id, assoc, map_id, presheaf.pushforward, presheaf.pushforward.comp_inv_app],
dsimp,
simp only [comp_id, nat_trans.naturality], }
end }
-- TODO Assemble the last two constructions into a functor
-- `(C ⥤ D) ⥤ (PresheafedSpace C ⥤ PresheafedSpace D)`
end nat_trans
end category_theory
|
28bb539a0cb2b546d5ec82fecba4124a274a64d7 | 4fa118f6209450d4e8d058790e2967337811b2b5 | /src/for_mathlib/rings.lean | 34c835a7a361175767379daa1431b412fe659c21 | [
"Apache-2.0"
] | permissive | leanprover-community/lean-perfectoid-spaces | 16ab697a220ed3669bf76311daa8c466382207f7 | 95a6520ce578b30a80b4c36e36ab2d559a842690 | refs/heads/master | 1,639,557,829,139 | 1,638,797,866,000 | 1,638,797,866,000 | 135,769,296 | 96 | 10 | Apache-2.0 | 1,638,797,866,000 | 1,527,892,754,000 | Lean | UTF-8 | Lean | false | false | 1,318 | lean | import data.subtype data.equiv.algebra ring_theory.ideal_operations
import for_mathlib.data.set.basic
universes u u₁ u₂ v v₁ w
attribute [move_cast] units.inv_eq_inv units.coe_inv
open set
lemma range_units_coe (K : Type*) [division_ring K]: range (coe : units K → K) = -{0} :=
begin
ext x,
rw mem_compl_singleton_iff,
split,
{ rintro ⟨u, hu⟩ h',
change u.val = x at hu,
simpa [hu, h'] using u.val_inv },
{ intro h,
refine ⟨units.mk0 _ h, _⟩,
change (units.mk0 x h).val = _,
simp [units.mk0] }
end
lemma range_units_val (K : Type*) [division_ring K]: range (coe : units K → K) = -{0} :=
range_units_coe K
namespace ideal
open function
local attribute [instance] set.pointwise_mul_comm_semiring
-- The following should just be the conjunction of
-- comap f ⊥ = ker f
-- ker f = ⊥ (for injective f)
-- jmc: we have inj_iff_ker_eq_bot in mathlib (ideal_operations.lean). I guess that should work.
-- So I think this one can be deleted.
lemma comap_bot_of_inj {R : Type u} [comm_ring R] {S : Type v} [comm_ring S] (f : R → S) [is_ring_hom f]
(h : injective f) :
ideal.comap f ⊥ = ⊥ :=
lattice.eq_bot_iff.2 $
begin
intros r hr,
change r ∈ f ⁻¹' {0} at hr,
simp at *,
apply h,
rw hr,
symmetry,
rw is_ring_hom.map_zero f,
end
end ideal
|
66b6c2722384920b3cc7219ec50210fc2e94fd52 | 4727251e0cd73359b15b664c3170e5d754078599 | /test/noncomm_ring.lean | ccd4677adcb40b2b84d646277de12dfbbe1f0a50 | [
"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,878 | lean | import tactic.noncomm_ring
local notation `⁅`a`,` b`⁆` := a * b - b * a
local infix ` ⚬ `:70 := λ a b, a * b + b * a
variables {R : Type*} [ring R]
variables (a b c : R)
example : 0 = 0 := by noncomm_ring
example : a = a := by noncomm_ring
example : (a + b) * c = a * c + b * c := by noncomm_ring
example : a * (b + c) = a * b + a * c := by noncomm_ring
example : a - b = a + -b := by noncomm_ring
example : a * b * c = a * (b * c) := by noncomm_ring
example : a + a = a * 2 := by noncomm_ring
example : a + a = 2 * a := by noncomm_ring
example : -a = (-1) * a := by noncomm_ring
example : a + a + a = 3 * a := by noncomm_ring
example : a ^ 2 = a * a := by noncomm_ring
example : a ^ 3 = a * a * a := by noncomm_ring
example : (-a) * b = -(a * b) := by noncomm_ring
example : a * (-b) = -(a * b) := by noncomm_ring
example : a * (b + c + b + c - 2*b) = 2*a*c := by noncomm_ring
example : a * (b + c + b + c - (2 : ℕ) • b) = 2*a*c := by noncomm_ring
example : (a + b)^2 = a^2 + a*b + b*a + b^2 := by noncomm_ring
example : (a - b)^2 = a^2 - a*b - b*a + b^2 := by noncomm_ring
example : (a + b)^3 = a^3 + a^2*b + a*b*a + a*b^2 + b*a^2 + b*a*b + b^2*a + b^3 := by noncomm_ring
example : (a - b)^3 = a^3 - a^2*b - a*b*a + a*b^2 - b*a^2 + b*a*b + b^2*a - b^3 := by noncomm_ring
example : ⁅a, a⁆ = 0 := by noncomm_ring
example : ⁅a, b⁆ = -⁅b, a⁆ := by noncomm_ring
example : ⁅a + b, c⁆ = ⁅a, c⁆ + ⁅b, c⁆ := by noncomm_ring
example : ⁅a, b + c⁆ = ⁅a, b⁆ + ⁅a, c⁆ := by noncomm_ring
example : ⁅a, ⁅b, c⁆⁆ + ⁅b, ⁅c, a⁆⁆ + ⁅c, ⁅a, b⁆⁆ = 0 := by noncomm_ring
example : ⁅⁅a, b⁆, c⁆ + ⁅⁅b, c⁆, a⁆ + ⁅⁅c, a⁆, b⁆ = 0 := by noncomm_ring
example : ⁅a, ⁅b, c⁆⁆ = ⁅⁅a, b⁆, c⁆ + ⁅b, ⁅a, c⁆⁆ := by noncomm_ring
example : ⁅⁅a, b⁆, c⁆ = ⁅⁅a, c⁆, b⁆ + ⁅a, ⁅b, c⁆⁆ := by noncomm_ring
example : ⁅a * b, c⁆ = a * ⁅b, c⁆ + ⁅a, c⁆ * b := by noncomm_ring
example : ⁅a, b * c⁆ = ⁅a, b⁆ * c + b * ⁅a, c⁆ := by noncomm_ring
example : ⁅3 * a, a⁆ = 0 := by noncomm_ring
example : ⁅a * -5, a⁆ = 0 := by noncomm_ring
example : ⁅a^3, a⁆ = 0 := by noncomm_ring
example : a ⚬ a = 2*a^2 := by noncomm_ring
example : (2 * a) ⚬ a = 4*a^2 := by noncomm_ring
example : a ⚬ b = b ⚬ a := by noncomm_ring
example : a ⚬ (b + c) = a ⚬ b + a ⚬ c := by noncomm_ring
example : (a + b) ⚬ c = a ⚬ c + b ⚬ c := by noncomm_ring
example : (a ⚬ b) ⚬ (a ⚬ a) = a ⚬ (b ⚬ (a ⚬ a)) := by noncomm_ring
example : ⁅a, b ⚬ c⁆ = ⁅a, b⁆ ⚬ c + b ⚬ ⁅a, c⁆ := by noncomm_ring
example : ⁅a ⚬ b, c⁆ = a ⚬ ⁅b, c⁆ + ⁅a, c⁆ ⚬ b := by noncomm_ring
example : (a ⚬ b) ⚬ c - a ⚬ (b ⚬ c) = -⁅⁅a, b⁆, c⁆ + ⁅a, ⁅b, c⁆⁆ := by noncomm_ring
example : a + -b = -b + a := by noncomm_ring
|
f8f03ca42ec46ca011120bdc42c5dc3f5721a18f | 4d2583807a5ac6caaffd3d7a5f646d61ca85d532 | /src/order/jordan_holder.lean | 1240f93f63840833c43f9f2ce3a5f04bb1ff952d | [
"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 | 30,891 | lean | /-
Copyright (c) 2021 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes
-/
import order.lattice
import data.list.sort
import data.equiv.fin
import data.equiv.functor
/-!
# Jordan-Hölder Theorem
This file proves the Jordan Hölder theorem for a `jordan_holder_lattice`, a class also defined in
this file. Examples of `jordan_holder_lattice` include `subgroup G` if `G` is a group, and
`submodule R M` if `M` is an `R`-module. Using this approach the theorem need not be proved
seperately for both groups and modules, the proof in this file can be applied to both.
## Main definitions
The main definitions in this file are `jordan_holder_lattice` and `composition_series`,
and the relation `equivalent` on `composition_series`
A `jordan_holder_lattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `is_maximal`, and a notion
of isomorphism of pairs `iso`. In the example of subgroups of a group, `is_maximal H K` means that
`H` is a maximal normal subgroup of `K`, and `iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `iso (H, H ⊔ K) (H ⊓ K, K)`.
A `composition_series X` is a finite nonempty series of elements of the lattice `X` such that
each element is maximal inside the next. The length of a `composition_series X` is
one less than the number of elements in the series. Note that there is no stipulation
that a series start from the bottom of the lattice and finish at the top.
For a composition series `s`, `s.top` is the largest element of the series,
and `s.bot` is the least element.
Two `composition_series X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : fin s₁.length ≃ fin s₂.length` such that for any `i`,
`iso (s₁ i, s₁ i.succ) (s₂ (e i), s₂ (e i.succ))`
## Main theorems
The main theorem is `composition_series.jordan_holder`, which says that if two composition
series have the same least element and the same largest element,
then they are `equivalent`.
## TODO
Provide instances of `jordan_holder_lattice` for both submodules and subgroups, and potentially
for modular lattices.
It is not entirely clear how this should be done. Possibly there should be no global instances
of `jordan_holder_lattice`, and the instances should only be defined locally in order to prove
the Jordan-Hölder theorem for modules/groups and the API should be transferred because many of the
theorems in this file will have stronger versions for modules. There will also need to be an API for
mapping composition series across homomorphisms. It is also probably possible to
provide an instance of `jordan_holder_lattice` for any `modular_lattice`, and in this case the
Jordan-Hölder theorem will say that there is a well defined notion of length of a modular lattice.
However an instance of `jordan_holder_lattice` for a modular lattice will not be able to contain
the correct notion of isomorphism for modules, so a separate instance for modules will still be
required and this will clash with the instance for modular lattices, and so at least one of these
instances should not be a global instance.
-/
universe u
open set
/--
A `jordan_holder_lattice` is the class for which the Jordan Hölder theorem is proved. A
Jordan Hölder lattice is a lattice equipped with a notion of maximality, `is_maximal`, and a notion
of isomorphism of pairs `iso`. In the example of subgroups of a group, `is_maximal H K` means that
`H` is a maximal normal subgroup of `K`, and `iso (H₁, K₁) (H₂, K₂)` means that the quotient
`H₁ / K₁` is isomorphic to the quotient `H₂ / K₂`. `iso` must be symmetric and transitive and must
satisfy the second isomorphism theorem `iso (H, H ⊔ K) (H ⊓ K, K)`.
Examples include `subgroup G` if `G` is a group, and `submodule R M` if `M` is an `R`-module.
-/
class jordan_holder_lattice (X : Type u) [lattice X] :=
(is_maximal : X → X → Prop)
(lt_of_is_maximal : ∀ {x y}, is_maximal x y → x < y)
(sup_eq_of_is_maximal : ∀ {x y z}, is_maximal x z → is_maximal y z →
x ≠ y → x ⊔ y = z)
(is_maximal_inf_left_of_is_maximal_sup : ∀ {x y}, is_maximal x (x ⊔ y) → is_maximal y (x ⊔ y) →
is_maximal (x ⊓ y) x)
(iso : (X × X) → (X × X) → Prop)
(iso_symm : ∀ {x y}, iso x y → iso y x)
(iso_trans : ∀ {x y z}, iso x y → iso y z → iso x z)
(second_iso : ∀ {x y}, is_maximal x (x ⊔ y) → iso (x, x ⊔ y) (x ⊓ y, y))
namespace jordan_holder_lattice
variables {X : Type u} [lattice X] [jordan_holder_lattice X]
lemma is_maximal_inf_right_of_is_maximal_sup {x y : X}
(hxz : is_maximal x (x ⊔ y)) (hyz : is_maximal y (x ⊔ y)) :
is_maximal (x ⊓ y) y :=
begin
rw [inf_comm],
rw [sup_comm] at hxz hyz,
exact is_maximal_inf_left_of_is_maximal_sup hyz hxz
end
lemma is_maximal_of_eq_inf (x b : X) {a y : X}
(ha : x ⊓ y = a) (hxy : x ≠ y) (hxb : is_maximal x b) (hyb : is_maximal y b) :
is_maximal a y :=
begin
have hb : x ⊔ y = b,
from sup_eq_of_is_maximal hxb hyb hxy,
substs a b,
exact is_maximal_inf_right_of_is_maximal_sup hxb hyb
end
lemma second_iso_of_eq {x y a b : X} (hm : is_maximal x a) (ha : x ⊔ y = a) (hb : x ⊓ y = b) :
iso (x, a) (b, y) :=
by substs a b; exact second_iso hm
lemma is_maximal.iso_refl {x y : X} (h : is_maximal x y) : iso (x, y) (x, y) :=
second_iso_of_eq h
(sup_eq_right.2 (le_of_lt (lt_of_is_maximal h)))
(inf_eq_left.2 (le_of_lt (lt_of_is_maximal h)))
end jordan_holder_lattice
open jordan_holder_lattice
attribute [symm] iso_symm
attribute [trans] iso_trans
/--
A `composition_series X` is a finite nonempty series of elements of a
`jordan_holder_lattice` such that each element is maximal inside the next. The length of a
`composition_series X` is one less than the number of elements in the series.
Note that there is no stipulation that a series start from the bottom of the lattice and finish at
the top. For a composition series `s`, `s.top` is the largest element of the series,
and `s.bot` is the least element.
-/
structure composition_series (X : Type u) [lattice X] [jordan_holder_lattice X] : Type u :=
(length : ℕ)
(series : fin (length + 1) → X)
(step' : ∀ i : fin length, is_maximal (series i.cast_succ) (series i.succ))
namespace composition_series
variables {X : Type u} [lattice X] [jordan_holder_lattice X]
instance : has_coe_to_fun (composition_series X) (λ x, fin (x.length + 1) → X) :=
{ coe := composition_series.series }
instance [inhabited X] : inhabited (composition_series X) :=
⟨{ length := 0,
series := λ _, default X,
step' := λ x, x.elim0 }⟩
variables {X}
lemma step (s : composition_series X) : ∀ i : fin s.length,
is_maximal (s i.cast_succ) (s i.succ) := s.step'
@[simp] lemma coe_fn_mk (length : ℕ) (series step) :
(@composition_series.mk X _ _ length series step : fin length.succ → X) = series := rfl
theorem lt_succ (s : composition_series X) (i : fin s.length) :
s i.cast_succ < s i.succ :=
lt_of_is_maximal (s.step _)
protected theorem strict_mono (s : composition_series X) : strict_mono s :=
fin.strict_mono_iff_lt_succ.2 (λ i h, s.lt_succ ⟨i, nat.lt_of_succ_lt_succ h⟩)
protected theorem injective (s : composition_series X) : function.injective s :=
s.strict_mono.injective
@[simp] protected theorem inj (s : composition_series X) {i j : fin s.length.succ} :
s i = s j ↔ i = j :=
s.injective.eq_iff
instance : has_mem X (composition_series X) :=
⟨λ x s, x ∈ set.range s⟩
lemma mem_def {x : X} {s : composition_series X} : x ∈ s ↔ x ∈ set.range s := iff.rfl
lemma total {s : composition_series X} {x y : X} (hx : x ∈ s) (hy : y ∈ s) : x ≤ y ∨ y ≤ x :=
begin
rcases set.mem_range.1 hx with ⟨i, rfl⟩,
rcases set.mem_range.1 hy with ⟨j, rfl⟩,
rw [s.strict_mono.le_iff_le, s.strict_mono.le_iff_le],
exact le_total i j
end
/-- The ordered `list X` of elements of a `composition_series X`. -/
def to_list (s : composition_series X) : list X := list.of_fn s
/-- Two `composition_series` are equal if they are the same length and
have the same `i`th element for every `i` -/
lemma ext_fun {s₁ s₂ : composition_series X}
(hl : s₁.length = s₂.length)
(h : ∀ i, s₁ i = s₂ (fin.cast (congr_arg nat.succ hl) i)) :
s₁ = s₂ :=
begin
cases s₁, cases s₂,
dsimp at *,
subst hl,
simpa [function.funext_iff] using h
end
@[simp] lemma length_to_list (s : composition_series X) : s.to_list.length = s.length + 1 :=
by rw [to_list, list.length_of_fn]
lemma to_list_ne_nil (s : composition_series X) : s.to_list ≠ [] :=
by rw [← list.length_pos_iff_ne_nil, length_to_list]; exact nat.succ_pos _
lemma to_list_injective : function.injective (@composition_series.to_list X _ _) :=
λ s₁ s₂ (h : list.of_fn s₁ = list.of_fn s₂),
have h₁ : s₁.length = s₂.length,
from nat.succ_injective
((list.length_of_fn s₁).symm.trans $
(congr_arg list.length h).trans $
list.length_of_fn s₂),
have h₂ : ∀ i : fin s₁.length.succ, (s₁ i) = s₂ (fin.cast (congr_arg nat.succ h₁) i),
begin
assume i,
rw [← list.nth_le_of_fn s₁ i, ← list.nth_le_of_fn s₂],
simp [h]
end,
begin
cases s₁, cases s₂,
dsimp at *,
subst h₁,
simp only [heq_iff_eq, eq_self_iff_true, true_and],
simp only [fin.cast_refl] at h₂,
exact funext h₂
end
lemma chain'_to_list (s : composition_series X) :
list.chain' is_maximal s.to_list :=
list.chain'_iff_nth_le.2
begin
assume i hi,
simp only [to_list, list.nth_le_of_fn'],
rw [length_to_list] at hi,
exact s.step ⟨i, hi⟩
end
lemma to_list_sorted (s : composition_series X) : s.to_list.sorted (<) :=
list.pairwise_iff_nth_le.2 (λ i j hi hij,
begin
dsimp [to_list],
rw [list.nth_le_of_fn', list.nth_le_of_fn'],
exact s.strict_mono hij
end)
lemma to_list_nodup (s : composition_series X) : s.to_list.nodup :=
list.nodup_iff_nth_le_inj.2
(λ i j hi hj,
begin
delta to_list,
rw [list.nth_le_of_fn', list.nth_le_of_fn', s.injective.eq_iff, fin.ext_iff,
fin.coe_mk, fin.coe_mk],
exact id
end)
@[simp] lemma mem_to_list {s : composition_series X} {x : X} : x ∈ s.to_list ↔ x ∈ s :=
by rw [to_list, list.mem_of_fn, mem_def]
/-- Make a `composition_series X` from the ordered list of its elements. -/
def of_list (l : list X) (hl : l ≠ []) (hc : list.chain' is_maximal l) :
composition_series X :=
{ length := l.length - 1,
series := λ i, l.nth_le i begin
conv_rhs { rw ← tsub_add_cancel_of_le (nat.succ_le_of_lt (list.length_pos_of_ne_nil hl)) },
exact i.2
end,
step' := λ ⟨i, hi⟩, list.chain'_iff_nth_le.1 hc i hi }
lemma length_of_list (l : list X) (hl : l ≠ []) (hc : list.chain' is_maximal l) :
(of_list l hl hc).length = l.length - 1 := rfl
lemma of_list_to_list (s : composition_series X) :
of_list s.to_list s.to_list_ne_nil s.chain'_to_list = s :=
begin
refine ext_fun _ _,
{ rw [length_of_list, length_to_list, nat.succ_sub_one] },
{ rintros ⟨i, hi⟩,
dsimp [of_list, to_list],
rw [list.nth_le_of_fn'] }
end
@[simp] lemma of_list_to_list' (s : composition_series X) :
of_list s.to_list s.to_list_ne_nil s.chain'_to_list = s :=
of_list_to_list s
@[simp] lemma to_list_of_list (l : list X) (hl : l ≠ []) (hc : list.chain' is_maximal l) :
to_list (of_list l hl hc) = l :=
begin
refine list.ext_le _ _,
{ rw [length_to_list, length_of_list,
tsub_add_cancel_of_le (nat.succ_le_of_lt $ list.length_pos_of_ne_nil hl)] },
{ assume i hi hi',
dsimp [of_list, to_list],
rw [list.nth_le_of_fn'],
refl }
end
/-- Two `composition_series` are equal if they have the same elements. See also `ext_fun`. -/
@[ext] lemma ext {s₁ s₂ : composition_series X} (h : ∀ x, x ∈ s₁ ↔ x ∈ s₂) : s₁ = s₂ :=
to_list_injective $ list.eq_of_perm_of_sorted
(by classical; exact list.perm_of_nodup_nodup_to_finset_eq
s₁.to_list_nodup
s₂.to_list_nodup
(finset.ext $ by simp *))
s₁.to_list_sorted s₂.to_list_sorted
/-- The largest element of a `composition_series` -/
def top (s : composition_series X) : X := s (fin.last _)
lemma top_mem (s : composition_series X) : s.top ∈ s :=
mem_def.2 (set.mem_range.2 ⟨fin.last _, rfl⟩)
@[simp] lemma le_top {s : composition_series X} (i : fin (s.length + 1)) : s i ≤ s.top :=
s.strict_mono.monotone (fin.le_last _)
lemma le_top_of_mem {s : composition_series X} {x : X} (hx : x ∈ s) : x ≤ s.top :=
let ⟨i, hi⟩ := set.mem_range.2 hx in hi ▸ le_top _
/-- The smallest element of a `composition_series` -/
def bot (s : composition_series X) : X := s 0
lemma bot_mem (s : composition_series X) : s.bot ∈ s :=
mem_def.2 (set.mem_range.2 ⟨0, rfl⟩)
@[simp] lemma bot_le {s : composition_series X} (i : fin (s.length + 1)) : s.bot ≤ s i :=
s.strict_mono.monotone (fin.zero_le _)
lemma bot_le_of_mem {s : composition_series X} {x : X} (hx : x ∈ s) : s.bot ≤ x :=
let ⟨i, hi⟩ := set.mem_range.2 hx in hi ▸ bot_le _
lemma length_pos_of_mem_ne {s : composition_series X}
{x y : X} (hx : x ∈ s) (hy : y ∈ s) (hxy : x ≠ y) :
0 < s.length :=
let ⟨i, hi⟩ := hx, ⟨j, hj⟩ := hy in
have hij : i ≠ j, from mt s.inj.2 $ λ h, hxy (hi ▸ hj ▸ h),
hij.lt_or_lt.elim
(λ hij, (lt_of_le_of_lt (zero_le i)
(lt_of_lt_of_le hij (nat.le_of_lt_succ j.2))))
(λ hji, (lt_of_le_of_lt (zero_le j)
(lt_of_lt_of_le hji (nat.le_of_lt_succ i.2))))
lemma forall_mem_eq_of_length_eq_zero {s : composition_series X}
(hs : s.length = 0) {x y} (hx : x ∈ s) (hy : y ∈ s) : x = y :=
by_contradiction (λ hxy, pos_iff_ne_zero.1 (length_pos_of_mem_ne hx hy hxy) hs)
/-- Remove the largest element from a `composition_series`. If the series `s`
has length zero, then `s.erase_top = s` -/
@[simps] def erase_top (s : composition_series X) : composition_series X :=
{ length := s.length - 1,
series := λ i, s ⟨i, lt_of_lt_of_le i.2 (nat.succ_le_succ tsub_le_self)⟩,
step' := λ i, begin
have := s.step ⟨i, lt_of_lt_of_le i.2 tsub_le_self⟩,
cases i,
exact this
end }
lemma top_erase_top (s : composition_series X) :
s.erase_top.top = s ⟨s.length - 1, lt_of_le_of_lt tsub_le_self (nat.lt_succ_self _)⟩ :=
show s _ = s _, from congr_arg s
begin
ext,
simp only [erase_top_length, fin.coe_last, fin.coe_cast_succ, fin.coe_of_nat_eq_mod,
fin.coe_mk, coe_coe]
end
lemma erase_top_top_le (s : composition_series X) : s.erase_top.top ≤ s.top :=
by simp [erase_top, top, s.strict_mono.le_iff_le, fin.le_iff_coe_le_coe, tsub_le_self]
@[simp] lemma bot_erase_top (s : composition_series X) : s.erase_top.bot = s.bot := rfl
lemma mem_erase_top_of_ne_of_mem {s : composition_series X} {x : X}
(hx : x ≠ s.top) (hxs : x ∈ s) : x ∈ s.erase_top :=
begin
{ rcases hxs with ⟨i, rfl⟩,
have hi : (i : ℕ) < (s.length - 1).succ,
{ conv_rhs { rw [← nat.succ_sub (length_pos_of_mem_ne ⟨i, rfl⟩ s.top_mem hx),
nat.succ_sub_one] },
exact lt_of_le_of_ne
(nat.le_of_lt_succ i.2)
(by simpa [top, s.inj, fin.ext_iff] using hx) },
refine ⟨i.cast_succ, _⟩,
simp [fin.ext_iff, nat.mod_eq_of_lt hi] }
end
lemma mem_erase_top {s : composition_series X} {x : X}
(h : 0 < s.length) : x ∈ s.erase_top ↔ x ≠ s.top ∧ x ∈ s :=
begin
simp only [mem_def],
dsimp only [erase_top, coe_fn_mk],
split,
{ rintros ⟨i, rfl⟩,
have hi : (i : ℕ) < s.length,
{ conv_rhs { rw [← nat.succ_sub_one s.length, nat.succ_sub h] },
exact i.2 },
simp [top, fin.ext_iff, (ne_of_lt hi)] },
{ intro h,
exact mem_erase_top_of_ne_of_mem h.1 h.2 }
end
lemma lt_top_of_mem_erase_top {s : composition_series X} {x : X} (h : 0 < s.length)
(hx : x ∈ s.erase_top) : x < s.top :=
lt_of_le_of_ne
(le_top_of_mem ((mem_erase_top h).1 hx).2)
((mem_erase_top h).1 hx).1
lemma is_maximal_erase_top_top {s : composition_series X} (h : 0 < s.length) :
is_maximal s.erase_top.top s.top :=
have s.length - 1 + 1 = s.length,
by conv_rhs { rw [← nat.succ_sub_one s.length] }; rw nat.succ_sub h,
begin
rw [top_erase_top, top],
convert s.step ⟨s.length - 1, nat.sub_lt h zero_lt_one⟩;
ext; simp [this]
end
lemma append_cast_add_aux
{s₁ s₂ : composition_series X}
(i : fin s₁.length) :
fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂
(fin.cast_add s₂.length i).cast_succ = s₁ i.cast_succ :=
by { cases i, simp [fin.append, *] }
lemma append_succ_cast_add_aux
{s₁ s₂ : composition_series X}
(i : fin s₁.length)
(h : s₁ (fin.last _) = s₂ 0) :
fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂
(fin.cast_add s₂.length i).succ = s₁ i.succ :=
begin
cases i with i hi,
simp only [fin.append, hi, fin.succ_mk, function.comp_app, fin.cast_succ_mk,
fin.coe_mk, fin.cast_add_mk],
split_ifs,
{ refl },
{ have : i + 1 = s₁.length, from le_antisymm hi (le_of_not_gt h_1),
calc s₂ ⟨i + 1 - s₁.length, by simp [this]⟩
= s₂ 0 : congr_arg s₂ (by simp [fin.ext_iff, this])
... = s₁ (fin.last _) : h.symm
... = _ : congr_arg s₁ (by simp [fin.ext_iff, this]) }
end
lemma append_nat_add_aux
{s₁ s₂ : composition_series X}
(i : fin s₂.length) :
fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂
(fin.nat_add s₁.length i).cast_succ = s₂ i.cast_succ :=
begin
cases i,
simp only [fin.append, nat.not_lt_zero, fin.nat_add_mk, add_lt_iff_neg_left,
add_tsub_cancel_left, dif_neg, fin.cast_succ_mk, not_false_iff, fin.coe_mk]
end
lemma append_succ_nat_add_aux
{s₁ s₂ : composition_series X}
(i : fin s₂.length) :
fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂
(fin.nat_add s₁.length i).succ = s₂ i.succ :=
begin
cases i with i hi,
simp only [fin.append, add_assoc, nat.not_lt_zero, fin.nat_add_mk, add_lt_iff_neg_left,
add_tsub_cancel_left, fin.succ_mk, dif_neg, not_false_iff, fin.coe_mk]
end
/-- Append two composition series `s₁` and `s₂` such that
the least element of `s₁` is the maximum element of `s₂`. -/
@[simps length] def append (s₁ s₂ : composition_series X)
(h : s₁.top = s₂.bot) : composition_series X :=
{ length := s₁.length + s₂.length,
series := fin.append (nat.add_succ _ _).symm (s₁ ∘ fin.cast_succ) s₂,
step' := λ i, begin
refine fin.add_cases _ _ i,
{ intro i,
rw [append_succ_cast_add_aux _ h, append_cast_add_aux],
exact s₁.step i },
{ intro i,
rw [append_nat_add_aux, append_succ_nat_add_aux],
exact s₂.step i }
end }
@[simp] lemma append_cast_add {s₁ s₂ : composition_series X}
(h : s₁.top = s₂.bot) (i : fin s₁.length) :
append s₁ s₂ h (fin.cast_add s₂.length i).cast_succ = s₁ i.cast_succ :=
append_cast_add_aux i
@[simp] lemma append_succ_cast_add {s₁ s₂ : composition_series X}
(h : s₁.top = s₂.bot) (i : fin s₁.length) :
append s₁ s₂ h (fin.cast_add s₂.length i).succ = s₁ i.succ :=
append_succ_cast_add_aux i h
@[simp] lemma append_nat_add {s₁ s₂ : composition_series X}
(h : s₁.top = s₂.bot) (i : fin s₂.length) :
append s₁ s₂ h (fin.nat_add s₁.length i).cast_succ = s₂ i.cast_succ :=
append_nat_add_aux i
@[simp] lemma append_succ_nat_add {s₁ s₂ : composition_series X}
(h : s₁.top = s₂.bot) (i : fin s₂.length) :
append s₁ s₂ h (fin.nat_add s₁.length i).succ = s₂ i.succ :=
append_succ_nat_add_aux i
/-- Add an element to the top of a `composition_series` -/
@[simps length] def snoc (s : composition_series X) (x : X)
(hsat : is_maximal s.top x) : composition_series X :=
{ length := s.length + 1,
series := fin.snoc s x,
step' := λ i, begin
refine fin.last_cases _ _ i,
{ rwa [fin.snoc_cast_succ, fin.succ_last, fin.snoc_last, ← top] },
{ intro i,
rw [fin.snoc_cast_succ, ← fin.cast_succ_fin_succ, fin.snoc_cast_succ],
exact s.step _ }
end }
@[simp] lemma top_snoc (s : composition_series X) (x : X)
(hsat : is_maximal s.top x) : (snoc s x hsat).top = x :=
fin.snoc_last _ _
@[simp] lemma snoc_last (s : composition_series X) (x : X) (hsat : is_maximal s.top x) :
snoc s x hsat (fin.last (s.length + 1)) = x :=
fin.snoc_last _ _
@[simp] lemma snoc_cast_succ (s : composition_series X) (x : X) (hsat : is_maximal s.top x)
(i : fin (s.length + 1)) : snoc s x hsat (i.cast_succ) = s i :=
fin.snoc_cast_succ _ _ _
@[simp] lemma bot_snoc (s : composition_series X) (x : X) (hsat : is_maximal s.top x) :
(snoc s x hsat).bot = s.bot :=
by rw [bot, bot, ← fin.cast_succ_zero, snoc_cast_succ]
lemma mem_snoc {s : composition_series X} {x y: X}
{hsat : is_maximal s.top x} : y ∈ snoc s x hsat ↔ y ∈ s ∨ y = x :=
begin
simp only [snoc, mem_def],
split,
{ rintros ⟨i, rfl⟩,
refine fin.last_cases _ (λ i, _) i,
{ right, simp },
{ left, simp } },
{ intro h,
rcases h with ⟨i, rfl⟩ | rfl,
{ use i.cast_succ, simp },
{ use (fin.last _), simp } }
end
lemma eq_snoc_erase_top {s : composition_series X} (h : 0 < s.length) :
s = snoc (erase_top s) s.top (is_maximal_erase_top_top h) :=
begin
ext x,
simp [mem_snoc, mem_erase_top h],
by_cases h : x = s.top; simp [*, s.top_mem]
end
@[simp] lemma snoc_erase_top_top {s : composition_series X}
(h : is_maximal s.erase_top.top s.top) : s.erase_top.snoc s.top h = s :=
have h : 0 < s.length,
from nat.pos_of_ne_zero begin
assume hs,
refine ne_of_gt (lt_of_is_maximal h) _,
simp [top, fin.ext_iff, hs]
end,
(eq_snoc_erase_top h).symm
/-- Two `composition_series X`, `s₁` and `s₂` are equivalent if there is a bijection
`e : fin s₁.length ≃ fin s₂.length` such that for any `i`,
`iso (s₁ i) (s₁ i.succ) (s₂ (e i), s₂ (e i.succ))` -/
def equivalent (s₁ s₂ : composition_series X) : Prop :=
∃ f : fin s₁.length ≃ fin s₂.length,
∀ i : fin s₁.length,
iso (s₁ i.cast_succ, s₁ i.succ)
(s₂ (f i).cast_succ, s₂ (f i).succ)
namespace equivalent
@[refl] lemma refl (s : composition_series X) : equivalent s s :=
⟨equiv.refl _, λ _, (s.step _).iso_refl⟩
@[symm] lemma symm {s₁ s₂ : composition_series X} (h : equivalent s₁ s₂) :
equivalent s₂ s₁ :=
⟨h.some.symm, λ i, iso_symm (by simpa using h.some_spec (h.some.symm i))⟩
@[trans] lemma trans {s₁ s₂ s₃ : composition_series X}
(h₁ : equivalent s₁ s₂)
(h₂ : equivalent s₂ s₃) :
equivalent s₁ s₃ :=
⟨h₁.some.trans h₂.some, λ i, iso_trans (h₁.some_spec i) (h₂.some_spec (h₁.some i))⟩
lemma append
{s₁ s₂ t₁ t₂ : composition_series X}
(hs : s₁.top = s₂.bot)
(ht : t₁.top = t₂.bot)
(h₁ : equivalent s₁ t₁)
(h₂ : equivalent s₂ t₂) :
equivalent (append s₁ s₂ hs) (append t₁ t₂ ht) :=
let e : fin (s₁.length + s₂.length) ≃ fin (t₁.length + t₂.length) :=
calc fin (s₁.length + s₂.length) ≃ fin s₁.length ⊕ fin s₂.length : fin_sum_fin_equiv.symm
... ≃ fin t₁.length ⊕ fin t₂.length : equiv.sum_congr h₁.some h₂.some
... ≃ fin (t₁.length + t₂.length) : fin_sum_fin_equiv in
⟨e, begin
assume i,
refine fin.add_cases _ _ i,
{ assume i,
simpa [top, bot] using h₁.some_spec i },
{ assume i,
simpa [top, bot] using h₂.some_spec i }
end⟩
protected lemma snoc
{s₁ s₂ : composition_series X}
{x₁ x₂ : X}
{hsat₁ : is_maximal s₁.top x₁}
{hsat₂ : is_maximal s₂.top x₂}
(hequiv : equivalent s₁ s₂)
(htop : iso (s₁.top, x₁) (s₂.top, x₂)) :
equivalent (s₁.snoc x₁ hsat₁) (s₂.snoc x₂ hsat₂) :=
let e : fin s₁.length.succ ≃ fin s₂.length.succ :=
calc fin (s₁.length + 1) ≃ option (fin s₁.length) : fin_succ_equiv_last
... ≃ option (fin s₂.length) : functor.map_equiv option hequiv.some
... ≃ fin (s₂.length + 1) : fin_succ_equiv_last.symm in
⟨e, λ i, begin
refine fin.last_cases _ _ i,
{ simpa [top] using htop },
{ assume i,
simpa [fin.succ_cast_succ] using hequiv.some_spec i }
end⟩
lemma length_eq {s₁ s₂ : composition_series X} (h : equivalent s₁ s₂) : s₁.length = s₂.length :=
by simpa using fintype.card_congr h.some
lemma snoc_snoc_swap
{s : composition_series X}
{x₁ x₂ y₁ y₂ : X}
{hsat₁ : is_maximal s.top x₁}
{hsat₂ : is_maximal s.top x₂}
{hsaty₁ : is_maximal (snoc s x₁ hsat₁).top y₁}
{hsaty₂ : is_maximal (snoc s x₂ hsat₂).top y₂}
(hr₁ : iso (s.top, x₁) (x₂, y₂))
(hr₂ : iso (x₁, y₁) (s.top, x₂)) :
equivalent
(snoc (snoc s x₁ hsat₁) y₁ hsaty₁)
(snoc (snoc s x₂ hsat₂) y₂ hsaty₂) :=
let e : fin (s.length + 1 + 1) ≃ fin (s.length + 1 + 1) :=
equiv.swap (fin.last _) (fin.cast_succ (fin.last _)) in
have h1 : ∀ {i : fin s.length},
i.cast_succ.cast_succ ≠ (fin.last _).cast_succ,
from λ _, ne_of_lt (by simp [fin.cast_succ_lt_last]),
have h2 : ∀ {i : fin s.length},
i.cast_succ.cast_succ ≠ (fin.last _),
from λ _, ne_of_lt (by simp [fin.cast_succ_lt_last]),
⟨e, begin
intro i,
dsimp only [e],
refine fin.last_cases _ (λ i, _) i,
{ erw [equiv.swap_apply_left, snoc_cast_succ, snoc_last, fin.succ_last, snoc_last,
snoc_cast_succ, snoc_cast_succ, fin.succ_cast_succ, snoc_cast_succ,
fin.succ_last, snoc_last],
exact hr₂ },
{ refine fin.last_cases _ (λ i, _) i,
{ erw [equiv.swap_apply_right, snoc_cast_succ, snoc_cast_succ,
snoc_cast_succ, fin.succ_cast_succ, snoc_cast_succ,
fin.succ_last, snoc_last, snoc_last, fin.succ_last, snoc_last],
exact hr₁ },
{ erw [equiv.swap_apply_of_ne_of_ne h2 h1, snoc_cast_succ, snoc_cast_succ,
snoc_cast_succ, snoc_cast_succ, fin.succ_cast_succ, snoc_cast_succ,
fin.succ_cast_succ, snoc_cast_succ, snoc_cast_succ, snoc_cast_succ],
exact (s.step i).iso_refl } }
end⟩
end equivalent
lemma length_eq_zero_of_bot_eq_bot_of_top_eq_top_of_length_eq_zero
{s₁ s₂ : composition_series X}
(hb : s₁.bot = s₂.bot) (ht : s₁.top = s₂.top)
(hs₁ : s₁.length = 0) : s₂.length = 0 :=
begin
have : s₁.bot = s₁.top,
from congr_arg s₁ (fin.ext (by simp [hs₁])),
have : (fin.last s₂.length) = (0 : fin s₂.length.succ),
from s₂.injective (hb.symm.trans (this.trans ht)).symm,
simpa [fin.ext_iff]
end
lemma length_pos_of_bot_eq_bot_of_top_eq_top_of_length_pos
{s₁ s₂ : composition_series X}
(hb : s₁.bot = s₂.bot) (ht : s₁.top = s₂.top) :
0 < s₁.length → 0 < s₂.length :=
not_imp_not.1 begin
simp only [pos_iff_ne_zero, ne.def, not_iff_not, not_not],
exact length_eq_zero_of_bot_eq_bot_of_top_eq_top_of_length_eq_zero hb.symm ht.symm
end
lemma eq_of_bot_eq_bot_of_top_eq_top_of_length_eq_zero
{s₁ s₂ : composition_series X}
(hb : s₁.bot = s₂.bot) (ht : s₁.top = s₂.top)
(hs₁0 : s₁.length = 0) :
s₁ = s₂ :=
have ∀ x, x ∈ s₁ ↔ x = s₁.top,
from λ x, ⟨λ hx, forall_mem_eq_of_length_eq_zero hs₁0 hx s₁.top_mem, λ hx, hx.symm ▸ s₁.top_mem⟩,
have ∀ x, x ∈ s₂ ↔ x = s₂.top,
from λ x, ⟨λ hx, forall_mem_eq_of_length_eq_zero
(length_eq_zero_of_bot_eq_bot_of_top_eq_top_of_length_eq_zero hb ht hs₁0)
hx s₂.top_mem, λ hx, hx.symm ▸ s₂.top_mem⟩,
by { ext, simp * }
/-- Given a `composition_series`, `s`, and an element `x`
such that `x` is maximal inside `s.top` there is a series, `t`,
such that `t.top = x`, `t.bot = s.bot`
and `snoc t s.top _` is equivalent to `s`. -/
lemma exists_top_eq_snoc_equivalant (s : composition_series X) (x : X)
(hm : is_maximal x s.top) (hb : s.bot ≤ x) :
∃ t : composition_series X, t.bot = s.bot ∧ t.length + 1 = s.length ∧
∃ htx : t.top = x, equivalent s (snoc t s.top (htx.symm ▸ hm)) :=
begin
induction hn : s.length with n ih generalizing s x,
{ exact (ne_of_gt (lt_of_le_of_lt hb (lt_of_is_maximal hm))
(forall_mem_eq_of_length_eq_zero hn s.top_mem s.bot_mem)).elim },
{ have h0s : 0 < s.length, from hn.symm ▸ nat.succ_pos _,
by_cases hetx : s.erase_top.top = x,
{ use s.erase_top,
simp [← hetx, hn] },
{ have imxs : is_maximal (x ⊓ s.erase_top.top) s.erase_top.top,
from is_maximal_of_eq_inf x s.top rfl (ne.symm hetx) hm
(is_maximal_erase_top_top h0s),
have := ih _ _ imxs (le_inf (by simpa) (le_top_of_mem s.erase_top.bot_mem)) (by simp [hn]),
rcases this with ⟨t, htb, htl, htt, hteqv⟩,
have hmtx : is_maximal t.top x,
from is_maximal_of_eq_inf s.erase_top.top s.top
(by rw [inf_comm, htt]) hetx
(is_maximal_erase_top_top h0s) hm,
use snoc t x hmtx,
refine ⟨by simp [htb], by simp [htl], by simp, _⟩,
have : s.equivalent ((snoc t s.erase_top.top (htt.symm ▸ imxs)).snoc s.top
(by simpa using is_maximal_erase_top_top h0s)),
{ conv_lhs { rw eq_snoc_erase_top h0s },
exact equivalent.snoc hteqv
(by simpa using (is_maximal_erase_top_top h0s).iso_refl) },
refine this.trans _,
refine equivalent.snoc_snoc_swap _ _,
{ exact iso_symm (second_iso_of_eq hm
(sup_eq_of_is_maximal hm
(is_maximal_erase_top_top h0s)
(ne.symm hetx))
htt.symm) },
{ exact second_iso_of_eq (is_maximal_erase_top_top h0s)
(sup_eq_of_is_maximal
(is_maximal_erase_top_top h0s)
hm hetx)
(by rw [inf_comm, htt]) } } }
end
/-- The **Jordan-Hölder** theorem, stated for any `jordan_holder_lattice`.
If two composition series start and finish at the same place, they are equivalent. -/
theorem jordan_holder (s₁ s₂ : composition_series X)
(hb : s₁.bot = s₂.bot) (ht : s₁.top = s₂.top) :
equivalent s₁ s₂ :=
begin
induction hle : s₁.length with n ih generalizing s₁ s₂,
{ rw [eq_of_bot_eq_bot_of_top_eq_top_of_length_eq_zero hb ht hle] },
{ have h0s₂ : 0 < s₂.length,
from length_pos_of_bot_eq_bot_of_top_eq_top_of_length_pos hb ht (hle.symm ▸ nat.succ_pos _),
rcases exists_top_eq_snoc_equivalant s₁ s₂.erase_top.top
(ht.symm ▸ is_maximal_erase_top_top h0s₂)
(hb.symm ▸ s₂.bot_erase_top ▸ bot_le_of_mem (top_mem _)) with ⟨t, htb, htl, htt, hteq⟩,
have := ih t s₂.erase_top (by simp [htb, ← hb]) htt (nat.succ_inj'.1 (htl.trans hle)),
refine hteq.trans _,
conv_rhs { rw [eq_snoc_erase_top h0s₂] },
simp only [ht],
exact equivalent.snoc this
(by simp [htt, (is_maximal_erase_top_top h0s₂).iso_refl]) }
end
end composition_series
|
060e70cd90a29d2009c4301a629d3bc3d73d97c4 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/eagerUnfoldingIssue.lean | 1946e7a4b67c267e3f5216872698b05c0d3febaf | [
"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 | 203 | lean | import Lean
namespace Lean.Elab
def f1 (x : Nat) : StateM Nat Unit := do
logInfo m!"{x}"
pure ()
abbrev M := StateM Nat Unit
def f2 (x : Nat) : M := do
logInfo m!"{x}"
pure ()
end Lean.Elab
|
acc267b524dc682fe9a800c82932630e1da27f90 | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/data/set/intervals/pi.lean | 4ded6da0e95fd60ce0c921d9edd65913794e696a | [
"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 | 6,133 | lean | /-
Copyright (c) 2020 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import data.set.intervals.basic
import data.set.lattice
/-!
# Intervals in `pi`-space
In this we prove various simple lemmas about intervals in `Π i, α i`. Closed intervals (`Ici x`,
`Iic x`, `Icc x y`) are equal to products of their projections to `α i`, while (semi-)open intervals
usually include the corresponding products as proper subsets.
-/
variables {ι : Type*} {α : ι → Type*}
namespace set
section pi_preorder
variables [Π i, preorder (α i)] (x y : Π i, α i)
@[simp] lemma pi_univ_Ici : pi univ (λ i, Ici (x i)) = Ici x :=
ext $ λ y, by simp [pi.le_def]
@[simp] lemma pi_univ_Iic : pi univ (λ i, Iic (x i)) = Iic x :=
ext $ λ y, by simp [pi.le_def]
@[simp] lemma pi_univ_Icc : pi univ (λ i, Icc (x i) (y i)) = Icc x y :=
ext $ λ y, by simp [pi.le_def, forall_and_distrib]
lemma piecewise_mem_Icc {s : set ι} [Π j, decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : Π i, α i}
(h₁ : ∀ i ∈ s, f₁ i ∈ Icc (g₁ i) (g₂ i)) (h₂ : ∀ i ∉ s, f₂ i ∈ Icc (g₁ i) (g₂ i)) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
⟨le_piecewise (λ i hi, (h₁ i hi).1) (λ i hi, (h₂ i hi).1),
piecewise_le (λ i hi, (h₁ i hi).2) (λ i hi, (h₂ i hi).2)⟩
lemma piecewise_mem_Icc' {s : set ι} [Π j, decidable (j ∈ s)] {f₁ f₂ g₁ g₂ : Π i, α i}
(h₁ : f₁ ∈ Icc g₁ g₂) (h₂ : f₂ ∈ Icc g₁ g₂) :
s.piecewise f₁ f₂ ∈ Icc g₁ g₂ :=
piecewise_mem_Icc (λ i hi, ⟨h₁.1 _, h₁.2 _⟩) (λ i hi, ⟨h₂.1 _, h₂.2 _⟩)
section nonempty
variable [nonempty ι]
lemma pi_univ_Ioi_subset : pi univ (λ i, Ioi (x i)) ⊆ Ioi x :=
λ z hz, ⟨λ i, le_of_lt $ hz i trivial,
λ h, nonempty.elim ‹nonempty ι› $ λ i, (h i).not_lt (hz i trivial)⟩
lemma pi_univ_Iio_subset : pi univ (λ i, Iio (x i)) ⊆ Iio x :=
@pi_univ_Ioi_subset ι (λ i, order_dual (α i)) _ x _
lemma pi_univ_Ioo_subset : pi univ (λ i, Ioo (x i) (y i)) ⊆ Ioo x y :=
λ x hx, ⟨pi_univ_Ioi_subset _ $ λ i hi, (hx i hi).1, pi_univ_Iio_subset _ $ λ i hi, (hx i hi).2⟩
lemma pi_univ_Ioc_subset : pi univ (λ i, Ioc (x i) (y i)) ⊆ Ioc x y :=
λ x hx, ⟨pi_univ_Ioi_subset _ $ λ i hi, (hx i hi).1, λ i, (hx i trivial).2⟩
lemma pi_univ_Ico_subset : pi univ (λ i, Ico (x i) (y i)) ⊆ Ico x y :=
λ x hx, ⟨λ i, (hx i trivial).1, pi_univ_Iio_subset _ $ λ i hi, (hx i hi).2⟩
end nonempty
variable [decidable_eq ι]
open function (update)
lemma pi_univ_Ioc_update_left {x y : Π i, α i} {i₀ : ι} {m : α i₀} (hm : x i₀ ≤ m) :
pi univ (λ i, Ioc (update x i₀ m i) (y i)) = {z | m < z i₀} ∩ pi univ (λ i, Ioc (x i) (y i)) :=
begin
have : Ioc m (y i₀) = Ioi m ∩ Ioc (x i₀) (y i₀),
by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, ← inter_assoc,
inter_eq_self_of_subset_left (Ioi_subset_Ioi hm)],
simp_rw [univ_pi_update i₀ _ _ (λ i z, Ioc z (y i)), ← pi_inter_compl ({i₀} : set ι),
singleton_pi', ← inter_assoc, this],
refl
end
lemma pi_univ_Ioc_update_right {x y : Π i, α i} {i₀ : ι} {m : α i₀} (hm : m ≤ y i₀) :
pi univ (λ i, Ioc (x i) (update y i₀ m i)) = {z | z i₀ ≤ m} ∩ pi univ (λ i, Ioc (x i) (y i)) :=
begin
have : Ioc (x i₀) m = Iic m ∩ Ioc (x i₀) (y i₀),
by rw [← Ioi_inter_Iic, ← Ioi_inter_Iic, inter_left_comm,
inter_eq_self_of_subset_left (Iic_subset_Iic.2 hm)],
simp_rw [univ_pi_update i₀ y m (λ i z, Ioc (x i) z), ← pi_inter_compl ({i₀} : set ι),
singleton_pi', ← inter_assoc, this],
refl
end
lemma disjoint_pi_univ_Ioc_update_left_right {x y : Π i, α i} {i₀ : ι} {m : α i₀} :
disjoint (pi univ (λ i, Ioc (x i) (update y i₀ m i)))
(pi univ (λ i, Ioc (update x i₀ m i) (y i))) :=
begin
rintro z ⟨h₁, h₂⟩,
refine (h₁ i₀ (mem_univ _)).2.not_lt _,
simpa only [function.update_same] using (h₂ i₀ (mem_univ _)).1
end
end pi_preorder
variables [decidable_eq ι] [Π i, linear_order (α i)]
open function (update)
lemma pi_univ_Ioc_update_union (x y : Π i, α i) (i₀ : ι) (m : α i₀) (hm : m ∈ Icc (x i₀) (y i₀)) :
pi univ (λ i, Ioc (x i) (update y i₀ m i)) ∪ pi univ (λ i, Ioc (update x i₀ m i) (y i)) =
pi univ (λ i, Ioc (x i) (y i)) :=
by simp_rw [pi_univ_Ioc_update_left hm.1, pi_univ_Ioc_update_right hm.2,
← union_inter_distrib_right, ← set_of_or, le_or_lt, set_of_true, univ_inter]
/-- If `x`, `y`, `x'`, and `y'` are functions `Π i : ι, α i`, then
the set difference between the box `[x, y]` and the product of the open intervals `(x' i, y' i)`
is covered by the union of the following boxes: for each `i : ι`, we take
`[x, update y i (x' i)]` and `[update x i (y' i), y]`.
E.g., if `x' = x` and `y' = y`, then this lemma states that the difference between a closed box
`[x, y]` and the corresponding open box `{z | ∀ i, x i < z i < y i}` is covered by the union
of the faces of `[x, y]`. -/
lemma Icc_diff_pi_univ_Ioo_subset (x y x' y' : Π i, α i) :
Icc x y \ pi univ (λ i, Ioo (x' i) (y' i)) ⊆
(⋃ i : ι, Icc x (update y i (x' i))) ∪ ⋃ i : ι, Icc (update x i (y' i)) y :=
begin
rintros a ⟨⟨hxa, hay⟩, ha'⟩,
simpa [le_update_iff, update_le_iff, hxa, hay, hxa _, hay _, ← exists_or_distrib,
not_and_distrib] using ha'
end
/-- If `x`, `y`, `z` are functions `Π i : ι, α i`, then
the set difference between the box `[x, z]` and the product of the intervals `(y i, z i]`
is covered by the union of the boxes `[x, update z i (y i)]`.
E.g., if `x = y`, then this lemma states that the difference between a closed box
`[x, y]` and the product of half-open intervals `{z | ∀ i, x i < z i ≤ y i}` is covered by the union
of the faces of `[x, y]` adjacent to `x`. -/
lemma Icc_diff_pi_univ_Ioc_subset (x y z : Π i, α i) :
Icc x z \ pi univ (λ i, Ioc (y i) (z i)) ⊆ ⋃ i : ι, Icc x (update z i (y i)) :=
begin
rintros a ⟨⟨hax, haz⟩, hay⟩,
simpa [not_and_distrib, hax, le_update_iff, haz _] using hay
end
end set
|
610ff5d184c83aa19a5dad093086f5a892c6b84e | 38bf3fd2bb651ab70511408fcf70e2029e2ba310 | /src/category_theory/adjunction/basic.lean | f9cbc17a12c7847bf6d970b8912ca8fe37c8c8f4 | [
"Apache-2.0"
] | permissive | JaredCorduan/mathlib | 130392594844f15dad65a9308c242551bae6cd2e | d5de80376088954d592a59326c14404f538050a1 | refs/heads/master | 1,595,862,206,333 | 1,570,816,457,000 | 1,570,816,457,000 | 209,134,499 | 0 | 0 | Apache-2.0 | 1,568,746,811,000 | 1,568,746,811,000 | null | UTF-8 | Lean | false | false | 10,260 | lean | /-
Copyright (c) 2019 Reid Barton. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Reid Barton, Johan Commelin
-/
import category_theory.equivalence
import data.equiv.basic
namespace category_theory
open category
universes v₁ v₂ v₃ u₁ u₂ u₃ -- declare the `v`'s first; see `category_theory.category` for an explanation
local attribute [elab_simple] whisker_left whisker_right
variables {C : Type u₁} [𝒞 : category.{v₁} C] {D : Type u₂} [𝒟 : category.{v₂} D]
include 𝒞 𝒟
/--
`F ⊣ G` represents the data of an adjunction between two functors
`F : C ⥤ D` and `G : D ⥤ C`. `F` is the left adjoint and `G` is the right adjoint.
-/
structure adjunction (F : C ⥤ D) (G : D ⥤ C) :=
(hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
(unit : 𝟭 C ⟶ F.comp G)
(counit : G.comp F ⟶ 𝟭 D)
(hom_equiv_unit' : Π {X Y f}, (hom_equiv X Y) f = (unit : _ ⟶ _).app X ≫ G.map f . obviously)
(hom_equiv_counit' : Π {X Y g}, (hom_equiv X Y).symm g = F.map g ≫ counit.app Y . obviously)
infix ` ⊣ `:15 := adjunction
class is_left_adjoint (left : C ⥤ D) :=
(right : D ⥤ C)
(adj : left ⊣ right)
class is_right_adjoint (right : D ⥤ C) :=
(left : C ⥤ D)
(adj : left ⊣ right)
def left_adjoint (R : D ⥤ C) [is_right_adjoint R] : C ⥤ D :=
is_right_adjoint.left R
def right_adjoint (L : C ⥤ D) [is_left_adjoint L] : D ⥤ C :=
is_left_adjoint.right L
namespace adjunction
restate_axiom hom_equiv_unit'
restate_axiom hom_equiv_counit'
attribute [simp, priority 10] hom_equiv_unit hom_equiv_counit
section
variables {F : C ⥤ D} {G : D ⥤ C} (adj : F ⊣ G) {X' X : C} {Y Y' : D}
@[simp, priority 10] lemma hom_equiv_naturality_left_symm (f : X' ⟶ X) (g : X ⟶ G.obj Y) :
(adj.hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (adj.hom_equiv X Y).symm g :=
by rw [hom_equiv_counit, F.map_comp, assoc, adj.hom_equiv_counit.symm]
@[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g :=
by rw [← equiv.eq_symm_apply]; simp [-hom_equiv_unit]
@[simp, priority 10] lemma hom_equiv_naturality_right (f : F.obj X ⟶ Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y') (f ≫ g) = (adj.hom_equiv X Y) f ≫ G.map g :=
by rw [hom_equiv_unit, G.map_comp, ← assoc, ←hom_equiv_unit]
@[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g :=
by rw [equiv.symm_apply_eq]; simp [-hom_equiv_counit]
@[simp] lemma left_triangle :
(whisker_right adj.unit F) ≫ (whisker_left F adj.counit) = nat_trans.id _ :=
begin
ext1 X, dsimp,
erw [← adj.hom_equiv_counit, equiv.symm_apply_eq, adj.hom_equiv_unit],
simp
end
@[simp] lemma right_triangle :
(whisker_left G adj.unit) ≫ (whisker_right adj.counit G) = nat_trans.id _ :=
begin
ext1 Y, dsimp,
erw [← adj.hom_equiv_unit, ← equiv.eq_symm_apply, adj.hom_equiv_counit],
simp
end
@[simp, reassoc] lemma left_triangle_components :
F.map (adj.unit.app X) ≫ adj.counit.app (F.obj X) = 𝟙 (F.obj X) :=
congr_arg (λ (t : nat_trans _ (𝟭 C ⋙ F)), t.app X) adj.left_triangle
@[simp, reassoc] lemma right_triangle_components {Y : D} :
adj.unit.app (G.obj Y) ≫ G.map (adj.counit.app Y) = 𝟙 (G.obj Y) :=
congr_arg (λ (t : nat_trans _ (G ⋙ 𝟭 C)), t.app Y) adj.right_triangle
@[simp, reassoc] lemma counit_naturality {X Y : D} (f : X ⟶ Y) :
F.map (G.map f) ≫ (adj.counit).app Y = (adj.counit).app X ≫ f :=
adj.counit.naturality f
@[simp, reassoc] lemma unit_naturality {X Y : C} (f : X ⟶ Y) :
(adj.unit).app X ≫ G.map (F.map f) = f ≫ (adj.unit).app Y :=
(adj.unit.naturality f).symm
end
end adjunction
namespace adjunction
structure core_hom_equiv (F : C ⥤ D) (G : D ⥤ C) :=
(hom_equiv : Π (X Y), (F.obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
(hom_equiv_naturality_left_symm' : Π {X' X Y} (f : X' ⟶ X) (g : X ⟶ G.obj Y),
(hom_equiv X' Y).symm (f ≫ g) = F.map f ≫ (hom_equiv X Y).symm g . obviously)
(hom_equiv_naturality_right' : Π {X Y Y'} (f : F.obj X ⟶ Y) (g : Y ⟶ Y'),
(hom_equiv X Y') (f ≫ g) = (hom_equiv X Y) f ≫ G.map g . obviously)
namespace core_hom_equiv
restate_axiom hom_equiv_naturality_left_symm'
restate_axiom hom_equiv_naturality_right'
attribute [simp, priority 10] hom_equiv_naturality_left_symm hom_equiv_naturality_right
variables {F : C ⥤ D} {G : D ⥤ C} (adj : core_hom_equiv F G) {X' X : C} {Y Y' : D}
@[simp] lemma hom_equiv_naturality_left (f : X' ⟶ X) (g : F.obj X ⟶ Y) :
(adj.hom_equiv X' Y) (F.map f ≫ g) = f ≫ (adj.hom_equiv X Y) g :=
by rw [← equiv.eq_symm_apply]; simp
@[simp] lemma hom_equiv_naturality_right_symm (f : X ⟶ G.obj Y) (g : Y ⟶ Y') :
(adj.hom_equiv X Y').symm (f ≫ G.map g) = (adj.hom_equiv X Y).symm f ≫ g :=
by rw [equiv.symm_apply_eq]; simp
end core_hom_equiv
structure core_unit_counit (F : C ⥤ D) (G : D ⥤ C) :=
(unit : 𝟭 C ⟶ F.comp G)
(counit : G.comp F ⟶ 𝟭 D)
(left_triangle' : whisker_right unit F ≫ whisker_left F counit = nat_trans.id _ . obviously)
(right_triangle' : whisker_left G unit ≫ whisker_right counit G = nat_trans.id _ . obviously)
namespace core_unit_counit
restate_axiom left_triangle'
restate_axiom right_triangle'
attribute [simp] left_triangle right_triangle
end core_unit_counit
variables {F : C ⥤ D} {G : D ⥤ C}
def mk_of_hom_equiv (adj : core_hom_equiv F G) : F ⊣ G :=
{ unit :=
{ app := λ X, (adj.hom_equiv X (F.obj X)) (𝟙 (F.obj X)),
naturality' :=
begin
intros,
erw [← adj.hom_equiv_naturality_left, ← adj.hom_equiv_naturality_right],
dsimp, simp
end },
counit :=
{ app := λ Y, (adj.hom_equiv _ _).inv_fun (𝟙 (G.obj Y)),
naturality' :=
begin
intros,
erw [← adj.hom_equiv_naturality_left_symm, ← adj.hom_equiv_naturality_right_symm],
dsimp, simp
end },
hom_equiv_unit' := λ X Y f, by erw [← adj.hom_equiv_naturality_right]; simp,
hom_equiv_counit' := λ X Y f, by erw [← adj.hom_equiv_naturality_left_symm]; simp,
.. adj }
def mk_of_unit_counit (adj : core_unit_counit F G) : F ⊣ G :=
{ hom_equiv := λ X Y,
{ to_fun := λ f, adj.unit.app X ≫ G.map f,
inv_fun := λ g, F.map g ≫ adj.counit.app Y,
left_inv := λ f, begin
change F.map (_ ≫ _) ≫ _ = _,
rw [F.map_comp, assoc, ←functor.comp_map, adj.counit.naturality, ←assoc],
convert id_comp _ f,
exact congr_arg (λ t : nat_trans _ _, t.app _) adj.left_triangle
end,
right_inv := λ g, begin
change _ ≫ G.map (_ ≫ _) = _,
rw [G.map_comp, ←assoc, ←functor.comp_map, ←adj.unit.naturality, assoc],
convert comp_id _ g,
exact congr_arg (λ t : nat_trans _ _, t.app _) adj.right_triangle
end },
.. adj }
section
omit 𝒟
def id : 𝟭 C ⊣ 𝟭 C :=
{ hom_equiv := λ X Y, equiv.refl _,
unit := 𝟙 _,
counit := 𝟙 _ }
end
section
variables {E : Type u₃} [ℰ : category.{v₃} E] (H : D ⥤ E) (I : E ⥤ D)
def comp (adj₁ : F ⊣ G) (adj₂ : H ⊣ I) : F ⋙ H ⊣ I ⋙ G :=
{ hom_equiv := λ X Z, equiv.trans (adj₂.hom_equiv _ _) (adj₁.hom_equiv _ _),
unit := adj₁.unit ≫
(whisker_left F $ whisker_right adj₂.unit G) ≫ (functor.associator _ _ _).inv,
counit := (functor.associator _ _ _).hom ≫
(whisker_left I $ whisker_right adj₁.counit H) ≫ adj₂.counit }
end
section construct_left
-- Construction of a left adjoint. In order to construct a left
-- adjoint to a functor G : D → C, it suffices to give the object part
-- of a functor F : C → D together with isomorphisms Hom(FX, Y) ≃
-- Hom(X, GY) natural in Y. The action of F on morphisms can be
-- constructed from this data.
variables {F_obj : C → D} {G}
variables (e : Π X Y, (F_obj X ⟶ Y) ≃ (X ⟶ G.obj Y))
variables (he : Π X Y Y' g h, e X Y' (h ≫ g) = e X Y h ≫ G.map g)
include he
private lemma he' {X Y Y'} (f g) : (e X Y').symm (f ≫ G.map g) = (e X Y).symm f ≫ g :=
by intros; rw [equiv.symm_apply_eq, he]; simp
def left_adjoint_of_equiv : C ⥤ D :=
{ obj := F_obj,
map := λ X X' f, (e X (F_obj X')).symm (f ≫ e X' (F_obj X') (𝟙 _)),
map_comp' := λ X X' X'' f f', begin
rw [equiv.symm_apply_eq, he, equiv.apply_symm_apply],
conv { to_rhs, rw [assoc, ←he, id_comp, equiv.apply_symm_apply] },
simp
end }
def adjunction_of_equiv_left : left_adjoint_of_equiv e he ⊣ G :=
mk_of_hom_equiv
{ hom_equiv := e,
hom_equiv_naturality_left_symm' :=
begin
intros,
erw [← he' e he, ← equiv.apply_eq_iff_eq],
simp [(he _ _ _ _ _).symm]
end }
end construct_left
section construct_right
-- Construction of a right adjoint, analogous to the above.
variables {F} {G_obj : D → C}
variables (e : Π X Y, (F.obj X ⟶ Y) ≃ (X ⟶ G_obj Y))
variables (he : Π X' X Y f g, e X' Y (F.map f ≫ g) = f ≫ e X Y g)
include he
private lemma he' {X' X Y} (f g) : F.map f ≫ (e X Y).symm g = (e X' Y).symm (f ≫ g) :=
by intros; rw [equiv.eq_symm_apply, he]; simp
def right_adjoint_of_equiv : D ⥤ C :=
{ obj := G_obj,
map := λ Y Y' g, (e (G_obj Y) Y') ((e (G_obj Y) Y).symm (𝟙 _) ≫ g),
map_comp' := λ Y Y' Y'' g g', begin
rw [← equiv.eq_symm_apply, ← he' e he, equiv.symm_apply_apply],
conv { to_rhs, rw [← assoc, he' e he, comp_id, equiv.symm_apply_apply] },
simp
end }
def adjunction_of_equiv_right : F ⊣ right_adjoint_of_equiv e he :=
mk_of_hom_equiv
{ hom_equiv := e,
hom_equiv_naturality_left_symm' := by intros; rw [equiv.symm_apply_eq, he]; simp,
hom_equiv_naturality_right' :=
begin
intros X Y Y' g h,
erw [←he, equiv.apply_eq_iff_eq, ←assoc, he' e he, comp_id, equiv.symm_apply_apply]
end }
end construct_right
end adjunction
open adjunction
namespace equivalence
def to_adjunction (e : C ≌ D) : e.functor ⊣ e.inverse :=
mk_of_unit_counit ⟨e.unit, e.counit, by { ext, exact e.functor_unit_comp X },
by { ext, exact e.unit_inverse_comp X }⟩
end equivalence
namespace functor
def adjunction (E : C ⥤ D) [is_equivalence E] : E ⊣ E.inv :=
(E.as_equivalence).to_adjunction
end functor
end category_theory
|
67ef1d618f998620eb823ec5dcf9ebd7d1353d4a | a7602958ab456501ff85db8cf5553f7bcab201d7 | /Assignment8/4.4-homework.lean | 93d8e2dd369f13d76276ccf3dcdeba824b1dc906 | [] | no_license | enlauren/math-logic | 081e2e737c8afb28dbb337968df95ead47321ba0 | 086b6935543d1841f1db92d0e49add1124054c37 | refs/heads/master | 1,594,506,621,950 | 1,558,634,976,000 | 1,558,634,976,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 8,315 | lean | -- Assignment 8
-- Dom Farolino, farolidm@mail.uc.edu
-- Math Logic
-- For this assignment, proofs of all of the 11 given identities in
-- section 4.4 are presented here.
open classical
variables (α : Type) (p q : α → Prop)
variable a : α
variable r : Prop
example : (∃ x : α, r) → r :=
assume h: (∃ x : α, r),
exists.elim h
(assume t: α,
assume ht: r,
show r, from ht
)
example: r → (∃ x : α, r) :=
assume hr: r,
show (∃ x : α, r), from exists.intro a hr
example: (∃ x, p x ∧ r) ↔ (∃ x, p x) ∧ r :=
iff.intro
(assume h: (∃ x, p x ∧ r),
show (∃ x, p x) ∧ r, from
exists.elim h
(assume y: α,
assume hinner: p y ∧ r,
have hey: ∃ y, p y, from exists.intro y hinner.left,
show (∃ y, p y) ∧ r, from and.intro hey hinner.right
)
)
(assume h: (∃ x, p x) ∧ r,
show (∃ x, p x ∧ r), from
exists.elim h.left
(assume y: α,
assume hinner: p y,
have hand: p y ∧ r, from (and.intro hinner h.right),
show (∃ y, p y ∧ r), from exists.intro y hand
)
)
example: (∃ x, p x ∨ q x) ↔ (∃ x, p x) ∨ (∃ x, q x) :=
iff.intro
(assume h: (∃ x, p x ∨ q x),
show (∃ x, p x) ∨ (∃ x, q x), from
exists.elim h
(assume y: α,
assume hinner: p y ∨ q y, show (∃ y, p y) ∨ (∃ y, q y), from
or.elim hinner
(assume hpy: p y,
have halmost: (∃ y, p y), from exists.intro y hpy,
show (∃ y, p y) ∨ (∃ y, q y), from or.inl halmost
)
(assume hqy: q y,
have halmost: (∃ y, q y), from exists.intro y hqy,
show (∃ y, p y) ∨ (∃ y, q y), from or.inr halmost
)
)
)
(assume h: (∃ x, p x) ∨ (∃ x, q x),
show (∃ x, p x ∨ q x), from
or.elim h
(assume h1: (∃ x, p x),
exists.elim h1
(assume y: α,
assume hinner: p y,
have halmost: p y ∨ q y, from or.inl hinner,
show (∃ x, p x ∨ q x), from exists.intro y halmost
)
)
(assume h1: (∃ x, q x),
exists.elim h1
(assume y: α,
assume hinner: q y,
have halmost: p y ∨ q y, from or.inr hinner,
show (∃ x, p x ∨ q x), from exists.intro y halmost
)
)
)
example: (∀ x, p x) ↔ ¬ (∃ x, ¬ p x) :=
iff.intro
(assume h: (∀ x, p x),
show ¬ (∃ x, ¬ p x), from
assume hpos: (∃ x, ¬ p x),
show false, from
exists.elim hpos
(assume y: α,
assume hinner: ¬ p y,
show false, from hinner (h y)
)
)
(assume h: ¬ (∃ x, ¬ p x),
show (∀ x, p x), from
assume x: α,
show p x, from
by_contradiction
(assume h1: ¬ p x,
have hpos: ∃ x, ¬ p x, from exists.intro x h1,
show false, from h hpos
)
-- Originally went with this, but I found this was not the right
-- approach:
-- by_contradiction (assume h1: ¬ (∀ x, p x), sorry)
)
-- This one was rough...
example: (∃ x, p x) ↔ ¬ (∀ x, ¬ p x) :=
iff.intro
(assume h: (∃ x, p x),
show ¬ (∀ x, ¬ p x), from
assume hpos: (∀ x, ¬ p x),
show false, from
exists.elim h
(assume y: α,
assume hinner: p y,
show false, from (hpos y) hinner
)
)
(assume h: ¬ (∀ x, ¬ p x),
show (∃ x, p x), from
by_contradiction
(assume hneg: ¬ (∃ x, p x),
have hpos: (∀ x, ¬ p x), from
assume y: α,
-- have hnpy: ¬ p y, from -- Can uncomment this and "hnpy," below if wanted.
assume hy: p y,
have hey: ∃ y, p y, from exists.intro y hy,
show false, from hneg hey,
-- hnpy,
show false, from h hpos
)
)
example: (¬ ∃ x, p x) ↔ (∀ x, ¬ p x) :=
iff.intro
(assume h: (¬ ∃ x, p x),
show (∀ x, ¬ p x), from
assume x: α,
show ¬ p x, from
assume hpx: p x,
show false, from h (exists.intro x hpx)
)
(assume h: (∀ x, ¬ p x),
show (¬ ∃ x, p x), from
assume hpos: ∃ x, p x,
show false, from
exists.elim hpos
(assume y: α,
assume hpy: p y,
show false, from (h y) hpy
)
)
example: (¬ ∀ x, p x) ↔ (∃ x, ¬ p x) :=
iff.intro
(assume h: (¬ ∀ x, p x),
show (∃ x, ¬ p x), from
by_contradiction
(assume hneg: ¬ (∃ x, ¬ p x),
have hpos: (∀ x, p x), from
assume y: α,
-- have hpy: p y, from -- Can uncomment this and "hpy," if wanted.
by_contradiction
(assume hnpy: ¬ p y,
show false, from hneg (exists.intro y hnpy)
),
-- hpy,
show false, from h hpos
)
)
(assume h: (∃ x, ¬ p x),
show (¬ ∀ x, p x), from
assume hpos: (∀ x, p x),
show false, from
exists.elim h
(assume y: α,
assume hinner: ¬ p y,
show false, from hinner (hpos y)
)
)
-- Last 3:
example: (∀ x, p x → r) ↔ (∃ x, p x) → r :=
iff.intro
(assume h: (∀ x, p x → r),
show (∃ x, p x) → r, from
assume hex: (∃ x, p x),
show r, from
exists.elim hex
(assume y: α,
assume hinner: p y,
show r, from h y hinner)
)
(assume h: (∃ x, p x) → r,
show (∀ x, p x → r), from
by_cases
(assume hep: ∃ x, p x,
show (∀ x, p x → r), from
assume x, -- Does not specifically have to be x.
fun h', h hep
)
(assume hnep : ¬ ∃ x, p x,
-- show (∀ x, p x → r), from
by_contradiction
(assume hnap: ¬ (∀ x, p x → r),
have hep: ∃ x, p x, from
by_contradiction
(assume hnep': ¬ ∃ x, p x,
have hap: (∀ x, p x → r), from
assume x: α,
show p x → r, from
(assume hpx: p x,
show r, from absurd (exists.intro x hpx) hnep'
),
show false, from hnap hap
),
show false, from hnep hep
)
)
)
-- Given by the book:
example: (∃ x, p x → r) ↔ (∀ x, p x) → r :=
iff.intro
(assume ⟨b, (hb : p b → r)⟩,
assume h2 : ∀ x, p x,
show r, from hb (h2 b))
(assume h1 : (∀ x, p x) → r,
show ∃ x, p x → r, from
by_cases
(assume hap : ∀ x, p x,
show ∃ x, p x → r, from
⟨a, fun h', h1 hap⟩
)
(assume hnap : ¬ ∀ x, p x,
by_contradiction
(assume hnex : ¬ ∃ x, p x → r,
have hap : ∀ x, p x, from
assume x,
by_contradiction
(assume hnp : ¬ p x,
have hex : ∃ x, p x → r,
-- from ⟨x, (assume hp, absurd hp hnp)⟩,
from exists.intro x (assume hp: p x, absurd hp hnp),
show false, from hnex hex),
show false, from hnap hap)))
example: (∃ x, r → p x) ↔ (r → ∃ x, p x) :=
iff.intro
(assume h: (∃ x, r → p x),
assume hr: r,
show ∃ x, p x, from
exists.elim h
(assume y: α,
assume hinner: r → p y,
have hpy: p y, from hinner hr,
exists.intro y hpy
)
)
(assume h: (r → ∃ x, p x),
show (∃ x, r → p x), from
by_cases
(assume hc: r,
exists.elim (h hc)
(assume y: α,
assume hinner: p y,
have hcom: r → p y, from (assume hr, hinner),
show (∃ x, r → p x), from exists.intro y hcom
)
)
(assume hc: ¬ r,
show (∃ x, r → p x), from
exists.intro a (assume hr: r, absurd hr hc) -- Weird.
)
) |
093bf258ca154c29a5390aafc67919667c6aeb9c | e1440579fb0723caf9edf1ed07aee74bbf4f5ce7 | /lean-experiments/stumps-learnable/src/lib/basic.lean | 1c7d46b5243b5c03ea48edc0d09d47918229fe0e | [
"Apache-2.0"
] | permissive | palmskog/coq-proba | 1ecc5b7f399894ea14d6094a31a063280a122099 | f73e2780871e2a3dd83b7ce9d3aed19f499f07e5 | refs/heads/master | 1,599,620,504,720 | 1,572,960,008,000 | 1,572,960,008,000 | 221,326,479 | 0 | 0 | Apache-2.0 | 1,573,598,769,000 | 1,573,598,768,000 | null | UTF-8 | Lean | false | false | 11,418 | lean | /-
Copyright © 2019, Oracle and/or its affiliates. All rights reserved.
-/
import lib.attributed.probability_theory
import lib.attributed.dvector lib.attributed.to_mathlib
import measure_theory.giry_monad
import measure_theory.measure_space
import data.complex.exponential
local attribute [instance] classical.prop_decidable
universes u v
open nnreal measure_theory nat list measure_theory.measure to_integration probability_measure set dfin lattice ennreal
variables {α : Type u} {β : Type u} {γ : Type v}[measurable_space α]
infixl ` >>=ₐ `:55 := measure.bind
infixl ` <$>ₐ `:55 := measure.map
local notation `doₐ` binders ` ←ₐ ` m ` ; ` t:(scoped p, m >>=ₐ p) := t
local notation `ret` := measure.dirac
lemma split_set {α β : Type u} (Pa : α → Prop) (Pb : β → Prop) : {m : α × β | Pa m.fst} = {x : α | Pa x}.prod univ := by ext1; cases x; dsimp at *; simp at *
instance has_zero_dfin {n} : has_zero $ dfin (n+1) := ⟨dfin.fz⟩
lemma vec.split_set {n : ℕ} (P : α → Prop) (μ : probability_measure α) :
{x : vec α (n+2)| P (kth_projn x 1)} = set.prod univ {x : vec α (n+1) | P (kth_projn x 0)} :=
begin
ext1, cases x, cases x_snd, dsimp at *, simp at *, refl,
end
lemma vec.prod_measure_univ' {n : ℕ} [nonempty α] [ne : ∀ n, nonempty (vec α n)](μ : probability_measure α) : (vec.prod_measure μ n : measure (vec α (n))) (univ) = 1
:=
by exact measure_univ _
noncomputable def vec.prob_measure (n : ℕ) [nonempty α] (μ : probability_measure α) : probability_measure (vec α n) :=
⟨ vec.prod_measure μ n , vec.prod_measure_univ' μ ⟩
lemma vec.prob_measure_apply (n : ℕ) [nonempty α] {μ : probability_measure α} {S : set (vec α n)} (hS : is_measurable S) : (vec.prob_measure n μ) S = ((vec.prod_measure μ n) S) := rfl
lemma measure_kth_projn' {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : is_measurable {x : vec α (n + 1) | P (kth_projn x 0)}) :
(vec.prod_measure μ (n+2) : probability_measure (vec α (n+2))) {x : vec α (n + 2) | P (kth_projn x 1)} = μ {x : α | P x} :=
begin
rw vec.split_set _ μ,
rw vec.prod_measure_eq,
rw prod.prob_measure_apply _ _ is_measurable.univ _, rw prob_univ,rw one_mul,
have h: {x : vec α (n + 1) | P (kth_projn x 0)} = {x : vec α (n + 1) | P (x.fst)}, {
ext1, cases x, refl,
},
rw h, clear h,
induction n with k ih, rw vec.prod_measure_eq,
have h₁: {x : vec α (0 + 1) | P (x.fst)} = set.prod {x:α | P(x)} univ,by ext1; cases x; dsimp at *;simp at *,
rw h₁, rw vec.prod_measure,rw prod.prob_measure_apply _ _ _ is_measurable.univ, rw prob_univ, rw mul_one, assumption,assumption, exact hP,
have h₂ : {x : vec α (succ k + 1) | P (x.fst)} = {x : vec α (k + 2) | P (x.fst)},by refl,
rw h₂, clear h₂,
have h₃ : {x : vec α (k + 2) | P (x.fst)} = set.prod {x : α | P(x)} univ, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₃, rw vec.prod_measure_eq,rw prod.prob_measure_apply _ _ _ is_measurable.univ, rw prob_univ, rw mul_one, assumption, apply nonempty.vec, exact hP, assumption, apply nonempty.vec, assumption,
end
@[simp] lemma measure_kth_projn {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n i, is_measurable {x : vec α n | P (kth_projn x i)}) : ∀ (i : dfin (n+1)),
(vec.prod_measure μ n : probability_measure (vec α n)) {x : vec α n | P (kth_projn x i)} = μ {x : α | P x} :=
begin
intros i,
induction n with n b dk ih, rw vec.prod_measure,
have g : {x : vec α 0 | P (kth_projn x i)} = {x | P x}, by tidy, rw g, refl,
have h: {x : vec α (n + 1) | P (kth_projn x fz)} = {x : vec α (n + 1) | P (x.fst)}, {
ext1, cases x, refl,
},
cases i,
rw h, clear h,
have h₃ : {x : vec α (n + 1) | P (x.fst)} = set.prod {x : α | P(x)} univ, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₃, rw vec.prod_measure_eq, rw prod.prob_measure_apply _ _ hP is_measurable.univ, rw prob_univ, rw mul_one, exact (nonempty.vec n), rw vec.prod_measure_eq,
have h₄ : {x : vec α (succ n) | P (kth_projn x (fs i_a))} = set.prod univ {x : vec α n | P (kth_projn x i_a)}, {
ext1, cases x, dsimp at *, simp at *,
},
rw h₄, rw prod.prob_measure_apply _ _ is_measurable.univ _, rw prob_univ, rw one_mul, rw b,
assumption, exact (nonempty.vec n),
apply hp',
end
lemma dfin_succ_prop_iff_fst_and_rst {α : Type u} (P : α → Prop) {k : ℕ} (x : vec α (succ k)) : (∀ (i : dfin (succ k + 1)), P (kth_projn x i)) ↔ P (x.fst) ∧ ∀ (i : dfin (succ k)), P (kth_projn (x.snd) i) :=
begin
fsplit,
intros h, split, have := h fz, have : kth_projn x 0 = x.fst, cases x, refl, rw ←this, assumption,
intro i₀, cases x, have := h (fs i₀), rwa kth_projn at this,
intros g i₁, cases g with l r, cases i₁ with ifz ifs, have : kth_projn x fz = x.fst, cases x, refl, rw this, assumption,
cases x, rw kth_projn, exact r i₁_a,
end
lemma independence {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n, is_measurable {x : vec α n | ∀ i, P (kth_projn x i)}) :
(vec.prod_measure μ n : probability_measure (vec α n)) {x : vec α n | ∀ (i : dfin (n + 1)), P (kth_projn x i)} = μ {x : α | P x} ^ (n+1) :=
begin
induction n with k ih,
simp only [nat.pow_zero, nat_zero_eq_zero],
have g : {x : vec α 0 | ∀ i : dfin 1, P (kth_projn x i)} = {x | P x}, {
ext1, dsimp at *, fsplit, intros a, exact (a fz), intros a i, assumption,
},
rw g, simp, refl,
have h₂ : {x : vec α (succ k) | ∀ (i : dfin (succ k + 1)), P (kth_projn x i)} = set.prod {x | P x} {x : vec α k | ∀ (i : dfin (succ k)), P (kth_projn x i)},{
ext1, apply dfin_succ_prop_iff_fst_and_rst,
},
rw [h₂],
rw vec.prod_measure_eq, rw vec.prod_measure_apply _ _ hP (hp' k),rw ih,refl,
end
@[simp] lemma prob_independence {n : ℕ} [nonempty α] {P : α → Prop} (μ : probability_measure α) (hP : is_measurable {x : α | P x}) (hp' : ∀ n, is_measurable {x : vec α n | ∀ i, P (kth_projn x i)}) :
(vec.prob_measure n μ : probability_measure (vec α n)) {x : vec α n | ∀ (i : dfin (succ n)), P (kth_projn x i)} = (μ {x : α | P x}) ^ (n+1) :=
begin
induction n with k ih,
simp only [nat.pow_zero, nat_zero_eq_zero],
have g : {x : vec α 0 | ∀ i : dfin 1, P (kth_projn x i)} = {x | P x}, {
ext1, dsimp at *, fsplit, intros a, exact (a fz), intros a i, assumption,
},
rw g, rw vec.prob_measure, simp, refl,
have h₂ : {x : vec α (succ k) | ∀ (i : dfin (succ (succ k))), P (kth_projn x i)} = set.prod {x | P x} {x : vec α k | ∀ (i : dfin (succ k)), P (kth_projn x i)},{
ext1, apply dfin_succ_prop_iff_fst_and_rst,
},
rw h₂,
rw vec.prob_measure_apply _ _,
rw [vec.prod_measure_eq], rw vec.prod_measure_apply _ _ hP, rw pow_succ', rw ←ih, rw mul_comm, rw vec.prob_measure_apply, exact hp' k, exact hp' k, exact is_measurable_set_prod hP (hp' k),
end
noncomputable def point_indicators {f h: α → bool} {n : ℕ} (hf : measurable f) (hh : measurable h) (i : dfin (succ n)) := χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧
lemma integral_point_indicators {f h: α → bool} {n : ℕ} [ne : nonempty (vec α n)] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (μ : measure (vec α n)) :
∀ i : dfin (succ n),
(∫ χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧ ðμ) = μ ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}) := assume i, integral_char_fun μ (hA n i)
lemma finally {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) : let η := (vec.prod_measure μ n).to_measure in
∀ i, (∫ (χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧) ðη) = μ.to_measure {x : α | h x ≠ f x} :=
begin
intros η i₀,
rw [integral_point_indicators hf hh hA (vec.prod_measure μ n).to_measure i₀], rw ←coe_eq_to_measure, rw ←coe_eq_to_measure,
rw measure_kth_projn μ hB,
intro n₀, apply hA,
end
lemma integral_char_fun_finset_sum {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) (m : finset(dfin (succ n))):
(∫finset.sum m (λ (i : dfin (succ n)), ⇑χ⟦{x : vec α n | h (kth_projn x i) ≠ f (kth_projn x i)}⟧)ð((vec.prod_measure μ n).to_measure)) = m.sum (λ i, ((vec.prod_measure μ n)) ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) :=
begin
rw integral,
refine finset.induction_on m _ _,
{ simp, erw lintegral_zero },
{ assume a s has ih, simp [has], erw [lintegral_add],
erw simple_func.lintegral_eq_integral,unfold char_fun,
erw simple_func.restrict_const_integral, dsimp, rw ←ih, rw one_mul, rw coe_eq_to_measure, refl, exact(hA n a),
exact measurable.comp (simple_func.measurable _) measurable_id,
refine measurable.comp _ measurable_id,
refine finset.induction_on s _ _,
{simp, exact simple_func.measurable 0,},
{intros a b c d, simp [c], apply measure_theory.measurable_add, exact simple_func.measurable _, exact d,}
},
end
lemma integral_sum_dfin {f h : α → bool} {n : ℕ} [nonempty α] (hf : measurable f) (hh : measurable h) (hA : ∀ n i, is_measurable ({x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)})) (hB : is_measurable {x : α | h x ≠ f x}) (μ : probability_measure α) (m : finset(dfin (succ n))) : let η := (vec.prod_measure μ n) in
(∫ m.sum (λ i, χ ⟦{x : vec α n | h(kth_projn x i) ≠ f (kth_projn x i)}⟧) ðη.to_measure )= m.sum (λ i, (μ.to_measure : measure α) {x : α | h x ≠ f x}) :=
begin
intros η,
rw [integral_char_fun_finset_sum hf hh hA hB],
congr, funext, rw measure_kth_projn μ hB hA, rw coe_eq_to_measure,
end
lemma measure_sum_const {f h : α → bool} {n : ℕ} (hf : measurable f) (hh : measurable h) (m : finset (fin n)) (μ : probability_measure α) :
m.sum (λ i, (μ : measure α) {x : α | h x ≠ f x}) = (m.card : ℕ) * ((μ : measure α) {x : α | h x ≠ f x}) :=
begin
apply finset.induction_on m, simp,
intros a b c d,
simp [c], rw add_monoid.add_smul, rw [add_monoid.smul],
simp [monoid.pow], rw right_distrib, rw monoid.one_mul, rw ←d,
simp,
end
namespace hoeffding
open complex real
noncomputable def exp_fun (f : α → ennreal) : α → ℝ := λ x, exp $ (f x).to_real
local notation `∫` f `𝒹`m := integral m.to_measure f
lemma integral_char_rect [measurable_space α] [measurable_space β] [n₁ : nonempty α] [n₂ : nonempty β](μ : probability_measure α) (ν : probability_measure β) {A : set α} {B : set β} (hA : is_measurable A) (hB : is_measurable B) :
(∫ χ ⟦ A.prod B ⟧ 𝒹(μ ⊗ₚ ν)) = (μ A) * (ν B) :=
begin
haveI := (nonempty_prod.2 (and.intro n₁ n₂)),
rw [integral_char_fun _ (is_measurable_set_prod hA hB),←coe_eq_to_measure,
(prod.prob_measure_apply _ _ hA hB)], simp,
end
end hoeffding
|
e4d8df1b45637eb76a125745b8bb949608fcfc74 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/ring_theory/witt_vector/compare.lean | 8041ad4f5aecb1032b0980b2a0c03a2aa2cbda34 | [
"Apache-2.0"
] | permissive | leanprover-community/mathlib | 56a2cadd17ac88caf4ece0a775932fa26327ba0e | 442a83d738cb208d3600056c489be16900ba701d | refs/heads/master | 1,693,584,102,358 | 1,693,471,902,000 | 1,693,471,902,000 | 97,922,418 | 1,595 | 352 | Apache-2.0 | 1,694,693,445,000 | 1,500,624,130,000 | Lean | UTF-8 | Lean | false | false | 8,399 | lean | /-
Copyright (c) 2020 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Robert Y. Lewis
-/
import ring_theory.witt_vector.truncated
import ring_theory.witt_vector.identities
import number_theory.padics.ring_homs
/-!
# Comparison isomorphism between `witt_vector p (zmod p)` and `ℤ_[p]`
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We construct a ring isomorphism between `witt_vector p (zmod p)` and `ℤ_[p]`.
This isomorphism follows from the fact that both satisfy the universal property
of the inverse limit of `zmod (p^n)`.
## Main declarations
* `witt_vector.to_zmod_pow`: a family of compatible ring homs `𝕎 (zmod p) → zmod (p^k)`
* `witt_vector.equiv`: the isomorphism
## References
* [Hazewinkel, *Witt Vectors*][Haze09]
* [Commelin and Lewis, *Formalizing the Ring of Witt Vectors*][CL21]
-/
noncomputable theory
variables {p : ℕ} [hp : fact p.prime]
local notation `𝕎` := witt_vector p
include hp
namespace truncated_witt_vector
variables (p) (n : ℕ) (R : Type*) [comm_ring R]
lemma eq_of_le_of_cast_pow_eq_zero [char_p R p] (i : ℕ) (hin : i ≤ n)
(hpi : (p ^ i : truncated_witt_vector p n R) = 0) :
i = n :=
begin
contrapose! hpi,
replace hin := lt_of_le_of_ne hin hpi, clear hpi,
have : (↑p ^ i : truncated_witt_vector p n R) = witt_vector.truncate n (↑p ^ i),
{ rw [ring_hom.map_pow, map_nat_cast] },
rw [this, ext_iff, not_forall], clear this,
use ⟨i, hin⟩,
rw [witt_vector.coeff_truncate, coeff_zero, fin.coe_mk, witt_vector.coeff_p_pow],
haveI : nontrivial R := char_p.nontrivial_of_char_ne_one hp.1.ne_one,
exact one_ne_zero
end
section iso
variables (p n) {R}
lemma card_zmod : fintype.card (truncated_witt_vector p n (zmod p)) = p ^ n :=
by rw [card, zmod.card]
lemma char_p_zmod : char_p (truncated_witt_vector p n (zmod p)) (p ^ n) :=
char_p_of_prime_pow_injective _ _ _ (card_zmod _ _)
(eq_of_le_of_cast_pow_eq_zero p n (zmod p))
local attribute [instance] char_p_zmod
/--
The unique isomorphism between `zmod p^n` and `truncated_witt_vector p n (zmod p)`.
This isomorphism exists, because `truncated_witt_vector p n (zmod p)` is a finite ring
with characteristic and cardinality `p^n`.
-/
def zmod_equiv_trunc : zmod (p^n) ≃+* truncated_witt_vector p n (zmod p) :=
zmod.ring_equiv (truncated_witt_vector p n (zmod p)) (card_zmod _ _)
lemma zmod_equiv_trunc_apply {x : zmod (p^n)} :
zmod_equiv_trunc p n x = zmod.cast_hom (by refl) (truncated_witt_vector p n (zmod p)) x :=
rfl
/--
The following diagram commutes:
```text
zmod (p^n) ----------------------------> zmod (p^m)
| |
| |
v v
truncated_witt_vector p n (zmod p) ----> truncated_witt_vector p m (zmod p)
```
Here the vertical arrows are `truncated_witt_vector.zmod_equiv_trunc`,
the horizontal arrow at the top is `zmod.cast_hom`,
and the horizontal arrow at the bottom is `truncated_witt_vector.truncate`.
-/
lemma commutes {m : ℕ} (hm : n ≤ m) :
(truncate hm).comp (zmod_equiv_trunc p m).to_ring_hom =
(zmod_equiv_trunc p n).to_ring_hom.comp (zmod.cast_hom (pow_dvd_pow p hm) _) :=
ring_hom.ext_zmod _ _
lemma commutes' {m : ℕ} (hm : n ≤ m) (x : zmod (p^m)) :
truncate hm (zmod_equiv_trunc p m x) =
zmod_equiv_trunc p n (zmod.cast_hom (pow_dvd_pow p hm) _ x) :=
show (truncate hm).comp (zmod_equiv_trunc p m).to_ring_hom x = _,
by rw commutes _ _ hm; refl
lemma commutes_symm' {m : ℕ} (hm : n ≤ m) (x : truncated_witt_vector p m (zmod p)) :
(zmod_equiv_trunc p n).symm (truncate hm x) =
zmod.cast_hom (pow_dvd_pow p hm) _ ((zmod_equiv_trunc p m).symm x) :=
begin
apply (zmod_equiv_trunc p n).injective,
rw ← commutes',
simp
end
/--
The following diagram commutes:
```text
truncated_witt_vector p n (zmod p) ----> truncated_witt_vector p m (zmod p)
| |
| |
v v
zmod (p^n) ----------------------------> zmod (p^m)
```
Here the vertical arrows are `(truncated_witt_vector.zmod_equiv_trunc p _).symm`,
the horizontal arrow at the top is `zmod.cast_hom`,
and the horizontal arrow at the bottom is `truncated_witt_vector.truncate`.
-/
lemma commutes_symm {m : ℕ} (hm : n ≤ m) :
(zmod_equiv_trunc p n).symm.to_ring_hom.comp (truncate hm) =
(zmod.cast_hom (pow_dvd_pow p hm) _).comp (zmod_equiv_trunc p m).symm.to_ring_hom :=
by ext; apply commutes_symm'
end iso
end truncated_witt_vector
namespace witt_vector
open truncated_witt_vector
variables (p)
/--
`to_zmod_pow` is a family of compatible ring homs. We get this family by composing
`truncated_witt_vector.zmod_equiv_trunc` (in right-to-left direction)
with `witt_vector.truncate`.
-/
def to_zmod_pow (k : ℕ) : 𝕎 (zmod p) →+* zmod (p ^ k) :=
(zmod_equiv_trunc p k).symm.to_ring_hom.comp (truncate k)
lemma to_zmod_pow_compat (m n : ℕ) (h : m ≤ n) :
(zmod.cast_hom (pow_dvd_pow p h) (zmod (p ^ m))).comp (to_zmod_pow p n) = to_zmod_pow p m :=
calc (zmod.cast_hom _ (zmod (p ^ m))).comp
((zmod_equiv_trunc p n).symm.to_ring_hom.comp (truncate n)) =
((zmod_equiv_trunc p m).symm.to_ring_hom.comp
(truncated_witt_vector.truncate h)).comp (truncate n) :
by rw [commutes_symm, ring_hom.comp_assoc]
... = (zmod_equiv_trunc p m).symm.to_ring_hom.comp (truncate m) :
by rw [ring_hom.comp_assoc, truncate_comp_witt_vector_truncate]
/--
`to_padic_int` lifts `to_zmod_pow : 𝕎 (zmod p) →+* zmod (p ^ k)` to a ring hom to `ℤ_[p]`
using `padic_int.lift`, the universal property of `ℤ_[p]`.
-/
def to_padic_int : 𝕎 (zmod p) →+* ℤ_[p] := padic_int.lift $ to_zmod_pow_compat p
lemma zmod_equiv_trunc_compat (k₁ k₂ : ℕ) (hk : k₁ ≤ k₂) :
(truncated_witt_vector.truncate hk).comp
((zmod_equiv_trunc p k₂).to_ring_hom.comp
(padic_int.to_zmod_pow k₂)) =
(zmod_equiv_trunc p k₁).to_ring_hom.comp (padic_int.to_zmod_pow k₁) :=
by rw [← ring_hom.comp_assoc, commutes, ring_hom.comp_assoc, padic_int.zmod_cast_comp_to_zmod_pow]
/--
`from_padic_int` uses `witt_vector.lift` to lift `truncated_witt_vector.zmod_equiv_trunc`
composed with `padic_int.to_zmod_pow` to a ring hom `ℤ_[p] →+* 𝕎 (zmod p)`.
-/
def from_padic_int : ℤ_[p] →+* 𝕎 (zmod p) :=
witt_vector.lift (λ k, (zmod_equiv_trunc p k).to_ring_hom.comp (padic_int.to_zmod_pow k)) $
zmod_equiv_trunc_compat _
lemma to_padic_int_comp_from_padic_int :
(to_padic_int p).comp (from_padic_int p) = ring_hom.id ℤ_[p] :=
begin
rw ← padic_int.to_zmod_pow_eq_iff_ext,
intro n,
rw [← ring_hom.comp_assoc, to_padic_int, padic_int.lift_spec],
simp only [from_padic_int, to_zmod_pow, ring_hom.comp_id],
rw [ring_hom.comp_assoc, truncate_comp_lift, ← ring_hom.comp_assoc],
simp only [ring_equiv.symm_to_ring_hom_comp_to_ring_hom, ring_hom.id_comp]
end
lemma to_padic_int_comp_from_padic_int_ext (x) :
(to_padic_int p).comp (from_padic_int p) x = ring_hom.id ℤ_[p] x :=
by rw to_padic_int_comp_from_padic_int
lemma from_padic_int_comp_to_padic_int :
(from_padic_int p).comp (to_padic_int p) = ring_hom.id (𝕎 (zmod p)) :=
begin
apply witt_vector.hom_ext,
intro n,
rw [from_padic_int, ← ring_hom.comp_assoc, truncate_comp_lift, ring_hom.comp_assoc],
simp only [to_padic_int, to_zmod_pow, ring_hom.comp_id, padic_int.lift_spec, ring_hom.id_comp,
← ring_hom.comp_assoc, ring_equiv.to_ring_hom_comp_symm_to_ring_hom]
end
lemma from_padic_int_comp_to_padic_int_ext (x) :
(from_padic_int p).comp (to_padic_int p) x = ring_hom.id (𝕎 (zmod p)) x :=
by rw from_padic_int_comp_to_padic_int
/--
The ring of Witt vectors over `zmod p` is isomorphic to the ring of `p`-adic integers. This
equivalence is witnessed by `witt_vector.to_padic_int` with inverse `witt_vector.from_padic_int`.
-/
def equiv : 𝕎 (zmod p) ≃+* ℤ_[p] :=
{ to_fun := to_padic_int p,
inv_fun := from_padic_int p,
left_inv := from_padic_int_comp_to_padic_int_ext _,
right_inv := to_padic_int_comp_from_padic_int_ext _,
map_mul' := ring_hom.map_mul _,
map_add' := ring_hom.map_add _ }
end witt_vector
|
f9606a91833f138753908933851ef7818b554928 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/bigop.lean | a317ff915f0cf489d71c4dfde9b88de7bd2ec652 | [
"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 | 4,050 | lean | abbrev Sequence (α : Type) := List α
def bigop (init : β) (seq : Sequence α) (op : β → β → β) (f : α → Bool × β) : β := Id.run do
let mut result := init
for a in seq do
let (ok, b) := f a
if ok then
result := op result b
return result
#eval bigop 0 [1, 2, 4] Add.add fun elem => (elem % 2 == 0, elem * 2)
def iota : Nat → Nat → List Nat
| _, 0 => []
| m, n+1 => m :: iota (m+1) n
def index_iota (m n : Nat) := iota m (n - m)
class Enumerable (α : Type) where
elems : List α
instance : Enumerable Bool where
elems := [false, true]
instance {α β} [Enumerable α] [Enumerable β]: Enumerable (α × β) where
elems := Enumerable.elems.bind fun (a : α) => Enumerable.elems.bind fun (b : β) => [(a, b)]
def finElems (n : Nat) : List (Fin n) :=
match n with
| 0 => []
| n+1 => go (n+1) n (by simp_arith)
where
go (n : Nat) (i : Nat) (h : i < n) : List (Fin n) :=
match i with
| 0 => [⟨0, h⟩]
| i+1 => ⟨i+1, h⟩ :: go n i (Nat.lt_of_succ_lt h)
instance : Enumerable (Fin n) where
elems := (finElems n).reverse
instance : OfNat (Fin (Nat.succ n)) m :=
⟨Fin.ofNat m⟩
-- Declare a new syntax category for "indexing" big operators
declare_syntax_cat index
syntax term:51 "≤" ident "<" term : index
syntax term:51 "≤" ident "<" term "|" term : index
syntax ident "<-" term : index
syntax ident "<-" term "|" term : index
-- Primitive notation for big operators
syntax "_big" "[" term "," term "]" "(" index ")" term : term
-- We define how to expand `_big` with the different kinds of index
macro_rules
| `(_big [$op, $idx] ($i:ident <- $r | $p) $F) => `(bigop $idx $r $op (fun $i:ident => ($p, $F)))
| `(_big [$op, $idx] ($i:ident <- $r) $F) => `(bigop $idx $r $op (fun $i:ident => (true, $F)))
| `(_big [$op, $idx] ($lower:term ≤ $i:ident < $upper) $F) => `(bigop $idx (index_iota $lower $upper) $op (fun $i:ident => (true, $F)))
| `(_big [$op, $idx] ($lower:term ≤ $i:ident < $upper | $p) $F) => `(bigop $idx (index_iota $lower $upper) $op (fun $i:ident => ($p, $F)))
-- Define `∑ `
syntax "∑ " "(" index ")" term : term
macro_rules | `(∑ ($idx) $F) => `(_big [Add.add, 0] ($idx) $F)
-- We can already use `Sum` with the different kinds of index.
#check ∑ (i <- [0, 2, 4] | i != 2) i
#check ∑ (10 ≤ i < 20 | i != 5) i+1
#check ∑ (10 ≤ i < 20) i+1
-- Define `∏`
syntax "∏" "(" index ")" term : term
macro_rules | `(∏ ($idx) $F) => `(_big [Mul.mul, 1] ($idx) $F)
-- The examples above now also work for `Prod`
#check ∏ (i <- [0, 2, 4] | i != 2) i
#check ∏ (10 ≤ i < 20 | i != 5) i+1
#check ∏ (10 ≤ i < 20) i+1
-- We can extend our grammar for the syntax category `index`.
syntax ident "|" term : index
syntax ident ":" term : index
syntax ident ":" term "|" term : index
-- And new rules
macro_rules
| `(_big [$op, $idx] ($i:ident : $type) $F) => `(bigop $idx (Enumerable.elems (α := $type)) $op (fun $i:ident => (true, $F)))
| `(_big [$op, $idx] ($i:ident : $type | $p) $F) => `(bigop $idx (Enumerable.elems (α := $type)) $op (fun $i:ident => ($p, $F)))
| `(_big [$op, $idx] ($i:ident | $p) $F) => `(bigop $idx (Enumerable.elems) $op (fun $i:ident => ($p, $F)))
-- The new syntax is immediately available for all big operators that we have defined
def myPred (x : Fin 10) : Bool := true
#check ∑ (i : Fin 10) i+1
#check ∑ (i : Fin 10 | i != 2) i+1
#check ∑ (i | myPred i) i+i
#check ∏ (i : Fin 10) i+1
#check ∏ (i : Fin 10 | i != 2) i+1
#check ∏ (i | myPred i) i+i
-- We can easily create alternative syntax for any big operator.
syntax "Summation" index "=>" term : term
macro_rules | `(Summation $idx => $F) => `(∑ ($idx) $F)
#check Summation 10 ≤ i < 20 => i+1
-- Now, we create command for automating the generation of big operators.
syntax "def_bigop" str term:max term:max : command
macro_rules
| `(def_bigop $head:str $op $unit) =>
`(macro $head:str "(" idx:index ")" F:term : term => `(_big [$op, $unit] ($$idx) $$F))
def_bigop "SUM" Nat.add 0
#check SUM (i <- [0, 1, 2]) i+1
|
f7028865994ecb6ac57b63c8811a0311daa60a95 | 097294e9b80f0d9893ac160b9c7219aa135b51b9 | /instructor/propositional_logic/satisfiability/exam2.lean | 133148e804d23d130688dd963744d4a2f44378c8 | [] | 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 | 3,466 | lean | import .satisfiability
import .rules_of_reasoning
/-
CS2102 Exam #2: Propositional Logic
-/
/-
#1. Define a predicate function, is_satisfiable: pExp → bool
that returns true iff the given proposition is satisfiable.
Hint: Model your answer on our definition of is_valid. You
may need to define one or more helper functions. You should
test your solution, but we will only grade your definition.
Please write test cases in a separate file. Do not submit
that file.
-/
-- Answer here
/-
#2. Clearly the propositions in rules_of_reasoning.lean that
are valid are also satisfiable. But what about the following?
Apply your satisfiability predicate function to decide whether
or not each of the following formulae is satisfiable or not.
Write an "#eval is_satisfiable e" command for each expression.
A. The "fallacies" in that file (the ones that aren't valid).
B. The proposition, pFalse.
C. The following propositions:
1. P ∧ ¬ P
2. P ∨ ¬ P
3. = (¬x1 ∨ x2) ∧ (¬x2 ∨ x3 ∨ ¬x4) ∧ (x1 ∨ x2 ∨ x3 ∨ ¬x4)
Note that for 3. you will have to define four new variables.
Call them x1, x2, x3, and x4.
-/
-- Answers here
/-
3. In the previous problems, you defined a satisfiability
predicate function that returns true or false depending on
whether a given formula is satisfiable or not. Often we will
want to know not only whether there exists a solution but an
actual example of a solution, if there is one. Define a function
called sat_solver : pExp → option (var → bool) that returns a
satisfying interpretation (as "some interpretation") if there
is one, or "none" otherwise. Hint: Model your solution on our
validity checker. First compute the list of interpretations for
a given expression, e, then reduce that list to a value of type
option (var → bool). Evaluate e under each interpretation in
the list until either (A) you find one, call it i, for which e
evaluates to true, or until you reach the empty list, empty
handed.
-/
-- Answer here
/-
4. Define a predicate function, is_unsatisfiable : pExp → bool,
that takes a propositional logic formula, e, and returns true
iff e is unsatisfiable. Hint: Easy. Build on what you have.
-/
-- Answer here
/-
5. Given a propositional logic expression, e, and an incorrect
claim that it's valid, we often want to produce a counter-example
to that claim. Such a counter example is an interpretation under
which the expression is not true. Equivalently, a counterexample
is an interpretation under which the *negation* of the expression
*is* true.
Define a function, counterexample : pExp → option (var → bool),
that takes any expression e and returns either a counterexample
(as "some interpretation") or "none" if there isn't one. Hint:
given e, try to find a model for the expression, ¬ e.
-/
-- Answer here
/-
6. Give an English language example for every valid rule of
reasoning in rules_of_reasoning.lean, and also give an English
language counter-example for each fallacy.
For example, for the rule, P >> Q >> P ∧ Q, you could say,
"If the ball is red then if (in addition to that) the box
is blue, then (in this context) the ball is red AND the box
is blue." It will be easiest is you re-use the same words
for P, Q, and R, in all of your examples. E.g., P means "the
ball is red", Q means "the box is blue", etc.
Copy the contents of rules_of_reasoning.lean into this comment
block and under each rule give your English language sentence.
-/ |
7412866eab6baa8204ef8e34b139cca8d14c9a16 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/data/sigma/lex.lean | 70437dd8a05fbf98a013152f67c7a4fa8f476159 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 6,823 | lean | /-
Copyright (c) 2021 Yaël Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies
-/
import data.sigma.basic
import order.rel_classes
/-!
# Lexicographic order on a sigma type
This defines the lexicographical order of two arbitrary relations on a sigma type and proves some
lemmas about `psigma.lex`, which is defined in core Lean.
Given a relation in the index type and a relation on each summand, the lexicographical order on the
sigma type relates `a` and `b` if their summands are related or they are in the same summand and
related by the summand's relation.
## See also
Related files are:
* `data.finset.colex`: Colexicographic order on finite sets.
* `data.list.lex`: Lexicographic order on lists.
* `data.sigma.order`: Lexicographic order on `Σ i, α i` per say.
* `data.psigma.order`: Lexicographic order on `Σ' i, α i`.
* `data.prod.lex`: Lexicographic order on `α × β`. Can be thought of as the special case of
`sigma.lex` where all summands are the same
-/
namespace sigma
variables {ι : Type*} {α : ι → Type*} {r r₁ r₂ : ι → ι → Prop} {s s₁ s₂ : Π i, α i → α i → Prop}
{a b : Σ i, α i}
/-- The lexicographical order on a sigma type. It takes in a relation on the index type and a
relation for each summand. `a` is related to `b` iff their summands are related or they are in the
same summand and are related through the summand's relation. -/
inductive lex (r : ι → ι → Prop) (s : Π i, α i → α i → Prop) : Π a b : Σ i, α i, Prop
| left {i j : ι} (a : α i) (b : α j) : r i j → lex ⟨i, a⟩ ⟨j, b⟩
| right {i : ι} (a b : α i) : s i a b → lex ⟨i, a⟩ ⟨i, b⟩
lemma lex_iff : lex r s a b ↔ r a.1 b.1 ∨ ∃ h : a.1 = b.1, s _ (h.rec a.2) b.2 :=
begin
split,
{ rintro (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩),
{ exact or.inl hij },
{ exact or.inr ⟨rfl, hab⟩ } },
{ obtain ⟨i, a⟩ := a,
obtain ⟨j, b⟩ := b,
dsimp only,
rintro (h | ⟨rfl, h⟩),
{ exact lex.left _ _ h },
{ exact lex.right _ _ h } }
end
instance lex.decidable (r : ι → ι → Prop) (s : Π i, α i → α i → Prop) [decidable_eq ι]
[decidable_rel r] [Π i, decidable_rel (s i)] :
decidable_rel (lex r s) :=
λ a b, decidable_of_decidable_of_iff infer_instance lex_iff.symm
lemma lex.mono (hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ i, α i}
(h : lex r₁ s₁ a b) :
lex r₂ s₂ a b :=
begin
obtain (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩) := h,
{ exact lex.left _ _ (hr _ _ hij) },
{ exact lex.right _ _ (hs _ _ _ hab) }
end
lemma lex.mono_left (hr : ∀ a b, r₁ a b → r₂ a b) {a b : Σ i, α i} (h : lex r₁ s a b) :
lex r₂ s a b :=
h.mono hr $ λ _ _ _, id
lemma lex.mono_right (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ i, α i} (h : lex r s₁ a b) :
lex r s₂ a b :=
h.mono (λ _ _, id) hs
instance [Π i, is_refl (α i) (s i)] : is_refl _ (lex r s) := ⟨λ ⟨i, a⟩, lex.right _ _ $ refl _⟩
instance [is_irrefl ι r] [Π i, is_irrefl (α i) (s i)] : is_irrefl _ (lex r s) :=
⟨begin
rintro _ (⟨i, j, a, b, hi⟩ | ⟨i, a, b, ha⟩),
{ exact irrefl _ hi },
{ exact irrefl _ ha }
end⟩
instance [is_trans ι r] [Π i, is_trans (α i) (s i)] : is_trans _ (lex r s) :=
⟨begin
rintro _ _ _ (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩) (⟨_, k, _, c, hk⟩ | ⟨_, _, c, hc⟩),
{ exact lex.left _ _ (trans hij hk) },
{ exact lex.left _ _ hij },
{ exact lex.left _ _ hk },
{ exact lex.right _ _ (trans hab hc) }
end⟩
instance [is_symm ι r] [Π i, is_symm (α i) (s i)] : is_symm _ (lex r s) :=
⟨begin
rintro _ _ (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩),
{ exact lex.left _ _ (symm hij) },
{ exact lex.right _ _ (symm hab) }
end⟩
local attribute [instance] is_asymm.is_irrefl
instance [is_asymm ι r] [Π i, is_antisymm (α i) (s i)] : is_antisymm _ (lex r s) :=
⟨begin
rintro _ _ (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩) (⟨_, _, _, _, hji⟩ | ⟨_, _, _, hba⟩),
{ exact (asymm hij hji).elim },
{ exact (irrefl _ hij).elim },
{ exact (irrefl _ hji).elim },
{ exact ext rfl (heq_of_eq $ antisymm hab hba) }
end⟩
instance [is_trichotomous ι r] [Π i, is_total (α i) (s i)] : is_total _ (lex r s) :=
⟨begin
rintro ⟨i, a⟩ ⟨j, b⟩,
obtain hij | rfl | hji := trichotomous_of r i j,
{ exact or.inl (lex.left _ _ hij) },
{ obtain hab | hba := total_of (s i) a b,
{ exact or.inl (lex.right _ _ hab) },
{ exact or.inr (lex.right _ _ hba) } },
{ exact or.inr (lex.left _ _ hji) }
end⟩
instance [is_trichotomous ι r] [Π i, is_trichotomous (α i) (s i)] : is_trichotomous _ (lex r s) :=
⟨begin
rintro ⟨i, a⟩ ⟨j, b⟩,
obtain hij | rfl | hji := trichotomous_of r i j,
{ exact or.inl (lex.left _ _ hij) },
{ obtain hab | rfl | hba := trichotomous_of (s i) a b,
{ exact or.inl (lex.right _ _ hab) },
{ exact or.inr (or.inl rfl) },
{ exact or.inr (or.inr $ lex.right _ _ hba) } },
{ exact or.inr (or.inr $ lex.left _ _ hji) }
end⟩
end sigma
/-! ### `psigma` -/
namespace psigma
variables {ι : Sort*} {α : ι → Sort*} {r r₁ r₂ : ι → ι → Prop} {s s₁ s₂ : Π i, α i → α i → Prop}
lemma lex_iff {a b : Σ' i, α i} : lex r s a b ↔ r a.1 b.1 ∨ ∃ h : a.1 = b.1, s _ (h.rec a.2) b.2 :=
begin
split,
{ rintro (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩),
{ exact or.inl hij },
{ exact or.inr ⟨rfl, hab⟩ } },
{ obtain ⟨i, a⟩ := a,
obtain ⟨j, b⟩ := b,
dsimp only,
rintro (h | ⟨rfl, h⟩),
{ exact lex.left _ _ h },
{ exact lex.right _ h } }
end
instance lex.decidable (r : ι → ι → Prop) (s : Π i, α i → α i → Prop) [decidable_eq ι]
[decidable_rel r] [Π i, decidable_rel (s i)] :
decidable_rel (lex r s) :=
λ a b, decidable_of_decidable_of_iff infer_instance lex_iff.symm
lemma lex.mono {r₁ r₂ : ι → ι → Prop} {s₁ s₂ : Π i, α i → α i → Prop}
(hr : ∀ a b, r₁ a b → r₂ a b) (hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ' i, α i}
(h : lex r₁ s₁ a b) :
lex r₂ s₂ a b :=
begin
obtain (⟨i, j, a, b, hij⟩ | ⟨i, a, b, hab⟩) := h,
{ exact lex.left _ _ (hr _ _ hij) },
{ exact lex.right _ (hs _ _ _ hab) }
end
lemma lex.mono_left {r₁ r₂ : ι → ι → Prop} {s : Π i, α i → α i → Prop}
(hr : ∀ a b, r₁ a b → r₂ a b) {a b : Σ' i, α i} (h : lex r₁ s a b) :
lex r₂ s a b :=
h.mono hr $ λ _ _ _, id
lemma lex.mono_right {r : ι → ι → Prop} {s₁ s₂ : Π i, α i → α i → Prop}
(hs : ∀ i a b, s₁ i a b → s₂ i a b) {a b : Σ' i, α i} (h : lex r s₁ a b) :
lex r s₂ a b :=
h.mono (λ _ _, id) hs
end psigma
|
6e0db1aaa774e4e1aa6a1ca43ca8b94b3b2b47a0 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/lie/matrix.lean | eb02bbf72b6b9efc6161940bc036ed74543f8ff4 | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 3,353 | lean | /-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import algebra.lie.of_associative
import linear_algebra.matrix.reindex
import linear_algebra.matrix.to_linear_equiv
/-!
# Lie algebras of matrices
An important class of Lie algebras are those arising from the associative algebra structure on
square matrices over a commutative ring. This file provides some very basic definitions whose
primary value stems from their utility when constructing the classical Lie algebras using matrices.
## Main definitions
* `lie_equiv_matrix'`
* `matrix.lie_conj`
* `matrix.reindex_lie_equiv`
## Tags
lie algebra, matrix
-/
universes u v w w₁ w₂
section matrices
open_locale matrix
variables {R : Type u} [comm_ring R]
variables {n : Type w} [decidable_eq n] [fintype n]
/-- The natural equivalence between linear endomorphisms of finite free modules and square matrices
is compatible with the Lie algebra structures. -/
def lie_equiv_matrix' : module.End R (n → R) ≃ₗ⁅R⁆ matrix n n R :=
{ map_lie' := λ T S,
begin
let f := @linear_map.to_matrix' R _ n n _ _,
change f (T.comp S - S.comp T) = (f T) * (f S) - (f S) * (f T),
have h : ∀ (T S : module.End R _), f (T.comp S) = (f T) ⬝ (f S) := linear_map.to_matrix'_comp,
rw [linear_equiv.map_sub, h, h, matrix.mul_eq_mul, matrix.mul_eq_mul],
end,
..linear_map.to_matrix' }
@[simp] lemma lie_equiv_matrix'_apply (f : module.End R (n → R)) :
lie_equiv_matrix' f = f.to_matrix' := rfl
@[simp] lemma lie_equiv_matrix'_symm_apply (A : matrix n n R) :
(@lie_equiv_matrix' R _ n _ _).symm A = A.to_lin' := rfl
/-- An invertible matrix induces a Lie algebra equivalence from the space of matrices to itself. -/
def matrix.lie_conj (P : matrix n n R) (h : invertible P) :
matrix n n R ≃ₗ⁅R⁆ matrix n n R :=
((@lie_equiv_matrix' R _ n _ _).symm.trans (P.to_linear_equiv' h).lie_conj).trans lie_equiv_matrix'
@[simp] lemma matrix.lie_conj_apply (P A : matrix n n R) (h : invertible P) :
P.lie_conj h A = P ⬝ A ⬝ P⁻¹ :=
by simp [linear_equiv.conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
@[simp] lemma matrix.lie_conj_symm_apply (P A : matrix n n R) (h : invertible P) :
(P.lie_conj h).symm A = P⁻¹ ⬝ A ⬝ P :=
by simp [linear_equiv.symm_conj_apply, matrix.lie_conj, linear_map.to_matrix'_comp,
linear_map.to_matrix'_to_lin']
variables {m : Type w₁} [decidable_eq m] [fintype m] (e : n ≃ m)
/-- For square matrices, the natural map that reindexes a matrix's rows and columns with equivalent
types, `matrix.reindex`, is an equivalence of Lie algebras. -/
def matrix.reindex_lie_equiv : matrix n n R ≃ₗ⁅R⁆ matrix m m R :=
{ to_fun := matrix.reindex e e,
map_lie' := λ M N, by simp only [lie_ring.of_associative_ring_bracket, matrix.reindex_apply,
matrix.submatrix_mul_equiv, matrix.mul_eq_mul, matrix.submatrix_sub, pi.sub_apply],
..(matrix.reindex_linear_equiv R R e e) }
@[simp] lemma matrix.reindex_lie_equiv_apply (M : matrix n n R) :
matrix.reindex_lie_equiv e M = matrix.reindex e e M := rfl
@[simp] lemma matrix.reindex_lie_equiv_symm :
(matrix.reindex_lie_equiv e : _ ≃ₗ⁅R⁆ _).symm = matrix.reindex_lie_equiv e.symm := rfl
end matrices
|
1dbb52f050ddc219c2f9344b706553478cb93d3d | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/order/monotone.lean | 7f1a05ce9834f9c53eb377fadadb526fa572b6d7 | [
"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 | 38,217 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro, Yaël Dillies
-/
import order.compare
import order.max
import order.rel_classes
/-!
# Monotonicity
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/591
> Any changes to this file require a corresponding PR to mathlib4.
This file defines (strictly) monotone/antitone functions. Contrary to standard mathematical usage,
"monotone"/"mono" here means "increasing", not "increasing or decreasing". We use "antitone"/"anti"
to mean "decreasing".
## Definitions
* `monotone f`: A function `f` between two preorders is monotone if `a ≤ b` implies `f a ≤ f b`.
* `antitone f`: A function `f` between two preorders is antitone if `a ≤ b` implies `f b ≤ f a`.
* `monotone_on f s`: Same as `monotone f`, but for all `a, b ∈ s`.
* `antitone_on f s`: Same as `antitone f`, but for all `a, b ∈ s`.
* `strict_mono f` : A function `f` between two preorders is strictly monotone if `a < b` implies
`f a < f b`.
* `strict_anti f` : A function `f` between two preorders is strictly antitone if `a < b` implies
`f b < f a`.
* `strict_mono_on f s`: Same as `strict_mono f`, but for all `a, b ∈ s`.
* `strict_anti_on f s`: Same as `strict_anti f`, but for all `a, b ∈ s`.
## Main theorems
* `monotone_nat_of_le_succ`, `monotone_int_of_le_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n ≤ f (n + 1)` for all `n`, then `f` is monotone.
* `antitone_nat_of_succ_le`, `antitone_int_of_succ_le`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) ≤ f n` for all `n`, then `f` is antitone.
* `strict_mono_nat_of_lt_succ`, `strict_mono_int_of_lt_succ`: If `f : ℕ → α` or `f : ℤ → α` and
`f n < f (n + 1)` for all `n`, then `f` is strictly monotone.
* `strict_anti_nat_of_succ_lt`, `strict_anti_int_of_succ_lt`: If `f : ℕ → α` or `f : ℤ → α` and
`f (n + 1) < f n` for all `n`, then `f` is strictly antitone.
## Implementation notes
Some of these definitions used to only require `has_le α` or `has_lt α`. The advantage of this is
unclear and it led to slight elaboration issues. Now, everything requires `preorder α` and seems to
work fine. Related Zulip discussion:
https://leanprover.zulipchat.com/#narrow/stream/113488-general/topic/Order.20diamond/near/254353352.
## TODO
The above theorems are also true in `ℕ+`, `fin n`... To make that work, we need `succ_order α`
and `succ_archimedean α`.
## Tags
monotone, strictly monotone, antitone, strictly antitone, increasing, strictly increasing,
decreasing, strictly decreasing
-/
open function order_dual
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w} {δ : Type*} {r : α → α → Prop}
section monotone_def
variables [preorder α] [preorder β]
/-- A function `f` is monotone if `a ≤ b` implies `f a ≤ f b`. -/
def monotone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f a ≤ f b
/-- A function `f` is antitone if `a ≤ b` implies `f b ≤ f a`. -/
def antitone (f : α → β) : Prop := ∀ ⦃a b⦄, a ≤ b → f b ≤ f a
/-- A function `f` is monotone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f a ≤ f b`. -/
def monotone_on (f : α → β) (s : set α) : Prop :=
∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a ≤ b → f a ≤ f b
/-- A function `f` is antitone on `s` if, for all `a, b ∈ s`, `a ≤ b` implies `f b ≤ f a`. -/
def antitone_on (f : α → β) (s : set α) : Prop :=
∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a ≤ b → f b ≤ f a
/-- A function `f` is strictly monotone if `a < b` implies `f a < f b`. -/
def strict_mono (f : α → β) : Prop :=
∀ ⦃a b⦄, a < b → f a < f b
/-- A function `f` is strictly antitone if `a < b` implies `f b < f a`. -/
def strict_anti (f : α → β) : Prop :=
∀ ⦃a b⦄, a < b → f b < f a
/-- A function `f` is strictly monotone on `s` if, for all `a, b ∈ s`, `a < b` implies
`f a < f b`. -/
def strict_mono_on (f : α → β) (s : set α) : Prop :=
∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a < b → f a < f b
/-- A function `f` is strictly antitone on `s` if, for all `a, b ∈ s`, `a < b` implies
`f b < f a`. -/
def strict_anti_on (f : α → β) (s : set α) : Prop :=
∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a < b → f b < f a
end monotone_def
/-! ### Monotonicity on the dual order
Strictly, many of the `*_on.dual` lemmas in this section should use `of_dual ⁻¹' s` instead of `s`,
but right now this is not possible as `set.preimage` is not defined yet, and importing it creates
an import cycle.
Often, you should not need the rewriting lemmas. Instead, you probably want to add `.dual`,
`.dual_left` or `.dual_right` to your `monotone`/`antitone` hypothesis.
-/
section order_dual
variables [preorder α] [preorder β] {f : α → β} {s : set α}
@[simp] lemma monotone_comp_of_dual_iff : monotone (f ∘ of_dual) ↔ antitone f := forall_swap
@[simp] lemma antitone_comp_of_dual_iff : antitone (f ∘ of_dual) ↔ monotone f := forall_swap
@[simp] lemma monotone_to_dual_comp_iff : monotone (to_dual ∘ f) ↔ antitone f := iff.rfl
@[simp] lemma antitone_to_dual_comp_iff : antitone (to_dual ∘ f) ↔ monotone f := iff.rfl
@[simp] lemma monotone_on_comp_of_dual_iff : monotone_on (f ∘ of_dual) s ↔ antitone_on f s :=
forall₂_swap
@[simp] lemma antitone_on_comp_of_dual_iff : antitone_on (f ∘ of_dual) s ↔ monotone_on f s :=
forall₂_swap
@[simp] lemma monotone_on_to_dual_comp_iff : monotone_on (to_dual ∘ f) s ↔ antitone_on f s :=
iff.rfl
@[simp] lemma antitone_on_to_dual_comp_iff : antitone_on (to_dual ∘ f) s ↔ monotone_on f s :=
iff.rfl
@[simp] lemma strict_mono_comp_of_dual_iff : strict_mono (f ∘ of_dual) ↔ strict_anti f :=
forall_swap
@[simp] lemma strict_anti_comp_of_dual_iff : strict_anti (f ∘ of_dual) ↔ strict_mono f :=
forall_swap
@[simp] lemma strict_mono_to_dual_comp_iff : strict_mono (to_dual ∘ f) ↔ strict_anti f := iff.rfl
@[simp] lemma strict_anti_to_dual_comp_iff : strict_anti (to_dual ∘ f) ↔ strict_mono f := iff.rfl
@[simp] lemma strict_mono_on_comp_of_dual_iff :
strict_mono_on (f ∘ of_dual) s ↔ strict_anti_on f s := forall₂_swap
@[simp] lemma strict_anti_on_comp_of_dual_iff :
strict_anti_on (f ∘ of_dual) s ↔ strict_mono_on f s := forall₂_swap
@[simp] lemma strict_mono_on_to_dual_comp_iff :
strict_mono_on (to_dual ∘ f) s ↔ strict_anti_on f s := iff.rfl
@[simp] lemma strict_anti_on_to_dual_comp_iff :
strict_anti_on (to_dual ∘ f) s ↔ strict_mono_on f s := iff.rfl
protected lemma monotone.dual (hf : monotone f) : monotone (to_dual ∘ f ∘ of_dual) := swap hf
protected lemma antitone.dual (hf : antitone f) : antitone (to_dual ∘ f ∘ of_dual) := swap hf
protected lemma monotone_on.dual (hf : monotone_on f s) : monotone_on (to_dual ∘ f ∘ of_dual) s :=
swap₂ hf
protected lemma antitone_on.dual (hf : antitone_on f s) : antitone_on (to_dual ∘ f ∘ of_dual) s :=
swap₂ hf
protected lemma strict_mono.dual (hf : strict_mono f) : strict_mono (to_dual ∘ f ∘ of_dual) :=
swap hf
protected lemma strict_anti.dual (hf : strict_anti f) : strict_anti (to_dual ∘ f ∘ of_dual) :=
swap hf
protected lemma strict_mono_on.dual (hf : strict_mono_on f s) :
strict_mono_on (to_dual ∘ f ∘ of_dual) s := swap₂ hf
protected lemma strict_anti_on.dual (hf : strict_anti_on f s) :
strict_anti_on (to_dual ∘ f ∘ of_dual) s := swap₂ hf
alias antitone_comp_of_dual_iff ↔ _ monotone.dual_left
alias monotone_comp_of_dual_iff ↔ _ antitone.dual_left
alias antitone_to_dual_comp_iff ↔ _ monotone.dual_right
alias monotone_to_dual_comp_iff ↔ _ antitone.dual_right
alias antitone_on_comp_of_dual_iff ↔ _ monotone_on.dual_left
alias monotone_on_comp_of_dual_iff ↔ _ antitone_on.dual_left
alias antitone_on_to_dual_comp_iff ↔ _ monotone_on.dual_right
alias monotone_on_to_dual_comp_iff ↔ _ antitone_on.dual_right
alias strict_anti_comp_of_dual_iff ↔ _ strict_mono.dual_left
alias strict_mono_comp_of_dual_iff ↔ _ strict_anti.dual_left
alias strict_anti_to_dual_comp_iff ↔ _ strict_mono.dual_right
alias strict_mono_to_dual_comp_iff ↔ _ strict_anti.dual_right
alias strict_anti_on_comp_of_dual_iff ↔ _ strict_mono_on.dual_left
alias strict_mono_on_comp_of_dual_iff ↔ _ strict_anti_on.dual_left
alias strict_anti_on_to_dual_comp_iff ↔ _ strict_mono_on.dual_right
alias strict_mono_on_to_dual_comp_iff ↔ _ strict_anti_on.dual_right
end order_dual
/-! ### Monotonicity in function spaces -/
section preorder
variables [preorder α]
theorem monotone.comp_le_comp_left [preorder β]
{f : β → α} {g h : γ → β} (hf : monotone f) (le_gh : g ≤ h) :
has_le.le.{max w u} (f ∘ g) (f ∘ h) :=
λ x, hf (le_gh x)
variables [preorder γ]
theorem monotone_lam {f : α → β → γ} (hf : ∀ b, monotone (λ a, f a b)) : monotone f :=
λ a a' h b, hf b h
theorem monotone_app (f : β → α → γ) (b : β) (hf : monotone (λ a b, f b a)) : monotone (f b) :=
λ a a' h, hf h b
theorem antitone_lam {f : α → β → γ} (hf : ∀ b, antitone (λ a, f a b)) : antitone f :=
λ a a' h b, hf b h
theorem antitone_app (f : β → α → γ) (b : β) (hf : antitone (λ a b, f b a)) : antitone (f b) :=
λ a a' h, hf h b
end preorder
lemma function.monotone_eval {ι : Type u} {α : ι → Type v} [∀ i, preorder (α i)] (i : ι) :
monotone (function.eval i : (Π i, α i) → α i) :=
λ f g H, H i
/-! ### Monotonicity hierarchy -/
section preorder
variables [preorder α]
section preorder
variables [preorder β] {f : α → β} {s : set α} {a b : α}
/-!
These four lemmas are there to strip off the semi-implicit arguments `⦃a b : α⦄`. This is useful
when you do not want to apply a `monotone` assumption (i.e. your goal is `a ≤ b → f a ≤ f b`).
However if you find yourself writing `hf.imp h`, then you should have written `hf h` instead.
-/
lemma monotone.imp (hf : monotone f) (h : a ≤ b) : f a ≤ f b := hf h
lemma antitone.imp (hf : antitone f) (h : a ≤ b) : f b ≤ f a := hf h
lemma strict_mono.imp (hf : strict_mono f) (h : a < b) : f a < f b := hf h
lemma strict_anti.imp (hf : strict_anti f) (h : a < b) : f b < f a := hf h
protected lemma monotone.monotone_on (hf : monotone f) (s : set α) : monotone_on f s :=
λ a _ b _, hf.imp
protected lemma antitone.antitone_on (hf : antitone f) (s : set α) : antitone_on f s :=
λ a _ b _, hf.imp
@[simp] lemma monotone_on_univ : monotone_on f set.univ ↔ monotone f :=
⟨λ h a b, h trivial trivial, λ h, h.monotone_on _⟩
@[simp] lemma antitone_on_univ : antitone_on f set.univ ↔ antitone f :=
⟨λ h a b, h trivial trivial, λ h, h.antitone_on _⟩
protected lemma strict_mono.strict_mono_on (hf : strict_mono f) (s : set α) : strict_mono_on f s :=
λ a _ b _, hf.imp
protected lemma strict_anti.strict_anti_on (hf : strict_anti f) (s : set α) : strict_anti_on f s :=
λ a _ b _, hf.imp
@[simp] lemma strict_mono_on_univ : strict_mono_on f set.univ ↔ strict_mono f :=
⟨λ h a b, h trivial trivial, λ h, h.strict_mono_on _⟩
@[simp] lemma strict_anti_on_univ : strict_anti_on f set.univ ↔ strict_anti f :=
⟨λ h a b, h trivial trivial, λ h, h.strict_anti_on _⟩
end preorder
section partial_order
variables [partial_order β] {f : α → β}
lemma monotone.strict_mono_of_injective (h₁ : monotone f) (h₂ : injective f) : strict_mono f :=
λ a b h, (h₁ h.le).lt_of_ne (λ H, h.ne $ h₂ H)
lemma antitone.strict_anti_of_injective (h₁ : antitone f) (h₂ : injective f) : strict_anti f :=
λ a b h, (h₁ h.le).lt_of_ne (λ H, h.ne $ h₂ H.symm)
end partial_order
end preorder
section partial_order
variables [partial_order α] [preorder β] {f : α → β} {s : set α}
lemma monotone_iff_forall_lt : monotone f ↔ ∀ ⦃a b⦄, a < b → f a ≤ f b :=
forall₂_congr $ λ a b, ⟨λ hf h, hf h.le, λ hf h, h.eq_or_lt.elim (λ H, (congr_arg _ H).le) hf⟩
lemma antitone_iff_forall_lt : antitone f ↔ ∀ ⦃a b⦄, a < b → f b ≤ f a :=
forall₂_congr $ λ a b, ⟨λ hf h, hf h.le, λ hf h, h.eq_or_lt.elim (λ H, (congr_arg _ H).ge) hf⟩
lemma monotone_on_iff_forall_lt :
monotone_on f s ↔ ∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a < b → f a ≤ f b :=
⟨λ hf a ha b hb h, hf ha hb h.le,
λ hf a ha b hb h, h.eq_or_lt.elim (λ H, (congr_arg _ H).le) (hf ha hb)⟩
lemma antitone_on_iff_forall_lt :
antitone_on f s ↔ ∀ ⦃a⦄ (ha : a ∈ s) ⦃b⦄ (hb : b ∈ s), a < b → f b ≤ f a :=
⟨λ hf a ha b hb h, hf ha hb h.le,
λ hf a ha b hb h, h.eq_or_lt.elim (λ H, (congr_arg _ H).ge) (hf ha hb)⟩
-- `preorder α` isn't strong enough: if the preorder on `α` is an equivalence relation,
-- then `strict_mono f` is vacuously true.
protected lemma strict_mono_on.monotone_on (hf : strict_mono_on f s) : monotone_on f s :=
monotone_on_iff_forall_lt.2 $ λ a ha b hb h, (hf ha hb h).le
protected lemma strict_anti_on.antitone_on (hf : strict_anti_on f s) : antitone_on f s :=
antitone_on_iff_forall_lt.2 $ λ a ha b hb h, (hf ha hb h).le
protected lemma strict_mono.monotone (hf : strict_mono f) : monotone f :=
monotone_iff_forall_lt.2 $ λ a b h, (hf h).le
protected lemma strict_anti.antitone (hf : strict_anti f) : antitone f :=
antitone_iff_forall_lt.2 $ λ a b h, (hf h).le
end partial_order
/-! ### Monotonicity from and to subsingletons -/
namespace subsingleton
variables [preorder α] [preorder β]
protected lemma monotone [subsingleton α] (f : α → β) : monotone f :=
λ a b _, (congr_arg _ $ subsingleton.elim _ _).le
protected lemma antitone [subsingleton α] (f : α → β) : antitone f :=
λ a b _, (congr_arg _ $ subsingleton.elim _ _).le
lemma monotone' [subsingleton β] (f : α → β) : monotone f := λ a b _, (subsingleton.elim _ _).le
lemma antitone' [subsingleton β] (f : α → β) : antitone f := λ a b _, (subsingleton.elim _ _).le
protected lemma strict_mono [subsingleton α] (f : α → β) : strict_mono f :=
λ a b h, (h.ne $ subsingleton.elim _ _).elim
protected lemma strict_anti [subsingleton α] (f : α → β) : strict_anti f :=
λ a b h, (h.ne $ subsingleton.elim _ _).elim
end subsingleton
/-! ### Miscellaneous monotonicity results -/
lemma monotone_id [preorder α] : monotone (id : α → α) := λ a b, id
lemma monotone_on_id [preorder α] {s : set α} : monotone_on id s := λ a ha b hb, id
lemma strict_mono_id [preorder α] : strict_mono (id : α → α) := λ a b, id
lemma strict_mono_on_id [preorder α] {s : set α} : strict_mono_on id s := λ a ha b hb, id
theorem monotone_const [preorder α] [preorder β] {c : β} : monotone (λ (a : α), c) :=
λ a b _, le_rfl
theorem monotone_on_const [preorder α] [preorder β] {c : β} {s : set α} :
monotone_on (λ (a : α), c) s :=
λ a _ b _ _, le_rfl
theorem antitone_const [preorder α] [preorder β] {c : β} : antitone (λ (a : α), c) :=
λ a b _, le_refl c
theorem antitone_on_const [preorder α] [preorder β] {c : β} {s : set α} :
antitone_on (λ (a : α), c) s :=
λ a _ b _ _, le_rfl
lemma strict_mono_of_le_iff_le [preorder α] [preorder β] {f : α → β}
(h : ∀ x y, x ≤ y ↔ f x ≤ f y) : strict_mono f :=
λ a b, (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1
lemma strict_anti_of_le_iff_le [preorder α] [preorder β] {f : α → β}
(h : ∀ x y, x ≤ y ↔ f y ≤ f x) : strict_anti f :=
λ a b, (lt_iff_lt_of_le_iff_le' (h _ _) (h _ _)).1
lemma injective_of_lt_imp_ne [linear_order α] {f : α → β} (h : ∀ x y, x < y → f x ≠ f y) :
injective f :=
begin
intros x y hxy,
contrapose hxy,
cases ne.lt_or_lt hxy with hxy hxy,
exacts [h _ _ hxy, (h _ _ hxy).symm]
end
lemma injective_of_le_imp_le [partial_order α] [preorder β] (f : α → β)
(h : ∀ {x y}, f x ≤ f y → x ≤ y) : injective f :=
λ x y hxy, (h hxy.le).antisymm (h hxy.ge)
section preorder
variables [preorder α] [preorder β] {f g : α → β} {a : α}
lemma strict_mono.is_max_of_apply (hf : strict_mono f) (ha : is_max (f a)) : is_max a :=
of_not_not $ λ h, let ⟨b, hb⟩ := not_is_max_iff.1 h in (hf hb).not_is_max ha
lemma strict_mono.is_min_of_apply (hf : strict_mono f) (ha : is_min (f a)) : is_min a :=
of_not_not $ λ h, let ⟨b, hb⟩ := not_is_min_iff.1 h in (hf hb).not_is_min ha
lemma strict_anti.is_max_of_apply (hf : strict_anti f) (ha : is_min (f a)) : is_max a :=
of_not_not $ λ h, let ⟨b, hb⟩ := not_is_max_iff.1 h in (hf hb).not_is_min ha
lemma strict_anti.is_min_of_apply (hf : strict_anti f) (ha : is_max (f a)) : is_min a :=
of_not_not $ λ h, let ⟨b, hb⟩ := not_is_min_iff.1 h in (hf hb).not_is_max ha
protected lemma strict_mono.ite' (hf : strict_mono f) (hg : strict_mono g) {p : α → Prop}
[decidable_pred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x)
(hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → f x < g y) :
strict_mono (λ x, if p x then f x else g x) :=
begin
intros x y h,
by_cases hy : p y,
{ have hx : p x := hp h hy,
simpa [hx, hy] using hf h },
by_cases hx : p x,
{ simpa [hx, hy] using hfg hx hy h },
{ simpa [hx, hy] using hg h}
end
protected lemma strict_mono.ite (hf : strict_mono f) (hg : strict_mono g) {p : α → Prop}
[decidable_pred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, f x ≤ g x) :
strict_mono (λ x, if p x then f x else g x) :=
hf.ite' hg hp $ λ x y hx hy h, (hf h).trans_le (hfg y)
protected lemma strict_anti.ite' (hf : strict_anti f) (hg : strict_anti g) {p : α → Prop}
[decidable_pred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x)
(hfg : ∀ ⦃x y⦄, p x → ¬p y → x < y → g y < f x) :
strict_anti (λ x, if p x then f x else g x) :=
(strict_mono.ite' hf.dual_right hg.dual_right hp hfg).dual_right
protected lemma strict_anti.ite (hf : strict_anti f) (hg : strict_anti g) {p : α → Prop}
[decidable_pred p] (hp : ∀ ⦃x y⦄, x < y → p y → p x) (hfg : ∀ x, g x ≤ f x) :
strict_anti (λ x, if p x then f x else g x) :=
hf.ite' hg hp $ λ x y hx hy h, (hfg y).trans_lt (hf h)
end preorder
/-! ### Monotonicity under composition -/
section composition
variables [preorder α] [preorder β] [preorder γ] {g : β → γ} {f : α → β} {s : set α}
protected lemma monotone.comp (hg : monotone g) (hf : monotone f) :
monotone (g ∘ f) :=
λ a b h, hg (hf h)
lemma monotone.comp_antitone (hg : monotone g) (hf : antitone f) :
antitone (g ∘ f) :=
λ a b h, hg (hf h)
protected lemma antitone.comp (hg : antitone g) (hf : antitone f) :
monotone (g ∘ f) :=
λ a b h, hg (hf h)
lemma antitone.comp_monotone (hg : antitone g) (hf : monotone f) :
antitone (g ∘ f) :=
λ a b h, hg (hf h)
protected lemma monotone.iterate {f : α → α} (hf : monotone f) (n : ℕ) : monotone (f^[n]) :=
nat.rec_on n monotone_id (λ n h, h.comp hf)
protected lemma monotone.comp_monotone_on (hg : monotone g) (hf : monotone_on f s) :
monotone_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
lemma monotone.comp_antitone_on (hg : monotone g) (hf : antitone_on f s) :
antitone_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
protected lemma antitone.comp_antitone_on (hg : antitone g) (hf : antitone_on f s) :
monotone_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
lemma antitone.comp_monotone_on (hg : antitone g) (hf : monotone_on f s) :
antitone_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
protected lemma strict_mono.comp (hg : strict_mono g) (hf : strict_mono f) :
strict_mono (g ∘ f) :=
λ a b h, hg (hf h)
lemma strict_mono.comp_strict_anti (hg : strict_mono g) (hf : strict_anti f) :
strict_anti (g ∘ f) :=
λ a b h, hg (hf h)
protected lemma strict_anti.comp (hg : strict_anti g) (hf : strict_anti f) :
strict_mono (g ∘ f) :=
λ a b h, hg (hf h)
lemma strict_anti.comp_strict_mono (hg : strict_anti g) (hf : strict_mono f) :
strict_anti (g ∘ f) :=
λ a b h, hg (hf h)
protected lemma strict_mono.iterate {f : α → α} (hf : strict_mono f) (n : ℕ) :
strict_mono (f^[n]) :=
nat.rec_on n strict_mono_id (λ n h, h.comp hf)
protected lemma strict_mono.comp_strict_mono_on (hg : strict_mono g) (hf : strict_mono_on f s) :
strict_mono_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
lemma strict_mono.comp_strict_anti_on (hg : strict_mono g) (hf : strict_anti_on f s) :
strict_anti_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
protected lemma strict_anti.comp_strict_anti_on (hg : strict_anti g) (hf : strict_anti_on f s) :
strict_mono_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
lemma strict_anti.comp_strict_mono_on (hg : strict_anti g) (hf : strict_mono_on f s) :
strict_anti_on (g ∘ f) s :=
λ a ha b hb h, hg (hf ha hb h)
end composition
namespace list
section fold
theorem foldl_monotone [preorder α] {f : α → β → α} (H : ∀ b, monotone (λ a, f a b)) (l : list β) :
monotone (λ a, l.foldl f a) :=
list.rec_on l (λ _ _, id) (λ i l hl _ _ h, hl (H _ h))
theorem foldr_monotone [preorder β] {f : α → β → β} (H : ∀ a, monotone (f a)) (l : list α) :
monotone (λ b, l.foldr f b) :=
λ _ _ h, list.rec_on l h (λ i l hl, H i hl)
theorem foldl_strict_mono [preorder α] {f : α → β → α} (H : ∀ b, strict_mono (λ a, f a b))
(l : list β) : strict_mono (λ a, l.foldl f a) :=
list.rec_on l (λ _ _, id) (λ i l hl _ _ h, hl (H _ h))
theorem foldr_strict_mono [preorder β] {f : α → β → β} (H : ∀ a, strict_mono (f a)) (l : list α) :
strict_mono (λ b, l.foldr f b) :=
λ _ _ h, list.rec_on l h (λ i l hl, H i hl)
end fold
end list
/-! ### Monotonicity in linear orders -/
section linear_order
variables [linear_order α]
section preorder
variables [preorder β] {f : α → β} {s : set α}
open ordering
lemma monotone.reflect_lt (hf : monotone f) {a b : α} (h : f a < f b) : a < b :=
lt_of_not_ge (λ h', h.not_le (hf h'))
lemma antitone.reflect_lt (hf : antitone f) {a b : α} (h : f a < f b) : b < a :=
lt_of_not_ge (λ h', h.not_le (hf h'))
lemma monotone_on.reflect_lt (hf : monotone_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s)
(h : f a < f b) :
a < b :=
lt_of_not_ge $ λ h', h.not_le $ hf hb ha h'
lemma antitone_on.reflect_lt (hf : antitone_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s)
(h : f a < f b) :
b < a :=
lt_of_not_ge $ λ h', h.not_le $ hf ha hb h'
lemma strict_mono_on.le_iff_le (hf : strict_mono_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ a ≤ b :=
⟨λ h, le_of_not_gt $ λ h', (hf hb ha h').not_le h,
λ h, h.lt_or_eq_dec.elim (λ h', (hf ha hb h').le) (λ h', h' ▸ le_rfl)⟩
lemma strict_anti_on.le_iff_le (hf : strict_anti_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a ≤ f b ↔ b ≤ a :=
hf.dual_right.le_iff_le hb ha
lemma strict_mono_on.eq_iff_eq (hf : strict_mono_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ a = b :=
⟨λ h, le_antisymm ((hf.le_iff_le ha hb).mp h.le) ((hf.le_iff_le hb ha).mp h.ge),
by { rintro rfl, refl, }⟩
lemma strict_anti_on.eq_iff_eq (hf : strict_anti_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a = f b ↔ b = a :=
(hf.dual_right.eq_iff_eq ha hb).trans eq_comm
lemma strict_mono_on.lt_iff_lt (hf : strict_mono_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ a < b :=
by rw [lt_iff_le_not_le, lt_iff_le_not_le, hf.le_iff_le ha hb, hf.le_iff_le hb ha]
lemma strict_anti_on.lt_iff_lt (hf : strict_anti_on f s) {a b : α} (ha : a ∈ s) (hb : b ∈ s) :
f a < f b ↔ b < a :=
hf.dual_right.lt_iff_lt hb ha
lemma strict_mono.le_iff_le (hf : strict_mono f) {a b : α} :
f a ≤ f b ↔ a ≤ b :=
(hf.strict_mono_on set.univ).le_iff_le trivial trivial
lemma strict_anti.le_iff_le (hf : strict_anti f) {a b : α} :
f a ≤ f b ↔ b ≤ a :=
(hf.strict_anti_on set.univ).le_iff_le trivial trivial
lemma strict_mono.lt_iff_lt (hf : strict_mono f) {a b : α} :
f a < f b ↔ a < b :=
(hf.strict_mono_on set.univ).lt_iff_lt trivial trivial
lemma strict_anti.lt_iff_lt (hf : strict_anti f) {a b : α} :
f a < f b ↔ b < a :=
(hf.strict_anti_on set.univ).lt_iff_lt trivial trivial
protected theorem strict_mono_on.compares (hf : strict_mono_on f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) :
∀ {o : ordering}, o.compares (f a) (f b) ↔ o.compares a b
| ordering.lt := hf.lt_iff_lt ha hb
| ordering.eq := ⟨λ h, ((hf.le_iff_le ha hb).1 h.le).antisymm ((hf.le_iff_le hb ha).1 h.symm.le),
congr_arg _⟩
| ordering.gt := hf.lt_iff_lt hb ha
protected theorem strict_anti_on.compares (hf : strict_anti_on f s) {a b : α} (ha : a ∈ s)
(hb : b ∈ s) {o : ordering} :
o.compares (f a) (f b) ↔ o.compares b a :=
to_dual_compares_to_dual.trans $ hf.dual_right.compares hb ha
protected theorem strict_mono.compares (hf : strict_mono f) {a b : α} {o : ordering} :
o.compares (f a) (f b) ↔ o.compares a b :=
(hf.strict_mono_on set.univ).compares trivial trivial
protected theorem strict_anti.compares (hf : strict_anti f) {a b : α} {o : ordering} :
o.compares (f a) (f b) ↔ o.compares b a :=
(hf.strict_anti_on set.univ).compares trivial trivial
lemma strict_mono.injective (hf : strict_mono f) : injective f :=
λ x y h, show compares eq x y, from hf.compares.1 h
lemma strict_anti.injective (hf : strict_anti f) : injective f :=
λ x y h, show compares eq x y, from hf.compares.1 h.symm
lemma strict_mono.maximal_of_maximal_image (hf : strict_mono f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmax (f x))
lemma strict_mono.minimal_of_minimal_image (hf : strict_mono f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmin (f x))
lemma strict_anti.minimal_of_maximal_image (hf : strict_anti f) {a} (hmax : ∀ p, p ≤ f a) (x : α) :
a ≤ x :=
hf.le_iff_le.mp (hmax (f x))
lemma strict_anti.maximal_of_minimal_image (hf : strict_anti f) {a} (hmin : ∀ p, f a ≤ p) (x : α) :
x ≤ a :=
hf.le_iff_le.mp (hmin (f x))
end preorder
section partial_order
variables [partial_order β] {f : α → β}
lemma monotone.strict_mono_iff_injective (hf : monotone f) :
strict_mono f ↔ injective f :=
⟨λ h, h.injective, hf.strict_mono_of_injective⟩
lemma antitone.strict_anti_iff_injective (hf : antitone f) :
strict_anti f ↔ injective f :=
⟨λ h, h.injective, hf.strict_anti_of_injective⟩
end partial_order
variables [linear_order β] {f : α → β} {s : set α} {x y : α}
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_le_le :
¬ monotone f ∧ ¬ antitone f ↔ ∃ a b c, a ≤ b ∧ b ≤ c ∧
(f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) :=
begin
simp_rw [monotone, antitone, not_forall, not_le],
refine iff.symm ⟨_, _⟩,
{ rintro ⟨a, b, c, hab, hbc, ⟨hfab, hfcb⟩ | ⟨hfba, hfbc⟩⟩,
exacts [⟨⟨_, _, hbc, hfcb⟩, _, _, hab, hfab⟩, ⟨⟨_, _, hab, hfba⟩, _, _, hbc, hfbc⟩] },
rintro ⟨⟨a, b, hab, hfba⟩, c, d, hcd, hfcd⟩,
obtain hda | had := le_total d a,
{ obtain hfad | hfda := le_total (f a) (f d),
{ exact ⟨c, d, b, hcd, hda.trans hab, or.inl ⟨hfcd, hfba.trans_le hfad⟩⟩ },
{ exact ⟨c, a, b, hcd.trans hda, hab, or.inl ⟨hfcd.trans_le hfda, hfba⟩⟩ } },
obtain hac | hca := le_total a c,
{ obtain hfdb | hfbd := le_or_lt (f d) (f b),
{ exact ⟨a, c, d, hac, hcd, or.inr ⟨hfcd.trans $ hfdb.trans_lt hfba, hfcd⟩⟩ },
obtain hfca | hfac := lt_or_le (f c) (f a),
{ exact ⟨a, c, d, hac, hcd, or.inr ⟨hfca, hfcd⟩⟩ },
obtain hbd | hdb := le_total b d,
{ exact ⟨a, b, d, hab, hbd, or.inr ⟨hfba, hfbd⟩⟩ },
{ exact ⟨a, d, b, had, hdb, or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ } },
{ obtain hfdb | hfbd := le_or_lt (f d) (f b),
{ exact ⟨c, a, b, hca, hab, or.inl ⟨hfcd.trans $ hfdb.trans_lt hfba, hfba⟩⟩ },
obtain hfca | hfac := lt_or_le (f c) (f a),
{ exact ⟨c, a, b, hca, hab, or.inl ⟨hfca, hfba⟩⟩ },
obtain hbd | hdb := le_total b d,
{ exact ⟨a, b, d, hab, hbd, or.inr ⟨hfba, hfbd⟩⟩ },
{ exact ⟨a, d, b, had, hdb, or.inl ⟨hfac.trans_lt hfcd, hfbd⟩⟩ } }
end
/-- A function between linear orders which is neither monotone nor antitone makes a dent upright or
downright. -/
lemma not_monotone_not_antitone_iff_exists_lt_lt :
¬ monotone f ∧ ¬ antitone f ↔ ∃ a b c, a < b ∧ b < c ∧
(f a < f b ∧ f c < f b ∨ f b < f a ∧ f b < f c) :=
begin
simp_rw [not_monotone_not_antitone_iff_exists_le_le, ←and_assoc],
refine exists₃_congr (λ a b c, and_congr_left $ λ h, (ne.le_iff_lt _).and $ ne.le_iff_lt _);
rintro rfl; simpa using h,
end
/-!
### Strictly monotone functions and `cmp`
-/
lemma strict_mono_on.cmp_map_eq (hf : strict_mono_on f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp x y :=
((hf.compares hx hy).2 (cmp_compares x y)).cmp_eq
lemma strict_mono.cmp_map_eq (hf : strict_mono f) (x y : α) : cmp (f x) (f y) = cmp x y :=
(hf.strict_mono_on set.univ).cmp_map_eq trivial trivial
lemma strict_anti_on.cmp_map_eq (hf : strict_anti_on f s) (hx : x ∈ s) (hy : y ∈ s) :
cmp (f x) (f y) = cmp y x :=
hf.dual_right.cmp_map_eq hy hx
lemma strict_anti.cmp_map_eq (hf : strict_anti f) (x y : α) : cmp (f x) (f y) = cmp y x :=
(hf.strict_anti_on set.univ).cmp_map_eq trivial trivial
end linear_order
/-! ### Monotonicity in `ℕ` and `ℤ` -/
section preorder
variables [preorder α]
lemma nat.rel_of_forall_rel_succ_of_le_of_lt (r : β → β → Prop) [is_trans β r]
{f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄
(hab : a ≤ b) (hbc : b < c) :
r (f b) (f c) :=
begin
induction hbc with k b_lt_k r_b_k,
exacts [h _ hab, trans r_b_k (h _ (hab.trans_lt b_lt_k).le)]
end
lemma nat.rel_of_forall_rel_succ_of_le_of_le (r : β → β → Prop) [is_refl β r] [is_trans β r]
{f : ℕ → β} {a : ℕ} (h : ∀ n, a ≤ n → r (f n) (f (n + 1))) ⦃b c : ℕ⦄
(hab : a ≤ b) (hbc : b ≤ c) :
r (f b) (f c) :=
hbc.eq_or_lt.elim (λ h, h ▸ refl _) (nat.rel_of_forall_rel_succ_of_le_of_lt r h hab)
lemma nat.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [is_trans β r]
{f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a < b) : r (f a) (f b) :=
nat.rel_of_forall_rel_succ_of_le_of_lt r (λ n _, h n) le_rfl hab
lemma nat.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [is_refl β r] [is_trans β r]
{f : ℕ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℕ⦄ (hab : a ≤ b) : r (f a) (f b) :=
nat.rel_of_forall_rel_succ_of_le_of_le r (λ n _, h n) le_rfl hab
lemma monotone_nat_of_le_succ {f : ℕ → α} (hf : ∀ n, f n ≤ f (n + 1)) :
monotone f :=
nat.rel_of_forall_rel_succ_of_le (≤) hf
lemma antitone_nat_of_succ_le {f : ℕ → α} (hf : ∀ n, f (n + 1) ≤ f n) : antitone f :=
@monotone_nat_of_le_succ αᵒᵈ _ _ hf
lemma strict_mono_nat_of_lt_succ {f : ℕ → α} (hf : ∀ n, f n < f (n + 1)) : strict_mono f :=
nat.rel_of_forall_rel_succ_of_lt (<) hf
lemma strict_anti_nat_of_succ_lt {f : ℕ → α} (hf : ∀ n, f (n + 1) < f n) : strict_anti f :=
@strict_mono_nat_of_lt_succ αᵒᵈ _ f hf
namespace nat
/-- If `α` is a preorder with no maximal elements, then there exists a strictly monotone function
`ℕ → α` with any prescribed value of `f 0`. -/
lemma exists_strict_mono' [no_max_order α] (a : α) : ∃ f : ℕ → α, strict_mono f ∧ f 0 = a :=
begin
have := (λ x : α, exists_gt x),
choose g hg,
exact ⟨λ n, nat.rec_on n a (λ _, g), strict_mono_nat_of_lt_succ $ λ n, hg _, rfl⟩
end
/-- If `α` is a preorder with no maximal elements, then there exists a strictly antitone function
`ℕ → α` with any prescribed value of `f 0`. -/
lemma exists_strict_anti' [no_min_order α] (a : α) : ∃ f : ℕ → α, strict_anti f ∧ f 0 = a :=
exists_strict_mono' (order_dual.to_dual a)
variable (α)
/-- If `α` is a nonempty preorder with no maximal elements, then there exists a strictly monotone
function `ℕ → α`. -/
lemma exists_strict_mono [nonempty α] [no_max_order α] : ∃ f : ℕ → α, strict_mono f :=
let ⟨a⟩ := ‹nonempty α›, ⟨f, hf, hfa⟩ := exists_strict_mono' a in ⟨f, hf⟩
/-- If `α` is a nonempty preorder with no minimal elements, then there exists a strictly antitone
function `ℕ → α`. -/
lemma exists_strict_anti [nonempty α] [no_min_order α] : ∃ f : ℕ → α, strict_anti f :=
exists_strict_mono αᵒᵈ
end nat
lemma int.rel_of_forall_rel_succ_of_lt (r : β → β → Prop) [is_trans β r]
{f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a < b) : r (f a) (f b) :=
begin
rcases hab.dest with ⟨n, rfl⟩, clear hab,
induction n with n ihn,
{ rw int.coe_nat_one, apply h },
{ rw [int.coe_nat_succ, ← int.add_assoc],
exact trans ihn (h _) }
end
lemma int.rel_of_forall_rel_succ_of_le (r : β → β → Prop) [is_refl β r] [is_trans β r]
{f : ℤ → β} (h : ∀ n, r (f n) (f (n + 1))) ⦃a b : ℤ⦄ (hab : a ≤ b) : r (f a) (f b) :=
hab.eq_or_lt.elim (λ h, h ▸ refl _) (λ h', int.rel_of_forall_rel_succ_of_lt r h h')
lemma monotone_int_of_le_succ {f : ℤ → α} (hf : ∀ n, f n ≤ f (n + 1)) : monotone f :=
int.rel_of_forall_rel_succ_of_le (≤) hf
lemma antitone_int_of_succ_le {f : ℤ → α} (hf : ∀ n, f (n + 1) ≤ f n) : antitone f :=
int.rel_of_forall_rel_succ_of_le (≥) hf
lemma strict_mono_int_of_lt_succ {f : ℤ → α} (hf : ∀ n, f n < f (n + 1)) : strict_mono f :=
int.rel_of_forall_rel_succ_of_lt (<) hf
lemma strict_anti_int_of_succ_lt {f : ℤ → α} (hf : ∀ n, f (n + 1) < f n) : strict_anti f :=
int.rel_of_forall_rel_succ_of_lt (>) hf
namespace int
variables (α) [nonempty α] [no_min_order α] [no_max_order α]
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
monotone function `f : ℤ → α`. -/
lemma exists_strict_mono : ∃ f : ℤ → α, strict_mono f :=
begin
inhabit α,
rcases nat.exists_strict_mono' (default : α) with ⟨f, hf, hf₀⟩,
rcases nat.exists_strict_anti' (default : α) with ⟨g, hg, hg₀⟩,
refine ⟨λ n, int.cases_on n f (λ n, g (n + 1)), strict_mono_int_of_lt_succ _⟩,
rintro (n|_|n),
{ exact hf n.lt_succ_self },
{ show g 1 < f 0,
rw [hf₀, ← hg₀],
exact hg nat.zero_lt_one },
{ exact hg (nat.lt_succ_self _) }
end
/-- If `α` is a nonempty preorder with no minimal or maximal elements, then there exists a strictly
antitone function `f : ℤ → α`. -/
lemma exists_strict_anti : ∃ f : ℤ → α, strict_anti f := exists_strict_mono αᵒᵈ
end int
-- TODO@Yael: Generalize the following four to succ orders
/-- If `f` is a monotone function from `ℕ` to a preorder such that `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
lemma monotone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : monotone f) (n : ℕ) {x : α}
(h1 : f n < x) (h2 : x < f (n + 1)) (a : ℕ) :
f a ≠ x :=
by { rintro rfl, exact (hf.reflect_lt h1).not_le (nat.le_of_lt_succ $ hf.reflect_lt h2) }
/-- If `f` is an antitone function from `ℕ` to a preorder such that `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
lemma antitone.ne_of_lt_of_lt_nat {f : ℕ → α} (hf : antitone f)
(n : ℕ) {x : α} (h1 : f (n + 1) < x) (h2 : x < f n) (a : ℕ) : f a ≠ x :=
by { rintro rfl, exact (hf.reflect_lt h2).not_le (nat.le_of_lt_succ $ hf.reflect_lt h1) }
/-- If `f` is a monotone function from `ℤ` to a preorder and `x` lies between `f n` and
`f (n + 1)`, then `x` doesn't lie in the range of `f`. -/
lemma monotone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : monotone f) (n : ℤ) {x : α}
(h1 : f n < x) (h2 : x < f (n + 1)) (a : ℤ) :
f a ≠ x :=
by { rintro rfl, exact (hf.reflect_lt h1).not_le (int.le_of_lt_add_one $ hf.reflect_lt h2) }
/-- If `f` is an antitone function from `ℤ` to a preorder and `x` lies between `f (n + 1)` and
`f n`, then `x` doesn't lie in the range of `f`. -/
lemma antitone.ne_of_lt_of_lt_int {f : ℤ → α} (hf : antitone f)
(n : ℤ) {x : α} (h1 : f (n + 1) < x) (h2 : x < f n) (a : ℤ) : f a ≠ x :=
by { rintro rfl, exact (hf.reflect_lt h2).not_le (int.le_of_lt_add_one $ hf.reflect_lt h1) }
lemma strict_mono.id_le {φ : ℕ → ℕ} (h : strict_mono φ) : ∀ n, n ≤ φ n :=
λ n, nat.rec_on n (nat.zero_le _)
(λ n hn, nat.succ_le_of_lt (hn.trans_lt $ h $ nat.lt_succ_self n))
end preorder
lemma subtype.mono_coe [preorder α] (t : set α) : monotone (coe : (subtype t) → α) :=
λ x y, id
lemma subtype.strict_mono_coe [preorder α] (t : set α) : strict_mono (coe : (subtype t) → α) :=
λ x y, id
section preorder
variables [preorder α] [preorder β] [preorder γ] [preorder δ] {f : α → γ} {g : β → δ} {a b : α}
lemma monotone_fst : monotone (@prod.fst α β) := λ a b, and.left
lemma monotone_snd : monotone (@prod.snd α β) := λ a b, and.right
lemma monotone.prod_map (hf : monotone f) (hg : monotone g) : monotone (prod.map f g) :=
λ a b h, ⟨hf h.1, hg h.2⟩
lemma antitone.prod_map (hf : antitone f) (hg : antitone g) : antitone (prod.map f g) :=
λ a b h, ⟨hf h.1, hg h.2⟩
end preorder
section partial_order
variables [partial_order α] [partial_order β] [preorder γ] [preorder δ]
{f : α → γ} {g : β → δ}
lemma strict_mono.prod_map (hf : strict_mono f) (hg : strict_mono g) : strict_mono (prod.map f g) :=
λ a b, by { simp_rw prod.lt_iff,
exact or.imp (and.imp hf.imp hg.monotone.imp) (and.imp hf.monotone.imp hg.imp) }
lemma strict_anti.prod_map (hf : strict_anti f) (hg : strict_anti g) : strict_anti (prod.map f g) :=
λ a b, by { simp_rw prod.lt_iff,
exact or.imp (and.imp hf.imp hg.antitone.imp) (and.imp hf.antitone.imp hg.imp) }
end partial_order
namespace function
variables [preorder α]
lemma const_mono : monotone (const β : α → β → α) := λ a b h i, h
lemma const_strict_mono [nonempty β] : strict_mono (const β : α → β → α) := λ a b, const_lt_const.2
end function
|
c12fe4c6defa5388916418158e50772159b770cf | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/geometry/manifold/smooth_manifold_with_corners.lean | a6c6ba9631dabeeb927251c3e61b2d57569013c5 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 44,701 | 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.calculus.cont_diff
import geometry.manifold.charted_space
/-!
# Smooth manifolds (possibly with boundary or corners)
A smooth manifold is a manifold modelled on a normed vector space, or a subset like a
half-space (to get manifolds with boundaries) for which the changes of coordinates are smooth maps.
We define a model with corners as a map `I : H → E` embedding nicely the topological space `H` in
the vector space `E` (or more precisely as a structure containing all the relevant properties).
Given such a model with corners `I` on `(E, H)`, we define the groupoid of local
homeomorphisms of `H` which are smooth when read in `E` (for any regularity `n : ℕ∞`).
With this groupoid at hand and the general machinery of charted spaces, we thus get the notion
of `C^n` manifold with respect to any model with corners `I` on `(E, H)`. We also introduce a
specific type class for `C^∞` manifolds as these are the most commonly used.
## Main definitions
* `model_with_corners 𝕜 E H` :
a structure containing informations on the way a space `H` embeds in a
model vector space E over the field `𝕜`. This is all that is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
* `model_with_corners_self 𝕜 E` :
trivial model with corners structure on the space `E` embedded in itself by the identity.
* `cont_diff_groupoid n I` :
when `I` is a model with corners on `(𝕜, E, H)`, this is the groupoid of local homeos of `H`
which are of class `C^n` over the normed field `𝕜`, when read in `E`.
* `smooth_manifold_with_corners I M` :
a type class saying that the charted space `M`, modelled on the space `H`, has `C^∞` changes of
coordinates with respect to the model with corners `I` on `(𝕜, E, H)`. This type class is just
a shortcut for `has_groupoid M (cont_diff_groupoid ∞ I)`.
* `ext_chart_at I x`:
in a smooth manifold with corners with the model `I` on `(E, H)`, the charts take values in `H`,
but often we may want to use their `E`-valued version, obtained by composing the charts with `I`.
Since the target is in general not open, we can not register them as local homeomorphisms, but
we register them as local equivs. `ext_chart_at I x` is the canonical such local equiv around `x`.
As specific examples of models with corners, we define (in the file `real_instances.lean`)
* `model_with_corners_self ℝ (euclidean_space (fin n))` for the model space used to define
`n`-dimensional real manifolds without boundary (with notation `𝓡 n` in the locale `manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_half_space n)` for the model space
used to define `n`-dimensional real manifolds with boundary (with notation `𝓡∂ n` in the locale
`manifold`)
* `model_with_corners ℝ (euclidean_space (fin n)) (euclidean_quadrant n)` for the model space used
to define `n`-dimensional real manifolds with corners
With these definitions at hand, to invoke an `n`-dimensional real manifold without boundary,
one could use
`variables {n : ℕ} {M : Type*} [topological_space M] [charted_space (euclidean_space (fin n)) M]
[smooth_manifold_with_corners (𝓡 n) M]`.
However, this is not the recommended way: a theorem proved using this assumption would not apply
for instance to the tangent space of such a manifold, which is modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin n))` and not on `euclidean_space (fin (2 * n))`!
In the same way, it would not apply to product manifolds, modelled on
`(euclidean_space (fin n)) × (euclidean_space (fin m))`.
The right invocation does not focus on one specific construction, but on all constructions sharing
the right properties, like
`variables {E : Type*} [normed_add_comm_group E] [normed_space ℝ E] [finite_dimensional ℝ E]
{I : model_with_corners ℝ E E} [I.boundaryless]
{M : Type*} [topological_space M] [charted_space E M] [smooth_manifold_with_corners I M]`
Here, `I.boundaryless` is a typeclass property ensuring that there is no boundary (this is for
instance the case for `model_with_corners_self`, or products of these). Note that one could consider
as a natural assumption to only use the trivial model with corners `model_with_corners_self ℝ E`,
but again in product manifolds the natural model with corners will not be this one but the product
one (and they are not defeq as `(λp : E × F, (p.1, p.2))` is not defeq to the identity). So, it is
important to use the above incantation to maximize the applicability of theorems.
## Implementation notes
We want to talk about manifolds modelled on a vector space, but also on manifolds with
boundary, modelled on a half space (or even manifolds with corners). For the latter examples,
we still want to define smooth functions, tangent bundles, and so on. As smooth functions are
well defined on vector spaces or subsets of these, one could take for model space a subtype of a
vector space. With the drawback that the whole vector space itself (which is the most basic
example) is not directly a subtype of itself: the inclusion of `univ : set E` in `set E` would
show up in the definition, instead of `id`.
A good abstraction covering both cases it to have a vector
space `E` (with basic example the Euclidean space), a model space `H` (with basic example the upper
half space), and an embedding of `H` into `E` (which can be the identity for `H = E`, or
`subtype.val` for manifolds with corners). We say that the pair `(E, H)` with their embedding is a
model with corners, and we encompass all the relevant properties (in particular the fact that the
image of `H` in `E` should have unique differentials) in the definition of `model_with_corners`.
We concentrate on `C^∞` manifolds: all the definitions work equally well for `C^n` manifolds, but
later on it is a pain to carry all over the smoothness parameter, especially when one wants to deal
with `C^k` functions as there would be additional conditions `k ≤ n` everywhere. Since one deals
almost all the time with `C^∞` (or analytic) manifolds, this seems to be a reasonable choice that
one could revisit later if needed. `C^k` manifolds are still available, but they should be called
using `has_groupoid M (cont_diff_groupoid k I)` where `I` is the model with corners.
I have considered using the model with corners `I` as a typeclass argument, possibly `out_param`, to
get lighter notations later on, but it did not turn out right, as on `E × F` there are two natural
model with corners, the trivial (identity) one, and the product one, and they are not defeq and one
needs to indicate to Lean which one we want to use.
This means that when talking on objects on manifolds one will most often need to specify the model
with corners one is using. For instance, the tangent bundle will be `tangent_bundle I M` and the
derivative will be `mfderiv I I' f`, instead of the more natural notations `tangent_bundle 𝕜 M` and
`mfderiv 𝕜 f` (the field has to be explicit anyway, as some manifolds could be considered both as
real and complex manifolds).
-/
noncomputable theory
universes u v w u' v' w'
open set filter function
open_locale manifold filter topological_space
localized "notation (name := with_top.nat.top) `∞` := (⊤ : ℕ∞)" in manifold
/-! ### Models with corners. -/
/-- A structure containing informations on the way a space `H` embeds in a
model vector space `E` over the field `𝕜`. This is all what is needed to
define a smooth manifold with model space `H`, and model vector space `E`.
-/
@[nolint has_nonempty_instance]
structure model_with_corners (𝕜 : Type*) [nontrivially_normed_field 𝕜]
(E : Type*) [normed_add_comm_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
extends local_equiv H E :=
(source_eq : source = univ)
(unique_diff' : unique_diff_on 𝕜 to_local_equiv.target)
(continuous_to_fun : continuous to_fun . tactic.interactive.continuity')
(continuous_inv_fun : continuous inv_fun . tactic.interactive.continuity')
attribute [simp, mfld_simps] model_with_corners.source_eq
/-- A vector space is a model with corners. -/
def model_with_corners_self (𝕜 : Type*) [nontrivially_normed_field 𝕜]
(E : Type*) [normed_add_comm_group E] [normed_space 𝕜 E] : model_with_corners 𝕜 E E :=
{ to_local_equiv := local_equiv.refl E,
source_eq := rfl,
unique_diff' := unique_diff_on_univ,
continuous_to_fun := continuous_id,
continuous_inv_fun := continuous_id }
localized "notation (name := model_with_corners_self) `𝓘(` 𝕜 `, ` E `)` :=
model_with_corners_self 𝕜 E" in manifold
localized "notation (name := model_with_corners_self.self) `𝓘(` 𝕜 `)` :=
model_with_corners_self 𝕜 𝕜" in manifold
section
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
namespace model_with_corners
instance : has_coe_to_fun (model_with_corners 𝕜 E H) (λ _, H → E) := ⟨λ e, e.to_fun⟩
/-- The inverse to a model with corners, only registered as a local equiv. -/
protected def symm : local_equiv E H := I.to_local_equiv.symm
/-- 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 (𝕜 : Type*) [nontrivially_normed_field 𝕜]
(E : Type*) [normed_add_comm_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
(I : model_with_corners 𝕜 E H) : H → E := I
/-- See Note [custom simps projection] -/
def simps.symm_apply (𝕜 : Type*) [nontrivially_normed_field 𝕜]
(E : Type*) [normed_add_comm_group E] [normed_space 𝕜 E] (H : Type*) [topological_space H]
(I : model_with_corners 𝕜 E H) : E → H := I.symm
initialize_simps_projections model_with_corners
(to_local_equiv_to_fun → apply, to_local_equiv_inv_fun → symm_apply,
to_local_equiv_source → source, to_local_equiv_target → target, -to_local_equiv)
/- Register a few lemmas to make sure that `simp` puts expressions in normal form -/
@[simp, mfld_simps] lemma to_local_equiv_coe : (I.to_local_equiv : H → E) = I :=
rfl
@[simp, mfld_simps] lemma mk_coe (e : local_equiv H E) (a b c d) :
((model_with_corners.mk e a b c d : model_with_corners 𝕜 E H) : H → E) = (e : H → E) := rfl
@[simp, mfld_simps] lemma to_local_equiv_coe_symm : (I.to_local_equiv.symm : E → H) = I.symm := rfl
@[simp, mfld_simps] lemma mk_symm (e : local_equiv H E) (a b c d) :
(model_with_corners.mk e a b c d : model_with_corners 𝕜 E H).symm = e.symm :=
rfl
@[continuity] protected lemma continuous : continuous I := I.continuous_to_fun
protected lemma continuous_at {x} : continuous_at I x := I.continuous.continuous_at
protected lemma continuous_within_at {s x} : continuous_within_at I s x :=
I.continuous_at.continuous_within_at
@[continuity] lemma continuous_symm : continuous I.symm := I.continuous_inv_fun
lemma continuous_at_symm {x} : continuous_at I.symm x := I.continuous_symm.continuous_at
lemma continuous_within_at_symm {s x} : continuous_within_at I.symm s x :=
I.continuous_symm.continuous_within_at
lemma continuous_on_symm {s} : continuous_on I.symm s := I.continuous_symm.continuous_on
@[simp, mfld_simps] lemma target_eq : I.target = range (I : H → E) :=
by { rw [← image_univ, ← I.source_eq], exact (I.to_local_equiv.image_source_eq_target).symm }
protected lemma unique_diff : unique_diff_on 𝕜 (range I) := I.target_eq ▸ I.unique_diff'
@[simp, mfld_simps] protected lemma left_inv (x : H) : I.symm (I x) = x :=
by { refine I.left_inv' _, simp }
protected lemma left_inverse : left_inverse I.symm I := I.left_inv
lemma injective : injective I :=
I.left_inverse.injective
@[simp, mfld_simps] lemma symm_comp_self : I.symm ∘ I = id :=
I.left_inverse.comp_eq_id
protected lemma right_inv_on : right_inv_on I.symm I (range I) :=
I.left_inverse.right_inv_on_range
@[simp, mfld_simps] protected lemma right_inv {x : E} (hx : x ∈ range I) : I (I.symm x) = x :=
I.right_inv_on hx
protected lemma image_eq (s : set H) : I '' s = I.symm ⁻¹' s ∩ range I :=
begin
refine (I.to_local_equiv.image_eq_target_inter_inv_preimage _).trans _,
{ rw I.source_eq, exact subset_univ _ },
{ rw [inter_comm, I.target_eq, I.to_local_equiv_coe_symm] }
end
protected lemma closed_embedding : closed_embedding I :=
I.left_inverse.closed_embedding I.continuous_symm I.continuous
lemma closed_range : is_closed (range I) :=
I.closed_embedding.closed_range
lemma map_nhds_eq (x : H) : map I (𝓝 x) = 𝓝[range I] (I x) :=
I.closed_embedding.to_embedding.map_nhds_eq x
lemma image_mem_nhds_within {x : H} {s : set H} (hs : s ∈ 𝓝 x) :
I '' s ∈ 𝓝[range I] (I x) :=
I.map_nhds_eq x ▸ image_mem_map hs
lemma symm_map_nhds_within_range (x : H) :
map I.symm (𝓝[range I] (I x)) = 𝓝 x :=
by rw [← I.map_nhds_eq, map_map, I.symm_comp_self, map_id]
lemma unique_diff_preimage {s : set H} (hs : is_open s) :
unique_diff_on 𝕜 (I.symm ⁻¹' s ∩ range I) :=
by { rw inter_comm, exact I.unique_diff.inter (hs.preimage I.continuous_inv_fun) }
lemma unique_diff_preimage_source {β : Type*} [topological_space β]
{e : local_homeomorph H β} : unique_diff_on 𝕜 (I.symm ⁻¹' (e.source) ∩ range I) :=
I.unique_diff_preimage e.open_source
lemma unique_diff_at_image {x : H} : unique_diff_within_at 𝕜 (range I) (I x) :=
I.unique_diff _ (mem_range_self _)
protected lemma locally_compact [locally_compact_space E] (I : model_with_corners 𝕜 E H) :
locally_compact_space H :=
begin
have : ∀ (x : H), (𝓝 x).has_basis (λ s, s ∈ 𝓝 (I x) ∧ is_compact s)
(λ s, I.symm '' (s ∩ range ⇑I)),
{ intro x,
rw ← I.symm_map_nhds_within_range,
exact ((compact_basis_nhds (I x)).inf_principal _).map _ },
refine locally_compact_space_of_has_basis this _,
rintro x s ⟨-, hsc⟩,
exact (hsc.inter_right I.closed_range).image I.continuous_symm
end
open topological_space
protected lemma second_countable_topology [second_countable_topology E]
(I : model_with_corners 𝕜 E H) : second_countable_topology H :=
I.closed_embedding.to_embedding.second_countable_topology
end model_with_corners
section
variables (𝕜 E)
/-- In the trivial model with corners, the associated local equiv is the identity. -/
@[simp, mfld_simps] lemma model_with_corners_self_local_equiv :
(𝓘(𝕜, E)).to_local_equiv = local_equiv.refl E := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe :
(𝓘(𝕜, E) : E → E) = id := rfl
@[simp, mfld_simps] lemma model_with_corners_self_coe_symm :
(𝓘(𝕜, E).symm : E → E) = id := rfl
end
end
section model_with_corners_prod
/-- Given two model_with_corners `I` on `(E, H)` and `I'` on `(E', H')`, we define the model with
corners `I.prod I'` on `(E × E', model_prod H H')`. This appears in particular for the manifold
structure on the tangent bundle to a manifold modelled on `(E, H)`: it will be modelled on
`(E × E, H × E)`. See note [Manifold type tags] for explanation about `model_prod H H'`
vs `H × H'`. -/
@[simps (lemmas_only)] def model_with_corners.prod
{𝕜 : Type u} [nontrivially_normed_field 𝕜]
{E : Type v} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) {E' : Type v'} [normed_add_comm_group E'] [normed_space 𝕜 E']
{H' : Type w'} [topological_space H'] (I' : model_with_corners 𝕜 E' H') :
model_with_corners 𝕜 (E × E') (model_prod H H') :=
{ to_fun := λ x, (I x.1, I' x.2),
inv_fun := λ x, (I.symm x.1, I'.symm x.2),
source := {x | x.1 ∈ I.source ∧ x.2 ∈ I'.source},
source_eq := by simp only [set_of_true] with mfld_simps,
unique_diff' := I.unique_diff'.prod I'.unique_diff',
continuous_to_fun := I.continuous_to_fun.prod_map I'.continuous_to_fun,
continuous_inv_fun := I.continuous_inv_fun.prod_map I'.continuous_inv_fun,
.. I.to_local_equiv.prod I'.to_local_equiv }
/-- Given a finite family of `model_with_corners` `I i` on `(E i, H i)`, we define the model with
corners `pi I` on `(Π i, E i, model_pi H)`. See note [Manifold type tags] for explanation about
`model_pi H`. -/
def model_with_corners.pi
{𝕜 : Type u} [nontrivially_normed_field 𝕜] {ι : Type v} [fintype ι]
{E : ι → Type w} [Π i, normed_add_comm_group (E i)] [Π i, normed_space 𝕜 (E i)]
{H : ι → Type u'} [Π i, topological_space (H i)] (I : Π i, model_with_corners 𝕜 (E i) (H i)) :
model_with_corners 𝕜 (Π i, E i) (model_pi H) :=
{ to_local_equiv := local_equiv.pi (λ i, (I i).to_local_equiv),
source_eq := by simp only [set.pi_univ] with mfld_simps,
unique_diff' := unique_diff_on.pi ι E _ _ (λ i _, (I i).unique_diff'),
continuous_to_fun := continuous_pi $ λ i, (I i).continuous.comp (continuous_apply i),
continuous_inv_fun := continuous_pi $ λ i, (I i).continuous_symm.comp (continuous_apply i) }
/-- Special case of product model with corners, which is trivial on the second factor. This shows up
as the model to tangent bundles. -/
@[reducible] def model_with_corners.tangent
{𝕜 : Type u} [nontrivially_normed_field 𝕜]
{E : Type v} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) : model_with_corners 𝕜 (E × E) (model_prod H E) :=
I.prod (𝓘(𝕜, E))
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜] {E : Type*} [normed_add_comm_group E]
[normed_space 𝕜 E] {E' : Type*} [normed_add_comm_group E'] [normed_space 𝕜 E'] {F : Type*}
[normed_add_comm_group F] [normed_space 𝕜 F] {F' : Type*} [normed_add_comm_group F']
[normed_space 𝕜 F']
{H : Type*} [topological_space H] {H' : Type*} [topological_space H']
{G : Type*} [topological_space G] {G' : Type*} [topological_space G']
{I : model_with_corners 𝕜 E H} {J : model_with_corners 𝕜 F G}
@[simp, mfld_simps] lemma model_with_corners_prod_to_local_equiv :
(I.prod J).to_local_equiv = I.to_local_equiv.prod (J.to_local_equiv) :=
rfl
@[simp, mfld_simps] lemma model_with_corners_prod_coe
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
(I.prod I' : _ × _ → _ × _) = prod.map I I' := rfl
@[simp, mfld_simps] lemma model_with_corners_prod_coe_symm
(I : model_with_corners 𝕜 E H) (I' : model_with_corners 𝕜 E' H') :
((I.prod I').symm : _ × _ → _ × _) = prod.map I.symm I'.symm := rfl
end model_with_corners_prod
section boundaryless
/-- Property ensuring that the model with corners `I` defines manifolds without boundary. -/
class model_with_corners.boundaryless {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H) : Prop :=
(range_eq_univ : range I = univ)
/-- The trivial model with corners has no boundary -/
instance model_with_corners_self_boundaryless (𝕜 : Type*) [nontrivially_normed_field 𝕜]
(E : Type*) [normed_add_comm_group E] [normed_space 𝕜 E] :
(model_with_corners_self 𝕜 E).boundaryless :=
⟨by simp⟩
/-- If two model with corners are boundaryless, their product also is -/
instance model_with_corners.range_eq_univ_prod {𝕜 : Type u} [nontrivially_normed_field 𝕜]
{E : Type v} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type w} [topological_space H]
(I : model_with_corners 𝕜 E H) [I.boundaryless] {E' : Type v'} [normed_add_comm_group E']
[normed_space 𝕜 E'] {H' : Type w'} [topological_space H']
(I' : model_with_corners 𝕜 E' H') [I'.boundaryless] :
(I.prod I').boundaryless :=
begin
split,
dsimp [model_with_corners.prod, model_prod],
rw [← prod_range_range_eq, model_with_corners.boundaryless.range_eq_univ,
model_with_corners.boundaryless.range_eq_univ, univ_prod_univ]
end
end boundaryless
section cont_diff_groupoid
/-! ### Smooth functions on models with corners -/
variables {m n : ℕ∞} {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H]
(I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
variable (n)
/-- Given a model with corners `(E, H)`, we define the groupoid of `C^n` transformations of `H` as
the maps that are `C^n` when read in `E` through `I`. -/
def cont_diff_groupoid : structure_groupoid H :=
pregroupoid.groupoid
{ property := λf s, cont_diff_on 𝕜 n (I ∘ f ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
comp := λf g u v hf hg hu hv huv, begin
have : I ∘ (g ∘ f) ∘ I.symm = (I ∘ g ∘ I.symm) ∘ (I ∘ f ∘ I.symm),
by { ext x, simp },
rw this,
apply cont_diff_on.comp hg _,
{ rintros x ⟨hx1, hx2⟩,
simp only with mfld_simps at ⊢ hx1,
exact hx1.2 },
{ refine hf.mono _,
rintros x ⟨hx1, hx2⟩,
exact ⟨hx1.1, hx2⟩ }
end,
id_mem := begin
apply cont_diff_on.congr (cont_diff_id.cont_diff_on),
rintros x ⟨hx1, hx2⟩,
rcases mem_range.1 hx2 with ⟨y, hy⟩,
rw ← hy,
simp only with mfld_simps,
end,
locality := λf u hu H, begin
apply cont_diff_on_of_locally_cont_diff_on,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rcases H x hy1 with ⟨v, v_open, xv, hv⟩,
have : ((I.symm ⁻¹' (u ∩ v)) ∩ (range I))
= ((I.symm ⁻¹' u) ∩ (range I) ∩ I.symm ⁻¹' v),
{ rw [preimage_inter, inter_assoc, inter_assoc],
congr' 1,
rw inter_comm },
rw this at hv,
exact ⟨I.symm ⁻¹' v, v_open.preimage I.continuous_symm, by simpa, hv⟩
end,
congr := λf g u hu fg hf, begin
apply hf.congr,
rintros y ⟨hy1, hy2⟩,
rcases mem_range.1 hy2 with ⟨x, hx⟩,
rw ← hx at ⊢ hy1,
simp only with mfld_simps at ⊢ hy1,
rw fg _ hy1
end }
variable {n}
/-- Inclusion of the groupoid of `C^n` local diffeos in the groupoid of `C^m` local diffeos when
`m ≤ n` -/
lemma cont_diff_groupoid_le (h : m ≤ n) :
cont_diff_groupoid n I ≤ cont_diff_groupoid m I :=
begin
rw [cont_diff_groupoid, cont_diff_groupoid],
apply groupoid_of_pregroupoid_le,
assume f s hfs,
exact cont_diff_on.of_le hfs h
end
/-- The groupoid of `0`-times continuously differentiable maps is just the groupoid of all
local homeomorphisms -/
lemma cont_diff_groupoid_zero_eq :
cont_diff_groupoid 0 I = continuous_groupoid H :=
begin
apply le_antisymm le_top,
assume u hu,
-- we have to check that every local homeomorphism belongs to `cont_diff_groupoid 0 I`,
-- by unfolding its definition
change u ∈ cont_diff_groupoid 0 I,
rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid],
simp only [cont_diff_on_zero],
split,
{ refine I.continuous.comp_continuous_on (u.continuous_on.comp I.continuous_on_symm _),
exact (maps_to_preimage _ _).mono_left (inter_subset_left _ _) },
{ refine I.continuous.comp_continuous_on (u.symm.continuous_on.comp I.continuous_on_symm _),
exact (maps_to_preimage _ _).mono_left (inter_subset_left _ _) },
end
variable (n)
/-- An identity local homeomorphism belongs to the `C^n` groupoid. -/
lemma of_set_mem_cont_diff_groupoid {s : set H} (hs : is_open s) :
local_homeomorph.of_set s hs ∈ cont_diff_groupoid n I :=
begin
rw [cont_diff_groupoid, mem_groupoid_of_pregroupoid],
suffices h : cont_diff_on 𝕜 n (I ∘ I.symm) (I.symm ⁻¹' s ∩ range I),
by simp [h],
have : cont_diff_on 𝕜 n id (univ : set E) :=
cont_diff_id.cont_diff_on,
exact this.congr_mono (λ x hx, by simp [hx.2]) (subset_univ _)
end
/-- The composition of a local homeomorphism from `H` to `M` and its inverse belongs to
the `C^n` groupoid. -/
lemma symm_trans_mem_cont_diff_groupoid (e : local_homeomorph M H) :
e.symm.trans e ∈ cont_diff_groupoid n I :=
begin
have : e.symm.trans e ≈ local_homeomorph.of_set e.target e.open_target :=
local_homeomorph.trans_symm_self _,
exact structure_groupoid.eq_on_source _
(of_set_mem_cont_diff_groupoid n I e.open_target) this
end
variables {E' H' : Type*} [normed_add_comm_group E'] [normed_space 𝕜 E'] [topological_space H']
/-- The product of two smooth local homeomorphisms is smooth. -/
lemma cont_diff_groupoid_prod
{I : model_with_corners 𝕜 E H} {I' : model_with_corners 𝕜 E' H'}
{e : local_homeomorph H H} {e' : local_homeomorph H' H'}
(he : e ∈ cont_diff_groupoid ⊤ I) (he' : e' ∈ cont_diff_groupoid ⊤ I') :
e.prod e' ∈ cont_diff_groupoid ⊤ (I.prod I') :=
begin
cases he with he he_symm,
cases he' with he' he'_symm,
simp only at he he_symm he' he'_symm,
split;
simp only [local_equiv.prod_source, local_homeomorph.prod_to_local_equiv],
{ have h3 := cont_diff_on.prod_map he he',
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, },
{ have h3 := cont_diff_on.prod_map he_symm he'_symm,
rw [← I.image_eq, ← I'.image_eq, set.prod_image_image_eq] at h3,
rw ← (I.prod I').image_eq,
exact h3, }
end
/-- The `C^n` groupoid is closed under restriction. -/
instance : closed_under_restriction (cont_diff_groupoid n I) :=
(closed_under_restriction_iff_id_le _).mpr
begin
apply structure_groupoid.le_iff.mpr,
rintros e ⟨s, hs, hes⟩,
apply (cont_diff_groupoid n I).eq_on_source' _ _ _ hes,
exact of_set_mem_cont_diff_groupoid n I hs,
end
end cont_diff_groupoid
section smooth_manifold_with_corners
/-! ### Smooth manifolds with corners -/
/-- Typeclass defining smooth manifolds with corners with respect to a model with corners, over a
field `𝕜` and with infinite smoothness to simplify typeclass search and statements later on. -/
@[ancestor has_groupoid]
class smooth_manifold_with_corners {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M] extends
has_groupoid M (cont_diff_groupoid ∞ I) : Prop
lemma smooth_manifold_with_corners.mk' {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
[gr : has_groupoid M (cont_diff_groupoid ∞ I)] :
smooth_manifold_with_corners I M := { ..gr }
lemma smooth_manifold_with_corners_of_cont_diff_on
{𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
(h : ∀ (e e' : local_homeomorph M H), e ∈ atlas H M → e' ∈ atlas H M →
cont_diff_on 𝕜 ⊤ (I ∘ (e.symm ≫ₕ e') ∘ I.symm)
(I.symm ⁻¹' (e.symm ≫ₕ e').source ∩ range I)) :
smooth_manifold_with_corners I M :=
{ compatible :=
begin
haveI : has_groupoid M (cont_diff_groupoid ∞ I) := has_groupoid_of_pregroupoid _ h,
apply structure_groupoid.compatible,
end }
/-- For any model with corners, the model space is a smooth manifold -/
instance model_space_smooth {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E] {H : Type*} [topological_space H]
{I : model_with_corners 𝕜 E H} :
smooth_manifold_with_corners I H := { .. has_groupoid_model_space _ _ }
end smooth_manifold_with_corners
namespace smooth_manifold_with_corners
/- We restate in the namespace `smooth_manifolds_with_corners` some lemmas that hold for general
charted space with a structure groupoid, avoiding the need to specify the groupoid
`cont_diff_groupoid ∞ I` explicitly. -/
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
(M : Type*) [topological_space M] [charted_space H M]
/-- The maximal atlas of `M` for the smooth manifold with corners structure corresponding to the
model with corners `I`. -/
def maximal_atlas := (cont_diff_groupoid ∞ I).maximal_atlas M
variable {M}
lemma subset_maximal_atlas [smooth_manifold_with_corners I M] :
atlas H M ⊆ maximal_atlas I M :=
structure_groupoid.subset_maximal_atlas _
lemma chart_mem_maximal_atlas [smooth_manifold_with_corners I M] (x : M) :
chart_at H x ∈ maximal_atlas I M :=
structure_groupoid.chart_mem_maximal_atlas _ x
variable {I}
lemma compatible_of_mem_maximal_atlas
{e e' : local_homeomorph M H} (he : e ∈ maximal_atlas I M) (he' : e' ∈ maximal_atlas I M) :
e.symm.trans e' ∈ cont_diff_groupoid ∞ I :=
structure_groupoid.compatible_of_mem_maximal_atlas he he'
/-- The product of two smooth manifolds with corners is naturally a smooth manifold with corners. -/
instance prod {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{E' : Type*} [normed_add_comm_group E'] [normed_space 𝕜 E']
{H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
{H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
(M : Type*) [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
(M' : Type*) [topological_space M'] [charted_space H' M'] [smooth_manifold_with_corners I' M'] :
smooth_manifold_with_corners (I.prod I') (M×M') :=
{ compatible :=
begin
rintros f g ⟨f1, f2, hf1, hf2, rfl⟩ ⟨g1, g2, hg1, hg2, rfl⟩,
rw [local_homeomorph.prod_symm, local_homeomorph.prod_trans],
have h1 := has_groupoid.compatible (cont_diff_groupoid ⊤ I) hf1 hg1,
have h2 := has_groupoid.compatible (cont_diff_groupoid ⊤ I') hf2 hg2,
exact cont_diff_groupoid_prod h1 h2,
end }
end smooth_manifold_with_corners
lemma local_homeomorph.singleton_smooth_manifold_with_corners
{𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
(e : local_homeomorph M H) (h : e.source = set.univ) :
@smooth_manifold_with_corners 𝕜 _ E _ _ H _ I M _ (e.singleton_charted_space h) :=
@smooth_manifold_with_corners.mk' _ _ _ _ _ _ _ _ _ _ (id _) $
e.singleton_has_groupoid h (cont_diff_groupoid ∞ I)
lemma open_embedding.singleton_smooth_manifold_with_corners
{𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M]
[nonempty M] {f : M → H} (h : open_embedding f) :
@smooth_manifold_with_corners 𝕜 _ E _ _ H _ I M _ h.singleton_charted_space :=
(h.to_local_homeomorph f).singleton_smooth_manifold_with_corners I (by simp)
namespace topological_space.opens
open topological_space
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M] [smooth_manifold_with_corners I M]
(s : opens M)
instance : smooth_manifold_with_corners I s := { ..s.has_groupoid (cont_diff_groupoid ∞ I) }
end topological_space.opens
section extended_charts
open_locale topological_space
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
{M : Type*} [topological_space M] [charted_space H M]
(x : M) {s t : set M}
/-!
### Extended charts
In a smooth manifold with corners, the model space is the space `H`. However, we will also
need to use extended charts taking values in the model vector space `E`. These extended charts are
not `local_homeomorph` as the target is not open in `E` in general, but we can still register them
as `local_equiv`.
-/
/-- The preferred extended chart on a manifold with corners around a point `x`, from a neighborhood
of `x` to the model vector space. -/
@[simp, mfld_simps] def ext_chart_at (x : M) : local_equiv M E :=
(chart_at H x).to_local_equiv.trans I.to_local_equiv
lemma ext_chart_at_coe : ⇑(ext_chart_at I x) = I ∘ chart_at H x := rfl
lemma ext_chart_at_coe_symm :
⇑(ext_chart_at I x).symm = (chart_at H x).symm ∘ I.symm := rfl
lemma ext_chart_at_source : (ext_chart_at I x).source = (chart_at H x).source :=
by rw [ext_chart_at, local_equiv.trans_source, I.source_eq, preimage_univ, inter_univ]
lemma ext_chart_at_open_source : is_open (ext_chart_at I x).source :=
by { rw ext_chart_at_source, exact (chart_at H x).open_source }
lemma mem_ext_chart_source : x ∈ (ext_chart_at I x).source :=
by simp only [ext_chart_at_source, mem_chart_source]
lemma ext_chart_at_target (x : M) : (ext_chart_at I x).target =
I.symm ⁻¹' (chart_at H x).target ∩ range I :=
by simp_rw [ext_chart_at, local_equiv.trans_target, I.target_eq, I.to_local_equiv_coe_symm,
inter_comm]
lemma ext_chart_at_to_inv :
(ext_chart_at I x).symm ((ext_chart_at I x) x) = x :=
(ext_chart_at I x).left_inv (mem_ext_chart_source I x)
lemma maps_to_ext_chart_at (hs : s ⊆ (chart_at H x).source) :
maps_to (ext_chart_at I x) s ((ext_chart_at I x).symm ⁻¹' s ∩ range I) :=
begin
rw [maps_to', ext_chart_at_coe, ext_chart_at_coe_symm, preimage_comp, ← I.image_eq, image_comp,
(chart_at H x).image_eq_target_inter_inv_preimage hs],
exact image_subset _ (inter_subset_right _ _)
end
lemma ext_chart_at_source_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝 x' :=
is_open.mem_nhds (ext_chart_at_open_source I x) h
lemma ext_chart_at_source_mem_nhds : (ext_chart_at I x).source ∈ 𝓝 x :=
ext_chart_at_source_mem_nhds' I x (mem_ext_chart_source I x)
lemma ext_chart_at_source_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).source ∈ 𝓝[s] x' :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds' I x h)
lemma ext_chart_at_source_mem_nhds_within :
(ext_chart_at I x).source ∈ 𝓝[s] x :=
mem_nhds_within_of_mem_nhds (ext_chart_at_source_mem_nhds I x)
lemma ext_chart_at_continuous_on :
continuous_on (ext_chart_at I x) (ext_chart_at I x).source :=
begin
refine I.continuous.comp_continuous_on _,
rw ext_chart_at_source,
exact (chart_at H x).continuous_on
end
lemma ext_chart_at_continuous_at' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x) x' :=
(ext_chart_at_continuous_on I x).continuous_at $ ext_chart_at_source_mem_nhds' I x h
lemma ext_chart_at_continuous_at : continuous_at (ext_chart_at I x) x :=
ext_chart_at_continuous_at' _ _ (mem_ext_chart_source I x)
lemma ext_chart_at_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
(chart_at H x).continuous_on_symm.comp I.continuous_on_symm $
(maps_to_preimage _ _).mono_left (inter_subset_right _ _)
lemma ext_chart_at_map_nhds' {x y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝 y) = 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [ext_chart_at_coe, (∘), ← I.map_nhds_eq, ← (chart_at H x).map_nhds_eq, map_map],
rwa ext_chart_at_source at hy
end
lemma ext_chart_at_map_nhds :
map (ext_chart_at I x) (𝓝 x) = 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds' I $ mem_ext_chart_source I x
lemma ext_chart_at_target_mem_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x y) :=
begin
rw [← local_equiv.image_source_eq_target, ← ext_chart_at_map_nhds' I hy],
exact image_mem_map (ext_chart_at_source_mem_nhds' _ _ hy)
end
lemma ext_chart_at_target_mem_nhds_within :
(ext_chart_at I x).target ∈ 𝓝[range I] (ext_chart_at I x x) :=
ext_chart_at_target_mem_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_target_subset_range : (ext_chart_at I x).target ⊆ range I :=
by simp only with mfld_simps
lemma nhds_within_ext_chart_target_eq' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
𝓝[(ext_chart_at I x).target] (ext_chart_at I x y) =
𝓝[range I] (ext_chart_at I x y) :=
(nhds_within_mono _ (ext_chart_at_target_subset_range _ _)).antisymm $
nhds_within_le_of_mem (ext_chart_at_target_mem_nhds_within' _ _ hy)
lemma nhds_within_ext_chart_target_eq :
𝓝[(ext_chart_at I x).target] ((ext_chart_at I x) x) =
𝓝[range I] ((ext_chart_at I x) x) :=
nhds_within_ext_chart_target_eq' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_at_symm'' {y : E} (h : y ∈ (ext_chart_at I x).target) :
continuous_at (ext_chart_at I x).symm y :=
continuous_at.comp ((chart_at H x).continuous_at_symm h.2) (I.continuous_symm.continuous_at)
lemma ext_chart_continuous_at_symm' {x' : M} (h : x' ∈ (ext_chart_at I x).source) :
continuous_at (ext_chart_at I x).symm (ext_chart_at I x x') :=
ext_chart_continuous_at_symm'' I _ $ (ext_chart_at I x).map_source h
lemma ext_chart_continuous_at_symm :
continuous_at (ext_chart_at I x).symm ((ext_chart_at I x) x) :=
ext_chart_continuous_at_symm' I x (mem_ext_chart_source I x)
lemma ext_chart_continuous_on_symm :
continuous_on (ext_chart_at I x).symm (ext_chart_at I x).target :=
λ y hy, (ext_chart_continuous_at_symm'' _ _ hy).continuous_within_at
lemma ext_chart_preimage_open_of_open' {s : set E} (hs : is_open s) :
is_open ((ext_chart_at I x).source ∩ ext_chart_at I x ⁻¹' s) :=
(ext_chart_at_continuous_on I x).preimage_open_of_open (ext_chart_at_open_source _ _) hs
lemma ext_chart_preimage_open_of_open {s : set E} (hs : is_open s) :
is_open ((chart_at H x).source ∩ ext_chart_at I x ⁻¹' s) :=
by { rw ← ext_chart_at_source I, exact ext_chart_preimage_open_of_open' I x hs }
lemma ext_chart_at_map_nhds_within_eq_image' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x y) :=
by set e := ext_chart_at I x;
calc map e (𝓝[s] y) = map e (𝓝[e.source ∩ s] y) :
congr_arg (map e) (nhds_within_inter_of_mem (ext_chart_at_source_mem_nhds_within' I x hy)).symm
... = 𝓝[e '' (e.source ∩ s)] (e y) :
((ext_chart_at I x).left_inv_on.mono $ inter_subset_left _ _).map_nhds_within_eq
((ext_chart_at I x).left_inv hy)
(ext_chart_continuous_at_symm' I x hy).continuous_within_at
(ext_chart_at_continuous_at' I x hy).continuous_within_at
lemma ext_chart_at_map_nhds_within_eq_image :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[ext_chart_at I x '' ((ext_chart_at I x).source ∩ s)] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within_eq_image' I x (mem_ext_chart_source I x)
lemma ext_chart_at_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x) (𝓝[s] y) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y) :=
by rw [ext_chart_at_map_nhds_within_eq_image' I x hy, nhds_within_inter,
← nhds_within_ext_chart_target_eq' _ _ hy, ← nhds_within_inter,
(ext_chart_at I x).image_source_inter_eq', inter_comm]
lemma ext_chart_at_map_nhds_within :
map (ext_chart_at I x) (𝓝[s] x) =
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x) :=
ext_chart_at_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x y)) = 𝓝[s] y :=
begin
rw [← ext_chart_at_map_nhds_within' I x hy, map_map, map_congr, map_id],
exact (ext_chart_at I x).left_inv_on.eq_on.eventually_eq_of_mem
(ext_chart_at_source_mem_nhds_within' _ _ hy)
end
lemma ext_chart_at_symm_map_nhds_within_range' {y : M} (hy : y ∈ (ext_chart_at I x).source) :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x y)) = 𝓝 y :=
by rw [← nhds_within_univ, ← ext_chart_at_symm_map_nhds_within' I x hy, preimage_univ, univ_inter]
lemma ext_chart_at_symm_map_nhds_within :
map (ext_chart_at I x).symm
(𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] (ext_chart_at I x x)) = 𝓝[s] x :=
ext_chart_at_symm_map_nhds_within' I x (mem_ext_chart_source I x)
lemma ext_chart_at_symm_map_nhds_within_range :
map (ext_chart_at I x).symm (𝓝[range I] (ext_chart_at I x x)) = 𝓝 x :=
ext_chart_at_symm_map_nhds_within_range' I x (mem_ext_chart_source I x)
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
in the source is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within' {x' : M} (h : x' ∈ (ext_chart_at I x).source)
(ht : t ∈ 𝓝[s] x') :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x') :=
by rwa [← ext_chart_at_symm_map_nhds_within' I x h, mem_map] at ht
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of the
base point is a neighborhood of the preimage, within a set. -/
lemma ext_chart_preimage_mem_nhds_within (ht : t ∈ 𝓝[s] x) :
(ext_chart_at I x).symm ⁻¹' t ∈
𝓝[(ext_chart_at I x).symm ⁻¹' s ∩ range I] ((ext_chart_at I x) x) :=
ext_chart_preimage_mem_nhds_within' I x (mem_ext_chart_source I x) ht
lemma ext_chart_preimage_mem_nhds' {x' : M} (h : x' ∈ (ext_chart_at I x).source) (ht : t ∈ 𝓝 x') :
(ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 (ext_chart_at I x x') :=
begin
apply (ext_chart_continuous_at_symm' I x h).preimage_mem_nhds,
rwa (ext_chart_at I x).left_inv h
end
/-- Technical lemma ensuring that the preimage under an extended chart of a neighborhood of a point
is a neighborhood of the preimage. -/
lemma ext_chart_preimage_mem_nhds (ht : t ∈ 𝓝 x) :
(ext_chart_at I x).symm ⁻¹' t ∈ 𝓝 ((ext_chart_at I x) x) :=
begin
apply (ext_chart_continuous_at_symm I x).preimage_mem_nhds,
rwa (ext_chart_at I x).left_inv (mem_ext_chart_source _ _)
end
/-- Technical lemma to rewrite suitably the preimage of an intersection under an extended chart, to
bring it into a convenient form to apply derivative lemmas. -/
lemma ext_chart_preimage_inter_eq :
((ext_chart_at I x).symm ⁻¹' (s ∩ t) ∩ range I)
= ((ext_chart_at I x).symm ⁻¹' s ∩ range I) ∩ ((ext_chart_at I x).symm ⁻¹' t) :=
by mfld_set_tac
/-! We use the name `ext_coord_change` for `(ext_chart_at I x').symm ≫ ext_chart_at I x`. -/
lemma ext_coord_change_source (x x' : M) :
((ext_chart_at I x').symm ≫ ext_chart_at I x).source =
I '' ((chart_at H x').symm ≫ₕ (chart_at H x)).source :=
by { simp_rw [local_equiv.trans_source, I.image_eq, ext_chart_at_source, local_equiv.symm_source,
ext_chart_at_target, inter_right_comm _ (range I)], refl }
lemma cont_diff_on_ext_coord_change [smooth_manifold_with_corners I M] (x x' : M) :
cont_diff_on 𝕜 ⊤ (ext_chart_at I x ∘ (ext_chart_at I x').symm)
((ext_chart_at I x').symm ≫ ext_chart_at I x).source :=
by { rw [ext_coord_change_source, I.image_eq], exact (has_groupoid.compatible
(cont_diff_groupoid ⊤ I) (chart_mem_atlas H x') (chart_mem_atlas H x)).1 }
lemma cont_diff_within_at_ext_coord_change [smooth_manifold_with_corners I M] (x x' : M) {y : E}
(hy : y ∈ ((ext_chart_at I x').symm ≫ ext_chart_at I x).source) :
cont_diff_within_at 𝕜 ⊤ (ext_chart_at I x ∘ (ext_chart_at I x').symm) (range I) y :=
begin
apply (cont_diff_on_ext_coord_change I x x' y hy).mono_of_mem,
rw [ext_coord_change_source] at hy ⊢,
obtain ⟨z, hz, rfl⟩ := hy,
exact I.image_mem_nhds_within ((local_homeomorph.open_source _).mem_nhds hz)
end
variable (𝕜)
lemma ext_chart_self_eq {x : H} : ⇑(ext_chart_at I x) = I := rfl
lemma ext_chart_self_apply {x y : H} : ext_chart_at I x y = I y := rfl
/-- In the case of the manifold structure on a vector space, the extended charts are just the
identity.-/
lemma ext_chart_model_space_eq_id (x : E) : ext_chart_at 𝓘(𝕜, E) x = local_equiv.refl E :=
by simp only with mfld_simps
lemma ext_chart_model_space_apply {x y : E} : ext_chart_at 𝓘(𝕜, E) x y = y := rfl
end extended_charts
|
bbb3a51a4451e737bc250bb02562d9887a2fc70f | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/topology/algebra/uniform_group.lean | e41c7ff2dfe75a3de602956b5d91aa618ebf84f1 | [
"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 | 19,981 | lean | /-
Copyright (c) 2018 Patrick Massot. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Patrick Massot, Johannes Hölzl
-/
import topology.uniform_space.uniform_embedding
import topology.uniform_space.complete_separated
import topology.algebra.group
import tactic.abel
/-!
# Uniform structure on topological groups
* `topological_add_group.to_uniform_space` and `topological_add_group_is_uniform` can be used to
construct a canonical uniformity for a topological add group.
* extension of ℤ-bilinear maps to complete groups (useful for ring completions)
* `add_group_with_zero_nhd`: construct the topological structure from a group with a neighbourhood
around zero. Then with `topological_add_group.to_uniform_space` one can derive a `uniform_space`.
-/
noncomputable theory
open_locale classical uniformity topological_space filter
section uniform_add_group
open filter set
variables {α : Type*} {β : Type*}
/-- A uniform (additive) group is a group in which the addition and negation are
uniformly continuous. -/
class uniform_add_group (α : Type*) [uniform_space α] [add_group α] : Prop :=
(uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2))
theorem uniform_add_group.mk' {α} [uniform_space α] [add_group α]
(h₁ : uniform_continuous (λp:α×α, p.1 + p.2))
(h₂ : uniform_continuous (λp:α, -p)) : uniform_add_group α :=
⟨by simpa only [sub_eq_add_neg] using
h₁.comp (uniform_continuous_fst.prod_mk (h₂.comp uniform_continuous_snd))⟩
variables [uniform_space α] [add_group α] [uniform_add_group α]
lemma uniform_continuous_sub : uniform_continuous (λp:α×α, p.1 - p.2) :=
uniform_add_group.uniform_continuous_sub
lemma uniform_continuous.sub [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x - g x) :=
uniform_continuous_sub.comp (hf.prod_mk hg)
lemma uniform_continuous.neg [uniform_space β] {f : β → α}
(hf : uniform_continuous f) : uniform_continuous (λx, - f x) :=
have uniform_continuous (λx, 0 - f x),
from uniform_continuous_const.sub hf,
by simp * at *
lemma uniform_continuous_neg : uniform_continuous (λx:α, - x) :=
uniform_continuous_id.neg
lemma uniform_continuous.add [uniform_space β] {f : β → α} {g : β → α}
(hf : uniform_continuous f) (hg : uniform_continuous g) : uniform_continuous (λx, f x + g x) :=
have uniform_continuous (λx, f x - - g x), from hf.sub hg.neg,
by simp [*, sub_eq_add_neg] at *
lemma uniform_continuous_add : uniform_continuous (λp:α×α, p.1 + p.2) :=
uniform_continuous_fst.add uniform_continuous_snd
@[priority 10]
instance uniform_add_group.to_topological_add_group : topological_add_group α :=
{ continuous_add := uniform_continuous_add.continuous,
continuous_neg := uniform_continuous_neg.continuous }
instance [uniform_space β] [add_group β] [uniform_add_group β] : uniform_add_group (α × β) :=
⟨((uniform_continuous_fst.comp uniform_continuous_fst).sub
(uniform_continuous_fst.comp uniform_continuous_snd)).prod_mk
((uniform_continuous_snd.comp uniform_continuous_fst).sub
(uniform_continuous_snd.comp uniform_continuous_snd))⟩
lemma uniformity_translate (a : α) : (𝓤 α).map (λx:α×α, (x.1 + a, x.2 + a)) = 𝓤 α :=
le_antisymm
(uniform_continuous_id.add uniform_continuous_const)
(calc 𝓤 α =
((𝓤 α).map (λx:α×α, (x.1 + -a, x.2 + -a))).map (λx:α×α, (x.1 + a, x.2 + a)) :
by simp [filter.map_map, (∘)]; exact filter.map_id.symm
... ≤ (𝓤 α).map (λx:α×α, (x.1 + a, x.2 + a)) :
filter.map_mono (uniform_continuous_id.add uniform_continuous_const))
lemma uniform_embedding_translate (a : α) : uniform_embedding (λx:α, x + a) :=
{ comap_uniformity := begin
rw [← uniformity_translate a, comap_map] {occs := occurrences.pos [1]},
rintros ⟨p₁, p₂⟩ ⟨q₁, q₂⟩,
simp [prod.eq_iff_fst_eq_snd_eq] {contextual := tt}
end,
inj := add_left_injective a }
section
variables (α)
lemma uniformity_eq_comap_nhds_zero : 𝓤 α = comap (λx:α×α, x.2 - x.1) (𝓝 (0:α)) :=
begin
rw [nhds_eq_comap_uniformity, filter.comap_comap],
refine le_antisymm (filter.map_le_iff_le_comap.1 _) _,
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invariant uniform_continuous_sub hs
with ⟨t, ht, hts⟩,
refine mem_map.2 (mem_sets_of_superset ht _),
rintros ⟨a, b⟩,
simpa [subset_def] using hts a b a },
{ assume s hs,
rcases mem_uniformity_of_uniform_continuous_invariant uniform_continuous_add hs
with ⟨t, ht, hts⟩,
refine ⟨_, ht, _⟩,
rintros ⟨a, b⟩, simpa [subset_def] using hts 0 (b - a) a }
end
end
lemma group_separation_rel (x y : α) : (x, y) ∈ separation_rel α ↔ x - y ∈ closure ({0} : set α) :=
have embedding (λa, a + (y - x)), from (uniform_embedding_translate (y - x)).embedding,
show (x, y) ∈ ⋂₀ (𝓤 α).sets ↔ x - y ∈ closure ({0} : set α),
begin
rw [this.closure_eq_preimage_closure_image, uniformity_eq_comap_nhds_zero α, sInter_comap_sets],
simp [mem_closure_iff_nhds, inter_singleton_nonempty, sub_eq_add_neg, add_assoc]
end
lemma uniform_continuous_of_tendsto_zero [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} [is_add_group_hom f] (h : tendsto f (𝓝 0) (𝓝 0)) :
uniform_continuous f :=
begin
have : ((λx:β×β, x.2 - x.1) ∘ (λx:α×α, (f x.1, f x.2))) = (λx:α×α, f (x.2 - x.1)),
{ simp only [is_add_group_hom.map_sub f] },
rw [uniform_continuous, uniformity_eq_comap_nhds_zero α, uniformity_eq_comap_nhds_zero β,
tendsto_comap_iff, this],
exact tendsto.comp h tendsto_comap
end
lemma add_monoid_hom.uniform_continuous_of_continuous_at_zero
[uniform_space β] [add_group β] [uniform_add_group β]
(f : α →+ β) (hf : continuous_at f 0) :
uniform_continuous f :=
uniform_continuous_of_tendsto_zero (by simpa using hf.tendsto)
lemma uniform_continuous_of_continuous [uniform_space β] [add_group β] [uniform_add_group β]
{f : α → β} [is_add_group_hom f] (h : continuous f) :
uniform_continuous f :=
uniform_continuous_of_tendsto_zero $
suffices tendsto f (𝓝 0) (𝓝 (f 0)), by rwa [is_add_group_hom.map_zero f] at this,
h.tendsto 0
end uniform_add_group
section topological_add_comm_group
universes u v w x
open filter
variables {G : Type u} [add_comm_group G] [topological_space G] [topological_add_group G]
variable (G)
/-- The right uniformity on a topological group. -/
def topological_add_group.to_uniform_space : uniform_space G :=
{ uniformity := comap (λp:G×G, p.2 - p.1) (𝓝 0),
refl :=
by refine map_le_iff_le_comap.1 (le_trans _ (pure_le_nhds 0));
simp [set.subset_def] {contextual := tt},
symm :=
begin
suffices : tendsto ((λp, -p) ∘ (λp:G×G, p.2 - p.1)) (comap (λp:G×G, p.2 - p.1) (𝓝 0)) (𝓝 (-0)),
{ simpa [(∘), tendsto_comap_iff] },
exact tendsto.comp (tendsto.neg tendsto_id) tendsto_comap
end,
comp :=
begin
intros D H,
rw mem_lift'_sets,
{ rcases H with ⟨U, U_nhds, U_sub⟩,
rcases exists_nhds_zero_half U_nhds with ⟨V, ⟨V_nhds, V_sum⟩⟩,
existsi ((λp:G×G, p.2 - p.1) ⁻¹' V),
have H : (λp:G×G, p.2 - p.1) ⁻¹' V ∈ comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)),
by existsi [V, V_nhds] ; refl,
existsi H,
have comp_rel_sub :
comp_rel ((λp:G×G, p.2 - p.1) ⁻¹' V) ((λp, p.2 - p.1) ⁻¹' V) ⊆ (λp:G×G, p.2 - p.1) ⁻¹' U,
begin
intros p p_comp_rel,
rcases p_comp_rel with ⟨z, ⟨Hz1, Hz2⟩⟩,
simpa [sub_eq_add_neg, add_comm, add_left_comm] using V_sum _ Hz1 _ Hz2
end,
exact set.subset.trans comp_rel_sub U_sub },
{ exact monotone_comp_rel monotone_id monotone_id }
end,
is_open_uniformity :=
begin
intro S,
let S' := λ x, {p : G × G | p.1 = x → p.2 ∈ S},
show is_open S ↔ ∀ (x : G), x ∈ S → S' x ∈ comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)),
rw [is_open_iff_mem_nhds],
refine forall_congr (assume a, forall_congr (assume ha, _)),
rw [← nhds_translation a, mem_comap_sets, mem_comap_sets],
refine exists_congr (assume t, exists_congr (assume ht, _)),
show (λ (y : G), y - a) ⁻¹' t ⊆ S ↔ (λ (p : G × G), p.snd - p.fst) ⁻¹' t ⊆ S' a,
split,
{ rintros h ⟨x, y⟩ hx rfl, exact h hx },
{ rintros h x hx, exact @h (a, x) hx rfl }
end }
section
local attribute [instance] topological_add_group.to_uniform_space
lemma uniformity_eq_comap_nhds_zero' : 𝓤 G = comap (λp:G×G, p.2 - p.1) (𝓝 (0 : G)) := rfl
variable {G}
lemma topological_add_group_is_uniform : uniform_add_group G :=
have tendsto
((λp:(G×G), p.1 - p.2) ∘ (λp:(G×G)×(G×G), (p.1.2 - p.1.1, p.2.2 - p.2.1)))
(comap (λp:(G×G)×(G×G), (p.1.2 - p.1.1, p.2.2 - p.2.1)) ((𝓝 0).prod (𝓝 0)))
(𝓝 (0 - 0)) :=
(tendsto_fst.sub tendsto_snd).comp tendsto_comap,
begin
constructor,
rw [uniform_continuous, uniformity_prod_eq_prod, tendsto_map'_iff,
uniformity_eq_comap_nhds_zero' G, tendsto_comap_iff, prod_comap_comap_eq],
simpa [(∘), sub_eq_add_neg, add_comm, add_left_comm] using this
end
end
lemma to_uniform_space_eq {G : Type*} [u : uniform_space G] [add_comm_group G]
[uniform_add_group G] :
topological_add_group.to_uniform_space G = u :=
begin
ext : 1,
show @uniformity G (topological_add_group.to_uniform_space G) = 𝓤 G,
rw [uniformity_eq_comap_nhds_zero' G, uniformity_eq_comap_nhds_zero G]
end
end topological_add_comm_group
namespace add_comm_group
section Z_bilin
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables [add_comm_group α] [add_comm_group β] [add_comm_group γ]
/- TODO: when modules are changed to have more explicit base ring, then change replace `is_Z_bilin`
by using `is_bilinear_map ℤ` from `tensor_product`. -/
/-- `ℤ`-bilinearity for maps between additive commutative groups. -/
class is_Z_bilin (f : α × β → γ) : Prop :=
(add_left [] : ∀ a a' b, f (a + a', b) = f (a, b) + f (a', b))
(add_right [] : ∀ a b b', f (a, b + b') = f (a, b) + f (a, b'))
variables (f : α × β → γ) [is_Z_bilin f]
lemma is_Z_bilin.comp_hom {g : γ → δ} [add_comm_group δ] [is_add_group_hom g] :
is_Z_bilin (g ∘ f) :=
by constructor; simp [(∘), is_Z_bilin.add_left f, is_Z_bilin.add_right f, is_add_hom.map_add g]
instance is_Z_bilin.comp_swap : is_Z_bilin (f ∘ prod.swap) :=
⟨λ a a' b, is_Z_bilin.add_right f b a a',
λ a b b', is_Z_bilin.add_left f b b' a⟩
lemma is_Z_bilin.zero_left : ∀ b, f (0, b) = 0 :=
begin
intro b,
apply add_right_eq_self.1,
rw [ ←is_Z_bilin.add_left f, zero_add]
end
lemma is_Z_bilin.zero_right : ∀ a, f (a, 0) = 0 :=
is_Z_bilin.zero_left (f ∘ prod.swap)
lemma is_Z_bilin.zero : f (0, 0) = 0 :=
is_Z_bilin.zero_left f 0
lemma is_Z_bilin.neg_left : ∀ a b, f (-a, b) = -f (a, b) :=
begin
intros a b,
apply eq_of_sub_eq_zero,
rw [sub_eq_add_neg, neg_neg, ←is_Z_bilin.add_left f, neg_add_self, is_Z_bilin.zero_left f]
end
lemma is_Z_bilin.neg_right : ∀ a b, f (a, -b) = -f (a, b) :=
assume a b, is_Z_bilin.neg_left (f ∘ prod.swap) b a
lemma is_Z_bilin.sub_left : ∀ a a' b, f (a - a', b) = f (a, b) - f (a', b) :=
begin
intros,
simp [sub_eq_add_neg],
rw [is_Z_bilin.add_left f, is_Z_bilin.neg_left f]
end
lemma is_Z_bilin.sub_right : ∀ a b b', f (a, b - b') = f (a, b) - f (a,b') :=
assume a b b', is_Z_bilin.sub_left (f ∘ prod.swap) b b' a
end Z_bilin
end add_comm_group
open add_comm_group filter set function
section
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
-- α, β and G are abelian topological groups, G is a uniform space
variables [topological_space α] [add_comm_group α]
variables [topological_space β] [add_comm_group β]
variables {G : Type*} [uniform_space G] [add_comm_group G]
variables {ψ : α × β → G} (hψ : continuous ψ) [ψbilin : is_Z_bilin ψ]
include hψ ψbilin
lemma is_Z_bilin.tendsto_zero_left (x₁ : α) : tendsto ψ (𝓝 (x₁, 0)) (𝓝 0) :=
begin
have := hψ.tendsto (x₁, 0),
rwa [is_Z_bilin.zero_right ψ] at this
end
lemma is_Z_bilin.tendsto_zero_right (y₁ : β) : tendsto ψ (𝓝 (0, y₁)) (𝓝 0) :=
begin
have := hψ.tendsto (0, y₁),
rwa [is_Z_bilin.zero_left ψ] at this
end
end
section
variables {α : Type*} {β : Type*}
variables [topological_space α] [add_comm_group α] [topological_add_group α]
-- β is a dense subgroup of α, inclusion is denoted by e
variables [topological_space β] [add_comm_group β]
variables {e : β → α} [is_add_group_hom e] (de : dense_inducing e)
include de
lemma tendsto_sub_comap_self (x₀ : α) :
tendsto (λt:β×β, t.2 - t.1) (comap (λp:β×β, (e p.1, e p.2)) $ 𝓝 (x₀, x₀)) (𝓝 0) :=
begin
have comm : (λx:α×α, x.2-x.1) ∘ (λt:β×β, (e t.1, e t.2)) = e ∘ (λt:β×β, t.2 - t.1),
{ ext t,
change e t.2 - e t.1 = e (t.2 - t.1),
rwa ← is_add_group_hom.map_sub e t.2 t.1 },
have lim : tendsto (λ x : α × α, x.2-x.1) (𝓝 (x₀, x₀)) (𝓝 (e 0)),
{ have := (continuous_sub.comp (@continuous_swap α α _ _)).tendsto (x₀, x₀),
simpa [-sub_eq_add_neg, sub_self, eq.symm (is_add_group_hom.map_zero e)] using this },
have := de.tendsto_comap_nhds_nhds lim comm,
simp [-sub_eq_add_neg, this]
end
end
namespace dense_inducing
variables {α : Type*} {β : Type*} {γ : Type*} {δ : Type*}
variables {G : Type*}
-- β is a dense subgroup of α, inclusion is denoted by e
-- δ is a dense subgroup of γ, inclusion is denoted by f
variables [topological_space α] [add_comm_group α] [topological_add_group α]
variables [topological_space β] [add_comm_group β] [topological_add_group β]
variables [topological_space γ] [add_comm_group γ] [topological_add_group γ]
variables [topological_space δ] [add_comm_group δ] [topological_add_group δ]
variables [uniform_space G] [add_comm_group G] [uniform_add_group G] [separated_space G]
[complete_space G]
variables {e : β → α} [is_add_group_hom e] (de : dense_inducing e)
variables {f : δ → γ} [is_add_group_hom f] (df : dense_inducing f)
variables {φ : β × δ → G} (hφ : continuous φ) [bilin : is_Z_bilin φ]
include de df hφ bilin
variables {W' : set G} (W'_nhd : W' ∈ 𝓝 (0 : G))
include W'_nhd
private lemma extend_Z_bilin_aux (x₀ : α) (y₁ : δ) :
∃ U₂ ∈ comap e (𝓝 x₀), ∀ x x' ∈ U₂, φ (x' - x, y₁) ∈ W' :=
begin
let Nx := 𝓝 x₀,
let ee := λ u : β × β, (e u.1, e u.2),
have lim1 : tendsto (λ a : β × β, (a.2 - a.1, y₁)) (comap e Nx ×ᶠ comap e Nx) (𝓝 (0, y₁)),
{ have := tendsto.prod_mk (tendsto_sub_comap_self de x₀)
(tendsto_const_nhds : tendsto (λ (p : β × β), y₁) (comap ee $ 𝓝 (x₀, x₀)) (𝓝 y₁)),
rw [nhds_prod_eq, prod_comap_comap_eq, ←nhds_prod_eq],
exact (this : _) },
have lim := tendsto.comp (is_Z_bilin.tendsto_zero_right hφ y₁) lim1,
rw tendsto_prod_self_iff at lim,
exact lim W' W'_nhd,
end
private lemma extend_Z_bilin_key (x₀ : α) (y₀ : γ) :
∃ U ∈ comap e (𝓝 x₀), ∃ V ∈ comap f (𝓝 y₀),
∀ x x' ∈ U, ∀ y y' ∈ V, φ (x', y') - φ (x, y) ∈ W' :=
begin
let Nx := 𝓝 x₀,
let Ny := 𝓝 y₀,
let dp := dense_inducing.prod de df,
let ee := λ u : β × β, (e u.1, e u.2),
let ff := λ u : δ × δ, (f u.1, f u.2),
have lim_φ : filter.tendsto φ (𝓝 (0, 0)) (𝓝 0),
{ have := hφ.tendsto (0, 0),
rwa [is_Z_bilin.zero φ] at this },
have lim_φ_sub_sub : tendsto (λ (p : (β × β) × (δ × δ)), φ (p.1.2 - p.1.1, p.2.2 - p.2.1))
((comap ee $ 𝓝 (x₀, x₀)) ×ᶠ (comap ff $ 𝓝 (y₀, y₀))) (𝓝 0),
{ have lim_sub_sub : tendsto (λ (p : (β × β) × δ × δ), (p.1.2 - p.1.1, p.2.2 - p.2.1))
((comap ee (𝓝 (x₀, x₀))) ×ᶠ (comap ff (𝓝 (y₀, y₀)))) (𝓝 0 ×ᶠ 𝓝 0),
{ have := filter.prod_mono (tendsto_sub_comap_self de x₀) (tendsto_sub_comap_self df y₀),
rwa prod_map_map_eq at this },
rw ← nhds_prod_eq at lim_sub_sub,
exact tendsto.comp lim_φ lim_sub_sub },
rcases exists_nhds_zero_quarter W'_nhd with ⟨W, W_nhd, W4⟩,
have : ∃ U₁ ∈ comap e (𝓝 x₀), ∃ V₁ ∈ comap f (𝓝 y₀),
∀ x x' ∈ U₁, ∀ y y' ∈ V₁, φ (x'-x, y'-y) ∈ W,
{ have := tendsto_prod_iff.1 lim_φ_sub_sub W W_nhd,
repeat { rw [nhds_prod_eq, ←prod_comap_comap_eq] at this },
rcases this with ⟨U, U_in, V, V_in, H⟩,
rw [mem_prod_same_iff] at U_in V_in,
rcases U_in with ⟨U₁, U₁_in, HU₁⟩,
rcases V_in with ⟨V₁, V₁_in, HV₁⟩,
existsi [U₁, U₁_in, V₁, V₁_in],
intros x x' x_in x'_in y y' y_in y'_in,
exact H _ _ (HU₁ (mk_mem_prod x_in x'_in)) (HV₁ (mk_mem_prod y_in y'_in)) },
rcases this with ⟨U₁, U₁_nhd, V₁, V₁_nhd, H⟩,
obtain ⟨x₁, x₁_in⟩ : U₁.nonempty :=
((de.comap_nhds_ne_bot _).nonempty_of_mem U₁_nhd),
obtain ⟨y₁, y₁_in⟩ : V₁.nonempty :=
((df.comap_nhds_ne_bot _).nonempty_of_mem V₁_nhd),
rcases (extend_Z_bilin_aux de df hφ W_nhd x₀ y₁) with ⟨U₂, U₂_nhd, HU⟩,
rcases (extend_Z_bilin_aux df de (hφ.comp continuous_swap) W_nhd y₀ x₁) with ⟨V₂, V₂_nhd, HV⟩,
existsi [U₁ ∩ U₂, inter_mem_sets U₁_nhd U₂_nhd,
V₁ ∩ V₂, inter_mem_sets V₁_nhd V₂_nhd],
rintros x x' ⟨xU₁, xU₂⟩ ⟨x'U₁, x'U₂⟩ y y' ⟨yV₁, yV₂⟩ ⟨y'V₁, y'V₂⟩,
have key_formula : φ(x', y') - φ(x, y) =
φ(x' - x, y₁) + φ(x' - x, y' - y₁) + φ(x₁, y' - y) + φ(x - x₁, y' - y),
{ repeat { rw is_Z_bilin.sub_left φ },
repeat { rw is_Z_bilin.sub_right φ },
apply eq_of_sub_eq_zero,
simp [sub_eq_add_neg], abel },
rw key_formula,
have h₁ := HU x x' xU₂ x'U₂,
have h₂ := H x x' xU₁ x'U₁ y₁ y' y₁_in y'V₁,
have h₃ := HV y y' yV₂ y'V₂,
have h₄ := H x₁ x x₁_in xU₁ y y' yV₁ y'V₁,
exact W4 h₁ h₂ h₃ h₄
end
omit W'_nhd
open dense_inducing
/-- Bourbaki GT III.6.5 Theorem I:
ℤ-bilinear continuous maps from dense images into a complete Hausdorff group extend by continuity.
Note: Bourbaki assumes that α and β are also complete Hausdorff, but this is not necessary. -/
theorem extend_Z_bilin : continuous (extend (de.prod df) φ) :=
begin
refine continuous_extend_of_cauchy _ _,
rintro ⟨x₀, y₀⟩,
split,
{ apply ne_bot.map,
apply comap_ne_bot,
intros U h,
rcases mem_closure_iff_nhds.1 ((de.prod df).dense (x₀, y₀)) U h with ⟨x, x_in, ⟨z, z_x⟩⟩,
existsi z,
cc },
{ suffices : map (λ (p : (β × δ) × (β × δ)), φ p.2 - φ p.1)
(comap (λ (p : (β × δ) × β × δ), ((e p.1.1, f p.1.2), (e p.2.1, f p.2.2)))
(𝓝 (x₀, y₀) ×ᶠ 𝓝 (x₀, y₀))) ≤ 𝓝 0,
by rwa [uniformity_eq_comap_nhds_zero G, prod_map_map_eq, ←map_le_iff_le_comap, filter.map_map,
prod_comap_comap_eq],
intros W' W'_nhd,
have key := extend_Z_bilin_key de df hφ W'_nhd x₀ y₀,
rcases key with ⟨U, U_nhd, V, V_nhd, h⟩,
rw mem_comap_sets at U_nhd,
rcases U_nhd with ⟨U', U'_nhd, U'_sub⟩,
rw mem_comap_sets at V_nhd,
rcases V_nhd with ⟨V', V'_nhd, V'_sub⟩,
rw [mem_map, mem_comap_sets, nhds_prod_eq],
existsi set.prod (set.prod U' V') (set.prod U' V'),
rw mem_prod_same_iff,
simp only [exists_prop],
split,
{ change U' ∈ 𝓝 x₀ at U'_nhd,
change V' ∈ 𝓝 y₀ at V'_nhd,
have := prod_mem_prod U'_nhd V'_nhd,
tauto },
{ intros p h',
simp only [set.mem_preimage, set.prod_mk_mem_set_prod_eq] at h',
rcases p with ⟨⟨x, y⟩, ⟨x', y'⟩⟩,
apply h ; tauto } }
end
end dense_inducing
|
974baa9108506714fb8fb28f4301989ff3803a1b | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/algebra/group/to_additive.lean | b6d05ff9c0ea8ac67d2c5cb73bdb470728bd395d | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 13,229 | lean | /-
Copyright (c) 2017 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Yury Kudryashov
-/
import tactic.transform_decl
import tactic.algebra
/-!
# Transport multiplicative to additive
This file defines an attribute `to_additive` that can be used to
automatically transport theorems and definitions (but not inductive
types and structures) from a multiplicative theory to an additive theory.
Usage information is contained in the doc string of `to_additive.attr`.
### Missing features
* Automatically transport structures and other inductive types.
* For structures, automatically generate theorems like `group α ↔
add_group (additive α)`.
* Rewrite rules for the last part of the name that work in more
cases. E.g., we can replace `monoid` with `add_monoid` etc.
-/
namespace to_additive
open tactic exceptional
section performance_hack -- see Note [user attribute parameters]
local attribute [semireducible] reflected
local attribute [instance, priority 9000]
private meta def hacky_name_reflect : has_reflect name :=
λ n, `(id %%(expr.const n []) : name)
/-- An auxiliary attribute used to store the names of the additive versions of declarations
that have been processed by `to_additive`. -/
@[user_attribute]
private meta def aux_attr : user_attribute (name_map name) name :=
{ name := `to_additive_aux,
descr := "Auxiliary attribute for `to_additive`. DON'T USE IT",
cache_cfg := ⟨λ ns,
ns.mfoldl
(λ dict n', do
let n := match n' with
| name.mk_string s pre := if s = "_to_additive" then pre else n'
| _ := n'
end,
param ← aux_attr.get_param_untyped n',
pure $ dict.insert n param.app_arg.const_name)
mk_name_map, []⟩,
parser := lean.parser.ident }
end performance_hack
/-- A command that can be used to have future uses of `to_additive` change the `src` namespace
to the `tgt` namespace.
For example:
```
run_cmd to_additive.map_namespace `quotient_group `quotient_add_group
```
Later uses of `to_additive` on declarations in the `quotient_group` namespace will be created
in the `quotient_add_group` namespaces.
-/
meta def map_namespace (src tgt : name) : command :=
do let n := src.mk_string "_to_additive",
let decl := declaration.thm n [] `(unit) (pure (reflect ())),
add_decl decl,
aux_attr.set n tgt tt
/-- `value_type` is the type of the arguments that can be provided to `to_additive`.
`to_additive.parser` parses the provided arguments into `name` for the target and an
optional doc string. -/
@[derive has_reflect, derive inhabited]
structure value_type : Type := (tgt : name) (doc : option string)
/-- `add_comm_prefix x s` returns `"comm_" ++ s` if `x = tt` and `s` otherwise. -/
meta def add_comm_prefix : bool → string → string
| tt s := ("comm_" ++ s)
| ff s := s
/-- Dictionary used by `to_additive.guess_name` to autogenerate names. -/
meta def tr : bool → list string → list string
| is_comm ("one" :: "le" :: s) := add_comm_prefix is_comm "nonneg" :: tr ff s
| is_comm ("one" :: "lt" :: s) := add_comm_prefix is_comm "pos" :: tr ff s
| is_comm ("le" :: "one" :: s) := add_comm_prefix is_comm "nonpos" :: tr ff s
| is_comm ("lt" :: "one" :: s) := add_comm_prefix is_comm "neg" :: tr ff s
| is_comm ("mul" :: "support" :: s) := add_comm_prefix is_comm "support" :: tr ff s
| is_comm ("mul" :: "indicator" :: s) := add_comm_prefix is_comm "indicator" :: tr ff s
| is_comm ("mul" :: s) := add_comm_prefix is_comm "add" :: tr ff s
| is_comm ("smul" :: s) := add_comm_prefix is_comm "vadd" :: tr ff s
| is_comm ("inv" :: s) := add_comm_prefix is_comm "neg" :: tr ff s
| is_comm ("div" :: s) := add_comm_prefix is_comm "sub" :: tr ff s
| is_comm ("one" :: s) := add_comm_prefix is_comm "zero" :: tr ff s
| is_comm ("prod" :: s) := add_comm_prefix is_comm "sum" :: tr ff s
| is_comm ("finprod" :: s) := add_comm_prefix is_comm "finsum" :: tr ff s
| is_comm ("monoid" :: s) := ("add_" ++ add_comm_prefix is_comm "monoid") :: tr ff s
| is_comm ("submonoid" :: s) := ("add_" ++ add_comm_prefix is_comm "submonoid") :: tr ff s
| is_comm ("group" :: s) := ("add_" ++ add_comm_prefix is_comm "group") :: tr ff s
| is_comm ("subgroup" :: s) := ("add_" ++ add_comm_prefix is_comm "subgroup") :: tr ff s
| is_comm ("semigroup" :: s) := ("add_" ++ add_comm_prefix is_comm "semigroup") :: tr ff s
| is_comm ("magma" :: s) := ("add_" ++ add_comm_prefix is_comm "magma") :: tr ff s
| is_comm ("comm" :: s) := tr tt s
| is_comm (x :: s) := (add_comm_prefix is_comm x :: tr ff s)
| tt [] := ["comm"]
| ff [] := []
/-- Autogenerate target name for `to_additive`. -/
meta def guess_name : string → string :=
string.map_tokens ''' $
λ s, string.intercalate (string.singleton '_') $
tr ff (s.split_on '_')
/-- Return the provided target name or autogenerate one if one was not provided. -/
meta def target_name (src tgt : name) (dict : name_map name) : tactic name :=
(if tgt.get_prefix ≠ name.anonymous -- `tgt` is a full name
then pure tgt
else match src with
| (name.mk_string s pre) :=
do let tgt_auto := guess_name s,
guard (tgt.to_string ≠ tgt_auto)
<|> trace ("`to_additive " ++ src.to_string ++ "`: correctly autogenerated target " ++
"name, you may remove the explicit " ++ tgt_auto ++ " argument."),
pure $ name.mk_string
(if tgt = name.anonymous then tgt_auto else tgt.to_string)
(pre.map_prefix dict.find)
| _ := fail ("to_additive: can't transport " ++ src.to_string)
end) >>=
(λ res,
if res = src
then fail ("to_additive: can't transport " ++ src.to_string ++ " to itself")
else pure res)
/-- the parser for the arguments to `to_additive` -/
meta def parser : lean.parser value_type :=
do
tgt ← optional lean.parser.ident,
e ← optional interactive.types.texpr,
doc ← match e with
| some pe := some <$> ((to_expr pe >>= eval_expr string) : tactic string)
| none := pure none
end,
return ⟨tgt.get_or_else name.anonymous, doc⟩
private meta def proceed_fields_aux (src tgt : name) (prio : ℕ) (f : name → tactic (list string)) :
command :=
do
src_fields ← f src,
tgt_fields ← f tgt,
guard (src_fields.length = tgt_fields.length) <|>
fail ("Failed to map fields of " ++ src.to_string),
(src_fields.zip tgt_fields).mmap' $
λ names, guard (names.fst = names.snd) <|>
aux_attr.set (src.append names.fst) (tgt.append names.snd) tt prio
/-- Add the `aux_attr` attribute to the structure fields of `src`
so that future uses of `to_additive` will map them to the corresponding `tgt` fields. -/
meta def proceed_fields (env : environment) (src tgt : name) (prio : ℕ) : command :=
let aux := proceed_fields_aux src tgt prio in
do
aux (λ n, pure $ list.map name.to_string $ (env.structure_fields n).get_or_else []) >>
aux (λ n, (list.map (λ (x : name), "to_" ++ x.to_string) <$> get_tagged_ancestors n)) >>
aux (λ n, (env.constructors_of n).mmap $
λ cs, match cs with
| (name.mk_string s pre) :=
(guard (pre = n) <|> fail "Bad constructor name") >>
pure s
| _ := fail "Bad constructor name"
end)
/--
The attribute `to_additive` can be used to automatically transport theorems
and definitions (but not inductive types and structures) from a multiplicative
theory to an additive theory.
To use this attribute, just write:
```
@[to_additive]
theorem mul_comm' {α} [comm_semigroup α] (x y : α) : x * y = y * x := comm_semigroup.mul_comm
```
This code will generate a theorem named `add_comm'`. It is also
possible to manually specify the name of the new declaration, and
provide a documentation string:
```
@[to_additive add_foo "add_foo doc string"]
/-- foo doc string -/
theorem foo := sorry
```
The transport tries to do the right thing in most cases using several
heuristics described below. However, in some cases it fails, and
requires manual intervention.
If the declaration to be transported has attributes which need to be
copied to the additive version, then `to_additive` should come last:
```
@[simp, to_additive] lemma mul_one' {G : Type*} [group G] (x : G) : x * 1 = x := mul_one x
```
The exception to this rule is the `simps` attribute, which should come after `to_additive`:
```
@[to_additive, simps]
instance {M N} [has_mul M] [has_mul N] : has_mul (M × N) := ⟨λ p q, ⟨p.1 * q.1, p.2 * q.2⟩⟩
```
## Implementation notes
The transport process generally works by taking all the names of
identifiers appearing in the name, type, and body of a declaration and
creating a new declaration by mapping those names to additive versions
using a simple string-based dictionary and also using all declarations
that have previously been labeled with `to_additive`.
In the `mul_comm'` example above, `to_additive` maps:
* `mul_comm'` to `add_comm'`,
* `comm_semigroup` to `add_comm_semigroup`,
* `x * y` to `x + y` and `y * x` to `y + x`, and
* `comm_semigroup.mul_comm'` to `add_comm_semigroup.add_comm'`.
Even when `to_additive` is unable to automatically generate the additive
version of a declaration, it can be useful to apply the attribute manually:
```
attribute [to_additive foo_add_bar] foo_bar
```
This will allow future uses of `to_additive` to recognize that
`foo_bar` should be replaced with `foo_add_bar`.
### Handling of hidden definitions
Before transporting the “main” declaration `src`, `to_additive` first
scans its type and value for names starting with `src`, and transports
them. This includes auxiliary definitions like `src._match_1`,
`src._proof_1`.
After transporting the “main” declaration, `to_additive` transports
its equational lemmas.
### Structure fields and constructors
If `src` is a structure, then `to_additive` automatically adds
structure fields to its mapping, and similarly for constructors of
inductive types.
For new structures this means that `to_additive` automatically handles
coercions, and for old structures it does the same, if ancestry
information is present in `@[ancestor]` attributes. The `ancestor`
attribute must come before the `to_additive` attribute, and it is
essential that the order of the base structures passed to `ancestor` matches
between the multiplicative and additive versions of the structure.
### Name generation
* If `@[to_additive]` is called without a `name` argument, then the
new name is autogenerated. First, it takes the longest prefix of
the source name that is already known to `to_additive`, and replaces
this prefix with its additive counterpart. Second, it takes the last
part of the name (i.e., after the last dot), and replaces common
name parts (“mul”, “one”, “inv”, “prod”) with their additive versions.
* Namespaces can be transformed using `map_namespace`. For example:
```
run_cmd to_additive.map_namespace `quotient_group `quotient_add_group
```
Later uses of `to_additive` on declarations in the `quotient_group`
namespace will be created in the `quotient_add_group` namespaces.
* If `@[to_additive]` is called with a `name` argument `new_name`
/without a dot/, then `to_additive` updates the prefix as described
above, then replaces the last part of the name with `new_name`.
* If `@[to_additive]` is called with a `name` argument
`new_namespace.new_name` /with a dot/, then `to_additive` uses this
new name as is.
As a safety check, in the first two cases `to_additive` double checks
that the new name differs from the original one.
-/
@[user_attribute]
protected meta def attr : user_attribute unit value_type :=
{ name := `to_additive,
descr := "Transport multiplicative to additive",
parser := parser,
after_set := some $ λ src prio persistent, do
guard persistent <|> fail "`to_additive` can't be used as a local attribute",
env ← get_env,
val ← attr.get_param src,
dict ← aux_attr.get_cache,
tgt ← target_name src val.tgt dict,
aux_attr.set src tgt tt,
let dict := dict.insert src tgt,
if env.contains tgt
then proceed_fields env src tgt prio
else do
transform_decl_with_prefix_dict dict src tgt
[`reducible, `simp, `instance, `refl, `symm, `trans, `elab_as_eliminator, `no_rsimp],
match val.doc with
| some doc := add_doc_string tgt doc
| none := skip
end }
add_tactic_doc
{ name := "to_additive",
category := doc_category.attr,
decl_names := [`to_additive.attr],
tags := ["transport", "environment", "lemma derivation"] }
end to_additive
/- map operations -/
attribute [to_additive] has_mul has_one has_inv has_div
|
eaa4e04cacda1dd054d6ef7a58f857f4b0cbfe82 | 01ae0d022f2e2fefdaaa898938c1ac1fbce3b3ab | /categories/path_category.lean | f347aeaa7225e826b5a72776f3da5d4d3e65d046 | [] | no_license | PatrickMassot/lean-category-theory | 0f56a83464396a253c28a42dece16c93baf8ad74 | ef239978e91f2e1c3b8e88b6e9c64c155dc56c99 | refs/heads/master | 1,629,739,187,316 | 1,512,422,659,000 | 1,512,422,659,000 | 113,098,786 | 0 | 0 | null | 1,512,424,022,000 | 1,512,424,022,000 | null | UTF-8 | Lean | false | false | 2,738 | lean | -- Copyright (c) 2017 Scott Morrison. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Authors: Stephen Morgan and Scott Morrison
import .functor
import .graphs
open categories
universe variables u v
namespace categories.graphs
definition PathCategory ( G : Graph ) : Category :=
{
Obj := G.Obj,
Hom := λ x y, path x y,
identity := λ x, path.nil x,
compose := λ _ _ _ f g, concatenate_paths f g,
left_identity := ♮,
right_identity := begin
tidy,
induction f,
{
-- when f is nil
trivial,
},
{
-- when f is cons
exact congr_arg (λ p, path.cons e p) ih_1
}
end,
associativity := begin
tidy,
induction f,
{
-- when f is nil
trivial,
},
{
-- when f is cons
exact congr_arg (λ p, path.cons e p) (ih_1 g)
}
end
}
open categories.functor
definition path_to_morphism
{ G : Graph }
{ C : Category }
( H : GraphHomomorphism G C.graph )
: Π { X Y : G.Obj }, path X Y → C.Hom (H.onObjects X) (H.onObjects Y)
| ._ ._ (path.nil Z) := C.identity (H.onObjects Z)
| ._ ._ (@path.cons ._ _ _ _ e p) := C.compose (H.onMorphisms e) (path_to_morphism p)
-- PROJECT obtain this as the left adjoint to the forgetful functor.
definition Functor.from_GraphHomomorphism { G : Graph } { C : Category } ( H : GraphHomomorphism G C.graph ) : Functor (PathCategory G) C :=
{
onObjects := H.onObjects,
onMorphisms := λ _ _ f, path_to_morphism H f,
identities := ♮,
functoriality := begin
-- PROJECT automation
tidy,
induction f,
{
unfold concatenate_paths,
unfold path_to_morphism,
tidy,
},
{
let p := ih_1 g,
unfold concatenate_paths,
unfold path_to_morphism,
blast,
}
end
}
instance GraphHomomorphism_to_Functor_coercion { G : Graph } { C : Category }: has_coe (GraphHomomorphism G C.graph) (Functor (PathCategory G) C) :=
{ coe := Functor.from_GraphHomomorphism }
end categories.graphs
|
99b4bf521af0dcfe572778e7428c6416aedc7526 | 302c785c90d40ad3d6be43d33bc6a558354cc2cf | /src/data/equiv/mul_add_aut.lean | 2a17de1a9a699365d1389811b41228eb5ddb1a9d | [
"Apache-2.0"
] | permissive | ilitzroth/mathlib | ea647e67f1fdfd19a0f7bdc5504e8acec6180011 | 5254ef14e3465f6504306132fe3ba9cec9ffff16 | refs/heads/master | 1,680,086,661,182 | 1,617,715,647,000 | 1,617,715,647,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 5,644 | lean | /-
Copyright (c) 2018 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Callum Sutton, Yury Kudryashov
-/
import data.equiv.mul_add
import group_theory.perm.basic
/-!
# Multiplicative and additive group automorphisms
This file defines the automorphism group structure on `add_aut R := add_equiv R R` and
`mul_aut R := mul_equiv R R`.
## Implementation notes
The definition of multiplication in the automorphism groups agrees with function composition,
multiplication in `equiv.perm`, and multiplication in `category_theory.End`, but not with
`category_theory.comp`.
This file is kept separate from `data/equiv/mul_add` so that `group_theory.perm` is free to use
equivalences (and other files that use them) before the group structure is defined.
## Tags
mul_aut, add_aut
-/
variables {A : Type*} {M : Type*} {G : Type*}
/-- The group of multiplicative automorphisms. -/
@[to_additive "The group of additive automorphisms."]
def mul_aut (M : Type*) [has_mul M] := M ≃* M
attribute [reducible] mul_aut add_aut
namespace mul_aut
variables (M) [has_mul M]
/--
The group operation on multiplicative automorphisms is defined by
`λ g h, mul_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance : group (mul_aut M) :=
by refine_struct
{ mul := λ g h, mul_equiv.trans h g,
one := mul_equiv.refl M,
inv := mul_equiv.symm,
div := _ };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (mul_aut M) := ⟨1⟩
@[simp] lemma coe_mul (e₁ e₂ : mul_aut M) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl
@[simp] lemma coe_one : ⇑(1 : mul_aut M) = id := rfl
lemma mul_def (e₁ e₂ : mul_aut M) : e₁ * e₂ = e₂.trans e₁ := rfl
lemma one_def : (1 : mul_aut M) = mul_equiv.refl _ := rfl
lemma inv_def (e₁ : mul_aut M) : e₁⁻¹ = e₁.symm := rfl
@[simp] lemma mul_apply (e₁ e₂ : mul_aut M) (m : M) : (e₁ * e₂) m = e₁ (e₂ m) := rfl
@[simp] lemma one_apply (m : M) : (1 : mul_aut M) m = m := rfl
@[simp] lemma apply_inv_self (e : mul_aut M) (m : M) : e (e⁻¹ m) = m :=
mul_equiv.apply_symm_apply _ _
@[simp] lemma inv_apply_self (e : mul_aut M) (m : M) : e⁻¹ (e m) = m :=
mul_equiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : mul_aut M →* equiv.perm M :=
by refine_struct { to_fun := mul_equiv.to_equiv }; intros; refl
/-- Group conjugation, `mul_aut.conj g h = g * h * g⁻¹`, as a monoid homomorphism
mapping multiplication in `G` into multiplication in the automorphism group `mul_aut G`. -/
def conj [group G] : G →* mul_aut G :=
{ to_fun := λ g,
{ to_fun := λ h, g * h * g⁻¹,
inv_fun := λ h, g⁻¹ * h * g,
left_inv := λ _, by simp [mul_assoc],
right_inv := λ _, by simp [mul_assoc],
map_mul' := by simp [mul_assoc] },
map_mul' := λ _ _, by ext; simp [mul_assoc],
map_one' := by ext; simp [mul_assoc] }
@[simp] lemma conj_apply [group G] (g h : G) : conj g h = g * h * g⁻¹ := rfl
@[simp] lemma conj_symm_apply [group G] (g h : G) : (conj g).symm h = g⁻¹ * h * g := rfl
@[simp] lemma conj_inv_apply [group G] (g h : G) : (conj g)⁻¹ h = g⁻¹ * h * g := rfl
end mul_aut
namespace add_aut
variables (A) [has_add A]
/--
The group operation on additive automorphisms is defined by
`λ g h, add_equiv.trans h g`.
This means that multiplication agrees with composition, `(g*h)(x) = g (h x)`.
-/
instance group : group (add_aut A) :=
by refine_struct
{ mul := λ g h, add_equiv.trans h g,
one := add_equiv.refl A,
inv := add_equiv.symm,
div := _ };
intros; ext; try { refl }; apply equiv.left_inv
instance : inhabited (add_aut A) := ⟨1⟩
@[simp] lemma coe_mul (e₁ e₂ : add_aut A) : ⇑(e₁ * e₂) = e₁ ∘ e₂ := rfl
@[simp] lemma coe_one : ⇑(1 : add_aut A) = id := rfl
lemma mul_def (e₁ e₂ : add_aut A) : e₁ * e₂ = e₂.trans e₁ := rfl
lemma one_def : (1 : add_aut A) = add_equiv.refl _ := rfl
lemma inv_def (e₁ : add_aut A) : e₁⁻¹ = e₁.symm := rfl
@[simp] lemma mul_apply (e₁ e₂ : add_aut A) (a : A) : (e₁ * e₂) a = e₁ (e₂ a) := rfl
@[simp] lemma one_apply (a : A) : (1 : add_aut A) a = a := rfl
@[simp] lemma apply_inv_self (e : add_aut A) (a : A) : e⁻¹ (e a) = a :=
add_equiv.apply_symm_apply _ _
@[simp] lemma inv_apply_self (e : add_aut A) (a : A) : e (e⁻¹ a) = a :=
add_equiv.apply_symm_apply _ _
/-- Monoid hom from the group of multiplicative automorphisms to the group of permutations. -/
def to_perm : add_aut A →* equiv.perm A :=
by refine_struct { to_fun := add_equiv.to_equiv }; intros; refl
/-- Additive group conjugation, `add_aut.conj g h = g + h - g`, as an additive monoid
homomorphism mapping addition in `G` into multiplication in the automorphism group `add_aut G`
(written additively in order to define the map). -/
def conj [add_group G] : G →+ additive (add_aut G) :=
{ to_fun := λ g, @additive.of_mul (add_aut G)
{ to_fun := λ h, g + h - g,
inv_fun := λ h, -g + h + g,
left_inv := λ _, by simp [add_assoc],
right_inv := λ _, by simp [add_assoc],
map_add' := by simp [add_assoc, sub_eq_add_neg] },
map_add' := λ _ _, by apply additive.to_mul.injective; ext; simp [add_assoc, sub_eq_add_neg],
map_zero' := by ext; simpa }
@[simp] lemma conj_apply [add_group G] (g h : G) : conj g h = g + h - g := rfl
@[simp] lemma conj_symm_apply [add_group G] (g h : G) : (conj g).symm h = -g + h + g := rfl
@[simp] lemma conj_inv_apply [add_group G] (g h : G) : (-(conj g)) h = -g + h + g := rfl
end add_aut
|
a283b237d8169f4eaf0807ffd4f59c536938b991 | 55c7fc2bf55d496ace18cd6f3376e12bb14c8cc5 | /src/algebra/group_ring_action.lean | 0058faae66aa69bbf9ac674a930ebd307fe88ec1 | [
"Apache-2.0"
] | permissive | dupuisf/mathlib | 62de4ec6544bf3b79086afd27b6529acfaf2c1bb | 8582b06b0a5d06c33ee07d0bdf7c646cae22cf36 | refs/heads/master | 1,669,494,854,016 | 1,595,692,409,000 | 1,595,692,409,000 | 272,046,630 | 0 | 0 | Apache-2.0 | 1,592,066,143,000 | 1,592,066,142,000 | null | UTF-8 | Lean | false | false | 8,565 | lean | /-
Copyright (c) 2020 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
Group action on rings.
-/
import group_theory.group_action
import data.equiv.ring
import data.polynomial.monic
universes u v
open_locale big_operators
section prio
set_option default_priority 100 -- see Note [default priority]
/-- Typeclass for multiplicative actions by monoids on semirings. -/
class mul_semiring_action (M : Type u) [monoid M] (R : Type v) [semiring R]
extends distrib_mul_action M R :=
(smul_one : ∀ (g : M), (g • 1 : R) = 1)
(smul_mul : ∀ (g : M) (x y : R), g • (x * y) = (g • x) * (g • y))
end prio
export mul_semiring_action (smul_one)
section semiring
variables (M G : Type u) [monoid M] [group G]
variables (A R S F : Type v) [add_monoid A] [semiring R] [comm_semiring S] [field F]
variables {M R}
lemma smul_mul' [mul_semiring_action M R] (g : M) (x y : R) :
g • (x * y) = (g • x) * (g • y) :=
mul_semiring_action.smul_mul g x y
variables (M R)
/-- Each element of the monoid defines a additive monoid homomorphism. -/
def distrib_mul_action.to_add_monoid_hom [distrib_mul_action M A] (x : M) : A →+ A :=
{ to_fun := (•) x,
map_zero' := smul_zero x,
map_add' := smul_add x }
/-- Each element of the group defines an additive monoid isomorphism. -/
def distrib_mul_action.to_add_equiv [distrib_mul_action G A] (x : G) : A ≃+ A :=
{ .. distrib_mul_action.to_add_monoid_hom G A x,
.. mul_action.to_perm G A x }
/-- The monoid of endomorphisms. -/
def monoid.End := M →* M
instance monoid.End.monoid : monoid (monoid.End M) :=
{ mul := monoid_hom.comp,
one := monoid_hom.id M,
mul_assoc := λ _ _ _, monoid_hom.comp_assoc _ _ _,
mul_one := monoid_hom.comp_id,
one_mul := monoid_hom.id_comp }
instance monoid.End.inhabited : inhabited (monoid.End M) :=
⟨1⟩
/-- The monoid of endomorphisms. -/
def add_monoid.End := A →+ A
instance add_monoid.End.monoid : monoid (add_monoid.End A) :=
{ mul := add_monoid_hom.comp,
one := add_monoid_hom.id A,
mul_assoc := λ _ _ _, add_monoid_hom.comp_assoc _ _ _,
mul_one := add_monoid_hom.comp_id,
one_mul := add_monoid_hom.id_comp }
instance add_monoid.End.inhabited : inhabited (add_monoid.End A) :=
⟨1⟩
/-- Each element of the group defines an additive monoid homomorphism. -/
def distrib_mul_action.hom_add_monoid_hom [distrib_mul_action M A] : M →* add_monoid.End A :=
{ to_fun := distrib_mul_action.to_add_monoid_hom M A,
map_one' := add_monoid_hom.ext $ λ x, one_smul M x,
map_mul' := λ x y, add_monoid_hom.ext $ λ z, mul_smul x y z }
/-- Each element of the monoid defines a semiring homomorphism. -/
def mul_semiring_action.to_semiring_hom [mul_semiring_action M R] (x : M) : R →+* R :=
{ map_one' := smul_one x,
map_mul' := smul_mul' x,
.. distrib_mul_action.to_add_monoid_hom M R x }
/-- Each element of the group defines a semiring isomorphism. -/
def mul_semiring_action.to_semiring_equiv [mul_semiring_action G R] (x : G) : R ≃+* R :=
{ .. distrib_mul_action.to_add_equiv G R x,
.. mul_semiring_action.to_semiring_hom G R x }
section prod
variables [mul_semiring_action M R] [mul_semiring_action M S]
lemma list.smul_prod (g : M) (L : list R) : g • L.prod = (L.map $ (•) g).prod :=
monoid_hom.map_list_prod (mul_semiring_action.to_semiring_hom M R g : R →* R) L
lemma multiset.smul_prod (g : M) (m : multiset S) : g • m.prod = (m.map $ (•) g).prod :=
monoid_hom.map_multiset_prod (mul_semiring_action.to_semiring_hom M S g : S →* S) m
lemma smul_prod (g : M) {ι : Type*} (f : ι → S) (s : finset ι) :
g • ∏ i in s, f i = ∏ i in s, g • f i :=
monoid_hom.map_prod (mul_semiring_action.to_semiring_hom M S g : S →* S) f s
end prod
section simp_lemmas
variables {M G A R}
attribute [simp] smul_one smul_mul' smul_zero smul_add
@[simp] lemma smul_inv [mul_semiring_action M F] (x : M) (m : F) : x • m⁻¹ = (x • m)⁻¹ :=
(mul_semiring_action.to_semiring_hom M F x).map_inv _
@[simp] lemma smul_pow [mul_semiring_action M R] (x : M) (m : R) (n : ℕ) :
x • m ^ n = (x • m) ^ n :=
nat.rec_on n (smul_one x) $ λ n ih, (smul_mul' x m (m ^ n)).trans $ congr_arg _ ih
end simp_lemmas
namespace polynomial
variables [mul_semiring_action M S]
noncomputable instance : mul_semiring_action M (polynomial S) :=
{ smul := λ m, map $ mul_semiring_action.to_semiring_hom M S m,
one_smul := λ p, by { ext n, erw coeff_map, exact one_smul M (p.coeff n) },
mul_smul := λ m n p, by { ext i,
iterate 3 { rw coeff_map (mul_semiring_action.to_semiring_hom M S _) },
exact mul_smul m n (p.coeff i) },
smul_add := λ m p q, map_add (mul_semiring_action.to_semiring_hom M S m),
smul_zero := λ m, map_zero (mul_semiring_action.to_semiring_hom M S m),
smul_one := λ m, map_one (mul_semiring_action.to_semiring_hom M S m),
smul_mul := λ m p q, map_mul (mul_semiring_action.to_semiring_hom M S m), }
@[simp] lemma coeff_smul' (m : M) (p : polynomial S) (n : ℕ) :
(m • p).coeff n = m • p.coeff n :=
coeff_map _ _
@[simp] lemma smul_C (m : M) (r : S) : m • C r = C (m • r) :=
map_C _
@[simp] lemma smul_X (m : M) : (m • X : polynomial S) = X :=
map_X _
theorem smul_eval_smul (m : M) (f : polynomial S) (x : S) :
(m • f).eval (m • x) = m • f.eval x :=
polynomial.induction_on f
(λ r, by rw [smul_C, eval_C, eval_C])
(λ f g ihf ihg, by rw [smul_add, eval_add, ihf, ihg, eval_add, smul_add])
(λ n r ih, by rw [smul_mul', smul_pow, smul_C, smul_X, eval_mul, eval_C, eval_pow, eval_X,
eval_mul, eval_C, eval_pow, eval_X, smul_mul', smul_pow])
theorem eval_smul' [mul_semiring_action G S] (g : G) (f : polynomial S) (x : S) :
f.eval (g • x) = g • (g⁻¹ • f).eval x :=
by rw [← smul_eval_smul, mul_action.smul_inv_smul]
theorem smul_eval [mul_semiring_action G S] (g : G) (f : polynomial S) (x : S) :
(g • f).eval x = g • f.eval (g⁻¹ • x) :=
by rw [← smul_eval_smul, mul_action.smul_inv_smul]
end polynomial
end semiring
section ring
variables (M : Type u) [monoid M] {R : Type v} [ring R] [mul_semiring_action M R]
variables (S : set R) [is_subring S]
open mul_action
set_option old_structure_cmd false
/-- A subring invariant under the action. -/
class is_invariant_subring : Prop :=
(smul_mem : ∀ (m : M) {x : R}, x ∈ S → m • x ∈ S)
variables [is_invariant_subring M S]
instance is_invariant_subring.to_mul_semiring_action : mul_semiring_action M S :=
{ smul := λ m x, ⟨m • x, is_invariant_subring.smul_mem m x.2⟩,
one_smul := λ s, subtype.eq $ one_smul M s,
mul_smul := λ m₁ m₂ s, subtype.eq $ mul_smul m₁ m₂ s,
smul_add := λ m s₁ s₂, subtype.eq $ smul_add m s₁ s₂,
smul_zero := λ m, subtype.eq $ smul_zero m,
smul_one := λ m, subtype.eq $ smul_one m,
smul_mul := λ m s₁ s₂, subtype.eq $ smul_mul' m s₁ s₂ }
end ring
section comm_ring
variables (G : Type u) [group G] [fintype G]
variables (R : Type v) [comm_ring R] [mul_semiring_action G R]
open mul_action
open_locale classical
noncomputable instance (s : set G) [is_subgroup s] : fintype (quotient_group.quotient s) :=
quotient.fintype _
/-- the product of `(X - g • x)` over distinct `g • x`. -/
noncomputable def prod_X_sub_smul (x : R) : polynomial R :=
(finset.univ : finset (quotient_group.quotient $ mul_action.stabilizer G x)).prod $
λ g, polynomial.X - polynomial.C (of_quotient_stabilizer G x g)
theorem prod_X_sub_smul.monic (x : R) : (prod_X_sub_smul G R x).monic :=
polynomial.monic_prod_of_monic _ _ $ λ g _, polynomial.monic_X_sub_C _
theorem prod_X_sub_smul.eval (x : R) : (prod_X_sub_smul G R x).eval x = 0 :=
(finset.prod_hom _ (polynomial.eval x)).symm.trans $ finset.prod_eq_zero (finset.mem_univ $ quotient_group.mk 1) $
by rw [of_quotient_stabilizer_mk, one_smul, polynomial.eval_sub, polynomial.eval_X, polynomial.eval_C, sub_self]
theorem prod_X_sub_smul.smul (x : R) (g : G) :
g • prod_X_sub_smul G R x = prod_X_sub_smul G R x :=
(smul_prod _ _ _ _ _).trans $ finset.prod_bij (λ g' _, g • g') (λ _ _, finset.mem_univ _)
(λ g' _, by rw [of_quotient_stabilizer_smul, smul_sub, polynomial.smul_X, polynomial.smul_C])
(λ _ _ _ _ H, (mul_action.bijective g).1 H)
(λ g' _, ⟨g⁻¹ • g', finset.mem_univ _, by rw [smul_smul, mul_inv_self, one_smul]⟩)
theorem prod_X_sub_smul.coeff (x : R) (g : G) (n : ℕ) :
g • (prod_X_sub_smul G R x).coeff n =
(prod_X_sub_smul G R x).coeff n :=
by rw [← polynomial.coeff_smul', prod_X_sub_smul.smul]
end comm_ring
|
186633a09733abaff8fb26c695cebcf4c2d0cba1 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/matchUnknownFVarBug.lean | c3c08e01b7e57cd11ff003fc4abca7f418dc7be3 | [
"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 | 85 | lean | example (n? : Option Nat) : False := by
match h:n?, h':n? with
| some 0, _ => {}
|
cf45584b5dfa585c152ce36f14350a63d39de9be | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/category_theory/thin_auto.lean | dbb0e20a63959f45af66dc409c41928f51f80cf1 | [] | 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,449 | lean | /-
Copyright (c) 2019 Scott Morrison, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Bhavik Mehta
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.category_theory.functor_category
import Mathlib.category_theory.isomorphism
import Mathlib.PostPort
universes u₁ v₁ v₂ u₂
namespace Mathlib
/-!
# Thin categories
A thin category (also known as a sparse category) is a category with at most one morphism between
each pair of objects.
Examples include posets, but also some indexing categories (diagrams) for special shapes of
(co)limits.
To construct a category instance one only needs to specify the `category_struct` part,
as the axioms hold for free.
If `C` is thin, then the category of functors to `C` is also thin.
Further, to show two objects are isomorphic in a thin category, it suffices only to give a morphism
in each direction.
-/
namespace category_theory
/-- Construct a category instance from a category_struct, using the fact that
hom spaces are subsingletons to prove the axioms. -/
def thin_category {C : Type u₁} [category_struct C] [∀ (X Y : C), subsingleton (X ⟶ Y)] :
category C :=
category.mk
-- We don't assume anything about where the category instance on `C` came from.
-- In particular this allows `C` to be a preorder, with the category instance inherited from the
-- preorder structure.
/-- If `C` is a thin category, then `D ⥤ C` is a thin category. -/
protected instance functor_thin {C : Type u₁} [category C] {D : Type u₂} [category D]
[∀ (X Y : C), subsingleton (X ⟶ Y)] (F₁ : D ⥤ C) (F₂ : D ⥤ C) : subsingleton (F₁ ⟶ F₂) :=
subsingleton.intro
fun (α β : F₁ ⟶ F₂) =>
nat_trans.ext α β
(funext fun (_x : D) => subsingleton.elim (nat_trans.app α _x) (nat_trans.app β _x))
/-- To show `X ≅ Y` in a thin category, it suffices to just give any morphism in each direction. -/
def iso_of_both_ways {C : Type u₁} [category C] [∀ (X Y : C), subsingleton (X ⟶ Y)] {X : C} {Y : C}
(f : X ⟶ Y) (g : Y ⟶ X) : X ≅ Y :=
iso.mk f g
protected instance subsingleton_iso {C : Type u₁} [category C] [∀ (X Y : C), subsingleton (X ⟶ Y)]
{X : C} {Y : C} : subsingleton (X ≅ Y) :=
subsingleton.intro fun (i₁ i₂ : X ≅ Y) => iso.ext (subsingleton.elim (iso.hom i₁) (iso.hom i₂))
end Mathlib |
543ec23a380dde8f22d3e415efa9b5cb7d118560 | f5f7e6fae601a5fe3cac7cc3ed353ed781d62419 | /src/topology/metric_space/completion.lean | 7a0dc2dc39bf23c95b0f03e7d9d768632af32294 | [
"Apache-2.0"
] | permissive | EdAyers/mathlib | 9ecfb2f14bd6caad748b64c9c131befbff0fb4e0 | ca5d4c1f16f9c451cf7170b10105d0051db79e1b | refs/heads/master | 1,626,189,395,845 | 1,555,284,396,000 | 1,555,284,396,000 | 144,004,030 | 0 | 0 | Apache-2.0 | 1,533,727,664,000 | 1,533,727,663,000 | null | UTF-8 | Lean | false | false | 8,830 | lean | /-
Copyright (c) 2019 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Sébastien Gouëzel
The completion of a metric space.
Completion of uniform spaces are already defined in `topology.uniform_space.completion`. We show
here that the uniform space completion of a metric space inherits a metric space structure,
by extending the distance to the completion and checking that it is indeed a distance, and that
it defines the same uniformity as the already defined uniform structure on the completion
-/
import topology.uniform_space.completion topology.instances.real topology.metric_space.isometry
open lattice set filter uniform_space uniform_space.completion
noncomputable theory
universes u
variables {α : Type u} [metric_space α]
namespace metric
/-- The distance on the completion is obtained by extending the distance on the original space,
by uniform continuity. -/
instance : has_dist (completion α) :=
⟨λx y, completion.extension (λp:α×α, dist p.1 p.2) (completion.prod (x, y))⟩
/-- The new distance is uniformly continuous. -/
protected lemma completion.uniform_continuous_dist :
uniform_continuous (λp:completion α × completion α, dist p.1 p.2) :=
uniform_continuous.comp uniform_continuous_prod uniform_continuous_extension
/-- The new distance is an extension of the original distance. -/
protected lemma completion.dist_eq (x y : α) : dist (x : completion α) y = dist x y :=
begin
unfold dist,
rw [completion.prod_coe_coe, completion.extension_coe],
exact uniform_continuous_dist',
end
/- Let us check that the new distance satisfies the axioms of a distance, by starting from the
properties on α and extending them to `completion α` by continuity. -/
protected lemma completion.dist_self (x : completion α) : dist x x = 0 :=
begin
apply induction_on x,
{ refine is_closed_eq _ continuous_const,
have : continuous (λx : completion α, (x, x)) :=
continuous.prod_mk continuous_id continuous_id,
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ assume a,
rw [completion.dist_eq, dist_self] }
end
protected lemma completion.dist_comm (x y : completion α) : dist x y = dist y x :=
begin
apply induction_on₂ x y,
{ refine is_closed_eq completion.uniform_continuous_dist.continuous _,
exact continuous.comp continuous_swap completion.uniform_continuous_dist.continuous },
{ assume a b,
rw [completion.dist_eq, completion.dist_eq, dist_comm] }
end
protected lemma completion.dist_triangle (x y z : completion α) : dist x z ≤ dist x y + dist y z :=
begin
apply induction_on₃ x y z,
{ refine is_closed_le _ (continuous_add _ _),
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.2)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_snd),
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ have : continuous (λp : completion α × completion α × completion α, (p.1, p.2.1)) :=
continuous.prod_mk continuous_fst (continuous.comp continuous_snd continuous_fst),
exact continuous.comp this completion.uniform_continuous_dist.continuous },
{ have : continuous (λp : completion α × completion α × completion α, (p.2.1, p.2.2)) :=
continuous.prod_mk (continuous.comp continuous_snd continuous_fst)
(continuous.comp continuous_snd continuous_snd),
exact continuous.comp this completion.uniform_continuous_dist.continuous }},
{ assume a b c,
rw [completion.dist_eq, completion.dist_eq, completion.dist_eq],
exact dist_triangle a b c }
end
/-- Elements of the uniformity (defined generally for completions) can be characterized in terms
of the distance. -/
protected lemma completion.mem_uniformity_dist (s : set (completion α × completion α)) :
s ∈ uniformity (completion α) ↔ (∃ε>0, ∀{a b}, dist a b < ε → (a, b) ∈ s) :=
begin
split,
{ /- Start from an entourage `s`. It contains a closed entourage `t`. Its pullback in α is an
entourage, so it contains an ε-neighborhood of the diagonal by definition of the entourages
in metric spaces. Then `t` contains an ε-neighborhood of the diagonal in `completion α`, as
closed properties pass to the completion. -/
assume hs,
rcases mem_uniformity_is_closed hs with ⟨t, ht, ⟨tclosed, ts⟩⟩,
have A : {x : α × α | (coe (x.1), coe (x.2)) ∈ t} ∈ uniformity α :=
uniform_continuous_def.1 (uniform_continuous_coe α) t ht,
rcases mem_uniformity_dist.1 A with ⟨ε, εpos, hε⟩,
refine ⟨ε, εpos, λx y hxy, _⟩,
have : ε ≤ dist x y ∨ (x, y) ∈ t,
{ apply induction_on₂ x y,
{ have : {x : completion α × completion α | ε ≤ dist (x.fst) (x.snd) ∨ (x.fst, x.snd) ∈ t}
= {p : completion α × completion α | ε ≤ dist p.1 p.2} ∪ t, by ext; simp,
rw this,
apply is_closed_union _ tclosed,
exact is_closed_le continuous_const completion.uniform_continuous_dist.continuous },
{ assume x y,
rw completion.dist_eq,
by_cases h : ε ≤ dist x y,
{ exact or.inl h },
{ have Z := hε (not_le.1 h),
simp only [set.mem_set_of_eq] at Z,
exact or.inr Z }}},
simp only [not_le.mpr hxy, false_or, not_le] at this,
exact ts this },
{ /- Start from a set `s` containing an ε-neighborhood of the diagonal in `completion α`. To show
that it is an entourage, we use the fact that `dist` is uniformly continuous on
`completion α × completion α` (this is a general property of the extension of uniformly
continuous functions). Therefore, the preimage of the ε-neighborhood of the diagonal in ℝ
is an entourage in `completion α × completion α`. Massaging this property, it follows that
the ε-neighborhood of the diagonal is an entourage in `completion α`, and therefore this is
also the case of `s`. -/
rintros ⟨ε, εpos, hε⟩,
let r : set (ℝ × ℝ) := {p | dist p.1 p.2 < ε},
have : r ∈ uniformity ℝ := metric.dist_mem_uniformity εpos,
have T := uniform_continuous_def.1 (@completion.uniform_continuous_dist α _) r this,
simp only [uniformity_prod_eq_prod, mem_prod_iff, exists_prop,
filter.mem_map, set.mem_set_of_eq] at T,
rcases T with ⟨t1, ht1, t2, ht2, ht⟩,
refine mem_sets_of_superset ht1 _,
have A : ∀a b : completion α, (a, b) ∈ t1 → dist a b < ε,
{ assume a b hab,
have : ((a, b), (a, a)) ∈ set.prod t1 t2 := ⟨hab, refl_mem_uniformity ht2⟩,
have I := ht this,
simp [completion.dist_self, real.dist_eq, completion.dist_comm] at I,
exact lt_of_le_of_lt (le_abs_self _) I },
show t1 ⊆ s,
{ rintros ⟨a, b⟩ hp,
have : dist a b < ε := A a b hp,
exact hε this }}
end
/-- If two points are at distance 0, then they coincide. -/
protected lemma completion.eq_of_dist_eq_zero (x y : completion α) (h : dist x y = 0) : x = y :=
begin
/- This follows from the separation of `completion α` and from the description of
entourages in terms of the distance. -/
have : separated (completion α) := by apply_instance,
refine separated_def.1 this x y (λs hs, _),
rcases (completion.mem_uniformity_dist s).1 hs with ⟨ε, εpos, hε⟩,
rw ← h at εpos,
exact hε εpos
end
/- Reformulate `completion.mem_uniformity_dist` in terms that are suitable for the definition
of the metric space structure. -/
protected lemma completion.uniformity_dist' :
uniformity (completion α) = (⨅ε:{ε:ℝ // ε>0}, principal {p | dist p.1 p.2 < ε.val}) :=
begin
ext s, rw mem_infi,
{ simp [completion.mem_uniformity_dist, subset_def] },
{ rintro ⟨r, hr⟩ ⟨p, hp⟩, use ⟨min r p, lt_min hr hp⟩,
simp [lt_min_iff, (≥)] {contextual := tt} },
{ exact ⟨⟨1, zero_lt_one⟩⟩ }
end
protected lemma completion.uniformity_dist :
uniformity (completion α) = (⨅ ε>0, principal {p | dist p.1 p.2 < ε}) :=
by simpa [infi_subtype] using @completion.uniformity_dist' α _
/-- Metric space structure on the completion of a metric space. -/
instance completion.metric_space : metric_space (completion α) :=
{ dist_self := completion.dist_self,
eq_of_dist_eq_zero := completion.eq_of_dist_eq_zero,
dist_comm := completion.dist_comm,
dist_triangle := completion.dist_triangle,
to_uniform_space := by apply_instance,
uniformity_dist := completion.uniformity_dist }
/-- The embedding of a metric space in its completion is an isometry. -/
lemma completion.coe_isometry : isometry (coe : α → completion α) :=
isometry_emetric_iff_metric.2 completion.dist_eq
end metric
|
b1c8af2cf05fcb32b2343255b68f7341a2ccb3d8 | 4727251e0cd73359b15b664c3170e5d754078599 | /src/data/pfunctor/multivariate/W.lean | dbb2b2165b607e5974f3e101fc77e7f96e54e8a6 | [
"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 | 10,503 | lean | /-
Copyright (c) 2018 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Simon Hudon
-/
import data.pfunctor.multivariate.basic
/-!
# The W construction as a multivariate polynomial functor.
W types are well-founded tree-like structures. They are defined
as the least fixpoint of a polynomial functor.
## Main definitions
* `W_mk` - constructor
* `W_dest - destructor
* `W_rec` - recursor: basis for defining functions by structural recursion on `P.W α`
* `W_rec_eq` - defining equation for `W_rec`
* `W_ind` - induction principle for `P.W α`
## Implementation notes
Three views of M-types:
* `Wp`: polynomial functor
* `W`: data type inductively defined by a triple:
shape of the root, data in the root and children of the root
* `W`: least fixed point of a polynomial functor
Specifically, we define the polynomial functor `Wp` as:
* A := a tree-like structure without information in the nodes
* B := given the tree-like structure `t`, `B t` is a valid path
(specified inductively by `W_path`) from the root of `t` to any given node.
As a result `Wp.obj α` is made of a dataless tree and a function from
its valid paths to values of `α`
## Reference
* Jeremy Avigad, Mario M. Carneiro and Simon Hudon.
[*Data Types as Quotients of Polynomial Functors*][avigad-carneiro-hudon2019]
-/
universes u v
namespace mvpfunctor
open typevec
open_locale mvfunctor
variables {n : ℕ} (P : mvpfunctor.{u} (n+1))
/-- A path from the root of a tree to one of its node -/
inductive W_path : P.last.W → fin2 n → Type u
| root (a : P.A) (f : P.last.B a → P.last.W) (i : fin2 n) (c : P.drop.B a i) :
W_path ⟨a, f⟩ i
| child (a : P.A) (f : P.last.B a → P.last.W) (i : fin2 n) (j : P.last.B a) (c : W_path (f j) i) :
W_path ⟨a, f⟩ i
instance W_path.inhabited (x : P.last.W) {i} [I : inhabited (P.drop.B x.head i)] :
inhabited (W_path P x i) :=
⟨ match x, I with
| ⟨a, f ⟩, I := W_path.root a f i (@default _ I)
end ⟩
/-- Specialized destructor on `W_path` -/
def W_path_cases_on {α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(g' : P.drop.B a ⟹ α) (g : Π j : P.last.B a, P.W_path (f j) ⟹ α) :
P.W_path ⟨a, f⟩ ⟹ α :=
begin
intros i x, cases x,
case W_path.root : _ _ i c { exact g' i c },
case W_path.child : _ _ i j c { exact g j i c}
end
/-- Specialized destructor on `W_path` -/
def W_path_dest_left {α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(h : P.W_path ⟨a, f⟩ ⟹ α) :
P.drop.B a ⟹ α :=
λ i c, h i (W_path.root a f i c)
/-- Specialized destructor on `W_path` -/
def W_path_dest_right {α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(h : P.W_path ⟨a, f⟩ ⟹ α) :
Π j : P.last.B a, P.W_path (f j) ⟹ α :=
λ j i c, h i (W_path.child a f i j c)
theorem W_path_dest_left_W_path_cases_on
{α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(g' : P.drop.B a ⟹ α) (g : Π j : P.last.B a, P.W_path (f j) ⟹ α) :
P.W_path_dest_left (P.W_path_cases_on g' g) = g' := rfl
theorem W_path_dest_right_W_path_cases_on
{α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(g' : P.drop.B a ⟹ α) (g : Π j : P.last.B a, P.W_path (f j) ⟹ α) :
P.W_path_dest_right (P.W_path_cases_on g' g) = g := rfl
theorem W_path_cases_on_eta {α : typevec n} {a : P.A} {f : P.last.B a → P.last.W}
(h : P.W_path ⟨a, f⟩ ⟹ α) :
P.W_path_cases_on (P.W_path_dest_left h) (P.W_path_dest_right h) = h :=
by ext i x; cases x; reflexivity
theorem comp_W_path_cases_on {α β : typevec n} (h : α ⟹ β) {a : P.A} {f : P.last.B a → P.last.W}
(g' : P.drop.B a ⟹ α) (g : Π j : P.last.B a, P.W_path (f j) ⟹ α) :
h ⊚ P.W_path_cases_on g' g = P.W_path_cases_on (h ⊚ g') (λ i, h ⊚ g i) :=
by ext i x; cases x; reflexivity
/-- Polynomial functor for the W-type of `P`. `A` is a data-less well-founded
tree whereas, for a given `a : A`, `B a` is a valid path in tree `a` so
that `Wp.obj α` is made of a tree and a function from its valid paths to
the values it contains -/
def Wp : mvpfunctor n :=
{ A := P.last.W, B := P.W_path }
/-- W-type of `P` -/
@[nolint has_inhabited_instance]
def W (α : typevec n) : Type* := P.Wp.obj α
instance mvfunctor_W : mvfunctor P.W := by delta mvpfunctor.W; apply_instance
/-!
First, describe operations on `W` as a polynomial functor.
-/
/-- Constructor for `Wp` -/
def Wp_mk {α : typevec n} (a : P.A) (f : P.last.B a → P.last.W) (f' : P.W_path ⟨a, f⟩ ⟹ α) :
P.W α :=
⟨⟨a, f⟩, f'⟩
/-- Recursor for `Wp` -/
def Wp_rec {α : typevec n} {C : Type*}
(g : Π (a : P.A) (f : P.last.B a → P.last.W),
(P.W_path ⟨a, f⟩ ⟹ α) → (P.last.B a → C) → C) :
Π (x : P.last.W) (f' : P.W_path x ⟹ α), C
| ⟨a, f⟩ f' := g a f f' (λ i, Wp_rec (f i) (P.W_path_dest_right f' i))
theorem Wp_rec_eq {α : typevec n} {C : Type*}
(g : Π (a : P.A) (f : P.last.B a → P.last.W),
(P.W_path ⟨a, f⟩ ⟹ α) → (P.last.B a → C) → C)
(a : P.A) (f : P.last.B a → P.last.W) (f' : P.W_path ⟨a, f⟩ ⟹ α) :
P.Wp_rec g ⟨a, f⟩ f' = g a f f' (λ i, P.Wp_rec g (f i) (P.W_path_dest_right f' i)) :=
rfl
-- Note: we could replace Prop by Type* and obtain a dependent recursor
theorem Wp_ind {α : typevec n} {C : Π x : P.last.W, P.W_path x ⟹ α → Prop}
(ih : ∀ (a : P.A) (f : P.last.B a → P.last.W)
(f' : P.W_path ⟨a, f⟩ ⟹ α),
(∀ i : P.last.B a, C (f i) (P.W_path_dest_right f' i)) → C ⟨a, f⟩ f') :
Π (x : P.last.W) (f' : P.W_path x ⟹ α), C x f'
| ⟨a, f⟩ f' := ih a f f' (λ i, Wp_ind _ _)
/-!
Now think of W as defined inductively by the data ⟨a, f', f⟩ where
- `a : P.A` is the shape of the top node
- `f' : P.drop.B a ⟹ α` is the contents of the top node
- `f : P.last.B a → P.last.W` are the subtrees
-/
/-- Constructor for `W` -/
def W_mk {α : typevec n} (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) :
P.W α :=
let g : P.last.B a → P.last.W := λ i, (f i).fst,
g' : P.W_path ⟨a, g⟩ ⟹ α := P.W_path_cases_on f' (λ i, (f i).snd) in
⟨⟨a, g⟩, g'⟩
/-- Recursor for `W` -/
def W_rec {α : typevec n} {C : Type*}
(g : Π a : P.A, ((P.drop).B a ⟹ α) → ((P.last).B a → P.W α) → ((P.last).B a → C) → C) :
P.W α → C
| ⟨a, f'⟩ :=
let g' (a : P.A) (f : P.last.B a → P.last.W) (h : P.W_path ⟨a, f⟩ ⟹ α)
(h' : P.last.B a → C) : C :=
g a (P.W_path_dest_left h) (λ i, ⟨f i, P.W_path_dest_right h i⟩) h' in
P.Wp_rec g' a f'
/-- Defining equation for the recursor of `W` -/
theorem W_rec_eq {α : typevec n} {C : Type*}
(g : Π a : P.A, ((P.drop).B a ⟹ α) → ((P.last).B a → P.W α) → ((P.last).B a → C) → C)
(a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) :
P.W_rec g (P.W_mk a f' f) = g a f' f (λ i, P.W_rec g (f i)) :=
begin
rw [W_mk, W_rec], dsimp, rw [Wp_rec_eq],
dsimp only [W_path_dest_left_W_path_cases_on, W_path_dest_right_W_path_cases_on],
congr; ext1 i; cases (f i); refl
end
/-- Induction principle for `W` -/
theorem W_ind {α : typevec n} {C : P.W α → Prop}
(ih : ∀ (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α),
(∀ i, C (f i)) → C (P.W_mk a f' f)) :
∀ x, C x :=
begin
intro x, cases x with a f,
apply @Wp_ind n P α (λ a f, C ⟨a, f⟩), dsimp,
intros a f f' ih',
dsimp [W_mk] at ih,
let ih'' := ih a (P.W_path_dest_left f') (λ i, ⟨f i, P.W_path_dest_right f' i⟩),
dsimp at ih'', rw W_path_cases_on_eta at ih'',
apply ih'',
apply ih'
end
theorem W_cases {α : typevec n} {C : P.W α → Prop}
(ih : ∀ (a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α), C (P.W_mk a f' f)) :
∀ x, C x :=
P.W_ind (λ a f' f ih', ih a f' f)
/-- W-types are functorial -/
def W_map {α β : typevec n} (g : α ⟹ β) : P.W α → P.W β :=
λ x, g <$$> x
theorem W_mk_eq {α : typevec n} (a : P.A) (f : P.last.B a → P.last.W)
(g' : P.drop.B a ⟹ α) (g : Π j : P.last.B a, P.W_path (f j) ⟹ α) :
P.W_mk a g' (λ i, ⟨f i, g i⟩) =
⟨⟨a, f⟩, P.W_path_cases_on g' g⟩ := rfl
theorem W_map_W_mk {α β : typevec n} (g : α ⟹ β)
(a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) :
g <$$> P.W_mk a f' f = P.W_mk a (g ⊚ f') (λ i, g <$$> f i) :=
begin
show _ = P.W_mk a (g ⊚ f') (mvfunctor.map g ∘ f),
have : mvfunctor.map g ∘ f = λ i, ⟨(f i).fst, g ⊚ ((f i).snd)⟩,
{ ext i : 1, dsimp [function.comp], cases (f i), refl },
rw this,
have : f = λ i, ⟨(f i).fst, (f i).snd⟩,
{ ext1, cases (f x), refl },
rw this, dsimp,
rw [W_mk_eq, W_mk_eq],
have h := mvpfunctor.map_eq P.Wp g,
rw [h, comp_W_path_cases_on]
end
-- TODO: this technical theorem is used in one place in constructing the initial algebra.
-- Can it be avoided?
/-- Constructor of a value of `P.obj (α ::: β)` from components.
Useful to avoid complicated type annotation -/
@[reducible] def obj_append1 {α : typevec n} {β : Type*}
(a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → β) :
P.obj (α ::: β) :=
⟨a, split_fun f' f⟩
theorem map_obj_append1 {α γ : typevec n} (g : α ⟹ γ)
(a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) :
append_fun g (P.W_map g) <$$> P.obj_append1 a f' f =
P.obj_append1 a (g ⊚ f') (λ x, P.W_map g (f x)) :=
by rw [obj_append1, obj_append1, map_eq, append_fun, ← split_fun_comp]; refl
/-!
Yet another view of the W type: as a fixed point for a multivariate polynomial functor.
These are needed to use the W-construction to construct a fixed point of a qpf, since
the qpf axioms are expressed in terms of `map` on `P`.
-/
/-- Constructor for the W-type of `P` -/
def W_mk' {α : typevec n} : P.obj (α ::: P.W α) → P.W α
| ⟨a, f⟩ := P.W_mk a (drop_fun f) (last_fun f)
/-- Destructor for the W-type of `P` -/
def W_dest' {α : typevec.{u} n} : P.W α → P.obj (α.append1 (P.W α)) :=
P.W_rec (λ a f' f _, ⟨a, split_fun f' f⟩)
theorem W_dest'_W_mk {α : typevec n}
(a : P.A) (f' : P.drop.B a ⟹ α) (f : P.last.B a → P.W α) :
P.W_dest' (P.W_mk a f' f) = ⟨a, split_fun f' f⟩ :=
by rw [W_dest', W_rec_eq]
theorem W_dest'_W_mk' {α : typevec n} (x : P.obj (α.append1 (P.W α))) :
P.W_dest' (P.W_mk' x) = x :=
by cases x with a f; rw [W_mk', W_dest'_W_mk, split_drop_fun_last_fun]
end mvpfunctor
|
d2e1888b7de5c8c8e07981226ae853ab3b3231d4 | 0c1546a496eccfb56620165cad015f88d56190c5 | /library/init/meta/relation_tactics.lean | 33a87a89721d7eb7ecd72322116bab78cacf46b7 | [
"Apache-2.0"
] | permissive | Solertis/lean | 491e0939957486f664498fbfb02546e042699958 | 84188c5aa1673fdf37a082b2de8562dddf53df3f | refs/heads/master | 1,610,174,257,606 | 1,486,263,620,000 | 1,486,263,620,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 1,599 | 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
-/
prelude
import init.meta.tactic init.function
namespace tactic
open expr
private meta def relation_tactic (t : transparency) (op_for : environment → name → option name) (tac_name : string) : tactic unit :=
do tgt ← target,
env ← get_env,
r ← return $ get_app_fn tgt,
match (op_for env (const_name r)) with
| (some refl) := mk_const refl >>= apply_core t tt ff tt
| none := fail $ tac_name ++ " tactic failed, target is not a relation application with the expected property."
end
meta def reflexivity_core (t : transparency) : tactic unit :=
relation_tactic t environment.refl_for "reflexivity"
meta def reflexivity : tactic unit :=
reflexivity_core semireducible
meta def symmetry : tactic unit :=
relation_tactic semireducible environment.symm_for "symmetry"
meta def transitivity : tactic unit :=
relation_tactic semireducible environment.trans_for "transitivity"
meta def relation_lhs_rhs : expr → tactic (name × expr × expr) :=
λ e, do
(const c _) ← return e^.get_app_fn | failed,
env ← get_env,
(some (arity, lhs_pos, rhs_pos)) ← return $ env^.relation_info c | failed,
args ← return $ get_app_args e,
guard (args^.length = arity),
(some lhs) ← return $ args^.nth lhs_pos | failed,
(some rhs) ← return $ args^.nth rhs_pos | failed,
return (c, lhs, rhs)
meta def target_lhs_rhs : tactic (name × expr × expr) :=
target >>= relation_lhs_rhs
end tactic
|
1803bb0cbe2b1567174f0ee2537753dbedb7dd1b | 367134ba5a65885e863bdc4507601606690974c1 | /src/category_theory/limits/constructions/over/connected.lean | 4a9b1f6b2a65751224ced6d2b11213296519fed8 | [
"Apache-2.0"
] | permissive | kodyvajjha/mathlib | 9bead00e90f68269a313f45f5561766cfd8d5cad | b98af5dd79e13a38d84438b850a2e8858ec21284 | refs/heads/master | 1,624,350,366,310 | 1,615,563,062,000 | 1,615,563,062,000 | 162,666,963 | 0 | 0 | Apache-2.0 | 1,545,367,651,000 | 1,545,367,651,000 | null | UTF-8 | Lean | false | false | 2,906 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin, Reid Barton, Bhavik Mehta
-/
import category_theory.over
import category_theory.limits.connected
import category_theory.limits.creates
/-!
# Connected limits in the over category
Shows that the forgetful functor `over B ⥤ C` creates connected limits, in particular `over B` has
any connected limit which `C` has.
-/
universes v u -- declare the `v`'s first; see `category_theory.category` for an explanation
noncomputable theory
open category_theory category_theory.limits
variables {J : Type v} [small_category J]
variables {C : Type u} [category.{v} C]
variable {X : C}
namespace category_theory.over
namespace creates_connected
/--
(Impl) Given a diagram in the over category, produce a natural transformation from the
diagram legs to the specific object.
-/
def nat_trans_in_over {B : C} (F : J ⥤ over B) :
F ⋙ forget B ⟶ (category_theory.functor.const J).obj B :=
{ app := λ j, (F.obj j).hom }
local attribute [tidy] tactic.case_bash
/--
(Impl) Given a cone in the base category, raise it to a cone in the over category. Note this is
where the connected assumption is used.
-/
@[simps]
def raise_cone [is_connected J] {B : C} {F : J ⥤ over B} (c : cone (F ⋙ forget B)) :
cone F :=
{ X := over.mk (c.π.app (classical.arbitrary J) ≫ (F.obj (classical.arbitrary J)).hom),
π :=
{ app := λ j,
over.hom_mk (c.π.app j) (nat_trans_from_is_connected (c.π ≫ nat_trans_in_over F) j _) } }
lemma raised_cone_lowers_to_original [is_connected J] {B : C} {F : J ⥤ over B}
(c : cone (F ⋙ forget B)) (t : is_limit c) :
(forget B).map_cone (raise_cone c) = c :=
by tidy
/-- (Impl) Show that the raised cone is a limit. -/
def raised_cone_is_limit [is_connected J] {B : C} {F : J ⥤ over B}
{c : cone (F ⋙ forget B)} (t : is_limit c) :
is_limit (raise_cone c) :=
{ lift := λ s, over.hom_mk (t.lift ((forget B).map_cone s)) (by { dsimp, simp }),
uniq' := λ s m K, by { ext1, apply t.hom_ext, intro j, simp [← K j] } }
end creates_connected
/-- The forgetful functor from the over category creates any connected limit. -/
instance forget_creates_connected_limits
[is_connected J] {B : C} : creates_limits_of_shape J (forget B) :=
{ creates_limit := λ K,
creates_limit_of_reflects_iso (λ c t,
{ lifted_cone := creates_connected.raise_cone c,
valid_lift := eq_to_iso (creates_connected.raised_cone_lowers_to_original c t),
makes_limit := creates_connected.raised_cone_is_limit t } ) }
/-- The over category has any connected limit which the original category has. -/
instance has_connected_limits
{B : C} [is_connected J] [has_limits_of_shape J C] : has_limits_of_shape J (over B) :=
{ has_limit := λ F, has_limit_of_created F (forget B) }
end category_theory.over
|
5eada6bc00ece654621056b5118b90f0c9a3bddb | 6dc0c8ce7a76229dd81e73ed4474f15f88a9e294 | /tests/lean/run/simp1.lean | 61fe508cee8011eb67a1fb7afc5c36e03f8c247d | [
"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,310 | lean | import Lean
@[simp] theorem ex1 (x : Nat) : 2 * x = x + x :=
sorry
@[simp] theorem ex2 (xs : List α) : xs ++ [] = xs :=
sorry
@[simp] theorem ex3 (xs ys zs : List α) : (xs ++ ys) ++ zs = xs ++ (ys ++ zs) :=
sorry
@[simp] theorem ex5 (p : Prop) : p ∨ True :=
sorry
@[simp] theorem ex4 (xs : List α) : ¬(x :: xs = []) :=
sorry
@[simp] theorem ex6 (p q : Prop) : p ∨ q ↔ q ∨ p:=
sorry
@[simp high] theorem ex7 [Add α] (a b : α) : a + b = b + a :=
sorry
@[simp↓] theorem ex8 [Add α] (p q : Prop) : (¬ (p ∧ q)) = (¬p ∨ ¬q) :=
sorry
axiom aux {α} (f : List α → List α) (xs ys : List α) : f (xs ++ ys) ++ [] = f (xs ++ ys)
open Lean
open Lean.Meta
def tst1 : MetaM Unit := do
let lemmas ← Meta.getSimpLemmas
trace[Meta.debug]! "{lemmas.pre}\n-----\n{lemmas.post}"
set_option trace.Meta.debug true in
#eval tst1
def tst2 : MetaM Unit := do
let c ← getConstInfo `aux
forallTelescopeReducing c.type fun xs type => do
match type.eq? with
| none => throwError! "unexpected"
| some (_, lhs, _) =>
trace[Meta.debug]! "lhs: {lhs}"
let s ← Meta.getSimpLemmas
let m ← s.post.getMatch lhs
trace[Meta.debug]! "result: {m}"
assert! m.any fun s => s.name? == `ex2
set_option trace.Meta.debug true in
#eval tst2
|
e1cad0d5a387321d70fac3288a717f790984723c | 92b50235facfbc08dfe7f334827d47281471333b | /library/init/nat.lean | fe10da573bac26f19d283bd3e4906d97c8d9e037 | [
"Apache-2.0"
] | permissive | htzh/lean | 24f6ed7510ab637379ec31af406d12584d31792c | d70c79f4e30aafecdfc4a60b5d3512199200ab6e | refs/heads/master | 1,607,677,731,270 | 1,437,089,952,000 | 1,437,089,952,000 | 37,078,816 | 0 | 0 | null | 1,433,780,956,000 | 1,433,780,955,000 | null | UTF-8 | Lean | false | false | 11,407 | lean | /-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura
-/
prelude
import init.wf init.tactic init.num
open eq.ops decidable or
namespace nat
notation `ℕ` := nat
/- basic definitions on natural numbers -/
inductive le (a : ℕ) : ℕ → Prop :=
| refl : le a a
| step : Π {b}, le a b → le a (succ b)
infix `≤` := le
attribute le.refl [refl]
definition lt [reducible] (n m : ℕ) := succ n ≤ m
definition ge [reducible] (n m : ℕ) := m ≤ n
definition gt [reducible] (n m : ℕ) := succ m ≤ n
infix `<` := lt
infix `≥` := ge
infix `>` := gt
definition pred [unfold 1] (a : nat) : nat :=
nat.cases_on a zero (λ a₁, a₁)
-- add is defined in init.num
definition sub (a b : nat) : nat :=
nat.rec_on b a (λ b₁ r, pred r)
definition mul (a b : nat) : nat :=
nat.rec_on b zero (λ b₁ r, r + a)
notation a - b := sub a b
notation a * b := mul a b
/- properties of ℕ -/
protected definition is_inhabited [instance] : inhabited nat :=
inhabited.mk zero
protected definition has_decidable_eq [instance] : ∀ x y : nat, decidable (x = y)
| has_decidable_eq zero zero := inl rfl
| has_decidable_eq (succ x) zero := inr (by contradiction)
| has_decidable_eq zero (succ y) := inr (by contradiction)
| has_decidable_eq (succ x) (succ y) :=
match has_decidable_eq x y with
| inl xeqy := inl (by rewrite xeqy)
| inr xney := inr (λ h : succ x = succ y, by injection h with xeqy; exact absurd xeqy xney)
end
/- properties of inequality -/
theorem le_of_eq {n m : ℕ} (p : n = m) : n ≤ m := p ▸ le.refl n
theorem le_succ (n : ℕ) : n ≤ succ n := by repeat constructor
theorem pred_le (n : ℕ) : pred n ≤ n := by cases n;all_goals (repeat constructor)
theorem le_succ_iff_true [rewrite] (n : ℕ) : n ≤ succ n ↔ true :=
iff_true_intro (le_succ n)
theorem pred_le_iff_true [rewrite] (n : ℕ) : pred n ≤ n ↔ true :=
iff_true_intro (pred_le n)
theorem le.trans [trans] {n m k : ℕ} (H1 : n ≤ m) (H2 : m ≤ k) : n ≤ k :=
by induction H2 with n H2 IH;exact H1;exact le.step IH
theorem le_succ_of_le {n m : ℕ} (H : n ≤ m) : n ≤ succ m := le.trans H !le_succ
theorem le_of_succ_le {n m : ℕ} (H : succ n ≤ m) : n ≤ m := le.trans !le_succ H
theorem le_of_lt {n m : ℕ} (H : n < m) : n ≤ m := le_of_succ_le H
theorem succ_le_succ {n m : ℕ} (H : n ≤ m) : succ n ≤ succ m :=
by induction H;reflexivity;exact le.step v_0
theorem pred_le_pred {n m : ℕ} (H : n ≤ m) : pred n ≤ pred m :=
by induction H;reflexivity;cases b;exact v_0;exact le.step v_0
theorem le_of_succ_le_succ {n m : ℕ} (H : succ n ≤ succ m) : n ≤ m :=
pred_le_pred H
theorem le_succ_of_pred_le {n m : ℕ} (H : pred n ≤ m) : n ≤ succ m :=
by cases n;exact le.step H;exact succ_le_succ H
theorem not_succ_le_self {n : ℕ} : ¬succ n ≤ n :=
by induction n with n IH;all_goals intros;cases a;apply IH;exact le_of_succ_le_succ a
theorem succ_le_self_iff_false [rewrite] (n : ℕ) : succ n ≤ n ↔ false :=
iff_false_intro not_succ_le_self
theorem zero_le (n : ℕ) : 0 ≤ n :=
by induction n with n IH;apply le.refl;exact le.step IH
theorem zero_le_iff_true [rewrite] (n : ℕ) : 0 ≤ n ↔ true :=
iff_true_intro (zero_le n)
theorem lt.step {n m : ℕ} (H : n < m) : n < succ m :=
le.step H
theorem zero_lt_succ (n : ℕ) : 0 < succ n :=
by induction n with n IH;apply le.refl;exact le.step IH
theorem zero_lt_succ_iff_true [rewrite] (n : ℕ) : 0 < succ n ↔ true :=
iff_true_intro (zero_lt_succ n)
theorem lt.trans [trans] {n m k : ℕ} (H1 : n < m) (H2 : m < k) : n < k :=
le.trans (le.step H1) H2
theorem lt_of_le_of_lt [trans] {n m k : ℕ} (H1 : n ≤ m) (H2 : m < k) : n < k :=
le.trans (succ_le_succ H1) H2
theorem lt_of_lt_of_le [trans] {n m k : ℕ} (H1 : n < m) (H2 : m ≤ k) : n < k :=
le.trans H1 H2
theorem le.antisymm {n m : ℕ} (H1 : n ≤ m) (H2 : m ≤ n) : n = m :=
begin
cases H1 with m' H1',
{ reflexivity},
{ cases H2 with n' H2',
{ reflexivity},
{ exfalso, apply not_succ_le_self, exact lt.trans H1' H2'}},
end
theorem not_succ_le_zero (n : ℕ) : ¬succ n ≤ zero :=
by intro H; cases H
theorem succ_le_zero_iff_false (n : ℕ) : succ n ≤ zero ↔ false :=
iff_false_intro (not_succ_le_zero n)
theorem lt.irrefl (n : ℕ) : ¬n < n := not_succ_le_self
theorem lt_self_iff_false [rewrite] (n : ℕ) : n < n ↔ false :=
iff_false_intro (lt.irrefl n)
theorem self_lt_succ (n : ℕ) : n < succ n := !le.refl
theorem self_lt_succ_iff_true [rewrite] (n : ℕ) : n < succ n ↔ true :=
iff_true_intro (self_lt_succ n)
theorem lt.base (n : ℕ) : n < succ n := !le.refl
theorem le_lt_antisymm {n m : ℕ} (H1 : n ≤ m) (H2 : m < n) : false :=
!lt.irrefl (lt_of_le_of_lt H1 H2)
theorem lt_le_antisymm {n m : ℕ} (H1 : n < m) (H2 : m ≤ n) : false :=
le_lt_antisymm H2 H1
theorem lt.asymm {n m : ℕ} (H1 : n < m) (H2 : m < n) : false :=
le_lt_antisymm (le_of_lt H1) H2
definition lt.by_cases {a b : ℕ} {P : Type} (H1 : a < b → P) (H2 : a = b → P) (H3 : b < a → P) : P :=
begin
revert b H1 H2 H3, induction a with a IH,
{ intros, cases b,
exact H2 rfl,
exact H1 !zero_lt_succ},
{ intros, cases b with b,
exact H3 !zero_lt_succ,
{ apply IH,
intro H, exact H1 (succ_le_succ H),
intro H, exact H2 (congr rfl H),
intro H, exact H3 (succ_le_succ H)}}
end
theorem lt.trichotomy (a b : ℕ) : a < b ∨ a = b ∨ b < a :=
lt.by_cases (λH, inl H) (λH, inr (inl H)) (λH, inr (inr H))
theorem lt_ge_by_cases {a b : ℕ} {P : Type} (H1 : a < b → P) (H2 : a ≥ b → P) : P :=
lt.by_cases H1 (λH, H2 (le_of_eq H⁻¹)) (λH, H2 (le_of_lt H))
theorem lt_or_ge (a b : ℕ) : (a < b) ∨ (a ≥ b) :=
lt_ge_by_cases inl inr
theorem not_lt_zero (a : ℕ) : ¬ a < zero :=
by intro H; cases H
theorem lt_zero_iff_false [rewrite] (a : ℕ) : a < zero ↔ false :=
iff_false_intro (not_lt_zero a)
-- less-than is well-founded
definition lt.wf [instance] : well_founded lt :=
begin
constructor, intro n, induction n with n IH,
{ constructor, intros n H, exfalso, exact !not_lt_zero H},
{ constructor, intros m H,
assert aux : ∀ {n₁} (hlt : m < n₁), succ n = n₁ → acc lt m,
{ intros n₁ hlt, induction hlt,
{ intro p, injection p with q, exact q ▸ IH},
{ intro p, injection p with q, exact (acc.inv (q ▸ IH) a)}},
apply aux H rfl},
end
definition measure {A : Type} (f : A → ℕ) : A → A → Prop :=
inv_image lt f
definition measure.wf {A : Type} (f : A → ℕ) : well_founded (measure f) :=
inv_image.wf f lt.wf
theorem succ_lt_succ {a b : ℕ} (H : a < b) : succ a < succ b :=
succ_le_succ H
theorem lt_of_succ_lt {a b : ℕ} (H : succ a < b) : a < b :=
le_of_succ_le H
theorem lt_of_succ_lt_succ {a b : ℕ} (H : succ a < succ b) : a < b :=
le_of_succ_le_succ H
definition decidable_le [instance] : decidable_rel le :=
begin
intros n, induction n with n IH,
{ intro m, left, apply zero_le},
{ intro m, cases m with m,
{ right, apply not_succ_le_zero},
{ let H := IH m, clear IH,
cases H with H H,
left, exact succ_le_succ H,
right, intro H2, exact H (le_of_succ_le_succ H2)}}
end
definition decidable_lt [instance] : decidable_rel lt := _
definition decidable_gt [instance] : decidable_rel gt := _
definition decidable_ge [instance] : decidable_rel ge := _
theorem eq_or_lt_of_le {a b : ℕ} (H : a ≤ b) : a = b ∨ a < b :=
by cases H with b' H; exact inl rfl; exact inr (succ_le_succ H)
theorem le_of_eq_or_lt {a b : ℕ} (H : a = b ∨ a < b) : a ≤ b :=
by cases H with H H; exact le_of_eq H; exact le_of_lt H
theorem eq_or_lt_of_not_lt {a b : ℕ} (hnlt : ¬ a < b) : a = b ∨ b < a :=
or.rec_on (lt.trichotomy a b)
(λ hlt, absurd hlt hnlt)
(λ h, h)
theorem lt_succ_of_le {a b : ℕ} (h : a ≤ b) : a < succ b :=
succ_le_succ h
theorem lt_of_succ_le {a b : ℕ} (h : succ a ≤ b) : a < b := h
theorem succ_le_of_lt {a b : ℕ} (h : a < b) : succ a ≤ b := h
definition max (a b : ℕ) : ℕ := if a < b then b else a
definition min (a b : ℕ) : ℕ := if a < b then a else b
theorem max_self [rewrite] (a : ℕ) : max a a = a :=
eq.rec_on !if_t_t rfl
theorem max_eq_right' {a b : ℕ} (H : a < b) : max a b = b :=
if_pos H
-- different versions will be defined in algebra
theorem max_eq_left' {a b : ℕ} (H : ¬ a < b) : max a b = a :=
if_neg H
theorem eq_max_right {a b : ℕ} (H : a < b) : b = max a b :=
eq.rec_on (max_eq_right' H) rfl
theorem eq_max_left {a b : ℕ} (H : ¬ a < b) : a = max a b :=
eq.rec_on (max_eq_left' H) rfl
theorem le_max_left (a b : ℕ) : a ≤ max a b :=
by_cases
(λ h : a < b, le_of_lt (eq.rec_on (eq_max_right h) h))
(λ h : ¬ a < b, eq.rec_on (eq_max_left h) !le.refl)
theorem le_max_left_iff_true [rewrite] (a b : ℕ) : a ≤ max a b ↔ true :=
iff_true_intro (le_max_left a b)
theorem le_max_right (a b : ℕ) : b ≤ max a b :=
by_cases
(λ h : a < b, eq.rec_on (eq_max_right h) !le.refl)
(λ h : ¬ a < b, or.rec_on (eq_or_lt_of_not_lt h)
(λ heq, eq.rec_on heq (eq.rec_on (eq.symm (max_self a)) !le.refl))
(λ h : b < a,
have aux : a = max a b, from eq_max_left (lt.asymm h),
eq.rec_on aux (le_of_lt h)))
theorem le_max_right_iff_true [rewrite] (a b : ℕ) : b ≤ max a b ↔ true :=
iff_true_intro (le_max_right a b)
theorem succ_sub_succ_eq_sub [rewrite] (a b : ℕ) : succ a - succ b = a - b :=
by induction b with b IH;reflexivity; apply congr (eq.refl pred) IH
theorem sub_eq_succ_sub_succ (a b : ℕ) : a - b = succ a - succ b :=
eq.rec_on (succ_sub_succ_eq_sub a b) rfl
theorem zero_sub_eq_zero [rewrite] (a : ℕ) : zero - a = zero :=
nat.rec_on a
rfl
(λ a₁ (ih : zero - a₁ = zero), congr (eq.refl pred) ih)
theorem zero_eq_zero_sub (a : ℕ) : zero = zero - a :=
eq.rec_on (zero_sub_eq_zero a) rfl
theorem sub_lt {a b : ℕ} : zero < a → zero < b → a - b < a :=
have aux : Π {a}, zero < a → Π {b}, zero < b → a - b < a, from
λa h₁, le.rec_on h₁
(λb h₂, le.cases_on h₂
(lt.base zero)
(λ b₁ bpos,
eq.rec_on (sub_eq_succ_sub_succ zero b₁)
(eq.rec_on (zero_eq_zero_sub b₁) (lt.base zero))))
(λa₁ apos ih b h₂, le.cases_on h₂
(lt.base a₁)
(λ b₁ bpos,
eq.rec_on (sub_eq_succ_sub_succ a₁ b₁)
(lt.trans (@ih b₁ bpos) (lt.base a₁)))),
λ h₁ h₂, aux h₁ h₂
theorem sub_le (a b : ℕ) : a - b ≤ a :=
nat.rec_on b
(le.refl a)
(λ b₁ ih, le.trans !pred_le ih)
theorem sub_le_iff_true [rewrite] (a b : ℕ) : a - b ≤ a ↔ true :=
iff_true_intro (sub_le a b)
theorem sub_lt_succ (a b : ℕ) : a - b < succ a :=
lt_succ_of_le (sub_le a b)
theorem sub_lt_succ_iff_true [rewrite] (a b : ℕ) : a - b < succ a ↔ true :=
iff_true_intro (sub_lt_succ a b)
end nat
|
923ca0a16f662ce53d69d80aa35ec4ef5360d0db | d436468d80b739ba7e06843c4d0d2070e43448e5 | /src/data/real/nnreal.lean | 8bc895ec25b4b8deca0625a599dab1509737a38a | [
"Apache-2.0"
] | permissive | roro47/mathlib | 761fdc002aef92f77818f3fef06bf6ec6fc1a28e | 80aa7d52537571a2ca62a3fdf71c9533a09422cf | refs/heads/master | 1,599,656,410,625 | 1,573,649,488,000 | 1,573,649,488,000 | 221,452,951 | 0 | 0 | Apache-2.0 | 1,573,647,693,000 | 1,573,647,692,000 | null | UTF-8 | Lean | false | false | 17,337 | lean | /-
Copyright (c) 2018 Johan Commelin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johan Commelin
Nonnegative real numbers.
-/
import data.real.basic order.lattice algebra.field
noncomputable theory
open lattice
open_locale classical
/-- Nonnegative real numbers. -/
def nnreal := {r : ℝ // 0 ≤ r}
localized "notation ` ℝ≥0 ` := nnreal" in nnreal
namespace nnreal
instance : has_coe ℝ≥0 ℝ := ⟨subtype.val⟩
instance : can_lift ℝ nnreal :=
{ coe := coe,
cond := λ r, r ≥ 0,
prf := λ x hx, ⟨⟨x, hx⟩, rfl⟩ }
protected lemma eq {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) → n = m := subtype.eq
protected lemma eq_iff {n m : ℝ≥0} : (n : ℝ) = (m : ℝ) ↔ n = m :=
iff.intro nnreal.eq (congr_arg coe)
protected def of_real (r : ℝ) : ℝ≥0 := ⟨max r 0, le_max_right _ _⟩
lemma coe_of_real (r : ℝ) (hr : 0 ≤ r) : (nnreal.of_real r : ℝ) = r :=
max_eq_left hr
lemma coe_nonneg (r : nnreal) : (0 : ℝ) ≤ r := r.2
instance : has_zero ℝ≥0 := ⟨⟨0, le_refl 0⟩⟩
instance : has_one ℝ≥0 := ⟨⟨1, zero_le_one⟩⟩
instance : has_add ℝ≥0 := ⟨λa b, ⟨a + b, add_nonneg a.2 b.2⟩⟩
instance : has_sub ℝ≥0 := ⟨λa b, nnreal.of_real (a - b)⟩
instance : has_mul ℝ≥0 := ⟨λa b, ⟨a * b, mul_nonneg a.2 b.2⟩⟩
instance : has_inv ℝ≥0 := ⟨λa, ⟨(a.1)⁻¹, inv_nonneg.2 a.2⟩⟩
instance : has_div ℝ≥0 := ⟨λa b, ⟨a.1 / b.1, div_nonneg' a.2 b.2⟩⟩
instance : has_le ℝ≥0 := ⟨λ r s, (r:ℝ) ≤ s⟩
instance : has_bot ℝ≥0 := ⟨0⟩
instance : inhabited ℝ≥0 := ⟨0⟩
@[simp] protected lemma coe_zero : ((0 : ℝ≥0) : ℝ) = 0 := rfl
@[simp] protected lemma coe_one : ((1 : ℝ≥0) : ℝ) = 1 := rfl
@[simp] protected lemma coe_add (r₁ r₂ : ℝ≥0) : ((r₁ + r₂ : ℝ≥0) : ℝ) = r₁ + r₂ := rfl
@[simp] protected lemma coe_mul (r₁ r₂ : ℝ≥0) : ((r₁ * r₂ : ℝ≥0) : ℝ) = r₁ * r₂ := rfl
@[simp] protected lemma coe_div (r₁ r₂ : ℝ≥0) : ((r₁ / r₂ : ℝ≥0) : ℝ) = r₁ / r₂ := rfl
@[simp] protected lemma coe_inv (r : ℝ≥0) : ((r⁻¹ : ℝ≥0) : ℝ) = r⁻¹ := rfl
@[simp] protected lemma coe_sub (r₁ r₂ : ℝ≥0) (h : r₂ ≤ r₁) : ((r₁ - r₂ : ℝ≥0) : ℝ) = r₁ - r₂ :=
max_eq_left $ le_sub.2 $ by simp [show (r₂ : ℝ) ≤ r₁, from h]
-- TODO: setup semifield!
@[simp] protected lemma zero_div (r : ℝ≥0) : 0 / r = 0 := nnreal.eq (zero_div _)
@[simp] protected lemma coe_eq_zero (r : ℝ≥0) : ↑r = (0 : ℝ) ↔ r = 0 := @nnreal.eq_iff r 0
instance : comm_semiring ℝ≥0 :=
begin
refine { zero := 0, add := (+), one := 1, mul := (*), ..};
{ intros;
apply nnreal.eq;
simp [mul_comm, mul_assoc, add_comm_monoid.add, left_distrib, right_distrib,
add_comm_monoid.zero] }
end
instance : is_semiring_hom (coe : ℝ≥0 → ℝ) := by refine_struct {..}; intros; refl
lemma sum_coe {α} {s : finset α} {f : α → ℝ≥0} : ↑(s.sum f) = s.sum (λa, (f a : ℝ)) :=
eq.symm $ finset.sum_hom _
lemma prod_coe {α} {s : finset α} {f : α → ℝ≥0} : ↑(s.prod f) = s.prod (λa, (f a : ℝ)) :=
eq.symm $ finset.prod_hom _
lemma smul_coe (r : ℝ≥0) : ∀n, ↑(add_monoid.smul n r) = add_monoid.smul n (r:ℝ)
| 0 := rfl
| (n + 1) := by simp [add_monoid.add_smul, smul_coe n]
@[simp] protected lemma coe_nat_cast : ∀(n : ℕ), (↑(↑n : ℝ≥0) : ℝ) = n
| 0 := rfl
| (n + 1) := by simp [coe_nat_cast n]
instance : decidable_linear_order ℝ≥0 :=
decidable_linear_order.lift (coe : ℝ≥0 → ℝ) subtype.val_injective (by apply_instance)
@[elim_cast] protected lemma coe_le {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) ≤ r₂ ↔ r₁ ≤ r₂ := iff.rfl
@[elim_cast] protected lemma coe_lt {r₁ r₂ : ℝ≥0} : (r₁ : ℝ) < r₂ ↔ r₁ < r₂ := iff.rfl
@[elim_cast] protected lemma coe_pos {r : ℝ≥0} : (0 : ℝ) < r ↔ 0 < r := iff.rfl
instance : order_bot ℝ≥0 :=
{ bot := ⊥, bot_le := assume ⟨a, h⟩, h, .. nnreal.decidable_linear_order }
instance : canonically_ordered_monoid ℝ≥0 :=
{ add_le_add_left := assume a b h c, @add_le_add_left ℝ _ a b h c,
lt_of_add_lt_add_left := assume a b c, @lt_of_add_lt_add_left ℝ _ a b c,
le_iff_exists_add := assume ⟨a, ha⟩ ⟨b, hb⟩,
iff.intro
(assume h : a ≤ b,
⟨⟨b - a, le_sub_iff_add_le.2 $ by simp [h]⟩,
nnreal.eq $ show b = a + (b - a), by rw [add_sub_cancel'_right]⟩)
(assume ⟨⟨c, hc⟩, eq⟩, eq.symm ▸ show a ≤ a + c, from (le_add_iff_nonneg_right a).2 hc),
..nnreal.comm_semiring,
..nnreal.lattice.order_bot,
..nnreal.decidable_linear_order }
instance : distrib_lattice ℝ≥0 := by apply_instance
instance : semilattice_inf_bot ℝ≥0 :=
{ .. nnreal.lattice.order_bot, .. nnreal.lattice.distrib_lattice }
instance : semilattice_sup_bot ℝ≥0 :=
{ .. nnreal.lattice.order_bot, .. nnreal.lattice.distrib_lattice }
instance : linear_ordered_semiring ℝ≥0 :=
{ add_left_cancel := assume a b c h, nnreal.eq $ @add_left_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
add_right_cancel := assume a b c h, nnreal.eq $ @add_right_cancel ℝ _ a b c (nnreal.eq_iff.2 h),
le_of_add_le_add_left := assume a b c, @le_of_add_le_add_left ℝ _ a b c,
mul_le_mul_of_nonneg_left := assume a b c, @mul_le_mul_of_nonneg_left ℝ _ a b c,
mul_le_mul_of_nonneg_right := assume a b c, @mul_le_mul_of_nonneg_right ℝ _ a b c,
mul_lt_mul_of_pos_left := assume a b c, @mul_lt_mul_of_pos_left ℝ _ a b c,
mul_lt_mul_of_pos_right := assume a b c, @mul_lt_mul_of_pos_right ℝ _ a b c,
zero_lt_one := @zero_lt_one ℝ _,
.. nnreal.decidable_linear_order,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : canonically_ordered_comm_semiring ℝ≥0 :=
{ zero_ne_one := assume h, @zero_ne_one ℝ _ $ congr_arg subtype.val $ h,
mul_eq_zero_iff := assume a b, nnreal.eq_iff.symm.trans $ mul_eq_zero.trans $ by simp,
.. nnreal.linear_ordered_semiring,
.. nnreal.canonically_ordered_monoid,
.. nnreal.comm_semiring }
instance : densely_ordered ℝ≥0 :=
⟨assume a b (h : (a : ℝ) < b), let ⟨c, hac, hcb⟩ := dense h in
⟨⟨c, le_trans a.property $ le_of_lt $ hac⟩, hac, hcb⟩⟩
instance : no_top_order ℝ≥0 :=
⟨assume a, let ⟨b, hb⟩ := no_top (a:ℝ) in ⟨⟨b, le_trans a.property $ le_of_lt $ hb⟩, hb⟩⟩
lemma bdd_above_coe {s : set ℝ≥0} : bdd_above ((coe : nnreal → ℝ) '' s) ↔ bdd_above s :=
iff.intro
(assume ⟨b, hb⟩, ⟨nnreal.of_real b, assume ⟨y, hy⟩ hys, show y ≤ max b 0, from
le_max_left_of_le $ hb _ $ set.mem_image_of_mem _ hys⟩)
(assume ⟨b, hb⟩, ⟨b, assume y ⟨x, hx, eq⟩, eq ▸ hb _ $ hx⟩)
lemma bdd_below_coe (s : set ℝ≥0) : bdd_below ((coe : nnreal → ℝ) '' s) :=
⟨0, assume r ⟨q, _, eq⟩, eq ▸ q.2⟩
instance : has_Sup ℝ≥0 :=
⟨λs, ⟨Sup ((coe : nnreal → ℝ) '' s),
begin
by_cases h : s = ∅,
{ simp [h, set.image_empty, real.Sup_empty] },
rcases set.ne_empty_iff_exists_mem.1 h with ⟨⟨b, hb⟩, hbs⟩,
by_cases h' : bdd_above s,
{ exact le_cSup_of_le (bdd_above_coe.2 h') (set.mem_image_of_mem _ hbs) hb },
{ rw [real.Sup_of_not_bdd_above], rwa [bdd_above_coe] }
end⟩⟩
instance : has_Inf ℝ≥0 :=
⟨λs, ⟨Inf ((coe : nnreal → ℝ) '' s),
begin
by_cases h : s = ∅,
{ simp [h, set.image_empty, real.Inf_empty] },
exact le_cInf (by simp [h]) (assume r ⟨q, _, eq⟩, eq ▸ q.2)
end⟩⟩
lemma coe_Sup (s : set nnreal) : (↑(Sup s) : ℝ) = Sup ((coe : nnreal → ℝ) '' s) := rfl
lemma coe_Inf (s : set nnreal) : (↑(Inf s) : ℝ) = Inf ((coe : nnreal → ℝ) '' s) := rfl
instance : conditionally_complete_linear_order_bot ℝ≥0 :=
{ Sup := Sup,
Inf := Inf,
le_cSup := assume s a hs ha, le_cSup (bdd_above_coe.2 hs) (set.mem_image_of_mem _ ha),
cSup_le := assume s a hs h,show Sup ((coe : nnreal → ℝ) '' s) ≤ a, from
cSup_le (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h _ hb,
cInf_le := assume s a _ has, cInf_le (bdd_below_coe s) (set.mem_image_of_mem _ has),
le_cInf := assume s a hs h, show (↑a : ℝ) ≤ Inf ((coe : nnreal → ℝ) '' s), from
le_cInf (by simp [hs]) $ assume r ⟨b, hb, eq⟩, eq ▸ h _ hb,
cSup_empty := nnreal.eq $ by simp [coe_Sup, real.Sup_empty]; refl,
decidable_le := begin assume x y, apply classical.dec end,
.. nnreal.linear_ordered_semiring, .. lattice.lattice_of_decidable_linear_order,
.. nnreal.lattice.order_bot }
instance : archimedean nnreal :=
⟨ assume x y pos_y,
let ⟨n, hr⟩ := archimedean.arch (x:ℝ) (pos_y : (0 : ℝ) < y) in
⟨n, show (x:ℝ) ≤ (add_monoid.smul n y : nnreal), by simp [*, smul_coe]⟩ ⟩
lemma le_of_forall_epsilon_le {a b : nnreal} (h : ∀ε, ε > 0 → a ≤ b + ε) : a ≤ b :=
le_of_forall_le_of_dense $ assume x hxb,
begin
rcases le_iff_exists_add.1 (le_of_lt hxb) with ⟨ε, rfl⟩,
exact h _ ((lt_add_iff_pos_right b).1 hxb)
end
lemma lt_iff_exists_rat_btwn (a b : nnreal) :
a < b ↔ (∃q:ℚ, 0 ≤ q ∧ a < nnreal.of_real q ∧ nnreal.of_real q < b) :=
iff.intro
(assume (h : (↑a:ℝ) < (↑b:ℝ)),
let ⟨q, haq, hqb⟩ := exists_rat_btwn h in
have 0 ≤ (q : ℝ), from le_trans a.2 $ le_of_lt haq,
⟨q, rat.cast_nonneg.1 this, by simp [coe_of_real _ this, nnreal.coe_lt.symm, haq, hqb]⟩)
(assume ⟨q, _, haq, hqb⟩, lt_trans haq hqb)
lemma bot_eq_zero : (⊥ : nnreal) = 0 := rfl
lemma mul_sup (a b c : ℝ≥0) : a * (b ⊔ c) = (a * b) ⊔ (a * c) :=
begin
cases le_total b c with h h,
{ simp [sup_eq_max, max_eq_right h, max_eq_right (mul_le_mul_of_nonneg_left h (zero_le a))] },
{ simp [sup_eq_max, max_eq_left h, max_eq_left (mul_le_mul_of_nonneg_left h (zero_le a))] },
end
lemma mul_finset_sup {α} {f : α → ℝ≥0} {s : finset α} (r : ℝ≥0) :
r * s.sup f = s.sup (λa, r * f a) :=
begin
refine s.induction_on _ _,
{ simp [bot_eq_zero] },
{ assume a s has ih, simp [has, ih, mul_sup], }
end
section of_real
@[simp] lemma zero_le_coe {q : nnreal} : 0 ≤ (q : ℝ) := q.2
@[simp] lemma of_real_zero : nnreal.of_real 0 = 0 :=
by simp [nnreal.of_real]; refl
@[simp] lemma of_real_one : nnreal.of_real 1 = 1 :=
by simp [nnreal.of_real, max_eq_left (zero_le_one : (0 :ℝ) ≤ 1)]; refl
@[simp] lemma of_real_pos {r : ℝ} : 0 < nnreal.of_real r ↔ 0 < r :=
by simp [nnreal.of_real, nnreal.coe_lt.symm, lt_irrefl]
@[simp] lemma of_real_eq_zero {r : ℝ} : nnreal.of_real r = 0 ↔ r ≤ 0 :=
by simpa [-of_real_pos] using (not_iff_not.2 (@of_real_pos r))
lemma of_real_of_nonpos {r : ℝ} : r ≤ 0 → nnreal.of_real r = 0 :=
of_real_eq_zero.2
@[simp] lemma of_real_coe {r : nnreal} : nnreal.of_real r = r :=
nnreal.eq $ by simp [nnreal.of_real]
@[simp] lemma of_real_le_of_real_iff {r p : ℝ} (hp : 0 ≤ p) :
nnreal.of_real r ≤ nnreal.of_real p ↔ r ≤ p :=
by simp [nnreal.coe_le.symm, nnreal.of_real, hp]
@[simp] lemma of_real_lt_of_real_iff' {r p : ℝ} :
nnreal.of_real r < nnreal.of_real p ↔ r < p ∧ 0 < p :=
by simp [nnreal.coe_lt.symm, nnreal.of_real, lt_irrefl]
lemma of_real_lt_of_real_iff {r p : ℝ} (h : 0 < p) :
nnreal.of_real r < nnreal.of_real p ↔ r < p :=
of_real_lt_of_real_iff'.trans (and_iff_left h)
@[simp] lemma of_real_add {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real (r + p) = nnreal.of_real r + nnreal.of_real p :=
nnreal.eq $ by simp [nnreal.of_real, hr, hp, add_nonneg]
lemma of_real_add_of_real {r p : ℝ} (hr : 0 ≤ r) (hp : 0 ≤ p) :
nnreal.of_real r + nnreal.of_real p = nnreal.of_real (r + p) :=
(of_real_add hr hp).symm
lemma of_real_le_of_real {r p : ℝ} (h : r ≤ p) : nnreal.of_real r ≤ nnreal.of_real p :=
nnreal.coe_le.2 $ max_le_max h $ le_refl _
lemma of_real_add_le {r p : ℝ} : nnreal.of_real (r + p) ≤ nnreal.of_real r + nnreal.of_real p :=
nnreal.coe_le.1 $ max_le (add_le_add (le_max_left _ _) (le_max_left _ _)) nnreal.zero_le_coe
lemma of_real_le_iff_le_coe {r : ℝ} {p : nnreal} : nnreal.of_real r ≤ p ↔ r ≤ ↑p :=
begin
cases le_total 0 r,
{ rw [← nnreal.coe_le, nnreal.coe_of_real r h] },
{ rw [of_real_eq_zero.2 h], split,
intro, exact le_trans h (coe_nonneg _),
intro, exact zero_le _ }
end
lemma le_of_real_iff_coe_le {r : nnreal} {p : ℝ} (hp : p ≥ 0) : r ≤ nnreal.of_real p ↔ ↑r ≤ p :=
by rw [← nnreal.coe_le, nnreal.coe_of_real p hp]
lemma of_real_lt_iff_lt_coe {r : ℝ} {p : nnreal} (ha : r ≥ 0) : nnreal.of_real r < p ↔ r < ↑p :=
by rw [← nnreal.coe_lt, nnreal.coe_of_real r ha]
lemma lt_of_real_iff_coe_lt {r : nnreal} {p : ℝ} : r < nnreal.of_real p ↔ ↑r < p :=
begin
cases le_total 0 p,
{ rw [← nnreal.coe_lt, nnreal.coe_of_real p h] },
{ rw [of_real_eq_zero.2 h], split,
intro, have := not_lt_of_le (zero_le r), contradiction,
intro rp, have : ¬(p ≤ 0) := not_le_of_lt (lt_of_le_of_lt (coe_nonneg _) rp), contradiction }
end
end of_real
section mul
lemma mul_eq_mul_left {a b c : nnreal} (h : a ≠ 0) : (a * b = a * c ↔ b = c) :=
begin
rw [← nnreal.eq_iff, ← nnreal.eq_iff, nnreal.coe_mul, nnreal.coe_mul], split,
{ exact eq_of_mul_eq_mul_left (mt (@nnreal.eq_iff a 0).1 h) },
{ assume h, rw [h] }
end
lemma of_real_mul {p q : ℝ} (hp : 0 ≤ p) :
nnreal.of_real (p * q) = nnreal.of_real p * nnreal.of_real q :=
begin
cases le_total 0 q with hq hq,
{ apply nnreal.eq,
have := max_eq_left (mul_nonneg hp hq),
simpa [nnreal.of_real, hp, hq, max_eq_left] },
{ have hpq := mul_nonpos_of_nonneg_of_nonpos hp hq,
rw [of_real_eq_zero.2 hq, of_real_eq_zero.2 hpq, mul_zero] }
end
end mul
section sub
lemma sub_eq_zero {r p : nnreal} (h : r ≤ p) : r - p = 0 :=
nnreal.eq $ max_eq_right $ sub_le_iff_le_add.2 $ by simpa [nnreal.coe_le] using h
protected lemma sub_lt_self {r p : nnreal} : 0 < r → 0 < p → r - p < r :=
assume hr hp,
begin
cases le_total r p,
{ rwa [sub_eq_zero h] },
{ rw [← nnreal.coe_lt, nnreal.coe_sub _ _ h], exact sub_lt_self _ hp }
end
@[simp] lemma sub_le_iff_le_add {r p q : nnreal} : r - p ≤ q ↔ r ≤ q + p :=
match le_total p r with
| or.inl h :=
by rw [← nnreal.coe_le, ← nnreal.coe_le, nnreal.coe_sub _ _ h, nnreal.coe_add, sub_le_iff_le_add]
| or.inr h :=
have r ≤ p + q, from le_add_right h,
by simpa [nnreal.coe_le, nnreal.coe_le, sub_eq_zero h]
end
lemma add_sub_cancel {r p : nnreal} : (p + r) - r = p :=
nnreal.eq $ by rw [nnreal.coe_sub, nnreal.coe_add, add_sub_cancel]; exact le_add_left (le_refl _)
lemma add_sub_cancel' {r p : nnreal} : (r + p) - r = p :=
by rw [add_comm, add_sub_cancel]
@[simp] lemma sub_add_cancel_of_le {a b : nnreal} (h : b ≤ a) : (a - b) + b = a :=
nnreal.eq $ by rw [nnreal.coe_add, nnreal.coe_sub _ _ h, sub_add_cancel]
end sub
section inv
lemma div_def {r p : nnreal} : r / p = r * p⁻¹ := rfl
@[simp] lemma inv_zero : (0 : nnreal)⁻¹ = 0 := nnreal.eq inv_zero
@[simp] lemma inv_eq_zero {r : nnreal} : (r : nnreal)⁻¹ = 0 ↔ r = 0 :=
by rw [← nnreal.eq_iff, nnreal.coe_inv, nnreal.coe_zero, inv_eq_zero, ← nnreal.coe_zero, nnreal.eq_iff]
@[simp] lemma inv_pos {r : nnreal} : 0 < r⁻¹ ↔ 0 < r :=
by simp [zero_lt_iff_ne_zero]
@[simp] lemma inv_mul_cancel {r : ℝ≥0} (h : r ≠ 0) : r⁻¹ * r = 1 :=
nnreal.eq $ inv_mul_cancel $ mt (@nnreal.eq_iff r 0).1 h
@[simp] lemma mul_inv_cancel {r : ℝ≥0} (h : r ≠ 0) : r * r⁻¹ = 1 :=
by rw [mul_comm, inv_mul_cancel h]
@[simp] lemma inv_inv {r : ℝ≥0} : r⁻¹⁻¹ = r := nnreal.eq $ inv_inv' _
@[simp] lemma inv_le {r p : ℝ≥0} (h : r ≠ 0) : r⁻¹ ≤ p ↔ 1 ≤ r * p :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h]
lemma inv_le_of_le_mul {r p : ℝ≥0} (h : 1 ≤ r * p) : r⁻¹ ≤ p :=
by by_cases r = 0; simp [*, inv_le]
@[simp] lemma le_inv_iff_mul_le {r p : ℝ≥0} (h : p ≠ 0) : (r ≤ p⁻¹ ↔ r * p ≤ 1) :=
by rw [← mul_le_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
@[simp] lemma lt_inv_iff_mul_lt {r p : ℝ≥0} (h : p ≠ 0) : (r < p⁻¹ ↔ r * p < 1) :=
by rw [← mul_lt_mul_left (zero_lt_iff_ne_zero.2 h), mul_inv_cancel h, mul_comm]
lemma mul_le_if_le_inv {a b r : nnreal} (hr : r ≠ 0) : r * a ≤ b ↔ a ≤ r⁻¹ * b :=
have 0 < r, from lt_of_le_of_ne (zero_le r) hr.symm,
by rw [← @mul_le_mul_left _ _ a _ r this, ← mul_assoc, mul_inv_cancel hr, one_mul]
lemma le_of_forall_lt_one_mul_lt {x y : ℝ≥0} (h : ∀a<1, a * x ≤ y) : x ≤ y :=
le_of_forall_ge_of_dense $ assume a ha,
have hx : x ≠ 0 := zero_lt_iff_ne_zero.1 (lt_of_le_of_lt (zero_le _) ha),
have hx' : x⁻¹ ≠ 0, by rwa [(≠), inv_eq_zero],
have a * x⁻¹ < 1, by rwa [← lt_inv_iff_mul_lt hx', inv_inv],
have (a * x⁻¹) * x ≤ y, from h _ this,
by rwa [mul_assoc, inv_mul_cancel hx, mul_one] at this
lemma div_add_div_same (a b c : ℝ≥0) : a / c + b / c = (a + b) / c :=
eq.symm $ right_distrib a b (c⁻¹)
lemma add_halves (a : ℝ≥0) : a / 2 + a / 2 = a := nnreal.eq (add_halves a)
lemma half_lt_self {a : ℝ≥0} (h : a ≠ 0) : a / 2 < a :=
by rw [← nnreal.coe_lt, nnreal.coe_div]; exact
half_lt_self (bot_lt_iff_ne_bot.2 h)
end inv
end nnreal
|
db87d4a4801cf248870b08852be84eb875bf18e3 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/sizeof2.lean | 929ba9a182d11e8e69aed87078979bbfa705c827 | [
"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 | 204 | lean | mutual
inductive Arg (α : Type u) where
| val (a : α)
| expr (e : Expr α)
inductive Expr (α : Type u) where
| app (f : String) (a : List (Arg α))
end
#print Expr.app.sizeOf_spec
|
6a163fa462289ccd19ddb1c88ccc254010ee63af | 957a80ea22c5abb4f4670b250d55534d9db99108 | /library/init/algebra/classes.lean | 41d2db242015a129ff12b924defca42f6ca2640c | [
"Apache-2.0"
] | permissive | GaloisInc/lean | aa1e64d604051e602fcf4610061314b9a37ab8cd | f1ec117a24459b59c6ff9e56a1d09d9e9e60a6c0 | refs/heads/master | 1,592,202,909,807 | 1,504,624,387,000 | 1,504,624,387,000 | 75,319,626 | 2 | 1 | Apache-2.0 | 1,539,290,164,000 | 1,480,616,104,000 | C++ | UTF-8 | Lean | false | false | 2,902 | 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.logic
universes u
@[algebra] class is_commutative (α : Type u) (op : α → α → α) : Prop :=
(comm : ∀ a b, op a b = op b a)
@[algebra] class is_associative (α : Type u) (op : α → α → α) : Prop :=
(assoc : ∀ a b c, op (op a b) c = op a (op b c))
@[algebra] class is_left_id (α : Type u) (op : α → α → α) (o : inout α) : Prop :=
(left_id : ∀ a, op o a = a)
@[algebra] class is_right_id (α : Type u) (op : α → α → α) (o : inout α) : Prop :=
(right_id : ∀ a, op a o = a)
@[algebra] class is_left_null (α : Type u) (op : α → α → α) (o : inout α) : Prop :=
(left_null : ∀ a, op o a = o)
@[algebra] class is_right_null (α : Type u) (op : α → α → α) (o : inout α) : Prop :=
(right_null : ∀ a, op a o = o)
@[algebra] class is_left_cancel (α : Type u) (op : α → α → α) : Prop :=
(left_cancel : ∀ a b c, op a b = op a c → b = c)
@[algebra] class is_right_cancel (α : Type u) (op : α → α → α) : Prop :=
(right_cancel : ∀ a b c, op a b = op c b → a = c)
@[algebra] class is_idempotent (α : Type u) (op : α → α → α) : Prop :=
(idempotent : ∀ a, op a a = a)
@[algebra] class is_left_distrib (α : Type u) (op₁ : α → α → α) (op₂ : inout α → α → α) : Prop :=
(left_distrib : ∀ a b c, op₁ a (op₂ b c) = op₂ (op₁ a b) (op₁ a c))
@[algebra] class is_right_distrib (α : Type u) (op₁ : α → α → α) (op₂ : inout α → α → α) : Prop :=
(right_distrib : ∀ a b c, op₁ (op₂ a b) c = op₂ (op₁ a c) (op₁ b c))
@[algebra] class is_left_inv (α : Type u) (op : α → α → α) (inv : inout α → α) (o : inout α) : Prop :=
(left_inv : ∀ a, op (inv a) a = o)
@[algebra] class is_right_inv (α : Type u) (op : α → α → α) (inv : inout α → α) (o : inout α) : Prop :=
(right_inv : ∀ a, op a (inv a) = o)
@[algebra] class is_cond_left_inv (α : Type u) (op : α → α → α) (inv : inout α → α) (o : inout α) (p : inout α → Prop) : Prop :=
(left_inv : ∀ a, p a → op (inv a) a = o)
@[algebra] class is_cond_right_inv (α : Type u) (op : α → α → α) (inv : inout α → α) (o : inout α) (p : inout α → Prop) : Prop :=
(right_inv : ∀ a, p a → op a (inv a) = o)
@[algebra] class is_distinct (α : Type u) (a : α) (b : α) : Prop :=
(distinct : a ≠ b)
/-
-- The following type class doesn't seem very useful, a regular simp lemma should work for this.
class is_inv (α : Type u) (β : Type v) (f : α → β) (g : inout β → α) : Prop :=
(inv : ∀ a, g (f a) = a)
-- The following one can also be handled using a regular simp lemma
class is_idempotent (α : Type u) (f : α → α) : Prop :=
(idempotent : ∀ a, f (f a) = f a)
-/
|
9949b259e8e275777ed4c9d9a3ded31e7357d23b | 4efff1f47634ff19e2f786deadd394270a59ecd2 | /src/data/equiv/denumerable.lean | 64c3366f597a3e91d1cb2ad670a8a6509aa11240 | [
"Apache-2.0"
] | permissive | agjftucker/mathlib | d634cd0d5256b6325e3c55bb7fb2403548371707 | 87fe50de17b00af533f72a102d0adefe4a2285e8 | refs/heads/master | 1,625,378,131,941 | 1,599,166,526,000 | 1,599,166,526,000 | 160,748,509 | 0 | 0 | Apache-2.0 | 1,544,141,789,000 | 1,544,141,789,000 | null | UTF-8 | Lean | false | false | 9,157 | lean | /-
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Mario Carneiro
Denumerable (countably infinite) types, as a typeclass extending
encodable. This is used to provide explicit encode/decode functions
from nat, where the functions are known inverses of each other.
-/
import data.equiv.encodable.basic
import data.sigma
import data.fintype.basic
import data.list.min_max
open nat
section prio
set_option default_priority 100 -- see Note [default priority]
/-- 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)
end prio
namespace denumerable
section
variables {α : Type*} {β : Type*} [denumerable α] [denumerable β]
open encodable
theorem decode_is_some (α) [denumerable α] (n : ℕ) :
(decode α n).is_some :=
option.is_some_iff_exists.2 $
(decode_inv n).imp $ λ a, Exists.fst
def of_nat (α) [f : denumerable α] (n : ℕ) : α :=
option.get (decode_is_some α n)
@[simp, priority 900]
theorem decode_eq_of_nat (α) [denumerable α] (n : ℕ) :
decode α n = some (of_nat α n) :=
option.eq_some_of_is_some _
@[simp] theorem of_nat_of_decode {n b}
(h : decode α n = some b) : of_nat α n = b :=
option.some.inj $ (decode_eq_of_nat _ _).symm.trans h
@[simp] theorem encode_of_nat (n) : encode (of_nat α n) = n :=
let ⟨a, h, e⟩ := decode_inv n in
by rwa [of_nat_of_decode h]
@[simp] theorem of_nat_encode (a) : of_nat α (encode a) = a :=
of_nat_of_decode (encodek _)
def eqv (α) [denumerable α] : α ≃ ℕ :=
⟨encode, of_nat α, of_nat_encode, encode_of_nat⟩
def mk' {α} (e : α ≃ ℕ) : denumerable α :=
{ encode := e,
decode := some ∘ e.symm,
encodek := λ a, congr_arg some (e.symm_apply_apply _),
decode_inv := λ n, ⟨_, rfl, e.apply_symm_apply _⟩ }
def of_equiv (α) {β} [denumerable α] (e : β ≃ α) : denumerable β :=
{ decode_inv := λ n, by simp,
..encodable.of_equiv _ e }
@[simp] theorem of_equiv_of_nat (α) {β} [denumerable α] (e : β ≃ α)
(n) : @of_nat β (of_equiv _ e) n = e.symm (of_nat α n) :=
by apply of_nat_of_decode; show option.map _ _ = _; simp
def equiv₂ (α β) [denumerable α] [denumerable β] : α ≃ β := (eqv α).trans (eqv β).symm
instance nat : denumerable nat := ⟨λ n, ⟨_, rfl, rfl⟩⟩
@[simp] theorem of_nat_nat (n) : of_nat ℕ n = n := rfl
instance option : denumerable (option α) := ⟨λ n, by cases n; simp⟩
instance sum : denumerable (α ⊕ β) :=
⟨λ n, begin
suffices : ∃ a ∈ @decode_sum α β _ _ n,
encode_sum a = bit (bodd n) (div2 n), {simpa [bit_decomp]},
simp [decode_sum]; cases bodd n; simp [decode_sum, bit, encode_sum]
end⟩
section sigma
variables {γ : α → Type*} [∀ a, denumerable (γ a)]
instance sigma : denumerable (sigma γ) :=
⟨λ n, by simp [decode_sigma]; exact ⟨_, _, ⟨rfl, heq.rfl⟩, by simp⟩⟩
@[simp] theorem sigma_of_nat_val (n : ℕ) :
of_nat (sigma γ) n = ⟨of_nat α (unpair n).1, of_nat (γ _) (unpair n).2⟩ :=
option.some.inj $
by rw [← decode_eq_of_nat, decode_sigma_val]; simp; refl
end sigma
instance prod : denumerable (α × β) :=
of_equiv _ (equiv.sigma_equiv_prod α β).symm
@[simp] theorem prod_of_nat_val (n : ℕ) :
of_nat (α × β) n = (of_nat α (unpair n).1, of_nat β (unpair n).2) :=
by simp; refl
@[simp] theorem prod_nat_of_nat : of_nat (ℕ × ℕ) = unpair :=
by funext; simp
instance int : denumerable ℤ := denumerable.mk' equiv.int_equiv_nat
instance pnat : denumerable ℕ+ := denumerable.mk' equiv.pnat_equiv_nat
instance ulift : denumerable (ulift α) := of_equiv _ equiv.ulift
instance plift : denumerable (plift α) := of_equiv _ equiv.plift
def pair : α × α ≃ α := equiv₂ _ _
end
end denumerable
namespace nat.subtype
open function encodable
variables {s : set ℕ} [infinite s]
section classical
open_locale classical
lemma exists_succ (x : s) : ∃ n, x.1 + n + 1 ∈ s :=
classical.by_contradiction $ λ h,
have ∀ (a : ℕ) (ha : a ∈ s), a < x.val.succ,
from λ a ha, lt_of_not_ge (λ hax, h ⟨a - (x.1 + 1),
by rwa [add_right_comm, nat.add_sub_cancel' hax]⟩),
infinite.not_fintype
⟨(((multiset.range x.1.succ).filter (∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), subtype.mk y hy)
(by simp [-multiset.range_succ])).to_finset,
by simpa [subtype.ext_iff_val, multiset.mem_filter, -multiset.range_succ]⟩
end classical
variable [decidable_pred s]
def succ (x : s) : s :=
have h : ∃ m, x.1 + m + 1 ∈ s, from exists_succ x,
⟨x.1 + nat.find h + 1, nat.find_spec h⟩
lemma succ_le_of_lt {x y : s} (h : y < x) : succ y ≤ x :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
let ⟨k, hk⟩ := nat.exists_eq_add_of_lt h in
have nat.find hx ≤ k, from nat.find_min' _ (hk ▸ x.2),
show y.1 + nat.find hx + 1 ≤ x.1,
by rw hk; exact add_le_add_right (add_le_add_left this _) _
lemma le_succ_of_forall_lt_le {x y : s} (h : ∀ z < x, z ≤ y) : x ≤ succ y :=
have hx : ∃ m, y.1 + m + 1 ∈ s, from exists_succ _,
show x.1 ≤ y.1 + nat.find hx + 1,
from le_of_not_gt $ λ hxy,
have y.1 + nat.find hx + 1 ≤ y.1 := h ⟨_, nat.find_spec hx⟩ hxy,
not_lt_of_le this $
calc y.1 ≤ y.1 + nat.find hx : le_add_of_nonneg_right (nat.zero_le _)
... < y.1 + nat.find hx + 1 : nat.lt_succ_self _
lemma lt_succ_self (x : s) : x < succ x :=
calc x.1 ≤ x.1 + _ : le_add_right (le_refl _)
... < succ x : nat.lt_succ_self (x.1 + _)
lemma lt_succ_iff_le {x y : s} : x < succ y ↔ x ≤ y :=
⟨λ h, le_of_not_gt (λ h', not_le_of_gt h (succ_le_of_lt h')),
λ h, lt_of_le_of_lt h (lt_succ_self _)⟩
def of_nat (s : set ℕ) [decidable_pred s] [infinite s] : ℕ → s
| 0 := ⊥
| (n+1) := succ (of_nat n)
lemma of_nat_surjective_aux : ∀ {x : ℕ} (hx : x ∈ s), ∃ n, of_nat s n = ⟨x, hx⟩
| x := λ hx, let t : list s := ((list.range x).filter (λ y, y ∈ s)).pmap
(λ (y : ℕ) (hy : y ∈ s), ⟨y, hy⟩) (by simp) in
have hmt : ∀ {y : s}, y ∈ t ↔ y < ⟨x, hx⟩,
by simp [list.mem_filter, subtype.ext_iff_val, t]; intros; refl,
have wf : ∀ m : s, list.maximum t = m → m.1 < x,
from λ m hmax, by simpa [hmt] using list.maximum_mem hmax,
begin
cases hmax : list.maximum t with m,
{ exact ⟨0, le_antisymm (@bot_le s _ _)
(le_of_not_gt (λ h, list.not_mem_nil (⊥ : s) $
by rw [← list.maximum_eq_none.1 hmax, hmt]; exact h))⟩ },
{ cases of_nat_surjective_aux m.2 with a ha,
exact ⟨a + 1, le_antisymm
(by rw of_nat; exact succ_le_of_lt (by rw ha; exact wf _ hmax)) $
by rw of_nat; exact le_succ_of_forall_lt_le
(λ z hz, by rw ha; cases m; exact list.le_maximum_of_mem (hmt.2 hz) hmax)⟩ }
end
using_well_founded {dec_tac := `[tauto]}
lemma of_nat_surjective : surjective (of_nat s) :=
λ ⟨x, hx⟩, of_nat_surjective_aux hx
private def to_fun_aux (x : s) : ℕ :=
(list.range x).countp s
private lemma to_fun_aux_eq (x : s) :
to_fun_aux x = ((finset.range x).filter s).card :=
by rw [to_fun_aux, list.countp_eq_length_filter]; refl
open finset
private lemma right_inverse_aux : ∀ n, to_fun_aux (of_nat s n) = n
| 0 := begin
rw [to_fun_aux_eq, card_eq_zero, eq_empty_iff_forall_not_mem],
assume n,
rw [mem_filter, of_nat, mem_range],
assume h,
exact not_lt_of_le bot_le (show (⟨n, h.2⟩ : s) < ⊥, from h.1)
end
| (n+1) := have ih : to_fun_aux (of_nat s n) = n, from right_inverse_aux n,
have h₁ : (of_nat s n : ℕ) ∉ (range (of_nat s n)).filter s, by simp,
have h₂ : (range (succ (of_nat s n))).filter s =
insert (of_nat s n) ((range (of_nat s n)).filter s),
begin
simp only [finset.ext_iff, mem_insert, mem_range, mem_filter],
assume m,
exact ⟨λ h, by simp only [h.2, and_true]; exact or.symm
(lt_or_eq_of_le ((@lt_succ_iff_le _ _ _ ⟨m, h.2⟩ _).1 h.1)),
λ h, h.elim (λ h, h.symm ▸ ⟨lt_succ_self _, subtype.property _⟩)
(λ h, ⟨lt_of_le_of_lt (le_of_lt h.1) (lt_succ_self _), h.2⟩)⟩
end,
begin
clear_aux_decl,
simp only [to_fun_aux_eq, of_nat, range_succ] at *,
conv {to_rhs, rw [← ih, ← card_insert_of_not_mem h₁, ← h₂] },
end
def denumerable (s : set ℕ) [decidable_pred s] [infinite s] : denumerable s :=
denumerable.of_equiv ℕ
{ to_fun := to_fun_aux,
inv_fun := of_nat s,
left_inv := left_inverse_of_surjective_of_right_inverse
of_nat_surjective right_inverse_aux,
right_inv := right_inverse_aux }
end nat.subtype
namespace denumerable
open encodable
def of_encodable_of_infinite (α : Type*) [encodable α] [infinite α] : denumerable α :=
begin
letI := @decidable_range_encode α _;
letI : infinite (set.range (@encode α _)) :=
infinite.of_injective _ (equiv.set.range _ encode_injective).injective,
letI := nat.subtype.denumerable (set.range (@encode α _)),
exact denumerable.of_equiv (set.range (@encode α _))
(equiv_range_encode α)
end
end denumerable
|
5fa53eefc28b7f990782e83c0c755835d7fb166e | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/order/liminf_limsup.lean | ececbb65f351558867780e225b383e95014aceab | [
"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 | 46,870 | lean | /-
Copyright (c) 2018 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Johannes Hölzl, Rémy Degenne
-/
import order.filter.cofinite
import order.hom.complete_lattice
/-!
# liminfs and limsups of functions and filters
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Defines the Liminf/Limsup of a function taking values in a conditionally complete lattice, with
respect to an arbitrary filter.
We define `Limsup f` (`Liminf f`) where `f` is a filter taking values in a conditionally complete
lattice. `Limsup f` is the smallest element `a` such that, eventually, `u ≤ a` (and vice versa for
`Liminf f`). To work with the Limsup along a function `u` use `Limsup (map u f)`.
Usually, one defines the Limsup as `Inf (Sup s)` where the Inf is taken over all sets in the filter.
For instance, in ℕ along a function `u`, this is `Inf_n (Sup_{k ≥ n} u k)` (and the latter quantity
decreases with `n`, so this is in fact a limit.). There is however a difficulty: it is well possible
that `u` is not bounded on the whole space, only eventually (think of `Limsup (λx, 1/x)` on ℝ. Then
there is no guarantee that the quantity above really decreases (the value of the `Sup` beforehand is
not really well defined, as one can not use ∞), so that the Inf could be anything. So one can not
use this `Inf Sup ...` definition in conditionally complete lattices, and one has to use a less
tractable definition.
In conditionally complete lattices, the definition is only useful for filters which are eventually
bounded above (otherwise, the Limsup would morally be +∞, which does not belong to the space) and
which are frequently bounded below (otherwise, the Limsup would morally be -∞, which is not in the
space either). We start with definitions of these concepts for arbitrary filters, before turning to
the definitions of Limsup and Liminf.
In complete lattices, however, it coincides with the `Inf Sup` definition.
-/
open filter set
open_locale filter
variables {α β γ ι : Type*}
namespace filter
section relation
/-- `f.is_bounded (≺)`: the filter `f` is eventually bounded w.r.t. the relation `≺`, i.e.
eventually, it is bounded by some uniform bound.
`r` will be usually instantiated with `≤` or `≥`. -/
def is_bounded (r : α → α → Prop) (f : filter α) := ∃ b, ∀ᶠ x in f, r x b
/-- `f.is_bounded_under (≺) u`: the image of the filter `f` under `u` is eventually bounded w.r.t.
the relation `≺`, i.e. eventually, it is bounded by some uniform bound. -/
def is_bounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (map u f).is_bounded r
variables {r : α → α → Prop} {f g : filter α}
/-- `f` is eventually bounded if and only if, there exists an admissible set on which it is
bounded. -/
lemma is_bounded_iff : f.is_bounded r ↔ (∃s∈f.sets, ∃b, s ⊆ {x | r x b}) :=
iff.intro
(assume ⟨b, hb⟩, ⟨{a | r a b}, hb, b, subset.refl _⟩)
(assume ⟨s, hs, b, hb⟩, ⟨b, mem_of_superset hs hb⟩)
/-- A bounded function `u` is in particular eventually bounded. -/
lemma is_bounded_under_of {f : filter β} {u : β → α} :
(∃b, ∀x, r (u x) b) → f.is_bounded_under r u
| ⟨b, hb⟩ := ⟨b, show ∀ᶠ x in f, r (u x) b, from eventually_of_forall hb⟩
lemma is_bounded_bot : is_bounded r ⊥ ↔ nonempty α :=
by simp [is_bounded, exists_true_iff_nonempty]
lemma is_bounded_top : is_bounded r ⊤ ↔ (∃t, ∀x, r x t) :=
by simp [is_bounded, eq_univ_iff_forall]
lemma is_bounded_principal (s : set α) : is_bounded r (𝓟 s) ↔ (∃t, ∀x∈s, r x t) :=
by simp [is_bounded, subset_def]
lemma is_bounded_sup [is_trans α r] (hr : ∀b₁ b₂, ∃b, r b₁ b ∧ r b₂ b) :
is_bounded r f → is_bounded r g → is_bounded r (f ⊔ g)
| ⟨b₁, h₁⟩ ⟨b₂, h₂⟩ := let ⟨b, rb₁b, rb₂b⟩ := hr b₁ b₂ in
⟨b, eventually_sup.mpr ⟨h₁.mono (λ x h, trans h rb₁b), h₂.mono (λ x h, trans h rb₂b)⟩⟩
lemma is_bounded.mono (h : f ≤ g) : is_bounded r g → is_bounded r f
| ⟨b, hb⟩ := ⟨b, h hb⟩
lemma is_bounded_under.mono {f g : filter β} {u : β → α} (h : f ≤ g) :
g.is_bounded_under r u → f.is_bounded_under r u :=
λ hg, hg.mono (map_mono h)
lemma is_bounded_under.mono_le [preorder β] {l : filter α} {u v : α → β}
(hu : is_bounded_under (≤) l u) (hv : v ≤ᶠ[l] u) : is_bounded_under (≤) l v :=
hu.imp $ λ b hb, (eventually_map.1 hb).mp $ hv.mono $ λ x, le_trans
lemma is_bounded_under.mono_ge [preorder β] {l : filter α} {u v : α → β}
(hu : is_bounded_under (≥) l u) (hv : u ≤ᶠ[l] v) : is_bounded_under (≥) l v :=
@is_bounded_under.mono_le α βᵒᵈ _ _ _ _ hu hv
lemma is_bounded_under_const [is_refl α r] {l : filter β} {a : α} : is_bounded_under r l (λ _, a) :=
⟨a, eventually_map.2 $ eventually_of_forall $ λ _, refl _⟩
lemma is_bounded.is_bounded_under {q : β → β → Prop} {u : α → β}
(hf : ∀a₀ a₁, r a₀ a₁ → q (u a₀) (u a₁)) : f.is_bounded r → f.is_bounded_under q u
| ⟨b, h⟩ := ⟨u b, show ∀ᶠ x in f, q (u x) (u b), from h.mono (λ x, hf x b)⟩
lemma not_is_bounded_under_of_tendsto_at_top [preorder β] [no_max_order β] {f : α → β}
{l : filter α} [l.ne_bot] (hf : tendsto f l at_top) :
¬ is_bounded_under (≤) l f :=
begin
rintro ⟨b, hb⟩,
rw eventually_map at hb,
obtain ⟨b', h⟩ := exists_gt b,
have hb' := (tendsto_at_top.mp hf) b',
have : {x : α | f x ≤ b} ∩ {x : α | b' ≤ f x} = ∅ :=
eq_empty_of_subset_empty (λ x hx, (not_le_of_lt h) (le_trans hx.2 hx.1)),
exact (nonempty_of_mem (hb.and hb')).ne_empty this
end
lemma not_is_bounded_under_of_tendsto_at_bot [preorder β] [no_min_order β] {f : α → β}
{l : filter α} [l.ne_bot](hf : tendsto f l at_bot) :
¬ is_bounded_under (≥) l f :=
@not_is_bounded_under_of_tendsto_at_top α βᵒᵈ _ _ _ _ _ hf
lemma is_bounded_under.bdd_above_range_of_cofinite [preorder β] [is_directed β (≤)] {f : α → β}
(hf : is_bounded_under (≤) cofinite f) : bdd_above (range f) :=
begin
rcases hf with ⟨b, hb⟩,
haveI : nonempty β := ⟨b⟩,
rw [← image_univ, ← union_compl_self {x | f x ≤ b}, image_union, bdd_above_union],
exact ⟨⟨b, ball_image_iff.2 $ λ x, id⟩, (hb.image f).bdd_above⟩
end
lemma is_bounded_under.bdd_below_range_of_cofinite [preorder β] [is_directed β (≥)] {f : α → β}
(hf : is_bounded_under (≥) cofinite f) : bdd_below (range f) :=
@is_bounded_under.bdd_above_range_of_cofinite α βᵒᵈ _ _ _ hf
lemma is_bounded_under.bdd_above_range [preorder β] [is_directed β (≤)] {f : ℕ → β}
(hf : is_bounded_under (≤) at_top f) : bdd_above (range f) :=
by { rw ← nat.cofinite_eq_at_top at hf, exact hf.bdd_above_range_of_cofinite }
lemma is_bounded_under.bdd_below_range [preorder β] [is_directed β (≥)] {f : ℕ → β}
(hf : is_bounded_under (≥) at_top f) : bdd_below (range f) :=
@is_bounded_under.bdd_above_range βᵒᵈ _ _ _ hf
/-- `is_cobounded (≺) f` states that the filter `f` does not tend to infinity w.r.t. `≺`. This is
also called frequently bounded. Will be usually instantiated with `≤` or `≥`.
There is a subtlety in this definition: we want `f.is_cobounded` to hold for any `f` in the case of
complete lattices. This will be relevant to deduce theorems on complete lattices from their
versions on conditionally complete lattices with additional assumptions. We have to be careful in
the edge case of the trivial filter containing the empty set: the other natural definition
`¬ ∀ a, ∀ᶠ n in f, a ≤ n`
would not work as well in this case.
-/
def is_cobounded (r : α → α → Prop) (f : filter α) := ∃b, ∀a, (∀ᶠ x in f, r x a) → r b a
/-- `is_cobounded_under (≺) f u` states that the image of the filter `f` under the map `u` does not
tend to infinity w.r.t. `≺`. This is also called frequently bounded. Will be usually instantiated
with `≤` or `≥`. -/
def is_cobounded_under (r : α → α → Prop) (f : filter β) (u : β → α) := (map u f).is_cobounded r
/-- To check that a filter is frequently bounded, it suffices to have a witness
which bounds `f` at some point for every admissible set.
This is only an implication, as the other direction is wrong for the trivial filter.-/
lemma is_cobounded.mk [is_trans α r] (a : α) (h : ∀s∈f, ∃x∈s, r a x) : f.is_cobounded r :=
⟨a, assume y s, let ⟨x, h₁, h₂⟩ := h _ s in trans h₂ h₁⟩
/-- A filter which is eventually bounded is in particular frequently bounded (in the opposite
direction). At least if the filter is not trivial. -/
lemma is_bounded.is_cobounded_flip [is_trans α r] [ne_bot f] :
f.is_bounded r → f.is_cobounded (flip r)
| ⟨a, ha⟩ := ⟨a, assume b hb,
let ⟨x, rxa, rbx⟩ := (ha.and hb).exists in
show r b a, from trans rbx rxa⟩
lemma is_bounded.is_cobounded_ge [preorder α] [ne_bot f] (h : f.is_bounded (≤)) :
f.is_cobounded (≥) :=
h.is_cobounded_flip
lemma is_bounded.is_cobounded_le [preorder α] [ne_bot f] (h : f.is_bounded (≥)) :
f.is_cobounded (≤) :=
h.is_cobounded_flip
lemma is_cobounded_bot : is_cobounded r ⊥ ↔ (∃b, ∀x, r b x) :=
by simp [is_cobounded]
lemma is_cobounded_top : is_cobounded r ⊤ ↔ nonempty α :=
by simp [is_cobounded, eq_univ_iff_forall, exists_true_iff_nonempty] {contextual := tt}
lemma is_cobounded_principal (s : set α) :
(𝓟 s).is_cobounded r ↔ (∃b, ∀a, (∀x∈s, r x a) → r b a) :=
by simp [is_cobounded, subset_def]
lemma is_cobounded.mono (h : f ≤ g) : f.is_cobounded r → g.is_cobounded r
| ⟨b, hb⟩ := ⟨b, assume a ha, hb a (h ha)⟩
end relation
section nonempty
variables [preorder α] [nonempty α] {f : filter β} {u : β → α}
lemma is_bounded_le_at_bot : (at_bot : filter α).is_bounded (≤) :=
‹nonempty α›.elim $ λ a, ⟨a, eventually_le_at_bot _⟩
lemma is_bounded_ge_at_top : (at_top : filter α).is_bounded (≥) :=
‹nonempty α›.elim $ λ a, ⟨a, eventually_ge_at_top _⟩
lemma tendsto.is_bounded_under_le_at_bot (h : tendsto u f at_bot) : f.is_bounded_under (≤) u :=
is_bounded_le_at_bot.mono h
lemma tendsto.is_bounded_under_ge_at_top (h : tendsto u f at_top) : f.is_bounded_under (≥) u :=
is_bounded_ge_at_top.mono h
lemma bdd_above_range_of_tendsto_at_top_at_bot [is_directed α (≤)] {u : ℕ → α}
(hx : tendsto u at_top at_bot) : bdd_above (set.range u) :=
hx.is_bounded_under_le_at_bot.bdd_above_range
lemma bdd_below_range_of_tendsto_at_top_at_top [is_directed α (≥)] {u : ℕ → α}
(hx : tendsto u at_top at_top) : bdd_below (set.range u) :=
hx.is_bounded_under_ge_at_top.bdd_below_range
end nonempty
lemma is_cobounded_le_of_bot [preorder α] [order_bot α] {f : filter α} : f.is_cobounded (≤) :=
⟨⊥, assume a h, bot_le⟩
lemma is_cobounded_ge_of_top [preorder α] [order_top α] {f : filter α} : f.is_cobounded (≥) :=
⟨⊤, assume a h, le_top⟩
lemma is_bounded_le_of_top [preorder α] [order_top α] {f : filter α} : f.is_bounded (≤) :=
⟨⊤, eventually_of_forall $ λ _, le_top⟩
lemma is_bounded_ge_of_bot [preorder α] [order_bot α] {f : filter α} : f.is_bounded (≥) :=
⟨⊥, eventually_of_forall $ λ _, bot_le⟩
@[simp] lemma _root_.order_iso.is_bounded_under_le_comp [preorder α] [preorder β] (e : α ≃o β)
{l : filter γ} {u : γ → α} :
is_bounded_under (≤) l (λ x, e (u x)) ↔ is_bounded_under (≤) l u :=
e.surjective.exists.trans $ exists_congr $ λ a, by simp only [eventually_map, e.le_iff_le]
@[simp] lemma _root_.order_iso.is_bounded_under_ge_comp [preorder α] [preorder β] (e : α ≃o β)
{l : filter γ} {u : γ → α} :
is_bounded_under (≥) l (λ x, e (u x)) ↔ is_bounded_under (≥) l u :=
e.dual.is_bounded_under_le_comp
@[simp, to_additive]
lemma is_bounded_under_le_inv [ordered_comm_group α] {l : filter β} {u : β → α} :
is_bounded_under (≤) l (λ x, (u x)⁻¹) ↔ is_bounded_under (≥) l u :=
(order_iso.inv α).is_bounded_under_ge_comp
@[simp, to_additive]
lemma is_bounded_under_ge_inv [ordered_comm_group α] {l : filter β} {u : β → α} :
is_bounded_under (≥) l (λ x, (u x)⁻¹) ↔ is_bounded_under (≤) l u :=
(order_iso.inv α).is_bounded_under_le_comp
lemma is_bounded_under.sup [semilattice_sup α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≤) u → f.is_bounded_under (≤) v → f.is_bounded_under (≤) (λa, u a ⊔ v a)
| ⟨bu, (hu : ∀ᶠ x in f, u x ≤ bu)⟩ ⟨bv, (hv : ∀ᶠ x in f, v x ≤ bv)⟩ :=
⟨bu ⊔ bv, show ∀ᶠ x in f, u x ⊔ v x ≤ bu ⊔ bv,
by filter_upwards [hu, hv] with _ using sup_le_sup⟩
@[simp] lemma is_bounded_under_le_sup [semilattice_sup α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≤) (λ a, u a ⊔ v a) ↔ f.is_bounded_under (≤) u ∧ f.is_bounded_under (≤) v :=
⟨λ h, ⟨h.mono_le $ eventually_of_forall $ λ _, le_sup_left,
h.mono_le $ eventually_of_forall $ λ _, le_sup_right⟩, λ h, h.1.sup h.2⟩
lemma is_bounded_under.inf [semilattice_inf α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≥) u → f.is_bounded_under (≥) v → f.is_bounded_under (≥) (λa, u a ⊓ v a) :=
@is_bounded_under.sup αᵒᵈ β _ _ _ _
@[simp] lemma is_bounded_under_ge_inf [semilattice_inf α] {f : filter β} {u v : β → α} :
f.is_bounded_under (≥) (λ a, u a ⊓ v a) ↔ f.is_bounded_under (≥) u ∧ f.is_bounded_under (≥) v :=
@is_bounded_under_le_sup αᵒᵈ _ _ _ _ _
lemma is_bounded_under_le_abs [linear_ordered_add_comm_group α] {f : filter β} {u : β → α} :
f.is_bounded_under (≤) (λ a, |u a|) ↔ f.is_bounded_under (≤) u ∧ f.is_bounded_under (≥) u :=
is_bounded_under_le_sup.trans $ and_congr iff.rfl is_bounded_under_le_neg
/-- Filters are automatically bounded or cobounded in complete lattices. To use the same statements
in complete and conditionally complete lattices but let automation fill automatically the
boundedness proofs in complete lattices, we use the tactic `is_bounded_default` in the statements,
in the form `(hf : f.is_bounded (≥) . is_bounded_default)`. -/
meta def is_bounded_default : tactic unit :=
tactic.applyc ``is_cobounded_le_of_bot <|>
tactic.applyc ``is_cobounded_ge_of_top <|>
tactic.applyc ``is_bounded_le_of_top <|>
tactic.applyc ``is_bounded_ge_of_bot
section conditionally_complete_lattice
variables [conditionally_complete_lattice α]
/-- The `Limsup` of a filter `f` is the infimum of the `a` such that, eventually for `f`,
holds `x ≤ a`. -/
def Limsup (f : filter α) : α := Inf { a | ∀ᶠ n in f, n ≤ a }
/-- The `Liminf` of a filter `f` is the supremum of the `a` such that, eventually for `f`,
holds `x ≥ a`. -/
def Liminf (f : filter α) : α := Sup { a | ∀ᶠ n in f, a ≤ n }
/-- The `limsup` of a function `u` along a filter `f` is the infimum of the `a` such that,
eventually for `f`, holds `u x ≤ a`. -/
def limsup (u : β → α) (f : filter β) : α := Limsup (map u f)
/-- The `liminf` of a function `u` along a filter `f` is the supremum of the `a` such that,
eventually for `f`, holds `u x ≥ a`. -/
def liminf (u : β → α) (f : filter β) : α := Liminf (map u f)
/-- The `blimsup` of a function `u` along a filter `f`, bounded by a predicate `p`, is the infimum
of the `a` such that, eventually for `f`, `u x ≤ a` whenever `p x` holds. -/
def blimsup (u : β → α) (f : filter β) (p : β → Prop) :=
Inf { a | ∀ᶠ x in f, p x → u x ≤ a }
/-- The `bliminf` of a function `u` along a filter `f`, bounded by a predicate `p`, is the supremum
of the `a` such that, eventually for `f`, `a ≤ u x` whenever `p x` holds. -/
def bliminf (u : β → α) (f : filter β) (p : β → Prop) :=
Sup { a | ∀ᶠ x in f, p x → a ≤ u x }
section
variables {f : filter β} {u : β → α} {p : β → Prop}
theorem limsup_eq : limsup u f = Inf { a | ∀ᶠ n in f, u n ≤ a } := rfl
theorem liminf_eq : liminf u f = Sup { a | ∀ᶠ n in f, a ≤ u n } := rfl
theorem blimsup_eq : blimsup u f p = Inf { a | ∀ᶠ x in f, p x → u x ≤ a } := rfl
theorem bliminf_eq : bliminf u f p = Sup { a | ∀ᶠ x in f, p x → a ≤ u x } := rfl
end
@[simp] lemma blimsup_true (f : filter β) (u : β → α) :
blimsup u f (λ x, true) = limsup u f :=
by simp [blimsup_eq, limsup_eq]
@[simp] lemma bliminf_true (f : filter β) (u : β → α) :
bliminf u f (λ x, true) = liminf u f :=
by simp [bliminf_eq, liminf_eq]
lemma blimsup_eq_limsup_subtype {f : filter β} {u : β → α} {p : β → Prop} :
blimsup u f p = limsup (u ∘ (coe : {x | p x} → β)) (comap coe f) :=
begin
simp only [blimsup_eq, limsup_eq, function.comp_app, eventually_comap, set_coe.forall,
subtype.coe_mk, mem_set_of_eq],
congr,
ext a,
exact eventually_congr (eventually_of_forall
(λ x, ⟨λ hx y hy hxy, hxy.symm ▸ (hx (hxy ▸ hy)), λ hx hx', hx x hx' rfl⟩)),
end
lemma bliminf_eq_liminf_subtype {f : filter β} {u : β → α} {p : β → Prop} :
bliminf u f p = liminf (u ∘ (coe : {x | p x} → β)) (comap coe f) :=
@blimsup_eq_limsup_subtype αᵒᵈ β _ f u p
theorem Limsup_le_of_le {f : filter α} {a}
(hf : f.is_cobounded (≤) . is_bounded_default) (h : ∀ᶠ n in f, n ≤ a) : Limsup f ≤ a :=
cInf_le hf h
theorem le_Liminf_of_le {f : filter α} {a}
(hf : f.is_cobounded (≥) . is_bounded_default) (h : ∀ᶠ n in f, a ≤ n) : a ≤ Liminf f :=
le_cSup hf h
theorem limsup_le_of_le {f : filter β} {u : β → α} {a}
(hf : f.is_cobounded_under (≤) u . is_bounded_default) (h : ∀ᶠ n in f, u n ≤ a) :
limsup u f ≤ a :=
cInf_le hf h
theorem le_liminf_of_le {f : filter β} {u : β → α} {a}
(hf : f.is_cobounded_under (≥) u . is_bounded_default) (h : ∀ᶠ n in f, a ≤ u n) :
a ≤ liminf u f :=
le_cSup hf h
theorem le_Limsup_of_le {f : filter α} {a}
(hf : f.is_bounded (≤) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, n ≤ b) → a ≤ b) :
a ≤ Limsup f :=
le_cInf hf h
theorem Liminf_le_of_le {f : filter α} {a}
(hf : f.is_bounded (≥) . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, b ≤ n) → b ≤ a) :
Liminf f ≤ a :=
cSup_le hf h
theorem le_limsup_of_le {f : filter β} {u : β → α} {a}
(hf : f.is_bounded_under (≤) u . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, u n ≤ b) → a ≤ b) :
a ≤ limsup u f :=
le_cInf hf h
theorem liminf_le_of_le {f : filter β} {u : β → α} {a}
(hf : f.is_bounded_under (≥) u . is_bounded_default) (h : ∀ b, (∀ᶠ n in f, b ≤ u n) → b ≤ a) :
liminf u f ≤ a :=
cSup_le hf h
theorem Liminf_le_Limsup {f : filter α} [ne_bot f]
(h₁ : f.is_bounded (≤) . is_bounded_default) (h₂ : f.is_bounded (≥) . is_bounded_default) :
Liminf f ≤ Limsup f :=
Liminf_le_of_le h₂ $ assume a₀ ha₀, le_Limsup_of_le h₁ $ assume a₁ ha₁,
show a₀ ≤ a₁, from let ⟨b, hb₀, hb₁⟩ := (ha₀.and ha₁).exists in le_trans hb₀ hb₁
lemma liminf_le_limsup {f : filter β} [ne_bot f] {u : β → α}
(h : f.is_bounded_under (≤) u . is_bounded_default)
(h' : f.is_bounded_under (≥) u . is_bounded_default) :
liminf u f ≤ limsup u f :=
Liminf_le_Limsup h h'
lemma Limsup_le_Limsup {f g : filter α}
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in g, n ≤ a) → ∀ᶠ n in f, n ≤ a) : Limsup f ≤ Limsup g :=
cInf_le_cInf hf hg h
lemma Liminf_le_Liminf {f g : filter α}
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default)
(h : ∀ a, (∀ᶠ n in f, a ≤ n) → ∀ᶠ n in g, a ≤ n) : Liminf f ≤ Liminf g :=
cSup_le_cSup hg hf h
lemma limsup_le_limsup {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : u ≤ᶠ[f] v)
(hu : f.is_cobounded_under (≤) u . is_bounded_default)
(hv : f.is_bounded_under (≤) v . is_bounded_default) :
limsup u f ≤ limsup v f :=
Limsup_le_Limsup hu hv $ assume b, h.trans
lemma liminf_le_liminf {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a ≤ v a)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hv : f.is_cobounded_under (≥) v . is_bounded_default) :
liminf u f ≤ liminf v f :=
@limsup_le_limsup βᵒᵈ α _ _ _ _ h hv hu
lemma Limsup_le_Limsup_of_le {f g : filter α} (h : f ≤ g)
(hf : f.is_cobounded (≤) . is_bounded_default) (hg : g.is_bounded (≤) . is_bounded_default) :
Limsup f ≤ Limsup g :=
Limsup_le_Limsup hf hg (assume a ha, h ha)
lemma Liminf_le_Liminf_of_le {f g : filter α} (h : g ≤ f)
(hf : f.is_bounded (≥) . is_bounded_default) (hg : g.is_cobounded (≥) . is_bounded_default) :
Liminf f ≤ Liminf g :=
Liminf_le_Liminf hf hg (assume a ha, h ha)
lemma limsup_le_limsup_of_le {α β} [conditionally_complete_lattice β] {f g : filter α} (h : f ≤ g)
{u : α → β} (hf : f.is_cobounded_under (≤) u . is_bounded_default)
(hg : g.is_bounded_under (≤) u . is_bounded_default) :
limsup u f ≤ limsup u g :=
Limsup_le_Limsup_of_le (map_mono h) hf hg
lemma liminf_le_liminf_of_le {α β} [conditionally_complete_lattice β] {f g : filter α} (h : g ≤ f)
{u : α → β} (hf : f.is_bounded_under (≥) u . is_bounded_default)
(hg : g.is_cobounded_under (≥) u . is_bounded_default) :
liminf u f ≤ liminf u g :=
Liminf_le_Liminf_of_le (map_mono h) hf hg
theorem Limsup_principal {s : set α} (h : bdd_above s) (hs : s.nonempty) :
Limsup (𝓟 s) = Sup s :=
by simp [Limsup]; exact cInf_upper_bounds_eq_cSup h hs
theorem Liminf_principal {s : set α} (h : bdd_below s) (hs : s.nonempty) :
Liminf (𝓟 s) = Inf s :=
@Limsup_principal αᵒᵈ _ s h hs
lemma limsup_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : limsup u f = limsup v f :=
begin
rw limsup_eq,
congr' with b,
exact eventually_congr (h.mono $ λ x hx, by simp [hx])
end
lemma blimsup_congr {f : filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
blimsup u f p = blimsup v f p :=
begin
rw blimsup_eq,
congr' with b,
refine eventually_congr (h.mono $ λ x hx, ⟨λ h₁ h₂, _, λ h₁ h₂, _⟩),
{ rw ← hx h₂, exact h₁ h₂, },
{ rw hx h₂, exact h₁ h₂, },
end
lemma bliminf_congr {f : filter β} {u v : β → α} {p : β → Prop} (h : ∀ᶠ a in f, p a → u a = v a) :
bliminf u f p = bliminf v f p :=
@blimsup_congr αᵒᵈ _ _ _ _ _ _ h
lemma liminf_congr {α : Type*} [conditionally_complete_lattice β] {f : filter α} {u v : α → β}
(h : ∀ᶠ a in f, u a = v a) : liminf u f = liminf v f :=
@limsup_congr βᵒᵈ _ _ _ _ _ h
lemma limsup_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} [ne_bot f]
(b : β) : limsup (λ x, b) f = b :=
by simpa only [limsup_eq, eventually_const] using cInf_Ici
lemma liminf_const {α : Type*} [conditionally_complete_lattice β] {f : filter α} [ne_bot f]
(b : β) : liminf (λ x, b) f = b :=
@limsup_const βᵒᵈ α _ f _ b
end conditionally_complete_lattice
section complete_lattice
variables [complete_lattice α]
@[simp] theorem Limsup_bot : Limsup (⊥ : filter α) = ⊥ :=
bot_unique $ Inf_le $ by simp
@[simp] theorem Liminf_bot : Liminf (⊥ : filter α) = ⊤ :=
top_unique $ le_Sup $ by simp
@[simp] theorem Limsup_top : Limsup (⊤ : filter α) = ⊤ :=
top_unique $ le_Inf $
by simp [eq_univ_iff_forall]; exact assume b hb, (top_unique $ hb _)
@[simp] theorem Liminf_top : Liminf (⊤ : filter α) = ⊥ :=
bot_unique $ Sup_le $
by simp [eq_univ_iff_forall]; exact assume b hb, (bot_unique $ hb _)
@[simp] lemma blimsup_false {f : filter β} {u : β → α} :
blimsup u f (λ x, false) = ⊥ :=
by simp [blimsup_eq]
@[simp] lemma bliminf_false {f : filter β} {u : β → α} :
bliminf u f (λ x, false) = ⊤ :=
by simp [bliminf_eq]
/-- Same as limsup_const applied to `⊥` but without the `ne_bot f` assumption -/
lemma limsup_const_bot {f : filter β} : limsup (λ x : β, (⊥ : α)) f = (⊥ : α) :=
begin
rw [limsup_eq, eq_bot_iff],
exact Inf_le (eventually_of_forall (λ x, le_rfl)),
end
/-- Same as limsup_const applied to `⊤` but without the `ne_bot f` assumption -/
lemma liminf_const_top {f : filter β} : liminf (λ x : β, (⊤ : α)) f = (⊤ : α) :=
@limsup_const_bot αᵒᵈ β _ _
theorem has_basis.Limsup_eq_infi_Sup {ι} {p : ι → Prop} {s} {f : filter α} (h : f.has_basis p s) :
Limsup f = ⨅ i (hi : p i), Sup (s i) :=
le_antisymm
(le_infi₂ $ λ i hi, Inf_le $ h.eventually_iff.2 ⟨i, hi, λ x, le_Sup⟩)
(le_Inf $ assume a ha, let ⟨i, hi, ha⟩ := h.eventually_iff.1 ha in
infi₂_le_of_le _ hi $ Sup_le ha)
theorem has_basis.Liminf_eq_supr_Inf {p : ι → Prop} {s : ι → set α} {f : filter α}
(h : f.has_basis p s) : Liminf f = ⨆ i (hi : p i), Inf (s i) :=
@has_basis.Limsup_eq_infi_Sup αᵒᵈ _ _ _ _ _ h
theorem Limsup_eq_infi_Sup {f : filter α} : Limsup f = ⨅ s ∈ f, Sup s :=
f.basis_sets.Limsup_eq_infi_Sup
theorem Liminf_eq_supr_Inf {f : filter α} : Liminf f = ⨆ s ∈ f, Inf s :=
@Limsup_eq_infi_Sup αᵒᵈ _ _
theorem limsup_le_supr {f : filter β} {u : β → α} : limsup u f ≤ ⨆ n, u n :=
limsup_le_of_le (by is_bounded_default) (eventually_of_forall (le_supr u))
theorem infi_le_liminf {f : filter β} {u : β → α} : (⨅ n, u n) ≤ liminf u f :=
le_liminf_of_le (by is_bounded_default) (eventually_of_forall (infi_le u))
/-- In a complete lattice, the limsup of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem limsup_eq_infi_supr {f : filter β} {u : β → α} : limsup u f = ⨅ s ∈ f, ⨆ a ∈ s, u a :=
(f.basis_sets.map u).Limsup_eq_infi_Sup.trans $
by simp only [Sup_image, id]
lemma limsup_eq_infi_supr_of_nat {u : ℕ → α} : limsup u at_top = ⨅ n : ℕ, ⨆ i ≥ n, u i :=
(at_top_basis.map u).Limsup_eq_infi_Sup.trans $
by simp only [Sup_image, infi_const]; refl
lemma limsup_eq_infi_supr_of_nat' {u : ℕ → α} : limsup u at_top = ⨅ n : ℕ, ⨆ i : ℕ, u (i + n) :=
by simp only [limsup_eq_infi_supr_of_nat, supr_ge_eq_supr_nat_add]
theorem has_basis.limsup_eq_infi_supr {p : ι → Prop} {s : ι → set β} {f : filter β} {u : β → α}
(h : f.has_basis p s) : limsup u f = ⨅ i (hi : p i), ⨆ a ∈ s i, u a :=
(h.map u).Limsup_eq_infi_Sup.trans $ by simp only [Sup_image, id]
lemma blimsup_congr' {f : filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊥ → (p x ↔ q x)) :
blimsup u f p = blimsup u f q :=
begin
simp only [blimsup_eq],
congr,
ext a,
refine eventually_congr (h.mono $ λ b hb, _),
cases eq_or_ne (u b) ⊥ with hu hu, { simp [hu], },
rw hb hu,
end
lemma bliminf_congr' {f : filter β} {p q : β → Prop} {u : β → α}
(h : ∀ᶠ x in f, u x ≠ ⊤ → (p x ↔ q x)) :
bliminf u f p = bliminf u f q :=
@blimsup_congr' αᵒᵈ β _ _ _ _ _ h
lemma blimsup_eq_infi_bsupr {f : filter β} {p : β → Prop} {u : β → α} :
blimsup u f p = ⨅ s ∈ f, ⨆ b (hb : p b ∧ b ∈ s), u b :=
begin
refine le_antisymm (Inf_le_Inf _) (infi_le_iff.mpr $ λ a ha, le_Inf_iff.mpr $ λ a' ha', _),
{ rintros - ⟨s, rfl⟩,
simp only [mem_set_of_eq, le_infi_iff],
conv { congr, funext, rw imp.swap, },
refine eventually_imp_distrib_left.mpr (λ h, eventually_iff_exists_mem.2 ⟨s, h, λ x h₁ h₂, _⟩),
exact @le_supr₂ α β (λ b, p b ∧ b ∈ s) _ (λ b hb, u b) x ⟨h₂, h₁⟩, },
{ obtain ⟨s, hs, hs'⟩ := eventually_iff_exists_mem.mp ha',
simp_rw imp.swap at hs',
exact (le_infi_iff.mp (ha s) hs).trans (by simpa only [supr₂_le_iff, and_imp]), },
end
lemma blimsup_eq_infi_bsupr_of_nat {p : ℕ → Prop} {u : ℕ → α} :
blimsup u at_top p = ⨅ i, ⨆ j (hj : p j ∧ i ≤ j), u j :=
by simp only [blimsup_eq_limsup_subtype, mem_preimage, mem_Ici, function.comp_app, cinfi_pos,
supr_subtype, (at_top_basis.comap (coe : {x | p x} → ℕ)).limsup_eq_infi_supr, mem_set_of_eq,
subtype.coe_mk, supr_and]
/-- In a complete lattice, the liminf of a function is the infimum over sets `s` in the filter
of the supremum of the function over `s` -/
theorem liminf_eq_supr_infi {f : filter β} {u : β → α} : liminf u f = ⨆ s ∈ f, ⨅ a ∈ s, u a :=
@limsup_eq_infi_supr αᵒᵈ β _ _ _
lemma liminf_eq_supr_infi_of_nat {u : ℕ → α} : liminf u at_top = ⨆ n : ℕ, ⨅ i ≥ n, u i :=
@limsup_eq_infi_supr_of_nat αᵒᵈ _ u
lemma liminf_eq_supr_infi_of_nat' {u : ℕ → α} : liminf u at_top = ⨆ n : ℕ, ⨅ i : ℕ, u (i + n) :=
@limsup_eq_infi_supr_of_nat' αᵒᵈ _ _
theorem has_basis.liminf_eq_supr_infi {p : ι → Prop} {s : ι → set β} {f : filter β} {u : β → α}
(h : f.has_basis p s) : liminf u f = ⨆ i (hi : p i), ⨅ a ∈ s i, u a :=
@has_basis.limsup_eq_infi_supr αᵒᵈ _ _ _ _ _ _ _ h
lemma bliminf_eq_supr_binfi {f : filter β} {p : β → Prop} {u : β → α} :
bliminf u f p = ⨆ s ∈ f, ⨅ b (hb : p b ∧ b ∈ s), u b :=
@blimsup_eq_infi_bsupr αᵒᵈ β _ f p u
lemma bliminf_eq_supr_binfi_of_nat {p : ℕ → Prop} {u : ℕ → α} :
bliminf u at_top p = ⨆ i, ⨅ j (hj : p j ∧ i ≤ j), u j :=
@blimsup_eq_infi_bsupr_of_nat αᵒᵈ _ p u
lemma limsup_eq_Inf_Sup {ι R : Type*} (F : filter ι) [complete_lattice R] (a : ι → R) :
limsup a F = Inf ((λ I, Sup (a '' I)) '' F.sets) :=
begin
refine le_antisymm _ _,
{ rw limsup_eq,
refine Inf_le_Inf (λ x hx, _),
rcases (mem_image _ F.sets x).mp hx with ⟨I, ⟨I_mem_F, hI⟩⟩,
filter_upwards [I_mem_F] with i hi,
exact hI ▸ le_Sup (mem_image_of_mem _ hi), },
{ refine le_Inf_iff.mpr (λ b hb, Inf_le_of_le (mem_image_of_mem _ $ filter.mem_sets.mpr hb)
$ Sup_le _),
rintros _ ⟨_, h, rfl⟩,
exact h, },
end
lemma liminf_eq_Sup_Inf {ι R : Type*} (F : filter ι) [complete_lattice R] (a : ι → R) :
liminf a F = Sup ((λ I, Inf (a '' I)) '' F.sets) :=
@filter.limsup_eq_Inf_Sup ι (order_dual R) _ _ a
@[simp] lemma liminf_nat_add (f : ℕ → α) (k : ℕ) :
liminf (λ i, f (i + k)) at_top = liminf f at_top :=
by { simp_rw liminf_eq_supr_infi_of_nat, exact supr_infi_ge_nat_add f k }
@[simp] lemma limsup_nat_add (f : ℕ → α) (k : ℕ) :
limsup (λ i, f (i + k)) at_top = limsup f at_top :=
@liminf_nat_add αᵒᵈ _ f k
lemma liminf_le_of_frequently_le' {α β} [complete_lattice β]
{f : filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, u a ≤ x) :
liminf u f ≤ x :=
begin
rw liminf_eq,
refine Sup_le (λ b hb, _),
have hbx : ∃ᶠ a in f, b ≤ x,
{ revert h,
rw [←not_imp_not, not_frequently, not_frequently],
exact λ h, hb.mp (h.mono (λ a hbx hba hax, hbx (hba.trans hax))), },
exact hbx.exists.some_spec,
end
lemma le_limsup_of_frequently_le' {α β} [complete_lattice β]
{f : filter α} {u : α → β} {x : β} (h : ∃ᶠ a in f, x ≤ u a) :
x ≤ limsup u f :=
@liminf_le_of_frequently_le' _ βᵒᵈ _ _ _ _ h
/-- If `f : α → α` is a morphism of complete lattices, then the limsup of its iterates of any
`a : α` is a fixed point. -/
@[simp] lemma complete_lattice_hom.apply_limsup_iterate (f : complete_lattice_hom α α) (a : α) :
f (limsup (λ n, f^[n] a) at_top) = limsup (λ n, f^[n] a) at_top :=
begin
rw [limsup_eq_infi_supr_of_nat', map_infi],
simp_rw [_root_.map_supr, ← function.comp_apply f, ← function.iterate_succ' f, ← nat.add_succ],
conv_rhs { rw infi_split _ ((<) (0 : ℕ)), },
simp only [not_lt, le_zero_iff, infi_infi_eq_left, add_zero, infi_nat_gt_zero_eq, left_eq_inf],
refine (infi_le (λ i, ⨆ j, (f^[j + (i + 1)]) a) 0).trans _,
simp only [zero_add, function.comp_app, supr_le_iff],
exact λ i, le_supr (λ i, (f^[i] a)) (i + 1),
end
/-- If `f : α → α` is a morphism of complete lattices, then the liminf of its iterates of any
`a : α` is a fixed point. -/
lemma complete_lattice_hom.apply_liminf_iterate (f : complete_lattice_hom α α) (a : α) :
f (liminf (λ n, f^[n] a) at_top) = liminf (λ n, f^[n] a) at_top :=
(complete_lattice_hom.dual f).apply_limsup_iterate _
variables {f g : filter β} {p q : β → Prop} {u v : β → α}
lemma blimsup_mono (h : ∀ x, p x → q x) :
blimsup u f p ≤ blimsup u f q :=
Inf_le_Inf $ λ a ha, ha.mono $ by tauto
lemma bliminf_antitone (h : ∀ x, p x → q x) :
bliminf u f q ≤ bliminf u f p :=
Sup_le_Sup $ λ a ha, ha.mono $ by tauto
lemma mono_blimsup' (h : ∀ᶠ x in f, p x → u x ≤ v x) :
blimsup u f p ≤ blimsup v f p :=
Inf_le_Inf $ λ a ha, (ha.and h).mono $ λ x hx hx', (hx.2 hx').trans (hx.1 hx')
lemma mono_blimsup (h : ∀ x, p x → u x ≤ v x) :
blimsup u f p ≤ blimsup v f p :=
mono_blimsup' $ eventually_of_forall h
lemma mono_bliminf' (h : ∀ᶠ x in f, p x → u x ≤ v x) :
bliminf u f p ≤ bliminf v f p :=
Sup_le_Sup $ λ a ha, (ha.and h).mono $ λ x hx hx', (hx.1 hx').trans (hx.2 hx')
lemma mono_bliminf (h : ∀ x, p x → u x ≤ v x) :
bliminf u f p ≤ bliminf v f p :=
mono_bliminf' $ eventually_of_forall h
lemma bliminf_antitone_filter (h : f ≤ g) :
bliminf u g p ≤ bliminf u f p :=
Sup_le_Sup $ λ a ha, ha.filter_mono h
lemma blimsup_monotone_filter (h : f ≤ g) :
blimsup u f p ≤ blimsup u g p :=
Inf_le_Inf $ λ a ha, ha.filter_mono h
@[simp] lemma blimsup_and_le_inf :
blimsup u f (λ x, p x ∧ q x) ≤ blimsup u f p ⊓ blimsup u f q :=
le_inf (blimsup_mono $ by tauto) (blimsup_mono $ by tauto)
@[simp] lemma bliminf_sup_le_and :
bliminf u f p ⊔ bliminf u f q ≤ bliminf u f (λ x, p x ∧ q x) :=
@blimsup_and_le_inf αᵒᵈ β _ f p q u
/-- See also `filter.blimsup_or_eq_sup`. -/
@[simp] lemma blimsup_sup_le_or :
blimsup u f p ⊔ blimsup u f q ≤ blimsup u f (λ x, p x ∨ q x) :=
sup_le (blimsup_mono $ by tauto) (blimsup_mono $ by tauto)
/-- See also `filter.bliminf_or_eq_inf`. -/
@[simp] lemma bliminf_or_le_inf :
bliminf u f (λ x, p x ∨ q x) ≤ bliminf u f p ⊓ bliminf u f q :=
@blimsup_sup_le_or αᵒᵈ β _ f p q u
lemma order_iso.apply_blimsup [complete_lattice γ] (e : α ≃o γ) :
e (blimsup u f p) = blimsup (e ∘ u) f p :=
begin
simp only [blimsup_eq, map_Inf, function.comp_app],
congr,
ext c,
obtain ⟨a, rfl⟩ := e.surjective c,
simp,
end
lemma order_iso.apply_bliminf [complete_lattice γ] (e : α ≃o γ) :
e (bliminf u f p) = bliminf (e ∘ u) f p :=
@order_iso.apply_blimsup αᵒᵈ β γᵒᵈ _ f p u _ e.dual
lemma Sup_hom.apply_blimsup_le [complete_lattice γ] (g : Sup_hom α γ) :
g (blimsup u f p) ≤ blimsup (g ∘ u) f p :=
begin
simp only [blimsup_eq_infi_bsupr],
refine ((order_hom_class.mono g).map_infi₂_le _).trans _,
simp only [_root_.map_supr],
end
lemma Inf_hom.le_apply_bliminf [complete_lattice γ] (g : Inf_hom α γ) :
bliminf (g ∘ u) f p ≤ g (bliminf u f p) :=
@Sup_hom.apply_blimsup_le αᵒᵈ β γᵒᵈ _ f p u _ g.dual
end complete_lattice
section complete_distrib_lattice
variables [complete_distrib_lattice α] {f : filter β} {p q : β → Prop} {u : β → α}
@[simp] lemma blimsup_or_eq_sup :
blimsup u f (λ x, p x ∨ q x) = blimsup u f p ⊔ blimsup u f q :=
begin
refine le_antisymm _ blimsup_sup_le_or,
simp only [blimsup_eq, Inf_sup_eq, sup_Inf_eq, le_infi₂_iff, mem_set_of_eq],
refine λ a' ha' a ha, Inf_le ((ha.and ha').mono $ λ b h hb, _),
exact or.elim hb (λ hb, le_sup_of_le_left $ h.1 hb) (λ hb, le_sup_of_le_right $ h.2 hb),
end
@[simp] lemma bliminf_or_eq_inf :
bliminf u f (λ x, p x ∨ q x) = bliminf u f p ⊓ bliminf u f q :=
@blimsup_or_eq_sup αᵒᵈ β _ f p q u
lemma sup_limsup [ne_bot f] (a : α) :
a ⊔ limsup u f = limsup (λ x, a ⊔ u x) f :=
begin
simp only [limsup_eq_infi_supr, supr_sup_eq, sup_binfi_eq],
congr, ext s, congr, ext hs, congr,
exact (bsupr_const (nonempty_of_mem hs)).symm,
end
lemma inf_liminf [ne_bot f] (a : α) :
a ⊓ liminf u f = liminf (λ x, a ⊓ u x) f :=
@sup_limsup αᵒᵈ β _ f _ _ _
lemma sup_liminf (a : α) :
a ⊔ liminf u f = liminf (λ x, a ⊔ u x) f :=
begin
simp only [liminf_eq_supr_infi],
rw [sup_comm, bsupr_sup (⟨univ, univ_mem⟩ : ∃ (i : set β), i ∈ f)],
simp_rw [binfi_sup_eq, @sup_comm _ _ a],
end
lemma inf_limsup (a : α) :
a ⊓ limsup u f = limsup (λ x, a ⊓ u x) f :=
@sup_liminf αᵒᵈ β _ f _ _
end complete_distrib_lattice
section complete_boolean_algebra
variables [complete_boolean_algebra α] (f : filter β) (u : β → α)
lemma limsup_compl :
(limsup u f)ᶜ = liminf (compl ∘ u) f :=
by simp only [limsup_eq_infi_supr, liminf_eq_supr_infi, compl_infi, compl_supr]
lemma liminf_compl :
(liminf u f)ᶜ = limsup (compl ∘ u) f :=
by simp only [limsup_eq_infi_supr, liminf_eq_supr_infi, compl_infi, compl_supr]
lemma limsup_sdiff (a : α) :
(limsup u f) \ a = limsup (λ b, (u b) \ a) f :=
begin
simp only [limsup_eq_infi_supr, sdiff_eq],
rw binfi_inf (⟨univ, univ_mem⟩ : ∃ (i : set β), i ∈ f),
simp_rw [inf_comm, inf_bsupr_eq, inf_comm],
end
lemma liminf_sdiff [ne_bot f] (a : α) :
(liminf u f) \ a = liminf (λ b, (u b) \ a) f :=
by simp only [sdiff_eq, @inf_comm _ _ _ aᶜ, inf_liminf]
lemma sdiff_limsup [ne_bot f] (a : α) :
a \ limsup u f = liminf (λ b, a \ u b) f :=
begin
rw ← compl_inj_iff,
simp only [sdiff_eq, liminf_compl, (∘), compl_inf, compl_compl, sup_limsup],
end
lemma sdiff_liminf (a : α) :
a \ liminf u f = limsup (λ b, a \ u b) f :=
begin
rw ← compl_inj_iff,
simp only [sdiff_eq, limsup_compl, (∘), compl_inf, compl_compl, sup_liminf],
end
end complete_boolean_algebra
section set_lattice
variables {p : ι → Prop} {s : ι → set α}
lemma cofinite.blimsup_set_eq :
blimsup s cofinite p = { x | { n | p n ∧ x ∈ s n }.infinite } :=
begin
simp only [blimsup_eq, le_eq_subset, eventually_cofinite, not_forall, Inf_eq_sInter, exists_prop],
ext x,
refine ⟨λ h, _, λ hx t h, _⟩;
contrapose! h,
{ simp only [mem_sInter, mem_set_of_eq, not_forall, exists_prop],
exact ⟨{x}ᶜ, by simpa using h, by simp⟩, },
{ exact hx.mono (λ i hi, ⟨hi.1, λ hit, h (hit hi.2)⟩), },
end
lemma cofinite.bliminf_set_eq :
bliminf s cofinite p = { x | { n | p n ∧ x ∉ s n }.finite } :=
begin
rw ← compl_inj_iff,
simpa only [bliminf_eq_supr_binfi, compl_infi, compl_supr, ← blimsup_eq_infi_bsupr,
cofinite.blimsup_set_eq],
end
/-- In other words, `limsup cofinite s` is the set of elements lying inside the family `s`
infinitely often. -/
lemma cofinite.limsup_set_eq :
limsup s cofinite = { x | { n | x ∈ s n }.infinite } :=
by simp only [← cofinite.blimsup_true s, cofinite.blimsup_set_eq, true_and]
/-- In other words, `liminf cofinite s` is the set of elements lying outside the family `s`
finitely often. -/
lemma cofinite.liminf_set_eq :
liminf s cofinite = { x | { n | x ∉ s n }.finite } :=
by simp only [← cofinite.bliminf_true s, cofinite.bliminf_set_eq, true_and]
lemma exists_forall_mem_of_has_basis_mem_blimsup
{l : filter β} {b : ι → set β} {q : ι → Prop} (hl : l.has_basis q b)
{u : β → set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : {i | q i} → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i :=
begin
rw blimsup_eq_infi_bsupr at hx,
simp only [supr_eq_Union, infi_eq_Inter, mem_Inter, mem_Union, exists_prop] at hx,
choose g hg hg' using hx,
refine ⟨λ (i : {i | q i}), g (b i) (hl.mem_of_mem i.2), λ i, ⟨_, _⟩⟩,
{ exact hg' (b i) (hl.mem_of_mem i.2), },
{ exact hg (b i) (hl.mem_of_mem i.2), },
end
lemma exists_forall_mem_of_has_basis_mem_blimsup'
{l : filter β} {b : ι → set β} (hl : l.has_basis (λ _, true) b)
{u : β → set α} {p : β → Prop} {x : α} (hx : x ∈ blimsup u l p) :
∃ f : ι → β, ∀ i, x ∈ u (f i) ∧ p (f i) ∧ f i ∈ b i :=
begin
obtain ⟨f, hf⟩ := exists_forall_mem_of_has_basis_mem_blimsup hl hx,
exact ⟨λ i, f ⟨i, trivial⟩, λ i, hf ⟨i, trivial⟩⟩,
end
end set_lattice
section conditionally_complete_linear_order
lemma frequently_lt_of_lt_Limsup {f : filter α} [conditionally_complete_linear_order α] {a : α}
(hf : f.is_cobounded (≤) . is_bounded_default) (h : a < Limsup f) : ∃ᶠ n in f, a < n :=
begin
contrapose! h,
simp only [not_frequently, not_lt] at h,
exact Limsup_le_of_le hf h,
end
lemma frequently_lt_of_Liminf_lt {f : filter α} [conditionally_complete_linear_order α] {a : α}
(hf : f.is_cobounded (≥) . is_bounded_default) (h : Liminf f < a) : ∃ᶠ n in f, n < a :=
@frequently_lt_of_lt_Limsup (order_dual α) f _ a hf h
lemma eventually_lt_of_lt_liminf {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : b < liminf u f) (hu : f.is_bounded_under (≥) u . is_bounded_default) :
∀ᶠ a in f, b < u a :=
begin
obtain ⟨c, hc, hbc⟩ : ∃ (c : β) (hc : c ∈ {c : β | ∀ᶠ (n : α) in f, c ≤ u n}), b < c :=
exists_lt_of_lt_cSup hu h,
exact hc.mono (λ x hx, lt_of_lt_of_le hbc hx)
end
lemma eventually_lt_of_limsup_lt {f : filter α} [conditionally_complete_linear_order β]
{u : α → β} {b : β} (h : limsup u f < b) (hu : f.is_bounded_under (≤) u . is_bounded_default) :
∀ᶠ a in f, u a < b :=
@eventually_lt_of_lt_liminf _ βᵒᵈ _ _ _ _ h hu
lemma le_limsup_of_frequently_le {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, b ≤ u x)
(hu : f.is_bounded_under (≤) u . is_bounded_default) :
b ≤ limsup u f :=
begin
revert hu_le,
rw [←not_imp_not, not_frequently],
simp_rw ←lt_iff_not_ge,
exact λ h, eventually_lt_of_limsup_lt h hu,
end
lemma liminf_le_of_frequently_le {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β} (hu_le : ∃ᶠ x in f, u x ≤ b)
(hu : f.is_bounded_under (≥) u . is_bounded_default) :
liminf u f ≤ b :=
@le_limsup_of_frequently_le _ βᵒᵈ _ f u b hu_le hu
lemma frequently_lt_of_lt_limsup {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β}
(hu : f.is_cobounded_under (≤) u . is_bounded_default) (h : b < limsup u f) :
∃ᶠ x in f, b < u x :=
begin
contrapose! h,
apply Limsup_le_of_le hu,
simpa using h,
end
lemma frequently_lt_of_liminf_lt {α β} [conditionally_complete_linear_order β] {f : filter α}
{u : α → β} {b : β}
(hu : f.is_cobounded_under (≥) u . is_bounded_default) (h : liminf u f < b) :
∃ᶠ x in f, u x < b :=
@frequently_lt_of_lt_limsup _ βᵒᵈ _ f u b hu h
variables [conditionally_complete_linear_order α] {f : filter α} {b : α}
lemma lt_mem_sets_of_Limsup_lt (h : f.is_bounded (≤)) (l : f.Limsup < b) : ∀ᶠ a in f, a < b :=
let ⟨c, (h : ∀ᶠ a in f, a ≤ c), hcb⟩ := exists_lt_of_cInf_lt h l in
mem_of_superset h $ λ a, hcb.trans_le'
lemma gt_mem_sets_of_Liminf_gt : f.is_bounded (≥) → b < f.Liminf → ∀ᶠ a in f, b < a :=
@lt_mem_sets_of_Limsup_lt αᵒᵈ _ _ _
end conditionally_complete_linear_order
end filter
section order
open filter
lemma monotone.is_bounded_under_le_comp [nonempty β] [linear_order β] [preorder γ]
[no_max_order γ] {g : β → γ} {f : α → β} {l : filter α} (hg : monotone g)
(hg' : tendsto g at_top at_top) :
is_bounded_under (≤) l (g ∘ f) ↔ is_bounded_under (≤) l f :=
begin
refine ⟨_, λ h, h.is_bounded_under hg⟩,
rintro ⟨c, hc⟩, rw eventually_map at hc,
obtain ⟨b, hb⟩ : ∃ b, ∀ a ≥ b, c < g a := eventually_at_top.1 (hg'.eventually_gt_at_top c),
exact ⟨b, hc.mono $ λ x hx, not_lt.1 (λ h, (hb _ h.le).not_le hx)⟩
end
lemma monotone.is_bounded_under_ge_comp [nonempty β] [linear_order β] [preorder γ]
[no_min_order γ] {g : β → γ} {f : α → β} {l : filter α} (hg : monotone g)
(hg' : tendsto g at_bot at_bot) :
is_bounded_under (≥) l (g ∘ f) ↔ is_bounded_under (≥) l f :=
hg.dual.is_bounded_under_le_comp hg'
lemma antitone.is_bounded_under_le_comp [nonempty β] [linear_order β] [preorder γ]
[no_max_order γ] {g : β → γ} {f : α → β} {l : filter α} (hg : antitone g)
(hg' : tendsto g at_bot at_top) :
is_bounded_under (≤) l (g ∘ f) ↔ is_bounded_under (≥) l f :=
hg.dual_right.is_bounded_under_ge_comp hg'
lemma antitone.is_bounded_under_ge_comp [nonempty β] [linear_order β] [preorder γ]
[no_min_order γ] {g : β → γ} {f : α → β} {l : filter α} (hg : antitone g)
(hg' : tendsto g at_top at_bot) :
is_bounded_under (≥) l (g ∘ f) ↔ is_bounded_under (≤) l f :=
hg.dual_right.is_bounded_under_le_comp hg'
lemma galois_connection.l_limsup_le [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {v : α → β}
{l : β → γ} {u : γ → β} (gc : galois_connection l u)
(hlv : f.is_bounded_under (≤) (λ x, l (v x)) . is_bounded_default)
(hv_co : f.is_cobounded_under (≤) v . is_bounded_default) :
l (limsup v f) ≤ limsup (λ x, l (v x)) f :=
begin
refine le_Limsup_of_le hlv (λ c hc, _),
rw filter.eventually_map at hc,
simp_rw (gc _ _) at hc ⊢,
exact Limsup_le_of_le hv_co hc,
end
lemma order_iso.limsup_apply {γ} [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {u : α → β} (g : β ≃o γ)
(hu : f.is_bounded_under (≤) u . is_bounded_default)
(hu_co : f.is_cobounded_under (≤) u . is_bounded_default)
(hgu : f.is_bounded_under (≤) (λ x, g (u x)) . is_bounded_default)
(hgu_co : f.is_cobounded_under (≤) (λ x, g (u x)) . is_bounded_default) :
g (limsup u f) = limsup (λ x, g (u x)) f :=
begin
refine le_antisymm (g.to_galois_connection.l_limsup_le hgu hu_co) _,
rw [←(g.symm.symm_apply_apply $ limsup (λ x, g (u x)) f), g.symm_symm],
refine g.monotone _,
have hf : u = λ i, g.symm (g (u i)), from funext (λ i, (g.symm_apply_apply (u i)).symm),
nth_rewrite 0 hf,
refine g.symm.to_galois_connection.l_limsup_le _ hgu_co,
simp_rw g.symm_apply_apply,
exact hu,
end
lemma order_iso.liminf_apply {γ} [conditionally_complete_lattice β]
[conditionally_complete_lattice γ] {f : filter α} {u : α → β} (g : β ≃o γ)
(hu : f.is_bounded_under (≥) u . is_bounded_default)
(hu_co : f.is_cobounded_under (≥) u . is_bounded_default)
(hgu : f.is_bounded_under (≥) (λ x, g (u x)) . is_bounded_default)
(hgu_co : f.is_cobounded_under (≥) (λ x, g (u x)) . is_bounded_default) :
g (liminf u f) = liminf (λ x, g (u x)) f :=
@order_iso.limsup_apply α βᵒᵈ γᵒᵈ _ _ f u g.dual hu hu_co hgu hgu_co
end order
|
273bd1ee703d1f8eb48cad7004c299ebb519368c | 8b9f17008684d796c8022dab552e42f0cb6fb347 | /tests/lean/hott/rewriter1.hlean | b21e76d016f6d39ad2d743044dfbdbf0a33f6746 | [
"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 | 663 | hlean | import algebra.group
open path_algebra
constant f {A : Type} : A → A → A
theorem test1 {A : Type} [s : add_comm_group A] (a b c : A) : f (a + 0) (f (a + 0) (a + 0)) = f a (f (0 + a) a) :=
begin
rewrite [
add_zero at {1, 3}, -- rewrite 1st and 3rd occurrences
{0 + _}add_comm] -- apply commutativity to (0 + _)
end
axiom Ax {A : Type} [s₁ : has_mul A] [s₂ : has_one A] (a : A) : f (a * 1) (a * 1) = 1
theorem test2 {A : Type} [s : comm_group A] (a b c : A) : f a a = 1 :=
begin
rewrite [-(mul_one a), -- - means apply symmetry, rewrite 0 ==> a * 0 at 1st and 2nd occurrences
Ax] -- use Ax as rewrite rule
end
|
b56cf82949411c443c72163b73c30e9d8e5f5d8a | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/data/rat/lemmas.lean | dca8988238a72c74b3dba9c6cbb9014a35e56ecf | [
"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,307 | lean | /-
Copyright (c) 2019 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro
-/
import data.rat.defs
import data.int.cast.lemmas
import data.int.div
import algebra.group_with_zero.units.lemmas
import tactic.nth_rewrite
/-!
# Further lemmas for the Rational Numbers
-/
namespace rat
open_locale rat
theorem num_dvd (a) {b : ℤ} (b0 : b ≠ 0) : (a /. b).num ∣ a :=
begin
cases e : a /. b with n d h c,
rw [rat.num_denom', rat.mk_eq b0
(ne_of_gt (int.coe_nat_pos.2 h))] at e,
refine (int.nat_abs_dvd.1 $ int.dvd_nat_abs.1 $ int.coe_nat_dvd.2 $
c.dvd_of_dvd_mul_right _),
have := congr_arg int.nat_abs e,
simp only [int.nat_abs_mul, int.nat_abs_of_nat] at this, simp [this]
end
theorem denom_dvd (a b : ℤ) : ((a /. b).denom : ℤ) ∣ b :=
begin
by_cases b0 : b = 0, {simp [b0]},
cases e : a /. b with n d h c,
rw [num_denom', mk_eq b0 (ne_of_gt (int.coe_nat_pos.2 h))] at e,
refine (int.dvd_nat_abs.1 $ int.coe_nat_dvd.2 $ c.symm.dvd_of_dvd_mul_left _),
rw [← int.nat_abs_mul, ← int.coe_nat_dvd, int.dvd_nat_abs, ← e], simp
end
lemma num_denom_mk {q : ℚ} {n d : ℤ} (hd : d ≠ 0) (qdf : q = n /. d) :
∃ c : ℤ, n = c * q.num ∧ d = c * q.denom :=
begin
obtain rfl|hn := eq_or_ne n 0,
{ simp [qdf] },
have : q.num * d = n * ↑(q.denom),
{ refine (rat.mk_eq _ hd).mp _,
{ exact int.coe_nat_ne_zero.mpr (rat.denom_ne_zero _) },
{ rwa [num_denom] } },
have hqdn : q.num ∣ n,
{ rw qdf, exact rat.num_dvd _ hd },
refine ⟨n / q.num, _, _⟩,
{ rw int.div_mul_cancel hqdn },
{ refine int.eq_mul_div_of_mul_eq_mul_of_dvd_left _ hqdn this,
rw qdf,
exact rat.num_ne_zero_of_ne_zero ((mk_ne_zero hd).mpr hn) }
end
theorem mk_pnat_num (n : ℤ) (d : ℕ+) :
(mk_pnat n d).num = n / nat.gcd n.nat_abs d :=
by cases d; refl
theorem mk_pnat_denom (n : ℤ) (d : ℕ+) :
(mk_pnat n d).denom = d / nat.gcd n.nat_abs d :=
by cases d; refl
lemma num_mk (n d : ℤ) :
(n /. d).num = d.sign * n / n.gcd d :=
begin
rcases d with ((_ | _) | _);
simp [rat.mk, mk_nat, mk_pnat, nat.succ_pnat, int.sign, int.gcd,
-nat.cast_succ, -int.coe_nat_succ, int.zero_div]
end
lemma denom_mk (n d : ℤ) :
(n /. d).denom = if d = 0 then 1 else d.nat_abs / n.gcd d :=
begin
rcases d with ((_ | _) | _);
simp [rat.mk, mk_nat, mk_pnat, nat.succ_pnat, int.sign, int.gcd,
-nat.cast_succ, -int.coe_nat_succ]
end
theorem mk_pnat_denom_dvd (n : ℤ) (d : ℕ+) :
(mk_pnat n d).denom ∣ d.1 :=
begin
rw mk_pnat_denom,
apply nat.div_dvd_of_dvd,
apply nat.gcd_dvd_right
end
theorem add_denom_dvd (q₁ q₂ : ℚ) : (q₁ + q₂).denom ∣ q₁.denom * q₂.denom :=
by { cases q₁, cases q₂, apply mk_pnat_denom_dvd }
theorem mul_denom_dvd (q₁ q₂ : ℚ) : (q₁ * q₂).denom ∣ q₁.denom * q₂.denom :=
by { cases q₁, cases q₂, apply mk_pnat_denom_dvd }
theorem mul_num (q₁ q₂ : ℚ) : (q₁ * q₂).num =
(q₁.num * q₂.num) / nat.gcd (q₁.num * q₂.num).nat_abs (q₁.denom * q₂.denom) :=
by cases q₁; cases q₂; refl
theorem mul_denom (q₁ q₂ : ℚ) : (q₁ * q₂).denom =
(q₁.denom * q₂.denom) / nat.gcd (q₁.num * q₂.num).nat_abs (q₁.denom * q₂.denom) :=
by cases q₁; cases q₂; refl
theorem mul_self_num (q : ℚ) : (q * q).num = q.num * q.num :=
by rw [mul_num, int.nat_abs_mul, nat.coprime.gcd_eq_one, int.coe_nat_one, int.div_one];
exact (q.cop.mul_right q.cop).mul (q.cop.mul_right q.cop)
theorem mul_self_denom (q : ℚ) : (q * q).denom = q.denom * q.denom :=
by rw [rat.mul_denom, int.nat_abs_mul, nat.coprime.gcd_eq_one, nat.div_one];
exact (q.cop.mul_right q.cop).mul (q.cop.mul_right q.cop)
lemma add_num_denom (q r : ℚ) : q + r =
((q.num * r.denom + q.denom * r.num : ℤ)) /. (↑q.denom * ↑r.denom : ℤ) :=
have hqd : (q.denom : ℤ) ≠ 0, from int.coe_nat_ne_zero_iff_pos.2 q.3,
have hrd : (r.denom : ℤ) ≠ 0, from int.coe_nat_ne_zero_iff_pos.2 r.3,
by conv_lhs { rw [←@num_denom q, ←@num_denom r, rat.add_def hqd hrd] };
simp [mul_comm]
section casts
lemma exists_eq_mul_div_num_and_eq_mul_div_denom (n : ℤ) {d : ℤ} (d_ne_zero : d ≠ 0) :
∃ (c : ℤ), n = c * ((n : ℚ) / d).num ∧ (d : ℤ) = c * ((n : ℚ) / d).denom :=
begin
have : ((n : ℚ) / d) = rat.mk n d, by rw [←rat.mk_eq_div],
exact rat.num_denom_mk d_ne_zero this
end
lemma mul_num_denom' (q r : ℚ) :
(q * r).num * q.denom * r.denom = q.num * r.num * (q * r).denom :=
begin
let s := (q.num * r.num) /. (q.denom * r.denom : ℤ),
have hs : (q.denom * r.denom : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.mpr (mul_pos q.pos r.pos),
obtain ⟨c, ⟨c_mul_num, c_mul_denom⟩⟩ :=
exists_eq_mul_div_num_and_eq_mul_div_denom (q.num * r.num) hs,
rw [c_mul_num, mul_assoc, mul_comm],
nth_rewrite 0 c_mul_denom,
repeat {rw mul_assoc},
apply mul_eq_mul_left_iff.2,
rw or_iff_not_imp_right,
intro c_pos,
have h : _ = s := @mul_def q.num q.denom r.num r.denom
(int.coe_nat_ne_zero_iff_pos.mpr q.pos)
(int.coe_nat_ne_zero_iff_pos.mpr r.pos),
rw [num_denom, num_denom] at h,
rw h,
rw mul_comm,
apply rat.eq_iff_mul_eq_mul.mp,
rw ←mk_eq_div,
end
lemma add_num_denom' (q r : ℚ) :
(q + r).num * q.denom * r.denom = (q.num * r.denom + r.num * q.denom) * (q + r).denom :=
begin
let s := mk (q.num * r.denom + r.num * q.denom) (q.denom * r.denom : ℤ),
have hs : (q.denom * r.denom : ℤ) ≠ 0 := int.coe_nat_ne_zero_iff_pos.mpr (mul_pos q.pos r.pos),
obtain ⟨c, ⟨c_mul_num, c_mul_denom⟩⟩ := exists_eq_mul_div_num_and_eq_mul_div_denom
(q.num * r.denom + r.num * q.denom) hs,
rw [c_mul_num, mul_assoc, mul_comm],
nth_rewrite 0 c_mul_denom,
repeat {rw mul_assoc},
apply mul_eq_mul_left_iff.2,
rw or_iff_not_imp_right,
intro c_pos,
have h : _ = s := @add_def q.num q.denom r.num r.denom
(int.coe_nat_ne_zero_iff_pos.mpr q.pos)
(int.coe_nat_ne_zero_iff_pos.mpr r.pos),
rw [num_denom, num_denom] at h,
rw h,
rw mul_comm,
apply rat.eq_iff_mul_eq_mul.mp,
rw ←mk_eq_div,
end
lemma substr_num_denom' (q r : ℚ) :
(q - r).num * q.denom * r.denom = (q.num * r.denom - r.num * q.denom) * (q - r).denom :=
by rw [sub_eq_add_neg, sub_eq_add_neg, ←neg_mul, ←num_neg_eq_neg_num, ←denom_neg_eq_denom r,
add_num_denom' q (-r)]
end casts
lemma inv_def' {q : ℚ} : q⁻¹ = (q.denom : ℚ) / q.num :=
by { conv_lhs { rw ←@num_denom q }, rw [inv_def, mk_eq_div, int.cast_coe_nat] }
protected lemma inv_neg (q : ℚ) : (-q)⁻¹ = -q⁻¹ := by { rw ←@num_denom q, simp [-num_denom] }
@[simp] lemma mul_denom_eq_num {q : ℚ} : q * q.denom = q.num :=
begin
suffices : mk (q.num) ↑(q.denom) * mk ↑(q.denom) 1 = mk (q.num) 1, by
{ conv { for q [1] { rw ←(@num_denom q) }}, rwa [coe_int_eq_mk, coe_nat_eq_mk] },
have : (q.denom : ℤ) ≠ 0, from ne_of_gt (by exact_mod_cast q.pos),
rw [(rat.mul_def this one_ne_zero), (mul_comm (q.denom : ℤ) 1), (div_mk_div_cancel_left this)]
end
lemma denom_div_cast_eq_one_iff (m n : ℤ) (hn : n ≠ 0) :
((m : ℚ) / n).denom = 1 ↔ n ∣ m :=
begin
replace hn : (n:ℚ) ≠ 0, by rwa [ne.def, ← int.cast_zero, coe_int_inj],
split,
{ intro h,
lift ((m : ℚ) / n) to ℤ using h with k hk,
use k,
rwa [eq_div_iff_mul_eq hn, ← int.cast_mul, mul_comm, eq_comm, coe_int_inj] at hk },
{ rintros ⟨d, rfl⟩,
rw [int.cast_mul, mul_comm, mul_div_cancel _ hn, rat.coe_int_denom] }
end
lemma num_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :
(a / b : ℚ).num = a :=
begin
lift b to ℕ using le_of_lt hb0,
norm_cast at hb0 h,
rw [← rat.mk_eq_div, ← rat.mk_pnat_eq a b hb0, rat.mk_pnat_num, pnat.mk_coe, h.gcd_eq_one,
int.coe_nat_one, int.div_one]
end
lemma denom_div_eq_of_coprime {a b : ℤ} (hb0 : 0 < b) (h : nat.coprime a.nat_abs b.nat_abs) :
((a / b : ℚ).denom : ℤ) = b :=
begin
lift b to ℕ using le_of_lt hb0,
norm_cast at hb0 h,
rw [← rat.mk_eq_div, ← rat.mk_pnat_eq a b hb0, rat.mk_pnat_denom, pnat.mk_coe, h.gcd_eq_one,
nat.div_one]
end
lemma div_int_inj {a b c d : ℤ} (hb0 : 0 < b) (hd0 : 0 < d)
(h1 : nat.coprime a.nat_abs b.nat_abs) (h2 : nat.coprime c.nat_abs d.nat_abs)
(h : (a : ℚ) / b = (c : ℚ) / d) : a = c ∧ b = d :=
begin
apply and.intro,
{ rw [← (num_div_eq_of_coprime hb0 h1), h, num_div_eq_of_coprime hd0 h2] },
{ rw [← (denom_div_eq_of_coprime hb0 h1), h, denom_div_eq_of_coprime hd0 h2] }
end
@[norm_cast] lemma coe_int_div_self (n : ℤ) : ((n / n : ℤ) : ℚ) = n / n :=
begin
by_cases hn : n = 0,
{ subst hn, simp only [int.cast_zero, int.zero_div, zero_div] },
{ have : (n : ℚ) ≠ 0, { rwa ← coe_int_inj at hn },
simp only [int.div_self hn, int.cast_one, ne.def, not_false_iff, div_self this] }
end
@[norm_cast] lemma coe_nat_div_self (n : ℕ) : ((n / n : ℕ) : ℚ) = n / n :=
coe_int_div_self n
lemma coe_int_div (a b : ℤ) (h : b ∣ a) : ((a / b : ℤ) : ℚ) = a / b :=
begin
rcases h with ⟨c, rfl⟩,
simp only [mul_comm b, int.mul_div_assoc c (dvd_refl b), int.cast_mul, mul_div_assoc,
coe_int_div_self]
end
lemma coe_nat_div (a b : ℕ) (h : b ∣ a) : ((a / b : ℕ) : ℚ) = a / b :=
begin
rcases h with ⟨c, rfl⟩,
simp only [mul_comm b, nat.mul_div_assoc c (dvd_refl b), nat.cast_mul, mul_div_assoc,
coe_nat_div_self]
end
lemma inv_coe_int_num_of_pos {a : ℤ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 :=
begin
rw [rat.inv_def', rat.coe_int_num, rat.coe_int_denom, nat.cast_one, ←int.cast_one],
apply num_div_eq_of_coprime ha0,
rw int.nat_abs_one,
exact nat.coprime_one_left _,
end
lemma inv_coe_nat_num_of_pos {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.num = 1 :=
inv_coe_int_num_of_pos (by exact_mod_cast ha0 : 0 < (a : ℤ))
lemma inv_coe_int_denom_of_pos {a : ℤ} (ha0 : 0 < a) : ((a : ℚ)⁻¹.denom : ℤ) = a :=
begin
rw [rat.inv_def', rat.coe_int_num, rat.coe_int_denom, nat.cast_one, ←int.cast_one],
apply denom_div_eq_of_coprime ha0,
rw int.nat_abs_one,
exact nat.coprime_one_left _,
end
lemma inv_coe_nat_denom_of_pos {a : ℕ} (ha0 : 0 < a) : (a : ℚ)⁻¹.denom = a :=
begin
rw [← int.coe_nat_eq_coe_nat_iff, ← int.cast_coe_nat a, inv_coe_int_denom_of_pos],
rwa [← nat.cast_zero, nat.cast_lt]
end
@[simp] lemma inv_coe_int_num (a : ℤ) : (a : ℚ)⁻¹.num = int.sign a :=
begin
induction a using int.induction_on;
simp [←int.neg_succ_of_nat_coe', int.neg_succ_of_nat_coe, -neg_add_rev, rat.inv_neg,
int.coe_nat_add_one_out, -nat.cast_succ, inv_coe_nat_num_of_pos, -int.cast_neg_succ_of_nat,
@eq_comm ℤ 1, int.sign_eq_one_of_pos]
end
@[simp] lemma inv_coe_nat_num (a : ℕ) : (a : ℚ)⁻¹.num = int.sign a :=
inv_coe_int_num a
@[simp] lemma inv_coe_int_denom (a : ℤ) : (a : ℚ)⁻¹.denom = if a = 0 then 1 else a.nat_abs :=
begin
induction a using int.induction_on;
simp [←int.neg_succ_of_nat_coe', int.neg_succ_of_nat_coe, -neg_add_rev, rat.inv_neg,
int.coe_nat_add_one_out, -nat.cast_succ, inv_coe_nat_denom_of_pos,
-int.cast_neg_succ_of_nat]
end
@[simp] lemma inv_coe_nat_denom (a : ℕ) : (a : ℚ)⁻¹.denom = if a = 0 then 1 else a :=
by simpa using inv_coe_int_denom a
protected lemma «forall» {p : ℚ → Prop} : (∀ r, p r) ↔ ∀ a b : ℤ, p (a / b) :=
⟨λ h _ _, h _,
λ h q, (show q = q.num / q.denom, from by simp [rat.div_num_denom]).symm ▸ (h q.1 q.2)⟩
protected lemma «exists» {p : ℚ → Prop} : (∃ r, p r) ↔ ∃ a b : ℤ, p (a / b) :=
⟨λ ⟨r, hr⟩, ⟨r.num, r.denom, by rwa [← mk_eq_div, num_denom]⟩, λ ⟨a, b, h⟩, ⟨_, h⟩⟩
/-!
### Denominator as `ℕ+`
-/
section pnat_denom
/-- Denominator as `ℕ+`. -/
def pnat_denom (x : ℚ) : ℕ+ := ⟨x.denom, x.pos⟩
@[simp] lemma coe_pnat_denom (x : ℚ) : (x.pnat_denom : ℕ) = x.denom := rfl
@[simp] lemma mk_pnat_pnat_denom_eq (x : ℚ) : mk_pnat x.num x.pnat_denom = x :=
by rw [pnat_denom, mk_pnat_eq, num_denom]
lemma pnat_denom_eq_iff_denom_eq {x : ℚ} {n : ℕ+} : x.pnat_denom = n ↔ x.denom = ↑n :=
subtype.ext_iff
@[simp] lemma pnat_denom_one : (1 : ℚ).pnat_denom = 1 := rfl
@[simp] lemma pnat_denom_zero : (0 : ℚ).pnat_denom = 1 := rfl
end pnat_denom
end rat
|
8da24111e65b8233b057353a3bb735625e19398e | a45212b1526d532e6e83c44ddca6a05795113ddc | /src/order/basic.lean | 9b44878a7e2e2081ffe27c2d329503776bdda0af | [
"Apache-2.0"
] | permissive | fpvandoorn/mathlib | b21ab4068db079cbb8590b58fda9cc4bc1f35df4 | b3433a51ea8bc07c4159c1073838fc0ee9b8f227 | refs/heads/master | 1,624,791,089,608 | 1,556,715,231,000 | 1,556,715,231,000 | 165,722,980 | 5 | 0 | Apache-2.0 | 1,552,657,455,000 | 1,547,494,646,000 | Lean | UTF-8 | Lean | false | false | 23,516 | lean | /-
Copyright (c) 2014 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Mario Carneiro
-/
import logic.basic data.sum data.set.basic algebra.order
open function
/- TODO: automatic construction of dual definitions / theorems -/
universes u v w
variables {α : Type u} {β : Type v} {γ : Type w} {r : α → α → Prop}
theorem ge_of_eq [preorder α] {a b : α} : a = b → a ≥ b :=
λ h, h ▸ le_refl a
theorem is_refl.swap (r) [is_refl α r] : is_refl α (swap r) := ⟨refl_of r⟩
theorem is_irrefl.swap (r) [is_irrefl α r] : is_irrefl α (swap r) := ⟨irrefl_of r⟩
theorem is_trans.swap (r) [is_trans α r] : is_trans α (swap r) :=
⟨λ a b c h₁ h₂, trans_of r h₂ h₁⟩
theorem is_antisymm.swap (r) [is_antisymm α r] : is_antisymm α (swap r) :=
⟨λ a b h₁ h₂, antisymm h₂ h₁⟩
theorem is_asymm.swap (r) [is_asymm α r] : is_asymm α (swap r) :=
⟨λ a b h₁ h₂, asymm_of r h₂ h₁⟩
theorem is_total.swap (r) [is_total α r] : is_total α (swap r) :=
⟨λ a b, (total_of r a b).swap⟩
theorem is_trichotomous.swap (r) [is_trichotomous α r] : is_trichotomous α (swap r) :=
⟨λ a b, by simpa [swap, or.comm, or.left_comm] using trichotomous_of r a b⟩
theorem is_preorder.swap (r) [is_preorder α r] : is_preorder α (swap r) :=
{..@is_refl.swap α r _, ..@is_trans.swap α r _}
theorem is_strict_order.swap (r) [is_strict_order α r] : is_strict_order α (swap r) :=
{..@is_irrefl.swap α r _, ..@is_trans.swap α r _}
theorem is_partial_order.swap (r) [is_partial_order α r] : is_partial_order α (swap r) :=
{..@is_preorder.swap α r _, ..@is_antisymm.swap α r _}
theorem is_total_preorder.swap (r) [is_total_preorder α r] : is_total_preorder α (swap r) :=
{..@is_preorder.swap α r _, ..@is_total.swap α r _}
theorem is_linear_order.swap (r) [is_linear_order α r] : is_linear_order α (swap r) :=
{..@is_partial_order.swap α r _, ..@is_total.swap α r _}
def antisymm_of_asymm (r) [is_asymm α r] : is_antisymm α r :=
⟨λ x y h₁ h₂, (asymm h₁ h₂).elim⟩
/- Convert algebraic structure style to explicit relation style typeclasses -/
instance [preorder α] : is_refl α (≤) := ⟨le_refl⟩
instance [preorder α] : is_refl α (≥) := is_refl.swap _
instance [preorder α] : is_trans α (≤) := ⟨@le_trans _ _⟩
instance [preorder α] : is_trans α (≥) := is_trans.swap _
instance [preorder α] : is_preorder α (≤) := {}
instance [preorder α] : is_preorder α (≥) := {}
instance [preorder α] : is_irrefl α (<) := ⟨lt_irrefl⟩
instance [preorder α] : is_irrefl α (>) := is_irrefl.swap _
instance [preorder α] : is_trans α (<) := ⟨@lt_trans _ _⟩
instance [preorder α] : is_trans α (>) := is_trans.swap _
instance [preorder α] : is_asymm α (<) := ⟨@lt_asymm _ _⟩
instance [preorder α] : is_asymm α (>) := is_asymm.swap _
instance [preorder α] : is_antisymm α (<) := antisymm_of_asymm _
instance [preorder α] : is_antisymm α (>) := antisymm_of_asymm _
instance [preorder α] : is_strict_order α (<) := {}
instance [preorder α] : is_strict_order α (>) := {}
instance preorder.is_total_preorder [preorder α] [is_total α (≤)] : is_total_preorder α (≤) := {}
instance [partial_order α] : is_antisymm α (≤) := ⟨@le_antisymm _ _⟩
instance [partial_order α] : is_antisymm α (≥) := is_antisymm.swap _
instance [partial_order α] : is_partial_order α (≤) := {}
instance [partial_order α] : is_partial_order α (≥) := {}
instance [linear_order α] : is_total α (≤) := ⟨le_total⟩
instance [linear_order α] : is_total α (≥) := is_total.swap _
instance linear_order.is_total_preorder [linear_order α] : is_total_preorder α (≤) := by apply_instance
instance [linear_order α] : is_total_preorder α (≥) := {}
instance [linear_order α] : is_linear_order α (≤) := {}
instance [linear_order α] : is_linear_order α (≥) := {}
instance [linear_order α] : is_trichotomous α (<) := ⟨lt_trichotomy⟩
instance [linear_order α] : is_trichotomous α (>) := is_trichotomous.swap _
theorem preorder.ext {α} {A B : preorder α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
begin
resetI, cases A, cases B, congr,
{ funext x y, exact propext (H x y) },
{ funext x y,
dsimp [(≤)] at A_lt_iff_le_not_le B_lt_iff_le_not_le H,
simp [A_lt_iff_le_not_le, B_lt_iff_le_not_le, H] },
end
theorem partial_order.ext {α} {A B : partial_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by haveI this := preorder.ext H;
cases A; cases B; injection this; congr'
theorem linear_order.ext {α} {A B : linear_order α}
(H : ∀ x y : α, (by haveI := A; exact x ≤ y) ↔ x ≤ y) : A = B :=
by haveI this := partial_order.ext H;
cases A; cases B; injection this; congr'
/-- Given an order `R` on `β` and a function `f : α → β`,
the preimage order on `α` is defined by `x ≤ y ↔ f x ≤ f y`.
It is the unique order on `α` making `f` an order embedding
(assuming `f` is injective). -/
@[simp] def order.preimage {α β} (f : α → β) (s : β → β → Prop) (x y : α) := s (f x) (f y)
infix ` ⁻¹'o `:80 := order.preimage
section monotone
variables [preorder α] [preorder β] [preorder γ]
/-- A function between preorders is monotone if
`a ≤ b` implies `f a ≤ f b`. -/
def monotone (f : α → β) := ∀⦃a b⦄, a ≤ b → f a ≤ f b
theorem monotone_id : @monotone α α _ _ id := assume x y h, h
theorem monotone_const {b : β} : monotone (λ(a:α), b) := assume x y h, le_refl b
theorem monotone_comp {f : α → β} {g : β → γ} (m_f : monotone f) (m_g : monotone g) :
monotone (g ∘ f) :=
assume a b h, m_g (m_f h)
lemma monotone_of_monotone_nat {f : ℕ → α} (hf : ∀n, f n ≤ f (n + 1)) :
monotone f | n m h :=
begin
induction h,
{ refl },
{ transitivity, assumption, exact hf _ }
end
end monotone
def order_dual (α : Type*) := α
namespace order_dual
instance (α : Type*) [has_le α] : has_le (order_dual α) := ⟨λx y:α, y ≤ x⟩
instance (α : Type*) [has_lt α] : has_lt (order_dual α) := ⟨λx y:α, y < x⟩
instance (α : Type*) [preorder α] : preorder (order_dual α) :=
{ le_refl := le_refl,
le_trans := assume a b c hab hbc, le_trans hbc hab,
lt_iff_le_not_le := λ _ _, lt_iff_le_not_le,
.. order_dual.has_le α,
.. order_dual.has_lt α }
instance (α : Type*) [partial_order α] : partial_order (order_dual α) :=
{ le_antisymm := assume a b hab hba, @le_antisymm α _ a b hba hab, .. order_dual.preorder α }
instance (α : Type*) [linear_order α] : linear_order (order_dual α) :=
{ le_total := assume a b:α, le_total b a, .. order_dual.partial_order α }
instance (α : Type*) [decidable_linear_order α] : decidable_linear_order (order_dual α) :=
{ decidable_le := show decidable_rel (λa b:α, b ≤ a), by apply_instance,
decidable_lt := show decidable_rel (λa b:α, b < a), by apply_instance,
.. order_dual.linear_order α }
end order_dual
/- order instances on the function space -/
instance pi.preorder {ι : Type u} {α : ι → Type v} [∀i, preorder (α i)] : preorder (Πi, α i) :=
{ le := λx y, ∀i, x i ≤ y i,
le_refl := assume a i, le_refl (a i),
le_trans := assume a b c h₁ h₂ i, le_trans (h₁ i) (h₂ i) }
instance pi.partial_order {ι : Type u} {α : ι → Type v} [∀i, partial_order (α i)] : partial_order (Πi, α i) :=
{ le_antisymm := λf g h1 h2, funext (λb, le_antisymm (h1 b) (h2 b)),
..pi.preorder }
theorem comp_le_comp_left_of_monotone [preorder α] [preorder β] [preorder γ]
{f : β → α} {g h : γ → β} (m_f : monotone f) (le_gh : g ≤ h) : has_le.le.{max w u} (f ∘ g) (f ∘ h) :=
assume x, m_f (le_gh x)
section monotone
variables [preorder α] [preorder γ]
theorem monotone_lam {f : α → β → γ} (m : ∀b, monotone (λa, f a b)) : monotone f :=
assume a a' h b, m b h
theorem monotone_app (f : β → α → γ) (b : β) (m : monotone (λa b, f b a)) : monotone (f b) :=
assume a a' h, m h b
end monotone
def preorder.lift {α β} [preorder β] (f : α → β) : preorder α :=
{ le := λx y, f x ≤ f y,
le_refl := λ a, le_refl _,
le_trans := λ a b c, le_trans,
lt := λx y, f x < f y,
lt_iff_le_not_le := λ a b, lt_iff_le_not_le }
def partial_order.lift {α β} [partial_order β]
(f : α → β) (inj : injective f) : partial_order α :=
{ le_antisymm := λ a b h₁ h₂, inj (le_antisymm h₁ h₂), .. preorder.lift f }
def linear_order.lift {α β} [linear_order β]
(f : α → β) (inj : injective f) : linear_order α :=
{ le_total := λx y, le_total (f x) (f y), .. partial_order.lift f inj }
def decidable_linear_order.lift {α β} [decidable_linear_order β]
(f : α → β) (inj : injective f) : decidable_linear_order α :=
{ decidable_le := λ x y, show decidable (f x ≤ f y), by apply_instance,
decidable_lt := λ x y, show decidable (f x < f y), by apply_instance,
decidable_eq := λ x y, decidable_of_iff _ ⟨@inj x y, congr_arg f⟩,
.. linear_order.lift f inj }
instance subtype.preorder {α} [preorder α] (p : α → Prop) : preorder (subtype p) :=
preorder.lift subtype.val
instance subtype.partial_order {α} [partial_order α] (p : α → Prop) : partial_order (subtype p) :=
partial_order.lift subtype.val $ λ x y, subtype.eq'
instance subtype.linear_order {α} [linear_order α] (p : α → Prop) : linear_order (subtype p) :=
linear_order.lift subtype.val $ λ x y, subtype.eq'
instance subtype.decidable_linear_order {α} [decidable_linear_order α] (p : α → Prop) :
decidable_linear_order (subtype p) :=
decidable_linear_order.lift subtype.val $ λ x y, subtype.eq'
instance prod.has_le (α : Type u) (β : Type v) [has_le α] [has_le β] : has_le (α × β) :=
⟨λp q, p.1 ≤ q.1 ∧ p.2 ≤ q.2⟩
instance prod.preorder (α : Type u) (β : Type v) [preorder α] [preorder β] : preorder (α × β) :=
{ le_refl := assume ⟨a, b⟩, ⟨le_refl a, le_refl b⟩,
le_trans := assume ⟨a, b⟩ ⟨c, d⟩ ⟨e, f⟩ ⟨hac, hbd⟩ ⟨hce, hdf⟩,
⟨le_trans hac hce, le_trans hbd hdf⟩,
.. prod.has_le α β }
/-- The pointwise partial order on a product.
(The lexicographic ordering is defined in order/lexicographic.lean, and the instances are
available via the type synonym `lex α β = α × β`.) -/
instance prod.partial_order (α : Type u) (β : Type v) [partial_order α] [partial_order β] :
partial_order (α × β) :=
{ le_antisymm := assume ⟨a, b⟩ ⟨c, d⟩ ⟨hac, hbd⟩ ⟨hca, hdb⟩,
prod.ext (le_antisymm hac hca) (le_antisymm hbd hdb),
.. prod.preorder α β }
/- additional order classes -/
/-- order without a top element; somtimes called cofinal -/
class no_top_order (α : Type u) [preorder α] : Prop :=
(no_top : ∀a:α, ∃a', a < a')
lemma no_top [preorder α] [no_top_order α] : ∀a:α, ∃a', a < a' :=
no_top_order.no_top
/-- order without a bottom element; somtimes called coinitial or dense -/
class no_bot_order (α : Type u) [preorder α] : Prop :=
(no_bot : ∀a:α, ∃a', a' < a)
lemma no_bot [preorder α] [no_bot_order α] : ∀a:α, ∃a', a' < a :=
no_bot_order.no_bot
/-- An order is dense if there is an element between any pair of distinct elements. -/
class densely_ordered (α : Type u) [preorder α] : Prop :=
(dense : ∀a₁ a₂:α, a₁ < a₂ → ∃a, a₁ < a ∧ a < a₂)
lemma dense [preorder α] [densely_ordered α] : ∀{a₁ a₂:α}, a₁ < a₂ → ∃a, a₁ < a ∧ a < a₂ :=
densely_ordered.dense
lemma le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α} (h : ∀a₃>a₂, a₁ ≤ a₃) :
a₁ ≤ a₂ :=
le_of_not_gt $ assume ha,
let ⟨a, ha₁, ha₂⟩ := dense ha in
lt_irrefl a $ lt_of_lt_of_le ‹a < a₁› (h _ ‹a₂ < a›)
lemma eq_of_le_of_forall_le_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀a₃>a₂, a₁ ≤ a₃) : a₁ = a₂ :=
le_antisymm (le_of_forall_le_of_dense h₂) h₁
lemma le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}(h : ∀a₃<a₁, a₂ ≥ a₃) :
a₁ ≤ a₂ :=
le_of_not_gt $ assume ha,
let ⟨a, ha₁, ha₂⟩ := dense ha in
lt_irrefl a $ lt_of_le_of_lt (h _ ‹a < a₁›) ‹a₂ < a›
lemma eq_of_le_of_forall_ge_of_dense [linear_order α] [densely_ordered α] {a₁ a₂ : α}
(h₁ : a₂ ≤ a₁) (h₂ : ∀a₃<a₁, a₂ ≥ a₃) : a₁ = a₂ :=
le_antisymm (le_of_forall_ge_of_dense h₂) h₁
lemma dense_or_discrete [linear_order α] {a₁ a₂ : α} (h : a₁ < a₂) :
(∃a, a₁ < a ∧ a < a₂) ∨ ((∀a>a₁, a ≥ a₂) ∧ (∀a<a₂, a ≤ a₁)) :=
classical.or_iff_not_imp_left.2 $ assume h,
⟨assume a ha₁, le_of_not_gt $ assume ha₂, h ⟨a, ha₁, ha₂⟩,
assume a ha₂, le_of_not_gt $ assume ha₁, h ⟨a, ha₁, ha₂⟩⟩
lemma trans_trichotomous_left [is_trans α r] [is_trichotomous α r] {a b c : α} :
¬r b a → r b c → r a c :=
begin
intros h₁ h₂, rcases trichotomous_of r a b with h₃|h₃|h₃,
exact trans h₃ h₂, rw h₃, exact h₂, exfalso, exact h₁ h₃
end
lemma trans_trichotomous_right [is_trans α r] [is_trichotomous α r] {a b c : α} :
r a b → ¬r c b → r a c :=
begin
intros h₁ h₂, rcases trichotomous_of r b c with h₃|h₃|h₃,
exact trans h₁ h₃, rw ←h₃, exact h₁, exfalso, exact h₂ h₃
end
section
variables {s : β → β → Prop} {t : γ → γ → Prop}
theorem is_irrefl_of_is_asymm [is_asymm α r] : is_irrefl α r :=
⟨λ a h, asymm h h⟩
/-- Construct a partial order from a `is_strict_order` relation -/
def partial_order_of_SO (r) [is_strict_order α r] : partial_order α :=
{ le := λ x y, x = y ∨ r x y,
lt := r,
le_refl := λ x, or.inl rfl,
le_trans := λ x y z h₁ h₂,
match y, z, h₁, h₂ with
| _, _, or.inl rfl, h₂ := h₂
| _, _, h₁, or.inl rfl := h₁
| _, _, or.inr h₁, or.inr h₂ := or.inr (trans h₁ h₂)
end,
le_antisymm := λ x y h₁ h₂,
match y, h₁, h₂ with
| _, or.inl rfl, h₂ := rfl
| _, h₁, or.inl rfl := rfl
| _, or.inr h₁, or.inr h₂ := (asymm h₁ h₂).elim
end,
lt_iff_le_not_le := λ x y,
⟨λ h, ⟨or.inr h, not_or
(λ e, by rw e at h; exact irrefl _ h)
(asymm h)⟩,
λ ⟨h₁, h₂⟩, h₁.resolve_left (λ e, h₂ $ e ▸ or.inl rfl)⟩ }
/-- This is basically the same as `is_strict_total_order`, but that definition is
in Type (probably by mistake) and also has redundant assumptions. -/
@[algebra] class is_strict_total_order' (α : Type u) (lt : α → α → Prop) extends is_trichotomous α lt, is_strict_order α lt : Prop.
/-- Construct a linear order from a `is_strict_total_order'` relation -/
def linear_order_of_STO' (r) [is_strict_total_order' α r] : linear_order α :=
{ le_total := λ x y,
match y, trichotomous_of r x y with
| y, or.inl h := or.inl (or.inr h)
| _, or.inr (or.inl rfl) := or.inl (or.inl rfl)
| _, or.inr (or.inr h) := or.inr (or.inr h)
end,
..partial_order_of_SO r }
/-- Construct a decidable linear order from a `is_strict_total_order'` relation -/
def decidable_linear_order_of_STO' (r) [is_strict_total_order' α r] [decidable_rel r] : decidable_linear_order α :=
by letI LO := linear_order_of_STO' r; exact
{ decidable_le := λ x y, decidable_of_iff (¬ r y x) (@not_lt _ _ y x),
..LO }
noncomputable def classical.DLO (α) [LO : linear_order α] : decidable_linear_order α :=
{ decidable_le := classical.dec_rel _, ..LO }
theorem is_strict_total_order'.swap (r) [is_strict_total_order' α r] : is_strict_total_order' α (swap r) :=
{..is_trichotomous.swap r, ..is_strict_order.swap r}
instance [linear_order α] : is_strict_total_order' α (<) := {}
/-- A connected order is one satisfying the condition `a < c → a < b ∨ b < c`.
This is recognizable as an intuitionistic substitute for `a ≤ b ∨ b ≤ a` on
the constructive reals, and is also known as negative transitivity,
since the contrapositive asserts transitivity of the relation `¬ a < b`. -/
@[algebra] class is_order_connected (α : Type u) (lt : α → α → Prop) : Prop :=
(conn : ∀ a b c, lt a c → lt a b ∨ lt b c)
theorem is_order_connected.neg_trans {r : α → α → Prop} [is_order_connected α r]
{a b c} (h₁ : ¬ r a b) (h₂ : ¬ r b c) : ¬ r a c :=
mt (is_order_connected.conn a b c) $ by simp [h₁, h₂]
theorem is_strict_weak_order_of_is_order_connected [is_asymm α r]
[is_order_connected α r] : is_strict_weak_order α r :=
{ trans := λ a b c h₁ h₂, (is_order_connected.conn _ c _ h₁).resolve_right (asymm h₂),
incomp_trans := λ a b c ⟨h₁, h₂⟩ ⟨h₃, h₄⟩,
⟨is_order_connected.neg_trans h₁ h₃, is_order_connected.neg_trans h₄ h₂⟩,
..@is_irrefl_of_is_asymm α r _ }
instance is_order_connected_of_is_strict_total_order'
[is_strict_total_order' α r] : is_order_connected α r :=
⟨λ a b c h, (trichotomous _ _).imp_right (λ o,
o.elim (λ e, e ▸ h) (λ h', trans h' h))⟩
instance is_strict_total_order_of_is_strict_total_order'
[is_strict_total_order' α r] : is_strict_total_order α r :=
{..is_strict_weak_order_of_is_order_connected}
instance [linear_order α] : is_strict_total_order α (<) := by apply_instance
instance [linear_order α] : is_order_connected α (<) := by apply_instance
instance [linear_order α] : is_incomp_trans α (<) := by apply_instance
instance [linear_order α] : is_strict_weak_order α (<) := by apply_instance
/-- An extensional relation is one in which an element is determined by its set
of predecessors. It is named for the `x ∈ y` relation in set theory, whose
extensionality is one of the first axioms of ZFC. -/
@[algebra] class is_extensional (α : Type u) (r : α → α → Prop) : Prop :=
(ext : ∀ a b, (∀ x, r x a ↔ r x b) → a = b)
instance is_extensional_of_is_strict_total_order'
[is_strict_total_order' α r] : is_extensional α r :=
⟨λ a b H, ((@trichotomous _ r _ a b)
.resolve_left $ mt (H _).2 (irrefl a))
.resolve_right $ mt (H _).1 (irrefl b)⟩
/-- A well order is a well-founded linear order. -/
@[algebra] class is_well_order (α : Type u) (r : α → α → Prop) extends is_strict_total_order' α r : Prop :=
(wf : well_founded r)
instance is_well_order.is_strict_total_order {α} (r : α → α → Prop) [is_well_order α r] : is_strict_total_order α r := by apply_instance
instance is_well_order.is_extensional {α} (r : α → α → Prop) [is_well_order α r] : is_extensional α r := by apply_instance
instance is_well_order.is_trichotomous {α} (r : α → α → Prop) [is_well_order α r] : is_trichotomous α r := by apply_instance
instance is_well_order.is_trans {α} (r : α → α → Prop) [is_well_order α r] : is_trans α r := by apply_instance
instance is_well_order.is_irrefl {α} (r : α → α → Prop) [is_well_order α r] : is_irrefl α r := by apply_instance
instance is_well_order.is_asymm {α} (r : α → α → Prop) [is_well_order α r] : is_asymm α r := by apply_instance
noncomputable def decidable_linear_order_of_is_well_order (r : α → α → Prop) [is_well_order α r] :
decidable_linear_order α :=
by { haveI := linear_order_of_STO' r, exact classical.DLO α }
instance empty_relation.is_well_order [subsingleton α] : is_well_order α empty_relation :=
{ trichotomous := λ a b, or.inr $ or.inl $ subsingleton.elim _ _,
irrefl := λ a, id,
trans := λ a b c, false.elim,
wf := ⟨λ a, ⟨_, λ y, false.elim⟩⟩ }
instance nat.lt.is_well_order : is_well_order ℕ (<) := ⟨nat.lt_wf⟩
instance sum.lex.is_well_order [is_well_order α r] [is_well_order β s] : is_well_order (α ⊕ β) (sum.lex r s) :=
{ trichotomous := λ a b, by cases a; cases b; simp; apply trichotomous,
irrefl := λ a, by cases a; simp; apply irrefl,
trans := λ a b c, by cases a; cases b; simp; cases c; simp; apply trans,
wf := sum.lex_wf (is_well_order.wf r) (is_well_order.wf s) }
instance prod.lex.is_well_order [is_well_order α r] [is_well_order β s] : is_well_order (α × β) (prod.lex r s) :=
{ trichotomous := λ ⟨a₁, a₂⟩ ⟨b₁, b₂⟩,
match @trichotomous _ r _ a₁ b₁ with
| or.inl h₁ := or.inl $ prod.lex.left _ _ _ h₁
| or.inr (or.inr h₁) := or.inr $ or.inr $ prod.lex.left _ _ _ h₁
| or.inr (or.inl e) := e ▸ match @trichotomous _ s _ a₂ b₂ with
| or.inl h := or.inl $ prod.lex.right _ _ h
| or.inr (or.inr h) := or.inr $ or.inr $ prod.lex.right _ _ h
| or.inr (or.inl e) := e ▸ or.inr $ or.inl rfl
end
end,
irrefl := λ ⟨a₁, a₂⟩ h, by cases h with _ _ _ _ h _ _ _ h;
[exact irrefl _ h, exact irrefl _ h],
trans := λ a b c h₁ h₂, begin
cases h₁ with a₁ a₂ b₁ b₂ ab a₁ b₁ b₂ ab;
cases h₂ with _ _ c₁ c₂ bc _ _ c₂ bc,
{ exact prod.lex.left _ _ _ (trans ab bc) },
{ exact prod.lex.left _ _ _ ab },
{ exact prod.lex.left _ _ _ bc },
{ exact prod.lex.right _ _ (trans ab bc) }
end,
wf := prod.lex_wf (is_well_order.wf r) (is_well_order.wf s) }
/-- An unbounded or cofinal set -/
def unbounded (r : α → α → Prop) (s : set α) : Prop := ∀ a, ∃ b ∈ s, ¬ r b a
/-- A bounded or final set -/
def bounded (r : α → α → Prop) (s : set α) : Prop := ∃a, ∀ b ∈ s, r b a
theorem well_founded.has_min {α} {r : α → α → Prop} (H : well_founded r)
(p : set α) : p ≠ ∅ → ∃ a ∈ p, ∀ x ∈ p, ¬ r x a :=
by haveI := classical.prop_decidable; exact
not_imp_comm.1 (λ he, set.eq_empty_iff_forall_not_mem.2 $ λ a,
acc.rec_on (H.apply a) $ λ a H IH h,
he ⟨_, h, λ y, imp_not_comm.1 (IH y)⟩)
/-- The minimum element of a nonempty set in a well-founded order -/
noncomputable def well_founded.min {α} {r : α → α → Prop} (H : well_founded r)
(p : set α) (h : p ≠ ∅) : α :=
classical.some (H.has_min p h)
theorem well_founded.min_mem {α} {r : α → α → Prop} (H : well_founded r)
(p : set α) (h : p ≠ ∅) : H.min p h ∈ p :=
let ⟨h, _⟩ := classical.some_spec (H.has_min p h) in h
theorem well_founded.not_lt_min {α} {r : α → α → Prop} (H : well_founded r)
(p : set α) (h : p ≠ ∅) {x} (xp : x ∈ p) : ¬ r x (H.min p h) :=
let ⟨_, h'⟩ := classical.some_spec (H.has_min p h) in h' _ xp
variable (r)
local infix `≼` : 50 := r
/-- A family of elements of α is directed (with respect to a relation `≼` on α)
if there is a member of the family `≼`-above any pair in the family. -/
def directed {ι : Sort v} (f : ι → α) := ∀x y, ∃z, f x ≼ f z ∧ f y ≼ f z
/-- A subset of α is directed if there is an element of the set `≼`-above any
pair of elements in the set. -/
def directed_on (s : set α) := ∀ (x ∈ s) (y ∈ s), ∃z ∈ s, x ≼ z ∧ y ≼ z
theorem directed_on_iff_directed {s} : @directed_on α r s ↔ directed r (coe : s → α) :=
by simp [directed, directed_on]; refine ball_congr (λ x hx, by simp; refl)
theorem directed_comp {ι} (f : ι → β) (g : β → α) :
directed r (g ∘ f) ↔ directed (g ⁻¹'o r) f := iff.rfl
theorem directed_mono {s : α → α → Prop} {ι} (f : ι → α)
(H : ∀ a b, r a b → s a b) (h : directed r f) : directed s f :=
λ a b, let ⟨c, h₁, h₂⟩ := h a b in ⟨c, H _ _ h₁, H _ _ h₂⟩
end
|
73aba34e6a6b6171a54528ceaedb438ad490ad2d | bb31430994044506fa42fd667e2d556327e18dfe | /src/algebra/big_operators/basic.lean | 07286aca97d6a3e2677f0509257b0de6971ba5f8 | [
"Apache-2.0"
] | permissive | sgouezel/mathlib | 0cb4e5335a2ba189fa7af96d83a377f83270e503 | 00638177efd1b2534fc5269363ebf42a7871df9a | refs/heads/master | 1,674,527,483,042 | 1,673,665,568,000 | 1,673,665,568,000 | 119,598,202 | 0 | 0 | null | 1,517,348,647,000 | 1,517,348,646,000 | null | UTF-8 | Lean | false | false | 78,709 | 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.multiset.lemmas
import algebra.group.pi
import algebra.group_power.lemmas
import algebra.hom.equiv.basic
import algebra.ring.opposite
import data.finset.sum
import data.fintype.basic
import data.finset.sigma
import data.multiset.powerset
import data.set.pairwise
/-!
# Big operators
In this file we define products and sums indexed by finite sets (specifically, `finset`).
## Notation
We introduce the following notation, localized in `big_operators`.
To enable the notation, use `open_locale big_operators`.
Let `s` be a `finset α`, and `f : α → β` a function.
* `∏ x in s, f x` is notation for `finset.prod s f` (assuming `β` is a `comm_monoid`)
* `∑ x in s, f x` is notation for `finset.sum s f` (assuming `β` is an `add_comm_monoid`)
* `∏ x, f x` is notation for `finset.prod finset.univ f`
(assuming `α` is a `fintype` and `β` is a `comm_monoid`)
* `∑ x, f x` is notation for `finset.sum finset.univ f`
(assuming `α` is a `fintype` and `β` is an `add_comm_monoid`)
## Implementation Notes
The first arguments in all definitions and lemmas is the codomain of the function of the big
operator. This is necessary for the heuristic in `@[to_additive]`.
See the documentation of `to_additive.attr` for more information.
-/
universes u v w
variables {ι : Type*} {β : Type u} {α : Type v} {γ : Type w}
open fin
namespace finset
/--
`∏ x in s, f x` is the product of `f x`
as `x` ranges over the elements of the finite set `s`.
-/
@[to_additive "`∑ x in s, f x` is the sum of `f x` as `x` ranges over the elements
of the finite set `s`."]
protected def prod [comm_monoid β] (s : finset α) (f : α → β) : β := (s.1.map f).prod
@[simp, to_additive] lemma prod_mk [comm_monoid β] (s : multiset α) (hs : s.nodup) (f : α → β) :
(⟨s, hs⟩ : finset α).prod f = (s.map f).prod :=
rfl
@[simp, to_additive] lemma prod_val [comm_monoid α] (s : finset α) : s.1.prod = s.prod id :=
by rw [finset.prod, multiset.map_id]
end finset
/--
There is no established mathematical convention
for the operator precedence of big operators like `∏` and `∑`.
We will have to make a choice.
Online discussions, such as https://math.stackexchange.com/q/185538/30839
seem to suggest that `∏` and `∑` should have the same precedence,
and that this should be somewhere between `*` and `+`.
The latter have precedence levels `70` and `65` respectively,
and we therefore choose the level `67`.
In practice, this means that parentheses should be placed as follows:
```lean
∑ k in K, (a k + b k) = ∑ k in K, a k + ∑ k in K, b k →
∏ k in K, a k * b k = (∏ k in K, a k) * (∏ k in K, b k)
```
(Example taken from page 490 of Knuth's *Concrete Mathematics*.)
-/
library_note "operator precedence of big operators"
localized "notation (name := finset.sum_univ)
`∑` binders `, ` r:(scoped:67 f, finset.sum finset.univ f) := r" in big_operators
localized "notation (name := finset.prod_univ)
`∏` binders `, ` r:(scoped:67 f, finset.prod finset.univ f) := r" in big_operators
localized "notation (name := finset.sum)
`∑` binders ` in ` s `, ` r:(scoped:67 f, finset.sum s f) := r" in big_operators
localized "notation (name := finset.prod)
`∏` binders ` in ` s `, ` r:(scoped:67 f, finset.prod s f) := r" in big_operators
open_locale big_operators
namespace finset
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
@[to_additive] lemma prod_eq_multiset_prod [comm_monoid β] (s : finset α) (f : α → β) :
∏ x in s, f x = (s.1.map f).prod := rfl
@[to_additive]
theorem prod_eq_fold [comm_monoid β] (s : finset α) (f : α → β) :
∏ x in s, f x = s.fold (*) 1 f :=
rfl
@[simp] lemma sum_multiset_singleton (s : finset α) :
s.sum (λ x, {x}) = s.val :=
by simp only [sum_eq_multiset_sum, multiset.sum_map_singleton]
end finset
@[to_additive]
lemma map_prod [comm_monoid β] [comm_monoid γ] {G : Type*} [monoid_hom_class G β γ] (g : G)
(f : α → β) (s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
by simp only [finset.prod_eq_multiset_prod, map_multiset_prod, multiset.map_map]
section deprecated
/-- Deprecated: use `_root_.map_prod` instead. -/
@[to_additive "Deprecated: use `_root_.map_sum` instead."]
protected lemma monoid_hom.map_prod [comm_monoid β] [comm_monoid γ] (g : β →* γ) (f : α → β)
(s : finset α) : g (∏ x in s, f x) = ∏ x in s, g (f x) :=
map_prod g f s
/-- Deprecated: use `_root_.map_prod` instead. -/
@[to_additive "Deprecated: use `_root_.map_sum` instead."]
protected lemma mul_equiv.map_prod [comm_monoid β] [comm_monoid γ] (g : β ≃* γ) (f : α → β)
(s : finset α) : g (∏ x in s, f x) = ∏ x in s, g (f x) :=
map_prod g f s
/-- Deprecated: use `_root_.map_list_prod` instead. -/
protected lemma ring_hom.map_list_prod [semiring β] [semiring γ] (f : β →+* γ) (l : list β) :
f l.prod = (l.map f).prod :=
map_list_prod f l
/-- Deprecated: use `_root_.map_list_sum` instead. -/
protected lemma ring_hom.map_list_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(f : β →+* γ) (l : list β) :
f l.sum = (l.map f).sum :=
map_list_sum f l
/-- A morphism into the opposite ring acts on the product by acting on the reversed elements.
Deprecated: use `_root_.unop_map_list_prod` instead.
-/
protected lemma ring_hom.unop_map_list_prod [semiring β] [semiring γ] (f : β →+* γᵐᵒᵖ)
(l : list β) : mul_opposite.unop (f l.prod) = (l.map (mul_opposite.unop ∘ f)).reverse.prod :=
unop_map_list_prod f l
/-- Deprecated: use `_root_.map_multiset_prod` instead. -/
protected lemma ring_hom.map_multiset_prod [comm_semiring β] [comm_semiring γ] (f : β →+* γ)
(s : multiset β) :
f s.prod = (s.map f).prod :=
map_multiset_prod f s
/-- Deprecated: use `_root_.map_multiset_sum` instead. -/
protected lemma ring_hom.map_multiset_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(f : β →+* γ) (s : multiset β) :
f s.sum = (s.map f).sum :=
map_multiset_sum f s
/-- Deprecated: use `_root_.map_prod` instead. -/
protected lemma ring_hom.map_prod [comm_semiring β] [comm_semiring γ] (g : β →+* γ) (f : α → β)
(s : finset α) :
g (∏ x in s, f x) = ∏ x in s, g (f x) :=
map_prod g f s
/-- Deprecated: use `_root_.map_sum` instead. -/
protected lemma ring_hom.map_sum [non_assoc_semiring β] [non_assoc_semiring γ]
(g : β →+* γ) (f : α → β) (s : finset α) :
g (∑ x in s, f x) = ∑ x in s, g (f x) :=
map_sum g f s
end deprecated
@[to_additive]
lemma monoid_hom.coe_finset_prod [mul_one_class β] [comm_monoid γ] (f : α → β →* γ) (s : finset α) :
⇑(∏ x in s, f x) = ∏ x in s, f x :=
(monoid_hom.coe_fn β γ).map_prod _ _
-- See also `finset.prod_apply`, with the same conclusion
-- but with the weaker hypothesis `f : α → β → γ`.
@[simp, to_additive]
lemma monoid_hom.finset_prod_apply [mul_one_class β] [comm_monoid γ] (f : α → β →* γ)
(s : finset α) (b : β) : (∏ x in s, f x) b = ∏ x in s, f x b :=
(monoid_hom.eval b).map_prod _ _
variables {s s₁ s₂ : finset α} {a : α} {f g : α → β}
namespace finset
section comm_monoid
variables [comm_monoid β]
@[simp, to_additive] lemma prod_empty : ∏ x in ∅, f x = 1 := rfl
@[to_additive] lemma prod_of_empty [is_empty α] (s : finset α) : ∏ i in s, f i = 1 :=
by rw [eq_empty_of_is_empty s, prod_empty]
@[simp, to_additive]
lemma prod_cons (h : a ∉ s) : (∏ x in (cons a s h), f x) = f a * ∏ x in s, f x :=
fold_cons h
@[simp, to_additive]
lemma prod_insert [decidable_eq α] : a ∉ s → (∏ x in (insert a s), f x) = f a * ∏ x in s, f x :=
fold_insert
/--
The product of `f` over `insert a s` is the same as
the product over `s`, as long as `a` is in `s` or `f a = 1`.
-/
@[simp, to_additive "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `a` is in `s` or `f a = 0`."]
lemma prod_insert_of_eq_one_if_not_mem [decidable_eq α] (h : a ∉ s → f a = 1) :
∏ x in insert a s, f x = ∏ x in s, f x :=
begin
by_cases hm : a ∈ s,
{ simp_rw insert_eq_of_mem hm },
{ rw [prod_insert hm, h hm, one_mul] },
end
/--
The product of `f` over `insert a s` is the same as the product over `s`, as long as `f a = 1`.
-/
@[simp, to_additive "The sum of `f` over `insert a s` is the same as
the sum over `s`, as long as `f a = 0`."]
lemma prod_insert_one [decidable_eq α] (h : f a = 1) :
∏ x in insert a s, f x = ∏ x in s, f x :=
prod_insert_of_eq_one_if_not_mem (λ _, h)
@[simp, to_additive]
lemma prod_singleton : (∏ x in (singleton a), f x) = f a :=
eq.trans fold_singleton $ mul_one _
@[to_additive]
lemma prod_pair [decidable_eq α] {a b : α} (h : a ≠ b) :
(∏ x in ({a, b} : finset α), f x) = f a * f b :=
by rw [prod_insert (not_mem_singleton.2 h), prod_singleton]
@[simp, priority 1100, to_additive]
lemma prod_const_one : (∏ x in s, (1 : β)) = 1 :=
by simp only [finset.prod, multiset.map_const, multiset.prod_repeat, one_pow]
@[simp, to_additive]
lemma prod_image [decidable_eq α] {s : finset γ} {g : γ → α} :
(∀ x ∈ s, ∀ y ∈ s, g x = g y → x = y) → (∏ x in (s.image g), f x) = ∏ x in s, f (g x) :=
fold_image
@[simp, to_additive]
lemma prod_map (s : finset α) (e : α ↪ γ) (f : γ → β) :
(∏ x in (s.map e), f x) = ∏ x in s, f (e x) :=
by rw [finset.prod, finset.map_val, multiset.map_map]; refl
@[congr, to_additive]
lemma prod_congr (h : s₁ = s₂) : (∀ x ∈ s₂, f x = g x) → s₁.prod f = s₂.prod g :=
by rw [h]; exact fold_congr
attribute [congr] finset.sum_congr
@[to_additive]
lemma prod_disj_union (h) : ∏ x in s₁.disj_union s₂ h, f x = (∏ x in s₁, f x) * ∏ x in s₂, f x :=
by { refine eq.trans _ (fold_disj_union h), rw one_mul, refl }
@[to_additive]
lemma prod_disj_Union (s : finset ι) (t : ι → finset α) (h) :
∏ x in s.disj_Union t h, f x = ∏ i in s, ∏ x in t i, f x :=
begin
refine eq.trans _ (fold_disj_Union h),
dsimp [finset.prod, multiset.prod, multiset.fold, finset.disj_Union, finset.fold],
congr',
exact prod_const_one.symm,
end
@[to_additive]
lemma prod_union_inter [decidable_eq α] :
(∏ x in (s₁ ∪ s₂), f x) * (∏ x in (s₁ ∩ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
fold_union_inter
@[to_additive]
lemma prod_union [decidable_eq α] (h : disjoint s₁ s₂) :
(∏ x in (s₁ ∪ s₂), f x) = (∏ x in s₁, f x) * (∏ x in s₂, f x) :=
by rw [←prod_union_inter, (disjoint_iff_inter_eq_empty.mp h)]; exact (mul_one _).symm
@[to_additive]
lemma prod_filter_mul_prod_filter_not (s : finset α) (p : α → Prop) [decidable_pred p]
[decidable_pred (λ x, ¬p x)] (f : α → β) :
(∏ x in s.filter p, f x) * (∏ x in s.filter (λ x, ¬p x), f x) = ∏ x in s, f x :=
begin
haveI := classical.dec_eq α,
rw [← prod_union (disjoint_filter_filter_neg _ _ p), filter_union_filter_neg_eq]
end
section to_list
@[simp, to_additive]
lemma prod_to_list (s : finset α) (f : α → β) : (s.to_list.map f).prod = s.prod f :=
by rw [finset.prod, ← multiset.coe_prod, ← multiset.coe_map, finset.coe_to_list]
end to_list
@[to_additive]
lemma _root_.equiv.perm.prod_comp (σ : equiv.perm α) (s : finset α) (f : α → β)
(hs : {a | σ a ≠ a} ⊆ s) :
(∏ x in s, f (σ x)) = ∏ x in s, f x :=
by { convert (prod_map _ σ.to_embedding _).symm, exact (map_perm hs).symm }
@[to_additive]
lemma _root_.equiv.perm.prod_comp' (σ : equiv.perm α) (s : finset α) (f : α → α → β)
(hs : {a | σ a ≠ a} ⊆ s) :
(∏ x in s, f (σ x) x) = ∏ x in s, f x (σ.symm x) :=
by { convert σ.prod_comp s (λ x, f x (σ.symm x)) hs, ext, rw equiv.symm_apply_apply }
end comm_monoid
end finset
section
open finset
variables [fintype α] [comm_monoid β]
@[to_additive]
lemma is_compl.prod_mul_prod {s t : finset α} (h : is_compl s t) (f : α → β) :
(∏ i in s, f i) * (∏ i in t, f i) = ∏ i, f i :=
(finset.prod_disj_union h.disjoint).symm.trans $
by { classical, rw [finset.disj_union_eq_union, ← finset.sup_eq_union, h.sup_eq_top]; refl }
end
namespace finset
section comm_monoid
variables [comm_monoid β]
/-- Multiplying the products of a function over `s` and over `sᶜ` gives the whole product.
For a version expressed with subtypes, see `fintype.prod_subtype_mul_prod_subtype`. -/
@[to_additive "Adding the sums of a function over `s` and over `sᶜ` gives the whole sum.
For a version expressed with subtypes, see `fintype.sum_subtype_add_sum_subtype`. "]
lemma prod_mul_prod_compl [fintype α] [decidable_eq α] (s : finset α) (f : α → β) :
(∏ i in s, f i) * (∏ i in sᶜ, f i) = ∏ i, f i :=
is_compl.prod_mul_prod is_compl_compl f
@[to_additive]
lemma prod_compl_mul_prod [fintype α] [decidable_eq α] (s : finset α) (f : α → β) :
(∏ i in sᶜ, f i) * (∏ i in s, f i) = ∏ i, f i :=
(@is_compl_compl _ s _).symm.prod_mul_prod f
@[to_additive]
lemma prod_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) :
(∏ x in (s₂ \ s₁), f x) * (∏ x in s₁, f x) = (∏ x in s₂, f x) :=
by rw [←prod_union sdiff_disjoint, sdiff_union_of_subset h]
@[simp, to_additive]
lemma prod_disj_sum (s : finset α) (t : finset γ) (f : α ⊕ γ → β) :
∏ x in s.disj_sum t, f x = (∏ x in s, f (sum.inl x)) * (∏ x in t, f (sum.inr x)) :=
begin
rw [←map_inl_disj_union_map_inr, prod_disj_union, prod_map, prod_map],
refl,
end
@[to_additive]
lemma prod_sum_elim (s : finset α) (t : finset γ) (f : α → β) (g : γ → β) :
∏ x in s.disj_sum t, sum.elim f g x = (∏ x in s, f x) * (∏ x in t, g x) :=
by simp
@[to_additive]
lemma prod_bUnion [decidable_eq α] {s : finset γ} {t : γ → finset α}
(hs : set.pairwise_disjoint ↑s t) :
(∏ x in s.bUnion t, f x) = ∏ x in s, ∏ i in t x, f i :=
by rw [←disj_Union_eq_bUnion _ _ hs, prod_disj_Union]
/-- Product over a sigma type equals the product of fiberwise products. For rewriting
in the reverse direction, use `finset.prod_sigma'`. -/
@[to_additive "Sum over a sigma type equals the sum of fiberwise sums. For rewriting
in the reverse direction, use `finset.sum_sigma'`"]
lemma prod_sigma {σ : α → Type*}
(s : finset α) (t : Π a, finset (σ a)) (f : sigma σ → β) :
(∏ x in s.sigma t, f x) = ∏ a in s, ∏ s in (t a), f ⟨a, s⟩ :=
by simp_rw [←disj_Union_map_sigma_mk, prod_disj_Union, prod_map, function.embedding.sigma_mk_apply]
@[to_additive]
lemma prod_sigma' {σ : α → Type*}
(s : finset α) (t : Π a, finset (σ a)) (f : Π a, σ a → β) :
(∏ a in s, ∏ s in (t a), f a s) = ∏ x in s.sigma t, f x.1 x.2 :=
eq.symm $ prod_sigma s t (λ x, f x.1 x.2)
/--
Reorder a product.
The difference with `prod_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
-/
@[to_additive "
Reorder a sum.
The difference with `sum_bij'` is that the bijection is specified as a surjective injection,
rather than by an inverse function.
"]
lemma prod_bij {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, γ) (hi : ∀ a ha, i a ha ∈ t) (h : ∀ a ha, f a = g (i a ha))
(i_inj : ∀ a₁ a₂ ha₁ ha₂, i a₁ ha₁ = i a₂ ha₂ → a₁ = a₂) (i_surj : ∀ b ∈ t, ∃ a ha, b = i a ha) :
(∏ x in s, f x) = (∏ x in t, g x) :=
congr_arg multiset.prod
(multiset.map_eq_map_of_bij_of_nodup f g s.2 t.2 i hi h i_inj i_surj)
/--
Reorder a product.
The difference with `prod_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
-/
@[to_additive "
Reorder a sum.
The difference with `sum_bij` is that the bijection is specified with an inverse, rather than
as a surjective injection.
"]
lemma prod_bij' {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, γ) (hi : ∀ a ha, i a ha ∈ t) (h : ∀ a ha, f a = g (i a ha))
(j : Π a ∈ t, α) (hj : ∀ a ha, j a ha ∈ s) (left_inv : ∀ a ha, j (i a ha) (hi a ha) = a)
(right_inv : ∀ a ha, i (j a ha) (hj a ha) = a) :
(∏ x in s, f x) = (∏ x in t, g x) :=
begin
refine prod_bij i hi h _ _,
{intros a1 a2 h1 h2 eq, rw [←left_inv a1 h1, ←left_inv a2 h2], cc,},
{intros b hb, use j b hb, use hj b hb, exact (right_inv b hb).symm,},
end
/-- Reindexing a product over a finset along an equivalence.
See `equiv.prod_comp` for the version where `s` and `s'` are `univ`. -/
@[to_additive /-" Reindexing a sum over a finset along an equivalence.
See `equiv.sum_comp` for the version where `s` and `s'` are `univ`. "-/]
lemma equiv.prod_comp_finset {ι'} [decidable_eq ι] (e : ι ≃ ι') (f : ι' → β) {s' : finset ι'}
{s : finset ι}
(h : s = s'.image e.symm) :
∏ i' in s', f i' = ∏ i in s, f (e i) :=
begin
rw [h],
refine finset.prod_bij' (λ i' hi', e.symm i') (λ a ha, finset.mem_image_of_mem _ ha)
(λ a ha, by simp_rw [e.apply_symm_apply]) (λ i hi, e i) (λ a ha, _)
(λ a ha, e.apply_symm_apply a) (λ a ha, e.symm_apply_apply a),
rcases finset.mem_image.mp ha with ⟨i', hi', rfl⟩,
rwa [e.apply_symm_apply]
end
@[to_additive] lemma prod_finset_product
(r : finset (γ × α)) (s : finset γ) (t : γ → finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ × α → β} :
∏ p in r, f p = ∏ c in s, ∏ a in t c, f (c, a) :=
begin
refine eq.trans _ (prod_sigma s t (λ p, f (p.1, p.2))),
exact prod_bij' (λ p hp, ⟨p.1, p.2⟩) (λ p, mem_sigma.mpr ∘ (h p).mp)
(λ p hp, congr_arg f prod.mk.eta.symm) (λ p hp, (p.1, p.2))
(λ p, (h (p.1, p.2)).mpr ∘ mem_sigma.mp) (λ p hp, prod.mk.eta) (λ p hp, p.eta),
end
@[to_additive] lemma prod_finset_product'
(r : finset (γ × α)) (s : finset γ) (t : γ → finset α)
(h : ∀ p : γ × α, p ∈ r ↔ p.1 ∈ s ∧ p.2 ∈ t p.1) {f : γ → α → β} :
∏ p in r, f p.1 p.2 = ∏ c in s, ∏ a in t c, f c a :=
prod_finset_product r s t h
@[to_additive] lemma prod_finset_product_right
(r : finset (α × γ)) (s : finset γ) (t : γ → finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α × γ → β} :
∏ p in r, f p = ∏ c in s, ∏ a in t c, f (a, c) :=
begin
refine eq.trans _ (prod_sigma s t (λ p, f (p.2, p.1))),
exact prod_bij' (λ p hp, ⟨p.2, p.1⟩) (λ p, mem_sigma.mpr ∘ (h p).mp)
(λ p hp, congr_arg f prod.mk.eta.symm) (λ p hp, (p.2, p.1))
(λ p, (h (p.2, p.1)).mpr ∘ mem_sigma.mp) (λ p hp, prod.mk.eta) (λ p hp, p.eta),
end
@[to_additive] lemma prod_finset_product_right'
(r : finset (α × γ)) (s : finset γ) (t : γ → finset α)
(h : ∀ p : α × γ, p ∈ r ↔ p.2 ∈ s ∧ p.1 ∈ t p.2) {f : α → γ → β} :
∏ p in r, f p.1 p.2 = ∏ c in s, ∏ a in t c, f a c :=
prod_finset_product_right r s t h
@[to_additive]
lemma prod_fiberwise_of_maps_to [decidable_eq γ] {s : finset α} {t : finset γ} {g : α → γ}
(h : ∀ x ∈ s, g x ∈ t) (f : α → β) :
(∏ y in t, ∏ x in s.filter (λ x, g x = y), f x) = ∏ x in s, f x :=
begin
rw [← disj_Union_filter_eq_of_maps_to h] {occs := occurrences.pos [2]},
rw prod_disj_Union,
end
@[to_additive]
lemma prod_image' [decidable_eq α] {s : finset γ} {g : γ → α} (h : γ → β)
(eq : ∀ c ∈ s, f (g c) = ∏ x in s.filter (λ c', g c' = g c), h x) :
(∏ x in s.image g, f x) = ∏ x in s, h x :=
calc (∏ x in s.image g, f x) = ∏ x in s.image g, ∏ x in s.filter (λ c', g c' = x), h x :
prod_congr rfl $ λ x hx, let ⟨c, hcs, hc⟩ := mem_image.1 hx in hc ▸ (eq c hcs)
... = ∏ x in s, h x : prod_fiberwise_of_maps_to (λ x, mem_image_of_mem g) _
@[to_additive]
lemma prod_mul_distrib : ∏ x in s, (f x * g x) = (∏ x in s, f x) * (∏ x in s, g x) :=
eq.trans (by rw one_mul; refl) fold_op_distrib
@[to_additive]
lemma prod_product {s : finset γ} {t : finset α} {f : γ×α → β} :
(∏ x in s ×ˢ t, f x) = ∏ x in s, ∏ y in t, f (x, y) :=
prod_finset_product (s ×ˢ t) s (λ a, t) (λ p, mem_product)
/-- An uncurried version of `finset.prod_product`. -/
@[to_additive "An uncurried version of `finset.sum_product`"]
lemma prod_product' {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s ×ˢ t, f x.1 x.2) = ∏ x in s, ∏ y in t, f x y :=
prod_product
@[to_additive]
lemma prod_product_right {s : finset γ} {t : finset α} {f : γ×α → β} :
(∏ x in s ×ˢ t, f x) = ∏ y in t, ∏ x in s, f (x, y) :=
prod_finset_product_right (s ×ˢ t) t (λ a, s) (λ p, mem_product.trans and.comm)
/-- An uncurried version of `finset.prod_product_right`. -/
@[to_additive "An uncurried version of `finset.prod_product_right`"]
lemma prod_product_right' {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s ×ˢ t, f x.1 x.2) = ∏ y in t, ∏ x in s, f x y :=
prod_product_right
/-- Generalization of `finset.prod_comm` to the case when the inner `finset`s depend on the outer
variable. -/
@[to_additive "Generalization of `finset.sum_comm` to the case when the inner `finset`s depend on
the outer variable."]
lemma prod_comm' {s : finset γ} {t : γ → finset α} {t' : finset α} {s' : α → finset γ}
(h : ∀ x y, x ∈ s ∧ y ∈ t x ↔ x ∈ s' y ∧ y ∈ t') {f : γ → α → β} :
(∏ x in s, ∏ y in t x, f x y) = (∏ y in t', ∏ x in s' y, f x y) :=
begin
classical,
have : ∀ z : γ × α,
z ∈ s.bUnion (λ x, (t x).map $ function.embedding.sectr x _) ↔ z.1 ∈ s ∧ z.2 ∈ t z.1,
{ rintro ⟨x, y⟩, simp },
exact (prod_finset_product' _ _ _ this).symm.trans
(prod_finset_product_right' _ _ _ $ λ ⟨x, y⟩, (this _).trans ((h x y).trans and.comm))
end
@[to_additive]
lemma prod_comm {s : finset γ} {t : finset α} {f : γ → α → β} :
(∏ x in s, ∏ y in t, f x y) = (∏ y in t, ∏ x in s, f x y) :=
prod_comm' $ λ _ _, iff.rfl
@[to_additive]
lemma prod_hom_rel [comm_monoid γ] {r : β → γ → Prop} {f : α → β} {g : α → γ} {s : finset α}
(h₁ : r 1 1) (h₂ : ∀ a b c, r b c → r (f a * b) (g a * c)) : r (∏ x in s, f x) (∏ x in s, g x) :=
by { delta finset.prod, apply multiset.prod_hom_rel; assumption }
@[to_additive]
lemma prod_eq_one {f : α → β} {s : finset α} (h : ∀ x ∈ s, f x = 1) : (∏ x in s, f x) = 1 :=
calc (∏ x in s, f x) = ∏ x in s, 1 : finset.prod_congr rfl h
... = 1 : finset.prod_const_one
@[to_additive]
lemma prod_subset_one_on_sdiff [decidable_eq α] (h : s₁ ⊆ s₂) (hg : ∀ x ∈ (s₂ \ s₁), g x = 1)
(hfg : ∀ x ∈ s₁, f x = g x) : ∏ i in s₁, f i = ∏ i in s₂, g i :=
begin
rw [← prod_sdiff h, prod_eq_one hg, one_mul],
exact prod_congr rfl hfg
end
@[to_additive]
lemma prod_subset (h : s₁ ⊆ s₂) (hf : ∀ x ∈ s₂, x ∉ s₁ → f x = 1) :
(∏ x in s₁, f x) = ∏ x in s₂, f x :=
by haveI := classical.dec_eq α; exact prod_subset_one_on_sdiff h (by simpa) (λ _ _, rfl)
@[to_additive]
lemma prod_filter_of_ne {p : α → Prop} [decidable_pred p] (hp : ∀ x ∈ s, f x ≠ 1 → p x) :
(∏ x in (s.filter p), f x) = (∏ x in s, f x) :=
prod_subset (filter_subset _ _) $ λ x,
by { classical, rw [not_imp_comm, mem_filter], exact λ h₁ h₂, ⟨h₁, hp _ h₁ h₂⟩ }
-- If we use `[decidable_eq β]` here, some rewrites fail because they find a wrong `decidable`
-- instance first; `{∀ x, decidable (f x ≠ 1)}` doesn't work with `rw ← prod_filter_ne_one`
@[to_additive]
lemma prod_filter_ne_one [∀ x, decidable (f x ≠ 1)] :
(∏ x in (s.filter $ λ x, f x ≠ 1), f x) = (∏ x in s, f x) :=
prod_filter_of_ne $ λ _ _, id
@[to_additive]
lemma prod_filter (p : α → Prop) [decidable_pred p] (f : α → β) :
(∏ a in s.filter p, f a) = (∏ a in s, if p a then f a else 1) :=
calc (∏ a in s.filter p, f a) = ∏ a in s.filter p, if p a then f a else 1 :
prod_congr rfl (assume a h, by rw [if_pos (mem_filter.1 h).2])
... = ∏ a in s, if p a then f a else 1 :
begin
refine prod_subset (filter_subset _ s) (assume x hs h, _),
rw [mem_filter, not_and] at h,
exact if_neg (h hs)
end
@[to_additive]
lemma prod_eq_single_of_mem {s : finset α} {f : α → β} (a : α) (h : a ∈ s)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) : (∏ x in s, f x) = f a :=
begin
haveI := classical.dec_eq α,
calc (∏ x in s, f x) = ∏ x in {a}, f x :
begin
refine (prod_subset _ _).symm,
{ intros _ H, rwa mem_singleton.1 H },
{ simpa only [mem_singleton] }
end
... = f a : prod_singleton
end
@[to_additive]
lemma prod_eq_single {s : finset α} {f : α → β} (a : α)
(h₀ : ∀ b ∈ s, b ≠ a → f b = 1) (h₁ : a ∉ s → f a = 1) : (∏ x in s, f x) = f a :=
by haveI := classical.dec_eq α;
from classical.by_cases
(assume : a ∈ s, prod_eq_single_of_mem a this h₀)
(assume : a ∉ s,
(prod_congr rfl $ λ b hb, h₀ b hb $ by rintro rfl; cc).trans $
prod_const_one.trans (h₁ this).symm)
@[to_additive]
lemma prod_eq_mul_of_mem {s : finset α} {f : α → β} (a b : α) (ha : a ∈ s) (hb : b ∈ s) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) : (∏ x in s, f x) = (f a) * (f b) :=
begin
haveI := classical.dec_eq α;
let s' := ({a, b} : finset α),
have hu : s' ⊆ s,
{ refine insert_subset.mpr _, apply and.intro ha, apply singleton_subset_iff.mpr hb },
have hf : ∀ c ∈ s, c ∉ s' → f c = 1,
{ intros c hc hcs,
apply h₀ c hc,
apply not_or_distrib.mp,
intro hab,
apply hcs,
apply mem_insert.mpr,
rw mem_singleton,
exact hab },
rw ←prod_subset hu hf,
exact finset.prod_pair hn
end
@[to_additive]
lemma prod_eq_mul {s : finset α} {f : α → β} (a b : α) (hn : a ≠ b)
(h₀ : ∀ c ∈ s, c ≠ a ∧ c ≠ b → f c = 1) (ha : a ∉ s → f a = 1) (hb : b ∉ s → f b = 1) :
(∏ x in s, f x) = (f a) * (f b) :=
begin
haveI := classical.dec_eq α;
by_cases h₁ : a ∈ s; by_cases h₂ : b ∈ s,
{ exact prod_eq_mul_of_mem a b h₁ h₂ hn h₀ },
{ rw [hb h₂, mul_one],
apply prod_eq_single_of_mem a h₁,
exact λ c hc hca, h₀ c hc ⟨hca, ne_of_mem_of_not_mem hc h₂⟩ },
{ rw [ha h₁, one_mul],
apply prod_eq_single_of_mem b h₂,
exact λ c hc hcb, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, hcb⟩ },
{ rw [ha h₁, hb h₂, mul_one],
exact trans
(prod_congr rfl (λ c hc, h₀ c hc ⟨ne_of_mem_of_not_mem hc h₁, ne_of_mem_of_not_mem hc h₂⟩))
prod_const_one }
end
@[to_additive]
lemma prod_attach {f : α → β} : (∏ x in s.attach, f x) = (∏ x in s, f x) :=
by haveI := classical.dec_eq α; exact
calc (∏ x in s.attach, f x.val) = (∏ x in (s.attach).image subtype.val, f x) :
by rw [prod_image]; exact assume x _ y _, subtype.eq
... = _ : by rw [attach_image_val]
/-- A product over `s.subtype p` equals one over `s.filter p`. -/
@[simp, to_additive "A sum over `s.subtype p` equals one over `s.filter p`."]
lemma prod_subtype_eq_prod_filter (f : α → β) {p : α → Prop} [decidable_pred p] :
∏ x in s.subtype p, f x = ∏ x in s.filter p, f x :=
begin
conv_lhs { erw ←prod_map (s.subtype p) (function.embedding.subtype _) f },
exact prod_congr (subtype_map _) (λ x hx, rfl)
end
/-- If all elements of a `finset` satisfy the predicate `p`, a product
over `s.subtype p` equals that product over `s`. -/
@[to_additive "If all elements of a `finset` satisfy the predicate `p`, a sum
over `s.subtype p` equals that sum over `s`."]
lemma prod_subtype_of_mem (f : α → β) {p : α → Prop} [decidable_pred p]
(h : ∀ x ∈ s, p x) : ∏ x in s.subtype p, f x = ∏ x in s, f x :=
by simp_rw [prod_subtype_eq_prod_filter, filter_true_of_mem h]
/-- A product of a function over a `finset` in a subtype equals a
product in the main type of a function that agrees with the first
function on that `finset`. -/
@[to_additive "A sum of a function over a `finset` in a subtype equals a
sum in the main type of a function that agrees with the first
function on that `finset`."]
lemma prod_subtype_map_embedding {p : α → Prop} {s : finset {x // p x}} {f : {x // p x} → β}
{g : α → β} (h : ∀ x : {x // p x}, x ∈ s → g x = f x) :
∏ x in s.map (function.embedding.subtype _), g x = ∏ x in s, f x :=
begin
rw finset.prod_map,
exact finset.prod_congr rfl h
end
variables (f s)
@[to_additive]
lemma prod_coe_sort_eq_attach (f : s → β) :
∏ (i : s), f i = ∏ i in s.attach, f i :=
rfl
@[to_additive]
lemma prod_coe_sort :
∏ (i : s), f i = ∏ i in s, f i :=
prod_attach
@[to_additive]
lemma prod_finset_coe (f : α → β) (s : finset α) :
∏ (i : (s : set α)), f i = ∏ i in s, f i :=
prod_coe_sort s f
variables {f s}
@[to_additive]
lemma prod_subtype {p : α → Prop} {F : fintype (subtype p)} (s : finset α)
(h : ∀ x, x ∈ s ↔ p x) (f : α → β) :
∏ a in s, f a = ∏ a : subtype p, f a :=
have (∈ s) = p, from set.ext h, by { substI p, rw ← prod_coe_sort, congr }
/-- The product of a function `g` defined only on a set `s` is equal to
the product of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 1` off `s`. -/
@[to_additive "The sum of a function `g` defined only on a set `s` is equal to
the sum of a function `f` defined everywhere,
as long as `f` and `g` agree on `s`, and `f = 0` off `s`."]
lemma prod_congr_set
{α : Type*} [comm_monoid α] {β : Type*} [fintype β]
(s : set β) [decidable_pred (∈s)] (f : β → α) (g : s → α)
(w : ∀ (x : β) (h : x ∈ s), f x = g ⟨x, h⟩) (w' : ∀ (x : β), x ∉ s → f x = 1) :
finset.univ.prod f = finset.univ.prod g :=
begin
rw ←@finset.prod_subset _ _ s.to_finset finset.univ f _ (by simp),
{ rw finset.prod_subtype,
{ apply finset.prod_congr rfl,
exact λ ⟨x, h⟩ _, w x h, },
{ simp, }, },
{ rintro x _ h, exact w' x (by simpa using h), },
end
@[to_additive] lemma prod_apply_dite {s : finset α} {p : α → Prop} {hp : decidable_pred p}
[decidable_pred (λ x, ¬ p x)] (f : Π (x : α), p x → γ) (g : Π (x : α), ¬p x → γ)
(h : γ → β) :
(∏ x in s, h (if hx : p x then f x hx else g x hx)) =
(∏ x in (s.filter p).attach, h (f x.1 (mem_filter.mp x.2).2)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (g x.1 (mem_filter.mp x.2).2)) :=
calc ∏ x in s, h (if hx : p x then f x hx else g x hx)
= (∏ x in s.filter p, h (if hx : p x then f x hx else g x hx)) *
(∏ x in s.filter (λ x, ¬ p x), h (if hx : p x then f x hx else g x hx)) :
(prod_filter_mul_prod_filter_not s p _).symm
... = (∏ x in (s.filter p).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (if hx : p x.1 then f x.1 hx else g x.1 hx)) :
congr_arg2 _ prod_attach.symm prod_attach.symm
... = (∏ x in (s.filter p).attach, h (f x.1 (mem_filter.mp x.2).2)) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, h (g x.1 (mem_filter.mp x.2).2)) :
congr_arg2 _
(prod_congr rfl (λ x hx, congr_arg h (dif_pos (mem_filter.mp x.2).2)))
(prod_congr rfl (λ x hx, congr_arg h (dif_neg (mem_filter.mp x.2).2)))
@[to_additive] lemma prod_apply_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → γ) (h : γ → β) :
(∏ x in s, h (if p x then f x else g x)) =
(∏ x in s.filter p, h (f x)) * (∏ x in s.filter (λ x, ¬ p x), h (g x)) :=
trans (prod_apply_dite _ _ _)
(congr_arg2 _ (@prod_attach _ _ _ _ (h ∘ f)) (@prod_attach _ _ _ _ (h ∘ g)))
@[to_additive] lemma prod_dite {s : finset α} {p : α → Prop} {hp : decidable_pred p}
(f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
(∏ x in (s.filter p).attach, f x.1 (mem_filter.mp x.2).2) *
(∏ x in (s.filter (λ x, ¬ p x)).attach, g x.1 (mem_filter.mp x.2).2) :=
by simp [prod_apply_dite _ _ (λ x, x)]
@[to_additive] lemma prod_ite {s : finset α}
{p : α → Prop} {hp : decidable_pred p} (f g : α → β) :
(∏ x in s, if p x then f x else g x) =
(∏ x in s.filter p, f x) * (∏ x in s.filter (λ x, ¬ p x), g x) :=
by simp [prod_apply_ite _ _ (λ x, x)]
@[to_additive] lemma prod_ite_of_false {p : α → Prop} {hp : decidable_pred p} (f g : α → β)
(h : ∀ x ∈ s, ¬p x) : (∏ x in s, if p x then f x else g x) = (∏ x in s, g x) :=
by { rw prod_ite, simp [filter_false_of_mem h, filter_true_of_mem h] }
@[to_additive] lemma prod_ite_of_true {p : α → Prop} {hp : decidable_pred p} (f g : α → β)
(h : ∀ x ∈ s, p x) : (∏ x in s, if p x then f x else g x) = (∏ x in s, f x) :=
by { simp_rw ←(ite_not (p _)), apply prod_ite_of_false, simpa }
@[to_additive] lemma prod_apply_ite_of_false {p : α → Prop} {hp : decidable_pred p} (f g : α → γ)
(k : γ → β) (h : ∀ x ∈ s, ¬p x) :
(∏ x in s, k (if p x then f x else g x)) = (∏ x in s, k (g x)) :=
by { simp_rw apply_ite k, exact prod_ite_of_false _ _ h }
@[to_additive] lemma prod_apply_ite_of_true {p : α → Prop} {hp : decidable_pred p} (f g : α → γ)
(k : γ → β) (h : ∀ x ∈ s, p x) :
(∏ x in s, k (if p x then f x else g x)) = (∏ x in s, k (f x)) :=
by { simp_rw apply_ite k, exact prod_ite_of_true _ _ h }
@[to_additive]
lemma prod_extend_by_one [decidable_eq α] (s : finset α) (f : α → β) :
∏ i in s, (if i ∈ s then f i else 1) = ∏ i in s, f i :=
prod_congr rfl $ λ i hi, if_pos hi
@[simp, to_additive]
lemma prod_ite_mem [decidable_eq α] (s t : finset α) (f : α → β) :
∏ i in s, (if i ∈ t then f i else 1) = ∏ i in (s ∩ t), f i :=
by rw [← finset.prod_filter, finset.filter_mem_eq_inter]
@[simp, to_additive]
lemma prod_dite_eq [decidable_eq α] (s : finset α) (a : α) (b : Π x : α, a = x → β) :
(∏ x in s, (if h : a = x then b x h else 1)) = ite (a ∈ s) (b a rfl) 1 :=
begin
split_ifs with h,
{ rw [finset.prod_eq_single a, dif_pos rfl],
{ intros, rw dif_neg, cc },
{ cc } },
{ rw finset.prod_eq_one,
intros, rw dif_neg, intro, cc }
end
@[simp, to_additive]
lemma prod_dite_eq' [decidable_eq α] (s : finset α) (a : α) (b : Π x : α, x = a → β) :
(∏ x in s, (if h : x = a then b x h else 1)) = ite (a ∈ s) (b a rfl) 1 :=
begin
split_ifs with h,
{ rw [finset.prod_eq_single a, dif_pos rfl],
{ intros, rw dif_neg, cc },
{ cc } },
{ rw finset.prod_eq_one,
intros, rw dif_neg, intro, cc }
end
@[simp, to_additive] lemma prod_ite_eq [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (a = x) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq s a (λ x _, b x)
/-- A product taken over a conditional whose condition is an equality test on the index and whose
alternative is `1` has value either the term at that index or `1`.
The difference with `finset.prod_ite_eq` is that the arguments to `eq` are swapped. -/
@[simp, to_additive "A sum taken over a conditional whose condition is an equality test on the index
and whose alternative is `0` has value either the term at that index or `0`.
The difference with `finset.sum_ite_eq` is that the arguments to `eq` are swapped."]
lemma prod_ite_eq' [decidable_eq α] (s : finset α) (a : α) (b : α → β) :
(∏ x in s, (ite (x = a) (b x) 1)) = ite (a ∈ s) (b a) 1 :=
prod_dite_eq' s a (λ x _, b x)
@[to_additive]
lemma prod_ite_index (p : Prop) [decidable p] (s t : finset α) (f : α → β) :
(∏ x in if p then s else t, f x) = if p then ∏ x in s, f x else ∏ x in t, f x :=
apply_ite (λ s, ∏ x in s, f x) _ _ _
@[simp, to_additive]
lemma prod_ite_irrel (p : Prop) [decidable p] (s : finset α) (f g : α → β) :
(∏ x in s, if p then f x else g x) = if p then ∏ x in s, f x else ∏ x in s, g x :=
by { split_ifs with h; refl }
@[simp, to_additive]
lemma prod_dite_irrel (p : Prop) [decidable p] (s : finset α) (f : p → α → β) (g : ¬p → α → β) :
(∏ x in s, if h : p then f h x else g h x) = if h : p then ∏ x in s, f h x else ∏ x in s, g h x :=
by { split_ifs with h; refl }
@[simp] lemma sum_pi_single' {ι M : Type*} [decidable_eq ι] [add_comm_monoid M]
(i : ι) (x : M) (s : finset ι) :
∑ j in s, pi.single i x j = if i ∈ s then x else 0 :=
sum_dite_eq' _ _ _
@[simp] lemma sum_pi_single {ι : Type*} {M : ι → Type*}
[decidable_eq ι] [Π i, add_comm_monoid (M i)] (i : ι) (f : Π i, M i) (s : finset ι) :
∑ j in s, pi.single j (f j) i = if i ∈ s then f i else 0 :=
sum_dite_eq _ _ _
@[to_additive]
lemma prod_bij_ne_one {s : finset α} {t : finset γ} {f : α → β} {g : γ → β}
(i : Π a ∈ s, f a ≠ 1 → γ) (hi : ∀ a h₁ h₂, i a h₁ h₂ ∈ t)
(i_inj : ∀ a₁ a₂ h₁₁ h₁₂ h₂₁ h₂₂, i a₁ h₁₁ h₁₂ = i a₂ h₂₁ h₂₂ → a₁ = a₂)
(i_surj : ∀ b ∈ t, g b ≠ 1 → ∃ a h₁ h₂, b = i a h₁ h₂)
(h : ∀ a h₁ h₂, f a = g (i a h₁ h₂)) :
(∏ x in s, f x) = (∏ x in t, g x) :=
by classical; exact
calc (∏ x in s, f x) = ∏ x in (s.filter $ λ x, f x ≠ 1), f x : prod_filter_ne_one.symm
... = ∏ x in (t.filter $ λ x, g x ≠ 1), g x :
prod_bij (assume a ha, i a (mem_filter.mp ha).1 (mem_filter.mp ha).2)
(assume a ha, (mem_filter.mp ha).elim $ λ h₁ h₂, mem_filter.mpr
⟨hi a h₁ h₂, λ hg, h₂ (hg ▸ h a h₁ h₂)⟩)
(assume a ha, (mem_filter.mp ha).elim $ h a)
(assume a₁ a₂ ha₁ ha₂,
(mem_filter.mp ha₁).elim $ λ ha₁₁ ha₁₂,
(mem_filter.mp ha₂).elim $ λ ha₂₁ ha₂₂, i_inj a₁ a₂ _ _ _ _)
(assume b hb, (mem_filter.mp hb).elim $ λ h₁ h₂,
let ⟨a, ha₁, ha₂, eq⟩ := i_surj b h₁ h₂ in ⟨a, mem_filter.mpr ⟨ha₁, ha₂⟩, eq⟩)
... = (∏ x in t, g x) : prod_filter_ne_one
@[to_additive] lemma prod_dite_of_false {p : α → Prop} {hp : decidable_pred p}
(h : ∀ x ∈ s, ¬ p x) (f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
∏ (x : s), g x.val (h x.val x.property) :=
prod_bij (λ x hx, ⟨x,hx⟩) (λ x hx, by simp) (λ a ha, by { dsimp, rw dif_neg })
(λ a₁ a₂ h₁ h₂ hh, congr_arg coe hh) (λ b hb, ⟨b.1, b.2, by simp⟩)
@[to_additive] lemma prod_dite_of_true {p : α → Prop} {hp : decidable_pred p}
(h : ∀ x ∈ s, p x) (f : Π (x : α), p x → β) (g : Π (x : α), ¬p x → β) :
(∏ x in s, if hx : p x then f x hx else g x hx) =
∏ (x : s), f x.val (h x.val x.property) :=
prod_bij (λ x hx, ⟨x,hx⟩) (λ x hx, by simp) (λ a ha, by { dsimp, rw dif_pos })
(λ a₁ a₂ h₁ h₂ hh, congr_arg coe hh) (λ b hb, ⟨b.1, b.2, by simp⟩)
@[to_additive]
lemma nonempty_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : s.nonempty :=
s.eq_empty_or_nonempty.elim (λ H, false.elim $ h $ H.symm ▸ prod_empty) id
@[to_additive]
lemma exists_ne_one_of_prod_ne_one (h : (∏ x in s, f x) ≠ 1) : ∃ a ∈ s, f a ≠ 1 :=
begin
classical,
rw ← prod_filter_ne_one at h,
rcases nonempty_of_prod_ne_one h with ⟨x, hx⟩,
exact ⟨x, (mem_filter.1 hx).1, (mem_filter.1 hx).2⟩
end
@[to_additive]
lemma prod_range_succ_comm (f : ℕ → β) (n : ℕ) :
∏ x in range (n + 1), f x = f n * ∏ x in range n, f x :=
by rw [range_succ, prod_insert not_mem_range_self]
@[to_additive]
lemma prod_range_succ (f : ℕ → β) (n : ℕ) :
∏ x in range (n + 1), f x = (∏ x in range n, f x) * f n :=
by simp only [mul_comm, prod_range_succ_comm]
@[to_additive]
lemma prod_range_succ' (f : ℕ → β) :
∀ n : ℕ, (∏ k in range (n + 1), f k) = (∏ k in range n, f (k+1)) * f 0
| 0 := prod_range_succ _ _
| (n + 1) := by rw [prod_range_succ _ n, mul_right_comm, ← prod_range_succ', prod_range_succ]
@[to_additive]
lemma eventually_constant_prod {u : ℕ → β} {N : ℕ} (hu : ∀ n ≥ N, u n = 1) {n : ℕ} (hn : N ≤ n) :
∏ k in range (n + 1), u k = ∏ k in range (N + 1), u k :=
begin
obtain ⟨m, rfl : n = N + m⟩ := le_iff_exists_add.mp hn,
clear hn,
induction m with m hm,
{ simp },
erw [prod_range_succ, hm],
simp [hu, @zero_le' ℕ],
end
@[to_additive]
lemma prod_range_add (f : ℕ → β) (n m : ℕ) :
∏ x in range (n + m), f x =
(∏ x in range n, f x) * (∏ x in range m, f (n + x)) :=
begin
induction m with m hm,
{ simp },
{ rw [nat.add_succ, prod_range_succ, hm, prod_range_succ, mul_assoc], },
end
@[to_additive]
lemma prod_range_add_div_prod_range {α : Type*} [comm_group α] (f : ℕ → α) (n m : ℕ) :
(∏ k in range (n + m), f k) / (∏ k in range n, f k) = ∏ k in finset.range m, f (n + k) :=
div_eq_of_eq_mul' (prod_range_add f n m)
@[to_additive]
lemma prod_range_zero (f : ℕ → β) :
∏ k in range 0, f k = 1 :=
by rw [range_zero, prod_empty]
@[to_additive sum_range_one]
lemma prod_range_one (f : ℕ → β) :
∏ k in range 1, f k = f 0 :=
by { rw [range_one], apply @prod_singleton β ℕ 0 f }
open list
@[to_additive] lemma prod_list_map_count [decidable_eq α] (l : list α)
{M : Type*} [comm_monoid M] (f : α → M) :
(l.map f).prod = ∏ m in l.to_finset, (f m) ^ (l.count m) :=
begin
induction l with a s IH, { simp only [map_nil, prod_nil, count_nil, pow_zero, prod_const_one] },
simp only [list.map, list.prod_cons, to_finset_cons, IH],
by_cases has : a ∈ s.to_finset,
{ rw [insert_eq_of_mem has, ← insert_erase has, prod_insert (not_mem_erase _ _),
prod_insert (not_mem_erase _ _), ← mul_assoc, count_cons_self, pow_succ],
congr' 1,
refine prod_congr rfl (λ x hx, _),
rw [count_cons_of_ne (ne_of_mem_erase hx)] },
rw [prod_insert has, count_cons_self, count_eq_zero_of_not_mem (mt mem_to_finset.2 has), pow_one],
congr' 1,
refine prod_congr rfl (λ x hx, _),
rw count_cons_of_ne,
rintro rfl,
exact has hx,
end
@[to_additive]
lemma prod_list_count [decidable_eq α] [comm_monoid α] (s : list α) :
s.prod = ∏ m in s.to_finset, m ^ (s.count m) :=
by simpa using prod_list_map_count s id
@[to_additive]
lemma prod_list_count_of_subset [decidable_eq α] [comm_monoid α]
(m : list α) (s : finset α) (hs : m.to_finset ⊆ s) :
m.prod = ∏ i in s, i ^ (m.count i) :=
begin
rw prod_list_count,
refine prod_subset hs (λ x _ hx, _),
rw [mem_to_finset] at hx,
rw [count_eq_zero_of_not_mem hx, pow_zero],
end
lemma sum_filter_count_eq_countp [decidable_eq α] (p : α → Prop) [decidable_pred p] (l : list α) :
∑ x in l.to_finset.filter p, l.count x = l.countp p :=
by simp [finset.sum, sum_map_count_dedup_filter_eq_countp p l]
open multiset
@[to_additive] lemma prod_multiset_map_count [decidable_eq α] (s : multiset α)
{M : Type*} [comm_monoid M] (f : α → M) :
(s.map f).prod = ∏ m in s.to_finset, (f m) ^ (s.count m) :=
by { refine quot.induction_on s (λ l, _), simp [prod_list_map_count l f] }
@[to_additive]
lemma prod_multiset_count [decidable_eq α] [comm_monoid α] (s : multiset α) :
s.prod = ∏ m in s.to_finset, m ^ (s.count m) :=
by { convert prod_multiset_map_count s id, rw multiset.map_id }
@[to_additive]
lemma prod_multiset_count_of_subset [decidable_eq α] [comm_monoid α]
(m : multiset α) (s : finset α) (hs : m.to_finset ⊆ s) :
m.prod = ∏ i in s, i ^ (m.count i) :=
begin
revert hs,
refine quot.induction_on m (λ l, _),
simp only [quot_mk_to_coe'', coe_prod, coe_count],
apply prod_list_count_of_subset l s
end
@[to_additive] lemma prod_mem_multiset [decidable_eq α]
(m : multiset α) (f : {x // x ∈ m} → β) (g : α → β)
(hfg : ∀ x, f x = g x) :
∏ (x : {x // x ∈ m}), f x = ∏ x in m.to_finset, g x :=
prod_bij (λ x _, x.1) (λ x _, multiset.mem_to_finset.mpr x.2)
(λ _ _, hfg _)
(λ _ _ _ _ h, by { ext, assumption })
(λ y hy, ⟨⟨y, multiset.mem_to_finset.mp hy⟩, finset.mem_univ _, rfl⟩)
/--
To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors.
-/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
lemma prod_induction {M : Type*} [comm_monoid M] (f : α → M) (p : M → Prop)
(p_mul : ∀ a b, p a → p b → p (a * b)) (p_one : p 1) (p_s : ∀ x ∈ s, p $ f x) :
p $ ∏ x in s, f x :=
multiset.prod_induction _ _ p_mul p_one (multiset.forall_mem_map_iff.mpr p_s)
/--
To prove a property of a product, it suffices to prove that
the property is multiplicative and holds on factors.
-/
@[to_additive "To prove a property of a sum, it suffices to prove that
the property is additive and holds on summands."]
lemma prod_induction_nonempty {M : Type*} [comm_monoid M] (f : α → M) (p : M → Prop)
(p_mul : ∀ a b, p a → p b → p (a * b)) (hs_nonempty : s.nonempty) (p_s : ∀ x ∈ s, p $ f x) :
p $ ∏ x in s, f x :=
multiset.prod_induction_nonempty p p_mul (by simp [nonempty_iff_ne_empty.mp hs_nonempty])
(multiset.forall_mem_map_iff.mpr p_s)
/-- For any product along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can verify
that it's equal to a different function just by checking ratios of adjacent terms.
This is a multiplicative discrete analogue of the fundamental theorem of calculus. -/
@[to_additive "For any sum along `{0, ..., n - 1}` of a commutative-monoid-valued function, we can
verify that it's equal to a different function just by checking differences of adjacent terms.
This is a discrete analogue of the fundamental theorem of calculus."]
lemma prod_range_induction (f s : ℕ → β) (h0 : s 0 = 1) (h : ∀ n, s (n + 1) = s n * f n) (n : ℕ) :
∏ k in finset.range n, f k = s n :=
begin
induction n with k hk,
{ simp only [h0, finset.prod_range_zero] },
{ simp only [hk, finset.prod_range_succ, h, mul_comm] }
end
/-- A telescoping product along `{0, ..., n - 1}` of a commutative group valued function reduces to
the ratio of the last and first factors. -/
@[to_additive "A telescoping sum along `{0, ..., n - 1}` of an additive commutative group valued
function reduces to the difference of the last and first terms."]
lemma prod_range_div {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
∏ i in range n, (f (i + 1) / f i) = f n / f 0 :=
by apply prod_range_induction; simp
@[to_additive]
lemma prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
∏ i in range n, (f i / f (i + 1)) = f 0 / f n :=
by apply prod_range_induction; simp
@[to_additive]
lemma eq_prod_range_div {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
f n = f 0 * ∏ i in range n, (f (i + 1) / f i) :=
by rw [prod_range_div, mul_div_cancel'_right]
@[to_additive]
lemma eq_prod_range_div' {M : Type*} [comm_group M] (f : ℕ → M) (n : ℕ) :
f n = ∏ i in range (n + 1), if i = 0 then f 0 else f i / f (i - 1) :=
by { conv_lhs { rw [finset.eq_prod_range_div f] }, simp [finset.prod_range_succ', mul_comm] }
/--
A telescoping sum along `{0, ..., n-1}` of an `ℕ`-valued function
reduces to the difference of the last and first terms
when the function we are summing is monotone.
-/
lemma sum_range_tsub [canonically_ordered_add_monoid α] [has_sub α] [has_ordered_sub α]
[contravariant_class α α (+) (≤)] {f : ℕ → α} (h : monotone f) (n : ℕ) :
∑ i in range n, (f (i+1) - f i) = f n - f 0 :=
begin
refine sum_range_induction _ _ (tsub_self _) (λ n, _) _,
have h₁ : f n ≤ f (n+1) := h (nat.le_succ _),
have h₂ : f 0 ≤ f n := h (nat.zero_le _),
rw [tsub_add_eq_add_tsub h₂, add_tsub_cancel_of_le h₁],
end
@[simp, to_additive] lemma prod_const (b : β) : (∏ x in s, b) = b ^ s.card :=
(congr_arg _ $ s.val.map_const b).trans $ multiset.prod_repeat b s.card
@[to_additive]
lemma pow_eq_prod_const (b : β) : ∀ n, b ^ n = ∏ k in range n, b := by simp
@[to_additive]
lemma prod_pow (s : finset α) (n : ℕ) (f : α → β) :
∏ x in s, f x ^ n = (∏ x in s, f x) ^ n :=
multiset.prod_map_pow
@[to_additive]
lemma prod_flip {n : ℕ} (f : ℕ → β) :
∏ r in range (n + 1), f (n - r) = ∏ k in range (n + 1), f k :=
begin
induction n with n ih,
{ rw [prod_range_one, prod_range_one] },
{ rw [prod_range_succ', prod_range_succ _ (nat.succ n)],
simp [← ih] }
end
@[to_additive]
lemma prod_involution {s : finset α} {f : α → β} :
∀ (g : Π a ∈ s, α)
(h : ∀ a ha, f a * f (g a ha) = 1)
(g_ne : ∀ a ha, f a ≠ 1 → g a ha ≠ a)
(g_mem : ∀ a ha, g a ha ∈ s)
(g_inv : ∀ a ha, g (g a ha) (g_mem a ha) = a),
(∏ x in s, f x) = 1 :=
by haveI := classical.dec_eq α;
haveI := classical.dec_eq β; exact
finset.strong_induction_on s
(λ s ih g h g_ne g_mem g_inv,
s.eq_empty_or_nonempty.elim (λ hs, hs.symm ▸ rfl)
(λ ⟨x, hx⟩,
have hmem : ∀ y ∈ (s.erase x).erase (g x hx), y ∈ s,
from λ y hy, (mem_of_mem_erase (mem_of_mem_erase hy)),
have g_inj : ∀ {x hx y hy}, g x hx = g y hy → x = y,
from λ x hx y hy h, by rw [← g_inv x hx, ← g_inv y hy]; simp [h],
have ih': ∏ y in erase (erase s x) (g x hx), f y = (1 : β) :=
ih ((s.erase x).erase (g x hx))
⟨subset.trans (erase_subset _ _) (erase_subset _ _),
λ h, not_mem_erase (g x hx) (s.erase x) (h (g_mem x hx))⟩
(λ y hy, g y (hmem y hy))
(λ y hy, h y (hmem y hy))
(λ y hy, g_ne y (hmem y hy))
(λ y hy, mem_erase.2 ⟨λ (h : g y _ = g x hx), by simpa [g_inj h] using hy,
mem_erase.2 ⟨λ (h : g y _ = x),
have y = g x hx, from g_inv y (hmem y hy) ▸ by simp [h],
by simpa [this] using hy, g_mem y (hmem y hy)⟩⟩)
(λ y hy, g_inv y (hmem y hy)),
if hx1 : f x = 1
then ih' ▸ eq.symm (prod_subset hmem
(λ y hy hy₁,
have y = x ∨ y = g x hx, by simpa [hy, not_and_distrib, or_comm] using hy₁,
this.elim (λ hy, hy.symm ▸ hx1)
(λ hy, h x hx ▸ hy ▸ hx1.symm ▸ (one_mul _).symm)))
else by rw [← insert_erase hx, prod_insert (not_mem_erase _ _),
← insert_erase (mem_erase.2 ⟨g_ne x hx hx1, g_mem x hx⟩),
prod_insert (not_mem_erase _ _), ih', mul_one, h x hx]))
/-- The product of the composition of functions `f` and `g`, is the product over `b ∈ s.image g` of
`f b` to the power of the cardinality of the fibre of `b`. See also `finset.prod_image`. -/
@[to_additive "The sum of the composition of functions `f` and `g`, is the sum over `b ∈ s.image g`
of `f b` times of the cardinality of the fibre of `b`. See also `finset.sum_image`."]
lemma prod_comp [decidable_eq γ] (f : γ → β) (g : α → γ) :
∏ a in s, f (g a) = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :=
calc ∏ a in s, f (g a)
= ∏ x in (s.image g).sigma (λ b : γ, s.filter (λ a, g a = b)), f (g x.2) :
prod_bij (λ a ha, ⟨g a, a⟩) (by simp; tauto) (λ _ _, rfl) (by simp) -- `(by finish)` closes this
(by { rintro ⟨b_fst, b_snd⟩ H,
simp only [mem_image, exists_prop, mem_filter, mem_sigma] at H,
tauto })
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f (g a) : prod_sigma _ _ _
... = ∏ b in s.image g, ∏ a in s.filter (λ a, g a = b), f b :
prod_congr rfl (λ b hb, prod_congr rfl (by simp {contextual := tt}))
... = ∏ b in s.image g, f b ^ (s.filter (λ a, g a = b)).card :
prod_congr rfl (λ _ _, prod_const _)
@[to_additive]
lemma prod_piecewise [decidable_eq α] (s t : finset α) (f g : α → β) :
(∏ x in s, (t.piecewise f g) x) = (∏ x in s ∩ t, f x) * (∏ x in s \ t, g x) :=
by { rw [piecewise, prod_ite, filter_mem_eq_inter, ← sdiff_eq_filter], }
@[to_additive]
lemma prod_inter_mul_prod_diff [decidable_eq α] (s t : finset α) (f : α → β) :
(∏ x in s ∩ t, f x) * (∏ x in s \ t, f x) = (∏ x in s, f x) :=
by { convert (s.prod_piecewise t f f).symm, simp [finset.piecewise] }
@[to_additive]
lemma prod_eq_mul_prod_diff_singleton [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x in s, f x = f i * ∏ x in s \ {i}, f x :=
by { convert (s.prod_inter_mul_prod_diff {i} f).symm, simp [h] }
@[to_additive]
lemma prod_eq_prod_diff_singleton_mul [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s)
(f : α → β) : ∏ x in s, f x = (∏ x in s \ {i}, f x) * f i :=
by { rw [prod_eq_mul_prod_diff_singleton h, mul_comm] }
@[to_additive]
lemma _root_.fintype.prod_eq_mul_prod_compl [decidable_eq α] [fintype α] (a : α) (f : α → β) :
∏ i, f i = (f a) * ∏ i in {a}ᶜ, f i :=
prod_eq_mul_prod_diff_singleton (mem_univ a) f
@[to_additive]
lemma _root_.fintype.prod_eq_prod_compl_mul [decidable_eq α] [fintype α] (a : α) (f : α → β) :
∏ i, f i = (∏ i in {a}ᶜ, f i) * f a :=
prod_eq_prod_diff_singleton_mul (mem_univ a) f
lemma dvd_prod_of_mem (f : α → β) {a : α} {s : finset α} (ha : a ∈ s) :
f a ∣ ∏ i in s, f i :=
begin
classical,
rw finset.prod_eq_mul_prod_diff_singleton ha,
exact dvd_mul_right _ _,
end
/-- A product can be partitioned into a product of products, each equivalent under a setoid. -/
@[to_additive "A sum can be partitioned into a sum of sums, each equivalent under a setoid."]
lemma prod_partition (R : setoid α) [decidable_rel R.r] :
(∏ x in s, f x) = ∏ xbar in s.image quotient.mk, ∏ y in s.filter (λ y, ⟦y⟧ = xbar), f y :=
begin
refine (finset.prod_image' f (λ x hx, _)).symm,
refl,
end
/-- If we can partition a product into subsets that cancel out, then the whole product cancels. -/
@[to_additive "If we can partition a sum into subsets that cancel out, then the whole sum cancels."]
lemma prod_cancels_of_partition_cancels (R : setoid α) [decidable_rel R.r]
(h : ∀ x ∈ s, (∏ a in s.filter (λ y, y ≈ x), f a) = 1) : (∏ x in s, f x) = 1 :=
begin
rw [prod_partition R, ←finset.prod_eq_one],
intros xbar xbar_in_s,
obtain ⟨x, x_in_s, xbar_eq_x⟩ := mem_image.mp xbar_in_s,
rw [←xbar_eq_x, filter_congr (λ y _, @quotient.eq _ R y x)],
apply h x x_in_s,
end
@[to_additive]
lemma prod_update_of_not_mem [decidable_eq α] {s : finset α} {i : α}
(h : i ∉ s) (f : α → β) (b : β) : (∏ x in s, function.update f i b x) = (∏ x in s, f x) :=
begin
apply prod_congr rfl (λ j hj, _),
have : j ≠ i, by { assume eq, rw eq at hj, exact h hj },
simp [this]
end
@[to_additive]
lemma prod_update_of_mem [decidable_eq α] {s : finset α} {i : α} (h : i ∈ s) (f : α → β) (b : β) :
(∏ x in s, function.update f i b x) = b * (∏ x in s \ (singleton i), f x) :=
by { rw [update_eq_piecewise, prod_piecewise], simp [h] }
/-- If a product of a `finset` of size at most 1 has a given value, so
do the terms in that product. -/
@[to_additive eq_of_card_le_one_of_sum_eq "If a sum of a `finset` of size at most 1 has a given
value, so do the terms in that sum."]
lemma eq_of_card_le_one_of_prod_eq {s : finset α} (hc : s.card ≤ 1) {f : α → β} {b : β}
(h : ∏ x in s, f x = b) : ∀ x ∈ s, f x = b :=
begin
intros x hx,
by_cases hc0 : s.card = 0,
{ exact false.elim (card_ne_zero_of_mem hx hc0) },
{ have h1 : s.card = 1 := le_antisymm hc (nat.one_le_of_lt (nat.pos_of_ne_zero hc0)),
rw card_eq_one at h1,
cases h1 with x2 hx2,
rw [hx2, mem_singleton] at hx,
simp_rw hx2 at h,
rw hx,
rw prod_singleton at h,
exact h }
end
/-- Taking a product over `s : finset α` is the same as multiplying the value on a single element
`f a` by the product of `s.erase a`.
See `multiset.prod_map_erase` for the `multiset` version. -/
@[to_additive "Taking a sum over `s : finset α` is the same as adding the value on a single element
`f a` to the sum over `s.erase a`.
See `multiset.sum_map_erase` for the `multiset` version."]
lemma mul_prod_erase [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
f a * (∏ x in s.erase a, f x) = ∏ x in s, f x :=
by rw [← prod_insert (not_mem_erase a s), insert_erase h]
/-- A variant of `finset.mul_prod_erase` with the multiplication swapped. -/
@[to_additive "A variant of `finset.add_sum_erase` with the addition swapped."]
lemma prod_erase_mul [decidable_eq α] (s : finset α) (f : α → β) {a : α} (h : a ∈ s) :
(∏ x in s.erase a, f x) * f a = ∏ x in s, f x :=
by rw [mul_comm, mul_prod_erase s f h]
/-- If a function applied at a point is 1, a product is unchanged by
removing that point, if present, from a `finset`. -/
@[to_additive "If a function applied at a point is 0, a sum is unchanged by
removing that point, if present, from a `finset`."]
lemma prod_erase [decidable_eq α] (s : finset α) {f : α → β} {a : α} (h : f a = 1) :
∏ x in s.erase a, f x = ∏ x in s, f x :=
begin
rw ←sdiff_singleton_eq_erase,
refine prod_subset (sdiff_subset _ _) (λ x hx hnx, _),
rw sdiff_singleton_eq_erase at hnx,
rwa eq_of_mem_of_not_mem_erase hx hnx
end
/-- See also `finset.prod_boole`. -/
@[to_additive "See also `finset.sum_boole`."]
lemma prod_ite_one {f : α → Prop} [decidable_pred f] (hf : (s : set α).pairwise_disjoint f)
(a : β) :
∏ i in s, ite (f i) a 1 = ite (∃ i ∈ s, f i) a 1 :=
begin
split_ifs,
{ obtain ⟨i, hi, hfi⟩ := h,
rw [prod_eq_single_of_mem _ hi, if_pos hfi],
exact λ j hj h, if_neg (λ hfj, (hf hj hi h).le_bot ⟨hfj, hfi⟩) },
{ push_neg at h,
rw prod_eq_one,
exact λ i hi, if_neg (h i hi) }
end
lemma sum_erase_lt_of_pos {γ : Type*} [decidable_eq α] [ordered_add_comm_monoid γ]
[covariant_class γ γ (+) (<)] {s : finset α} {d : α} (hd : d ∈ s) {f : α → γ} (hdf : 0 < f d) :
∑ (m : α) in s.erase d, f m < ∑ (m : α) in s, f m :=
begin
nth_rewrite_rhs 0 ←finset.insert_erase hd,
rw finset.sum_insert (finset.not_mem_erase d s),
exact lt_add_of_pos_left _ hdf,
end
/-- If a product is 1 and the function is 1 except possibly at one
point, it is 1 everywhere on the `finset`. -/
@[to_additive "If a sum is 0 and the function is 0 except possibly at one
point, it is 0 everywhere on the `finset`."]
lemma eq_one_of_prod_eq_one {s : finset α} {f : α → β} {a : α} (hp : ∏ x in s, f x = 1)
(h1 : ∀ x ∈ s, x ≠ a → f x = 1) : ∀ x ∈ s, f x = 1 :=
begin
intros x hx,
classical,
by_cases h : x = a,
{ rw h,
rw h at hx,
rw [←prod_subset (singleton_subset_iff.2 hx)
(λ t ht ha, h1 t ht (not_mem_singleton.1 ha)),
prod_singleton] at hp,
exact hp },
{ exact h1 x hx h }
end
lemma prod_pow_boole [decidable_eq α] (s : finset α) (f : α → β) (a : α) :
(∏ x in s, (f x)^(ite (a = x) 1 0)) = ite (a ∈ s) (f a) 1 :=
by simp
lemma prod_dvd_prod_of_dvd {S : finset α} (g1 g2 : α → β) (h : ∀ a ∈ S, g1 a ∣ g2 a) :
S.prod g1 ∣ S.prod g2 :=
begin
classical,
apply finset.induction_on' S, { simp },
intros a T haS _ haT IH,
repeat {rw finset.prod_insert haT},
exact mul_dvd_mul (h a haS) IH,
end
lemma prod_dvd_prod_of_subset {ι M : Type*} [comm_monoid M] (s t : finset ι) (f : ι → M)
(h : s ⊆ t) : ∏ i in s, f i ∣ ∏ i in t, f i :=
multiset.prod_dvd_prod_of_le $ multiset.map_le_map $ by simpa
end comm_monoid
/-- If `f = g = h` everywhere but at `i`, where `f i = g i + h i`, then the product of `f` over `s`
is the sum of the products of `g` and `h`. -/
lemma prod_add_prod_eq [comm_semiring β] {s : finset α} {i : α} {f g h : α → β}
(hi : i ∈ s) (h1 : g i + h i = f i) (h2 : ∀ j ∈ s, j ≠ i → g j = f j)
(h3 : ∀ j ∈ s, j ≠ i → h j = f j) : ∏ i in s, g i + ∏ i in s, h i = ∏ i in s, f i :=
by { classical, simp_rw [prod_eq_mul_prod_diff_singleton hi, ← h1, right_distrib],
congr' 2; apply prod_congr rfl; simpa }
lemma card_eq_sum_ones (s : finset α) : s.card = ∑ _ in s, 1 :=
by simp
lemma sum_const_nat {m : ℕ} {f : α → ℕ} (h₁ : ∀ x ∈ s, f x = m) :
(∑ x in s, f x) = card s * m :=
begin
rw [← nat.nsmul_eq_mul, ← sum_const],
apply sum_congr rfl h₁
end
@[simp]
lemma sum_boole {s : finset α} {p : α → Prop} [non_assoc_semiring β] {hp : decidable_pred p} :
(∑ x in s, if p x then (1 : β) else (0 : β)) = (s.filter p).card :=
by simp only [add_zero,
mul_one,
finset.sum_const,
nsmul_eq_mul,
eq_self_iff_true,
finset.sum_const_zero,
finset.sum_ite]
lemma _root_.commute.sum_right [non_unital_non_assoc_semiring β] (s : finset α)
(f : α → β) (b : β) (h : ∀ i ∈ s, commute b (f i)) :
commute b (∑ i in s, f i) :=
commute.multiset_sum_right _ _ $ λ b hb, begin
obtain ⟨i, hi, rfl⟩ := multiset.mem_map.mp hb,
exact h _ hi
end
lemma _root_.commute.sum_left [non_unital_non_assoc_semiring β] (s : finset α)
(f : α → β) (b : β) (h : ∀ i ∈ s, commute (f i) b) :
commute (∑ i in s, f i) b :=
(commute.sum_right _ _ _ $ λ i hi, (h _ hi).symm).symm
section opposite
open mul_opposite
/-- Moving to the opposite additive commutative monoid commutes with summing. -/
@[simp] lemma op_sum [add_comm_monoid β] {s : finset α} (f : α → β) :
op (∑ x in s, f x) = ∑ x in s, op (f x) :=
(op_add_equiv : β ≃+ βᵐᵒᵖ).map_sum _ _
@[simp] lemma unop_sum [add_comm_monoid β] {s : finset α} (f : α → βᵐᵒᵖ) :
unop (∑ x in s, f x) = ∑ x in s, unop (f x) :=
(op_add_equiv : β ≃+ βᵐᵒᵖ).symm.map_sum _ _
end opposite
section division_comm_monoid
variables [division_comm_monoid β]
@[simp, to_additive] lemma prod_inv_distrib : (∏ x in s, (f x)⁻¹) = (∏ x in s, f x)⁻¹ :=
multiset.prod_map_inv
@[simp, to_additive]
lemma prod_div_distrib : (∏ x in s, f x / g x) = (∏ x in s, f x) / ∏ x in s, g x :=
multiset.prod_map_div
@[to_additive]
lemma prod_zpow (f : α → β) (s : finset α) (n : ℤ) : ∏ a in s, (f a) ^ n = (∏ a in s, f a) ^ n :=
multiset.prod_map_zpow
end division_comm_monoid
section comm_group
variables [comm_group β] [decidable_eq α]
@[simp, to_additive] lemma prod_sdiff_eq_div (h : s₁ ⊆ s₂) :
(∏ x in (s₂ \ s₁), f x) = (∏ x in s₂, f x) / (∏ x in s₁, f x) :=
by rw [eq_div_iff_mul_eq', prod_sdiff h]
@[to_additive] lemma prod_sdiff_div_prod_sdiff :
(∏ x in s₂ \ s₁, f x) / (∏ x in s₁ \ s₂, f x) = (∏ x in s₂, f x) / (∏ x in s₁, f x) :=
by simp [← finset.prod_sdiff (@inf_le_left _ _ s₁ s₂),
← finset.prod_sdiff (@inf_le_right _ _ s₁ s₂)]
@[simp, to_additive]
lemma prod_erase_eq_div {a : α} (h : a ∈ s) : (∏ x in s.erase a, f x) = (∏ x in s, f x) / f a :=
by rw [eq_div_iff_mul_eq', prod_erase_mul _ _ h]
end comm_group
@[simp] theorem card_sigma {σ : α → Type*} (s : finset α) (t : Π a, finset (σ a)) :
card (s.sigma t) = ∑ a in s, card (t a) :=
multiset.card_sigma _ _
@[simp] lemma card_disj_Union (s : finset α) (t : α → finset β) (h) :
(s.disj_Union t h).card = s.sum (λ i, (t i).card) :=
multiset.card_bind _ _
lemma card_bUnion [decidable_eq β] {s : finset α} {t : α → finset β}
(h : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → disjoint (t x) (t y)) :
(s.bUnion t).card = ∑ u in s, card (t u) :=
calc (s.bUnion t).card = ∑ i in s.bUnion t, 1 : by simp
... = ∑ a in s, ∑ i in t a, 1 : finset.sum_bUnion h
... = ∑ u in s, card (t u) : by simp
lemma card_bUnion_le [decidable_eq β] {s : finset α} {t : α → finset β} :
(s.bUnion t).card ≤ ∑ a in s, (t a).card :=
by haveI := classical.dec_eq α; exact
finset.induction_on s (by simp)
(λ a s has ih,
calc ((insert a s).bUnion t).card ≤ (t a).card + (s.bUnion t).card :
by rw bUnion_insert; exact finset.card_union_le _ _
... ≤ ∑ a in insert a s, card (t a) :
by rw sum_insert has; exact add_le_add_left ih _)
theorem card_eq_sum_card_fiberwise [decidable_eq β] {f : α → β} {s : finset α} {t : finset β}
(H : ∀ x ∈ s, f x ∈ t) :
s.card = ∑ a in t, (s.filter (λ x, f x = a)).card :=
by simp only [card_eq_sum_ones, sum_fiberwise_of_maps_to H]
theorem card_eq_sum_card_image [decidable_eq β] (f : α → β) (s : finset α) :
s.card = ∑ a in s.image f, (s.filter (λ x, f x = a)).card :=
card_eq_sum_card_fiberwise (λ _, mem_image_of_mem _)
lemma mem_sum {f : α → multiset β} (s : finset α) (b : β) :
b ∈ ∑ x in s, f x ↔ ∃ a ∈ s, b ∈ f a :=
begin
classical,
refine s.induction_on (by simp) _,
{ intros a t hi ih,
simp [sum_insert hi, ih, or_and_distrib_right, exists_or_distrib] }
end
section prod_eq_zero
variables [comm_monoid_with_zero β]
lemma prod_eq_zero (ha : a ∈ s) (h : f a = 0) : (∏ x in s, f x) = 0 :=
by { haveI := classical.dec_eq α, rw [←prod_erase_mul _ _ ha, h, mul_zero] }
lemma prod_boole {s : finset α} {p : α → Prop} [decidable_pred p] :
∏ i in s, ite (p i) (1 : β) (0 : β) = ite (∀ i ∈ s, p i) 1 0 :=
begin
split_ifs,
{ apply prod_eq_one,
intros i hi,
rw if_pos (h i hi) },
{ push_neg at h,
rcases h with ⟨i, hi, hq⟩,
apply prod_eq_zero hi,
rw [if_neg hq] },
end
variables [nontrivial β] [no_zero_divisors β]
lemma prod_eq_zero_iff : (∏ x in s, f x) = 0 ↔ (∃ a ∈ s, f a = 0) :=
begin
classical,
apply finset.induction_on s,
exact ⟨not.elim one_ne_zero, λ ⟨_, H, _⟩, H.elim⟩,
assume a s ha ih,
rw [prod_insert ha, mul_eq_zero, bex_def, exists_mem_insert, ih, ← bex_def]
end
theorem prod_ne_zero_iff : (∏ x in s, f x) ≠ 0 ↔ (∀ a ∈ s, f a ≠ 0) :=
by { rw [ne, prod_eq_zero_iff], push_neg }
end prod_eq_zero
@[to_additive]
lemma prod_unique_nonempty {α β : Type*} [comm_monoid β] [unique α]
(s : finset α) (f : α → β) (h : s.nonempty) :
(∏ x in s, f x) = f default :=
by rw [h.eq_singleton_default, finset.prod_singleton]
end finset
namespace fintype
open finset
/-- `fintype.prod_bijective` is a variant of `finset.prod_bij` that accepts `function.bijective`.
See `function.bijective.prod_comp` for a version without `h`. -/
@[to_additive "`fintype.sum_equiv` is a variant of `finset.sum_bij` that accepts
`function.bijective`.
See `function.bijective.sum_comp` for a version without `h`. "]
lemma prod_bijective {α β M : Type*} [fintype α] [fintype β] [comm_monoid M]
(e : α → β) (he : function.bijective e) (f : α → M) (g : β → M) (h : ∀ x, f x = g (e x)) :
∏ x : α, f x = ∏ x : β, g x :=
prod_bij
(λ x _, e x)
(λ x _, mem_univ (e x))
(λ x _, h x)
(λ x x' _ _ h, he.injective h)
(λ y _, (he.surjective y).imp $ λ a h, ⟨mem_univ _, h.symm⟩)
/-- `fintype.prod_equiv` is a specialization of `finset.prod_bij` that
automatically fills in most arguments.
See `equiv.prod_comp` for a version without `h`.
-/
@[to_additive "`fintype.sum_equiv` is a specialization of `finset.sum_bij` that
automatically fills in most arguments.
See `equiv.sum_comp` for a version without `h`.
"]
lemma prod_equiv {α β M : Type*} [fintype α] [fintype β] [comm_monoid M]
(e : α ≃ β) (f : α → M) (g : β → M) (h : ∀ x, f x = g (e x)) :
∏ x : α, f x = ∏ x : β, g x :=
prod_bijective e e.bijective f g h
variables {f s}
@[to_additive]
lemma prod_unique {α β : Type*} [comm_monoid β] [unique α] [fintype α] (f : α → β) :
(∏ x : α, f x) = f default :=
by rw [univ_unique, prod_singleton]
@[to_additive] lemma prod_empty {α β : Type*} [comm_monoid β] [is_empty α] [fintype α] (f : α → β) :
(∏ x : α, f x) = 1 :=
finset.prod_of_empty _
@[to_additive] lemma prod_subsingleton {α β : Type*} [comm_monoid β] [subsingleton α] [fintype α]
(f : α → β) (a : α) :
(∏ x : α, f x) = f a :=
begin
haveI : unique α := unique_of_subsingleton a,
convert prod_unique f
end
@[to_additive]
lemma prod_subtype_mul_prod_subtype {α β : Type*} [fintype α] [comm_monoid β]
(p : α → Prop) (f : α → β) [decidable_pred p] :
(∏ (i : {x // p x}), f i) * (∏ i : {x // ¬ p x}, f i) = ∏ i, f i :=
begin
classical,
let s := {x | p x}.to_finset,
rw [← finset.prod_subtype s, ← finset.prod_subtype sᶜ],
{ exact finset.prod_mul_prod_compl _ _ },
{ simp },
{ simp }
end
end fintype
namespace list
@[to_additive] lemma prod_to_finset {M : Type*} [decidable_eq α] [comm_monoid M]
(f : α → M) : ∀ {l : list α} (hl : l.nodup), l.to_finset.prod f = (l.map f).prod
| [] _ := by simp
| (a :: l) hl := let ⟨not_mem, hl⟩ := list.nodup_cons.mp hl in
by simp [finset.prod_insert (mt list.mem_to_finset.mp not_mem), prod_to_finset hl]
end list
namespace multiset
lemma disjoint_list_sum_left {a : multiset α} {l : list (multiset α)} :
multiset.disjoint l.sum a ↔ ∀ b ∈ l, multiset.disjoint b a :=
begin
induction l with b bs ih,
{ simp only [zero_disjoint, list.not_mem_nil, is_empty.forall_iff, forall_const, list.sum_nil], },
{ simp_rw [list.sum_cons, disjoint_add_left, list.mem_cons_iff, forall_eq_or_imp],
simp [and.congr_left_iff, iff_self, ih], },
end
lemma disjoint_list_sum_right {a : multiset α} {l : list (multiset α)} :
multiset.disjoint a l.sum ↔ ∀ b ∈ l, multiset.disjoint a b :=
by simpa only [disjoint_comm] using disjoint_list_sum_left
lemma disjoint_sum_left {a : multiset α} {i : multiset (multiset α)} :
multiset.disjoint i.sum a ↔ ∀ b ∈ i, multiset.disjoint b a :=
quotient.induction_on i $ λ l, begin
rw [quot_mk_to_coe, multiset.coe_sum],
exact disjoint_list_sum_left,
end
lemma disjoint_sum_right {a : multiset α} {i : multiset (multiset α)} :
multiset.disjoint a i.sum ↔ ∀ b ∈ i, multiset.disjoint a b :=
by simpa only [disjoint_comm] using disjoint_sum_left
lemma disjoint_finset_sum_left {β : Type*} {i : finset β} {f : β → multiset α} {a : multiset α} :
multiset.disjoint (i.sum f) a ↔ ∀ b ∈ i, multiset.disjoint (f b) a :=
begin
convert (@disjoint_sum_left _ a) (map f i.val),
simp [and.congr_left_iff, iff_self],
end
lemma disjoint_finset_sum_right {β : Type*} {i : finset β} {f : β → multiset α} {a : multiset α} :
multiset.disjoint a (i.sum f) ↔ ∀ b ∈ i, multiset.disjoint a (f b) :=
by simpa only [disjoint_comm] using disjoint_finset_sum_left
variables [decidable_eq α]
lemma add_eq_union_left_of_le {x y z : multiset α} (h : y ≤ x) :
z + x = z ∪ y ↔ z.disjoint x ∧ x = y :=
begin
rw ←add_eq_union_iff_disjoint,
split,
{ intro h0,
rw and_iff_right_of_imp,
{ exact (le_of_add_le_add_left $ h0.trans_le $ union_le_add z y).antisymm h, },
{ rintro rfl,
exact h0, } },
{ rintro ⟨h0, rfl⟩,
exact h0, }
end
lemma add_eq_union_right_of_le {x y z : multiset α} (h : z ≤ y) :
x + y = x ∪ z ↔ y = z ∧ x.disjoint y :=
by simpa only [and_comm] using add_eq_union_left_of_le h
lemma finset_sum_eq_sup_iff_disjoint {β : Type*} {i : finset β} {f : β → multiset α} :
i.sum f = i.sup f ↔ ∀ x y ∈ i, x ≠ y → multiset.disjoint (f x) (f y) :=
begin
induction i using finset.cons_induction_on with z i hz hr,
{ simp only [finset.not_mem_empty, is_empty.forall_iff, implies_true_iff,
finset.sum_empty, finset.sup_empty, bot_eq_zero, eq_self_iff_true], },
{ simp_rw [finset.sum_cons hz, finset.sup_cons, finset.mem_cons, multiset.sup_eq_union,
forall_eq_or_imp, ne.def, eq_self_iff_true, not_true, is_empty.forall_iff, true_and,
imp_and_distrib, forall_and_distrib, ←hr, @eq_comm _ z],
have := λ x ∈ i, ne_of_mem_of_not_mem H hz,
simp only [this, not_false_iff, true_implies_iff] {contextual := tt},
simp_rw [←disjoint_finset_sum_left, ←disjoint_finset_sum_right, disjoint_comm, ←and_assoc,
and_self],
exact add_eq_union_left_of_le (finset.sup_le (λ x hx, le_sum_of_mem (mem_map_of_mem f hx))), },
end
lemma sup_powerset_len {α : Type*} [decidable_eq α] (x : multiset α) :
finset.sup (finset.range (x.card + 1)) (λ k, x.powerset_len k) = x.powerset :=
begin
convert bind_powerset_len x,
rw [multiset.bind, multiset.join, ←finset.range_val, ←finset.sum_eq_multiset_sum],
exact eq.symm (finset_sum_eq_sup_iff_disjoint.mpr
(λ _ _ _ _ h, pairwise_disjoint_powerset_len x h)),
end
@[simp] lemma to_finset_sum_count_eq (s : multiset α) :
(∑ a in s.to_finset, s.count a) = s.card :=
calc (∑ a in s.to_finset, s.count a) = (∑ a in s.to_finset, s.count a • 1) :
by simp only [smul_eq_mul, mul_one]
... = (s.map (λ _, 1)).sum : (finset.sum_multiset_map_count _ _).symm
... = s.card : by simp
lemma count_sum' {s : finset β} {a : α} {f : β → multiset α} :
count a (∑ x in s, f x) = ∑ x in s, count a (f x) :=
by { dunfold finset.sum, rw count_sum }
@[simp] lemma to_finset_sum_count_nsmul_eq (s : multiset α) :
(∑ a in s.to_finset, s.count a • {a}) = s :=
by rw [← finset.sum_multiset_map_count, multiset.sum_map_singleton]
theorem exists_smul_of_dvd_count (s : multiset α) {k : ℕ}
(h : ∀ (a : α), a ∈ s → k ∣ multiset.count a s) :
∃ (u : multiset α), s = k • u :=
begin
use ∑ a in s.to_finset, (s.count a / k) • {a},
have h₂ : ∑ (x : α) in s.to_finset, k • (count x s / k) • ({x} : multiset α) =
∑ (x : α) in s.to_finset, count x s • {x},
{ apply finset.sum_congr rfl,
intros x hx,
rw [← mul_nsmul, nat.mul_div_cancel' (h x (mem_to_finset.mp hx))] },
rw [← finset.sum_nsmul, h₂, to_finset_sum_count_nsmul_eq]
end
lemma to_finset_prod_dvd_prod [comm_monoid α] (S : multiset α) : S.to_finset.prod id ∣ S.prod :=
begin
rw finset.prod_eq_multiset_prod,
refine multiset.prod_dvd_prod_of_le _,
simp [multiset.dedup_le S],
end
@[to_additive]
lemma prod_sum {α : Type*} {ι : Type*} [comm_monoid α] (f : ι → multiset α) (s : finset ι) :
(∑ x in s, f x).prod = ∏ x in s, (f x).prod :=
begin
classical,
induction s using finset.induction_on with a t hat ih,
{ rw [finset.sum_empty, finset.prod_empty, multiset.prod_zero] },
{ rw [finset.sum_insert hat, finset.prod_insert hat, multiset.prod_add, ih] }
end
end multiset
namespace nat
@[simp, norm_cast] lemma cast_list_sum [add_monoid_with_one β] (s : list ℕ) :
(↑(s.sum) : β) = (s.map coe).sum :=
map_list_sum (cast_add_monoid_hom β) _
@[simp, norm_cast] lemma cast_list_prod [semiring β] (s : list ℕ) :
(↑(s.prod) : β) = (s.map coe).prod :=
map_list_prod (cast_ring_hom β) _
@[simp, norm_cast] lemma cast_multiset_sum [add_comm_monoid_with_one β] (s : multiset ℕ) :
(↑(s.sum) : β) = (s.map coe).sum :=
map_multiset_sum (cast_add_monoid_hom β) _
@[simp, norm_cast] lemma cast_multiset_prod [comm_semiring β] (s : multiset ℕ) :
(↑(s.prod) : β) = (s.map coe).prod :=
map_multiset_prod (cast_ring_hom β) _
@[simp, norm_cast] lemma cast_sum [add_comm_monoid_with_one β] (s : finset α) (f : α → ℕ) :
↑(∑ x in s, f x : ℕ) = (∑ x in s, (f x : β)) :=
map_sum (cast_add_monoid_hom β) _ _
@[simp, norm_cast] lemma cast_prod [comm_semiring β] (f : α → ℕ) (s : finset α) :
(↑∏ i in s, f i : β) = ∏ i in s, f i :=
map_prod (cast_ring_hom β) _ _
end nat
namespace int
@[simp, norm_cast] lemma cast_list_sum [add_group_with_one β] (s : list ℤ) :
(↑(s.sum) : β) = (s.map coe).sum :=
map_list_sum (cast_add_hom β) _
@[simp, norm_cast] lemma cast_list_prod [ring β] (s : list ℤ) :
(↑(s.prod) : β) = (s.map coe).prod :=
map_list_prod (cast_ring_hom β) _
@[simp, norm_cast] lemma cast_multiset_sum [add_comm_group_with_one β] (s : multiset ℤ) :
(↑(s.sum) : β) = (s.map coe).sum :=
map_multiset_sum (cast_add_hom β) _
@[simp, norm_cast] lemma cast_multiset_prod {R : Type*} [comm_ring R] (s : multiset ℤ) :
(↑(s.prod) : R) = (s.map coe).prod :=
map_multiset_prod (cast_ring_hom R) _
@[simp, norm_cast] lemma cast_sum [add_comm_group_with_one β] (s : finset α) (f : α → ℤ) :
↑(∑ x in s, f x : ℤ) = (∑ x in s, (f x : β)) :=
map_sum (cast_add_hom β) _ _
@[simp, norm_cast] lemma cast_prod {R : Type*} [comm_ring R] (f : α → ℤ) (s : finset α) :
(↑∏ i in s, f i : R) = ∏ i in s, f i :=
(int.cast_ring_hom R).map_prod _ _
end int
@[simp, norm_cast] lemma units.coe_prod {M : Type*} [comm_monoid M] (f : α → Mˣ)
(s : finset α) : (↑∏ i in s, f i : M) = ∏ i in s, f i :=
(units.coe_hom M).map_prod _ _
lemma units.mk0_prod [comm_group_with_zero β] (s : finset α) (f : α → β) (h) :
units.mk0 (∏ b in s, f b) h =
∏ b in s.attach, units.mk0 (f b) (λ hh, h (finset.prod_eq_zero b.2 hh)) :=
by { classical, induction s using finset.induction_on; simp* }
lemma nat_abs_sum_le {ι : Type*} (s : finset ι) (f : ι → ℤ) :
(∑ i in s, f i).nat_abs ≤ ∑ i in s, (f i).nat_abs :=
begin
classical,
apply finset.induction_on s,
{ simp only [finset.sum_empty, int.nat_abs_zero] },
{ intros i s his IH,
simp only [his, finset.sum_insert, not_false_iff],
exact (int.nat_abs_add_le _ _).trans (add_le_add le_rfl IH) }
end
/-! ### `additive`, `multiplicative` -/
open additive multiplicative
section monoid
variables [monoid α]
@[simp] lemma of_mul_list_prod (s : list α) : of_mul s.prod = (s.map of_mul).sum :=
by simpa [of_mul]
@[simp] lemma to_mul_list_sum (s : list (additive α)) :
to_mul s.sum = (s.map to_mul).prod := by simpa [to_mul, of_mul]
end monoid
section add_monoid
variables [add_monoid α]
@[simp] lemma of_add_list_prod (s : list α) : of_add s.sum = (s.map of_add).prod :=
by simpa [of_add]
@[simp] lemma to_add_list_sum (s : list (multiplicative α)) :
to_add s.prod = (s.map to_add).sum := by simpa [to_add, of_add]
end add_monoid
section comm_monoid
variables [comm_monoid α]
@[simp] lemma of_mul_multiset_prod (s : multiset α) :
of_mul s.prod = (s.map of_mul).sum := by simpa [of_mul]
@[simp] lemma to_mul_multiset_sum (s : multiset (additive α)) :
to_mul s.sum = (s.map to_mul).prod := by simpa [to_mul, of_mul]
@[simp] lemma of_mul_prod (s : finset ι) (f : ι → α) :
of_mul (∏ i in s, f i) = ∑ i in s, of_mul (f i) := rfl
@[simp] lemma to_mul_sum (s : finset ι) (f : ι → additive α) :
to_mul (∑ i in s, f i) = ∏ i in s, to_mul (f i) := rfl
end comm_monoid
section add_comm_monoid
variables [add_comm_monoid α]
@[simp] lemma of_add_multiset_prod (s : multiset α) :
of_add s.sum = (s.map of_add).prod := by simpa [of_add]
@[simp] lemma to_add_multiset_sum (s : multiset (multiplicative α)) :
to_add s.prod = (s.map to_add).sum := by simpa [to_add, of_add]
@[simp] lemma of_add_sum (s : finset ι) (f : ι → α) :
of_add (∑ i in s, f i) = ∏ i in s, of_add (f i) := rfl
@[simp] lemma to_add_prod (s : finset ι) (f : ι → multiplicative α) :
to_add (∏ i in s, f i) = ∑ i in s, to_add (f i) := rfl
end add_comm_monoid
|
2bee6083731e9c3783cfc90d4aab3393793b4372 | 6b10c15e653d49d146378acda9f3692e9b5b1950 | /examples/logic/unnamed_87.lean | c4e4bcde4c8e1d96fb16bffa9d37fdfd979d5f97 | [] | no_license | gebner/mathematics_in_lean | 3cf7f18767208ea6c3307ec3a67c7ac266d8514d | 6d1462bba46d66a9b948fc1aef2714fd265cde0b | refs/heads/master | 1,655,301,945,565 | 1,588,697,505,000 | 1,588,697,505,000 | 261,523,603 | 0 | 0 | null | 1,588,695,611,000 | 1,588,695,610,000 | null | UTF-8 | Lean | false | false | 86 | lean | variable A : Prop
-- BEGIN
example : A → A :=
begin
intro h,
apply h
end
-- END |
4b4ed8c0fc8e024f1e647fa9c719854ce5ddad5b | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/logic/nonempty.lean | 85efbcdae858b57e0dab7964202de6a6a3d9624b | [
"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 | 5,862 | 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 logic.basic
/-!
# Nonempty types
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> https://github.com/leanprover-community/mathlib4/pull/487
> Any changes to this file require a corresponding PR to mathlib4.
This file proves a few extra facts about `nonempty`, which is defined in core Lean.
## Main declarations
* `nonempty.some`: Extracts a witness of nonemptiness using choice. Takes `nonempty α` explicitly.
* `classical.arbitrary`: Extracts a witness of nonemptiness using choice. Takes `nonempty α` as an
instance.
-/
variables {α β : Type*} {γ : α → Type*}
attribute [simp] nonempty_of_inhabited
@[priority 20]
instance has_zero.nonempty [has_zero α] : nonempty α := ⟨0⟩
@[priority 20]
instance has_one.nonempty [has_one α] : nonempty α := ⟨1⟩
lemma exists_true_iff_nonempty {α : Sort*} : (∃a:α, true) ↔ nonempty α :=
iff.intro (λ⟨a, _⟩, ⟨a⟩) (λ⟨a⟩, ⟨a, trivial⟩)
@[simp] lemma nonempty_Prop {p : Prop} : nonempty p ↔ p :=
iff.intro (assume ⟨h⟩, h) (assume h, ⟨h⟩)
lemma not_nonempty_iff_imp_false {α : Sort*} : ¬ nonempty α ↔ α → false :=
⟨λ h a, h ⟨a⟩, λ h ⟨a⟩, h a⟩
@[simp] lemma nonempty_sigma : nonempty (Σa:α, γ a) ↔ (∃a:α, nonempty (γ a)) :=
iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩)
@[simp] lemma nonempty_psigma {α} {β : α → Sort*} : nonempty (psigma β) ↔ (∃a:α, nonempty (β a)) :=
iff.intro (assume ⟨⟨a, c⟩⟩, ⟨a, ⟨c⟩⟩) (assume ⟨a, ⟨c⟩⟩, ⟨⟨a, c⟩⟩)
@[simp] lemma nonempty_subtype {α} {p : α → Prop} : nonempty (subtype p) ↔ (∃a:α, p a) :=
iff.intro (assume ⟨⟨a, h⟩⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a, h⟩⟩)
@[simp] lemma nonempty_prod : nonempty (α × β) ↔ (nonempty α ∧ nonempty β) :=
iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩)
@[simp] lemma nonempty_pprod {α β} : nonempty (pprod α β) ↔ (nonempty α ∧ nonempty β) :=
iff.intro (assume ⟨⟨a, b⟩⟩, ⟨⟨a⟩, ⟨b⟩⟩) (assume ⟨⟨a⟩, ⟨b⟩⟩, ⟨⟨a, b⟩⟩)
@[simp] lemma nonempty_sum : nonempty (α ⊕ β) ↔ (nonempty α ∨ nonempty β) :=
iff.intro
(assume ⟨h⟩, match h with sum.inl a := or.inl ⟨a⟩ | sum.inr b := or.inr ⟨b⟩ end)
(assume h, match h with or.inl ⟨a⟩ := ⟨sum.inl a⟩ | or.inr ⟨b⟩ := ⟨sum.inr b⟩ end)
@[simp] lemma nonempty_psum {α β} : nonempty (psum α β) ↔ (nonempty α ∨ nonempty β) :=
iff.intro
(assume ⟨h⟩, match h with psum.inl a := or.inl ⟨a⟩ | psum.inr b := or.inr ⟨b⟩ end)
(assume h, match h with or.inl ⟨a⟩ := ⟨psum.inl a⟩ | or.inr ⟨b⟩ := ⟨psum.inr b⟩ end)
@[simp] lemma nonempty_empty : ¬ nonempty empty :=
assume ⟨h⟩, h.elim
@[simp] lemma nonempty_ulift : nonempty (ulift α) ↔ nonempty α :=
iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩)
@[simp] lemma nonempty_plift {α} : nonempty (plift α) ↔ nonempty α :=
iff.intro (assume ⟨⟨a⟩⟩, ⟨a⟩) (assume ⟨a⟩, ⟨⟨a⟩⟩)
@[simp] lemma nonempty.forall {α} {p : nonempty α → Prop} : (∀h:nonempty α, p h) ↔ (∀a, p ⟨a⟩) :=
iff.intro (assume h a, h _) (assume h ⟨a⟩, h _)
@[simp] lemma nonempty.exists {α} {p : nonempty α → Prop} : (∃h:nonempty α, p h) ↔ (∃a, p ⟨a⟩) :=
iff.intro (assume ⟨⟨a⟩, h⟩, ⟨a, h⟩) (assume ⟨a, h⟩, ⟨⟨a⟩, h⟩)
/-- Using `classical.choice`, lifts a (`Prop`-valued) `nonempty` instance to a (`Type`-valued)
`inhabited` instance. `classical.inhabited_of_nonempty` already exists, in
`core/init/classical.lean`, but the assumption is not a type class argument,
which makes it unsuitable for some applications. -/
noncomputable def classical.inhabited_of_nonempty' {α} [h : nonempty α] : inhabited α :=
⟨classical.choice h⟩
/-- Using `classical.choice`, extracts a term from a `nonempty` type. -/
@[reducible] protected noncomputable def nonempty.some {α} (h : nonempty α) : α :=
classical.choice h
/-- Using `classical.choice`, extracts a term from a `nonempty` type. -/
@[reducible] protected noncomputable def classical.arbitrary (α) [h : nonempty α] : α :=
classical.choice h
/-- Given `f : α → β`, if `α` is nonempty then `β` is also nonempty.
`nonempty` cannot be a `functor`, because `functor` is restricted to `Type`. -/
lemma nonempty.map {α β} (f : α → β) : nonempty α → nonempty β
| ⟨h⟩ := ⟨f h⟩
protected lemma nonempty.map2 {α β γ : Sort*} (f : α → β → γ) : nonempty α → nonempty β → nonempty γ
| ⟨x⟩ ⟨y⟩ := ⟨f x y⟩
protected lemma nonempty.congr {α β} (f : α → β) (g : β → α) :
nonempty α ↔ nonempty β :=
⟨nonempty.map f, nonempty.map g⟩
lemma nonempty.elim_to_inhabited {α : Sort*} [h : nonempty α] {p : Prop}
(f : inhabited α → p) : p :=
h.elim $ f ∘ inhabited.mk
instance {α β} [h : nonempty α] [h2 : nonempty β] : nonempty (α × β) :=
h.elim $ λ g, h2.elim $ λ g2, ⟨⟨g, g2⟩⟩
instance {ι : Sort*} {α : ι → Sort*} [Π i, nonempty (α i)] : nonempty (Π i, α i) :=
⟨λ _, classical.arbitrary _⟩
lemma classical.nonempty_pi {ι} {α : ι → Sort*} : nonempty (Π i, α i) ↔ ∀ i, nonempty (α i) :=
⟨λ ⟨f⟩ a, ⟨f a⟩, @pi.nonempty _ _⟩
lemma subsingleton_of_not_nonempty {α : Sort*} (h : ¬ nonempty α) : subsingleton α :=
⟨λ x, false.elim $ not_nonempty_iff_imp_false.mp h x⟩
lemma function.surjective.nonempty [h : nonempty β] {f : α → β} (hf : function.surjective f) :
nonempty α :=
let ⟨y⟩ := h, ⟨x, hx⟩ := hf y in ⟨x⟩
|
ddb0f582b935d39ff4dd5a2f52d94c84fe991a5b | fa02ed5a3c9c0adee3c26887a16855e7841c668b | /src/algebra/algebra/operations.lean | 658ebeff2c06e1ba83275a87d60c663802fb2709 | [
"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 | 13,043 | lean | /-
Copyright (c) 2019 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import algebra.algebra.basic
/-!
# Multiplication and division of submodules of an algebra.
An interface for multiplication and division of sub-R-modules of an R-algebra A is developed.
## Main definitions
Let `R` be a commutative ring (or semiring) and aet `A` be an `R`-algebra.
* `1 : submodule R A` : the R-submodule R of the R-algebra A
* `has_mul (submodule R A)` : multiplication of two sub-R-modules M and N of A is defined to be
the smallest submodule containing all the products `m * n`.
* `has_div (submodule R A)` : `I / J` is defined to be the submodule consisting of all `a : A` such
that `a • J ⊆ I`
It is proved that `submodule R A` is a semiring, and also an algebra over `set A`.
## Tags
multiplication of submodules, division of subodules, submodule semiring
-/
universes u v
open algebra set
namespace submodule
variables {R : Type u} [comm_semiring R]
section ring
variables {A : Type v} [semiring A] [algebra R A]
variables (S T : set A) {M N P Q : submodule R A} {m n : A}
/-- `1 : submodule R A` is the submodule R of A. -/
instance : has_one (submodule R A) :=
⟨submodule.map (of_id R A).to_linear_map (⊤ : submodule R R)⟩
theorem one_eq_map_top :
(1 : submodule R A) = submodule.map (of_id R A).to_linear_map (⊤ : submodule R R) := rfl
theorem one_eq_span : (1 : submodule R A) = R ∙ 1 :=
begin
apply submodule.ext,
intro a,
erw [mem_map, mem_span_singleton],
apply exists_congr,
intro r,
simpa [smul_def],
end
theorem one_le : (1 : submodule R A) ≤ P ↔ (1 : A) ∈ P :=
by simpa only [one_eq_span, span_le, set.singleton_subset_iff]
/-- Multiplication of sub-R-modules of an R-algebra A. The submodule `M * N` is the
smallest R-submodule of `A` containing the elements `m * n` for `m ∈ M` and `n ∈ N`. -/
instance : has_mul (submodule R A) :=
⟨λ M N, ⨆ s : M, N.map $ algebra.lmul R A s.1⟩
theorem mul_mem_mul (hm : m ∈ M) (hn : n ∈ N) : m * n ∈ M * N :=
(le_supr _ ⟨m, hm⟩ : _ ≤ M * N) ⟨n, hn, rfl⟩
theorem mul_le : M * N ≤ P ↔ ∀ (m ∈ M) (n ∈ N), m * n ∈ P :=
⟨λ H m hm n hn, H $ mul_mem_mul hm hn,
λ H, supr_le $ λ ⟨m, hm⟩, map_le_iff_le_comap.2 $ λ n hn, H m hm n hn⟩
@[elab_as_eliminator] protected theorem mul_induction_on
{C : A → Prop} {r : A} (hr : r ∈ M * N)
(hm : ∀ (m ∈ M) (n ∈ N), C (m * n))
(h0 : C 0) (ha : ∀ x y, C x → C y → C (x + y))
(hs : ∀ (r : R) x, C x → C (r • x)) : C r :=
(@mul_le _ _ _ _ _ _ _ ⟨C, h0, ha, hs⟩).2 hm hr
variables R
theorem span_mul_span : span R S * span R T = span R (S * T) :=
begin
apply le_antisymm,
{ rw mul_le, intros a ha b hb,
apply span_induction ha,
work_on_goal 0 { intros, apply span_induction hb,
work_on_goal 0 { intros, exact subset_span ⟨_, _, ‹_›, ‹_›, rfl⟩ } },
all_goals { intros, simp only [mul_zero, zero_mul, zero_mem,
left_distrib, right_distrib, mul_smul_comm, smul_mul_assoc],
try {apply add_mem _ _ _}, try {apply smul_mem _ _ _} }, assumption' },
{ rw span_le, rintros _ ⟨a, b, ha, hb, rfl⟩,
exact mul_mem_mul (subset_span ha) (subset_span hb) }
end
variables {R}
variables (M N P Q)
protected theorem mul_assoc : (M * N) * P = M * (N * P) :=
le_antisymm (mul_le.2 $ λ mn hmn p hp,
suffices M * N ≤ (M * (N * P)).comap (algebra.lmul_right R p), from this hmn,
mul_le.2 $ λ m hm n hn, show m * n * p ∈ M * (N * P), from
(mul_assoc m n p).symm ▸ mul_mem_mul hm (mul_mem_mul hn hp))
(mul_le.2 $ λ m hm np hnp,
suffices N * P ≤ (M * N * P).comap (algebra.lmul_left R m), from this hnp,
mul_le.2 $ λ n hn p hp, show m * (n * p) ∈ M * N * P, from
mul_assoc m n p ▸ mul_mem_mul (mul_mem_mul hm hn) hp)
@[simp] theorem mul_bot : M * ⊥ = ⊥ :=
eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [submodule.mem_bot] at hn ⊢; rw [hn, mul_zero]
@[simp] theorem bot_mul : ⊥ * M = ⊥ :=
eq_bot_iff.2 $ mul_le.2 $ λ m hm n hn, by rw [submodule.mem_bot] at hm ⊢; rw [hm, zero_mul]
@[simp] protected theorem one_mul : (1 : submodule R A) * M = M :=
by { conv_lhs { rw [one_eq_span, ← span_eq M] }, erw [span_mul_span, one_mul, span_eq] }
@[simp] protected theorem mul_one : M * 1 = M :=
by { conv_lhs { rw [one_eq_span, ← span_eq M] }, erw [span_mul_span, mul_one, span_eq] }
variables {M N P Q}
@[mono] theorem mul_le_mul (hmp : M ≤ P) (hnq : N ≤ Q) : M * N ≤ P * Q :=
mul_le.2 $ λ m hm n hn, mul_mem_mul (hmp hm) (hnq hn)
theorem mul_le_mul_left (h : M ≤ N) : M * P ≤ N * P :=
mul_le_mul h (le_refl P)
theorem mul_le_mul_right (h : N ≤ P) : M * N ≤ M * P :=
mul_le_mul (le_refl M) h
variables (M N P)
theorem mul_sup : M * (N ⊔ P) = M * N ⊔ M * P :=
le_antisymm (mul_le.2 $ λ m hm np hnp, let ⟨n, hn, p, hp, hnp⟩ := mem_sup.1 hnp in
mem_sup.2 ⟨_, mul_mem_mul hm hn, _, mul_mem_mul hm hp, hnp ▸ (mul_add m n p).symm⟩)
(sup_le (mul_le_mul_right le_sup_left) (mul_le_mul_right le_sup_right))
theorem sup_mul : (M ⊔ N) * P = M * P ⊔ N * P :=
le_antisymm (mul_le.2 $ λ mn hmn p hp, let ⟨m, hm, n, hn, hmn⟩ := mem_sup.1 hmn in
mem_sup.2 ⟨_, mul_mem_mul hm hp, _, mul_mem_mul hn hp, hmn ▸ (add_mul m n p).symm⟩)
(sup_le (mul_le_mul_left le_sup_left) (mul_le_mul_left le_sup_right))
lemma mul_subset_mul : (↑M : set A) * (↑N : set A) ⊆ (↑(M * N) : set A) :=
by { rintros _ ⟨i, j, hi, hj, rfl⟩, exact mul_mem_mul hi hj }
lemma map_mul {A'} [semiring A'] [algebra R A'] (f : A →ₐ[R] A') :
map f.to_linear_map (M * N) = map f.to_linear_map M * map f.to_linear_map N :=
calc map f.to_linear_map (M * N)
= ⨆ (i : M), (N.map (lmul R A i)).map f.to_linear_map : map_supr _ _
... = map f.to_linear_map M * map f.to_linear_map N :
begin
apply congr_arg Sup,
ext S,
split; rintros ⟨y, hy⟩,
{ use [f y, mem_map.mpr ⟨y.1, y.2, rfl⟩],
refine trans _ hy,
ext,
simp },
{ obtain ⟨y', hy', fy_eq⟩ := mem_map.mp y.2,
use [y', hy'],
refine trans _ hy,
rw f.to_linear_map_apply at fy_eq,
ext,
simp [fy_eq] }
end
section decidable_eq
open_locale classical
lemma mem_span_mul_finite_of_mem_span_mul {S : set A} {S' : set A} {x : A}
(hx : x ∈ span R (S * S')) :
∃ (T T' : finset A), ↑T ⊆ S ∧ ↑T' ⊆ S' ∧ x ∈ span R (T * T' : set A) :=
begin
obtain ⟨U, h, hU⟩ := mem_span_finite_of_mem_span hx,
obtain ⟨T, T', hS, hS', h⟩ := finset.subset_mul h,
use [T, T', hS, hS'],
have h' : (U : set A) ⊆ T * T', { assumption_mod_cast, },
have h'' := span_mono h' hU,
assumption,
end
end decidable_eq
lemma mem_span_mul_finite_of_mem_mul {P Q : submodule R A} {x : A} (hx : x ∈ P * Q) :
∃ (T T' : finset A), (T : set A) ⊆ P ∧ (T' : set A) ⊆ Q ∧ x ∈ span R (T * T' : set A) :=
submodule.mem_span_mul_finite_of_mem_span_mul
(by rwa [← submodule.span_eq P, ← submodule.span_eq Q, submodule.span_mul_span] at hx)
variables {M N P}
/-- Sub-R-modules of an R-algebra form a semiring. -/
instance : semiring (submodule R A) :=
{ one_mul := submodule.one_mul,
mul_one := submodule.mul_one,
mul_assoc := submodule.mul_assoc,
zero_mul := bot_mul,
mul_zero := mul_bot,
left_distrib := mul_sup,
right_distrib := sup_mul,
..submodule.add_comm_monoid_submodule,
..submodule.has_one,
..submodule.has_mul }
variables (M)
lemma pow_subset_pow {n : ℕ} : (↑M : set A)^n ⊆ ↑(M^n : submodule R A) :=
begin
induction n with n ih,
{ erw [pow_zero, pow_zero, set.singleton_subset_iff],
rw [set_like.mem_coe, ← one_le],
exact le_refl _ },
{ rw [pow_succ, pow_succ],
refine set.subset.trans (set.mul_subset_mul (subset.refl _) ih) _,
apply mul_subset_mul }
end
/-- `span` is a semiring homomorphism (recall multiplication is pointwise multiplication of subsets
on either side). -/
def span.ring_hom : set_semiring A →+* submodule R A :=
{ to_fun := submodule.span R,
map_zero' := span_empty,
map_one' := le_antisymm (span_le.2 $ singleton_subset_iff.2 ⟨1, ⟨⟩, (algebra_map R A).map_one⟩)
(map_le_iff_le_comap.2 $ λ r _, mem_span_singleton.2 ⟨r, (algebra_map_eq_smul_one r).symm⟩),
map_add' := span_union,
map_mul' := λ s t, by erw [span_mul_span, ← image_mul_prod] }
end ring
section comm_ring
variables {A : Type v} [comm_semiring A] [algebra R A]
variables {M N : submodule R A} {m n : A}
theorem mul_mem_mul_rev (hm : m ∈ M) (hn : n ∈ N) : n * m ∈ M * N :=
mul_comm m n ▸ mul_mem_mul hm hn
variables (M N)
protected theorem mul_comm : M * N = N * M :=
le_antisymm (mul_le.2 $ λ r hrm s hsn, mul_mem_mul_rev hsn hrm)
(mul_le.2 $ λ r hrn s hsm, mul_mem_mul_rev hsm hrn)
/-- Sub-R-modules of an R-algebra A form a semiring. -/
instance : comm_semiring (submodule R A) :=
{ mul_comm := submodule.mul_comm,
.. submodule.semiring }
variables (R A)
/-- R-submodules of the R-algebra A are a module over `set A`. -/
instance module_set : module (set_semiring A) (submodule R A) :=
{ smul := λ s P, span R s * P,
smul_add := λ _ _ _, mul_add _ _ _,
add_smul := λ s t P, show span R (s ⊔ t) * P = _, by { erw [span_union, right_distrib] },
mul_smul := λ s t P, show _ = _ * (_ * _),
by { rw [← mul_assoc, span_mul_span, ← image_mul_prod] },
one_smul := λ P, show span R {(1 : A)} * P = _,
by { conv_lhs {erw ← span_eq P}, erw [span_mul_span, one_mul, span_eq] },
zero_smul := λ P, show span R ∅ * P = ⊥, by erw [span_empty, bot_mul],
smul_zero := λ _, mul_bot _ }
variables {R A}
lemma smul_def {s : set_semiring A} {P : submodule R A} : s • P = span R s * P := rfl
lemma smul_le_smul {s t : set_semiring A} {M N : submodule R A} (h₁ : s.down ≤ t.down)
(h₂ : M ≤ N) : s • M ≤ t • N :=
mul_le_mul (span_mono h₁) h₂
lemma smul_singleton (a : A) (M : submodule R A) :
({a} : set A).up • M = M.map (lmul_left _ a) :=
begin
conv_lhs {rw ← span_eq M},
change span _ _ * span _ _ = _,
rw [span_mul_span],
apply le_antisymm,
{ rw span_le,
rintros _ ⟨b, m, hb, hm, rfl⟩,
rw [set_like.mem_coe, mem_map, set.mem_singleton_iff.mp hb],
exact ⟨m, hm, rfl⟩ },
{ rintros _ ⟨m, hm, rfl⟩, exact subset_span ⟨a, m, set.mem_singleton a, hm, rfl⟩ }
end
section quotient
/-- The elements of `I / J` are the `x` such that `x • J ⊆ I`.
In fact, we define `x ∈ I / J` to be `∀ y ∈ J, x * y ∈ I` (see `mem_div_iff_forall_mul_mem`),
which is equivalent to `x • J ⊆ I` (see `mem_div_iff_smul_subset`), but nicer to use in proofs.
This is the general form of the ideal quotient, traditionally written $I : J$.
-/
instance : has_div (submodule R A) :=
⟨ λ I J, {
carrier := { x | ∀ y ∈ J, x * y ∈ I },
zero_mem' := λ y hy, by { rw zero_mul, apply submodule.zero_mem },
add_mem' := λ a b ha hb y hy, by { rw add_mul, exact submodule.add_mem _ (ha _ hy) (hb _ hy) },
smul_mem' := λ r x hx y hy, by { rw algebra.smul_mul_assoc,
exact submodule.smul_mem _ _ (hx _ hy) } } ⟩
lemma mem_div_iff_forall_mul_mem {x : A} {I J : submodule R A} :
x ∈ I / J ↔ ∀ y ∈ J, x * y ∈ I :=
iff.refl _
lemma mem_div_iff_smul_subset {x : A} {I J : submodule R A} : x ∈ I / J ↔ x • (J : set A) ⊆ I :=
⟨ λ h y ⟨y', hy', xy'_eq_y⟩, by { rw ← xy'_eq_y, apply h, assumption },
λ h y hy, h (set.smul_mem_smul_set hy) ⟩
lemma le_div_iff {I J K : submodule R A} : I ≤ J / K ↔ ∀ (x ∈ I) (z ∈ K), x * z ∈ J := iff.refl _
lemma le_div_iff_mul_le {I J K : submodule R A} : I ≤ J / K ↔ I * K ≤ J :=
by rw [le_div_iff, mul_le]
@[simp] lemma one_le_one_div {I : submodule R A} :
1 ≤ 1 / I ↔ I ≤ 1 :=
begin
split, all_goals {intro hI},
{rwa [le_div_iff_mul_le, one_mul] at hI},
{rwa [le_div_iff_mul_le, one_mul]},
end
lemma le_self_mul_one_div {I : submodule R A} (hI : I ≤ 1) :
I ≤ I * (1 / I) :=
begin
rw [← mul_one I] {occs := occurrences.pos [1]},
apply mul_le_mul_right (one_le_one_div.mpr hI),
end
lemma mul_one_div_le_one {I : submodule R A} : I * (1 / I) ≤ 1 :=
begin
rw submodule.mul_le,
intros m hm n hn,
rw [submodule.mem_div_iff_forall_mul_mem] at hn,
rw mul_comm,
exact hn m hm,
end
@[simp] lemma map_div {B : Type*} [comm_ring B] [algebra R B]
(I J : submodule R A) (h : A ≃ₐ[R] B) :
(I / J).map h.to_linear_map = I.map h.to_linear_map / J.map h.to_linear_map :=
begin
ext x,
simp only [mem_map, mem_div_iff_forall_mul_mem],
split,
{ rintro ⟨x, hx, rfl⟩ _ ⟨y, hy, rfl⟩,
exact ⟨x * y, hx _ hy, h.map_mul x y⟩ },
{ rintro hx,
refine ⟨h.symm x, λ z hz, _, h.apply_symm_apply x⟩,
obtain ⟨xz, xz_mem, hxz⟩ := hx (h z) ⟨z, hz, rfl⟩,
convert xz_mem,
apply h.injective,
erw [h.map_mul, h.apply_symm_apply, hxz] }
end
end quotient
end comm_ring
end submodule
|
6f2f1858288484b67ad507f150b4d8d767877df6 | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/analysis/analytic/inverse.lean | d2c1a11a873ea77c1818415223e0344f9b25505b | [
"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 | 27,387 | lean | /-
Copyright (c) 2021 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.analytic.composition
import tactic.congrm
/-!
# Inverse of analytic functions
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
We construct the left and right inverse of a formal multilinear series with invertible linear term,
we prove that they coincide and study their properties (notably convergence).
## Main statements
* `p.left_inv i`: the formal left inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.right_inv i`: the formal right inverse of the formal multilinear series `p`,
for `i : E ≃L[𝕜] F` which coincides with `p₁`.
* `p.left_inv_comp` says that `p.left_inv i` is indeed a left inverse to `p` when `p₁ = i`.
* `p.right_inv_comp` says that `p.right_inv i` is indeed a right inverse to `p` when `p₁ = i`.
* `p.left_inv_eq_right_inv`: the two inverses coincide.
* `p.radius_right_inv_pos_of_radius_pos`: if a power series has a positive radius of convergence,
then so does its inverse.
-/
open_locale big_operators classical topology
open finset filter
namespace formal_multilinear_series
variables {𝕜 : Type*} [nontrivially_normed_field 𝕜]
{E : Type*} [normed_add_comm_group E] [normed_space 𝕜 E]
{F : Type*} [normed_add_comm_group F] [normed_space 𝕜 F]
/-! ### The left inverse of a formal multilinear series -/
/-- The left inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `(left_inv p i) ∘ p = id`. For this, the linear term
`p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `q ∘ p` is `∑ qₖ (p_{j₁}, ..., p_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `qₙ (p₁, ..., p₁)`. We adjust the definition so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def left_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) := - ∑ c : {c : composition (n+2) // c.length < n + 2},
have (c : composition (n+2)).length < n+2 := c.2,
(left_inv (c : composition (n+2)).length).comp_along_composition
(p.comp_continuous_linear_map i.symm) c
@[simp] lemma left_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 0 = 0 := by rw left_inv
@[simp] lemma left_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.left_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw left_inv
/-- The left inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma left_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.left_inv i = p.left_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
cases n, { simp }, -- if one replaces `simp` with `refl`, the proof times out in the kernel.
cases n, { simp }, -- TODO: why?
simp only [left_inv, neg_inj],
refine finset.sum_congr rfl (λ c cuniv, _),
rcases c with ⟨c, hc⟩,
ext v,
dsimp,
simp [IH _ hc],
end
/-- The left inverse to a formal multilinear series is indeed a left inverse, provided its linear
term is invertible. -/
lemma left_inv_comp (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
(left_inv p i).comp p = id 𝕜 E :=
begin
ext n v,
cases n,
{ simp only [left_inv, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def,
not_false_iff, zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [left_inv, comp_coeff_one, h, id_apply_one, continuous_linear_equiv.coe_apply,
continuous_linear_equiv.symm_apply_apply, continuous_multilinear_curry_fin1_symm_apply] },
have A : (finset.univ : finset (composition (n+2)))
= {c | composition.length c < n + 2}.to_finset ∪ {composition.ones (n+2)},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : c.length < n + 2,
{ simp [h] },
{ simp [composition.eq_ones_iff_le_length.2 (not_lt.1 h)] } },
have B : disjoint ({c | composition.length c < n + 2} : set (composition (n + 2))).to_finset
{composition.ones (n+2)}, by simp,
have C : (p.left_inv i (composition.ones (n + 2)).length)
(λ (j : fin (composition.ones n.succ.succ).length), p 1 (λ k,
v ((fin.cast_le (composition.length_le _)) j)))
= p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)),
{ apply formal_multilinear_series.congr _ (composition.ones_length _) (λ j hj1 hj2, _),
exact formal_multilinear_series.congr _ rfl (λ k hk1 hk2, by congr) },
have D : p.left_inv i (n+2) (λ (j : fin (n+2)), p 1 (λ k, v j)) =
- ∑ (c : composition (n + 2)) in {c : composition (n + 2) | c.length < n + 2}.to_finset,
(p.left_inv i c.length) (p.apply_composition c v),
{ simp only [left_inv, continuous_multilinear_map.neg_apply, neg_inj,
continuous_multilinear_map.sum_apply],
convert (sum_to_finset_eq_subtype (λ (c : composition (n+2)), c.length < n+2)
(λ (c : composition (n+2)), (continuous_multilinear_map.comp_along_composition
(p.comp_continuous_linear_map ↑(i.symm)) c (p.left_inv i c.length))
(λ (j : fin (n + 2)), p 1 (λ (k : fin 1), v j)))).symm.trans _,
simp only [comp_continuous_linear_map_apply_composition,
continuous_multilinear_map.comp_along_composition_apply],
congr,
ext c,
congr,
ext k,
simp [h] },
simp [formal_multilinear_series.comp, show n + 2 ≠ 1, by dec_trivial, A, finset.sum_union B,
apply_composition_ones, C, D, -set.to_finset_set_of],
end
/-! ### The right inverse of a formal multilinear series -/
/-- The right inverse of a formal multilinear series, where the `n`-th term is defined inductively
in terms of the previous ones to make sure that `p ∘ (right_inv p i) = id`. For this, the linear
term `p₁` in `p` should be invertible. In the definition, `i` is a linear isomorphism that should
coincide with `p₁`, so that one can use its inverse in the construction. The definition does not
use that `i = p₁`, but proofs that the definition is well-behaved do.
The `n`-th term in `p ∘ q` is `∑ pₖ (q_{j₁}, ..., q_{jₖ})` over `j₁ + ... + jₖ = n`. In this
expression, `qₙ` appears only once, in `p₁ (qₙ)`. We adjust the definition of `qₙ` so that this
term compensates the rest of the sum, using `i⁻¹` as an inverse to `p₁`.
These formulas only make sense when the constant term `p₀` vanishes. The definition we give is
general, but it ignores the value of `p₀`.
-/
noncomputable def right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
formal_multilinear_series 𝕜 F E
| 0 := 0
| 1 := (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm
| (n+2) :=
let q : formal_multilinear_series 𝕜 F E := λ k, if h : k < n + 2 then right_inv k else 0 in
- (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map ((p.comp q) (n+2))
@[simp] lemma right_inv_coeff_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 0 = 0 := by rw right_inv
@[simp] lemma right_inv_coeff_one (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.right_inv i 1 = (continuous_multilinear_curry_fin1 𝕜 F E).symm i.symm := by rw right_inv
/-- The right inverse does not depend on the zeroth coefficient of a formal multilinear
series. -/
lemma right_inv_remove_zero (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) :
p.remove_zero.right_inv i = p.right_inv i :=
begin
ext1 n,
induction n using nat.strong_rec' with n IH,
rcases n with _|_|n,
{ simp only [right_inv_coeff_zero] },
{ simp only [right_inv_coeff_one] },
simp only [right_inv, neg_inj],
rw remove_zero_comp_of_pos _ _ (add_pos_of_nonneg_of_pos (n.zero_le) zero_lt_two),
congr' 2 with k,
by_cases hk : k < n+2; simp [hk, IH]
end
lemma comp_right_inv_aux1 {n : ℕ} (hn : 0 < n)
(p : formal_multilinear_series 𝕜 E F) (q : formal_multilinear_series 𝕜 F E) (v : fin n → F) :
p.comp q n v =
(∑ (c : composition n) in {c : composition n | 1 < c.length}.to_finset,
p c.length (q.apply_composition c v)) + p 1 (λ i, q n v) :=
begin
have A : (finset.univ : finset (composition n))
= {c | 1 < composition.length c}.to_finset ∪ {composition.single n hn},
{ refine subset.antisymm (λ c hc, _) (subset_univ _),
by_cases h : 1 < c.length,
{ simp [h] },
{ have : c.length = 1,
by { refine (eq_iff_le_not_lt.2 ⟨ _, h⟩).symm, exact c.length_pos_of_pos hn },
rw ← composition.eq_single_iff_length hn at this,
simp [this] } },
have B : disjoint ({c | 1 < composition.length c} : set (composition n)).to_finset
{composition.single n hn}, by simp,
have C : p (composition.single n hn).length
(q.apply_composition (composition.single n hn) v)
= p 1 (λ (i : fin 1), q n v),
{ apply p.congr (composition.single_length hn) (λ j hj1 hj2, _),
simp [apply_composition_single] },
simp [formal_multilinear_series.comp, A, finset.sum_union B, C, -set.to_finset_set_of],
end
lemma comp_right_inv_aux2
(p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (v : fin (n + 2) → F) :
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length (apply_composition (λ (k : ℕ), ite (k < n + 2) (p.right_inv i k) 0) c v) =
∑ (c : composition (n + 2)) in {c : composition (n + 2) | 1 < c.length}.to_finset,
p c.length ((p.right_inv i).apply_composition c v) :=
begin
have N : 0 < n + 2, by dec_trivial,
refine sum_congr rfl (λ c hc, p.congr rfl (λ j hj1 hj2, _)),
have : ∀ k, c.blocks_fun k < n + 2,
{ simp only [set.mem_to_finset, set.mem_set_of_eq] at hc,
simp [← composition.ne_single_iff N, composition.eq_single_iff_length, ne_of_gt hc] },
simp [apply_composition, this],
end
/-- The right inverse to a formal multilinear series is indeed a right inverse, provided its linear
term is invertible and its constant term vanishes. -/
lemma comp_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
p.comp (right_inv p i) = id 𝕜 F :=
begin
ext n v,
cases n,
{ simp only [h0, continuous_multilinear_map.zero_apply, id_apply_ne_one, ne.def, not_false_iff,
zero_ne_one, comp_coeff_zero']},
cases n,
{ simp only [comp_coeff_one, h, right_inv, continuous_linear_equiv.apply_symm_apply, id_apply_one,
continuous_linear_equiv.coe_apply, continuous_multilinear_curry_fin1_symm_apply] },
have N : 0 < n+2, by dec_trivial,
simp [comp_right_inv_aux1 N, h, right_inv, lt_irrefl n, show n + 2 ≠ 1, by dec_trivial,
← sub_eq_add_neg, sub_eq_zero, comp_right_inv_aux2, -set.to_finset_set_of],
end
lemma right_inv_coeff (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F) (n : ℕ) (hn : 2 ≤ n) :
p.right_inv i n = - (i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition n)),
p.comp_along_composition (p.right_inv i) c) :=
begin
cases n, { exact false.elim (zero_lt_two.not_le hn) },
cases n, { exact false.elim (one_lt_two.not_le hn) },
simp only [right_inv, neg_inj],
congr' 1,
ext v,
have N : 0 < n + 2, by dec_trivial,
have : (p 1) (λ (i : fin 1), 0) = 0 := continuous_multilinear_map.map_zero _,
simp [comp_right_inv_aux1 N, lt_irrefl n, this, comp_right_inv_aux2, -set.to_finset_set_of],
end
/-! ### Coincidence of the left and the right inverse -/
private lemma left_inv_eq_right_inv_aux (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) (h0 : p 0 = 0) :
left_inv p i = right_inv p i := calc
left_inv p i = (left_inv p i).comp (id 𝕜 F) : by simp
... = (left_inv p i).comp (p.comp (right_inv p i)) : by rw comp_right_inv p i h h0
... = ((left_inv p i).comp p).comp (right_inv p i) : by rw comp_assoc
... = (id 𝕜 E).comp (right_inv p i) : by rw left_inv_comp p i h
... = right_inv p i : by simp
/-- The left inverse and the right inverse of a formal multilinear series coincide. This is not at
all obvious from their definition, but it follows from uniqueness of inverses (which comes from the
fact that composition is associative on formal multilinear series). -/
theorem left_inv_eq_right_inv (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(h : p 1 = (continuous_multilinear_curry_fin1 𝕜 E F).symm i) :
left_inv p i = right_inv p i := calc
left_inv p i = left_inv p.remove_zero i : by rw left_inv_remove_zero
... = right_inv p.remove_zero i : by { apply left_inv_eq_right_inv_aux; simp [h] }
... = right_inv p i : by rw right_inv_remove_zero
/-!
### Convergence of the inverse of a power series
Assume that `p` is a convergent multilinear series, and let `q` be its (left or right) inverse.
Using the left-inverse formula gives
$$
q_n = - (p_1)^{-n} \sum_{k=0}^{n-1} \sum_{i_1 + \dotsc + i_k = n} q_k (p_{i_1}, \dotsc, p_{i_k}).
$$
Assume for simplicity that we are in dimension `1` and `p₁ = 1`. In the formula for `qₙ`, the term
`q_{n-1}` appears with a multiplicity of `n-1` (choosing the index `i_j` for which `i_j = 2` while
all the other indices are equal to `1`), which indicates that `qₙ` might grow like `n!`. This is
bad for summability properties.
It turns out that the right-inverse formula is better behaved, and should instead be used for this
kind of estimate. It reads
$$
q_n = - (p_1)^{-1} \sum_{k=2}^n \sum_{i_1 + \dotsc + i_k = n} p_k (q_{i_1}, \dotsc, q_{i_k}).
$$
Here, `q_{n-1}` can only appear in the term with `k = 2`, and it only appears twice, so there is
hope this formula can lead to an at most geometric behavior.
Let `Qₙ = ‖qₙ‖`. Bounding `‖pₖ‖` with `C r^k` gives an inequality
$$
Q_n ≤ C' \sum_{k=2}^n r^k \sum_{i_1 + \dotsc + i_k = n} Q_{i_1} \dotsm Q_{i_k}.
$$
This formula is not enough to prove by naive induction on `n` a bound of the form `Qₙ ≤ D R^n`.
However, assuming that the inequality above were an equality, one could get a formula for the
generating series of the `Qₙ`:
$$
\begin{align}
Q(z) & := \sum Q_n z^n = Q_1 z + C' \sum_{2 \leq k \leq n} \sum_{i_1 + \dotsc + i_k = n}
(r z^{i_1} Q_{i_1}) \dotsm (r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (\sum_{i_1 \geq 1} r z^{i_1} Q_{i_1})
\dotsm (\sum_{i_k \geq 1} r z^{i_k} Q_{i_k})
\\ & = Q_1 z + C' \sum_{k = 2}^\infty (r Q(z))^k
= Q_1 z + C' (r Q(z))^2 / (1 - r Q(z)).
\end{align}
$$
One can solve this formula explicitly. The solution is analytic in a neighborhood of `0` in `ℂ`,
hence its coefficients grow at most geometrically (by a contour integral argument), and therefore
the original `Qₙ`, which are bounded by these ones, are also at most geometric.
This classical argument is not really satisfactory, as it requires an a priori bound on a complex
analytic function. Another option would be to compute explicitly its terms (with binomial
coefficients) to obtain an explicit geometric bound, but this would be very painful.
Instead, we will use the above intuition, but in a slightly different form, with finite sums and an
induction. I learnt this trick in [pöschel2017siegelsternberg]. Let
$S_n = \sum_{k=1}^n Q_k a^k$ (where `a` is a positive real parameter to be chosen suitably small).
The above computation but with finite sums shows that
$$
S_n \leq Q_1 a + C' \sum_{k=2}^n (r S_{n-1})^k.
$$
In particular, $S_n \leq Q_1 a + C' (r S_{n-1})^2 / (1- r S_{n-1})$.
Assume that $S_{n-1} \leq K a$, where `K > Q₁` is fixed and `a` is small enough so that
`r K a ≤ 1/2` (to control the denominator). Then this equation gives a bound
$S_n \leq Q_1 a + 2 C' r^2 K^2 a^2$.
If `a` is small enough, this is bounded by `K a` as the second term is quadratic in `a`, and
therefore negligible.
By induction, we deduce `Sₙ ≤ K a` for all `n`, which gives in particular the fact that `aⁿ Qₙ`
remains bounded.
-/
/-- First technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in a general abstract setup. -/
lemma radius_right_inv_pos_of_radius_pos_aux1
(n : ℕ) (p : ℕ → ℝ) (hp : ∀ k, 0 ≤ p k) {r a : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) :
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
≤ ∑ j in Ico 2 (n + 1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :=
calc
∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, p (c.blocks_fun j))
= ∑ k in Ico 2 (n + 1),
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
∏ j, r * (a ^ (c.blocks_fun j) * p (c.blocks_fun j))) :
begin
simp_rw [mul_sum],
apply sum_congr rfl (λ k hk, _),
apply sum_congr rfl (λ c hc, _),
rw [prod_mul_distrib, prod_mul_distrib, prod_pow_eq_pow_sum, composition.sum_blocks_fun,
prod_const, card_fin],
ring,
end
... ≤ ∑ d in comp_partial_sum_target 2 (n + 1) n,
∏ (j : fin d.2.length), r * (a ^ d.2.blocks_fun j * p (d.2.blocks_fun j)) :
begin
rw sum_sigma',
refine sum_le_sum_of_subset_of_nonneg _ (λ x hx1 hx2,
prod_nonneg (λ j hj, mul_nonneg hr (mul_nonneg (pow_nonneg ha _) (hp _)))),
rintros ⟨k, c⟩ hd,
simp only [set.mem_to_finset, mem_Ico, mem_sigma, set.mem_set_of_eq] at hd,
simp only [mem_comp_partial_sum_target_iff],
refine ⟨hd.2, c.length_le.trans_lt hd.1.2, λ j, _⟩,
have : c ≠ composition.single k (zero_lt_two.trans_le hd.1.1),
by simp [composition.eq_single_iff_length, ne_of_gt hd.2],
rw composition.ne_single_iff at this,
exact (this j).trans_le (nat.lt_succ_iff.mp hd.1.2)
end
... = ∑ e in comp_partial_sum_source 2 (n+1) n, ∏ (j : fin e.1), r * (a ^ e.2 j * p (e.2 j)) :
begin
symmetry,
apply comp_change_of_variables_sum,
rintros ⟨k, blocks_fun⟩ H,
have K : (comp_change_of_variables 2 (n + 1) n ⟨k, blocks_fun⟩ H).snd.length = k, by simp,
congr' 2; try { rw K },
rw fin.heq_fun_iff K.symm,
assume j,
rw comp_change_of_variables_blocks_fun,
end
... = ∑ j in Ico 2 (n+1), r ^ j * (∑ k in Ico 1 n, a ^ k * p k) ^ j :
begin
rw [comp_partial_sum_source, ← sum_sigma' (Ico 2 (n + 1))
(λ (k : ℕ), (fintype.pi_finset (λ (i : fin k), Ico 1 n) : finset (fin k → ℕ)))
(λ n e, ∏ (j : fin n), r * (a ^ e j * p (e j)))],
apply sum_congr rfl (λ j hj, _),
simp only [← @multilinear_map.mk_pi_algebra_apply ℝ (fin j) _ ℝ],
simp only [← multilinear_map.map_sum_finset (multilinear_map.mk_pi_algebra ℝ (fin j) ℝ)
(λ k (m : ℕ), r * (a ^ m * p m))],
simp only [multilinear_map.mk_pi_algebra_apply],
dsimp,
simp [prod_const, ← mul_sum, mul_pow],
end
/-- Second technical lemma to control the growth of coefficients of the inverse. Bound the explicit
expression for `∑_{k<n+1} aᵏ Qₖ` in terms of a sum of powers of the same sum one step before,
in the specific setup we are interesting in, by reducing to the general bound in
`radius_right_inv_pos_of_radius_pos_aux1`. -/
lemma radius_right_inv_pos_of_radius_pos_aux2
{n : ℕ} (hn : 2 ≤ n + 1) (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
{r a C : ℝ} (hr : 0 ≤ r) (ha : 0 ≤ a) (hC : 0 ≤ C) (hp : ∀ n, ‖p n‖ ≤ C * r ^ n) :
(∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖) ≤
‖(i.symm : F →L[𝕜] E)‖ * a + ‖(i.symm : F →L[𝕜] E)‖ * C * ∑ k in Ico 2 (n + 1),
(r * ((∑ j in Ico 1 n, a ^ j * ‖p.right_inv i j‖))) ^ k :=
let I := ‖(i.symm : F →L[𝕜] E)‖ in calc
∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖
= a * I + ∑ k in Ico 2 (n + 1), a ^ k * ‖p.right_inv i k‖ :
by simp only [linear_isometry_equiv.norm_map, pow_one, right_inv_coeff_one,
nat.Ico_succ_singleton, sum_singleton, ← sum_Ico_consecutive _ one_le_two hn]
... = a * I + ∑ k in Ico 2 (n + 1), a ^ k *
‖(i.symm : F →L[𝕜] E).comp_continuous_multilinear_map
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
p.comp_along_composition (p.right_inv i) c)‖ :
begin
congr' 1,
apply sum_congr rfl (λ j hj, _),
rw [right_inv_coeff _ _ _ (mem_Ico.1 hj).1, norm_neg],
end
... ≤ a * ‖(i.symm : F →L[𝕜] E)‖ + ∑ k in Ico 2 (n + 1), a ^ k * (I *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
C * r ^ c.length * ∏ j, ‖p.right_inv i (c.blocks_fun j)‖)) :
begin
apply_rules [add_le_add, le_refl, sum_le_sum (λ j hj, _), mul_le_mul_of_nonneg_left,
pow_nonneg, ha],
apply (continuous_linear_map.norm_comp_continuous_multilinear_map_le _ _).trans,
apply mul_le_mul_of_nonneg_left _ (norm_nonneg _),
apply (norm_sum_le _ _).trans,
apply sum_le_sum (λ c hc, _),
apply (comp_along_composition_norm _ _ _).trans,
apply mul_le_mul_of_nonneg_right (hp _),
exact prod_nonneg (λ j hj, norm_nonneg _),
end
... = I * a + I * C * ∑ k in Ico 2 (n + 1), a ^ k *
(∑ c in ({c | 1 < composition.length c}.to_finset : finset (composition k)),
r ^ c.length * ∏ j, ‖p.right_inv i (c.blocks_fun j)‖) :
begin
simp_rw [mul_assoc C, ← mul_sum, ← mul_assoc, mul_comm _ (‖↑i.symm‖), mul_assoc, ← mul_sum,
← mul_assoc, mul_comm _ C, mul_assoc, ← mul_sum],
ring,
end
... ≤ I * a + I * C * ∑ k in Ico 2 (n+1), (r * ((∑ j in Ico 1 n, a ^ j * ‖p.right_inv i j‖))) ^ k :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, norm_nonneg, hC, mul_nonneg],
simp_rw [mul_pow],
apply radius_right_inv_pos_of_radius_pos_aux1 n (λ k, ‖p.right_inv i k‖)
(λ k, norm_nonneg _) hr ha,
end
/-- If a a formal multilinear series has a positive radius of convergence, then its right inverse
also has a positive radius of convergence. -/
theorem radius_right_inv_pos_of_radius_pos (p : formal_multilinear_series 𝕜 E F) (i : E ≃L[𝕜] F)
(hp : 0 < p.radius) : 0 < (p.right_inv i).radius :=
begin
obtain ⟨C, r, Cpos, rpos, ple⟩ : ∃ C r (hC : 0 < C) (hr : 0 < r), ∀ (n : ℕ), ‖p n‖ ≤ C * r ^ n :=
le_mul_pow_of_radius_pos p hp,
let I := ‖(i.symm : F →L[𝕜] E)‖,
-- choose `a` small enough to make sure that `∑_{k ≤ n} aᵏ Qₖ` will be controllable by
-- induction
obtain ⟨a, apos, ha1, ha2⟩ : ∃ a (apos : 0 < a),
(2 * I * C * r^2 * (I + 1) ^ 2 * a ≤ 1) ∧ (r * (I + 1) * a ≤ 1/2),
{ have : tendsto (λ a, 2 * I * C * r^2 * (I + 1) ^ 2 * a) (𝓝 0)
(𝓝 (2 * I * C * r^2 * (I + 1) ^ 2 * 0)) := tendsto_const_nhds.mul tendsto_id,
have A : ∀ᶠ a in 𝓝 0, 2 * I * C * r^2 * (I + 1) ^ 2 * a < 1,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have : tendsto (λ a, r * (I + 1) * a) (𝓝 0)
(𝓝 (r * (I + 1) * 0)) := tendsto_const_nhds.mul tendsto_id,
have B : ∀ᶠ a in 𝓝 0, r * (I + 1) * a < 1/2,
by { apply (tendsto_order.1 this).2, simp [zero_lt_one] },
have C : ∀ᶠ a in 𝓝[>] (0 : ℝ), (0 : ℝ) < a,
by { filter_upwards [self_mem_nhds_within] with _ ha using ha },
rcases (C.and ((A.and B).filter_mono inf_le_left)).exists with ⟨a, ha⟩,
exact ⟨a, ha.1, ha.2.1.le, ha.2.2.le⟩ },
-- check by induction that the partial sums are suitably bounded, using the choice of `a` and the
-- inductive control from Lemma `radius_right_inv_pos_of_radius_pos_aux2`.
let S := λ n, ∑ k in Ico 1 n, a ^ k * ‖p.right_inv i k‖,
have IRec : ∀ n, 1 ≤ n → S n ≤ (I + 1) * a,
{ apply nat.le_induction,
{ simp only [S],
rw [Ico_eq_empty_of_le (le_refl 1), sum_empty],
exact mul_nonneg (add_nonneg (norm_nonneg _) zero_le_one) apos.le },
{ assume n one_le_n hn,
have In : 2 ≤ n + 1, by linarith,
have Snonneg : 0 ≤ S n :=
sum_nonneg (λ x hx, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _)),
have rSn : r * S n ≤ 1/2 := calc
r * S n ≤ r * ((I+1) * a) : mul_le_mul_of_nonneg_left hn rpos.le
... ≤ 1/2 : by rwa [← mul_assoc],
calc S (n + 1) ≤ I * a + I * C * ∑ k in Ico 2 (n + 1), (r * S n)^k :
radius_right_inv_pos_of_radius_pos_aux2 In p i rpos.le apos.le Cpos.le ple
... = I * a + I * C * (((r * S n) ^ 2 - (r * S n) ^ (n + 1)) / (1 - r * S n)) :
by { rw geom_sum_Ico' _ In, exact ne_of_lt (rSn.trans_lt (by norm_num)) }
... ≤ I * a + I * C * ((r * S n) ^ 2 / (1/2)) :
begin
apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le],
refine div_le_div (sq_nonneg _) _ (by norm_num) (by linarith),
simp only [sub_le_self_iff],
apply pow_nonneg (mul_nonneg rpos.le Snonneg),
end
... = I * a + 2 * I * C * (r * S n) ^ 2 : by ring
... ≤ I * a + 2 * I * C * (r * ((I + 1) * a)) ^ 2 :
by apply_rules [add_le_add, le_refl, mul_le_mul_of_nonneg_left, mul_nonneg, norm_nonneg,
Cpos.le, zero_le_two, pow_le_pow_of_le_left, rpos.le]
... = (I + 2 * I * C * r^2 * (I + 1) ^ 2 * a) * a : by ring
... ≤ (I + 1) * a :
by apply_rules [mul_le_mul_of_nonneg_right, apos.le, add_le_add, le_refl] } },
-- conclude that all coefficients satisfy `aⁿ Qₙ ≤ (I + 1) a`.
let a' : nnreal := ⟨a, apos.le⟩,
suffices H : (a' : ennreal) ≤ (p.right_inv i).radius,
by { apply lt_of_lt_of_le _ H, exact_mod_cast apos },
apply le_radius_of_bound _ ((I + 1) * a) (λ n, _),
by_cases hn : n = 0,
{ have : ‖p.right_inv i n‖ = ‖p.right_inv i 0‖, by congr; try { rw hn },
simp only [this, norm_zero, zero_mul, right_inv_coeff_zero],
apply_rules [mul_nonneg, add_nonneg, norm_nonneg, zero_le_one, apos.le] },
{ have one_le_n : 1 ≤ n := bot_lt_iff_ne_bot.2 hn,
calc ‖p.right_inv i n‖ * ↑a' ^ n = a ^ n * ‖p.right_inv i n‖ : mul_comm _ _
... ≤ ∑ k in Ico 1 (n + 1), a ^ k * ‖p.right_inv i k‖ :
begin
have : ∀ k ∈ Ico 1 (n + 1), 0 ≤ a ^ k * ‖p.right_inv i k‖ :=
λ k hk, mul_nonneg (pow_nonneg apos.le _) (norm_nonneg _),
exact single_le_sum this (by simp [one_le_n]),
end
... ≤ (I + 1) * a : IRec (n + 1) (by dec_trivial) }
end
end formal_multilinear_series
|
b3b71f013a38aed6b52065647a5a2eac039e5096 | a0e23cfdd129a671bf3154ee1a8a3a72bf4c7940 | /tests/lean/run/def10.lean | eb0de93d1c6d4f1ebe54c6f003ccd4ef3e13773e | [
"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 | 413 | lean |
def f : Bool → Bool → Nat
| _, _ => 10
example : f true true = 10 :=
rfl
def g : Bool → Bool → Bool → Nat
| true, _, true => 1
| _, false, false => 2
| _, _, _ => 3
theorem ex1 : g true true true = 1 := rfl
theorem ex2 : g true false true = 1 := rfl
theorem ex3 : g true false false = 2 := rfl
theorem ex4 : g false false false = 2 := rfl
theorem ex5 : g false true true = 3 := rfl
|
09b70a5c3a157c494e6094d966bfe4002f1195d0 | 74addaa0e41490cbaf2abd313a764c96df57b05d | /Mathlib/Lean3Lib/init/meta/rec_util_auto.lean | 5e97a6f2ed97aed14e67d12c71b2b378d055a302 | [] | 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 | 448 | lean | /-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
Helper tactic for showing that a type has decidable equality.
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.meta.tactic
import Mathlib.Lean3Lib.init.data.option.basic
namespace Mathlib
namespace tactic
/-- Return tt iff e's type is of the form `(I_name ...)` -/
end Mathlib |
ed522d22ce5384fe0d1ecdaf41d65e1b74bc62c5 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/category_theory/abelian/subobject.lean | da3e05db28aab9843d83a368f9e7e4be1aef8475 | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 3,052 | lean | /-
Copyright (c) 2022 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import category_theory.abelian.opposite
import category_theory.subobject.limits
/-!
# Equivalence between subobjects and quotients in an abelian category
-/
open category_theory category_theory.limits opposite
universes v u
noncomputable theory
namespace category_theory.abelian
variables {C : Type u} [category.{v} C]
/-- In an abelian category, the subobjects and quotient objects of an object `X` are
order-isomorphic via taking kernels and cokernels.
Implemented here using subobjects in the opposite category,
since mathlib does not have a notion of quotient objects at the time of writing. -/
@[simps]
def subobject_iso_subobject_op [abelian C] (X : C) : subobject X ≃o (subobject (op X))ᵒᵈ :=
begin
refine order_iso.of_hom_inv (cokernel_order_hom X) (kernel_order_hom X) _ _,
{ change (cokernel_order_hom X).comp (kernel_order_hom X) = _,
refine order_hom.ext _ _ (funext (subobject.ind _ _)),
introsI A f hf,
dsimp only [order_hom.comp_coe, function.comp_app, kernel_order_hom_coe, subobject.lift_mk,
cokernel_order_hom_coe, order_hom.id_coe, id.def],
refine subobject.mk_eq_mk_of_comm _ _ ⟨_, _, quiver.hom.unop_inj _, quiver.hom.unop_inj _⟩ _,
{ exact (abelian.epi_desc f.unop _ (cokernel.condition (kernel.ι f.unop))).op },
{ exact (cokernel.desc _ _ (kernel.condition f.unop)).op },
{ simp only [← cancel_epi (cokernel.π (kernel.ι f.unop)), unop_comp, quiver.hom.unop_op,
unop_id_op, cokernel.π_desc_assoc, comp_epi_desc, category.comp_id] },
{ simp only [← cancel_epi f.unop, unop_comp, quiver.hom.unop_op, unop_id, comp_epi_desc_assoc,
cokernel.π_desc, category.comp_id] },
{ exact quiver.hom.unop_inj (by simp only [unop_comp, quiver.hom.unop_op, comp_epi_desc]) } },
{ change (kernel_order_hom X).comp (cokernel_order_hom X) = _,
refine order_hom.ext _ _ (funext (subobject.ind _ _)),
introsI A f hf,
dsimp only [order_hom.comp_coe, function.comp_app, cokernel_order_hom_coe, subobject.lift_mk,
kernel_order_hom_coe, order_hom.id_coe, id.def, unop_op, quiver.hom.unop_op],
refine subobject.mk_eq_mk_of_comm _ _ ⟨_, _, _, _⟩ _,
{ exact abelian.mono_lift f _ (kernel.condition (cokernel.π f)) },
{ exact kernel.lift _ _ (cokernel.condition f) },
{ simp only [← cancel_mono (kernel.ι (cokernel.π f)), category.assoc, image.fac, mono_lift_comp,
category.id_comp, auto_param_eq] },
{ simp only [← cancel_mono f, category.assoc, mono_lift_comp, image.fac, category.id_comp,
auto_param_eq] },
{ simp only [mono_lift_comp] } }
end
/-- A well-powered abelian category is also well-copowered. -/
instance well_powered_opposite [abelian C] [well_powered C] : well_powered Cᵒᵖ :=
{ subobject_small := λ X,
(small_congr (subobject_iso_subobject_op (unop X)).to_equiv).1 infer_instance }
end category_theory.abelian
|
2e92de4924e0186dcd2f5aa3c76528c271b1fdee | 4727251e0cd73359b15b664c3170e5d754078599 | /src/algebra/symmetrized.lean | 40c1a004829e5a8a8047b03a2e2ee0fa54eedabc | [
"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 | 8,819 | lean | /-
Copyright (c) 2021 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import algebra.module.basic
import tactic.abel
/-!
# Symmetrized algebra
A commutative multiplication on a real or complex space can be constructed from any multiplication
by "symmetrization" i.e
$$
a \circ b = \frac{1}{2}(ab + ba)
$$
We provide the symmetrized version of a type `α` as `sym_alg α`, with notation `αˢʸᵐ`.
## Implementation notes
The approach taken here is inspired by algebra.opposites. We use Oxford Spellings
(IETF en-GB-oxendict).
## References
* [Hanche-Olsen and Størmer, Jordan Operator Algebras][hancheolsenstormer1984]
-/
open function
/--
The symmetrized algebra has the same underlying space as the original algebra.
-/
def sym_alg (α : Type*) : Type* := α
postfix `ˢʸᵐ`:std.prec.max_plus := sym_alg
namespace sym_alg
variables {α : Type*}
/-- The element of `sym_alg α` that represents `a : α`. -/
@[pattern,pp_nodot]
def sym : α → αˢʸᵐ := id
/-- The element of `α` represented by `x : αˢʸᵐ`. -/
@[pp_nodot]
def unsym : αˢʸᵐ → α := id
@[simp] lemma unsym_sym (a : α) : unsym (sym a) = a := rfl
@[simp] lemma sym_unsym (a : α) : sym (unsym a) = a := rfl
@[simp] lemma sym_comp_unsym : (sym : α → αˢʸᵐ) ∘ unsym = id := rfl
@[simp] lemma unsym_comp_sym : (unsym : αˢʸᵐ → α) ∘ sym = id := rfl
/-- The canonical bijection between `α` and `αˢʸᵐ`. -/
@[simps apply symm_apply { fully_applied := ff }]
def sym_equiv : α ≃ αˢʸᵐ := ⟨sym, unsym, unsym_sym, sym_unsym⟩
lemma sym_bijective : bijective (sym : α → αˢʸᵐ) := sym_equiv.bijective
lemma unsym_bijective : bijective (unsym : αˢʸᵐ → α) := sym_equiv.symm.bijective
lemma sym_injective : injective (sym : α → αˢʸᵐ) := sym_bijective.injective
lemma sym_surjective : surjective (sym : α → αˢʸᵐ) := sym_bijective.surjective
lemma unsym_injective : injective (unsym : αˢʸᵐ → α) := unsym_bijective.injective
lemma unsym_surjective : surjective (unsym : αˢʸᵐ → α) := unsym_bijective.surjective
@[simp] lemma sym_inj {a b : α} : sym a = sym b ↔ a = b := sym_injective.eq_iff
@[simp] lemma unsym_inj {a b : αˢʸᵐ} : unsym a = unsym b ↔ a = b := unsym_injective.eq_iff
instance [nontrivial α] : nontrivial αˢʸᵐ := sym_injective.nontrivial
instance [inhabited α] : inhabited αˢʸᵐ := ⟨sym default⟩
instance [subsingleton α] : subsingleton αˢʸᵐ := unsym_injective.subsingleton
instance [unique α] : unique αˢʸᵐ := unique.mk' _
instance [is_empty α] : is_empty αˢʸᵐ := function.is_empty unsym
@[to_additive]
instance [has_one α] : has_one αˢʸᵐ := { one := sym 1 }
instance [has_add α] : has_add αˢʸᵐ :=
{ add := λ a b, sym (unsym a + unsym b) }
instance [has_sub α] : has_sub αˢʸᵐ := { sub := λ a b, sym (unsym a - unsym b) }
instance [has_neg α] : has_neg αˢʸᵐ :=
{ neg := λ a, sym (-unsym a) }
/- Introduce the symmetrized multiplication-/
instance [has_add α] [has_mul α] [has_one α] [invertible (2 : α)] : has_mul (αˢʸᵐ) :=
{ mul := λ a b, sym (⅟2 * (unsym a * unsym b + unsym b * unsym a)) }
@[to_additive] instance [has_inv α] : has_inv αˢʸᵐ :=
{ inv := λ a, sym $ (unsym a)⁻¹ }
instance (R : Type*) [has_scalar R α] : has_scalar R αˢʸᵐ :=
{ smul := λ r a, sym (r • unsym a) }
@[simp, to_additive] lemma sym_one [has_one α] : sym (1 : α) = 1 := rfl
@[simp, to_additive] lemma unsym_one [has_one α] : unsym (1 : αˢʸᵐ) = 1 := rfl
@[simp] lemma sym_add [has_add α] (a b : α) : sym (a + b) = sym a + sym b := rfl
@[simp] lemma unsym_add [has_add α] (a b : αˢʸᵐ) : unsym (a + b) = unsym a + unsym b := rfl
@[simp] lemma sym_sub [has_sub α] (a b : α) : sym (a - b) = sym a - sym b := rfl
@[simp] lemma unsym_sub [has_sub α] (a b : αˢʸᵐ) : unsym (a - b) = unsym a - unsym b := rfl
@[simp] lemma sym_neg [has_neg α] (a : α) : sym (-a) = -sym a := rfl
@[simp] lemma unsym_neg [has_neg α] (a : αˢʸᵐ) : unsym (-a) = -unsym a := rfl
lemma mul_def [has_add α] [has_mul α] [has_one α] [invertible (2 : α)] (a b : αˢʸᵐ) :
a * b = sym (⅟2*(unsym a * unsym b + unsym b * unsym a)) := by refl
lemma unsym_mul [has_mul α] [has_add α] [has_one α] [invertible (2 : α)] (a b : αˢʸᵐ) :
unsym (a * b) = ⅟2*(unsym a * unsym b + unsym b * unsym a) := by refl
lemma sym_mul_sym [has_mul α] [has_add α] [has_one α] [invertible (2 : α)] (a b : α) :
sym a * sym b = sym (⅟2*(a * b + b * a)) :=
rfl
@[simp, to_additive] lemma sym_inv [has_inv α] (a : α) : sym (a⁻¹) = (sym a)⁻¹ := rfl
@[simp, to_additive] lemma unsym_inv [has_inv α] (a : αˢʸᵐ) : unsym (a⁻¹) = (unsym a)⁻¹ := rfl
@[simp] lemma sym_smul {R : Type*} [has_scalar R α] (c : R) (a : α) : sym (c • a) = c • sym a := rfl
@[simp] lemma unsym_smul {R : Type*} [has_scalar R α] (c : R) (a : αˢʸᵐ) :
unsym (c • a) = c • unsym a := rfl
@[simp, to_additive] lemma unsym_eq_one_iff [has_one α] (a : αˢʸᵐ) : a.unsym = 1 ↔ a = 1 :=
unsym_injective.eq_iff' rfl
@[simp, to_additive] lemma sym_eq_one_iff [has_one α] (a : α) : sym a = 1 ↔ a = 1 :=
sym_injective.eq_iff' rfl
@[to_additive] lemma unsym_ne_one_iff [has_one α] (a : αˢʸᵐ) : a.unsym ≠ (1 : α) ↔ a ≠ (1 : αˢʸᵐ) :=
not_congr $ unsym_eq_one_iff a
@[to_additive] lemma sym_ne_one_iff [has_one α] (a : α) : sym a ≠ (1 : αˢʸᵐ) ↔ a ≠ (1 : α) :=
not_congr $ sym_eq_one_iff a
instance [add_comm_semigroup α] : add_comm_semigroup (αˢʸᵐ) :=
unsym_injective.add_comm_semigroup _ unsym_add
instance [add_monoid α] : add_monoid (αˢʸᵐ) :=
unsym_injective.add_monoid _ unsym_zero unsym_add (λ _ _, rfl)
instance [add_group α] : add_group (αˢʸᵐ) :=
unsym_injective.add_group _ unsym_zero
unsym_add unsym_neg unsym_sub (λ _ _, rfl) (λ _ _, rfl)
instance [add_comm_monoid α] : add_comm_monoid (αˢʸᵐ) :=
{ ..sym_alg.add_comm_semigroup, ..sym_alg.add_monoid }
instance [add_comm_group α] : add_comm_group (αˢʸᵐ) :=
{ ..sym_alg.add_comm_monoid, ..sym_alg.add_group }
instance {R : Type*} [semiring R] [add_comm_monoid α] [module R α] : module R αˢʸᵐ :=
function.injective.module R ⟨unsym, unsym_zero, unsym_add⟩ unsym_injective unsym_smul
instance [has_mul α] [has_add α] [has_one α] [invertible (2 : α)] (a : α) [invertible a] :
invertible (sym a) :=
{ inv_of := sym (⅟a),
inv_of_mul_self := begin
rw [sym_mul_sym, mul_inv_of_self, inv_of_mul_self, ←bit0, inv_of_mul_self, sym_one],
end,
mul_inv_of_self := begin
rw [sym_mul_sym, mul_inv_of_self, inv_of_mul_self, ←bit0, inv_of_mul_self, sym_one],
end }
@[simp] lemma inv_of_sym [has_mul α] [has_add α] [has_one α] [invertible (2 : α)] (a : α)
[invertible a] : ⅟(sym a) = sym (⅟a) := rfl
instance [semiring α] [invertible (2 : α)] : non_assoc_semiring (αˢʸᵐ) :=
{ one := 1,
mul := (*),
zero := (0),
zero_mul := λ _, by rw [mul_def, unsym_zero, zero_mul, mul_zero, add_zero, mul_zero, sym_zero],
mul_zero := λ _, by rw [mul_def, unsym_zero, zero_mul, mul_zero, add_zero, mul_zero, sym_zero],
mul_one := λ _, by rw [mul_def, unsym_one, mul_one, one_mul, ←two_mul, inv_of_mul_self_assoc,
sym_unsym],
one_mul := λ _, by rw [mul_def, unsym_one, mul_one, one_mul, ←two_mul, inv_of_mul_self_assoc,
sym_unsym],
left_distrib := λ a b c, match a, b, c with
| sym a, sym b, sym c := begin
rw [sym_mul_sym, sym_mul_sym, ←sym_add, sym_mul_sym, ←sym_add, mul_add a, add_mul _ _ a,
add_add_add_comm, mul_add],
end
end,
right_distrib := λ a b c, match a, b, c with
| sym a, sym b, sym c := begin
rw [sym_mul_sym, sym_mul_sym, ←sym_add, sym_mul_sym, ←sym_add, mul_add c, add_mul _ _ c,
add_add_add_comm, mul_add],
end
end,
..sym_alg.add_comm_monoid, }
/-- The symmetrization of a real (unital, associative) algebra is a non-associative ring. -/
instance [ring α] [invertible (2 : α)] : non_assoc_ring (αˢʸᵐ) :=
{ ..sym_alg.non_assoc_semiring,
..sym_alg.add_comm_group, }
/-! The squaring operation coincides for both multiplications -/
lemma unsym_mul_self [semiring α] [invertible (2 : α)] (a : αˢʸᵐ) :
unsym (a*a) = unsym a * unsym a :=
by rw [mul_def, unsym_sym, ←two_mul, inv_of_mul_self_assoc]
lemma sym_mul_self [semiring α] [invertible (2 : α)] (a : α) : sym (a*a) = sym a * sym a :=
by rw [sym_mul_sym, ←two_mul, inv_of_mul_self_assoc]
lemma mul_comm [has_mul α] [add_comm_semigroup α] [has_one α] [invertible (2 : α)] (a b : αˢʸᵐ) :
a * b = b * a :=
by rw [mul_def, mul_def, add_comm]
end sym_alg
|
f9a442a9e61e281e6d6693db4a009ddbfc939a3f | b7f22e51856f4989b970961f794f1c435f9b8f78 | /tests/lean/record_rec_protected.lean | a84cdf02bb0efa9b9ffdcea09274777eaa064109 | [
"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 | 141 | lean | import logic data.unit
structure point (A : Type) (B : Type) :=
mk :: (x : A) (y : B)
open point
check rec -- error, rec is protected
|
208dc948b83c15aa64a944a10d47222676466890 | c1a29ca460720df88ab68dc42d9a1a02e029d505 | /examples/basics/calculating_2_1.lean | 82b28bebb469aa02f43a960bd913bfe248ca0470 | [] | no_license | agusakov/mathematics_in_lean | acb5b3d659e4522ae4b4836ea550527f03f6546c | 2539562e4d91c858c73dbecb5b282ce1a7d38b6d | refs/heads/master | 1,665,963,365,241 | 1,592,080,022,000 | 1,592,080,022,000 | 272,078,062 | 0 | 0 | null | 1,592,078,772,000 | 1,592,078,772,000 | null | UTF-8 | Lean | false | false | 11,503 | lean | import data.real.basic
variables a b c d e f : ℝ
/-We generally learn to carry out mathematical calculations without
thinking of them as proofs. But when we justify each step in a calculation,
as Lean requires us to do, the net result is a proof that the left-hand side
of the calculation is equal to the right-hand side.
In Lean, stating a theorem is tantamount to stating a goal, namely, the
goal of proving the theorem. Lean provides the rewrite tactic, abbreviated rw,
to replace the left-hand side of an identity by the right-hand side in the goal.
If a, b, and c are real numbers, mul_assoc a b c is the identity a * b * c = a * (b * c)
and mul_comm a b is the identity a * b = b * a. In Lean, multiplication associates
to the left, so the left-hand side of mul_assoc could also be written (a * b) * c.
However, it is generally good style to be mindful of Lean’s notational conventions
and leave out parentheses when Lean does as well.
Let’s try out rw.-/
example (a b c : ℝ) : (a * b) * c = b * (a * c) :=
begin
rw mul_comm a b,
rw mul_assoc b a c
end
/-As you move your cursor past each step of the proof, you can see the
goal of the proof change. The import line at the beginning of the example
imports the theory of the real numbers from mathlib. For the sake of brevity,
we generally suppress information like this when it is repeated from example
to example. Clicking the try it! button displays all the example as it is meant
to be processed and checked by Lean.
You can type the ℝ character as \R or \real in the VS Code editor. The symbol doesn’t
appear until you hit space or the tab key. If you hover over a symbol when reading a
Lean file, VS Code will show you the syntax that can be used to enter it. If your
keyboard does not have a backslash, you can change the leading character by changing
the lean.input.leader setting in VS Code.
Try proving these identities, in each case replacing sorry by a tactic proof. With
the rw tactic, you can use a left arrow (\l) to reverse an identity. For example,
rw ← mul_assoc a b c replaces a * (b * c) by a * b * c in the current goal.-/
-- BEGIN
example (a b c : ℝ) : (c * b) * a = b * (a * c) :=
begin
rw mul_assoc,
rw mul_comm,
rw mul_assoc,
end
example (a b c : ℝ) : a * (b * c) = b * (a * c) :=
begin
rw ← mul_assoc,
rw mul_comm a b,
rw mul_assoc,
end
-- END
/-You can also use identities like mul_assoc and mul_comm without arguments.
In this case, the rewrite tactic tries to match the left-hand side with an
expression in the goal, using the first pattern it finds.
-/
-- BEGIN
example (a b c : ℝ) : a * b * c = b * c * a :=
begin
rw mul_assoc,
rw mul_comm,
end
-- END
/-You can also provide partial information. For example, mul_comm a matches
any pattern of the form a * ? and rewrites it to ? * a. Try doing the first of
these examples without providing any arguments at all, and the second with only
one argument.
-/
-- BEGIN
example (a b c : ℝ) : a * (b * c) = b * (c * a) :=
begin
rw mul_comm,
rw mul_assoc,
end
example (a b c : ℝ) : a * (b * c) = b * (a * c) :=
begin
rw ← mul_assoc,
rw mul_comm a b,
rw mul_assoc,
end
-- END
/-
In the Lean editor mode, when a cursor is in the middle of a tactic proof,
Lean reports on the current proof state. A typical proof state in Lean might
look as follows:
1 goal
x y : ℕ,
h₁ : prime x,
h₂ : ¬even x,
h₃ : y > x
⊢ y ≥ 4
The lines before the one that begins with ⊢ denote the context:
they are the objects and assumptions currently at play. In this example,
these include two objects, x and y, each a natural number. They also include
three assumptions, labelled h₁, h₂, and h₃. In Lean, everything in a context
is labelled with an identifier. You can type these subscripted labels as
h\1, h\2, and h\3, but any legal identifiers would do:
you can use h1, h2, h3 instead, or foo, bar, and baz.
The last line represents the goal, that is, the fact to be proved.
Sometimes people use target for the fact to be proved, and goal for the
combination of the context and the target. In practice, the intended meaning
is usually clear.
You an also use rw with facts from the local context.
-/
-- BEGIN
example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
begin
rw h',
rw ←mul_assoc,
rw h,
rw mul_assoc
end
-- END
/-
Try these:
For the second one, you can use the theorem sub_self, where
sub_self a is the identity a - a = 0.
-/
-- BEGIN
example (a b c d e f : ℝ) (h : b * c = e * f) :
a * b * c * d = a * e * f * d :=
begin
repeat {rw mul_assoc},
rw ← mul_assoc b c d,
rw h,
repeat {rw ← mul_assoc},
end
example (a b c d : ℝ) (hyp : c = b * a - d) (hyp' : d = a * b) : c = 0 :=
begin
rw hyp' at hyp,
rw mul_comm a b at hyp,
rw sub_self at hyp,
exact hyp,
end
-- END
/-
We now introduce some useful features of Lean. First, multiple rewrite
commands can be carried out with a single command, by listing the relevant
identities within square brackets. Second, when a tactic proof is just a
single command, we can replace the begin ... end block with a by.
-/
-- BEGIN
example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
begin
rw [h', ←mul_assoc, h, mul_assoc]
end
example (a b c d e f : ℝ) (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
by rw [h', ←mul_assoc, h, mul_assoc]
-- END
/-
You still see the incremental progress by placing the cursor after
a comma in any list of rewrites.
Another trick is that we can declare variables once and forall outside
an example or theorem. When Lean sees them mentioned in the statement
of the theorem, it includes them automatically.-/
-- BEGIN
-- a b c d e f : ℝ
example (h : a * b = c * d) (h' : e = f) :
a * (b * e) = c * (d * f) :=
by rw [h', ←mul_assoc, h, mul_assoc]
-- END
/-We can delimit the scope of the declaration by putting it in a
section ... end block. Finally, Lean provides us with a command to
determine the type of an expression:
-/
-- BEGIN
section
-- a b c : ℝ
#check a
#check a + b
#check (a : ℝ)
#check mul_comm a b
#check (mul_comm a b : a * b = b * a)
#check mul_assoc c a b
#check mul_comm a
#check mul_comm
#check @mul_comm
#check mul_add a b c
#check add_mul a b c
#check add_comm
end
-- END
/-
The #check command works for both objects and facts. In
response to the command #check a, Lean reports that a has type ℝ.
In response to the command #check mul_comm a b, Lean reports that
mul_comm a b is a proof of the fact a * b = b * a. The command
#check (a : ℝ) states our expectation that the type of a is ℝ, and
Lean will raise an error if that is not the case. We will explain
the output of the last three #check commands later, but in the meanwhile,
you can take a look at them, and experiment with some #check commands
of your own.
Let’s try some more examples. The theorem two_mul a says that
a + a = 2 * a. The theorems add_mul and mul_add express the
distributivity of multiplication over addition, and the
theorem add_assoc expresses the associativity of addition.
Use the #check command to see the precise statements.-/
-- a b : ℝ
-- BEGIN
example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
begin
rw [mul_add, add_mul, add_mul],
rw [←add_assoc, add_assoc (a * a)],
rw [mul_comm b a, ←two_mul]
end
-- END
/-Whereas it is possible to figure out what it going on in this
proof by stepping through it in the editor, it is hard to read on its
own. Lean provides a more structured way of writing proofs like this
using the calc keyword.
-/
-- BEGIN
example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
calc
(a + b) * (a + b)
= a * a + b * a + (a * b + b * b) :
by rw [mul_add, add_mul, add_mul]
... = a * a + (b * a + a * b) + b * b :
by rw [←add_assoc, add_assoc (a * a)]
... = a * a + 2 * (a * b) + b * b :
by rw [mul_comm b a, ←two_mul]
-- END
/-Notice that there is no more begin ... end block:
an expression that begins with calc is a proof term.
A calc expression can also be used inside a tactic proof,
but Lean interprets it as the instruction to use the
resulting proof term to solve the goal.
The calc syntax is finicky: the dots and colons and justification
have to be in the format indicated above. Lean ignores whitespace
like spaces, tabs, and returns, so you have some flexibility to
make the calculation look more attractive. One way to write a calc
proof is to outline it first using the sorry tactic for justification,
make sure Lean accepts the expression modulo these, and then justify
the individual steps using tactics.-/
-- a b : ℝ
-- BEGIN
example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
calc
(a + b) * (a + b)
= a * a + b * a + (a * b + b * b) :
begin
sorry
end
... = a * a + (b * a + a * b) + b * b : by sorry
... = a * a + 2 * (a * b) + b * b : by sorry
-- END
/-Try proving the following identity using both a pure rw proof
and a more structured calc proof:
-/
-- a b c d : ℝ
-- BEGIN
example : (a + b) * (c + d) = a * c + a * d + b * c + b * d :=
calc
(a + b) * (c + d)
= a * c + b * c + (a * d + b * d) :
by rw [mul_add, add_mul, add_mul]
... = a * c + (b * c + a * d) + b * d :
by rw [←add_assoc, add_assoc (a * c)]
... = a * c + a * d + b * c + b * d :
by rw [add_comm (b*c) (a*d), ← add_assoc]
-- END
/-The following exercise is a little more challenging.
You can use the theorems listed underneath.
-/
-- a b c d : ℝ
-- BEGIN
example (a b : ℝ) : (a + b) * (a - b) = a^2 - b^2 :=
calc
(a + b) * (a - b)
= a * a + b * a - (a * b + b * b) :
by rw [mul_sub, add_mul, add_mul]
... = a * a + (a * b - a * b - b * b) :
by rw [← add_sub, ← sub_sub, mul_comm b a]
... = a * a - b * b :
by rw [sub_self (a*b), add_sub, add_zero]
... = a^2 - b^2 :
by rw [pow_two, pow_two]
#check pow_two a
#check mul_sub a b c
#check add_mul a b c
#check add_sub a b c
#check sub_sub a b c
#check add_zero a
-- END
/-We can also perform rewriting in an assumption in the context.
For example, rw mul_comm a b at hyp replaces a*b by b*a
in the assumption hyp.
-/
-- a b c d : ℝ
-- BEGIN
example (a b c d : ℝ) (hyp : c = d * a + b) (hyp' : b = a * d) :
c = 2 * a * d :=
begin
rw hyp' at hyp,
rw mul_comm d a at hyp,
rw ← two_mul (a*d) at hyp,
rw ← mul_assoc 2 a d at hyp,
exact hyp
end
-- END
/-In the last step, the exact tactic can use hyp to solve the
goal because at that point hyp matches the goal exactly.
We close this section by noting that mathlib provides a
useful bit of automation with a ring tactic, which is
designed to prove identities in any ring.-/
-- a b c d : ℝ
-- BEGIN
example : (c * b) * a = b * (a * c) :=
by ring
example : (a + b) * (a + b) = a * a + 2 * (a * b) + b * b :=
by ring
example : (a + b) * (a - b) = a^2 - b^2 :=
by ring
example (hyp : c = d * a + b) (hyp' : b = a * d) :
c = 2 * a * d :=
begin
rw [hyp, hyp'],
ring
end
-- END
/-The ring tactic is imported indirectly when we
import data.real.basic, but we will see in the next
section that it can be used for calculations on structures
other than the real numbers. It can be imported explicitly
with the command import tactic.
-/
|
dbee487c2df02fc1d2ed14e87220d237c5aa1035 | 80cc5bf14c8ea85ff340d1d747a127dcadeb966f | /src/data/pfunctor/univariate/M.lean | 303c186ca28df2652f096c60b64caeb737c81062 | [
"Apache-2.0"
] | permissive | lacker/mathlib | f2439c743c4f8eb413ec589430c82d0f73b2d539 | ddf7563ac69d42cfa4a1bfe41db1fed521bd795f | refs/heads/master | 1,671,948,326,773 | 1,601,479,268,000 | 1,601,479,268,000 | 298,686,743 | 0 | 0 | Apache-2.0 | 1,601,070,794,000 | 1,601,070,794,000 | null | UTF-8 | Lean | false | false | 21,955 | lean | /-
Copyright (c) 2017 Simon Hudon All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Simon Hudon
-/
import data.pfunctor.univariate.basic
/-!
# M-types
M types are potentially infinite tree-like structures. They are defined
as the greatest fixpoint of a polynomial functor.
-/
universes u v w
open nat function list (hiding head')
variables (F : pfunctor.{u})
local prefix `♯`:0 := cast (by simp [*] <|> cc <|> solve_by_elim)
namespace pfunctor
namespace approx
/-- `cofix_a F n` is an `n` level approximation of a M-type -/
inductive cofix_a : ℕ → Type u
| continue : cofix_a 0
| intro {n} : ∀ a, (F.B a → cofix_a n) → cofix_a (succ n)
/-- default inhabitant of `cofix_a` -/
protected def cofix_a.default [inhabited F.A] : Π n, cofix_a F n
| 0 := cofix_a.continue
| (succ n) := cofix_a.intro (default _) $ λ _, cofix_a.default n
instance [inhabited F.A] {n} : inhabited (cofix_a F n) := ⟨ cofix_a.default F n ⟩
lemma cofix_a_eq_zero : ∀ x y : cofix_a F 0, x = y
| cofix_a.continue cofix_a.continue := rfl
variables {F}
/--
The label of the root of the tree for a non-trivial
approximation of the cofix of a pfunctor.
-/
def head' : Π {n}, cofix_a F (succ n) → F.A
| n (cofix_a.intro i _) := i
/-- for a non-trivial approximation, return all the subtrees of the root -/
def children' : Π {n} (x : cofix_a F (succ n)), F.B (head' x) → cofix_a F n
| n (cofix_a.intro a f) := f
lemma approx_eta {n : ℕ} (x : cofix_a F (n+1)) :
x = cofix_a.intro (head' x) (children' x) :=
by cases x; refl
/-- Relation between two approximations of the cofix of a pfunctor that state they both contain the same
data until one of them is truncated -/
inductive agree : ∀ {n : ℕ}, cofix_a F n → cofix_a F (n+1) → Prop
| continue (x : cofix_a F 0) (y : cofix_a F 1) : agree x y
| intro {n} {a} (x : F.B a → cofix_a F n) (x' : F.B a → cofix_a F (n+1)) :
(∀ i : F.B a, agree (x i) (x' i)) →
agree (cofix_a.intro a x) (cofix_a.intro a x')
/--
Given an infinite series of approximations `approx`,
`all_agree approx` states that they are all consistent with each other.
-/
def all_agree (x : Π n, cofix_a F n) :=
∀ n, agree (x n) (x (succ n))
@[simp]
lemma agree_trival {x : cofix_a F 0} {y : cofix_a F 1} :
agree x y :=
by { constructor }
lemma agree_children {n : ℕ} (x : cofix_a F (succ n)) (y : cofix_a F (succ n+1))
{i j} (h₀ : i == j) (h₁ : agree x y) :
agree (children' x i) (children' y j) :=
begin
cases h₁, cases h₀,
apply h₁_a_1,
end
/-- `truncate a` turns `a` into a more limited approximation -/
def truncate : ∀ {n : ℕ}, cofix_a F (n+1) → cofix_a F n
| 0 (cofix_a.intro _ _) := cofix_a.continue
| (succ n) (cofix_a.intro i f) := cofix_a.intro i $ truncate ∘ f
lemma truncate_eq_of_agree {n : ℕ} (x : cofix_a F n) (y : cofix_a F (succ n)) (h : agree x y) :
truncate y = x :=
begin
induction n generalizing x y; cases x; cases y,
{ refl },
{ cases h with _ _ _ _ _ h₀ h₁,
cases h,
simp only [truncate, function.comp, true_and, eq_self_iff_true, heq_iff_eq],
ext y, apply n_ih,
apply h₁ }
end
variables {X : Type w}
variables (f : X → F.obj X)
/-- `s_corec f i n` creates an approximation of height `n`
of the final coalgebra of `f` -/
def s_corec : Π (i : X) n, cofix_a F n
| _ 0 := cofix_a.continue
| j (succ n) := cofix_a.intro (f j).1 (λ i, s_corec ((f j).2 i) _)
lemma P_corec (i : X) (n : ℕ) : agree (s_corec f i n) (s_corec f i (succ n)) :=
begin
induction n with n generalizing i,
constructor,
cases h : f i with y g,
constructor,
introv,
apply n_ih,
end
/-- `path F` provides indices to access internal nodes in `corec F` -/
def path (F : pfunctor.{u}) := list F.Idx
instance path.inhabited : inhabited (path F) := ⟨ [] ⟩
open list nat
instance : subsingleton (cofix_a F 0) :=
⟨ by { intros, casesm* cofix_a F 0, refl } ⟩
lemma head_succ' (n m : ℕ) (x : Π n, cofix_a F n) (Hconsistent : all_agree x) :
head' (x (succ n)) = head' (x (succ m)) :=
begin
suffices : ∀ n, head' (x (succ n)) = head' (x 1),
{ simp [this] },
clear m n, intro,
cases h₀ : x (succ n) with _ i₀ f₀,
cases h₁ : x 1 with _ i₁ f₁,
dsimp only [head'],
induction n with n,
{ rw h₁ at h₀, cases h₀, trivial },
{ have H := Hconsistent (succ n),
cases h₂ : x (succ n) with _ i₂ f₂,
rw [h₀,h₂] at H,
apply n_ih (truncate ∘ f₀),
rw h₂,
cases H,
congr, funext j, dsimp only [comp_app],
rw truncate_eq_of_agree,
apply H_a_1 }
end
end approx
open approx
/-- Internal definition for `M`. It is needed to avoid name clashes
between `M.mk` and `M.cases_on` and the declarations generated for
the structure -/
structure M_intl :=
(approx : ∀ n, cofix_a F n)
(consistent : all_agree approx)
/-- For polynomial functor `F`, `M F` is its final coalgebra -/
def M := M_intl F
lemma M.default_consistent [inhabited F.A] : Π n, agree (default (cofix_a F n)) (default (cofix_a F (succ n)))
| 0 := agree.continue _ _
| (succ n) := agree.intro _ _ $ λ _, M.default_consistent n
instance M.inhabited [inhabited F.A] : inhabited (M F) :=
⟨ { approx := λ n, default _,
consistent := M.default_consistent _ } ⟩
instance M_intl.inhabited [inhabited F.A] : inhabited (M_intl F) :=
show inhabited (M F), by apply_instance
namespace M
lemma ext' (x y : M F) (H : ∀ i : ℕ, x.approx i = y.approx i) : x = y :=
by { cases x, cases y, congr' with n, apply H }
variables {X : Type*}
variables (f : X → F.obj X)
variables {F}
/-- Corecursor for the M-type defined by `F`. -/
protected def corec (i : X) : M F :=
{ approx := s_corec f i,
consistent := P_corec _ _ }
variables {F}
/-- given a tree generated by `F`, `head` gives us the first piece of data
it contains -/
def head (x : M F) :=
head' (x.1 1)
/-- return all the subtrees of the root of a tree `x : M F` -/
def children (x : M F) (i : F.B (head x)) : M F :=
let H := λ n : ℕ, @head_succ' _ n 0 x.1 x.2 in
{ approx := λ n, children' (x.1 _) (cast (congr_arg _ $ by simp only [head,H]; refl) i),
consistent :=
begin
intro,
have P' := x.2 (succ n),
apply agree_children _ _ _ P',
transitivity i,
apply cast_heq,
symmetry,
apply cast_heq,
end }
/-- select a subtree using a `i : F.Idx` or return an arbitrary tree if
`i` designates no subtree of `x` -/
def ichildren [inhabited (M F)] [decidable_eq F.A] (i : F.Idx) (x : M F) : M F :=
if H' : i.1 = head x
then children x (cast (congr_arg _ $ by simp only [head,H']; refl) i.2)
else default _
lemma head_succ (n m : ℕ) (x : M F) :
head' (x.approx (succ n)) = head' (x.approx (succ m)) :=
head_succ' n m _ x.consistent
lemma head_eq_head' : Π (x : M F) (n : ℕ),
head x = head' (x.approx $ n+1)
| ⟨x,h⟩ n := head_succ' _ _ _ h
lemma head'_eq_head : Π (x : M F) (n : ℕ),
head' (x.approx $ n+1) = head x
| ⟨x,h⟩ n := head_succ' _ _ _ h
lemma truncate_approx (x : M F) (n : ℕ) :
truncate (x.approx $ n+1) = x.approx n :=
truncate_eq_of_agree _ _ (x.consistent _)
/-- unfold an M-type -/
def dest : M F → F.obj (M F)
| x := ⟨head x,λ i, children x i ⟩
namespace approx
/-- generates the approximations needed for `M.mk` -/
protected def s_mk (x : F.obj $ M F) : Π n, cofix_a F n
| 0 := cofix_a.continue
| (succ n) := cofix_a.intro x.1 (λ i, (x.2 i).approx n)
protected lemma P_mk (x : F.obj $ M F)
: all_agree (approx.s_mk x)
| 0 := by { constructor }
| (succ n) := by { constructor, introv,
apply (x.2 i).consistent }
end approx
/-- constructor for M-types -/
protected def mk (x : F.obj $ M F) : M F :=
{ approx := approx.s_mk x,
consistent := approx.P_mk x }
/-- `agree' n` relates two trees of type `M F` that
are the same up to dept `n` -/
inductive agree' : ℕ → M F → M F → Prop
| trivial (x y : M F) : agree' 0 x y
| step {n : ℕ} {a} (x y : F.B a → M F) {x' y'} :
x' = M.mk ⟨a,x⟩ →
y' = M.mk ⟨a,y⟩ →
(∀ i, agree' n (x i) (y i)) →
agree' (succ n) x' y'
@[simp]
lemma dest_mk (x : F.obj $ M F) :
dest (M.mk x) = x :=
begin
funext i,
dsimp only [M.mk,dest],
cases x with x ch, congr' with i,
cases h : ch i,
simp only [children,M.approx.s_mk,children',cast_eq],
dsimp only [M.approx.s_mk,children'],
congr, rw h,
end
@[simp] lemma mk_dest (x : M F) :
M.mk (dest x) = x :=
begin
apply ext', intro n,
dsimp only [M.mk],
induction n with n,
{ apply subsingleton.elim },
dsimp only [approx.s_mk,dest,head],
cases h : x.approx (succ n) with _ hd ch,
have h' : hd = head' (x.approx 1),
{ rw [← head_succ' n,h,head'], apply x.consistent },
revert ch, rw h', intros, congr,
{ ext a, dsimp only [children],
h_generalize! hh : a == a'',
rw h, intros, cases hh, refl },
end
lemma mk_inj {x y : F.obj $ M F}
(h : M.mk x = M.mk y) : x = y :=
by rw [← dest_mk x,h,dest_mk]
/-- destructor for M-types -/
protected def cases {r : M F → Sort w}
(f : ∀ (x : F.obj $ M F), r (M.mk x)) (x : M F) : r x :=
suffices r (M.mk (dest x)),
by { haveI := classical.prop_decidable,
haveI := inhabited.mk x,
rw [← mk_dest x], exact this },
f _
/-- destructor for M-types -/
protected def cases_on {r : M F → Sort w}
(x : M F) (f : ∀ (x : F.obj $ M F), r (M.mk x)) : r x :=
M.cases f x
/-- destructor for M-types, similar to `cases_on` but also
gives access directly to the root and subtrees on an M-type -/
protected def cases_on' {r : M F → Sort w}
(x : M F) (f : ∀ a f, r (M.mk ⟨a,f⟩)) : r x :=
M.cases_on x (λ ⟨a,g⟩, f a _)
lemma approx_mk (a : F.A) (f : F.B a → M F) (i : ℕ) :
(M.mk ⟨a, f⟩).approx (succ i) = cofix_a.intro a (λ j, (f j).approx i) :=
rfl
@[simp] lemma agree'_refl {n : ℕ} (x : M F) :
agree' n x x :=
by { induction n generalizing x; induction x using pfunctor.M.cases_on';
constructor; try { refl }, intros, apply n_ih }
lemma agree_iff_agree' {n : ℕ} (x y : M F) :
agree (x.approx n) (y.approx $ n+1) ↔ agree' n x y :=
begin
split; intros h,
{ induction n generalizing x y, constructor,
{ induction x using pfunctor.M.cases_on',
induction y using pfunctor.M.cases_on',
simp only [approx_mk] at h, cases h,
constructor; try { refl },
intro i, apply n_ih, apply h_a_1 } },
{ induction n generalizing x y, constructor,
{ cases h,
induction x using pfunctor.M.cases_on',
induction y using pfunctor.M.cases_on',
simp only [approx_mk],
replace h_a_1 := mk_inj h_a_1, cases h_a_1,
replace h_a_2 := mk_inj h_a_2, cases h_a_2,
constructor, intro i, apply n_ih, apply h_a_3 } },
end
@[simp]
lemma cases_mk {r : M F → Sort*} (x : F.obj $ M F) (f : Π (x : F.obj $ M F), r (M.mk x)) :
pfunctor.M.cases f (M.mk x) = f x :=
begin
dsimp only [M.mk,pfunctor.M.cases,dest,head,approx.s_mk,head'],
cases x, dsimp only [approx.s_mk],
apply eq_of_heq,
apply rec_heq_of_heq, congr' with x,
dsimp only [children,approx.s_mk,children'],
cases h : x_snd x, dsimp only [head],
congr' with n, change (x_snd (x)).approx n = _, rw h
end
@[simp]
lemma cases_on_mk {r : M F → Sort*} (x : F.obj $ M F) (f : Π x : F.obj $ M F, r (M.mk x)) :
pfunctor.M.cases_on (M.mk x) f = f x :=
cases_mk x f
@[simp]
lemma cases_on_mk' {r : M F → Sort*} {a} (x : F.B a → M F) (f : Π a (f : F.B a → M F), r (M.mk ⟨a,f⟩)) :
pfunctor.M.cases_on' (M.mk ⟨a,x⟩) f = f a x :=
cases_mk ⟨_,x⟩ _
/-- `is_path p x` tells us if `p` is a valid path through `x` -/
inductive is_path : path F → M F → Prop
| nil (x : M F) : is_path [] x
| cons (xs : path F) {a} (x : M F) (f : F.B a → M F) (i : F.B a) :
x = M.mk ⟨a,f⟩ →
is_path xs (f i) →
is_path (⟨a,i⟩ :: xs) x
lemma is_path_cons {xs : path F} {a a'} {f : F.B a → M F} {i : F.B a'}
(h : is_path (⟨a',i⟩ :: xs) (M.mk ⟨a,f⟩)) :
a = a' :=
begin
revert h, generalize h : (M.mk ⟨a,f⟩) = x,
intros h', cases h', subst x,
cases mk_inj h'_a_1, refl,
end
lemma is_path_cons' {xs : path F} {a} {f : F.B a → M F} {i : F.B a}
(h : is_path (⟨a,i⟩ :: xs) (M.mk ⟨a,f⟩)) :
is_path xs (f i) :=
begin
revert h, generalize h : (M.mk ⟨a,f⟩) = x,
intros h', cases h', subst x,
cases mk_inj h'_a_1, exact h'_a_2,
end
/-- follow a path through a value of `M F` and return the subtree
found at the end of the path if it is a valid path for that value and
return a default tree -/
def isubtree [decidable_eq F.A] [inhabited (M F)] : path F → M F → M F
| [] x := x
| (⟨a, i⟩ :: ps) x :=
pfunctor.M.cases_on' x (λ a' f,
(if h : a = a' then isubtree ps (f $ cast (by rw h) i)
else default (M F) : (λ x, M F) (M.mk ⟨a',f⟩)))
/-- similar to `isubtree` but returns the data at the end of the path instead
of the whole subtree -/
def iselect [decidable_eq F.A] [inhabited (M F)] (ps : path F) : M F → F.A :=
λ (x : M F), head $ isubtree ps x
lemma iselect_eq_default [decidable_eq F.A] [inhabited (M F)] (ps : path F) (x : M F)
(h : ¬ is_path ps x) :
iselect ps x = head (default $ M F) :=
begin
induction ps generalizing x,
{ exfalso, apply h, constructor },
{ cases ps_hd with a i,
induction x using pfunctor.M.cases_on',
simp only [iselect,isubtree] at ps_ih ⊢,
by_cases h'' : a = x_a, subst x_a,
{ simp only [dif_pos, eq_self_iff_true, cases_on_mk'],
rw ps_ih, intro h', apply h,
constructor; try { refl }, apply h' },
{ simp * } }
end
@[simp] lemma head_mk (x : F.obj (M F)) :
head (M.mk x) = x.1 :=
eq.symm $
calc x.1
= (dest (M.mk x)).1 : by rw dest_mk
... = head (M.mk x) : by refl
lemma children_mk {a} (x : F.B a → (M F)) (i : F.B (head (M.mk ⟨a,x⟩))) :
children (M.mk ⟨a,x⟩) i = x (cast (by rw head_mk) i) :=
by apply ext'; intro n; refl
@[simp]
lemma ichildren_mk [decidable_eq F.A] [inhabited (M F)] (x : F.obj (M F)) (i : F.Idx) :
ichildren i (M.mk x) = x.iget i :=
by { dsimp only [ichildren,pfunctor.obj.iget],
congr' with h, apply ext',
dsimp only [children',M.mk,approx.s_mk],
intros, refl }
@[simp]
lemma isubtree_cons [decidable_eq F.A] [inhabited (M F)] (ps : path F) {a} (f : F.B a → M F) {i : F.B a} :
isubtree (⟨_,i⟩ :: ps) (M.mk ⟨a,f⟩) = isubtree ps (f i) :=
by simp only [isubtree,ichildren_mk,pfunctor.obj.iget,dif_pos,isubtree,M.cases_on_mk']; refl
@[simp]
lemma iselect_nil [decidable_eq F.A] [inhabited (M F)] {a} (f : F.B a → M F) :
iselect nil (M.mk ⟨a,f⟩) = a :=
by refl
@[simp]
lemma iselect_cons [decidable_eq F.A] [inhabited (M F)] (ps : path F) {a} (f : F.B a → M F) {i} :
iselect (⟨a,i⟩ :: ps) (M.mk ⟨a,f⟩) = iselect ps (f i) :=
by simp only [iselect,isubtree_cons]
lemma corec_def {X} (f : X → F.obj X) (x₀ : X) :
M.corec f x₀ = M.mk (M.corec f <$> f x₀) :=
begin
dsimp only [M.corec,M.mk],
congr' with n,
cases n with n,
{ dsimp only [s_corec,approx.s_mk], refl, },
{ dsimp only [s_corec,approx.s_mk], cases h : (f x₀),
dsimp only [(<$>),pfunctor.map],
congr, }
end
lemma ext_aux [inhabited (M F)] [decidable_eq F.A] {n : ℕ} (x y z : M F)
(hx : agree' n z x)
(hy : agree' n z y)
(hrec : ∀ (ps : path F),
n = ps.length →
iselect ps x = iselect ps y) :
x.approx (n+1) = y.approx (n+1) :=
begin
induction n with n generalizing x y z,
{ specialize hrec [] rfl,
induction x using pfunctor.M.cases_on', induction y using pfunctor.M.cases_on',
simp only [iselect_nil] at hrec, subst hrec,
simp only [approx_mk, true_and, eq_self_iff_true, heq_iff_eq],
apply subsingleton.elim },
{ cases hx, cases hy,
induction x using pfunctor.M.cases_on', induction y using pfunctor.M.cases_on',
subst z,
replace hx_a_2 := mk_inj hx_a_2, cases hx_a_2,
replace hy_a_1 := mk_inj hy_a_1, cases hy_a_1,
replace hy_a_2 := mk_inj hy_a_2, cases hy_a_2,
simp only [approx_mk, true_and, eq_self_iff_true, heq_iff_eq],
ext i, apply n_ih,
{ apply hx_a_3 }, { apply hy_a_3 },
introv h, specialize hrec (⟨_,i⟩ :: ps) (congr_arg _ h),
simp only [iselect_cons] at hrec, exact hrec }
end
open pfunctor.approx
variables {F}
local attribute [instance, priority 0] classical.prop_decidable
lemma ext [inhabited (M F)]
(x y : M F)
(H : ∀ (ps : path F), iselect ps x = iselect ps y) :
x = y :=
begin
apply ext', intro i,
induction i with i,
{ cases x.approx 0, cases y.approx 0, constructor },
{ apply ext_aux x y x,
{ rw ← agree_iff_agree', apply x.consistent },
{ rw [← agree_iff_agree',i_ih], apply y.consistent },
introv H',
dsimp only [iselect] at H,
cases H',
apply H ps }
end
section bisim
variable (R : M F → M F → Prop)
local infix ~ := R
/-- Bisimulation is the standard proof technique for equality between
infinite tree-like structures -/
structure is_bisimulation : Prop :=
(head : ∀ {a a'} {f f'}, M.mk ⟨a,f⟩ ~ M.mk ⟨a',f'⟩ → a = a')
(tail : ∀ {a} {f f' : F.B a → M F},
M.mk ⟨a,f⟩ ~ M.mk ⟨a,f'⟩ →
(∀ (i : F.B a), f i ~ f' i) )
theorem nth_of_bisim [inhabited (M F)] (bisim : is_bisimulation R) (s₁ s₂) (ps : path F) :
s₁ ~ s₂ →
is_path ps s₁ ∨ is_path ps s₂ →
iselect ps s₁ = iselect ps s₂ ∧
∃ a (f f' : F.B a → M F),
isubtree ps s₁ = M.mk ⟨a,f⟩ ∧
isubtree ps s₂ = M.mk ⟨a,f'⟩ ∧
∀ (i : F.B a), f i ~ f' i :=
begin
intros h₀ hh,
induction s₁ using pfunctor.M.cases_on' with a f,
induction s₂ using pfunctor.M.cases_on' with a' f',
have : a = a' := bisim.head h₀, subst a',
induction ps with i ps generalizing a f f',
{ existsi [rfl,a,f,f',rfl,rfl],
apply bisim.tail h₀ },
cases i with a' i,
have : a = a',
{ cases hh; cases is_path_cons hh; refl },
subst a', dsimp only [iselect] at ps_ih ⊢,
have h₁ := bisim.tail h₀ i,
induction h : (f i) using pfunctor.M.cases_on' with a₀ f₀,
induction h' : (f' i) using pfunctor.M.cases_on' with a₁ f₁,
simp only [h,h',isubtree_cons] at ps_ih ⊢,
rw [h,h'] at h₁,
have : a₀ = a₁ := bisim.head h₁, subst a₁,
apply (ps_ih _ _ _ h₁),
rw [← h,← h'], apply or_of_or_of_imp_of_imp hh is_path_cons' is_path_cons'
end
theorem eq_of_bisim [nonempty (M F)] (bisim : is_bisimulation R) : ∀ s₁ s₂, s₁ ~ s₂ → s₁ = s₂ :=
begin
inhabit (M F),
introv Hr, apply ext,
introv,
by_cases h : is_path ps s₁ ∨ is_path ps s₂,
{ have H := nth_of_bisim R bisim _ _ ps Hr h,
exact H.left },
{ rw not_or_distrib at h, cases h with h₀ h₁,
simp only [iselect_eq_default,*,not_false_iff] }
end
end bisim
universes u' v'
/-- corecursor for `M F` with swapped arguments -/
def corec_on {X : Type*} (x₀ : X) (f : X → F.obj X) : M F :=
M.corec f x₀
variables {P : pfunctor.{u}} {α : Type u}
lemma dest_corec (g : α → P.obj α) (x : α) :
M.dest (M.corec g x) = M.corec g <$> g x :=
by rw [corec_def,dest_mk]
lemma bisim (R : M P → M P → Prop)
(h : ∀ x y, R x y → ∃ a f f',
M.dest x = ⟨a, f⟩ ∧
M.dest y = ⟨a, f'⟩ ∧
∀ i, R (f i) (f' i)) :
∀ x y, R x y → x = y :=
begin
introv h',
haveI := inhabited.mk x.head,
apply eq_of_bisim R _ _ _ h', clear h' x y,
split; introv ih;
rcases h _ _ ih with ⟨ a'', g, g', h₀, h₁, h₂ ⟩; clear h,
{ replace h₀ := congr_arg sigma.fst h₀,
replace h₁ := congr_arg sigma.fst h₁,
simp only [dest_mk] at h₀ h₁,
rw [h₀,h₁], },
{ simp only [dest_mk] at h₀ h₁,
cases h₀, cases h₁,
apply h₂, },
end
theorem bisim' {α : Type*} (Q : α → Prop) (u v : α → M P)
(h : ∀ x, Q x → ∃ a f f',
M.dest (u x) = ⟨a, f⟩ ∧
M.dest (v x) = ⟨a, f'⟩ ∧
∀ i, ∃ x', Q x' ∧ f i = u x' ∧ f' i = v x') :
∀ x, Q x → u x = v x :=
λ x Qx,
let R := λ w z : M P, ∃ x', Q x' ∧ w = u x' ∧ z = v x' in
@M.bisim P R
(λ x y ⟨x', Qx', xeq, yeq⟩,
let ⟨a, f, f', ux'eq, vx'eq, h'⟩ := h x' Qx' in
⟨a, f, f', xeq.symm ▸ ux'eq, yeq.symm ▸ vx'eq, h'⟩)
_ _ ⟨x, Qx, rfl, rfl⟩
-- for the record, show M_bisim follows from _bisim'
theorem bisim_equiv (R : M P → M P → Prop)
(h : ∀ x y, R x y → ∃ a f f',
M.dest x = ⟨a, f⟩ ∧
M.dest y = ⟨a, f'⟩ ∧
∀ i, R (f i) (f' i)) :
∀ x y, R x y → x = y :=
λ x y Rxy,
let Q : M P × M P → Prop := λ p, R p.fst p.snd in
bisim' Q prod.fst prod.snd
(λ p Qp,
let ⟨a, f, f', hx, hy, h'⟩ := h p.fst p.snd Qp in
⟨a, f, f', hx, hy, λ i, ⟨⟨f i, f' i⟩, h' i, rfl, rfl⟩⟩)
⟨x, y⟩ Rxy
theorem corec_unique (g : α → P.obj α) (f : α → M P)
(hyp : ∀ x, M.dest (f x) = f <$> (g x)) :
f = M.corec g :=
begin
ext x,
apply bisim' (λ x, true) _ _ _ _ trivial,
clear x,
intros x _,
cases gxeq : g x with a f',
have h₀ : M.dest (f x) = ⟨a, f ∘ f'⟩,
{ rw [hyp, gxeq, pfunctor.map_eq] },
have h₁ : M.dest (M.corec g x) = ⟨a, M.corec g ∘ f'⟩,
{ rw [dest_corec, gxeq, pfunctor.map_eq], },
refine ⟨_, _, _, h₀, h₁, _⟩,
intro i,
exact ⟨f' i, trivial, rfl, rfl⟩
end
/-- corecursor where the state of the computation can be sent downstream
in the form of a recursive call -/
def corec₁ {α : Type u} (F : Π X, (α → X) → α → P.obj X) : α → M P :=
M.corec (F _ id)
/-- corecursor where it is possible to return a fully formed value at any point
of the computation -/
def corec' {α : Type u} (F : Π {X : Type u}, (α → X) → α → M P ⊕ P.obj X) (x : α) : M P :=
corec₁
(λ X rec (a : M P ⊕ α),
let y := a >>= F (rec ∘ sum.inr) in
match y with
| sum.inr y := y
| sum.inl y := (rec ∘ sum.inl) <$> M.dest y
end )
(@sum.inr (M P) _ x)
end M
end pfunctor
|
adb3c2602682f8c9d1e16937253ddfae2a7dcb1a | 07c6143268cfb72beccd1cc35735d424ebcb187b | /src/analysis/normed_space/operator_norm.lean | 4c80a2f4fc6434af85ec1b5d1df26927047d64b7 | [
"Apache-2.0"
] | permissive | khoek/mathlib | bc49a842910af13a3c372748310e86467d1dc766 | aa55f8b50354b3e11ba64792dcb06cccb2d8ee28 | refs/heads/master | 1,588,232,063,837 | 1,587,304,803,000 | 1,587,304,803,000 | 176,688,517 | 0 | 0 | Apache-2.0 | 1,553,070,585,000 | 1,553,070,585,000 | null | UTF-8 | Lean | false | false | 27,936 | lean | /-
Copyright (c) 2019 Jan-David Salchow. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jan-David Salchow, Sébastien Gouëzel, Jean Lo
Operator norm on the space of continuous linear maps
Define the operator norm on the space of continuous linear maps between normed spaces, and prove
its basic properties. In particular, show that this space is itself a normed space.
-/
import topology.metric_space.lipschitz analysis.normed_space.riesz_lemma
import analysis.asymptotics
noncomputable theory
open_locale classical
set_option class.instance_max_depth 70
variables {𝕜 : Type*} {E : Type*} {F : Type*} {G : Type*}
[normed_group E] [normed_group F] [normed_group G]
open metric continuous_linear_map
lemma exists_pos_bound_of_bound {f : E → F} (M : ℝ) (h : ∀x, ∥f x∥ ≤ M * ∥x∥) :
∃ N, 0 < N ∧ ∀x, ∥f x∥ ≤ N * ∥x∥ :=
⟨max M 1, lt_of_lt_of_le zero_lt_one (le_max_right _ _), λx, calc
∥f x∥ ≤ M * ∥x∥ : h x
... ≤ max M 1 * ∥x∥ : mul_le_mul_of_nonneg_right (le_max_left _ _) (norm_nonneg _) ⟩
section normed_field
/- Most statements in this file require the field to be non-discrete, as this is necessary
to deduce an inequality `∥f x∥ ≤ C ∥x∥` from the continuity of f. However, the other direction always
holds. In this section, we just assume that `𝕜` is a normed field. In the remainder of the file,
it will be non-discrete. -/
variables [normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] (f : E →ₗ[𝕜] F)
lemma linear_map.lipschitz_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
lipschitz_with (nnreal.of_real C) f :=
lipschitz_with.of_dist_le' $ λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
theorem linear_map.antilipschitz_of_bound {K : nnreal} (h : ∀ x, ∥x∥ ≤ K * ∥f x∥) :
antilipschitz_with K f :=
antilipschitz_with.of_le_mul_dist $
λ x y, by simpa only [dist_eq_norm, f.map_sub] using h (x - y)
lemma linear_map.uniform_continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
uniform_continuous f :=
(f.lipschitz_of_bound C h).uniform_continuous
lemma linear_map.continuous_of_bound (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
continuous f :=
(f.lipschitz_of_bound C h).continuous
/-- Construct a continuous linear map from a linear map and a bound on this linear map.
The fact that the norm of the continuous linear map is then controlled is given in
`linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F :=
⟨f, linear_map.continuous_of_bound f C h⟩
/-- Construct a continuous linear map from a linear map and the existence of a bound on this linear
map. If you have an explicit bound, use `linear_map.mk_continuous` instead, as a norm estimate will
follow automatically in `linear_map.mk_continuous_norm_le`. -/
def linear_map.mk_continuous_of_exists_bound (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) : E →L[𝕜] F :=
⟨f, let ⟨C, hC⟩ := h in linear_map.continuous_of_bound f C hC⟩
@[simp, norm_cast] lemma linear_map.mk_continuous_coe (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
((f.mk_continuous C h) : E →ₗ[𝕜] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_apply (C : ℝ) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) :
f.mk_continuous C h x = f x := rfl
@[simp, norm_cast] lemma linear_map.mk_continuous_of_exists_bound_coe (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) :
((f.mk_continuous_of_exists_bound h) : E →ₗ[𝕜] F) = f := rfl
@[simp] lemma linear_map.mk_continuous_of_exists_bound_apply (h : ∃C, ∀x, ∥f x∥ ≤ C * ∥x∥) (x : E) :
f.mk_continuous_of_exists_bound h x = f x := rfl
lemma linear_map.continuous_iff_is_closed_ker {f : E →ₗ[𝕜] 𝕜} :
continuous f ↔ is_closed (f.ker : set E) :=
begin
-- the continuity of f obviously implies that its kernel is closed
refine ⟨λh, (continuous_iff_is_closed.1 h) {0} (t1_space.t1 0), λh, _⟩,
-- for the other direction, we assume that the kernel is closed
by_cases hf : ∀x, x ∈ f.ker,
{ -- if `f = 0`, its continuity is obvious
have : (f : E → 𝕜) = (λx, 0), by { ext x, simpa using hf x },
rw this,
exact continuous_const },
{ /- if `f` is not zero, we use an element `x₀ ∉ ker f` such that `∥x₀∥ ≤ 2 ∥x₀ - y∥` for all
`y ∈ ker f`, given by Riesz's lemma, and prove that `2 ∥f x₀∥ / ∥x₀∥` gives a bound on the
operator norm of `f`. For this, start from an arbitrary `x` and note that
`y = x₀ - (f x₀ / f x) x` belongs to the kernel of `f`. Applying the above inequality to `x₀`
and `y` readily gives the conclusion. -/
push_neg at hf,
let r : ℝ := (2 : ℝ)⁻¹,
have : 0 ≤ r, by norm_num [r],
have : r < 1, by norm_num [r],
obtain ⟨x₀, x₀ker, h₀⟩ : ∃ (x₀ : E), x₀ ∉ f.ker ∧ ∀ y ∈ linear_map.ker f, r * ∥x₀∥ ≤ ∥x₀ - y∥,
from riesz_lemma h hf this,
have : x₀ ≠ 0,
{ assume h,
have : x₀ ∈ f.ker, by { rw h, exact (linear_map.ker f).zero },
exact x₀ker this },
have rx₀_ne_zero : r * ∥x₀∥ ≠ 0, by { simp [norm_eq_zero, this], norm_num },
have : ∀x, ∥f x∥ ≤ (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥,
{ assume x,
by_cases hx : f x = 0,
{ rw [hx, norm_zero],
apply_rules [mul_nonneg', norm_nonneg, inv_nonneg.2, norm_nonneg] },
{ let y := x₀ - (f x₀ * (f x)⁻¹ ) • x,
have fy_zero : f y = 0, by calc
f y = f x₀ - (f x₀ * (f x)⁻¹ ) * f x : by simp [y]
... = 0 :
by { rw [mul_assoc, inv_mul_cancel hx, mul_one, sub_eq_zero_of_eq], refl },
have A : r * ∥x₀∥ ≤ ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥, from calc
r * ∥x₀∥ ≤ ∥x₀ - y∥ : h₀ _ (linear_map.mem_ker.2 fy_zero)
... = ∥(f x₀ * (f x)⁻¹ ) • x∥ : by { dsimp [y], congr, abel }
... = ∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥ :
by rw [norm_smul, normed_field.norm_mul, normed_field.norm_inv],
calc
∥f x∥ = (r * ∥x₀∥)⁻¹ * (r * ∥x₀∥) * ∥f x∥ : by rwa [inv_mul_cancel, one_mul]
... ≤ (r * ∥x₀∥)⁻¹ * (∥f x₀∥ * ∥f x∥⁻¹ * ∥x∥) * ∥f x∥ : begin
apply mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left A _) (norm_nonneg _),
exact inv_nonneg.2 (mul_nonneg' (by norm_num) (norm_nonneg _))
end
... = (∥f x∥ ⁻¹ * ∥f x∥) * (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ : by ring
... = (((r * ∥x₀∥)⁻¹) * ∥f x₀∥) * ∥x∥ :
by { rw [inv_mul_cancel, one_mul], simp [norm_eq_zero, hx] } } },
exact linear_map.continuous_of_bound f _ this }
end
end normed_field
variables [nondiscrete_normed_field 𝕜] [normed_space 𝕜 E] [normed_space 𝕜 F] [normed_space 𝕜 G]
(c : 𝕜) (f g : E →L[𝕜] F) (h : F →L[𝕜] G) (x y z : E)
include 𝕜
/-- A continuous linear map between normed spaces is bounded when the field is nondiscrete.
The continuity ensures boundedness on a ball of some radius `δ`. The nondiscreteness is then
used to rescale any element into an element of norm in `[δ/C, δ]`, whose image has a controlled norm.
The norm control for the original element follows by rescaling. -/
lemma linear_map.bound_of_continuous (f : E →ₗ[𝕜] F) (hf : continuous f) :
∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) :=
begin
have : continuous_at f 0 := continuous_iff_continuous_at.1 hf _,
rcases metric.tendsto_nhds_nhds.1 this 1 zero_lt_one with ⟨ε, ε_pos, hε⟩,
let δ := ε/2,
have δ_pos : δ > 0 := half_pos ε_pos,
have H : ∀{a}, ∥a∥ ≤ δ → ∥f a∥ ≤ 1,
{ assume a ha,
have : dist (f a) (f 0) ≤ 1,
{ apply le_of_lt (hε _),
rw [dist_eq_norm, sub_zero],
exact lt_of_le_of_lt ha (half_lt_self ε_pos) },
simpa using this },
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
refine ⟨δ⁻¹ * ∥c∥, mul_pos (inv_pos.2 δ_pos) (lt_trans zero_lt_one hc), (λx, _)⟩,
by_cases h : x = 0,
{ simp only [h, norm_zero, mul_zero, linear_map.map_zero] },
{ rcases rescale_to_shell hc δ_pos h with ⟨d, hd, dxle, ledx, dinv⟩,
calc ∥f x∥
= ∥f ((d⁻¹ * d) • x)∥ : by rwa [inv_mul_cancel, one_smul]
... = ∥d∥⁻¹ * ∥f (d • x)∥ :
by rw [mul_smul, linear_map.map_smul, norm_smul, normed_field.norm_inv]
... ≤ ∥d∥⁻¹ * 1 :
mul_le_mul_of_nonneg_left (H dxle) (by { rw ← normed_field.norm_inv, exact norm_nonneg _ })
... ≤ δ⁻¹ * ∥c∥ * ∥x∥ : by { rw mul_one, exact dinv } }
end
namespace continuous_linear_map
theorem bound : ∃ C, 0 < C ∧ (∀ x : E, ∥f x∥ ≤ C * ∥x∥) :=
f.to_linear_map.bound_of_continuous f.2
section
open asymptotics filter
theorem is_O_id (l : filter E) : is_O f (λ x, x) l :=
let ⟨M, hMp, hM⟩ := f.bound in is_O_of_le' l hM
theorem is_O_comp {E : Type*} (g : F →L[𝕜] G) (f : E → F) (l : filter E) :
is_O (λ x', g (f x')) f l :=
(g.is_O_id ⊤).comp_tendsto le_top
theorem is_O_sub (f : E →L[𝕜] F) (l : filter E) (x : E) :
is_O (λ x', f (x' - x)) (λ x', x' - x) l :=
f.is_O_comp _ l
end
section op_norm
open set real
set_option class.instance_max_depth 100
/-- The operator norm of a continuous linear map is the inf of all its bounds. -/
def op_norm := Inf { c | c ≥ 0 ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ }
instance has_op_norm : has_norm (E →L[𝕜] F) := ⟨op_norm⟩
-- So that invocations of `real.Inf_le` make sense: we show that the set of
-- bounds is nonempty and bounded below.
lemma bounds_nonempty {f : E →L[𝕜] F} :
∃ c, c ∈ { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } :=
let ⟨M, hMp, hMb⟩ := f.bound in ⟨M, le_of_lt hMp, hMb⟩
lemma bounds_bdd_below {f : E →L[𝕜] F} :
bdd_below { c | 0 ≤ c ∧ ∀ x, ∥f x∥ ≤ c * ∥x∥ } :=
⟨0, λ _ ⟨hn, _⟩, hn⟩
lemma op_norm_nonneg : 0 ≤ ∥f∥ :=
lb_le_Inf _ bounds_nonempty (λ _ ⟨hx, _⟩, hx)
/-- The fundamental property of the operator norm: `∥f x∥ ≤ ∥f∥ * ∥x∥`. -/
theorem le_op_norm : ∥f x∥ ≤ ∥f∥ * ∥x∥ :=
classical.by_cases
(λ heq : x = 0, by { rw heq, simp })
(λ hne, have hlt : 0 < ∥x∥, from norm_pos_iff.2 hne,
le_mul_of_div_le hlt ((le_Inf _ bounds_nonempty bounds_bdd_below).2
(λ c ⟨_, hc⟩, div_le_of_le_mul hlt (by { rw mul_comm, apply hc }))))
theorem le_op_norm_of_le {c : ℝ} {x} (h : ∥x∥ ≤ c) : ∥f x∥ ≤ ∥f∥ * c :=
le_trans (f.le_op_norm x) (mul_le_mul_of_nonneg_left h f.op_norm_nonneg)
/-- continuous linear maps are Lipschitz continuous. -/
theorem lipschitz : lipschitz_with ⟨∥f∥, op_norm_nonneg f⟩ f :=
lipschitz_with.of_dist_le_mul $ λ x y,
by { rw [dist_eq_norm, dist_eq_norm, ←map_sub], apply le_op_norm }
lemma ratio_le_op_norm : ∥f x∥ / ∥x∥ ≤ ∥f∥ :=
(or.elim (lt_or_eq_of_le (norm_nonneg _))
(λ hlt, div_le_of_le_mul hlt (by { rw mul_comm, apply le_op_norm }))
(λ heq, by { rw [←heq, div_zero], apply op_norm_nonneg }))
/-- The image of the unit ball under a continuous linear map is bounded. -/
lemma unit_le_op_norm : ∥x∥ ≤ 1 → ∥f x∥ ≤ ∥f∥ :=
mul_one ∥f∥ ▸ f.le_op_norm_of_le
/-- If one controls the norm of every `A x`, then one controls the norm of `A`. -/
lemma op_norm_le_bound {M : ℝ} (hMp: 0 ≤ M) (hM : ∀ x, ∥f x∥ ≤ M * ∥x∥) :
∥f∥ ≤ M :=
Inf_le _ bounds_bdd_below ⟨hMp, hM⟩
theorem op_norm_le_of_lipschitz {f : E →L[𝕜] F} {K : nnreal} (hf : lipschitz_with K f) :
∥f∥ ≤ K :=
f.op_norm_le_bound K.2 $ λ x, by simpa only [dist_zero_right, f.map_zero] using hf.dist_le_mul x 0
/-- The operator norm satisfies the triangle inequality. -/
theorem op_norm_add_le : ∥f + g∥ ≤ ∥f∥ + ∥g∥ :=
show ∥f + g∥ ≤ (coe : nnreal → ℝ) (⟨_, f.op_norm_nonneg⟩ + ⟨_, g.op_norm_nonneg⟩),
from op_norm_le_of_lipschitz (f.lipschitz.add g.lipschitz)
/-- An operator is zero iff its norm vanishes. -/
theorem op_norm_zero_iff : ∥f∥ = 0 ↔ f = 0 :=
iff.intro
(λ hn, continuous_linear_map.ext (λ x, norm_le_zero_iff.1
(calc _ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _
... = _ : by rw [hn, zero_mul])))
(λ hf, le_antisymm (Inf_le _ bounds_bdd_below
⟨ge_of_eq rfl, λ _, le_of_eq (by { rw [zero_mul, hf], exact norm_zero })⟩)
(op_norm_nonneg _))
@[simp] lemma norm_zero : ∥(0 : E →L[𝕜] F)∥ = 0 :=
by rw op_norm_zero_iff
/-- The norm of the identity is at most `1`. It is in fact `1`, except when the space is trivial
where it is `0`. It means that one can not do better than an inequality in general. -/
lemma norm_id_le : ∥(id : E →L[𝕜] E)∥ ≤ 1 :=
op_norm_le_bound _ zero_le_one (λx, by simp)
/-- If a space is non-trivial, then the norm of the identity equals `1`. -/
lemma norm_id (h : ∃ x : E, x ≠ 0) : ∥(id : E →L[𝕜] E)∥ = 1 :=
le_antisymm norm_id_le $ let ⟨x, hx⟩ := h in
have _ := ratio_le_op_norm (id : E →L[𝕜] E) x,
by rwa [id_apply, div_self (ne_of_gt $ norm_pos_iff.2 hx)] at this
/-- The operator norm is homogeneous. -/
lemma op_norm_smul : ∥c • f∥ = ∥c∥ * ∥f∥ :=
le_antisymm
((c • f).op_norm_le_bound
(mul_nonneg (norm_nonneg _) (op_norm_nonneg _)) (λ _,
begin
erw [norm_smul, mul_assoc],
exact mul_le_mul_of_nonneg_left (le_op_norm _ _) (norm_nonneg _)
end))
(lb_le_Inf _ bounds_nonempty (λ _ ⟨hn, hc⟩,
(or.elim (lt_or_eq_of_le (norm_nonneg c))
(λ hlt,
begin
rw mul_comm,
exact mul_le_of_le_div hlt (Inf_le _ bounds_bdd_below
⟨div_nonneg hn hlt, λ _,
(by { rw div_mul_eq_mul_div, exact le_div_of_mul_le hlt
(by { rw [ mul_comm, ←norm_smul ], exact hc _ }) })⟩)
end)
(λ heq, by { rw [←heq, zero_mul], exact hn }))))
lemma op_norm_neg : ∥-f∥ = ∥f∥ := calc
∥-f∥ = ∥(-1:𝕜) • f∥ : by rw neg_one_smul
... = ∥(-1:𝕜)∥ * ∥f∥ : by rw op_norm_smul
... = ∥f∥ : by simp
/-- Continuous linear maps themselves form a normed space with respect to
the operator norm. -/
instance to_normed_group : normed_group (E →L[𝕜] F) :=
normed_group.of_core _ ⟨op_norm_zero_iff, op_norm_add_le, op_norm_neg⟩
instance to_normed_space : normed_space 𝕜 (E →L[𝕜] F) :=
⟨op_norm_smul⟩
/-- The operator norm is submultiplicative. -/
lemma op_norm_comp_le (f : E →L[𝕜] F) : ∥h.comp f∥ ≤ ∥h∥ * ∥f∥ :=
(Inf_le _ bounds_bdd_below
⟨mul_nonneg (op_norm_nonneg _) (op_norm_nonneg _), λ x,
by { rw mul_assoc, exact h.le_op_norm_of_le (f.le_op_norm x) } ⟩)
/-- A continuous linear map is automatically uniformly continuous. -/
protected theorem uniform_continuous : uniform_continuous f :=
f.lipschitz.uniform_continuous
variable {f}
/-- A continuous linear map is an isometry if and only if it preserves the norm. -/
lemma isometry_iff_norm_image_eq_norm :
isometry f ↔ ∀x, ∥f x∥ = ∥x∥ :=
begin
rw isometry_emetric_iff_metric,
split,
{ assume H x,
have := H x 0,
rwa [dist_eq_norm, dist_eq_norm, f.map_zero, sub_zero, sub_zero] at this },
{ assume H x y,
rw [dist_eq_norm, dist_eq_norm, ← f.map_sub, H] }
end
variable (f)
theorem uniform_embedding_of_bound {K : nnreal} (hf : ∀ x, ∥x∥ ≤ K * ∥f x∥) :
uniform_embedding f :=
(f.to_linear_map.antilipschitz_of_bound hf).uniform_embedding f.uniform_continuous
/-- If a continuous linear map is a uniform embedding, then it is expands the distances
by a positive factor.-/
theorem antilipschitz_of_uniform_embedding (hf : uniform_embedding f) :
∃ K, antilipschitz_with K f :=
begin
obtain ⟨ε, εpos, hε⟩ : ∃ (ε : ℝ) (H : ε > 0), ∀ {x y : E}, dist (f x) (f y) < ε → dist x y < 1, from
(uniform_embedding_iff.1 hf).2.2 1 zero_lt_one,
let δ := ε/2,
have δ_pos : δ > 0 := half_pos εpos,
have H : ∀{x}, ∥f x∥ ≤ δ → ∥x∥ ≤ 1,
{ assume x hx,
have : dist x 0 ≤ 1,
{ apply le_of_lt,
apply hε,
simp [dist_eq_norm],
exact lt_of_le_of_lt hx (half_lt_self εpos) },
simpa using this },
rcases normed_field.exists_one_lt_norm 𝕜 with ⟨c, hc⟩,
refine ⟨⟨δ⁻¹, _⟩ * nnnorm c, f.to_linear_map.antilipschitz_of_bound $ λx, _⟩,
exact inv_nonneg.2 (le_of_lt δ_pos),
by_cases hx : f x = 0,
{ have : f x = f 0, by { simp [hx] },
have : x = 0 := (uniform_embedding_iff.1 hf).1 this,
simp [this] },
{ rcases rescale_to_shell hc δ_pos hx with ⟨d, hd, dxle, ledx, dinv⟩,
have : ∥f (d • x)∥ ≤ δ, by simpa,
have : ∥d • x∥ ≤ 1 := H this,
calc ∥x∥ = ∥d∥⁻¹ * ∥d • x∥ :
by rwa [← normed_field.norm_inv, ← norm_smul, ← mul_smul, inv_mul_cancel, one_smul]
... ≤ ∥d∥⁻¹ * 1 :
mul_le_mul_of_nonneg_left this (inv_nonneg.2 (norm_nonneg _))
... ≤ δ⁻¹ * ∥c∥ * ∥f x∥ :
by rwa [mul_one] }
end
section completeness
open_locale topological_space
open filter
/-- If the target space is complete, the space of continuous linear maps with its norm is also
complete. -/
instance [complete_space F] : complete_space (E →L[𝕜] F) :=
begin
-- We show that every Cauchy sequence converges.
refine metric.complete_of_cauchy_seq_tendsto (λ f hf, _),
-- We now expand out the definition of a Cauchy sequence,
rcases cauchy_seq_iff_le_tendsto_0.1 hf with ⟨b, b0, b_bound, b_lim⟩, clear hf,
-- and establish that the evaluation at any point `v : E` is Cauchy.
have cau : ∀ v, cauchy_seq (λ n, f n v),
{ assume v,
apply cauchy_seq_iff_le_tendsto_0.2 ⟨λ n, b n * ∥v∥, λ n, _, _, _⟩,
{ exact mul_nonneg (b0 n) (norm_nonneg _) },
{ assume n m N hn hm,
rw dist_eq_norm,
apply le_trans ((f n - f m).le_op_norm v) _,
exact mul_le_mul_of_nonneg_right (b_bound n m N hn hm) (norm_nonneg v) },
{ simpa using b_lim.mul tendsto_const_nhds } },
-- We assemble the limits points of those Cauchy sequences
-- (which exist as `F` is complete)
-- into a function which we call `G`.
choose G hG using λv, cauchy_seq_tendsto_of_complete (cau v),
-- Next, we show that this `G` is linear,
let Glin : E →ₗ[𝕜] F :=
{ to_fun := G,
add := λ v w, begin
have A := hG (v + w),
have B := (hG v).add (hG w),
simp only [map_add] at A B,
exact tendsto_nhds_unique filter.at_top_ne_bot A B,
end,
smul := λ c v, begin
have A := hG (c • v),
have B := filter.tendsto.smul (@tendsto_const_nhds _ ℕ _ c _) (hG v),
simp only [map_smul] at A B,
exact tendsto_nhds_unique filter.at_top_ne_bot A B
end },
-- and that `G` has norm at most `(b 0 + ∥f 0∥)`.
have Gnorm : ∀ v, ∥G v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥,
{ assume v,
have A : ∀ n, ∥f n v∥ ≤ (b 0 + ∥f 0∥) * ∥v∥,
{ assume n,
apply le_trans ((f n).le_op_norm _) _,
apply mul_le_mul_of_nonneg_right _ (norm_nonneg v),
calc ∥f n∥ = ∥(f n - f 0) + f 0∥ : by { congr' 1, abel }
... ≤ ∥f n - f 0∥ + ∥f 0∥ : norm_add_le _ _
... ≤ b 0 + ∥f 0∥ : begin
apply add_le_add_right,
simpa [dist_eq_norm] using b_bound n 0 0 (zero_le _) (zero_le _)
end },
exact le_of_tendsto at_top_ne_bot (hG v).norm (eventually_of_forall _ A) },
-- Thus `G` is continuous, and we propose that as the limit point of our original Cauchy sequence.
let Gcont := Glin.mk_continuous _ Gnorm,
use Gcont,
-- Our last task is to establish convergence to `G` in norm.
have : ∀ n, ∥f n - Gcont∥ ≤ b n,
{ assume n,
apply op_norm_le_bound _ (b0 n) (λ v, _),
have A : ∀ᶠ m in at_top, ∥(f n - f m) v∥ ≤ b n * ∥v∥,
{ refine eventually_at_top.2 ⟨n, λ m hm, _⟩,
apply le_trans ((f n - f m).le_op_norm _) _,
exact mul_le_mul_of_nonneg_right (b_bound n m n (le_refl _) hm) (norm_nonneg v) },
have B : tendsto (λ m, ∥(f n - f m) v∥) at_top (𝓝 (∥(f n - Gcont) v∥)) :=
tendsto.norm (tendsto_const_nhds.sub (hG v)),
exact le_of_tendsto at_top_ne_bot B A },
erw tendsto_iff_norm_tendsto_zero,
exact squeeze_zero (λ n, norm_nonneg _) this b_lim,
end
end completeness
section uniformly_extend
variables [complete_space F] (e : E →L[𝕜] G) (h_dense : dense_range e)
section
variables (h_e : uniform_inducing e)
/-- Extension of a continuous linear map `f : E →L[𝕜] F`, with `E` a normed space and `F` a complete
normed space, along a uniform and dense embedding `e : E →L[𝕜] G`. -/
def extend : G →L[𝕜] F :=
/- extension of `f` is continuous -/
have cont : _ := (uniform_continuous_uniformly_extend h_e h_dense f.uniform_continuous).continuous,
/- extension of `f` agrees with `f` on the domain of the embedding `e` -/
have eq : _ := uniformly_extend_of_ind h_e h_dense f.uniform_continuous,
{ to_fun := (h_e.dense_inducing h_dense).extend f,
add :=
begin
refine is_closed_property2 h_dense (is_closed_eq _ _) _,
{ exact cont.comp (continuous_fst.add continuous_snd) },
{ exact (cont.comp continuous_fst).add (cont.comp continuous_snd) },
{ assume x y, rw ← e.map_add, simp only [eq], exact f.map_add _ _ },
end,
smul := λk,
begin
refine is_closed_property h_dense (is_closed_eq _ _) _,
{ exact cont.comp (continuous_const.smul continuous_id) },
{ exact (continuous_const.smul continuous_id).comp cont },
{ assume x, rw ← map_smul, simp only [eq], exact map_smul _ _ _ },
end,
cont := cont
}
@[simp] lemma extend_zero : extend (0 : E →L[𝕜] F) e h_dense h_e = 0 :=
begin
apply ext,
refine is_closed_property h_dense (is_closed_eq _ _) _,
{ exact (uniform_continuous_uniformly_extend h_e h_dense uniform_continuous_const).continuous },
{ simp only [zero_apply], exact continuous_const },
{ assume x, exact uniformly_extend_of_ind h_e h_dense uniform_continuous_const x }
end
end
section
variables {N : nnreal} (h_e : ∀x, ∥x∥ ≤ N * ∥e x∥)
local notation `ψ` := f.extend e h_dense (uniform_embedding_of_bound _ h_e).to_uniform_inducing
/-- If a dense embedding `e : E →L[𝕜] G` expands the norm by a constant factor `N⁻¹`, then the norm
of the extension of `f` along `e` is bounded by `N * ∥f∥`. -/
lemma op_norm_extend_le : ∥ψ∥ ≤ N * ∥f∥ :=
begin
have uni : uniform_inducing e := (uniform_embedding_of_bound _ h_e).to_uniform_inducing,
have eq : ∀x, ψ (e x) = f x := uniformly_extend_of_ind uni h_dense f.uniform_continuous,
by_cases N0 : 0 ≤ N,
{ refine op_norm_le_bound ψ _ (is_closed_property h_dense (is_closed_le _ _) _),
{ exact mul_nonneg N0 (norm_nonneg _) },
{ exact continuous_norm.comp (cont ψ) },
{ exact continuous_const.mul continuous_norm },
{ assume x,
rw eq,
calc ∥f x∥ ≤ ∥f∥ * ∥x∥ : le_op_norm _ _
... ≤ ∥f∥ * (N * ∥e x∥) : mul_le_mul_of_nonneg_left (h_e x) (norm_nonneg _)
... ≤ N * ∥f∥ * ∥e x∥ : by rw [mul_comm ↑N ∥f∥, mul_assoc] } },
{ have he : ∀ x : E, x = 0,
{ assume x,
have N0 : N ≤ 0 := le_of_lt (lt_of_not_ge N0),
rw ← norm_le_zero_iff,
exact le_trans (h_e x) (mul_nonpos_of_nonpos_of_nonneg N0 (norm_nonneg _)) },
have hf : f = 0, { ext, simp only [he x, zero_apply, map_zero] },
have hψ : ψ = 0, { rw hf, apply extend_zero },
rw [hψ, hf, norm_zero, norm_zero, mul_zero] }
end
end
end uniformly_extend
end op_norm
/-- The norm of the tensor product of a scalar linear map and of an element of a normed space
is the product of the norms. -/
@[simp] lemma smul_right_norm {c : E →L[𝕜] 𝕜} {f : F} :
∥smul_right c f∥ = ∥c∥ * ∥f∥ :=
begin
refine le_antisymm _ _,
{ apply op_norm_le_bound _ (mul_nonneg (norm_nonneg _) (norm_nonneg _)) (λx, _),
calc
∥(c x) • f∥ = ∥c x∥ * ∥f∥ : norm_smul _ _
... ≤ (∥c∥ * ∥x∥) * ∥f∥ :
mul_le_mul_of_nonneg_right (le_op_norm _ _) (norm_nonneg _)
... = ∥c∥ * ∥f∥ * ∥x∥ : by ring },
{ by_cases h : ∥f∥ = 0,
{ rw h, simp [norm_nonneg] },
{ have : 0 < ∥f∥ := lt_of_le_of_ne (norm_nonneg _) (ne.symm h),
rw ← le_div_iff this,
apply op_norm_le_bound _ (div_nonneg (norm_nonneg _) this) (λx, _),
rw [div_mul_eq_mul_div, le_div_iff this],
calc ∥c x∥ * ∥f∥ = ∥c x • f∥ : (norm_smul _ _).symm
... = ∥((smul_right c f) : E → F) x∥ : rfl
... ≤ ∥smul_right c f∥ * ∥x∥ : le_op_norm _ _ } },
end
section restrict_scalars
variable (𝕜)
variables {𝕜' : Type*} [normed_field 𝕜'] [normed_algebra 𝕜 𝕜']
{E' : Type*} [normed_group E'] [normed_space 𝕜' E']
{F' : Type*} [normed_group F'] [normed_space 𝕜' F']
local attribute [instance, priority 500] normed_space.restrict_scalars
/-- `𝕜`-linear continuous function induced by a `𝕜'`-linear continuous function when `𝕜'` is a
normed algebra over `𝕜`. -/
def restrict_scalars (f : E' →L[𝕜'] F') : E' →L[𝕜] F' :=
{ cont := f.cont,
..linear_map.restrict_scalars 𝕜 (f.to_linear_map) }
@[simp, norm_cast] lemma restrict_scalars_coe_eq_coe (f : E' →L[𝕜'] F') :
(f.restrict_scalars 𝕜 : E' →ₗ[𝕜] F') = (f : E' →ₗ[𝕜'] F').restrict_scalars 𝕜 := rfl
@[simp, norm_cast squash] lemma restrict_scalars_coe_eq_coe' (f : E' →L[𝕜'] F') :
(f.restrict_scalars 𝕜 : E' → F') = f := rfl
end restrict_scalars
end continuous_linear_map
namespace continuous_linear_equiv
variable (e : E ≃L[𝕜] F)
protected lemma lipschitz : lipschitz_with (nnnorm (e : E →L[𝕜] F)) e :=
(e : E →L[𝕜] F).lipschitz
protected lemma antilipschitz : antilipschitz_with (nnnorm (e.symm : F →L[𝕜] E)) e :=
e.symm.lipschitz.to_right_inverse e.left_inv
/-- A continuous linear equiv is a uniform embedding. -/
lemma uniform_embedding : uniform_embedding e :=
e.antilipschitz.uniform_embedding e.lipschitz.uniform_continuous
lemma one_le_norm_mul_norm_symm (h : ∃ x : E, x ≠ 0) :
1 ≤ ∥(e : E →L[𝕜] F)∥ * ∥(e.symm : F →L[𝕜] E)∥ :=
begin
rw [mul_comm],
convert (e.symm : F →L[𝕜] E).op_norm_comp_le (e : E →L[𝕜] F),
rw [e.coe_symm_comp_coe, continuous_linear_map.norm_id h]
end
lemma norm_pos (h : ∃ x : E, x ≠ 0) : 0 < ∥(e : E →L[𝕜] F)∥ :=
pos_of_mul_pos_right (lt_of_lt_of_le zero_lt_one (e.one_le_norm_mul_norm_symm h)) (norm_nonneg _)
lemma norm_symm_pos (h : ∃ x : E, x ≠ 0) : 0 < ∥(e.symm : F →L[𝕜] E)∥ :=
pos_of_mul_pos_left (lt_of_lt_of_le zero_lt_one (e.one_le_norm_mul_norm_symm h)) (norm_nonneg _)
lemma subsingleton_or_norm_symm_pos : subsingleton E ∨ 0 < ∥(e.symm : F →L[𝕜] E)∥ :=
(subsingleton_or_exists_ne (0 : E)).imp id (λ hE, e.norm_symm_pos hE)
lemma subsingleton_or_nnnorm_symm_pos : subsingleton E ∨ 0 < (nnnorm $ (e.symm : F →L[𝕜] E)) :=
subsingleton_or_norm_symm_pos e
end continuous_linear_equiv
lemma linear_equiv.uniform_embedding (e : E ≃ₗ[𝕜] F) (h₁ : continuous e) (h₂ : continuous e.symm) :
uniform_embedding e :=
continuous_linear_equiv.uniform_embedding
{ continuous_to_fun := h₁,
continuous_inv_fun := h₂,
.. e }
/-- If a continuous linear map is constructed from a linear map via the constructor `mk_continuous`,
then its norm is bounded by the bound given to the constructor if it is nonnegative. -/
lemma linear_map.mk_continuous_norm_le (f : E →ₗ[𝕜] F) {C : ℝ} (hC : 0 ≤ C) (h : ∀x, ∥f x∥ ≤ C * ∥x∥) :
∥f.mk_continuous C h∥ ≤ C :=
continuous_linear_map.op_norm_le_bound _ hC h
|
12d0075caf25c28cd736d8fba61e55375b4b2bbd | 8cae430f0a71442d02dbb1cbb14073b31048e4b0 | /src/algebra/category/Module/limits.lean | 43f099089be5117dfb95f22ab3289bfe89dbdd09 | [
"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 | 7,611 | 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 algebra.category.Module.basic
import algebra.category.Group.limits
import algebra.direct_limit
/-!
# The category of R-modules has all limits
> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
Further, these limits are preserved by the forgetful functor --- that is,
the underlying types are just the limits in the category of types.
-/
open category_theory
open category_theory.limits
universes v w u -- `u` is determined by the ring, so can come last
noncomputable theory
namespace Module
variables {R : Type u} [ring R]
variables {J : Type v} [small_category J]
instance add_comm_group_obj (F : J ⥤ Module.{max v w} R) (j) :
add_comm_group ((F ⋙ forget (Module R)).obj j) :=
by { change add_comm_group (F.obj j), apply_instance }
instance module_obj (F : J ⥤ Module.{max v w} R) (j) :
module R ((F ⋙ forget (Module R)).obj j) :=
by { change module R (F.obj j), apply_instance }
/--
The flat sections of a functor into `Module R` form a submodule of all sections.
-/
def sections_submodule (F : J ⥤ Module.{max v w} R) :
submodule R (Π j, F.obj j) :=
{ carrier := (F ⋙ forget (Module R)).sections,
smul_mem' := λ r s sh j j' f,
begin
simp only [forget_map_eq_coe, functor.comp_map, pi.smul_apply, linear_map.map_smul],
dsimp [functor.sections] at sh,
rw sh f,
end,
..(AddGroup.sections_add_subgroup
(F ⋙ forget₂ (Module R) AddCommGroup.{max v w} ⋙ forget₂ AddCommGroup AddGroup.{max v w})) }
-- Adding the following instance speeds up `limit_module` noticeably,
-- by preventing a bad unfold of `limit_add_comm_group`.
instance limit_add_comm_monoid (F : J ⥤ Module R) :
add_comm_monoid (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X :=
show add_comm_monoid (sections_submodule F), by apply_instance
instance limit_add_comm_group (F : J ⥤ Module R) :
add_comm_group (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X :=
show add_comm_group (sections_submodule F), by apply_instance
instance limit_module (F : J ⥤ Module R) :
module R (types.limit_cone (F ⋙ forget (Module.{max v w} R))).X :=
show module R (sections_submodule F), by apply_instance
/-- `limit.π (F ⋙ forget Ring) j` as a `ring_hom`. -/
def limit_π_linear_map (F : J ⥤ Module R) (j) :
(types.limit_cone (F ⋙ forget (Module.{max v w} R))).X →ₗ[R] (F ⋙ forget (Module R)).obj j :=
{ to_fun := (types.limit_cone (F ⋙ forget (Module R))).π.app j,
map_smul' := λ x y, rfl,
map_add' := λ x y, rfl }
namespace has_limits
-- The next two definitions are used in the construction of `has_limits (Module R)`.
-- After that, the limits should be constructed using the generic limits API,
-- e.g. `limit F`, `limit.cone F`, and `limit.is_limit F`.
/--
Construction of a limit cone in `Module R`.
(Internal use only; use the limits API.)
-/
def limit_cone (F : J ⥤ Module.{max v w} R) : cone F :=
{ X := Module.of R (types.limit_cone (F ⋙ forget _)).X,
π :=
{ app := limit_π_linear_map F,
naturality' := λ j j' f,
linear_map.coe_injective ((types.limit_cone (F ⋙ forget _)).π.naturality f) } }
/--
Witness that the limit cone in `Module R` is a limit cone.
(Internal use only; use the limits API.)
-/
def limit_cone_is_limit (F : J ⥤ Module.{max v w} R) : is_limit (limit_cone F) :=
by refine is_limit.of_faithful
(forget (Module R)) (types.limit_cone_is_limit _)
(λ s, ⟨_, _, _⟩) (λ s, rfl);
intros;
ext j;
simp only [subtype.coe_mk, functor.map_cone_π_app, forget_map_eq_coe,
linear_map.map_add, linear_map.map_smul];
refl
end has_limits
open has_limits
/-- The category of R-modules has all limits. -/
@[irreducible]
instance has_limits_of_size : has_limits_of_size.{v v} (Module.{max v w} R) :=
{ has_limits_of_shape := λ J 𝒥, by exactI
{ has_limit := λ F, has_limit.mk
{ cone := limit_cone F,
is_limit := limit_cone_is_limit F } } }
instance has_limits : has_limits (Module.{w} R) := Module.has_limits_of_size.{w w u}
/--
An auxiliary declaration to speed up typechecking.
-/
def forget₂_AddCommGroup_preserves_limits_aux (F : J ⥤ Module.{max v w} R) :
is_limit ((forget₂ (Module R) AddCommGroup).map_cone (limit_cone F)) :=
AddCommGroup.limit_cone_is_limit (F ⋙ forget₂ (Module R) AddCommGroup.{max v w})
/--
The forgetful functor from R-modules to abelian groups preserves all limits.
-/
instance forget₂_AddCommGroup_preserves_limits_of_size :
preserves_limits_of_size.{v v} (forget₂ (Module R) AddCommGroup.{max v w}) :=
{ preserves_limits_of_shape := λ J 𝒥, by exactI
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
(limit_cone_is_limit F) (forget₂_AddCommGroup_preserves_limits_aux F) } }
instance forget₂_AddCommGroup_preserves_limits :
preserves_limits (forget₂ (Module R) AddCommGroup.{w}) :=
Module.forget₂_AddCommGroup_preserves_limits_of_size.{w w}
/--
The forgetful functor from R-modules to types preserves all limits.
-/
instance forget_preserves_limits_of_size :
preserves_limits_of_size.{v v} (forget (Module.{max v w} R)) :=
{ preserves_limits_of_shape := λ J 𝒥, by exactI
{ preserves_limit := λ F, preserves_limit_of_preserves_limit_cone
(limit_cone_is_limit F) (types.limit_cone_is_limit (F ⋙ forget _)) } }
instance forget_preserves_limits : preserves_limits (forget (Module.{w} R)) :=
Module.forget_preserves_limits_of_size.{w w}
section direct_limit
open module
variables {ι : Type v}
variables [dec_ι : decidable_eq ι] [preorder ι]
variables (G : ι → Type v)
variables [Π i, add_comm_group (G i)] [Π i, module R (G i)]
variables (f : Π i j, i ≤ j → G i →ₗ[R] G j) [directed_system G (λ i j h, f i j h)]
/-- The diagram (in the sense of `category_theory`)
of an unbundled `direct_limit` of modules. -/
@[simps]
def direct_limit_diagram : ι ⥤ Module R :=
{ obj := λ i, Module.of R (G i),
map := λ i j hij, f i j hij.le,
map_id' := λ i, by { apply linear_map.ext, intro x, apply module.directed_system.map_self },
map_comp' := λ i j k hij hjk,
begin
apply linear_map.ext,
intro x,
symmetry,
apply module.directed_system.map_map
end }
variables [decidable_eq ι]
/-- The `cocone` on `direct_limit_diagram` corresponding to
the unbundled `direct_limit` of modules.
In `direct_limit_is_colimit` we show that it is a colimit cocone. -/
@[simps]
def direct_limit_cocone : cocone (direct_limit_diagram G f) :=
{ X := Module.of R $ direct_limit G f,
ι := { app := module.direct_limit.of R ι G f,
naturality' := λ i j hij, by { apply linear_map.ext, intro x, exact direct_limit.of_f } } }
/-- The unbundled `direct_limit` of modules is a colimit
in the sense of `category_theory`. -/
@[simps]
def direct_limit_is_colimit [nonempty ι] [is_directed ι (≤)] :
is_colimit (direct_limit_cocone G f) :=
{ desc := λ s, direct_limit.lift R ι G f s.ι.app $ λ i j h x, by { rw [←s.w (hom_of_le h)], refl },
fac' := λ s i,
begin
apply linear_map.ext,
intro x,
dsimp,
exact direct_limit.lift_of s.ι.app _ x,
end,
uniq' := λ s m h,
begin
have : s.ι.app = λ i, linear_map.comp m (direct_limit.of R ι (λ i, G i) (λ i j H, f i j H) i),
{ funext i, rw ← h, refl },
apply linear_map.ext,
intro x,
simp only [this],
apply module.direct_limit.lift_unique
end }
end direct_limit
end Module
|
f913547083002eba90917b2e01791a9d0ad9b05b | 5d166a16ae129621cb54ca9dde86c275d7d2b483 | /tests/lean/run/my_tac_class.lean | 650399cfe5982e47add282a24be51c97935179fa | [
"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 | 1,756 | lean | meta def mytac :=
state_t nat tactic
meta instance : monad mytac :=
state_t.monad _ _
meta instance : monad.has_monad_lift tactic mytac :=
monad.monad_transformer_lift (state_t nat) tactic
meta instance (α : Type) : has_coe (tactic α) (mytac α) :=
⟨monad.monad_lift⟩
namespace mytac
meta def step {α : Type} (t : mytac α) : mytac unit :=
t >> return ()
meta def istep {α : Type} (line0 col0 line col : nat) (t : mytac α) : mytac unit :=
λ v s, result.cases_on (@scope_trace _ line col (t v s))
(λ ⟨a, v⟩ new_s, result.success ((), v) new_s)
(λ opt_msg_thunk e new_s,
match opt_msg_thunk with
| some msg_thunk :=
let msg := λ _ : unit, msg_thunk () ++ format.line ++ to_fmt "value: " ++ to_fmt v ++ format.line ++ to_fmt "state:" ++ format.line ++ new_s^.to_format in
interaction_monad.result.exception (some msg) (some ⟨line, col⟩) new_s
| none := interaction_monad.silent_fail new_s
end)
meta def execute (tac : mytac unit) : tactic unit :=
tac 0 >> return ()
meta def save_info (p : pos) : mytac unit :=
do v ← state_t.read,
s ← tactic.read,
tactic.save_info_thunk p
(λ _, to_fmt "Custom state: " ++ to_fmt v ++ format.line ++
tactic_state.to_format s)
namespace interactive
meta def intros : mytac unit :=
tactic.intros >> return ()
meta def constructor : mytac unit :=
tactic.constructor
meta def trace (s : string) : mytac unit :=
tactic.trace s
meta def assumption : mytac unit :=
tactic.assumption
meta def inc : mytac unit :=
do v ← state_t.read, state_t.write (v+1)
end interactive
end mytac
example (p q : Prop) : p → q → p ∧ q :=
begin [mytac]
intros,
inc,
trace "test",
constructor,
inc,
assumption,
assumption
end
|
a3742c8f01708845b5fa5368a99a0fb0977a3340 | a9d0fb7b0e4f802bd3857b803e6c5c23d87fef91 | /hott/tools/helper_tactics.hlean | 91375d8f76c69ab02637797ae8241c53185315e3 | [
"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 | 374 | hlean | -- Copyright (c) 2014 Microsoft Corporation. All rights reserved.
-- Released under Apache 2.0 license as described in the file LICENSE.
-- Author: Leonardo de Moura, Jeremy Avigad
-- tools.helper_tactics
-- ====================
-- Useful tactics.
open tactic
namespace helper_tactics
definition apply_refl := apply eq.refl
tactic_hint apply_refl
end helper_tactics
|
0afd254ab26dcd2412bcdc360b5100513f63af27 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/algebra/monoid_algebra/no_zero_divisors.lean | 4a6499cd4e06737e5f46aa02b4ee032bc17a770e | [
"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 | 7,744 | lean | /-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import algebra.monoid_algebra.support
/-!
# Variations on non-zero divisors in `add_monoid_algebra`s
This file studies the interaction between typeclass assumptions on two Types `R` and `A` and
whether `add_monoid_algebra R A` has non-zero zero-divisors. For some background on related
questions, see [Kaplansky's Conjectures](https://en.wikipedia.org/wiki/Kaplansky%27s_conjectures),
especially the *zero divisor conjecture*.
_Conjecture._
Let `K` be a field, and `G` a torsion-free group. The group ring `K[G]` does not contain
nontrivial zero divisors, that is, it is a domain.
We formalize in this file the well-known result that if `R` is a field and `A` is a left-ordered
group, then `R[A]` contains no non-zero zero-divisors. Some of these assumptions can be trivially
weakened: below we mention what assumptions are sufficient for the proofs in this file.
## Main results
* `no_zero_divisors.of_left_ordered` shows that if `R` is a semiring with no non-zero
zero-divisors, `A` is a linearly ordered, add right cancel semigroup with strictly monotone
left addition, then `add_monoid_algebra R A` has no non-zero zero-divisors.
* `no_zero_divisors.of_right_ordered` shows that if `R` is a semiring with no non-zero
zero-divisors, `A` is a linearly ordered, add left cancel semigroup with strictly monotone
right addition, then `add_monoid_algebra R A` has no non-zero zero-divisors.
The conditions on `A` imposed in `no_zero_divisors.of_left_ordered` are sometimes referred to as
`left-ordered`.
The conditions on `A` imposed in `no_zero_divisors.of_right_ordered` are sometimes referred to as
`right-ordered`.
These conditions are sufficient, but not necessary. As mentioned above, *Kaplansky's Conjecture*
asserts that `A` being torsion-free may be enough.
-/
namespace add_monoid_algebra
open finsupp
variables {R A : Type*} [semiring R]
/-- The coefficient of a monomial in a product `f * g` that can be reached in at most one way
as a product of monomials in the supports of `f` and `g` is a product. -/
lemma mul_apply_add_eq_mul_of_forall_ne [has_add A] {f g : add_monoid_algebra R A} {a0 b0 : A}
(h : ∀ {a b : A}, a ∈ f.support → b ∈ g.support → (a ≠ a0 ∨ b ≠ b0) → a + b ≠ a0 + b0) :
(f * g) (a0 + b0) = f a0 * g b0 :=
begin
classical,
rw mul_apply,
refine (finset.sum_eq_single a0 _ _).trans _,
{ exact λ b H hb, finset.sum_eq_zero (λ x H1, if_neg (h H H1 (or.inl hb))) },
{ exact λ af0, by simp [not_mem_support_iff.mp af0] },
{ refine (finset.sum_eq_single b0 (λ b bg b0, _) _).trans (if_pos rfl),
{ by_cases af : a0 ∈ f.support,
{ exact if_neg (h af bg (or.inr b0)) },
{ simp only [not_mem_support_iff.mp af, zero_mul, if_t_t] } },
{ exact λ bf0, by simp [not_mem_support_iff.mp bf0] } },
end
section left_or_right_orderability
lemma left.exists_add_of_mem_support_single_mul [add_left_cancel_semigroup A]
{g : add_monoid_algebra R A} (a x : A)
(hx : x ∈ (single a 1 * g : add_monoid_algebra R A).support) :
∃ b ∈ g.support, a + b = x :=
by rwa [support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _), finset.mem_map] at hx
lemma right.exists_add_of_mem_support_single_mul [add_right_cancel_semigroup A]
{f : add_monoid_algebra R A} (b x : A)
(hx : x ∈ (f * single b 1 : add_monoid_algebra R A).support) :
∃ a ∈ f.support, a + b = x :=
by rwa [support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _), finset.mem_map] at hx
/-- If `R` is a semiring with no non-trivial zero-divisors and `A` is a left-ordered add right
cancel semigroup, then `add_monoid_algebra R A` also contains no non-zero zero-divisors. -/
lemma no_zero_divisors.of_left_ordered [no_zero_divisors R]
[add_right_cancel_semigroup A] [linear_order A] [covariant_class A A (+) (<)] :
no_zero_divisors (add_monoid_algebra R A) :=
⟨λ f g fg, begin
contrapose! fg,
let gmin : A := g.support.min' (support_nonempty_iff.mpr fg.2),
refine support_nonempty_iff.mp _,
obtain ⟨a, ha, H⟩ := right.exists_add_of_mem_support_single_mul gmin
((f * single gmin 1 : add_monoid_algebra R A).support.min'
(by rw support_mul_single; simp [support_nonempty_iff.mpr fg.1])) (finset.min'_mem _ _),
refine ⟨a + gmin, mem_support_iff.mpr _⟩,
rw mul_apply_add_eq_mul_of_forall_ne _,
{ refine mul_ne_zero _ _,
exacts [mem_support_iff.mp ha, mem_support_iff.mp (finset.min'_mem _ _)] },
{ rw H,
rintro b c bf cg (hb | hc); refine ne_of_gt _,
{ refine lt_of_lt_of_le (_ : _ < b + gmin ) _,
{ apply finset.min'_lt_of_mem_erase_min',
rw ← H,
apply finset.mem_erase_of_ne_of_mem,
{ simpa only [ne.def, add_left_inj] },
{ rw support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _),
simpa only [finset.mem_map, add_right_embedding_apply, add_left_inj, exists_prop,
exists_eq_right] } },
{ haveI : covariant_class A A (+) (≤) := has_add.to_covariant_class_left A,
exact add_le_add_left (finset.min'_le _ _ cg) _ } },
{ refine lt_of_le_of_lt (_ : _ ≤ b + gmin) _,
{ apply finset.min'_le,
rw support_mul_single _ _ (λ y, by rw mul_one : ∀ y : R, y * 1 = 0 ↔ _),
simp only [bf, finset.mem_map, add_right_embedding_apply, add_left_inj, exists_prop,
exists_eq_right] },
{ refine add_lt_add_left _ _,
exact finset.min'_lt_of_mem_erase_min' _ _ (finset.mem_erase.mpr ⟨hc, cg⟩) } } }
end⟩
/-- If `R` is a semiring with no non-trivial zero-divisors and `A` is a right-ordered add left
cancel semigroup, then `add_monoid_algebra R A` also contains no non-zero zero-divisors. -/
lemma no_zero_divisors.of_right_ordered [no_zero_divisors R]
[add_left_cancel_semigroup A] [linear_order A] [covariant_class A A (function.swap (+)) (<)] :
no_zero_divisors (add_monoid_algebra R A) :=
⟨λ f g fg, begin
contrapose! fg,
let fmin : A := f.support.min' (support_nonempty_iff.mpr fg.1),
refine support_nonempty_iff.mp _,
obtain ⟨a, ha, H⟩ := left.exists_add_of_mem_support_single_mul fmin
((single fmin 1 * g : add_monoid_algebra R A).support.min'
(by rw support_single_mul; simp [support_nonempty_iff.mpr fg.2])) (finset.min'_mem _ _),
refine ⟨fmin + a, mem_support_iff.mpr _⟩,
rw mul_apply_add_eq_mul_of_forall_ne _,
{ refine mul_ne_zero _ _,
exacts [mem_support_iff.mp (finset.min'_mem _ _), mem_support_iff.mp ha] },
{ rw H,
rintro b c bf cg (hb | hc); refine ne_of_gt _,
{ refine lt_of_le_of_lt (_ : _ ≤ fmin + c) _,
{ apply finset.min'_le,
rw support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _),
simp only [cg, finset.mem_map, add_left_embedding_apply, add_right_inj, exists_prop,
exists_eq_right] },
{ refine add_lt_add_right _ _,
exact finset.min'_lt_of_mem_erase_min' _ _ (finset.mem_erase.mpr ⟨hb, bf⟩) } },
{ refine lt_of_lt_of_le (_ : _ < fmin + c) _,
{ apply finset.min'_lt_of_mem_erase_min',
rw ← H,
apply finset.mem_erase_of_ne_of_mem,
{ simpa only [ne.def, add_right_inj] },
{ rw support_single_mul _ _ (λ y, by rw one_mul : ∀ y : R, 1 * y = 0 ↔ _),
simpa only [finset.mem_map, add_left_embedding_apply, add_right_inj, exists_prop,
exists_eq_right]} },
{ haveI : covariant_class A A (function.swap (+)) (≤) := has_add.to_covariant_class_right A,
exact add_le_add_right (finset.min'_le _ _ bf) _ } } }
end⟩
end left_or_right_orderability
end add_monoid_algebra
|
9d316ff8a70aac262e95ddc79dc95af701b9ba61 | f7315930643edc12e76c229a742d5446dad77097 | /tests/lean/run/tactic26.lean | 7f86e364d4580e9693adc3a99ecd0ee53a546efb | [
"Apache-2.0"
] | permissive | bmalehorn/lean | 8f77b762a76c59afff7b7403f9eb5fc2c3ce70c1 | 53653c352643751c4b62ff63ec5e555f11dae8eb | refs/heads/master | 1,610,945,684,489 | 1,429,681,220,000 | 1,429,681,449,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 734 | lean | import logic data.num
open tactic inhabited
namespace foo
inductive sum (A : Type) (B : Type) : Type :=
| inl : A → sum A B
| inr : B → sum A B
theorem inl_inhabited {A : Type} (B : Type) (H : inhabited A) : inhabited (sum A B)
:= inhabited.destruct H (λ a, inhabited.mk (sum.inl B a))
theorem inr_inhabited (A : Type) {B : Type} (H : inhabited B) : inhabited (sum A B)
:= inhabited.destruct H (λ b, inhabited.mk (sum.inr A b))
definition my_tac := fixpoint (λ t, ( apply @inl_inhabited; t
| apply @inr_inhabited; t
| apply @num.is_inhabited
))
tactic_hint my_tac
theorem T : inhabited (sum false num)
end foo
|
2216fc01d0ef8e5f12ea47a151ca53e5ccd29580 | f4bff2062c030df03d65e8b69c88f79b63a359d8 | /src/game/sets/sets_level07.lean | cbaf3420dfd57d5cd792a82269bfba3637ed1444 | [
"Apache-2.0"
] | permissive | adastra7470/real-number-game | 776606961f52db0eb824555ed2f8e16f92216ea3 | f9dcb7d9255a79b57e62038228a23346c2dc301b | refs/heads/master | 1,669,221,575,893 | 1,594,669,800,000 | 1,594,669,800,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 902 | lean | import tactic --hide
import game.sets.sets_level06 -- hide
variable X : Type --hide
open_locale classical -- hide
namespace xena -- hide
/-
# Chapter 1 : Sets
## Level 7 : The empty set
-/
/-
The way to handle the empty set is the following:
```
lemma mem_empty_iff (a : X) : a ∈ (∅ : set X) ↔ false
```
-/
/- Axiom : mem_empty_iff :
a ∈ (∅ : set X) ↔ false
-/
/- Hint : Stuck?
Remember that `exfalso` changes any goal to `false`. This can be
convenient if your hypotheses can prove `false`.
Another approach: if `hx : false` then `cases hx` will do a case
split into every proof of false -- but there are no proofs of
false! So there will be no cases left to do.
-/
/- Lemma
The empty set is a subset of any set $A$.
-/
theorem empty_set_subset (A : set X) : ∅ ⊆ A :=
begin
rw subset_iff,
intros x hx,
exfalso,
rw mem_empty_iff at hx,
exact hx,
end
end xena |
7842d72e45833bc1a5c0d85e6a3da8f9df4effe2 | bdb33f8b7ea65f7705fc342a178508e2722eb851 | /ring_theory/localization.lean | 0b6e5eb156eb9d58c36709edb48e89b014914a32 | [
"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 | 9,984 | lean | /-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau
-/
import tactic.ring data.quot ring_theory.ideals group_theory.submonoid
universe u
namespace localization
variables (α : Type u) [comm_ring α] (S : set α) [is_submonoid S]
def r : α × S → α × S → Prop :=
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩, ∃ t ∈ S, (s₁ * r₂ - s₂ * r₁) * t = 0
local infix ≈ := r α S
section
variables {α S}
theorem r_of_eq : ∀{a₀ a₁ : α × S} (h : a₀.2.1 * a₁.1 = a₁.2.1 * a₀.1), a₀ ≈ a₁
| ⟨r₀, s₀, hs₀⟩ ⟨r₁, s₁, hs₁⟩ h := ⟨1, is_submonoid.one_mem S, by simp [h] at h ⊢⟩
end
theorem refl (x : α × S) : x ≈ x := r_of_eq rfl
theorem symm : ∀ (x y : α × S), x ≈ y → y ≈ x :=
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩, ⟨t, hts,
calc (s₂ * r₁ - s₁ * r₂) * t = -((s₁ * r₂ - s₂ * r₁) * t) : by simp [add_mul]
... = 0 : by rw ht; simp⟩
theorem trans : ∀ (x y z : α × S), x ≈ y → y ≈ z → x ≈ z :=
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨t, hts, ht⟩ ⟨t', hts', ht'⟩,
⟨s₂ * t' * t, is_submonoid.mul_mem (is_submonoid.mul_mem hs₂ hts') hts,
calc (s₁ * r₃ - s₃ * r₁) * (s₂ * t' * t) =
t' * s₃ * ((s₁ * r₂ - s₂ * r₁) * t) + t * s₁ * ((s₂ * r₃ - s₃ * r₂) * t') :
by simp [mul_left_comm, mul_add, mul_comm]
... = 0 : by rw [ht, ht']; simp⟩
instance : setoid (α × S) :=
⟨r α S, refl α S, symm α S, trans α S⟩
def loc := quotient $ localization.setoid α S
private def add_aux : α × S → α × S → loc α S :=
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩, ⟦⟨s₁ * r₂ + s₂ * r₁, s₁ * s₂, is_submonoid.mul_mem hs₁ hs₂⟩⟧
instance : has_add (loc α S) :=
⟨quotient.lift₂ (add_aux α S) $
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩,
quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅,
calc (s₁ * s₂ * (s₃ * r₄ + s₄ * r₃) - s₃ * s₄ * (s₁ * r₂ + s₂ * r₁)) * (t₆ * t₅) =
s₁ * s₃ * ((s₂ * r₄ - s₄ * r₂) * t₆) * t₅ + s₂ * s₄ * ((s₁ * r₃ - s₃ * r₁) * t₅) * t₆ : by ring
... = 0 : by rw [ht₆, ht₅]; simp⟩⟩
private def neg_aux : α × S → loc α S :=
λ ⟨r, s, hs⟩, ⟦⟨-r, s, hs⟩⟧
instance : has_neg (loc α S) :=
⟨quotient.lift (neg_aux α S) $
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩,
quotient.sound ⟨t, hts,
calc (s₁ * -r₂ - s₂ * -r₁) * t = -((s₁ * r₂ - s₂ * r₁) * t) : by ring
... = 0 : by rw ht; simp⟩⟩
private def mul_aux : α × S → α × S → loc α S :=
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩, ⟦⟨r₁ * r₂, s₁ * s₂, is_submonoid.mul_mem hs₁ hs₂⟩⟧
instance : has_mul (loc α S) :=
⟨quotient.lift₂ (mul_aux α S) $
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨r₃, s₃, hs₃⟩ ⟨r₄, s₄, hs₄⟩ ⟨t₅, hts₅, ht₅⟩ ⟨t₆, hts₆, ht₆⟩,
quotient.sound ⟨t₆ * t₅, is_submonoid.mul_mem hts₆ hts₅,
calc ((s₁ * s₂) * (r₃ * r₄) - (s₃ * s₄) * (r₁ * r₂)) * (t₆ * t₅) =
t₆ * ((s₁ * r₃ - s₃ * r₁) * t₅) * r₂ * s₄ + t₅ * ((s₂ * r₄ - s₄ * r₂) * t₆) * r₃ * s₁ :
by simp [mul_left_comm, mul_add, mul_comm]
... = 0 : by rw [ht₅, ht₆]; simp⟩⟩
def of_comm_ring : α → loc α S := λ r, ⟦⟨r, 1, is_submonoid.one_mem S⟩⟧
instance : comm_ring (loc α S) :=
by refine
{ add := has_add.add,
add_assoc := λ m n k, quotient.induction_on₃ m n k _,
zero := of_comm_ring α S 0,
zero_add := quotient.ind _,
add_zero := quotient.ind _,
neg := has_neg.neg,
add_left_neg := quotient.ind _,
add_comm := quotient.ind₂ _,
mul := has_mul.mul,
mul_assoc := λ m n k, quotient.induction_on₃ m n k _,
one := of_comm_ring α S 1,
one_mul := quotient.ind _,
mul_one := quotient.ind _,
left_distrib := λ m n k, quotient.induction_on₃ m n k _,
right_distrib := λ m n k, quotient.induction_on₃ m n k _,
mul_comm := quotient.ind₂ _ };
{ intros,
try {cases a with r₁ s₁, cases s₁ with s₁ hs₁},
try {cases b with r₂ s₂, cases s₂ with s₂ hs₂},
try {cases c with r₃ s₃, cases s₃ with s₃ hs₃},
refine (quotient.sound $ r_of_eq _),
simp [mul_left_comm, mul_add, mul_comm] }
instance : is_ring_hom (of_comm_ring α S) :=
{ map_add := λ x y, quotient.sound $ by simp,
map_mul := λ x y, quotient.sound $ by simp,
map_one := rfl }
variable {α}
def away (x : α) := loc α (powers x)
instance away.comm_ring (x : α) : comm_ring (away x) :=
localization.comm_ring α (powers x)
section at_prime
variables (P : set α) [is_prime_ideal P]
instance prime.is_submonoid :
is_submonoid (set.compl P) :=
{ one_mem := λ h, is_proper_ideal.ne_univ P $ is_submodule.univ_of_one_mem P h,
mul_mem := λ x y hnx hny hxy, or.cases_on (is_prime_ideal.mem_or_mem_of_mul_mem hxy) hnx hny }
def at_prime := loc α (set.compl P)
instance at_prime.comm_ring : comm_ring (at_prime P) :=
localization.comm_ring α (set.compl P)
instance at_prime.local_ring : local_ring (at_prime P) :=
local_of_nonunits_ideal
(λ hze,
let ⟨t, hts, ht⟩ := quotient.exact hze in
hts $ have htz : t = 0, by simpa using ht,
suffices (0:α) ∈ P, by rwa htz,
@is_submodule.zero _ _ _ _ P _)
(λ x y hx hy ⟨z, hz⟩,
let ⟨⟨r₁, s₁, hs₁⟩, hrs₁⟩ := quotient.exists_rep x,
⟨⟨r₂, s₂, hs₂⟩, hrs₂⟩ := quotient.exists_rep y,
⟨⟨r₃, s₃, hs₃⟩, hrs₃⟩ := quotient.exists_rep z in
have _,
by rw [← hrs₁, ← hrs₂, ← hrs₃] at hz; from quotient.exact hz,
let ⟨t, hts, ht⟩ := this in
have hr₁ : r₁ ∈ P,
from classical.by_contradiction $ λ hnr₁, hx ⟨⟦⟨s₁, r₁, hnr₁⟩⟧,
by rw ←hrs₁; from (quotient.sound $ r_of_eq $ by simp [mul_comm])⟩,
have hr₂ : r₂ ∈ P,
from classical.by_contradiction $ λ hnr₂, hy ⟨⟦⟨s₂, r₂, hnr₂⟩⟧,
by rw ←hrs₂; from (quotient.sound $ r_of_eq $ by simp [mul_comm])⟩,
have hr₃ : _ ,
from or.resolve_right (mem_or_mem_of_mul_eq_zero P ht) hts,
have h : s₃ * (s₁ * s₂) - r₃ * (s₁ * r₂ + s₂ * r₁) ∈ P,
by simpa using hr₃,
have h1 : r₃ * (s₁ * r₂ + s₂ * r₁) ∈ P,
from is_submodule.smul r₃ $
is_submodule.add (is_submodule.smul s₁ hr₂) (is_submodule.smul s₂ hr₁),
have h2 : s₃ * (s₁ * s₂) ∈ P,
from calc s₃ * (s₁ * s₂) =
s₃ * (s₁ * s₂) - r₃ * (s₁ * r₂ + s₂ * r₁) + r₃ * (s₁ * r₂ + s₂ * r₁) :
eq.symm $ sub_add_cancel _ _
... ∈ P : is_submodule.add h h1,
have h3 : s₁ * s₂ ∈ P,
from or.resolve_left (is_prime_ideal.mem_or_mem_of_mul_mem h2) hs₃,
or.cases_on (is_prime_ideal.mem_or_mem_of_mul_mem h3) hs₁ hs₂)
end at_prime
variable (α)
def non_zero_divisors : set α := {x | ∀ z, z * x = 0 → z = 0}
instance non_zero_divisors.is_submonoid : is_submonoid (non_zero_divisors α) :=
{ one_mem := λ z hz, by simpa using hz,
mul_mem := λ x₁ x₂ hx₁ hx₂ z hz,
have z * x₁ * x₂ = 0, by rwa mul_assoc,
hx₁ z $ hx₂ (z * x₁) this }
def quotient_ring := loc α (non_zero_divisors α)
instance quotient_ring.comm_ring : comm_ring (quotient_ring α) :=
localization.comm_ring α (non_zero_divisors α)
section quotient_ring
variables {β : Type u} [integral_domain β] [decidable_eq β]
lemma ne_zero_of_mem_non_zero_divisors {x : β} :
x ∈ localization.non_zero_divisors β → x ≠ 0 :=
λ hm hz,
have 1 * x = 0, by simp [hz],
zero_ne_one (hm 1 this).symm
lemma eq_zero_of_ne_zero_of_mul_eq_zero {x y : β} :
x ≠ 0 → y * x = 0 → y = 0 :=
λ hnx hxy, or.resolve_right (eq_zero_or_eq_zero_of_mul_eq_zero hxy) hnx
lemma mem_non_zero_divisors_of_ne_zero {x : β} :
x ≠ 0 → x ∈ localization.non_zero_divisors β :=
λ hnx z, eq_zero_of_ne_zero_of_mul_eq_zero hnx
variable (β)
private def inv_aux : β × (non_zero_divisors β) → quotient_ring β :=
λ ⟨r, s, hs⟩, if h : r = 0 then 0 else ⟦⟨s, r, mem_non_zero_divisors_of_ne_zero h⟩⟧
instance : has_inv (quotient_ring β) :=
⟨quotient.lift (inv_aux β) $
λ ⟨r₁, s₁, hs₁⟩ ⟨r₂, s₂, hs₂⟩ ⟨t, hts, ht⟩,
begin
have hrs : s₁ * r₂ = 0 + s₂ * r₁,
from sub_eq_iff_eq_add.1 (hts _ ht),
by_cases hr₁ : r₁ = 0;
by_cases hr₂ : r₂ = 0;
simp [hr₁, hr₂] at hrs; simp [inv_aux, hr₁, hr₂],
{ exfalso,
exact ne_zero_of_mem_non_zero_divisors hs₁
(eq_zero_of_ne_zero_of_mul_eq_zero hr₂ hrs) },
{ exfalso,
exact ne_zero_of_mem_non_zero_divisors hs₂
(eq_zero_of_ne_zero_of_mul_eq_zero hr₁ hrs.symm) },
{ apply r_of_eq,
simpa [mul_comm] using hrs.symm }
end⟩
def quotient_ring.field.of_integral_domain : field (quotient_ring β) :=
by refine
{ inv := has_inv.inv,
zero_ne_one := λ hzo,
let ⟨t, hts, ht⟩ := quotient.exact hzo in
zero_ne_one (by simpa using hts _ ht : 0 = 1),
mul_inv_cancel := quotient.ind _,
inv_mul_cancel := quotient.ind _,
..localization.comm_ring β _ };
{ intros x hnx,
rcases x with ⟨x, z, hz⟩,
have : x ≠ 0,
from assume hx, hnx (quotient.sound $ r_of_eq $ by simp [hx]),
simp [has_inv.inv, inv_aux, inv_aux._match_1, this],
exact (quotient.sound $ r_of_eq $ by simp; ring) }
end quotient_ring
end localization
|
c015809818561bd4eb7e50c379ddcabd88324264 | 6432ea7a083ff6ba21ea17af9ee47b9c371760f7 | /tests/lean/run/1179b.lean | 6448ceaadd220a4054c086787a265965845ac9f2 | [
"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 | 383 | lean | inductive Foo : Nat → Type _
| nil : Foo 0
| cons (t: Foo l) : Foo l
def Foo.bar (t₁: Foo l₁) (t₂ : Foo l₂) : Bool :=
match t₂ with
| cons s₁ => t₁.bar s₁
| _ => false
attribute [simp] Foo.bar
example (h : t₂ = .nil) : Foo.bar t₁ t₂ = false := by
unfold Foo.bar
split
· contradiction
· rfl
set_option pp.proofs true
#print Foo.bar.match_1
|
b024b387fdf837c9fb142990ea948a6df5d72dba | e0f9ba56b7fedc16ef8697f6caeef5898b435143 | /test/norm_cast_int.lean | 0246953ff69859d0bd7dc996f30dbe25a3069447 | [
"Apache-2.0"
] | permissive | anrddh/mathlib | 6a374da53c7e3a35cb0298b0cd67824efef362b4 | a4266a01d2dcb10de19369307c986d038c7bb6a6 | refs/heads/master | 1,656,710,827,909 | 1,589,560,456,000 | 1,589,560,456,000 | 264,271,800 | 0 | 0 | Apache-2.0 | 1,589,568,062,000 | 1,589,568,061,000 | null | UTF-8 | Lean | false | false | 561 | lean | import tactic.norm_cast data.int.basic
set_option pp.numerals false
set_option pp.notation false
-- set_option trace.simplify.rewrite true
#eval norm_cast.numeral_to_coe `(0 : ℤ)
#eval norm_cast.numeral_to_coe `(1 : ℤ)
#eval norm_cast.numeral_to_coe `(2 : ℤ)
#eval norm_cast.numeral_to_coe `(3 : ℤ)
#eval norm_cast.coe_to_numeral `((0 : ℕ) : ℤ)
#eval norm_cast.coe_to_numeral `((1 : ℕ) : ℤ)
#eval norm_cast.coe_to_numeral `((2 : ℕ) : ℤ)
#eval norm_cast.coe_to_numeral `((3 : ℕ) : ℤ)
example : ((42 : ℕ) : ℤ) = 42 := by norm_cast
|
777006d56bfd5cfeac005072ec9a356cbfbbddd9 | d406927ab5617694ec9ea7001f101b7c9e3d9702 | /src/category_theory/linear/yoneda.lean | 8c27c8c26beb221c1ee916c7045b3d2bbd80f86b | [
"Apache-2.0"
] | permissive | alreadydone/mathlib | dc0be621c6c8208c581f5170a8216c5ba6721927 | c982179ec21091d3e102d8a5d9f5fe06c8fafb73 | refs/heads/master | 1,685,523,275,196 | 1,670,184,141,000 | 1,670,184,141,000 | 287,574,545 | 0 | 0 | Apache-2.0 | 1,670,290,714,000 | 1,597,421,623,000 | Lean | UTF-8 | Lean | false | false | 4,744 | lean | /-
Copyright (c) 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import algebra.category.Module.basic
import category_theory.linear.basic
import category_theory.preadditive.yoneda
/-!
# The Yoneda embedding for `R`-linear categories
The Yoneda embedding for `R`-linear categories `C`,
sends an object `X : C` to the `Module R`-valued presheaf on `C`,
with value on `Y : Cᵒᵖ` given by `Module.of R (unop Y ⟶ X)`.
TODO: `linear_yoneda R C` is `R`-linear.
TODO: In fact, `linear_yoneda` itself is additive and `R`-linear.
-/
universes w v u
open opposite
namespace category_theory
variables (R : Type w) [ring R] (C : Type u) [category.{v} C] [preadditive C] [linear R C]
/-- The Yoneda embedding for `R`-linear categories `C`,
sending an object `X : C` to the `Module R`-valued presheaf on `C`,
with value on `Y : Cᵒᵖ` given by `Module.of R (unop Y ⟶ X)`. -/
@[simps]
def linear_yoneda : C ⥤ Cᵒᵖ ⥤ Module R :=
{ obj := λ X,
{ obj := λ Y, Module.of R (unop Y ⟶ X),
map := λ Y Y' f, linear.left_comp R _ f.unop,
map_comp' := λ _ _ _ f g, linear_map.ext $ λ _, category.assoc _ _ _,
map_id' := λ Y, linear_map.ext $ λ _, category.id_comp _ },
map := λ X X' f,
{ app := λ Y, linear.right_comp R _ f,
naturality' := λ X Y f, linear_map.ext $ λ x, by simp only [category.assoc, Module.coe_comp,
function.comp_app, linear.left_comp_apply, linear.right_comp_apply] },
map_id' := λ X, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _,
by simp only [linear.right_comp_apply, category.comp_id, nat_trans.id_app, Module.id_apply],
map_comp' := λ _ _ _ f g, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _,
by simp only [category.assoc, linear.right_comp_apply, nat_trans.comp_app, Module.coe_comp,
function.comp_app] }
/-- The Yoneda embedding for `R`-linear categories `C`,
sending an object `Y : Cᵒᵖ` to the `Module R`-valued copresheaf on `C`,
with value on `X : C` given by `Module.of R (unop Y ⟶ X)`. -/
@[simps]
def linear_coyoneda : Cᵒᵖ ⥤ C ⥤ Module R :=
{ obj := λ Y,
{ obj := λ X, Module.of R (unop Y ⟶ X),
map := λ Y Y', linear.right_comp _ _,
map_id' := λ Y, linear_map.ext $ λ _, category.comp_id _,
map_comp' := λ _ _ _ f g, linear_map.ext $ λ _, eq.symm (category.assoc _ _ _) },
map := λ Y Y' f,
{ app := λ X, linear.left_comp _ _ f.unop,
naturality' := λ X Y f, linear_map.ext $ λ x, by simp only [category.assoc, Module.coe_comp,
function.comp_app, linear.right_comp_apply, linear.left_comp_apply] },
map_id' := λ X, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _,
by simp only [linear.left_comp_apply, unop_id, category.id_comp, nat_trans.id_app,
Module.id_apply],
map_comp' := λ _ _ _ f g, nat_trans.ext _ _ $ funext $ λ _, linear_map.ext $ λ _,
by simp only [category.assoc, Module.coe_comp, function.comp_app, linear.left_comp_apply,
unop_comp, nat_trans.comp_app]}
instance linear_yoneda_obj_additive (X : C) : ((linear_yoneda R C).obj X).additive := {}
instance linear_coyoneda_obj_additive (Y : Cᵒᵖ) : ((linear_coyoneda R C).obj Y).additive := {}
@[simp] lemma whiskering_linear_yoneda : linear_yoneda R C ⋙
(whiskering_right _ _ _).obj (forget (Module.{v} R)) = yoneda :=
rfl
@[simp] lemma whiskering_linear_yoneda₂ : linear_yoneda R C ⋙
(whiskering_right _ _ _).obj (forget₂ (Module.{v} R) AddCommGroup.{v}) = preadditive_yoneda :=
rfl
@[simp] lemma whiskering_linear_coyoneda : linear_coyoneda R C ⋙
(whiskering_right _ _ _).obj (forget (Module.{v} R)) = coyoneda :=
rfl
@[simp] lemma whiskering_linear_coyoneda₂ : linear_coyoneda R C ⋙
(whiskering_right _ _ _).obj (forget₂ (Module.{v} R) AddCommGroup.{v}) = preadditive_coyoneda :=
rfl
instance linear_yoneda_full : full (linear_yoneda R C) :=
let yoneda_full : full (linear_yoneda R C ⋙
(whiskering_right _ _ _).obj (forget (Module.{v} R))) := yoneda.yoneda_full in
by exactI full.of_comp_faithful (linear_yoneda R C)
(((whiskering_right _ _ _)).obj (forget (Module.{v} R)))
instance linear_coyoneda_full : full (linear_coyoneda R C) :=
let coyoneda_full : full (linear_coyoneda R C ⋙
(whiskering_right _ _ _).obj (forget (Module.{v} R))) := coyoneda.coyoneda_full in
by exactI full.of_comp_faithful (linear_coyoneda R C)
(((whiskering_right _ _ _)).obj (forget (Module.{v} R)))
instance linear_yoneda_faithful : faithful (linear_yoneda R C) :=
faithful.of_comp_eq (whiskering_linear_yoneda R C)
instance linear_coyoneda_faithful : faithful (linear_coyoneda R C) :=
faithful.of_comp_eq (whiskering_linear_coyoneda R C)
end category_theory
|
7d4d83f6f26f45638faf9659a95f65e0fcafa5b5 | 95dcf8dea2baf2b4b0a60d438f27c35ae3dd3990 | /src/analysis/normed_space/deriv.lean | 3bc8b3a566bdf7f51416d4482e929e71b84d6d5b | [
"Apache-2.0"
] | permissive | uniformity1/mathlib | 829341bad9dfa6d6be9adaacb8086a8a492e85a4 | dd0e9bd8f2e5ec267f68e72336f6973311909105 | refs/heads/master | 1,588,592,015,670 | 1,554,219,842,000 | 1,554,219,842,000 | 179,110,702 | 0 | 0 | Apache-2.0 | 1,554,220,076,000 | 1,554,220,076,000 | null | UTF-8 | Lean | false | false | 14,131 | lean | /-
Copyright (c) 2019 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: Jeremy Avigad
The Fréchet derivative.
Let `E` and `F` be normed spaces, and `f : E → F`. Then
`has_fderiv_at_within f f' x s`
says that the function `f' : E → F` is a bounded linear map and `f` has derivative `f'` at
`x`, where the domain of interest is restricted to `s`. We also have
`has_fderiv_at f f' x := has_fderiv_at_within f f' x univ`
The derivative is defined in terms of the `is_o` relation, but also characterized in terms of
the `tendsto` relation.
-/
import topology.basic analysis.normed_space.bounded_linear_maps analysis.asymptotics tactic.abel
open filter asymptotics
section
variables (K : Type*) [normed_field K]
variables {E : Type*} [normed_space K E]
variables {F : Type*} [normed_space K F]
variables {G : Type*} [normed_space K G]
include K
def has_fderiv_at_filter (f : E → F) (f' : E → F) (x : E) (L : filter E) :=
is_bounded_linear_map K f' ∧
is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L
def has_fderiv_at_within (f : E → F) (f' : E → F) (x : E) (s : set E) :=
has_fderiv_at_filter K f f' x (nhds_within x s)
def has_fderiv_at (f : E → F) (f' : E → F) (x : E) :=
has_fderiv_at_filter K f f' x (nhds x)
variables {K}
theorem has_fderiv_at_filter.is_o {f : E → F} {f' : E → F} {x L}
(h : has_fderiv_at_filter K f f' x L) :
is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L :=
h.right
theorem has_fderiv_at.is_o {f : E → F} {f' : E → F} {x : E} (h : has_fderiv_at K f f' x) :
is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) (nhds x) :=
h.is_o
theorem has_fderiv_at_filter_iff_tendsto {f : E → F} {f' : E → F} {x : E} {L : filter E} :
has_fderiv_at_filter K f f' x L ↔
is_bounded_linear_map K f' ∧
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (nhds 0) :=
and.congr_right_iff.mpr $
assume bf' : is_bounded_linear_map K f',
have f'0 : f' 0 = 0 := (bf'.to_linear_map _).map_zero,
have h : ∀ x', ∥x' - x∥ = 0 → ∥f x' - f x - f' (x' - x)∥ = 0, from
assume x' hx',
have x' = x, from eq_of_sub_eq_zero ((norm_eq_zero _).mp hx'),
by rw this; simp [f'0],
begin
rw [←is_o_norm_left, ←is_o_norm_right, is_o_iff_tendsto h],
exact tendsto.congr'r (λ x', mul_comm _ _)
end
theorem has_fderiv_at_within_iff_tendsto {f : E → F} {f' : E → F} {x : E} {s : set E} :
has_fderiv_at_within K f f' x s ↔
is_bounded_linear_map K f' ∧
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (nhds_within x s) (nhds 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_iff_tendsto {f : E → F} {f' : E → F} {x : E} :
has_fderiv_at K f f' x ↔
is_bounded_linear_map K f' ∧
tendsto (λ x', ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) (nhds x) (nhds 0) :=
has_fderiv_at_filter_iff_tendsto
theorem has_fderiv_at_filter.mono {f : E → F} {f' : E → F} {x : E} {L₁ L₂ : filter E}
(hst : L₁ ≤ L₂) : has_fderiv_at_filter K f f' x L₂ → has_fderiv_at_filter K f f' x L₁ :=
and.imp_right (is_o.mono hst)
theorem has_fderiv_at_within.mono {f : E → F} {f' : E → F} {x : E} {s t : set E}
(hst : s ⊆ t) : has_fderiv_at_within K f f' x t → has_fderiv_at_within K f f' x s :=
has_fderiv_at_filter.mono (nhds_within_mono _ hst)
theorem has_fderiv_at_filter_of_has_fderiv_at {f : E → F} {f' : E → F} {x : E}
{L : filter E} (hL : L ≤ nhds x) (h : has_fderiv_at K f f' x) : has_fderiv_at_filter K f f' x L :=
h.mono hL
theorem has_fderiv_at_within_of_has_fderiv_at {f : E → F} {f' : E → F} {x : E} {s : set E} :
has_fderiv_at K f f' x → has_fderiv_at_within K f f' x s :=
has_fderiv_at_filter_of_has_fderiv_at lattice.inf_le_left
theorem has_fderiv_at_filter_congr' {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E} {L : filter E}
(hx : f₀ x = f₁ x) (h₀ : {x | f₀ x = f₁ x} ∈ L) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_filter K f₀ f₀' x L ↔ has_fderiv_at_filter K f₁ f₁' x L :=
by rw (funext h₁ : f₀' = f₁'); exact
and_congr_right (λ _, is_o_congr
(by filter_upwards [h₀] λ x' (h:_=_), by simp [h, hx])
(univ_mem_sets' $ λ _, rfl))
theorem has_fderiv_at_filter_congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E} {L : filter E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_filter K f₀ f₀' x L ↔ has_fderiv_at_filter K f₁ f₁' x L :=
has_fderiv_at_filter_congr' (h₀ _) (univ_mem_sets' h₀) h₁
theorem has_fderiv_at_filter.congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E} {L : filter E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_filter K f₀ f₀' x L → has_fderiv_at_filter K f₁ f₁' x L :=
(has_fderiv_at_filter_congr h₀ h₁).1
theorem has_fderiv_at_within_congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E} {s : set E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_within K f₀ f₀' x s ↔ has_fderiv_at_within K f₁ f₁' x s :=
has_fderiv_at_filter_congr h₀ h₁
theorem has_fderiv_at_within.congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E} {s : set E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at_within K f₀ f₀' x s → has_fderiv_at_within K f₁ f₁' x s :=
(has_fderiv_at_within_congr h₀ h₁).1
theorem has_fderiv_at_congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at K f₀ f₀' x ↔ has_fderiv_at K f₁ f₁' x :=
has_fderiv_at_filter_congr h₀ h₁
theorem has_fderiv_at.congr {f₀ f₁ : E → F} {f₀' f₁' : E → F} {x : E}
(h₀ : ∀ x, f₀ x = f₁ x) (h₁ : ∀ x, f₀' x = f₁' x) :
has_fderiv_at K f₀ f₀' x → has_fderiv_at K f₁ f₁' x :=
(has_fderiv_at_congr h₀ h₁).1
theorem has_fderiv_at_filter_id (x : E) (L : filter E) : has_fderiv_at_filter K id id x L :=
⟨is_bounded_linear_map.id, (is_o_zero _ _).congr_left (by simp)⟩
theorem has_fderiv_at_within_id (x : E) (s : set E) : has_fderiv_at_within K id id x s :=
has_fderiv_at_filter_id _ _
theorem has_fderiv_at_id (x : E) : has_fderiv_at K id id x :=
has_fderiv_at_filter_id _ _
theorem has_fderiv_at_filter_const (c : F) (x : E) (L : filter E) :
has_fderiv_at_filter K (λ x, c) (λ y, 0) x L :=
⟨is_bounded_linear_map.zero, (is_o_zero _ _).congr_left (by simp)⟩
theorem has_fderiv_at_within_const (c : F) (x : E) (s : set E) :
has_fderiv_at_within K (λ x, c) (λ y, 0) x s :=
has_fderiv_at_filter_const _ _ _
theorem has_fderiv_at_const (c : F) (x : E) :
has_fderiv_at K (λ x, c) (λ y, 0) x :=
has_fderiv_at_filter_const _ _ _
set_option class.instance_max_depth 43
theorem has_fderiv_at_filter_smul {f : E → F} {f' : E → F} {x : E} {L : filter E}
(c : K) (h : has_fderiv_at_filter K f f' x L) :
has_fderiv_at_filter K (λ x, c • f x) (λ x, c • f' x) x L :=
⟨is_bounded_linear_map.smul c h.left,
(is_o_const_smul_left h.right c).congr_left $
λ x, by simp [smul_neg, smul_add]⟩
theorem has_fderiv_at_within_smul {f : E → F} {f' : E → F} {x : E} {s : set E}
(c : K) : has_fderiv_at_within K f f' x s →
has_fderiv_at_within K (λ x, c • f x) (λ x, c • f' x) x s :=
has_fderiv_at_filter_smul _
theorem has_fderiv_at_smul {f : E → F} {f' : E → F} {x : E}
(c : K) : has_fderiv_at K f f' x →
has_fderiv_at K (λ x, c • f x) (λ x, c • f' x) x :=
has_fderiv_at_filter_smul _
theorem has_fderiv_at_filter_add {f g : E → F} {f' g' : E → F} {x : E} {L : filter E}
(hf : has_fderiv_at_filter K f f' x L) (hg : has_fderiv_at_filter K g g' x L) :
has_fderiv_at_filter K (λ x, f x + g x) (λ x, f' x + g' x) x L :=
⟨is_bounded_linear_map.add hf.left hg.left,
(hf.right.add hg.right).congr_left (by simp)⟩
theorem has_fderiv_at_within_add {f g : E → F} {f' g' : E → F} {x : E} {s : set E} :
has_fderiv_at_within K f f' x s → has_fderiv_at_within K g g' x s →
has_fderiv_at_within K (λ x, f x + g x) (λ x, f' x + g' x) x s :=
has_fderiv_at_filter_add
theorem has_fderiv_at_add {f g : E → F} {f' g' : E → F} {x : E} :
has_fderiv_at K f f' x → has_fderiv_at K g g' x →
has_fderiv_at K (λ x, f x + g x) (λ x, f' x + g' x) x :=
has_fderiv_at_filter_add
theorem has_fderiv_at_filter_neg {f : E → F} {f' : E → F} {x : E} {L : filter E}
(h : has_fderiv_at_filter K f f' x L) :
has_fderiv_at_filter K (λ x, -f x) (λ x, -f' x) x L :=
(has_fderiv_at_filter_smul (-1 : K) h).congr (by simp) (by simp)
theorem has_fderiv_at_within_neg {f : E → F} {f' : E → F} {x : E} {s : set E} :
has_fderiv_at_within K f f' x s → has_fderiv_at_within K (λ x, -f x) (λ x, -f' x) x s :=
has_fderiv_at_filter_neg
theorem has_fderiv_at_neg {f : E → F} {f' : E → F} {x : E} :
has_fderiv_at K f f' x → has_fderiv_at K (λ x, -f x) (λ x, -f' x) x :=
has_fderiv_at_filter_neg
theorem has_fderiv_at_filter_sub {f g : E → F} {f' g' : E → F} {x : E} {L : filter E}
(hf : has_fderiv_at_filter K f f' x L) (hg : has_fderiv_at_filter K g g' x L) :
has_fderiv_at_filter K (λ x, f x - g x) (λ x, f' x - g' x) x L :=
has_fderiv_at_filter_add hf (has_fderiv_at_filter_neg hg)
theorem has_fderiv_at_within_sub {f g : E → F} {f' g' : E → F} {x : E} {s : set E} :
has_fderiv_at_within K f f' x s → has_fderiv_at_within K g g' x s →
has_fderiv_at_within K (λ x, f x - g x) (λ x, f' x - g' x) x s :=
has_fderiv_at_filter_sub
theorem has_fderiv_at_sub {f g : E → F} {f' g' : E → F} {x : E} :
has_fderiv_at K f f' x → has_fderiv_at K g g' x →
has_fderiv_at K (λ x, f x - g x) (λ x, f' x - g' x) x :=
has_fderiv_at_filter_sub
theorem has_fderiv_at_filter.is_O_sub {f : E → F} {f' : E → F} {x : E} {L : filter E}
(h : has_fderiv_at_filter K f f' x L) : is_O (λ x', f x' - f x) (λ x', x' - x) L :=
h.2.to_is_O.congr_of_sub.2 (h.1.is_O_sub _ _)
theorem has_fderiv_at_filter.tendsto_nhds {f : E → F} {f' : E → F} {x : E} {L : filter E}
(hL : L ≤ nhds x) (h : has_fderiv_at_filter K f f' x L) : tendsto f L (nhds (f x)) :=
begin
have : tendsto (λ x', f x' - f x) L (nhds 0),
{ refine h.is_O_sub.trans_tendsto (tendsto_le_left hL _),
rw ← sub_self x, exact tendsto_sub tendsto_id tendsto_const_nhds },
have := tendsto_add this tendsto_const_nhds,
rw zero_add (f x) at this,
exact this.congr (by simp)
end
theorem has_fderiv_at_within.continuous_at_within {f : E → F} {f' : E → F} {x : E} {s : set E} :
has_fderiv_at_within K f f' x s → continuous_at_within f x s :=
has_fderiv_at_filter.tendsto_nhds lattice.inf_le_left
theorem has_fderiv_at.continuous_at {f : E → F} {f' : E → F} {x : E} :
has_fderiv_at K f f' x → continuous_at f x :=
has_fderiv_at_filter.tendsto_nhds (le_refl _)
theorem has_fderiv_at_filter.comp {g g' : F → G} {f f' : E → F} {L : filter E} {x : E}
(hf : has_fderiv_at_filter K f f' x L)
(hg : has_fderiv_at_filter K g g' (f x) (L.map f)) :
has_fderiv_at_filter K (g ∘ f) (g' ∘ f') x L :=
⟨hg.1.comp hf.1, begin
have eq₁ := (hg.1.is_O_comp _).trans_is_o hf.2,
have eq₂ := ((hg.2.comp f).mono le_comap_map).trans_is_O hf.is_O_sub,
refine eq₂.tri (eq₁.congr_left (λ x', _)),
rw [show g' (_-_) = g' _ - g' _, from (hg.1.to_linear_map _).map_sub _ _]
end⟩
/- A readable version of the previous theorem, a general form of the chain rule. -/
example {g g' : F → G} {f f' : E → F} {L : filter E} {x : E}
(hf : has_fderiv_at_filter K f f' x L)
(hg : has_fderiv_at_filter K g g' (f x) (L.map f)) :
has_fderiv_at_filter K (g ∘ f) (g' ∘ f') x L :=
⟨hg.1.comp hf.1,
begin
have : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', f x' - f x) L,
from (hg.2.comp f).mono le_comap_map,
have eq₁ : is_o (λ x', g (f x') - g (f x) - g' (f x' - f x)) (λ x', x' - x) L,
from this.trans_is_O hf.is_O_sub,
have eq₂ : is_o (λ x', f x' - f x - f' (x' - x)) (λ x', x' - x) L,
from hf.2,
have : is_O (λ x', g' (f x' - f x - f' (x' - x))) (λ x', f x' - f x - f' (x' - x)) L,
from hg.1.is_O_comp _,
have : is_o (λ x', g' (f x' - f x - f' (x' - x))) (λ x', x' - x) L,
from this.trans_is_o eq₂,
have eq₃ : is_o (λ x', g' (f x' - f x) - (g' (f' (x' - x)))) (λ x', x' - x) L,
by { refine this.congr_left (λ x', _),
rw [show g' (_-_) = g' _ - g' _, from (hg.1.to_linear_map _).map_sub _ _] },
exact eq₁.tri eq₃
end⟩
theorem has_fderiv_at_within.comp {g g' : F → G} {f f' : E → F} {s : set E} {x : E}
(hf : has_fderiv_at_within K f f' x s)
(hg : has_fderiv_at_within K g g' (f x) (f '' s)) :
has_fderiv_at_within K (g ∘ f) (g' ∘ f') x s :=
hf.comp (has_fderiv_at_filter.mono
hf.continuous_at_within.tendsto_nhds_within_image hg)
/-- The chain rule. -/
theorem has_fderiv_at.comp {g g' : F → G} {f f' : E → F} {x : E}
(hf : has_fderiv_at K f f' x) (hg : has_fderiv_at K g g' (f x)) :
has_fderiv_at K (g ∘ f) (g' ∘ f') x :=
hf.comp (hg.mono hf.continuous_at)
end
/-
In the special case of a normed space over the reals, we can use scalar multiplication in the
`tendsto` characterization of the Fréchet derivative.
-/
section
variables {E : Type*} [normed_space ℝ E]
variables {F : Type*} [normed_space ℝ F]
variables {G : Type*} [normed_space ℝ G]
set_option class.instance_max_depth 34
theorem has_fderiv_at_filter_real_equiv {f : E → F} {f' : E → F} {x : E} {L : filter E}
(bf' : is_bounded_linear_map ℝ f') :
tendsto (λ x' : E, ∥x' - x∥⁻¹ * ∥f x' - f x - f' (x' - x)∥) L (nhds 0) ↔
tendsto (λ x' : E, ∥x' - x∥⁻¹ • (f x' - f x - f' (x' - x))) L (nhds 0) :=
begin
have f'0 : f' 0 = 0 := (bf'.to_linear_map _).map_zero,
symmetry, rw [tendsto_iff_norm_tendsto_zero], refine tendsto.congr'r (λ x', _),
have : ∥x' + -x∥⁻¹ ≥ 0, from inv_nonneg.mpr (norm_nonneg _),
simp [norm_smul, real.norm_eq_abs, abs_of_nonneg this]
end
end
|
67b1fe9d0eb7b20a1d20a6497bc117aebe9af3a0 | d1bbf1801b3dcb214451d48214589f511061da63 | /src/analysis/analytic/basic.lean | 4d16e4d0e2dd323d2e53de800ac0b37a64c3e689 | [
"Apache-2.0"
] | permissive | cheraghchi/mathlib | 5c366f8c4f8e66973b60c37881889da8390cab86 | f29d1c3038422168fbbdb2526abf7c0ff13e86db | refs/heads/master | 1,676,577,831,283 | 1,610,894,638,000 | 1,610,894,638,000 | null | 0 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 39,754 | lean | /-
Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Sébastien Gouëzel, Yury Kudryashov
-/
import analysis.calculus.formal_multilinear_series
import analysis.specific_limits
/-!
# Analytic functions
A function is analytic in one dimension around `0` if it can be written as a converging power series
`Σ pₙ zⁿ`. This definition can be extended to any dimension (even in infinite dimension) by
requiring that `pₙ` is a continuous `n`-multilinear map. In general, `pₙ` is not unique (in two
dimensions, taking `p₂ (x, y) (x', y') = x y'` or `y x'` gives the same map when applied to a
vector `(x, y) (x, y)`). A way to guarantee uniqueness is to take a symmetric `pₙ`, but this is not
always possible in nonzero characteristic (in characteristic 2, the previous example has no
symmetric representative). Therefore, we do not insist on symmetry or uniqueness in the definition,
and we only require the existence of a converging series.
The general framework is important to say that the exponential map on bounded operators on a Banach
space is analytic, as well as the inverse on invertible operators.
## Main definitions
Let `p` be a formal multilinear series from `E` to `F`, i.e., `p n` is a multilinear map on `E^n`
for `n : ℕ`.
* `p.radius`: the largest `r : ennreal` such that `∥p n∥ * r^n` grows subexponentially, defined as
a liminf.
* `p.le_radius_of_bound`, `p.le_radius_of_bound_nnreal`, `p.le_radius_of_is_O`: if `∥p n∥ * r ^ n`
is bounded above, then `r ≤ p.radius`;
* `p.is_o_of_lt_radius`, `p.norm_mul_pow_le_mul_pow_of_lt_radius`, `p.is_o_one_of_lt_radius`,
`p.norm_mul_pow_le_of_lt_radius`, `p.nnnorm_mul_pow_le_of_lt_radius`: if `r < p.radius`, then
`∥p n∥ * r ^ n` tends to zero exponentially;
* `p.lt_radius_of_is_O`: if `r ≠ 0` and `∥p n∥ * r ^ n = O(a ^ n)` for some `-1 < a < 1`, then
`r < p.radius`;
* `p.partial_sum n x`: the sum `∑_{i = 0}^{n-1} pᵢ xⁱ`.
* `p.sum x`: the sum `∑'_{i = 0}^{∞} pᵢ xⁱ`.
Additionally, let `f` be a function from `E` to `F`.
* `has_fpower_series_on_ball f p x r`: on the ball of center `x` with radius `r`,
`f (x + y) = ∑'_n pₙ yⁿ`.
* `has_fpower_series_at f p x`: on some ball of center `x` with positive radius, holds
`has_fpower_series_on_ball f p x r`.
* `analytic_at 𝕜 f x`: there exists a power series `p` such that holds
`has_fpower_series_at f p x`.
We develop the basic properties of these notions, notably:
* If a function admits a power series, it is continuous (see
`has_fpower_series_on_ball.continuous_on` and `has_fpower_series_at.continuous_at` and
`analytic_at.continuous_at`).
* In a complete space, the sum of a formal power series with positive radius is well defined on the
disk of convergence, see `formal_multilinear_series.has_fpower_series_on_ball`.
* If a function admits a power series in a ball, then it is analytic at any point `y` of this ball,
and the power series there can be expressed in terms of the initial power series `p` as
`p.change_origin y`. See `has_fpower_series_on_ball.change_origin`. It follows in particular that
the set of points at which a given function is analytic is open, see `is_open_analytic_at`.
## Implementation details
We only introduce the radius of convergence of a power series, as `p.radius`.
For a power series in finitely many dimensions, there is a finer (directional, coordinate-dependent)
notion, describing the polydisk of convergence. This notion is more specific, and not necessary to
build the general theory. We do not define it here.
-/
noncomputable theory
variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
{E : Type*} [normed_group E] [normed_space 𝕜 E]
{F : Type*} [normed_group F] [normed_space 𝕜 F]
{G : Type*} [normed_group G] [normed_space 𝕜 G]
open_locale topological_space classical big_operators nnreal
open set filter asymptotics
/-! ### The radius of a formal multilinear series -/
namespace formal_multilinear_series
variables (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
/-- The radius of a formal multilinear series is the largest `r` such that the sum `Σ pₙ yⁿ`
converges for all `∥y∥ < r`. -/
def radius (p : formal_multilinear_series 𝕜 E F) : ennreal :=
⨆ (r : ℝ≥0) (C : ℝ) (hr : ∀ n, ∥p n∥ * r ^ n ≤ C), (r : ennreal)
/-- If `∥pₙ∥ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound (p : formal_multilinear_series 𝕜 E F) (C : ℝ) {r : ℝ≥0}
(h : ∀ (n : ℕ), ∥p n∥ * r^n ≤ C) : (r : ennreal) ≤ p.radius :=
le_supr_of_le r $ le_supr_of_le C $ (le_supr (λ _, (r : ennreal)) h)
/-- If `∥pₙ∥ rⁿ` is bounded in `n`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_bound_nnreal (p : formal_multilinear_series 𝕜 E F) (C : ℝ≥0) {r : ℝ≥0}
(h : ∀ (n : ℕ), nnnorm (p n) * r^n ≤ C) : (r : ennreal) ≤ p.radius :=
p.le_radius_of_bound C $ λ n, by exact_mod_cast (h n)
/-- If `∥pₙ∥ rⁿ = O(1)`, as `n → ∞`, then the radius of `p` is at least `r`. -/
lemma le_radius_of_is_O (h : is_O (λ n, ∥p n∥ * r^n) (λ n, (1 : ℝ)) at_top) : ↑r ≤ p.radius :=
exists.elim (is_O_one_nat_at_top_iff.1 h) $ λ C hC, p.le_radius_of_bound C $
λ n, (le_abs_self _).trans (hC n)
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` tends to zero exponentially:
for some `0 < a < 1`, `∥p n∥ rⁿ = o(aⁿ)`. -/
lemma is_o_of_lt_radius (h : ↑r < p.radius) :
∃ a ∈ Ioo (0 : ℝ) 1, is_o (λ n, ∥p n∥ * r ^ n) (pow a) at_top :=
begin
rw (tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 1 4,
simp only [radius, lt_supr_iff] at h,
rcases h with ⟨t, C, hC, rt⟩,
rw [ennreal.coe_lt_coe, ← nnreal.coe_lt_coe] at rt,
have : 0 < (t : ℝ), from r.coe_nonneg.trans_lt rt,
rw [← div_lt_one this] at rt,
refine ⟨_, rt, C, or.inr zero_lt_one, λ n, _⟩,
calc abs (∥p n∥ * r ^ n) = (∥p n∥ * t ^ n) * (r / t) ^ n :
by field_simp [mul_right_comm, abs_mul, this.ne']
... ≤ C * (r / t) ^ n : mul_le_mul_of_nonneg_right (hC n) (pow_nonneg (div_nonneg r.2 t.2) _)
end
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ = o(1)`. -/
lemma is_o_one_of_lt_radius (h : ↑r < p.radius) :
is_o (λ n, ∥p n∥ * r ^ n) (λ _, 1 : ℕ → ℝ) at_top :=
let ⟨a, ha, hp⟩ := p.is_o_of_lt_radius h in
hp.trans $ (is_o_pow_pow_of_lt_left ha.1.le ha.2).congr (λ n, rfl) one_pow
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` tends to zero exponentially:
for some `0 < a < 1` and `C > 0`, `∥p n∥ * r ^ n ≤ C * a ^ n`. -/
lemma norm_mul_pow_le_mul_pow_of_lt_radius (h : ↑r < p.radius) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ∥p n∥ * r^n ≤ C * a^n :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 1 5).mp (p.is_o_of_lt_radius h)
with ⟨a, ha, C, hC, H⟩,
exact ⟨a, ha, C, hC, λ n, (le_abs_self _).trans (H n)⟩
end
/-- If `r ≠ 0` and `∥pₙ∥ rⁿ = O(aⁿ)` for some `-1 < a < 1`, then `r < p.radius`. -/
lemma lt_radius_of_is_O (h₀ : r ≠ 0) {a : ℝ} (ha : a ∈ Ioo (-1 : ℝ) 1)
(hp : is_O (λ n, ∥p n∥ * r ^ n) (pow a) at_top) :
↑r < p.radius :=
begin
rcases ((tfae_exists_lt_is_o_pow (λ n, ∥p n∥ * r ^ n) 1).out 2 5).mp ⟨a, ha, hp⟩
with ⟨a, ha, C, hC, hp⟩,
replace h₀ : 0 < r := pos_iff_ne_zero.2 h₀,
lift a to ℝ≥0 using ha.1.le,
have : (r : ℝ) < r / a :=
(lt_div_iff ha.1).2 (by simpa only [mul_one] using mul_lt_mul_of_pos_left ha.2 h₀),
norm_cast at this,
rw [← ennreal.coe_lt_coe] at this,
refine this.trans_le (p.le_radius_of_bound C $ λ n, _),
rw [nnreal.coe_div, div_pow, ← mul_div_assoc, div_le_iff (pow_pos ha.1 n)],
exact (le_abs_self _).trans (hp n)
end
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` is bounded. -/
lemma norm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ennreal) < p.radius) : ∃ C > 0, ∀ n, ∥p n∥ * r^n ≤ C :=
let ⟨a, ha, C, hC, h⟩ := p.norm_mul_pow_le_mul_pow_of_lt_radius h
in ⟨C, hC, λ n, (h n).trans $ mul_le_of_le_one_right hC.lt.le (pow_le_one _ ha.1.le ha.2.le)⟩
/-- For `r` strictly smaller than the radius of `p`, then `∥pₙ∥ rⁿ` is bounded. -/
lemma nnnorm_mul_pow_le_of_lt_radius (p : formal_multilinear_series 𝕜 E F) {r : ℝ≥0}
(h : (r : ennreal) < p.radius) : ∃ C > 0, ∀ n, nnnorm (p n) * r^n ≤ C :=
let ⟨C, hC, hp⟩ := p.norm_mul_pow_le_of_lt_radius h
in ⟨⟨C, hC.lt.le⟩, hC, by exact_mod_cast hp⟩
/-- The radius of the sum of two formal series is at least the minimum of their two radii. -/
lemma min_radius_le_radius_add (p q : formal_multilinear_series 𝕜 E F) :
min p.radius q.radius ≤ (p + q).radius :=
begin
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
rw lt_min_iff at hr,
have := ((p.is_o_one_of_lt_radius hr.1).add (q.is_o_one_of_lt_radius hr.2)).is_O,
refine (p + q).le_radius_of_is_O ((is_O_of_le _ $ λ n, _).trans this),
rw [← add_mul, normed_field.norm_mul, normed_field.norm_mul, norm_norm],
exact mul_le_mul_of_nonneg_right ((norm_add_le _ _).trans (le_abs_self _)) (norm_nonneg _)
end
@[simp] lemma radius_neg (p : formal_multilinear_series 𝕜 E F) : (-p).radius = p.radius :=
by simp [radius]
/-- Given a formal multilinear series `p` and a vector `x`, then `p.sum x` is the sum `Σ pₙ xⁿ`. A
priori, it only behaves well when `∥x∥ < p.radius`. -/
protected def sum (p : formal_multilinear_series 𝕜 E F) (x : E) : F := ∑' n : ℕ , p n (λ i, x)
/-- Given a formal multilinear series `p` and a vector `x`, then `p.partial_sum n x` is the sum
`Σ pₖ xᵏ` for `k ∈ {0,..., n-1}`. -/
def partial_sum (p : formal_multilinear_series 𝕜 E F) (n : ℕ) (x : E) : F :=
∑ k in finset.range n, p k (λ(i : fin k), x)
/-- The partial sums of a formal multilinear series are continuous. -/
lemma partial_sum_continuous (p : formal_multilinear_series 𝕜 E F) (n : ℕ) :
continuous (p.partial_sum n) :=
by continuity
end formal_multilinear_series
/-! ### Expanding a function as a power series -/
section
variables {f g : E → F} {p pf pg : formal_multilinear_series 𝕜 E F} {x : E} {r r' : ennreal}
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series on the ball of radius `r > 0` around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `∥y∥ < r`.
-/
structure has_fpower_series_on_ball
(f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) (r : ennreal) : Prop :=
(r_le : r ≤ p.radius)
(r_pos : 0 < r)
(has_sum : ∀ {y}, y ∈ emetric.ball (0 : E) r → has_sum (λn:ℕ, p n (λ(i : fin n), y)) (f (x + y)))
/-- Given a function `f : E → F` and a formal multilinear series `p`, we say that `f` has `p` as
a power series around `x` if `f (x + y) = ∑' pₙ yⁿ` for all `y` in a neighborhood of `0`. -/
def has_fpower_series_at (f : E → F) (p : formal_multilinear_series 𝕜 E F) (x : E) :=
∃ r, has_fpower_series_on_ball f p x r
variable (𝕜)
/-- Given a function `f : E → F`, we say that `f` is analytic at `x` if it admits a convergent power
series expansion around `x`. -/
def analytic_at (f : E → F) (x : E) :=
∃ (p : formal_multilinear_series 𝕜 E F), has_fpower_series_at f p x
variable {𝕜}
lemma has_fpower_series_on_ball.has_fpower_series_at (hf : has_fpower_series_on_ball f p x r) :
has_fpower_series_at f p x := ⟨r, hf⟩
lemma has_fpower_series_at.analytic_at (hf : has_fpower_series_at f p x) : analytic_at 𝕜 f x :=
⟨p, hf⟩
lemma has_fpower_series_on_ball.analytic_at (hf : has_fpower_series_on_ball f p x r) :
analytic_at 𝕜 f x :=
hf.has_fpower_series_at.analytic_at
lemma has_fpower_series_on_ball.radius_pos (hf : has_fpower_series_on_ball f p x r) :
0 < p.radius :=
lt_of_lt_of_le hf.r_pos hf.r_le
lemma has_fpower_series_at.radius_pos (hf : has_fpower_series_at f p x) :
0 < p.radius :=
let ⟨r, hr⟩ := hf in hr.radius_pos
lemma has_fpower_series_on_ball.mono
(hf : has_fpower_series_on_ball f p x r) (r'_pos : 0 < r') (hr : r' ≤ r) :
has_fpower_series_on_ball f p x r' :=
⟨le_trans hr hf.1, r'_pos, λ y hy, hf.has_sum (emetric.ball_subset_ball hr hy)⟩
lemma has_fpower_series_on_ball.add
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f + g) (pf + pg) x r :=
{ r_le := le_trans (le_min_iff.2 ⟨hf.r_le, hg.r_le⟩) (pf.min_radius_le_radius_add pg),
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).add (hg.has_sum hy) }
lemma has_fpower_series_at.add
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f + g) (pf + pg) x :=
begin
rcases hf with ⟨rf, hrf⟩,
rcases hg with ⟨rg, hrg⟩,
have P : 0 < min rf rg, by simp [hrf.r_pos, hrg.r_pos],
exact ⟨min rf rg, (hrf.mono P (min_le_left _ _)).add (hrg.mono P (min_le_right _ _))⟩
end
lemma analytic_at.add (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f + g) x :=
let ⟨pf, hpf⟩ := hf, ⟨qf, hqf⟩ := hg in (hpf.add hqf).analytic_at
lemma has_fpower_series_on_ball.neg (hf : has_fpower_series_on_ball f pf x r) :
has_fpower_series_on_ball (-f) (-pf) x r :=
{ r_le := by { rw pf.radius_neg, exact hf.r_le },
r_pos := hf.r_pos,
has_sum := λ y hy, (hf.has_sum hy).neg }
lemma has_fpower_series_at.neg
(hf : has_fpower_series_at f pf x) : has_fpower_series_at (-f) (-pf) x :=
let ⟨rf, hrf⟩ := hf in hrf.neg.has_fpower_series_at
lemma analytic_at.neg (hf : analytic_at 𝕜 f x) : analytic_at 𝕜 (-f) x :=
let ⟨pf, hpf⟩ := hf in hpf.neg.analytic_at
lemma has_fpower_series_on_ball.sub
(hf : has_fpower_series_on_ball f pf x r) (hg : has_fpower_series_on_ball g pg x r) :
has_fpower_series_on_ball (f - g) (pf - pg) x r :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_at.sub
(hf : has_fpower_series_at f pf x) (hg : has_fpower_series_at g pg x) :
has_fpower_series_at (f - g) (pf - pg) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma analytic_at.sub (hf : analytic_at 𝕜 f x) (hg : analytic_at 𝕜 g x) :
analytic_at 𝕜 (f - g) x :=
by simpa only [sub_eq_add_neg] using hf.add hg.neg
lemma has_fpower_series_on_ball.coeff_zero (hf : has_fpower_series_on_ball f pf x r)
(v : fin 0 → E) : pf 0 v = f x :=
begin
have v_eq : v = (λ i, 0) := subsingleton.elim _ _,
have zero_mem : (0 : E) ∈ emetric.ball (0 : E) r, by simp [hf.r_pos],
have : ∀ i ≠ 0, pf i (λ j, 0) = 0,
{ assume i hi,
have : 0 < i := pos_iff_ne_zero.2 hi,
exact continuous_multilinear_map.map_coord_zero _ (⟨0, this⟩ : fin i) rfl },
have A := (hf.has_sum zero_mem).unique (has_sum_single _ this),
simpa [v_eq] using A.symm,
end
lemma has_fpower_series_at.coeff_zero (hf : has_fpower_series_at f pf x) (v : fin 0 → E) :
pf 0 v = f x :=
let ⟨rf, hrf⟩ := hf in hrf.coeff_zero v
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence.
This version provides an upper estimate that decreases both in `∥y∥` and `n`. See also
`has_fpower_series_on_ball.uniform_geometric_approx` for a weaker version. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ennreal) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), ∀ n, ∥p n∥ * r' ^n ≤ C * a^n :=
p.norm_mul_pow_le_mul_pow_of_lt_radius (h.trans_le hf.r_le),
refine ⟨a, ha, C / (1 - a), div_pos hC (sub_pos.2 ha.2), λ y hy n, _⟩,
have yr' : ∥y∥ < r', by { rw ball_0_eq at hy, exact hy },
have hr'0 : 0 < (r' : ℝ), from (norm_nonneg _).trans_lt yr',
have : y ∈ emetric.ball (0 : E) r,
{ refine mem_emetric_ball_0_iff.2 (lt_trans _ h),
exact_mod_cast yr' },
rw [norm_sub_rev, ← mul_div_right_comm],
have ya : a * (∥y∥ / ↑r') ≤ a,
from mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg),
suffices : ∥p.partial_sum n y - f (x + y)∥ ≤ C * (a * (∥y∥ / r')) ^ n / (1 - a * (∥y∥ / r')),
{ refine this.trans _,
apply_rules [div_le_div_of_le_left, sub_pos.2, div_nonneg, mul_nonneg, pow_nonneg, hC.lt.le,
ha.1.le, norm_nonneg, nnreal.coe_nonneg, ha.2, (sub_le_sub_iff_left _).2] },
apply norm_sub_le_of_geometric_bound_of_has_sum (ya.trans_lt ha.2) _ (hf.has_sum this),
assume n,
calc ∥(p n) (λ (i : fin n), y)∥ ≤ ∥p n∥ * (∏ i : fin n, ∥y∥) :
continuous_multilinear_map.le_op_norm _ _
... = (∥p n∥ * r' ^ n) * (∥y∥ / r') ^ n : by field_simp [hr'0.ne', mul_right_comm]
... ≤ (C * a ^ n) * (∥y∥ / r') ^ n :
mul_le_mul_of_nonneg_right (hp n) (pow_nonneg (div_nonneg (norm_nonneg _) r'.coe_nonneg) _)
... ≤ C * (a * (∥y∥ / r')) ^ n : by rw [mul_pow, mul_assoc]
end
/-- If a function admits a power series expansion, then it is exponentially close to the partial
sums of this power series on strict subdisks of the disk of convergence. -/
lemma has_fpower_series_on_ball.uniform_geometric_approx {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ennreal) < r) :
∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0), (∀ y ∈ metric.ball (0 : E) r', ∀ n,
∥f (x + y) - p.partial_sum n y∥ ≤ C * a ^ n) :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine ⟨a, ha, C, hC, λ y hy n, (hp y hy n).trans _⟩,
have yr' : ∥y∥ < r', by rwa ball_0_eq at hy,
refine mul_le_mul_of_nonneg_left (pow_le_pow_of_le_left _ _ _) hC.lt.le,
exacts [mul_nonneg ha.1.le (div_nonneg (norm_nonneg y) r'.coe_nonneg),
mul_le_of_le_one_right ha.1.le (div_le_one_of_le yr'.le r'.coe_nonneg)]
end
/-- Taylor formula for an analytic function, `is_O` version. -/
lemma has_fpower_series_at.is_O_sub_partial_sum_pow (hf : has_fpower_series_at f p x) (n : ℕ) :
is_O (λ y : E, f (x + y) - p.partial_sum n y) (λ y, ∥y∥ ^ n) (𝓝 0) :=
begin
rcases hf with ⟨r, hf⟩,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hf.r_pos with ⟨r', r'0, h⟩,
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * (a * (∥y∥ / r')) ^ n),
from hf.uniform_geometric_approx' h,
refine is_O_iff.2 ⟨C * (a / r') ^ n, _⟩,
replace r'0 : 0 < (r' : ℝ), by exact_mod_cast r'0,
filter_upwards [metric.ball_mem_nhds (0 : E) r'0], intros y hy,
simpa [mul_pow, mul_div_assoc, mul_assoc, div_mul_eq_mul_div] using hp y hy n
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f (x + y)`
is the uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ennreal) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n y)
(λ y, f (x + y)) at_top (metric.ball (0 : E) r') :=
begin
obtain ⟨a, ha, C, hC, hp⟩ : ∃ (a ∈ Ioo (0 : ℝ) 1) (C > 0),
(∀ y ∈ metric.ball (0 : E) r', ∀ n, ∥f (x + y) - p.partial_sum n y∥ ≤ C * a ^ n),
from hf.uniform_geometric_approx h,
refine metric.tendsto_uniformly_on_iff.2 (λ ε εpos, _),
have L : tendsto (λ n, (C : ℝ) * a^n) at_top (𝓝 ((C : ℝ) * 0)) :=
tendsto_const_nhds.mul (tendsto_pow_at_top_nhds_0_of_lt_1 ha.1.le ha.2),
rw mul_zero at L,
refine (L.eventually (gt_mem_nhds εpos)).mono (λ n hn y hy, _),
rw dist_eq_norm,
exact (hp y hy n).trans_lt hn
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f (x + y)`
is the locally uniform limit of `p.partial_sum n y` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n y) (λ y, f (x + y))
at_top (emetric.ball (0 : E) r) :=
begin
assume u hu x hx,
rcases ennreal.lt_iff_exists_nnreal_btwn.1 hx with ⟨r', xr', hr'⟩,
have : emetric.ball (0 : E) r' ∈ 𝓝 x :=
mem_nhds_sets emetric.is_open_ball xr',
refine ⟨emetric.ball (0 : E) r', mem_nhds_within_of_mem_nhds this, _⟩,
simpa [metric.emetric_ball_nnreal] using hf.tendsto_uniformly_on hr' u hu
end
/-- If a function admits a power series expansion at `x`, then it is the uniform limit of the
partial sums of this power series on strict subdisks of the disk of convergence, i.e., `f y`
is the uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_uniformly_on' {r' : ℝ≥0}
(hf : has_fpower_series_on_ball f p x r) (h : (r' : ennreal) < r) :
tendsto_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (metric.ball (x : E) r') :=
begin
convert (hf.tendsto_uniformly_on h).comp (λ y, y - x),
{ simp [(∘)] },
{ ext z, simp [dist_eq_norm] }
end
/-- If a function admits a power series expansion at `x`, then it is the locally uniform limit of
the partial sums of this power series on the disk of convergence, i.e., `f y`
is the locally uniform limit of `p.partial_sum n (y - x)` there. -/
lemma has_fpower_series_on_ball.tendsto_locally_uniformly_on'
(hf : has_fpower_series_on_ball f p x r) :
tendsto_locally_uniformly_on (λ n y, p.partial_sum n (y - x)) f at_top (emetric.ball (x : E) r) :=
begin
have A : continuous_on (λ (y : E), y - x) (emetric.ball (x : E) r) :=
(continuous_id.sub continuous_const).continuous_on,
convert (hf.tendsto_locally_uniformly_on).comp (λ (y : E), y - x) _ A,
{ ext z, simp },
{ assume z, simp [edist_eq_coe_nnnorm, edist_eq_coe_nnnorm_sub] }
end
/-- If a function admits a power series expansion on a disk, then it is continuous there. -/
lemma has_fpower_series_on_ball.continuous_on
(hf : has_fpower_series_on_ball f p x r) : continuous_on f (emetric.ball x r) :=
hf.tendsto_locally_uniformly_on'.continuous_on $ λ n,
((p.partial_sum_continuous n).comp (continuous_id.sub continuous_const)).continuous_on
lemma has_fpower_series_at.continuous_at (hf : has_fpower_series_at f p x) : continuous_at f x :=
let ⟨r, hr⟩ := hf in hr.continuous_on.continuous_at (emetric.ball_mem_nhds x (hr.r_pos))
lemma analytic_at.continuous_at (hf : analytic_at 𝕜 f x) : continuous_at f x :=
let ⟨p, hp⟩ := hf in hp.continuous_at
/-- In a complete space, the sum of a converging power series `p` admits `p` as a power series.
This is not totally obvious as we need to check the convergence of the series. -/
lemma formal_multilinear_series.has_fpower_series_on_ball [complete_space F]
(p : formal_multilinear_series 𝕜 E F) (h : 0 < p.radius) :
has_fpower_series_on_ball p.sum p 0 p.radius :=
{ r_le := le_refl _,
r_pos := h,
has_sum := λ y hy, begin
rw zero_add,
replace hy : (nnnorm y : ennreal) < p.radius,
by { convert hy, exact (edist_eq_coe_nnnorm _).symm },
obtain ⟨a, ha : a ∈ Ioo (0 : ℝ) 1, C, hC : 0 < C, hp⟩ :=
p.norm_mul_pow_le_mul_pow_of_lt_radius hy,
refine (summable_of_norm_bounded (λ n, (C : ℝ) * a ^ n)
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _) (λ n, _)).has_sum,
calc ∥(p n) (λ (i : fin n), y)∥
≤ ∥p n∥ * (∏ i : fin n, ∥y∥) : continuous_multilinear_map.le_op_norm _ _
... = ∥p n∥ * (nnnorm y)^n : by simp
... ≤ C * a ^ n : hp n
end }
lemma has_fpower_series_on_ball.sum [complete_space F] (h : has_fpower_series_on_ball f p x r)
{y : E} (hy : y ∈ emetric.ball (0 : E) r) : f (x + y) = p.sum y :=
begin
have A := h.has_sum hy,
have B := (p.has_fpower_series_on_ball h.radius_pos).has_sum (lt_of_lt_of_le hy h.r_le),
simpa using A.unique B
end
/-- The sum of a converging power series is continuous in its disk of convergence. -/
lemma formal_multilinear_series.continuous_on [complete_space F] :
continuous_on p.sum (emetric.ball 0 p.radius) :=
begin
cases (zero_le p.radius).eq_or_lt with h h,
{ simp [← h, continuous_on_empty] },
{ exact (p.has_fpower_series_on_ball h).continuous_on }
end
end
/-!
### Changing origin in a power series
If a function is analytic in a disk `D(x, R)`, then it is analytic in any disk contained in that
one. Indeed, one can write
$$
f (x + y + z) = \sum_{n} p_n (y + z)^n = \sum_{n, k} \binom{n}{k} p_n y^{n-k} z^k
= \sum_{k} \Bigl(\sum_{n} \binom{n}{k} p_n y^{n-k}\Bigr) z^k.
$$
The corresponding power series has thus a `k`-th coefficient equal to
$\sum_{n} \binom{n}{k} p_n y^{n-k}$. In the general case where `pₙ` is a multilinear map, this has
to be interpreted suitably: instead of having a binomial coefficient, one should sum over all
possible subsets `s` of `fin n` of cardinal `k`, and attribute `z` to the indices in `s` and
`y` to the indices outside of `s`.
In this paragraph, we implement this. The new power series is called `p.change_origin y`. Then, we
check its convergence and the fact that its sum coincides with the original sum. The outcome of this
discussion is that the set of points where a function is analytic is open.
-/
namespace formal_multilinear_series
variables (p : formal_multilinear_series 𝕜 E F) {x y : E} {r : ℝ≥0}
/--
Changing the origin of a formal multilinear series `p`, so that
`p.sum (x+y) = (p.change_origin x).sum y` when this makes sense.
Here, we don't use the bracket notation `⟨n, s, hs⟩` in place of the argument `i` in the lambda,
as this leads to a bad definition with auxiliary `_match` statements,
but we will try to use pattern matching in lambdas as much as possible in the proofs below
to increase readability.
-/
def change_origin (x : E) : formal_multilinear_series 𝕜 E F :=
λ k, ∑' i : Σ (n : ℕ), {s : finset (fin n) // finset.card s = k}, (p i.1).restr i.2 i.2.2 x
/-- Auxiliary lemma controlling the summability of the sequence appearing in the definition of
`p.change_origin`, first version. -/
-- Note here and below it is necessary to use `@` and provide implicit arguments using `_`,
-- so that it is possible to use pattern matching in the lambda.
-- Overall this seems a good trade-off in readability.
lemma change_origin_summable_aux1 (h : (nnnorm x + r : ennreal) < p.radius) :
@summable ℝ _ _ _ ((λ ⟨n, s⟩, ∥p n∥ * ∥x∥ ^ (n - s.card) * r ^ s.card) :
(Σ (n : ℕ), finset (fin n)) → ℝ) :=
begin
obtain ⟨a, ha, C, hC, hp : ∀ n, ∥p n∥ * (∥x∥ + ↑r) ^ n ≤ C * a ^ n⟩ :=
p.norm_mul_pow_le_mul_pow_of_lt_radius h,
set B : (Σ n, finset (fin n)) → ℝ := λ ⟨n, s⟩, ∥p n∥ * ∥x∥ ^ (n - s.card) * r ^ s.card,
have H : ∀ n s, 0 ≤ B ⟨n, s⟩ := λ n s, by apply_rules [mul_nonneg, pow_nonneg, norm_nonneg, r.2],
rw summable_sigma_of_nonneg (λ ⟨n, s⟩, H n s),
have : ∀ n, has_sum (λ s, B ⟨n, s⟩) (∥p n∥ * (∥x∥ + r) ^ n),
{ simpa only [← fin.sum_pow_mul_eq_add_pow, finset.mul_sum, ← mul_assoc,
add_comm _ ↑r, mul_right_comm] using λ n, has_sum_fintype (λ s, B ⟨n, s⟩) },
refine ⟨λ n, (this n).summable, _⟩,
simp only [(this _).tsum_eq],
exact summable_of_nonneg_of_le (λ n, (this n).nonneg (H n)) hp
((summable_geometric_of_lt_1 ha.1.le ha.2).mul_left _)
end
/-- Auxiliary lemma controlling the summability of the sequence appearing in the definition of
`p.change_origin`, second version. -/
lemma change_origin_summable_aux2 (h : (nnnorm x + r : ennreal) < p.radius) :
@summable ℝ _ _ _ ((λ ⟨k, n, s, hs⟩, ∥(p n).restr s hs x∥ * ↑r ^ k) :
(Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // finset.card s = k}) → ℝ) :=
begin
let Bnorm : (Σ (n : ℕ), finset (fin n)) → ℝ := λ ⟨n, s⟩, ∥p n∥ * ∥x∥ ^ (n - s.card) * r ^ s.card,
have SBnorm : summable Bnorm := p.change_origin_summable_aux1 h,
let Anorm : (Σ (n : ℕ), finset (fin n)) → ℝ := λ ⟨n, s⟩, ∥(p n).restr s rfl x∥ * r ^ s.card,
have SAnorm : summable Anorm,
{ refine summable_of_norm_bounded _ SBnorm (λ i, _),
rcases i with ⟨n, s⟩,
suffices H : ∥(p n).restr s rfl x∥ * (r : ℝ) ^ s.card ≤
(∥p n∥ * ∥x∥ ^ (n - finset.card s) * r ^ s.card),
{ have : ∥(r: ℝ)∥ = r, by rw [real.norm_eq_abs, abs_of_nonneg (nnreal.coe_nonneg _)],
simpa [Anorm, Bnorm, this] using H },
exact mul_le_mul_of_nonneg_right ((p n).norm_restr s rfl x)
(pow_nonneg (nnreal.coe_nonneg _) _) },
let e : (Σ (n : ℕ), finset (fin n)) ≃
(Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // finset.card s = k}) :=
{ to_fun := λ ⟨n, s⟩, ⟨s.card, n, s, rfl⟩,
inv_fun := λ ⟨k, n, s, hs⟩, ⟨n, s⟩,
left_inv := λ ⟨n, s⟩, rfl,
right_inv := λ ⟨k, n, s, hs⟩, by { induction hs, refl } },
rw ← e.summable_iff,
convert SAnorm,
ext ⟨n, s⟩,
refl
end
/-- An auxiliary definition for `change_origin_radius`. -/
def change_origin_summable_aux_j (k : ℕ) :
(Σ (n : ℕ), {s : finset (fin n) // finset.card s = k})
→ (Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // finset.card s = k}) :=
λ ⟨n, s, hs⟩, ⟨k, n, s, hs⟩
lemma change_origin_summable_aux_j_injective (k : ℕ) :
function.injective (change_origin_summable_aux_j k) :=
begin
rintros ⟨_, ⟨_, _⟩⟩ ⟨_, ⟨_, _⟩⟩ a,
simp only [change_origin_summable_aux_j, true_and, eq_self_iff_true, heq_iff_eq,
sigma.mk.inj_iff] at a,
rcases a with ⟨rfl, a⟩,
simpa using a,
end
/-- Auxiliary lemma controlling the summability of the sequence appearing in the definition of
`p.change_origin`, third version. -/
lemma change_origin_summable_aux3 (k : ℕ) (h : (nnnorm x : ennreal) < p.radius) :
@summable ℝ _ _ _ (λ ⟨n, s, hs⟩, ∥(p n).restr s hs x∥ :
(Σ (n : ℕ), {s : finset (fin n) // finset.card s = k}) → ℝ) :=
begin
obtain ⟨r, rpos, hr⟩ : ∃ (r : ℝ≥0), 0 < r ∧ ((nnnorm x + r) : ennreal) < p.radius :=
ennreal.lt_iff_exists_add_pos_lt.mp h,
have S : @summable ℝ _ _ _ ((λ ⟨n, s, hs⟩, ∥(p n).restr s hs x∥ * (r : ℝ) ^ k) :
(Σ (n : ℕ), {s : finset (fin n) // finset.card s = k}) → ℝ),
{ convert (p.change_origin_summable_aux2 hr).comp_injective
(change_origin_summable_aux_j_injective k),
-- again, cleanup that could be done by `tidy`:
ext ⟨_, ⟨_, _⟩⟩, refl },
have : (r : ℝ)^k ≠ 0, by simp [pow_ne_zero, nnreal.coe_eq_zero, ne_of_gt rpos],
apply (summable_mul_right_iff this).2,
convert S,
-- again, cleanup that could be done by `tidy`:
ext ⟨_, ⟨_, _⟩⟩, refl,
end
-- FIXME this causes a deterministic timeout with `-T50000`
/-- The radius of convergence of `p.change_origin x` is at least `p.radius - ∥x∥`. In other words,
`p.change_origin x` is well defined on the largest ball contained in the original ball of
convergence.-/
lemma change_origin_radius : p.radius - nnnorm x ≤ (p.change_origin x).radius :=
begin
cases le_or_lt p.radius (nnnorm x) with h h,
{ have : radius p - ↑(nnnorm x) = 0 := ennreal.sub_eq_zero_of_le h,
rw this,
exact zero_le _ },
refine ennreal.le_of_forall_nnreal_lt (λ r hr, _),
rw [ennreal.lt_sub_iff_add_lt, add_comm] at hr,
let A : (Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // finset.card s = k}) → ℝ :=
λ ⟨k, n, s, hs⟩, ∥(p n).restr s hs x∥ * (r : ℝ) ^ k,
have SA : summable A := p.change_origin_summable_aux2 hr,
have A_nonneg : ∀ i, 0 ≤ A i,
{ rintros ⟨k, n, s, hs⟩,
change 0 ≤ ∥(p n).restr s hs x∥ * (r : ℝ) ^ k,
refine mul_nonneg (norm_nonneg _) (pow_nonneg (nnreal.coe_nonneg _) _) },
have tsum_nonneg : 0 ≤ tsum A := tsum_nonneg A_nonneg,
refine le_radius_of_bound _ (tsum A) (λ k, _),
calc ∥change_origin p x k∥ * ↑r ^ k
≤ (∑' i : Σ (n : ℕ), {s : finset (fin n) // finset.card s = k},
∥(p i.1).restr i.2.1 i.2.2 x∥) * r ^ k :
begin
apply mul_le_mul_of_nonneg_right _ (pow_nonneg (nnreal.coe_nonneg _) _),
apply norm_tsum_le_tsum_norm,
convert p.change_origin_summable_aux3 k h,
ext ⟨_, _, _⟩,
refl
end
... = tsum (λ i, ∥(p i.1).restr i.2.1 i.2.2 x∥ * ↑r ^ k :
(Σ (n : ℕ), {s : finset (fin n) // finset.card s = k}) → ℝ) :
begin
rw tsum_mul_right,
end
... = tsum (A ∘ change_origin_summable_aux_j k) :
begin
congr,
ext ⟨_, _, _⟩,
refl
end
... ≤ tsum A : tsum_comp_le_tsum_of_inj SA A_nonneg (change_origin_summable_aux_j_injective k)
end
-- From this point on, assume that the space is complete, to make sure that series that converge
-- in norm also converge in `F`.
variable [complete_space F]
/-- The `k`-th coefficient of `p.change_origin` is the sum of a summable series. -/
lemma change_origin_has_sum (k : ℕ) (h : (nnnorm x : ennreal) < p.radius) :
@has_sum (E [×k]→L[𝕜] F) _ _ _ ((λ i, (p i.1).restr i.2.1 i.2.2 x) :
(Σ (n : ℕ), {s : finset (fin n) // finset.card s = k}) → (E [×k]→L[𝕜] F))
(p.change_origin x k) :=
begin
apply summable.has_sum,
apply summable_of_summable_norm,
convert p.change_origin_summable_aux3 k h,
ext ⟨_, _, _⟩,
refl
end
/-- Summing the series `p.change_origin x` at a point `y` gives back `p (x + y)`-/
theorem change_origin_eval (h : (nnnorm x + nnnorm y : ennreal) < p.radius) :
has_sum ((λk:ℕ, p.change_origin x k (λ (i : fin k), y))) (p.sum (x + y)) :=
begin
/- The series on the left is a series of series. If we order the terms differently, we get back
to `p.sum (x + y)`, in which the `n`-th term is expanded by multilinearity. In the proof below,
the term on the left is the sum of a series of terms `A`, the sum on the right is the sum of a
series of terms `B`, and we show that they correspond to each other by reordering to conclude the
proof. -/
have radius_pos : 0 < p.radius := lt_of_le_of_lt (zero_le _) h,
-- `A` is the terms of the series whose sum gives the series for `p.change_origin`
let A : (Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // s.card = k}) → F :=
λ ⟨k, n, s, hs⟩, (p n).restr s hs x (λ(i : fin k), y),
-- `B` is the terms of the series whose sum gives `p (x + y)`, after expansion by multilinearity.
let B : (Σ (n : ℕ), finset (fin n)) → F := λ ⟨n, s⟩, (p n).restr s rfl x (λ (i : fin s.card), y),
let Bnorm : (Σ (n : ℕ), finset (fin n)) → ℝ :=
λ ⟨n, s⟩, ∥p n∥ * ∥x∥ ^ (n - s.card) * ∥y∥ ^ s.card,
have SBnorm : summable Bnorm, by convert p.change_origin_summable_aux1 h,
have SB : summable B,
{ refine summable_of_norm_bounded _ SBnorm _,
rintros ⟨n, s⟩,
calc ∥(p n).restr s rfl x (λ (i : fin s.card), y)∥
≤ ∥(p n).restr s rfl x∥ * ∥y∥ ^ s.card :
begin
convert ((p n).restr s rfl x).le_op_norm (λ (i : fin s.card), y),
simp [(finset.prod_const (∥y∥))],
end
... ≤ (∥p n∥ * ∥x∥ ^ (n - s.card)) * ∥y∥ ^ s.card :
mul_le_mul_of_nonneg_right ((p n).norm_restr _ _ _) (pow_nonneg (norm_nonneg _) _) },
-- Check that indeed the sum of `B` is `p (x + y)`.
have has_sum_B : has_sum B (p.sum (x + y)),
{ have K1 : ∀ n, has_sum (λ (s : finset (fin n)), B ⟨n, s⟩) (p n (λ (i : fin n), x + y)),
{ assume n,
have : (p n) (λ (i : fin n), y + x) = ∑ s : finset (fin n),
p n (finset.piecewise s (λ (i : fin n), y) (λ (i : fin n), x)) :=
(p n).map_add_univ (λ i, y) (λ i, x),
simp [add_comm y x] at this,
rw this,
exact has_sum_fintype _ },
have K2 : has_sum (λ (n : ℕ), (p n) (λ (i : fin n), x + y)) (p.sum (x + y)),
{ have : x + y ∈ emetric.ball (0 : E) p.radius,
{ apply lt_of_le_of_lt _ h,
rw [edist_eq_coe_nnnorm, ← ennreal.coe_add, ennreal.coe_le_coe],
exact norm_add_le x y },
simpa using (p.has_fpower_series_on_ball radius_pos).has_sum this },
exact has_sum.sigma_of_has_sum K2 K1 SB },
-- Deduce that the sum of `A` is also `p (x + y)`, as the terms `A` and `B` are the same up to
-- reordering
have has_sum_A : has_sum A (p.sum (x + y)),
{ let e : (Σ (n : ℕ), finset (fin n)) ≃
(Σ (k : ℕ) (n : ℕ), {s : finset (fin n) // finset.card s = k}) :=
{ to_fun := λ ⟨n, s⟩, ⟨s.card, n, s, rfl⟩,
inv_fun := λ ⟨k, n, s, hs⟩, ⟨n, s⟩,
left_inv := λ ⟨n, s⟩, rfl,
right_inv := λ ⟨k, n, s, hs⟩, by { induction hs, refl } },
have : A ∘ e = B, by { ext ⟨⟩, refl },
rw ← e.has_sum_iff,
convert has_sum_B },
-- Summing `A ⟨k, c⟩` with fixed `k` and varying `c` is exactly the `k`-th term in the series
-- defining `p.change_origin`, by definition
have J : ∀k, has_sum (λ c, A ⟨k, c⟩) (p.change_origin x k (λ(i : fin k), y)),
{ assume k,
have : (nnnorm x : ennreal) < radius p := lt_of_le_of_lt (le_add_right (le_refl _)) h,
convert continuous_multilinear_map.has_sum_eval (p.change_origin_has_sum k this)
(λ(i : fin k), y),
ext ⟨_, _, _⟩,
refl },
exact has_sum_A.sigma J
end
end formal_multilinear_series
section
variables [complete_space F] {f : E → F} {p : formal_multilinear_series 𝕜 E F} {x y : E}
{r : ennreal}
/-- If a function admits a power series expansion `p` on a ball `B (x, r)`, then it also admits a
power series on any subball of this ball (even with a different center), given by `p.change_origin`.
-/
theorem has_fpower_series_on_ball.change_origin
(hf : has_fpower_series_on_ball f p x r) (h : (nnnorm y : ennreal) < r) :
has_fpower_series_on_ball f (p.change_origin y) (x + y) (r - nnnorm y) :=
{ r_le := begin
apply le_trans _ p.change_origin_radius,
exact ennreal.sub_le_sub hf.r_le (le_refl _)
end,
r_pos := by simp [h],
has_sum := begin
assume z hz,
have A : (nnnorm y : ennreal) + nnnorm z < r,
{ have : edist z 0 < r - ↑(nnnorm y) := hz,
rwa [edist_eq_coe_nnnorm, ennreal.lt_sub_iff_add_lt, add_comm] at this },
convert p.change_origin_eval (lt_of_lt_of_le A hf.r_le),
have : y + z ∈ emetric.ball (0 : E) r := calc
edist (y + z) 0 ≤ ↑(nnnorm y) + ↑(nnnorm z) :
by { rw [edist_eq_coe_nnnorm, ← ennreal.coe_add, ennreal.coe_le_coe], exact norm_add_le y z }
... < r : A,
simpa only [add_assoc] using hf.sum this
end }
lemma has_fpower_series_on_ball.analytic_at_of_mem
(hf : has_fpower_series_on_ball f p x r) (h : y ∈ emetric.ball x r) :
analytic_at 𝕜 f y :=
begin
have : (nnnorm (y - x) : ennreal) < r, by simpa [edist_eq_coe_nnnorm_sub] using h,
have := hf.change_origin this,
rw [add_sub_cancel'_right] at this,
exact this.analytic_at
end
variables (𝕜 f)
lemma is_open_analytic_at : is_open {x | analytic_at 𝕜 f x} :=
begin
rw is_open_iff_forall_mem_open,
rintro x ⟨p, r, hr⟩,
refine ⟨emetric.ball x r, λ y hy, hr.analytic_at_of_mem hy, emetric.is_open_ball, _⟩,
simp only [edist_self, emetric.mem_ball, hr.r_pos]
end
variables {𝕜 f}
end
|
3d5104c345a8967784ace870cc8fa20fdbe9ed77 | fe84e287c662151bb313504482b218a503b972f3 | /src/combinatorics/qualify.lean | 4f3465ae32c886871ad1478fd024535914a019f3 | [] | no_license | NeilStrickland/lean_lib | 91e163f514b829c42fe75636407138b5c75cba83 | 6a9563de93748ace509d9db4302db6cd77d8f92c | refs/heads/master | 1,653,408,198,261 | 1,652,996,419,000 | 1,652,996,419,000 | 181,006,067 | 4 | 1 | null | null | null | null | UTF-8 | Lean | false | false | 4,539 | lean | /-
Copyright (c) 2019 Neil Strickland. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Neil Strickland
Suppose we have a list `l` in a type `α`. Suppose we also have a
subset `s` of `α`, formalised in the usual way as a term of type
`set α`, or equivalently a predicate `α → Prop`. Associated to
this we have a subtype `s' = {a : α // a ∈ s}`, and coercions
have been defined so that Lean will interpret `s` as `s'` where
necessary. If all elements of `l` satisfy the predicate defining
`s`, then a mathematician would say that `l` can be regarded as
an element of `list s`. In Lean we still have a corresponding term
`l'` of type `s`, but it is not literally the same as `l`. This
story is not just relevant for lists; there are similar
considerations for pairs, finsets, elements of the free group and
so on.
In this file we use the notation `qualify h l` for `l'`, where
`h` is a proof that the elements of `l` satisfy the relevant
predicate. We prove various basic lemmas about this operation
and its inverse. We have tried to write things in a way that
could be smoothly generalised to functors other than `list`,
but there should probably be some apparatus of type classes
which we have not yet set up. Also, Mario has suggested that
`cod_restrict` would be a better name than `qualify`, for
compatibility with some existing code.
-/
import data.list.basic
import data.list.nodup
variables {α : Type*}
namespace list
open list
def qualify {s : set α} (l : list α) (h : ∀ {a}, a ∈ l → s a) : list s :=
pmap subtype.mk l @h
lemma length_qualify {s : set α} (l : list α) (h : ∀ {a}, a ∈ l → s a) :
(qualify l @h).length = l.length := length_pmap
def unqualify {s : set α} (l : list s) : list α := l.map subtype.val
@[simp]
lemma unqualify_nil {s : set α} : unqualify (@nil s) = nil := rfl
@[simp]
lemma unqualify_cons {s : set α} (a : s) (l : list s) :
unqualify (a :: l) = a.val :: (unqualify l) := rfl
lemma unqualify_eq {s : set α} {l₁ l₂ : list s} :
l₁ = l₂ ↔ (unqualify l₁ = unqualify l₂) :=
begin
split,
{exact congr_arg unqualify,},
{induction l₁ with x₁ l₁ ih generalizing l₂,
{rw[unqualify_nil],
rcases l₂ with _ | ⟨x₂,l₂⟩,
{intro,refl},
{rw[unqualify_cons],intro eu,exact false.elim (list.no_confusion eu)}
},{
rw[unqualify_cons],
rcases l₂ with _ | ⟨x₂,l₂⟩,
{intro eu,exact false.elim (list.no_confusion eu)},
{rw[unqualify_cons],intro eu,injection eu with euh eut,congr,
exact subtype.eq euh,exact ih eut,
}
}
}
end
@[simp]
lemma length_unqualify {s : set α} (l : list s) : (unqualify l).length = l.length :=
length_map subtype.val l
lemma mem_unqualify {s : set α} {l : list s} {a : α} :
a ∈ unqualify l ↔ (∃ h : s a, subtype.mk a h ∈ l) :=
begin
rcases (@mem_map s α subtype.val a l) with ⟨h0,h1⟩,
split,
{intro h2,rcases h0 h2 with ⟨⟨a,a_in_s⟩,⟨a_in_l,rfl⟩⟩,exact ⟨a_in_s,a_in_l⟩ },
{rintro ⟨a_in_s,a_in_l⟩,exact h1 ⟨⟨a,a_in_s⟩,⟨a_in_l,rfl⟩⟩}
end
lemma mem_unqualify' {s : set α} {l : list s} {a : s} :
a.val ∈ unqualify l ↔ a ∈ l :=
begin
split,
{intro h0,
rcases (mem_unqualify.mp h0) with ⟨a_in_s,a_in_l⟩ ,
have h1 : a = ⟨a.val,a_in_s⟩ := subtype.eq rfl,
rw[h1],exact a_in_l,
},
{intro h0,exact mem_map_of_mem _ h0,}
end
@[simp]
lemma un_qualify {s : set α} (l : list α) (h : ∀ {a}, a ∈ l → s a) :
unqualify (qualify l @h) = l :=
begin
dsimp[qualify],
induction l with x l ih,
{refl},
{rw[unqualify,pmap,map],congr,
exact ih (λ a a_in_l, h (mem_cons_of_mem x a_in_l)),
}
end
def requalify {s t : set α} (l : list s) (h : ∀ {u : s}, u ∈ l → t u) : list t :=
qualify (unqualify l)
(λ a a_in_l,
begin rcases (mem_unqualify.mp a_in_l) with ⟨a_in_s,a_in_l⟩, exact h a_in_l, end )
@[simp]
lemma un_requalify {s t : set α} (l : list s) (h : ∀ {u : s}, u ∈ l → t u) :
unqualify (requalify l @h) = unqualify l :=
begin
dsimp[requalify],rw[un_qualify]
end
lemma nodup_unqualify {s : set α} : ∀ {l : list s}, (unqualify l).nodup ↔ l.nodup
| [] := by { rw[unqualify_nil],simp only [nodup_nil], }
| (a :: l) := begin
rw[unqualify_cons,nodup_cons,nodup_cons,nodup_unqualify,@mem_unqualify' α s l a],
end
lemma nodup_qualify {s : set α} (l : list α) (h : ∀ {a}, a ∈ l → s a) :
(qualify l @h).nodup ↔ l.nodup := by { rw[← nodup_unqualify,un_qualify], }
end list |
1cd759816df14f79f39e0778304417b2ff4d99d3 | 6e4b1527dfc11d1b56419f0d747c66d3b258260b | /src/parsing/char.lean | f28d231d523ad6039a6d83a9aa1fcca22b69b111 | [
"Apache-2.0"
] | permissive | jroesch/parsing | 7860046a3b96dd3695f25e274034de518a2da7c6 | 8ac39e59498d33b674fda526bfef44af66ca9df8 | refs/heads/master | 1,626,501,031,276 | 1,508,386,101,000 | 1,508,386,101,000 | 107,495,434 | 1 | 0 | null | null | null | null | UTF-8 | Lean | false | false | 597 | lean | import data.buffer
import .core
namespace parser.char
open parser
@[reducible] def t := parser char
-- def parser = parser
/-- Matches a string. Does not consume input in case of failure. -/
def str (s : string) : parser char unit :=
decorate_error s $ s.to_list.mmap' el
def many_char (p : parser char char) : parser char string :=
list.as_string <$> many p
-- universe u
/-- Runs a parser on the given input. The parser needs to match the complete input. -/
def run_string {α : Type} (p : parser char α) (input : string) : sum string α :=
run p input.to_char_buffer
end parser.char
|
32f0b00faee7437dd0f25313876d7c051ce3d666 | 9dc8cecdf3c4634764a18254e94d43da07142918 | /src/order/partition/finpartition.lean | 3d351d98f15ba76ca62e7842940ee87d33489ada | [
"Apache-2.0"
] | permissive | jcommelin/mathlib | d8456447c36c176e14d96d9e76f39841f69d2d9b | ee8279351a2e434c2852345c51b728d22af5a156 | refs/heads/master | 1,664,782,136,488 | 1,663,638,983,000 | 1,663,638,983,000 | 132,563,656 | 0 | 0 | Apache-2.0 | 1,663,599,929,000 | 1,525,760,539,000 | Lean | UTF-8 | Lean | false | false | 19,720 | lean | /-
Copyright (c) 2022 Yaël Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yaël Dillies, Bhavik Mehta
-/
import algebra.big_operators.basic
import order.atoms
import order.locally_finite
import order.sup_indep
/-!
# Finite partitions
In this file, we define finite partitions. A finpartition of `a : α` is a finite set of pairwise
disjoint parts `parts : finset α` which does not contain `⊥` and whose supremum is `a`.
Finpartitions of a finset are at the heart of Szemerédi's regularity lemma. They are also studied
purely order theoretically in Sperner theory.
## Constructions
We provide many ways to build finpartitions:
* `finpartition.of_erase`: Builds a finpartition by erasing `⊥` for you.
* `finpartition.of_subset`: Builds a finpartition from a subset of the parts of a previous
finpartition.
* `finpartition.empty`: The empty finpartition of `⊥`.
* `finpartition.indiscrete`: The indiscrete, aka trivial, aka pure, finpartition made of a single
part.
* `finpartition.discrete`: The discrete finpartition of `s : finset α` made of singletons.
* `finpartition.bind`: Puts together the finpartitions of the parts of a finpartition into a new
finpartition.
* `finpartition.atomise`: Makes a finpartition of `s : finset α` by breaking `s` along all finsets
in `F : finset (finset α)`. Two elements of `s` belong to the same part iff they belong to the
same elements of `F`.
`finpartition.indiscrete` and `finpartition.bind` together form the monadic structure of
`finpartition`.
## Implementation notes
Forbidding `⊥` as a part follows mathematical tradition and is a pragmatic choice concerning
operations on `finpartition`. Not caring about `⊥` being a part or not breaks extensionality (it's
not because the parts of `P` and the parts of `Q` have the same elements that `P = Q`). Enforcing
`⊥` to be a part makes `finpartition.bind` uglier and doesn't rid us of the need of
`finpartition.of_erase`.
## TODO
Link `finpartition` and `setoid.is_partition`.
The order is the wrong way around to make `finpartition a` a graded order. Is it bad to depart from
the literature and turn the order around?
-/
open finset function
open_locale big_operators
variables {α : Type*}
/-- A finite partition of `a : α` is a pairwise disjoint finite set of elements whose supremum is
`a`. We forbid `⊥` as a part. -/
@[ext, derive decidable_eq] structure finpartition [lattice α] [order_bot α] (a : α) :=
(parts : finset α)
(sup_indep : parts.sup_indep id)
(sup_parts : parts.sup id = a)
(not_bot_mem : ⊥ ∉ parts)
attribute [protected] finpartition.sup_indep
namespace finpartition
section lattice
variables [lattice α] [order_bot α]
/-- A `finpartition` constructor which does not insist on `⊥` not being a part. -/
@[simps] def of_erase [decidable_eq α] {a : α} (parts : finset α)
(sup_indep : parts.sup_indep id) (sup_parts : parts.sup id = a) :
finpartition a :=
{ parts := parts.erase ⊥,
sup_indep := sup_indep.subset (erase_subset _ _),
sup_parts := (sup_erase_bot _).trans sup_parts,
not_bot_mem := not_mem_erase _ _ }
/-- A `finpartition` constructor from a bigger existing finpartition. -/
@[simps] def of_subset {a b : α} (P : finpartition a) {parts : finset α}
(subset : parts ⊆ P.parts) (sup_parts : parts.sup id = b) :
finpartition b :=
{ parts := parts,
sup_indep := P.sup_indep.subset subset,
sup_parts := sup_parts,
not_bot_mem := λ h, P.not_bot_mem (subset h) }
/-- Changes the type of a finpartition to an equal one. -/
@[simps] def copy {a b : α} (P : finpartition a) (h : a = b) : finpartition b :=
{ parts := P.parts,
sup_indep := P.sup_indep,
sup_parts := h ▸ P.sup_parts,
not_bot_mem := P.not_bot_mem }
variables (α)
/-- The empty finpartition. -/
@[simps] protected def empty : finpartition (⊥ : α) :=
{ parts := ∅,
sup_indep := sup_indep_empty _,
sup_parts := finset.sup_empty,
not_bot_mem := not_mem_empty ⊥ }
instance : inhabited (finpartition (⊥ : α)) := ⟨finpartition.empty α⟩
@[simp] lemma default_eq_empty : (default : finpartition (⊥ : α)) = finpartition.empty α := rfl
variables {α} {a : α}
/-- The finpartition in one part, aka indiscrete finpartition. -/
@[simps] def indiscrete (ha : a ≠ ⊥) : finpartition a :=
{ parts := {a},
sup_indep := sup_indep_singleton _ _,
sup_parts := finset.sup_singleton,
not_bot_mem := λ h, ha (mem_singleton.1 h).symm }
variables (P : finpartition a)
protected lemma le {b : α} (hb : b ∈ P.parts) : b ≤ a := (le_sup hb).trans P.sup_parts.le
lemma ne_bot {b : α} (hb : b ∈ P.parts) : b ≠ ⊥ := λ h, P.not_bot_mem $ h.subst hb
protected lemma disjoint : (P.parts : set α).pairwise_disjoint id := P.sup_indep.pairwise_disjoint
variables {P}
lemma parts_eq_empty_iff : P.parts = ∅ ↔ a = ⊥ :=
begin
simp_rw ←P.sup_parts,
refine ⟨λ h, _, λ h, eq_empty_iff_forall_not_mem.2 (λ b hb, P.not_bot_mem _)⟩,
{ rw h,
exact finset.sup_empty },
{ rwa ←le_bot_iff.1 ((le_sup hb).trans h.le) }
end
lemma parts_nonempty_iff : P.parts.nonempty ↔ a ≠ ⊥ :=
by rw [nonempty_iff_ne_empty, not_iff_not, parts_eq_empty_iff]
lemma parts_nonempty (P : finpartition a) (ha : a ≠ ⊥) : P.parts.nonempty := parts_nonempty_iff.2 ha
instance : unique (finpartition (⊥ : α)) :=
{ uniq := λ P,
by { ext a, exact iff_of_false (λ h, P.ne_bot h $ le_bot_iff.1 $ P.le h) (not_mem_empty a) },
..finpartition.inhabited α }
/-- There's a unique partition of an atom. -/
@[reducible] -- See note [reducible non instances]
def _root_.is_atom.unique_finpartition (ha : is_atom a) : unique (finpartition a) :=
{ default := indiscrete ha.1,
uniq := λ P, begin
have h : ∀ b ∈ P.parts, b = a,
{ exact λ b hb, (ha.le_iff.mp $ P.le hb).resolve_left (P.ne_bot hb) },
ext b,
refine iff.trans ⟨h b, _⟩ mem_singleton.symm,
rintro rfl,
obtain ⟨c, hc⟩ := P.parts_nonempty ha.1,
simp_rw ←h c hc,
exact hc,
end }
instance [fintype α] [decidable_eq α] (a : α) :
fintype (finpartition a) :=
@fintype.of_surjective {p : finset α // p.sup_indep id ∧ p.sup id = a ∧ ⊥ ∉ p} (finpartition a) _
(subtype.fintype _) (λ i, ⟨i.1, i.2.1, i.2.2.1, i.2.2.2⟩) (λ ⟨_, y, z, w⟩, ⟨⟨_, y, z, w⟩, rfl⟩)
/-! ### Refinement order -/
section order
/-- We say that `P ≤ Q` if `P` refines `Q`: each part of `P` is less than some part of `Q`. -/
instance : has_le (finpartition a) := ⟨λ P Q, ∀ ⦃b⦄, b ∈ P.parts → ∃ c ∈ Q.parts, b ≤ c⟩
instance : partial_order (finpartition a) :=
{ le_refl := λ P b hb, ⟨b, hb, le_rfl⟩,
le_trans := λ P Q R hPQ hQR b hb, begin
obtain ⟨c, hc, hbc⟩ := hPQ hb,
obtain ⟨d, hd, hcd⟩ := hQR hc,
exact ⟨d, hd, hbc.trans hcd⟩,
end,
le_antisymm := λ P Q hPQ hQP, begin
ext b,
refine ⟨λ hb, _, λ hb, _⟩,
{ obtain ⟨c, hc, hbc⟩ := hPQ hb,
obtain ⟨d, hd, hcd⟩ := hQP hc,
rwa hbc.antisymm,
rwa P.disjoint.eq_of_le hb hd (P.ne_bot hb) (hbc.trans hcd) },
{ obtain ⟨c, hc, hbc⟩ := hQP hb,
obtain ⟨d, hd, hcd⟩ := hPQ hc,
rwa hbc.antisymm,
rwa Q.disjoint.eq_of_le hb hd (Q.ne_bot hb) (hbc.trans hcd) }
end,
..finpartition.has_le }
instance [decidable (a = ⊥)] : order_top (finpartition a) :=
{ top := if ha : a = ⊥ then (finpartition.empty α).copy ha.symm else indiscrete ha,
le_top := λ P,
begin
split_ifs,
{ intros x hx,
simpa [h, P.ne_bot hx] using P.le hx },
{ exact λ b hb, ⟨a, mem_singleton_self _, P.le hb⟩ }
end }
lemma parts_top_subset (a : α) [decidable (a = ⊥)] : (⊤ : finpartition a).parts ⊆ {a} :=
begin
intros b hb,
change b ∈ finpartition.parts (dite _ _ _) at hb,
split_ifs at hb,
{ simp only [copy_parts, empty_parts, not_mem_empty] at hb,
exact hb.elim },
{ exact hb }
end
lemma parts_top_subsingleton (a : α) [decidable (a = ⊥)] :
((⊤ : finpartition a).parts : set α).subsingleton :=
set.subsingleton_of_subset_singleton $ λ b hb, mem_singleton.1 $ parts_top_subset _ hb
end order
end lattice
section distrib_lattice
variables [distrib_lattice α] [order_bot α]
section inf
variables [decidable_eq α] {a b c : α}
instance : has_inf (finpartition a) :=
⟨λ P Q, of_erase ((P.parts ×ˢ Q.parts).image $ λ bc, bc.1 ⊓ bc.2)
begin
rw sup_indep_iff_disjoint_erase,
simp only [mem_image, and_imp, exists_prop, forall_exists_index, id.def, prod.exists,
mem_product, finset.disjoint_sup_right, mem_erase, ne.def],
rintro _ x₁ y₁ hx₁ hy₁ rfl _ h x₂ y₂ hx₂ hy₂ rfl,
rcases eq_or_ne x₁ x₂ with rfl | xdiff,
{ refine disjoint.mono inf_le_right inf_le_right (Q.disjoint hy₁ hy₂ _),
intro t,
simpa [t] using h },
exact disjoint.mono inf_le_left inf_le_left (P.disjoint hx₁ hx₂ xdiff),
end
begin
rw [sup_image, comp.left_id, sup_product_left],
transitivity P.parts.sup id ⊓ Q.parts.sup id,
{ simp_rw [finset.sup_inf_distrib_right, finset.sup_inf_distrib_left],
refl },
{ rw [P.sup_parts, Q.sup_parts, inf_idem] }
end⟩
@[simp] lemma parts_inf (P Q : finpartition a) :
(P ⊓ Q).parts = ((P.parts ×ˢ Q.parts).image $ λ bc : α × α, bc.1 ⊓ bc.2).erase ⊥ := rfl
instance : semilattice_inf (finpartition a) :=
{ inf_le_left := λ P Q b hb, begin
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb),
rw mem_product at hc,
exact ⟨c.1, hc.1, inf_le_left⟩,
end,
inf_le_right := λ P Q b hb, begin
obtain ⟨c, hc, rfl⟩ := mem_image.1 (mem_of_mem_erase hb),
rw mem_product at hc,
exact ⟨c.2, hc.2, inf_le_right⟩,
end,
le_inf := λ P Q R hPQ hPR b hb, begin
obtain ⟨c, hc, hbc⟩ := hPQ hb,
obtain ⟨d, hd, hbd⟩ := hPR hb,
have h := _root_.le_inf hbc hbd,
refine ⟨c ⊓ d, mem_erase_of_ne_of_mem (ne_bot_of_le_ne_bot (P.ne_bot hb) h)
(mem_image.2 ⟨(c, d), mem_product.2 ⟨hc, hd⟩, rfl⟩), h⟩,
end,
..finpartition.partial_order, ..finpartition.has_inf }
end inf
lemma exists_le_of_le {a b : α} {P Q : finpartition a} (h : P ≤ Q) (hb : b ∈ Q.parts) :
∃ c ∈ P.parts, c ≤ b :=
begin
by_contra' H,
refine Q.ne_bot hb (disjoint_self.1 $ disjoint.mono_right (Q.le hb) _),
rw [←P.sup_parts, finset.disjoint_sup_right],
rintro c hc,
obtain ⟨d, hd, hcd⟩ := h hc,
refine (Q.disjoint hb hd _).mono_right hcd,
rintro rfl,
exact H _ hc hcd,
end
lemma card_mono {a : α} {P Q : finpartition a} (h : P ≤ Q) : Q.parts.card ≤ P.parts.card :=
begin
classical,
have : ∀ b ∈ Q.parts, ∃ c ∈ P.parts, c ≤ b := λ b, exists_le_of_le h,
choose f hP hf using this,
rw ←card_attach,
refine card_le_card_of_inj_on (λ b, f _ b.2) (λ b _, hP _ b.2) (λ b hb c hc h, _),
exact subtype.coe_injective (Q.disjoint.elim b.2 c.2 $ λ H, P.ne_bot (hP _ b.2) $
disjoint_self.1 $ H.mono (hf _ b.2) $ h.le.trans $ hf _ c.2),
end
variables [decidable_eq α] {a b c : α}
section bind
variables {P : finpartition a} {Q : Π i ∈ P.parts, finpartition i}
/-- Given a finpartition `P` of `a` and finpartitions of each part of `P`, this yields the
finpartition of `a` obtained by juxtaposing all the subpartitions. -/
@[simps] def bind (P : finpartition a) (Q : Π i ∈ P.parts, finpartition i) : finpartition a :=
{ parts := P.parts.attach.bUnion (λ i, (Q i.1 i.2).parts),
sup_indep := begin
rw sup_indep_iff_pairwise_disjoint,
rintro a ha b hb h,
rw [finset.mem_coe, finset.mem_bUnion] at ha hb,
obtain ⟨⟨A, hA⟩, -, ha⟩ := ha,
obtain ⟨⟨B, hB⟩, -, hb⟩ := hb,
obtain rfl | hAB := eq_or_ne A B,
{ exact (Q A hA).disjoint ha hb h },
{ exact (P.disjoint hA hB hAB).mono ((Q A hA).le ha) ((Q B hB).le hb) }
end,
sup_parts := begin
simp_rw [sup_bUnion, ←P.sup_parts],
rw [eq_comm, ←finset.sup_attach],
exact sup_congr rfl (λ b hb, (Q b.1 b.2).sup_parts.symm),
end,
not_bot_mem := λ h, begin
rw finset.mem_bUnion at h,
obtain ⟨⟨A, hA⟩, -, h⟩ := h,
exact (Q A hA).not_bot_mem h,
end }
lemma mem_bind : b ∈ (P.bind Q).parts ↔ ∃ A hA, b ∈ (Q A hA).parts :=
begin
rw [bind, mem_bUnion],
split,
{ rintro ⟨⟨A, hA⟩, -, h⟩,
exact ⟨A, hA, h⟩ },
{ rintro ⟨A, hA, h⟩,
exact ⟨⟨A, hA⟩, mem_attach _ ⟨A, hA⟩, h⟩ }
end
lemma card_bind (Q : Π i ∈ P.parts, finpartition i) :
(P.bind Q).parts.card = ∑ A in P.parts.attach, (Q _ A.2).parts.card :=
begin
apply card_bUnion,
rintro ⟨b, hb⟩ - ⟨c, hc⟩ - hbc d,
rw [inf_eq_inter, mem_inter],
rintro ⟨hdb, hdc⟩,
rw [ne.def, subtype.mk_eq_mk] at hbc,
exact (Q b hb).ne_bot hdb (eq_bot_iff.2 $
(le_inf ((Q b hb).le hdb) $ (Q c hc).le hdc).trans $ P.disjoint hb hc hbc),
end
end bind
/-- Adds `b` to a finpartition of `a` to make a finpartition of `a ⊔ b`. -/
@[simps] def extend (P : finpartition a) (hb : b ≠ ⊥) (hab : disjoint a b) (hc : a ⊔ b = c) :
finpartition c :=
{ parts := insert b P.parts,
sup_indep :=
begin
rw [sup_indep_iff_pairwise_disjoint, coe_insert],
exact P.disjoint.insert (λ d hd hbd, hab.symm.mono_right $ P.le hd),
end,
sup_parts := by rwa [sup_insert, P.sup_parts, id, _root_.sup_comm],
not_bot_mem := λ h, (mem_insert.1 h).elim hb.symm P.not_bot_mem }
lemma card_extend (P : finpartition a) (b c : α) {hb : b ≠ ⊥} {hab : disjoint a b}
{hc : a ⊔ b = c} :
(P.extend hb hab hc).parts.card = P.parts.card + 1 :=
card_insert_of_not_mem $ λ h, hb $ hab.symm.eq_bot_of_le $ P.le h
end distrib_lattice
section generalized_boolean_algebra
variables [generalized_boolean_algebra α] [decidable_eq α] {a b c : α} (P : finpartition a)
/-- Restricts a finpartition to avoid a given element. -/
@[simps] def avoid (b : α) : finpartition (a \ b) :=
of_erase
(P.parts.image (\ b))
(P.disjoint.image_finset_of_le $ λ a, sdiff_le).sup_indep
(by rw [sup_image, comp.left_id, finset.sup_sdiff_right, ←id_def, P.sup_parts])
@[simp] lemma mem_avoid : c ∈ (P.avoid b).parts ↔ ∃ d ∈ P.parts, ¬ d ≤ b ∧ d \ b = c :=
begin
simp only [avoid, of_erase_parts, mem_erase, ne.def, mem_image, exists_prop,
←exists_and_distrib_left, @and.left_comm (c ≠ ⊥)],
refine exists_congr (λ d, and_congr_right' $ and_congr_left _),
rintro rfl,
rw sdiff_eq_bot_iff,
end
end generalized_boolean_algebra
end finpartition
/-! ### Finite partitions of finsets -/
namespace finpartition
variables [decidable_eq α] {s t : finset α} (P : finpartition s)
lemma nonempty_of_mem_parts {a : finset α} (ha : a ∈ P.parts) : a.nonempty :=
nonempty_iff_ne_empty.2 $ P.ne_bot ha
lemma exists_mem {a : α} (ha : a ∈ s) : ∃ t ∈ P.parts, a ∈ t :=
by { simp_rw ←P.sup_parts at ha, exact mem_sup.1 ha }
lemma bUnion_parts : P.parts.bUnion id = s := (sup_eq_bUnion _ _).symm.trans P.sup_parts
lemma sum_card_parts : ∑ i in P.parts, i.card = s.card :=
begin
convert congr_arg finset.card P.bUnion_parts,
rw card_bUnion P.sup_indep.pairwise_disjoint,
refl,
end
/-- `⊥` is the partition in singletons, aka discrete partition. -/
instance (s : finset α) : has_bot (finpartition s) :=
⟨{ parts := s.map ⟨singleton, singleton_injective⟩,
sup_indep := set.pairwise_disjoint.sup_indep begin
rw finset.coe_map,
exact finset.pairwise_disjoint_range_singleton.subset (set.image_subset_range _ _),
end,
sup_parts := by rw [sup_map, comp.left_id, embedding.coe_fn_mk, finset.sup_singleton'],
not_bot_mem := by simp }⟩
@[simp] lemma parts_bot (s : finset α) :
(⊥ : finpartition s).parts = s.map ⟨singleton, singleton_injective⟩ := rfl
lemma card_bot (s : finset α) : (⊥ : finpartition s).parts.card = s.card := finset.card_map _
lemma mem_bot_iff : t ∈ (⊥ : finpartition s).parts ↔ ∃ a ∈ s, {a} = t := mem_map
instance (s : finset α) : order_bot (finpartition s) :=
{ bot_le := λ P t ht, begin
rw mem_bot_iff at ht,
obtain ⟨a, ha, rfl⟩ := ht,
obtain ⟨t, ht, hat⟩ := P.exists_mem ha,
exact ⟨t, ht, singleton_subset_iff.2 hat⟩,
end,
..finpartition.has_bot s }
lemma card_parts_le_card (P : finpartition s) : P.parts.card ≤ s.card :=
by { rw ←card_bot s, exact card_mono bot_le }
section atomise
/-- Cuts `s` along the finsets in `F`: Two elements of `s` will be in the same part if they are
in the same finsets of `F`. -/
def atomise (s : finset α) (F : finset (finset α)) : finpartition s :=
of_erase
(F.powerset.image $ λ Q, s.filter (λ i, ∀ t ∈ F, t ∈ Q ↔ i ∈ t))
(set.pairwise_disjoint.sup_indep $ λ x hx y hy h z hz, h begin
rw [mem_coe, mem_image] at hx hy,
obtain ⟨Q, hQ, rfl⟩ := hx,
obtain ⟨R, hR, rfl⟩ := hy,
suffices h : Q = R,
{ subst h },
rw [id, id, inf_eq_inter, mem_inter, mem_filter, mem_filter] at hz,
rw mem_powerset at hQ hR,
ext i,
refine ⟨λ hi, _, λ hi, _⟩,
{ rwa [hz.2.2 _ (hQ hi), ←hz.1.2 _ (hQ hi)] },
{ rwa [hz.1.2 _ (hR hi), ←hz.2.2 _ (hR hi)] }
end)
(begin
refine (finset.sup_le $ λ t ht, _).antisymm (λ a ha, _),
{ rw mem_image at ht,
obtain ⟨A, hA, rfl⟩ := ht,
exact s.filter_subset _ },
{ rw [mem_sup],
refine ⟨s.filter (λ i, ∀ t, t ∈ F → (t ∈ F.filter (λ u, a ∈ u) ↔ i ∈ t)),
mem_image_of_mem _ (mem_powerset.2 $ filter_subset _ _), mem_filter.2 ⟨ha, λ t ht, _⟩⟩,
rw mem_filter,
exact and_iff_right ht }
end)
variables {F : finset (finset α)}
lemma mem_atomise :
t ∈ (atomise s F).parts ↔ t.nonempty ∧ ∃ (Q ⊆ F), s.filter (λ i, ∀ u ∈ F, u ∈ Q ↔ i ∈ u) = t :=
by simp only [atomise, of_erase, bot_eq_empty, mem_erase, mem_image, nonempty_iff_ne_empty,
mem_singleton, and_comm, mem_powerset, exists_prop]
lemma atomise_empty (hs : s.nonempty) : (atomise s ∅).parts = {s} :=
begin
simp only [atomise, powerset_empty, image_singleton, not_mem_empty, is_empty.forall_iff,
implies_true_iff, filter_true],
exact erase_eq_of_not_mem (not_mem_singleton.2 hs.ne_empty.symm),
end
lemma card_atomise_le : (atomise s F).parts.card ≤ 2^F.card :=
(card_le_of_subset $ erase_subset _ _).trans $ finset.card_image_le.trans (card_powerset _).le
lemma bUnion_filter_atomise (ht : t ∈ F) (hts : t ⊆ s) :
((atomise s F).parts.filter $ λ u, u ⊆ t ∧ u.nonempty).bUnion id = t :=
begin
ext a,
refine mem_bUnion.trans ⟨λ ⟨u, hu, ha⟩, (mem_filter.1 hu).2.1 ha, λ ha, _⟩,
obtain ⟨u, hu, hau⟩ := (atomise s F).exists_mem (hts ha),
refine ⟨u, mem_filter.2 ⟨hu, λ b hb, _, _, hau⟩, hau⟩,
obtain ⟨Q, hQ, rfl⟩ := (mem_atomise.1 hu).2,
rw mem_filter at hau hb,
rwa [←hb.2 _ ht, hau.2 _ ht],
end
lemma card_filter_atomise_le_two_pow (ht : t ∈ F) :
((atomise s F).parts.filter $ λ u, u ⊆ t ∧ u.nonempty).card ≤ 2 ^ (F.card - 1) :=
begin
suffices h : (atomise s F).parts.filter (λ u, u ⊆ t ∧ u.nonempty)
⊆ (F.erase t).powerset.image (λ P, s.filter $ λ i, ∀ x ∈ F, x ∈ insert t P ↔ i ∈ x),
{ refine (card_le_of_subset h).trans (card_image_le.trans _),
rw [card_powerset, card_erase_of_mem ht] },
rw subset_iff,
simp only [mem_erase, mem_sdiff, mem_powerset, mem_image, exists_prop, mem_filter, and_assoc,
finset.nonempty, exists_imp_distrib, and_imp, mem_atomise, forall_apply_eq_imp_iff₂],
rintro P' i hi P PQ rfl hy₂ j hj,
refine ⟨P.erase t, erase_subset_erase _ PQ, _⟩,
simp only [insert_erase (((mem_filter.1 hi).2 _ ht).2 $ hy₂ hi), filter_congr_decidable],
end
end atomise
end finpartition
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.